react-semaphor 0.0.392 → 0.0.393

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/index.cjs CHANGED
@@ -1,4 +1,4 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("./chunks/index-DyhVlpG9.js"),e=require("react/jsx-runtime"),C=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 ie=gs(C);/**
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("./chunks/index-BYukbeLe.js"),e=require("react/jsx-runtime"),C=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 ie=gs(C);/**
2
2
  * @license lucide-react v0.453.0 - ISC
3
3
  *
4
4
  * This source code is licensed under the ISC license.
@@ -78,12 +78,12 @@
78
78
  *
79
79
  * This source code is licensed under the ISC license.
80
80
  * See the LICENSE file in the root directory of this source tree.
81
- */const _e=s.createLucideIcon("Donut",[["path",{d:"M20.5 10a2.5 2.5 0 0 1-2.4-3H18a2.95 2.95 0 0 1-2.6-4.4 10 10 0 1 0 6.3 7.1c-.3.2-.8.3-1.2.3",key:"19sr3x"}],["circle",{cx:"12",cy:"12",r:"3",key:"1v7zrd"}]]);/**
81
+ */const Pe=s.createLucideIcon("Donut",[["path",{d:"M20.5 10a2.5 2.5 0 0 1-2.4-3H18a2.95 2.95 0 0 1-2.6-4.4 10 10 0 1 0 6.3 7.1c-.3.2-.8.3-1.2.3",key:"19sr3x"}],["circle",{cx:"12",cy:"12",r:"3",key:"1v7zrd"}]]);/**
82
82
  * @license lucide-react v0.453.0 - ISC
83
83
  *
84
84
  * This source code is licensed under the ISC license.
85
85
  * See the LICENSE file in the root directory of this source tree.
86
- */const Pe=s.createLucideIcon("EllipsisVertical",[["circle",{cx:"12",cy:"12",r:"1",key:"41hilf"}],["circle",{cx:"12",cy:"5",r:"1",key:"gxeob9"}],["circle",{cx:"12",cy:"19",r:"1",key:"lyex9k"}]]);/**
86
+ */const _e=s.createLucideIcon("EllipsisVertical",[["circle",{cx:"12",cy:"12",r:"1",key:"41hilf"}],["circle",{cx:"12",cy:"5",r:"1",key:"gxeob9"}],["circle",{cx:"12",cy:"19",r:"1",key:"lyex9k"}]]);/**
87
87
  * @license lucide-react v0.453.0 - ISC
88
88
  *
89
89
  * This source code is licensed under the ISC license.
@@ -168,12 +168,12 @@
168
168
  *
169
169
  * This source code is licensed under the ISC license.
170
170
  * See the LICENSE file in the root directory of this source tree.
171
- */const _s=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"}]]);/**
171
+ */const Ps=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"}]]);/**
172
172
  * @license lucide-react v0.453.0 - ISC
173
173
  *
174
174
  * This source code is licensed under the ISC license.
175
175
  * See the LICENSE file in the root directory of this source tree.
176
- */const Ps=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"}]]);/**
176
+ */const _s=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"}]]);/**
177
177
  * @license lucide-react v0.453.0 - ISC
178
178
  *
179
179
  * This source code is licensed under the ISC license.
@@ -238,7 +238,7 @@
238
238
  *
239
239
  * This source code is licensed under the ISC license.
240
240
  * See the LICENSE file in the root directory of this source tree.
241
- */const Je=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 Ne(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 l;return{...o,cards:(l=o.cards)==null?void 0:l.map(c=>We(c))}})}})}}function We(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(l=>({...l,data:[]}))}},customCfg:Xs(t.customCfg),data:[]}}function Xs(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 Ys(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 Se(t,n){if(!n)return null;const{id:a,template:r,filterValues:o,isDefault:l,shared:c}=t;return await s.postRequest("https://semaphor.cloud/api/v1/lens",n,{lensId:a,template:r,filterValues:o,isDefault:l,shared:c,operation:"update"})}async function Zs(t,n){return n?await s.postRequest("https://semaphor.cloud/api/v1/lens",n,{operation:"delete",lensId:t}):null}function et(){const[t,n]=C.useState(""),[a,r]=C.useState(!1),o=s.useDashboardStore(p=>p.lenses),{setLenses:l,setSelectedLensId:c}=s.useDashboardActions(),[d,u]=C.useState(!1),[x,h]=C.useState(!1),g=s.useDashboardStore(p=>p.dashboard),b=s.useDashboardStore(p=>p.filterValues),{authToken:i}=s.useSemaphorContext();async function f(){u(!0);const p=Ne(g),S=await Ys(t,p,b,i==null?void 0:i.accessToken);S&&(l([...o||[],S]),c(S.id),h(!1)),u(!1)}return e.jsxs(s.Dialog,{open:x,onOpenChange:h,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:p=>{n(p.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:f,disabled:d,children:d?"Creating...":"Add"})})]})]})}function st(){const[t,n]=C.useState(!1),a=s.useDashboardStore(h=>h.lenses),r=s.useDashboardStore(h=>h.selectedLensId),{setLenses:o,setSelectedLensId:l}=s.useDashboardActions(),{authToken:c}=s.useSemaphorContext();async function d(h){l(h)}async function u(h){if(await Zs(h,c==null?void 0:c.accessToken)){const b=a==null?void 0:a.filter(i=>i.id!==h);o(b||[]),l("original")}}async function x(h){const g=a==null?void 0:a.map(f=>f.id===h.id?{...f,isDefault:!h.isDefault}:{...f,isDefault:!1});o(g||[]);const b={...h,isDefault:!h.isDefault};await Se(b,c==null?void 0:c.accessToken);const i=a==null?void 0:a.find(f=>f.isDefault);if(i&&i.id!==h.id){const f={...i,isDefault:!1};await Se(f,c==null?void 0:c.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(Ts,{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:d,children:[e.jsx(s.DropdownMenuRadioItem,{value:"original",children:"Original"}),a==null?void 0:a.map(h=>e.jsxs(s.DropdownMenuRadioItem,{className:"group flex justify-between gap-2",value:h.id,children:[e.jsx("p",{children:h.name}),e.jsxs("span",{className:"flex items-center gap-3",children:[e.jsx(Ms,{onClick:g=>{g.preventDefault(),x(h)},className:s.cn("size-3.5 text-muted-foreground hover:cursor-pointer hover:text-foreground group-hover:visible",{invisible:!h.isDefault,"text-green-500":h.isDefault}),strokeWidth:1.5}),e.jsx(s.Cross2Icon,{onClick:g=>{g.preventDefault(),u(h.id)},className:"invisible size-3.5 text-muted-foreground hover:cursor-pointer hover:text-foreground group-hover:visible",strokeWidth:1.5})]})]},h.id))]})]})]})}async function Ke(){var i;const t=s.useDashboardStore.getState().authToken,n=s.useDashboardStore.getState().theme,a=s.useDashboardStore.getState().filterValues,r=(i=s.useDashboardStore.getState().dashboard)==null?void 0:i.title,o=s.useDashboardStore.getState().isDownloadingPdf,l=s.useDashboardStore.getState().selectedSheetId;if(o)return;const c=new URLSearchParams;c.set("token",(t==null?void 0:t.accessToken)||""),c.set("theme",n||"light"),c.set("filterValues",JSON.stringify(a)),c.set("selectedSheetId",l||"");const d=`https://semaphor.cloud/api/v1/generate-pdf?params=${encodeURIComponent(c.toString())}`;s.useDashboardStore.setState({isDownloadingPdf:!0});const h=(await(await fetch(d,{method:"GET",headers:{Authorization:`Bearer ${t==null?void 0:t.accessToken}`}})).json()).url,g=document.createElement("a");g.href=h;const b=`${r}-${new Date().toISOString()}.pdf`;g.download=b,g.click(),s.useDashboardStore.setState({isDownloadingPdf:!1})}function tt({iconClassName:t}){const{authToken:n}=s.useSemaphorContext();s.useDashboardStore(o=>{var l;return(l=o.dashboard)==null?void 0:l.title}),s.useDashboardStore(o=>o.theme),s.useDashboardStore(o=>o.filterValues);const a=s.useDashboardStore(o=>o.isDownloadingPdf);async function r(){await Ke()}return e.jsx(s.Button,{variant:"link",className:"group h-7 p-2",size:"sm",onClick:r,children:a?e.jsx(he,{className:s.cn("size-3.5 animate-spin",t)}):e.jsx(s.Download,{className:s.cn("size-3.5",t),strokeWidth:1.5})})}function at(){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 l=s.useDashboardStore(m=>m.isDashboardEditing),c=s.useEditorStore(m=>m.selectedConnectionId),[d,u]=C.useState(!1),x=s.useDashboardStore(m=>m.filterValues),h=s.useDashboardStore(m=>m.isVisualEditing),g=s.useDashboardStore(m=>m.showFilters);s.useDashboardStore(m=>m.showDashboardJSON);const b=s.useDashboardStore(m=>m.onSaveFunction),i=s.useDashboardStore(m=>m.actions.setShowFilters),{addFrame:f,setSelectedFrameId:p}=s.useDashboardStore(m=>m.actions),{getSelectedSheet:S,setIsDashboardEditing:j,setShowDashboardJSON:w}=s.useDashboardStore(m=>m.actions),v=S(),{tenantId:I,endUserId:z}=C.useMemo(()=>s.getTenantAndEndUserId(t==null?void 0:t.accessToken),[t==null?void 0:t.accessToken]),L=C.useMemo(()=>I||z,[I,z]),q=()=>{if(!l||!v)return;const m={connectionId:c,id:s.v4(),title:"Title",description:"Description",preferences:{onClickFilter:[{columnIndex:0,expression:""}]},type:"bar",sql:"select COUNT(*) from YOUR_TABLE",data:[]},O={id:s.v4(),cards:[m],activeCardId:m.id};f(v.id,O),p(O.id)},V=()=>{j(!0)};async function B(){if(u(!0),!a||!r)return;const m=Ne(o),O=JSON.stringify(m),H={...r,template:O,filterValues:x};await Se(H,t==null?void 0:t.accessToken),s.ue.success("Lens saved"),b==null||b(m),u(!1)}return h?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:[!h&&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(Ws,{className:"h-4 w-4",strokeWidth:1.5})}),e.jsx(tt,{}),l&&!h&&L&&e.jsx(et,{}),!h&&L&&e.jsx(st,{}),l&&!h&&e.jsxs(s.Button,{variant:"secondary",className:"h-7 p-2",size:"sm",disabled:!l,onClick:q,children:[e.jsx(s.Plus,{className:"mr-2 h-4 w-4",strokeWidth:1.5}),"Frame"]}),!l&&e.jsx(s.Button,{variant:"ghost",className:"h-7 p-2",onClick:V,size:"sm",children:e.jsx(s.Pencil,{className:"h-4 w-4",strokeWidth:1.5})}),l&&!h&&e.jsx(s.Button,{variant:"ghost",role:"close",className:"h-7 p-2",onClick:()=>{j(!1),w(!1)},size:"sm",children:e.jsx(s.Cross2Icon,{className:"h-4 w-4",strokeWidth:1.5})}),l&&!h&&L&&e.jsx(s.Button,{className:"h-7 p-2",variant:"ghost",disabled:d,onClick:B,size:"sm",children:e.jsx(Gs,{className:"h-4 w-4",strokeWidth:1.5})}),!g&&!h&&l&&e.jsx(s.Button,{className:"h-7 p-2",variant:"ghost",onClick:()=>i(!0),size:"sm",children:e.jsx(s.Filter,{className:"h-4 w-4",strokeWidth:1.5})}),!h&&l&&!1,!h&&!1]})]})}function nt({name:t,items:n,value:a,onChange:r,isLoading:o,isError:l,refetch:c,className:d,showNone:u=!1}){const x=ie.useRef(null),[h,g]=ie.useState(!1),[b,i]=ie.useState("100%"),f=u?[...n||[],{id:"none",name:"None"}]:n;ie.useLayoutEffect(()=>{x.current&&i(x.current.offsetWidth)},[]);function p(){var j;return o?"Loading...":l?"Error":a?(j=n==null?void 0:n.find(w=>w.id===a))==null?void 0:j.name:`Select ${t}`}function S(j,w){r(w),g(!1)}return e.jsxs(s.Popover,{open:h,onOpenChange:g,children:[e.jsx(s.PopoverTrigger,{asChild:!0,children:e.jsxs(s.Button,{ref:x,variant:"outline",role:"combobox","aria-expanded":h,className:s.cn("flex h-9 w-full max-w-[226px] justify-between",d),children:[e.jsx("span",{className:"overflow-hidden text-ellipsis whitespace-nowrap",children:p()}),e.jsx(s.ChevronDown,{className:"size-4 opacity-50"})]})}),e.jsx(s.PopoverContent,{className:"w-full p-0",style:{minWidth:b},children:e.jsxs(s.Command,{children:[e.jsxs("div",{className:"flex h-9 items-center justify-between border-b pr-1",children:[e.jsx(s.CommandInput,{className:"h-9",placeholder:"Search..."}),e.jsx(s.IconButton,{className:"h-7",onClick:c,children:e.jsx($e,{className:s.cn("size-3.5 opacity-50",o&&"animate-spin")})})]}),e.jsxs(s.CommandList,{children:[e.jsxs(s.CommandEmpty,{children:["No ",t==null?void 0:t.toLowerCase()," found."]}),e.jsx(s.CommandGroup,{children:f==null?void 0:f.map(j=>e.jsx(s.CommandItem,{className:"overflow-x-auto",value:j.name,onSelect:w=>S(w,j.id),children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(s.Check,{className:s.cn("size-4",a===j.id?"opacity-100":"opacity-0")}),e.jsx("div",{title:j.name,children:j.name})]})},j.id))})]})]})})]})}function oe({title:t,items:n,value:a,isLoading:r,isError:o,refetch:l,connectionTooltip:c,onChange:d,showNone:u=!1,className:x,showIcon:h=!0,disabled:g=!1,type:b="select"}){const i=r?"Loading...":o?"Error":a;function f(){if(t==="Connection")return e.jsx(Ps,{className:"size-4 rotate-90"});if(t==="Database")return e.jsx(ks,{className:"size-4"});if(t==="Schema")return e.jsx(_s,{className:"size-4"});if(t==="Table")return e.jsx(s.Table2,{className:"size-4"});if(t==="Model")return e.jsx(ys,{className:"size-4"})}function p(){return e.jsxs(s.Select,{disabled:g,value:i,onValueChange:d,children:[e.jsx(s.SelectTrigger,{className:s.cn("h-9 w-full border-muted focus:ring-1 focus:ring-offset-0",x),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($e,{className:s.cn("mr-1 size-3 cursor-pointer text-muted-foreground hover:text-foreground",r&&"animate-spin"),onClick:l})]}),e.jsxs(e.Fragment,{children:[u&&e.jsx(s.SelectItem,{value:"none",children:"None"},"none"),n&&n.map((j,w)=>e.jsx(s.SelectItem,{value:j.id,children:j.name},w))]}),(r||o)&&e.jsx(s.SelectItem,{value:i,children:i})]})})]})}function S(){return e.jsx(nt,{items:n,value:i,onChange:d||(()=>{}),isLoading:r,isError:o,refetch:l,name:t,showNone:u})}return e.jsxs("div",{className:"flex items-center gap-2",children:[h&&e.jsx("div",{className:"shrink-0",children:c?e.jsxs(s.Tooltip,{children:[e.jsx(s.TooltipTrigger,{children:f()}),e.jsx(s.TooltipContent,{className:"text-xs",align:"start",children:c})]}):f()}),b==="combobox"?S():p()]})}function rt({column:t}){const[n,a]=C.useState(!1),r=s.useEditorStore(f=>f.selectedTableName),o=s.useEditorStore(f=>f.selectedSchemaName),l=s.useEditorStore(f=>f.selectedDatamodelId),c=s.useEditorStore(f=>f.sqlGen),{modelItems:d,connectionType:u}=ne(),x=s.useEditorStore(f=>f.actions.setSqlGen),h=s.useEditorStore(f=>f.actions.setCardSql),g=s.useEditorStore(f=>f.actions.setRunSql);function b(f,p){var v;const S=s.createSqlGenConfig(f,c,p),j=(v=d==null?void 0:d.find(I=>I.id===l))==null?void 0:v.name;x(S);const w=s.getSql(S,s.fmt(o||""),s.fmt(r),j,u);w&&(h(w),g(!0)),a(!1)}function i(){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(Pe,{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:i()})]})}function Xe({column:t}){return e.jsxs(s.Tooltip,{children:[e.jsx(s.TooltipTrigger$1,{asChild:!0,children:s.isTextDataType(t.data_type)?e.jsx(Je,{className:"size-3"}):s.isNumberDataType(t.data_type)?e.jsx(Os,{className:"size-3"}):s.isDateDataType(t.data_type)?e.jsx(s.Calendar,{className:"size-3"}):s.isBooleanDataType(t.data_type)?e.jsx(Ks,{className:"size-3"}):t.data_type.toLowerCase()==="json"?e.jsx(Ss,{className:"size-3"}):e.jsx($s,{className:"size-3"})}),e.jsx(s.TooltipContent,{children:e.jsx("p",{className:"font-mono text-xs",children:t.data_type})})]})}function ot({schemaName:t,tableName:n,columns:a,status:r}){const o=s.useEditorStore(m=>m.sqlGen),l=s.useEditorStore(m=>m.selectedConnectionId),c=s.useEditorStore(m=>m.selectedDatabaseName),d=s.useEditorStore(m=>m.selectedSchemaName),u=s.useEditorStore(m=>m.selectedTableName),x=s.useEditorStore(m=>m.selectedDatamodelId),h=s.useDashboardStore(m=>m.dashboard.aiScopeTables),{addToAIScope:g,removeFromAIScope:b}=s.useDashboardActions(),{setAIScopeTables:i}=s.useDashboardStore(m=>m.actions),f=s.useEditorStore(m=>m.actions.setRunSql),p=s.useEditorStore(m=>m.actions.setSqlGen),S=s.useEditorStore(m=>m.actions.setIsShowingVisual),j=s.useEditorStore(m=>m.actions.setCardSql),{connectionType:w,modelItems:v,selectedDatamodelName:I}=ne();function z(m){var _;const O=s.createSqlGenConfig(m,o);p(O);const H=(_=v==null?void 0:v.find(G=>G.id===x))==null?void 0:_.name,A=s.getSql(O,s.fmt(t),s.fmt(n),H,w);A&&(j(A),f(!0))}function L(){return(h==null?void 0:h.find(m=>m.connectionId===l&&(m.tableName===u||m.datamodelName===I)))!==void 0}function q(m){m===!0&&(u||I)&&l?(g({connectionId:l,connectionType:w==="S3"||w==="API"?"DuckDb":w,databaseName:c||"",schemaName:d||"",tableName:u||"",datamodelName:s.resolveDatamodelName(I),datamodelId:x||""}),s.ue.success("Added to Assistant Scope",{position:"top-right",duration:2500,richColors:!0})):(b({connectionId:l||"",connectionType:w||"",tableName:u||"",datamodelName:s.resolveDatamodelName(I),datamodelId:x||"",databaseName:c||"",schemaName:d||""}),s.ue("Removed from Assistant Scope",{position:"top-right",duration:2e3,richColors:!0}))}function V(){const m=s.getFormattedTableNameForQuery({schemaName:t,tableName:n,modelName:I,connectionType:w});S(!1);const O=w==="MSSQL"?`SELECT top 10 * FROM ${m}`:`SELECT * FROM ${m} LIMIT 10`;j(O),f(!0)}function B(){const m=s.getFormattedTableNameForQuery({schemaName:t,tableName:n,modelName:I,connectionType:w});j(`SELECT COUNT(*) as count FROM ${m}`),f(!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:`${L()?"Remove from":"Add to"} Assistant Scope`,pressed:L(),onPressedChange:q,variant:"outline",className:s.cn("h-9 px-2",{}),children:[e.jsx(s.Plus,{className:s.cn("mr-1 size-4",{"text-green-400":L(),"text-muted-foreground":!L()})}),"AI"]}),e.jsxs(s.Button,{disabled:r!=="Success",onClick:V,size:"sm",variant:"secondary",className:"flex",children:[r!=="Success"?e.jsx(he,{className:"mr-2 h-4 w-4 animate-spin text-foreground/50"}):e.jsx(qs,{className:"mr-2 size-4"}),"Top 10"]}),e.jsxs(s.Button,{disabled:r!=="Success",onClick:B,size:"sm",variant:"secondary",className:"w-full",children:[r!=="Success"?e.jsx(he,{className:"mr-2 h-4 w-4 animate-spin text-foreground/50"}):e.jsx(Us,{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:()=>z(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(Xe,{column:m}),e.jsx("span",{children:m.column_name})]}),e.jsx("div",{onClick:O=>O.stopPropagation(),className:"flex items-center justify-end",children:s.isNumberDataType(m.data_type)&&e.jsx(rt,{column:m})})]},m.column_name))}),e.jsx(s.ScrollBar,{orientation:"vertical"}),e.jsx(s.ScrollBar,{orientation:"horizontal"})]})]})}function ne(t,n){var ke,Ee,Ie,De,Te,Le;let a=C.useMemo(()=>[],[]);const r=s.useSemaphorContext().authToken||t,o=s.useEditorStore(N=>N.selectedConnectionId),l=s.useEditorStore(N=>N.selectedDatamodelId),c=s.useEditorStore(N=>N.selectedDatabaseName),d=s.useEditorStore(N=>N.selectedSchemaName),u=s.useEditorStore(N=>N.selectedTableName),x=s.useEditorStore(N=>N.actions.setCurrentColumns),h=s.useEditorStore(N=>N.actions.setSelectedConnectionId),g=s.useEditorStore(N=>N.actions.setSelectedDatamodelId),b=s.useEditorStore(N=>N.actions.setSelectedDatabaseName),i=s.useEditorStore(N=>N.actions.setSelectedSchemaName),f=s.useEditorStore(N=>N.actions.setSelectedTableName);s.useEditorStore(N=>N.actions.setCardSql);function p(N){return o&&c&&d&&c!=="NA"?!0:o&&N==="API"?!1:!!(o&&N==="S3")}function S(N){return!!(o&&c&&c!=="NA"&&d&&u||o&&(N==="S3"||N==="API")||l&&l)}function j(N){return o&&N?!(N==="API"||N==="S3"):!1}const{refetch:w,data:v,isLoading:I,isError:z}=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:L,data:q,isLoading:V,isError:B}=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=v==null?void 0:v.connections.find(N=>N.id===o),O=m==null?void 0:m.type,H=(m==null?void 0:m.type)==="API"||(m==null?void 0:m.type)==="S3",{data:A,isLoading:_,isFetching:G,isError:M,refetch:y}=s.useQuery({queryKey:["databases",o],queryFn:()=>s.getRequest("https://semaphor.cloud/api/v1/databases",(r==null?void 0:r.accessToken)||"",{connection_id:o}),enabled:j(O)}),{data:E,isLoading:R,isFetching:$,isError:U,refetch:F}=s.useQuery({queryKey:["schemas",o,c],queryFn:()=>s.getRequest("https://semaphor.cloud/api/v1/schemas",(r==null?void 0:r.accessToken)||"",{connection_id:o,database_name:c}),enabled:!!o&&!!c&&!H&&c!=="NA"}),{data:T,isLoading:Y,isFetching:k,isError:P,refetch:J}=s.useQuery({queryKey:["tables",o,c,d],queryFn:()=>s.getRequest("https://semaphor.cloud/api/v1/tables",(r==null?void 0:r.accessToken)||"",{connection_id:o,database_name:c,schema_name:d}),enabled:p(O)}),{data:K,isLoading:ae,isFetching:se,isError:Q,refetch:X}=s.useQuery({queryKey:["columns",o,c,l,d,u],queryFn:()=>s.getRequest("https://semaphor.cloud/api/v1/columns",(r==null?void 0:r.accessToken)||"",{connection_id:o,datamodel_id:l||"",database_name:c,schema_name:d,table_name:u}),enabled:S(O)});C.useEffect(()=>{x(a)},[K,x,a]),C.useEffect(()=>{(O==="S3"||O==="API")&&(b(""),i(""),g(""),O==="API"&&f("api"))},[O,f,b,i,g]);const D=(m==null?void 0:m.type)==="API"?(ke=m==null?void 0:m.type)==null?void 0:ke.toLowerCase():u||"",W=H?"":d||"";function Z(N){i(N),f("")}function ee(N){b(N==="none"?"":N),i(""),f(""),N!=="none"&&N!==""&&g("")}function de(N){h(N)}function be(N){g(N==="none"?"":N),N!=="none"&&N!==""&&b("")}A&&((Ee=A==null?void 0:A.databases)==null?void 0:Ee.length)>0,E&&((Ie=E==null?void 0:E.schemas)==null?void 0:Ie.length)>0,K&&((De=K==null?void 0:K.columns)==null?void 0:De.length)>0&&(a=K.columns.map(N=>({...N,data_type:N.data_type.toLowerCase()}))),M&&(a=[]),(Q||z)&&(a=[]);const me=v==null?void 0:v.connections.map(N=>({id:N.id,name:N.name,type:N.type})),ye=(Te=q==null?void 0:q.datamodels)==null?void 0:Te.map(N=>({id:N.id,name:N.name})),ms=A==null?void 0:A.databases.map(N=>({id:N.database_name,name:N.database_name})),xs=E==null?void 0:E.schemas.map(N=>({id:N.schema_name,name:N.schema_name})),ps=T==null?void 0:T.tables.map(N=>({id:N.table_name,name:N.table_name})),fs=(Le=q==null?void 0:q.datamodels.find(N=>N.id===l))==null?void 0:Le.name;return{connectionItems:me,isConnectionsLoading:I,isConnectionsError:z,modelItems:ye,selectedDatamodelId:l,selectedDatamodelName:fs,isModelsLoading:V,isModelsError:B,databaseItems:ms,isDatabasesLoadingOrFetching:_||G,isDatabaseError:M,schemaItems:xs,isSchemaLoadingOrFetching:R||$,isSchemaError:U,tableItems:ps,isTableLoadingOrFetching:Y||k,isTableError:P,columns:a,isColumnsLoadingOrFetching:ae||se,isColumnsError:Q,isNonDbConnection:H,connectionType:O,tableName:D,schemaName:W,refetchConnections:w,refetchModels:L,refetchDatabases:y,refetchSchemas:F,refetchTables:J,refetchColumns:X,handleConnectionChange:de,handleDatamodelChange:be,handleDatabaseChange:ee,handleSchemaChange:Z}}function Ye({ColumnsComponent:t}){var se;const n=s.useEditorStore(Q=>Q.selectedConnectionId),a=s.useEditorStore(Q=>Q.selectedDatamodelId),r=s.useEditorStore(Q=>Q.selectedDatabaseName),o=s.useEditorStore(Q=>Q.selectedSchemaName),l=s.useEditorStore(Q=>Q.selectedTableName),c=s.useEditorStore(Q=>Q.actions.setSelectedTableName),{connectionItems:d,modelItems:u,schemaItems:x,databaseItems:h,tableItems:g,columns:b,isConnectionsLoading:i,isModelsLoading:f,isConnectionsError:p,isModelsError:S,isDatabasesLoadingOrFetching:j,isDatabaseError:w,isSchemaLoadingOrFetching:v,isSchemaError:I,isColumnsError:z,isColumnsLoadingOrFetching:L,isTableLoadingOrFetching:q,isTableError:V,connectionType:B,isNonDbConnection:m,refetchDatabases:O,refetchModels:H,refetchSchemas:A,refetchTables:_,refetchColumns:G,refetchConnections:M,handleConnectionChange:y,handleDatabaseChange:E,handleSchemaChange:R,handleDatamodelChange:$,tableName:U,schemaName:F}=ne();function T(){return t?t(F,U,b):e.jsx(ot,{schemaName:F,tableName:U,columns:b,status:L?"Loading...":z?"Error":"Success"})}function Y(){window.location.href="mailto:support@semaphor.cloud?subject=Help&body=I need help with..."}function k(){if(!n||B==="S3"||B==="API")return null;if(!a||a==="none")return e.jsx(oe,{refetch:O,showNone:!0,onChange:E,isError:w,isLoading:j,items:h,value:r||"",title:"Database",type:"combobox"})}function P(){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 J(){if(!n||B==="S3"||B==="API")return null;if(!r||r==="none")return e.jsx(oe,{refetch:H,showNone:!0,onChange:$,isError:S,isLoading:f,items:u,value:a||"",title:"Model",type:"combobox"})}function K(){return!n||B==="S3"||B==="API"||!r||r==="none"?null:e.jsx(oe,{refetch:A,onChange:R,isError:I,isLoading:v,items:x,value:o||"",title:"Schema",type:"combobox"})}function ae(){function Q(){let X=!1;return B==="API"?(X=!1,X):((B==="S3"||n&&r&&r!=="none"&&o)&&(X=!0),X)}return Q()?e.jsx(oe,{refetch:_,onChange:c,isError:V,items:g,isLoading:q,value:l||"",title:"Table",type:"combobox"}):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(oe,{refetch:M,items:d,title:"Connection",value:n||"",onChange:y,isLoading:i,isError:p,type:"combobox",connectionTooltip:((se=d==null?void 0:d.find(Q=>Q.id===n))==null?void 0:se.type)||""}),k(),P(),J(),K(),ae()]}),T(),e.jsx("div",{className:"flex items-end justify-center gap-2 px-6 py-4",children:e.jsxs(s.Button,{onClick:Y,size:"sm",variant:"secondary",className:"w-full",children:[e.jsx(Bs,{className:"mr-2 size-4"}),"Help"]})})]})}function it(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 l=t.length;if(o!==-1&&(l=o),r!==-1&&r<l&&(l=r),n!==-1){const c=t.substring(0,n),d=t.substring(n);return`${c} {{ filters | where }} AND ${d.substring(6)}`}else if(a!==-1){const c=t.substring(0,a),d=t.substring(a);return`${c} {{ filters | where }} ${d}`}else{const c=t.substring(0,l),d=t.substring(l);return console.log("beforeClause",c),console.log("afterClause",d),d?`${c} {{ filters | where }} ${d}`:`${c.replace(/;$/,"")} {{ filters | where }}`}}function lt({sql:t,error:n,onClick:a}){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(vs,{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,size:"sm",variant:"secondary",children:[e.jsx(As,{className:"mr-2 h-4 w-4"}),"Debug with Assistant"]})]})})})]})}function ct(){const[t,n]=C.useState([]),[a,r]=C.useState(""),[o,l]=C.useState(null),{authToken:c}=s.useSemaphorContext(),d=s.useEditorStore(k=>{var P;return(P=k==null?void 0:k.card)==null?void 0:P.sql}),u=s.useEditorStore(k=>{var P;return(P=k==null?void 0:k.card)==null?void 0:P.python}),x=s.useEditorStore(k=>k.actions.setCardSql),h=s.useEditorStore(k=>k.actions.setRunSql),g=s.useEditorStore(k=>k.actions.switchCardType),b=s.useEditorStore(k=>k.userInputForAI),i=s.useEditorStore(k=>k.triggerAIRun),f=s.useEditorStore(k=>k.selectedDatabaseName),p=s.useEditorStore(k=>k.selectedTableName),S=s.useEditorStore(k=>k.selectedConnectionId),j=s.useEditorStore(k=>k.selectedSchemaName),w=s.useDashboardStore(k=>k.dashboard.aiScopeTables),{setTriggerAIRun:v}=s.useEditorActions(),{selectedDatamodelName:I,connectionType:z,selectedDatamodelId:L}=ne(),{messages:q,setMessages:V,reload:B,append:m,input:O,setInput:H,status:A,handleInputChange:_,handleSubmit:G,stop:M}=s.useChat({api:"https://semaphor.cloud/api/v1/assistant",headers:{Authorization:`Bearer ${c==null?void 0:c.accessToken}`},body:{random:Math.random()},maxSteps:10,onToolCall:y,onFinish(k,P){E(P.usage),r(""),console.log("onFinish",k,P),P.finishReason==="stop"&&r("")}});C.useEffect(()=>{i&&b&&(_({target:{value:b}}),setTimeout(()=>{G(),v(!1)},100))},[i,G,b,v,_]);async function y({toolCall:k}){if(k.toolName==="createChart"){console.log("createChart",k.args);const P=k.args.sql,J=k.args.chartType;return g(J),x(P),h(!0),{status:"success",message:"Let the user know that chart is created"}}else if(k.toolName==="getTableColumns")r("Getting table columns...");else{if(k.toolName==="getUserSql")return d?{status:"success",sql:d,python:u||""}:{status:"error",message:"No SQL found"};if(k.toolName==="getCurrentTableScope")return r("Getting table scope..."),T(),{status:"success",tables:t};r("Analyzing...")}}function E(k){l(P=>P?{promptTokens:P.promptTokens+k.promptTokens,completionTokens:P.completionTokens+k.completionTokens,totalTokens:P.totalTokens+k.totalTokens}:k)}function R(k){const P=s.removeFromScopeArray(t,k);U(P)}function $(k){return k.map(J=>({...J,connectionType:J.connectionType==="API"||J.connectionType==="S3"?"DuckDb":J.connectionType}))}function U(k){const P=$(k);n(P),V(J=>[...J,{id:crypto.randomUUID(),role:"system",content:`Current scope of tables | ${JSON.stringify(P)}`}])}function F(){const k={databaseName:f||"",schemaName:j||"",tableName:p||"",datamodelId:L||"",datamodelName:s.resolveDatamodelName(I),connectionId:S||"",connectionType:z||""},P=s.dedup([...t,k]);U(P)}function T(){const k={databaseName:f||"",schemaName:j||"",tableName:p||"",datamodelName:s.resolveDatamodelName(I),connectionId:S||"",connectionType:z||"",datamodelId:L||""};if(!s.isInAiScopeArray([...w||[],...t],k)||t.length===0){const J=s.dedup([...w||[],...t,k]).filter(K=>K.connectionId===k.connectionId);U(J)}}const Y=!["ready","error"].includes(A);return{messages:q,setMessages:V,reload:B,append:m,input:O,setInput:H,isLoading:Y,handleSetAIScope:T,handleAddCurrentTableToScope:F,removeFromCurrentSelections:R,currentScope:t,setCurrentScope:n,handleInputChange:_,handleSubmit:G,stop:M,chatStatus:A,toolStatus:a,llmUsage:o}}const dt=!1;function ut(){const t=s.useEditorStore(M=>M.showAIDialog),n=C.useRef(t),a=C.useRef(null),r=C.useRef(null),[o,l]=C.useState(!1),[c,d]=C.useState(dt),[u,x]=C.useState(!1),h=s.useEditorStore(M=>M.actions.setCardSql),g=s.useEditorStore(M=>M.actions.setRunSql),{setShowAIDialog:b}=s.useEditorActions(),{messages:i,setMessages:f,reload:p,input:S,setInput:j,isLoading:w,handleSetAIScope:v,handleAddCurrentTableToScope:I,removeFromCurrentSelections:z,currentScope:L,setCurrentScope:q,handleInputChange:V,handleSubmit:B,stop:m,chatStatus:O,toolStatus:H,llmUsage:A}=ct();C.useEffect(()=>{const M=n.current?"smooth":"auto";n.current=t;const y=setTimeout(()=>{var E;a.current&&(a.current.scroll({top:a.current.scrollHeight,behavior:M}),(E=r.current)==null||E.focus())},50);return()=>clearTimeout(y)},[i,t]);function _(M){b(!1),h(M),g(!0)}function G(){return e.jsxs(s.DropdownMenu,{children:[e.jsx(s.DropdownMenuTrigger,{children:e.jsx(s.Button,{className:"h-7 p-2",size:"sm",variant:"ghost",children:e.jsx(Pe,{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:o,onCheckedChange:l,children:"Token Usage"}),e.jsx(s.DropdownMenuCheckboxItem,{checked:c,onCheckedChange:d,children:"Tool Invocations"}),e.jsx(s.DropdownMenuCheckboxItem,{checked:u,onCheckedChange:x,children:"System Message"})]})]})}return e.jsxs(s.Dialog,{open:t,onOpenChange:b,children:[e.jsx(s.DialogTrigger,{asChild:!0,children:e.jsx(s.Button,{onClick:v,size:"sm",className:"w-full cursor-text justify-start font-normal text-muted-foreground focus-visible:ring-0 focus-visible:ring-offset-0",variant:"ghost",children:"Type your question..."})}),e.jsxs(s.DialogContent,{className:"flex flex-col justify-between overflow-auto sm:max-w-[425px] md:max-h-[700px] md:min-w-[625px] [&>button]:hidden",children:[e.jsx(s.DialogHeader,{children:e.jsxs("div",{className:"flex items-start justify-between gap-2",children:[e.jsxs("div",{children:[e.jsx(s.DialogTitle,{children:"Assistant"}),L&&L.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:"Context:"}),L==null?void 0:L.map((M,y)=>e.jsxs("div",{className:"flex items-center gap-2 rounded-md border border-border bg-muted px-2 py-1 text-xs",children:[s.getFormattedTableNameForQuery({schemaName:M.schemaName||"",tableName:M.tableName||"",modelName:M.datamodelName||"",connectionType:M.connectionType||""}),e.jsx("button",{onClick:()=>{z(M)},children:e.jsx(s.X,{className:"size-3 text-muted-foreground hover:text-foreground"})})]},y))]}),(L==null?void 0:L.length)===0&&e.jsxs("div",{className:"mt-2 flex items-center gap-2",children:[e.jsx("span",{className:"text-xs text-muted-foreground",children:"Context: None"}),e.jsxs(s.Button,{className:"h-6 text-xs",size:"sm",variant:"secondary",onClick:I,children:[e.jsx(s.Plus,{className:"mr-2 size-3"}),"Current Table"]})]})]}),e.jsxs("div",{className:"flex items-center",children:[G(),e.jsx(s.Button,{className:"h-7 p-2",size:"sm",variant:"ghost",onClick:()=>{f([]),q([]),p()},children:e.jsx(s.RefreshCcw,{className:"size-3.5 text-muted-foreground"})})]})]})}),e.jsx("div",{ref:a,className:"h-[700px] w-full overflow-auto",children:e.jsxs("div",{className:"space-y-4 py-2 pr-3",role:"messages",children:[e.jsx(s.PrintMessages,{messages:i,showTools:c,handleRun:_,showSystemMessage:u}),e.jsx(s.ChatStatus,{status:s.getStatus(O,H),isLoading:w})]})}),e.jsx(s.ChatInput,{stop:m,ref:r,setInput:j,input:S,handleInputChange:V,handleSubmit:B,isLoading:w}),A&&o&&e.jsx("div",{className:"flex h-8 items-center justify-between",children:e.jsxs("div",{className:"text-xs text-muted-foreground",children:["Usage: ",A.promptTokens," prompt tokens,"," ",A.completionTokens," completion tokens,"," ",A.totalTokens," total tokens"]})})]})]})}var Ze={color:void 0,size:void 0,className:void 0,style:void 0,attr:void 0},Ae=C.createContext&&C.createContext(Ze),ht=["attr","size","title"];function mt(t,n){if(t==null)return{};var a=xt(t,n),r,o;if(Object.getOwnPropertySymbols){var l=Object.getOwnPropertySymbols(t);for(o=0;o<l.length;o++)r=l[o],!(n.indexOf(r)>=0)&&Object.prototype.propertyIsEnumerable.call(t,r)&&(a[r]=t[r])}return a}function xt(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 fe(){return fe=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},fe.apply(this,arguments)}function Oe(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 ge(t){for(var n=1;n<arguments.length;n++){var a=arguments[n]!=null?arguments[n]:{};n%2?Oe(Object(a),!0).forEach(function(r){pt(t,r,a[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(a)):Oe(Object(a)).forEach(function(r){Object.defineProperty(t,r,Object.getOwnPropertyDescriptor(a,r))})}return t}function pt(t,n,a){return n=ft(n),n in t?Object.defineProperty(t,n,{value:a,enumerable:!0,configurable:!0,writable:!0}):t[n]=a,t}function ft(t){var n=gt(t,"string");return typeof n=="symbol"?n:n+""}function gt(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 es(t){return t&&t.map((n,a)=>C.createElement(n.tag,ge({key:a},n.attr),es(n.child)))}function le(t){return n=>C.createElement(jt,fe({attr:ge({},t.attr)},n),es(t.child))}function jt(t){var n=a=>{var{attr:r,size:o,title:l}=t,c=mt(t,ht),d=o||a.size||"1em",u;return a.className&&(u=a.className),t.className&&(u=(u?u+" ":"")+t.className),C.createElement("svg",fe({stroke:"currentColor",fill:"currentColor",strokeWidth:"0"},a.attr,r,c,{className:u,style:ge(ge({color:t.color||a.color},a.style),t.style),height:d,width:d,xmlns:"http://www.w3.org/2000/svg"}),l&&C.createElement("title",null,l),t.children)};return Ae!==void 0?C.createElement(Ae.Consumer,null,a=>n(a)):n(Ze)}function bt(t){return le({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 ss(t){const{theme:n}=s.useTheme(),a=s.useDashboardStore(p=>p.theme),r=s.useEditorStore(p=>p.frame),o=s.useEditorStore(p=>p.card),l=s.useEditorStore(p=>p.activeTabCardId),c=s.Le(),{refetch:d}=s.useDashboardCardQuery(o),{updateCardTab:u,setRunSql:x}=s.useEditorActions(),h=C.useRef(),g=C.useRef({}),b=r.cards.find(p=>p.id===l),i=C.useCallback(()=>{let p="";return t==="python"&&(p=(b==null?void 0:b.python)||s.PYTHON_DEFAULT_CODE),t==="sql"&&(p=(b==null?void 0:b.sql)||""),p},[t,b]);C.useEffect(()=>{if(l&&o.id&&o.id!==l){if(h.current&&c){const p=h.current.getModel();p&&(g.current[o.id]=p);let S=g.current[l];if(!S){const j=i();S=c.editor.createModel(j,t),g.current[l]=S}h.current.setModel(S)}u(l,o),x(!0)}},[l,o,u,c,x,t,i]),C.useEffect(()=>{if(!c)return;const p=window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light",S=a==="system"?p:a;c.editor.defineTheme("default",{base:S==="light"?"vs":"vs-dark",inherit:!0,rules:[],colors:{"editor.background":S==="light"?"#ffffff":s.hslStringToHex("240 10% 10%")}}),c.editor.setTheme("default")},[n,a,c]),C.useEffect(()=>{const p=h.current;p&&c&&o&&p.addCommand(c.KeyMod.Shift|c.KeyCode.Enter,function(){return d(),!1})},[c,d,o]);function f(p,S){if(h.current=p,!g.current[o.id]){const j=p.getModel(),w=i();g.current[o.id]=j||(S==null?void 0:S.editor.createModel(w,t))||p.getModel()}p.setModel(g.current[o.id])}return{handleEditorDidMount:f}}function yt(){const t=s.useEditorStore(c=>c.card.sql),n=s.useEditorStore(c=>c.sqlGen),{setCardSql:a,setSqlGen:r}=s.useEditorActions(),{handleEditorDidMount:o}=ss("sql");function l(c){a(c),s.isObjectEmpty(n)||r({})}return e.jsx(s.Ft,{theme:"default",className:"pt-3",onChange:l,value:t||"",options:{minimap:{enabled:!1},wordWrap:"on",scrollbar:{verticalScrollbarSize:0,horizontalScrollbarSize:0},fontSize:13,renderLineHighlight:"none"},defaultLanguage:"sql",onMount:o})}function St(){const t=s.useEditorStore(o=>o.card.python),{setCardPython:n}=s.useEditorActions(),{handleEditorDidMount:a}=ss("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 Ct({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 vt(){var X;const[t,n]=C.useState({queryKey:[],queryData:null}),a=s.useQueryClient(),[r,o]=C.useState(!1),[l,c]=C.useState(!1),d=s.useEditorStore(D=>D.frame),u=s.useEditorStore(D=>D.card),x=s.useEditorStore(D=>D.isShowingVisual),h=s.useEditorStore(D=>D.selectedConnectionId),g=s.useEditorStore(D=>D.selectedDatabaseName),b=s.useEditorStore(D=>D.selectedDatamodelId),i=s.useEditorStore(D=>D.selectedSchemaName),f=s.useEditorStore(D=>D.selectedTableName),p=s.useEditorStore(D=>{var W;return(W=D==null?void 0:D.card)==null?void 0:W.sql}),{sheetFilterValues:S}=s.useSheetFilterValues(),{setCardCustomCfg:j,setQueryResultColumns:w,setCardSql:v,setPythonStdOut:I,setCardPreferences:z,setCardType:L,setCardPython:q,runAssistant:V}=s.useEditorActions(),B=s.useEditorStore(D=>D.onSave),m=s.useEditorStore(D=>D.onClose),O=s.useEditorStore(D=>D.actions.setSqlGen),H=s.useEditorStore(D=>D.runSql),A=s.useEditorStore(D=>D.actions.setRunSql),_=s.useEditorStore(D=>D.actions.setCardCfg),G=s.useEditorStore(D=>D.actions.setIsSqlRunning),{data:M,isLoading:y,isFetching:E,isSuccess:R,isError:$,error:U,queryKey:F,refetch:T}=s.useDashboardCardQuery(u);C.useEffect(()=>{if(M&&(M.rowLimitExceeded&&s.ue.error("Row limit (10,000) exceeded. Refine your query.",{position:"top-center",richColors:!0}),I((M==null?void 0:M.output)||""),M.records.length>0)){const{dimensionKeys:D}=s.getKeys(M.records);w(D)}},[M,w,I]),C.useEffect(()=>{(y||E)&&G(!0),($||R)&&G(!1),$&&(w([]),I(""))},[y,E,M,I,$,R,G,w,U]),C.useEffect(()=>{H&&(a.getQueryData(F)||T(),A(!1))},[H,T,A,F,a]);function Y(){const D=a.getQueryData(F);t.queryData||n({queryKey:F,queryData:D}),a.setQueryData(F,null),a.removeQueries({queryKey:F,exact:!0}),v(""),O({}),q(""),_(void 0),j(""),z({}),L("bar")}function k(D,W){if(D.length===0)return"";if(W){const Z=D.find(ee=>ee.id===W);if(Z){const ee=Z.tabTitle;if(ee=="All__Header")return D[0].id;if(ee&&ee.endsWith("__Header")){const be=ee.split("__")[0],me=D.find(ye=>ye.tabTitle===be);return me?me.id:D[0].id}return W}}return D[0].id}function P(){let D=p;p&&!p.includes("{{")&&(D=it(p),v(D));const W={...u,lastSelectedSchema:i,lastSelectedDatamodelId:b,lastSelectedDatabase:g,lastSelectedTable:f,connectionId:h,type:x?u.type:"table",sql:D,customCfg:x?u.customCfg:null},Z=d.cards.map(de=>de.id===u.id?W:de),ee={...d,cards:Z,activeCardId:k(Z,d.activeCardId)};B==null||B(ee)}function J(){const{queryKey:D,queryData:W}=t;D&&W&&a.setQueryData(D,W),O({}),m==null||m()}async function K(){const D=`Can you help me debug this query in the current table scope?
241
+ */const Je=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 Ne(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 l;return{...o,cards:(l=o.cards)==null?void 0:l.map(c=>We(c))}})}})}}function We(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(l=>({...l,data:[]}))}},customCfg:Xs(t.customCfg),data:[]}}function Xs(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 Ys(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 Se(t,n){if(!n)return null;const{id:a,template:r,filterValues:o,isDefault:l,shared:c}=t;return await s.postRequest("https://semaphor.cloud/api/v1/lens",n,{lensId:a,template:r,filterValues:o,isDefault:l,shared:c,operation:"update"})}async function Zs(t,n){return n?await s.postRequest("https://semaphor.cloud/api/v1/lens",n,{operation:"delete",lensId:t}):null}function et(){const[t,n]=C.useState(""),[a,r]=C.useState(!1),o=s.useDashboardStore(p=>p.lenses),{setLenses:l,setSelectedLensId:c}=s.useDashboardActions(),[d,u]=C.useState(!1),[x,h]=C.useState(!1),g=s.useDashboardStore(p=>p.dashboard),y=s.useDashboardStore(p=>p.filterValues),{authToken:i}=s.useSemaphorContext();async function f(){u(!0);const p=Ne(g),S=await Ys(t,p,y,i==null?void 0:i.accessToken);S&&(l([...o||[],S]),c(S.id),h(!1)),u(!1)}return e.jsxs(s.Dialog,{open:x,onOpenChange:h,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:p=>{n(p.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:f,disabled:d,children:d?"Creating...":"Add"})})]})]})}function st(){const[t,n]=C.useState(!1),a=s.useDashboardStore(h=>h.lenses),r=s.useDashboardStore(h=>h.selectedLensId),{setLenses:o,setSelectedLensId:l}=s.useDashboardActions(),{authToken:c}=s.useSemaphorContext();async function d(h){l(h)}async function u(h){if(await Zs(h,c==null?void 0:c.accessToken)){const y=a==null?void 0:a.filter(i=>i.id!==h);o(y||[]),l("original")}}async function x(h){const g=a==null?void 0:a.map(f=>f.id===h.id?{...f,isDefault:!h.isDefault}:{...f,isDefault:!1});o(g||[]);const y={...h,isDefault:!h.isDefault};await Se(y,c==null?void 0:c.accessToken);const i=a==null?void 0:a.find(f=>f.isDefault);if(i&&i.id!==h.id){const f={...i,isDefault:!1};await Se(f,c==null?void 0:c.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(Ts,{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:d,children:[e.jsx(s.DropdownMenuRadioItem,{value:"original",children:"Original"}),a==null?void 0:a.map(h=>e.jsxs(s.DropdownMenuRadioItem,{className:"group flex justify-between gap-2",value:h.id,children:[e.jsx("p",{children:h.name}),e.jsxs("span",{className:"flex items-center gap-3",children:[e.jsx(Ms,{onClick:g=>{g.preventDefault(),x(h)},className:s.cn("size-3.5 text-muted-foreground hover:cursor-pointer hover:text-foreground group-hover:visible",{invisible:!h.isDefault,"text-green-500":h.isDefault}),strokeWidth:1.5}),e.jsx(s.Cross2Icon,{onClick:g=>{g.preventDefault(),u(h.id)},className:"invisible size-3.5 text-muted-foreground hover:cursor-pointer hover:text-foreground group-hover:visible",strokeWidth:1.5})]})]},h.id))]})]})]})}async function Ke(){var i;const t=s.useDashboardStore.getState().authToken,n=s.useDashboardStore.getState().theme,a=s.useDashboardStore.getState().filterValues,r=(i=s.useDashboardStore.getState().dashboard)==null?void 0:i.title,o=s.useDashboardStore.getState().isDownloadingPdf,l=s.useDashboardStore.getState().selectedSheetId;if(o)return;const c=new URLSearchParams;c.set("token",(t==null?void 0:t.accessToken)||""),c.set("theme",n||"light"),c.set("filterValues",JSON.stringify(a)),c.set("selectedSheetId",l||"");const d=`https://semaphor.cloud/api/v1/generate-pdf?params=${encodeURIComponent(c.toString())}`;s.useDashboardStore.setState({isDownloadingPdf:!0});const h=(await(await fetch(d,{method:"GET",headers:{Authorization:`Bearer ${t==null?void 0:t.accessToken}`}})).json()).url,g=document.createElement("a");g.href=h;const y=`${r}-${new Date().toISOString()}.pdf`;g.download=y,g.click(),s.useDashboardStore.setState({isDownloadingPdf:!1})}function tt({iconClassName:t}){const{authToken:n}=s.useSemaphorContext();s.useDashboardStore(o=>{var l;return(l=o.dashboard)==null?void 0:l.title}),s.useDashboardStore(o=>o.theme),s.useDashboardStore(o=>o.filterValues);const a=s.useDashboardStore(o=>o.isDownloadingPdf);async function r(){await Ke()}return e.jsx(s.Button,{variant:"link",className:"group h-7 p-2",size:"sm",onClick:r,children:a?e.jsx(he,{className:s.cn("size-3.5 animate-spin",t)}):e.jsx(s.Download,{className:s.cn("size-3.5",t),strokeWidth:1.5})})}function at(){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 l=s.useDashboardStore(m=>m.isDashboardEditing),c=s.useEditorStore(m=>m.selectedConnectionId),[d,u]=C.useState(!1),x=s.useDashboardStore(m=>m.filterValues),h=s.useDashboardStore(m=>m.isVisualEditing),g=s.useDashboardStore(m=>m.showFilters);s.useDashboardStore(m=>m.showDashboardJSON);const y=s.useDashboardStore(m=>m.onSaveFunction),i=s.useDashboardStore(m=>m.actions.setShowFilters),{addFrame:f,setSelectedFrameId:p}=s.useDashboardStore(m=>m.actions),{getSelectedSheet:S,setIsDashboardEditing:j,setShowDashboardJSON:w}=s.useDashboardStore(m=>m.actions),v=S(),{tenantId:I,endUserId:M}=C.useMemo(()=>s.getTenantAndEndUserId(t==null?void 0:t.accessToken),[t==null?void 0:t.accessToken]),L=C.useMemo(()=>I||M,[I,M]),q=()=>{if(!l||!v)return;const m={connectionId:c,id:s.v4(),title:"Title",description:"Description",preferences:{onClickFilter:[{columnIndex:0,expression:""}]},type:"bar",sql:"select COUNT(*) from YOUR_TABLE",data:[]},O={id:s.v4(),cards:[m],activeCardId:m.id};f(v.id,O),p(O.id)},V=()=>{j(!0)};async function B(){if(u(!0),!a||!r)return;const m=Ne(o),O=JSON.stringify(m),H={...r,template:O,filterValues:x};await Se(H,t==null?void 0:t.accessToken),s.ue.success("Lens saved"),y==null||y(m),u(!1)}return h?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:[!h&&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(Ws,{className:"h-4 w-4",strokeWidth:1.5})}),e.jsx(tt,{}),l&&!h&&L&&e.jsx(et,{}),!h&&L&&e.jsx(st,{}),l&&!h&&e.jsxs(s.Button,{variant:"secondary",className:"h-7 p-2",size:"sm",disabled:!l,onClick:q,children:[e.jsx(s.Plus,{className:"mr-2 h-4 w-4",strokeWidth:1.5}),"Frame"]}),!l&&e.jsx(s.Button,{variant:"ghost",className:"h-7 p-2",onClick:V,size:"sm",children:e.jsx(s.Pencil,{className:"h-4 w-4",strokeWidth:1.5})}),l&&!h&&e.jsx(s.Button,{variant:"ghost",role:"close",className:"h-7 p-2",onClick:()=>{j(!1),w(!1)},size:"sm",children:e.jsx(s.Cross2Icon,{className:"h-4 w-4",strokeWidth:1.5})}),l&&!h&&L&&e.jsx(s.Button,{className:"h-7 p-2",variant:"ghost",disabled:d,onClick:B,size:"sm",children:e.jsx(Gs,{className:"h-4 w-4",strokeWidth:1.5})}),!g&&!h&&l&&e.jsx(s.Button,{className:"h-7 p-2",variant:"ghost",onClick:()=>i(!0),size:"sm",children:e.jsx(s.Filter,{className:"h-4 w-4",strokeWidth:1.5})}),!h&&l&&!1,!h&&!1]})]})}function nt({name:t,items:n,value:a,onChange:r,isLoading:o,isError:l,refetch:c,className:d,showNone:u=!1}){const x=ie.useRef(null),[h,g]=ie.useState(!1),[y,i]=ie.useState("100%"),f=u?[...n||[],{id:"none",name:"None"}]:n;ie.useLayoutEffect(()=>{x.current&&i(x.current.offsetWidth)},[]);function p(){var j;return o?"Loading...":l?"Error":a?(j=n==null?void 0:n.find(w=>w.id===a))==null?void 0:j.name:`Select ${t}`}function S(j,w){r(w),g(!1)}return e.jsxs(s.Popover,{open:h,onOpenChange:g,children:[e.jsx(s.PopoverTrigger,{asChild:!0,children:e.jsxs(s.Button,{ref:x,variant:"outline",role:"combobox","aria-expanded":h,className:s.cn("flex h-9 w-full max-w-[226px] justify-between",d),children:[e.jsx("span",{className:"overflow-hidden text-ellipsis whitespace-nowrap",children:p()}),e.jsx(s.ChevronDown,{className:"size-4 opacity-50"})]})}),e.jsx(s.PopoverContent,{className:"w-full p-0",style:{minWidth:y},children:e.jsxs(s.Command,{children:[e.jsxs("div",{className:"flex h-9 items-center justify-between border-b pr-1",children:[e.jsx(s.CommandInput,{className:"h-9",placeholder:"Search..."}),e.jsx(s.IconButton,{className:"h-7",onClick:c,children:e.jsx($e,{className:s.cn("size-3.5 opacity-50",o&&"animate-spin")})})]}),e.jsxs(s.CommandList,{children:[e.jsxs(s.CommandEmpty,{children:["No ",t==null?void 0:t.toLowerCase()," found."]}),e.jsx(s.CommandGroup,{children:f==null?void 0:f.map(j=>e.jsx(s.CommandItem,{className:"overflow-x-auto",value:j.name,onSelect:w=>S(w,j.id),children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(s.Check,{className:s.cn("size-4",a===j.id?"opacity-100":"opacity-0")}),e.jsx("div",{title:j.name,children:j.name})]})},j.id))})]})]})})]})}function oe({title:t,items:n,value:a,isLoading:r,isError:o,refetch:l,connectionTooltip:c,onChange:d,showNone:u=!1,className:x,showIcon:h=!0,disabled:g=!1,type:y="select"}){const i=r?"Loading...":o?"Error":a;function f(){if(t==="Connection")return e.jsx(_s,{className:"size-4 rotate-90"});if(t==="Database")return e.jsx(ks,{className:"size-4"});if(t==="Schema")return e.jsx(Ps,{className:"size-4"});if(t==="Table")return e.jsx(s.Table2,{className:"size-4"});if(t==="Model")return e.jsx(ys,{className:"size-4"})}function p(){return e.jsxs(s.Select,{disabled:g,value:i,onValueChange:d,children:[e.jsx(s.SelectTrigger,{className:s.cn("h-9 w-full border-muted focus:ring-1 focus:ring-offset-0",x),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($e,{className:s.cn("mr-1 size-3 cursor-pointer text-muted-foreground hover:text-foreground",r&&"animate-spin"),onClick:l})]}),e.jsxs(e.Fragment,{children:[u&&e.jsx(s.SelectItem,{value:"none",children:"None"},"none"),n&&n.map((j,w)=>e.jsx(s.SelectItem,{value:j.id,children:j.name},w))]}),(r||o)&&e.jsx(s.SelectItem,{value:i,children:i})]})})]})}function S(){return e.jsx(nt,{items:n,value:i,onChange:d||(()=>{}),isLoading:r,isError:o,refetch:l,name:t,showNone:u})}return e.jsxs("div",{className:"flex items-center gap-2",children:[h&&e.jsx("div",{className:"shrink-0",children:c?e.jsxs(s.Tooltip,{children:[e.jsx(s.TooltipTrigger,{children:f()}),e.jsx(s.TooltipContent,{className:"text-xs",align:"start",children:c})]}):f()}),y==="combobox"?S():p()]})}function rt({column:t}){const[n,a]=C.useState(!1),r=s.useEditorStore(f=>f.selectedTableName),o=s.useEditorStore(f=>f.selectedSchemaName),l=s.useEditorStore(f=>f.selectedDatamodelId),c=s.useEditorStore(f=>f.sqlGen),{modelItems:d,connectionType:u}=ne(),x=s.useEditorStore(f=>f.actions.setSqlGen),h=s.useEditorStore(f=>f.actions.setCardSql),g=s.useEditorStore(f=>f.actions.setRunSql);function y(f,p){var v;const S=s.createSqlGenConfig(f,c,p),j=(v=d==null?void 0:d.find(I=>I.id===l))==null?void 0:v.name;x(S);const w=s.getSql(S,s.fmt(o||""),s.fmt(r),j,u);w&&(h(w),g(!0)),a(!1)}function i(){return e.jsxs("ul",{className:"text-xs",children:[e.jsx("li",{onClick:()=>y(t,"COUNT"),className:"cursor-pointer p-1 px-3 transition-colors hover:bg-muted",children:"Count"}),e.jsx("li",{onClick:()=>y(t,"AVG"),className:"cursor-pointer p-1 px-3 transition-colors hover:bg-muted",children:"Avg"}),e.jsx("li",{onClick:()=>y(t,"SUM"),className:"cursor-pointer p-1 px-3 transition-colors hover:bg-muted",children:"Sum"}),e.jsx("li",{onClick:()=>y(t,"MAX"),className:"cursor-pointer p-1 px-3 transition-colors hover:bg-muted",children:"Max"}),e.jsx("li",{onClick:()=>y(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(_e,{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:i()})]})}function Xe({column:t}){return e.jsxs(s.Tooltip,{children:[e.jsx(s.TooltipTrigger$1,{asChild:!0,children:s.isTextDataType(t.data_type)?e.jsx(Je,{className:"size-3"}):s.isNumberDataType(t.data_type)?e.jsx(Os,{className:"size-3"}):s.isDateDataType(t.data_type)?e.jsx(s.Calendar,{className:"size-3"}):s.isBooleanDataType(t.data_type)?e.jsx(Ks,{className:"size-3"}):t.data_type.toLowerCase()==="json"?e.jsx(Ss,{className:"size-3"}):e.jsx($s,{className:"size-3"})}),e.jsx(s.TooltipContent,{children:e.jsx("p",{className:"font-mono text-xs",children:t.data_type})})]})}function ot({schemaName:t,tableName:n,columns:a,status:r}){const o=s.useEditorStore(m=>m.sqlGen),l=s.useEditorStore(m=>m.selectedConnectionId),c=s.useEditorStore(m=>m.selectedDatabaseName),d=s.useEditorStore(m=>m.selectedSchemaName),u=s.useEditorStore(m=>m.selectedTableName),x=s.useEditorStore(m=>m.selectedDatamodelId),h=s.useDashboardStore(m=>m.dashboard.aiScopeTables),{addToAIScope:g,removeFromAIScope:y}=s.useDashboardActions(),{setAIScopeTables:i}=s.useDashboardStore(m=>m.actions),f=s.useEditorStore(m=>m.actions.setRunSql),p=s.useEditorStore(m=>m.actions.setSqlGen),S=s.useEditorStore(m=>m.actions.setIsShowingVisual),j=s.useEditorStore(m=>m.actions.setCardSql),{connectionType:w,modelItems:v,selectedDatamodelName:I}=ne();function M(m){var P;const O=s.createSqlGenConfig(m,o);p(O);const H=(P=v==null?void 0:v.find(G=>G.id===x))==null?void 0:P.name,A=s.getSql(O,s.fmt(t),s.fmt(n),H,w);A&&(j(A),f(!0))}function L(){return(h==null?void 0:h.find(m=>m.connectionId===l&&(m.tableName===u||m.datamodelName===I)))!==void 0}function q(m){m===!0&&(u||I)&&l?(g({connectionId:l,connectionType:w==="S3"||w==="API"?"DuckDb":w,databaseName:c||"",schemaName:d||"",tableName:u||"",datamodelName:s.resolveDatamodelName(I),datamodelId:x||""}),s.ue.success("Added to Assistant Scope",{position:"top-right",duration:2500,richColors:!0})):(y({connectionId:l||"",connectionType:w||"",tableName:u||"",datamodelName:s.resolveDatamodelName(I),datamodelId:x||"",databaseName:c||"",schemaName:d||""}),s.ue("Removed from Assistant Scope",{position:"top-right",duration:2e3,richColors:!0}))}function V(){const m=s.getFormattedTableNameForQuery({schemaName:t,tableName:n,modelName:I,connectionType:w});S(!1);const O=w==="MSSQL"?`SELECT top 10 * FROM ${m}`:`SELECT * FROM ${m} LIMIT 10`;j(O),f(!0)}function B(){const m=s.getFormattedTableNameForQuery({schemaName:t,tableName:n,modelName:I,connectionType:w});j(`SELECT COUNT(*) as count FROM ${m}`),f(!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:`${L()?"Remove from":"Add to"} Assistant Scope`,pressed:L(),onPressedChange:q,variant:"outline",className:s.cn("h-9 px-2",{}),children:[e.jsx(s.Plus,{className:s.cn("mr-1 size-4",{"text-green-400":L(),"text-muted-foreground":!L()})}),"AI"]}),e.jsxs(s.Button,{disabled:r!=="Success",onClick:V,size:"sm",variant:"secondary",className:"flex",children:[r!=="Success"?e.jsx(he,{className:"mr-2 h-4 w-4 animate-spin text-foreground/50"}):e.jsx(qs,{className:"mr-2 size-4"}),"Top 10"]}),e.jsxs(s.Button,{disabled:r!=="Success",onClick:B,size:"sm",variant:"secondary",className:"w-full",children:[r!=="Success"?e.jsx(he,{className:"mr-2 h-4 w-4 animate-spin text-foreground/50"}):e.jsx(Us,{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:()=>M(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(Xe,{column:m}),e.jsx("span",{children:m.column_name})]}),e.jsx("div",{onClick:O=>O.stopPropagation(),className:"flex items-center justify-end",children:s.isNumberDataType(m.data_type)&&e.jsx(rt,{column:m})})]},m.column_name))}),e.jsx(s.ScrollBar,{orientation:"vertical"}),e.jsx(s.ScrollBar,{orientation:"horizontal"})]})]})}function ne(t,n){var ke,Ee,Ie,De,Te,Le;let a=C.useMemo(()=>[],[]);const r=s.useSemaphorContext().authToken||t,o=s.useEditorStore(N=>N.selectedConnectionId),l=s.useEditorStore(N=>N.selectedDatamodelId),c=s.useEditorStore(N=>N.selectedDatabaseName),d=s.useEditorStore(N=>N.selectedSchemaName),u=s.useEditorStore(N=>N.selectedTableName),x=s.useEditorStore(N=>N.actions.setCurrentColumns),h=s.useEditorStore(N=>N.actions.setSelectedConnectionId),g=s.useEditorStore(N=>N.actions.setSelectedDatamodelId),y=s.useEditorStore(N=>N.actions.setSelectedDatabaseName),i=s.useEditorStore(N=>N.actions.setSelectedSchemaName),f=s.useEditorStore(N=>N.actions.setSelectedTableName);s.useEditorStore(N=>N.actions.setCardSql);function p(N){return o&&c&&d&&c!=="NA"?!0:o&&N==="API"?!1:!!(o&&N==="S3")}function S(N){return!!(o&&c&&c!=="NA"&&d&&u||o&&(N==="S3"||N==="API")||l&&l)}function j(N){return o&&N?!(N==="API"||N==="S3"):!1}const{refetch:w,data:v,isLoading:I,isError:M}=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:L,data:q,isLoading:V,isError:B}=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=v==null?void 0:v.connections.find(N=>N.id===o),O=m==null?void 0:m.type,H=(m==null?void 0:m.type)==="API"||(m==null?void 0:m.type)==="S3",{data:A,isLoading:P,isFetching:G,isError:R,refetch:b}=s.useQuery({queryKey:["databases",o],queryFn:()=>s.getRequest("https://semaphor.cloud/api/v1/databases",(r==null?void 0:r.accessToken)||"",{connection_id:o}),enabled:j(O)}),{data:E,isLoading:F,isFetching:$,isError:U,refetch:z}=s.useQuery({queryKey:["schemas",o,c],queryFn:()=>s.getRequest("https://semaphor.cloud/api/v1/schemas",(r==null?void 0:r.accessToken)||"",{connection_id:o,database_name:c}),enabled:!!o&&!!c&&!H&&c!=="NA"}),{data:T,isLoading:Y,isFetching:k,isError:_,refetch:J}=s.useQuery({queryKey:["tables",o,c,d],queryFn:()=>s.getRequest("https://semaphor.cloud/api/v1/tables",(r==null?void 0:r.accessToken)||"",{connection_id:o,database_name:c,schema_name:d}),enabled:p(O)}),{data:K,isLoading:ae,isFetching:se,isError:Q,refetch:X}=s.useQuery({queryKey:["columns",o,c,l,d,u],queryFn:()=>s.getRequest("https://semaphor.cloud/api/v1/columns",(r==null?void 0:r.accessToken)||"",{connection_id:o,datamodel_id:l||"",database_name:c,schema_name:d,table_name:u}),enabled:S(O)});C.useEffect(()=>{x(a)},[K,x,a]),C.useEffect(()=>{(O==="S3"||O==="API")&&(y(""),i(""),g(""),O==="API"&&f("api"))},[O,f,y,i,g]);const D=(m==null?void 0:m.type)==="API"?(ke=m==null?void 0:m.type)==null?void 0:ke.toLowerCase():u||"",W=H?"":d||"";function Z(N){i(N),f("")}function ee(N){y(N==="none"?"":N),i(""),f(""),N!=="none"&&N!==""&&g("")}function de(N){h(N)}function be(N){g(N==="none"?"":N),N!=="none"&&N!==""&&y("")}A&&((Ee=A==null?void 0:A.databases)==null?void 0:Ee.length)>0,E&&((Ie=E==null?void 0:E.schemas)==null?void 0:Ie.length)>0,K&&((De=K==null?void 0:K.columns)==null?void 0:De.length)>0&&(a=K.columns.map(N=>({...N,data_type:N.data_type.toLowerCase()}))),R&&(a=[]),(Q||M)&&(a=[]);const me=v==null?void 0:v.connections.map(N=>({id:N.id,name:N.name,type:N.type})),ye=(Te=q==null?void 0:q.datamodels)==null?void 0:Te.map(N=>({id:N.id,name:N.name})),ms=A==null?void 0:A.databases.map(N=>({id:N.database_name,name:N.database_name})),xs=E==null?void 0:E.schemas.map(N=>({id:N.schema_name,name:N.schema_name})),ps=T==null?void 0:T.tables.map(N=>({id:N.table_name,name:N.table_name})),fs=(Le=q==null?void 0:q.datamodels.find(N=>N.id===l))==null?void 0:Le.name;return{connectionItems:me,isConnectionsLoading:I,isConnectionsError:M,modelItems:ye,selectedDatamodelId:l,selectedDatamodelName:fs,isModelsLoading:V,isModelsError:B,databaseItems:ms,isDatabasesLoadingOrFetching:P||G,isDatabaseError:R,schemaItems:xs,isSchemaLoadingOrFetching:F||$,isSchemaError:U,tableItems:ps,isTableLoadingOrFetching:Y||k,isTableError:_,columns:a,isColumnsLoadingOrFetching:ae||se,isColumnsError:Q,isNonDbConnection:H,connectionType:O,tableName:D,schemaName:W,refetchConnections:w,refetchModels:L,refetchDatabases:b,refetchSchemas:z,refetchTables:J,refetchColumns:X,handleConnectionChange:de,handleDatamodelChange:be,handleDatabaseChange:ee,handleSchemaChange:Z}}function Ye({ColumnsComponent:t}){var se;const n=s.useEditorStore(Q=>Q.selectedConnectionId),a=s.useEditorStore(Q=>Q.selectedDatamodelId),r=s.useEditorStore(Q=>Q.selectedDatabaseName),o=s.useEditorStore(Q=>Q.selectedSchemaName),l=s.useEditorStore(Q=>Q.selectedTableName),c=s.useEditorStore(Q=>Q.actions.setSelectedTableName),{connectionItems:d,modelItems:u,schemaItems:x,databaseItems:h,tableItems:g,columns:y,isConnectionsLoading:i,isModelsLoading:f,isConnectionsError:p,isModelsError:S,isDatabasesLoadingOrFetching:j,isDatabaseError:w,isSchemaLoadingOrFetching:v,isSchemaError:I,isColumnsError:M,isColumnsLoadingOrFetching:L,isTableLoadingOrFetching:q,isTableError:V,connectionType:B,isNonDbConnection:m,refetchDatabases:O,refetchModels:H,refetchSchemas:A,refetchTables:P,refetchColumns:G,refetchConnections:R,handleConnectionChange:b,handleDatabaseChange:E,handleSchemaChange:F,handleDatamodelChange:$,tableName:U,schemaName:z}=ne();function T(){return t?t(z,U,y):e.jsx(ot,{schemaName:z,tableName:U,columns:y,status:L?"Loading...":M?"Error":"Success"})}function Y(){window.location.href="mailto:support@semaphor.cloud?subject=Help&body=I need help with..."}function k(){if(!n||B==="S3"||B==="API")return null;if(!a||a==="none")return e.jsx(oe,{refetch:O,showNone:!0,onChange:E,isError:w,isLoading:j,items:h,value:r||"",title:"Database",type:"combobox"})}function _(){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 J(){if(!n||B==="S3"||B==="API")return null;if(!r||r==="none")return e.jsx(oe,{refetch:H,showNone:!0,onChange:$,isError:S,isLoading:f,items:u,value:a||"",title:"Model",type:"combobox"})}function K(){return!n||B==="S3"||B==="API"||!r||r==="none"?null:e.jsx(oe,{refetch:A,onChange:F,isError:I,isLoading:v,items:x,value:o||"",title:"Schema",type:"combobox"})}function ae(){function Q(){let X=!1;return B==="API"?(X=!1,X):((B==="S3"||n&&r&&r!=="none"&&o)&&(X=!0),X)}return Q()?e.jsx(oe,{refetch:P,onChange:c,isError:V,items:g,isLoading:q,value:l||"",title:"Table",type:"combobox"}):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(oe,{refetch:R,items:d,title:"Connection",value:n||"",onChange:b,isLoading:i,isError:p,type:"combobox",connectionTooltip:((se=d==null?void 0:d.find(Q=>Q.id===n))==null?void 0:se.type)||""}),k(),_(),J(),K(),ae()]}),T(),e.jsx("div",{className:"flex items-end justify-center gap-2 px-6 py-4",children:e.jsxs(s.Button,{onClick:Y,size:"sm",variant:"secondary",className:"w-full",children:[e.jsx(Bs,{className:"mr-2 size-4"}),"Help"]})})]})}function it(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 l=t.length;if(o!==-1&&(l=o),r!==-1&&r<l&&(l=r),n!==-1){const c=t.substring(0,n),d=t.substring(n);return`${c} {{ filters | where }} AND ${d.substring(6)}`}else if(a!==-1){const c=t.substring(0,a),d=t.substring(a);return`${c} {{ filters | where }} ${d}`}else{const c=t.substring(0,l),d=t.substring(l);return console.log("beforeClause",c),console.log("afterClause",d),d?`${c} {{ filters | where }} ${d}`:`${c.replace(/;$/,"")} {{ filters | where }}`}}function lt({sql:t,error:n,onClick:a}){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(vs,{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,size:"sm",variant:"secondary",children:[e.jsx(As,{className:"mr-2 h-4 w-4"}),"Debug with Assistant"]})]})})})]})}function ct(){const[t,n]=C.useState([]),[a,r]=C.useState(""),[o,l]=C.useState(null),{authToken:c}=s.useSemaphorContext(),d=s.useEditorStore(k=>{var _;return(_=k==null?void 0:k.card)==null?void 0:_.sql}),u=s.useEditorStore(k=>{var _;return(_=k==null?void 0:k.card)==null?void 0:_.python}),x=s.useEditorStore(k=>k.actions.setCardSql),h=s.useEditorStore(k=>k.actions.setRunSql),g=s.useEditorStore(k=>k.actions.switchCardType),y=s.useEditorStore(k=>k.userInputForAI),i=s.useEditorStore(k=>k.triggerAIRun),f=s.useEditorStore(k=>k.selectedDatabaseName),p=s.useEditorStore(k=>k.selectedTableName),S=s.useEditorStore(k=>k.selectedConnectionId),j=s.useEditorStore(k=>k.selectedSchemaName),w=s.useDashboardStore(k=>k.dashboard.aiScopeTables),{setTriggerAIRun:v}=s.useEditorActions(),{selectedDatamodelName:I,connectionType:M,selectedDatamodelId:L}=ne(),{messages:q,setMessages:V,reload:B,append:m,input:O,setInput:H,status:A,handleInputChange:P,handleSubmit:G,stop:R}=s.useChat({api:"https://semaphor.cloud/api/v1/assistant",headers:{Authorization:`Bearer ${c==null?void 0:c.accessToken}`},body:{random:Math.random()},maxSteps:10,onToolCall:b,onFinish(k,_){E(_.usage),r(""),console.log("onFinish",k,_),_.finishReason==="stop"&&r("")}});C.useEffect(()=>{i&&y&&(P({target:{value:y}}),setTimeout(()=>{G(),v(!1)},100))},[i,G,y,v,P]);async function b({toolCall:k}){if(k.toolName==="createChart"){console.log("createChart",k.args);const _=k.args.sql,J=k.args.chartType;return g(J),x(_),h(!0),{status:"success",message:"Let the user know that chart is created"}}else if(k.toolName==="getTableColumns")r("Getting table columns...");else{if(k.toolName==="getUserSql")return d?{status:"success",sql:d,python:u||""}:{status:"error",message:"No SQL found"};if(k.toolName==="getCurrentTableScope")return r("Getting table scope..."),T(),{status:"success",tables:t};r("Analyzing...")}}function E(k){l(_=>_?{promptTokens:_.promptTokens+k.promptTokens,completionTokens:_.completionTokens+k.completionTokens,totalTokens:_.totalTokens+k.totalTokens}:k)}function F(k){const _=s.removeFromScopeArray(t,k);U(_)}function $(k){return k.map(J=>({...J,connectionType:J.connectionType==="API"||J.connectionType==="S3"?"DuckDb":J.connectionType}))}function U(k){const _=$(k);n(_),V(J=>[...J,{id:crypto.randomUUID(),role:"system",content:`Current scope of tables | ${JSON.stringify(_)}`}])}function z(){const k={databaseName:f||"",schemaName:j||"",tableName:p||"",datamodelId:L||"",datamodelName:s.resolveDatamodelName(I),connectionId:S||"",connectionType:M||""},_=s.dedup([...t,k]);U(_)}function T(){const k={databaseName:f||"",schemaName:j||"",tableName:p||"",datamodelName:s.resolveDatamodelName(I),connectionId:S||"",connectionType:M||"",datamodelId:L||""};if(!s.isInAiScopeArray([...w||[],...t],k)||t.length===0){const J=s.dedup([...w||[],...t,k]).filter(K=>K.connectionId===k.connectionId);U(J)}}const Y=!["ready","error"].includes(A);return{messages:q,setMessages:V,reload:B,append:m,input:O,setInput:H,isLoading:Y,handleSetAIScope:T,handleAddCurrentTableToScope:z,removeFromCurrentSelections:F,currentScope:t,setCurrentScope:n,handleInputChange:P,handleSubmit:G,stop:R,chatStatus:A,toolStatus:a,llmUsage:o}}const dt=!1;function ut(){const t=s.useEditorStore(b=>b.showAIDialog),n=C.useRef(t),a=C.useRef(null),r=C.useRef(null),[o,l]=C.useState(!1),[c,d]=C.useState(dt),[u,x]=C.useState(!1),h=s.useEditorStore(b=>b.actions.setCardSql),g=s.useEditorStore(b=>b.actions.setRunSql),{setShowAIDialog:y}=s.useEditorActions(),{messages:i,setMessages:f,reload:p,input:S,setInput:j,isLoading:w,handleSetAIScope:v,handleAddCurrentTableToScope:I,removeFromCurrentSelections:M,currentScope:L,setCurrentScope:q,handleInputChange:V,handleSubmit:B,stop:m,chatStatus:O,toolStatus:H,llmUsage:A}=ct();C.useEffect(()=>{const b=n.current?"smooth":"auto";n.current=t;const E=setTimeout(()=>{var F;a.current&&(a.current.scroll({top:a.current.scrollHeight,behavior:b}),(F=r.current)==null||F.focus())},50);return()=>clearTimeout(E)},[i,t]);function P(b){y(!1),h(b),g(!0)}function G(){return e.jsxs(s.DropdownMenu,{children:[e.jsx(s.DropdownMenuTrigger,{children:e.jsx(s.Button,{className:"h-7 p-2",size:"sm",variant:"ghost",children:e.jsx(_e,{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:o,onCheckedChange:l,children:"Token Usage"}),e.jsx(s.DropdownMenuCheckboxItem,{checked:c,onCheckedChange:d,children:"Tool Invocations"}),e.jsx(s.DropdownMenuCheckboxItem,{checked:u,onCheckedChange:x,children:"System Message"})]})]})}const R=(S==null?void 0:S.length)===0&&(i==null?void 0:i.filter(b=>b.role==="user").length)===0;return e.jsxs(s.Dialog,{open:t,onOpenChange:y,children:[e.jsx(s.DialogTrigger,{asChild:!0,children:e.jsx(s.Button,{onClick:v,size:"sm",className:"w-full cursor-text justify-start font-normal text-muted-foreground focus-visible:ring-0 focus-visible:ring-offset-0",variant:"ghost",children:"Type your question..."})}),e.jsxs(s.DialogContent,{className:"flex flex-col justify-between overflow-auto sm:max-w-[425px] md:max-h-[700px] md:min-w-[625px] [&>button]:hidden",children:[e.jsx(s.DialogHeader,{children:e.jsxs("div",{className:"flex items-start justify-between gap-2",children:[e.jsxs("div",{children:[e.jsx(s.DialogTitle,{children:"Assistant"}),L&&L.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:"Context:"}),L==null?void 0:L.map((b,E)=>e.jsxs("div",{className:"flex items-center gap-2 rounded-md border border-border bg-muted px-2 py-1 text-xs",children:[s.getFormattedTableNameForQuery({schemaName:b.schemaName||"",tableName:b.tableName||"",modelName:b.datamodelName||"",connectionType:b.connectionType||""}),e.jsx("button",{onClick:()=>{M(b)},children:e.jsx(s.X,{className:"size-3 text-muted-foreground hover:text-foreground"})})]},E))]}),(L==null?void 0:L.length)===0&&e.jsxs("div",{className:"mt-2 flex items-center gap-2",children:[e.jsx("span",{className:"text-xs text-muted-foreground",children:"Context: None"}),e.jsxs(s.Button,{className:"h-6 text-xs",size:"sm",variant:"secondary",onClick:I,children:[e.jsx(s.Plus,{className:"mr-2 size-3"}),"Current Table"]})]})]}),e.jsxs("div",{className:"flex items-center",children:[G(),e.jsx(s.Button,{className:"h-7 p-2",size:"sm",variant:"ghost",onClick:()=>{f([]),q([]),p()},children:e.jsx(s.RefreshCcw,{className:"size-3.5 text-muted-foreground"})})]})]})}),e.jsx("div",{ref:a,className:"h-[700px] w-full overflow-auto",children:e.jsxs("div",{className:"space-y-4 py-2 pr-3",role:"messages",children:[e.jsx(s.PrintMessages,{messages:i,showTools:c,handleRun:P,showSystemMessage:u}),e.jsx(s.ChatStatus,{status:s.getStatus(O,H),isLoading:w})]})}),R&&e.jsx(s.Placeholders,{}),e.jsx(s.ChatInput,{stop:m,ref:r,setInput:j,input:S,handleInputChange:V,handleSubmit:B,isLoading:w}),A&&o&&e.jsx("div",{className:"flex h-8 items-center justify-between",children:e.jsxs("div",{className:"text-xs text-muted-foreground",children:["Usage: ",A.promptTokens," prompt tokens,"," ",A.completionTokens," completion tokens,"," ",A.totalTokens," total tokens"]})})]})]})}var Ze={color:void 0,size:void 0,className:void 0,style:void 0,attr:void 0},Ae=C.createContext&&C.createContext(Ze),ht=["attr","size","title"];function mt(t,n){if(t==null)return{};var a=xt(t,n),r,o;if(Object.getOwnPropertySymbols){var l=Object.getOwnPropertySymbols(t);for(o=0;o<l.length;o++)r=l[o],!(n.indexOf(r)>=0)&&Object.prototype.propertyIsEnumerable.call(t,r)&&(a[r]=t[r])}return a}function xt(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 fe(){return fe=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},fe.apply(this,arguments)}function Oe(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 ge(t){for(var n=1;n<arguments.length;n++){var a=arguments[n]!=null?arguments[n]:{};n%2?Oe(Object(a),!0).forEach(function(r){pt(t,r,a[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(a)):Oe(Object(a)).forEach(function(r){Object.defineProperty(t,r,Object.getOwnPropertyDescriptor(a,r))})}return t}function pt(t,n,a){return n=ft(n),n in t?Object.defineProperty(t,n,{value:a,enumerable:!0,configurable:!0,writable:!0}):t[n]=a,t}function ft(t){var n=gt(t,"string");return typeof n=="symbol"?n:n+""}function gt(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 es(t){return t&&t.map((n,a)=>C.createElement(n.tag,ge({key:a},n.attr),es(n.child)))}function le(t){return n=>C.createElement(jt,fe({attr:ge({},t.attr)},n),es(t.child))}function jt(t){var n=a=>{var{attr:r,size:o,title:l}=t,c=mt(t,ht),d=o||a.size||"1em",u;return a.className&&(u=a.className),t.className&&(u=(u?u+" ":"")+t.className),C.createElement("svg",fe({stroke:"currentColor",fill:"currentColor",strokeWidth:"0"},a.attr,r,c,{className:u,style:ge(ge({color:t.color||a.color},a.style),t.style),height:d,width:d,xmlns:"http://www.w3.org/2000/svg"}),l&&C.createElement("title",null,l),t.children)};return Ae!==void 0?C.createElement(Ae.Consumer,null,a=>n(a)):n(Ze)}function bt(t){return le({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 ss(t){const{theme:n}=s.useTheme(),a=s.useDashboardStore(p=>p.theme),r=s.useEditorStore(p=>p.frame),o=s.useEditorStore(p=>p.card),l=s.useEditorStore(p=>p.activeTabCardId),c=s.Le(),{refetch:d}=s.useDashboardCardQuery(o),{updateCardTab:u,setRunSql:x}=s.useEditorActions(),h=C.useRef(),g=C.useRef({}),y=r.cards.find(p=>p.id===l),i=C.useCallback(()=>{let p="";return t==="python"&&(p=(y==null?void 0:y.python)||s.PYTHON_DEFAULT_CODE),t==="sql"&&(p=(y==null?void 0:y.sql)||""),p},[t,y]);C.useEffect(()=>{if(l&&o.id&&o.id!==l){if(h.current&&c){const p=h.current.getModel();p&&(g.current[o.id]=p);let S=g.current[l];if(!S){const j=i();S=c.editor.createModel(j,t),g.current[l]=S}h.current.setModel(S)}u(l,o),x(!0)}},[l,o,u,c,x,t,i]),C.useEffect(()=>{if(!c)return;const p=window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light",S=a==="system"?p:a;c.editor.defineTheme("default",{base:S==="light"?"vs":"vs-dark",inherit:!0,rules:[],colors:{"editor.background":S==="light"?"#ffffff":s.hslStringToHex("240 10% 10%")}}),c.editor.setTheme("default")},[n,a,c]),C.useEffect(()=>{const p=h.current;p&&c&&o&&p.addCommand(c.KeyMod.Shift|c.KeyCode.Enter,function(){return d(),!1})},[c,d,o]);function f(p,S){if(h.current=p,!g.current[o.id]){const j=p.getModel(),w=i();g.current[o.id]=j||(S==null?void 0:S.editor.createModel(w,t))||p.getModel()}p.setModel(g.current[o.id])}return{handleEditorDidMount:f}}function yt(){const t=s.useEditorStore(c=>c.card.sql),n=s.useEditorStore(c=>c.sqlGen),{setCardSql:a,setSqlGen:r}=s.useEditorActions(),{handleEditorDidMount:o}=ss("sql");function l(c){a(c),s.isObjectEmpty(n)||r({})}return e.jsx(s.Ft,{theme:"default",className:"pt-3",onChange:l,value:t||"",options:{minimap:{enabled:!1},wordWrap:"on",scrollbar:{verticalScrollbarSize:0,horizontalScrollbarSize:0},fontSize:13,renderLineHighlight:"none"},defaultLanguage:"sql",onMount:o})}function St(){const t=s.useEditorStore(o=>o.card.python),{setCardPython:n}=s.useEditorActions(),{handleEditorDidMount:a}=ss("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 Ct({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 vt(){var X;const[t,n]=C.useState({queryKey:[],queryData:null}),a=s.useQueryClient(),[r,o]=C.useState(!1),[l,c]=C.useState(!1),d=s.useEditorStore(D=>D.frame),u=s.useEditorStore(D=>D.card),x=s.useEditorStore(D=>D.isShowingVisual),h=s.useEditorStore(D=>D.selectedConnectionId),g=s.useEditorStore(D=>D.selectedDatabaseName),y=s.useEditorStore(D=>D.selectedDatamodelId),i=s.useEditorStore(D=>D.selectedSchemaName),f=s.useEditorStore(D=>D.selectedTableName),p=s.useEditorStore(D=>{var W;return(W=D==null?void 0:D.card)==null?void 0:W.sql}),{sheetFilterValues:S}=s.useSheetFilterValues(),{setCardCustomCfg:j,setQueryResultColumns:w,setCardSql:v,setPythonStdOut:I,setCardPreferences:M,setCardType:L,setCardPython:q,runAssistant:V}=s.useEditorActions(),B=s.useEditorStore(D=>D.onSave),m=s.useEditorStore(D=>D.onClose),O=s.useEditorStore(D=>D.actions.setSqlGen),H=s.useEditorStore(D=>D.runSql),A=s.useEditorStore(D=>D.actions.setRunSql),P=s.useEditorStore(D=>D.actions.setCardCfg),G=s.useEditorStore(D=>D.actions.setIsSqlRunning),{data:R,isLoading:b,isFetching:E,isSuccess:F,isError:$,error:U,queryKey:z,refetch:T}=s.useDashboardCardQuery(u);C.useEffect(()=>{if(R&&(R.rowLimitExceeded&&s.ue.error("Row limit (10,000) exceeded. Refine your query.",{position:"top-center",richColors:!0}),I((R==null?void 0:R.output)||""),R.records.length>0)){const{dimensionKeys:D}=s.getKeys(R.records);w(D)}},[R,w,I]),C.useEffect(()=>{(b||E)&&G(!0),($||F)&&G(!1),$&&(w([]),I(""))},[b,E,R,I,$,F,G,w,U]),C.useEffect(()=>{H&&(a.getQueryData(z)||T(),A(!1))},[H,T,A,z,a]);function Y(){const D=a.getQueryData(z);t.queryData||n({queryKey:z,queryData:D}),a.setQueryData(z,null),a.removeQueries({queryKey:z,exact:!0}),v(""),O({}),q(""),P(void 0),j(""),M({}),L("bar")}function k(D,W){if(D.length===0)return"";if(W){const Z=D.find(ee=>ee.id===W);if(Z){const ee=Z.tabTitle;if(ee=="All__Header")return D[0].id;if(ee&&ee.endsWith("__Header")){const be=ee.split("__")[0],me=D.find(ye=>ye.tabTitle===be);return me?me.id:D[0].id}return W}}return D[0].id}function _(){let D=p;p&&!p.includes("{{")&&(D=it(p),v(D));const W={...u,lastSelectedSchema:i,lastSelectedDatamodelId:y,lastSelectedDatabase:g,lastSelectedTable:f,connectionId:h,type:x?u.type:"table",sql:D,customCfg:x?u.customCfg:null},Z=d.cards.map(de=>de.id===u.id?W:de),ee={...d,cards:Z,activeCardId:k(Z,d.activeCardId)};B==null||B(ee)}function J(){const{queryKey:D,queryData:W}=t;D&&W&&a.setQueryData(D,W),O({}),m==null||m()}async function K(){const D=`Can you help me debug this query in the current table scope?
242
242
 
243
243
  Error:
244
244
 
@@ -248,5 +248,5 @@
248
248
 
249
249
  ${p}
250
250
 
251
- `;V(D)}function ae(){return e.jsxs(e.Fragment,{children:[l&&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(Ct,{jsonString:JSON.stringify(S,null,2)})})}),S&&S.length>0&&e.jsx(s.Button,{variant:"ghost",onClick:()=>c(!l),className:"absolute bottom-0 right-6 size-7 p-1",children:l?e.jsx(s.X,{className:"size-3.5 text-muted-foreground"}):e.jsx(s.Filter,{className:"size-3.5 text-muted-foreground"})})]})}function se(){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(yt,{})}),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(St,{})}),e.jsx("code",{className:"absolute right-6 top-3 text-xs text-muted-foreground/70",children:"python"})]})]})]})}const Q=(U==null?void 0:U.message)||((X=M==null?void 0:M.error)==null?void 0:X.message);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:[se(),ae()]}),e.jsxs("div",{role:"editor-controls",className:"item-center flex flex-wrap justify-between gap-2 px-6 py-4",children:[e.jsxs("div",{className:"flex grow items-center gap-2",children:[e.jsxs(s.Button,{title:"Shift + Enter",disabled:y||E,onClick:()=>{T()},className:"shrink-0",size:"sm",children:[y||E?e.jsx(he,{className:"mr-2 h-4 w-4 animate-spin"}):e.jsx(s.Play,{className:"mr-2 h-4 w-4"}),"Run"]}),e.jsx(lt,{sql:M==null?void 0:M.sql,error:Q,onClick:K}),e.jsxs(s.Button,{onClick:Y,className:"",size:"sm",variant:"secondary",children:[e.jsx(Es,{className:"mr-2 size-4"}),"Clear"]}),e.jsx(s.Toggle,{pressed:r,onPressedChange:D=>o(D),className:"",size:"sm",children:e.jsx(bt,{className:"size-4 text-foreground/70"})}),e.jsx(ut,{})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(s.Button,{onClick:J,className:"w-full",size:"sm",variant:"secondary",children:[e.jsx(s.Cross2Icon,{className:"mr-2 size-4"}),"Close"]}),e.jsxs(s.Button,{onClick:P,size:"sm",variant:"secondary",children:[e.jsx(s.Check,{className:"mr-2 size-4 font-bold text-green-600"}),"Accept"]})]})]})]})}function Nt({data:t}){var c;const[n,a]=C.useState([]),o=Object.keys(t[0]).map(d=>({accessorKey:d,header:({column:u})=>{const x=u.getIsSorted();return e.jsx("div",{className:"flex gap-2",children:e.jsxs("div",{className:"flex cursor-pointer items-center",onClick:()=>u.toggleSorting(u.getIsSorted()==="asc"),children:[d,x==="asc"?e.jsx(s.TriangleUpIcon,{className:"ml-2 h-5 w-5"}):x==="desc"?e.jsx(s.TriangleDownIcon,{className:"ml-2 h-5 w-5"}):null]})})}})),l=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:l.getHeaderGroups().map(d=>e.jsx(s.TableRow,{children:d.headers.map(u=>e.jsx(s.TableHead,{className:"sticky top-0 h-11 bg-muted font-semibold",children:u.isPlaceholder?null:s.flexRender(u.column.columnDef.header,u.getContext())},u.id))},d.id))}),e.jsx(s.TableBody,{children:(c=l.getRowModel().rows)!=null&&c.length?l.getRowModel().rows.map(d=>e.jsx(s.TableRow,{className:"whitespace-nowrap py-2","data-state":d.getIsSelected()&&"selected",children:d.getVisibleCells().map(u=>e.jsx(s.TableCell,{className:"py-3",children:s.flexRender(u.column.columnDef.cell,u.getContext())},u.id))},d.id)):e.jsx(s.TableRow,{children:e.jsx(s.TableCell,{colSpan:o.length,className:"h-24 text-center",children:"No results."})})})]})})}function wt({card:t}){var w,v,I,z,L,q,V,B,m,O,H;const[n,a]=C.useState(!1),[r,o]=C.useState([]),{authToken:l}=s.useSemaphorContext(),c=s.getTokenParams(l==null?void 0:l.accessToken),d=s.useDashboardStore(A=>A.themeStyle),u={colors:((v=(w=d==null?void 0:d.chart)==null?void 0:w.dataset)==null?void 0:v.backgroundColor)||[]};(I=t.customCardPreferences)!=null&&I.inputData;const{getCard:x}=s.useCustomVisual(((z=t.customCardPreferences)==null?void 0:z.url)||""),h=((L=t.customCardPreferences)==null?void 0:L.visualType)||"single",g=s.useEditorStore(A=>A.frame),{setCustomCardPreferences:b}=s.useEditorActions(),{data:i}=s.useDashboardCardQuery(t),f=C.useCallback((A,_)=>{o(G=>({...G,[A]:_}))},[]);if(!((q=t.customCardPreferences)!=null&&q.componentName))return null;const p=x((V=t.customCardPreferences)==null?void 0:V.componentName);function S(A){a(A)}const j=Object.keys(((B=t.customCardPreferences)==null?void 0:B.dataInputCardIds)||{}).map(A=>{var M,y,E;const _=(y=(M=t.customCardPreferences)==null?void 0:M.dataInputCardIds)==null?void 0:y[A].cardId,G=(E=g==null?void 0:g.cards)==null?void 0:E.find(R=>R.id===_);return G||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(C.Suspense,{fallback:e.jsx(e.Fragment,{}),children:[p&&h==="single"&&e.jsx(p,{params:c,theme:u,settings:(m=t.customCardPreferences)==null?void 0:m.settings,onDataChange:f,data:(i==null?void 0:i.records)||[]}),p&&h==="multiple"&&e.jsxs(e.Fragment,{children:[Object.keys(((O=t.customCardPreferences)==null?void 0:O.dataInputCardIds)||{}).map(A=>{var M,y,E;const _=(y=(M=t.customCardPreferences)==null?void 0:M.dataInputCardIds)==null?void 0:y[A].cardId,G=(E=g==null?void 0:g.cards)==null?void 0:E.find(R=>R.id===_);if(G)return e.jsx(s.MultiInputEmptyRenderer,{onLoadingStatus:S,onDataChange:f,dataInputIndex:A,card:G},G.id+A)}),e.jsx("div",{className:"flex flex-col gap-2",children:e.jsx(p,{theme:u,onDataChange:f,settings:j.map(A=>{var _;return(_=A==null?void 0:A.customCardPreferences)==null?void 0:_.settings}),data:j.map(A=>A!=null&&A.id?r==null?void 0:r[A.id]:[])})})]})]},(H=t.customCardPreferences)==null?void 0:H.componentName)})}function ts({className:t,...n}){var S;const a=s.useEditorStore(j=>j.card),r=((S=a.customCardPreferences)==null?void 0:S.showCardHeader)??!0,o=s.useEditorStore(j=>j.frame),l=s.useDashboardStore(j=>j.dashboard.filters);s.useEditorStore(j=>j.actions.setRunSql);const{updateFilter:c}=s.useDashboardActions(),d=l==null?void 0:l.find(j=>j.id===o.filterId),{data:u,isLoading:x,isFetching:h}=s.useDashboardCardQuery(a),{setCard:g}=s.useEditorActions(),{data:b}=s.useTopoJson(a);if(!a.id)return null;let i;u!=null&&u.records&&(u==null?void 0:u.records.length)>0&&(i=s.createChartConfig({data:u==null?void 0:u.records,cardType:a.type,cfg:a.cfg,customCfg:a.customCfg,preferences:a.preferences,topoJson:b}));function f(j){return e.jsx(wt,{card:j})}function p(){var j;if(u!=null&&u.records&&(u==null?void 0:u.records.length)===0&&!x&&!h)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 f(a);if(!["table","custom"].includes(a.type)&&i)return e.jsx(s.ChartJsVisual,{cfg:i},JSON.stringify(i)+JSON.stringify(a.preferences)+((j=a==null?void 0:a.preferences)==null?void 0:j.customVisualCode));if(a.type==="table"&&(u!=null&&u.records)&&(u==null?void 0:u.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:u==null?void 0:u.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:j=>g({...a,title:j}),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:j=>g({...a,description:j}),children:e.jsx(s.CardDescription,{children:a.description||"Edit description..."})},a.description)]}),d&&e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(s.Editable,{className:"my-1",text:d.title||d.column,onSave:j=>c({...d,title:j}),children:e.jsx(s.Label,{children:d.title})}),e.jsx(s.FilterComponent,{filter:d})]})]}),e.jsx(s.CardContent,{className:"flex grow flex-col",children:p()})]})}const Me=({language:t,value:n,onChange:a,readonly:r})=>e.jsx(s.Ft,{className:"h-full w-full overflow-hidden text-xs",theme:"default",options:{minimap:{enabled:!1},wordWrap:"on",scrollbar:{verticalScrollbarSize:0,horizontalScrollbarSize:0},fontSize:12,lineHeight:16,renderLineHighlight:"none",readOnly:r},defaultLanguage:t,value:n,onChange:a}),kt=()=>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."})]})]}),Et=({customCode:t,customConfig:n,onConfigChange:a,onCodeChange:r})=>e.jsxs(s.Tabs,{defaultValue:"final-config",className:"flex w-1/2 flex-col",children:[e.jsxs(s.TabsList,{className:"justify-start rounded-sm rounded-b-none border border-b-0",children:[e.jsx(s.TabsTrigger,{value:"final-config",children:"Config"}),e.jsx(s.TabsTrigger,{value:"custom-code",children:"Custom Code"})]}),e.jsx(s.TabsContent,{value:"final-config",className:"mt-0 grow rounded-b border border-t-0",children:e.jsx(Me,{language:"json",value:n,onChange:a})}),e.jsx(s.TabsContent,{value:"custom-code",className:"mt-0 grow rounded-b border border-t-0",children:e.jsx(Me,{language:"javascript",value:t,onChange:r})})]}),It=({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 Dt(){const[t,n]=C.useState(!1),[a,r]=C.useState(""),[o,l]=C.useState(""),[c,d]=C.useState(""),[u,x]=C.useState(""),h=s.useEditorStore(v=>v.card),g=s.useEditorStore(v=>v.card.customCfg),{data:b}=s.useDashboardCardQuery(h),{data:i}=s.useTopoJson(h),{setCardCustomCfg:f,setCustomVisualCode:p}=s.useEditorActions(),S=v=>{var I,z;return JSON.stringify({...v,data:{...v.data,datasets:(z=(I=v.data)==null?void 0:I.datasets)==null?void 0:z.map(L=>({...L,data:[]}))}},null,2)},j=()=>{var I,z;if(!((I=b==null?void 0:b.records)!=null&&I.length))return;const v=s.createChartConfig({data:b.records,cardType:h.type,cfg:h.cfg,preferences:h.preferences,topoJson:i});if(v){r(S(v)),d(((z=h.preferences)==null?void 0:z.customVisualCode)||"");const L=s.merge(v,g);l(S(L))}},w=()=>{try{if(c&&p(c),o){const v=JSON.parse(o),I=s.getObjectDiff(JSON.parse(a),v);f(I),x("")}}catch{x("Invalid JSON configuration")}};return e.jsxs(s.Dialog,{open:t,onOpenChange:n,children:[e.jsx(s.DialogTrigger,{asChild:!0,children:e.jsx(s.IconButton,{tooltip:"Customize Visual",onClick:j,className:g?"text-green-600 hover:text-green-700":"",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(kt,{}),e.jsxs("div",{className:"flex grow gap-2",children:[e.jsx(s.ErrorBoundary,{FallbackComponent:s.FallbackEditorCard,children:e.jsx(ts,{className:"w-1/2 rounded shadow-none"})}),e.jsx(Et,{customCode:c,customConfig:o,onConfigChange:v=>l(v??""),onCodeChange:v=>d(v??"")})]}),e.jsx(It,{error:u,hasCustomConfig:!!g,onReset:()=>{l(a),f(null)},onApply:w,onClose:()=>n(!1)})]})]})}function as(t){return le({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 Tt(t){return le({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 ns(t){return le({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 rs(t){return le({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 os(t){return le({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 is(t){const[n,a]=C.useState(null);return n}function ls(){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 Lt({onChartTypeChange:t}){const[n,a]=C.useState([]),{data:r}=ls();return C.useEffect(()=>{(async()=>{var l;if(r){const d=(await Promise.all((l=r==null?void 0:r.plugins)==null?void 0:l.map(async u=>(await s.loadManifest(u.value)).visuals.map(g=>({name:g.name,icon:g.icon,url:u.value}))))).flat();a(d)}})()},[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,l)=>e.jsx(At,{text:o.name,onClick:()=>t("custom",o),icon:o.icon},o.url+o.name+l))})]})}const At=({text:t,icon:n,onClick:a})=>{const r=is(),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 Ot(){var h,g;const[t,n]=C.useState(!1),a=s.useEditorStore(b=>b.card),r=a.type,{setCardType:o,setCardPreferences:l,setChartOrientation:c}=s.useEditorStore(b=>b.actions),{setCardCustomCfg:d,setCustomCardPreferences:u}=s.useEditorActions();function x(b,i){d(null),l({}),o(b),i&&u({type:"component",visualType:"single",url:i.url,componentName:i.name,icon:i.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:"ghost",children:e.jsx(Mt,{className:"size-4",chartType:r,customIcon:(h=a.customCardPreferences)==null?void 0:h.icon,componentName:(g=a.customCardPreferences)==null?void 0:g.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:()=>x("bar"),className:"font-normal",variant:"ghost",children:e.jsx(Ce,{className:"size-5"})}),e.jsx(s.Button,{onClick:()=>x("line"),variant:"ghost",children:e.jsx(ve,{className:"size-5"})}),e.jsx(s.Button,{onClick:()=>x("stackedBar"),variant:"ghost",children:e.jsx(Ve,{className:"size-5"})}),e.jsx(s.Button,{onClick:()=>x("stackedLine"),variant:"ghost",children:e.jsx(rs,{className:"size-5",strokeWidth:0})}),e.jsx(s.Button,{onClick:()=>x("scatter"),variant:"ghost",children:e.jsx(Be,{className:"size-5"})}),e.jsx(s.Button,{onClick:()=>x("bubble"),variant:"ghost",children:e.jsx(ns,{className:"size-5"})}),e.jsx(s.Button,{onClick:()=>x("pie"),variant:"ghost",children:e.jsx(qe,{className:"size-5"})}),e.jsx(s.Button,{onClick:()=>x("doughnut"),variant:"ghost",children:e.jsx(_e,{className:"size-5"})}),e.jsx(s.Button,{onClick:()=>x("radar"),variant:"ghost",children:e.jsx(Ge,{className:"size-5"})}),e.jsx(s.Button,{onClick:()=>x("polarArea"),variant:"ghost",children:e.jsx(as,{className:"size-6"})}),e.jsx(s.Button,{onClick:()=>x("pyramid"),variant:"ghost",children:e.jsx(Qe,{className:"size-5"})}),e.jsx(s.Button,{onClick:()=>x("range"),variant:"ghost",children:e.jsx(Re,{className:"size-5"})}),e.jsx(s.Button,{onClick:()=>x("table"),variant:"ghost",children:e.jsx(s.Table2,{className:"size-5"})}),e.jsx(s.Button,{onClick:()=>x("kpi"),variant:"ghost",children:e.jsx(os,{className:"size-6"})}),e.jsx(s.Button,{onClick:()=>x("text"),variant:"ghost",children:e.jsx(bs,{className:"size-5"})}),e.jsx(s.Button,{onClick:()=>x("map"),variant:"ghost",children:e.jsx(He,{className:"size-5"})}),e.jsx(s.Button,{onClick:()=>x("custom"),variant:"ghost",children:e.jsx(Ue,{className:"size-5"})})]}),e.jsx(Lt,{onChartTypeChange:x})]})]})}function Mt({chartType:t,className:n,customIcon:a,componentName:r}){const o=is();switch(t){case"bar":return e.jsx(Ce,{className:n});case"line":return e.jsx(ve,{className:n});case"pie":return e.jsx(qe,{className:n});case"radar":return e.jsx(Ge,{className:n});case"scatter":return e.jsx(Be,{className:n});case"bubble":return e.jsx(ns,{className:n});case"doughnut":return e.jsx(_e,{className:n});case"stackedBar":return e.jsx(Ve,{className:n});case"stackedLine":return e.jsx(rs,{className:n});case"polarArea":return e.jsx(as,{className:n});case"pyramid":return e.jsx(Qe,{className:n});case"range":return e.jsx(Re,{className:n});case"kpi":return e.jsx(os,{className:n});case"text":return e.jsx(Je,{className:n});case"map":return e.jsx(He,{className:n});case"custom":return a&&o?e.jsx(o,{className:n}):r?r==null?void 0:r.charAt(0).toUpperCase():e.jsx(Ue,{className:n});default:return e.jsx(s.Table2,{className:n})}}function zt(){const t=s.useEditorStore(d=>{var u,x,h,g;return(g=(h=(x=(u=d.card.preferences)==null?void 0:u.chartOptions)==null?void 0:x.plugins)==null?void 0:h.legend)==null?void 0:g.position}),n=s.useEditorStore(d=>{var u,x,h,g;return(g=(h=(x=(u=d.card.preferences)==null?void 0:u.chartOptions)==null?void 0:x.plugins)==null?void 0:h.legend)==null?void 0:g.align}),a=s.useEditorStore(d=>{var u,x,h,g;return(g=(h=(x=(u=d.card.preferences)==null?void 0:u.chartOptions)==null?void 0:x.plugins)==null?void 0:h.legend)==null?void 0:g.display}),{setLegendOptions:r}=s.useEditorActions(),o=d=>{r({display:d,position:t,align:n})},l=d=>{r({display:a,position:d,align:n})},c=d=>{r({display:a,position:t,align:d})};return e.jsxs(s.Popover,{children:[e.jsx(s.PopoverTrigger,{asChild:!0,children:e.jsx(s.IconButton,{tooltip:"Legend Settings",children:e.jsx(zs,{className:"size-4"})})}),e.jsx(s.PopoverContent,{className:"w-80",children:e.jsxs("div",{className:"grid gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("h4",{className:"font-medium leading-none",children:"Legend Options"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Set the legend options for the chart."})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsxs("div",{className:"grid grid-cols-3 items-center gap-4",children:[e.jsx(s.Label,{htmlFor:"displayLegend",children:"Display"}),e.jsx("div",{className:"col-span-2 flex h-8 items-center",children:e.jsx(s.SmallSwitch,{checked:a,onCheckedChange:o,defaultChecked:!0,id:"displayLegend"})})]}),e.jsxs("div",{className:"grid grid-cols-3 items-center gap-4",children:[e.jsx(s.Label,{htmlFor:"position",children:"Position"}),e.jsxs(s.Select,{value:t,onValueChange:l,children:[e.jsx(s.SelectTrigger,{className:"col-span-2 h-8 focus:ring-1 focus:ring-offset-0",children:e.jsx(s.SelectValue,{placeholder:"Select position"})}),e.jsxs(s.SelectContent,{children:[e.jsx(s.SelectItem,{value:"top",children:"Top"}),e.jsx(s.SelectItem,{value:"left",children:"Left"}),e.jsx(s.SelectItem,{value:"bottom",children:"Bottom"}),e.jsx(s.SelectItem,{value:"right",children:"Right"})]})]})]}),e.jsxs("div",{className:"grid grid-cols-3 items-center gap-4",children:[e.jsx(s.Label,{htmlFor:"align",children:"Align"}),e.jsxs(s.Select,{value:n,onValueChange:c,children:[e.jsx(s.SelectTrigger,{className:"col-span-2 h-8 focus:ring-1 focus:ring-offset-0",children:e.jsx(s.SelectValue,{placeholder:"Select alignment"})}),e.jsxs(s.SelectContent,{children:[e.jsx(s.SelectItem,{value:"start",children:"Start"}),e.jsx(s.SelectItem,{value:"center",children:"Center"}),e.jsx(s.SelectItem,{value:"end",children:"End"})]})]})]})]})]})})]})}function ze(){var M;const t=s.useEditorStore(y=>y.frame),n=s.useEditorStore(y=>y.card),a=s.useEditorStore(y=>y.isShowingVisual),r=s.useEditorStore(y=>y.isSqlRunning),o=s.useEditorStore(y=>y.pythonStdOut),l=s.useEditorStore(y=>{var E;return(E=y.card.preferences)==null?void 0:E.chartOptions});s.useEditorStore(y=>y.actions.setRunSql);const c=s.getChartGridStyle(l),{setFrame:d,setCard:u,updateCardInFrame:x,setActiveTabCardId:h,runAssistant:g,setChartGrid:b}=s.useEditorActions(),{data:i,isLoading:f,isFetching:p,error:S}=s.useDashboardCardQuery(n);if(!n)return e.jsx(e.Fragment,{children:"No Active Card"});function j(){const y={connectionId:n.connectionId,id:s.v4(),title:"Title",description:"Description",preferences:{onClickFilter:[{columnIndex:0,expression:""}]},type:"bar",sql:"",data:[]};w(y)}function w(y){const E={...t,cards:[...t.cards,y],activeCardId:y.id};d(E),h(y.id)}function v(){const y={...n,id:s.v4(),title:`${n.title} Copy`,tabTitle:`${n.tabTitle||n.title} Copy`};w(y)}function I(y){const E=t.cards.filter(U=>U.id!==y),R=E[0],$={...t,cards:E,activeCardId:R.id};d($),h(R.id),u(R)}function z(y){h(y)}const L=(y,E)=>{console.log("handleDragStart",E),y.dataTransfer.setData("tabIndex",E.toString())},q=y=>{y.preventDefault()},V=(y,E)=>{const R=y.dataTransfer.getData("tabIndex");if(R===E.toString())return;const $=Array.from(t.cards),[U]=$.splice(parseInt(R),1);$.splice(E,0,U),d({...t,cards:$})};function B(y,E){return y.cards.length===1&&(E.displayTab===!0||E.displayTab===void 0)||y.activeCardId!==E.id&&(E.displayTab===!0||E.displayTab===void 0)?null:e.jsx("div",{onClick:()=>{const R=E.displayTab===void 0?!1:!E.displayTab;u({...E,displayTab:R}),x({...E,displayTab:R})},children:E.displayTab===!0||E.displayTab===void 0?e.jsx(s.Eye,{className:"mr-2 size-3.5 text-muted-foreground hover:text-foreground"}):e.jsx(Is,{className:"mr-2 size-3.5 text-muted-foreground hover:text-foreground"})})}function m(){return e.jsxs(s.Tabs,{onValueChange:z,value:t.activeCardId,className:"flex grow flex-col",children:[t.cards.map(y=>e.jsx(s.TabsContent,{className:"mt-0 grow",value:y.id,children:O()},y.id)),e.jsx(s.TabsList,{className:"group mx-6 justify-between",children:e.jsxs("div",{className:"flex items-center",children:[t.cards.map((y,E)=>e.jsx(s.Editable,{text:y.tabTitle||y.title,onSave:R=>{u({...n,tabTitle:R}),x({...n,tabTitle:R})},children:e.jsxs(s.TabsTrigger,{draggable:!0,onDragStart:R=>L(R,E),onDragOver:q,onDrop:R=>V(R,E),className:"",value:y.id,children:[B(t,y),y.tabTitle||y.title,t.activeCardId===y.id&&t.cards.length>1&&e.jsx(s.X,{className:"ml-2 size-3.5 text-muted-foreground hover:text-foreground",onClick:()=>I(y.id)})]})},y.id)),e.jsx(s.Button,{className:"ml-1 h-8 px-2 hover:bg-muted-foreground/50",variant:"outline",onClick:j,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:v,children:e.jsx(ws,{className:"h-4 w-4"})})]})})]})}function O(){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:i==null?void 0:i.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:i==null?void 0:i.records})})})}):e.jsx(s.ErrorBoundary,{FallbackComponent:s.FallbackEditorCard,children:e.jsx(ts,{className:"grow border-none shadow-none"})})}function H(){const y=JSON.stringify(i==null?void 0:i.records,null,2),E=new Blob([y],{type:"application/json"}),R=URL.createObjectURL(E),$=document.createElement("a");$.href=R,$.download=`${n.title}.json`,$.click()}function A(){const E=[Object.keys(i==null?void 0:i.records.reduce((F,T)=>({...F,...T}),{})).join(","),...((i==null?void 0:i.records)||[]).map(F=>Object.values(F).join(","))].join(`
252
- `),R=new Blob([E],{type:"text/csv"}),$=URL.createObjectURL(R),U=document.createElement("a");U.href=$,U.download=`${n.title}.csv`,U.click()}function _(){const y=`Can you get the documentation for ${n.type} chart?`;g(y)}function G(){const y=["xy","none","x","y"],R=(y.indexOf(c)+1)%y.length;b(y[R])}return e.jsxs("div",{className:"relative flex h-full flex-col py-3",children:[(f||p)&&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(he,{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",children:[e.jsx(Ot,{}),e.jsx(s.IconButton,{tooltip:"Visual Docs",onClick:_,children:e.jsx(js,{className:"size-4"})}),!["table","custom"].includes(n.type)&&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:A,children:e.jsx(Tt,{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:H,children:e.jsx(Ds,{strokeWidth:1.5,className:"size-4"})}),e.jsx(s.CopyButton,{text:JSON.stringify(i==null?void 0:i.records,null,2),className:"h-7 w-fit px-1 font-mono text-xs text-muted-foreground/70"})]}),a&&e.jsxs("div",{className:"flex items-center",children:[!["kpi","text","custom","table"].includes(n.type)&&e.jsx(zt,{}),!["pie","doughnut","radar","polarArea","table","custom","kpi","text","map"].includes(n.type)&&e.jsxs(s.IconButton,{tooltip:"Grid Style",onClick:G,children:[(c==="xy"||!c)&&e.jsx(Ls,{className:"size-4"}),c==="x"&&e.jsx(Ns,{className:"size-4"}),c==="y"&&e.jsx(Hs,{className:"size-4"}),c==="none"&&e.jsx(Qs,{className:"size-4"})]})]}),e.jsx(Vt,{})]}),a?m():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(Ft,{})}),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:[(i==null?void 0:i.records)&&(i==null?void 0:i.records.length)>0&&e.jsx(Nt,{data:(i==null?void 0:i.records)||[]}),(S||(i==null?void 0:i.error))&&e.jsx("span",{className:"font-mono text-xs",children:(S==null?void 0:S.message)||((M=i==null?void 0:i.error)==null?void 0:M.message)}),e.jsx(s.ScrollBar,{orientation:"horizontal"})]})})]})]})}function Ft(){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 Vt(){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 Rt({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 te({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(l=>e.jsx(s.SelectItem,{value:l.value,children:l.label},l.value))]})})]})}function ue({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 qt(){var p,S;const t=s.useEditorStore(j=>j.card.customCardPreferences),{data:n}=ls(),a=(n==null?void 0:n.plugins)||[],r=s.useEditorStore(j=>j.card),o=s.useEditorStore(j=>j.frame),l=(t==null?void 0:t.visualType)||"single",{setCustomCardPreferences:c}=s.useEditorActions(),{components:d,manifest:u}=s.useCustomVisual((t==null?void 0:t.url)||""),x=(p=u==null?void 0:u.visuals)==null?void 0:p.find(j=>j.name===(t==null?void 0:t.componentName));function h(j,w){if(!t)return;const I={...(t==null?void 0:t.dataInputCardIds)||{},[j]:{cardId:w,hookRef:null}};c({...t,dataInputCardIds:I})}function g(j){var v,I;const w=(v=o==null?void 0:o.cards)==null?void 0:v.filter(z=>{var L;return((L=z==null?void 0:z.customCardPreferences)==null?void 0:L.visualType)!=="multiple"}).map(z=>({value:z.id,label:z.tabTitle||z.title}));return e.jsx("div",{className:"space-y-2",children:(I=j==null?void 0:j.dataInputs)==null?void 0:I.map((z,L)=>{var q,V;return e.jsxs("div",{className:"grid grid-cols-10 gap-2",children:[e.jsx("div",{className:"col-span-4 flex items-center",children:z}),e.jsx(te,{className:"col-span-6 h-8 w-full justify-between",label:"",options:w||[],value:((V=(q=t==null?void 0:t.dataInputCardIds)==null?void 0:q[L])==null?void 0:V.cardId)||"",onValueChange:B=>h(L,B)})]},L+Math.random())})})}function b(j,w,v=[]){var I,z;return t?j==="input"?e.jsx(s.Input,{className:`h-8 w-full ${s.removeRing}`,value:((I=t==null?void 0:t.settings)==null?void 0:I[w])||"",onChange:L=>{c({...t,settings:{...t==null?void 0:t.settings,[w]:L.target.value}})}},w):j==="select"?e.jsx(te,{className:"h-8 w-full",label:"",options:v,value:((z=t==null?void 0:t.settings)==null?void 0:z[w])||"",onValueChange:L=>{c({...t,settings:{...t==null?void 0:t.settings,[w]:L}})}}):null:null}function i(j){const w=Object.entries((j==null?void 0:j.settings)||{});return e.jsx("div",{className:"space-y-3",children:w.map(([v,I])=>e.jsxs("div",{className:"space-y-2",children:[e.jsx(s.Label,{children:I.title}),b(I.ui,v,I.options)]},v))})}function f(j){t&&c({...t,visualType:j,componentName:""})}return e.jsxs("div",{className:"p-6",children:[e.jsx(ue,{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(te,{className:"h-8 w-full",label:"",options:a,value:(t==null?void 0:t.url)||"",onValueChange:j=>c({...t||{url:"",componentName:""},url:j})})})}),((t==null?void 0:t.type)==="component"||(t==null?void 0:t.type)===void 0)&&e.jsx(Rt,{options:[{value:"single",label:"Single Visual"},{value:"multiple",label:"Multi-Visual"}],value:l,onValueChange:f}),((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:d&&e.jsx(te,{className:"h-8 w-full",label:"",options:(d==null?void 0:d.filter(j=>j.type===l).map(j=>({value:j.name,label:j.name})))||[],value:t.componentName,onValueChange:j=>{console.log("changing value",j),c({...t,componentName:j})}})})]})})]})})}),e.jsx(s.Separator,{className:"my-4"}),((S=r==null?void 0:r.customCardPreferences)==null?void 0:S.componentName)&&e.jsxs(ue,{summary:"Component Settings",children:[x&&x.dataInputs&&e.jsxs("div",{className:"space-y-3",children:[e.jsx(s.Label,{children:"Input Mapping"}),e.jsx("div",{className:"px-2",children:g(x)})]}),x&&x.settings&&e.jsx("div",{className:"space-y-3",children:e.jsx("div",{className:"px-2",children:i(x)})})]})]})}function re(){const[t,n]=C.useState([]);s.useEditorStore(h=>h.card.cfg);const a=s.useEditorStore(h=>h.card.preferences),{setCardCfg:r,setFilterOnClickColumnIndex:o,setCardPreferences:l}=s.useEditorStore(h=>h.actions),c=s.useEditorStore(h=>h.queryResultColumns);s.useEditorStore(h=>{var g;return(g=h.card.preferences)==null?void 0:g.filterOnClickColumnIndex}),C.useEffect(()=>{c&&n(new Array(c.length).fill(!1))},[c]);function d(h,g){var b,i;g?a!=null&&a.onClickFilter&&((b=a==null?void 0:a.onClickFilter)==null?void 0:b.length)>0?l({...a,onClickFilter:[...a.onClickFilter,{columnIndex:h,expression:""}]}):l({...a,onClickFilter:[{columnIndex:h,expression:""}]}):(l({...a,onClickFilter:(i=a==null?void 0:a.onClickFilter)==null?void 0:i.filter(f=>f.columnIndex!==h)}),n(f=>{const p=[...f];return p[h]=!1,p}))}function u(h,g){var i;const b=(i=a==null?void 0:a.onClickFilter)==null?void 0:i.map(f=>f.columnIndex===h?{...f,expression:g.target.value}:f);l({...a,onClickFilter:b})}function x(h){var g,b,i,f;if(t!=null&&t[h]||(b=(g=a==null?void 0:a.onClickFilter)==null?void 0:g.find(p=>p.columnIndex===h))!=null&&b.expression)return e.jsx(s.Input,{value:(f=(i=a==null?void 0:a.onClickFilter)==null?void 0:i.find(p=>p.columnIndex===h))==null?void 0:f.expression,onChange:p=>u(h,p),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"}),c==null?void 0:c.map((h,g)=>{var b,i;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(f=>f.columnIndex===g)),onCheckedChange:f=>d(g,f)}),e.jsx("label",{className:"text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70",children:h}),e.jsx("div",{className:"flex items-center gap-2",children:((i=a==null?void 0:a.onClickFilter)==null?void 0:i.find(f=>f.columnIndex===g))&&e.jsx(s.Pencil,{onClick:()=>{n(f=>{const p=[...f];return p[g]=!f[g],p})},className:"invisible size-3 cursor-pointer text-gray-400 group-hover:visible"})})]}),x(g)]})},h)})]})}function je(){var c,d,u;const t=s.useEditorStore(x=>x.card.preferences),n=s.useEditorStore(x=>x.card.cfg),{setCardCfg:a,setCardPreferences:r,setChartOrientation:o}=s.useEditorStore(x=>x.actions);(c=n==null?void 0:n.options)!=null&&c.indexAxis;function l(x){o(x)}return e.jsxs(s.RadioGroup,{value:((d=t==null?void 0:t.chartOptions)==null?void 0:d.indexAxis)||((u=n==null?void 0:n.options)==null?void 0:u.indexAxis)||"x",onValueChange:l,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 xe="focus-visible:ring-0 focus-visible:ring-ring focus-visible:ring-offset-0";function Fe(t,n){var r,o,l;const a=s.getNumberAxis(t,n);return((l=(o=(r=t==null?void 0:t.chartOptions)==null?void 0:r.scales)==null?void 0:o[a])==null?void 0:l.type)||"linear"}function cs(){var M,y,E,R,$,U;const[t,n]=C.useState(!1),a=s.useEditorStore(F=>{var T;return(T=F.card)==null?void 0:T.preferences}),r=s.useEditorStore(F=>{var T;return(T=F.card)==null?void 0:T.cfg}),o=s.getNumberAxis(a,r),[l,c]=C.useState(Fe(a)),[d,u]=C.useState(((E=(y=(M=a==null?void 0:a.chartOptions)==null?void 0:M.scales)==null?void 0:y[o])==null?void 0:E.min)||""),[x,h]=C.useState(((U=($=(R=a==null?void 0:a.chartOptions)==null?void 0:R.scales)==null?void 0:$[o])==null?void 0:U.max)||""),[g,b]=C.useState(d||x?"custom":"auto"),[i,f]=C.useState(""),[p,S]=C.useState(0),[j,w]=C.useState(""),[v,I]=C.useState(""),[z,L]=C.useState(""),q=s.useEditorStore(F=>F.actions.setCardPreferences),{updateCardInFrame:V}=s.useEditorActions(),B=s.useEditorStore(F=>F.card),m=s.useEditorStore(F=>{var T;return(T=F.card)==null?void 0:T.type}),O=["pie","doughnut","polarArea"].includes(m);C.useEffect(()=>{var F,T,Y,k,P,J,K,ae,se,Q,X,D,W,Z;c(Fe(a)),u(((Y=(T=(F=a==null?void 0:a.chartOptions)==null?void 0:F.scales)==null?void 0:T[o])==null?void 0:Y.min)===0?0:""),h(((J=(P=(k=a==null?void 0:a.chartOptions)==null?void 0:k.scales)==null?void 0:P[o])==null?void 0:J.max)||""),f(((Q=(se=(ae=(K=a==null?void 0:a.chartOptions)==null?void 0:K.scales)==null?void 0:ae[o])==null?void 0:se.ticks)==null?void 0:Q.stepSize)||""),S(((X=a==null?void 0:a.numberAxisFormat)==null?void 0:X.decimalPlaces)||0),w(((D=a==null?void 0:a.numberAxisFormat)==null?void 0:D.suffix)||""),I(((W=a==null?void 0:a.numberAxisFormat)==null?void 0:W.currency)||""),L(((Z=a==null?void 0:a.numberAxisFormat)==null?void 0:Z.locale)||"")},[t,a,o]);function H(F,T){return T===""||/^[0-9\b]+$/.test(T)?Number(T):Number(F)}function A(){const F=[...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:v||"none",onValueChange:T=>I(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"}),F.map(T=>e.jsx(s.SelectItem,{value:T,children:T},T))]})})]}),e.jsxs(s.Select,{value:z,onValueChange:T=>L(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:p,onChange:T=>S(Number(T.target.value)),id:"format",className:`col-span-6 h-8 w-full tracking-wide ${xe}`})]})]})}function _(){return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"grid grid-cols-3 items-center gap-2",children:[e.jsx(s.Label,{htmlFor:"range",children:"Range"}),e.jsx(s.Input,{id:"min",value:d,onChange:F=>u(T=>H(T,F.target.value)),className:`col-span-1 h-8 w-full ${xe}`}),e.jsx(s.Input,{value:x,onChange:F=>h(T=>H(T,F.target.value)),id:"max",className:`col-span-1 h-8 w-full ${xe}`})]}),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:i,onChange:F=>f(T=>H(T,F.target.value)),id:"step-size",className:`col-span-1 h-8 w-full ${xe}`})]})]})}function G(){var k;let F={};g==="custom"&&(F={min:d,max:x,ticks:{stepSize:i}});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:l,...l==="linear"?F:{}}}},numberAxisFormat:{decimalPlaces:p,suffix:j,currency:v,locale:z}};console.log(T),q(T);const Y={...B,preferences:T};V(Y)}return e.jsxs(s.Popover,{onOpenChange:F=>n(F),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:O,value:l,onValueChange:F=>c(F),children:[e.jsx(s.SelectTrigger,{className:"col-span-2 h-8 w-full focus:ring-1 focus:ring-offset-0",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{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"})]})})]})]}),l=="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:O,id:"scale-option",value:g,onValueChange:F=>b(F),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"})]})]})]}),g==="custom"&&l=="linear"&&_(),A(),e.jsx(s.SelectSeparator,{}),e.jsx("div",{className:"grid grid-cols-3",children:e.jsx(s.Button,{onClick:G,variant:"secondary",className:"col-span-1 col-start-3 h-8 w-full",children:"Apply"})})]})]})})]})}function Bt({idx:t}){var d;const n=s.useEditorStore(u=>{var x;return(x=u.card)==null?void 0:x.preferences}),a=s.useEditorStore(u=>{var x;return(x=u.card.preferences)==null?void 0:x.datasetOptions}),r=s.useEditorStore(u=>u.actions.setCardPreferences),o=(d=n==null?void 0:n.chartOptions)==null?void 0:d.indexAxis,l=a==null?void 0:a.find(u=>u.idx===t);function c(u,x){(u==="end"||u==="start")&&s.getContrastColor(s.getCanvasBackgroundColor());const h={display:u!=="none",align:u,anchor:u,clamp:!0};if(!l)r({...n,datasetOptions:[...a||[],{idx:x,datalabels:h}]});else{const g={...l};g.datalabels=h;const b=a==null?void 0:a.map(i=>i.idx===x?g:i);r({...n,datasetOptions:b})}}return e.jsxs(s.Popover,{children:[e.jsx(s.PopoverTrigger,{children:e.jsx(Js,{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:()=>c("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:()=>c("start",t),size:"sm",variant:"secondary",className:"h-7 p-1 text-xs font-normal",children:e.jsx(Fs,{className:s.cn("h-4 w-4",{"rotate-90":o==="y"})})}),e.jsx(s.Button,{onClick:()=>c("center",t),size:"sm",variant:"secondary",className:"h-7 p-1 text-xs font-normal",children:e.jsx(Rs,{className:s.cn("h-4 w-4",{"rotate-90":o==="y"})})}),e.jsx(s.Button,{onClick:()=>c("end",t),size:"sm",variant:"secondary",className:"h-7 p-1 text-xs font-normal",children:e.jsx(Vs,{className:s.cn("h-4 w-4",{"rotate-90":o==="y"})})})]})})]})}function ds(){const t=s.useEditorStore(x=>x.card),n=s.useEditorStore(x=>{var h,g,b;return(b=(g=(h=x==null?void 0:x.card)==null?void 0:h.preferences)==null?void 0:g.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:l,metricKeys:c,dimensionKeys:d}=s.getKeys((a==null?void 0:a.records)||[]);let u=c;if(["stackedBar","stackedLine"].includes(t.type)){const x=s.pivotData({dataArray:(a==null?void 0:a.records)||[],groupKey:d[0],pivotKey:d[1],valueKey:u[0]}),{metricKeys:h}=s.getKeys(x);u=h}return l.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:d[0],children:us(d[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(cs,{})]}),e.jsx("div",{className:"my-1 max-h-[125px] space-y-1 overflow-y-auto",children:u.map((x,h)=>e.jsx(_t,{col:x,idx:h},x))})]})]})}function us(t,n=30){return t.length>n?t.slice(0,n)+"...":t}function _t({col:t,idx:n}){const a=s.useEditorStore(d=>{var u;return(u=d.card)==null?void 0:u.preferences}),r=s.useEditorStore(d=>{var u;return(u=d.card.preferences)==null?void 0:u.datasetOptions}),o=r==null?void 0:r.find(d=>d.idx===n),{setCardPreferences:l}=s.useEditorStore(d=>d.actions);function c(d){if(!o)l({...a,datasetOptions:[...r||[],{idx:n,type:d==="area"?"line":d,fill:d==="area"?"origin":""}]});else{const u={...o};u.type=d==="area"?"line":d,u.fill=d==="area"?"origin":"";const x=r==null?void 0:r.map(h=>h.idx===n?u:h);l({...a,datasetOptions:x})}}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:us(t)}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(Ce,{onClick:()=>c("bar"),className:"invisible size-4 cursor-pointer text-muted-foreground hover:text-foreground group-hover:visible"}),e.jsx(ve,{onClick:()=>c("line"),className:"invisible size-4 cursor-pointer text-muted-foreground hover:text-foreground group-hover:visible"}),e.jsx(Cs,{onClick:()=>c("area"),className:"invisible size-4 cursor-pointer text-muted-foreground hover:text-foreground group-hover:visible"}),e.jsx(Bt,{idx:n})]})]})}function hs(){const t=s.useEditorStore(i=>i.selectedConnectionId),n=s.useEditorStore(i=>i.selectedDatamodelId),a=s.useEditorStore(i=>i.selectedDatabaseName),r=s.useEditorStore(i=>i.selectedSchemaName),o=s.useEditorStore(i=>i.selectedTableName),l=s.useDashboardStore(i=>i.dashboard.filters)||[],c=s.useDashboardStore(i=>i.actions.addFilter),d=s.useDashboardStore(i=>i.actions.removeFilter),{removeFilterValues:u}=s.useDashboardActions(),{modelItems:x,tableName:h,connectionType:g}=ne();function b(i,f="dashboard"){var q;const p=s.fmt(i.column_name),S=s.fmt(a||""),j=s.fmt(r||""),w=s.fmt(h);let v=s.getQualifiedTableName(j,w,g),I=`${v}.${p}`;const z=(q=x==null?void 0:x.find(V=>V.id===n))==null?void 0:q.name;n&&n!=="none"&&(I=`${s.DATAMODEL_NAMESPCACE}.${z}.${p}`,v=`${s.DATAMODEL_NAMESPCACE}.${z}`);const L=l==null?void 0:l.find(V=>V.column===I&&V.table===w&&(V.database===S||V.database===a));if(L)u(L.id),d(L.id);else{const V=s.v4();return h==="api"&&t?(c({location:f,id:V,column:I,title:i.column_name,dataType:i.data_type,table:"api",database:"",connectionId:t,operation:"in",sql:s.getDefaultFilterSql(i.data_type,v,p)}),V):(c({id:V,location:f,column:I,title:i.column_name,dataType:i.data_type,table:o||"",database:a||"",connectionId:t||"",operation:"in",sql:s.getDefaultFilterSql(i.data_type,v,p)}),V)}}return{assignFilter:b}}function ce(){const t=s.useDashboardStore(d=>d.dashboard.filters),n=s.useEditorStore(d=>d.frame),{setFrame:a}=s.useEditorActions(),{columns:r}=ne(),{assignFilter:o}=hs();function l(d){const u=o(d,"frame");a({...n,filterId:u})}const c=t==null?void 0:t.find(d=>d.id===n.filterId);return e.jsxs("div",{className:"space-y-3",children:[e.jsx(s.Label,{children:"Card Filter"}),e.jsx(Pt,{onSelect:l,columns:r}),c&&e.jsx(s.FilterHeader,{filter:c})]})}function Pt({columns:t,onSelect:n}){var c;const[a,r]=ie.useState(!1),[o,l]=ie.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?(c=t.find(d=>d.column_name===o))==null?void 0:c.column_name:"Select Column...",e.jsx(s.CaretSortIcon,{className:"ml-2 h-4 w-4 shrink-0 opacity-50"})]})}),e.jsx(s.PopoverContent,{className:"w-[200px] p-0",children:e.jsxs(s.Command,{children:[e.jsx(s.CommandInput,{placeholder:"Search column",className:"h-9"}),e.jsxs(s.CommandList,{children:[e.jsx(s.CommandEmpty,{children:"No framework found."}),e.jsx(s.CommandGroup,{children:t.map(d=>e.jsxs(s.CommandItem,{value:d.column_name,onSelect:u=>{const x=u===o?"":u;l(x),r(!1),x&&n(d)},children:[d.column_name,e.jsx(s.CheckIcon,{className:s.cn("ml-auto h-4 w-4",o===d.column_name?"opacity-100":"opacity-0")})]},d.column_name))})]})]})})]})}function Ht({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(je,{}),e.jsx(ds,{})]})]}),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(re,{}),e.jsx(ce,{})]})]})]})})}function we(){var o,l,c;const t=s.useEditorStore(d=>d.card.cfg),n=s.useEditorStore(d=>d.actions.setCardCfg),a=s.useEditorStore(d=>d.card.type);function r(d){var h;const u={datalabels:{display:d!=="none",align:d,anchor:d,clamp:!0}},x={...t,options:{...t==null?void 0:t.options,plugins:{...(h=t==null?void 0:t.options)==null?void 0:h.plugins,...u}}};n(x),console.log(d)}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(cs,{})]}),e.jsxs(s.Select,{value:(c=(l=(o=t==null?void 0:t.options)==null?void 0:o.plugins)==null?void 0:l.datalabels)==null?void 0:c.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 Gt({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 (optional) - category"}),e.jsx("li",{children:"x-axis - number"}),e.jsx("li",{children:"y-axis - number"}),a==="bubble"&&e.jsx("li",{children:"radius - number"})]}),e.jsxs("div",{children:["See ",e.jsx("a",{target:"_blank",onClick:l=>l.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(we,{})})]}),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(re,{}),e.jsx(ce,{})]})]})]})})}const $t={datasets:[{type:"line",label:"Sum_sales",data:[]},{type:"bar",label:"Sum_profit",data:[]}]},Ut={datasets:[{fill:"origin",type:"line",label:"Sum_sales",data:[]}]};function Qt(){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:Jt(t)}),e.jsx("section",{className:"",children:["line","bar"].includes(t)&&e.jsx(je,{})}),!["kpi"].includes(t)&&e.jsxs("div",{className:"space-y-4",children:[e.jsx(we,{}),e.jsx(re,{}),e.jsx(ce,{})]})]})}function Jt(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($t,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(Ut,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 Wt(){var u,x,h,g,b;const t=s.useEditorStore(i=>i.card.preferences),n=s.useEditorStore(i=>i.actions.setCardPreferences),a=s.useEditorStore(i=>i.actions.setNumberFormat);s.useEditorStore(i=>{var f,p;return(p=(f=i.card.preferences)==null?void 0:f.formatNumber)==null?void 0:p.decimalPlaces});const r=s.useEditorStore(i=>{var f,p;return(p=(f=i.card.preferences)==null?void 0:f.formatNumber)==null?void 0:p.locale}),o=s.useEditorStore(i=>{var f,p;return(p=(f=i.card.preferences)==null?void 0:f.formatNumber)==null?void 0:p.currency});s.useEditorStore(i=>i.actions.setFilterOnClickField);const l=s.useEditorStore(i=>{var f,p;return(p=(f=i.card.preferences)==null?void 0:f.formatNumber)==null?void 0:p.colorRanges})||[],c=s.useEditorStore(i=>i.actions.setColorRanges),d=[...new Set(s.LOCALE_CURRENCY_PAIRS.map(i=>i.currency))];return e.jsxs("div",{children:[e.jsxs("div",{className:"mb-3 flex items-center gap-2",children:[e.jsx(s.Checkbox,{checked:!!((u=t==null?void 0:t.formatNumber)!=null&&u.enabled),onCheckedChange:i=>{n({...t,formatNumber:{...t==null?void 0:t.formatNumber,enabled:i}})}}),e.jsx(s.Label,{children:"Format Number"})]}),((x=t==null?void 0:t.formatNumber)==null?void 0:x.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:i=>{var f,p,S;return a(((f=t==null?void 0:t.formatNumber)==null?void 0:f.decimalPlaces)||0,((p=t==null?void 0:t.formatNumber)==null?void 0:p.currency)||"",i,((S=t==null?void 0:t.formatNumber)==null?void 0:S.suffix)||"")},children:[e.jsx(s.SelectTrigger,{className:"col-span-6 h-8 w-full focus:ring-1 focus:ring-offset-0",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{children:e.jsxs(s.SelectGroup,{children:[e.jsx(s.SelectLabel,{children:"Format"}),e.jsx(s.SelectItem,{value:"none",children:"None"},"none"),s.LOCALE_CURRENCY_PAIRS.map(i=>e.jsx(s.SelectItem,{value:i.locale,children:i.locale},i.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:i=>{var f,p,S;console.log("currency",i),a(((f=t==null?void 0:t.formatNumber)==null?void 0:f.decimalPlaces)||0,i==="none"?"":i,((p=t==null?void 0:t.formatNumber)==null?void 0:p.locale)||"",((S=t==null?void 0:t.formatNumber)==null?void 0:S.suffix)||"")},children:[e.jsx(s.SelectTrigger,{className:"col-span-6 h-8 w-full focus:ring-1 focus:ring-offset-0",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{children:e.jsxs(s.SelectGroup,{children:[e.jsx(s.SelectLabel,{children:"Currency"}),e.jsx(s.SelectItem,{value:"none",children:"None"},"none"),d.map(i=>e.jsx(s.SelectItem,{value:i,children:i},i))]})})]})]})]}),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:((g=(h=t==null?void 0:t.formatNumber)==null?void 0:h.decimalPlaces)==null?void 0:g.toString())||"0",onValueChange:i=>{var f,p,S;return a(Number(i),((f=t==null?void 0:t.formatNumber)==null?void 0:f.currency)||"",((p=t==null?void 0:t.formatNumber)==null?void 0:p.locale)||"",((S=t==null?void 0:t.formatNumber)==null?void 0:S.suffix)||"")},children:[e.jsx(s.SelectTrigger,{className:"col-span-3 h-8 w-full focus:ring-1 focus:ring-offset-0",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{children:["0","1","2","3","4"].map(i=>e.jsx(s.SelectItem,{value:i,children:i},i))})]})]}),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:i=>{var f,p,S;return a(((f=t==null?void 0:t.formatNumber)==null?void 0:f.decimalPlaces)||0,((p=t==null?void 0:t.formatNumber)==null?void 0:p.currency)||"",((S=t==null?void 0:t.formatNumber)==null?void 0:S.locale)||"",i.target.value)}})]})]})]})}),e.jsx(s.Separator,{className:"my-3"}),e.jsx(s.ColorFormat,{colorRanges:l,setColorRanges:c})]})]})}function Kt(){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(Wt,{})}),e.jsx("div",{}),e.jsx("div",{})]})}const Xt=[{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"}],Yt=["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"],Zt=Yt.map(t=>({label:t,value:t}));function ea(){var u,x,h,g,b,i,f,p,S,j,w,v,I,z,L,q,V,B;const t=s.useEditorStore(m=>m.card),n=(x=(u=t==null?void 0:t.preferences)==null?void 0:u.mapVisualOptions)==null?void 0:x.topoJsonUrl,[a,r]=C.useState(((g=(h=t==null?void 0:t.preferences)==null?void 0:h.mapVisualOptions)==null?void 0:g.customTopoJsonUrl)||""),{setCardPreferences:o}=s.useEditorActions(),{data:l}=s.useTopoJson(t),c=Object.keys((l==null?void 0:l.objects)||{}).map(m=>({label:m,value:m}))||[],d=[{label:"US States 10m",value:"https://unpkg.com/us-atlas/states-10m.json"},{label:"Countries 50m",value:"https://unpkg.com/world-atlas/countries-50m.json"},{label:"Custom",value:"custom"}];return e.jsxs("div",{className:"p-6",children:[e.jsx(ue,{summary:"Map Chart",children:e.jsx("p",{className:"rounded-md bg-muted p-2 font-mono text-xs",children:"SELECT country, value FROM table"})}),e.jsx(s.Separator,{className:"my-4"}),e.jsx(ue,{open:!0,summary:"Settings",children:e.jsxs("div",{className:"space-y-3 px-2",children:[e.jsx(te,{className:"h-9",options:d,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"}),l&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(s.Label,{children:"Map Object"}),e.jsx(te,{className:"h-9",options:c,value:((i=(b=t.preferences)==null?void 0:b.mapVisualOptions)==null?void 0:i.objectKey)||"",label:"Map Object",onValueChange:m=>{var O;o({...t.preferences,mapVisualOptions:{...(O=t.preferences)==null?void 0:O.mapVisualOptions,objectKey:m}})}})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(s.Label,{children:"Projection"}),e.jsx(te,{className:"h-9",options:Xt,value:((p=(f=t.preferences)==null?void 0:f.mapVisualOptions)==null?void 0:p.projection)||"",label:"Projection",onValueChange:m=>{var O;o({...t.preferences,mapVisualOptions:{...(O=t.preferences)==null?void 0:O.mapVisualOptions,projection:m}})}})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(s.Label,{children:"Colors"}),e.jsx(te,{className:"h-9",options:Zt,value:((j=(S=t.preferences)==null?void 0:S.mapVisualOptions)==null?void 0:j.colorScale)||"",label:"Select Color Scale",onValueChange:m=>{var O;o({...t.preferences,mapVisualOptions:{...(O=t.preferences)==null?void 0:O.mapVisualOptions,colorScale:m}})}})]})]})]})}),e.jsx(s.Separator,{className:"my-4"}),e.jsx(ue,{className:"",summary:"Scale Options",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(s.Input,{className:`h-9 w-full ${s.removeRing}`,type:"number",step:.1,value:((v=(w=t.preferences)==null?void 0:w.mapVisualOptions)==null?void 0:v.projectionScale)||1,onChange:m=>{var O;o({...t.preferences,mapVisualOptions:{...(O=t.preferences)==null?void 0:O.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:((L=(z=(I=t.preferences)==null?void 0:I.mapVisualOptions)==null?void 0:z.projectionOffset)==null?void 0:L[0])||0,onChange:m=>{var O,H,A,_;o({...t.preferences,mapVisualOptions:{...(O=t.preferences)==null?void 0:O.mapVisualOptions,projectionOffset:[Number(m.target.value),((_=(A=(H=t.preferences)==null?void 0:H.mapVisualOptions)==null?void 0:A.projectionOffset)==null?void 0:_[1])||0]}})}}),e.jsx(s.Label,{children:"Y"}),e.jsx(s.Input,{className:`h-9 w-full ${s.removeRing}`,type:"number",step:10,value:((B=(V=(q=t.preferences)==null?void 0:q.mapVisualOptions)==null?void 0:V.projectionOffset)==null?void 0:B[1])||0,onChange:m=>{var O,H,A,_;o({...t.preferences,mapVisualOptions:{...(O=t.preferences)==null?void 0:O.mapVisualOptions,projectionOffset:[((_=(A=(H=t.preferences)==null?void 0:H.mapVisualOptions)==null?void 0:A.projectionOffset)==null?void 0:_[0])||0,Number(m.target.value)]}})}})]})}),e.jsx(s.Separator,{className:"my-4"}),e.jsx(re,{})]})}function sa(){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 pe({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(je,{}),t!=="text"&&e.jsx(we,{}),t==="text"&&e.jsx(sa,{})]})]}),!["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(re,{}),e.jsx(ce,{})]})]})]})})}function ta(){const t=s.useEditorStore(r=>{var o,l;return(l=(o=r==null?void 0:r.card)==null?void 0:o.preferences)==null?void 0:l.sortChart}),{setSortChart:n}=s.useEditorActions();function a(){return e.jsxs("div",{className:"space-y-2",children:[e.jsx(s.Label,{children:"Sort"}),e.jsx(te,{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(je,{}),a(),e.jsx(ds,{})]})]}),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(re,{}),e.jsx(ce,{})]})]})]})})}function aa({cardType:t="table"}){console.log("cardType",t);const n=s.useEditorStore(o=>{var l;return(l=o.card)==null?void 0:l.preferences}),a=s.useEditorStore(o=>o.actions.setCardPreferences),r=o=>{a({...n,allowDownload:o})};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(re,{}),e.jsx(ce,{})]})]})}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(s.Checkbox,{onCheckedChange:r,id:"allow-download"}),e.jsx("label",{htmlFor:"allow-download",className:"text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70",children:"Allow Download"})]})]})}const na=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."]})]}),ra=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."]})]}),oa=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 ia(){const t=s.useEditorStore(a=>a.card.type);function n(a){switch(a){case"stackedBar":case"stackedLine":return e.jsx(ta,{});case"pyramid":return e.jsx(pe,{docContent:na,cardType:a});case"kpi":return e.jsx(Kt,{});case"line":case"bar":return e.jsx(Ht,{cardType:a});case"range":return e.jsx(pe,{docContent:ra,cardType:a});case"pie":case"doughnut":case"polarArea":case"radar":return e.jsx(pe,{cardType:a});case"bubble":case"scatter":return e.jsx(Gt,{cardType:a});case"table":return e.jsx(aa,{cardType:a});case"text":return e.jsx(pe,{docContent:oa,cardType:a,suffix:"Visual"});case"map":return e.jsx(ea,{});case"custom":return e.jsx(qt,{});default:return e.jsx(Qt,{})}}return e.jsxs(s.ScrollArea,{className:"h-full w-full text-sm",children:[n(t),e.jsx(s.ScrollBar,{orientation:"horizontal"})]})}function la(){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(vt,{})}),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(ia,{})})}),e.jsx(s.ResizableHandle,{className:"border"}),e.jsx(s.ResizablePanel,{minSize:40,defaultSize:75,maxSize:100,children:e.jsx(ze,{})})]}):e.jsx(ze,{})})]})}function ca({authToken:t,onSave:n,onClose:a}){s.useDashboardStore(c=>c.themeStyle);const r=s.useEditorStore(c=>c.actions.setOnSave),o=s.useEditorStore(c=>c.actions.setOnClose),l=s.useDashboardStore(c=>c.actions.setAuthToken);return C.useEffect(()=>{n&&r(n),a&&o(a)},[n,r,a,o]),C.useEffect(()=>{t&&t.accessToken&&l(t)},[t,l]),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(Ye,{})}),e.jsx(s.EditorMain,{children:e.jsx(la,{})})]})})}function da(){s.useDashboardStore(c=>c.selectedCardId);const t=s.useDashboardStore(c=>c.selectedSheetId),{setIsVisualEditing:n}=s.useDashboardStore(c=>c.actions),a=s.useDashboardStore(c=>c.isVisualEditing),r=s.useDashboardStore(c=>c.actions.updateFrame);function o(c){t&&(r(t,c),n(!1))}function l(){n(!1)}return e.jsx("div",{role:"editor-container",className:s.cn("flex grow",{"max-h-0 overflow-hidden":!a}),children:e.jsx(ca,{onSave:o,onClose:l})})}function ua(){const t=s.useEditorStore(l=>l.selectedDatabaseName),n=s.useEditorStore(l=>l.selectedTableName),a=s.useDashboardStore(l=>l.dashboard.filters)||[],{columns:r}=ne(),{assignFilter:o}=hs();return e.jsx(s.ScrollArea,{className:"flex-1 basis-0 flex-col px-3",children:r==null?void 0:r.map(l=>{const c=a==null?void 0:a.find(d=>d.column===s.fmt(l.column_name)&&d.table===n&&d.database===t);return e.jsx("div",{onClick:()=>o(l),className:s.cn("group flex cursor-pointer items-center justify-between border border-dashed border-background px-3 py-[6px] text-sm transition-colors hover:bg-muted/50",{"bg-muted":c}),children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Xe,{column:l}),e.jsx("span",{children:l.column_name})]})},l.column_name)})})}function ha(){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(Ye,{ColumnsComponent:()=>e.jsx(ua,{})})})]})}function ma(){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 xa(){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(ma,{}),e.jsx(s.DashboardTabs,{})]}),t&&e.jsx("div",{role:"filter-aside-container",className:"flex",children:e.jsx(ha,{})})]})}function pa(){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 fa({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(pa,{}),e.jsxs(s.DashboardPanel,{...a,children:[t&&e.jsx(at,{}),e.jsx(da,{}),e.jsx(xa,{})]})]})]})})}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.resolveDatamodelName=s.resolveDatamodelName;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=oe;exports.Surfboard=fa;exports.cleanCard=We;exports.downloadPdf=Ke;exports.getDashbaordStateWithoutData=Ne;exports.useEditorAside=ne;
251
+ `;V(D)}function ae(){return e.jsxs(e.Fragment,{children:[l&&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(Ct,{jsonString:JSON.stringify(S,null,2)})})}),S&&S.length>0&&e.jsx(s.Button,{variant:"ghost",onClick:()=>c(!l),className:"absolute bottom-0 right-6 size-7 p-1",children:l?e.jsx(s.X,{className:"size-3.5 text-muted-foreground"}):e.jsx(s.Filter,{className:"size-3.5 text-muted-foreground"})})]})}function se(){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(yt,{})}),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(St,{})}),e.jsx("code",{className:"absolute right-6 top-3 text-xs text-muted-foreground/70",children:"python"})]})]})]})}const Q=(U==null?void 0:U.message)||((X=R==null?void 0:R.error)==null?void 0:X.message);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:[se(),ae()]}),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:b||E,onClick:()=>{T()},className:"shrink-0",size:"sm",children:[b||E?e.jsx(he,{className:"mr-2 h-4 w-4 animate-spin"}):e.jsx(s.Play,{className:"mr-2 h-4 w-4"}),"Run"]}),e.jsx(lt,{sql:R==null?void 0:R.sql,error:Q,onClick:K}),e.jsxs(s.Button,{onClick:Y,className:"",size:"sm",variant:"secondary",children:[e.jsx(Es,{className:"mr-2 size-4"}),"Clear"]}),e.jsx(s.Toggle,{pressed:r,onPressedChange:D=>o(D),className:"",size:"sm",children:e.jsx(bt,{className:"size-4 text-foreground/70"})}),e.jsx(ut,{})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(s.Button,{onClick:J,className:"w-full",size:"sm",variant:"secondary",children:[e.jsx(s.Cross2Icon,{className:"mr-2 size-4"}),"Close"]}),e.jsxs(s.Button,{onClick:_,size:"sm",variant:"secondary",children:[e.jsx(s.Check,{className:"mr-2 size-4 font-bold text-green-600"}),"Accept"]})]})]})]})}function Nt({data:t}){var c;const[n,a]=C.useState([]),o=Object.keys(t[0]).map(d=>({accessorKey:d,header:({column:u})=>{const x=u.getIsSorted();return e.jsx("div",{className:"flex gap-2",children:e.jsxs("div",{className:"flex cursor-pointer items-center",onClick:()=>u.toggleSorting(u.getIsSorted()==="asc"),children:[d,x==="asc"?e.jsx(s.TriangleUpIcon,{className:"ml-2 h-5 w-5"}):x==="desc"?e.jsx(s.TriangleDownIcon,{className:"ml-2 h-5 w-5"}):null]})})}})),l=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:l.getHeaderGroups().map(d=>e.jsx(s.TableRow,{children:d.headers.map(u=>e.jsx(s.TableHead,{className:"sticky top-0 h-11 bg-muted font-semibold",children:u.isPlaceholder?null:s.flexRender(u.column.columnDef.header,u.getContext())},u.id))},d.id))}),e.jsx(s.TableBody,{children:(c=l.getRowModel().rows)!=null&&c.length?l.getRowModel().rows.map(d=>e.jsx(s.TableRow,{className:"whitespace-nowrap py-2","data-state":d.getIsSelected()&&"selected",children:d.getVisibleCells().map(u=>e.jsx(s.TableCell,{className:"py-3",children:s.flexRender(u.column.columnDef.cell,u.getContext())},u.id))},d.id)):e.jsx(s.TableRow,{children:e.jsx(s.TableCell,{colSpan:o.length,className:"h-24 text-center",children:"No results."})})})]})})}function wt({card:t}){var w,v,I,M,L,q,V,B,m,O,H;const[n,a]=C.useState(!1),[r,o]=C.useState([]),{authToken:l}=s.useSemaphorContext(),c=s.getTokenParams(l==null?void 0:l.accessToken),d=s.useDashboardStore(A=>A.themeStyle),u={colors:((v=(w=d==null?void 0:d.chart)==null?void 0:w.dataset)==null?void 0:v.backgroundColor)||[]};(I=t.customCardPreferences)!=null&&I.inputData;const{getCard:x}=s.useCustomVisual(((M=t.customCardPreferences)==null?void 0:M.url)||""),h=((L=t.customCardPreferences)==null?void 0:L.visualType)||"single",g=s.useEditorStore(A=>A.frame),{setCustomCardPreferences:y}=s.useEditorActions(),{data:i}=s.useDashboardCardQuery(t),f=C.useCallback((A,P)=>{o(G=>({...G,[A]:P}))},[]);if(!((q=t.customCardPreferences)!=null&&q.componentName))return null;const p=x((V=t.customCardPreferences)==null?void 0:V.componentName);function S(A){a(A)}const j=Object.keys(((B=t.customCardPreferences)==null?void 0:B.dataInputCardIds)||{}).map(A=>{var R,b,E;const P=(b=(R=t.customCardPreferences)==null?void 0:R.dataInputCardIds)==null?void 0:b[A].cardId,G=(E=g==null?void 0:g.cards)==null?void 0:E.find(F=>F.id===P);return G||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(C.Suspense,{fallback:e.jsx(e.Fragment,{}),children:[p&&h==="single"&&e.jsx(p,{params:c,theme:u,settings:(m=t.customCardPreferences)==null?void 0:m.settings,onDataChange:f,data:(i==null?void 0:i.records)||[]}),p&&h==="multiple"&&e.jsxs(e.Fragment,{children:[Object.keys(((O=t.customCardPreferences)==null?void 0:O.dataInputCardIds)||{}).map(A=>{var R,b,E;const P=(b=(R=t.customCardPreferences)==null?void 0:R.dataInputCardIds)==null?void 0:b[A].cardId,G=(E=g==null?void 0:g.cards)==null?void 0:E.find(F=>F.id===P);if(G)return e.jsx(s.MultiInputEmptyRenderer,{onLoadingStatus:S,onDataChange:f,dataInputIndex:A,card:G},G.id+A)}),e.jsx("div",{className:"flex flex-col gap-2",children:e.jsx(p,{theme:u,onDataChange:f,settings:j.map(A=>{var P;return(P=A==null?void 0:A.customCardPreferences)==null?void 0:P.settings}),data:j.map(A=>A!=null&&A.id?r==null?void 0:r[A.id]:[])})})]})]},(H=t.customCardPreferences)==null?void 0:H.componentName)})}function ts({className:t,...n}){var S;const a=s.useEditorStore(j=>j.card),r=((S=a.customCardPreferences)==null?void 0:S.showCardHeader)??!0,o=s.useEditorStore(j=>j.frame),l=s.useDashboardStore(j=>j.dashboard.filters);s.useEditorStore(j=>j.actions.setRunSql);const{updateFilter:c}=s.useDashboardActions(),d=l==null?void 0:l.find(j=>j.id===o.filterId),{data:u,isLoading:x,isFetching:h}=s.useDashboardCardQuery(a),{setCard:g}=s.useEditorActions(),{data:y}=s.useTopoJson(a);if(!a.id)return null;let i;u!=null&&u.records&&(u==null?void 0:u.records.length)>0&&(i=s.createChartConfig({data:u==null?void 0:u.records,cardType:a.type,cfg:a.cfg,customCfg:a.customCfg,preferences:a.preferences,topoJson:y}));function f(j){return e.jsx(wt,{card:j})}function p(){var j;if(u!=null&&u.records&&(u==null?void 0:u.records.length)===0&&!x&&!h)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 f(a);if(!["table","custom"].includes(a.type)&&i)return e.jsx(s.ChartJsVisual,{cfg:i},JSON.stringify(i)+JSON.stringify(a.preferences)+((j=a==null?void 0:a.preferences)==null?void 0:j.customVisualCode));if(a.type==="table"&&(u!=null&&u.records)&&(u==null?void 0:u.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:u==null?void 0:u.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:j=>g({...a,title:j}),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:j=>g({...a,description:j}),children:e.jsx(s.CardDescription,{children:a.description||"Edit description..."})},a.description)]}),d&&e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(s.Editable,{className:"my-1",text:d.title||d.column,onSave:j=>c({...d,title:j}),children:e.jsx(s.Label,{children:d.title})}),e.jsx(s.FilterComponent,{filter:d})]})]}),e.jsx(s.CardContent,{className:"flex grow flex-col",children:p()})]})}const Me=({language:t,value:n,onChange:a,readonly:r})=>e.jsx(s.Ft,{className:"h-full w-full overflow-hidden text-xs",theme:"default",options:{minimap:{enabled:!1},wordWrap:"on",scrollbar:{verticalScrollbarSize:0,horizontalScrollbarSize:0},fontSize:12,lineHeight:16,renderLineHighlight:"none",readOnly:r},defaultLanguage:t,value:n,onChange:a}),kt=()=>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."})]})]}),Et=({customCode:t,customConfig:n,onConfigChange:a,onCodeChange:r})=>e.jsxs(s.Tabs,{defaultValue:"final-config",className:"flex w-1/2 flex-col",children:[e.jsxs(s.TabsList,{className:"justify-start rounded-sm rounded-b-none border border-b-0",children:[e.jsx(s.TabsTrigger,{value:"final-config",children:"Config"}),e.jsx(s.TabsTrigger,{value:"custom-code",children:"Custom Code"})]}),e.jsx(s.TabsContent,{value:"final-config",className:"mt-0 grow rounded-b border border-t-0",children:e.jsx(Me,{language:"json",value:n,onChange:a})}),e.jsx(s.TabsContent,{value:"custom-code",className:"mt-0 grow rounded-b border border-t-0",children:e.jsx(Me,{language:"javascript",value:t,onChange:r})})]}),It=({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 Dt(){const[t,n]=C.useState(!1),[a,r]=C.useState(""),[o,l]=C.useState(""),[c,d]=C.useState(""),[u,x]=C.useState(""),h=s.useEditorStore(v=>v.card),g=s.useEditorStore(v=>v.card.customCfg),{data:y}=s.useDashboardCardQuery(h),{data:i}=s.useTopoJson(h),{setCardCustomCfg:f,setCustomVisualCode:p}=s.useEditorActions(),S=v=>{var I,M;return JSON.stringify({...v,data:{...v.data,datasets:(M=(I=v.data)==null?void 0:I.datasets)==null?void 0:M.map(L=>({...L,data:[]}))}},null,2)},j=()=>{var I,M;if(!((I=y==null?void 0:y.records)!=null&&I.length))return;const v=s.createChartConfig({data:y.records,cardType:h.type,cfg:h.cfg,preferences:h.preferences,topoJson:i});if(v){r(S(v)),d(((M=h.preferences)==null?void 0:M.customVisualCode)||"");const L=s.merge(v,g);l(S(L))}},w=()=>{try{if(c&&p(c),o){const v=JSON.parse(o),I=s.getObjectDiff(JSON.parse(a),v);f(I),x("")}}catch{x("Invalid JSON configuration")}};return e.jsxs(s.Dialog,{open:t,onOpenChange:n,children:[e.jsx(s.DialogTrigger,{asChild:!0,children:e.jsx(s.IconButton,{tooltip:"Customize Visual",onClick:j,className:g?"text-green-600 hover:text-green-700":"",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(kt,{}),e.jsxs("div",{className:"flex grow gap-2",children:[e.jsx(s.ErrorBoundary,{FallbackComponent:s.FallbackEditorCard,children:e.jsx(ts,{className:"w-1/2 rounded shadow-none"})}),e.jsx(Et,{customCode:c,customConfig:o,onConfigChange:v=>l(v??""),onCodeChange:v=>d(v??"")})]}),e.jsx(It,{error:u,hasCustomConfig:!!g,onReset:()=>{l(a),f(null)},onApply:w,onClose:()=>n(!1)})]})]})}function as(t){return le({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 Tt(t){return le({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 ns(t){return le({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 rs(t){return le({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 os(t){return le({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 is(t){const[n,a]=C.useState(null);return n}function ls(){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 Lt({onChartTypeChange:t}){const[n,a]=C.useState([]),{data:r}=ls();return C.useEffect(()=>{(async()=>{var l;if(r){const d=(await Promise.all((l=r==null?void 0:r.plugins)==null?void 0:l.map(async u=>(await s.loadManifest(u.value)).visuals.map(g=>({name:g.name,icon:g.icon,url:u.value}))))).flat();a(d)}})()},[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,l)=>e.jsx(At,{text:o.name,onClick:()=>t("custom",o),icon:o.icon},o.url+o.name+l))})]})}const At=({text:t,icon:n,onClick:a})=>{const r=is(),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 Ot(){var h,g;const[t,n]=C.useState(!1),a=s.useEditorStore(y=>y.card),r=a.type,{setCardType:o,setCardPreferences:l,setChartOrientation:c}=s.useEditorStore(y=>y.actions),{setCardCustomCfg:d,setCustomCardPreferences:u}=s.useEditorActions();function x(y,i){d(null),l({}),o(y),i&&u({type:"component",visualType:"single",url:i.url,componentName:i.name,icon:i.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:"ghost",children:e.jsx(Mt,{className:"size-4",chartType:r,customIcon:(h=a.customCardPreferences)==null?void 0:h.icon,componentName:(g=a.customCardPreferences)==null?void 0:g.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:()=>x("bar"),className:"font-normal",variant:"ghost",children:e.jsx(Ce,{className:"size-5"})}),e.jsx(s.Button,{onClick:()=>x("line"),variant:"ghost",children:e.jsx(ve,{className:"size-5"})}),e.jsx(s.Button,{onClick:()=>x("stackedBar"),variant:"ghost",children:e.jsx(Ve,{className:"size-5"})}),e.jsx(s.Button,{onClick:()=>x("stackedLine"),variant:"ghost",children:e.jsx(rs,{className:"size-5",strokeWidth:0})}),e.jsx(s.Button,{onClick:()=>x("scatter"),variant:"ghost",children:e.jsx(Be,{className:"size-5"})}),e.jsx(s.Button,{onClick:()=>x("bubble"),variant:"ghost",children:e.jsx(ns,{className:"size-5"})}),e.jsx(s.Button,{onClick:()=>x("pie"),variant:"ghost",children:e.jsx(qe,{className:"size-5"})}),e.jsx(s.Button,{onClick:()=>x("doughnut"),variant:"ghost",children:e.jsx(Pe,{className:"size-5"})}),e.jsx(s.Button,{onClick:()=>x("radar"),variant:"ghost",children:e.jsx(Ge,{className:"size-5"})}),e.jsx(s.Button,{onClick:()=>x("polarArea"),variant:"ghost",children:e.jsx(as,{className:"size-6"})}),e.jsx(s.Button,{onClick:()=>x("pyramid"),variant:"ghost",children:e.jsx(Qe,{className:"size-5"})}),e.jsx(s.Button,{onClick:()=>x("range"),variant:"ghost",children:e.jsx(Re,{className:"size-5"})}),e.jsx(s.Button,{onClick:()=>x("table"),variant:"ghost",children:e.jsx(s.Table2,{className:"size-5"})}),e.jsx(s.Button,{onClick:()=>x("kpi"),variant:"ghost",children:e.jsx(os,{className:"size-6"})}),e.jsx(s.Button,{onClick:()=>x("text"),variant:"ghost",children:e.jsx(bs,{className:"size-5"})}),e.jsx(s.Button,{onClick:()=>x("map"),variant:"ghost",children:e.jsx(He,{className:"size-5"})}),e.jsx(s.Button,{onClick:()=>x("custom"),variant:"ghost",children:e.jsx(Ue,{className:"size-5"})})]}),e.jsx(Lt,{onChartTypeChange:x})]})]})}function Mt({chartType:t,className:n,customIcon:a,componentName:r}){const o=is();switch(t){case"bar":return e.jsx(Ce,{className:n});case"line":return e.jsx(ve,{className:n});case"pie":return e.jsx(qe,{className:n});case"radar":return e.jsx(Ge,{className:n});case"scatter":return e.jsx(Be,{className:n});case"bubble":return e.jsx(ns,{className:n});case"doughnut":return e.jsx(Pe,{className:n});case"stackedBar":return e.jsx(Ve,{className:n});case"stackedLine":return e.jsx(rs,{className:n});case"polarArea":return e.jsx(as,{className:n});case"pyramid":return e.jsx(Qe,{className:n});case"range":return e.jsx(Re,{className:n});case"kpi":return e.jsx(os,{className:n});case"text":return e.jsx(Je,{className:n});case"map":return e.jsx(He,{className:n});case"custom":return a&&o?e.jsx(o,{className:n}):r?r==null?void 0:r.charAt(0).toUpperCase():e.jsx(Ue,{className:n});default:return e.jsx(s.Table2,{className:n})}}function zt(){const t=s.useEditorStore(d=>{var u,x,h,g;return(g=(h=(x=(u=d.card.preferences)==null?void 0:u.chartOptions)==null?void 0:x.plugins)==null?void 0:h.legend)==null?void 0:g.position}),n=s.useEditorStore(d=>{var u,x,h,g;return(g=(h=(x=(u=d.card.preferences)==null?void 0:u.chartOptions)==null?void 0:x.plugins)==null?void 0:h.legend)==null?void 0:g.align}),a=s.useEditorStore(d=>{var u,x,h,g;return(g=(h=(x=(u=d.card.preferences)==null?void 0:u.chartOptions)==null?void 0:x.plugins)==null?void 0:h.legend)==null?void 0:g.display}),{setLegendOptions:r}=s.useEditorActions(),o=d=>{r({display:d,position:t,align:n})},l=d=>{r({display:a,position:d,align:n})},c=d=>{r({display:a,position:t,align:d})};return e.jsxs(s.Popover,{children:[e.jsx(s.PopoverTrigger,{asChild:!0,children:e.jsx(s.IconButton,{tooltip:"Legend Settings",children:e.jsx(zs,{className:"size-4"})})}),e.jsx(s.PopoverContent,{className:"w-72",children:e.jsxs("div",{className:"grid gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("h4",{className:"font-medium leading-none",children:"Legend Options"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Set the legend options for the chart."})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsxs("div",{className:"grid grid-cols-3 items-center gap-4",children:[e.jsx(s.Label,{htmlFor:"displayLegend",children:"Display"}),e.jsx("div",{className:"col-span-2 flex h-8 items-center",children:e.jsx(s.SmallSwitch,{checked:a,onCheckedChange:o,defaultChecked:!0,id:"displayLegend"})})]}),e.jsxs("div",{className:"grid grid-cols-3 items-center gap-4",children:[e.jsx(s.Label,{htmlFor:"position",children:"Position"}),e.jsxs(s.Select,{value:t,onValueChange:l,children:[e.jsx(s.SelectTrigger,{className:"col-span-2 h-8 focus:ring-1 focus:ring-offset-0",children:e.jsx(s.SelectValue,{placeholder:"Select Position"})}),e.jsxs(s.SelectContent,{children:[e.jsx(s.SelectItem,{value:"top",children:"Top"}),e.jsx(s.SelectItem,{value:"left",children:"Left"}),e.jsx(s.SelectItem,{value:"bottom",children:"Bottom"}),e.jsx(s.SelectItem,{value:"right",children:"Right"})]})]})]}),e.jsxs("div",{className:"grid grid-cols-3 items-center gap-4",children:[e.jsx(s.Label,{htmlFor:"align",children:"Align"}),e.jsxs(s.Select,{value:n,onValueChange:c,children:[e.jsx(s.SelectTrigger,{className:"col-span-2 h-8 focus:ring-1 focus:ring-offset-0",children:e.jsx(s.SelectValue,{placeholder:"Select Alignment"})}),e.jsxs(s.SelectContent,{children:[e.jsx(s.SelectItem,{value:"start",children:"Start"}),e.jsx(s.SelectItem,{value:"center",children:"Center"}),e.jsx(s.SelectItem,{value:"end",children:"End"})]})]})]})]})]})})]})}function ze(){var R;const t=s.useEditorStore(b=>b.frame),n=s.useEditorStore(b=>b.card),a=s.useEditorStore(b=>b.isShowingVisual),r=s.useEditorStore(b=>b.isSqlRunning),o=s.useEditorStore(b=>b.pythonStdOut),l=s.useEditorStore(b=>{var E;return(E=b.card.preferences)==null?void 0:E.chartOptions});s.useEditorStore(b=>b.actions.setRunSql);const c=s.getChartGridStyle(l),{setFrame:d,setCard:u,updateCardInFrame:x,setActiveTabCardId:h,runAssistant:g,setChartGrid:y}=s.useEditorActions(),{data:i,isLoading:f,isFetching:p,error:S}=s.useDashboardCardQuery(n);if(!n)return e.jsx(e.Fragment,{children:"No Active Card"});function j(){const b={connectionId:n.connectionId,id:s.v4(),title:"Title",description:"Description",preferences:{onClickFilter:[{columnIndex:0,expression:""}]},type:"bar",sql:"",data:[]};w(b)}function w(b){const E={...t,cards:[...t.cards,b],activeCardId:b.id};d(E),h(b.id)}function v(){const b={...n,id:s.v4(),title:`${n.title} Copy`,tabTitle:`${n.tabTitle||n.title} Copy`};w(b)}function I(b){const E=t.cards.filter(U=>U.id!==b),F=E[0],$={...t,cards:E,activeCardId:F.id};d($),h(F.id),u(F)}function M(b){h(b)}const L=(b,E)=>{console.log("handleDragStart",E),b.dataTransfer.setData("tabIndex",E.toString())},q=b=>{b.preventDefault()},V=(b,E)=>{const F=b.dataTransfer.getData("tabIndex");if(F===E.toString())return;const $=Array.from(t.cards),[U]=$.splice(parseInt(F),1);$.splice(E,0,U),d({...t,cards:$})};function B(b,E){return b.cards.length===1&&(E.displayTab===!0||E.displayTab===void 0)||b.activeCardId!==E.id&&(E.displayTab===!0||E.displayTab===void 0)?null:e.jsx("div",{onClick:()=>{const F=E.displayTab===void 0?!1:!E.displayTab;u({...E,displayTab:F}),x({...E,displayTab:F})},children:E.displayTab===!0||E.displayTab===void 0?e.jsx(s.Eye,{className:"mr-2 size-3.5 text-muted-foreground hover:text-foreground"}):e.jsx(Is,{className:"mr-2 size-3.5 text-muted-foreground hover:text-foreground"})})}function m(){return e.jsxs(s.Tabs,{onValueChange:M,value:t.activeCardId,className:"flex grow flex-col",children:[t.cards.map(b=>e.jsx(s.TabsContent,{className:"mt-0 grow",value:b.id,children:O()},b.id)),e.jsx(s.TabsList,{className:"group mx-6 justify-between",children:e.jsxs("div",{className:"flex items-center",children:[t.cards.map((b,E)=>e.jsx(s.Editable,{text:b.tabTitle||b.title,onSave:F=>{u({...n,tabTitle:F}),x({...n,tabTitle:F})},children:e.jsxs(s.TabsTrigger,{draggable:!0,onDragStart:F=>L(F,E),onDragOver:q,onDrop:F=>V(F,E),className:"",value:b.id,children:[B(t,b),b.tabTitle||b.title,t.activeCardId===b.id&&t.cards.length>1&&e.jsx(s.X,{className:"ml-2 size-3.5 text-muted-foreground hover:text-foreground",onClick:()=>I(b.id)})]})},b.id)),e.jsx(s.Button,{className:"ml-1 h-8 px-2 hover:bg-muted-foreground/50",variant:"outline",onClick:j,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:v,children:e.jsx(ws,{className:"h-4 w-4"})})]})})]})}function O(){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:i==null?void 0:i.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:i==null?void 0:i.records})})})}):e.jsx(s.ErrorBoundary,{FallbackComponent:s.FallbackEditorCard,children:e.jsx(ts,{className:"grow border-none shadow-none"})})}function H(){const b=JSON.stringify(i==null?void 0:i.records,null,2),E=new Blob([b],{type:"application/json"}),F=URL.createObjectURL(E),$=document.createElement("a");$.href=F,$.download=`${n.title}.json`,$.click()}function A(){const E=[Object.keys(i==null?void 0:i.records.reduce((z,T)=>({...z,...T}),{})).join(","),...((i==null?void 0:i.records)||[]).map(z=>Object.values(z).join(","))].join(`
252
+ `),F=new Blob([E],{type:"text/csv"}),$=URL.createObjectURL(F),U=document.createElement("a");U.href=$,U.download=`${n.title}.csv`,U.click()}function P(){const b=`Can you get the documentation for ${n.type} chart?`;g(b)}function G(){const b=["xy","none","x","y"],F=(b.indexOf(c)+1)%b.length;y(b[F])}return e.jsxs("div",{className:"relative flex h-full flex-col py-3",children:[(f||p)&&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(he,{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",children:[e.jsx(Ot,{}),e.jsx(s.IconButton,{tooltip:"Visual Docs",onClick:P,children:e.jsx(js,{className:"size-4"})}),!["table","custom"].includes(n.type)&&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:A,children:e.jsx(Tt,{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:H,children:e.jsx(Ds,{strokeWidth:1.5,className:"size-4"})}),e.jsx(s.CopyButton,{text:JSON.stringify(i==null?void 0:i.records,null,2),className:"h-7 w-fit px-1 font-mono text-xs text-muted-foreground/70"})]}),a&&e.jsxs("div",{className:"flex items-center",children:[!["kpi","text","custom","table"].includes(n.type)&&e.jsx(zt,{}),!["pie","doughnut","radar","polarArea","table","custom","kpi","text","map"].includes(n.type)&&e.jsxs(s.IconButton,{tooltip:"Grid Style",onClick:G,children:[(c==="xy"||!c)&&e.jsx(Ls,{className:"size-4"}),c==="x"&&e.jsx(Ns,{className:"size-4"}),c==="y"&&e.jsx(Hs,{className:"size-4"}),c==="none"&&e.jsx(Qs,{className:"size-4"})]})]}),e.jsx(Vt,{})]}),a?m():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(Ft,{})}),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:[(i==null?void 0:i.records)&&(i==null?void 0:i.records.length)>0&&e.jsx(Nt,{data:(i==null?void 0:i.records)||[]}),(S||(i==null?void 0:i.error))&&e.jsx("span",{className:"font-mono text-xs",children:(S==null?void 0:S.message)||((R=i==null?void 0:i.error)==null?void 0:R.message)}),e.jsx(s.ScrollBar,{orientation:"horizontal"})]})})]})]})}function Ft(){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 Vt(){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.SmallSwitch,{checked:t,onCheckedChange:()=>n(!t),id:"visualize",className:"data-[state=checked]:bg-foreground/50"})]})}function Rt({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 te({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(l=>e.jsx(s.SelectItem,{value:l.value,children:l.label},l.value))]})})]})}function ue({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 qt(){var p,S;const t=s.useEditorStore(j=>j.card.customCardPreferences),{data:n}=ls(),a=(n==null?void 0:n.plugins)||[],r=s.useEditorStore(j=>j.card),o=s.useEditorStore(j=>j.frame),l=(t==null?void 0:t.visualType)||"single",{setCustomCardPreferences:c}=s.useEditorActions(),{components:d,manifest:u}=s.useCustomVisual((t==null?void 0:t.url)||""),x=(p=u==null?void 0:u.visuals)==null?void 0:p.find(j=>j.name===(t==null?void 0:t.componentName));function h(j,w){if(!t)return;const I={...(t==null?void 0:t.dataInputCardIds)||{},[j]:{cardId:w,hookRef:null}};c({...t,dataInputCardIds:I})}function g(j){var v,I;const w=(v=o==null?void 0:o.cards)==null?void 0:v.filter(M=>{var L;return((L=M==null?void 0:M.customCardPreferences)==null?void 0:L.visualType)!=="multiple"}).map(M=>({value:M.id,label:M.tabTitle||M.title}));return e.jsx("div",{className:"space-y-2",children:(I=j==null?void 0:j.dataInputs)==null?void 0:I.map((M,L)=>{var q,V;return e.jsxs("div",{className:"grid grid-cols-10 gap-2",children:[e.jsx("div",{className:"col-span-4 flex items-center",children:M}),e.jsx(te,{className:"col-span-6 h-8 w-full justify-between",label:"",options:w||[],value:((V=(q=t==null?void 0:t.dataInputCardIds)==null?void 0:q[L])==null?void 0:V.cardId)||"",onValueChange:B=>h(L,B)})]},L+Math.random())})})}function y(j,w,v=[]){var I,M;return t?j==="input"?e.jsx(s.Input,{className:`h-8 w-full ${s.removeRing}`,value:((I=t==null?void 0:t.settings)==null?void 0:I[w])||"",onChange:L=>{c({...t,settings:{...t==null?void 0:t.settings,[w]:L.target.value}})}},w):j==="select"?e.jsx(te,{className:"h-8 w-full",label:"",options:v,value:((M=t==null?void 0:t.settings)==null?void 0:M[w])||"",onValueChange:L=>{c({...t,settings:{...t==null?void 0:t.settings,[w]:L}})}}):null:null}function i(j){const w=Object.entries((j==null?void 0:j.settings)||{});return e.jsx("div",{className:"space-y-3",children:w.map(([v,I])=>e.jsxs("div",{className:"space-y-2",children:[e.jsx(s.Label,{children:I.title}),y(I.ui,v,I.options)]},v))})}function f(j){t&&c({...t,visualType:j,componentName:""})}return e.jsxs("div",{className:"p-6",children:[e.jsx(ue,{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(te,{className:"h-8 w-full",label:"",options:a,value:(t==null?void 0:t.url)||"",onValueChange:j=>c({...t||{url:"",componentName:""},url:j})})})}),((t==null?void 0:t.type)==="component"||(t==null?void 0:t.type)===void 0)&&e.jsx(Rt,{options:[{value:"single",label:"Single Visual"},{value:"multiple",label:"Multi-Visual"}],value:l,onValueChange:f}),((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:d&&e.jsx(te,{className:"h-8 w-full",label:"",options:(d==null?void 0:d.filter(j=>j.type===l).map(j=>({value:j.name,label:j.name})))||[],value:t.componentName,onValueChange:j=>{console.log("changing value",j),c({...t,componentName:j})}})})]})})]})})}),e.jsx(s.Separator,{className:"my-4"}),((S=r==null?void 0:r.customCardPreferences)==null?void 0:S.componentName)&&e.jsxs(ue,{summary:"Component Settings",children:[x&&x.dataInputs&&e.jsxs("div",{className:"space-y-3",children:[e.jsx(s.Label,{children:"Input Mapping"}),e.jsx("div",{className:"px-2",children:g(x)})]}),x&&x.settings&&e.jsx("div",{className:"space-y-3",children:e.jsx("div",{className:"px-2",children:i(x)})})]})]})}function re(){const[t,n]=C.useState([]);s.useEditorStore(h=>h.card.cfg);const a=s.useEditorStore(h=>h.card.preferences),{setCardCfg:r,setFilterOnClickColumnIndex:o,setCardPreferences:l}=s.useEditorStore(h=>h.actions),c=s.useEditorStore(h=>h.queryResultColumns);s.useEditorStore(h=>{var g;return(g=h.card.preferences)==null?void 0:g.filterOnClickColumnIndex}),C.useEffect(()=>{c&&n(new Array(c.length).fill(!1))},[c]);function d(h,g){var y,i;g?a!=null&&a.onClickFilter&&((y=a==null?void 0:a.onClickFilter)==null?void 0:y.length)>0?l({...a,onClickFilter:[...a.onClickFilter,{columnIndex:h,expression:""}]}):l({...a,onClickFilter:[{columnIndex:h,expression:""}]}):(l({...a,onClickFilter:(i=a==null?void 0:a.onClickFilter)==null?void 0:i.filter(f=>f.columnIndex!==h)}),n(f=>{const p=[...f];return p[h]=!1,p}))}function u(h,g){var i;const y=(i=a==null?void 0:a.onClickFilter)==null?void 0:i.map(f=>f.columnIndex===h?{...f,expression:g.target.value}:f);l({...a,onClickFilter:y})}function x(h){var g,y,i,f;if(t!=null&&t[h]||(y=(g=a==null?void 0:a.onClickFilter)==null?void 0:g.find(p=>p.columnIndex===h))!=null&&y.expression)return e.jsx(s.Input,{value:(f=(i=a==null?void 0:a.onClickFilter)==null?void 0:i.find(p=>p.columnIndex===h))==null?void 0:f.expression,onChange:p=>u(h,p),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"}),c==null?void 0:c.map((h,g)=>{var y,i;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:!!((y=a==null?void 0:a.onClickFilter)!=null&&y.find(f=>f.columnIndex===g)),onCheckedChange:f=>d(g,f)}),e.jsx("label",{className:"text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70",children:h}),e.jsx("div",{className:"flex items-center gap-2",children:((i=a==null?void 0:a.onClickFilter)==null?void 0:i.find(f=>f.columnIndex===g))&&e.jsx(s.Pencil,{onClick:()=>{n(f=>{const p=[...f];return p[g]=!f[g],p})},className:"invisible size-3 cursor-pointer text-gray-400 group-hover:visible"})})]}),x(g)]})},h)})]})}function je(){var c,d,u;const t=s.useEditorStore(x=>x.card.preferences),n=s.useEditorStore(x=>x.card.cfg),{setCardCfg:a,setCardPreferences:r,setChartOrientation:o}=s.useEditorStore(x=>x.actions);(c=n==null?void 0:n.options)!=null&&c.indexAxis;function l(x){o(x)}return e.jsxs(s.RadioGroup,{value:((d=t==null?void 0:t.chartOptions)==null?void 0:d.indexAxis)||((u=n==null?void 0:n.options)==null?void 0:u.indexAxis)||"x",onValueChange:l,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 xe="focus-visible:ring-0 focus-visible:ring-ring focus-visible:ring-offset-0";function Fe(t,n){var r,o,l;const a=s.getNumberAxis(t,n);return((l=(o=(r=t==null?void 0:t.chartOptions)==null?void 0:r.scales)==null?void 0:o[a])==null?void 0:l.type)||"linear"}function cs(){var R,b,E,F,$,U;const[t,n]=C.useState(!1),a=s.useEditorStore(z=>{var T;return(T=z.card)==null?void 0:T.preferences}),r=s.useEditorStore(z=>{var T;return(T=z.card)==null?void 0:T.cfg}),o=s.getNumberAxis(a,r),[l,c]=C.useState(Fe(a)),[d,u]=C.useState(((E=(b=(R=a==null?void 0:a.chartOptions)==null?void 0:R.scales)==null?void 0:b[o])==null?void 0:E.min)||""),[x,h]=C.useState(((U=($=(F=a==null?void 0:a.chartOptions)==null?void 0:F.scales)==null?void 0:$[o])==null?void 0:U.max)||""),[g,y]=C.useState(d||x?"custom":"auto"),[i,f]=C.useState(""),[p,S]=C.useState(0),[j,w]=C.useState(""),[v,I]=C.useState(""),[M,L]=C.useState(""),q=s.useEditorStore(z=>z.actions.setCardPreferences),{updateCardInFrame:V}=s.useEditorActions(),B=s.useEditorStore(z=>z.card),m=s.useEditorStore(z=>{var T;return(T=z.card)==null?void 0:T.type}),O=["pie","doughnut","polarArea"].includes(m);C.useEffect(()=>{var z,T,Y,k,_,J,K,ae,se,Q,X,D,W,Z;c(Fe(a)),u(((Y=(T=(z=a==null?void 0:a.chartOptions)==null?void 0:z.scales)==null?void 0:T[o])==null?void 0:Y.min)===0?0:""),h(((J=(_=(k=a==null?void 0:a.chartOptions)==null?void 0:k.scales)==null?void 0:_[o])==null?void 0:J.max)||""),f(((Q=(se=(ae=(K=a==null?void 0:a.chartOptions)==null?void 0:K.scales)==null?void 0:ae[o])==null?void 0:se.ticks)==null?void 0:Q.stepSize)||""),S(((X=a==null?void 0:a.numberAxisFormat)==null?void 0:X.decimalPlaces)||0),w(((D=a==null?void 0:a.numberAxisFormat)==null?void 0:D.suffix)||""),I(((W=a==null?void 0:a.numberAxisFormat)==null?void 0:W.currency)||""),L(((Z=a==null?void 0:a.numberAxisFormat)==null?void 0:Z.locale)||"")},[t,a,o]);function H(z,T){return T===""||/^[0-9\b]+$/.test(T)?Number(T):Number(z)}function A(){const z=[...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:v||"none",onValueChange:T=>I(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"}),z.map(T=>e.jsx(s.SelectItem,{value:T,children:T},T))]})})]}),e.jsxs(s.Select,{value:M,onValueChange:T=>L(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:p,onChange:T=>S(Number(T.target.value)),id:"format",className:`col-span-6 h-8 w-full tracking-wide ${xe}`})]})]})}function P(){return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"grid grid-cols-3 items-center gap-2",children:[e.jsx(s.Label,{htmlFor:"range",children:"Range"}),e.jsx(s.Input,{id:"min",value:d,onChange:z=>u(T=>H(T,z.target.value)),className:`col-span-1 h-8 w-full ${xe}`}),e.jsx(s.Input,{value:x,onChange:z=>h(T=>H(T,z.target.value)),id:"max",className:`col-span-1 h-8 w-full ${xe}`})]}),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:i,onChange:z=>f(T=>H(T,z.target.value)),id:"step-size",className:`col-span-1 h-8 w-full ${xe}`})]})]})}function G(){var k;let z={};g==="custom"&&(z={min:d,max:x,ticks:{stepSize:i}});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:l,...l==="linear"?z:{}}}},numberAxisFormat:{decimalPlaces:p,suffix:j,currency:v,locale:M}};console.log(T),q(T);const Y={...B,preferences:T};V(Y)}return e.jsxs(s.Popover,{onOpenChange:z=>n(z),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:O,value:l,onValueChange:z=>c(z),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"})]})})]})]}),l=="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:O,id:"scale-option",value:g,onValueChange:z=>y(z),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"})]})]})]}),g==="custom"&&l=="linear"&&P(),A(),e.jsx(s.SelectSeparator,{}),e.jsx("div",{className:"grid grid-cols-3",children:e.jsx(s.Button,{onClick:G,variant:"secondary",className:"col-span-1 col-start-3 h-8 w-full",children:"Apply"})})]})]})})]})}function Bt({idx:t}){var d;const n=s.useEditorStore(u=>{var x;return(x=u.card)==null?void 0:x.preferences}),a=s.useEditorStore(u=>{var x;return(x=u.card.preferences)==null?void 0:x.datasetOptions}),r=s.useEditorStore(u=>u.actions.setCardPreferences),o=(d=n==null?void 0:n.chartOptions)==null?void 0:d.indexAxis,l=a==null?void 0:a.find(u=>u.idx===t);function c(u,x){(u==="end"||u==="start")&&s.getContrastColor(s.getCanvasBackgroundColor());const h={display:u!=="none",align:u,anchor:u,clamp:!0};if(!l)r({...n,datasetOptions:[...a||[],{idx:x,datalabels:h}]});else{const g={...l};g.datalabels=h;const y=a==null?void 0:a.map(i=>i.idx===x?g:i);r({...n,datasetOptions:y})}}return e.jsxs(s.Popover,{children:[e.jsx(s.PopoverTrigger,{children:e.jsx(Js,{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:()=>c("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:()=>c("start",t),size:"sm",variant:"secondary",className:"h-7 p-1 text-xs font-normal",children:e.jsx(Fs,{className:s.cn("h-4 w-4",{"rotate-90":o==="y"})})}),e.jsx(s.Button,{onClick:()=>c("center",t),size:"sm",variant:"secondary",className:"h-7 p-1 text-xs font-normal",children:e.jsx(Rs,{className:s.cn("h-4 w-4",{"rotate-90":o==="y"})})}),e.jsx(s.Button,{onClick:()=>c("end",t),size:"sm",variant:"secondary",className:"h-7 p-1 text-xs font-normal",children:e.jsx(Vs,{className:s.cn("h-4 w-4",{"rotate-90":o==="y"})})})]})})]})}function ds(){const t=s.useEditorStore(x=>x.card),n=s.useEditorStore(x=>{var h,g,y;return(y=(g=(h=x==null?void 0:x.card)==null?void 0:h.preferences)==null?void 0:g.chartOptions)==null?void 0:y.indexAxis}),{data:a}=s.useDashboardCardQuery(t),r=n==="y"?"Y axis":"X axis",o=n==="y"?"X axis":"Y axis",{keys:l,metricKeys:c,dimensionKeys:d}=s.getKeys((a==null?void 0:a.records)||[]);let u=c;if(["stackedBar","stackedLine"].includes(t.type)){const x=s.pivotData({dataArray:(a==null?void 0:a.records)||[],groupKey:d[0],pivotKey:d[1],valueKey:u[0]}),{metricKeys:h}=s.getKeys(x);u=h}return l.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:d[0],children:us(d[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(cs,{})]}),e.jsx("div",{className:"my-1 max-h-[125px] space-y-1 overflow-y-auto",children:u.map((x,h)=>e.jsx(Pt,{col:x,idx:h},x))})]})]})}function us(t,n=30){return t.length>n?t.slice(0,n)+"...":t}function Pt({col:t,idx:n}){const a=s.useEditorStore(d=>{var u;return(u=d.card)==null?void 0:u.preferences}),r=s.useEditorStore(d=>{var u;return(u=d.card.preferences)==null?void 0:u.datasetOptions}),o=r==null?void 0:r.find(d=>d.idx===n),{setCardPreferences:l}=s.useEditorStore(d=>d.actions);function c(d){if(!o)l({...a,datasetOptions:[...r||[],{idx:n,type:d==="area"?"line":d,fill:d==="area"?"origin":""}]});else{const u={...o};u.type=d==="area"?"line":d,u.fill=d==="area"?"origin":"";const x=r==null?void 0:r.map(h=>h.idx===n?u:h);l({...a,datasetOptions:x})}}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:us(t)}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(Ce,{onClick:()=>c("bar"),className:"invisible size-4 cursor-pointer text-muted-foreground hover:text-foreground group-hover:visible"}),e.jsx(ve,{onClick:()=>c("line"),className:"invisible size-4 cursor-pointer text-muted-foreground hover:text-foreground group-hover:visible"}),e.jsx(Cs,{onClick:()=>c("area"),className:"invisible size-4 cursor-pointer text-muted-foreground hover:text-foreground group-hover:visible"}),e.jsx(Bt,{idx:n})]})]})}function hs(){const t=s.useEditorStore(i=>i.selectedConnectionId),n=s.useEditorStore(i=>i.selectedDatamodelId),a=s.useEditorStore(i=>i.selectedDatabaseName),r=s.useEditorStore(i=>i.selectedSchemaName),o=s.useEditorStore(i=>i.selectedTableName),l=s.useDashboardStore(i=>i.dashboard.filters)||[],c=s.useDashboardStore(i=>i.actions.addFilter),d=s.useDashboardStore(i=>i.actions.removeFilter),{removeFilterValues:u}=s.useDashboardActions(),{modelItems:x,tableName:h,connectionType:g}=ne();function y(i,f="dashboard"){var q;const p=s.fmt(i.column_name),S=s.fmt(a||""),j=s.fmt(r||""),w=s.fmt(h);let v=s.getQualifiedTableName(j,w,g),I=`${v}.${p}`;const M=(q=x==null?void 0:x.find(V=>V.id===n))==null?void 0:q.name;n&&n!=="none"&&(I=`${s.DATAMODEL_NAMESPCACE}.${M}.${p}`,v=`${s.DATAMODEL_NAMESPCACE}.${M}`);const L=l==null?void 0:l.find(V=>V.column===I&&V.table===w&&(V.database===S||V.database===a));if(L)u(L.id),d(L.id);else{const V=s.v4();return h==="api"&&t?(c({location:f,id:V,column:I,title:i.column_name,dataType:i.data_type,table:"api",database:"",connectionId:t,operation:"in",sql:s.getDefaultFilterSql(i.data_type,v,p)}),V):(c({id:V,location:f,column:I,title:i.column_name,dataType:i.data_type,table:o||"",database:a||"",connectionId:t||"",operation:"in",sql:s.getDefaultFilterSql(i.data_type,v,p)}),V)}}return{assignFilter:y}}function ce(){const t=s.useDashboardStore(d=>d.dashboard.filters),n=s.useEditorStore(d=>d.frame),{setFrame:a}=s.useEditorActions(),{columns:r}=ne(),{assignFilter:o}=hs();function l(d){const u=o(d,"frame");a({...n,filterId:u})}const c=t==null?void 0:t.find(d=>d.id===n.filterId);return e.jsxs("div",{className:"space-y-3",children:[e.jsx(s.Label,{children:"Card Filter"}),e.jsx(_t,{onSelect:l,columns:r}),c&&e.jsx(s.FilterHeader,{filter:c})]})}function _t({columns:t,onSelect:n}){var c;const[a,r]=ie.useState(!1),[o,l]=ie.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?(c=t.find(d=>d.column_name===o))==null?void 0:c.column_name:"Select Column...",e.jsx(s.CaretSortIcon,{className:"ml-2 h-4 w-4 shrink-0 opacity-50"})]})}),e.jsx(s.PopoverContent,{className:"w-[200px] p-0",children:e.jsxs(s.Command,{children:[e.jsx(s.CommandInput,{placeholder:"Search column",className:"h-9"}),e.jsxs(s.CommandList,{children:[e.jsx(s.CommandEmpty,{children:"No framework found."}),e.jsx(s.CommandGroup,{children:t.map(d=>e.jsxs(s.CommandItem,{value:d.column_name,onSelect:u=>{const x=u===o?"":u;l(x),r(!1),x&&n(d)},children:[d.column_name,e.jsx(s.CheckIcon,{className:s.cn("ml-auto h-4 w-4",o===d.column_name?"opacity-100":"opacity-0")})]},d.column_name))})]})]})})]})}function Ht({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(je,{}),e.jsx(ds,{})]})]}),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(re,{}),e.jsx(ce,{})]})]})]})})}function we(){var o,l,c;const t=s.useEditorStore(d=>d.card.cfg),n=s.useEditorStore(d=>d.actions.setCardCfg),a=s.useEditorStore(d=>d.card.type);function r(d){var h;const u={datalabels:{display:d!=="none",align:d,anchor:d,clamp:!0}},x={...t,options:{...t==null?void 0:t.options,plugins:{...(h=t==null?void 0:t.options)==null?void 0:h.plugins,...u}}};n(x),console.log(d)}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(cs,{})]}),e.jsxs(s.Select,{value:(c=(l=(o=t==null?void 0:t.options)==null?void 0:o.plugins)==null?void 0:l.datalabels)==null?void 0:c.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 Gt({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 (optional) - category"}),e.jsx("li",{children:"x-axis - number"}),e.jsx("li",{children:"y-axis - number"}),a==="bubble"&&e.jsx("li",{children:"radius - number"})]}),e.jsxs("div",{children:["See ",e.jsx("a",{target:"_blank",onClick:l=>l.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(we,{})})]}),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(re,{}),e.jsx(ce,{})]})]})]})})}const $t={datasets:[{type:"line",label:"Sum_sales",data:[]},{type:"bar",label:"Sum_profit",data:[]}]},Ut={datasets:[{fill:"origin",type:"line",label:"Sum_sales",data:[]}]};function Qt(){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:Jt(t)}),e.jsx("section",{className:"",children:["line","bar"].includes(t)&&e.jsx(je,{})}),!["kpi"].includes(t)&&e.jsxs("div",{className:"space-y-4",children:[e.jsx(we,{}),e.jsx(re,{}),e.jsx(ce,{})]})]})}function Jt(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($t,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(Ut,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 Wt(){var u,x,h,g,y;const t=s.useEditorStore(i=>i.card.preferences),n=s.useEditorStore(i=>i.actions.setCardPreferences),a=s.useEditorStore(i=>i.actions.setNumberFormat);s.useEditorStore(i=>{var f,p;return(p=(f=i.card.preferences)==null?void 0:f.formatNumber)==null?void 0:p.decimalPlaces});const r=s.useEditorStore(i=>{var f,p;return(p=(f=i.card.preferences)==null?void 0:f.formatNumber)==null?void 0:p.locale}),o=s.useEditorStore(i=>{var f,p;return(p=(f=i.card.preferences)==null?void 0:f.formatNumber)==null?void 0:p.currency});s.useEditorStore(i=>i.actions.setFilterOnClickField);const l=s.useEditorStore(i=>{var f,p;return(p=(f=i.card.preferences)==null?void 0:f.formatNumber)==null?void 0:p.colorRanges})||[],c=s.useEditorStore(i=>i.actions.setColorRanges),d=[...new Set(s.LOCALE_CURRENCY_PAIRS.map(i=>i.currency))];return e.jsxs("div",{children:[e.jsxs("div",{className:"mb-3 flex items-center gap-2",children:[e.jsx(s.Checkbox,{checked:!!((u=t==null?void 0:t.formatNumber)!=null&&u.enabled),onCheckedChange:i=>{n({...t,formatNumber:{...t==null?void 0:t.formatNumber,enabled:i}})}}),e.jsx(s.Label,{children:"Format Number"})]}),((x=t==null?void 0:t.formatNumber)==null?void 0:x.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:i=>{var f,p,S;return a(((f=t==null?void 0:t.formatNumber)==null?void 0:f.decimalPlaces)||0,((p=t==null?void 0:t.formatNumber)==null?void 0:p.currency)||"",i,((S=t==null?void 0:t.formatNumber)==null?void 0:S.suffix)||"")},children:[e.jsx(s.SelectTrigger,{className:"col-span-6 h-8 w-full focus:ring-1 focus:ring-offset-0",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{children:e.jsxs(s.SelectGroup,{children:[e.jsx(s.SelectLabel,{children:"Format"}),e.jsx(s.SelectItem,{value:"none",children:"None"},"none"),s.LOCALE_CURRENCY_PAIRS.map(i=>e.jsx(s.SelectItem,{value:i.locale,children:i.locale},i.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:i=>{var f,p,S;console.log("currency",i),a(((f=t==null?void 0:t.formatNumber)==null?void 0:f.decimalPlaces)||0,i==="none"?"":i,((p=t==null?void 0:t.formatNumber)==null?void 0:p.locale)||"",((S=t==null?void 0:t.formatNumber)==null?void 0:S.suffix)||"")},children:[e.jsx(s.SelectTrigger,{className:"col-span-6 h-8 w-full focus:ring-1 focus:ring-offset-0",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{children:e.jsxs(s.SelectGroup,{children:[e.jsx(s.SelectLabel,{children:"Currency"}),e.jsx(s.SelectItem,{value:"none",children:"None"},"none"),d.map(i=>e.jsx(s.SelectItem,{value:i,children:i},i))]})})]})]})]}),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:((g=(h=t==null?void 0:t.formatNumber)==null?void 0:h.decimalPlaces)==null?void 0:g.toString())||"0",onValueChange:i=>{var f,p,S;return a(Number(i),((f=t==null?void 0:t.formatNumber)==null?void 0:f.currency)||"",((p=t==null?void 0:t.formatNumber)==null?void 0:p.locale)||"",((S=t==null?void 0:t.formatNumber)==null?void 0:S.suffix)||"")},children:[e.jsx(s.SelectTrigger,{className:"col-span-3 h-8 w-full focus:ring-1 focus:ring-offset-0",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{children:["0","1","2","3","4"].map(i=>e.jsx(s.SelectItem,{value:i,children:i},i))})]})]}),e.jsxs("div",{className:"w-full space-y-1",children:[e.jsx(s.Label,{children:"Suffix"}),e.jsx(s.Input,{value:((y=t==null?void 0:t.formatNumber)==null?void 0:y.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:i=>{var f,p,S;return a(((f=t==null?void 0:t.formatNumber)==null?void 0:f.decimalPlaces)||0,((p=t==null?void 0:t.formatNumber)==null?void 0:p.currency)||"",((S=t==null?void 0:t.formatNumber)==null?void 0:S.locale)||"",i.target.value)}})]})]})]})}),e.jsx(s.Separator,{className:"my-3"}),e.jsx(s.ColorFormat,{colorRanges:l,setColorRanges:c})]})]})}function Kt(){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(Wt,{})}),e.jsx("div",{}),e.jsx("div",{})]})}const Xt=[{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"}],Yt=["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"],Zt=Yt.map(t=>({label:t,value:t}));function ea(){var u,x,h,g,y,i,f,p,S,j,w,v,I,M,L,q,V,B;const t=s.useEditorStore(m=>m.card),n=(x=(u=t==null?void 0:t.preferences)==null?void 0:u.mapVisualOptions)==null?void 0:x.topoJsonUrl,[a,r]=C.useState(((g=(h=t==null?void 0:t.preferences)==null?void 0:h.mapVisualOptions)==null?void 0:g.customTopoJsonUrl)||""),{setCardPreferences:o}=s.useEditorActions(),{data:l}=s.useTopoJson(t),c=Object.keys((l==null?void 0:l.objects)||{}).map(m=>({label:m,value:m}))||[],d=[{label:"US States 10m",value:"https://unpkg.com/us-atlas/states-10m.json"},{label:"Countries 50m",value:"https://unpkg.com/world-atlas/countries-50m.json"},{label:"Custom",value:"custom"}];return e.jsxs("div",{className:"p-6",children:[e.jsx(ue,{summary:"Map Chart",children:e.jsx("p",{className:"rounded-md bg-muted p-2 font-mono text-xs",children:"SELECT country, value FROM table"})}),e.jsx(s.Separator,{className:"my-4"}),e.jsx(ue,{open:!0,summary:"Settings",children:e.jsxs("div",{className:"space-y-3 px-2",children:[e.jsx(te,{className:"h-9",options:d,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"}),l&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(s.Label,{children:"Map Object"}),e.jsx(te,{className:"h-9",options:c,value:((i=(y=t.preferences)==null?void 0:y.mapVisualOptions)==null?void 0:i.objectKey)||"",label:"Map Object",onValueChange:m=>{var O;o({...t.preferences,mapVisualOptions:{...(O=t.preferences)==null?void 0:O.mapVisualOptions,objectKey:m}})}})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(s.Label,{children:"Projection"}),e.jsx(te,{className:"h-9",options:Xt,value:((p=(f=t.preferences)==null?void 0:f.mapVisualOptions)==null?void 0:p.projection)||"",label:"Projection",onValueChange:m=>{var O;o({...t.preferences,mapVisualOptions:{...(O=t.preferences)==null?void 0:O.mapVisualOptions,projection:m}})}})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(s.Label,{children:"Colors"}),e.jsx(te,{className:"h-9",options:Zt,value:((j=(S=t.preferences)==null?void 0:S.mapVisualOptions)==null?void 0:j.colorScale)||"",label:"Select Color Scale",onValueChange:m=>{var O;o({...t.preferences,mapVisualOptions:{...(O=t.preferences)==null?void 0:O.mapVisualOptions,colorScale:m}})}})]})]})]})}),e.jsx(s.Separator,{className:"my-4"}),e.jsx(ue,{className:"",summary:"Scale Options",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(s.Input,{className:`h-9 w-full ${s.removeRing}`,type:"number",step:.1,value:((v=(w=t.preferences)==null?void 0:w.mapVisualOptions)==null?void 0:v.projectionScale)||1,onChange:m=>{var O;o({...t.preferences,mapVisualOptions:{...(O=t.preferences)==null?void 0:O.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:((L=(M=(I=t.preferences)==null?void 0:I.mapVisualOptions)==null?void 0:M.projectionOffset)==null?void 0:L[0])||0,onChange:m=>{var O,H,A,P;o({...t.preferences,mapVisualOptions:{...(O=t.preferences)==null?void 0:O.mapVisualOptions,projectionOffset:[Number(m.target.value),((P=(A=(H=t.preferences)==null?void 0:H.mapVisualOptions)==null?void 0:A.projectionOffset)==null?void 0:P[1])||0]}})}}),e.jsx(s.Label,{children:"Y"}),e.jsx(s.Input,{className:`h-9 w-full ${s.removeRing}`,type:"number",step:10,value:((B=(V=(q=t.preferences)==null?void 0:q.mapVisualOptions)==null?void 0:V.projectionOffset)==null?void 0:B[1])||0,onChange:m=>{var O,H,A,P;o({...t.preferences,mapVisualOptions:{...(O=t.preferences)==null?void 0:O.mapVisualOptions,projectionOffset:[((P=(A=(H=t.preferences)==null?void 0:H.mapVisualOptions)==null?void 0:A.projectionOffset)==null?void 0:P[0])||0,Number(m.target.value)]}})}})]})}),e.jsx(s.Separator,{className:"my-4"}),e.jsx(re,{})]})}function sa(){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 pe({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(je,{}),t!=="text"&&e.jsx(we,{}),t==="text"&&e.jsx(sa,{})]})]}),!["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(re,{}),e.jsx(ce,{})]})]})]})})}function ta(){const t=s.useEditorStore(r=>{var o,l;return(l=(o=r==null?void 0:r.card)==null?void 0:o.preferences)==null?void 0:l.sortChart}),{setSortChart:n}=s.useEditorActions();function a(){return e.jsxs("div",{className:"space-y-2",children:[e.jsx(s.Label,{children:"Sort"}),e.jsx(te,{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(je,{}),a(),e.jsx(ds,{})]})]}),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(re,{}),e.jsx(ce,{})]})]})]})})}function aa({cardType:t="table"}){console.log("cardType",t);const n=s.useEditorStore(o=>{var l;return(l=o.card)==null?void 0:l.preferences}),a=s.useEditorStore(o=>o.actions.setCardPreferences),r=o=>{a({...n,allowDownload:o})};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(re,{}),e.jsx(ce,{})]})]})}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(s.Checkbox,{onCheckedChange:r,id:"allow-download"}),e.jsx("label",{htmlFor:"allow-download",className:"text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70",children:"Allow Download"})]})]})}const na=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."]})]}),ra=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."]})]}),oa=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 ia(){const t=s.useEditorStore(a=>a.card.type);function n(a){switch(a){case"stackedBar":case"stackedLine":return e.jsx(ta,{});case"pyramid":return e.jsx(pe,{docContent:na,cardType:a});case"kpi":return e.jsx(Kt,{});case"line":case"bar":return e.jsx(Ht,{cardType:a});case"range":return e.jsx(pe,{docContent:ra,cardType:a});case"pie":case"doughnut":case"polarArea":case"radar":return e.jsx(pe,{cardType:a});case"bubble":case"scatter":return e.jsx(Gt,{cardType:a});case"table":return e.jsx(aa,{cardType:a});case"text":return e.jsx(pe,{docContent:oa,cardType:a,suffix:"Visual"});case"map":return e.jsx(ea,{});case"custom":return e.jsx(qt,{});default:return e.jsx(Qt,{})}}return e.jsxs(s.ScrollArea,{className:"h-full w-full text-sm",children:[n(t),e.jsx(s.ScrollBar,{orientation:"horizontal"})]})}function la(){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(vt,{})}),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(ia,{})})}),e.jsx(s.ResizableHandle,{className:"border"}),e.jsx(s.ResizablePanel,{minSize:40,defaultSize:75,maxSize:100,children:e.jsx(ze,{})})]}):e.jsx(ze,{})})]})}function ca({authToken:t,onSave:n,onClose:a}){s.useDashboardStore(c=>c.themeStyle);const r=s.useEditorStore(c=>c.actions.setOnSave),o=s.useEditorStore(c=>c.actions.setOnClose),l=s.useDashboardStore(c=>c.actions.setAuthToken);return C.useEffect(()=>{n&&r(n),a&&o(a)},[n,r,a,o]),C.useEffect(()=>{t&&t.accessToken&&l(t)},[t,l]),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(Ye,{})}),e.jsx(s.EditorMain,{children:e.jsx(la,{})})]})})}function da(){s.useDashboardStore(c=>c.selectedCardId);const t=s.useDashboardStore(c=>c.selectedSheetId),{setIsVisualEditing:n}=s.useDashboardStore(c=>c.actions),a=s.useDashboardStore(c=>c.isVisualEditing),r=s.useDashboardStore(c=>c.actions.updateFrame);function o(c){t&&(r(t,c),n(!1))}function l(){n(!1)}return e.jsx("div",{role:"editor-container",className:s.cn("flex grow",{"max-h-0 overflow-hidden":!a}),children:e.jsx(ca,{onSave:o,onClose:l})})}function ua(){const t=s.useEditorStore(l=>l.selectedDatabaseName),n=s.useEditorStore(l=>l.selectedTableName),a=s.useDashboardStore(l=>l.dashboard.filters)||[],{columns:r}=ne(),{assignFilter:o}=hs();return e.jsx(s.ScrollArea,{className:"flex-1 basis-0 flex-col px-3",children:r==null?void 0:r.map(l=>{const c=a==null?void 0:a.find(d=>d.column===s.fmt(l.column_name)&&d.table===n&&d.database===t);return e.jsx("div",{onClick:()=>o(l),className:s.cn("group flex cursor-pointer items-center justify-between border border-dashed border-background px-3 py-[6px] text-sm transition-colors hover:bg-muted/50",{"bg-muted":c}),children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Xe,{column:l}),e.jsx("span",{children:l.column_name})]})},l.column_name)})})}function ha(){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(Ye,{ColumnsComponent:()=>e.jsx(ua,{})})})]})}function ma(){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 xa(){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(ma,{}),e.jsx(s.DashboardTabs,{})]}),t&&e.jsx("div",{role:"filter-aside-container",className:"flex",children:e.jsx(ha,{})})]})}function pa(){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 fa({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(pa,{}),e.jsxs(s.DashboardPanel,{...a,children:[t&&e.jsx(at,{}),e.jsx(da,{}),e.jsx(xa,{})]})]})]})})}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.resolveDatamodelName=s.resolveDatamodelName;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=oe;exports.Surfboard=fa;exports.cleanCard=We;exports.downloadPdf=Ke;exports.getDashbaordStateWithoutData=Ne;exports.useEditorAside=ne;