react-semaphor 0.0.380 → 0.0.381
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/{index-DVyKgtY2.js → index-Aexvs6bn.js} +5890 -5880
- package/dist/chunks/{index-DtslCSgq.js → index-DkaJf5Kh.js} +84 -84
- package/dist/dashboard/index.cjs +1 -1
- package/dist/dashboard/index.js +1 -1
- package/dist/index.cjs +13 -13
- package/dist/index.js +911 -934
- package/dist/style.css +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("./chunks/index-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("./chunks/index-DkaJf5Kh.js"),e=require("react/jsx-runtime"),y=require("react");require("react-dom");function gs(t){const n=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(t){for(const a in t)if(a!=="default"){const r=Object.getOwnPropertyDescriptor(t,a);Object.defineProperty(n,a,r.get?r:{enumerable:!0,get:()=>t[a]})}}return n.default=t,Object.freeze(n)}const Ve=gs(y);/**
|
|
2
2
|
* @license lucide-react v0.453.0 - ISC
|
|
3
3
|
*
|
|
4
4
|
* This source code is licensed under the ISC license.
|
|
@@ -118,52 +118,52 @@
|
|
|
118
118
|
*
|
|
119
119
|
* This source code is licensed under the ISC license.
|
|
120
120
|
* See the LICENSE file in the root directory of this source tree.
|
|
121
|
-
*/const
|
|
121
|
+
*/const Os=s.createLucideIcon("Logs",[["path",{d:"M13 12h8",key:"h98zly"}],["path",{d:"M13 18h8",key:"oe0vm4"}],["path",{d:"M13 6h8",key:"15sg57"}],["path",{d:"M3 12h1",key:"lp3yf2"}],["path",{d:"M3 18h1",key:"1eiwyy"}],["path",{d:"M3 6h1",key:"rgxa97"}],["path",{d:"M8 12h1",key:"1con00"}],["path",{d:"M8 18h1",key:"13wk12"}],["path",{d:"M8 6h1",key:"tn6mkg"}]]);/**
|
|
122
122
|
* @license lucide-react v0.453.0 - ISC
|
|
123
123
|
*
|
|
124
124
|
* This source code is licensed under the ISC license.
|
|
125
125
|
* See the LICENSE file in the root directory of this source tree.
|
|
126
|
-
*/const
|
|
126
|
+
*/const $e=s.createLucideIcon("Map",[["path",{d:"M14.106 5.553a2 2 0 0 0 1.788 0l3.659-1.83A1 1 0 0 1 21 4.619v12.764a1 1 0 0 1-.553.894l-4.553 2.277a2 2 0 0 1-1.788 0l-4.212-2.106a2 2 0 0 0-1.788 0l-3.659 1.83A1 1 0 0 1 3 19.381V6.618a1 1 0 0 1 .553-.894l4.553-2.277a2 2 0 0 1 1.788 0z",key:"169xi5"}],["path",{d:"M15 5.764v15",key:"1pn4in"}],["path",{d:"M9 3.236v15",key:"1uimfh"}]]);/**
|
|
127
127
|
* @license lucide-react v0.453.0 - ISC
|
|
128
128
|
*
|
|
129
129
|
* This source code is licensed under the ISC license.
|
|
130
130
|
* See the LICENSE file in the root directory of this source tree.
|
|
131
|
-
*/const Ms=s.createLucideIcon("
|
|
131
|
+
*/const Ms=s.createLucideIcon("MessageSquareMore",[["path",{d:"M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z",key:"1lielz"}],["path",{d:"M8 10h.01",key:"19clt8"}],["path",{d:"M12 10h.01",key:"1nrarc"}],["path",{d:"M16 10h.01",key:"1m94wz"}]]);/**
|
|
132
132
|
* @license lucide-react v0.453.0 - ISC
|
|
133
133
|
*
|
|
134
134
|
* This source code is licensed under the ISC license.
|
|
135
135
|
* See the LICENSE file in the root directory of this source tree.
|
|
136
|
-
*/const Fs=s.createLucideIcon("
|
|
136
|
+
*/const Fs=s.createLucideIcon("Network",[["rect",{x:"16",y:"16",width:"6",height:"6",rx:"1",key:"4q2zg0"}],["rect",{x:"2",y:"16",width:"6",height:"6",rx:"1",key:"8cvhb9"}],["rect",{x:"9",y:"2",width:"6",height:"6",rx:"1",key:"1egb70"}],["path",{d:"M5 16v-3a1 1 0 0 1 1-1h12a1 1 0 0 1 1 1v3",key:"1jsf9p"}],["path",{d:"M12 12V8",key:"2874zd"}]]);/**
|
|
137
137
|
* @license lucide-react v0.453.0 - ISC
|
|
138
138
|
*
|
|
139
139
|
* This source code is licensed under the ISC license.
|
|
140
140
|
* See the LICENSE file in the root directory of this source tree.
|
|
141
|
-
*/const Vs=s.createLucideIcon("
|
|
141
|
+
*/const Vs=s.createLucideIcon("Plug2",[["path",{d:"M9 2v6",key:"17ngun"}],["path",{d:"M15 2v6",key:"s7yy2p"}],["path",{d:"M12 17v5",key:"bb1du9"}],["path",{d:"M5 8h14",key:"pcz4l3"}],["path",{d:"M6 11V8h12v3a6 6 0 1 1-12 0Z",key:"wtfw2c"}]]);/**
|
|
142
142
|
* @license lucide-react v0.453.0 - ISC
|
|
143
143
|
*
|
|
144
144
|
* This source code is licensed under the ISC license.
|
|
145
145
|
* See the LICENSE file in the root directory of this source tree.
|
|
146
|
-
*/const Rs=s.createLucideIcon("
|
|
146
|
+
*/const Rs=s.createLucideIcon("RefreshCw",[["path",{d:"M3 12a9 9 0 0 1 9-9 9.75 9.75 0 0 1 6.74 2.74L21 8",key:"v9h5vc"}],["path",{d:"M21 3v5h-5",key:"1q7to0"}],["path",{d:"M21 12a9 9 0 0 1-9 9 9.75 9.75 0 0 1-6.74-2.74L3 16",key:"3uifl3"}],["path",{d:"M8 16H3v5",key:"1cv678"}]]);/**
|
|
147
147
|
* @license lucide-react v0.453.0 - ISC
|
|
148
148
|
*
|
|
149
149
|
* This source code is licensed under the ISC license.
|
|
150
150
|
* See the LICENSE file in the root directory of this source tree.
|
|
151
|
-
*/const
|
|
151
|
+
*/const qs=s.createLucideIcon("Save",[["path",{d:"M15.2 3a2 2 0 0 1 1.4.6l3.8 3.8a2 2 0 0 1 .6 1.4V19a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2z",key:"1c8476"}],["path",{d:"M17 21v-7a1 1 0 0 0-1-1H8a1 1 0 0 0-1 1v7",key:"1ydtos"}],["path",{d:"M7 3v4a1 1 0 0 0 1 1h7",key:"t51u73"}]]);/**
|
|
152
152
|
* @license lucide-react v0.453.0 - ISC
|
|
153
153
|
*
|
|
154
154
|
* This source code is licensed under the ISC license.
|
|
155
155
|
* See the LICENSE file in the root directory of this source tree.
|
|
156
|
-
*/const
|
|
156
|
+
*/const Qe=s.createLucideIcon("Shapes",[["path",{d:"M8.3 10a.7.7 0 0 1-.626-1.079L11.4 3a.7.7 0 0 1 1.198-.043L16.3 8.9a.7.7 0 0 1-.572 1.1Z",key:"1bo67w"}],["rect",{x:"3",y:"14",width:"7",height:"7",rx:"1",key:"1bkyp8"}],["circle",{cx:"17.5",cy:"17.5",r:"3.5",key:"w3z12y"}]]);/**
|
|
157
157
|
* @license lucide-react v0.453.0 - ISC
|
|
158
158
|
*
|
|
159
159
|
* This source code is licensed under the ISC license.
|
|
160
160
|
* See the LICENSE file in the root directory of this source tree.
|
|
161
|
-
*/const Bs=s.createLucideIcon("
|
|
161
|
+
*/const Bs=s.createLucideIcon("ShieldQuestion",[["path",{d:"M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z",key:"oel41y"}],["path",{d:"M9.1 9a3 3 0 0 1 5.82 1c0 2-3 3-3 3",key:"mhlwft"}],["path",{d:"M12 17h.01",key:"p32p05"}]]);/**
|
|
162
162
|
* @license lucide-react v0.453.0 - ISC
|
|
163
163
|
*
|
|
164
164
|
* This source code is licensed under the ISC license.
|
|
165
165
|
* See the LICENSE file in the root directory of this source tree.
|
|
166
|
-
*/const _s=s.createLucideIcon("
|
|
166
|
+
*/const _s=s.createLucideIcon("Sigma",[["path",{d:"M18 7V5a1 1 0 0 0-1-1H6.5a.5.5 0 0 0-.4.8l4.5 6a2 2 0 0 1 0 2.4l-4.5 6a.5.5 0 0 0 .4.8H17a1 1 0 0 0 1-1v-2",key:"wuwx1p"}]]);/**
|
|
167
167
|
* @license lucide-react v0.453.0 - ISC
|
|
168
168
|
*
|
|
169
169
|
* This source code is licensed under the ISC license.
|
|
@@ -188,5 +188,5 @@
|
|
|
188
188
|
*
|
|
189
189
|
* This source code is licensed under the ISC license.
|
|
190
190
|
* See the LICENSE file in the root directory of this source tree.
|
|
191
|
-
*/const De=s.createLucideIcon("Type",[["polyline",{points:"4 7 4 4 20 4 20 7",key:"1nosan"}],["line",{x1:"9",x2:"15",y1:"20",y2:"20",key:"swin9y"}],["line",{x1:"12",x2:"12",y1:"4",y2:"20",key:"1tx1rr"}]]);function Ie(t){var n;return{...t,sheets:(n=t==null?void 0:t.sheets)==null?void 0:n.map(a=>{var r;return{...a,frames:(r=a.frames)==null?void 0:r.map(o=>{var i;return{...o,cards:(i=o.cards)==null?void 0:i.map(l=>Je(l))}})}})}}function Je(t){var n,a,r,o;return{...t,cfg:{...t.cfg,data:{...(n=t.cfg)==null?void 0:n.data,labels:[],datasets:(o=(r=(a=t.cfg)==null?void 0:a.data)==null?void 0:r.datasets)==null?void 0:o.map(i=>({...i,data:[]}))}},customCfg:Us(t.customCfg),data:[]}}function Us(t){var n,a;return t?{...t,data:{...t==null?void 0:t.data,labels:[],datasets:(a=(n=t==null?void 0:t.data)==null?void 0:n.datasets)==null?void 0:a.map(r=>({...r,data:[]}))}}:null}async function $s(t,n,a,r){if(!r)return null;const o=JSON.stringify(n);return await s.postRequest("https://semaphor.cloud/api/v1/lens",r,{name:t,template:o,filterValues:a,operation:"create"})}async function Ce(t,n){if(!n)return null;const{id:a,template:r,filterValues:o,isDefault:i,shared:l}=t;return await s.postRequest("https://semaphor.cloud/api/v1/lens",n,{lensId:a,template:r,filterValues:o,isDefault:i,shared:l,operation:"update"})}async function Qs(t,n){return n?await s.postRequest("https://semaphor.cloud/api/v1/lens",n,{operation:"delete",lensId:t}):null}function Js(){const[t,n]=y.useState(""),[a,r]=y.useState(!1),o=s.useDashboardStore(f=>f.lenses),{setLenses:i,setSelectedLensId:l}=s.useDashboardActions(),[c,d]=y.useState(!1),[h,x]=y.useState(!1),j=s.useDashboardStore(f=>f.dashboard),b=s.useDashboardStore(f=>f.filterValues),{authToken:u}=s.useSemaphorContext();async function p(){d(!0);const f=Ie(j),w=await $s(t,f,b,u==null?void 0:u.accessToken);w&&(i([...o||[],w]),l(w.id),x(!1)),d(!1)}return e.jsxs(s.Dialog,{open:h,onOpenChange:x,children:[e.jsx(s.DialogTrigger,{asChild:!0,children:e.jsxs(s.Button,{variant:"secondary",className:"h-7 p-2",size:"sm",children:[e.jsx(s.Plus,{className:"mr-2 h-4 w-4",strokeWidth:1.5}),"Lens"]})}),e.jsxs(s.DialogContent,{className:"sm:max-w-[425px]",children:[e.jsxs(s.DialogHeader,{children:[e.jsx(s.DialogTitle,{children:"Create Lens"}),e.jsx(s.DialogDescription,{children:"Lenses are private by default and are only visible to you."})]}),e.jsx("div",{className:"grid gap-4 py-4",children:e.jsxs("div",{className:"grid grid-cols-8 items-center gap-4",children:[e.jsx(s.Label,{className:"text-right",children:"Name"}),e.jsx(s.Input,{value:t,onChange:f=>{n(f.target.value)},id:"name",className:"col-span-7 focus-visible:ring-0 focus-visible:ring-ring focus-visible:ring-offset-0"})]})}),a&&e.jsx("p",{className:"text-sm",children:"The lens name already exists. Use a differnet name."}),e.jsx(s.DialogFooter,{children:e.jsx(s.Button,{size:"sm",variant:"outline",type:"submit",onClick:p,disabled:c,children:c?"Creating...":"Add"})})]})]})}function Ws(){const[t,n]=y.useState(!1),a=s.useDashboardStore(x=>x.lenses),r=s.useDashboardStore(x=>x.selectedLensId),{setLenses:o,setSelectedLensId:i}=s.useDashboardActions(),{authToken:l}=s.useSemaphorContext();async function c(x){i(x)}async function d(x){if(await Qs(x,l==null?void 0:l.accessToken)){const b=a==null?void 0:a.filter(u=>u.id!==x);o(b||[]),i("original")}}async function h(x){const j=a==null?void 0:a.map(p=>p.id===x.id?{...p,isDefault:!x.isDefault}:{...p,isDefault:!1});o(j||[]);const b={...x,isDefault:!x.isDefault};await Ce(b,l==null?void 0:l.accessToken);const u=a==null?void 0:a.find(p=>p.isDefault);if(u&&u.id!==x.id){const p={...u,isDefault:!1};await Ce(p,l==null?void 0:l.accessToken)}}return e.jsxs(s.DropdownMenu,{open:t,onOpenChange:n,children:[e.jsx(s.DropdownMenuTrigger,{asChild:!0,children:e.jsx(s.Button,{variant:"ghost",className:"h-7 p-2",children:e.jsx(Es,{className:"h-4 w-4",strokeWidth:1.5})})}),e.jsxs(s.DropdownMenuContent,{align:"end",className:"w-60",children:[e.jsx(s.DropdownMenuLabel,{className:"px-3",children:"Lenses"}),e.jsx(s.DropdownMenuSeparator,{}),e.jsxs(s.DropdownMenuRadioGroup,{value:r,onValueChange:c,children:[e.jsx(s.DropdownMenuRadioItem,{value:"original",children:"Original"}),a==null?void 0:a.map(x=>e.jsxs(s.DropdownMenuRadioItem,{className:"group flex justify-between gap-2",value:x.id,children:[e.jsx("p",{children:x.name}),e.jsxs("span",{className:"flex items-center gap-3",children:[e.jsx(Ts,{onClick:j=>{j.preventDefault(),h(x)},className:s.cn("size-3.5 text-muted-foreground hover:cursor-pointer hover:text-foreground group-hover:visible",{invisible:!x.isDefault,"text-green-500":x.isDefault}),strokeWidth:1.5}),e.jsx(s.Cross2Icon,{onClick:j=>{j.preventDefault(),d(x.id)},className:"invisible size-3.5 text-muted-foreground hover:cursor-pointer hover:text-foreground group-hover:visible",strokeWidth:1.5})]})]},x.id))]})]})]})}async function We(){var u;const t=s.useDashboardStore.getState().authToken,n=s.useDashboardStore.getState().theme,a=s.useDashboardStore.getState().filterValues,r=(u=s.useDashboardStore.getState().dashboard)==null?void 0:u.title,o=s.useDashboardStore.getState().isDownloadingPdf,i=s.useDashboardStore.getState().selectedSheetId;if(o)return;const l=new URLSearchParams;l.set("token",(t==null?void 0:t.accessToken)||""),l.set("theme",n||"light"),l.set("filterValues",JSON.stringify(a)),l.set("selectedSheetId",i||"");const c=`https://semaphor.cloud/api/v1/generate-pdf?params=${encodeURIComponent(l.toString())}`;s.useDashboardStore.setState({isDownloadingPdf:!0});const x=(await(await fetch(c,{method:"GET",headers:{Authorization:`Bearer ${t==null?void 0:t.accessToken}`}})).json()).url,j=document.createElement("a");j.href=x;const b=`${r}-${new Date().toISOString()}.pdf`;j.download=b,j.click(),s.useDashboardStore.setState({isDownloadingPdf:!1})}function Ks({iconClassName:t}){const{authToken:n}=s.useSemaphorContext();s.useDashboardStore(o=>{var i;return(i=o.dashboard)==null?void 0:i.title}),s.useDashboardStore(o=>o.theme),s.useDashboardStore(o=>o.filterValues);const a=s.useDashboardStore(o=>o.isDownloadingPdf);async function r(){await We()}return e.jsx(s.Button,{variant:"link",className:"group h-7 p-2",size:"sm",onClick:r,children:a?e.jsx(xe,{className:s.cn("size-3.5 animate-spin",t)}):e.jsx(s.Download,{className:s.cn("size-3.5",t),strokeWidth:1.5})})}function Zs(){const{authToken:t}=s.useSemaphorContext();s.useDashboardStore(m=>m.theme);const n=s.useDashboardStore(m=>m.lenses),a=s.useDashboardStore(m=>m.selectedLensId),r=n==null?void 0:n.find(m=>m.id===a),o=s.useDashboardStore(m=>m.dashboard);s.useDashboardStore(m=>m.selectedSheetId);const i=s.useDashboardStore(m=>m.isDashboardEditing),l=s.useEditorStore(m=>m.selectedConnectionId),[c,d]=y.useState(!1),h=s.useDashboardStore(m=>m.filterValues),x=s.useDashboardStore(m=>m.isVisualEditing),j=s.useDashboardStore(m=>m.showFilters);s.useDashboardStore(m=>m.showDashboardJSON);const b=s.useDashboardStore(m=>m.onSaveFunction),u=s.useDashboardStore(m=>m.actions.setShowFilters),{addFrame:p,setSelectedFrameId:f}=s.useDashboardStore(m=>m.actions),{getSelectedSheet:w,setIsDashboardEditing:S,setShowDashboardJSON:L}=s.useDashboardStore(m=>m.actions),N=w(),{tenantId:k,endUserId:A}=y.useMemo(()=>s.getTenantAndEndUserId(t==null?void 0:t.accessToken),[t==null?void 0:t.accessToken]),z=y.useMemo(()=>k||A,[k,A]),B=()=>{if(!i||!N)return;const m={connectionId:l,id:s.v4(),title:"Title",description:"Description",preferences:{onClickFilter:[{columnIndex:0,expression:""}]},type:"bar",sql:"select COUNT(*) from YOUR_TABLE",data:[]},g={id:s.v4(),cards:[m],activeCardId:m.id};p(N.id,g),f(g.id)},F=()=>{S(!0)};async function _(){if(d(!0),!a||!r)return;const m=Ie(o),g=JSON.stringify(m),D={...r,template:g,filterValues:h};await Ce(D,t==null?void 0:t.accessToken),s.ue.success("Lens saved"),b==null||b(m),d(!1)}return x?null:e.jsxs("div",{className:"flex items-center justify-between gap-2 border-b bg-muted/50 py-2 pl-3 pr-2",role:"dashboard-controls",children:[!x&&e.jsx("div",{className:"flex items-center gap-3",children:e.jsx(s.Label,{children:r==null?void 0:r.name})}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("button",{onClick:s.invalidateToken,children:e.jsx(Hs,{className:"h-4 w-4",strokeWidth:1.5})}),e.jsx(Ks,{}),i&&!x&&z&&e.jsx(Js,{}),!x&&z&&e.jsx(Ws,{}),i&&!x&&e.jsxs(s.Button,{variant:"secondary",className:"h-7 p-2",size:"sm",disabled:!i,onClick:B,children:[e.jsx(s.Plus,{className:"mr-2 h-4 w-4",strokeWidth:1.5}),"Frame"]}),!i&&e.jsx(s.Button,{variant:"ghost",className:"h-7 p-2",onClick:F,size:"sm",children:e.jsx(s.Pencil,{className:"h-4 w-4",strokeWidth:1.5})}),i&&!x&&e.jsx(s.Button,{variant:"ghost",role:"close",className:"h-7 p-2",onClick:()=>{S(!1),L(!1)},size:"sm",children:e.jsx(s.Cross2Icon,{className:"h-4 w-4",strokeWidth:1.5})}),i&&!x&&z&&e.jsx(s.Button,{className:"h-7 p-2",variant:"ghost",disabled:c,onClick:_,size:"sm",children:e.jsx(Rs,{className:"h-4 w-4",strokeWidth:1.5})}),!j&&!x&&i&&e.jsx(s.Button,{className:"h-7 p-2",variant:"ghost",onClick:()=>u(!0),size:"sm",children:e.jsx(s.Filter,{className:"h-4 w-4",strokeWidth:1.5})}),!x&&i&&!1,!x&&!1]})]})}function de({title:t,items:n,value:a,isLoading:r,isError:o,refetch:i,connectionTooltip:l,onChange:c,showNone:d=!1,className:h,showIcon:x=!0,disabled:j=!1}){const b=r?"Loading...":o?"Error":a;function u(){if(t==="Connection")return e.jsx(Fs,{className:"size-4 rotate-90"});if(t==="Database")return e.jsx(Cs,{className:"size-4"});if(t==="Schema")return e.jsx(Ms,{className:"size-4"});if(t==="Table")return e.jsx(Ee,{className:"size-4"});if(t==="Model")return e.jsx(js,{className:"size-4"})}return e.jsxs("div",{className:"flex items-center gap-2",children:[x&&e.jsx("div",{className:"shrink-0",children:l?e.jsxs(s.Tooltip,{children:[e.jsx(s.TooltipTrigger,{children:u()}),e.jsx(s.TooltipContent,{className:"text-xs",align:"start",children:l})]}):u()}),e.jsxs(s.Select,{disabled:j,value:b,onValueChange:c,children:[e.jsx(s.SelectTrigger,{className:s.cn("h-9 w-full focus:ring-1 focus:ring-offset-0",h),children:e.jsx(s.SelectValue,{placeholder:r?"Loading...":o?"Error":`Select ${t}`})}),e.jsx(s.SelectContent,{children:e.jsxs(s.SelectGroup,{children:[r?e.jsx(s.SelectLabel,{children:"Loading..."}):e.jsxs(s.SelectLabel,{className:"flex items-center justify-between gap-2",children:[t,e.jsx(Vs,{className:"mr-1 size-3 cursor-pointer text-muted-foreground hover:text-foreground",onClick:i})]}),e.jsxs(e.Fragment,{children:[d&&e.jsx(s.SelectItem,{value:"none",children:"None"},"none"),n&&n.map((p,f)=>e.jsx(s.SelectItem,{value:p.id,children:p.name},f))]}),(r||o)&&e.jsx(s.SelectItem,{value:b,children:b})]})})]})]})}function Xs({column:t}){const[n,a]=y.useState(!1),r=s.useEditorStore(p=>p.selectedTableName),o=s.useEditorStore(p=>p.selectedSchemaName),i=s.useEditorStore(p=>p.selectedDatamodelId),l=s.useEditorStore(p=>p.sqlGen),{modelItems:c,connectionType:d}=ne(),h=s.useEditorStore(p=>p.actions.setSqlGen),x=s.useEditorStore(p=>p.actions.setCardSql),j=s.useEditorStore(p=>p.actions.setRunSql);function b(p,f){var N;const w=s.createSqlGenConfig(p,l,f),S=(N=c==null?void 0:c.find(k=>k.id===i))==null?void 0:N.name;h(w);const L=s.getSql(w,s.fmt(o||""),s.fmt(r),S,d);L&&(x(L),j(!0)),a(!1)}function u(){return e.jsxs("ul",{className:"text-xs",children:[e.jsx("li",{onClick:()=>b(t,"COUNT"),className:"cursor-pointer p-1 px-3 transition-colors hover:bg-muted",children:"Count"}),e.jsx("li",{onClick:()=>b(t,"AVG"),className:"cursor-pointer p-1 px-3 transition-colors hover:bg-muted",children:"Avg"}),e.jsx("li",{onClick:()=>b(t,"SUM"),className:"cursor-pointer p-1 px-3 transition-colors hover:bg-muted",children:"Sum"}),e.jsx("li",{onClick:()=>b(t,"MAX"),className:"cursor-pointer p-1 px-3 transition-colors hover:bg-muted",children:"Max"}),e.jsx("li",{onClick:()=>b(t,"MIN"),className:"cursor-pointer p-1 px-3 transition-colors hover:bg-muted",children:"Min"})]})}return e.jsxs(s.HoverCard,{openDelay:0,open:n,onOpenChange:a,children:[e.jsx(s.HoverCardTrigger,{asChild:!0,children:e.jsx(ke,{className:"invisible size-3.5 cursor-pointer text-foreground/40 group-hover:visible"})}),e.jsx(s.HoverCardContent,{align:"center",className:"w-20 rounded-md p-0 shadow-none",children:u()})]})}function Ke({column:t}){return e.jsxs(s.Tooltip,{children:[e.jsx(s.TooltipTrigger$1,{asChild:!0,children:s.isTextDataType(t.data_type)?e.jsx(De,{className:"size-3"}):s.isNumberDataType(t.data_type)?e.jsx(Is,{className:"size-3"}):s.isDateDataType(t.data_type)?e.jsx(s.Calendar,{className:"size-3"}):s.isBooleanDataType(t.data_type)?e.jsx(Gs,{className:"size-3"}):t.data_type.toLowerCase()==="json"?e.jsx(bs,{className:"size-3"}):e.jsx(qs,{className:"size-3"})}),e.jsx(s.TooltipContent,{children:e.jsx("p",{className:"font-mono text-xs",children:t.data_type})})]})}function Ys({schemaName:t,tableName:n,columns:a,status:r}){const o=s.useEditorStore(m=>m.sqlGen),i=s.useEditorStore(m=>m.selectedConnectionId),l=s.useEditorStore(m=>m.selectedDatabaseName),c=s.useEditorStore(m=>m.selectedSchemaName),d=s.useEditorStore(m=>m.selectedTableName),h=s.useEditorStore(m=>m.selectedDatamodelId),x=s.useDashboardStore(m=>m.dashboard.aiScopeTables),{addToAIScope:j,removeFromAIScope:b}=s.useDashboardActions(),{setAIScopeTables:u}=s.useDashboardStore(m=>m.actions),p=s.useEditorStore(m=>m.actions.setRunSql),f=s.useEditorStore(m=>m.actions.setSqlGen),w=s.useEditorStore(m=>m.actions.setIsShowingVisual),S=s.useEditorStore(m=>m.actions.setCardSql),{connectionType:L,modelItems:N,selectedDatamodelName:k}=ne();function A(m){var O;const g=s.createSqlGenConfig(m,o);f(g);const D=(O=N==null?void 0:N.find(q=>q.id===h))==null?void 0:O.name,v=s.getSql(g,s.fmt(t),s.fmt(n),D,L);v&&(S(v),p(!0))}function z(){return(x==null?void 0:x.find(m=>m.connectionId===i&&(m.tableName===d||m.datamodelName===k)))!==void 0}function B(m){m===!0&&(d||k)&&i?(j({connectionId:i,connectionType:L==="S3"||L==="API"?"DuckDb":L,databaseName:l,schemaName:c,tableName:d,datamodelName:k}),s.ue.success("Added to Assistant Scope",{position:"top-right",duration:2500,richColors:!0})):(b({connectionId:i||"",connectionType:L||"",tableName:d||"",datamodelName:k||""}),s.ue("Removed from Assistant Scope",{position:"top-right",duration:2e3,richColors:!0}))}function F(){const m=s.getFormattedTableNameForQuery({schemaName:t,tableName:n,modelName:k,connectionType:L});w(!1);const g=L==="MSSQL"?`SELECT top 10 * FROM ${m}`:`SELECT * FROM ${m} LIMIT 10`;S(g),p(!0)}function _(){const m=s.getFormattedTableNameForQuery({schemaName:t,tableName:n,modelName:k,connectionType:L});S(`SELECT COUNT(*) as count FROM ${m}`),p(!0)}return e.jsxs("div",{className:"flex grow flex-col space-y-4 px-4",children:[e.jsxs("div",{className:"mx-2 flex items-center justify-center gap-2",children:[e.jsxs(s.Toggle,{title:`${z()?"Remove from":"Add to"} Assistant Scope`,pressed:z(),onPressedChange:B,variant:"outline",className:s.cn("h-9 px-2",{}),children:[e.jsx(s.Plus,{className:s.cn("mr-1 size-4",{"text-green-400":z(),"text-muted-foreground":!z()})}),"AI"]}),e.jsxs(s.Button,{disabled:r!=="Success",onClick:F,size:"sm",variant:"secondary",className:"flex",children:[r!=="Success"?e.jsx(xe,{className:"mr-2 h-4 w-4 animate-spin text-foreground/50"}):e.jsx(_s,{className:"mr-2 size-4"}),"Top 10"]}),e.jsxs(s.Button,{disabled:r!=="Success",onClick:_,size:"sm",variant:"secondary",className:"w-full",children:[r!=="Success"?e.jsx(xe,{className:"mr-2 h-4 w-4 animate-spin text-foreground/50"}):e.jsx(Bs,{className:"mr-2 size-4"}),"Count"]})]}),e.jsxs(s.ScrollArea,{className:"flex-1 basis-0 border-b border-t border-muted py-3",children:[e.jsx("div",{className:"flex flex-col gap-1",children:a==null?void 0:a.map(m=>e.jsxs("div",{onClick:()=>A(m),className:s.cn("group mx-3 flex cursor-pointer items-center justify-between rounded px-2 py-1 text-sm transition-colors hover:bg-muted/50",{"border border-dashed border-muted-foreground bg-muted":s.isColumnInSqlGen(m,o)}),children:[e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(Ke,{column:m}),e.jsx("span",{children:m.column_name})]}),e.jsx("div",{onClick:g=>g.stopPropagation(),className:"flex items-center justify-end",children:s.isNumberDataType(m.data_type)&&e.jsx(Xs,{column:m})})]},m.column_name))}),e.jsx(s.ScrollBar,{orientation:"vertical"}),e.jsx(s.ScrollBar,{orientation:"horizontal"})]})]})}function ne(t,n){var Le,Ae,ze,Oe,Me,Fe;let a=y.useMemo(()=>[],[]);const r=s.useSemaphorContext().authToken||t,o=s.useEditorStore(C=>C.selectedConnectionId),i=s.useEditorStore(C=>C.selectedDatamodelId),l=s.useEditorStore(C=>C.selectedDatabaseName),c=s.useEditorStore(C=>C.selectedSchemaName),d=s.useEditorStore(C=>C.selectedTableName),h=s.useEditorStore(C=>C.actions.setCurrentColumns),x=s.useEditorStore(C=>C.actions.setSelectedConnectionId),j=s.useEditorStore(C=>C.actions.setSelectedDatamodelId),b=s.useEditorStore(C=>C.actions.setSelectedDatabaseName),u=s.useEditorStore(C=>C.actions.setSelectedSchemaName),p=s.useEditorStore(C=>C.actions.setSelectedTableName);s.useEditorStore(C=>C.actions.setCardSql);function f(C){return o&&l&&c&&l!=="NA"?!0:o&&C==="API"?!1:!!(o&&C==="S3")}function w(C){return!!(o&&l&&l!=="NA"&&c&&d||o&&(C==="S3"||C==="API")||i&&i)}function S(C){return o&&C?!(C==="API"||C==="S3"):!1}const{refetch:L,data:N,isLoading:k,isError:A}=s.useQuery({queryKey:["connections"],queryFn:()=>s.getRequest("https://semaphor.cloud/api/v1/connections",(r==null?void 0:r.accessToken)||""),enabled:!!(r!=null&&r.accessToken)}),{refetch:z,data:B,isLoading:F,isError:_}=s.useQuery({queryKey:["models",o],queryFn:()=>s.getRequest("https://semaphor.cloud/api/v1/datamodels",(r==null?void 0:r.accessToken)||"",{connection_id:o}),enabled:!!(r!=null&&r.accessToken)&&!!o}),m=N==null?void 0:N.connections.find(C=>C.id===o),g=m==null?void 0:m.type,D=(m==null?void 0:m.type)==="API"||(m==null?void 0:m.type)==="S3",{data:v,isLoading:O,isFetching:q,isError:H,refetch:U}=s.useQuery({queryKey:["databases",o],queryFn:()=>s.getRequest("https://semaphor.cloud/api/v1/databases",(r==null?void 0:r.accessToken)||"",{connection_id:o}),enabled:S(g)}),{data:G,isLoading:W,isFetching:ee,isError:P,refetch:M}=s.useQuery({queryKey:["schemas",o,l],queryFn:()=>s.getRequest("https://semaphor.cloud/api/v1/schemas",(r==null?void 0:r.accessToken)||"",{connection_id:o,database_name:l}),enabled:!!o&&!!l&&!D&&l!=="NA"}),{data:T,isLoading:K,isFetching:Q,isError:X,refetch:Z}=s.useQuery({queryKey:["tables",o,l,c],queryFn:()=>s.getRequest("https://semaphor.cloud/api/v1/tables",(r==null?void 0:r.accessToken)||"",{connection_id:o,database_name:l,schema_name:c}),enabled:f(g)}),{data:$,isLoading:E,isFetching:V,isError:R,refetch:J}=s.useQuery({queryKey:["columns",o,l,i,c,d],queryFn:()=>s.getRequest("https://semaphor.cloud/api/v1/columns",(r==null?void 0:r.accessToken)||"",{connection_id:o,datamodel_id:i||"",database_name:l,schema_name:c,table_name:d}),enabled:w(g)});y.useEffect(()=>{h(a)},[$,h,a]),y.useEffect(()=>{(g==="S3"||g==="API")&&(b(""),u(""),j(""),g==="API"&&p("api"))},[g,p,b,u,j]);const le=(m==null?void 0:m.type)==="API"?(Le=m==null?void 0:m.type)==null?void 0:Le.toLowerCase():d||"",ce=D?"":c||"";function re(C){u(C),p("")}function I(C){b(C==="none"?"":C),u(""),p(""),C!=="none"&&C!==""&&j("")}function Y(C){x(C)}function oe(C){j(C==="none"?"":C),C!=="none"&&C!==""&&b("")}v&&((Ae=v==null?void 0:v.databases)==null?void 0:Ae.length)>0,G&&((ze=G==null?void 0:G.schemas)==null?void 0:ze.length)>0,$&&((Oe=$==null?void 0:$.columns)==null?void 0:Oe.length)>0&&(a=$.columns.map(C=>({...C,data_type:C.data_type.toLowerCase()}))),H&&(a=[]),(R||A)&&(a=[]);const se=N==null?void 0:N.connections.map(C=>({id:C.id,name:C.name,type:C.type})),he=(Me=B==null?void 0:B.datamodels)==null?void 0:Me.map(C=>({id:C.id,name:C.name})),ye=v==null?void 0:v.databases.map(C=>({id:C.database_name,name:C.database_name})),pe=G==null?void 0:G.schemas.map(C=>({id:C.schema_name,name:C.schema_name})),ve=T==null?void 0:T.tables.map(C=>({id:C.table_name,name:C.table_name})),fs=(Fe=B==null?void 0:B.datamodels.find(C=>C.id===i))==null?void 0:Fe.name;return{connectionItems:se,isConnectionsLoading:k,isConnectionsError:A,modelItems:he,selectedDatamodelId:i,selectedDatamodelName:fs,isModelsLoading:F,isModelsError:_,databaseItems:ye,isDatabasesLoadingOrFetching:O||q,isDatabaseError:H,schemaItems:pe,isSchemaLoadingOrFetching:W||ee,isSchemaError:P,tableItems:ve,isTableLoadingOrFetching:K||Q,isTableError:X,columns:a,isColumnsLoadingOrFetching:E||V,isColumnsError:R,isNonDbConnection:D,connectionType:g,tableName:le,schemaName:ce,refetchConnections:L,refetchModels:z,refetchDatabases:U,refetchSchemas:M,refetchTables:Z,refetchColumns:J,handleConnectionChange:Y,handleDatamodelChange:oe,handleDatabaseChange:I,handleSchemaChange:re}}function Ze({ColumnsComponent:t}){var V;const n=s.useEditorStore(R=>R.selectedConnectionId),a=s.useEditorStore(R=>R.selectedDatamodelId),r=s.useEditorStore(R=>R.selectedDatabaseName),o=s.useEditorStore(R=>R.selectedSchemaName),i=s.useEditorStore(R=>R.selectedTableName),l=s.useEditorStore(R=>R.actions.setSelectedTableName),{connectionItems:c,modelItems:d,schemaItems:h,databaseItems:x,tableItems:j,columns:b,isConnectionsLoading:u,isModelsLoading:p,isConnectionsError:f,isModelsError:w,isDatabasesLoadingOrFetching:S,isDatabaseError:L,isSchemaLoadingOrFetching:N,isSchemaError:k,isColumnsError:A,isColumnsLoadingOrFetching:z,isTableLoadingOrFetching:B,isTableError:F,connectionType:_,isNonDbConnection:m,refetchDatabases:g,refetchModels:D,refetchSchemas:v,refetchTables:O,refetchColumns:q,refetchConnections:H,handleConnectionChange:U,handleDatabaseChange:G,handleSchemaChange:W,handleDatamodelChange:ee,tableName:P,schemaName:M}=ne();function T(){return t?t(M,P,b):e.jsx(Ys,{schemaName:M,tableName:P,columns:b,status:z?"Loading...":A?"Error":"Success"})}function K(){window.location.href="mailto:support@semaphor.cloud?subject=Help&body=I need help with..."}function Q(){if(!n||_==="S3"||_==="API")return null;if(!a||a==="none")return e.jsx(de,{refetch:g,showNone:!0,onChange:G,isError:L,isLoading:S,items:x,value:r||"",title:"Database"})}function X(){if(n&&!m&&(!r||r==="none")&&(!a||a==="none"))return e.jsxs("div",{className:"grid grid-cols-3",children:[e.jsx("div",{className:"col-span-1 grid place-items-center",children:e.jsx(s.Separator,{})}),e.jsx("div",{className:"col-span-1 grid place-items-center",children:e.jsx(s.Label,{children:"OR"})}),e.jsx("div",{className:"col-span-1 grid place-items-center",children:e.jsx(s.Separator,{})})]})}function Z(){if(!n||_==="S3"||_==="API")return null;if(!r||r==="none")return e.jsx(de,{refetch:D,showNone:!0,onChange:ee,isError:w,isLoading:p,items:d,value:a||"",title:"Model"})}function $(){return!n||_==="S3"||_==="API"||!r||r==="none"?null:e.jsx(de,{refetch:v,onChange:W,isError:k,isLoading:N,items:h,value:o||"",title:"Schema"})}function E(){function R(){let J=!1;return _==="API"?(J=!1,J):((_==="S3"||n&&r&&r!=="none"&&o)&&(J=!0),J)}return R()?e.jsx(de,{refetch:O,onChange:l,isError:F,items:j,isLoading:B,value:i||"",title:"Table"}):null}return e.jsxs("aside",{className:"flex grow flex-col justify-between",children:[e.jsxs("section",{className:"space-y-3 px-6 py-4",children:[e.jsx(de,{refetch:H,items:c,title:"Connection",value:n||"",onChange:U,isLoading:u,isError:f,connectionTooltip:((V=c==null?void 0:c.find(R=>R.id===n))==null?void 0:V.type)||""}),Q(),X(),Z(),$(),E()]}),T(),e.jsx("div",{className:"flex items-end justify-center gap-2 px-6 py-4",children:e.jsxs(s.Button,{onClick:K,size:"sm",variant:"secondary",className:"w-full",children:[e.jsx(Os,{className:"mr-2 size-4"}),"Help"]})})]})}function et(t){const n=t.toUpperCase().indexOf("WHERE"),a=t.toUpperCase().indexOf("GROUP BY"),r=t.toUpperCase().indexOf("LIMIT"),o=t.toUpperCase().indexOf("ORDER BY");let i=t.length;if(o!==-1&&(i=o),r!==-1&&r<i&&(i=r),n!==-1){const l=t.substring(0,n),c=t.substring(n);return`${l} {{ filters | where }} AND ${c.substring(6)}`}else if(a!==-1){const l=t.substring(0,a),c=t.substring(a);return`${l} {{ filters | where }} ${c}`}else{const l=t.substring(0,i),c=t.substring(i);return console.log("beforeClause",l),console.log("afterClause",c),c?`${l} {{ filters | where }} ${c}`:`${l.replace(/;$/,"")} {{ filters | where }}`}}function st({error:t,setShowAIDialog:n,setUserInputforAI:a,setTriggerAIRun:r}){return e.jsxs(s.HoverCard,{openDelay:0,children:[e.jsx(s.HoverCardTrigger,{asChild:!0,children:e.jsx(s.Button,{variant:"link",className:"h-5 p-0",children:e.jsx(ys,{className:"h-4 w-4 text-red-500"})})}),e.jsx(s.HoverCardContent,{align:"start",className:"w-full min-w-fit max-w-[700px]",children:e.jsx("div",{className:"flex justify-between space-x-4",children:e.jsxs("div",{className:"flex grow flex-col space-y-2",children:[e.jsx(s.ScrollArea,{className:"max-h-[250px] min-h-0 overflow-scroll",children:e.jsx("p",{className:"overflow-auto rounded-md bg-muted p-2 text-xs leading-relaxed",children:t})}),e.jsxs(s.Button,{onClick:()=>{n(!0),a(t),r(!0)},size:"sm",variant:"outline",children:[e.jsx(Ds,{className:"mr-2 h-4 w-4"}),"Debug with AI"]})]})})})]})}function tt({userInput:t,triggerAIRun:n,setTriggerAIRun:a,open:r,setOpen:o}){const i=y.useRef(null),l=y.useRef(null),[c,d]=y.useState([]),[h,x]=y.useState(""),[j,b]=y.useState(null),{authToken:u}=s.useSemaphorContext(),p=s.useEditorStore(E=>{var V;return(V=E==null?void 0:E.card)==null?void 0:V.sql}),f=s.useEditorStore(E=>{var V;return(V=E==null?void 0:E.card)==null?void 0:V.python}),w=s.useEditorStore(E=>E.actions.setCardSql),S=s.useEditorStore(E=>E.actions.setRunSql),L=s.useEditorStore(E=>E.actions.switchCardType),N=s.useEditorStore(E=>E.selectedDatabaseName),k=s.useEditorStore(E=>E.selectedTableName),A=s.useEditorStore(E=>E.selectedConnectionId),z=s.useEditorStore(E=>E.selectedSchemaName),B=s.useDashboardStore(E=>E.dashboard.aiScopeTables),{selectedDatamodelName:F,connectionType:_}=ne(),{messages:m,setMessages:g,reload:D,append:v,input:O,status:q,handleInputChange:H,handleSubmit:U,stop:G}=s.useChat({api:"https://semaphor.cloud/api/v1/assistant",headers:{Authorization:`Bearer ${u==null?void 0:u.accessToken}`},body:{random:Math.random()},maxSteps:10,onToolCall:M,onFinish(E,V){ee(V.usage),x(""),console.log("onFinish",E,V),V.finishReason==="stop"&&x("")}});y.useEffect(()=>{n&&t&&(H({target:{value:t}}),setTimeout(()=>{U(),a(!1)},100))},[n,U,t,a,H]);const W=y.useRef(r);y.useEffect(()=>{const E=W.current?"smooth":"auto";W.current=r;const V=setTimeout(()=>{var R;l.current&&(l.current.scroll({top:l.current.scrollHeight,behavior:E}),(R=i.current)==null||R.focus())},50);return()=>clearTimeout(V)},[m,r]);function ee(E){b(V=>V?{promptTokens:V.promptTokens+E.promptTokens,completionTokens:V.completionTokens+E.completionTokens,totalTokens:V.totalTokens+E.totalTokens}:E)}function P(E){const V=s.removeFromScopeArray(c,E);K(V)}async function M({toolCall:E}){if(E.toolName==="createChart"){console.log("createChart",E.args);const V=E.args.sql,R=E.args.chartType;return L(R),w(V),S(!0),{status:"success",message:"Let the user know that chart is created"}}else if(E.toolName==="getTableColumns")x("Getting table columns...");else{if(E.toolName==="getUserSql")return p?(console.log("cardSql",p),console.log("cardPython",f),{status:"success",sql:p,python:f||""}):{status:"error",message:"No SQL found"};x("Thinking...")}}function T(E){return E.map(R=>({...R,connectionType:R.connectionType==="API"||R.connectionType==="S3"?"DuckDb":R.connectionType}))}function K(E){const V=T(E);d(V),g(R=>[...R,{id:crypto.randomUUID(),role:"system",content:`Current scope of tables | ${JSON.stringify(V)}`}])}function Q(){const E={databaseName:N||"",schemaName:z||"",tableName:k||"",datamodelName:F||"",connectionId:A||"",connectionType:_||""},V=s.dedup([...c,E]);K(V)}function X(){const E={databaseName:N||"",schemaName:z||"",tableName:k||"",datamodelName:F||"",connectionId:A||"",connectionType:_||""},V=s.isInAiScopeArray([...B||[],...c],E);if(console.log("isInScope",V),!V||c.length===0){const R=s.dedup([...B||[],...c,E]).filter(J=>J.connectionId===E.connectionId);K(R)}}function Z(E){o(!1),w(E),S(!0)}const $=!["ready","error"].includes(q);return{messages:m,setMessages:g,reload:D,append:v,input:O,isLoading:$,handleRun:Z,handleOpenDialogAndSetScope:X,handleAddCurrentTableToScope:Q,removeFromCurrentSelections:P,currentScope:c,setCurrentScope:d,containerRef:l,inputRef:i,handleInputChange:H,handleSubmit:U,stop:G,chatStatus:q,toolStatus:h,llmUsage:j}}const at=!1;function nt({open:t,setOpen:n,userInput:a,triggerAIRun:r,setTriggerAIRun:o}){const[i,l]=y.useState(!1),[c,d]=y.useState(at),[h,x]=y.useState(!1),{messages:j,setMessages:b,reload:u,input:p,isLoading:f,handleRun:w,handleOpenDialogAndSetScope:S,handleAddCurrentTableToScope:L,removeFromCurrentSelections:N,currentScope:k,setCurrentScope:A,containerRef:z,inputRef:B,handleInputChange:F,handleSubmit:_,stop:m,chatStatus:g,toolStatus:D,llmUsage:v}=tt({userInput:a,triggerAIRun:r,setTriggerAIRun:o,open:t,setOpen:n});function O(){return e.jsxs(s.DropdownMenu,{children:[e.jsx(s.DropdownMenuTrigger,{children:e.jsx(ke,{className:"size-3.5 text-muted-foreground/70 hover:text-muted-foreground"})}),e.jsxs(s.DropdownMenuContent,{align:"end",children:[e.jsx(s.DropdownMenuLabel,{children:"Options"}),e.jsx(s.DropdownMenuSeparator,{}),e.jsx(s.DropdownMenuCheckboxItem,{checked:i,onCheckedChange:l,children:"Token Usage"}),e.jsx(s.DropdownMenuCheckboxItem,{checked:c,onCheckedChange:d,children:"Tool Invocations"}),e.jsx(s.DropdownMenuCheckboxItem,{checked:h,onCheckedChange:x,children:"System Message"})]})]})}return e.jsxs(s.Dialog,{open:t,onOpenChange:n,children:[e.jsx(s.DialogTrigger,{asChild:!0,children:e.jsx(s.Button,{onClick:S,size:"sm",className:"w-full justify-start border font-normal text-muted-foreground focus-visible:ring-0 focus-visible:ring-offset-0",variant:"secondary",children:"Type your question..."})}),e.jsxs(s.DialogContent,{className:"flex flex-col justify-between overflow-auto sm:max-w-[425px] md:max-h-[625px] md:min-w-[625px]",children:[e.jsx(s.DialogHeader,{children:e.jsxs("div",{className:"flex items-start justify-between gap-2 pr-5",children:[e.jsxs("div",{children:[e.jsx(s.DialogTitle,{children:"Assistant"}),e.jsx(s.DialogDescription,{children:"What can I help you with?"}),k&&k.length>0&&e.jsxs("div",{className:"mt-2 flex flex-wrap items-center gap-2",children:[e.jsx("span",{className:"text-xs text-muted-foreground",children:"Tables in scope:"}),k==null?void 0:k.map((q,H)=>e.jsxs("div",{className:"flex items-center gap-2 rounded-md bg-muted px-2 py-1 text-xs",children:[s.getFormattedTableNameForQuery({schemaName:q.schemaName||"",tableName:q.tableName||"",modelName:q.datamodelName||"",connectionType:q.connectionType||""}),e.jsx("button",{onClick:()=>{N(q)},children:e.jsx(s.X,{className:"size-3 text-muted-foreground hover:text-foreground"})})]},H))]}),(k==null?void 0:k.length)===0&&e.jsxs("div",{className:"mt-2 flex items-center gap-2",children:[e.jsx("span",{className:"text-xs text-muted-foreground",children:"Tables in scope: None"}),e.jsxs(s.Button,{className:"h-6 text-xs",size:"sm",variant:"secondary",onClick:L,children:[e.jsx(s.Plus,{className:"mr-2 size-3"}),"Current Table"]})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[O(),e.jsx(s.Button,{className:"h-8",size:"sm",variant:"secondary",onClick:()=>{b([]),A([]),u()},children:"Clear"})]})]})}),e.jsx("div",{ref:z,className:"h-[625px] w-full overflow-auto border-t border-t-muted",children:e.jsxs("div",{className:"space-y-4 py-2 pr-3",role:"messages",children:[e.jsx(s.PrintMessages,{messages:j,showTools:c,handleRun:w,showSystemMessage:h}),e.jsx(s.ChatStatus,{status:s.getStatus(g,D),isLoading:f})]})}),e.jsx(s.ChatInput,{stop:m,ref:B,input:p,handleInputChange:F,handleSubmit:_,isLoading:f}),v&&i&&e.jsx("div",{className:"flex h-8 items-center justify-between",children:e.jsxs("div",{className:"text-xs text-muted-foreground",children:["Usage: ",v.promptTokens," prompt tokens,"," ",v.completionTokens," completion tokens,"," ",v.totalTokens," total tokens"]})})]})]})}var Xe={color:void 0,size:void 0,className:void 0,style:void 0,attr:void 0},Re=y.createContext&&y.createContext(Xe),rt=["attr","size","title"];function ot(t,n){if(t==null)return{};var a=it(t,n),r,o;if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(t);for(o=0;o<i.length;o++)r=i[o],!(n.indexOf(r)>=0)&&Object.prototype.propertyIsEnumerable.call(t,r)&&(a[r]=t[r])}return a}function it(t,n){if(t==null)return{};var a={};for(var r in t)if(Object.prototype.hasOwnProperty.call(t,r)){if(n.indexOf(r)>=0)continue;a[r]=t[r]}return a}function je(){return je=Object.assign?Object.assign.bind():function(t){for(var n=1;n<arguments.length;n++){var a=arguments[n];for(var r in a)Object.prototype.hasOwnProperty.call(a,r)&&(t[r]=a[r])}return t},je.apply(this,arguments)}function qe(t,n){var a=Object.keys(t);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(t);n&&(r=r.filter(function(o){return Object.getOwnPropertyDescriptor(t,o).enumerable})),a.push.apply(a,r)}return a}function be(t){for(var n=1;n<arguments.length;n++){var a=arguments[n]!=null?arguments[n]:{};n%2?qe(Object(a),!0).forEach(function(r){lt(t,r,a[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(a)):qe(Object(a)).forEach(function(r){Object.defineProperty(t,r,Object.getOwnPropertyDescriptor(a,r))})}return t}function lt(t,n,a){return n=ct(n),n in t?Object.defineProperty(t,n,{value:a,enumerable:!0,configurable:!0,writable:!0}):t[n]=a,t}function ct(t){var n=dt(t,"string");return typeof n=="symbol"?n:n+""}function dt(t,n){if(typeof t!="object"||!t)return t;var a=t[Symbol.toPrimitive];if(a!==void 0){var r=a.call(t,n);if(typeof r!="object")return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return(n==="string"?String:Number)(t)}function Ye(t){return t&&t.map((n,a)=>y.createElement(n.tag,be({key:a},n.attr),Ye(n.child)))}function te(t){return n=>y.createElement(ut,je({attr:be({},t.attr)},n),Ye(t.child))}function ut(t){var n=a=>{var{attr:r,size:o,title:i}=t,l=ot(t,rt),c=o||a.size||"1em",d;return a.className&&(d=a.className),t.className&&(d=(d?d+" ":"")+t.className),y.createElement("svg",je({stroke:"currentColor",fill:"currentColor",strokeWidth:"0"},a.attr,r,l,{className:d,style:be(be({color:t.color||a.color},a.style),t.style),height:c,width:c,xmlns:"http://www.w3.org/2000/svg"}),i&&y.createElement("title",null,i),t.children)};return Re!==void 0?y.createElement(Re.Consumer,null,a=>n(a)):n(Xe)}function ht(t){return te({attr:{viewBox:"0 0 448 512"},child:[{tag:"path",attr:{d:"M439.8 200.5c-7.7-30.9-22.3-54.2-53.4-54.2h-40.1v47.4c0 36.8-31.2 67.8-66.8 67.8H172.7c-29.2 0-53.4 25-53.4 54.3v101.8c0 29 25.2 46 53.4 54.3 33.8 9.9 66.3 11.7 106.8 0 26.9-7.8 53.4-23.5 53.4-54.3v-40.7H226.2v-13.6h160.2c31.1 0 42.6-21.7 53.4-54.2 11.2-33.5 10.7-65.7 0-108.6zM286.2 404c11.1 0 20.1 9.1 20.1 20.3 0 11.3-9 20.4-20.1 20.4-11 0-20.1-9.2-20.1-20.4.1-11.3 9.1-20.3 20.1-20.3zM167.8 248.1h106.8c29.7 0 53.4-24.5 53.4-54.3V91.9c0-29-24.4-50.7-53.4-55.6-35.8-5.9-74.7-5.6-106.8.1-45.2 8-53.4 24.7-53.4 55.6v40.7h106.9v13.6h-147c-31.1 0-58.3 18.7-66.8 54.2-9.8 40.7-10.2 66.1 0 108.6 7.6 31.6 25.7 54.2 56.8 54.2H101v-48.8c0-35.3 30.5-66.4 66.8-66.4zm-6.7-142.6c-11.1 0-20.1-9.1-20.1-20.3.1-11.3 9-20.4 20.1-20.4 11 0 20.1 9.2 20.1 20.4s-9 20.3-20.1 20.3z"},child:[]}]})(t)}function mt({sql:t}){return e.jsxs(s.HoverCard,{children:[e.jsx(s.HoverCardTrigger,{asChild:!0,children:e.jsx(s.Button,{variant:"link",className:"h-5 p-0",children:e.jsx(s.Info,{className:"h-4 w-4 text-muted-foreground"})})}),e.jsx(s.HoverCardContent,{align:"end",className:"w-full min-w-fit max-w-[700px] p-3 pt-2",children:e.jsxs("div",{className:"space-y-2",children:[e.jsx(s.Label,{className:"text-xs font-semibold",children:"Resolved Query"}),e.jsx("div",{className:"flex grow flex-col space-y-2",children:e.jsx(s.ScrollArea,{className:"max-h-[250px] min-h-0 overflow-scroll",children:e.jsx("p",{className:"overflow-auto rounded-md bg-muted p-2 font-mono text-xs leading-relaxed",children:t})})})]})})]})}function es(t){const{theme:n}=s.useTheme(),a=s.useDashboardStore(f=>f.theme),r=s.useEditorStore(f=>f.frame),o=s.useEditorStore(f=>f.card),i=s.useEditorStore(f=>f.activeTabCardId),l=s.Le(),{refetch:c}=s.useDashboardCardQuery(o),{updateCardTab:d,setRunSql:h}=s.useEditorActions(),x=y.useRef(),j=y.useRef({}),b=r.cards.find(f=>f.id===i),u=y.useCallback(()=>{let f="";return t==="python"&&(f=(b==null?void 0:b.python)||s.PYTHON_DEFAULT_CODE),t==="sql"&&(f=(b==null?void 0:b.sql)||""),f},[t,b]);y.useEffect(()=>{if(i&&o.id&&o.id!==i){if(x.current&&l){const f=x.current.getModel();f&&(j.current[o.id]=f);let w=j.current[i];if(!w){const S=u();w=l.editor.createModel(S,t),j.current[i]=w}x.current.setModel(w)}d(i,o),h(!0)}},[i,o,d,l,h,t,u]),y.useEffect(()=>{if(!l)return;const f=window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light",w=a==="system"?f:a;l.editor.defineTheme("default",{base:w==="light"?"vs":"vs-dark",inherit:!0,rules:[],colors:{"editor.background":w==="light"?"#ffffff":s.hslStringToHex("240 10% 10%")}}),l.editor.setTheme("default")},[n,a,l]),y.useEffect(()=>{const f=x.current;f&&l&&o&&f.addCommand(l.KeyMod.Shift|l.KeyCode.Enter,function(){return c(),!1})},[l,c,o]);function p(f,w){if(x.current=f,!j.current[o.id]){const S=f.getModel(),L=u();j.current[o.id]=S||(w==null?void 0:w.editor.createModel(L,t))||f.getModel()}f.setModel(j.current[o.id])}return{handleEditorDidMount:p}}function xt(){const t=s.useEditorStore(l=>l.card.sql),n=s.useEditorStore(l=>l.sqlGen),{setCardSql:a,setSqlGen:r}=s.useEditorActions(),{handleEditorDidMount:o}=es("sql");function i(l){a(l),s.isObjectEmpty(n)||r({})}return e.jsx(s.Ft,{theme:"default",className:"pt-3",onChange:i,value:t||"",options:{minimap:{enabled:!1},wordWrap:"on",scrollbar:{verticalScrollbarSize:0,horizontalScrollbarSize:0},fontSize:13,renderLineHighlight:"none"},defaultLanguage:"sql",onMount:o})}function pt(){const t=s.useEditorStore(o=>o.card.python),{setCardPython:n}=s.useEditorActions(),{handleEditorDidMount:a}=es("python");function r(o){n(o)}return e.jsx(s.Ft,{className:"pt-3",theme:"default",onChange:r,value:t||s.PYTHON_DEFAULT_CODE,options:{minimap:{enabled:!1},wordWrap:"on",scrollbar:{verticalScrollbarSize:0,horizontalScrollbarSize:0},fontSize:13,renderLineHighlight:"none"},defaultLanguage:"python",onMount:a})}function ft(){const t=s.useDashboardStore(i=>i.dashboard.filters),n=s.useDashboardStore(i=>i.filterValues),a=s.useDashboardStore(i=>i.selectedSheetId),r=t==null?void 0:t.filter(i=>i.sheetId===a||!i.sheetId),o=n==null?void 0:n.filter(i=>(r==null?void 0:r.some(l=>l.id===i.filterId))||i.filterId.endsWith(a));return e.jsx(s.Ft,{theme:"default",defaultLanguage:"json",className:"mt-1 min-h-[220px]",value:JSON.stringify(o,null,2),options:{readOnly:!0,minimap:{enabled:!1},lineNumbers:"off",glyphMargin:!1,wordWrap:"on",scrollbar:{verticalScrollbarSize:0,horizontalScrollbarSize:0},fontSize:12,renderLineHighlight:"none"}})}function gt(){var re;const[t,n]=y.useState({queryKey:[],queryData:null}),a=s.useQueryClient(),[r,o]=y.useState(!1),[i,l]=y.useState(!1),[c,d]=y.useState(!1),[h,x]=y.useState(""),[j,b]=y.useState(!1),u=s.useEditorStore(I=>I.frame),p=s.useEditorStore(I=>I.card),f=s.useEditorStore(I=>I.isShowingVisual),w=s.useEditorStore(I=>I.selectedConnectionId),S=s.useEditorStore(I=>I.selectedDatabaseName),L=s.useEditorStore(I=>I.selectedDatamodelId),N=s.useEditorStore(I=>I.selectedSchemaName),k=s.useEditorStore(I=>I.selectedTableName),A=s.useEditorStore(I=>{var Y;return(Y=I==null?void 0:I.card)==null?void 0:Y.sql}),z=s.useEditorStore(I=>I.applyFilters),{setCardCustomCfg:B,setQueryResultColumns:F,setCardSql:_,setPythonStdOut:m,setCardPreferences:g,setCardType:D,setCardPython:v}=s.useEditorActions(),O=s.useEditorStore(I=>I.onSave),q=s.useEditorStore(I=>I.onClose),H=s.useEditorStore(I=>I.actions.setSqlGen),U=s.useEditorStore(I=>I.runSql),G=s.useEditorStore(I=>I.actions.setRunSql),W=s.useEditorStore(I=>I.actions.setCardCfg),ee=s.useEditorStore(I=>I.actions.setIsSqlRunning),{data:P,isLoading:M,isFetching:T,isSuccess:K,isError:Q,error:X,queryKey:Z,refetch:$}=s.useDashboardCardQuery(p);y.useEffect(()=>{if(P&&(P.rowLimitExceeded&&s.ue.error("Row limit (10,000) exceeded. Refine your query.",{position:"top-center",richColors:!0}),m((P==null?void 0:P.output)||""),P.records.length>0)){const{dimensionKeys:I}=s.getKeys(P.records);F(I)}},[P,F,m]),y.useEffect(()=>{(M||T)&&ee(!0),(Q||K)&&ee(!1),Q&&(F([]),m(""))},[M,T,P,m,Q,K,ee,F,X]),y.useEffect(()=>{U&&(a.getQueryData(Z)||$(),G(!1))},[U,$,G,Z,a]);function E(){const I=a.getQueryData(Z);t.queryData||n({queryKey:Z,queryData:I}),a.setQueryData(Z,null),a.removeQueries({queryKey:Z,exact:!0}),_(""),H({}),v(""),W(void 0),B(""),g({}),D("bar")}function V(I,Y){if(I.length===0)return"";if(Y){const oe=I.find(se=>se.id===Y);if(oe){const se=oe.tabTitle;if(se=="All__Header")return I[0].id;if(se&&se.endsWith("__Header")){const ye=se.split("__")[0],pe=I.find(ve=>ve.tabTitle===ye);return pe?pe.id:I[0].id}return Y}}return I[0].id}function R(){let I=A;A&&!A.includes("{{")&&(I=et(A),_(I));const Y={...p,lastSelectedSchema:N,lastSelectedDatamodelId:L,lastSelectedDatabase:S,lastSelectedTable:k,connectionId:w,type:f?p.type:"table",sql:I,customCfg:f?p.customCfg:null},oe=u.cards.map(he=>he.id===p.id?Y:he),se={...u,cards:oe,activeCardId:V(oe,u.activeCardId)};O==null||O(se)}function J(){const{queryKey:I,queryData:Y}=t;I&&Y&&a.setQueryData(I,Y),H({}),q==null||q()}function le(){return e.jsxs(e.Fragment,{children:[i&&e.jsx("div",{className:"relative flex w-1/3 min-w-0 grow overflow-hidden border-l p-1 text-xs",role:"editor-filter-container",children:e.jsxs("div",{className:"w-[99%]",children:[e.jsxs("div",{className:"flex items-center gap-2 pt-3",children:[e.jsx(s.Label,{className:"ml-6 text-xs font-semibold",children:"Filters"}),i&&e.jsx(s.Cross2Icon,{onClick:()=>l(!1),className:"bg-background/50 text-foreground/50 hover:cursor-pointer hover:text-foreground"})]}),e.jsx(ft,{})]})}),!i&&e.jsx(s.Filter,{onClick:()=>l(!0),className:s.cn("absolute bottom-4 right-6 h-3 w-3 text-foreground/50 hover:cursor-pointer hover:text-foreground",{"font-bold text-red-800":z})})]})}function ce(){return e.jsxs(s.ResizablePanelGroup,{className:"flex grow pb-1",direction:"vertical",role:"editor-resizable-group",children:[e.jsxs(s.ResizablePanel,{id:"1",order:1,defaultSize:r?20:100,className:"relative flex grow",children:[e.jsx("div",{id:"sql-container",className:"relative flex w-[99%]",children:e.jsx(xt,{})}),r&&e.jsx("code",{className:"absolute right-6 top-3 text-xs text-muted-foreground/70",children:"sql"})]}),r&&e.jsxs(e.Fragment,{children:[e.jsx(s.ResizableHandle,{withHandle:!0,className:"border"}),e.jsxs(s.ResizablePanel,{id:"2",order:2,defaultSize:80,className:"relative flex grow",children:[e.jsx("div",{id:"python-container",className:"relative flex w-[99%] pt-0",children:e.jsx(pt,{})}),e.jsx("code",{className:"absolute right-6 top-3 text-xs text-muted-foreground/70",children:"python"})]})]})]})}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:[ce(),le()]}),e.jsxs("div",{role:"editor-controls",className:"item-center flex flex-wrap justify-between gap-2 px-6 py-4",children:[e.jsxs("div",{className:"flex grow items-center gap-2",children:[e.jsxs(s.Button,{title:"Shift + Enter",disabled:M||T,onClick:()=>{$()},className:"shrink-0",size:"sm",variant:"outline",children:[M||T?e.jsx(xe,{className:"mr-2 h-4 w-4 animate-spin text-foreground/50"}):e.jsx(s.Play,{className:"mr-2 h-4 w-4"}),"Run"]}),(Q||(P==null?void 0:P.error))&&e.jsx(st,{error:(X==null?void 0:X.message)||((re=P==null?void 0:P.error)==null?void 0:re.message),setShowAIDialog:d,setTriggerAIRun:b,setUserInputforAI:x}),e.jsxs(s.Button,{onClick:E,className:"",size:"sm",variant:"outline",children:[e.jsx(Ns,{className:"mr-2 size-4"}),"Clear"]}),e.jsx(s.Toggle,{pressed:r,onPressedChange:I=>o(I),className:"",size:"sm",variant:"outline",children:e.jsx(ht,{className:"size-4 text-foreground/70"})}),e.jsx(nt,{open:c,setOpen:d,userInput:h,triggerAIRun:j,setTriggerAIRun:b})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[(P==null?void 0:P.sql)&&e.jsx(mt,{sql:P.sql}),e.jsxs(s.Button,{onClick:J,className:"w-full",size:"sm",variant:"outline",children:[e.jsx(s.Cross2Icon,{className:"mr-2 size-4"}),"Close"]}),e.jsxs(s.Button,{onClick:R,size:"sm",variant:"outline",children:[e.jsx(s.Check,{className:"mr-2 size-4 font-bold text-green-600"}),"Accept"]})]})]})]})}function jt({data:t}){var l;const[n,a]=y.useState([]),o=Object.keys(t[0]).map(c=>({accessorKey:c,header:({column:d})=>{const h=d.getIsSorted();return e.jsx("div",{className:"flex gap-2",children:e.jsxs("div",{className:"flex cursor-pointer items-center",onClick:()=>d.toggleSorting(d.getIsSorted()==="asc"),children:[c,h==="asc"?e.jsx(s.TriangleUpIcon,{className:"ml-2 h-5 w-5"}):h==="desc"?e.jsx(s.TriangleDownIcon,{className:"ml-2 h-5 w-5"}):null]})})}})),i=s.useReactTable({data:t,columns:o,getCoreRowModel:s.getCoreRowModel(),getPaginationRowModel:s.getPaginationRowModel(),onSortingChange:a,getSortedRowModel:s.getSortedRowModel(),manualPagination:!0,state:{sorting:n}});return e.jsx("div",{className:"font-mono text-xs text-foreground/95",children:e.jsxs("table",{className:"w-full",children:[e.jsx(s.TableHeader,{children:i.getHeaderGroups().map(c=>e.jsx(s.TableRow,{children:c.headers.map(d=>e.jsx(s.TableHead,{className:"sticky top-0 h-11 bg-muted font-semibold",children:d.isPlaceholder?null:s.flexRender(d.column.columnDef.header,d.getContext())},d.id))},c.id))}),e.jsx(s.TableBody,{children:(l=i.getRowModel().rows)!=null&&l.length?i.getRowModel().rows.map(c=>e.jsx(s.TableRow,{className:"whitespace-nowrap py-2","data-state":c.getIsSelected()&&"selected",children:c.getVisibleCells().map(d=>e.jsx(s.TableCell,{className:"py-3",children:s.flexRender(d.column.columnDef.cell,d.getContext())},d.id))},c.id)):e.jsx(s.TableRow,{children:e.jsx(s.TableCell,{colSpan:o.length,className:"h-24 text-center",children:"No results."})})})]})})}function bt({card:t}){var L,N,k,A,z,B,F,_,m,g,D;const[n,a]=y.useState(!1),[r,o]=y.useState([]),{authToken:i}=s.useSemaphorContext(),l=s.getTokenParams(i==null?void 0:i.accessToken),c=s.useDashboardStore(v=>v.themeStyle),d={colors:((N=(L=c==null?void 0:c.chart)==null?void 0:L.dataset)==null?void 0:N.backgroundColor)||[]};(k=t.customCardPreferences)!=null&&k.inputData;const{getCard:h}=s.useCustomVisual(((A=t.customCardPreferences)==null?void 0:A.url)||""),x=((z=t.customCardPreferences)==null?void 0:z.visualType)||"single",j=s.useEditorStore(v=>v.frame),{setCustomCardPreferences:b}=s.useEditorActions(),{data:u}=s.useDashboardCardQuery(t),p=y.useCallback((v,O)=>{o(q=>({...q,[v]:O}))},[]);if(!((B=t.customCardPreferences)!=null&&B.componentName))return null;const f=h((F=t.customCardPreferences)==null?void 0:F.componentName);function w(v){a(v)}const S=Object.keys(((_=t.customCardPreferences)==null?void 0:_.dataInputCardIds)||{}).map(v=>{var H,U,G;const O=(U=(H=t.customCardPreferences)==null?void 0:H.dataInputCardIds)==null?void 0:U[v].cardId,q=(G=j==null?void 0:j.cards)==null?void 0:G.find(W=>W.id===O);return q||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(y.Suspense,{fallback:e.jsx(e.Fragment,{}),children:[f&&x==="single"&&e.jsx(f,{params:l,theme:d,settings:(m=t.customCardPreferences)==null?void 0:m.settings,onDataChange:p,data:(u==null?void 0:u.records)||[]}),f&&x==="multiple"&&e.jsxs(e.Fragment,{children:[Object.keys(((g=t.customCardPreferences)==null?void 0:g.dataInputCardIds)||{}).map(v=>{var H,U,G;const O=(U=(H=t.customCardPreferences)==null?void 0:H.dataInputCardIds)==null?void 0:U[v].cardId,q=(G=j==null?void 0:j.cards)==null?void 0:G.find(W=>W.id===O);if(q)return e.jsx(s.MultiInputEmptyRenderer,{onLoadingStatus:w,onDataChange:p,dataInputIndex:v,card:q},q.id+v)}),e.jsx("div",{className:"flex flex-col gap-2",children:e.jsx(f,{theme:d,onDataChange:p,settings:S.map(v=>{var O;return(O=v==null?void 0:v.customCardPreferences)==null?void 0:O.settings}),data:S.map(v=>v!=null&&v.id?r==null?void 0:r[v.id]:[])})})]})]},(D=t.customCardPreferences)==null?void 0:D.componentName)})}function ss({className:t,...n}){var w;const a=s.useEditorStore(S=>S.card),r=((w=a.customCardPreferences)==null?void 0:w.showCardHeader)??!0,o=s.useEditorStore(S=>S.frame),i=s.useDashboardStore(S=>S.dashboard.filters);s.useEditorStore(S=>S.actions.setRunSql);const{updateFilter:l}=s.useDashboardActions(),c=i==null?void 0:i.find(S=>S.id===o.filterId),{data:d,isLoading:h,isFetching:x}=s.useDashboardCardQuery(a),{setCard:j}=s.useEditorActions(),{data:b}=s.useTopoJson(a);if(!a.id)return null;let u;d!=null&&d.records&&(d==null?void 0:d.records.length)>0&&(u=s.createChartConfig({data:d==null?void 0:d.records,cardType:a.type,cfg:a.cfg,customCfg:a.customCfg,preferences:a.preferences,topoJson:b}));function p(S){return e.jsx(bt,{card:S})}function f(){var S;if(d!=null&&d.records&&(d==null?void 0:d.records.length)===0&&!h&&!x)return e.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-2",children:[e.jsx(s.TreePalm,{className:"size-8 text-muted-foreground"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"No records to display"})]});if(a.type==="custom")return p(a);if(!["table","custom"].includes(a.type)&&u)return e.jsx(s.ChartJsVisual,{cfg:u},JSON.stringify(u)+JSON.stringify(a.preferences)+((S=a==null?void 0:a.preferences)==null?void 0:S.customVisualCode));if(a.type==="table"&&(d!=null&&d.records)&&(d==null?void 0:d.records.length)>0)return e.jsxs(s.ScrollArea,{className:"relative mb-2 flex h-full min-h-0 w-full flex-1 grow basis-0",children:[e.jsx(s.TableVisual,{card:a,data:d==null?void 0:d.records}),e.jsx(s.ScrollBar,{orientation:"horizontal"})]})}return e.jsxs(s.Card,{role:"editor-visual-card",className:s.cn("relative flex h-full flex-col rounded-none",t),...n,children:[r&&e.jsxs(s.CardHeader,{className:"flex flex-row items-start justify-between py-4",children:[e.jsxs("div",{children:[e.jsx(s.Editable,{text:a.title,onSave:S=>j({...a,title:S}),children:e.jsx("div",{className:"flex items-center gap-5",children:e.jsx(s.CardTitle,{className:"text-base",children:a.title||"Edit title..."})})},a.title),e.jsx(s.Editable,{text:a.description||"",onSave:S=>j({...a,description:S}),children:e.jsx(s.CardDescription,{children:a.description||"Edit description..."})},a.description)]}),c&&e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(s.Editable,{className:"my-1",text:c.title||c.column,onSave:S=>l({...c,title:S}),children:e.jsx(s.Label,{children:c.title})}),e.jsx(s.FilterComponent,{filter:c})]})]}),e.jsx(s.CardContent,{className:"flex grow flex-col",children:f()})]})}const Be=({language:t,value:n,onChange:a})=>e.jsx(s.Ft,{className:"h-full w-full overflow-hidden text-xs",theme:"default",options:{minimap:{enabled:!1},wordWrap:"on",scrollbar:{verticalScrollbarSize:0,horizontalScrollbarSize:0},fontSize:12,lineHeight:16,renderLineHighlight:"none"},defaultLanguage:t,value:n,onChange:a}),St=()=>e.jsxs(s.DialogHeader,{children:[e.jsx("div",{className:"flex items-center gap-2",children:e.jsx(s.DialogTitle,{children:"Customize Card"})}),e.jsxs(s.DialogDescription,{children:["See the configuration options and documentation",e.jsx("a",{target:"_blank",className:"ml-1 text-blue-500 underline",href:"https://www.chartjs.org/docs/latest/samples/bar/vertical.html",children:"here."})]})]}),yt=({defaultConfig:t,customCode:n,customConfig:a,onConfigChange:r,onCodeChange:o})=>e.jsxs(s.Tabs,{defaultValue:"custom-config",className:"flex w-1/2 flex-col",children:[e.jsxs(s.TabsList,{className:"justify-start rounded-sm rounded-b-none border border-b-0",children:[e.jsx(s.TabsTrigger,{value:"custom-config",children:a?"Custom Config":"Default Config"}),e.jsx(s.TabsTrigger,{value:"output",children:"Output"}),e.jsx(s.TabsTrigger,{value:"custom-code",children:"Custom Code"})]}),e.jsx(s.TabsContent,{value:"output",className:"mt-0 grow rounded-b border border-t-0 p-2",children:e.jsx(s.Textarea,{readOnly:!0,value:t,className:"h-full resize-none border-none font-mono focus-visible:ring-0"})}),e.jsx(s.TabsContent,{value:"custom-config",className:"mt-0 grow rounded-b border border-t-0",children:e.jsx(Be,{language:"json",value:a,onChange:r})}),e.jsx(s.TabsContent,{value:"custom-code",className:"mt-0 grow rounded-b border border-t-0",children:e.jsx(Be,{language:"javascript",value:n,onChange:o})})]}),vt=({error:t,hasCustomConfig:n,onReset:a,onApply:r,onClose:o})=>e.jsxs(s.DialogFooter,{className:"flex items-center",children:[e.jsx(s.Label,{className:"mr-2 text-red-500",children:t}),e.jsx(s.Button,{disabled:!n,onClick:a,variant:"outline",children:"Reset"}),e.jsx(s.Button,{onClick:r,variant:"outline",children:"Apply"}),e.jsx(s.Button,{onClick:o,variant:"outline",children:"Close"})]});function Ct(){const[t,n]=y.useState(!1),[a,r]=y.useState(""),[o,i]=y.useState(""),[l,c]=y.useState(""),[d,h]=y.useState(""),x=s.useEditorStore(N=>N.card),j=s.useEditorStore(N=>N.card.customCfg),{data:b}=s.useDashboardCardQuery(x),{data:u}=s.useTopoJson(x),{setCardCustomCfg:p,setCustomVisualCode:f}=s.useEditorActions(),w=N=>{var k,A;return JSON.stringify({...N,data:{...N.data,datasets:(A=(k=N.data)==null?void 0:k.datasets)==null?void 0:A.map(z=>({...z,data:[]}))}},null,2)},S=()=>{var k,A;if(!((k=b==null?void 0:b.records)!=null&&k.length))return;const N=s.createChartConfig({data:b.records,cardType:x.type,cfg:x.cfg,preferences:x.preferences,topoJson:u});if(N){r(w(N)),c(((A=x.preferences)==null?void 0:A.customVisualCode)||"");const z=s.merge(N,j);i(w(z))}},L=()=>{try{if(l&&f(l),o){const N=JSON.parse(o),k=s.getObjectDiff(JSON.parse(a),N);p(k),h("")}}catch{h("Invalid JSON configuration")}};return e.jsxs(s.Dialog,{open:t,onOpenChange:n,children:[e.jsx(s.DialogTrigger,{asChild:!0,children:e.jsx(s.Button,{onClick:S,size:"sm",variant:"outline",className:j?"border-foreground/50 dark:border-foreground/70":"",children:e.jsx(s.Settings,{className:"h-4 w-4"})})}),e.jsxs(s.DialogContent,{className:"max-h-[70vh] min-h-[70vh] overflow-auto sm:min-w-[900px] lg:min-w-[1200px]",children:[e.jsx(St,{}),e.jsxs("div",{className:"flex grow gap-2",children:[e.jsx(s.ErrorBoundary,{FallbackComponent:s.FallbackEditorCard,children:e.jsx(ss,{className:"w-1/2 rounded shadow-none"})}),e.jsx(yt,{defaultConfig:a,customCode:l,customConfig:o,onConfigChange:N=>i(N??""),onCodeChange:N=>c(N??"")})]}),e.jsx(vt,{error:d,hasCustomConfig:!!j,onReset:()=>{i(a),p(null)},onApply:L,onClose:()=>n(!1)})]})]})}function ts(t){return te({attr:{viewBox:"0 0 1024 1024"},child:[{tag:"path",attr:{d:"M926.8 397.1l-396-288a31.81 31.81 0 0 0-37.6 0l-396 288a31.99 31.99 0 0 0-11.6 35.8l151.3 466a32 32 0 0 0 30.4 22.1h489.5c13.9 0 26.1-8.9 30.4-22.1l151.3-466c4.2-13.2-.5-27.6-11.7-35.8zM838.6 417l-98.5 32-200-144.7V199.9L838.6 417zM466 567.2l-89.1 122.3-55.2-169.2L466 567.2zm-116.3-96.8L484 373.3v140.8l-134.3-43.7zM512 599.2l93.9 128.9H418.1L512 599.2zm28.1-225.9l134.2 97.1L540.1 514V373.3zM558 567.2l144.3-46.9-55.2 169.2L558 567.2zm-74-367.3v104.4L283.9 449l-98.5-32L484 199.9zM169.3 470.8l86.5 28.1 80.4 246.4-53.8 73.9-113.1-348.4zM327.1 853l50.3-69h269.3l50.3 69H327.1zm414.5-33.8l-53.8-73.9 80.4-246.4 86.5-28.1-113.1 348.4z"},child:[]}]})(t)}function as(t){return te({attr:{viewBox:"0 0 256 256",fill:"currentColor"},child:[{tag:"path",attr:{d:"M128,24a8,8,0,0,0-8,8V88a8,8,0,0,0,8,8,32,32,0,1,1-27.72,16,8,8,0,0,0-2.93-10.93l-48.5-28A8,8,0,0,0,37.92,76,104,104,0,1,0,128,24ZM48.09,91.1,83,111.26A48.09,48.09,0,0,0,80,128c0,1.53.08,3,.22,4.52L41.28,143A88.16,88.16,0,0,1,48.09,91.1Zm-2.67,67.31,39-10.44A48.1,48.1,0,0,0,120,175.32v40.31A88.2,88.2,0,0,1,45.42,158.41ZM136,215.63V175.32a48,48,0,0,0,0-94.65V40.36a88,88,0,0,1,0,175.27Z"},child:[]}]})(t)}function ns(t){return te({attr:{viewBox:"0 0 256 256",fill:"currentColor"},child:[{tag:"path",attr:{d:"M128,24A104,104,0,1,0,232,128,104.11,104.11,0,0,0,128,24Zm87.63,96H191.48A64.1,64.1,0,0,0,136,64.52V40.37A88.13,88.13,0,0,1,215.63,120ZM120,120H80.68A48.09,48.09,0,0,1,120,80.68Zm0,16v39.32A48.09,48.09,0,0,1,80.68,136Zm16,0h39.32A48.09,48.09,0,0,1,136,175.32Zm0-16V80.68A48.09,48.09,0,0,1,175.32,120ZM120,40.37V64.52A64.1,64.1,0,0,0,64.52,120H40.37A88.13,88.13,0,0,1,120,40.37ZM40.37,136H64.52A64.1,64.1,0,0,0,120,191.48v24.15A88.13,88.13,0,0,1,40.37,136ZM136,215.63V191.48A64.1,64.1,0,0,0,191.48,136h24.15A88.13,88.13,0,0,1,136,215.63Z"},child:[]}]})(t)}function Nt(t){return te({attr:{viewBox:"0 0 256 256",fill:"currentColor"},child:[{tag:"path",attr:{d:"M48,180c0,11,7.18,20,16,20a14.24,14.24,0,0,0,10.22-4.66A8,8,0,0,1,85.78,206.4,30.06,30.06,0,0,1,64,216c-17.65,0-32-16.15-32-36s14.35-36,32-36a30.06,30.06,0,0,1,21.78,9.6,8,8,0,0,1-11.56,11.06A14.24,14.24,0,0,0,64,160C55.18,160,48,169,48,180Zm79.6-8.69c-4-1.16-8.14-2.35-10.45-3.84-1.25-.81-1.23-1-1.12-1.9a4.57,4.57,0,0,1,2-3.67c4.6-3.12,15.34-1.73,19.82-.56A8,8,0,0,0,142,145.86c-2.12-.55-21-5.22-32.84,2.76a20.58,20.58,0,0,0-9,14.95c-2,15.88,13.65,20.41,23,23.11,12.06,3.49,13.12,4.92,12.78,7.59-.31,2.41-1.26,3.34-2.14,3.93-4.6,3.06-15.17,1.56-19.55.36A8,8,0,0,0,109.94,214a61.34,61.34,0,0,0,15.19,2c5.82,0,12.3-1,17.49-4.46a20.82,20.82,0,0,0,9.19-15.23C154,179,137.49,174.17,127.6,171.31Zm83.09-26.84a8,8,0,0,0-10.23,4.84L188,184.21l-12.47-34.9a8,8,0,0,0-15.07,5.38l20,56a8,8,0,0,0,15.07,0l20-56A8,8,0,0,0,210.69,144.47ZM216,88v24a8,8,0,0,1-16,0V96H152a8,8,0,0,1-8-8V40H56v72a8,8,0,0,1-16,0V40A16,16,0,0,1,56,24h96a8,8,0,0,1,5.66,2.34l56,56A8,8,0,0,1,216,88Zm-27.31-8L160,51.31V80Z"},child:[]}]})(t)}function rs(t){return te({attr:{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"},child:[{tag:"path",attr:{d:"M6 16m-3 0a3 3 0 1 0 6 0a3 3 0 1 0 -6 0"},child:[]},{tag:"path",attr:{d:"M16 19m-2 0a2 2 0 1 0 4 0a2 2 0 1 0 -4 0"},child:[]},{tag:"path",attr:{d:"M14.5 7.5m-4.5 0a4.5 4.5 0 1 0 9 0a4.5 4.5 0 1 0 -9 0"},child:[]}]})(t)}function os(t){return te({attr:{viewBox:"0 0 24 24"},child:[{tag:"path",attr:{fill:"none",d:"M0 0h24v24H0z"},child:[]},{tag:"path",attr:{d:"m2 19.99 7.5-7.51 4 4 7.09-7.97L22 9.92l-8.5 9.56-4-4-6 6.01-1.5-1.5zm1.5-4.5 6-6.01 4 4L22 3.92l-1.41-1.41-7.09 7.97-4-4L2 13.99l1.5 1.5z"},child:[]}]})(t)}function is(t){return te({attr:{viewBox:"0 0 24 24"},child:[{tag:"path",attr:{fill:"none",d:"M0 0h24v24H0z"},child:[]},{tag:"path",attr:{d:"M4 9h4v11H4zM4 4h4v4H4zM10 7h4v4h-4zM16 10h4v4h-4zM16 15h4v5h-4zM10 12h4v8h-4z"},child:[]}]})(t)}function ls(t){return te({attr:{version:"1.2",baseProfile:"tiny",viewBox:"0 0 24 24"},child:[{tag:"path",attr:{d:"M4 18c-.552 0-1-.448-1-1v-6.382l-.553.276c-.495.248-1.095.046-1.342-.447-.247-.494-.046-1.094.448-1.342l2-1c.31-.155.678-.139.973.044.294.183.474.504.474.851v8c0 .552-.448 1-1 1zM13 18h-5c-.404 0-.769-.244-.924-.617-.155-.374-.069-.804.217-1.09l4-4c.254-.254.394-.591.394-.95 0-.358-.14-.695-.394-.949-.508-.508-1.39-.508-1.9.001-.253.252-.393.589-.393.948 0 .552-.448 1-1 1s-1-.448-1-1c0-.894.348-1.733.98-2.364 1.265-1.263 3.464-1.263 4.727.001.632.631.979 1.471.979 2.363 0 .893-.348 1.733-.979 2.364l-2.293 2.293h2.586c.552 0 1 .448 1 1s-.448 1-1 1zM20.955 12.377c.338-.457.545-1.016.545-1.627 0-1.517-1.234-2.75-2.75-2.75-1.031 0-1.966.569-2.44 1.484-.254.49-.063 1.094.428 1.348.49.254 1.094.062 1.348-.428.128-.249.383-.404.664-.404.414 0 .75.336.75.75s-.336.75-.75.75c-.552 0-1 .448-1 1s.448 1 1 1c.689 0 1.25.561 1.25 1.25s-.561 1.25-1.25 1.25-1.25-.561-1.25-1.25c0-.552-.448-1-1-1s-1 .448-1 1c0 1.792 1.458 3.25 3.25 3.25s3.25-1.458 3.25-3.25c0-.939-.406-1.779-1.045-2.373z"},child:[]}]})(t)}function cs(t){return te({attr:{viewBox:"0 0 512 512"},child:[{tag:"path",attr:{d:"M217 25v14h78V25h-78zm0 32v46h14V71h50v32h14V57h-78zm32 32v14h14V89h-14zm-64 32v46h30v-46h-30zm48 0v14h46v-14h-46zm64 0v46h30v-46h-30zm-64 32v14h46v-14h-46zm-80 32v46h62v-46h-62zm80 0v14h46v-14h-46zm64 0v46h62v-46h-62zm-64 32v14h46v-14h-46zm-112 32v46h94v-46h-94zm112 0v14h46v-14h-46zm64 0v46h94v-46h-94zm-64 32v14h46v-14h-46zM89 313v46h126v-46H89zm144 0v14h46v-14h-46zm64 0v46h126v-46H297zm-64 32v14h46v-14h-46zM57 377v46h158v-46H57zm176 0v14h46v-14h-46zm64 0v46h158v-46H297zm-64 32v14h46v-14h-46zM25 441v46h190v-46H25zm208 0v14h46v-14h-46zm64 0v46h190v-46H297zm-64 32v14h46v-14h-46z"},child:[]}]})(t)}function ds(t){const[n,a]=y.useState(null);return n}function us(){const{authToken:t}=s.useSemaphorContext(),{data:n,isLoading:a,isFetching:r,isError:o}=s.useQuery({queryKey:["plugins",t==null?void 0:t.accessToken],queryFn:()=>s.getPlugins(t==null?void 0:t.accessToken)});return{data:n,isLoading:a,isFetching:r,isError:o}}function wt({onChartTypeChange:t}){const[n,a]=y.useState([]),{data:r}=us();return y.useEffect(()=>{(async()=>{var i;if(r){const c=(await Promise.all((i=r==null?void 0:r.plugins)==null?void 0:i.map(async d=>(await s.loadManifest(d.value)).visuals.map(j=>({name:j.name,icon:j.icon,url:d.value}))))).flat();a(c)}})()},[r]),n.length===0?null:e.jsxs(e.Fragment,{children:[e.jsx(s.Separator,{className:"my-2"}),e.jsx("div",{className:"grid grid-cols-4 place-items-center",children:n.map((o,i)=>e.jsx(kt,{text:o.name,onClick:()=>t("custom",o),icon:o.icon},o.url+o.name+i))})]})}const kt=({text:t,icon:n,onClick:a})=>{const r=ds(),o=t.charAt(0).toUpperCase();return e.jsx(s.Button,{onClick:a,title:t,variant:"ghost",children:r?e.jsx(r,{className:"h-4 w-4"}):o})};function Et(){var x,j;const[t,n]=y.useState(!1),a=s.useEditorStore(b=>b.card),r=a.type,{setCardType:o,setCardPreferences:i,setChartOrientation:l}=s.useEditorStore(b=>b.actions),{setCardCustomCfg:c,setCustomCardPreferences:d}=s.useEditorActions();function h(b,u){c(null),i({}),o(b),u&&d({type:"component",visualType:"single",url:u.url,componentName:u.name,icon:u.icon}),n(!1)}return e.jsxs(s.Popover,{open:t,onOpenChange:n,children:[e.jsx(s.PopoverTrigger,{asChild:!0,children:e.jsx(s.Button,{size:"sm",variant:"outline",children:e.jsx(Dt,{className:"h-4 w-4",chartType:r,customIcon:(x=a.customCardPreferences)==null?void 0:x.icon,componentName:(j=a.customCardPreferences)==null?void 0:j.componentName})})}),e.jsxs(s.PopoverContent,{className:"w-50",children:[e.jsxs("div",{className:"grid grid-cols-4 place-items-center",children:[e.jsx(s.Button,{onClick:()=>h("bar"),className:"font-normal",variant:"ghost",children:e.jsx(Ne,{className:"size-5"})}),e.jsx(s.Button,{onClick:()=>h("line"),variant:"ghost",children:e.jsx(we,{className:"size-5"})}),e.jsx(s.Button,{onClick:()=>h("stackedBar"),variant:"ghost",children:e.jsx(is,{className:"size-5",strokeWidth:0})}),e.jsx(s.Button,{onClick:()=>h("stackedLine"),variant:"ghost",children:e.jsx(os,{className:"size-5",strokeWidth:0})}),e.jsx(s.Button,{onClick:()=>h("scatter"),variant:"ghost",children:e.jsx(Ue,{className:"size-5"})}),e.jsx(s.Button,{onClick:()=>h("bubble"),variant:"ghost",children:e.jsx(rs,{className:"size-4"})}),e.jsx(s.Button,{onClick:()=>h("pie"),variant:"ghost",children:e.jsx(Ge,{className:"size-5"})}),e.jsx(s.Button,{onClick:()=>h("doughnut"),variant:"ghost",children:e.jsx(as,{className:"size-5",strokeWidth:1})}),e.jsx(s.Button,{onClick:()=>h("radar"),variant:"ghost",children:e.jsx(ts,{className:"size-5 font-extralight",strokeWidth:.5})}),e.jsx(s.Button,{onClick:()=>h("polarArea"),variant:"ghost",children:e.jsx(ns,{className:"size-5"})}),e.jsx(s.Button,{onClick:()=>h("pyramid"),variant:"ghost",children:e.jsx(cs,{className:"size-5"})}),e.jsx(s.Button,{onClick:()=>h("range"),variant:"ghost",children:e.jsx(He,{className:"size-5"})}),e.jsx(s.Button,{onClick:()=>h("table"),variant:"ghost",children:e.jsx(Ee,{className:"size-5"})}),e.jsx(s.Button,{onClick:()=>h("kpi"),variant:"ghost",children:e.jsx(ls,{className:"size-6"})}),e.jsx(s.Button,{onClick:()=>h("text"),variant:"ghost",children:e.jsx(De,{className:"size-4"})}),e.jsx(s.Button,{onClick:()=>h("map"),variant:"ghost",children:e.jsx($e,{className:"size-4"})}),e.jsx(s.Button,{onClick:()=>h("custom"),variant:"ghost",children:e.jsx(Qe,{className:"size-4"})})]}),e.jsx(wt,{onChartTypeChange:h})]})]})}function Dt({chartType:t,className:n,customIcon:a,componentName:r}){const o=ds();switch(t){case"bar":return e.jsx(Ne,{className:n});case"line":return e.jsx(we,{className:n});case"pie":return e.jsx(Ge,{className:n});case"radar":return e.jsx(ts,{className:n});case"scatter":return e.jsx(Ue,{className:n});case"bubble":return e.jsx(rs,{className:n});case"doughnut":return e.jsx(as,{className:n});case"stackedBar":return e.jsx(is,{className:"size-4 text-foreground/70"});case"stackedLine":return e.jsx(os,{className:"size-4 text-foreground/70"});case"polarArea":return e.jsx(ns,{className:n});case"pyramid":return e.jsx(cs,{className:n});case"range":return e.jsx(He,{className:n});case"kpi":return e.jsx(ls,{className:n});case"text":return e.jsx(De,{className:n});case"map":return e.jsx($e,{className:n});case"custom":return a&&o?e.jsx(o,{className:n}):r?r==null?void 0:r.charAt(0).toUpperCase():e.jsx(Qe,{className:n});default:return e.jsx(Ee,{className:n})}}function It(){var a;const t=s.useEditorStore(r=>r.card);(a=t.customCardPreferences)==null||a.showCardHeader;const{setCustomCardPreferences:n}=s.useEditorActions();return e.jsxs(s.DropdownMenu,{children:[e.jsx(s.DropdownMenuTrigger,{asChild:!0,children:e.jsx(ke,{className:"size-4 cursor-pointer text-muted-foreground/70 transition-colors hover:text-muted-foreground"})}),e.jsx(s.DropdownMenuContent,{align:"start",className:"w-40 text-muted-foreground",children:e.jsxs(s.DropdownMenuItem,{onClick:()=>{navigator.clipboard.writeText(t.id),s.ue.success("Card ID copied to clipboard")},className:"cursor-pointer space-x-2",children:[e.jsx(s.IdCard,{className:"size-5"}),e.jsx("span",{children:"Copy Card ID"})]})})]})}function _e(){var m;const t=s.useEditorStore(g=>g.frame),n=s.useEditorStore(g=>g.card),a=s.useEditorStore(g=>g.isShowingVisual),r=s.useEditorStore(g=>g.isSqlRunning),o=s.useEditorStore(g=>g.pythonStdOut);s.useEditorStore(g=>g.actions.setRunSql);const{setFrame:i,setCard:l,updateCardInFrame:c,setActiveTabCardId:d}=s.useEditorActions(),{data:h,isLoading:x,isFetching:j,error:b}=s.useDashboardCardQuery(n);if(!n)return e.jsx(e.Fragment,{children:"No Active Card"});function u(){const g={connectionId:n.connectionId,id:s.v4(),title:"Title",description:"Description",preferences:{onClickFilter:[{columnIndex:0,expression:""}]},type:"bar",sql:"",data:[]};p(g)}function p(g){const D={...t,cards:[...t.cards,g],activeCardId:g.id};i(D),d(g.id)}function f(){const g={...n,id:s.v4(),title:`${n.title} Copy`,tabTitle:`${n.tabTitle||n.title} Copy`};p(g)}function w(g){const D=t.cards.filter(q=>q.id!==g),v=D[0],O={...t,cards:D,activeCardId:v.id};i(O),d(v.id),l(v)}function S(g){d(g)}const L=(g,D)=>{console.log("handleDragStart",D),g.dataTransfer.setData("tabIndex",D.toString())},N=g=>{g.preventDefault()},k=(g,D)=>{const v=g.dataTransfer.getData("tabIndex");if(v===D.toString())return;const O=Array.from(t.cards),[q]=O.splice(parseInt(v),1);O.splice(D,0,q),i({...t,cards:O})};function A(g,D){return g.cards.length===1&&(D.displayTab===!0||D.displayTab===void 0)||g.activeCardId!==D.id&&(D.displayTab===!0||D.displayTab===void 0)?null:e.jsx("div",{onClick:()=>{const v=D.displayTab===void 0?!1:!D.displayTab;l({...D,displayTab:v}),c({...D,displayTab:v})},children:D.displayTab===!0||D.displayTab===void 0?e.jsx(s.Eye,{className:"mr-2 size-3.5 text-muted-foreground hover:text-foreground"}):e.jsx(ws,{className:"mr-2 size-3.5 text-muted-foreground hover:text-foreground"})})}function z(){return e.jsxs(s.Tabs,{onValueChange:S,value:t.activeCardId,className:"flex grow flex-col",children:[t.cards.map(g=>e.jsx(s.TabsContent,{className:"mt-0 grow",value:g.id,children:B()},g.id)),e.jsx(s.TabsList,{className:"group mx-6 justify-between",children:e.jsxs("div",{className:"flex items-center",children:[t.cards.map((g,D)=>e.jsx(s.Editable,{text:g.tabTitle||g.title,onSave:v=>{l({...n,tabTitle:v}),c({...n,tabTitle:v})},children:e.jsxs(s.TabsTrigger,{draggable:!0,onDragStart:v=>L(v,D),onDragOver:N,onDrop:v=>k(v,D),className:"",value:g.id,children:[A(t,g),g.tabTitle||g.title,t.activeCardId===g.id&&t.cards.length>1&&e.jsx(s.X,{className:"ml-2 size-3.5 text-muted-foreground hover:text-foreground",onClick:()=>w(g.id)})]})},g.id)),e.jsx(s.Button,{className:"ml-1 h-8 px-2 hover:bg-muted-foreground/50",variant:"outline",onClick:u,children:e.jsx(s.Plus,{className:"h-4 w-4"})}),e.jsx(s.Button,{className:"invisible ml-1 h-8 px-2 hover:bg-muted-foreground/50 group-hover:visible",variant:"outline",onClick:f,children:e.jsx(vs,{className:"h-4 w-4"})})]})})]})}function B(){return n.type==="kpi"?e.jsx("div",{className:"flex h-full items-center justify-center",children:e.jsx("div",{className:"w-1/2 rounded-md border",children:e.jsx(s.KPICard,{card:n,data:h==null?void 0:h.records})})}):n.type==="text"?e.jsx("div",{className:"flex h-full items-center justify-center",children:e.jsx("div",{className:"w-1/2 rounded-md border",children:e.jsx(s.ScrollArea,{className:"mx-3 my-6 h-[300px] overflow-y-auto break-words px-3",children:e.jsx(s.TextCard,{isLoading:r,card:n,data:h==null?void 0:h.records})})})}):e.jsx(s.ErrorBoundary,{FallbackComponent:s.FallbackEditorCard,children:e.jsx(ss,{className:"grow border-none shadow-none"})})}function F(){const g=JSON.stringify(h==null?void 0:h.records,null,2),D=new Blob([g],{type:"application/json"}),v=URL.createObjectURL(D),O=document.createElement("a");O.href=v,O.download=`${n.title}.json`,O.click()}function _(){const D=[Object.keys(h==null?void 0:h.records.reduce((H,U)=>({...H,...U}),{})).join(","),...((h==null?void 0:h.records)||[]).map(H=>Object.values(H).join(","))].join(`
|
|
192
|
-
`),v=new Blob([D],{type:"text/csv"}),O=URL.createObjectURL(v),q=document.createElement("a");q.href=O,q.download=`${n.title}.csv`,q.click()}return e.jsxs("div",{className:"relative flex h-full flex-col py-3",children:[(x||j)&&e.jsx("div",{className:"absolute bottom-0 left-0 right-0 top-0 z-50 m-auto flex h-10 w-10 items-center justify-center rounded-md bg-muted",children:e.jsx(xe,{className:"h-8 w-8 animate-spin text-muted-foreground"})}),e.jsxs("div",{className:"mb-0 flex min-h-10 items-center justify-end gap-2 px-6",children:[a&&e.jsxs("div",{className:"flex grow items-center gap-2",children:[e.jsx(Et,{}),!["table","custom"].includes(n.type)&&e.jsx(Ct,{}),e.jsx(It,{})]}),!a&&e.jsxs("div",{className:"flex grow items-center gap-1",children:[e.jsx(s.Button,{className:"h-7 w-fit px-1 font-mono text-xs text-muted-foreground/70",variant:"ghost",size:"icon",onClick:_,children:e.jsx(Nt,{className:"size-4"})}),e.jsx(s.Button,{className:"h-7 w-fit px-1 font-mono text-xs text-muted-foreground/70",variant:"ghost",size:"icon",onClick:F,children:e.jsx(ks,{strokeWidth:1.5,className:"size-4"})}),e.jsx(s.CopyButton,{text:JSON.stringify(h==null?void 0:h.records,null,2),className:"h-7 w-fit px-1 font-mono text-xs text-muted-foreground/70"})]}),e.jsx(Lt,{})]}),a?z():e.jsxs(s.ResizablePanelGroup,{className:"px-6",direction:"horizontal",children:[o&&e.jsxs(e.Fragment,{children:[e.jsx(s.ResizablePanel,{id:"1",order:1,defaultSize:30,minSize:10,className:"relative flex h-full min-h-0 w-full flex-1 basis-0",children:o&&e.jsx(Tt,{})}),e.jsx(s.ResizableHandle,{})]}),e.jsx(s.ResizablePanel,{id:"2",order:2,minSize:10,className:"relative flex h-full min-h-0 w-full flex-1 basis-0",children:e.jsxs(s.ScrollArea,{className:"relative flex h-full min-h-0 w-full flex-1 basis-0",children:[(h==null?void 0:h.records)&&(h==null?void 0:h.records.length)>0&&e.jsx(jt,{data:(h==null?void 0:h.records)||[]}),(b||(h==null?void 0:h.error))&&e.jsx("span",{className:"font-mono text-xs",children:(b==null?void 0:b.message)||((m=h==null?void 0:h.error)==null?void 0:m.message)}),e.jsx(s.ScrollBar,{orientation:"horizontal"})]})})]})]})}function Tt(){const t=s.useEditorStore(a=>a.pythonStdOut);if(!t)return null;const n=t.replace(/\n/g,"<br>");return e.jsxs("div",{className:"relative flex w-full flex-col border-r",children:[e.jsx("div",{className:"sticky top-0 flex max-h-11 min-h-11 grow items-center border-b bg-muted px-3 font-mono text-xs font-semibold text-foreground/70",children:"Python Output"}),e.jsxs(s.ScrollArea,{className:"overflow-y-auto px-2 pt-1 font-mono text-xs text-foreground/90",children:[e.jsx("div",{dangerouslySetInnerHTML:{__html:n}}),e.jsx(s.ScrollBar,{orientation:"horizontal"})]})]})}function Lt(){const t=s.useEditorStore(a=>a.isShowingVisual),n=s.useEditorStore(a=>a.actions.setIsShowingVisual);return e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(s.Label,{htmlFor:"visualize",children:"Chart"}),e.jsx(s.Switch,{checked:t,onCheckedChange:()=>n(!t),id:"visualize",className:"data-[state=checked]:bg-foreground/50"})]})}function At({options:t,value:n,onValueChange:a}){return e.jsx(s.RadioGroup,{value:n,onValueChange:a,className:"flex gap-4",defaultValue:t[0].value,children:t.map(r=>e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(s.RadioGroupItem,{value:r.value,id:r.value}),e.jsx("label",{className:"text-sm",htmlFor:r.value,children:r.label})]},r.value))})}function ae({label:t,options:n,value:a,onValueChange:r,className:o}){return e.jsxs(s.Select,{value:a,onValueChange:r,children:[e.jsx(s.SelectTrigger,{className:s.cn("w-full focus:ring-0 focus:ring-offset-0",o),children:e.jsx(s.SelectValue,{placeholder:t})}),e.jsx(s.SelectContent,{children:e.jsxs(s.SelectGroup,{children:[e.jsx(s.SelectLabel,{children:t}),n.map(i=>e.jsx(s.SelectItem,{value:i.value,children:i.label},i.value))]})})]})}function me({children:t,summary:n,open:a,className:r}){return e.jsxs("details",{open:a,className:s.cn("space-y-4 [&_summary>svg]:open:-rotate-180",r),children:[e.jsxs("summary",{className:"flex cursor-pointer list-none items-center justify-between gap-4",children:[e.jsx(s.Label,{children:n}),e.jsx(s.ChevronUp,{className:"h-4 w-4"})]}),e.jsx("div",{className:"transition-all ease-in-out",children:t})]})}function zt(){var f,w;const t=s.useEditorStore(S=>S.card.customCardPreferences),{data:n}=us(),a=(n==null?void 0:n.plugins)||[],r=s.useEditorStore(S=>S.card),o=s.useEditorStore(S=>S.frame),i=(t==null?void 0:t.visualType)||"single",{setCustomCardPreferences:l}=s.useEditorActions(),{components:c,manifest:d}=s.useCustomVisual((t==null?void 0:t.url)||""),h=(f=d==null?void 0:d.visuals)==null?void 0:f.find(S=>S.name===(t==null?void 0:t.componentName));function x(S,L){if(!t)return;const k={...(t==null?void 0:t.dataInputCardIds)||{},[S]:{cardId:L,hookRef:null}};l({...t,dataInputCardIds:k})}function j(S){var N,k;const L=(N=o==null?void 0:o.cards)==null?void 0:N.filter(A=>{var z;return((z=A==null?void 0:A.customCardPreferences)==null?void 0:z.visualType)!=="multiple"}).map(A=>({value:A.id,label:A.tabTitle||A.title}));return e.jsx("div",{className:"space-y-2",children:(k=S==null?void 0:S.dataInputs)==null?void 0:k.map((A,z)=>{var B,F;return e.jsxs("div",{className:"grid grid-cols-10 gap-2",children:[e.jsx("div",{className:"col-span-4 flex items-center",children:A}),e.jsx(ae,{className:"col-span-6 h-8 w-full justify-between",label:"",options:L||[],value:((F=(B=t==null?void 0:t.dataInputCardIds)==null?void 0:B[z])==null?void 0:F.cardId)||"",onValueChange:_=>x(z,_)})]},z+Math.random())})})}function b(S,L,N=[]){var k,A;return t?S==="input"?e.jsx(s.Input,{className:`h-8 w-full ${s.removeRing}`,value:((k=t==null?void 0:t.settings)==null?void 0:k[L])||"",onChange:z=>{l({...t,settings:{...t==null?void 0:t.settings,[L]:z.target.value}})}},L):S==="select"?e.jsx(ae,{className:"h-8 w-full",label:"",options:N,value:((A=t==null?void 0:t.settings)==null?void 0:A[L])||"",onValueChange:z=>{l({...t,settings:{...t==null?void 0:t.settings,[L]:z}})}}):null:null}function u(S){const L=Object.entries((S==null?void 0:S.settings)||{});return e.jsx("div",{className:"space-y-3",children:L.map(([N,k])=>e.jsxs("div",{className:"space-y-2",children:[e.jsx(s.Label,{children:k.title}),b(k.ui,N,k.options)]},N))})}function p(S){t&&l({...t,visualType:S,componentName:""})}return e.jsxs("div",{className:"p-6",children:[e.jsx(me,{summary:"Plugin Settings",children:e.jsx("div",{className:"space-y-4 text-sm",children:e.jsxs("div",{className:"space-y-4 text-sm",children:[e.jsx("div",{className:"space-y-2",children:e.jsx("div",{className:"px-2",children:e.jsx(ae,{className:"h-8 w-full",label:"",options:a,value:(t==null?void 0:t.url)||"",onValueChange:S=>l({...t||{url:"",componentName:""},url:S})})})}),((t==null?void 0:t.type)==="component"||(t==null?void 0:t.type)===void 0)&&e.jsx(At,{options:[{value:"single",label:"Single Visual"},{value:"multiple",label:"Multi-Visual"}],value:i,onValueChange:p}),((t==null?void 0:t.type)==="component"||(t==null?void 0:t.type)===void 0)&&t&&e.jsx(e.Fragment,{children:e.jsxs("div",{className:"space-y-2",children:[e.jsx(s.Label,{children:"Component"}),e.jsx("div",{className:"space-y-2 px-2",children:c&&e.jsx(ae,{className:"h-8 w-full",label:"",options:(c==null?void 0:c.filter(S=>S.type===i).map(S=>({value:S.name,label:S.name})))||[],value:t.componentName,onValueChange:S=>{console.log("changing value",S),l({...t,componentName:S})}})})]})})]})})}),e.jsx(s.Separator,{className:"my-4"}),((w=r==null?void 0:r.customCardPreferences)==null?void 0:w.componentName)&&e.jsxs(me,{summary:"Component Settings",children:[h&&h.dataInputs&&e.jsxs("div",{className:"space-y-3",children:[e.jsx(s.Label,{children:"Input Mapping"}),e.jsx("div",{className:"px-2",children:j(h)})]}),h&&h.settings&&e.jsx("div",{className:"space-y-3",children:e.jsx("div",{className:"px-2",children:u(h)})})]})]})}function ie(){const[t,n]=y.useState([]);s.useEditorStore(x=>x.card.cfg);const a=s.useEditorStore(x=>x.card.preferences),{setCardCfg:r,setFilterOnClickColumnIndex:o,setCardPreferences:i}=s.useEditorStore(x=>x.actions),l=s.useEditorStore(x=>x.queryResultColumns);s.useEditorStore(x=>{var j;return(j=x.card.preferences)==null?void 0:j.filterOnClickColumnIndex}),y.useEffect(()=>{l&&n(new Array(l.length).fill(!1))},[l]);function c(x,j){var b,u;j?a!=null&&a.onClickFilter&&((b=a==null?void 0:a.onClickFilter)==null?void 0:b.length)>0?i({...a,onClickFilter:[...a.onClickFilter,{columnIndex:x,expression:""}]}):i({...a,onClickFilter:[{columnIndex:x,expression:""}]}):(i({...a,onClickFilter:(u=a==null?void 0:a.onClickFilter)==null?void 0:u.filter(p=>p.columnIndex!==x)}),n(p=>{const f=[...p];return f[x]=!1,f}))}function d(x,j){var u;const b=(u=a==null?void 0:a.onClickFilter)==null?void 0:u.map(p=>p.columnIndex===x?{...p,expression:j.target.value}:p);i({...a,onClickFilter:b})}function h(x){var j,b,u,p;if(t!=null&&t[x]||(b=(j=a==null?void 0:a.onClickFilter)==null?void 0:j.find(f=>f.columnIndex===x))!=null&&b.expression)return e.jsx(s.Input,{value:(p=(u=a==null?void 0:a.onClickFilter)==null?void 0:u.find(f=>f.columnIndex===x))==null?void 0:p.expression,onChange:f=>d(x,f),type:"text",className:"h-9 w-full font-mono text-xs focus-visible:ring-0 focus-visible:ring-ring focus-visible:ring-offset-0",placeholder:"Expression"})}return e.jsxs("div",{className:"space-y-2",children:[e.jsx(s.Label,{children:"On Click"}),l==null?void 0:l.map((x,j)=>{var b,u;return e.jsx("div",{className:"xbg-red-100 group flex items-center justify-between space-y-2",children:e.jsxs("div",{className:"grow",children:[e.jsxs("div",{className:"flex items-center space-x-2 py-2",children:[e.jsx(s.Checkbox,{checked:!!((b=a==null?void 0:a.onClickFilter)!=null&&b.find(p=>p.columnIndex===j)),onCheckedChange:p=>c(j,p)}),e.jsx("label",{className:"text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70",children:x}),e.jsx("div",{className:"flex items-center gap-2",children:((u=a==null?void 0:a.onClickFilter)==null?void 0:u.find(p=>p.columnIndex===j))&&e.jsx(s.Pencil,{onClick:()=>{n(p=>{const f=[...p];return f[j]=!p[j],f})},className:"invisible size-3 cursor-pointer text-gray-400 group-hover:visible"})})]}),h(j)]})},x)})]})}function Se(){var l,c,d;const t=s.useEditorStore(h=>h.card.preferences),n=s.useEditorStore(h=>h.card.cfg),{setCardCfg:a,setCardPreferences:r,setChartOrientation:o}=s.useEditorStore(h=>h.actions);(l=n==null?void 0:n.options)!=null&&l.indexAxis;function i(h){o(h)}return e.jsxs(s.RadioGroup,{value:((c=t==null?void 0:t.chartOptions)==null?void 0:c.indexAxis)||((d=n==null?void 0:n.options)==null?void 0:d.indexAxis)||"x",onValueChange:i,className:"flex gap-3",defaultValue:"x",children:[e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(s.RadioGroupItem,{value:"x",id:"r1"}),e.jsx("label",{className:"text-sm",htmlFor:"r1",children:"Vertical"})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(s.RadioGroupItem,{value:"y",id:"r2"}),e.jsx("label",{className:"text-sm",htmlFor:"r2",children:"Horizontal"})]})]})}const fe="focus-visible:ring-0 focus-visible:ring-ring focus-visible:ring-offset-0";function Pe(t,n){var r,o,i;const a=s.getNumberAxis(t,n);return((i=(o=(r=t==null?void 0:t.chartOptions)==null?void 0:r.scales)==null?void 0:o[a])==null?void 0:i.type)||"linear"}function hs(){var H,U,G,W,ee,P;const[t,n]=y.useState(!1),a=s.useEditorStore(M=>{var T;return(T=M.card)==null?void 0:T.preferences}),r=s.useEditorStore(M=>{var T;return(T=M.card)==null?void 0:T.cfg}),o=s.getNumberAxis(a,r),[i,l]=y.useState(Pe(a)),[c,d]=y.useState(((G=(U=(H=a==null?void 0:a.chartOptions)==null?void 0:H.scales)==null?void 0:U[o])==null?void 0:G.min)||""),[h,x]=y.useState(((P=(ee=(W=a==null?void 0:a.chartOptions)==null?void 0:W.scales)==null?void 0:ee[o])==null?void 0:P.max)||""),[j,b]=y.useState(c||h?"custom":"auto"),[u,p]=y.useState(""),[f,w]=y.useState(0),[S,L]=y.useState(""),[N,k]=y.useState(""),[A,z]=y.useState(""),B=s.useEditorStore(M=>M.actions.setCardPreferences),{updateCardInFrame:F}=s.useEditorActions(),_=s.useEditorStore(M=>M.card),m=s.useEditorStore(M=>{var T;return(T=M.card)==null?void 0:T.type}),g=["pie","doughnut","polarArea"].includes(m);y.useEffect(()=>{var M,T,K,Q,X,Z,$,E,V,R,J,le,ce,re;l(Pe(a)),d(((K=(T=(M=a==null?void 0:a.chartOptions)==null?void 0:M.scales)==null?void 0:T[o])==null?void 0:K.min)===0?0:""),x(((Z=(X=(Q=a==null?void 0:a.chartOptions)==null?void 0:Q.scales)==null?void 0:X[o])==null?void 0:Z.max)||""),p(((R=(V=(E=($=a==null?void 0:a.chartOptions)==null?void 0:$.scales)==null?void 0:E[o])==null?void 0:V.ticks)==null?void 0:R.stepSize)||""),w(((J=a==null?void 0:a.numberAxisFormat)==null?void 0:J.decimalPlaces)||0),L(((le=a==null?void 0:a.numberAxisFormat)==null?void 0:le.suffix)||""),k(((ce=a==null?void 0:a.numberAxisFormat)==null?void 0:ce.currency)||""),z(((re=a==null?void 0:a.numberAxisFormat)==null?void 0:re.locale)||"")},[t,a,o]);function D(M,T){return T===""||/^[0-9\b]+$/.test(T)?Number(T):Number(M)}function v(){const M=[...new Set(s.LOCALE_CURRENCY_PAIRS.map(T=>T.currency))];return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"grid grid-cols-6 items-center gap-2",children:[e.jsx(s.Label,{className:"col-span-2 hover:cursor-pointer hover:underline",htmlFor:"currency",children:e.jsx("a",{target:"_blank",href:"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat",children:"Currency"})}),e.jsxs(s.Select,{value:N||"none",onValueChange:T=>k(T==="none"?"":T),children:[e.jsx(s.SelectTrigger,{className:"col-span-2 h-8 w-full focus:ring-1 focus:ring-offset-0",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{children:e.jsxs(s.SelectGroup,{children:[e.jsx(s.SelectLabel,{children:"Currency"}),e.jsx(s.SelectItem,{value:"none",children:"None"}),M.map(T=>e.jsx(s.SelectItem,{value:T,children:T},T))]})})]}),e.jsxs(s.Select,{value:A,onValueChange:T=>z(T),children:[e.jsx(s.SelectTrigger,{className:"col-span-2 h-8 w-full focus:ring-1 focus:ring-offset-0",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{children:e.jsxs(s.SelectGroup,{children:[e.jsx(s.SelectLabel,{children:"Locale"}),s.LOCALE_CURRENCY_PAIRS.map(T=>e.jsx(s.SelectItem,{value:T.locale,children:T.locale},T.locale))]})})]})]}),e.jsxs("div",{className:"grid grid-cols-9 items-center gap-2",children:[e.jsx(s.Label,{className:"col-span-3",htmlFor:"format",children:"Decimals"}),e.jsx(s.Input,{value:f,onChange:T=>w(Number(T.target.value)),id:"format",className:`col-span-6 h-8 w-full tracking-wide ${fe}`})]})]})}function O(){return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"grid grid-cols-3 items-center gap-2",children:[e.jsx(s.Label,{htmlFor:"range",children:"Range"}),e.jsx(s.Input,{id:"min",value:c,onChange:M=>d(T=>D(T,M.target.value)),className:`col-span-1 h-8 w-full ${fe}`}),e.jsx(s.Input,{value:h,onChange:M=>x(T=>D(T,M.target.value)),id:"max",className:`col-span-1 h-8 w-full ${fe}`})]}),e.jsxs("div",{className:"grid grid-cols-3 items-center gap-2",children:[e.jsx(s.Label,{htmlFor:"step-size",children:"Step Size"}),e.jsx(s.Input,{value:u,onChange:M=>p(T=>D(T,M.target.value)),id:"step-size",className:`col-span-1 h-8 w-full ${fe}`})]})]})}function q(){var Q;let M={};j==="custom"&&(M={min:c,max:h,ticks:{stepSize:u}});const T={...a||{},chartOptions:{...a==null?void 0:a.chartOptions,scales:{...(Q=a==null?void 0:a.chartOptions)==null?void 0:Q.scales,[o]:{type:i,...i==="linear"?M:{}}}},numberAxisFormat:{decimalPlaces:f,suffix:S,currency:N,locale:A}};console.log(T),B(T);const K={..._,preferences:T};F(K)}return e.jsxs(s.Popover,{onOpenChange:M=>n(M),children:[e.jsx(s.PopoverTrigger,{asChild:!0,children:e.jsx(s.SliderIcon,{className:"size-4 cursor-pointer text-muted-foreground hover:text-foreground"})}),e.jsx(s.PopoverContent,{align:"center",className:"max-w-65",children:e.jsxs("div",{className:"grid gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("h4",{className:"font-medium leading-none",children:"Scale Options"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Set the scale for the number axis"})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsxs("div",{className:"grid grid-cols-3 items-center gap-2",children:[e.jsx(s.Label,{htmlFor:"scale",children:"Type"}),e.jsxs(s.Select,{disabled:g,value:i,onValueChange:M=>l(M),children:[e.jsx(s.SelectTrigger,{className:"col-span-2 h-8 w-full focus:ring-1 focus:ring-offset-0",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{id:"type",children:e.jsxs(s.SelectGroup,{children:[e.jsx(s.SelectLabel,{children:"Option"}),e.jsx(s.SelectItem,{value:"linear",children:"Linear"}),e.jsx(s.SelectItem,{value:"logarithmic",children:"Logarithmic"})]})})]})]}),i=="linear"&&e.jsxs("div",{className:"grid grid-cols-3 items-center gap-2 py-1",children:[e.jsx(s.Label,{htmlFor:"scale-option",children:"Setup"}),e.jsxs(s.RadioGroup,{disabled:g,id:"scale-option",value:j,onValueChange:M=>b(M),className:"col-span-2 flex gap-3",defaultValue:"x",children:[e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(s.RadioGroupItem,{value:"auto",id:"r1"}),e.jsx("label",{className:"text-sm",htmlFor:"r1",children:"Auto"})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(s.RadioGroupItem,{value:"custom",id:"r2"}),e.jsx("label",{className:"text-sm",htmlFor:"r2",children:"Custom"})]})]})]}),j==="custom"&&i=="linear"&&O(),v(),e.jsx(s.SelectSeparator,{}),e.jsx("div",{className:"grid grid-cols-3",children:e.jsx(s.Button,{onClick:q,variant:"secondary",className:"col-span-1 col-start-3 h-8 w-full",children:"Apply"})})]})]})})]})}function Ot({idx:t}){var c;const n=s.useEditorStore(d=>{var h;return(h=d.card)==null?void 0:h.preferences}),a=s.useEditorStore(d=>{var h;return(h=d.card.preferences)==null?void 0:h.datasetOptions}),r=s.useEditorStore(d=>d.actions.setCardPreferences),o=(c=n==null?void 0:n.chartOptions)==null?void 0:c.indexAxis,i=a==null?void 0:a.find(d=>d.idx===t);function l(d,h){(d==="end"||d==="start")&&s.getContrastColor(s.getCanvasBackgroundColor());const x={display:d!=="none",align:d,anchor:d,clamp:!0};if(!i)r({...n,datasetOptions:[...a||[],{idx:h,datalabels:x}]});else{const j={...i};j.datalabels=x;const b=a==null?void 0:a.map(u=>u.idx===h?j:u);r({...n,datasetOptions:b})}}return e.jsxs(s.Popover,{children:[e.jsx(s.PopoverTrigger,{children:e.jsx(Ps,{className:"invisible size-4 rotate-[135deg] cursor-pointer text-muted-foreground hover:text-foreground group-hover:visible"})}),e.jsx(s.PopoverContent,{className:"w-fit p-1",children:e.jsxs("div",{className:"flex gap-1",children:[e.jsx(s.Button,{onClick:()=>l("none",t),size:"sm",variant:"secondary",className:"h-7 p-1 text-xs font-normal",children:e.jsx(s.X,{className:"size-4"})}),e.jsx(s.Button,{onClick:()=>l("start",t),size:"sm",variant:"secondary",className:"h-7 p-1 text-xs font-normal",children:e.jsx(Ls,{className:s.cn("h-4 w-4",{"rotate-90":o==="y"})})}),e.jsx(s.Button,{onClick:()=>l("center",t),size:"sm",variant:"secondary",className:"h-7 p-1 text-xs font-normal",children:e.jsx(zs,{className:s.cn("h-4 w-4",{"rotate-90":o==="y"})})}),e.jsx(s.Button,{onClick:()=>l("end",t),size:"sm",variant:"secondary",className:"h-7 p-1 text-xs font-normal",children:e.jsx(As,{className:s.cn("h-4 w-4",{"rotate-90":o==="y"})})})]})})]})}function ms(){const t=s.useEditorStore(h=>h.card),n=s.useEditorStore(h=>{var x,j,b;return(b=(j=(x=h==null?void 0:h.card)==null?void 0:x.preferences)==null?void 0:j.chartOptions)==null?void 0:b.indexAxis}),{data:a}=s.useDashboardCardQuery(t),r=n==="y"?"Y axis":"X axis",o=n==="y"?"X axis":"Y axis",{keys:i,metricKeys:l,dimensionKeys:c}=s.getKeys((a==null?void 0:a.records)||[]);let d=l;if(["stackedBar","stackedLine"].includes(t.type)){const h=s.pivotData({dataArray:(a==null?void 0:a.records)||[],groupKey:c[0],pivotKey:c[1],valueKey:d[0]}),{metricKeys:x}=s.getKeys(h);d=x}return i.length===0?null:e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(s.Label,{children:r}),e.jsx("div",{className:"my-1 space-y-1",children:e.jsx("div",{className:"rounded-md bg-muted/70 px-3 py-2 hover:bg-muted",children:e.jsx("p",{title:c[0],children:xs(c[0])})})})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between gap-5",children:[e.jsx(s.Label,{children:o}),e.jsx(hs,{})]}),e.jsx("div",{className:"my-1 max-h-[125px] space-y-1 overflow-y-auto",children:d.map((h,x)=>e.jsx(Mt,{col:h,idx:x},h))})]})]})}function xs(t,n=30){return t.length>n?t.slice(0,n)+"...":t}function Mt({col:t,idx:n}){const a=s.useEditorStore(c=>{var d;return(d=c.card)==null?void 0:d.preferences}),r=s.useEditorStore(c=>{var d;return(d=c.card.preferences)==null?void 0:d.datasetOptions}),o=r==null?void 0:r.find(c=>c.idx===n),{setCardPreferences:i}=s.useEditorStore(c=>c.actions);function l(c){if(!o)i({...a,datasetOptions:[...r||[],{idx:n,type:c==="area"?"line":c,fill:c==="area"?"origin":""}]});else{const d={...o};d.type=c==="area"?"line":c,d.fill=c==="area"?"origin":"";const h=r==null?void 0:r.map(x=>x.idx===n?d:x);i({...a,datasetOptions:h})}}return e.jsxs("div",{className:"group flex items-center justify-between gap-5 rounded-md bg-muted/70 px-3 py-2 hover:bg-muted",children:[e.jsx("p",{title:t,children:xs(t)}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(Ne,{onClick:()=>l("bar"),className:"invisible size-4 cursor-pointer text-muted-foreground hover:text-foreground group-hover:visible"}),e.jsx(we,{onClick:()=>l("line"),className:"invisible size-4 cursor-pointer text-muted-foreground hover:text-foreground group-hover:visible"}),e.jsx(Ss,{onClick:()=>l("area"),className:"invisible size-4 cursor-pointer text-muted-foreground hover:text-foreground group-hover:visible"}),e.jsx(Ot,{idx:n})]})]})}function ps(){const t=s.useEditorStore(u=>u.selectedConnectionId),n=s.useEditorStore(u=>u.selectedDatamodelId),a=s.useEditorStore(u=>u.selectedDatabaseName),r=s.useEditorStore(u=>u.selectedSchemaName),o=s.useEditorStore(u=>u.selectedTableName),i=s.useDashboardStore(u=>u.dashboard.filters)||[],l=s.useDashboardStore(u=>u.actions.addFilter),c=s.useDashboardStore(u=>u.actions.removeFilter),{removeFilterValues:d}=s.useDashboardActions(),{modelItems:h,tableName:x,connectionType:j}=ne();function b(u,p="dashboard"){var B;const f=s.fmt(u.column_name),w=s.fmt(a||""),S=s.fmt(r||""),L=s.fmt(x);let N=s.getQualifiedTableName(S,L,j),k=`${N}.${f}`;const A=(B=h==null?void 0:h.find(F=>F.id===n))==null?void 0:B.name;n&&n!=="none"&&(k=`${s.DATAMODEL_NAMESPCACE}.${A}.${f}`,N=`${s.DATAMODEL_NAMESPCACE}.${A}`);const z=i==null?void 0:i.find(F=>F.column===k&&F.table===L&&(F.database===w||F.database===a));if(z)d(z.id),c(z.id);else{const F=s.v4();return x==="api"&&t?(l({location:p,id:F,column:k,title:u.column_name,dataType:u.data_type,table:"api",database:"",connectionId:t,operation:"in",sql:s.getDefaultFilterSql(u.data_type,N,f)}),F):(l({id:F,location:p,column:k,title:u.column_name,dataType:u.data_type,table:o||"",database:a||"",connectionId:t||"",operation:"in",sql:s.getDefaultFilterSql(u.data_type,N,f)}),F)}}return{assignFilter:b}}function ue(){const t=s.useDashboardStore(c=>c.dashboard.filters),n=s.useEditorStore(c=>c.frame),{setFrame:a}=s.useEditorActions(),{columns:r}=ne(),{assignFilter:o}=ps();function i(c){const d=o(c,"frame");a({...n,filterId:d})}const l=t==null?void 0:t.find(c=>c.id===n.filterId);return e.jsxs("div",{className:"space-y-3",children:[e.jsx(s.Label,{children:"Card Filter"}),e.jsx(Ft,{onSelect:i,columns:r}),l&&e.jsx(s.FilterHeader,{filter:l})]})}function Ft({columns:t,onSelect:n}){var l;const[a,r]=Ve.useState(!1),[o,i]=Ve.useState("");return e.jsxs(s.Popover,{open:a,onOpenChange:r,children:[e.jsx(s.PopoverTrigger,{asChild:!0,children:e.jsxs(s.Button,{size:"sm",variant:"outline",role:"combobox","aria-expanded":a,className:"w-full justify-between font-normal",children:[o?(l=t.find(c=>c.column_name===o))==null?void 0:l.column_name:"Select Column...",e.jsx(s.CaretSortIcon,{className:"ml-2 h-4 w-4 shrink-0 opacity-50"})]})}),e.jsx(s.PopoverContent,{className:"w-[200px] p-0",children:e.jsxs(s.Command,{children:[e.jsx(s.CommandInput,{placeholder:"Search column",className:"h-9"}),e.jsxs(s.CommandList,{children:[e.jsx(s.CommandEmpty,{children:"No framework found."}),e.jsx(s.CommandGroup,{children:t.map(c=>e.jsxs(s.CommandItem,{value:c.column_name,onSelect:d=>{const h=d===o?"":d;i(h),r(!1),h&&n(c)},children:[c.column_name,e.jsx(s.CheckIcon,{className:s.cn("ml-auto h-4 w-4",o===c.column_name?"opacity-100":"opacity-0")})]},c.column_name))})]})]})})]})}function Vt({cardType:t}){return e.jsx("div",{className:"space-y-6 px-6 py-2",children:e.jsxs(s.Accordion,{defaultValue:["item-2"],type:"multiple",children:[e.jsxs(s.AccordionItem,{value:"item-1",children:[e.jsx(s.AccordionTrigger,{children:`${s.titleCase(t)} Chart`}),e.jsxs(s.AccordionContent,{className:"space-y-4 font-mono text-xs",children:[e.jsx("div",{className:"rounded bg-muted px-2 py-1 text-xs",children:"SELECT x-axis, y-axis-1, y-axis-2,... FROM table"}),e.jsxs("ul",{className:"ml-6 list-disc text-xs [&>li]:mt-2",children:[e.jsx("li",{children:"x-axis - category"}),e.jsx("li",{children:"y-axis1 - number"}),e.jsx("li",{children:"y-axis2 - number"})]}),e.jsxs("div",{children:["See ",e.jsx("a",{target:"_blank",onClick:n=>n.stopPropagation(),className:"text-blue-700",href:"https://docs.semaphor.cloud/docs/charts/bar-line-area",children:"example"})," in the docs."]})]})]}),e.jsxs(s.AccordionItem,{value:"item-2",children:[e.jsx(s.AccordionTrigger,{children:"Settings"}),e.jsxs(s.AccordionContent,{className:"space-y-4 px-2",children:[e.jsx(Se,{}),e.jsx(ms,{})]})]}),e.jsxs(s.AccordionItem,{value:"item-3",children:[e.jsx(s.AccordionTrigger,{children:"Filters"}),e.jsxs(s.AccordionContent,{className:"space-y-4 px-2",children:[e.jsx(ie,{}),e.jsx(ue,{})]})]})]})})}function Te(){var o,i,l;const t=s.useEditorStore(c=>c.card.cfg),n=s.useEditorStore(c=>c.actions.setCardCfg),a=s.useEditorStore(c=>c.card.type);function r(c){var x;const d={datalabels:{display:c!=="none",align:c,anchor:c,clamp:!0}},h={...t,options:{...t==null?void 0:t.options,plugins:{...(x=t==null?void 0:t.options)==null?void 0:x.plugins,...d}}};n(h),console.log(c)}return e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("label",{className:"font-medium",children:"Data Labels"}),!["pyramid"].includes(a)&&e.jsx(hs,{})]}),e.jsxs(s.Select,{value:(l=(i=(o=t==null?void 0:t.options)==null?void 0:o.plugins)==null?void 0:i.datalabels)==null?void 0:l.anchor,onValueChange:r,defaultValue:"none",children:[e.jsx(s.SelectTrigger,{className:"h-8 w-full focus:ring-1 focus:ring-offset-0",children:e.jsx(s.SelectValue,{placeholder:"Select position"})}),e.jsx(s.SelectContent,{children:e.jsxs(s.SelectGroup,{children:[e.jsx(s.SelectLabel,{children:"Data Labels"}),e.jsx(s.SelectItem,{value:"none",children:"None"}),a!=="pyramid"&&e.jsx(s.SelectItem,{value:"start",children:"Start"}),e.jsx(s.SelectItem,{value:"center",children:"Center"}),a!=="pyramid"&&e.jsx(s.SelectItem,{value:"end",children:"End"})]})})]})]})}function Rt({cardType:t}){function n(a){return e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"rounded bg-muted px-2 py-1 text-xs",children:a==="bubble"?"SELECT label, [group], x-axis, y-axis, radius FROM table":"SELECT label, [group], x-axis, y-axis FROM table"}),e.jsxs("ul",{className:"ml-6 list-disc text-xs [&>li]:mt-2",children:[e.jsx("li",{children:"label - category"}),e.jsx("li",{children:"group - category"}),e.jsx("li",{children:"x-axis - category"}),e.jsx("li",{children:"y-axis - category"}),a==="bubble"&&e.jsx("li",{children:"radius - number"})]}),e.jsxs("div",{children:["See ",e.jsx("a",{target:"_blank",onClick:i=>i.stopPropagation(),className:"text-blue-700",href:"https://docs.semaphor.cloud/docs/charts/bubble",children:"example"})," in the docs."]})]})}return e.jsx("div",{className:"space-y-6 px-6 py-2",children:e.jsxs(s.Accordion,{defaultValue:["item-2"],type:"multiple",children:[e.jsxs(s.AccordionItem,{value:"item-1",children:[e.jsx(s.AccordionTrigger,{children:`${s.titleCase(t)} Chart`}),e.jsx(s.AccordionContent,{className:"space-y-4 font-mono text-xs",children:n(t)})]}),e.jsxs(s.AccordionItem,{value:"item-2",children:[e.jsx(s.AccordionTrigger,{children:"Settings"}),e.jsx(s.AccordionContent,{className:"px-2",children:e.jsx(Te,{})})]}),e.jsxs(s.AccordionItem,{value:"item-3",children:[e.jsx(s.AccordionTrigger,{children:"Filters"}),e.jsxs(s.AccordionContent,{className:"space-y-4 px-2",children:[e.jsx(ie,{}),e.jsx(ue,{})]})]})]})})}const qt={datasets:[{type:"line",label:"Sum_sales",data:[]},{type:"bar",label:"Sum_profit",data:[]}]},Bt={datasets:[{fill:"origin",type:"line",label:"Sum_sales",data:[]}]};function _t(){const t=s.useEditorStore(n=>n.card.type);return e.jsxs("div",{className:"space-y-6 p-6",children:[e.jsx(s.Accordion,{className:" ",type:"single",collapsible:!0,children:Pt(t)}),e.jsx("section",{className:"",children:["line","bar"].includes(t)&&e.jsx(Se,{})}),!["kpi"].includes(t)&&e.jsxs("div",{className:"space-y-4",children:[e.jsx(Te,{}),e.jsx(ie,{}),e.jsx(ue,{})]})]})}function Pt(t){if(["line","bar"].includes(t))return e.jsxs(e.Fragment,{children:[e.jsxs(s.AccordionItem,{value:"item-1",children:[e.jsx(s.AccordionTrigger,{className:"font-normal",children:e.jsx("p",{children:"Chart Query"})}),e.jsxs(s.AccordionContent,{className:" ",children:[e.jsx("div",{className:"rounded bg-muted px-2 py-1 font-mono text-xs font-semibold",children:"SELECT x-axis, y-axis-1, y-axis-2, y-axis-3,... FROM table"}),e.jsxs("ul",{className:"my-6 ml-6 list-disc text-xs font-normal [&>li]:mt-2",children:[e.jsx("li",{children:"X-axis - Category (ex. city)"}),e.jsx("li",{children:"Y-axis - Number (ex. population)"})]})]})]}),e.jsxs(s.AccordionItem,{value:"item-2",children:[e.jsx(s.AccordionTrigger,{className:"font-normal",children:"Mixed Chart"}),e.jsxs(s.AccordionContent,{className:"space-y-2 text-xs",children:[e.jsxs("p",{children:["Click ",e.jsx("b",{children:"Customize"})," and change the `type` property in the dataset."]}),e.jsx("pre",{children:JSON.stringify(qt,null,2)})]})]}),e.jsxs(s.AccordionItem,{value:"item-3",children:[e.jsx(s.AccordionTrigger,{className:"font-normal",children:"Area Chart"}),e.jsxs(s.AccordionContent,{className:"space-y-2 text-xs",children:[e.jsxs("p",{children:["Click ",e.jsx("b",{children:"Customize"})," and add `fill` property to the dataset. See",e.jsx("a",{className:"mx-1 text-blue-500 hover:underline",href:"https://www.chartjs.org/docs/latest/samples/area/line-boundaries.html",target:"_blank",children:"docs"}),"for more options."]}),e.jsx("pre",{children:JSON.stringify(Bt,null,2)})]})]})]});if(t==="bubble")return e.jsx(e.Fragment,{children:e.jsxs(s.AccordionItem,{value:"item-1",children:[e.jsx(s.AccordionTrigger,{className:"font-normal",children:e.jsxs("p",{children:["How to create a ",e.jsx("span",{children:t})," chart query?"]})}),e.jsxs(s.AccordionContent,{className:" ",children:[e.jsx("div",{className:"rounded bg-muted px-2 py-1 font-mono text-xs font-semibold",children:"SELECT label, x-axis, y-axis, radius FROM table"}),e.jsxs("ul",{className:"my-6 ml-6 list-disc text-xs font-normal [&>li]:mt-2",children:[e.jsx("li",{children:"Label - Category (ex. city)"}),e.jsx("li",{children:"Bubble Group (opt) - Category (ex. state)"}),e.jsx("li",{children:"X-axis - Number (ex. avg. age)"}),e.jsx("li",{children:"Y-axis - Number (ex. avg. weight)"}),e.jsx("li",{children:"Radius - Number (ex. population)"})]})]})]})});if(t==="scatter")return e.jsx(e.Fragment,{children:e.jsxs(s.AccordionItem,{value:"item-1",children:[e.jsx(s.AccordionTrigger,{className:"font-normal",children:e.jsxs("p",{children:["How to create a ",e.jsx("span",{children:t})," chart query?"]})}),e.jsxs(s.AccordionContent,{className:" ",children:[e.jsx("div",{className:"rounded bg-muted px-2 py-1 font-mono text-xs font-semibold",children:"SELECT label, x-axis, y-axis FROM table"}),e.jsxs("ul",{className:"my-6 ml-6 list-disc text-xs font-normal [&>li]:mt-2",children:[e.jsx("li",{children:"Label - Category (ex. city)"}),e.jsx("li",{children:"Group (opt) - Category (ex. state)"}),e.jsx("li",{children:"X-axis - Number (ex. avg. age)"}),e.jsx("li",{children:"Y-axis - Number (ex. avg. weight)"})]})]})]})});if(["pie","doughnut","polarArea"].includes(t))return e.jsx(e.Fragment,{children:e.jsxs(s.AccordionItem,{value:"item-1",children:[e.jsx(s.AccordionTrigger,{className:"font-normal",children:e.jsxs("p",{children:[e.jsx("span",{children:t==="polarArea"?"Polar":t.charAt(0).toUpperCase()+t.slice(1)})," ","chart query"]})}),e.jsxs(s.AccordionContent,{className:" ",children:[e.jsx("div",{className:"rounded bg-muted px-2 py-1 font-mono text-xs font-semibold",children:"SELECT label, measure FROM table"}),e.jsxs("ul",{className:"my-6 ml-6 list-disc text-xs font-normal [&>li]:mt-2",children:[e.jsx("li",{children:"Label - Category (ex. city)"}),e.jsx("li",{children:"Measure - Number (ex. population)"})]})]})]})})}function Ht(){var d,h,x,j,b;const t=s.useEditorStore(u=>u.card.preferences),n=s.useEditorStore(u=>u.actions.setCardPreferences),a=s.useEditorStore(u=>u.actions.setNumberFormat);s.useEditorStore(u=>{var p,f;return(f=(p=u.card.preferences)==null?void 0:p.formatNumber)==null?void 0:f.decimalPlaces});const r=s.useEditorStore(u=>{var p,f;return(f=(p=u.card.preferences)==null?void 0:p.formatNumber)==null?void 0:f.locale}),o=s.useEditorStore(u=>{var p,f;return(f=(p=u.card.preferences)==null?void 0:p.formatNumber)==null?void 0:f.currency});s.useEditorStore(u=>u.actions.setFilterOnClickField);const i=s.useEditorStore(u=>{var p,f;return(f=(p=u.card.preferences)==null?void 0:p.formatNumber)==null?void 0:f.colorRanges})||[],l=s.useEditorStore(u=>u.actions.setColorRanges),c=[...new Set(s.LOCALE_CURRENCY_PAIRS.map(u=>u.currency))];return e.jsxs("div",{children:[e.jsxs("div",{className:"mb-3 flex items-center gap-2",children:[e.jsx(s.Checkbox,{checked:!!((d=t==null?void 0:t.formatNumber)!=null&&d.enabled),onCheckedChange:u=>{n({...t,formatNumber:{...t==null?void 0:t.formatNumber,enabled:u}})}}),e.jsx(s.Label,{children:"Format Number"})]}),((h=t==null?void 0:t.formatNumber)==null?void 0:h.enabled)===!0&&e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsx("div",{children:e.jsxs("div",{className:"space-y-4 p-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("div",{className:"w-full space-y-1",children:[e.jsx(s.Label,{children:"Locale"}),e.jsxs(s.Select,{value:r||"none",onValueChange:u=>{var p,f,w;return a(((p=t==null?void 0:t.formatNumber)==null?void 0:p.decimalPlaces)||0,((f=t==null?void 0:t.formatNumber)==null?void 0:f.currency)||"",u,((w=t==null?void 0:t.formatNumber)==null?void 0:w.suffix)||"")},children:[e.jsx(s.SelectTrigger,{className:"col-span-6 h-8 w-full focus:ring-1 focus:ring-offset-0",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{children:e.jsxs(s.SelectGroup,{children:[e.jsx(s.SelectLabel,{children:"Format"}),e.jsx(s.SelectItem,{value:"none",children:"None"},"none"),s.LOCALE_CURRENCY_PAIRS.map(u=>e.jsx(s.SelectItem,{value:u.locale,children:u.locale},u.locale))]})})]})]}),e.jsxs("div",{className:"w-full space-y-1",children:[e.jsx(s.Label,{children:"Currency"}),e.jsxs(s.Select,{value:o||"none",onValueChange:u=>{var p,f,w;console.log("currency",u),a(((p=t==null?void 0:t.formatNumber)==null?void 0:p.decimalPlaces)||0,u==="none"?"":u,((f=t==null?void 0:t.formatNumber)==null?void 0:f.locale)||"",((w=t==null?void 0:t.formatNumber)==null?void 0:w.suffix)||"")},children:[e.jsx(s.SelectTrigger,{className:"col-span-6 h-8 w-full focus:ring-1 focus:ring-offset-0",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{children:e.jsxs(s.SelectGroup,{children:[e.jsx(s.SelectLabel,{children:"Currency"}),e.jsx(s.SelectItem,{value:"none",children:"None"},"none"),c.map(u=>e.jsx(s.SelectItem,{value:u,children:u},u))]})})]})]})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs("div",{className:"w-full space-y-1",children:[e.jsx(s.Label,{children:"Decimals"}),e.jsxs(s.Select,{value:((j=(x=t==null?void 0:t.formatNumber)==null?void 0:x.decimalPlaces)==null?void 0:j.toString())||"0",onValueChange:u=>{var p,f,w;return a(Number(u),((p=t==null?void 0:t.formatNumber)==null?void 0:p.currency)||"",((f=t==null?void 0:t.formatNumber)==null?void 0:f.locale)||"",((w=t==null?void 0:t.formatNumber)==null?void 0:w.suffix)||"")},children:[e.jsx(s.SelectTrigger,{className:"col-span-3 h-8 w-full focus:ring-1 focus:ring-offset-0",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{children:["0","1","2","3","4"].map(u=>e.jsx(s.SelectItem,{value:u,children:u},u))})]})]}),e.jsxs("div",{className:"w-full space-y-1",children:[e.jsx(s.Label,{children:"Suffix"}),e.jsx(s.Input,{value:((b=t==null?void 0:t.formatNumber)==null?void 0:b.suffix)||"",className:"h-8 font-mono text-xs focus-visible:ring-0 focus-visible:ring-ring focus-visible:ring-offset-0",placeholder:"K, M, B, %",onChange:u=>{var p,f,w;return a(((p=t==null?void 0:t.formatNumber)==null?void 0:p.decimalPlaces)||0,((f=t==null?void 0:t.formatNumber)==null?void 0:f.currency)||"",((w=t==null?void 0:t.formatNumber)==null?void 0:w.locale)||"",u.target.value)}})]})]})]})}),e.jsx(s.Separator,{className:"my-3"}),e.jsx(s.ColorFormat,{colorRanges:i,setColorRanges:l})]})]})}function Gt(){return e.jsxs("div",{className:"space-y-6 px-6 py-2",children:[e.jsx(s.Accordion,{type:"single",collapsible:!0,children:e.jsxs(s.AccordionItem,{value:"item-1",children:[e.jsx(s.AccordionTrigger,{className:"",children:"KPI Query"}),e.jsxs(s.AccordionContent,{className:"font-mono",children:[e.jsx("div",{className:"rounded bg-muted px-2 py-1 font-mono text-xs",children:"SELECT current, previous FROM table"}),e.jsxs("ul",{className:"my-6 ml-6 list-disc text-xs [&>li]:mt-2",children:[e.jsx("li",{children:"current - number"}),e.jsx("li",{children:"previous - number"})]}),e.jsxs("div",{children:["See ",e.jsx("a",{target:"_blank",onClick:t=>t.stopPropagation(),className:"text-blue-700",href:"https://docs.semaphor.cloud/docs/charts/kpi",children:"example"})," in the docs."]})]})]})}),e.jsx("section",{className:"",children:e.jsx(Ht,{})}),e.jsx("div",{}),e.jsx("div",{})]})}const Ut=[{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"}],$t=["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"],Qt=$t.map(t=>({label:t,value:t}));function Jt(){var d,h,x,j,b,u,p,f,w,S,L,N,k,A,z,B,F,_;const t=s.useEditorStore(m=>m.card),n=(h=(d=t==null?void 0:t.preferences)==null?void 0:d.mapVisualOptions)==null?void 0:h.topoJsonUrl,[a,r]=y.useState(((j=(x=t==null?void 0:t.preferences)==null?void 0:x.mapVisualOptions)==null?void 0:j.customTopoJsonUrl)||""),{setCardPreferences:o}=s.useEditorActions(),{data:i}=s.useTopoJson(t),l=Object.keys((i==null?void 0:i.objects)||{}).map(m=>({label:m,value:m}))||[],c=[{label:"US States 10m",value:"https://unpkg.com/us-atlas/states-10m.json"},{label:"Countries 50m",value:"https://unpkg.com/world-atlas/countries-50m.json"},{label:"Custom",value:"custom"}];return e.jsxs("div",{className:"p-6",children:[e.jsx(me,{summary:"Map Query",children:e.jsx("p",{className:"rounded-md bg-muted p-2 font-mono text-xs",children:"SELECT country, value FROM table"})}),e.jsx(s.Separator,{className:"my-4"}),e.jsx(me,{open:!0,summary:"Settings",children:e.jsxs("div",{className:"space-y-3 px-2",children:[e.jsx(ae,{className:"h-9",options:c,onValueChange:m=>{console.log("value",m),o({...t.preferences,mapVisualOptions:{topoJsonUrl:m}})},value:n||"",label:"Select Map"}),n==="custom"&&e.jsx(s.Input,{onChange:m=>{r(m.target.value)},onBlur:()=>{var m;console.log("onBlur",a),o({...t.preferences,mapVisualOptions:{...(m=t.preferences)==null?void 0:m.mapVisualOptions,customTopoJsonUrl:a}})},value:a,className:`h-9 w-full ${s.removeRing}`,placeholder:"Custom URL"}),i&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(s.Label,{children:"Map Object"}),e.jsx(ae,{className:"h-9",options:l,value:((u=(b=t.preferences)==null?void 0:b.mapVisualOptions)==null?void 0:u.objectKey)||"",label:"Map Object",onValueChange:m=>{var g;o({...t.preferences,mapVisualOptions:{...(g=t.preferences)==null?void 0:g.mapVisualOptions,objectKey:m}})}})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(s.Label,{children:"Projection"}),e.jsx(ae,{className:"h-9",options:Ut,value:((f=(p=t.preferences)==null?void 0:p.mapVisualOptions)==null?void 0:f.projection)||"",label:"Projection",onValueChange:m=>{var g;o({...t.preferences,mapVisualOptions:{...(g=t.preferences)==null?void 0:g.mapVisualOptions,projection:m}})}})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(s.Label,{children:"Colors"}),e.jsx(ae,{className:"h-9",options:Qt,value:((S=(w=t.preferences)==null?void 0:w.mapVisualOptions)==null?void 0:S.colorScale)||"",label:"Select Color Scale",onValueChange:m=>{var g;o({...t.preferences,mapVisualOptions:{...(g=t.preferences)==null?void 0:g.mapVisualOptions,colorScale:m}})}})]})]})]})}),e.jsx(s.Separator,{className:"my-4"}),e.jsx(me,{className:"",summary:"Scale Options",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(s.Input,{className:`h-9 w-full ${s.removeRing}`,type:"number",step:.1,value:((N=(L=t.preferences)==null?void 0:L.mapVisualOptions)==null?void 0:N.projectionScale)||1,onChange:m=>{var g;o({...t.preferences,mapVisualOptions:{...(g=t.preferences)==null?void 0:g.mapVisualOptions,projectionScale:Number(m.target.value)}})}}),e.jsx(s.Label,{children:"X"}),e.jsx(s.Input,{className:`h-9 w-full ${s.removeRing}`,type:"number",step:10,value:((z=(A=(k=t.preferences)==null?void 0:k.mapVisualOptions)==null?void 0:A.projectionOffset)==null?void 0:z[0])||0,onChange:m=>{var g,D,v,O;o({...t.preferences,mapVisualOptions:{...(g=t.preferences)==null?void 0:g.mapVisualOptions,projectionOffset:[Number(m.target.value),((O=(v=(D=t.preferences)==null?void 0:D.mapVisualOptions)==null?void 0:v.projectionOffset)==null?void 0:O[1])||0]}})}}),e.jsx(s.Label,{children:"Y"}),e.jsx(s.Input,{className:`h-9 w-full ${s.removeRing}`,type:"number",step:10,value:((_=(F=(B=t.preferences)==null?void 0:B.mapVisualOptions)==null?void 0:F.projectionOffset)==null?void 0:_[1])||0,onChange:m=>{var g,D,v,O;o({...t.preferences,mapVisualOptions:{...(g=t.preferences)==null?void 0:g.mapVisualOptions,projectionOffset:[((O=(v=(D=t.preferences)==null?void 0:D.mapVisualOptions)==null?void 0:v.projectionOffset)==null?void 0:O[0])||0,Number(m.target.value)]}})}})]})}),e.jsx(s.Separator,{className:"my-4"}),e.jsx(ie,{})]})}function Wt(){var r;const t=s.useEditorStore(o=>o.card.preferences),{setCardPreferences:n}=s.useEditorStore(o=>o.actions);function a(o){n({...t,textVisualOptions:{...t==null?void 0:t.textVisualOptions,isDynamicText:o==="dynamic"}})}return e.jsxs(s.RadioGroup,{value:(r=t==null?void 0:t.textVisualOptions)!=null&&r.isDynamicText?"dynamic":"static",onValueChange:a,className:"flex gap-3",defaultValue:"x",children:[e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(s.RadioGroupItem,{value:"static",id:"r1"}),e.jsx("label",{className:"text-sm",htmlFor:"r1",children:"Static"})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(s.RadioGroupItem,{value:"dynamic",id:"r2"}),e.jsx("label",{className:"text-sm",htmlFor:"r2",children:"Dynamic"})]})]})}function ge({cardType:t,docContent:n,suffix:a="Chart"}){return e.jsx("div",{className:"space-y-6 px-6 py-2",children:e.jsxs(s.Accordion,{defaultValue:["item-2"],type:"multiple",children:[e.jsxs(s.AccordionItem,{value:"item-1",children:[e.jsx(s.AccordionTrigger,{children:`${s.titleCase(t)} ${a}`}),e.jsx(s.AccordionContent,{children:n||e.jsxs("div",{className:"space-y-4 font-mono text-xs",children:[e.jsx("div",{className:"rounded bg-muted px-2 py-1 text-xs",children:"SELECT label, measure FROM table"}),e.jsxs("ul",{className:"ml-6 list-disc text-xs [&>li]:mt-2",children:[e.jsx("li",{children:"label - category"}),e.jsx("li",{children:"measure - number"})]}),e.jsxs("div",{children:["See ",e.jsx("a",{target:"_blank",onClick:r=>r.stopPropagation(),className:"text-blue-700",href:"https://docs.semaphor.cloud/docs/charts/pie-donut-polar",children:"example"})," in the docs."]})]})})]}),e.jsxs(s.AccordionItem,{value:"item-2",children:[e.jsx(s.AccordionTrigger,{children:"Settings"}),e.jsxs(s.AccordionContent,{className:"space-y-4 px-2",children:[t==="range"&&e.jsx(Se,{}),t!=="text"&&e.jsx(Te,{}),t==="text"&&e.jsx(Wt,{})]})]}),!["range","text"].includes(t)&&e.jsxs(s.AccordionItem,{value:"item-3",children:[e.jsx(s.AccordionTrigger,{children:"Filters"}),e.jsxs(s.AccordionContent,{className:"space-y-4 px-2",children:[e.jsx(ie,{}),e.jsx(ue,{})]})]})]})})}function Kt(){const t=s.useEditorStore(r=>{var o,i;return(i=(o=r==null?void 0:r.card)==null?void 0:o.preferences)==null?void 0:i.sortChart}),{setSortChart:n}=s.useEditorActions();function a(){return e.jsxs("div",{className:"space-y-2",children:[e.jsx(s.Label,{children:"Sort"}),e.jsx(ae,{className:"h-8",label:"Sort Chart",options:[{label:"None",value:"none"},{label:"ASC",value:"asc"},{label:"DESC",value:"desc"}],value:t||"none",onValueChange:r=>{n(r)}})]})}return e.jsx("div",{className:"space-y-6 px-6 py-2",children:e.jsxs(s.Accordion,{defaultValue:["item-2"],type:"multiple",children:[e.jsxs(s.AccordionItem,{value:"item-1",children:[e.jsx(s.AccordionTrigger,{children:"Stacked Chart"}),e.jsxs(s.AccordionContent,{className:"space-y-4 font-mono text-xs",children:[e.jsx("div",{className:"rounded bg-muted px-2 py-1 text-xs",children:"SELECT x-axis, stack-by, y-axis FROM table"}),e.jsxs("ul",{className:"ml-6 list-disc text-xs [&>li]:mt-2",children:[e.jsx("li",{children:"x-axis - category"}),e.jsx("li",{children:"stack by - category"}),e.jsx("li",{children:"y-axis - number"})]}),e.jsxs("div",{children:["See ",e.jsx("a",{target:"_blank",onClick:r=>r.stopPropagation(),className:"text-blue-700",href:"https://docs.semaphor.cloud/docs/charts/stacked",children:"example"})," in the docs."]})]})]}),e.jsxs(s.AccordionItem,{value:"item-2",children:[e.jsx(s.AccordionTrigger,{children:"Settings"}),e.jsxs(s.AccordionContent,{className:"space-y-4 px-2",children:[e.jsx(Se,{}),a(),e.jsx(ms,{})]})]}),e.jsxs(s.AccordionItem,{value:"item-3",children:[e.jsx(s.AccordionTrigger,{children:"Filters"}),e.jsxs(s.AccordionContent,{className:"space-y-4 px-2",children:[e.jsx(ie,{}),e.jsx(ue,{})]})]})]})})}function Zt({}){const t=s.useEditorStore(r=>{var o;return(o=r.card)==null?void 0:o.preferences}),n=s.useEditorStore(r=>r.actions.setCardPreferences),a=r=>{n({...t,allowDownload:r})};return e.jsxs("div",{className:"space-y-6 px-6 py-2",children:[e.jsx(s.Accordion,{defaultValue:["item-3"],type:"multiple",children:e.jsxs(s.AccordionItem,{value:"item-3",children:[e.jsx(s.AccordionTrigger,{children:"Filters"}),e.jsxs(s.AccordionContent,{className:"space-y-4 px-2",children:[e.jsx(ie,{}),e.jsx(ue,{})]})]})}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(s.Checkbox,{onCheckedChange:a,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 Xt=e.jsxs("div",{className:"space-y-4 font-mono text-xs",children:[e.jsx("div",{className:"rounded bg-muted px-2 py-1 text-xs",children:"SELECT dimension, cohort, metric FROM table"}),e.jsxs("div",{children:["See ",e.jsx("a",{target:"_blank",onClick:t=>t.stopPropagation(),className:"text-blue-700",href:"https://docs.semaphor.cloud/docs/charts/tornado",children:"example"})," in the docs."]})]}),Yt=e.jsxs("div",{className:"space-y-4 font-mono text-xs",children:[e.jsx("div",{className:"rounded bg-muted px-2 py-1 text-xs",children:"SELECT y-axis, label, range-from, range-to, range-value FROM table"}),e.jsxs("div",{children:["See ",e.jsx("a",{target:"_blank",onClick:t=>t.stopPropagation(),className:"text-blue-700",href:"https://docs.semaphor.cloud/docs/charts/range",children:"example"})," in the docs."]})]}),ea=e.jsxs("div",{className:"space-y-4 font-mono text-xs",children:[e.jsx("div",{className:"rounded bg-muted px-2 py-1 text-xs",children:"SELECT text FROM table limit 1"}),e.jsxs("div",{children:["See ",e.jsx("a",{target:"_blank",onClick:t=>t.stopPropagation(),className:"text-blue-700",href:"https://docs.semaphor.cloud/docs/charts/text",children:"example"})," in the docs."]})]});function sa(){const t=s.useEditorStore(a=>a.card.type);function n(a){switch(a){case"stackedBar":case"stackedLine":return e.jsx(Kt,{});case"pyramid":return e.jsx(ge,{docContent:Xt,cardType:a});case"kpi":return e.jsx(Gt,{});case"line":case"bar":return e.jsx(Vt,{cardType:a});case"range":return e.jsx(ge,{docContent:Yt,cardType:a});case"pie":case"doughnut":case"polarArea":case"radar":return e.jsx(ge,{cardType:a});case"bubble":case"scatter":return e.jsx(Rt,{cardType:a});case"table":return e.jsx(Zt,{cardType:a});case"text":return e.jsx(ge,{docContent:ea,cardType:a,suffix:"Visual"});case"map":return e.jsx(Jt,{});case"custom":return e.jsx(zt,{});default:return e.jsx(_t,{})}}return e.jsxs(s.ScrollArea,{className:"h-full w-full text-sm",children:[n(t),e.jsx(s.ScrollBar,{orientation:"horizontal"})]})}function ta(){const t=s.useEditorStore(n=>n.isShowingVisual);return e.jsxs(s.ResizablePanelGroup,{direction:"vertical",className:"min-h-[250px] min-w-full max-w-lg",children:[e.jsx(s.ResizablePanel,{role:"query-section",className:"flex",minSize:20,defaultSize:40,children:e.jsx(gt,{})}),e.jsx(s.ResizableHandle,{withHandle:!0,className:"border"}),e.jsx(s.ResizablePanel,{className:"pb-1",role:"visual-section",minSize:0,defaultSize:60,children:t?e.jsxs(s.ResizablePanelGroup,{direction:"horizontal",children:[e.jsx(e.Fragment,{children:e.jsx(s.ResizablePanel,{className:"flex min-w-[275px]",minSize:20,defaultSize:25,maxSize:30,children:e.jsx(sa,{})})}),e.jsx(s.ResizableHandle,{className:"border"}),e.jsx(s.ResizablePanel,{minSize:40,defaultSize:75,maxSize:100,children:e.jsx(_e,{})})]}):e.jsx(_e,{})})]})}function aa({authToken:t,onSave:n,onClose:a}){s.useDashboardStore(l=>l.themeStyle);const r=s.useEditorStore(l=>l.actions.setOnSave),o=s.useEditorStore(l=>l.actions.setOnClose),i=s.useDashboardStore(l=>l.actions.setAuthToken);return y.useEffect(()=>{n&&r(n),a&&o(a)},[n,r,a,o]),y.useEffect(()=>{t&&t.accessToken&&i(t)},[t,i]),e.jsx(s.ErrorBoundary,{FallbackComponent:s.Fallback,children:e.jsxs(s.EditorPanel,{style:{},className:"rounded-none",role:"editor-panel",children:[e.jsx(s.EditorAside,{className:"rounded-none border-r-[1.5px]",children:e.jsx(Ze,{})}),e.jsx(s.EditorMain,{children:e.jsx(ta,{})})]})})}function na(){s.useDashboardStore(l=>l.selectedCardId);const t=s.useDashboardStore(l=>l.selectedSheetId),{setIsVisualEditing:n}=s.useDashboardStore(l=>l.actions),a=s.useDashboardStore(l=>l.isVisualEditing),r=s.useDashboardStore(l=>l.actions.updateFrame);function o(l){t&&(r(t,l),n(!1))}function i(){n(!1)}return e.jsx("div",{role:"editor-container",className:s.cn("flex grow",{"max-h-0 overflow-hidden":!a}),children:e.jsx(aa,{onSave:o,onClose:i})})}function ra(){const t=s.useEditorStore(i=>i.selectedDatabaseName),n=s.useEditorStore(i=>i.selectedTableName),a=s.useDashboardStore(i=>i.dashboard.filters)||[],{columns:r}=ne(),{assignFilter:o}=ps();return e.jsx(s.ScrollArea,{className:"flex-1 basis-0 flex-col px-3",children:r==null?void 0:r.map(i=>{const l=a==null?void 0:a.find(c=>c.column===s.fmt(i.column_name)&&c.table===n&&c.database===t);return e.jsx("div",{onClick:()=>o(i),className:s.cn("group flex cursor-pointer items-center justify-between border border-dashed border-background px-3 py-[6px] text-sm transition-colors hover:bg-muted/50",{"bg-muted":l}),children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Ke,{column:i}),e.jsx("span",{children:i.column_name})]})},i.column_name)})})}function oa(){s.useDashboardStore(n=>n.showFilters);const t=s.useDashboardStore(n=>n.actions.setShowFilters);return e.jsxs("section",{className:"relative flex min-w-[320px] grow flex-col border-l px-1",children:[e.jsxs("div",{className:"mt-4 flex items-center justify-between gap-2 px-3",children:[e.jsx(s.Label,{className:"px-2 text-lg",children:"Filters"}),e.jsx(s.Button,{onClick:()=>t(!1),className:"h-7 w-7 p-0",variant:"ghost",children:e.jsx(s.Cross2Icon,{})})]}),e.jsx("div",{className:"flex grow",children:e.jsx(Ze,{ColumnsComponent:()=>e.jsx(ra,{})})})]})}function ia(){const t=s.useDashboardStore(r=>r.dashboard.filters),n=s.useDashboardStore(r=>r.theme),a=t==null?void 0:t.filter(r=>r.hide);return a!=null&&a.length?e.jsx("div",{className:s.cn("mb-1 flex items-center gap-2 border-y px-0.5 pb-0.5",{"bg-[repeating-linear-gradient(45deg,_#ffffff_0_3px,_#f3f3f3_3px_6px)]":n==="light","bg-[repeating-linear-gradient(45deg,_#18171d_0_3px,_#272729_3px_6px)]":n==="dark"}),children:a==null?void 0:a.map(r=>e.jsxs("div",{className:"flex min-w-[250px] max-w-fit flex-col gap-1 p-2",children:[e.jsx(s.FilterHeader,{filter:r}),e.jsx(s.FilterComponent,{filter:r})]},r.id))}):null}function la(){const t=s.useDashboardStore(r=>r.showFilters),n=s.useDashboardStore(r=>r.isVisualEditing),a=s.useDashboardStore(r=>r.isDashboardEditing);return e.jsxs("div",{role:"dashboard-plus-main",className:s.cn("",{"max-h-0 overflow-hidden":n,"flex grow overflow-auto":!n}),children:[e.jsxs("section",{className:"flex grow flex-col",children:[a&&e.jsx(ia,{}),e.jsx(s.DashboardTabs,{})]}),t&&e.jsx("div",{role:"filter-aside-container",className:"flex",children:e.jsx(oa,{})})]})}function ca(){const t=s.useDashboardStore(o=>o.dashboard),n=s.useDashboardStore(o=>o.actions.setDashboard),a=s.useDashboardStore(o=>o.showDashboardJSON),r=s.useDashboardStore(o=>o.actions.setShowDashboardJSON);return e.jsxs("div",{className:s.cn("relative p-2",{hidden:!a}),children:[e.jsxs(s.Button,{variant:"secondary",size:"sm",className:"absolute right-2 top-2 z-10 h-8",onClick:()=>r(!1),children:[e.jsx(s.X,{className:"mr-2 h-4 w-4"}),"Close"]}),e.jsx(s.de,{onChange:o=>{if(o)try{JSON.parse(o),n(JSON.parse(o))}catch{}},defaultLanguage:"json",className:"h-[550px] overflow-y-auto",value:JSON.stringify(t,null,2),options:{minimap:{enabled:!1},glyphMargin:!1,wordWrap:"on",scrollbar:{verticalScrollbarSize:0,horizontalScrollbarSize:0},fontSize:12,renderLineHighlight:"none"}})]})}function da({showControls:t=!1,showFooter:n=!0,...a}){return e.jsx(s.ErrorBoundary,{FallbackComponent:s.Fallback,children:e.jsxs(s.SemaphorContextProvider,{dashboardProps:a,children:[e.jsx(s.$e,{}),e.jsxs(s.UXProvider,{children:[e.jsx(ca,{}),e.jsxs(s.DashboardPanel,{...a,children:[t&&e.jsx(Zs,{}),e.jsx(na,{}),e.jsx(la,{})]})]})]})})}exports.Dashboard=s.Dashboard;exports.DashboardWC=s.DashboardWC;exports.SemaphorDataProvider=s.SemaphorQueryClient;exports.SemaphorQueryClient=s.SemaphorQueryClient;exports.createSqlGenConfig=s.createSqlGenConfig;exports.fmt=s.fmt;exports.getColumnDataType=s.getColumnDataType;exports.getFilterValueType=s.getFilterValueType;exports.getFormattedTableNameForQuery=s.getFormattedTableNameForQuery;exports.getQualifiedTableName=s.getQualifiedTableName;exports.getSql=s.getSql;exports.invalidateToken=s.invalidateToken;exports.isBooleanDataType=s.isBooleanDataType;exports.isColumnInSqlGen=s.isColumnInSqlGen;exports.isDateDataType=s.isDateDataType;exports.isNumberDataType=s.isNumberDataType;exports.isTextDataType=s.isTextDataType;exports.resolveDataType=s.resolveDataType;exports.useCard=s.useCard;exports.useDashboardActions=s.useDashboardActions;exports.useDashboardStore=s.useDashboardStore;exports.useDateFilterHook=s.useDateFilterHook;exports.useEditorActions=s.useEditorActions;exports.useEditorStore=s.useEditorStore;exports.useTextFilterHook=s.useTextFilterHook;exports.SelectComponent=de;exports.Surfboard=da;exports.cleanCard=Je;exports.downloadPdf=We;exports.getDashbaordStateWithoutData=Ie;exports.useEditorAside=ne;
|
|
191
|
+
*/const De=s.createLucideIcon("Type",[["polyline",{points:"4 7 4 4 20 4 20 7",key:"1nosan"}],["line",{x1:"9",x2:"15",y1:"20",y2:"20",key:"swin9y"}],["line",{x1:"12",x2:"12",y1:"4",y2:"20",key:"1tx1rr"}]]);function Ie(t){var n;return{...t,sheets:(n=t==null?void 0:t.sheets)==null?void 0:n.map(a=>{var r;return{...a,frames:(r=a.frames)==null?void 0:r.map(o=>{var i;return{...o,cards:(i=o.cards)==null?void 0:i.map(l=>Je(l))}})}})}}function Je(t){var n,a,r,o;return{...t,cfg:{...t.cfg,data:{...(n=t.cfg)==null?void 0:n.data,labels:[],datasets:(o=(r=(a=t.cfg)==null?void 0:a.data)==null?void 0:r.datasets)==null?void 0:o.map(i=>({...i,data:[]}))}},customCfg:Us(t.customCfg),data:[]}}function Us(t){var n,a;return t?{...t,data:{...t==null?void 0:t.data,labels:[],datasets:(a=(n=t==null?void 0:t.data)==null?void 0:n.datasets)==null?void 0:a.map(r=>({...r,data:[]}))}}:null}async function $s(t,n,a,r){if(!r)return null;const o=JSON.stringify(n);return await s.postRequest("https://semaphor.cloud/api/v1/lens",r,{name:t,template:o,filterValues:a,operation:"create"})}async function Ce(t,n){if(!n)return null;const{id:a,template:r,filterValues:o,isDefault:i,shared:l}=t;return await s.postRequest("https://semaphor.cloud/api/v1/lens",n,{lensId:a,template:r,filterValues:o,isDefault:i,shared:l,operation:"update"})}async function Qs(t,n){return n?await s.postRequest("https://semaphor.cloud/api/v1/lens",n,{operation:"delete",lensId:t}):null}function Js(){const[t,n]=y.useState(""),[a,r]=y.useState(!1),o=s.useDashboardStore(f=>f.lenses),{setLenses:i,setSelectedLensId:l}=s.useDashboardActions(),[c,d]=y.useState(!1),[h,x]=y.useState(!1),j=s.useDashboardStore(f=>f.dashboard),b=s.useDashboardStore(f=>f.filterValues),{authToken:u}=s.useSemaphorContext();async function p(){d(!0);const f=Ie(j),w=await $s(t,f,b,u==null?void 0:u.accessToken);w&&(i([...o||[],w]),l(w.id),x(!1)),d(!1)}return e.jsxs(s.Dialog,{open:h,onOpenChange:x,children:[e.jsx(s.DialogTrigger,{asChild:!0,children:e.jsxs(s.Button,{variant:"secondary",className:"h-7 p-2",size:"sm",children:[e.jsx(s.Plus,{className:"mr-2 h-4 w-4",strokeWidth:1.5}),"Lens"]})}),e.jsxs(s.DialogContent,{className:"sm:max-w-[425px]",children:[e.jsxs(s.DialogHeader,{children:[e.jsx(s.DialogTitle,{children:"Create Lens"}),e.jsx(s.DialogDescription,{children:"Lenses are private by default and are only visible to you."})]}),e.jsx("div",{className:"grid gap-4 py-4",children:e.jsxs("div",{className:"grid grid-cols-8 items-center gap-4",children:[e.jsx(s.Label,{className:"text-right",children:"Name"}),e.jsx(s.Input,{value:t,onChange:f=>{n(f.target.value)},id:"name",className:"col-span-7 focus-visible:ring-0 focus-visible:ring-ring focus-visible:ring-offset-0"})]})}),a&&e.jsx("p",{className:"text-sm",children:"The lens name already exists. Use a differnet name."}),e.jsx(s.DialogFooter,{children:e.jsx(s.Button,{size:"sm",variant:"outline",type:"submit",onClick:p,disabled:c,children:c?"Creating...":"Add"})})]})]})}function Ws(){const[t,n]=y.useState(!1),a=s.useDashboardStore(x=>x.lenses),r=s.useDashboardStore(x=>x.selectedLensId),{setLenses:o,setSelectedLensId:i}=s.useDashboardActions(),{authToken:l}=s.useSemaphorContext();async function c(x){i(x)}async function d(x){if(await Qs(x,l==null?void 0:l.accessToken)){const b=a==null?void 0:a.filter(u=>u.id!==x);o(b||[]),i("original")}}async function h(x){const j=a==null?void 0:a.map(p=>p.id===x.id?{...p,isDefault:!x.isDefault}:{...p,isDefault:!1});o(j||[]);const b={...x,isDefault:!x.isDefault};await Ce(b,l==null?void 0:l.accessToken);const u=a==null?void 0:a.find(p=>p.isDefault);if(u&&u.id!==x.id){const p={...u,isDefault:!1};await Ce(p,l==null?void 0:l.accessToken)}}return e.jsxs(s.DropdownMenu,{open:t,onOpenChange:n,children:[e.jsx(s.DropdownMenuTrigger,{asChild:!0,children:e.jsx(s.Button,{variant:"ghost",className:"h-7 p-2",children:e.jsx(Es,{className:"h-4 w-4",strokeWidth:1.5})})}),e.jsxs(s.DropdownMenuContent,{align:"end",className:"w-60",children:[e.jsx(s.DropdownMenuLabel,{className:"px-3",children:"Lenses"}),e.jsx(s.DropdownMenuSeparator,{}),e.jsxs(s.DropdownMenuRadioGroup,{value:r,onValueChange:c,children:[e.jsx(s.DropdownMenuRadioItem,{value:"original",children:"Original"}),a==null?void 0:a.map(x=>e.jsxs(s.DropdownMenuRadioItem,{className:"group flex justify-between gap-2",value:x.id,children:[e.jsx("p",{children:x.name}),e.jsxs("span",{className:"flex items-center gap-3",children:[e.jsx(Ts,{onClick:j=>{j.preventDefault(),h(x)},className:s.cn("size-3.5 text-muted-foreground hover:cursor-pointer hover:text-foreground group-hover:visible",{invisible:!x.isDefault,"text-green-500":x.isDefault}),strokeWidth:1.5}),e.jsx(s.Cross2Icon,{onClick:j=>{j.preventDefault(),d(x.id)},className:"invisible size-3.5 text-muted-foreground hover:cursor-pointer hover:text-foreground group-hover:visible",strokeWidth:1.5})]})]},x.id))]})]})]})}async function We(){var u;const t=s.useDashboardStore.getState().authToken,n=s.useDashboardStore.getState().theme,a=s.useDashboardStore.getState().filterValues,r=(u=s.useDashboardStore.getState().dashboard)==null?void 0:u.title,o=s.useDashboardStore.getState().isDownloadingPdf,i=s.useDashboardStore.getState().selectedSheetId;if(o)return;const l=new URLSearchParams;l.set("token",(t==null?void 0:t.accessToken)||""),l.set("theme",n||"light"),l.set("filterValues",JSON.stringify(a)),l.set("selectedSheetId",i||"");const c=`https://semaphor.cloud/api/v1/generate-pdf?params=${encodeURIComponent(l.toString())}`;s.useDashboardStore.setState({isDownloadingPdf:!0});const x=(await(await fetch(c,{method:"GET",headers:{Authorization:`Bearer ${t==null?void 0:t.accessToken}`}})).json()).url,j=document.createElement("a");j.href=x;const b=`${r}-${new Date().toISOString()}.pdf`;j.download=b,j.click(),s.useDashboardStore.setState({isDownloadingPdf:!1})}function Ks({iconClassName:t}){const{authToken:n}=s.useSemaphorContext();s.useDashboardStore(o=>{var i;return(i=o.dashboard)==null?void 0:i.title}),s.useDashboardStore(o=>o.theme),s.useDashboardStore(o=>o.filterValues);const a=s.useDashboardStore(o=>o.isDownloadingPdf);async function r(){await We()}return e.jsx(s.Button,{variant:"link",className:"group h-7 p-2",size:"sm",onClick:r,children:a?e.jsx(xe,{className:s.cn("size-3.5 animate-spin",t)}):e.jsx(s.Download,{className:s.cn("size-3.5",t),strokeWidth:1.5})})}function Zs(){const{authToken:t}=s.useSemaphorContext();s.useDashboardStore(m=>m.theme);const n=s.useDashboardStore(m=>m.lenses),a=s.useDashboardStore(m=>m.selectedLensId),r=n==null?void 0:n.find(m=>m.id===a),o=s.useDashboardStore(m=>m.dashboard);s.useDashboardStore(m=>m.selectedSheetId);const i=s.useDashboardStore(m=>m.isDashboardEditing),l=s.useEditorStore(m=>m.selectedConnectionId),[c,d]=y.useState(!1),h=s.useDashboardStore(m=>m.filterValues),x=s.useDashboardStore(m=>m.isVisualEditing),j=s.useDashboardStore(m=>m.showFilters);s.useDashboardStore(m=>m.showDashboardJSON);const b=s.useDashboardStore(m=>m.onSaveFunction),u=s.useDashboardStore(m=>m.actions.setShowFilters),{addFrame:p,setSelectedFrameId:f}=s.useDashboardStore(m=>m.actions),{getSelectedSheet:w,setIsDashboardEditing:S,setShowDashboardJSON:L}=s.useDashboardStore(m=>m.actions),N=w(),{tenantId:k,endUserId:A}=y.useMemo(()=>s.getTenantAndEndUserId(t==null?void 0:t.accessToken),[t==null?void 0:t.accessToken]),z=y.useMemo(()=>k||A,[k,A]),B=()=>{if(!i||!N)return;const m={connectionId:l,id:s.v4(),title:"Title",description:"Description",preferences:{onClickFilter:[{columnIndex:0,expression:""}]},type:"bar",sql:"select COUNT(*) from YOUR_TABLE",data:[]},g={id:s.v4(),cards:[m],activeCardId:m.id};p(N.id,g),f(g.id)},F=()=>{S(!0)};async function _(){if(d(!0),!a||!r)return;const m=Ie(o),g=JSON.stringify(m),D={...r,template:g,filterValues:h};await Ce(D,t==null?void 0:t.accessToken),s.ue.success("Lens saved"),b==null||b(m),d(!1)}return x?null:e.jsxs("div",{className:"flex items-center justify-between gap-2 border-b bg-muted/50 py-2 pl-3 pr-2",role:"dashboard-controls",children:[!x&&e.jsx("div",{className:"flex items-center gap-3",children:e.jsx(s.Label,{children:r==null?void 0:r.name})}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("button",{onClick:s.invalidateToken,children:e.jsx(Hs,{className:"h-4 w-4",strokeWidth:1.5})}),e.jsx(Ks,{}),i&&!x&&z&&e.jsx(Js,{}),!x&&z&&e.jsx(Ws,{}),i&&!x&&e.jsxs(s.Button,{variant:"secondary",className:"h-7 p-2",size:"sm",disabled:!i,onClick:B,children:[e.jsx(s.Plus,{className:"mr-2 h-4 w-4",strokeWidth:1.5}),"Frame"]}),!i&&e.jsx(s.Button,{variant:"ghost",className:"h-7 p-2",onClick:F,size:"sm",children:e.jsx(s.Pencil,{className:"h-4 w-4",strokeWidth:1.5})}),i&&!x&&e.jsx(s.Button,{variant:"ghost",role:"close",className:"h-7 p-2",onClick:()=>{S(!1),L(!1)},size:"sm",children:e.jsx(s.Cross2Icon,{className:"h-4 w-4",strokeWidth:1.5})}),i&&!x&&z&&e.jsx(s.Button,{className:"h-7 p-2",variant:"ghost",disabled:c,onClick:_,size:"sm",children:e.jsx(qs,{className:"h-4 w-4",strokeWidth:1.5})}),!j&&!x&&i&&e.jsx(s.Button,{className:"h-7 p-2",variant:"ghost",onClick:()=>u(!0),size:"sm",children:e.jsx(s.Filter,{className:"h-4 w-4",strokeWidth:1.5})}),!x&&i&&!1,!x&&!1]})]})}function de({title:t,items:n,value:a,isLoading:r,isError:o,refetch:i,connectionTooltip:l,onChange:c,showNone:d=!1,className:h,showIcon:x=!0,disabled:j=!1}){const b=r?"Loading...":o?"Error":a;function u(){if(t==="Connection")return e.jsx(Vs,{className:"size-4 rotate-90"});if(t==="Database")return e.jsx(Cs,{className:"size-4"});if(t==="Schema")return e.jsx(Fs,{className:"size-4"});if(t==="Table")return e.jsx(Ee,{className:"size-4"});if(t==="Model")return e.jsx(js,{className:"size-4"})}return e.jsxs("div",{className:"flex items-center gap-2",children:[x&&e.jsx("div",{className:"shrink-0",children:l?e.jsxs(s.Tooltip,{children:[e.jsx(s.TooltipTrigger,{children:u()}),e.jsx(s.TooltipContent,{className:"text-xs",align:"start",children:l})]}):u()}),e.jsxs(s.Select,{disabled:j,value:b,onValueChange:c,children:[e.jsx(s.SelectTrigger,{className:s.cn("h-9 w-full focus:ring-1 focus:ring-offset-0",h),children:e.jsx(s.SelectValue,{placeholder:r?"Loading...":o?"Error":`Select ${t}`})}),e.jsx(s.SelectContent,{children:e.jsxs(s.SelectGroup,{children:[r?e.jsx(s.SelectLabel,{children:"Loading..."}):e.jsxs(s.SelectLabel,{className:"flex items-center justify-between gap-2",children:[t,e.jsx(Rs,{className:"mr-1 size-3 cursor-pointer text-muted-foreground hover:text-foreground",onClick:i})]}),e.jsxs(e.Fragment,{children:[d&&e.jsx(s.SelectItem,{value:"none",children:"None"},"none"),n&&n.map((p,f)=>e.jsx(s.SelectItem,{value:p.id,children:p.name},f))]}),(r||o)&&e.jsx(s.SelectItem,{value:b,children:b})]})})]})]})}function Xs({column:t}){const[n,a]=y.useState(!1),r=s.useEditorStore(p=>p.selectedTableName),o=s.useEditorStore(p=>p.selectedSchemaName),i=s.useEditorStore(p=>p.selectedDatamodelId),l=s.useEditorStore(p=>p.sqlGen),{modelItems:c,connectionType:d}=ne(),h=s.useEditorStore(p=>p.actions.setSqlGen),x=s.useEditorStore(p=>p.actions.setCardSql),j=s.useEditorStore(p=>p.actions.setRunSql);function b(p,f){var N;const w=s.createSqlGenConfig(p,l,f),S=(N=c==null?void 0:c.find(k=>k.id===i))==null?void 0:N.name;h(w);const L=s.getSql(w,s.fmt(o||""),s.fmt(r),S,d);L&&(x(L),j(!0)),a(!1)}function u(){return e.jsxs("ul",{className:"text-xs",children:[e.jsx("li",{onClick:()=>b(t,"COUNT"),className:"cursor-pointer p-1 px-3 transition-colors hover:bg-muted",children:"Count"}),e.jsx("li",{onClick:()=>b(t,"AVG"),className:"cursor-pointer p-1 px-3 transition-colors hover:bg-muted",children:"Avg"}),e.jsx("li",{onClick:()=>b(t,"SUM"),className:"cursor-pointer p-1 px-3 transition-colors hover:bg-muted",children:"Sum"}),e.jsx("li",{onClick:()=>b(t,"MAX"),className:"cursor-pointer p-1 px-3 transition-colors hover:bg-muted",children:"Max"}),e.jsx("li",{onClick:()=>b(t,"MIN"),className:"cursor-pointer p-1 px-3 transition-colors hover:bg-muted",children:"Min"})]})}return e.jsxs(s.HoverCard,{openDelay:0,open:n,onOpenChange:a,children:[e.jsx(s.HoverCardTrigger,{asChild:!0,children:e.jsx(ke,{className:"invisible size-3.5 cursor-pointer text-foreground/40 group-hover:visible"})}),e.jsx(s.HoverCardContent,{align:"center",className:"w-20 rounded-md p-0 shadow-none",children:u()})]})}function Ke({column:t}){return e.jsxs(s.Tooltip,{children:[e.jsx(s.TooltipTrigger$1,{asChild:!0,children:s.isTextDataType(t.data_type)?e.jsx(De,{className:"size-3"}):s.isNumberDataType(t.data_type)?e.jsx(Is,{className:"size-3"}):s.isDateDataType(t.data_type)?e.jsx(s.Calendar,{className:"size-3"}):s.isBooleanDataType(t.data_type)?e.jsx(Gs,{className:"size-3"}):t.data_type.toLowerCase()==="json"?e.jsx(bs,{className:"size-3"}):e.jsx(Bs,{className:"size-3"})}),e.jsx(s.TooltipContent,{children:e.jsx("p",{className:"font-mono text-xs",children:t.data_type})})]})}function Ys({schemaName:t,tableName:n,columns:a,status:r}){const o=s.useEditorStore(m=>m.sqlGen),i=s.useEditorStore(m=>m.selectedConnectionId),l=s.useEditorStore(m=>m.selectedDatabaseName),c=s.useEditorStore(m=>m.selectedSchemaName),d=s.useEditorStore(m=>m.selectedTableName),h=s.useEditorStore(m=>m.selectedDatamodelId),x=s.useDashboardStore(m=>m.dashboard.aiScopeTables),{addToAIScope:j,removeFromAIScope:b}=s.useDashboardActions(),{setAIScopeTables:u}=s.useDashboardStore(m=>m.actions),p=s.useEditorStore(m=>m.actions.setRunSql),f=s.useEditorStore(m=>m.actions.setSqlGen),w=s.useEditorStore(m=>m.actions.setIsShowingVisual),S=s.useEditorStore(m=>m.actions.setCardSql),{connectionType:L,modelItems:N,selectedDatamodelName:k}=ne();function A(m){var O;const g=s.createSqlGenConfig(m,o);f(g);const D=(O=N==null?void 0:N.find(q=>q.id===h))==null?void 0:O.name,v=s.getSql(g,s.fmt(t),s.fmt(n),D,L);v&&(S(v),p(!0))}function z(){return(x==null?void 0:x.find(m=>m.connectionId===i&&(m.tableName===d||m.datamodelName===k)))!==void 0}function B(m){m===!0&&(d||k)&&i?(j({connectionId:i,connectionType:L==="S3"||L==="API"?"DuckDb":L,databaseName:l,schemaName:c,tableName:d,datamodelName:k}),s.ue.success("Added to Assistant Scope",{position:"top-right",duration:2500,richColors:!0})):(b({connectionId:i||"",connectionType:L||"",tableName:d||"",datamodelName:k||""}),s.ue("Removed from Assistant Scope",{position:"top-right",duration:2e3,richColors:!0}))}function F(){const m=s.getFormattedTableNameForQuery({schemaName:t,tableName:n,modelName:k,connectionType:L});w(!1);const g=L==="MSSQL"?`SELECT top 10 * FROM ${m}`:`SELECT * FROM ${m} LIMIT 10`;S(g),p(!0)}function _(){const m=s.getFormattedTableNameForQuery({schemaName:t,tableName:n,modelName:k,connectionType:L});S(`SELECT COUNT(*) as count FROM ${m}`),p(!0)}return e.jsxs("div",{className:"flex grow flex-col space-y-4 px-4",children:[e.jsxs("div",{className:"mx-2 flex items-center justify-center gap-2",children:[e.jsxs(s.Toggle,{title:`${z()?"Remove from":"Add to"} Assistant Scope`,pressed:z(),onPressedChange:B,variant:"outline",className:s.cn("h-9 px-2",{}),children:[e.jsx(s.Plus,{className:s.cn("mr-1 size-4",{"text-green-400":z(),"text-muted-foreground":!z()})}),"AI"]}),e.jsxs(s.Button,{disabled:r!=="Success",onClick:F,size:"sm",variant:"secondary",className:"flex",children:[r!=="Success"?e.jsx(xe,{className:"mr-2 h-4 w-4 animate-spin text-foreground/50"}):e.jsx(Os,{className:"mr-2 size-4"}),"Top 10"]}),e.jsxs(s.Button,{disabled:r!=="Success",onClick:_,size:"sm",variant:"secondary",className:"w-full",children:[r!=="Success"?e.jsx(xe,{className:"mr-2 h-4 w-4 animate-spin text-foreground/50"}):e.jsx(_s,{className:"mr-2 size-4"}),"Count"]})]}),e.jsxs(s.ScrollArea,{className:"flex-1 basis-0 border-b border-t border-muted py-3",children:[e.jsx("div",{className:"flex flex-col gap-1",children:a==null?void 0:a.map(m=>e.jsxs("div",{onClick:()=>A(m),className:s.cn("group mx-3 flex cursor-pointer items-center justify-between rounded px-2 py-1 text-sm transition-colors hover:bg-muted/50",{"border border-dashed border-muted-foreground bg-muted":s.isColumnInSqlGen(m,o)}),children:[e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(Ke,{column:m}),e.jsx("span",{children:m.column_name})]}),e.jsx("div",{onClick:g=>g.stopPropagation(),className:"flex items-center justify-end",children:s.isNumberDataType(m.data_type)&&e.jsx(Xs,{column:m})})]},m.column_name))}),e.jsx(s.ScrollBar,{orientation:"vertical"}),e.jsx(s.ScrollBar,{orientation:"horizontal"})]})]})}function ne(t,n){var Le,Ae,ze,Oe,Me,Fe;let a=y.useMemo(()=>[],[]);const r=s.useSemaphorContext().authToken||t,o=s.useEditorStore(C=>C.selectedConnectionId),i=s.useEditorStore(C=>C.selectedDatamodelId),l=s.useEditorStore(C=>C.selectedDatabaseName),c=s.useEditorStore(C=>C.selectedSchemaName),d=s.useEditorStore(C=>C.selectedTableName),h=s.useEditorStore(C=>C.actions.setCurrentColumns),x=s.useEditorStore(C=>C.actions.setSelectedConnectionId),j=s.useEditorStore(C=>C.actions.setSelectedDatamodelId),b=s.useEditorStore(C=>C.actions.setSelectedDatabaseName),u=s.useEditorStore(C=>C.actions.setSelectedSchemaName),p=s.useEditorStore(C=>C.actions.setSelectedTableName);s.useEditorStore(C=>C.actions.setCardSql);function f(C){return o&&l&&c&&l!=="NA"?!0:o&&C==="API"?!1:!!(o&&C==="S3")}function w(C){return!!(o&&l&&l!=="NA"&&c&&d||o&&(C==="S3"||C==="API")||i&&i)}function S(C){return o&&C?!(C==="API"||C==="S3"):!1}const{refetch:L,data:N,isLoading:k,isError:A}=s.useQuery({queryKey:["connections"],queryFn:()=>s.getRequest("https://semaphor.cloud/api/v1/connections",(r==null?void 0:r.accessToken)||""),enabled:!!(r!=null&&r.accessToken)}),{refetch:z,data:B,isLoading:F,isError:_}=s.useQuery({queryKey:["models",o],queryFn:()=>s.getRequest("https://semaphor.cloud/api/v1/datamodels",(r==null?void 0:r.accessToken)||"",{connection_id:o}),enabled:!!(r!=null&&r.accessToken)&&!!o}),m=N==null?void 0:N.connections.find(C=>C.id===o),g=m==null?void 0:m.type,D=(m==null?void 0:m.type)==="API"||(m==null?void 0:m.type)==="S3",{data:v,isLoading:O,isFetching:q,isError:P,refetch:U}=s.useQuery({queryKey:["databases",o],queryFn:()=>s.getRequest("https://semaphor.cloud/api/v1/databases",(r==null?void 0:r.accessToken)||"",{connection_id:o}),enabled:S(g)}),{data:G,isLoading:J,isFetching:ee,isError:H,refetch:M}=s.useQuery({queryKey:["schemas",o,l],queryFn:()=>s.getRequest("https://semaphor.cloud/api/v1/schemas",(r==null?void 0:r.accessToken)||"",{connection_id:o,database_name:l}),enabled:!!o&&!!l&&!D&&l!=="NA"}),{data:T,isLoading:W,isFetching:K,isError:X,refetch:Z}=s.useQuery({queryKey:["tables",o,l,c],queryFn:()=>s.getRequest("https://semaphor.cloud/api/v1/tables",(r==null?void 0:r.accessToken)||"",{connection_id:o,database_name:l,schema_name:c}),enabled:f(g)}),{data:$,isLoading:E,isFetching:V,isError:R,refetch:Q}=s.useQuery({queryKey:["columns",o,l,i,c,d],queryFn:()=>s.getRequest("https://semaphor.cloud/api/v1/columns",(r==null?void 0:r.accessToken)||"",{connection_id:o,datamodel_id:i||"",database_name:l,schema_name:c,table_name:d}),enabled:w(g)});y.useEffect(()=>{h(a)},[$,h,a]),y.useEffect(()=>{(g==="S3"||g==="API")&&(b(""),u(""),j(""),g==="API"&&p("api"))},[g,p,b,u,j]);const le=(m==null?void 0:m.type)==="API"?(Le=m==null?void 0:m.type)==null?void 0:Le.toLowerCase():d||"",ce=D?"":c||"";function re(C){u(C),p("")}function I(C){b(C==="none"?"":C),u(""),p(""),C!=="none"&&C!==""&&j("")}function Y(C){x(C)}function oe(C){j(C==="none"?"":C),C!=="none"&&C!==""&&b("")}v&&((Ae=v==null?void 0:v.databases)==null?void 0:Ae.length)>0,G&&((ze=G==null?void 0:G.schemas)==null?void 0:ze.length)>0,$&&((Oe=$==null?void 0:$.columns)==null?void 0:Oe.length)>0&&(a=$.columns.map(C=>({...C,data_type:C.data_type.toLowerCase()}))),P&&(a=[]),(R||A)&&(a=[]);const se=N==null?void 0:N.connections.map(C=>({id:C.id,name:C.name,type:C.type})),he=(Me=B==null?void 0:B.datamodels)==null?void 0:Me.map(C=>({id:C.id,name:C.name})),ye=v==null?void 0:v.databases.map(C=>({id:C.database_name,name:C.database_name})),pe=G==null?void 0:G.schemas.map(C=>({id:C.schema_name,name:C.schema_name})),ve=T==null?void 0:T.tables.map(C=>({id:C.table_name,name:C.table_name})),fs=(Fe=B==null?void 0:B.datamodels.find(C=>C.id===i))==null?void 0:Fe.name;return{connectionItems:se,isConnectionsLoading:k,isConnectionsError:A,modelItems:he,selectedDatamodelId:i,selectedDatamodelName:fs,isModelsLoading:F,isModelsError:_,databaseItems:ye,isDatabasesLoadingOrFetching:O||q,isDatabaseError:P,schemaItems:pe,isSchemaLoadingOrFetching:J||ee,isSchemaError:H,tableItems:ve,isTableLoadingOrFetching:W||K,isTableError:X,columns:a,isColumnsLoadingOrFetching:E||V,isColumnsError:R,isNonDbConnection:D,connectionType:g,tableName:le,schemaName:ce,refetchConnections:L,refetchModels:z,refetchDatabases:U,refetchSchemas:M,refetchTables:Z,refetchColumns:Q,handleConnectionChange:Y,handleDatamodelChange:oe,handleDatabaseChange:I,handleSchemaChange:re}}function Ze({ColumnsComponent:t}){var V;const n=s.useEditorStore(R=>R.selectedConnectionId),a=s.useEditorStore(R=>R.selectedDatamodelId),r=s.useEditorStore(R=>R.selectedDatabaseName),o=s.useEditorStore(R=>R.selectedSchemaName),i=s.useEditorStore(R=>R.selectedTableName),l=s.useEditorStore(R=>R.actions.setSelectedTableName),{connectionItems:c,modelItems:d,schemaItems:h,databaseItems:x,tableItems:j,columns:b,isConnectionsLoading:u,isModelsLoading:p,isConnectionsError:f,isModelsError:w,isDatabasesLoadingOrFetching:S,isDatabaseError:L,isSchemaLoadingOrFetching:N,isSchemaError:k,isColumnsError:A,isColumnsLoadingOrFetching:z,isTableLoadingOrFetching:B,isTableError:F,connectionType:_,isNonDbConnection:m,refetchDatabases:g,refetchModels:D,refetchSchemas:v,refetchTables:O,refetchColumns:q,refetchConnections:P,handleConnectionChange:U,handleDatabaseChange:G,handleSchemaChange:J,handleDatamodelChange:ee,tableName:H,schemaName:M}=ne();function T(){return t?t(M,H,b):e.jsx(Ys,{schemaName:M,tableName:H,columns:b,status:z?"Loading...":A?"Error":"Success"})}function W(){window.location.href="mailto:support@semaphor.cloud?subject=Help&body=I need help with..."}function K(){if(!n||_==="S3"||_==="API")return null;if(!a||a==="none")return e.jsx(de,{refetch:g,showNone:!0,onChange:G,isError:L,isLoading:S,items:x,value:r||"",title:"Database"})}function X(){if(n&&!m&&(!r||r==="none")&&(!a||a==="none"))return e.jsxs("div",{className:"grid grid-cols-3",children:[e.jsx("div",{className:"col-span-1 grid place-items-center",children:e.jsx(s.Separator,{})}),e.jsx("div",{className:"col-span-1 grid place-items-center",children:e.jsx(s.Label,{children:"OR"})}),e.jsx("div",{className:"col-span-1 grid place-items-center",children:e.jsx(s.Separator,{})})]})}function Z(){if(!n||_==="S3"||_==="API")return null;if(!r||r==="none")return e.jsx(de,{refetch:D,showNone:!0,onChange:ee,isError:w,isLoading:p,items:d,value:a||"",title:"Model"})}function $(){return!n||_==="S3"||_==="API"||!r||r==="none"?null:e.jsx(de,{refetch:v,onChange:J,isError:k,isLoading:N,items:h,value:o||"",title:"Schema"})}function E(){function R(){let Q=!1;return _==="API"?(Q=!1,Q):((_==="S3"||n&&r&&r!=="none"&&o)&&(Q=!0),Q)}return R()?e.jsx(de,{refetch:O,onChange:l,isError:F,items:j,isLoading:B,value:i||"",title:"Table"}):null}return e.jsxs("aside",{className:"flex grow flex-col justify-between",children:[e.jsxs("section",{className:"space-y-3 px-6 py-4",children:[e.jsx(de,{refetch:P,items:c,title:"Connection",value:n||"",onChange:U,isLoading:u,isError:f,connectionTooltip:((V=c==null?void 0:c.find(R=>R.id===n))==null?void 0:V.type)||""}),K(),X(),Z(),$(),E()]}),T(),e.jsx("div",{className:"flex items-end justify-center gap-2 px-6 py-4",children:e.jsxs(s.Button,{onClick:W,size:"sm",variant:"secondary",className:"w-full",children:[e.jsx(Ms,{className:"mr-2 size-4"}),"Help"]})})]})}function et(t){const n=t.toUpperCase().indexOf("WHERE"),a=t.toUpperCase().indexOf("GROUP BY"),r=t.toUpperCase().indexOf("LIMIT"),o=t.toUpperCase().indexOf("ORDER BY");let i=t.length;if(o!==-1&&(i=o),r!==-1&&r<i&&(i=r),n!==-1){const l=t.substring(0,n),c=t.substring(n);return`${l} {{ filters | where }} AND ${c.substring(6)}`}else if(a!==-1){const l=t.substring(0,a),c=t.substring(a);return`${l} {{ filters | where }} ${c}`}else{const l=t.substring(0,i),c=t.substring(i);return console.log("beforeClause",l),console.log("afterClause",c),c?`${l} {{ filters | where }} ${c}`:`${l.replace(/;$/,"")} {{ filters | where }}`}}function st({sql:t,error:n,setShowAIDialog:a,setUserInputforAI:r,setTriggerAIRun:o}){return!t&&!n?null:e.jsxs(s.HoverCard,{openDelay:n?0:500,children:[e.jsx(s.HoverCardTrigger,{asChild:!0,children:e.jsx(s.Button,{variant:"link",className:"h-5 p-0",children:n?e.jsx(ys,{className:"h-4 w-4 text-red-500"}):e.jsx(s.Info,{className:"h-4 w-4 text-muted-foreground"})})}),e.jsx(s.HoverCardContent,{align:"start",className:"w-full min-w-fit max-w-[700px]",children:e.jsx("div",{className:"flex justify-between space-x-4",children:e.jsxs("div",{className:"flex grow flex-col space-y-2",children:[e.jsxs(s.ScrollArea,{className:"max-h-[250px] min-h-0 overflow-scroll text-xs leading-relaxed text-foreground/80",children:[n&&n,t&&e.jsxs("div",{className:"flex flex-col space-y-1.5",children:[e.jsx("span",{className:"text-xs font-semibold",children:"Resolved SQL"}),e.jsx("span",{className:"font-mono",children:t})]})]}),n&&e.jsxs(s.Button,{onClick:()=>{a(!0),r(n),o(!0)},size:"sm",variant:"secondary",children:[e.jsx(Ds,{className:"mr-2 h-4 w-4"}),"Debug with Assistant"]})]})})})]})}function tt({userInput:t,triggerAIRun:n,setTriggerAIRun:a,open:r,setOpen:o}){const i=y.useRef(null),l=y.useRef(null),[c,d]=y.useState([]),[h,x]=y.useState(""),[j,b]=y.useState(null),{authToken:u}=s.useSemaphorContext(),p=s.useEditorStore(E=>{var V;return(V=E==null?void 0:E.card)==null?void 0:V.sql}),f=s.useEditorStore(E=>{var V;return(V=E==null?void 0:E.card)==null?void 0:V.python}),w=s.useEditorStore(E=>E.actions.setCardSql),S=s.useEditorStore(E=>E.actions.setRunSql),L=s.useEditorStore(E=>E.actions.switchCardType),N=s.useEditorStore(E=>E.selectedDatabaseName),k=s.useEditorStore(E=>E.selectedTableName),A=s.useEditorStore(E=>E.selectedConnectionId),z=s.useEditorStore(E=>E.selectedSchemaName),B=s.useDashboardStore(E=>E.dashboard.aiScopeTables),{selectedDatamodelName:F,connectionType:_}=ne(),{messages:m,setMessages:g,reload:D,append:v,input:O,status:q,handleInputChange:P,handleSubmit:U,stop:G}=s.useChat({api:"https://semaphor.cloud/api/v1/assistant",headers:{Authorization:`Bearer ${u==null?void 0:u.accessToken}`},body:{random:Math.random()},maxSteps:10,onToolCall:M,onFinish(E,V){ee(V.usage),x(""),console.log("onFinish",E,V),V.finishReason==="stop"&&x("")}});y.useEffect(()=>{n&&t&&(P({target:{value:t}}),setTimeout(()=>{U(),a(!1)},100))},[n,U,t,a,P]);const J=y.useRef(r);y.useEffect(()=>{const E=J.current?"smooth":"auto";J.current=r;const V=setTimeout(()=>{var R;l.current&&(l.current.scroll({top:l.current.scrollHeight,behavior:E}),(R=i.current)==null||R.focus())},50);return()=>clearTimeout(V)},[m,r]);function ee(E){b(V=>V?{promptTokens:V.promptTokens+E.promptTokens,completionTokens:V.completionTokens+E.completionTokens,totalTokens:V.totalTokens+E.totalTokens}:E)}function H(E){const V=s.removeFromScopeArray(c,E);W(V)}async function M({toolCall:E}){if(E.toolName==="createChart"){console.log("createChart",E.args);const V=E.args.sql,R=E.args.chartType;return L(R),w(V),S(!0),{status:"success",message:"Let the user know that chart is created"}}else if(E.toolName==="getTableColumns")x("Getting table columns...");else{if(E.toolName==="getUserSql")return p?(console.log("cardSql",p),console.log("cardPython",f),{status:"success",sql:p,python:f||""}):{status:"error",message:"No SQL found"};x("Thinking...")}}function T(E){return E.map(R=>({...R,connectionType:R.connectionType==="API"||R.connectionType==="S3"?"DuckDb":R.connectionType}))}function W(E){const V=T(E);d(V),g(R=>[...R,{id:crypto.randomUUID(),role:"system",content:`Current scope of tables | ${JSON.stringify(V)}`}])}function K(){const E={databaseName:N||"",schemaName:z||"",tableName:k||"",datamodelName:F||"",connectionId:A||"",connectionType:_||""},V=s.dedup([...c,E]);W(V)}function X(){const E={databaseName:N||"",schemaName:z||"",tableName:k||"",datamodelName:F||"",connectionId:A||"",connectionType:_||""},V=s.isInAiScopeArray([...B||[],...c],E);if(console.log("isInScope",V),!V||c.length===0){const R=s.dedup([...B||[],...c,E]).filter(Q=>Q.connectionId===E.connectionId);W(R)}}function Z(E){o(!1),w(E),S(!0)}const $=!["ready","error"].includes(q);return{messages:m,setMessages:g,reload:D,append:v,input:O,isLoading:$,handleRun:Z,handleOpenDialogAndSetScope:X,handleAddCurrentTableToScope:K,removeFromCurrentSelections:H,currentScope:c,setCurrentScope:d,containerRef:l,inputRef:i,handleInputChange:P,handleSubmit:U,stop:G,chatStatus:q,toolStatus:h,llmUsage:j}}const at=!1;function nt({open:t,setOpen:n,userInput:a,triggerAIRun:r,setTriggerAIRun:o}){const[i,l]=y.useState(!1),[c,d]=y.useState(at),[h,x]=y.useState(!1),{messages:j,setMessages:b,reload:u,input:p,isLoading:f,handleRun:w,handleOpenDialogAndSetScope:S,handleAddCurrentTableToScope:L,removeFromCurrentSelections:N,currentScope:k,setCurrentScope:A,containerRef:z,inputRef:B,handleInputChange:F,handleSubmit:_,stop:m,chatStatus:g,toolStatus:D,llmUsage:v}=tt({userInput:a,triggerAIRun:r,setTriggerAIRun:o,open:t,setOpen:n});function O(){return e.jsxs(s.DropdownMenu,{children:[e.jsx(s.DropdownMenuTrigger,{children:e.jsx(ke,{className:"size-3.5 text-muted-foreground/70 hover:text-muted-foreground"})}),e.jsxs(s.DropdownMenuContent,{align:"end",children:[e.jsx(s.DropdownMenuLabel,{children:"Options"}),e.jsx(s.DropdownMenuSeparator,{}),e.jsx(s.DropdownMenuCheckboxItem,{checked:i,onCheckedChange:l,children:"Token Usage"}),e.jsx(s.DropdownMenuCheckboxItem,{checked:c,onCheckedChange:d,children:"Tool Invocations"}),e.jsx(s.DropdownMenuCheckboxItem,{checked:h,onCheckedChange:x,children:"System Message"})]})]})}return e.jsxs(s.Dialog,{open:t,onOpenChange:n,children:[e.jsx(s.DialogTrigger,{asChild:!0,children:e.jsx(s.Button,{onClick:S,size:"sm",className:"w-full justify-start border font-normal text-muted-foreground focus-visible:ring-0 focus-visible:ring-offset-0",variant:"secondary",children:"Type your question..."})}),e.jsxs(s.DialogContent,{className:"flex flex-col justify-between overflow-auto sm:max-w-[425px] md:max-h-[625px] md:min-w-[625px]",children:[e.jsx(s.DialogHeader,{children:e.jsxs("div",{className:"flex items-start justify-between gap-2 pr-5",children:[e.jsxs("div",{children:[e.jsx(s.DialogTitle,{children:"Assistant"}),e.jsx(s.DialogDescription,{children:"What can I help you with?"}),k&&k.length>0&&e.jsxs("div",{className:"mt-2 flex flex-wrap items-center gap-2",children:[e.jsx("span",{className:"text-xs text-muted-foreground",children:"Tables in scope:"}),k==null?void 0:k.map((q,P)=>e.jsxs("div",{className:"flex items-center gap-2 rounded-md bg-muted px-2 py-1 text-xs",children:[s.getFormattedTableNameForQuery({schemaName:q.schemaName||"",tableName:q.tableName||"",modelName:q.datamodelName||"",connectionType:q.connectionType||""}),e.jsx("button",{onClick:()=>{N(q)},children:e.jsx(s.X,{className:"size-3 text-muted-foreground hover:text-foreground"})})]},P))]}),(k==null?void 0:k.length)===0&&e.jsxs("div",{className:"mt-2 flex items-center gap-2",children:[e.jsx("span",{className:"text-xs text-muted-foreground",children:"Tables in scope: None"}),e.jsxs(s.Button,{className:"h-6 text-xs",size:"sm",variant:"secondary",onClick:L,children:[e.jsx(s.Plus,{className:"mr-2 size-3"}),"Current Table"]})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[O(),e.jsx(s.Button,{className:"h-8",size:"sm",variant:"secondary",onClick:()=>{b([]),A([]),u()},children:"Clear"})]})]})}),e.jsx("div",{ref:z,className:"h-[625px] w-full overflow-auto border-t border-t-muted",children:e.jsxs("div",{className:"space-y-4 py-2 pr-3",role:"messages",children:[e.jsx(s.PrintMessages,{messages:j,showTools:c,handleRun:w,showSystemMessage:h}),e.jsx(s.ChatStatus,{status:s.getStatus(g,D),isLoading:f})]})}),e.jsx(s.ChatInput,{stop:m,ref:B,input:p,handleInputChange:F,handleSubmit:_,isLoading:f}),v&&i&&e.jsx("div",{className:"flex h-8 items-center justify-between",children:e.jsxs("div",{className:"text-xs text-muted-foreground",children:["Usage: ",v.promptTokens," prompt tokens,"," ",v.completionTokens," completion tokens,"," ",v.totalTokens," total tokens"]})})]})]})}var Xe={color:void 0,size:void 0,className:void 0,style:void 0,attr:void 0},Re=y.createContext&&y.createContext(Xe),rt=["attr","size","title"];function ot(t,n){if(t==null)return{};var a=it(t,n),r,o;if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(t);for(o=0;o<i.length;o++)r=i[o],!(n.indexOf(r)>=0)&&Object.prototype.propertyIsEnumerable.call(t,r)&&(a[r]=t[r])}return a}function it(t,n){if(t==null)return{};var a={};for(var r in t)if(Object.prototype.hasOwnProperty.call(t,r)){if(n.indexOf(r)>=0)continue;a[r]=t[r]}return a}function je(){return je=Object.assign?Object.assign.bind():function(t){for(var n=1;n<arguments.length;n++){var a=arguments[n];for(var r in a)Object.prototype.hasOwnProperty.call(a,r)&&(t[r]=a[r])}return t},je.apply(this,arguments)}function qe(t,n){var a=Object.keys(t);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(t);n&&(r=r.filter(function(o){return Object.getOwnPropertyDescriptor(t,o).enumerable})),a.push.apply(a,r)}return a}function be(t){for(var n=1;n<arguments.length;n++){var a=arguments[n]!=null?arguments[n]:{};n%2?qe(Object(a),!0).forEach(function(r){lt(t,r,a[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(a)):qe(Object(a)).forEach(function(r){Object.defineProperty(t,r,Object.getOwnPropertyDescriptor(a,r))})}return t}function lt(t,n,a){return n=ct(n),n in t?Object.defineProperty(t,n,{value:a,enumerable:!0,configurable:!0,writable:!0}):t[n]=a,t}function ct(t){var n=dt(t,"string");return typeof n=="symbol"?n:n+""}function dt(t,n){if(typeof t!="object"||!t)return t;var a=t[Symbol.toPrimitive];if(a!==void 0){var r=a.call(t,n);if(typeof r!="object")return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return(n==="string"?String:Number)(t)}function Ye(t){return t&&t.map((n,a)=>y.createElement(n.tag,be({key:a},n.attr),Ye(n.child)))}function te(t){return n=>y.createElement(ut,je({attr:be({},t.attr)},n),Ye(t.child))}function ut(t){var n=a=>{var{attr:r,size:o,title:i}=t,l=ot(t,rt),c=o||a.size||"1em",d;return a.className&&(d=a.className),t.className&&(d=(d?d+" ":"")+t.className),y.createElement("svg",je({stroke:"currentColor",fill:"currentColor",strokeWidth:"0"},a.attr,r,l,{className:d,style:be(be({color:t.color||a.color},a.style),t.style),height:c,width:c,xmlns:"http://www.w3.org/2000/svg"}),i&&y.createElement("title",null,i),t.children)};return Re!==void 0?y.createElement(Re.Consumer,null,a=>n(a)):n(Xe)}function ht(t){return te({attr:{viewBox:"0 0 448 512"},child:[{tag:"path",attr:{d:"M439.8 200.5c-7.7-30.9-22.3-54.2-53.4-54.2h-40.1v47.4c0 36.8-31.2 67.8-66.8 67.8H172.7c-29.2 0-53.4 25-53.4 54.3v101.8c0 29 25.2 46 53.4 54.3 33.8 9.9 66.3 11.7 106.8 0 26.9-7.8 53.4-23.5 53.4-54.3v-40.7H226.2v-13.6h160.2c31.1 0 42.6-21.7 53.4-54.2 11.2-33.5 10.7-65.7 0-108.6zM286.2 404c11.1 0 20.1 9.1 20.1 20.3 0 11.3-9 20.4-20.1 20.4-11 0-20.1-9.2-20.1-20.4.1-11.3 9.1-20.3 20.1-20.3zM167.8 248.1h106.8c29.7 0 53.4-24.5 53.4-54.3V91.9c0-29-24.4-50.7-53.4-55.6-35.8-5.9-74.7-5.6-106.8.1-45.2 8-53.4 24.7-53.4 55.6v40.7h106.9v13.6h-147c-31.1 0-58.3 18.7-66.8 54.2-9.8 40.7-10.2 66.1 0 108.6 7.6 31.6 25.7 54.2 56.8 54.2H101v-48.8c0-35.3 30.5-66.4 66.8-66.4zm-6.7-142.6c-11.1 0-20.1-9.1-20.1-20.3.1-11.3 9-20.4 20.1-20.4 11 0 20.1 9.2 20.1 20.4s-9 20.3-20.1 20.3z"},child:[]}]})(t)}function es(t){const{theme:n}=s.useTheme(),a=s.useDashboardStore(f=>f.theme),r=s.useEditorStore(f=>f.frame),o=s.useEditorStore(f=>f.card),i=s.useEditorStore(f=>f.activeTabCardId),l=s.Le(),{refetch:c}=s.useDashboardCardQuery(o),{updateCardTab:d,setRunSql:h}=s.useEditorActions(),x=y.useRef(),j=y.useRef({}),b=r.cards.find(f=>f.id===i),u=y.useCallback(()=>{let f="";return t==="python"&&(f=(b==null?void 0:b.python)||s.PYTHON_DEFAULT_CODE),t==="sql"&&(f=(b==null?void 0:b.sql)||""),f},[t,b]);y.useEffect(()=>{if(i&&o.id&&o.id!==i){if(x.current&&l){const f=x.current.getModel();f&&(j.current[o.id]=f);let w=j.current[i];if(!w){const S=u();w=l.editor.createModel(S,t),j.current[i]=w}x.current.setModel(w)}d(i,o),h(!0)}},[i,o,d,l,h,t,u]),y.useEffect(()=>{if(!l)return;const f=window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light",w=a==="system"?f:a;l.editor.defineTheme("default",{base:w==="light"?"vs":"vs-dark",inherit:!0,rules:[],colors:{"editor.background":w==="light"?"#ffffff":s.hslStringToHex("240 10% 10%")}}),l.editor.setTheme("default")},[n,a,l]),y.useEffect(()=>{const f=x.current;f&&l&&o&&f.addCommand(l.KeyMod.Shift|l.KeyCode.Enter,function(){return c(),!1})},[l,c,o]);function p(f,w){if(x.current=f,!j.current[o.id]){const S=f.getModel(),L=u();j.current[o.id]=S||(w==null?void 0:w.editor.createModel(L,t))||f.getModel()}f.setModel(j.current[o.id])}return{handleEditorDidMount:p}}function mt(){const t=s.useEditorStore(l=>l.card.sql),n=s.useEditorStore(l=>l.sqlGen),{setCardSql:a,setSqlGen:r}=s.useEditorActions(),{handleEditorDidMount:o}=es("sql");function i(l){a(l),s.isObjectEmpty(n)||r({})}return e.jsx(s.Ft,{theme:"default",className:"pt-3",onChange:i,value:t||"",options:{minimap:{enabled:!1},wordWrap:"on",scrollbar:{verticalScrollbarSize:0,horizontalScrollbarSize:0},fontSize:13,renderLineHighlight:"none"},defaultLanguage:"sql",onMount:o})}function xt(){const t=s.useEditorStore(o=>o.card.python),{setCardPython:n}=s.useEditorActions(),{handleEditorDidMount:a}=es("python");function r(o){n(o)}return e.jsx(s.Ft,{className:"pt-3",theme:"default",onChange:r,value:t||s.PYTHON_DEFAULT_CODE,options:{minimap:{enabled:!1},wordWrap:"on",scrollbar:{verticalScrollbarSize:0,horizontalScrollbarSize:0},fontSize:13,renderLineHighlight:"none"},defaultLanguage:"python",onMount:a})}function pt({jsonString:t}){return e.jsx(s.Ft,{theme:"default",defaultLanguage:"json",className:"mt-1 min-h-[220px]",value:t,options:{readOnly:!0,minimap:{enabled:!1},lineNumbers:"off",glyphMargin:!1,wordWrap:"on",scrollbar:{verticalScrollbarSize:0,horizontalScrollbarSize:0},fontSize:12,renderLineHighlight:"none"}})}function ft(){var re;const[t,n]=y.useState({queryKey:[],queryData:null}),a=s.useQueryClient(),[r,o]=y.useState(!1),[i,l]=y.useState(!1),[c,d]=y.useState(!1),[h,x]=y.useState(""),[j,b]=y.useState(!1),u=s.useEditorStore(I=>I.frame),p=s.useEditorStore(I=>I.card),f=s.useEditorStore(I=>I.isShowingVisual),w=s.useEditorStore(I=>I.selectedConnectionId),S=s.useEditorStore(I=>I.selectedDatabaseName),L=s.useEditorStore(I=>I.selectedDatamodelId),N=s.useEditorStore(I=>I.selectedSchemaName),k=s.useEditorStore(I=>I.selectedTableName),A=s.useEditorStore(I=>{var Y;return(Y=I==null?void 0:I.card)==null?void 0:Y.sql});s.useEditorStore(I=>I.applyFilters);const{sheetFilterValues:z}=s.useSheetFilterValues(),{setCardCustomCfg:B,setQueryResultColumns:F,setCardSql:_,setPythonStdOut:m,setCardPreferences:g,setCardType:D,setCardPython:v}=s.useEditorActions(),O=s.useEditorStore(I=>I.onSave),q=s.useEditorStore(I=>I.onClose),P=s.useEditorStore(I=>I.actions.setSqlGen),U=s.useEditorStore(I=>I.runSql),G=s.useEditorStore(I=>I.actions.setRunSql),J=s.useEditorStore(I=>I.actions.setCardCfg),ee=s.useEditorStore(I=>I.actions.setIsSqlRunning),{data:H,isLoading:M,isFetching:T,isSuccess:W,isError:K,error:X,queryKey:Z,refetch:$}=s.useDashboardCardQuery(p);y.useEffect(()=>{if(H&&(H.rowLimitExceeded&&s.ue.error("Row limit (10,000) exceeded. Refine your query.",{position:"top-center",richColors:!0}),m((H==null?void 0:H.output)||""),H.records.length>0)){const{dimensionKeys:I}=s.getKeys(H.records);F(I)}},[H,F,m]),y.useEffect(()=>{(M||T)&&ee(!0),(K||W)&&ee(!1),K&&(F([]),m(""))},[M,T,H,m,K,W,ee,F,X]),y.useEffect(()=>{U&&(a.getQueryData(Z)||$(),G(!1))},[U,$,G,Z,a]);function E(){const I=a.getQueryData(Z);t.queryData||n({queryKey:Z,queryData:I}),a.setQueryData(Z,null),a.removeQueries({queryKey:Z,exact:!0}),_(""),P({}),v(""),J(void 0),B(""),g({}),D("bar")}function V(I,Y){if(I.length===0)return"";if(Y){const oe=I.find(se=>se.id===Y);if(oe){const se=oe.tabTitle;if(se=="All__Header")return I[0].id;if(se&&se.endsWith("__Header")){const ye=se.split("__")[0],pe=I.find(ve=>ve.tabTitle===ye);return pe?pe.id:I[0].id}return Y}}return I[0].id}function R(){let I=A;A&&!A.includes("{{")&&(I=et(A),_(I));const Y={...p,lastSelectedSchema:N,lastSelectedDatamodelId:L,lastSelectedDatabase:S,lastSelectedTable:k,connectionId:w,type:f?p.type:"table",sql:I,customCfg:f?p.customCfg:null},oe=u.cards.map(he=>he.id===p.id?Y:he),se={...u,cards:oe,activeCardId:V(oe,u.activeCardId)};O==null||O(se)}function Q(){const{queryKey:I,queryData:Y}=t;I&&Y&&a.setQueryData(I,Y),P({}),q==null||q()}function le(){return e.jsxs(e.Fragment,{children:[i&&e.jsx("div",{className:"relative flex w-1/3 min-w-0 grow overflow-hidden text-xs",role:"editor-filter-container",children:e.jsx("div",{className:"mt-2 w-[99%]",children:e.jsx(pt,{jsonString:JSON.stringify(z,null,2)})})}),z&&z.length>0&&e.jsx(s.Button,{variant:"secondary",onClick:()=>l(!i),className:"absolute bottom-0 right-6 size-7 p-1",children:i?e.jsx(s.X,{className:"size-3.5 text-muted-foreground"}):e.jsx(s.Filter,{className:"size-3.5 text-muted-foreground"})})]})}function ce(){return e.jsxs(s.ResizablePanelGroup,{className:"flex grow pb-1",direction:"vertical",role:"editor-resizable-group",children:[e.jsxs(s.ResizablePanel,{id:"1",order:1,defaultSize:r?20:100,className:"relative flex grow",children:[e.jsx("div",{id:"sql-container",className:"relative flex w-[99%]",children:e.jsx(mt,{})}),r&&e.jsx("code",{className:"absolute right-6 top-3 text-xs text-muted-foreground/70",children:"sql"})]}),r&&e.jsxs(e.Fragment,{children:[e.jsx(s.ResizableHandle,{withHandle:!0,className:"border"}),e.jsxs(s.ResizablePanel,{id:"2",order:2,defaultSize:80,className:"relative flex grow",children:[e.jsx("div",{id:"python-container",className:"relative flex w-[99%] pt-0",children:e.jsx(xt,{})}),e.jsx("code",{className:"absolute right-6 top-3 text-xs text-muted-foreground/70",children:"python"})]})]})]})}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:[ce(),le()]}),e.jsxs("div",{role:"editor-controls",className:"item-center flex flex-wrap justify-between gap-2 px-6 py-4",children:[e.jsxs("div",{className:"flex grow items-center gap-2",children:[e.jsxs(s.Button,{title:"Shift + Enter",disabled:M||T,onClick:()=>{$()},className:"shrink-0",size:"sm",variant:"outline",children:[M||T?e.jsx(xe,{className:"mr-2 h-4 w-4 animate-spin text-foreground/50"}):e.jsx(s.Play,{className:"mr-2 h-4 w-4"}),"Run"]}),e.jsx(st,{sql:H==null?void 0:H.sql,error:(X==null?void 0:X.message)||((re=H==null?void 0:H.error)==null?void 0:re.message),setShowAIDialog:d,setTriggerAIRun:b,setUserInputforAI:x}),e.jsxs(s.Button,{onClick:E,className:"",size:"sm",variant:"outline",children:[e.jsx(Ns,{className:"mr-2 size-4"}),"Clear"]}),e.jsx(s.Toggle,{pressed:r,onPressedChange:I=>o(I),className:"",size:"sm",variant:"outline",children:e.jsx(ht,{className:"size-4 text-foreground/70"})}),e.jsx(nt,{open:c,setOpen:d,userInput:h,triggerAIRun:j,setTriggerAIRun:b})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(s.Button,{onClick:Q,className:"w-full",size:"sm",variant:"outline",children:[e.jsx(s.Cross2Icon,{className:"mr-2 size-4"}),"Close"]}),e.jsxs(s.Button,{onClick:R,size:"sm",variant:"outline",children:[e.jsx(s.Check,{className:"mr-2 size-4 font-bold text-green-600"}),"Accept"]})]})]})]})}function gt({data:t}){var l;const[n,a]=y.useState([]),o=Object.keys(t[0]).map(c=>({accessorKey:c,header:({column:d})=>{const h=d.getIsSorted();return e.jsx("div",{className:"flex gap-2",children:e.jsxs("div",{className:"flex cursor-pointer items-center",onClick:()=>d.toggleSorting(d.getIsSorted()==="asc"),children:[c,h==="asc"?e.jsx(s.TriangleUpIcon,{className:"ml-2 h-5 w-5"}):h==="desc"?e.jsx(s.TriangleDownIcon,{className:"ml-2 h-5 w-5"}):null]})})}})),i=s.useReactTable({data:t,columns:o,getCoreRowModel:s.getCoreRowModel(),getPaginationRowModel:s.getPaginationRowModel(),onSortingChange:a,getSortedRowModel:s.getSortedRowModel(),manualPagination:!0,state:{sorting:n}});return e.jsx("div",{className:"font-mono text-xs text-foreground/95",children:e.jsxs("table",{className:"w-full",children:[e.jsx(s.TableHeader,{children:i.getHeaderGroups().map(c=>e.jsx(s.TableRow,{children:c.headers.map(d=>e.jsx(s.TableHead,{className:"sticky top-0 h-11 bg-muted font-semibold",children:d.isPlaceholder?null:s.flexRender(d.column.columnDef.header,d.getContext())},d.id))},c.id))}),e.jsx(s.TableBody,{children:(l=i.getRowModel().rows)!=null&&l.length?i.getRowModel().rows.map(c=>e.jsx(s.TableRow,{className:"whitespace-nowrap py-2","data-state":c.getIsSelected()&&"selected",children:c.getVisibleCells().map(d=>e.jsx(s.TableCell,{className:"py-3",children:s.flexRender(d.column.columnDef.cell,d.getContext())},d.id))},c.id)):e.jsx(s.TableRow,{children:e.jsx(s.TableCell,{colSpan:o.length,className:"h-24 text-center",children:"No results."})})})]})})}function jt({card:t}){var L,N,k,A,z,B,F,_,m,g,D;const[n,a]=y.useState(!1),[r,o]=y.useState([]),{authToken:i}=s.useSemaphorContext(),l=s.getTokenParams(i==null?void 0:i.accessToken),c=s.useDashboardStore(v=>v.themeStyle),d={colors:((N=(L=c==null?void 0:c.chart)==null?void 0:L.dataset)==null?void 0:N.backgroundColor)||[]};(k=t.customCardPreferences)!=null&&k.inputData;const{getCard:h}=s.useCustomVisual(((A=t.customCardPreferences)==null?void 0:A.url)||""),x=((z=t.customCardPreferences)==null?void 0:z.visualType)||"single",j=s.useEditorStore(v=>v.frame),{setCustomCardPreferences:b}=s.useEditorActions(),{data:u}=s.useDashboardCardQuery(t),p=y.useCallback((v,O)=>{o(q=>({...q,[v]:O}))},[]);if(!((B=t.customCardPreferences)!=null&&B.componentName))return null;const f=h((F=t.customCardPreferences)==null?void 0:F.componentName);function w(v){a(v)}const S=Object.keys(((_=t.customCardPreferences)==null?void 0:_.dataInputCardIds)||{}).map(v=>{var P,U,G;const O=(U=(P=t.customCardPreferences)==null?void 0:P.dataInputCardIds)==null?void 0:U[v].cardId,q=(G=j==null?void 0:j.cards)==null?void 0:G.find(J=>J.id===O);return q||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(y.Suspense,{fallback:e.jsx(e.Fragment,{}),children:[f&&x==="single"&&e.jsx(f,{params:l,theme:d,settings:(m=t.customCardPreferences)==null?void 0:m.settings,onDataChange:p,data:(u==null?void 0:u.records)||[]}),f&&x==="multiple"&&e.jsxs(e.Fragment,{children:[Object.keys(((g=t.customCardPreferences)==null?void 0:g.dataInputCardIds)||{}).map(v=>{var P,U,G;const O=(U=(P=t.customCardPreferences)==null?void 0:P.dataInputCardIds)==null?void 0:U[v].cardId,q=(G=j==null?void 0:j.cards)==null?void 0:G.find(J=>J.id===O);if(q)return e.jsx(s.MultiInputEmptyRenderer,{onLoadingStatus:w,onDataChange:p,dataInputIndex:v,card:q},q.id+v)}),e.jsx("div",{className:"flex flex-col gap-2",children:e.jsx(f,{theme:d,onDataChange:p,settings:S.map(v=>{var O;return(O=v==null?void 0:v.customCardPreferences)==null?void 0:O.settings}),data:S.map(v=>v!=null&&v.id?r==null?void 0:r[v.id]:[])})})]})]},(D=t.customCardPreferences)==null?void 0:D.componentName)})}function ss({className:t,...n}){var w;const a=s.useEditorStore(S=>S.card),r=((w=a.customCardPreferences)==null?void 0:w.showCardHeader)??!0,o=s.useEditorStore(S=>S.frame),i=s.useDashboardStore(S=>S.dashboard.filters);s.useEditorStore(S=>S.actions.setRunSql);const{updateFilter:l}=s.useDashboardActions(),c=i==null?void 0:i.find(S=>S.id===o.filterId),{data:d,isLoading:h,isFetching:x}=s.useDashboardCardQuery(a),{setCard:j}=s.useEditorActions(),{data:b}=s.useTopoJson(a);if(!a.id)return null;let u;d!=null&&d.records&&(d==null?void 0:d.records.length)>0&&(u=s.createChartConfig({data:d==null?void 0:d.records,cardType:a.type,cfg:a.cfg,customCfg:a.customCfg,preferences:a.preferences,topoJson:b}));function p(S){return e.jsx(jt,{card:S})}function f(){var S;if(d!=null&&d.records&&(d==null?void 0:d.records.length)===0&&!h&&!x)return e.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-2",children:[e.jsx(s.TreePalm,{className:"size-8 text-muted-foreground"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"No records to display"})]});if(a.type==="custom")return p(a);if(!["table","custom"].includes(a.type)&&u)return e.jsx(s.ChartJsVisual,{cfg:u},JSON.stringify(u)+JSON.stringify(a.preferences)+((S=a==null?void 0:a.preferences)==null?void 0:S.customVisualCode));if(a.type==="table"&&(d!=null&&d.records)&&(d==null?void 0:d.records.length)>0)return e.jsxs(s.ScrollArea,{className:"relative mb-2 flex h-full min-h-0 w-full flex-1 grow basis-0",children:[e.jsx(s.TableVisual,{card:a,data:d==null?void 0:d.records}),e.jsx(s.ScrollBar,{orientation:"horizontal"})]})}return e.jsxs(s.Card,{role:"editor-visual-card",className:s.cn("relative flex h-full flex-col rounded-none",t),...n,children:[r&&e.jsxs(s.CardHeader,{className:"flex flex-row items-start justify-between py-4",children:[e.jsxs("div",{children:[e.jsx(s.Editable,{text:a.title,onSave:S=>j({...a,title:S}),children:e.jsx("div",{className:"flex items-center gap-5",children:e.jsx(s.CardTitle,{className:"text-base",children:a.title||"Edit title..."})})},a.title),e.jsx(s.Editable,{text:a.description||"",onSave:S=>j({...a,description:S}),children:e.jsx(s.CardDescription,{children:a.description||"Edit description..."})},a.description)]}),c&&e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(s.Editable,{className:"my-1",text:c.title||c.column,onSave:S=>l({...c,title:S}),children:e.jsx(s.Label,{children:c.title})}),e.jsx(s.FilterComponent,{filter:c})]})]}),e.jsx(s.CardContent,{className:"flex grow flex-col",children:f()})]})}const Be=({language:t,value:n,onChange:a})=>e.jsx(s.Ft,{className:"h-full w-full overflow-hidden text-xs",theme:"default",options:{minimap:{enabled:!1},wordWrap:"on",scrollbar:{verticalScrollbarSize:0,horizontalScrollbarSize:0},fontSize:12,lineHeight:16,renderLineHighlight:"none"},defaultLanguage:t,value:n,onChange:a}),bt=()=>e.jsxs(s.DialogHeader,{children:[e.jsx("div",{className:"flex items-center gap-2",children:e.jsx(s.DialogTitle,{children:"Customize Card"})}),e.jsxs(s.DialogDescription,{children:["See the configuration options and documentation",e.jsx("a",{target:"_blank",className:"ml-1 text-blue-500 underline",href:"https://www.chartjs.org/docs/latest/samples/bar/vertical.html",children:"here."})]})]}),St=({defaultConfig:t,customCode:n,customConfig:a,onConfigChange:r,onCodeChange:o})=>e.jsxs(s.Tabs,{defaultValue:"custom-config",className:"flex w-1/2 flex-col",children:[e.jsxs(s.TabsList,{className:"justify-start rounded-sm rounded-b-none border border-b-0",children:[e.jsx(s.TabsTrigger,{value:"custom-config",children:a?"Custom Config":"Default Config"}),e.jsx(s.TabsTrigger,{value:"output",children:"Output"}),e.jsx(s.TabsTrigger,{value:"custom-code",children:"Custom Code"})]}),e.jsx(s.TabsContent,{value:"output",className:"mt-0 grow rounded-b border border-t-0 p-2",children:e.jsx(s.Textarea,{readOnly:!0,value:t,className:"h-full resize-none border-none font-mono focus-visible:ring-0"})}),e.jsx(s.TabsContent,{value:"custom-config",className:"mt-0 grow rounded-b border border-t-0",children:e.jsx(Be,{language:"json",value:a,onChange:r})}),e.jsx(s.TabsContent,{value:"custom-code",className:"mt-0 grow rounded-b border border-t-0",children:e.jsx(Be,{language:"javascript",value:n,onChange:o})})]}),yt=({error:t,hasCustomConfig:n,onReset:a,onApply:r,onClose:o})=>e.jsxs(s.DialogFooter,{className:"flex items-center",children:[e.jsx(s.Label,{className:"mr-2 text-red-500",children:t}),e.jsx(s.Button,{disabled:!n,onClick:a,variant:"outline",children:"Reset"}),e.jsx(s.Button,{onClick:r,variant:"outline",children:"Apply"}),e.jsx(s.Button,{onClick:o,variant:"outline",children:"Close"})]});function vt(){const[t,n]=y.useState(!1),[a,r]=y.useState(""),[o,i]=y.useState(""),[l,c]=y.useState(""),[d,h]=y.useState(""),x=s.useEditorStore(N=>N.card),j=s.useEditorStore(N=>N.card.customCfg),{data:b}=s.useDashboardCardQuery(x),{data:u}=s.useTopoJson(x),{setCardCustomCfg:p,setCustomVisualCode:f}=s.useEditorActions(),w=N=>{var k,A;return JSON.stringify({...N,data:{...N.data,datasets:(A=(k=N.data)==null?void 0:k.datasets)==null?void 0:A.map(z=>({...z,data:[]}))}},null,2)},S=()=>{var k,A;if(!((k=b==null?void 0:b.records)!=null&&k.length))return;const N=s.createChartConfig({data:b.records,cardType:x.type,cfg:x.cfg,preferences:x.preferences,topoJson:u});if(N){r(w(N)),c(((A=x.preferences)==null?void 0:A.customVisualCode)||"");const z=s.merge(N,j);i(w(z))}},L=()=>{try{if(l&&f(l),o){const N=JSON.parse(o),k=s.getObjectDiff(JSON.parse(a),N);p(k),h("")}}catch{h("Invalid JSON configuration")}};return e.jsxs(s.Dialog,{open:t,onOpenChange:n,children:[e.jsx(s.DialogTrigger,{asChild:!0,children:e.jsx(s.Button,{onClick:S,size:"sm",variant:"outline",className:j?"border-foreground/50 dark:border-foreground/70":"",children:e.jsx(s.Settings,{className:"h-4 w-4"})})}),e.jsxs(s.DialogContent,{className:"max-h-[70vh] min-h-[70vh] overflow-auto sm:min-w-[900px] lg:min-w-[1200px]",children:[e.jsx(bt,{}),e.jsxs("div",{className:"flex grow gap-2",children:[e.jsx(s.ErrorBoundary,{FallbackComponent:s.FallbackEditorCard,children:e.jsx(ss,{className:"w-1/2 rounded shadow-none"})}),e.jsx(St,{defaultConfig:a,customCode:l,customConfig:o,onConfigChange:N=>i(N??""),onCodeChange:N=>c(N??"")})]}),e.jsx(yt,{error:d,hasCustomConfig:!!j,onReset:()=>{i(a),p(null)},onApply:L,onClose:()=>n(!1)})]})]})}function ts(t){return te({attr:{viewBox:"0 0 1024 1024"},child:[{tag:"path",attr:{d:"M926.8 397.1l-396-288a31.81 31.81 0 0 0-37.6 0l-396 288a31.99 31.99 0 0 0-11.6 35.8l151.3 466a32 32 0 0 0 30.4 22.1h489.5c13.9 0 26.1-8.9 30.4-22.1l151.3-466c4.2-13.2-.5-27.6-11.7-35.8zM838.6 417l-98.5 32-200-144.7V199.9L838.6 417zM466 567.2l-89.1 122.3-55.2-169.2L466 567.2zm-116.3-96.8L484 373.3v140.8l-134.3-43.7zM512 599.2l93.9 128.9H418.1L512 599.2zm28.1-225.9l134.2 97.1L540.1 514V373.3zM558 567.2l144.3-46.9-55.2 169.2L558 567.2zm-74-367.3v104.4L283.9 449l-98.5-32L484 199.9zM169.3 470.8l86.5 28.1 80.4 246.4-53.8 73.9-113.1-348.4zM327.1 853l50.3-69h269.3l50.3 69H327.1zm414.5-33.8l-53.8-73.9 80.4-246.4 86.5-28.1-113.1 348.4z"},child:[]}]})(t)}function as(t){return te({attr:{viewBox:"0 0 256 256",fill:"currentColor"},child:[{tag:"path",attr:{d:"M128,24a8,8,0,0,0-8,8V88a8,8,0,0,0,8,8,32,32,0,1,1-27.72,16,8,8,0,0,0-2.93-10.93l-48.5-28A8,8,0,0,0,37.92,76,104,104,0,1,0,128,24ZM48.09,91.1,83,111.26A48.09,48.09,0,0,0,80,128c0,1.53.08,3,.22,4.52L41.28,143A88.16,88.16,0,0,1,48.09,91.1Zm-2.67,67.31,39-10.44A48.1,48.1,0,0,0,120,175.32v40.31A88.2,88.2,0,0,1,45.42,158.41ZM136,215.63V175.32a48,48,0,0,0,0-94.65V40.36a88,88,0,0,1,0,175.27Z"},child:[]}]})(t)}function ns(t){return te({attr:{viewBox:"0 0 256 256",fill:"currentColor"},child:[{tag:"path",attr:{d:"M128,24A104,104,0,1,0,232,128,104.11,104.11,0,0,0,128,24Zm87.63,96H191.48A64.1,64.1,0,0,0,136,64.52V40.37A88.13,88.13,0,0,1,215.63,120ZM120,120H80.68A48.09,48.09,0,0,1,120,80.68Zm0,16v39.32A48.09,48.09,0,0,1,80.68,136Zm16,0h39.32A48.09,48.09,0,0,1,136,175.32Zm0-16V80.68A48.09,48.09,0,0,1,175.32,120ZM120,40.37V64.52A64.1,64.1,0,0,0,64.52,120H40.37A88.13,88.13,0,0,1,120,40.37ZM40.37,136H64.52A64.1,64.1,0,0,0,120,191.48v24.15A88.13,88.13,0,0,1,40.37,136ZM136,215.63V191.48A64.1,64.1,0,0,0,191.48,136h24.15A88.13,88.13,0,0,1,136,215.63Z"},child:[]}]})(t)}function Ct(t){return te({attr:{viewBox:"0 0 256 256",fill:"currentColor"},child:[{tag:"path",attr:{d:"M48,180c0,11,7.18,20,16,20a14.24,14.24,0,0,0,10.22-4.66A8,8,0,0,1,85.78,206.4,30.06,30.06,0,0,1,64,216c-17.65,0-32-16.15-32-36s14.35-36,32-36a30.06,30.06,0,0,1,21.78,9.6,8,8,0,0,1-11.56,11.06A14.24,14.24,0,0,0,64,160C55.18,160,48,169,48,180Zm79.6-8.69c-4-1.16-8.14-2.35-10.45-3.84-1.25-.81-1.23-1-1.12-1.9a4.57,4.57,0,0,1,2-3.67c4.6-3.12,15.34-1.73,19.82-.56A8,8,0,0,0,142,145.86c-2.12-.55-21-5.22-32.84,2.76a20.58,20.58,0,0,0-9,14.95c-2,15.88,13.65,20.41,23,23.11,12.06,3.49,13.12,4.92,12.78,7.59-.31,2.41-1.26,3.34-2.14,3.93-4.6,3.06-15.17,1.56-19.55.36A8,8,0,0,0,109.94,214a61.34,61.34,0,0,0,15.19,2c5.82,0,12.3-1,17.49-4.46a20.82,20.82,0,0,0,9.19-15.23C154,179,137.49,174.17,127.6,171.31Zm83.09-26.84a8,8,0,0,0-10.23,4.84L188,184.21l-12.47-34.9a8,8,0,0,0-15.07,5.38l20,56a8,8,0,0,0,15.07,0l20-56A8,8,0,0,0,210.69,144.47ZM216,88v24a8,8,0,0,1-16,0V96H152a8,8,0,0,1-8-8V40H56v72a8,8,0,0,1-16,0V40A16,16,0,0,1,56,24h96a8,8,0,0,1,5.66,2.34l56,56A8,8,0,0,1,216,88Zm-27.31-8L160,51.31V80Z"},child:[]}]})(t)}function rs(t){return te({attr:{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"},child:[{tag:"path",attr:{d:"M6 16m-3 0a3 3 0 1 0 6 0a3 3 0 1 0 -6 0"},child:[]},{tag:"path",attr:{d:"M16 19m-2 0a2 2 0 1 0 4 0a2 2 0 1 0 -4 0"},child:[]},{tag:"path",attr:{d:"M14.5 7.5m-4.5 0a4.5 4.5 0 1 0 9 0a4.5 4.5 0 1 0 -9 0"},child:[]}]})(t)}function os(t){return te({attr:{viewBox:"0 0 24 24"},child:[{tag:"path",attr:{fill:"none",d:"M0 0h24v24H0z"},child:[]},{tag:"path",attr:{d:"m2 19.99 7.5-7.51 4 4 7.09-7.97L22 9.92l-8.5 9.56-4-4-6 6.01-1.5-1.5zm1.5-4.5 6-6.01 4 4L22 3.92l-1.41-1.41-7.09 7.97-4-4L2 13.99l1.5 1.5z"},child:[]}]})(t)}function is(t){return te({attr:{viewBox:"0 0 24 24"},child:[{tag:"path",attr:{fill:"none",d:"M0 0h24v24H0z"},child:[]},{tag:"path",attr:{d:"M4 9h4v11H4zM4 4h4v4H4zM10 7h4v4h-4zM16 10h4v4h-4zM16 15h4v5h-4zM10 12h4v8h-4z"},child:[]}]})(t)}function ls(t){return te({attr:{version:"1.2",baseProfile:"tiny",viewBox:"0 0 24 24"},child:[{tag:"path",attr:{d:"M4 18c-.552 0-1-.448-1-1v-6.382l-.553.276c-.495.248-1.095.046-1.342-.447-.247-.494-.046-1.094.448-1.342l2-1c.31-.155.678-.139.973.044.294.183.474.504.474.851v8c0 .552-.448 1-1 1zM13 18h-5c-.404 0-.769-.244-.924-.617-.155-.374-.069-.804.217-1.09l4-4c.254-.254.394-.591.394-.95 0-.358-.14-.695-.394-.949-.508-.508-1.39-.508-1.9.001-.253.252-.393.589-.393.948 0 .552-.448 1-1 1s-1-.448-1-1c0-.894.348-1.733.98-2.364 1.265-1.263 3.464-1.263 4.727.001.632.631.979 1.471.979 2.363 0 .893-.348 1.733-.979 2.364l-2.293 2.293h2.586c.552 0 1 .448 1 1s-.448 1-1 1zM20.955 12.377c.338-.457.545-1.016.545-1.627 0-1.517-1.234-2.75-2.75-2.75-1.031 0-1.966.569-2.44 1.484-.254.49-.063 1.094.428 1.348.49.254 1.094.062 1.348-.428.128-.249.383-.404.664-.404.414 0 .75.336.75.75s-.336.75-.75.75c-.552 0-1 .448-1 1s.448 1 1 1c.689 0 1.25.561 1.25 1.25s-.561 1.25-1.25 1.25-1.25-.561-1.25-1.25c0-.552-.448-1-1-1s-1 .448-1 1c0 1.792 1.458 3.25 3.25 3.25s3.25-1.458 3.25-3.25c0-.939-.406-1.779-1.045-2.373z"},child:[]}]})(t)}function cs(t){return te({attr:{viewBox:"0 0 512 512"},child:[{tag:"path",attr:{d:"M217 25v14h78V25h-78zm0 32v46h14V71h50v32h14V57h-78zm32 32v14h14V89h-14zm-64 32v46h30v-46h-30zm48 0v14h46v-14h-46zm64 0v46h30v-46h-30zm-64 32v14h46v-14h-46zm-80 32v46h62v-46h-62zm80 0v14h46v-14h-46zm64 0v46h62v-46h-62zm-64 32v14h46v-14h-46zm-112 32v46h94v-46h-94zm112 0v14h46v-14h-46zm64 0v46h94v-46h-94zm-64 32v14h46v-14h-46zM89 313v46h126v-46H89zm144 0v14h46v-14h-46zm64 0v46h126v-46H297zm-64 32v14h46v-14h-46zM57 377v46h158v-46H57zm176 0v14h46v-14h-46zm64 0v46h158v-46H297zm-64 32v14h46v-14h-46zM25 441v46h190v-46H25zm208 0v14h46v-14h-46zm64 0v46h190v-46H297zm-64 32v14h46v-14h-46z"},child:[]}]})(t)}function ds(t){const[n,a]=y.useState(null);return n}function us(){const{authToken:t}=s.useSemaphorContext(),{data:n,isLoading:a,isFetching:r,isError:o}=s.useQuery({queryKey:["plugins",t==null?void 0:t.accessToken],queryFn:()=>s.getPlugins(t==null?void 0:t.accessToken)});return{data:n,isLoading:a,isFetching:r,isError:o}}function Nt({onChartTypeChange:t}){const[n,a]=y.useState([]),{data:r}=us();return y.useEffect(()=>{(async()=>{var i;if(r){const c=(await Promise.all((i=r==null?void 0:r.plugins)==null?void 0:i.map(async d=>(await s.loadManifest(d.value)).visuals.map(j=>({name:j.name,icon:j.icon,url:d.value}))))).flat();a(c)}})()},[r]),n.length===0?null:e.jsxs(e.Fragment,{children:[e.jsx(s.Separator,{className:"my-2"}),e.jsx("div",{className:"grid grid-cols-4 place-items-center",children:n.map((o,i)=>e.jsx(wt,{text:o.name,onClick:()=>t("custom",o),icon:o.icon},o.url+o.name+i))})]})}const wt=({text:t,icon:n,onClick:a})=>{const r=ds(),o=t.charAt(0).toUpperCase();return e.jsx(s.Button,{onClick:a,title:t,variant:"ghost",children:r?e.jsx(r,{className:"h-4 w-4"}):o})};function kt(){var x,j;const[t,n]=y.useState(!1),a=s.useEditorStore(b=>b.card),r=a.type,{setCardType:o,setCardPreferences:i,setChartOrientation:l}=s.useEditorStore(b=>b.actions),{setCardCustomCfg:c,setCustomCardPreferences:d}=s.useEditorActions();function h(b,u){c(null),i({}),o(b),u&&d({type:"component",visualType:"single",url:u.url,componentName:u.name,icon:u.icon}),n(!1)}return e.jsxs(s.Popover,{open:t,onOpenChange:n,children:[e.jsx(s.PopoverTrigger,{asChild:!0,children:e.jsx(s.Button,{size:"sm",variant:"outline",children:e.jsx(Et,{className:"h-4 w-4",chartType:r,customIcon:(x=a.customCardPreferences)==null?void 0:x.icon,componentName:(j=a.customCardPreferences)==null?void 0:j.componentName})})}),e.jsxs(s.PopoverContent,{className:"w-50",children:[e.jsxs("div",{className:"grid grid-cols-4 place-items-center",children:[e.jsx(s.Button,{onClick:()=>h("bar"),className:"font-normal",variant:"ghost",children:e.jsx(Ne,{className:"size-5"})}),e.jsx(s.Button,{onClick:()=>h("line"),variant:"ghost",children:e.jsx(we,{className:"size-5"})}),e.jsx(s.Button,{onClick:()=>h("stackedBar"),variant:"ghost",children:e.jsx(is,{className:"size-5",strokeWidth:0})}),e.jsx(s.Button,{onClick:()=>h("stackedLine"),variant:"ghost",children:e.jsx(os,{className:"size-5",strokeWidth:0})}),e.jsx(s.Button,{onClick:()=>h("scatter"),variant:"ghost",children:e.jsx(Ue,{className:"size-5"})}),e.jsx(s.Button,{onClick:()=>h("bubble"),variant:"ghost",children:e.jsx(rs,{className:"size-4"})}),e.jsx(s.Button,{onClick:()=>h("pie"),variant:"ghost",children:e.jsx(Ge,{className:"size-5"})}),e.jsx(s.Button,{onClick:()=>h("doughnut"),variant:"ghost",children:e.jsx(as,{className:"size-5",strokeWidth:1})}),e.jsx(s.Button,{onClick:()=>h("radar"),variant:"ghost",children:e.jsx(ts,{className:"size-5 font-extralight",strokeWidth:.5})}),e.jsx(s.Button,{onClick:()=>h("polarArea"),variant:"ghost",children:e.jsx(ns,{className:"size-5"})}),e.jsx(s.Button,{onClick:()=>h("pyramid"),variant:"ghost",children:e.jsx(cs,{className:"size-5"})}),e.jsx(s.Button,{onClick:()=>h("range"),variant:"ghost",children:e.jsx(He,{className:"size-5"})}),e.jsx(s.Button,{onClick:()=>h("table"),variant:"ghost",children:e.jsx(Ee,{className:"size-5"})}),e.jsx(s.Button,{onClick:()=>h("kpi"),variant:"ghost",children:e.jsx(ls,{className:"size-6"})}),e.jsx(s.Button,{onClick:()=>h("text"),variant:"ghost",children:e.jsx(De,{className:"size-4"})}),e.jsx(s.Button,{onClick:()=>h("map"),variant:"ghost",children:e.jsx($e,{className:"size-4"})}),e.jsx(s.Button,{onClick:()=>h("custom"),variant:"ghost",children:e.jsx(Qe,{className:"size-4"})})]}),e.jsx(Nt,{onChartTypeChange:h})]})]})}function Et({chartType:t,className:n,customIcon:a,componentName:r}){const o=ds();switch(t){case"bar":return e.jsx(Ne,{className:n});case"line":return e.jsx(we,{className:n});case"pie":return e.jsx(Ge,{className:n});case"radar":return e.jsx(ts,{className:n});case"scatter":return e.jsx(Ue,{className:n});case"bubble":return e.jsx(rs,{className:n});case"doughnut":return e.jsx(as,{className:n});case"stackedBar":return e.jsx(is,{className:"size-4 text-foreground/70"});case"stackedLine":return e.jsx(os,{className:"size-4 text-foreground/70"});case"polarArea":return e.jsx(ns,{className:n});case"pyramid":return e.jsx(cs,{className:n});case"range":return e.jsx(He,{className:n});case"kpi":return e.jsx(ls,{className:n});case"text":return e.jsx(De,{className:n});case"map":return e.jsx($e,{className:n});case"custom":return a&&o?e.jsx(o,{className:n}):r?r==null?void 0:r.charAt(0).toUpperCase():e.jsx(Qe,{className:n});default:return e.jsx(Ee,{className:n})}}function Dt(){var a;const t=s.useEditorStore(r=>r.card);(a=t.customCardPreferences)==null||a.showCardHeader;const{setCustomCardPreferences:n}=s.useEditorActions();return e.jsxs(s.DropdownMenu,{children:[e.jsx(s.DropdownMenuTrigger,{asChild:!0,children:e.jsx(ke,{className:"size-4 cursor-pointer text-muted-foreground/70 transition-colors hover:text-muted-foreground"})}),e.jsx(s.DropdownMenuContent,{align:"start",className:"w-40 text-muted-foreground",children:e.jsxs(s.DropdownMenuItem,{onClick:()=>{navigator.clipboard.writeText(t.id),s.ue.success("Card ID copied to clipboard")},className:"cursor-pointer space-x-2",children:[e.jsx(s.IdCard,{className:"size-5"}),e.jsx("span",{children:"Copy Card ID"})]})})]})}function _e(){var m;const t=s.useEditorStore(g=>g.frame),n=s.useEditorStore(g=>g.card),a=s.useEditorStore(g=>g.isShowingVisual),r=s.useEditorStore(g=>g.isSqlRunning),o=s.useEditorStore(g=>g.pythonStdOut);s.useEditorStore(g=>g.actions.setRunSql);const{setFrame:i,setCard:l,updateCardInFrame:c,setActiveTabCardId:d}=s.useEditorActions(),{data:h,isLoading:x,isFetching:j,error:b}=s.useDashboardCardQuery(n);if(!n)return e.jsx(e.Fragment,{children:"No Active Card"});function u(){const g={connectionId:n.connectionId,id:s.v4(),title:"Title",description:"Description",preferences:{onClickFilter:[{columnIndex:0,expression:""}]},type:"bar",sql:"",data:[]};p(g)}function p(g){const D={...t,cards:[...t.cards,g],activeCardId:g.id};i(D),d(g.id)}function f(){const g={...n,id:s.v4(),title:`${n.title} Copy`,tabTitle:`${n.tabTitle||n.title} Copy`};p(g)}function w(g){const D=t.cards.filter(q=>q.id!==g),v=D[0],O={...t,cards:D,activeCardId:v.id};i(O),d(v.id),l(v)}function S(g){d(g)}const L=(g,D)=>{console.log("handleDragStart",D),g.dataTransfer.setData("tabIndex",D.toString())},N=g=>{g.preventDefault()},k=(g,D)=>{const v=g.dataTransfer.getData("tabIndex");if(v===D.toString())return;const O=Array.from(t.cards),[q]=O.splice(parseInt(v),1);O.splice(D,0,q),i({...t,cards:O})};function A(g,D){return g.cards.length===1&&(D.displayTab===!0||D.displayTab===void 0)||g.activeCardId!==D.id&&(D.displayTab===!0||D.displayTab===void 0)?null:e.jsx("div",{onClick:()=>{const v=D.displayTab===void 0?!1:!D.displayTab;l({...D,displayTab:v}),c({...D,displayTab:v})},children:D.displayTab===!0||D.displayTab===void 0?e.jsx(s.Eye,{className:"mr-2 size-3.5 text-muted-foreground hover:text-foreground"}):e.jsx(ws,{className:"mr-2 size-3.5 text-muted-foreground hover:text-foreground"})})}function z(){return e.jsxs(s.Tabs,{onValueChange:S,value:t.activeCardId,className:"flex grow flex-col",children:[t.cards.map(g=>e.jsx(s.TabsContent,{className:"mt-0 grow",value:g.id,children:B()},g.id)),e.jsx(s.TabsList,{className:"group mx-6 justify-between",children:e.jsxs("div",{className:"flex items-center",children:[t.cards.map((g,D)=>e.jsx(s.Editable,{text:g.tabTitle||g.title,onSave:v=>{l({...n,tabTitle:v}),c({...n,tabTitle:v})},children:e.jsxs(s.TabsTrigger,{draggable:!0,onDragStart:v=>L(v,D),onDragOver:N,onDrop:v=>k(v,D),className:"",value:g.id,children:[A(t,g),g.tabTitle||g.title,t.activeCardId===g.id&&t.cards.length>1&&e.jsx(s.X,{className:"ml-2 size-3.5 text-muted-foreground hover:text-foreground",onClick:()=>w(g.id)})]})},g.id)),e.jsx(s.Button,{className:"ml-1 h-8 px-2 hover:bg-muted-foreground/50",variant:"outline",onClick:u,children:e.jsx(s.Plus,{className:"h-4 w-4"})}),e.jsx(s.Button,{className:"invisible ml-1 h-8 px-2 hover:bg-muted-foreground/50 group-hover:visible",variant:"outline",onClick:f,children:e.jsx(vs,{className:"h-4 w-4"})})]})})]})}function B(){return n.type==="kpi"?e.jsx("div",{className:"flex h-full items-center justify-center",children:e.jsx("div",{className:"w-1/2 rounded-md border",children:e.jsx(s.KPICard,{card:n,data:h==null?void 0:h.records})})}):n.type==="text"?e.jsx("div",{className:"flex h-full items-center justify-center",children:e.jsx("div",{className:"w-1/2 rounded-md border",children:e.jsx(s.ScrollArea,{className:"mx-3 my-6 h-[300px] overflow-y-auto break-words px-3",children:e.jsx(s.TextCard,{isLoading:r,card:n,data:h==null?void 0:h.records})})})}):e.jsx(s.ErrorBoundary,{FallbackComponent:s.FallbackEditorCard,children:e.jsx(ss,{className:"grow border-none shadow-none"})})}function F(){const g=JSON.stringify(h==null?void 0:h.records,null,2),D=new Blob([g],{type:"application/json"}),v=URL.createObjectURL(D),O=document.createElement("a");O.href=v,O.download=`${n.title}.json`,O.click()}function _(){const D=[Object.keys(h==null?void 0:h.records.reduce((P,U)=>({...P,...U}),{})).join(","),...((h==null?void 0:h.records)||[]).map(P=>Object.values(P).join(","))].join(`
|
|
192
|
+
`),v=new Blob([D],{type:"text/csv"}),O=URL.createObjectURL(v),q=document.createElement("a");q.href=O,q.download=`${n.title}.csv`,q.click()}return e.jsxs("div",{className:"relative flex h-full flex-col py-3",children:[(x||j)&&e.jsx("div",{className:"absolute bottom-0 left-0 right-0 top-0 z-50 m-auto flex h-10 w-10 items-center justify-center rounded-md bg-muted",children:e.jsx(xe,{className:"h-8 w-8 animate-spin text-muted-foreground"})}),e.jsxs("div",{className:"mb-0 flex min-h-10 items-center justify-end gap-2 px-6",children:[a&&e.jsxs("div",{className:"flex grow items-center gap-2",children:[e.jsx(kt,{}),!["table","custom"].includes(n.type)&&e.jsx(vt,{}),e.jsx(Dt,{})]}),!a&&e.jsxs("div",{className:"flex grow items-center gap-1",children:[e.jsx(s.Button,{className:"h-7 w-fit px-1 font-mono text-xs text-muted-foreground/70",variant:"ghost",size:"icon",onClick:_,children:e.jsx(Ct,{className:"size-4"})}),e.jsx(s.Button,{className:"h-7 w-fit px-1 font-mono text-xs text-muted-foreground/70",variant:"ghost",size:"icon",onClick:F,children:e.jsx(ks,{strokeWidth:1.5,className:"size-4"})}),e.jsx(s.CopyButton,{text:JSON.stringify(h==null?void 0:h.records,null,2),className:"h-7 w-fit px-1 font-mono text-xs text-muted-foreground/70"})]}),e.jsx(Tt,{})]}),a?z():e.jsxs(s.ResizablePanelGroup,{className:"px-6",direction:"horizontal",children:[o&&e.jsxs(e.Fragment,{children:[e.jsx(s.ResizablePanel,{id:"1",order:1,defaultSize:30,minSize:10,className:"relative flex h-full min-h-0 w-full flex-1 basis-0",children:o&&e.jsx(It,{})}),e.jsx(s.ResizableHandle,{})]}),e.jsx(s.ResizablePanel,{id:"2",order:2,minSize:10,className:"relative flex h-full min-h-0 w-full flex-1 basis-0",children:e.jsxs(s.ScrollArea,{className:"relative flex h-full min-h-0 w-full flex-1 basis-0",children:[(h==null?void 0:h.records)&&(h==null?void 0:h.records.length)>0&&e.jsx(gt,{data:(h==null?void 0:h.records)||[]}),(b||(h==null?void 0:h.error))&&e.jsx("span",{className:"font-mono text-xs",children:(b==null?void 0:b.message)||((m=h==null?void 0:h.error)==null?void 0:m.message)}),e.jsx(s.ScrollBar,{orientation:"horizontal"})]})})]})]})}function It(){const t=s.useEditorStore(a=>a.pythonStdOut);if(!t)return null;const n=t.replace(/\n/g,"<br>");return e.jsxs("div",{className:"relative flex w-full flex-col border-r",children:[e.jsx("div",{className:"sticky top-0 flex max-h-11 min-h-11 grow items-center border-b bg-muted px-3 font-mono text-xs font-semibold text-foreground/70",children:"Python Output"}),e.jsxs(s.ScrollArea,{className:"overflow-y-auto px-2 pt-1 font-mono text-xs text-foreground/90",children:[e.jsx("div",{dangerouslySetInnerHTML:{__html:n}}),e.jsx(s.ScrollBar,{orientation:"horizontal"})]})]})}function Tt(){const t=s.useEditorStore(a=>a.isShowingVisual),n=s.useEditorStore(a=>a.actions.setIsShowingVisual);return e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(s.Label,{htmlFor:"visualize",children:"Chart"}),e.jsx(s.Switch,{checked:t,onCheckedChange:()=>n(!t),id:"visualize",className:"data-[state=checked]:bg-foreground/50"})]})}function Lt({options:t,value:n,onValueChange:a}){return e.jsx(s.RadioGroup,{value:n,onValueChange:a,className:"flex gap-4",defaultValue:t[0].value,children:t.map(r=>e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(s.RadioGroupItem,{value:r.value,id:r.value}),e.jsx("label",{className:"text-sm",htmlFor:r.value,children:r.label})]},r.value))})}function ae({label:t,options:n,value:a,onValueChange:r,className:o}){return e.jsxs(s.Select,{value:a,onValueChange:r,children:[e.jsx(s.SelectTrigger,{className:s.cn("w-full focus:ring-0 focus:ring-offset-0",o),children:e.jsx(s.SelectValue,{placeholder:t})}),e.jsx(s.SelectContent,{children:e.jsxs(s.SelectGroup,{children:[e.jsx(s.SelectLabel,{children:t}),n.map(i=>e.jsx(s.SelectItem,{value:i.value,children:i.label},i.value))]})})]})}function me({children:t,summary:n,open:a,className:r}){return e.jsxs("details",{open:a,className:s.cn("space-y-4 [&_summary>svg]:open:-rotate-180",r),children:[e.jsxs("summary",{className:"flex cursor-pointer list-none items-center justify-between gap-4",children:[e.jsx(s.Label,{children:n}),e.jsx(s.ChevronUp,{className:"h-4 w-4"})]}),e.jsx("div",{className:"transition-all ease-in-out",children:t})]})}function At(){var f,w;const t=s.useEditorStore(S=>S.card.customCardPreferences),{data:n}=us(),a=(n==null?void 0:n.plugins)||[],r=s.useEditorStore(S=>S.card),o=s.useEditorStore(S=>S.frame),i=(t==null?void 0:t.visualType)||"single",{setCustomCardPreferences:l}=s.useEditorActions(),{components:c,manifest:d}=s.useCustomVisual((t==null?void 0:t.url)||""),h=(f=d==null?void 0:d.visuals)==null?void 0:f.find(S=>S.name===(t==null?void 0:t.componentName));function x(S,L){if(!t)return;const k={...(t==null?void 0:t.dataInputCardIds)||{},[S]:{cardId:L,hookRef:null}};l({...t,dataInputCardIds:k})}function j(S){var N,k;const L=(N=o==null?void 0:o.cards)==null?void 0:N.filter(A=>{var z;return((z=A==null?void 0:A.customCardPreferences)==null?void 0:z.visualType)!=="multiple"}).map(A=>({value:A.id,label:A.tabTitle||A.title}));return e.jsx("div",{className:"space-y-2",children:(k=S==null?void 0:S.dataInputs)==null?void 0:k.map((A,z)=>{var B,F;return e.jsxs("div",{className:"grid grid-cols-10 gap-2",children:[e.jsx("div",{className:"col-span-4 flex items-center",children:A}),e.jsx(ae,{className:"col-span-6 h-8 w-full justify-between",label:"",options:L||[],value:((F=(B=t==null?void 0:t.dataInputCardIds)==null?void 0:B[z])==null?void 0:F.cardId)||"",onValueChange:_=>x(z,_)})]},z+Math.random())})})}function b(S,L,N=[]){var k,A;return t?S==="input"?e.jsx(s.Input,{className:`h-8 w-full ${s.removeRing}`,value:((k=t==null?void 0:t.settings)==null?void 0:k[L])||"",onChange:z=>{l({...t,settings:{...t==null?void 0:t.settings,[L]:z.target.value}})}},L):S==="select"?e.jsx(ae,{className:"h-8 w-full",label:"",options:N,value:((A=t==null?void 0:t.settings)==null?void 0:A[L])||"",onValueChange:z=>{l({...t,settings:{...t==null?void 0:t.settings,[L]:z}})}}):null:null}function u(S){const L=Object.entries((S==null?void 0:S.settings)||{});return e.jsx("div",{className:"space-y-3",children:L.map(([N,k])=>e.jsxs("div",{className:"space-y-2",children:[e.jsx(s.Label,{children:k.title}),b(k.ui,N,k.options)]},N))})}function p(S){t&&l({...t,visualType:S,componentName:""})}return e.jsxs("div",{className:"p-6",children:[e.jsx(me,{summary:"Plugin Settings",children:e.jsx("div",{className:"space-y-4 text-sm",children:e.jsxs("div",{className:"space-y-4 text-sm",children:[e.jsx("div",{className:"space-y-2",children:e.jsx("div",{className:"px-2",children:e.jsx(ae,{className:"h-8 w-full",label:"",options:a,value:(t==null?void 0:t.url)||"",onValueChange:S=>l({...t||{url:"",componentName:""},url:S})})})}),((t==null?void 0:t.type)==="component"||(t==null?void 0:t.type)===void 0)&&e.jsx(Lt,{options:[{value:"single",label:"Single Visual"},{value:"multiple",label:"Multi-Visual"}],value:i,onValueChange:p}),((t==null?void 0:t.type)==="component"||(t==null?void 0:t.type)===void 0)&&t&&e.jsx(e.Fragment,{children:e.jsxs("div",{className:"space-y-2",children:[e.jsx(s.Label,{children:"Component"}),e.jsx("div",{className:"space-y-2 px-2",children:c&&e.jsx(ae,{className:"h-8 w-full",label:"",options:(c==null?void 0:c.filter(S=>S.type===i).map(S=>({value:S.name,label:S.name})))||[],value:t.componentName,onValueChange:S=>{console.log("changing value",S),l({...t,componentName:S})}})})]})})]})})}),e.jsx(s.Separator,{className:"my-4"}),((w=r==null?void 0:r.customCardPreferences)==null?void 0:w.componentName)&&e.jsxs(me,{summary:"Component Settings",children:[h&&h.dataInputs&&e.jsxs("div",{className:"space-y-3",children:[e.jsx(s.Label,{children:"Input Mapping"}),e.jsx("div",{className:"px-2",children:j(h)})]}),h&&h.settings&&e.jsx("div",{className:"space-y-3",children:e.jsx("div",{className:"px-2",children:u(h)})})]})]})}function ie(){const[t,n]=y.useState([]);s.useEditorStore(x=>x.card.cfg);const a=s.useEditorStore(x=>x.card.preferences),{setCardCfg:r,setFilterOnClickColumnIndex:o,setCardPreferences:i}=s.useEditorStore(x=>x.actions),l=s.useEditorStore(x=>x.queryResultColumns);s.useEditorStore(x=>{var j;return(j=x.card.preferences)==null?void 0:j.filterOnClickColumnIndex}),y.useEffect(()=>{l&&n(new Array(l.length).fill(!1))},[l]);function c(x,j){var b,u;j?a!=null&&a.onClickFilter&&((b=a==null?void 0:a.onClickFilter)==null?void 0:b.length)>0?i({...a,onClickFilter:[...a.onClickFilter,{columnIndex:x,expression:""}]}):i({...a,onClickFilter:[{columnIndex:x,expression:""}]}):(i({...a,onClickFilter:(u=a==null?void 0:a.onClickFilter)==null?void 0:u.filter(p=>p.columnIndex!==x)}),n(p=>{const f=[...p];return f[x]=!1,f}))}function d(x,j){var u;const b=(u=a==null?void 0:a.onClickFilter)==null?void 0:u.map(p=>p.columnIndex===x?{...p,expression:j.target.value}:p);i({...a,onClickFilter:b})}function h(x){var j,b,u,p;if(t!=null&&t[x]||(b=(j=a==null?void 0:a.onClickFilter)==null?void 0:j.find(f=>f.columnIndex===x))!=null&&b.expression)return e.jsx(s.Input,{value:(p=(u=a==null?void 0:a.onClickFilter)==null?void 0:u.find(f=>f.columnIndex===x))==null?void 0:p.expression,onChange:f=>d(x,f),type:"text",className:"h-9 w-full font-mono text-xs focus-visible:ring-0 focus-visible:ring-ring focus-visible:ring-offset-0",placeholder:"Expression"})}return e.jsxs("div",{className:"space-y-2",children:[e.jsx(s.Label,{children:"On Click"}),l==null?void 0:l.map((x,j)=>{var b,u;return e.jsx("div",{className:"xbg-red-100 group flex items-center justify-between space-y-2",children:e.jsxs("div",{className:"grow",children:[e.jsxs("div",{className:"flex items-center space-x-2 py-2",children:[e.jsx(s.Checkbox,{checked:!!((b=a==null?void 0:a.onClickFilter)!=null&&b.find(p=>p.columnIndex===j)),onCheckedChange:p=>c(j,p)}),e.jsx("label",{className:"text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70",children:x}),e.jsx("div",{className:"flex items-center gap-2",children:((u=a==null?void 0:a.onClickFilter)==null?void 0:u.find(p=>p.columnIndex===j))&&e.jsx(s.Pencil,{onClick:()=>{n(p=>{const f=[...p];return f[j]=!p[j],f})},className:"invisible size-3 cursor-pointer text-gray-400 group-hover:visible"})})]}),h(j)]})},x)})]})}function Se(){var l,c,d;const t=s.useEditorStore(h=>h.card.preferences),n=s.useEditorStore(h=>h.card.cfg),{setCardCfg:a,setCardPreferences:r,setChartOrientation:o}=s.useEditorStore(h=>h.actions);(l=n==null?void 0:n.options)!=null&&l.indexAxis;function i(h){o(h)}return e.jsxs(s.RadioGroup,{value:((c=t==null?void 0:t.chartOptions)==null?void 0:c.indexAxis)||((d=n==null?void 0:n.options)==null?void 0:d.indexAxis)||"x",onValueChange:i,className:"flex gap-3",defaultValue:"x",children:[e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(s.RadioGroupItem,{value:"x",id:"r1"}),e.jsx("label",{className:"text-sm",htmlFor:"r1",children:"Vertical"})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(s.RadioGroupItem,{value:"y",id:"r2"}),e.jsx("label",{className:"text-sm",htmlFor:"r2",children:"Horizontal"})]})]})}const fe="focus-visible:ring-0 focus-visible:ring-ring focus-visible:ring-offset-0";function Pe(t,n){var r,o,i;const a=s.getNumberAxis(t,n);return((i=(o=(r=t==null?void 0:t.chartOptions)==null?void 0:r.scales)==null?void 0:o[a])==null?void 0:i.type)||"linear"}function hs(){var P,U,G,J,ee,H;const[t,n]=y.useState(!1),a=s.useEditorStore(M=>{var T;return(T=M.card)==null?void 0:T.preferences}),r=s.useEditorStore(M=>{var T;return(T=M.card)==null?void 0:T.cfg}),o=s.getNumberAxis(a,r),[i,l]=y.useState(Pe(a)),[c,d]=y.useState(((G=(U=(P=a==null?void 0:a.chartOptions)==null?void 0:P.scales)==null?void 0:U[o])==null?void 0:G.min)||""),[h,x]=y.useState(((H=(ee=(J=a==null?void 0:a.chartOptions)==null?void 0:J.scales)==null?void 0:ee[o])==null?void 0:H.max)||""),[j,b]=y.useState(c||h?"custom":"auto"),[u,p]=y.useState(""),[f,w]=y.useState(0),[S,L]=y.useState(""),[N,k]=y.useState(""),[A,z]=y.useState(""),B=s.useEditorStore(M=>M.actions.setCardPreferences),{updateCardInFrame:F}=s.useEditorActions(),_=s.useEditorStore(M=>M.card),m=s.useEditorStore(M=>{var T;return(T=M.card)==null?void 0:T.type}),g=["pie","doughnut","polarArea"].includes(m);y.useEffect(()=>{var M,T,W,K,X,Z,$,E,V,R,Q,le,ce,re;l(Pe(a)),d(((W=(T=(M=a==null?void 0:a.chartOptions)==null?void 0:M.scales)==null?void 0:T[o])==null?void 0:W.min)===0?0:""),x(((Z=(X=(K=a==null?void 0:a.chartOptions)==null?void 0:K.scales)==null?void 0:X[o])==null?void 0:Z.max)||""),p(((R=(V=(E=($=a==null?void 0:a.chartOptions)==null?void 0:$.scales)==null?void 0:E[o])==null?void 0:V.ticks)==null?void 0:R.stepSize)||""),w(((Q=a==null?void 0:a.numberAxisFormat)==null?void 0:Q.decimalPlaces)||0),L(((le=a==null?void 0:a.numberAxisFormat)==null?void 0:le.suffix)||""),k(((ce=a==null?void 0:a.numberAxisFormat)==null?void 0:ce.currency)||""),z(((re=a==null?void 0:a.numberAxisFormat)==null?void 0:re.locale)||"")},[t,a,o]);function D(M,T){return T===""||/^[0-9\b]+$/.test(T)?Number(T):Number(M)}function v(){const M=[...new Set(s.LOCALE_CURRENCY_PAIRS.map(T=>T.currency))];return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"grid grid-cols-6 items-center gap-2",children:[e.jsx(s.Label,{className:"col-span-2 hover:cursor-pointer hover:underline",htmlFor:"currency",children:e.jsx("a",{target:"_blank",href:"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat",children:"Currency"})}),e.jsxs(s.Select,{value:N||"none",onValueChange:T=>k(T==="none"?"":T),children:[e.jsx(s.SelectTrigger,{className:"col-span-2 h-8 w-full focus:ring-1 focus:ring-offset-0",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{children:e.jsxs(s.SelectGroup,{children:[e.jsx(s.SelectLabel,{children:"Currency"}),e.jsx(s.SelectItem,{value:"none",children:"None"}),M.map(T=>e.jsx(s.SelectItem,{value:T,children:T},T))]})})]}),e.jsxs(s.Select,{value:A,onValueChange:T=>z(T),children:[e.jsx(s.SelectTrigger,{className:"col-span-2 h-8 w-full focus:ring-1 focus:ring-offset-0",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{children:e.jsxs(s.SelectGroup,{children:[e.jsx(s.SelectLabel,{children:"Locale"}),s.LOCALE_CURRENCY_PAIRS.map(T=>e.jsx(s.SelectItem,{value:T.locale,children:T.locale},T.locale))]})})]})]}),e.jsxs("div",{className:"grid grid-cols-9 items-center gap-2",children:[e.jsx(s.Label,{className:"col-span-3",htmlFor:"format",children:"Decimals"}),e.jsx(s.Input,{value:f,onChange:T=>w(Number(T.target.value)),id:"format",className:`col-span-6 h-8 w-full tracking-wide ${fe}`})]})]})}function O(){return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"grid grid-cols-3 items-center gap-2",children:[e.jsx(s.Label,{htmlFor:"range",children:"Range"}),e.jsx(s.Input,{id:"min",value:c,onChange:M=>d(T=>D(T,M.target.value)),className:`col-span-1 h-8 w-full ${fe}`}),e.jsx(s.Input,{value:h,onChange:M=>x(T=>D(T,M.target.value)),id:"max",className:`col-span-1 h-8 w-full ${fe}`})]}),e.jsxs("div",{className:"grid grid-cols-3 items-center gap-2",children:[e.jsx(s.Label,{htmlFor:"step-size",children:"Step Size"}),e.jsx(s.Input,{value:u,onChange:M=>p(T=>D(T,M.target.value)),id:"step-size",className:`col-span-1 h-8 w-full ${fe}`})]})]})}function q(){var K;let M={};j==="custom"&&(M={min:c,max:h,ticks:{stepSize:u}});const T={...a||{},chartOptions:{...a==null?void 0:a.chartOptions,scales:{...(K=a==null?void 0:a.chartOptions)==null?void 0:K.scales,[o]:{type:i,...i==="linear"?M:{}}}},numberAxisFormat:{decimalPlaces:f,suffix:S,currency:N,locale:A}};console.log(T),B(T);const W={..._,preferences:T};F(W)}return e.jsxs(s.Popover,{onOpenChange:M=>n(M),children:[e.jsx(s.PopoverTrigger,{asChild:!0,children:e.jsx(s.SliderIcon,{className:"size-4 cursor-pointer text-muted-foreground hover:text-foreground"})}),e.jsx(s.PopoverContent,{align:"center",className:"max-w-65",children:e.jsxs("div",{className:"grid gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("h4",{className:"font-medium leading-none",children:"Scale Options"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Set the scale for the number axis"})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsxs("div",{className:"grid grid-cols-3 items-center gap-2",children:[e.jsx(s.Label,{htmlFor:"scale",children:"Type"}),e.jsxs(s.Select,{disabled:g,value:i,onValueChange:M=>l(M),children:[e.jsx(s.SelectTrigger,{className:"col-span-2 h-8 w-full focus:ring-1 focus:ring-offset-0",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{id:"type",children:e.jsxs(s.SelectGroup,{children:[e.jsx(s.SelectLabel,{children:"Option"}),e.jsx(s.SelectItem,{value:"linear",children:"Linear"}),e.jsx(s.SelectItem,{value:"logarithmic",children:"Logarithmic"})]})})]})]}),i=="linear"&&e.jsxs("div",{className:"grid grid-cols-3 items-center gap-2 py-1",children:[e.jsx(s.Label,{htmlFor:"scale-option",children:"Setup"}),e.jsxs(s.RadioGroup,{disabled:g,id:"scale-option",value:j,onValueChange:M=>b(M),className:"col-span-2 flex gap-3",defaultValue:"x",children:[e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(s.RadioGroupItem,{value:"auto",id:"r1"}),e.jsx("label",{className:"text-sm",htmlFor:"r1",children:"Auto"})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(s.RadioGroupItem,{value:"custom",id:"r2"}),e.jsx("label",{className:"text-sm",htmlFor:"r2",children:"Custom"})]})]})]}),j==="custom"&&i=="linear"&&O(),v(),e.jsx(s.SelectSeparator,{}),e.jsx("div",{className:"grid grid-cols-3",children:e.jsx(s.Button,{onClick:q,variant:"secondary",className:"col-span-1 col-start-3 h-8 w-full",children:"Apply"})})]})]})})]})}function zt({idx:t}){var c;const n=s.useEditorStore(d=>{var h;return(h=d.card)==null?void 0:h.preferences}),a=s.useEditorStore(d=>{var h;return(h=d.card.preferences)==null?void 0:h.datasetOptions}),r=s.useEditorStore(d=>d.actions.setCardPreferences),o=(c=n==null?void 0:n.chartOptions)==null?void 0:c.indexAxis,i=a==null?void 0:a.find(d=>d.idx===t);function l(d,h){(d==="end"||d==="start")&&s.getContrastColor(s.getCanvasBackgroundColor());const x={display:d!=="none",align:d,anchor:d,clamp:!0};if(!i)r({...n,datasetOptions:[...a||[],{idx:h,datalabels:x}]});else{const j={...i};j.datalabels=x;const b=a==null?void 0:a.map(u=>u.idx===h?j:u);r({...n,datasetOptions:b})}}return e.jsxs(s.Popover,{children:[e.jsx(s.PopoverTrigger,{children:e.jsx(Ps,{className:"invisible size-4 rotate-[135deg] cursor-pointer text-muted-foreground hover:text-foreground group-hover:visible"})}),e.jsx(s.PopoverContent,{className:"w-fit p-1",children:e.jsxs("div",{className:"flex gap-1",children:[e.jsx(s.Button,{onClick:()=>l("none",t),size:"sm",variant:"secondary",className:"h-7 p-1 text-xs font-normal",children:e.jsx(s.X,{className:"size-4"})}),e.jsx(s.Button,{onClick:()=>l("start",t),size:"sm",variant:"secondary",className:"h-7 p-1 text-xs font-normal",children:e.jsx(Ls,{className:s.cn("h-4 w-4",{"rotate-90":o==="y"})})}),e.jsx(s.Button,{onClick:()=>l("center",t),size:"sm",variant:"secondary",className:"h-7 p-1 text-xs font-normal",children:e.jsx(zs,{className:s.cn("h-4 w-4",{"rotate-90":o==="y"})})}),e.jsx(s.Button,{onClick:()=>l("end",t),size:"sm",variant:"secondary",className:"h-7 p-1 text-xs font-normal",children:e.jsx(As,{className:s.cn("h-4 w-4",{"rotate-90":o==="y"})})})]})})]})}function ms(){const t=s.useEditorStore(h=>h.card),n=s.useEditorStore(h=>{var x,j,b;return(b=(j=(x=h==null?void 0:h.card)==null?void 0:x.preferences)==null?void 0:j.chartOptions)==null?void 0:b.indexAxis}),{data:a}=s.useDashboardCardQuery(t),r=n==="y"?"Y axis":"X axis",o=n==="y"?"X axis":"Y axis",{keys:i,metricKeys:l,dimensionKeys:c}=s.getKeys((a==null?void 0:a.records)||[]);let d=l;if(["stackedBar","stackedLine"].includes(t.type)){const h=s.pivotData({dataArray:(a==null?void 0:a.records)||[],groupKey:c[0],pivotKey:c[1],valueKey:d[0]}),{metricKeys:x}=s.getKeys(h);d=x}return i.length===0?null:e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(s.Label,{children:r}),e.jsx("div",{className:"my-1 space-y-1",children:e.jsx("div",{className:"rounded-md bg-muted/70 px-3 py-2 hover:bg-muted",children:e.jsx("p",{title:c[0],children:xs(c[0])})})})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between gap-5",children:[e.jsx(s.Label,{children:o}),e.jsx(hs,{})]}),e.jsx("div",{className:"my-1 max-h-[125px] space-y-1 overflow-y-auto",children:d.map((h,x)=>e.jsx(Ot,{col:h,idx:x},h))})]})]})}function xs(t,n=30){return t.length>n?t.slice(0,n)+"...":t}function Ot({col:t,idx:n}){const a=s.useEditorStore(c=>{var d;return(d=c.card)==null?void 0:d.preferences}),r=s.useEditorStore(c=>{var d;return(d=c.card.preferences)==null?void 0:d.datasetOptions}),o=r==null?void 0:r.find(c=>c.idx===n),{setCardPreferences:i}=s.useEditorStore(c=>c.actions);function l(c){if(!o)i({...a,datasetOptions:[...r||[],{idx:n,type:c==="area"?"line":c,fill:c==="area"?"origin":""}]});else{const d={...o};d.type=c==="area"?"line":c,d.fill=c==="area"?"origin":"";const h=r==null?void 0:r.map(x=>x.idx===n?d:x);i({...a,datasetOptions:h})}}return e.jsxs("div",{className:"group flex items-center justify-between gap-5 rounded-md bg-muted/70 px-3 py-2 hover:bg-muted",children:[e.jsx("p",{title:t,children:xs(t)}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(Ne,{onClick:()=>l("bar"),className:"invisible size-4 cursor-pointer text-muted-foreground hover:text-foreground group-hover:visible"}),e.jsx(we,{onClick:()=>l("line"),className:"invisible size-4 cursor-pointer text-muted-foreground hover:text-foreground group-hover:visible"}),e.jsx(Ss,{onClick:()=>l("area"),className:"invisible size-4 cursor-pointer text-muted-foreground hover:text-foreground group-hover:visible"}),e.jsx(zt,{idx:n})]})]})}function ps(){const t=s.useEditorStore(u=>u.selectedConnectionId),n=s.useEditorStore(u=>u.selectedDatamodelId),a=s.useEditorStore(u=>u.selectedDatabaseName),r=s.useEditorStore(u=>u.selectedSchemaName),o=s.useEditorStore(u=>u.selectedTableName),i=s.useDashboardStore(u=>u.dashboard.filters)||[],l=s.useDashboardStore(u=>u.actions.addFilter),c=s.useDashboardStore(u=>u.actions.removeFilter),{removeFilterValues:d}=s.useDashboardActions(),{modelItems:h,tableName:x,connectionType:j}=ne();function b(u,p="dashboard"){var B;const f=s.fmt(u.column_name),w=s.fmt(a||""),S=s.fmt(r||""),L=s.fmt(x);let N=s.getQualifiedTableName(S,L,j),k=`${N}.${f}`;const A=(B=h==null?void 0:h.find(F=>F.id===n))==null?void 0:B.name;n&&n!=="none"&&(k=`${s.DATAMODEL_NAMESPCACE}.${A}.${f}`,N=`${s.DATAMODEL_NAMESPCACE}.${A}`);const z=i==null?void 0:i.find(F=>F.column===k&&F.table===L&&(F.database===w||F.database===a));if(z)d(z.id),c(z.id);else{const F=s.v4();return x==="api"&&t?(l({location:p,id:F,column:k,title:u.column_name,dataType:u.data_type,table:"api",database:"",connectionId:t,operation:"in",sql:s.getDefaultFilterSql(u.data_type,N,f)}),F):(l({id:F,location:p,column:k,title:u.column_name,dataType:u.data_type,table:o||"",database:a||"",connectionId:t||"",operation:"in",sql:s.getDefaultFilterSql(u.data_type,N,f)}),F)}}return{assignFilter:b}}function ue(){const t=s.useDashboardStore(c=>c.dashboard.filters),n=s.useEditorStore(c=>c.frame),{setFrame:a}=s.useEditorActions(),{columns:r}=ne(),{assignFilter:o}=ps();function i(c){const d=o(c,"frame");a({...n,filterId:d})}const l=t==null?void 0:t.find(c=>c.id===n.filterId);return e.jsxs("div",{className:"space-y-3",children:[e.jsx(s.Label,{children:"Card Filter"}),e.jsx(Mt,{onSelect:i,columns:r}),l&&e.jsx(s.FilterHeader,{filter:l})]})}function Mt({columns:t,onSelect:n}){var l;const[a,r]=Ve.useState(!1),[o,i]=Ve.useState("");return e.jsxs(s.Popover,{open:a,onOpenChange:r,children:[e.jsx(s.PopoverTrigger,{asChild:!0,children:e.jsxs(s.Button,{size:"sm",variant:"outline",role:"combobox","aria-expanded":a,className:"w-full justify-between font-normal",children:[o?(l=t.find(c=>c.column_name===o))==null?void 0:l.column_name:"Select Column...",e.jsx(s.CaretSortIcon,{className:"ml-2 h-4 w-4 shrink-0 opacity-50"})]})}),e.jsx(s.PopoverContent,{className:"w-[200px] p-0",children:e.jsxs(s.Command,{children:[e.jsx(s.CommandInput,{placeholder:"Search column",className:"h-9"}),e.jsxs(s.CommandList,{children:[e.jsx(s.CommandEmpty,{children:"No framework found."}),e.jsx(s.CommandGroup,{children:t.map(c=>e.jsxs(s.CommandItem,{value:c.column_name,onSelect:d=>{const h=d===o?"":d;i(h),r(!1),h&&n(c)},children:[c.column_name,e.jsx(s.CheckIcon,{className:s.cn("ml-auto h-4 w-4",o===c.column_name?"opacity-100":"opacity-0")})]},c.column_name))})]})]})})]})}function Ft({cardType:t}){return e.jsx("div",{className:"space-y-6 px-6 py-2",children:e.jsxs(s.Accordion,{defaultValue:["item-2"],type:"multiple",children:[e.jsxs(s.AccordionItem,{value:"item-1",children:[e.jsx(s.AccordionTrigger,{children:`${s.titleCase(t)} Chart`}),e.jsxs(s.AccordionContent,{className:"space-y-4 font-mono text-xs",children:[e.jsx("div",{className:"rounded bg-muted px-2 py-1 text-xs",children:"SELECT x-axis, y-axis-1, y-axis-2,... FROM table"}),e.jsxs("ul",{className:"ml-6 list-disc text-xs [&>li]:mt-2",children:[e.jsx("li",{children:"x-axis - category"}),e.jsx("li",{children:"y-axis1 - number"}),e.jsx("li",{children:"y-axis2 - number"})]}),e.jsxs("div",{children:["See ",e.jsx("a",{target:"_blank",onClick:n=>n.stopPropagation(),className:"text-blue-700",href:"https://docs.semaphor.cloud/docs/charts/bar-line-area",children:"example"})," in the docs."]})]})]}),e.jsxs(s.AccordionItem,{value:"item-2",children:[e.jsx(s.AccordionTrigger,{children:"Settings"}),e.jsxs(s.AccordionContent,{className:"space-y-4 px-2",children:[e.jsx(Se,{}),e.jsx(ms,{})]})]}),e.jsxs(s.AccordionItem,{value:"item-3",children:[e.jsx(s.AccordionTrigger,{children:"Filters"}),e.jsxs(s.AccordionContent,{className:"space-y-4 px-2",children:[e.jsx(ie,{}),e.jsx(ue,{})]})]})]})})}function Te(){var o,i,l;const t=s.useEditorStore(c=>c.card.cfg),n=s.useEditorStore(c=>c.actions.setCardCfg),a=s.useEditorStore(c=>c.card.type);function r(c){var x;const d={datalabels:{display:c!=="none",align:c,anchor:c,clamp:!0}},h={...t,options:{...t==null?void 0:t.options,plugins:{...(x=t==null?void 0:t.options)==null?void 0:x.plugins,...d}}};n(h),console.log(c)}return e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("label",{className:"font-medium",children:"Data Labels"}),!["pyramid"].includes(a)&&e.jsx(hs,{})]}),e.jsxs(s.Select,{value:(l=(i=(o=t==null?void 0:t.options)==null?void 0:o.plugins)==null?void 0:i.datalabels)==null?void 0:l.anchor,onValueChange:r,defaultValue:"none",children:[e.jsx(s.SelectTrigger,{className:"h-8 w-full focus:ring-1 focus:ring-offset-0",children:e.jsx(s.SelectValue,{placeholder:"Select position"})}),e.jsx(s.SelectContent,{children:e.jsxs(s.SelectGroup,{children:[e.jsx(s.SelectLabel,{children:"Data Labels"}),e.jsx(s.SelectItem,{value:"none",children:"None"}),a!=="pyramid"&&e.jsx(s.SelectItem,{value:"start",children:"Start"}),e.jsx(s.SelectItem,{value:"center",children:"Center"}),a!=="pyramid"&&e.jsx(s.SelectItem,{value:"end",children:"End"})]})})]})]})}function Vt({cardType:t}){function n(a){return e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"rounded bg-muted px-2 py-1 text-xs",children:a==="bubble"?"SELECT label, [group], x-axis, y-axis, radius FROM table":"SELECT label, [group], x-axis, y-axis FROM table"}),e.jsxs("ul",{className:"ml-6 list-disc text-xs [&>li]:mt-2",children:[e.jsx("li",{children:"label - category"}),e.jsx("li",{children:"group - category"}),e.jsx("li",{children:"x-axis - category"}),e.jsx("li",{children:"y-axis - category"}),a==="bubble"&&e.jsx("li",{children:"radius - number"})]}),e.jsxs("div",{children:["See ",e.jsx("a",{target:"_blank",onClick:i=>i.stopPropagation(),className:"text-blue-700",href:"https://docs.semaphor.cloud/docs/charts/bubble",children:"example"})," in the docs."]})]})}return e.jsx("div",{className:"space-y-6 px-6 py-2",children:e.jsxs(s.Accordion,{defaultValue:["item-2"],type:"multiple",children:[e.jsxs(s.AccordionItem,{value:"item-1",children:[e.jsx(s.AccordionTrigger,{children:`${s.titleCase(t)} Chart`}),e.jsx(s.AccordionContent,{className:"space-y-4 font-mono text-xs",children:n(t)})]}),e.jsxs(s.AccordionItem,{value:"item-2",children:[e.jsx(s.AccordionTrigger,{children:"Settings"}),e.jsx(s.AccordionContent,{className:"px-2",children:e.jsx(Te,{})})]}),e.jsxs(s.AccordionItem,{value:"item-3",children:[e.jsx(s.AccordionTrigger,{children:"Filters"}),e.jsxs(s.AccordionContent,{className:"space-y-4 px-2",children:[e.jsx(ie,{}),e.jsx(ue,{})]})]})]})})}const Rt={datasets:[{type:"line",label:"Sum_sales",data:[]},{type:"bar",label:"Sum_profit",data:[]}]},qt={datasets:[{fill:"origin",type:"line",label:"Sum_sales",data:[]}]};function Bt(){const t=s.useEditorStore(n=>n.card.type);return e.jsxs("div",{className:"space-y-6 p-6",children:[e.jsx(s.Accordion,{className:" ",type:"single",collapsible:!0,children:_t(t)}),e.jsx("section",{className:"",children:["line","bar"].includes(t)&&e.jsx(Se,{})}),!["kpi"].includes(t)&&e.jsxs("div",{className:"space-y-4",children:[e.jsx(Te,{}),e.jsx(ie,{}),e.jsx(ue,{})]})]})}function _t(t){if(["line","bar"].includes(t))return e.jsxs(e.Fragment,{children:[e.jsxs(s.AccordionItem,{value:"item-1",children:[e.jsx(s.AccordionTrigger,{className:"font-normal",children:e.jsx("p",{children:"Chart Query"})}),e.jsxs(s.AccordionContent,{className:" ",children:[e.jsx("div",{className:"rounded bg-muted px-2 py-1 font-mono text-xs font-semibold",children:"SELECT x-axis, y-axis-1, y-axis-2, y-axis-3,... FROM table"}),e.jsxs("ul",{className:"my-6 ml-6 list-disc text-xs font-normal [&>li]:mt-2",children:[e.jsx("li",{children:"X-axis - Category (ex. city)"}),e.jsx("li",{children:"Y-axis - Number (ex. population)"})]})]})]}),e.jsxs(s.AccordionItem,{value:"item-2",children:[e.jsx(s.AccordionTrigger,{className:"font-normal",children:"Mixed Chart"}),e.jsxs(s.AccordionContent,{className:"space-y-2 text-xs",children:[e.jsxs("p",{children:["Click ",e.jsx("b",{children:"Customize"})," and change the `type` property in the dataset."]}),e.jsx("pre",{children:JSON.stringify(Rt,null,2)})]})]}),e.jsxs(s.AccordionItem,{value:"item-3",children:[e.jsx(s.AccordionTrigger,{className:"font-normal",children:"Area Chart"}),e.jsxs(s.AccordionContent,{className:"space-y-2 text-xs",children:[e.jsxs("p",{children:["Click ",e.jsx("b",{children:"Customize"})," and add `fill` property to the dataset. See",e.jsx("a",{className:"mx-1 text-blue-500 hover:underline",href:"https://www.chartjs.org/docs/latest/samples/area/line-boundaries.html",target:"_blank",children:"docs"}),"for more options."]}),e.jsx("pre",{children:JSON.stringify(qt,null,2)})]})]})]});if(t==="bubble")return e.jsx(e.Fragment,{children:e.jsxs(s.AccordionItem,{value:"item-1",children:[e.jsx(s.AccordionTrigger,{className:"font-normal",children:e.jsxs("p",{children:["How to create a ",e.jsx("span",{children:t})," chart query?"]})}),e.jsxs(s.AccordionContent,{className:" ",children:[e.jsx("div",{className:"rounded bg-muted px-2 py-1 font-mono text-xs font-semibold",children:"SELECT label, x-axis, y-axis, radius FROM table"}),e.jsxs("ul",{className:"my-6 ml-6 list-disc text-xs font-normal [&>li]:mt-2",children:[e.jsx("li",{children:"Label - Category (ex. city)"}),e.jsx("li",{children:"Bubble Group (opt) - Category (ex. state)"}),e.jsx("li",{children:"X-axis - Number (ex. avg. age)"}),e.jsx("li",{children:"Y-axis - Number (ex. avg. weight)"}),e.jsx("li",{children:"Radius - Number (ex. population)"})]})]})]})});if(t==="scatter")return e.jsx(e.Fragment,{children:e.jsxs(s.AccordionItem,{value:"item-1",children:[e.jsx(s.AccordionTrigger,{className:"font-normal",children:e.jsxs("p",{children:["How to create a ",e.jsx("span",{children:t})," chart query?"]})}),e.jsxs(s.AccordionContent,{className:" ",children:[e.jsx("div",{className:"rounded bg-muted px-2 py-1 font-mono text-xs font-semibold",children:"SELECT label, x-axis, y-axis FROM table"}),e.jsxs("ul",{className:"my-6 ml-6 list-disc text-xs font-normal [&>li]:mt-2",children:[e.jsx("li",{children:"Label - Category (ex. city)"}),e.jsx("li",{children:"Group (opt) - Category (ex. state)"}),e.jsx("li",{children:"X-axis - Number (ex. avg. age)"}),e.jsx("li",{children:"Y-axis - Number (ex. avg. weight)"})]})]})]})});if(["pie","doughnut","polarArea"].includes(t))return e.jsx(e.Fragment,{children:e.jsxs(s.AccordionItem,{value:"item-1",children:[e.jsx(s.AccordionTrigger,{className:"font-normal",children:e.jsxs("p",{children:[e.jsx("span",{children:t==="polarArea"?"Polar":t.charAt(0).toUpperCase()+t.slice(1)})," ","chart query"]})}),e.jsxs(s.AccordionContent,{className:" ",children:[e.jsx("div",{className:"rounded bg-muted px-2 py-1 font-mono text-xs font-semibold",children:"SELECT label, measure FROM table"}),e.jsxs("ul",{className:"my-6 ml-6 list-disc text-xs font-normal [&>li]:mt-2",children:[e.jsx("li",{children:"Label - Category (ex. city)"}),e.jsx("li",{children:"Measure - Number (ex. population)"})]})]})]})})}function Pt(){var d,h,x,j,b;const t=s.useEditorStore(u=>u.card.preferences),n=s.useEditorStore(u=>u.actions.setCardPreferences),a=s.useEditorStore(u=>u.actions.setNumberFormat);s.useEditorStore(u=>{var p,f;return(f=(p=u.card.preferences)==null?void 0:p.formatNumber)==null?void 0:f.decimalPlaces});const r=s.useEditorStore(u=>{var p,f;return(f=(p=u.card.preferences)==null?void 0:p.formatNumber)==null?void 0:f.locale}),o=s.useEditorStore(u=>{var p,f;return(f=(p=u.card.preferences)==null?void 0:p.formatNumber)==null?void 0:f.currency});s.useEditorStore(u=>u.actions.setFilterOnClickField);const i=s.useEditorStore(u=>{var p,f;return(f=(p=u.card.preferences)==null?void 0:p.formatNumber)==null?void 0:f.colorRanges})||[],l=s.useEditorStore(u=>u.actions.setColorRanges),c=[...new Set(s.LOCALE_CURRENCY_PAIRS.map(u=>u.currency))];return e.jsxs("div",{children:[e.jsxs("div",{className:"mb-3 flex items-center gap-2",children:[e.jsx(s.Checkbox,{checked:!!((d=t==null?void 0:t.formatNumber)!=null&&d.enabled),onCheckedChange:u=>{n({...t,formatNumber:{...t==null?void 0:t.formatNumber,enabled:u}})}}),e.jsx(s.Label,{children:"Format Number"})]}),((h=t==null?void 0:t.formatNumber)==null?void 0:h.enabled)===!0&&e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsx("div",{children:e.jsxs("div",{className:"space-y-4 p-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("div",{className:"w-full space-y-1",children:[e.jsx(s.Label,{children:"Locale"}),e.jsxs(s.Select,{value:r||"none",onValueChange:u=>{var p,f,w;return a(((p=t==null?void 0:t.formatNumber)==null?void 0:p.decimalPlaces)||0,((f=t==null?void 0:t.formatNumber)==null?void 0:f.currency)||"",u,((w=t==null?void 0:t.formatNumber)==null?void 0:w.suffix)||"")},children:[e.jsx(s.SelectTrigger,{className:"col-span-6 h-8 w-full focus:ring-1 focus:ring-offset-0",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{children:e.jsxs(s.SelectGroup,{children:[e.jsx(s.SelectLabel,{children:"Format"}),e.jsx(s.SelectItem,{value:"none",children:"None"},"none"),s.LOCALE_CURRENCY_PAIRS.map(u=>e.jsx(s.SelectItem,{value:u.locale,children:u.locale},u.locale))]})})]})]}),e.jsxs("div",{className:"w-full space-y-1",children:[e.jsx(s.Label,{children:"Currency"}),e.jsxs(s.Select,{value:o||"none",onValueChange:u=>{var p,f,w;console.log("currency",u),a(((p=t==null?void 0:t.formatNumber)==null?void 0:p.decimalPlaces)||0,u==="none"?"":u,((f=t==null?void 0:t.formatNumber)==null?void 0:f.locale)||"",((w=t==null?void 0:t.formatNumber)==null?void 0:w.suffix)||"")},children:[e.jsx(s.SelectTrigger,{className:"col-span-6 h-8 w-full focus:ring-1 focus:ring-offset-0",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{children:e.jsxs(s.SelectGroup,{children:[e.jsx(s.SelectLabel,{children:"Currency"}),e.jsx(s.SelectItem,{value:"none",children:"None"},"none"),c.map(u=>e.jsx(s.SelectItem,{value:u,children:u},u))]})})]})]})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs("div",{className:"w-full space-y-1",children:[e.jsx(s.Label,{children:"Decimals"}),e.jsxs(s.Select,{value:((j=(x=t==null?void 0:t.formatNumber)==null?void 0:x.decimalPlaces)==null?void 0:j.toString())||"0",onValueChange:u=>{var p,f,w;return a(Number(u),((p=t==null?void 0:t.formatNumber)==null?void 0:p.currency)||"",((f=t==null?void 0:t.formatNumber)==null?void 0:f.locale)||"",((w=t==null?void 0:t.formatNumber)==null?void 0:w.suffix)||"")},children:[e.jsx(s.SelectTrigger,{className:"col-span-3 h-8 w-full focus:ring-1 focus:ring-offset-0",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{children:["0","1","2","3","4"].map(u=>e.jsx(s.SelectItem,{value:u,children:u},u))})]})]}),e.jsxs("div",{className:"w-full space-y-1",children:[e.jsx(s.Label,{children:"Suffix"}),e.jsx(s.Input,{value:((b=t==null?void 0:t.formatNumber)==null?void 0:b.suffix)||"",className:"h-8 font-mono text-xs focus-visible:ring-0 focus-visible:ring-ring focus-visible:ring-offset-0",placeholder:"K, M, B, %",onChange:u=>{var p,f,w;return a(((p=t==null?void 0:t.formatNumber)==null?void 0:p.decimalPlaces)||0,((f=t==null?void 0:t.formatNumber)==null?void 0:f.currency)||"",((w=t==null?void 0:t.formatNumber)==null?void 0:w.locale)||"",u.target.value)}})]})]})]})}),e.jsx(s.Separator,{className:"my-3"}),e.jsx(s.ColorFormat,{colorRanges:i,setColorRanges:l})]})]})}function Ht(){return e.jsxs("div",{className:"space-y-6 px-6 py-2",children:[e.jsx(s.Accordion,{type:"single",collapsible:!0,children:e.jsxs(s.AccordionItem,{value:"item-1",children:[e.jsx(s.AccordionTrigger,{className:"",children:"KPI Query"}),e.jsxs(s.AccordionContent,{className:"font-mono",children:[e.jsx("div",{className:"rounded bg-muted px-2 py-1 font-mono text-xs",children:"SELECT current, previous FROM table"}),e.jsxs("ul",{className:"my-6 ml-6 list-disc text-xs [&>li]:mt-2",children:[e.jsx("li",{children:"current - number"}),e.jsx("li",{children:"previous - number"})]}),e.jsxs("div",{children:["See ",e.jsx("a",{target:"_blank",onClick:t=>t.stopPropagation(),className:"text-blue-700",href:"https://docs.semaphor.cloud/docs/charts/kpi",children:"example"})," in the docs."]})]})]})}),e.jsx("section",{className:"",children:e.jsx(Pt,{})}),e.jsx("div",{}),e.jsx("div",{})]})}const Gt=[{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"}],Ut=["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"],$t=Ut.map(t=>({label:t,value:t}));function Qt(){var d,h,x,j,b,u,p,f,w,S,L,N,k,A,z,B,F,_;const t=s.useEditorStore(m=>m.card),n=(h=(d=t==null?void 0:t.preferences)==null?void 0:d.mapVisualOptions)==null?void 0:h.topoJsonUrl,[a,r]=y.useState(((j=(x=t==null?void 0:t.preferences)==null?void 0:x.mapVisualOptions)==null?void 0:j.customTopoJsonUrl)||""),{setCardPreferences:o}=s.useEditorActions(),{data:i}=s.useTopoJson(t),l=Object.keys((i==null?void 0:i.objects)||{}).map(m=>({label:m,value:m}))||[],c=[{label:"US States 10m",value:"https://unpkg.com/us-atlas/states-10m.json"},{label:"Countries 50m",value:"https://unpkg.com/world-atlas/countries-50m.json"},{label:"Custom",value:"custom"}];return e.jsxs("div",{className:"p-6",children:[e.jsx(me,{summary:"Map Query",children:e.jsx("p",{className:"rounded-md bg-muted p-2 font-mono text-xs",children:"SELECT country, value FROM table"})}),e.jsx(s.Separator,{className:"my-4"}),e.jsx(me,{open:!0,summary:"Settings",children:e.jsxs("div",{className:"space-y-3 px-2",children:[e.jsx(ae,{className:"h-9",options:c,onValueChange:m=>{console.log("value",m),o({...t.preferences,mapVisualOptions:{topoJsonUrl:m}})},value:n||"",label:"Select Map"}),n==="custom"&&e.jsx(s.Input,{onChange:m=>{r(m.target.value)},onBlur:()=>{var m;console.log("onBlur",a),o({...t.preferences,mapVisualOptions:{...(m=t.preferences)==null?void 0:m.mapVisualOptions,customTopoJsonUrl:a}})},value:a,className:`h-9 w-full ${s.removeRing}`,placeholder:"Custom URL"}),i&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(s.Label,{children:"Map Object"}),e.jsx(ae,{className:"h-9",options:l,value:((u=(b=t.preferences)==null?void 0:b.mapVisualOptions)==null?void 0:u.objectKey)||"",label:"Map Object",onValueChange:m=>{var g;o({...t.preferences,mapVisualOptions:{...(g=t.preferences)==null?void 0:g.mapVisualOptions,objectKey:m}})}})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(s.Label,{children:"Projection"}),e.jsx(ae,{className:"h-9",options:Gt,value:((f=(p=t.preferences)==null?void 0:p.mapVisualOptions)==null?void 0:f.projection)||"",label:"Projection",onValueChange:m=>{var g;o({...t.preferences,mapVisualOptions:{...(g=t.preferences)==null?void 0:g.mapVisualOptions,projection:m}})}})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(s.Label,{children:"Colors"}),e.jsx(ae,{className:"h-9",options:$t,value:((S=(w=t.preferences)==null?void 0:w.mapVisualOptions)==null?void 0:S.colorScale)||"",label:"Select Color Scale",onValueChange:m=>{var g;o({...t.preferences,mapVisualOptions:{...(g=t.preferences)==null?void 0:g.mapVisualOptions,colorScale:m}})}})]})]})]})}),e.jsx(s.Separator,{className:"my-4"}),e.jsx(me,{className:"",summary:"Scale Options",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(s.Input,{className:`h-9 w-full ${s.removeRing}`,type:"number",step:.1,value:((N=(L=t.preferences)==null?void 0:L.mapVisualOptions)==null?void 0:N.projectionScale)||1,onChange:m=>{var g;o({...t.preferences,mapVisualOptions:{...(g=t.preferences)==null?void 0:g.mapVisualOptions,projectionScale:Number(m.target.value)}})}}),e.jsx(s.Label,{children:"X"}),e.jsx(s.Input,{className:`h-9 w-full ${s.removeRing}`,type:"number",step:10,value:((z=(A=(k=t.preferences)==null?void 0:k.mapVisualOptions)==null?void 0:A.projectionOffset)==null?void 0:z[0])||0,onChange:m=>{var g,D,v,O;o({...t.preferences,mapVisualOptions:{...(g=t.preferences)==null?void 0:g.mapVisualOptions,projectionOffset:[Number(m.target.value),((O=(v=(D=t.preferences)==null?void 0:D.mapVisualOptions)==null?void 0:v.projectionOffset)==null?void 0:O[1])||0]}})}}),e.jsx(s.Label,{children:"Y"}),e.jsx(s.Input,{className:`h-9 w-full ${s.removeRing}`,type:"number",step:10,value:((_=(F=(B=t.preferences)==null?void 0:B.mapVisualOptions)==null?void 0:F.projectionOffset)==null?void 0:_[1])||0,onChange:m=>{var g,D,v,O;o({...t.preferences,mapVisualOptions:{...(g=t.preferences)==null?void 0:g.mapVisualOptions,projectionOffset:[((O=(v=(D=t.preferences)==null?void 0:D.mapVisualOptions)==null?void 0:v.projectionOffset)==null?void 0:O[0])||0,Number(m.target.value)]}})}})]})}),e.jsx(s.Separator,{className:"my-4"}),e.jsx(ie,{})]})}function Jt(){var r;const t=s.useEditorStore(o=>o.card.preferences),{setCardPreferences:n}=s.useEditorStore(o=>o.actions);function a(o){n({...t,textVisualOptions:{...t==null?void 0:t.textVisualOptions,isDynamicText:o==="dynamic"}})}return e.jsxs(s.RadioGroup,{value:(r=t==null?void 0:t.textVisualOptions)!=null&&r.isDynamicText?"dynamic":"static",onValueChange:a,className:"flex gap-3",defaultValue:"x",children:[e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(s.RadioGroupItem,{value:"static",id:"r1"}),e.jsx("label",{className:"text-sm",htmlFor:"r1",children:"Static"})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(s.RadioGroupItem,{value:"dynamic",id:"r2"}),e.jsx("label",{className:"text-sm",htmlFor:"r2",children:"Dynamic"})]})]})}function ge({cardType:t,docContent:n,suffix:a="Chart"}){return e.jsx("div",{className:"space-y-6 px-6 py-2",children:e.jsxs(s.Accordion,{defaultValue:["item-2"],type:"multiple",children:[e.jsxs(s.AccordionItem,{value:"item-1",children:[e.jsx(s.AccordionTrigger,{children:`${s.titleCase(t)} ${a}`}),e.jsx(s.AccordionContent,{children:n||e.jsxs("div",{className:"space-y-4 font-mono text-xs",children:[e.jsx("div",{className:"rounded bg-muted px-2 py-1 text-xs",children:"SELECT label, measure FROM table"}),e.jsxs("ul",{className:"ml-6 list-disc text-xs [&>li]:mt-2",children:[e.jsx("li",{children:"label - category"}),e.jsx("li",{children:"measure - number"})]}),e.jsxs("div",{children:["See ",e.jsx("a",{target:"_blank",onClick:r=>r.stopPropagation(),className:"text-blue-700",href:"https://docs.semaphor.cloud/docs/charts/pie-donut-polar",children:"example"})," in the docs."]})]})})]}),e.jsxs(s.AccordionItem,{value:"item-2",children:[e.jsx(s.AccordionTrigger,{children:"Settings"}),e.jsxs(s.AccordionContent,{className:"space-y-4 px-2",children:[t==="range"&&e.jsx(Se,{}),t!=="text"&&e.jsx(Te,{}),t==="text"&&e.jsx(Jt,{})]})]}),!["range","text"].includes(t)&&e.jsxs(s.AccordionItem,{value:"item-3",children:[e.jsx(s.AccordionTrigger,{children:"Filters"}),e.jsxs(s.AccordionContent,{className:"space-y-4 px-2",children:[e.jsx(ie,{}),e.jsx(ue,{})]})]})]})})}function Wt(){const t=s.useEditorStore(r=>{var o,i;return(i=(o=r==null?void 0:r.card)==null?void 0:o.preferences)==null?void 0:i.sortChart}),{setSortChart:n}=s.useEditorActions();function a(){return e.jsxs("div",{className:"space-y-2",children:[e.jsx(s.Label,{children:"Sort"}),e.jsx(ae,{className:"h-8",label:"Sort Chart",options:[{label:"None",value:"none"},{label:"ASC",value:"asc"},{label:"DESC",value:"desc"}],value:t||"none",onValueChange:r=>{n(r)}})]})}return e.jsx("div",{className:"space-y-6 px-6 py-2",children:e.jsxs(s.Accordion,{defaultValue:["item-2"],type:"multiple",children:[e.jsxs(s.AccordionItem,{value:"item-1",children:[e.jsx(s.AccordionTrigger,{children:"Stacked Chart"}),e.jsxs(s.AccordionContent,{className:"space-y-4 font-mono text-xs",children:[e.jsx("div",{className:"rounded bg-muted px-2 py-1 text-xs",children:"SELECT x-axis, stack-by, y-axis FROM table"}),e.jsxs("ul",{className:"ml-6 list-disc text-xs [&>li]:mt-2",children:[e.jsx("li",{children:"x-axis - category"}),e.jsx("li",{children:"stack by - category"}),e.jsx("li",{children:"y-axis - number"})]}),e.jsxs("div",{children:["See ",e.jsx("a",{target:"_blank",onClick:r=>r.stopPropagation(),className:"text-blue-700",href:"https://docs.semaphor.cloud/docs/charts/stacked",children:"example"})," in the docs."]})]})]}),e.jsxs(s.AccordionItem,{value:"item-2",children:[e.jsx(s.AccordionTrigger,{children:"Settings"}),e.jsxs(s.AccordionContent,{className:"space-y-4 px-2",children:[e.jsx(Se,{}),a(),e.jsx(ms,{})]})]}),e.jsxs(s.AccordionItem,{value:"item-3",children:[e.jsx(s.AccordionTrigger,{children:"Filters"}),e.jsxs(s.AccordionContent,{className:"space-y-4 px-2",children:[e.jsx(ie,{}),e.jsx(ue,{})]})]})]})})}function Kt({}){const t=s.useEditorStore(r=>{var o;return(o=r.card)==null?void 0:o.preferences}),n=s.useEditorStore(r=>r.actions.setCardPreferences),a=r=>{n({...t,allowDownload:r})};return e.jsxs("div",{className:"space-y-6 px-6 py-2",children:[e.jsx(s.Accordion,{defaultValue:["item-3"],type:"multiple",children:e.jsxs(s.AccordionItem,{value:"item-3",children:[e.jsx(s.AccordionTrigger,{children:"Filters"}),e.jsxs(s.AccordionContent,{className:"space-y-4 px-2",children:[e.jsx(ie,{}),e.jsx(ue,{})]})]})}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(s.Checkbox,{onCheckedChange:a,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 Zt=e.jsxs("div",{className:"space-y-4 font-mono text-xs",children:[e.jsx("div",{className:"rounded bg-muted px-2 py-1 text-xs",children:"SELECT dimension, cohort, metric FROM table"}),e.jsxs("div",{children:["See ",e.jsx("a",{target:"_blank",onClick:t=>t.stopPropagation(),className:"text-blue-700",href:"https://docs.semaphor.cloud/docs/charts/tornado",children:"example"})," in the docs."]})]}),Xt=e.jsxs("div",{className:"space-y-4 font-mono text-xs",children:[e.jsx("div",{className:"rounded bg-muted px-2 py-1 text-xs",children:"SELECT y-axis, label, range-from, range-to, range-value FROM table"}),e.jsxs("div",{children:["See ",e.jsx("a",{target:"_blank",onClick:t=>t.stopPropagation(),className:"text-blue-700",href:"https://docs.semaphor.cloud/docs/charts/range",children:"example"})," in the docs."]})]}),Yt=e.jsxs("div",{className:"space-y-4 font-mono text-xs",children:[e.jsx("div",{className:"rounded bg-muted px-2 py-1 text-xs",children:"SELECT text FROM table limit 1"}),e.jsxs("div",{children:["See ",e.jsx("a",{target:"_blank",onClick:t=>t.stopPropagation(),className:"text-blue-700",href:"https://docs.semaphor.cloud/docs/charts/text",children:"example"})," in the docs."]})]});function ea(){const t=s.useEditorStore(a=>a.card.type);function n(a){switch(a){case"stackedBar":case"stackedLine":return e.jsx(Wt,{});case"pyramid":return e.jsx(ge,{docContent:Zt,cardType:a});case"kpi":return e.jsx(Ht,{});case"line":case"bar":return e.jsx(Ft,{cardType:a});case"range":return e.jsx(ge,{docContent:Xt,cardType:a});case"pie":case"doughnut":case"polarArea":case"radar":return e.jsx(ge,{cardType:a});case"bubble":case"scatter":return e.jsx(Vt,{cardType:a});case"table":return e.jsx(Kt,{cardType:a});case"text":return e.jsx(ge,{docContent:Yt,cardType:a,suffix:"Visual"});case"map":return e.jsx(Qt,{});case"custom":return e.jsx(At,{});default:return e.jsx(Bt,{})}}return e.jsxs(s.ScrollArea,{className:"h-full w-full text-sm",children:[n(t),e.jsx(s.ScrollBar,{orientation:"horizontal"})]})}function sa(){const t=s.useEditorStore(n=>n.isShowingVisual);return e.jsxs(s.ResizablePanelGroup,{direction:"vertical",className:"min-h-[250px] min-w-full max-w-lg",children:[e.jsx(s.ResizablePanel,{role:"query-section",className:"flex",minSize:20,defaultSize:40,children:e.jsx(ft,{})}),e.jsx(s.ResizableHandle,{withHandle:!0,className:"border"}),e.jsx(s.ResizablePanel,{className:"pb-1",role:"visual-section",minSize:0,defaultSize:60,children:t?e.jsxs(s.ResizablePanelGroup,{direction:"horizontal",children:[e.jsx(e.Fragment,{children:e.jsx(s.ResizablePanel,{className:"flex min-w-[275px]",minSize:20,defaultSize:25,maxSize:30,children:e.jsx(ea,{})})}),e.jsx(s.ResizableHandle,{className:"border"}),e.jsx(s.ResizablePanel,{minSize:40,defaultSize:75,maxSize:100,children:e.jsx(_e,{})})]}):e.jsx(_e,{})})]})}function ta({authToken:t,onSave:n,onClose:a}){s.useDashboardStore(l=>l.themeStyle);const r=s.useEditorStore(l=>l.actions.setOnSave),o=s.useEditorStore(l=>l.actions.setOnClose),i=s.useDashboardStore(l=>l.actions.setAuthToken);return y.useEffect(()=>{n&&r(n),a&&o(a)},[n,r,a,o]),y.useEffect(()=>{t&&t.accessToken&&i(t)},[t,i]),e.jsx(s.ErrorBoundary,{FallbackComponent:s.Fallback,children:e.jsxs(s.EditorPanel,{style:{},className:"rounded-none",role:"editor-panel",children:[e.jsx(s.EditorAside,{className:"rounded-none border-r-[1.5px]",children:e.jsx(Ze,{})}),e.jsx(s.EditorMain,{children:e.jsx(sa,{})})]})})}function aa(){s.useDashboardStore(l=>l.selectedCardId);const t=s.useDashboardStore(l=>l.selectedSheetId),{setIsVisualEditing:n}=s.useDashboardStore(l=>l.actions),a=s.useDashboardStore(l=>l.isVisualEditing),r=s.useDashboardStore(l=>l.actions.updateFrame);function o(l){t&&(r(t,l),n(!1))}function i(){n(!1)}return e.jsx("div",{role:"editor-container",className:s.cn("flex grow",{"max-h-0 overflow-hidden":!a}),children:e.jsx(ta,{onSave:o,onClose:i})})}function na(){const t=s.useEditorStore(i=>i.selectedDatabaseName),n=s.useEditorStore(i=>i.selectedTableName),a=s.useDashboardStore(i=>i.dashboard.filters)||[],{columns:r}=ne(),{assignFilter:o}=ps();return e.jsx(s.ScrollArea,{className:"flex-1 basis-0 flex-col px-3",children:r==null?void 0:r.map(i=>{const l=a==null?void 0:a.find(c=>c.column===s.fmt(i.column_name)&&c.table===n&&c.database===t);return e.jsx("div",{onClick:()=>o(i),className:s.cn("group flex cursor-pointer items-center justify-between border border-dashed border-background px-3 py-[6px] text-sm transition-colors hover:bg-muted/50",{"bg-muted":l}),children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Ke,{column:i}),e.jsx("span",{children:i.column_name})]})},i.column_name)})})}function ra(){s.useDashboardStore(n=>n.showFilters);const t=s.useDashboardStore(n=>n.actions.setShowFilters);return e.jsxs("section",{className:"relative flex min-w-[320px] grow flex-col border-l px-1",children:[e.jsxs("div",{className:"mt-4 flex items-center justify-between gap-2 px-3",children:[e.jsx(s.Label,{className:"px-2 text-lg",children:"Filters"}),e.jsx(s.Button,{onClick:()=>t(!1),className:"h-7 w-7 p-0",variant:"ghost",children:e.jsx(s.Cross2Icon,{})})]}),e.jsx("div",{className:"flex grow",children:e.jsx(Ze,{ColumnsComponent:()=>e.jsx(na,{})})})]})}function oa(){const t=s.useDashboardStore(r=>r.dashboard.filters),n=s.useDashboardStore(r=>r.theme),a=t==null?void 0:t.filter(r=>r.hide);return a!=null&&a.length?e.jsx("div",{className:s.cn("mb-1 flex items-center gap-2 border-y px-0.5 pb-0.5",{"bg-[repeating-linear-gradient(45deg,_#ffffff_0_3px,_#f3f3f3_3px_6px)]":n==="light","bg-[repeating-linear-gradient(45deg,_#18171d_0_3px,_#272729_3px_6px)]":n==="dark"}),children:a==null?void 0:a.map(r=>e.jsxs("div",{className:"flex min-w-[250px] max-w-fit flex-col gap-1 p-2",children:[e.jsx(s.FilterHeader,{filter:r}),e.jsx(s.FilterComponent,{filter:r})]},r.id))}):null}function ia(){const t=s.useDashboardStore(r=>r.showFilters),n=s.useDashboardStore(r=>r.isVisualEditing),a=s.useDashboardStore(r=>r.isDashboardEditing);return e.jsxs("div",{role:"dashboard-plus-main",className:s.cn("",{"max-h-0 overflow-hidden":n,"flex grow overflow-auto":!n}),children:[e.jsxs("section",{className:"flex grow flex-col",children:[a&&e.jsx(oa,{}),e.jsx(s.DashboardTabs,{})]}),t&&e.jsx("div",{role:"filter-aside-container",className:"flex",children:e.jsx(ra,{})})]})}function la(){const t=s.useDashboardStore(o=>o.dashboard),n=s.useDashboardStore(o=>o.actions.setDashboard),a=s.useDashboardStore(o=>o.showDashboardJSON),r=s.useDashboardStore(o=>o.actions.setShowDashboardJSON);return e.jsxs("div",{className:s.cn("relative p-2",{hidden:!a}),children:[e.jsxs(s.Button,{variant:"secondary",size:"sm",className:"absolute right-2 top-2 z-10 h-8",onClick:()=>r(!1),children:[e.jsx(s.X,{className:"mr-2 h-4 w-4"}),"Close"]}),e.jsx(s.de,{onChange:o=>{if(o)try{JSON.parse(o),n(JSON.parse(o))}catch{}},defaultLanguage:"json",className:"h-[550px] overflow-y-auto",value:JSON.stringify(t,null,2),options:{minimap:{enabled:!1},glyphMargin:!1,wordWrap:"on",scrollbar:{verticalScrollbarSize:0,horizontalScrollbarSize:0},fontSize:12,renderLineHighlight:"none"}})]})}function ca({showControls:t=!1,showFooter:n=!0,...a}){return e.jsx(s.ErrorBoundary,{FallbackComponent:s.Fallback,children:e.jsxs(s.SemaphorContextProvider,{dashboardProps:a,children:[e.jsx(s.$e,{}),e.jsxs(s.UXProvider,{children:[e.jsx(la,{}),e.jsxs(s.DashboardPanel,{...a,children:[t&&e.jsx(Zs,{}),e.jsx(aa,{}),e.jsx(ia,{})]})]})]})})}exports.Dashboard=s.Dashboard;exports.DashboardWC=s.DashboardWC;exports.SemaphorDataProvider=s.SemaphorQueryClient;exports.SemaphorQueryClient=s.SemaphorQueryClient;exports.createSqlGenConfig=s.createSqlGenConfig;exports.fmt=s.fmt;exports.getColumnDataType=s.getColumnDataType;exports.getFilterValueType=s.getFilterValueType;exports.getFormattedTableNameForQuery=s.getFormattedTableNameForQuery;exports.getQualifiedTableName=s.getQualifiedTableName;exports.getSql=s.getSql;exports.invalidateToken=s.invalidateToken;exports.isBooleanDataType=s.isBooleanDataType;exports.isColumnInSqlGen=s.isColumnInSqlGen;exports.isDateDataType=s.isDateDataType;exports.isNumberDataType=s.isNumberDataType;exports.isTextDataType=s.isTextDataType;exports.resolveDataType=s.resolveDataType;exports.useCard=s.useCard;exports.useDashboardActions=s.useDashboardActions;exports.useDashboardStore=s.useDashboardStore;exports.useDateFilterHook=s.useDateFilterHook;exports.useEditorActions=s.useEditorActions;exports.useEditorStore=s.useEditorStore;exports.useTextFilterHook=s.useTextFilterHook;exports.SelectComponent=de;exports.Surfboard=ca;exports.cleanCard=Je;exports.downloadPdf=We;exports.getDashbaordStateWithoutData=Ie;exports.useEditorAside=ne;
|