react-semaphor 0.0.414 → 0.0.416
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/chunks/{index-Dad5zgI7.js → index-C5WYD-0T.js} +6646 -6631
- package/dist/chunks/{index-BC5F6vck.js → index-DaWetboR.js} +81 -81
- package/dist/dashboard/index.cjs +1 -1
- package/dist/dashboard/index.js +1 -1
- package/dist/index.cjs +4 -4
- package/dist/index.js +1159 -1152
- package/dist/types/main.d.ts +9 -3
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("./chunks/index-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("./chunks/index-DaWetboR.js"),e=require("react/jsx-runtime"),S=require("react");require("react-dom");function vs(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 de=vs(S);/**
|
|
2
2
|
* @license lucide-react v0.453.0 - ISC
|
|
3
3
|
*
|
|
4
4
|
* This source code is licensed under the ISC license.
|
|
@@ -308,7 +308,7 @@
|
|
|
308
308
|
*
|
|
309
309
|
* This source code is licensed under the ISC license.
|
|
310
310
|
* See the LICENSE file in the root directory of this source tree.
|
|
311
|
-
*/const es=s.createLucideIcon("Type",[["polyline",{points:"4 7 4 4 20 4 20 7",key:"1nosan"}],["line",{x1:"9",x2:"15",y1:"20",y2:"20",key:"swin9y"}],["line",{x1:"12",x2:"12",y1:"4",y2:"20",key:"1tx1rr"}]]);function Ie(t){var n;return{...t,sheets:(n=t==null?void 0:t.sheets)==null?void 0:n.map(a=>{var r;return{...a,frames:(r=a.frames)==null?void 0:r.map(o=>{var c;return{...o,cards:(c=o.cards)==null?void 0:c.map(i=>ss(i))}})}})}}function ss(t){return{...t,customCfg:xt(t.customCfg),data:[]}}function xt(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 pt(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 ve(t,n){if(!n)return null;const{id:a,template:r,filterValues:o,isDefault:c,shared:i}=t;return await s.postRequest("https://semaphor.cloud/api/v1/lens",n,{lensId:a,template:r,filterValues:o,isDefault:c,shared:i,operation:"update"})}async function ft(t,n){return n?await s.postRequest("https://semaphor.cloud/api/v1/lens",n,{operation:"delete",lensId:t}):null}function gt(){const[t,n]=S.useState(""),[a,r]=S.useState(!1),o=s.useDashboardStore(p=>p.lenses),{setLenses:c,setSelectedLensId:i}=s.useDashboardActions(),[d,u]=S.useState(!1),[x,h]=S.useState(!1),f=s.useDashboardStore(p=>p.dashboard),b=s.useDashboardStore(p=>p.filterValues),{authToken:l}=s.useSemaphorContext();async function g(){u(!0);const p=Ie(f),C=await pt(t,p,b,l==null?void 0:l.accessToken);C&&(c([...o||[],C]),i(C.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"}),"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:g,disabled:d,children:d?"Creating...":"Add"})})]})]})}function jt(){const[t,n]=S.useState(!1),a=s.useDashboardStore(h=>h.lenses),r=s.useDashboardStore(h=>h.selectedLensId),{setLenses:o,setSelectedLensId:c}=s.useDashboardActions(),{authToken:i}=s.useSemaphorContext();async function d(h){c(h)}async function u(h){if(await ft(h,i==null?void 0:i.accessToken)){const b=a==null?void 0:a.filter(l=>l.id!==h);o(b||[]),c("original")}}async function x(h){const f=a==null?void 0:a.map(g=>g.id===h.id?{...g,isDefault:!h.isDefault}:{...g,isDefault:!1});o(f||[]);const b={...h,isDefault:!h.isDefault};await ve(b,i==null?void 0:i.accessToken);const l=a==null?void 0:a.find(g=>g.isDefault);if(l&&l.id!==h.id){const g={...l,isDefault:!1};await ve(g,i==null?void 0:i.accessToken)}}return e.jsxs(s.DropdownMenu,{open:t,onOpenChange:n,children:[e.jsx(s.DropdownMenuTrigger,{asChild:!0,children:e.jsx(s.IconButton,{tooltip:"Lenses",className:"h-7 p-2",children:e.jsx(Hs,{className:"h-4 w-4"})})}),e.jsxs(s.DropdownMenuContent,{align:"end",className:"w-60",children:[e.jsx(s.DropdownMenuLabel,{className:"px-3",children:"Lenses"}),e.jsx(s.DropdownMenuSeparator,{}),e.jsxs(s.DropdownMenuRadioGroup,{value:r,onValueChange:d,children:[e.jsx(s.DropdownMenuRadioItem,{value:"original",children:"Original"}),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(Qs,{onClick:f=>{f.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:f=>{f.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))]})]})]})}function ts(){var c;const t=s.useDashboardStore.getState().authToken,n=s.useDashboardStore.getState().theme,a=s.useDashboardStore.getState().filterValues,r=(c=s.useDashboardStore.getState().dashboard)==null?void 0:c.title,o=s.useDashboardStore.getState().selectedSheetId;return{authToken:t,theme:n||"light",filterValues:a,dashboardTitle:r||"",selectedSheetId:o||""}}async function as(){const t=s.useDashboardStore.getState().isDownloadingPdf,{authToken:n,theme:a,filterValues:r,dashboardTitle:o,selectedSheetId:c}=ts();if(t)return;const i=new URLSearchParams;i.set("token",(n==null?void 0:n.accessToken)||""),i.set("theme",a),i.set("filterValues",JSON.stringify(r)),i.set("selectedSheetId",c||"");const d=`https://semaphor.cloud/api/v1/generate-pdf?params=${encodeURIComponent(i.toString())}`;s.useDashboardStore.setState({isDownloadingPdf:!0});const h=(await(await fetch(d,{method:"GET",headers:{Authorization:`Bearer ${n==null?void 0:n.accessToken}`}})).json()).url,f=document.createElement("a");f.href=h;const b=`${o}-${new Date().toISOString()}.pdf`;f.download=b,f.click(),s.useDashboardStore.setState({isDownloadingPdf:!1})}function bt({iconClassName:t}){const{authToken:n}=s.useSemaphorContext();s.useDashboardStore(o=>{var c;return(c=o.dashboard)==null?void 0:c.title}),s.useDashboardStore(o=>o.theme),s.useDashboardStore(o=>o.filterValues);const a=s.useDashboardStore(o=>o.isDownloadingPdf);async function r(){await as()}return e.jsx(s.IconButton,{tooltip:"Download PDF",className:"h-7 p-2",onClick:r,children:a?e.jsx(ie,{className:s.cn("size-3.5 animate-spin",t)}):e.jsx(s.Download,{className:s.cn("size-4",t)})})}function se({defaultValue:t,label:n,options:a,value:r,onValueChange:o,className:c}){return e.jsxs(s.Select,{defaultValue:t,value:r,onValueChange:o,children:[e.jsx(s.SelectTrigger,{className:s.cn("w-full focus:ring-0 focus:ring-offset-0",c),children:e.jsx(s.SelectValue,{placeholder:n})}),e.jsx(s.SelectContent,{children:e.jsxs(s.SelectGroup,{children:[e.jsx(s.SelectLabel,{children:n}),a.map(i=>e.jsx(s.SelectItem,{value:i.value,children:i.label},i.value))]})})]})}const Oe=[{value:"daily",label:"Daily"},{value:"weekly",label:"Weekly"},{value:"biweekly",label:"Bi-Weekly"},{value:"monthly",label:"Monthly"}];function ns({triggerButtonClassName:t}){const{data:n,handleScheduleSubscription:a,handleDeleteSubscription:r,status:o,error:c,isDeleting:i}=yt(),[d,u]=S.useState(""),[x,h]=S.useState(Oe[0].value),[f,b]=S.useState("06:00"),[l,g]=S.useState("");return e.jsx(s.TooltipProvider,{delayDuration:0,children:e.jsxs(s.Popover,{children:[e.jsx(s.PopoverTrigger,{asChild:!0,children:e.jsx(s.IconButton,{tooltip:"Schedule Dashboard",className:s.cn("h-7 p-2",t),children:e.jsx(Fs,{className:"size-4"})})}),e.jsx(s.PopoverContent,{align:"end",className:"w-80",children:e.jsxs("div",{className:"grid gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("h4",{className:"font-medium leading-none",children:"Schedule Subscription"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Subscribe to receive dashboard via email"})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsxs("div",{className:"grid grid-cols-3 items-center gap-4",children:[e.jsx(s.Label,{htmlFor:"email",children:"Email"}),e.jsx(s.Input,{id:"email",value:d,onChange:p=>u(p.target.value),className:`col-span-2 h-8 ${s.removeRing}`})]}),e.jsxs("div",{className:"grid grid-cols-3 items-center gap-4",children:[e.jsx(s.Label,{htmlFor:"subject",children:"Subject"}),e.jsx(s.Input,{id:"subject",placeholder:"Monthly Sales Report",value:l,onChange:p=>{g(p.target.value.replace(/[^a-zA-Z0-9\s-_]/g,""))},className:`col-span-2 h-8 ${s.removeRing}`})]}),e.jsxs("div",{className:"grid grid-cols-3 items-center gap-4",children:[e.jsx(s.Label,{htmlFor:"frequency",children:"Frequency"}),e.jsx(se,{className:"col-span-2 h-8",label:"Select Frequency",options:Oe,value:x,onValueChange:p=>h(p)})]}),e.jsxs("div",{className:"grid grid-cols-3 items-center gap-4",children:[e.jsx(s.Label,{htmlFor:"time",children:"Time"}),e.jsx(s.Input,{id:"time",type:"time",value:f,onChange:p=>b(p.target.value),className:`col-span-2 h-8 ${s.removeRing}`})]}),e.jsx("div",{className:"mt-2 flex justify-end",children:e.jsxs(s.Button,{onClick:async()=>{await a({email:d,frequency:x,time:f,subject:l}),b("00:00"),u(""),g("")},className:"h-8 p-2",disabled:o==="loading"||!d,children:[o==="loading"&&e.jsx(ie,{className:"mr-2 size-4 animate-spin"}),o==="success"&&e.jsx(s.Check,{className:"mr-2 size-4"}),o==="error"&&e.jsxs(s.Tooltip,{children:[e.jsx(s.TooltipTrigger,{children:e.jsx($e,{className:"mr-2 size-4 text-destructive"})}),e.jsx(s.TooltipContent,{children:e.jsx("p",{children:c})})]}),"Schedule"]})}),n&&n.length>0&&e.jsxs("div",{className:"space-y-4",children:[e.jsx(s.Separator,{className:"my-2"}),e.jsx("div",{className:"space-y-2",children:e.jsxs("div",{className:"flex items-start justify-between",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("h4",{className:"font-medium leading-none",children:"Subscriptions"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Active email subscriptions"})]}),s.isDev]})}),e.jsx("div",{className:"grid gap-2",children:n==null?void 0:n.map(p=>e.jsxs("div",{className:"group grid grid-cols-5 gap-3",children:[e.jsx("div",{className:"col-span-3 text-sm",children:e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsxs("div",{className:"boder-border rounded-md border bg-muted px-2 py-1",children:[s.titleCase(p.frequency)," "]}),e.jsx(s.Label,{children:p.time})]})}),e.jsxs("div",{className:"col-span-2 flex items-center justify-end gap-4",children:[e.jsx(Fe,{tooltip:`Next Run: ${new Date(p.nextRun).toLocaleString()} ${p.timezone}`,children:e.jsx(Os,{className:"size-3.5"})}),e.jsx(Fe,{tooltip:`${p.endUserEmail}`,children:e.jsx(Xs,{className:"size-3.5"})}),i===p.id?e.jsx(ie,{className:"size-3.5 animate-spin"}):e.jsx(mt,{onClick:()=>r(p.id),className:"size-3.5 cursor-pointer"})]})]},p.id))})]})]})]})})]})})}const Fe=({children:t,tooltip:n})=>e.jsx(s.TooltipProvider,{delayDuration:0,children:e.jsxs(s.Tooltip,{children:[e.jsx(s.TooltipTrigger,{asChild:!0,children:t}),e.jsx(s.TooltipContent,{children:n})]})});function yt(){const[t,n]=S.useState("idle"),[a,r]=S.useState(""),[o,c]=S.useState(null),i=s.useDashboardStore(k=>k.authToken),d=s.useDashboardStore(k=>k.dashboard.id),u=s.useDashboardStore(k=>k.dashboard.title),{endUserId:x}=s.getTenantAndEndUserId((i==null?void 0:i.accessToken)||""),h="https://semaphor.cloud/api/v1/subscriptions/get",f={dashboardId:d,endUserId:x},{data:b,isLoading:l,isError:g,isFetching:p,refetch:C}=s.useQuery({queryKey:["subscriptions",d,x],queryFn:()=>s.getRequest(h,(i==null?void 0:i.accessToken)||"",f),enabled:!!(i!=null&&i.accessToken)&&!!d&&!!x});async function j({email:k,subject:L,frequency:v,time:A}){const{authToken:F,...V}=ts(),G=Intl.DateTimeFormat().resolvedOptions().timeZone,m={email:k,frequency:v,time:A,timezone:G,endUserId:x,endUserEmail:k,subject:L||u||"Scheduled Dashboard",dashboardId:d,dashboardParams:V};n("loading");const E="https://semaphor.cloud/api/v1/subscriptions/create";try{const q=await s.postRequestRegular(E,(F==null?void 0:F.accessToken)||"",{...m});n("success"),r(""),C(),setTimeout(()=>{n("idle")},2e3)}catch(q){console.error(q),n("error"),r(q.message)}}async function I(k){const L="https://semaphor.cloud/api/v1/subscriptions/delete";c(k);try{await s.postRequestRegular(L,(i==null?void 0:i.accessToken)||"",{id:k}),C(),setTimeout(()=>{c(null)},2e3)}catch(v){console.error(v),c(null),n("error"),r(v.message)}}return{data:b,isLoading:l,isFetching:p,isError:g,isDeleting:o,refetch:C,handleScheduleSubscription:j,handleDeleteSubscription:I,status:t,error:a}}function St(){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 c=s.useDashboardStore(m=>m.isDashboardEditing),i=s.useEditorStore(m=>m.selectedConnectionId),[d,u]=S.useState(!1),x=s.useDashboardStore(m=>m.filterValues),h=s.useDashboardStore(m=>m.isVisualEditing),f=s.useDashboardStore(m=>m.showFilters);s.useDashboardStore(m=>m.showDashboardJSON);const b=s.useDashboardStore(m=>m.onSaveFunction),l=s.useDashboardStore(m=>m.actions.setShowFilters),{addFrame:g,setSelectedFrameId:p}=s.useDashboardStore(m=>m.actions),{getSelectedSheet:C,setIsDashboardEditing:j,setShowDashboardJSON:I}=s.useDashboardStore(m=>m.actions),k=C(),{tenantId:L,endUserId:v}=S.useMemo(()=>s.getTenantAndEndUserId(t==null?void 0:t.accessToken),[t==null?void 0:t.accessToken]),A=S.useMemo(()=>L||v,[L,v]),F=()=>{if(!c||!k)return;const m={connectionId:i,id:s.v4(),title:"Title",description:"Description",preferences:{onClickFilter:[{columnIndex:0,expression:""}]},type:"bar",sql:"select COUNT(*) from YOUR_TABLE",data:[]},E={id:s.v4(),cards:[m],activeCardId:m.id};g(k.id,E),p(E.id)},V=()=>{j(!0)};async function G(){if(u(!0),!a||!r)return;const m=Ie(o),E=JSON.stringify(m),q={...r,template:E,filterValues:x};await ve(q,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 py-1 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:[!1,!h&&e.jsx(bt,{}),!h&&e.jsx(ns,{}),c&&!h&&A&&e.jsx(gt,{}),!h&&A&&e.jsx(jt,{}),c&&!h&&e.jsxs(s.Button,{variant:"secondary",className:"h-7 p-2",size:"sm",disabled:!c,onClick:F,children:[e.jsx(s.Plus,{className:"mr-2 h-4 w-4"}),"Frame"]}),!c&&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"})}),c&&!h&&e.jsx(s.IconButton,{className:"h-7 p-2",onClick:()=>{j(!1),I(!1)},children:e.jsx(s.Cross2Icon,{className:"h-4 w-4"})}),c&&!h&&A&&e.jsx(s.Button,{className:"h-7 p-2",variant:"ghost",disabled:d,onClick:G,size:"sm",children:e.jsx(it,{className:"h-4 w-4"})}),!f&&!h&&c&&e.jsx(s.Button,{className:"h-7 p-2",variant:"ghost",onClick:()=>l(!0),size:"sm",children:e.jsx(Je,{className:"h-4 w-4"})}),!h&&c&&!1,!h&&!1]})]})}function Ct({name:t,items:n,value:a,onChange:r,isLoading:o,isError:c,refetch:i,className:d,showNone:u=!1}){const x=de.useRef(null),[h,f]=de.useState(!1),[b,l]=de.useState("100%"),g=u?[...n||[],{id:"none",name:"None"}]:n;de.useLayoutEffect(()=>{x.current&&l(x.current.offsetWidth)},[]);function p(){var j;return o?"Loading...":c?"Error":a?(j=n==null?void 0:n.find(I=>I.id===a))==null?void 0:j.name:`Select ${t}`}function C(j,I){r(I),f(!1)}return e.jsxs(s.Popover,{open:h,onOpenChange:f,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:i,children:e.jsx(Ze,{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:g==null?void 0:g.map(j=>e.jsx(s.CommandItem,{className:"overflow-x-auto",value:j.name,onSelect:I=>C(I,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 ce({title:t,items:n,value:a,isLoading:r,isError:o,refetch:c,connectionTooltip:i,onChange:d,showNone:u=!1,className:x,showIcon:h=!0,disabled:f=!1,type:b="combobox"}){const l=r?"Loading...":o?"Error":a;function g(){if(t==="Connection")return e.jsx(nt,{className:"size-4 rotate-90"});if(t==="Database")return e.jsx(qs,{className:"size-4"});if(t==="Schema")return e.jsx(at,{className:"size-4"});if(t==="Table")return e.jsx(ke,{className:"size-4"});if(t==="Model")return e.jsx(As,{className:"size-4"})}function p(){return e.jsxs(s.Select,{disabled:f,value:l,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(Ze,{className:s.cn("mr-1 size-3 cursor-pointer text-muted-foreground hover:text-foreground",r&&"animate-spin"),onClick:c})]}),e.jsxs(e.Fragment,{children:[u&&e.jsx(s.SelectItem,{value:"none",children:"None"},"none"),n&&n.map((j,I)=>e.jsx(s.SelectItem,{value:j.id,children:j.name},I))]}),(r||o)&&e.jsx(s.SelectItem,{value:l,children:l})]})})]})}function C(){return e.jsx(Ct,{items:n,value:l,onChange:d||(()=>{}),isLoading:r,isError:o,refetch:c,name:t,showNone:u})}return e.jsx(s.TooltipProvider$1,{delayDuration:0,children:e.jsxs("div",{className:"flex items-center gap-2",children:[h&&e.jsx("div",{className:"shrink-0",children:i?e.jsxs(s.Tooltip,{children:[e.jsx(s.TooltipTrigger,{children:g()}),e.jsx(s.TooltipContent,{className:"text-xs",align:"start",children:i})]}):g()}),b==="select"?p():C()]})})}function vt({column:t}){const[n,a]=S.useState(!1),r=s.useEditorStore(g=>g.selectedTableName),o=s.useEditorStore(g=>g.selectedSchemaName),c=s.useEditorStore(g=>g.selectedDatamodelId),i=s.useEditorStore(g=>g.sqlGen),{modelItems:d,connectionType:u}=ne(),x=s.useEditorStore(g=>g.actions.setSqlGen),h=s.useEditorStore(g=>g.actions.setCardSql),f=s.useEditorStore(g=>g.actions.setRunSql);function b(g,p){var k;const C=s.createSqlGenConfig(g,i,p),j=(k=d==null?void 0:d.find(L=>L.id===c))==null?void 0:k.name;x(C);const I=s.getSql(C,s.fmt(o||""),s.fmt(r),j,u);I&&(h(I),f(!0)),a(!1)}function l(){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(Qe,{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:l()})]})}function rs({column:t}){return e.jsxs(s.Tooltip,{children:[e.jsx(s.TooltipTrigger$1,{asChild:!0,children:s.isTextDataType(t.data_type)?e.jsx(es,{className:"size-3"}):s.isNumberDataType(t.data_type)?e.jsx(Us,{className:"size-3"}):s.isDateDataType(t.data_type)?e.jsx(s.Calendar,{className:"size-3"}):s.isBooleanDataType(t.data_type)?e.jsx(ht,{className:"size-3"}):t.data_type.toLowerCase()==="json"?e.jsx(Ms,{className:"size-3"}):e.jsx(lt,{className:"size-3"})}),e.jsx(s.TooltipContent,{children:e.jsx("p",{className:"font-mono text-xs",children:t.data_type})})]})}function Nt({schemaName:t,tableName:n,columns:a,status:r}){const o=s.useEditorStore(m=>m.sqlGen),c=s.useEditorStore(m=>m.selectedConnectionId),i=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:f,removeFromAIScope:b}=s.useDashboardActions(),{setAIScopeTables:l}=s.useDashboardStore(m=>m.actions),g=s.useEditorStore(m=>m.actions.setRunSql),p=s.useEditorStore(m=>m.actions.setSqlGen),C=s.useEditorStore(m=>m.actions.setIsShowingVisual),j=s.useEditorStore(m=>m.actions.setCardSql),{connectionType:I,modelItems:k,selectedDatamodelName:L}=ne();function v(m){var B;const E=s.createSqlGenConfig(m,o);p(E);const q=(B=k==null?void 0:k.find(_=>_.id===x))==null?void 0:B.name,z=s.getSql(E,s.fmt(t),s.fmt(n),q,I);z&&(j(z),g(!0))}function A(){return(h==null?void 0:h.find(m=>m.connectionId===c&&(m.tableName===u||m.datamodelName===L)))!==void 0}function F(m){m===!0&&(u||L)&&c?(f({connectionId:c,connectionType:I==="S3"||I==="API"?"DuckDb":I,databaseName:i||"",schemaName:d||"",tableName:u||"",datamodelName:s.resolveDatamodelName(L),datamodelId:x||""}),s.ue.success("Added to Assistant Scope",{position:"top-right",duration:2500,richColors:!0})):(b({connectionId:c||"",connectionType:I||"",tableName:u||"",datamodelName:s.resolveDatamodelName(L),datamodelId:x||"",databaseName:i||"",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:L,connectionType:I});C(!1);const E=I==="MSSQL"?`SELECT top 10 * FROM ${m}`:`SELECT * FROM ${m} LIMIT 10`;j(E),g(!0)}function G(){const m=s.getFormattedTableNameForQuery({schemaName:t,tableName:n,modelName:L,connectionType:I});j(`SELECT COUNT(*) as count FROM ${m}`),g(!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:`${A()?"Remove from":"Add to"} Assistant Scope`,pressed:A(),onPressedChange:F,variant:"outline",className:s.cn("h-9 px-2",{}),children:[e.jsx(s.Plus,{className:s.cn("mr-1 size-4",{"text-green-400":A(),"text-muted-foreground":!A()})}),"AI"]}),e.jsxs(s.Button,{disabled:r!=="Success",onClick:V,size:"sm",variant:"secondary",className:"flex",children:[r!=="Success"?e.jsx(ie,{className:"mr-2 h-4 w-4 animate-spin text-foreground/50"}):e.jsx(Ys,{className:"mr-2 size-4"}),"Top 10"]}),e.jsxs(s.Button,{disabled:r!=="Success",onClick:G,size:"sm",variant:"secondary",className:"w-full",children:[r!=="Success"?e.jsx(ie,{className:"mr-2 h-4 w-4 animate-spin text-foreground/50"}):e.jsx(ct,{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:()=>v(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(rs,{column:m}),e.jsx("span",{children:m.column_name})]}),e.jsx("div",{onClick:E=>E.stopPropagation(),className:"flex items-center justify-end",children:s.isNumberDataType(m.data_type)&&e.jsx(vt,{column:m})})]},m.column_name))}),e.jsx(s.ScrollBar,{orientation:"vertical"}),e.jsx(s.ScrollBar,{orientation:"horizontal"})]})]})}function ne(t,n){var De,Te,Le,Ae,Me,ze;let a=S.useMemo(()=>[],[]);const r=s.useSemaphorContext().authToken||t,o=s.useEditorStore(w=>w.selectedConnectionId),c=s.useEditorStore(w=>w.selectedDatamodelId),i=s.useEditorStore(w=>w.selectedDatabaseName),d=s.useEditorStore(w=>w.selectedSchemaName),u=s.useEditorStore(w=>w.selectedTableName),x=s.useEditorStore(w=>w.actions.setCurrentColumns),h=s.useEditorStore(w=>w.actions.setSelectedConnectionId),f=s.useEditorStore(w=>w.actions.setSelectedDatamodelId),b=s.useEditorStore(w=>w.actions.setSelectedDatabaseName),l=s.useEditorStore(w=>w.actions.setSelectedSchemaName),g=s.useEditorStore(w=>w.actions.setSelectedTableName);s.useEditorStore(w=>w.actions.setCardSql);function p(w){return o&&i&&d&&i!=="NA"?!0:o&&w==="API"?!1:!!(o&&w==="S3")}function C(w){return!!(o&&i&&i!=="NA"&&d&&u||o&&(w==="S3"||w==="API")||c&&c)}function j(w){return o&&w?!(w==="API"||w==="S3"):!1}const{refetch:I,data:k,isLoading:L,isError:v}=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:A,data:F,isLoading:V,isError:G}=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=k==null?void 0:k.connections.find(w=>w.id===o),E=m==null?void 0:m.type,q=(m==null?void 0:m.type)==="API"||(m==null?void 0:m.type)==="S3",{data:z,isLoading:B,isFetching:_,isError:N,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(E)}),{data:O,isLoading:H,isFetching:Q,isError:R,refetch:M}=s.useQuery({queryKey:["schemas",o,i],queryFn:()=>s.getRequest("https://semaphor.cloud/api/v1/schemas",(r==null?void 0:r.accessToken)||"",{connection_id:o,database_name:i}),enabled:!!o&&!!i&&!q&&i!=="NA"}),{data:U,isLoading:J,isFetching:D,isError:P,refetch:Z}=s.useQuery({queryKey:["tables",o,i,d],queryFn:()=>s.getRequest("https://semaphor.cloud/api/v1/tables",(r==null?void 0:r.accessToken)||"",{connection_id:o,database_name:i,schema_name:d}),enabled:p(E)}),{data:K,isLoading:te,isFetching:ae,isError:X,refetch:$}=s.useQuery({queryKey:["columns",o,i,c,d,u],queryFn:()=>s.getRequest("https://semaphor.cloud/api/v1/columns",(r==null?void 0:r.accessToken)||"",{connection_id:o,datamodel_id:c||"",database_name:i,schema_name:d,table_name:u}),enabled:C(E)});S.useEffect(()=>{x(a)},[K,x,a]),S.useEffect(()=>{(E==="S3"||E==="API")&&(b(""),l(""),f(""),E==="API"&&g("api"))},[E,g,b,l,f]);const W=(m==null?void 0:m.type)==="API"?(De=m==null?void 0:m.type)==null?void 0:De.toLowerCase():u||"",re=q?"":d||"";function T(w){l(w),g("")}function Y(w){b(w==="none"?"":w),l(""),g(""),w!=="none"&&w!==""&&f("")}function oe(w){h(w)}function ee(w){f(w==="none"?"":w),w!=="none"&&w!==""&&b("")}z&&((Te=z==null?void 0:z.databases)==null?void 0:Te.length)>0,O&&((Le=O==null?void 0:O.schemas)==null?void 0:Le.length)>0,K&&((Ae=K==null?void 0:K.columns)==null?void 0:Ae.length)>0&&(a=K.columns.map(w=>({...w,data_type:w.data_type.toLowerCase()}))),N&&(a=[]),(X||v)&&(a=[]);const me=k==null?void 0:k.connections.map(w=>({id:w.id,name:w.name,type:w.type})),ye=(Me=F==null?void 0:F.datamodels)==null?void 0:Me.map(w=>({id:w.id,name:w.name})),pe=z==null?void 0:z.databases.map(w=>({id:w.database_name,name:w.database_name})),Se=O==null?void 0:O.schemas.map(w=>({id:w.schema_name,name:w.schema_name})),Ss=U==null?void 0:U.tables.map(w=>({id:w.table_name,name:w.table_name})),Cs=(ze=F==null?void 0:F.datamodels.find(w=>w.id===c))==null?void 0:ze.name;return{connectionItems:me,isConnectionsLoading:L,isConnectionsError:v,modelItems:ye,selectedDatamodelId:c,selectedDatamodelName:Cs,isModelsLoading:V,isModelsError:G,databaseItems:pe,isDatabasesLoadingOrFetching:B||_,isDatabaseError:N,schemaItems:Se,isSchemaLoadingOrFetching:H||Q,isSchemaError:R,tableItems:Ss,isTableLoadingOrFetching:J||D,isTableError:P,columns:a,isColumnsLoadingOrFetching:te||ae,isColumnsError:X,isNonDbConnection:q,connectionType:E,tableName:W,schemaName:re,refetchConnections:I,refetchModels:A,refetchDatabases:y,refetchSchemas:M,refetchTables:Z,refetchColumns:$,handleConnectionChange:oe,handleDatamodelChange:ee,handleDatabaseChange:Y,handleSchemaChange:T}}function os({ColumnsComponent:t}){var X;const n=s.useEditorStore($=>$.selectedConnectionId),a=s.useDashboardStore($=>$.showFilters),r=s.useEditorStore($=>$.selectedDatamodelId),o=s.useEditorStore($=>$.selectedDatabaseName),c=s.useEditorStore($=>$.selectedSchemaName),i=s.useEditorStore($=>$.selectedTableName),d=s.useEditorStore($=>$.actions.setSelectedTableName),{connectionItems:u,modelItems:x,schemaItems:h,databaseItems:f,tableItems:b,columns:l,isConnectionsLoading:g,isModelsLoading:p,isConnectionsError:C,isModelsError:j,isDatabasesLoadingOrFetching:I,isDatabaseError:k,isSchemaLoadingOrFetching:L,isSchemaError:v,isColumnsError:A,isColumnsLoadingOrFetching:F,isTableLoadingOrFetching:V,isTableError:G,connectionType:m,isNonDbConnection:E,refetchDatabases:q,refetchModels:z,refetchSchemas:B,refetchTables:_,refetchColumns:N,refetchConnections:y,handleConnectionChange:O,handleDatabaseChange:H,handleSchemaChange:Q,handleDatamodelChange:R,tableName:M,schemaName:U}=ne();function J(){return t?t(U,M,l):e.jsx(Nt,{schemaName:U,tableName:M,columns:l,status:F?"Loading...":A?"Error":"Success"})}function D(){window.location.href="mailto:support@semaphor.cloud?subject=Help&body=I need help with..."}function P(){if(!n||m==="S3"||m==="API")return null;if(!r||r==="none")return e.jsx(ce,{refetch:q,showNone:!0,onChange:H,isError:k,isLoading:I,items:f,value:o||"",title:"Database",type:"combobox"})}function Z(){if(n&&!E&&(!o||o==="none")&&(!r||r==="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 K(){if(!n||m==="S3"||m==="API")return null;if(!o||o==="none")return e.jsx(ce,{refetch:z,showNone:!0,onChange:R,isError:j,isLoading:p,items:x,value:r||"",title:"Model",type:"combobox"})}function te(){return!n||m==="S3"||m==="API"||!o||o==="none"?null:e.jsx(ce,{refetch:B,onChange:Q,isError:v,isLoading:L,items:h,value:c||"",title:"Schema",type:"combobox"})}function ae(){function $(){let W=!1;return m==="API"?(W=!1,W):((m==="S3"||n&&o&&o!=="none"&&c)&&(W=!0),W)}return $()?e.jsx(ce,{refetch:_,onChange:d,isError:G,items:b,isLoading:V,value:i||"",title:"Table",type:"combobox"}):null}return e.jsxs("aside",{className:s.cn("flex h-full min-w-[300px] flex-col justify-between rounded-none",{"border-r-[1px]":!a}),children:[e.jsxs("section",{className:"space-y-3 px-6 py-4",children:[e.jsx(ce,{refetch:y,items:u,title:"Connection",value:n||"",onChange:O,isLoading:g,isError:C,type:"combobox",connectionTooltip:((X=u==null?void 0:u.find($=>$.id===n))==null?void 0:X.type)||""}),P(),Z(),K(),te(),ae()]}),J(),e.jsx("div",{className:"flex items-end justify-center gap-2 px-6 py-4",children:e.jsxs(s.Button,{onClick:D,size:"sm",variant:"secondary",className:"w-full",children:[e.jsx(et,{className:"mr-2 size-4"}),"Help"]})})]})}function wt(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 c=t.length;if(o!==-1&&(c=o),r!==-1&&r<c&&(c=r),n!==-1){const i=t.substring(0,n),d=t.substring(n);return`${i} {{ filters | where }} AND ${d.substring(6)}`}else if(a!==-1){const i=t.substring(0,a),d=t.substring(a);return`${i} {{ filters | where }} ${d}`}else{const i=t.substring(0,c),d=t.substring(c);return console.log("beforeClause",i),console.log("afterClause",d),d?`${i} {{ filters | where }} ${d}`:`${i.replace(/;$/,"")} {{ filters | where }}`}}function kt({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($e,{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($s,{className:"mr-2 h-4 w-4"}),"Debug with Assistant"]})]})})})]})}var is={color:void 0,size:void 0,className:void 0,style:void 0,attr:void 0},Re=S.createContext&&S.createContext(is),It=["attr","size","title"];function Et(t,n){if(t==null)return{};var a=Dt(t,n),r,o;if(Object.getOwnPropertySymbols){var c=Object.getOwnPropertySymbols(t);for(o=0;o<c.length;o++)r=c[o],!(n.indexOf(r)>=0)&&Object.prototype.propertyIsEnumerable.call(t,r)&&(a[r]=t[r])}return a}function Dt(t,n){if(t==null)return{};var a={};for(var r in t)if(Object.prototype.hasOwnProperty.call(t,r)){if(n.indexOf(r)>=0)continue;a[r]=t[r]}return a}function je(){return je=Object.assign?Object.assign.bind():function(t){for(var n=1;n<arguments.length;n++){var a=arguments[n];for(var r in a)Object.prototype.hasOwnProperty.call(a,r)&&(t[r]=a[r])}return t},je.apply(this,arguments)}function Ve(t,n){var a=Object.keys(t);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(t);n&&(r=r.filter(function(o){return Object.getOwnPropertyDescriptor(t,o).enumerable})),a.push.apply(a,r)}return a}function be(t){for(var n=1;n<arguments.length;n++){var a=arguments[n]!=null?arguments[n]:{};n%2?Ve(Object(a),!0).forEach(function(r){Tt(t,r,a[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(a)):Ve(Object(a)).forEach(function(r){Object.defineProperty(t,r,Object.getOwnPropertyDescriptor(a,r))})}return t}function Tt(t,n,a){return n=Lt(n),n in t?Object.defineProperty(t,n,{value:a,enumerable:!0,configurable:!0,writable:!0}):t[n]=a,t}function Lt(t){var n=At(t,"string");return typeof n=="symbol"?n:n+""}function At(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 ls(t){return t&&t.map((n,a)=>S.createElement(n.tag,be({key:a},n.attr),ls(n.child)))}function ue(t){return n=>S.createElement(Mt,je({attr:be({},t.attr)},n),ls(t.child))}function Mt(t){var n=a=>{var{attr:r,size:o,title:c}=t,i=Et(t,It),d=o||a.size||"1em",u;return a.className&&(u=a.className),t.className&&(u=(u?u+" ":"")+t.className),S.createElement("svg",je({stroke:"currentColor",fill:"currentColor",strokeWidth:"0"},a.attr,r,i,{className:u,style:be(be({color:t.color||a.color},a.style),t.style),height:d,width:d,xmlns:"http://www.w3.org/2000/svg"}),c&&S.createElement("title",null,c),t.children)};return Re!==void 0?S.createElement(Re.Consumer,null,a=>n(a)):n(is)}function zt(t){return ue({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 cs(t){const{theme:n}=s.useTheme(),a=s.useDashboardStore(p=>p.theme),r=s.useEditorStore(p=>p.frame),o=s.useEditorStore(p=>p.card),c=s.useEditorStore(p=>p.activeTabCardId),i=s.Le(),{refetch:d}=s.useDashboardCardQuery(o),{updateCardTab:u,setRunSql:x}=s.useEditorActions(),h=S.useRef(),f=S.useRef({}),b=r.cards.find(p=>p.id===c),l=S.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]);S.useEffect(()=>{if(c&&o.id&&o.id!==c){if(h.current&&i){const p=h.current.getModel();p&&(f.current[o.id]=p);let C=f.current[c];if(!C){const j=l();C=i.editor.createModel(j,t),f.current[c]=C}h.current.setModel(C)}u(c,o),x(!0)}},[c,o,u,i,x,t,l]),S.useEffect(()=>{if(!i)return;const p=window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light",C=a==="system"?p:a;i.editor.defineTheme("default",{base:C==="light"?"vs":"vs-dark",inherit:!0,rules:[],colors:{"editor.background":C==="light"?"#ffffff":s.hslStringToHex("240 10% 10%")}}),i.editor.setTheme("default")},[n,a,i]),S.useEffect(()=>{const p=h.current;p&&i&&o&&p.addCommand(i.KeyMod.Shift|i.KeyCode.Enter,function(){return d(),!1})},[i,d,o]);function g(p,C){if(h.current=p,!f.current[o.id]){const j=p.getModel(),I=l();f.current[o.id]=j||(C==null?void 0:C.editor.createModel(I,t))||p.getModel()}p.setModel(f.current[o.id])}return{handleEditorDidMount:g}}function Ot(){const t=s.useEditorStore(i=>i.card.sql),n=s.useEditorStore(i=>i.sqlGen),{setCardSql:a,setSqlGen:r}=s.useEditorActions(),{handleEditorDidMount:o}=cs("sql");function c(i){a(i),s.isObjectEmpty(n)||r({})}return e.jsx(s.Ft,{theme:"default",className:"pt-3",onChange:c,value:t||"",options:{minimap:{enabled:!1},wordWrap:"on",scrollbar:{verticalScrollbarSize:0,horizontalScrollbarSize:0},fontSize:13,renderLineHighlight:"none"},defaultLanguage:"sql",onMount:o})}function Ft(){const t=s.useEditorStore(o=>o.card.python),{setCardPython:n}=s.useEditorActions(),{handleEditorDidMount:a}=cs("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 Rt({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 ds(t){const[n,a]=S.useState(""),[r,o]=S.useState(null),{authToken:c}=s.useSemaphorContext(),i=s.useEditorStore(D=>{var P;return(P=D==null?void 0:D.card)==null?void 0:P.sql}),d=s.useEditorStore(D=>{var P;return(P=D==null?void 0:D.card)==null?void 0:P.python}),u=s.useEditorStore(D=>D.actions.setCardSql),x=s.useEditorStore(D=>D.actions.setRunSql),h=s.useEditorStore(D=>D.actions.switchCardType),f=s.useEditorStore(D=>D.currentAssitantScope)||[],b=s.useEditorStore(D=>D.userInputForAI),l=s.useEditorStore(D=>D.triggerAIRun),g=s.useEditorStore(D=>D.selectedDatabaseName),p=s.useEditorStore(D=>D.selectedTableName),C=s.useEditorStore(D=>D.selectedConnectionId),j=s.useEditorStore(D=>D.selectedSchemaName),I=s.useDashboardStore(D=>D.dashboard.aiScopeTables),{setTriggerAIRun:k,setCurrentAssitantScope:L}=s.useEditorActions(),{selectedDatamodelName:v,connectionType:A,selectedDatamodelId:F}=ne(),{messages:V,setMessages:G,reload:m,append:E,input:q,setInput:z,status:B,handleInputChange:_,handleSubmit:N,stop:y}=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:O,onFinish(D,P){H(P.usage),a(""),P.finishReason==="stop"&&a("")}});S.useEffect(()=>{l&&b&&(_({target:{value:b}}),setTimeout(()=>{N(),k(!1)},100))},[l,N,b,k,_]);async function O({toolCall:D}){if(D.toolName==="createChartFromSql"){const P=D.args.sql,Z=D.args.chartType;return h(Z),u(P),x(!0),{status:"success",message:"Let the user know that chart is created"}}else if(D.toolName==="getTableColumns")a("Getting table columns...");else{if(D.toolName==="getUserSql")return i?{status:"success",sql:i,python:d||""}:{status:"error",message:"No SQL found"};if(D.toolName==="getCurrentTableScope")return a("Getting table scope..."),U(),{status:"success",tables:f};a("Analyzing...")}}function H(D){o(P=>P?{promptTokens:P.promptTokens+D.promptTokens,completionTokens:P.completionTokens+D.completionTokens,totalTokens:P.totalTokens+D.totalTokens}:D)}function Q(D){const P=s.removeFromScopeArray(f,D);R(P)}function R(D){const P=s.sanitizeAIScope(D);L(P),G(Z=>[...Z,{id:crypto.randomUUID(),role:"system",content:`Current scope of tables | ${JSON.stringify(P)}`}])}function M(){const D={databaseName:g||"",schemaName:j||"",tableName:p||"",datamodelId:F||"",datamodelName:s.resolveDatamodelName(v),connectionId:C||"",connectionType:A||""},P=s.dedup([...f,D]);R(P)}function U(){const D={databaseName:g||"",schemaName:j||"",tableName:p||"",datamodelName:s.resolveDatamodelName(v),connectionId:C||"",connectionType:A||"",datamodelId:F||""};if(!s.isInAiScopeArray([...I||[],...f],D)||f.length===0){const Z=s.dedup([...I||[],...f,D]).filter(K=>K.connectionId===D.connectionId);R(Z)}}const J=!["ready","error"].includes(B);return{messages:V,setMessages:G,reload:m,append:E,input:q,setInput:z,isLoading:J,handleSetAIScope:U,handleAddCurrentTableToScope:M,removeFromCurrentSelections:Q,currentAssitantScope:f,setCurrentAssitantScope:L,handleInputChange:_,handleSubmit:N,stop:y,chatStatus:B,toolStatus:n,llmUsage:r,onFinish:t}}function Vt(){var re;const[t,n]=S.useState({queryKey:[],queryData:null}),a=s.useQueryClient(),[r,o]=S.useState(!1),[c,i]=S.useState(!1),d=s.useEditorStore(T=>T.frame),u=s.useEditorStore(T=>T.card),x=s.useEditorStore(T=>T.isShowingVisual),h=s.useEditorStore(T=>T.selectedConnectionId),f=s.useEditorStore(T=>T.selectedDatabaseName),b=s.useEditorStore(T=>T.selectedDatamodelId),l=s.useEditorStore(T=>T.selectedSchemaName),g=s.useEditorStore(T=>T.showAIDialog),p=s.useEditorStore(T=>T.selectedTableName),C=s.useEditorStore(T=>{var Y;return(Y=T==null?void 0:T.card)==null?void 0:Y.sql}),{sheetFilterValues:j}=s.useSheetFilterValues(),{setCardCustomCfg:I,setQueryResultColumns:k,setCardSql:L,setPythonStdOut:v,setCardPreferences:A,setCardType:F,setCardPython:V,runAssistant:G,setShowAIDialog:m}=s.useEditorActions(),E=s.useEditorStore(T=>T.onSave),q=s.useEditorStore(T=>T.onClose),z=s.useEditorStore(T=>T.actions.setSqlGen),B=s.useEditorStore(T=>T.runSql),_=s.useEditorStore(T=>T.actions.setRunSql),N=s.useEditorStore(T=>T.actions.setIsSqlRunning),{data:y,isLoading:O,isFetching:H,isSuccess:Q,isError:R,error:M,queryKey:U,refetch:J}=s.useDashboardCardQuery(u),{handleSetAIScope:D}=ds();S.useEffect(()=>{if(y&&(y.rowLimitExceeded&&s.ue.error("Row limit (10,000) exceeded. Refine your query.",{position:"top-center",richColors:!0}),v((y==null?void 0:y.output)||""),y.records.length>0)){const{dimensionKeys:T}=s.getKeys(y.records);k(T)}},[y,k,v]),S.useEffect(()=>{(O||H)&&N(!0),(R||Q)&&N(!1),R&&(k([]),v(""))},[O,H,y,v,R,Q,N,k,M]),S.useEffect(()=>{B&&(a.getQueryData(U)||J(),_(!1))},[B,J,_,U,a]);function P(){const T=a.getQueryData(U);t.queryData||n({queryKey:U,queryData:T}),a.setQueryData(U,null),a.removeQueries({queryKey:U,exact:!0}),L(""),z({}),V(""),I(""),A({}),F("bar")}function Z(T,Y){if(T.length===0)return"";if(Y){const oe=T.find(ee=>ee.id===Y);if(oe){const ee=oe.tabTitle;if(ee=="All__Header")return T[0].id;if(ee&&ee.endsWith("__Header")){const ye=ee.split("__")[0],pe=T.find(Se=>Se.tabTitle===ye);return pe?pe.id:T[0].id}return Y}}return T[0].id}function K(){let T=C;C&&!C.includes("{{")&&(T=wt(C),L(T));const Y={...u,lastSelectedSchema:l,lastSelectedDatamodelId:b,lastSelectedDatabase:f,lastSelectedTable:p,connectionId:h,type:x?u.type:"table",sql:T,customCfg:x?u.customCfg:null},oe=d.cards.map(me=>me.id===u.id?Y:me),ee={...d,cards:oe,activeCardId:Z(oe,d.activeCardId)};E==null||E(ee)}function te(){const{queryKey:T,queryData:Y}=t;T&&Y&&a.setQueryData(T,Y),z({}),q==null||q()}async function ae(){const T=`Can you help me debug this query in the current table scope?
|
|
311
|
+
*/const es=s.createLucideIcon("Type",[["polyline",{points:"4 7 4 4 20 4 20 7",key:"1nosan"}],["line",{x1:"9",x2:"15",y1:"20",y2:"20",key:"swin9y"}],["line",{x1:"12",x2:"12",y1:"4",y2:"20",key:"1tx1rr"}]]);function Ie(t){var n;return{...t,sheets:(n=t==null?void 0:t.sheets)==null?void 0:n.map(a=>{var r;return{...a,frames:(r=a.frames)==null?void 0:r.map(o=>{var c;return{...o,cards:(c=o.cards)==null?void 0:c.map(l=>ss(l))}})}})}}function ss(t){return{...t,customCfg:xt(t.customCfg),data:[]}}function xt(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 pt(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 ve(t,n){if(!n)return null;const{id:a,template:r,filterValues:o,isDefault:c,shared:l}=t;return await s.postRequest("https://semaphor.cloud/api/v1/lens",n,{lensId:a,template:r,filterValues:o,isDefault:c,shared:l,operation:"update"})}async function ft(t,n){return n?await s.postRequest("https://semaphor.cloud/api/v1/lens",n,{operation:"delete",lensId:t}):null}function gt(){const[t,n]=S.useState(""),[a,r]=S.useState(!1),o=s.useDashboardStore(x=>x.lenses),{setLenses:c,setSelectedLensId:l}=s.useDashboardActions(),[d,u]=S.useState(!1),[p,h]=S.useState(!1),f=s.useDashboardStore(x=>x.dashboard),b=s.useDashboardStore(x=>x.filterValues),{authToken:i}=s.useSemaphorContext();async function j(){u(!0);const x=Ie(f),C=await pt(t,x,b,i==null?void 0:i.accessToken);C&&(c([...o||[],C]),l(C.id),h(!1)),u(!1)}return e.jsxs(s.Dialog,{open:p,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"}),"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:x=>{n(x.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:j,disabled:d,children:d?"Creating...":"Add"})})]})]})}function jt(){const[t,n]=S.useState(!1),a=s.useDashboardStore(h=>h.lenses),r=s.useDashboardStore(h=>h.selectedLensId),{setLenses:o,setSelectedLensId:c}=s.useDashboardActions(),{authToken:l}=s.useSemaphorContext();async function d(h){c(h)}async function u(h){if(await ft(h,l==null?void 0:l.accessToken)){const b=a==null?void 0:a.filter(i=>i.id!==h);o(b||[]),c("original")}}async function p(h){const f=a==null?void 0:a.map(j=>j.id===h.id?{...j,isDefault:!h.isDefault}:{...j,isDefault:!1});o(f||[]);const b={...h,isDefault:!h.isDefault};await ve(b,l==null?void 0:l.accessToken);const i=a==null?void 0:a.find(j=>j.isDefault);if(i&&i.id!==h.id){const j={...i,isDefault:!1};await ve(j,l==null?void 0:l.accessToken)}}return e.jsxs(s.DropdownMenu,{open:t,onOpenChange:n,children:[e.jsx(s.DropdownMenuTrigger,{asChild:!0,children:e.jsx(s.IconButton,{tooltip:"Lenses",className:"h-7 p-2",children:e.jsx(Hs,{className:"h-4 w-4"})})}),e.jsxs(s.DropdownMenuContent,{align:"end",className:"w-60",children:[e.jsx(s.DropdownMenuLabel,{className:"px-3",children:"Lenses"}),e.jsx(s.DropdownMenuSeparator,{}),e.jsxs(s.DropdownMenuRadioGroup,{value:r,onValueChange:d,children:[e.jsx(s.DropdownMenuRadioItem,{value:"original",children:"Original"}),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(Qs,{onClick:f=>{f.preventDefault(),p(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:f=>{f.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))]})]})]})}function ts(){var c;const t=s.useDashboardStore.getState().authToken,n=s.useDashboardStore.getState().theme,a=s.useDashboardStore.getState().filterValues,r=(c=s.useDashboardStore.getState().dashboard)==null?void 0:c.title,o=s.useDashboardStore.getState().selectedSheetId;return{authToken:t,theme:n||"light",filterValues:a,dashboardTitle:r||"",selectedSheetId:o||""}}async function as(){const t=s.useDashboardStore.getState().isDownloadingPdf,{authToken:n,theme:a,filterValues:r,dashboardTitle:o,selectedSheetId:c}=ts();if(t)return;const l=new URLSearchParams;l.set("token",(n==null?void 0:n.accessToken)||""),l.set("theme",a),l.set("filterValues",JSON.stringify(r)),l.set("selectedSheetId",c||"");const d=`https://semaphor.cloud/api/v1/generate-pdf?params=${encodeURIComponent(l.toString())}`;s.useDashboardStore.setState({isDownloadingPdf:!0});const h=(await(await fetch(d,{method:"GET",headers:{Authorization:`Bearer ${n==null?void 0:n.accessToken}`}})).json()).url,f=document.createElement("a");f.href=h;const b=`${o}-${new Date().toISOString()}.pdf`;f.download=b,f.click(),s.useDashboardStore.setState({isDownloadingPdf:!1})}function bt({iconClassName:t}){const{authToken:n}=s.useSemaphorContext();s.useDashboardStore(o=>{var c;return(c=o.dashboard)==null?void 0:c.title}),s.useDashboardStore(o=>o.theme),s.useDashboardStore(o=>o.filterValues);const a=s.useDashboardStore(o=>o.isDownloadingPdf);async function r(){await as()}return e.jsx(s.IconButton,{tooltip:"Download PDF",className:"h-7 p-2",onClick:r,children:a?e.jsx(ie,{className:s.cn("size-3.5 animate-spin",t)}):e.jsx(s.Download,{className:s.cn("size-4",t)})})}function se({defaultValue:t,label:n,options:a,value:r,onValueChange:o,className:c}){return e.jsxs(s.Select,{defaultValue:t,value:r,onValueChange:o,children:[e.jsx(s.SelectTrigger,{className:s.cn("w-full focus:ring-0 focus:ring-offset-0",c),children:e.jsx(s.SelectValue,{placeholder:n})}),e.jsx(s.SelectContent,{children:e.jsxs(s.SelectGroup,{children:[e.jsx(s.SelectLabel,{children:n}),a.map(l=>e.jsx(s.SelectItem,{value:l.value,children:l.label},l.value))]})})]})}const Oe=[{value:"daily",label:"Daily"},{value:"weekly",label:"Weekly"},{value:"biweekly",label:"Bi-Weekly"},{value:"monthly",label:"Monthly"}];function ns({triggerButtonClassName:t}){const{data:n,handleScheduleSubscription:a,handleDeleteSubscription:r,status:o,error:c,isDeleting:l}=yt(),[d,u]=S.useState(""),[p,h]=S.useState(Oe[0].value),[f,b]=S.useState("06:00"),[i,j]=S.useState("");return e.jsx(s.TooltipProvider,{delayDuration:0,children:e.jsxs(s.Popover,{children:[e.jsx(s.PopoverTrigger,{asChild:!0,children:e.jsx(s.IconButton,{tooltip:"Schedule Dashboard",className:s.cn("h-7 p-2",t),children:e.jsx(Fs,{className:"size-4"})})}),e.jsx(s.PopoverContent,{align:"end",className:"w-80",children:e.jsxs("div",{className:"grid gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("h4",{className:"font-medium leading-none",children:"Schedule Subscription"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Subscribe to receive dashboard via email"})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsxs("div",{className:"grid grid-cols-3 items-center gap-4",children:[e.jsx(s.Label,{htmlFor:"email",children:"Email"}),e.jsx(s.Input,{id:"email",value:d,onChange:x=>u(x.target.value),className:`col-span-2 h-8 ${s.removeRing}`})]}),e.jsxs("div",{className:"grid grid-cols-3 items-center gap-4",children:[e.jsx(s.Label,{htmlFor:"subject",children:"Subject"}),e.jsx(s.Input,{id:"subject",placeholder:"Monthly Sales Report",value:i,onChange:x=>{j(x.target.value.replace(/[^a-zA-Z0-9\s-_]/g,""))},className:`col-span-2 h-8 ${s.removeRing}`})]}),e.jsxs("div",{className:"grid grid-cols-3 items-center gap-4",children:[e.jsx(s.Label,{htmlFor:"frequency",children:"Frequency"}),e.jsx(se,{className:"col-span-2 h-8",label:"Select Frequency",options:Oe,value:p,onValueChange:x=>h(x)})]}),e.jsxs("div",{className:"grid grid-cols-3 items-center gap-4",children:[e.jsx(s.Label,{htmlFor:"time",children:"Time"}),e.jsx(s.Input,{id:"time",type:"time",value:f,onChange:x=>b(x.target.value),className:`col-span-2 h-8 ${s.removeRing}`})]}),e.jsx("div",{className:"mt-2 flex justify-end",children:e.jsxs(s.Button,{onClick:async()=>{await a({email:d,frequency:p,time:f,subject:i}),b("00:00"),u(""),j("")},className:"h-8 p-2",disabled:o==="loading"||!d,children:[o==="loading"&&e.jsx(ie,{className:"mr-2 size-4 animate-spin"}),o==="success"&&e.jsx(s.Check,{className:"mr-2 size-4"}),o==="error"&&e.jsxs(s.Tooltip,{children:[e.jsx(s.TooltipTrigger,{children:e.jsx($e,{className:"mr-2 size-4 text-destructive"})}),e.jsx(s.TooltipContent,{children:e.jsx("p",{children:c})})]}),"Schedule"]})}),n&&n.length>0&&e.jsxs("div",{className:"space-y-4",children:[e.jsx(s.Separator,{className:"my-2"}),e.jsx("div",{className:"space-y-2",children:e.jsxs("div",{className:"flex items-start justify-between",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("h4",{className:"font-medium leading-none",children:"Subscriptions"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Active email subscriptions"})]}),s.isDev]})}),e.jsx("div",{className:"grid gap-2",children:n==null?void 0:n.map(x=>e.jsxs("div",{className:"group grid grid-cols-5 gap-3",children:[e.jsx("div",{className:"col-span-3 text-sm",children:e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsxs("div",{className:"boder-border rounded-md border bg-muted px-2 py-1",children:[s.titleCase(x.frequency)," "]}),e.jsx(s.Label,{children:x.time})]})}),e.jsxs("div",{className:"col-span-2 flex items-center justify-end gap-4",children:[e.jsx(Fe,{tooltip:`Next Run: ${new Date(x.nextRun).toLocaleString()} ${x.timezone}`,children:e.jsx(Os,{className:"size-3.5"})}),e.jsx(Fe,{tooltip:`${x.endUserEmail}`,children:e.jsx(Xs,{className:"size-3.5"})}),l===x.id?e.jsx(ie,{className:"size-3.5 animate-spin"}):e.jsx(mt,{onClick:()=>r(x.id),className:"size-3.5 cursor-pointer"})]})]},x.id))})]})]})]})})]})})}const Fe=({children:t,tooltip:n})=>e.jsx(s.TooltipProvider,{delayDuration:0,children:e.jsxs(s.Tooltip,{children:[e.jsx(s.TooltipTrigger,{asChild:!0,children:t}),e.jsx(s.TooltipContent,{children:n})]})});function yt(){const[t,n]=S.useState("idle"),[a,r]=S.useState(""),[o,c]=S.useState(null),l=s.useDashboardStore(k=>k.authToken),d=s.useDashboardStore(k=>k.dashboard.id),u=s.useDashboardStore(k=>k.dashboard.title),{endUserId:p}=s.getTenantAndEndUserId((l==null?void 0:l.accessToken)||""),h="https://semaphor.cloud/api/v1/subscriptions/get",f={dashboardId:d,endUserId:p},{data:b,isLoading:i,isError:j,isFetching:x,refetch:C}=s.useQuery({queryKey:["subscriptions",d,p],queryFn:()=>s.getRequest(h,(l==null?void 0:l.accessToken)||"",f),enabled:!!(l!=null&&l.accessToken)&&!!d&&!!p});async function g({email:k,subject:T,frequency:v,time:A}){const{authToken:F,...V}=ts(),G=Intl.DateTimeFormat().resolvedOptions().timeZone,m={email:k,frequency:v,time:A,timezone:G,endUserId:p,endUserEmail:k,subject:T||u||"Scheduled Dashboard",dashboardId:d,dashboardParams:V};n("loading");const E="https://semaphor.cloud/api/v1/subscriptions/create";try{const q=await s.postRequestRegular(E,(F==null?void 0:F.accessToken)||"",{...m});n("success"),r(""),C(),setTimeout(()=>{n("idle")},2e3)}catch(q){console.error(q),n("error"),r(q.message)}}async function I(k){const T="https://semaphor.cloud/api/v1/subscriptions/delete";c(k);try{await s.postRequestRegular(T,(l==null?void 0:l.accessToken)||"",{id:k}),C(),setTimeout(()=>{c(null)},2e3)}catch(v){console.error(v),c(null),n("error"),r(v.message)}}return{data:b,isLoading:i,isFetching:x,isError:j,isDeleting:o,refetch:C,handleScheduleSubscription:g,handleDeleteSubscription:I,status:t,error:a}}function St(){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 c=s.useDashboardStore(m=>m.isDashboardEditing),l=s.useEditorStore(m=>m.selectedConnectionId),[d,u]=S.useState(!1),p=s.useDashboardStore(m=>m.filterValues),h=s.useDashboardStore(m=>m.isVisualEditing),f=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:j,setSelectedFrameId:x}=s.useDashboardStore(m=>m.actions),{getSelectedSheet:C,setIsDashboardEditing:g,setShowDashboardJSON:I}=s.useDashboardStore(m=>m.actions),k=C(),{tenantId:T,endUserId:v}=S.useMemo(()=>s.getTenantAndEndUserId(t==null?void 0:t.accessToken),[t==null?void 0:t.accessToken]),A=S.useMemo(()=>T||v,[T,v]),F=()=>{if(!c||!k)return;const m={connectionId:l,id:s.v4(),title:"Title",description:"Description",preferences:{onClickFilter:[{columnIndex:0,expression:""}]},type:"bar",sql:"select COUNT(*) from YOUR_TABLE",data:[]},E={id:s.v4(),cards:[m],activeCardId:m.id};j(k.id,E),x(E.id)},V=()=>{g(!0)};async function G(){if(u(!0),!a||!r)return;const m=Ie(o),E=JSON.stringify(m),q={...r,template:E,filterValues:p};await ve(q,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 py-1 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:[!1,!h&&e.jsx(bt,{}),!h&&e.jsx(ns,{}),c&&!h&&A&&e.jsx(gt,{}),!h&&A&&e.jsx(jt,{}),c&&!h&&e.jsxs(s.Button,{variant:"secondary",className:"h-7 p-2",size:"sm",disabled:!c,onClick:F,children:[e.jsx(s.Plus,{className:"mr-2 h-4 w-4"}),"Frame"]}),!c&&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"})}),c&&!h&&e.jsx(s.IconButton,{className:"h-7 p-2",onClick:()=>{g(!1),I(!1)},children:e.jsx(s.Cross2Icon,{className:"h-4 w-4"})}),c&&!h&&A&&e.jsx(s.Button,{className:"h-7 p-2",variant:"ghost",disabled:d,onClick:G,size:"sm",children:e.jsx(it,{className:"h-4 w-4"})}),!f&&!h&&c&&e.jsx(s.Button,{className:"h-7 p-2",variant:"ghost",onClick:()=>i(!0),size:"sm",children:e.jsx(Je,{className:"h-4 w-4"})}),!h&&c&&!1,!h&&!1]})]})}function Ct({name:t,items:n,value:a,onChange:r,isLoading:o,isError:c,refetch:l,className:d,showNone:u=!1}){const p=de.useRef(null),[h,f]=de.useState(!1),[b,i]=de.useState("100%"),j=u?[...n||[],{id:"none",name:"None"}]:n;de.useLayoutEffect(()=>{p.current&&i(p.current.offsetWidth)},[]);function x(){var g;return o?"Loading...":c?"Error":a?(g=n==null?void 0:n.find(I=>I.id===a))==null?void 0:g.name:`Select ${t}`}function C(g,I){r(I),f(!1)}return e.jsxs(s.Popover,{open:h,onOpenChange:f,children:[e.jsx(s.PopoverTrigger,{asChild:!0,children:e.jsxs(s.Button,{ref:p,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:x()}),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:l,children:e.jsx(Ze,{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:j==null?void 0:j.map(g=>e.jsx(s.CommandItem,{className:"overflow-x-auto",value:g.name,onSelect:I=>C(I,g.id),children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(s.Check,{className:s.cn("size-4",a===g.id?"opacity-100":"opacity-0")}),e.jsx("div",{title:g.name,children:g.name})]})},g.id))})]})]})})]})}function ce({title:t,items:n,value:a,isLoading:r,isError:o,refetch:c,connectionTooltip:l,onChange:d,showNone:u=!1,className:p,showIcon:h=!0,disabled:f=!1,type:b="combobox"}){const i=r?"Loading...":o?"Error":a;function j(){if(t==="Connection")return e.jsx(nt,{className:"size-4 rotate-90"});if(t==="Database")return e.jsx(qs,{className:"size-4"});if(t==="Schema")return e.jsx(at,{className:"size-4"});if(t==="Table")return e.jsx(ke,{className:"size-4"});if(t==="Model")return e.jsx(As,{className:"size-4"})}function x(){return e.jsxs(s.Select,{disabled:f,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",p),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(Ze,{className:s.cn("mr-1 size-3 cursor-pointer text-muted-foreground hover:text-foreground",r&&"animate-spin"),onClick:c})]}),e.jsxs(e.Fragment,{children:[u&&e.jsx(s.SelectItem,{value:"none",children:"None"},"none"),n&&n.map((g,I)=>e.jsx(s.SelectItem,{value:g.id,children:g.name},I))]}),(r||o)&&e.jsx(s.SelectItem,{value:i,children:i})]})})]})}function C(){return e.jsx(Ct,{items:n,value:i,onChange:d||(()=>{}),isLoading:r,isError:o,refetch:c,name:t,showNone:u})}return e.jsx(s.TooltipProvider$1,{delayDuration:0,children:e.jsxs("div",{className:"flex items-center gap-2",children:[h&&e.jsx("div",{className:"shrink-0",children:l?e.jsxs(s.Tooltip,{children:[e.jsx(s.TooltipTrigger,{children:j()}),e.jsx(s.TooltipContent,{className:"text-xs",align:"start",children:l})]}):j()}),b==="select"?x():C()]})})}function vt({column:t}){const[n,a]=S.useState(!1),r=s.useEditorStore(x=>x.selectedTableName),o=s.useEditorStore(x=>x.selectedSchemaName),c=s.useEditorStore(x=>x.selectedDatabaseName),l=s.useEditorStore(x=>x.selectedDatamodelId),d=s.useEditorStore(x=>x.sqlGen),{modelItems:u,connectionType:p}=ne(),h=s.useEditorStore(x=>x.actions.setSqlGen),f=s.useEditorStore(x=>x.actions.setCardSql),b=s.useEditorStore(x=>x.actions.setRunSql);function i(x,C){var T;const g=s.createSqlGenConfig(x,d,C),I=(T=u==null?void 0:u.find(v=>v.id===l))==null?void 0:T.name;h(g);const k=s.getSql(g,s.fmt(o||""),s.fmt(r),I,p,c||"");k&&(f(k),b(!0)),a(!1)}function j(){return e.jsxs("ul",{className:"text-xs",children:[e.jsx("li",{onClick:()=>i(t,"COUNT"),className:"cursor-pointer p-1 px-3 transition-colors hover:bg-muted",children:"Count"}),e.jsx("li",{onClick:()=>i(t,"AVG"),className:"cursor-pointer p-1 px-3 transition-colors hover:bg-muted",children:"Avg"}),e.jsx("li",{onClick:()=>i(t,"SUM"),className:"cursor-pointer p-1 px-3 transition-colors hover:bg-muted",children:"Sum"}),e.jsx("li",{onClick:()=>i(t,"MAX"),className:"cursor-pointer p-1 px-3 transition-colors hover:bg-muted",children:"Max"}),e.jsx("li",{onClick:()=>i(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(Qe,{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:j()})]})}function rs({column:t}){return e.jsxs(s.Tooltip,{children:[e.jsx(s.TooltipTrigger$1,{asChild:!0,children:s.isTextDataType(t.data_type)?e.jsx(es,{className:"size-3"}):s.isNumberDataType(t.data_type)?e.jsx(Us,{className:"size-3"}):s.isDateDataType(t.data_type)?e.jsx(s.Calendar,{className:"size-3"}):s.isBooleanDataType(t.data_type)?e.jsx(ht,{className:"size-3"}):t.data_type.toLowerCase()==="json"?e.jsx(Ms,{className:"size-3"}):e.jsx(lt,{className:"size-3"})}),e.jsx(s.TooltipContent,{children:e.jsx("p",{className:"font-mono text-xs",children:t.data_type})})]})}function Nt({schemaName:t,tableName:n,columns:a,status:r}){const o=s.useEditorStore(m=>m.sqlGen),c=s.useEditorStore(m=>m.selectedConnectionId),l=s.useEditorStore(m=>m.selectedDatabaseName),d=s.useEditorStore(m=>m.selectedSchemaName),u=s.useEditorStore(m=>m.selectedTableName),p=s.useEditorStore(m=>m.selectedDatamodelId),h=s.useDashboardStore(m=>m.dashboard.aiScopeTables),{addToAIScope:f,removeFromAIScope:b}=s.useDashboardActions(),{setAIScopeTables:i}=s.useDashboardStore(m=>m.actions),j=s.useEditorStore(m=>m.actions.setRunSql),x=s.useEditorStore(m=>m.actions.setSqlGen),C=s.useEditorStore(m=>m.actions.setIsShowingVisual),g=s.useEditorStore(m=>m.actions.setCardSql),{connectionType:I,modelItems:k,selectedDatamodelName:T}=ne();function v(m){var B;const E=s.createSqlGenConfig(m,o);x(E);const q=(B=k==null?void 0:k.find(_=>_.id===p))==null?void 0:B.name,z=s.getSql(E,s.fmt(t),s.fmt(n),q,I,l||"");z&&(g(z),j(!0))}function A(){return(h==null?void 0:h.find(m=>m.connectionId===c&&(m.tableName===u||m.datamodelName===T)))!==void 0}function F(m){m===!0&&(u||T)&&c?(f({connectionId:c,connectionType:I==="S3"||I==="API"?"DuckDb":I,databaseName:l||"",schemaName:d||"",tableName:u||"",datamodelName:s.resolveDatamodelName(T),datamodelId:p||""}),s.ue.success("Added to Assistant Scope",{position:"top-right",duration:2500,richColors:!0})):(b({connectionId:c||"",connectionType:I||"",tableName:u||"",datamodelName:s.resolveDatamodelName(T),datamodelId:p||"",databaseName:l||"",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:T,connectionType:I,databaseName:l||""});C(!1);const E=I==="MSSQL"?`SELECT top 10 * FROM ${m}`:`SELECT * FROM ${m} LIMIT 10`;g(E),j(!0)}function G(){const m=s.getFormattedTableNameForQuery({schemaName:t,tableName:n,modelName:T,connectionType:I,databaseName:l||""});g(`SELECT COUNT(*) as count FROM ${m}`),j(!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:`${A()?"Remove from":"Add to"} Assistant Scope`,pressed:A(),onPressedChange:F,variant:"outline",className:s.cn("h-9 px-2",{}),children:[e.jsx(s.Plus,{className:s.cn("mr-1 size-4",{"text-green-400":A(),"text-muted-foreground":!A()})}),"AI"]}),e.jsxs(s.Button,{disabled:r!=="Success",onClick:V,size:"sm",variant:"secondary",className:"flex",children:[r!=="Success"?e.jsx(ie,{className:"mr-2 h-4 w-4 animate-spin text-foreground/50"}):e.jsx(Ys,{className:"mr-2 size-4"}),"Top 10"]}),e.jsxs(s.Button,{disabled:r!=="Success",onClick:G,size:"sm",variant:"secondary",className:"w-full",children:[r!=="Success"?e.jsx(ie,{className:"mr-2 h-4 w-4 animate-spin text-foreground/50"}):e.jsx(ct,{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:()=>v(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(rs,{column:m}),e.jsx("span",{children:m.column_name})]}),e.jsx("div",{onClick:E=>E.stopPropagation(),className:"flex items-center justify-end",children:s.isNumberDataType(m.data_type)&&e.jsx(vt,{column:m})})]},m.column_name))}),e.jsx(s.ScrollBar,{orientation:"vertical"}),e.jsx(s.ScrollBar,{orientation:"horizontal"})]})]})}function ne(t,n){var De,Te,Le,Ae,Me,ze;let a=S.useMemo(()=>[],[]);const r=s.useSemaphorContext().authToken||t,o=s.useEditorStore(w=>w.selectedConnectionId),c=s.useEditorStore(w=>w.selectedDatamodelId),l=s.useEditorStore(w=>w.selectedDatabaseName),d=s.useEditorStore(w=>w.selectedSchemaName),u=s.useEditorStore(w=>w.selectedTableName),p=s.useEditorStore(w=>w.actions.setCurrentColumns),h=s.useEditorStore(w=>w.actions.setSelectedConnectionId),f=s.useEditorStore(w=>w.actions.setSelectedDatamodelId),b=s.useEditorStore(w=>w.actions.setSelectedDatabaseName),i=s.useEditorStore(w=>w.actions.setSelectedSchemaName),j=s.useEditorStore(w=>w.actions.setSelectedTableName);s.useEditorStore(w=>w.actions.setCardSql);function x(w){return o&&l&&d&&l!=="NA"?!0:o&&w==="API"?!1:!!(o&&w==="S3")}function C(w){return!!(o&&l&&l!=="NA"&&d&&u||o&&(w==="S3"||w==="API")||c&&c)}function g(w){return o&&w?!(w==="API"||w==="S3"):!1}const{refetch:I,data:k,isLoading:T,isError:v}=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:A,data:F,isLoading:V,isError:G}=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=k==null?void 0:k.connections.find(w=>w.id===o),E=m==null?void 0:m.type,q=(m==null?void 0:m.type)==="API"||(m==null?void 0:m.type)==="S3",{data:z,isLoading:B,isFetching:_,isError:N,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:g(E)}),{data:O,isLoading:H,isFetching:Q,isError:R,refetch:M}=s.useQuery({queryKey:["schemas",o,l],queryFn:()=>s.getRequest("https://semaphor.cloud/api/v1/schemas",(r==null?void 0:r.accessToken)||"",{connection_id:o,database_name:l}),enabled:!!o&&!!l&&!q&&l!=="NA"}),{data:U,isLoading:J,isFetching:D,isError:P,refetch:Z}=s.useQuery({queryKey:["tables",o,l,d],queryFn:()=>s.getRequest("https://semaphor.cloud/api/v1/tables",(r==null?void 0:r.accessToken)||"",{connection_id:o,database_name:l,schema_name:d}),enabled:x(E)}),{data:K,isLoading:te,isFetching:ae,isError:X,refetch:$}=s.useQuery({queryKey:["columns",o,l,c,d,u],queryFn:()=>s.getRequest("https://semaphor.cloud/api/v1/columns",(r==null?void 0:r.accessToken)||"",{connection_id:o,datamodel_id:c||"",database_name:l,schema_name:d,table_name:u}),enabled:C(E)});S.useEffect(()=>{p(a)},[K,p,a]),S.useEffect(()=>{(E==="S3"||E==="API")&&(b(""),i(""),f(""),E==="API"&&j("api"))},[E,j,b,i,f]);const W=(m==null?void 0:m.type)==="API"?(De=m==null?void 0:m.type)==null?void 0:De.toLowerCase():u||"",re=q?"":d||"";function L(w){i(w),j("")}function Y(w){b(w==="none"?"":w),i(""),j(""),w!=="none"&&w!==""&&f("")}function oe(w){h(w)}function ee(w){f(w==="none"?"":w),w!=="none"&&w!==""&&b("")}z&&((Te=z==null?void 0:z.databases)==null?void 0:Te.length)>0,O&&((Le=O==null?void 0:O.schemas)==null?void 0:Le.length)>0,K&&((Ae=K==null?void 0:K.columns)==null?void 0:Ae.length)>0&&(a=K.columns.map(w=>({...w,data_type:w.data_type.toLowerCase()}))),N&&(a=[]),(X||v)&&(a=[]);const me=k==null?void 0:k.connections.map(w=>({id:w.id,name:w.name,type:w.type})),ye=(Me=F==null?void 0:F.datamodels)==null?void 0:Me.map(w=>({id:w.id,name:w.name})),pe=z==null?void 0:z.databases.map(w=>({id:w.database_name,name:w.database_name})),Se=O==null?void 0:O.schemas.map(w=>({id:w.schema_name,name:w.schema_name})),Ss=U==null?void 0:U.tables.map(w=>({id:w.table_name,name:w.table_name})),Cs=(ze=F==null?void 0:F.datamodels.find(w=>w.id===c))==null?void 0:ze.name;return{connectionItems:me,isConnectionsLoading:T,isConnectionsError:v,modelItems:ye,selectedDatamodelId:c,selectedDatamodelName:Cs,isModelsLoading:V,isModelsError:G,databaseItems:pe,isDatabasesLoadingOrFetching:B||_,isDatabaseError:N,schemaItems:Se,isSchemaLoadingOrFetching:H||Q,isSchemaError:R,tableItems:Ss,isTableLoadingOrFetching:J||D,isTableError:P,columns:a,isColumnsLoadingOrFetching:te||ae,isColumnsError:X,isNonDbConnection:q,connectionType:E,tableName:W,schemaName:re,refetchConnections:I,refetchModels:A,refetchDatabases:y,refetchSchemas:M,refetchTables:Z,refetchColumns:$,handleConnectionChange:oe,handleDatamodelChange:ee,handleDatabaseChange:Y,handleSchemaChange:L}}function os({ColumnsComponent:t}){var X;const n=s.useEditorStore($=>$.selectedConnectionId),a=s.useDashboardStore($=>$.showFilters),r=s.useEditorStore($=>$.selectedDatamodelId),o=s.useEditorStore($=>$.selectedDatabaseName),c=s.useEditorStore($=>$.selectedSchemaName),l=s.useEditorStore($=>$.selectedTableName),d=s.useEditorStore($=>$.actions.setSelectedTableName),{connectionItems:u,modelItems:p,schemaItems:h,databaseItems:f,tableItems:b,columns:i,isConnectionsLoading:j,isModelsLoading:x,isConnectionsError:C,isModelsError:g,isDatabasesLoadingOrFetching:I,isDatabaseError:k,isSchemaLoadingOrFetching:T,isSchemaError:v,isColumnsError:A,isColumnsLoadingOrFetching:F,isTableLoadingOrFetching:V,isTableError:G,connectionType:m,isNonDbConnection:E,refetchDatabases:q,refetchModels:z,refetchSchemas:B,refetchTables:_,refetchColumns:N,refetchConnections:y,handleConnectionChange:O,handleDatabaseChange:H,handleSchemaChange:Q,handleDatamodelChange:R,tableName:M,schemaName:U}=ne();function J(){return t?t(U,M,i):e.jsx(Nt,{schemaName:U,tableName:M,columns:i,status:F?"Loading...":A?"Error":"Success"})}function D(){window.location.href="mailto:support@semaphor.cloud?subject=Help&body=I need help with..."}function P(){if(!n||m==="S3"||m==="API")return null;if(!r||r==="none")return e.jsx(ce,{refetch:q,showNone:!0,onChange:H,isError:k,isLoading:I,items:f,value:o||"",title:"Database",type:"combobox"})}function Z(){if(n&&!E&&(!o||o==="none")&&(!r||r==="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 K(){if(!n||m==="S3"||m==="API")return null;if(!o||o==="none")return e.jsx(ce,{refetch:z,showNone:!0,onChange:R,isError:g,isLoading:x,items:p,value:r||"",title:"Model",type:"combobox"})}function te(){return!n||m==="S3"||m==="API"||!o||o==="none"?null:e.jsx(ce,{refetch:B,onChange:Q,isError:v,isLoading:T,items:h,value:c||"",title:"Schema",type:"combobox"})}function ae(){function $(){let W=!1;return m==="API"?(W=!1,W):((m==="S3"||n&&o&&o!=="none"&&c)&&(W=!0),W)}return $()?e.jsx(ce,{refetch:_,onChange:d,isError:G,items:b,isLoading:V,value:l||"",title:"Table",type:"combobox"}):null}return e.jsxs("aside",{className:s.cn("flex h-full min-w-[300px] flex-col justify-between rounded-none",{"border-r-[1px]":!a}),children:[e.jsxs("section",{className:"space-y-3 px-6 py-4",children:[e.jsx(ce,{refetch:y,items:u,title:"Connection",value:n||"",onChange:O,isLoading:j,isError:C,type:"combobox",connectionTooltip:((X=u==null?void 0:u.find($=>$.id===n))==null?void 0:X.type)||""}),P(),Z(),K(),te(),ae()]}),J(),e.jsx("div",{className:"flex items-end justify-center gap-2 px-6 py-4",children:e.jsxs(s.Button,{onClick:D,size:"sm",variant:"secondary",className:"w-full",children:[e.jsx(et,{className:"mr-2 size-4"}),"Help"]})})]})}function wt(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 c=t.length;if(o!==-1&&(c=o),r!==-1&&r<c&&(c=r),n!==-1){const l=t.substring(0,n),d=t.substring(n);return`${l} {{ filters | where }} AND ${d.substring(6)}`}else if(a!==-1){const l=t.substring(0,a),d=t.substring(a);return`${l} {{ filters | where }} ${d}`}else{const l=t.substring(0,c),d=t.substring(c);return console.log("beforeClause",l),console.log("afterClause",d),d?`${l} {{ filters | where }} ${d}`:`${l.replace(/;$/,"")} {{ filters | where }}`}}function kt({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($e,{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($s,{className:"mr-2 h-4 w-4"}),"Debug with Assistant"]})]})})})]})}var is={color:void 0,size:void 0,className:void 0,style:void 0,attr:void 0},Re=S.createContext&&S.createContext(is),It=["attr","size","title"];function Et(t,n){if(t==null)return{};var a=Dt(t,n),r,o;if(Object.getOwnPropertySymbols){var c=Object.getOwnPropertySymbols(t);for(o=0;o<c.length;o++)r=c[o],!(n.indexOf(r)>=0)&&Object.prototype.propertyIsEnumerable.call(t,r)&&(a[r]=t[r])}return a}function Dt(t,n){if(t==null)return{};var a={};for(var r in t)if(Object.prototype.hasOwnProperty.call(t,r)){if(n.indexOf(r)>=0)continue;a[r]=t[r]}return a}function je(){return je=Object.assign?Object.assign.bind():function(t){for(var n=1;n<arguments.length;n++){var a=arguments[n];for(var r in a)Object.prototype.hasOwnProperty.call(a,r)&&(t[r]=a[r])}return t},je.apply(this,arguments)}function Ve(t,n){var a=Object.keys(t);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(t);n&&(r=r.filter(function(o){return Object.getOwnPropertyDescriptor(t,o).enumerable})),a.push.apply(a,r)}return a}function be(t){for(var n=1;n<arguments.length;n++){var a=arguments[n]!=null?arguments[n]:{};n%2?Ve(Object(a),!0).forEach(function(r){Tt(t,r,a[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(a)):Ve(Object(a)).forEach(function(r){Object.defineProperty(t,r,Object.getOwnPropertyDescriptor(a,r))})}return t}function Tt(t,n,a){return n=Lt(n),n in t?Object.defineProperty(t,n,{value:a,enumerable:!0,configurable:!0,writable:!0}):t[n]=a,t}function Lt(t){var n=At(t,"string");return typeof n=="symbol"?n:n+""}function At(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 ls(t){return t&&t.map((n,a)=>S.createElement(n.tag,be({key:a},n.attr),ls(n.child)))}function ue(t){return n=>S.createElement(Mt,je({attr:be({},t.attr)},n),ls(t.child))}function Mt(t){var n=a=>{var{attr:r,size:o,title:c}=t,l=Et(t,It),d=o||a.size||"1em",u;return a.className&&(u=a.className),t.className&&(u=(u?u+" ":"")+t.className),S.createElement("svg",je({stroke:"currentColor",fill:"currentColor",strokeWidth:"0"},a.attr,r,l,{className:u,style:be(be({color:t.color||a.color},a.style),t.style),height:d,width:d,xmlns:"http://www.w3.org/2000/svg"}),c&&S.createElement("title",null,c),t.children)};return Re!==void 0?S.createElement(Re.Consumer,null,a=>n(a)):n(is)}function zt(t){return ue({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 cs(t){const{theme:n}=s.useTheme(),a=s.useDashboardStore(x=>x.theme),r=s.useEditorStore(x=>x.frame),o=s.useEditorStore(x=>x.card),c=s.useEditorStore(x=>x.activeTabCardId),l=s.Le(),{refetch:d}=s.useDashboardCardQuery(o),{updateCardTab:u,setRunSql:p}=s.useEditorActions(),h=S.useRef(),f=S.useRef({}),b=r.cards.find(x=>x.id===c),i=S.useCallback(()=>{let x="";return t==="python"&&(x=(b==null?void 0:b.python)||s.PYTHON_DEFAULT_CODE),t==="sql"&&(x=(b==null?void 0:b.sql)||""),x},[t,b]);S.useEffect(()=>{if(c&&o.id&&o.id!==c){if(h.current&&l){const x=h.current.getModel();x&&(f.current[o.id]=x);let C=f.current[c];if(!C){const g=i();C=l.editor.createModel(g,t),f.current[c]=C}h.current.setModel(C)}u(c,o),p(!0)}},[c,o,u,l,p,t,i]),S.useEffect(()=>{if(!l)return;const x=window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light",C=a==="system"?x:a;l.editor.defineTheme("default",{base:C==="light"?"vs":"vs-dark",inherit:!0,rules:[],colors:{"editor.background":C==="light"?"#ffffff":s.hslStringToHex("240 10% 10%")}}),l.editor.setTheme("default")},[n,a,l]),S.useEffect(()=>{const x=h.current;x&&l&&o&&x.addCommand(l.KeyMod.Shift|l.KeyCode.Enter,function(){return d(),!1})},[l,d,o]);function j(x,C){if(h.current=x,!f.current[o.id]){const g=x.getModel(),I=i();f.current[o.id]=g||(C==null?void 0:C.editor.createModel(I,t))||x.getModel()}x.setModel(f.current[o.id])}return{handleEditorDidMount:j}}function Ot(){const t=s.useEditorStore(l=>l.card.sql),n=s.useEditorStore(l=>l.sqlGen),{setCardSql:a,setSqlGen:r}=s.useEditorActions(),{handleEditorDidMount:o}=cs("sql");function c(l){a(l),s.isObjectEmpty(n)||r({})}return e.jsx(s.Ft,{theme:"default",className:"pt-3",onChange:c,value:t||"",options:{minimap:{enabled:!1},wordWrap:"on",scrollbar:{verticalScrollbarSize:0,horizontalScrollbarSize:0},fontSize:13,renderLineHighlight:"none"},defaultLanguage:"sql",onMount:o})}function Ft(){const t=s.useEditorStore(o=>o.card.python),{setCardPython:n}=s.useEditorActions(),{handleEditorDidMount:a}=cs("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 Rt({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 ds(t){const[n,a]=S.useState(""),[r,o]=S.useState(null),{authToken:c}=s.useSemaphorContext(),l=s.useEditorStore(D=>{var P;return(P=D==null?void 0:D.card)==null?void 0:P.sql}),d=s.useEditorStore(D=>{var P;return(P=D==null?void 0:D.card)==null?void 0:P.python}),u=s.useEditorStore(D=>D.actions.setCardSql),p=s.useEditorStore(D=>D.actions.setRunSql),h=s.useEditorStore(D=>D.actions.switchCardType),f=s.useEditorStore(D=>D.currentAssitantScope)||[],b=s.useEditorStore(D=>D.userInputForAI),i=s.useEditorStore(D=>D.triggerAIRun),j=s.useEditorStore(D=>D.selectedDatabaseName),x=s.useEditorStore(D=>D.selectedTableName),C=s.useEditorStore(D=>D.selectedConnectionId),g=s.useEditorStore(D=>D.selectedSchemaName),I=s.useDashboardStore(D=>D.dashboard.aiScopeTables),{setTriggerAIRun:k,setCurrentAssitantScope:T}=s.useEditorActions(),{selectedDatamodelName:v,connectionType:A,selectedDatamodelId:F}=ne(),{messages:V,setMessages:G,reload:m,append:E,input:q,setInput:z,status:B,handleInputChange:_,handleSubmit:N,stop:y}=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:O,onFinish(D,P){H(P.usage),a(""),P.finishReason==="stop"&&a("")}});S.useEffect(()=>{i&&b&&(_({target:{value:b}}),setTimeout(()=>{N(),k(!1)},100))},[i,N,b,k,_]);async function O({toolCall:D}){if(D.toolName==="createChartFromSql"){const P=D.args.sql,Z=D.args.chartType;return h(Z),u(P),p(!0),{status:"success",message:"Let the user know that chart is created"}}else if(D.toolName==="getTableColumns")a("Getting table columns...");else{if(D.toolName==="getUserSql")return l?{status:"success",sql:l,python:d||""}:{status:"error",message:"No SQL found"};if(D.toolName==="getCurrentTableScope")return a("Getting table scope..."),U(),{status:"success",tables:f};a("Analyzing...")}}function H(D){o(P=>P?{promptTokens:P.promptTokens+D.promptTokens,completionTokens:P.completionTokens+D.completionTokens,totalTokens:P.totalTokens+D.totalTokens}:D)}function Q(D){const P=s.removeFromScopeArray(f,D);R(P)}function R(D){const P=s.sanitizeAIScope(D);T(P),G(Z=>[...Z,{id:crypto.randomUUID(),role:"system",content:`Current scope of tables | ${JSON.stringify(P)}`}])}function M(){const D={databaseName:j||"",schemaName:g||"",tableName:x||"",datamodelId:F||"",datamodelName:s.resolveDatamodelName(v),connectionId:C||"",connectionType:A||""},P=s.dedup([...f,D]);R(P)}function U(){const D={databaseName:j||"",schemaName:g||"",tableName:x||"",datamodelName:s.resolveDatamodelName(v),connectionId:C||"",connectionType:A||"",datamodelId:F||""};if(!s.isInAiScopeArray([...I||[],...f],D)||f.length===0){const Z=s.dedup([...I||[],...f,D]).filter(K=>K.connectionId===D.connectionId);R(Z)}}const J=!["ready","error"].includes(B);return{messages:V,setMessages:G,reload:m,append:E,input:q,setInput:z,isLoading:J,handleSetAIScope:U,handleAddCurrentTableToScope:M,removeFromCurrentSelections:Q,currentAssitantScope:f,setCurrentAssitantScope:T,handleInputChange:_,handleSubmit:N,stop:y,chatStatus:B,toolStatus:n,llmUsage:r,onFinish:t}}function Vt(){var re;const[t,n]=S.useState({queryKey:[],queryData:null}),a=s.useQueryClient(),[r,o]=S.useState(!1),[c,l]=S.useState(!1),d=s.useEditorStore(L=>L.frame),u=s.useEditorStore(L=>L.card),p=s.useEditorStore(L=>L.isShowingVisual),h=s.useEditorStore(L=>L.selectedConnectionId),f=s.useEditorStore(L=>L.selectedDatabaseName),b=s.useEditorStore(L=>L.selectedDatamodelId),i=s.useEditorStore(L=>L.selectedSchemaName),j=s.useEditorStore(L=>L.showAIDialog),x=s.useEditorStore(L=>L.selectedTableName),C=s.useEditorStore(L=>{var Y;return(Y=L==null?void 0:L.card)==null?void 0:Y.sql}),{sheetFilterValues:g}=s.useSheetFilterValues(),{setCardCustomCfg:I,setQueryResultColumns:k,setCardSql:T,setPythonStdOut:v,setCardPreferences:A,setCardType:F,setCardPython:V,runAssistant:G,setShowAIDialog:m}=s.useEditorActions(),E=s.useEditorStore(L=>L.onSave),q=s.useEditorStore(L=>L.onClose),z=s.useEditorStore(L=>L.actions.setSqlGen),B=s.useEditorStore(L=>L.runSql),_=s.useEditorStore(L=>L.actions.setRunSql),N=s.useEditorStore(L=>L.actions.setIsSqlRunning),{data:y,isLoading:O,isFetching:H,isSuccess:Q,isError:R,error:M,queryKey:U,refetch:J}=s.useDashboardCardQuery(u),{handleSetAIScope:D}=ds();S.useEffect(()=>{if(y&&(y.rowLimitExceeded&&s.ue.error("Row limit (10,000) exceeded. Refine your query.",{position:"top-center",richColors:!0}),v((y==null?void 0:y.output)||""),y.records.length>0)){const{dimensionKeys:L}=s.getKeys(y.records);k(L)}},[y,k,v]),S.useEffect(()=>{(O||H)&&N(!0),(R||Q)&&N(!1),R&&(k([]),v(""))},[O,H,y,v,R,Q,N,k,M]),S.useEffect(()=>{B&&(a.getQueryData(U)||J(),_(!1))},[B,J,_,U,a]);function P(){const L=a.getQueryData(U);t.queryData||n({queryKey:U,queryData:L}),a.setQueryData(U,null),a.removeQueries({queryKey:U,exact:!0}),T(""),z({}),V(""),I(""),A({}),F("bar")}function Z(L,Y){if(L.length===0)return"";if(Y){const oe=L.find(ee=>ee.id===Y);if(oe){const ee=oe.tabTitle;if(ee=="All__Header")return L[0].id;if(ee&&ee.endsWith("__Header")){const ye=ee.split("__")[0],pe=L.find(Se=>Se.tabTitle===ye);return pe?pe.id:L[0].id}return Y}}return L[0].id}function K(){let L=C;C&&!C.includes("{{")&&(L=wt(C),T(L));const Y={...u,lastSelectedSchema:i,lastSelectedDatamodelId:b,lastSelectedDatabase:f,lastSelectedTable:x,connectionId:h,type:p?u.type:"table",sql:L,customCfg:p?u.customCfg:null},oe=d.cards.map(me=>me.id===u.id?Y:me),ee={...d,cards:oe,activeCardId:Z(oe,d.activeCardId)};E==null||E(ee)}function te(){const{queryKey:L,queryData:Y}=t;L&&Y&&a.setQueryData(L,Y),z({}),q==null||q()}async function ae(){const L=`Can you help me debug this query in the current table scope?
|
|
312
312
|
|
|
313
313
|
Error:
|
|
314
314
|
|
|
@@ -318,5 +318,5 @@
|
|
|
318
318
|
|
|
319
319
|
${C}
|
|
320
320
|
|
|
321
|
-
`;G(T)}function X(){return e.jsxs(e.Fragment,{children:[c&&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(Rt,{jsonString:JSON.stringify(j,null,2)})})}),j&&j.length>0&&e.jsx(s.Button,{variant:"ghost",onClick:()=>i(!c),className:"absolute bottom-0 right-6 size-7 p-1",children:c?e.jsx(s.X,{className:"size-3.5 text-muted-foreground"}):e.jsx(Je,{className:"size-3.5 text-muted-foreground"})})]})}function $(){return e.jsxs(s.ResizablePanelGroup,{className:"flex grow pb-1",direction:"vertical",role:"editor-resizable-group",children:[e.jsxs(s.ResizablePanel,{id:"1",order:1,defaultSize:r?20:100,className:"relative flex grow",children:[e.jsx("div",{id:"sql-container",className:"relative flex w-[99%]",children:e.jsx(Ot,{})}),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(Ft,{})}),e.jsx("code",{className:"absolute right-6 top-3 text-xs text-muted-foreground/70",children:"python"})]})]})]})}const W=(M==null?void 0:M.message)||((re=y==null?void 0:y.error)==null?void 0:re.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:[$(),X()]}),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:O||H,onClick:()=>{J()},className:"shrink-0",size:"sm",children:[O||H?e.jsx(ie,{className:"mr-2 h-4 w-4 animate-spin"}):e.jsx(s.Play,{className:"mr-2 h-4 w-4"}),"Run"]}),e.jsx(kt,{sql:y==null?void 0:y.sql,error:W,onClick:ae}),e.jsxs(s.Button,{onClick:P,className:"",size:"sm",variant:"secondary",children:[e.jsx(Bs,{className:"mr-2 size-4"}),"Clear"]}),e.jsx(s.Toggle,{pressed:r,onPressedChange:T=>o(T),className:"",size:"sm",children:e.jsx(zt,{className:"size-4 text-foreground/70"})}),e.jsx("button",{disabled:g,onClick:()=>{D(),m(!0)},className:"h-9 w-full cursor-text px-3 text-left text-sm text-muted-foreground",children:g?"":"Type your question..."})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(s.Button,{onClick:te,className:"w-full",size:"sm",variant:"secondary",children:[e.jsx(s.Cross2Icon,{className:"mr-2 size-4"}),"Close"]}),e.jsxs(s.Button,{onClick:K,size:"sm",variant:"secondary",children:[e.jsx(s.Check,{className:"mr-2 size-4 font-bold text-green-600"}),"Accept"]})]})]})]})}function qt({data:t}){var i;const[n,a]=S.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]})})}})),c=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:c.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:(i=c.getRowModel().rows)!=null&&i.length?c.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 Bt({card:t}){var I,k,L,v,A,F,V,G,m,E,q;const[n,a]=S.useState(!1),[r,o]=S.useState([]),{authToken:c}=s.useSemaphorContext(),i=s.getTokenParams(c==null?void 0:c.accessToken),d=s.useDashboardStore(z=>z.themeStyle),u={colors:((k=(I=d==null?void 0:d.chart)==null?void 0:I.dataset)==null?void 0:k.backgroundColor)||[]};(L=t.customCardPreferences)!=null&&L.inputData;const{getCard:x}=s.useCustomVisual(((v=t.customCardPreferences)==null?void 0:v.url)||""),h=((A=t.customCardPreferences)==null?void 0:A.visualType)||"single",f=s.useEditorStore(z=>z.frame),{setCustomCardPreferences:b}=s.useEditorActions(),{data:l}=s.useDashboardCardQuery(t),g=S.useCallback((z,B)=>{o(_=>({..._,[z]:B}))},[]);if(!((F=t.customCardPreferences)!=null&&F.componentName))return null;const p=x((V=t.customCardPreferences)==null?void 0:V.componentName);function C(z){a(z)}const j=Object.keys(((G=t.customCardPreferences)==null?void 0:G.dataInputCardIds)||{}).map(z=>{var N,y,O;const B=(y=(N=t.customCardPreferences)==null?void 0:N.dataInputCardIds)==null?void 0:y[z].cardId,_=(O=f==null?void 0:f.cards)==null?void 0:O.find(H=>H.id===B);return _||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(S.Suspense,{fallback:e.jsx(e.Fragment,{}),children:[p&&h==="single"&&e.jsx(p,{params:i,theme:u,settings:(m=t.customCardPreferences)==null?void 0:m.settings,onDataChange:g,data:(l==null?void 0:l.records)||[]}),p&&h==="multiple"&&e.jsxs(e.Fragment,{children:[Object.keys(((E=t.customCardPreferences)==null?void 0:E.dataInputCardIds)||{}).map(z=>{var N,y,O;const B=(y=(N=t.customCardPreferences)==null?void 0:N.dataInputCardIds)==null?void 0:y[z].cardId,_=(O=f==null?void 0:f.cards)==null?void 0:O.find(H=>H.id===B);if(_)return e.jsx(s.MultiInputEmptyRenderer,{onLoadingStatus:C,onDataChange:g,dataInputIndex:z,card:_},_.id+z)}),e.jsx("div",{className:"flex flex-col gap-2",children:e.jsx(p,{theme:u,onDataChange:g,settings:j.map(z=>{var B;return(B=z==null?void 0:z.customCardPreferences)==null?void 0:B.settings}),data:j.map(z=>z!=null&&z.id?r==null?void 0:r[z.id]:[])})})]})]},(q=t.customCardPreferences)==null?void 0:q.componentName)})}function us({className:t,...n}){var C;const a=s.useEditorStore(j=>j.card),r=((C=a.customCardPreferences)==null?void 0:C.showCardHeader)??!0,o=s.useEditorStore(j=>j.frame),c=s.useDashboardStore(j=>j.dashboard.filters);s.useEditorStore(j=>j.actions.setRunSql);const{updateFilter:i}=s.useDashboardActions(),d=c==null?void 0:c.find(j=>j.id===o.filterId),{data:u,isLoading:x,isFetching:h}=s.useDashboardCardQuery(a),{setCard:f}=s.useEditorActions(),{data:b}=s.useTopoJson(a),l=S.useMemo(()=>!a.id||!(u!=null&&u.records)?null:s.createChartConfig({data:u==null?void 0:u.records,cardType:a.type,customCfg:a.customCfg,preferences:a.preferences,topoJson:b}),[a.id,u==null?void 0:u.records,a.type,a.customCfg,a.preferences,b]);function g(j){return e.jsx(Bt,{card:j})}function p(){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.id)return null;if(a.type==="custom")return g(a);if(!["table","custom"].includes(a.type)&&l)return e.jsx(e.Fragment,{children:x||h?e.jsx(e.Fragment,{}):e.jsx(s.ChartJsVisual,{cfg:l})});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=>f({...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=>f({...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=>i({...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 Ce=({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}),Pt=()=>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."})]})]}),_t=({customCode:t,cardCustomCfgString:n,mergedConfig:a,onConfigChange:r,onCodeChange:o})=>e.jsxs(s.Tabs,{defaultValue:"final-config",className:"flex w-1/2 flex-col",children:[e.jsxs(s.TabsList,{className:"justify-start rounded-sm rounded-b-none border border-b-0",children:[e.jsx(s.TabsTrigger,{value:"final-config",children:"Config"}),e.jsx(s.TabsTrigger,{value:"custom-config",children:"Changes"}),e.jsx(s.TabsTrigger,{value:"custom-code",children:"Custom Code"})]}),e.jsx(s.TabsContent,{value:"final-config",className:"mt-0 grow rounded-b border border-t-0",children:e.jsx(Ce,{language:"json",value:a,onChange:r})}),e.jsx(s.TabsContent,{value:"custom-config",className:"mt-0 grow rounded-b border border-t-0",children:e.jsx(Ce,{readonly:!0,language:"json",value:n,onChange:()=>{}})}),e.jsx(s.TabsContent,{value:"custom-code",className:"mt-0 grow rounded-b border border-t-0",children:e.jsx(Ce,{language:"javascript",value:t,onChange:o})})]}),Ht=({error:t,hasCardCustomConfig: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 Gt(){const[t,n]=S.useState(!1),[a,r]=S.useState(""),[o,c]=S.useState(""),[i,d]=S.useState(""),[u,x]=S.useState(""),h=s.useEditorStore(v=>v.card),f=s.useEditorStore(v=>v.card.customCfg),b=f?JSON.stringify(f,null,2):"",{data:l}=s.useDashboardCardQuery(h),{data:g}=s.useTopoJson(h),{setCardCustomCfg:p,setCustomVisualCode:C}=s.useEditorActions(),j=v=>{var A,F;return JSON.stringify({...v,data:{...v.data,datasets:(F=(A=v.data)==null?void 0:A.datasets)==null?void 0:F.map(V=>({...V,data:[]}))}},null,2)},I=()=>{var A,F;if(!((A=l==null?void 0:l.records)!=null&&A.length))return;const v=s.createChartConfig({data:l.records,cardType:h.type,preferences:h.preferences,topoJson:g});if(v){r(j(v)),d(((F=h.preferences)==null?void 0:F.customVisualCode)||"");const V=s.merge(v,f);c(j(V))}},k=()=>{try{if(i&&C(i),o){const v=JSON.parse(o),A=s.getObjectDiff(JSON.parse(a),v);p(A),x("")}}catch{x("Invalid JSON configuration")}},L=Object.keys(f||{}).length===0;return e.jsxs(s.Dialog,{open:t,onOpenChange:n,children:[e.jsx(s.DialogTrigger,{asChild:!0,children:e.jsx(s.IconButton,{tooltip:"Customize Visual",onClick:I,className:L?"":"text-green-600 hover:text-green-700",children:e.jsx(s.Settings,{className:"h-4 w-4"})})}),e.jsxs(s.DialogContent,{className:"flex h-[600px] grow flex-col overflow-auto sm:min-w-[900px] lg:min-w-[1200px]",children:[e.jsx(Pt,{}),e.jsxs("div",{className:"flex grow gap-2",children:[e.jsx(s.ErrorBoundary,{FallbackComponent:s.FallbackEditorCard,children:e.jsx(us,{className:"w-1/2 rounded shadow-none"})}),e.jsx(_t,{customCode:i,cardCustomCfgString:b,mergedConfig:o,onConfigChange:v=>c(v??""),onCodeChange:v=>d(v??"")})]}),e.jsx(Ht,{error:u,hasCardCustomConfig:!!f,onReset:()=>{c(a),p(null)},onApply:k,onClose:()=>n(!1)})]})]})}function hs(t){return ue({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 $t(t){return ue({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 ms(t){return ue({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 xs(t){return ue({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 ps(t){return ue({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 fs(t){const[n,a]=S.useState(null);return n}function gs(){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 Ut({onChartTypeChange:t}){const[n,a]=S.useState([]),{data:r}=gs();return S.useEffect(()=>{(async()=>{var c;if(r){const d=(await Promise.all((c=r==null?void 0:r.plugins)==null?void 0:c.map(async u=>(await s.loadManifest(u.value)).visuals.map(f=>({name:f.name,icon:f.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,c)=>e.jsx(Qt,{text:o.name,onClick:()=>t("custom",o),icon:o.icon},o.url+o.name+c))})]})}const Qt=({text:t,icon:n,onClick:a})=>{const r=fs(),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 Jt(){var f,b;const[t,n]=S.useState(!1),a=s.useEditorStore(l=>l.card),r=a.type,o=s.useDashboardStore(l=>l.isVisualEditing),{setCardType:c,setCardPreferences:i,setChartOrientation:d}=s.useEditorStore(l=>l.actions),{setCardCustomCfg:u,setCustomCardPreferences:x}=s.useEditorActions();function h(l,g){u(null),i({}),c(l),g&&x({type:"component",visualType:"single",url:g.url,componentName:g.name,icon:g.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:o?"ghost":"outline",children:e.jsx(Kt,{className:"size-4",chartType:r,customIcon:(f=a.customCardPreferences)==null?void 0:f.icon,componentName:(b=a.customCardPreferences)==null?void 0:b.componentName})})}),e.jsxs(s.PopoverContentCustom,{onOpenAutoFocus:l=>l.preventDefault(),className:"w-50",children:[e.jsxs("div",{className:"grid grid-cols-4 place-items-center",children:[e.jsx(s.IconButton,{tooltip:"Bar Chart",onClick:()=>h("bar"),className:"h-10 p-4",children:e.jsx(Ne,{className:"size-5"})}),e.jsx(s.IconButton,{tooltip:"Line Chart",onClick:()=>h("line"),className:"h-10 p-4",children:e.jsx(we,{className:"size-5"})}),e.jsx(s.IconButton,{tooltip:"Stacked Bar Chart",onClick:()=>h("stackedBar"),className:"h-10 p-4",children:e.jsx(Pe,{className:"size-5"})}),e.jsx(s.IconButton,{tooltip:"Stacked Line Chart",onClick:()=>h("stackedLine"),className:"h-10 p-4",children:e.jsx(xs,{className:"size-5",strokeWidth:0})}),e.jsx(s.IconButton,{tooltip:"Scatter Chart",onClick:()=>h("scatter"),className:"h-10 p-4",children:e.jsx(Ge,{className:"size-5"})}),e.jsx(s.IconButton,{tooltip:"Bubble Chart",onClick:()=>h("bubble"),className:"h-10 p-4",children:e.jsx(ms,{className:"size-5"})}),e.jsx(s.IconButton,{tooltip:"Pie Chart",onClick:()=>h("pie"),className:"h-10 p-4",children:e.jsx(He,{className:"size-5"})}),e.jsx(s.IconButton,{tooltip:"Doughnut Chart",onClick:()=>h("doughnut"),className:"h-10 p-4",children:e.jsx(Ue,{className:"size-5"})}),e.jsx(s.IconButton,{tooltip:"Radar Chart",onClick:()=>h("radar"),className:"h-10 p-4",children:e.jsx(We,{className:"size-5"})}),e.jsx(s.IconButton,{tooltip:"Polar Area Chart",onClick:()=>h("polarArea"),className:"h-10 p-4",children:e.jsx(hs,{className:"size-6"})}),e.jsx(s.IconButton,{tooltip:"Pyramid Chart",onClick:()=>h("pyramid"),className:"h-10 p-4",children:e.jsx(Xe,{className:"size-5"})}),e.jsx(s.IconButton,{tooltip:"Range Chart",onClick:()=>h("range"),className:"h-10 p-4",children:e.jsx(_e,{className:"size-5"})}),e.jsx(s.IconButton,{tooltip:"Table",onClick:()=>h("table"),className:"h-10 p-4",children:e.jsx(ke,{className:"size-5"})}),e.jsx(s.IconButton,{tooltip:"KPI",onClick:()=>h("kpi"),className:"h-10 p-4",children:e.jsx(ps,{className:"size-6"})}),e.jsx(s.IconButton,{tooltip:"Text",onClick:()=>h("text"),className:"h-10 p-4",children:e.jsx(Ls,{className:"size-5"})}),e.jsx(s.IconButton,{tooltip:"Map",onClick:()=>h("map"),className:"h-10 p-4",children:e.jsx(Ke,{className:"size-5"})}),e.jsx(s.IconButton,{tooltip:"Custom",onClick:()=>h("custom"),className:"h-10 p-4",children:e.jsx(Ye,{className:"size-5"})})]}),e.jsx(Ut,{onChartTypeChange:h})]})]})}function Kt({chartType:t,className:n,customIcon:a,componentName:r}){const o=fs();switch(t){case"bar":return e.jsx(Ne,{className:n});case"line":return e.jsx(we,{className:n});case"pie":return e.jsx(He,{className:n});case"radar":return e.jsx(We,{className:n});case"scatter":return e.jsx(Ge,{className:n});case"bubble":return e.jsx(ms,{className:n});case"doughnut":return e.jsx(Ue,{className:n});case"stackedBar":return e.jsx(Pe,{className:n});case"stackedLine":return e.jsx(xs,{className:n});case"polarArea":return e.jsx(hs,{className:n});case"pyramid":return e.jsx(Xe,{className:n});case"range":return e.jsx(_e,{className:n});case"kpi":return e.jsx(ps,{className:n});case"text":return e.jsx(es,{className:n});case"map":return e.jsx(Ke,{className:n});case"custom":return a&&o?e.jsx(o,{className:n}):r?r==null?void 0:r.charAt(0).toUpperCase():e.jsx(Ye,{className:n});default:return e.jsx(ke,{className:n})}}const fe="focus-visible:ring-0 focus-visible:ring-ring focus-visible:ring-offset-0";function qe(t,n){var r,o,c;const a=s.getNumberAxis(t,n);return((c=(o=(r=t==null?void 0:t.chartOptions)==null?void 0:r.scales)==null?void 0:o[a])==null?void 0:c.type)||"linear"}function Wt(){var _,N,y,O,H,Q;const[t,n]=S.useState(!1),a=s.useEditorStore(R=>{var M;return(M=R.card)==null?void 0:M.preferences}),r=s.getNumberAxis(a,{}),[o,c]=S.useState(qe(a)),[i,d]=S.useState(((y=(N=(_=a==null?void 0:a.chartOptions)==null?void 0:_.scales)==null?void 0:N[r])==null?void 0:y.min)||""),[u,x]=S.useState(((Q=(H=(O=a==null?void 0:a.chartOptions)==null?void 0:O.scales)==null?void 0:H[r])==null?void 0:Q.max)||""),[h,f]=S.useState(i||u?"custom":"auto"),[b,l]=S.useState(""),[g,p]=S.useState(0),[C,j]=S.useState(""),[I,k]=S.useState(""),[L,v]=S.useState(""),A=s.useEditorStore(R=>R.actions.setCardPreferences),{updateCardInFrame:F}=s.useEditorActions(),V=s.useEditorStore(R=>R.card),G=s.useEditorStore(R=>{var M;return(M=R.card)==null?void 0:M.type}),m=["pie","doughnut","polarArea"].includes(G);S.useEffect(()=>{var R,M,U,J,D,P,Z,K,te,ae,X,$,W,re;c(qe(a)),d(((U=(M=(R=a==null?void 0:a.chartOptions)==null?void 0:R.scales)==null?void 0:M[r])==null?void 0:U.min)===0?0:""),x(((P=(D=(J=a==null?void 0:a.chartOptions)==null?void 0:J.scales)==null?void 0:D[r])==null?void 0:P.max)||""),l(((ae=(te=(K=(Z=a==null?void 0:a.chartOptions)==null?void 0:Z.scales)==null?void 0:K[r])==null?void 0:te.ticks)==null?void 0:ae.stepSize)||""),p(((X=a==null?void 0:a.numberAxisFormat)==null?void 0:X.decimalPlaces)||0),j((($=a==null?void 0:a.numberAxisFormat)==null?void 0:$.suffix)||""),k(((W=a==null?void 0:a.numberAxisFormat)==null?void 0:W.currency)||""),v(((re=a==null?void 0:a.numberAxisFormat)==null?void 0:re.locale)||"")},[t,a,r]);function E(R,M){return M===""||/^[0-9\b]+$/.test(M)?Number(M):Number(R)}function q(){const R=[...new Set(s.LOCALE_CURRENCY_PAIRS.map(M=>M.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:I||"none",onValueChange:M=>k(M==="none"?"":M),children:[e.jsx(s.SelectTrigger,{className:"col-span-2 h-8 w-full focus:ring-1 focus:ring-offset-0",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{children:e.jsxs(s.SelectGroup,{children:[e.jsx(s.SelectLabel,{children:"Currency"}),e.jsx(s.SelectItem,{value:"none",children:"None"}),R.map(M=>e.jsx(s.SelectItem,{value:M,children:M},M))]})})]}),e.jsxs(s.Select,{value:L,onValueChange:M=>v(M),children:[e.jsx(s.SelectTrigger,{className:"col-span-2 h-8 w-full focus:ring-1 focus:ring-offset-0",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{children:e.jsxs(s.SelectGroup,{children:[e.jsx(s.SelectLabel,{children:"Locale"}),s.LOCALE_CURRENCY_PAIRS.map(M=>e.jsx(s.SelectItem,{value:M.locale,children:M.locale},M.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:g,onChange:M=>p(Number(M.target.value)),id:"format",className:`col-span-6 h-8 w-full tracking-wide ${fe}`})]})]})}function z(){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:i,onChange:R=>d(M=>E(M,R.target.value)),className:`col-span-1 h-8 w-full ${fe}`}),e.jsx(s.Input,{value:u,onChange:R=>x(M=>E(M,R.target.value)),id:"max",className:`col-span-1 h-8 w-full ${fe}`})]}),e.jsxs("div",{className:"grid grid-cols-3 items-center gap-2",children:[e.jsx(s.Label,{htmlFor:"step-size",children:"Step Size"}),e.jsx(s.Input,{value:b,onChange:R=>l(M=>E(M,R.target.value)),id:"step-size",className:`col-span-1 h-8 w-full ${fe}`})]})]})}function B(){var J;let R={};h==="custom"&&(R={min:i,max:u,ticks:{stepSize:b}});const M={...a||{},chartOptions:{...a==null?void 0:a.chartOptions,scales:{...(J=a==null?void 0:a.chartOptions)==null?void 0:J.scales,[r]:{type:o,...o==="linear"?R:{}}}},numberAxisFormat:{decimalPlaces:g,suffix:C,currency:I,locale:L}};console.log(M),A(M);const U={...V,preferences:M};F(U)}return e.jsxs(s.Popover,{onOpenChange:R=>n(R),children:[e.jsx(s.PopoverTrigger,{asChild:!0,children:e.jsx(s.IconButton,{tooltip:"Scale Options",children:e.jsx(ot,{className:"size-4 rotate-45"})})}),e.jsx(s.PopoverContentCustom,{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:m,value:o,onValueChange:R=>c(R),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"})]})})]})]}),o=="linear"&&e.jsxs("div",{className:"grid grid-cols-3 items-center gap-2 py-1",children:[e.jsx(s.Label,{htmlFor:"scale-option",children:"Setup"}),e.jsxs(s.RadioGroup,{disabled:m,id:"scale-option",value:h,onValueChange:R=>f(R),className:"col-span-2 flex gap-3",defaultValue:"x",children:[e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(s.RadioGroupItem,{value:"auto",id:"r1"}),e.jsx("label",{className:"text-sm",htmlFor:"r1",children:"Auto"})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(s.RadioGroupItem,{value:"custom",id:"r2"}),e.jsx("label",{className:"text-sm",htmlFor:"r2",children:"Custom"})]})]})]}),h==="custom"&&o=="linear"&&z(),q(),e.jsx(s.SelectSeparator,{}),e.jsx("div",{className:"grid grid-cols-3",children:e.jsx(s.Button,{onClick:B,variant:"secondary",className:"col-span-1 col-start-3 h-8 w-full",children:"Apply"})})]})]})})]})}function Zt(){const t=s.useEditorStore(d=>{var u,x,h,f;return(f=(h=(x=(u=d.card.preferences)==null?void 0:u.chartOptions)==null?void 0:x.plugins)==null?void 0:h.legend)==null?void 0:f.position}),n=s.useEditorStore(d=>{var u,x,h,f;return(f=(h=(x=(u=d.card.preferences)==null?void 0:u.chartOptions)==null?void 0:x.plugins)==null?void 0:h.legend)==null?void 0:f.align}),a=s.useEditorStore(d=>{var u,x,h,f;return(f=(h=(x=(u=d.card.preferences)==null?void 0:u.chartOptions)==null?void 0:x.plugins)==null?void 0:h.legend)==null?void 0:f.display}),{setLegendOptions:r}=s.useEditorActions(),o=d=>{r({display:d,position:t,align:n})},c=d=>{r({display:a,position:d,align:n})},i=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(Js,{className:"size-4"})})}),e.jsx(s.PopoverContentCustom,{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("div",{className:"col-span-2 flex h-8 items-center",children:[e.jsx(s.IconButton,{tooltip:"Top",onClick:()=>c("top"),children:e.jsx(s.ArrowUp,{className:"size-4"})}),e.jsx(s.IconButton,{tooltip:"Left",onClick:()=>c("left"),children:e.jsx(Es,{className:"size-4"})}),e.jsx(s.IconButton,{tooltip:"Bottom",onClick:()=>c("bottom"),children:e.jsx(Is,{className:"size-4"})}),e.jsx(s.IconButton,{tooltip:"Right",onClick:()=>c("right"),children:e.jsx(Ds,{className:"size-4"})})]})]}),e.jsxs("div",{className:"grid grid-cols-3 items-center gap-4",children:[e.jsx(s.Label,{htmlFor:"align",children:"Align"}),e.jsxs("div",{className:"col-span-2 flex h-8 items-center",children:[e.jsx(s.IconButton,{tooltip:"Start",onClick:()=>i("start"),children:e.jsx(ws,{className:"size-4"})}),e.jsx(s.IconButton,{tooltip:"Center",onClick:()=>i("center"),children:e.jsx(Ns,{className:"size-4"})}),e.jsx(s.IconButton,{tooltip:"End",onClick:()=>i("end"),children:e.jsx(ks,{className:"size-4"})})]})]})]})]})})]})}function Yt(){var c;const t=s.useEditorStore(i=>i.card.preferences),{setCardPreferences:n,setChartOrientation:a}=s.useEditorStore(i=>i.actions);function r(i){a(i)}const o=((c=t==null?void 0:t.chartOptions)==null?void 0:c.indexAxis)||"x";return e.jsx(s.IconButton,{onClick:()=>r(o==="y"?"x":"y"),tooltip:"Chart Orientation",children:o==="y"?e.jsx(tt,{className:"size-4"}):e.jsx(st,{className:"size-4"})})}function Xt(){const t=s.useEditorStore(i=>i.card),n=s.useEditorStore(i=>i.isShowingVisual),a=s.useEditorStore(i=>{var d,u;return(u=(d=i.card)==null?void 0:d.preferences)==null?void 0:u.chartOptions}),r=s.getChartGridStyle(a),{setChartGrid:o}=s.useEditorActions();function c(){const i=["xy","none","x","y"],u=(i.indexOf(r)+1)%i.length;o(i[u])}return n?e.jsxs("div",{"data-info":"visual-settings",className:"flex items-center",children:[["line","bar","range","stackedBar","stackedLine","horizontalBar"].includes(t.type)&&e.jsx(Yt,{}),!["kpi","text","custom","table"].includes(t.type)&&e.jsxs(e.Fragment,{children:[e.jsx(Wt,{}),e.jsx(Zt,{})]}),!["pie","doughnut","radar","polarArea","table","custom","kpi","text","map"].includes(t.type)&&e.jsxs(s.IconButton,{tooltip:"Grid Style",onClick:c,children:[(r==="xy"||!r)&&e.jsx(Gs,{className:"size-4"}),r==="x"&&e.jsx(Rs,{className:"size-4"}),r==="y"&&e.jsx(rt,{className:"size-4"}),r==="none"&&e.jsx(dt,{className:"size-4"})]})]}):null}function Be(){var _;const t=s.useEditorStore(N=>N.frame),n=s.useEditorStore(N=>N.card),a=s.useEditorStore(N=>N.isShowingVisual),r=s.useDashboardStore(N=>N.isVisualEditing),o=s.useEditorStore(N=>N.isSqlRunning),c=s.useEditorStore(N=>N.pythonStdOut),i=s.useEditorStore(N=>{var y;return(y=N.card.preferences)==null?void 0:y.chartOptions});s.useEditorStore(N=>N.actions.setRunSql),s.getChartGridStyle(i);const{setFrame:d,setCard:u,updateCardInFrame:x,setActiveTabCardId:h,runAssistant:f,setChartGrid:b}=s.useEditorActions(),{data:l,isLoading:g,isFetching:p,error:C}=s.useDashboardCardQuery(n);if(!n)return e.jsx(e.Fragment,{children:"No Active Card"});function j(){const N={connectionId:n.connectionId,id:s.v4(),title:"Title",description:"Description",preferences:{onClickFilter:[{columnIndex:0,expression:""}]},type:"bar",sql:"",data:[]};I(N)}function I(N){const y={...t,cards:[...t.cards,N],activeCardId:N.id};d(y),h(N.id)}function k(){const N={...n,id:s.v4(),title:`${n.title} Copy`,tabTitle:`${n.tabTitle||n.title} Copy`};I(N)}function L(N){const y=t.cards.filter(Q=>Q.id!==N),O=y[0],H={...t,cards:y,activeCardId:O.id};d(H),h(O.id),u(O)}function v(N){h(N)}const A=(N,y)=>{console.log("handleDragStart",y),N.dataTransfer.setData("tabIndex",y.toString())},F=N=>{N.preventDefault()},V=(N,y)=>{const O=N.dataTransfer.getData("tabIndex");if(O===y.toString())return;const H=Array.from(t.cards),[Q]=H.splice(parseInt(O),1);H.splice(y,0,Q),d({...t,cards:H})};function G(N,y){return N.cards.length===1&&(y.displayTab===!0||y.displayTab===void 0)||N.activeCardId!==y.id&&(y.displayTab===!0||y.displayTab===void 0)?null:e.jsx("div",{onClick:()=>{const O=y.displayTab===void 0?!1:!y.displayTab;u({...y,displayTab:O}),x({...y,displayTab:O})},children:y.displayTab===!0||y.displayTab===void 0?e.jsx(s.Eye,{className:"mr-2 size-3.5 text-muted-foreground hover:text-foreground"}):e.jsx(Ps,{className:"mr-2 size-3.5 text-muted-foreground hover:text-foreground"})})}function m(){return e.jsxs(s.Tabs,{onValueChange:v,value:t.activeCardId,className:"flex grow flex-col",children:[t.cards.map(N=>e.jsx(s.TabsContent,{className:"mt-0 grow",value:N.id,children:E()},N.id)),e.jsx(s.TabsList,{className:"group mx-6 justify-between overflow-x-auto",children:e.jsxs("div",{className:"flex items-center",children:[t.cards.map((N,y)=>e.jsx(s.Editable,{text:N.tabTitle||N.title,onSave:O=>{u({...n,tabTitle:O}),x({...n,tabTitle:O})},children:e.jsxs(s.TabsTrigger,{draggable:!0,onDragStart:O=>A(O,y),onDragOver:F,onDrop:O=>V(O,y),className:"",value:N.id,children:[G(t,N),N.tabTitle||N.title,t.activeCardId===N.id&&t.cards.length>1&&e.jsx(s.X,{className:"ml-2 size-3.5 text-muted-foreground hover:text-foreground",onClick:()=>L(N.id)})]})},N.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:k,children:e.jsx(Vs,{className:"h-4 w-4"})})]})})]})}function E(){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:l==null?void 0:l.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:o,card:n,data:l==null?void 0:l.records})})})}):e.jsx(s.ErrorBoundary,{FallbackComponent:s.FallbackEditorCard,children:e.jsx(us,{className:"grow border-none shadow-none"})})}function q(){const N=JSON.stringify(l==null?void 0:l.records,null,2),y=new Blob([N],{type:"application/json"}),O=URL.createObjectURL(y),H=document.createElement("a");H.href=O,H.download=`${n.title}.json`,H.click()}function z(){const y=[Object.keys(l==null?void 0:l.records.reduce((R,M)=>({...R,...M}),{})).join(","),...((l==null?void 0:l.records)||[]).map(R=>Object.values(R).join(","))].join(`
|
|
322
|
-
`),O=new Blob([y],{type:"text/csv"}),H=URL.createObjectURL(O),Q=document.createElement("a");Q.href=H,Q.download=`${n.title}.csv`,Q.click()}function B(){const N=`Can you get the documentation for ${n.type} chart?`;f(N)}return e.jsxs("div",{className:"relative isolate flex h-full flex-col py-3",children:[(g||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(ie,{className:"h-8 w-8 animate-spin text-muted-foreground"})}),e.jsxs("div",{className:"z-10 mb-0 flex min-h-10 items-center justify-end gap-2 px-6",children:[a&&e.jsxs("div",{className:"flex grow items-center",children:[e.jsx(Jt,{}),r&&e.jsx(s.IconButton,{tooltip:"Visual Docs",onClick:B,children:e.jsx(Ts,{className:"size-4"})}),!["table","custom"].includes(n.type)&&r&&e.jsx(Gt,{})]}),!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:z,children:e.jsx($t,{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:q,children:e.jsx(_s,{strokeWidth:1.5,className:"size-4"})}),e.jsx(s.CopyButton,{text:JSON.stringify(l==null?void 0:l.records,null,2),className:"h-7 w-fit px-1 font-mono text-xs text-muted-foreground/70"})]}),e.jsx(Xt,{}),e.jsx(sa,{})]}),a?m():e.jsxs(s.ResizablePanelGroup,{className:"px-6",direction:"horizontal",children:[c&&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:c&&e.jsx(ea,{})}),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:[(l==null?void 0:l.records)&&(l==null?void 0:l.records.length)>0&&e.jsx(qt,{data:(l==null?void 0:l.records)||[]}),(C||(l==null?void 0:l.error))&&e.jsx("span",{className:"font-mono text-xs",children:(C==null?void 0:C.message)||((_=l==null?void 0:l.error)==null?void 0:_.message)}),e.jsx(s.ScrollBar,{orientation:"horizontal"})]})})]})]})}function ea(){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 sa(){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 ta({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 xe({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 aa(){var p,C;const t=s.useEditorStore(j=>j.card.customCardPreferences),{data:n}=gs(),a=(n==null?void 0:n.plugins)||[],r=s.useEditorStore(j=>j.card),o=s.useEditorStore(j=>j.frame),c=(t==null?void 0:t.visualType)||"single",{setCustomCardPreferences:i}=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,I){if(!t)return;const L={...(t==null?void 0:t.dataInputCardIds)||{},[j]:{cardId:I,hookRef:null}};i({...t,dataInputCardIds:L})}function f(j){var k,L;const I=(k=o==null?void 0:o.cards)==null?void 0:k.filter(v=>{var A;return((A=v==null?void 0:v.customCardPreferences)==null?void 0:A.visualType)!=="multiple"}).map(v=>({value:v.id,label:v.tabTitle||v.title}));return e.jsx("div",{className:"space-y-2",children:(L=j==null?void 0:j.dataInputs)==null?void 0:L.map((v,A)=>{var F,V;return e.jsxs("div",{className:"grid grid-cols-10 gap-2",children:[e.jsx("div",{className:"col-span-4 flex items-center",children:v}),e.jsx(se,{className:"col-span-6 h-8 w-full justify-between",label:"",options:I||[],value:((V=(F=t==null?void 0:t.dataInputCardIds)==null?void 0:F[A])==null?void 0:V.cardId)||"",onValueChange:G=>h(A,G)})]},A+Math.random())})})}function b(j,I,k=[]){var L,v;return t?j==="input"?e.jsx(s.Input,{className:`h-8 w-full ${s.removeRing}`,value:((L=t==null?void 0:t.settings)==null?void 0:L[I])||"",onChange:A=>{i({...t,settings:{...t==null?void 0:t.settings,[I]:A.target.value}})}},I):j==="select"?e.jsx(se,{className:"h-8 w-full",label:"",options:k,value:((v=t==null?void 0:t.settings)==null?void 0:v[I])||"",onValueChange:A=>{i({...t,settings:{...t==null?void 0:t.settings,[I]:A}})}}):null:null}function l(j){const I=Object.entries((j==null?void 0:j.settings)||{});return e.jsx("div",{className:"space-y-3",children:I.map(([k,L])=>e.jsxs("div",{className:"space-y-2",children:[e.jsx(s.Label,{children:L.title}),b(L.ui,k,L.options)]},k))})}function g(j){t&&i({...t,visualType:j,componentName:""})}return e.jsxs("div",{className:"p-6",children:[e.jsx(xe,{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(se,{className:"h-8 w-full",label:"",options:a,value:(t==null?void 0:t.url)||"",onValueChange:j=>i({...t||{url:"",componentName:""},url:j})})})}),((t==null?void 0:t.type)==="component"||(t==null?void 0:t.type)===void 0)&&e.jsx(ta,{options:[{value:"single",label:"Single Visual"},{value:"multiple",label:"Multi-Visual"}],value:c,onValueChange:g}),((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(se,{className:"h-8 w-full",label:"",options:(d==null?void 0:d.filter(j=>j.type===c).map(j=>({value:j.name,label:j.name})))||[],value:t.componentName,onValueChange:j=>{console.log("changing value",j),i({...t,componentName:j})}})})]})})]})})}),e.jsx(s.Separator,{className:"my-4"}),((C=r==null?void 0:r.customCardPreferences)==null?void 0:C.componentName)&&e.jsxs(xe,{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:f(x)})]}),x&&x.settings&&e.jsx("div",{className:"space-y-3",children:e.jsx("div",{className:"px-2",children:l(x)})})]})]})}function le(){const[t,n]=S.useState([]),a=s.useEditorStore(x=>x.card.preferences),{setFilterOnClickColumnIndex:r,setCardPreferences:o}=s.useEditorStore(x=>x.actions),c=s.useEditorStore(x=>x.queryResultColumns);s.useEditorStore(x=>{var h;return(h=x.card.preferences)==null?void 0:h.filterOnClickColumnIndex}),S.useEffect(()=>{c&&n(new Array(c.length).fill(!1))},[c]);function i(x,h){var f,b;h?a!=null&&a.onClickFilter&&((f=a==null?void 0:a.onClickFilter)==null?void 0:f.length)>0?o({...a,onClickFilter:[...a.onClickFilter,{columnIndex:x,expression:""}]}):o({...a,onClickFilter:[{columnIndex:x,expression:""}]}):(o({...a,onClickFilter:(b=a==null?void 0:a.onClickFilter)==null?void 0:b.filter(l=>l.columnIndex!==x)}),n(l=>{const g=[...l];return g[x]=!1,g}))}function d(x,h){var b;const f=(b=a==null?void 0:a.onClickFilter)==null?void 0:b.map(l=>l.columnIndex===x?{...l,expression:h.target.value}:l);o({...a,onClickFilter:f})}function u(x){var h,f,b,l;if(t!=null&&t[x]||(f=(h=a==null?void 0:a.onClickFilter)==null?void 0:h.find(g=>g.columnIndex===x))!=null&&f.expression)return e.jsx(s.Input,{value:(l=(b=a==null?void 0:a.onClickFilter)==null?void 0:b.find(g=>g.columnIndex===x))==null?void 0:l.expression,onChange:g=>d(x,g),type:"text",className:"h-9 w-full font-mono text-xs focus-visible:ring-0 focus-visible:ring-ring focus-visible:ring-offset-0",placeholder:"Expression"})}return e.jsxs("div",{className:"space-y-2",children:[e.jsx(s.Label,{children:"On Click"}),c==null?void 0:c.map((x,h)=>{var f,b;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:!!((f=a==null?void 0:a.onClickFilter)!=null&&f.find(l=>l.columnIndex===h)),onCheckedChange:l=>i(h,l)}),e.jsx("label",{className:"text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70",children:x}),e.jsx("div",{className:"flex items-center gap-2",children:((b=a==null?void 0:a.onClickFilter)==null?void 0:b.find(l=>l.columnIndex===h))&&e.jsx(s.Pencil,{onClick:()=>{n(l=>{const g=[...l];return g[h]=!l[h],g})},className:"invisible size-3 cursor-pointer text-gray-400 group-hover:visible"})})]}),u(h)]})},x)})]})}function na({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,c=a==null?void 0:a.find(u=>u.idx===t);function i(u,x){(u==="end"||u==="start")&&s.getContrastColor(s.getCanvasBackgroundColor());const h={display:u!=="none",align:u,anchor:u,clamp:!0};if(!c)r({...n,datasetOptions:[...a||[],{idx:x,datalabels:h}]});else{const f={...c};f.datalabels=h;const b=a==null?void 0:a.map(l=>l.idx===x?f:l);r({...n,datasetOptions:b})}}return e.jsxs(s.Popover,{children:[e.jsx(s.PopoverTrigger,{children:e.jsx(ut,{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:()=>i("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:()=>i("start",t),size:"sm",variant:"secondary",className:"h-7 p-1 text-xs font-normal",children:e.jsx(Ks,{className:s.cn("h-4 w-4",{"rotate-90":o==="y"})})}),e.jsx(s.Button,{onClick:()=>i("center",t),size:"sm",variant:"secondary",className:"h-7 p-1 text-xs font-normal",children:e.jsx(Zs,{className:s.cn("h-4 w-4",{"rotate-90":o==="y"})})}),e.jsx(s.Button,{onClick:()=>i("end",t),size:"sm",variant:"secondary",className:"h-7 p-1 text-xs font-normal",children:e.jsx(Ws,{className:s.cn("h-4 w-4",{"rotate-90":o==="y"})})})]})})]})}function js(){const t=s.useEditorStore(x=>x.card),n=s.useEditorStore(x=>{var h,f,b;return(b=(f=(h=x==null?void 0:x.card)==null?void 0:h.preferences)==null?void 0:f.chartOptions)==null?void 0:b.indexAxis}),{data:a}=s.useDashboardCardQuery(t),r=n==="y"?"Metric":"Dimension",o=n==="y"?"Dimension":"Metric",{keys:c,metricKeys:i,dimensionKeys:d}=s.getKeys((a==null?void 0:a.records)||[]);let u=i;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 c.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:bs(d[0])})})})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(s.Label,{children:o}),e.jsx("div",{className:"my-1 max-h-[125px] space-y-1 overflow-y-auto",children:u.map((x,h)=>e.jsx(ra,{col:x,idx:h},x))})]})]})}function bs(t,n=30){return t.length>n?t.slice(0,n)+"...":t}function ra({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:c}=s.useEditorStore(d=>d.actions);function i(d){if(!o)c({...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);c({...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:bs(t)}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(Ne,{onClick:()=>i("bar"),className:"invisible size-4 cursor-pointer text-muted-foreground hover:text-foreground group-hover:visible"}),e.jsx(we,{onClick:()=>i("line"),className:"invisible size-4 cursor-pointer text-muted-foreground hover:text-foreground group-hover:visible"}),e.jsx(zs,{onClick:()=>i("area"),className:"invisible size-4 cursor-pointer text-muted-foreground hover:text-foreground group-hover:visible"}),e.jsx(na,{idx:n})]})]})}function ys(){const t=s.useEditorStore(l=>l.selectedConnectionId),n=s.useEditorStore(l=>l.selectedDatamodelId),a=s.useEditorStore(l=>l.selectedDatabaseName),r=s.useEditorStore(l=>l.selectedSchemaName),o=s.useEditorStore(l=>l.selectedTableName),c=s.useDashboardStore(l=>l.dashboard.filters)||[],i=s.useDashboardStore(l=>l.actions.addFilter),d=s.useDashboardStore(l=>l.actions.removeFilter),{removeFilterValues:u}=s.useDashboardActions(),{modelItems:x,tableName:h,connectionType:f}=ne();function b(l,g="dashboard"){var F;const p=s.fmt(l.column_name),C=s.fmt(a||""),j=s.fmt(r||""),I=s.fmt(h);let k=s.getQualifiedTableName(j,I,f),L=`${k}.${p}`;const v=(F=x==null?void 0:x.find(V=>V.id===n))==null?void 0:F.name;n&&n!=="none"&&(L=`${s.DATAMODEL_NAMESPCACE}.${v}.${p}`,k=`${s.DATAMODEL_NAMESPCACE}.${v}`);const A=c==null?void 0:c.find(V=>V.column===L&&V.table===I&&(V.database===C||V.database===a));if(A)u(A.id),d(A.id);else{const V=s.v4();return h==="api"&&t?(i({location:g,id:V,column:L,title:l.column_name,dataType:l.data_type,table:"api",database:"",connectionId:t,operation:"in",sql:s.getDefaultFilterSql(l.data_type,k,p)}),V):(i({id:V,location:g,column:L,title:l.column_name,dataType:l.data_type,table:o||"",database:a||"",connectionId:t||"",operation:"in",sql:s.getDefaultFilterSql(l.data_type,k,p)}),V)}}return{assignFilter:b}}function he(){const t=s.useDashboardStore(d=>d.dashboard.filters),n=s.useEditorStore(d=>d.frame),{setFrame:a}=s.useEditorActions(),{columns:r}=ne(),{assignFilter:o}=ys();function c(d){const u=o(d,"frame");a({...n,filterId:u})}const i=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(oa,{onSelect:c,columns:r}),i&&e.jsx(s.FilterHeader,{filter:i})]})}function oa({columns:t,onSelect:n}){var i;const[a,r]=de.useState(!1),[o,c]=de.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?(i=t.find(d=>d.column_name===o))==null?void 0:i.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;c(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 ia({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.jsx(s.AccordionContent,{className:"space-y-4 px-2",children:e.jsx(js,{})})]}),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(le,{}),e.jsx(he,{})]})]})]})})}function Ee(){var o,c,i;const t=s.useEditorStore(d=>d.card.type),n=s.useEditorStore(d=>d.card.preferences),{setCardPreferences:a}=s.useEditorStore(d=>d.actions);function r(d){var h;const u={datalabels:{display:d!=="none",align:d,anchor:d,clamp:!0}},x={...n,chartOptions:{...n==null?void 0:n.chartOptions,plugins:{...(h=n==null?void 0:n.chartOptions)==null?void 0:h.plugins,...u}}};a(x),console.log(d)}return e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"font-medium",children:"Data Labels"}),e.jsxs(s.Select,{value:((i=(c=(o=n==null?void 0:n.chartOptions)==null?void 0:o.plugins)==null?void 0:c.datalabels)==null?void 0:i.anchor)||"none",onValueChange:r,defaultValue:"none",children:[e.jsx(s.SelectTrigger,{className:"h-8 w-full focus:ring-1 focus:ring-offset-0",children:e.jsx(s.SelectValue,{placeholder:"Select position"})}),e.jsx(s.SelectContent,{children:e.jsxs(s.SelectGroup,{children:[e.jsx(s.SelectLabel,{children:"Data Labels"}),e.jsx(s.SelectItem,{value:"none",children:"None"}),t!=="pyramid"&&e.jsx(s.SelectItem,{value:"start",children:"Start"}),e.jsx(s.SelectItem,{value:"center",children:"Center"}),t!=="pyramid"&&e.jsx(s.SelectItem,{value:"end",children:"End"})]})})]})]})}function la({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:c=>c.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(Ee,{})})]}),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(le,{}),e.jsx(he,{})]})]})]})})}const ca={datasets:[{type:"line",label:"Sum_sales",data:[]},{type:"bar",label:"Sum_profit",data:[]}]},da={datasets:[{fill:"origin",type:"line",label:"Sum_sales",data:[]}]};function ua(){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:ha(t)}),!["kpi"].includes(t)&&e.jsxs("div",{className:"space-y-4",children:[e.jsx(Ee,{}),e.jsx(le,{}),e.jsx(he,{})]})]})}function ha(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(ca,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(da,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 ma(){var u,x,h,f,b;const t=s.useEditorStore(l=>l.card.preferences),n=s.useEditorStore(l=>l.actions.setCardPreferences),a=s.useEditorStore(l=>l.actions.setNumberFormat);s.useEditorStore(l=>{var g,p;return(p=(g=l.card.preferences)==null?void 0:g.formatNumber)==null?void 0:p.decimalPlaces});const r=s.useEditorStore(l=>{var g,p;return(p=(g=l.card.preferences)==null?void 0:g.formatNumber)==null?void 0:p.locale}),o=s.useEditorStore(l=>{var g,p;return(p=(g=l.card.preferences)==null?void 0:g.formatNumber)==null?void 0:p.currency});s.useEditorStore(l=>l.actions.setFilterOnClickField);const c=s.useEditorStore(l=>{var g,p;return(p=(g=l.card.preferences)==null?void 0:g.formatNumber)==null?void 0:p.colorRanges})||[],i=s.useEditorStore(l=>l.actions.setColorRanges),d=[...new Set(s.LOCALE_CURRENCY_PAIRS.map(l=>l.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:l=>{n({...t,formatNumber:{...t==null?void 0:t.formatNumber,enabled:l}})}}),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:l=>{var g,p,C;return a(((g=t==null?void 0:t.formatNumber)==null?void 0:g.decimalPlaces)||0,((p=t==null?void 0:t.formatNumber)==null?void 0:p.currency)||"",l,((C=t==null?void 0:t.formatNumber)==null?void 0:C.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(l=>e.jsx(s.SelectItem,{value:l.locale,children:l.locale},l.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:l=>{var g,p,C;console.log("currency",l),a(((g=t==null?void 0:t.formatNumber)==null?void 0:g.decimalPlaces)||0,l==="none"?"":l,((p=t==null?void 0:t.formatNumber)==null?void 0:p.locale)||"",((C=t==null?void 0:t.formatNumber)==null?void 0:C.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(l=>e.jsx(s.SelectItem,{value:l,children:l},l))]})})]})]})]}),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:((f=(h=t==null?void 0:t.formatNumber)==null?void 0:h.decimalPlaces)==null?void 0:f.toString())||"0",onValueChange:l=>{var g,p,C;return a(Number(l),((g=t==null?void 0:t.formatNumber)==null?void 0:g.currency)||"",((p=t==null?void 0:t.formatNumber)==null?void 0:p.locale)||"",((C=t==null?void 0:t.formatNumber)==null?void 0:C.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(l=>e.jsx(s.SelectItem,{value:l,children:l},l))})]})]}),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:l=>{var g,p,C;return a(((g=t==null?void 0:t.formatNumber)==null?void 0:g.decimalPlaces)||0,((p=t==null?void 0:t.formatNumber)==null?void 0:p.currency)||"",((C=t==null?void 0:t.formatNumber)==null?void 0:C.locale)||"",l.target.value)}})]})]})]})}),e.jsx(s.Separator,{className:"my-3"}),e.jsx(s.ColorFormat,{colorRanges:c,setColorRanges:i})]})]})}function xa(){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(ma,{})}),e.jsx("div",{}),e.jsx("div",{})]})}const pa=[{label:"Mercator",value:"mercator"},{label:"Azimuthal Equidistant",value:"azimuthalEquidistant"},{label:"Gnomonic",value:"gnomonic"},{label:"Orthographic",value:"orthographic"},{label:"Stereographic",value:"stereographic"},{label:"Equal Earth",value:"equalEarth"},{label:"Albers",value:"albers"},{label:"Albers USA",value:"albersUsa"},{label:"Conic Conformal",value:"conicConformal"},{label:"Conic Equal Area",value:"conicEqualArea"},{label:"Conic Equidistant",value:"conicEquidistant"},{label:"Equirectangular",value:"equirectangular"},{label:"Transverse Mercator",value:"transverseMercator"},{label:"Natural Earth 1",value:"naturalEarth1"}],fa=["blues","brBG","buGn","buPu","cividis","cool","cubehelixDefault","gnBu","greens","greys","inferno","magma","orRd","oranges","pRGn","piYG","plasma","puBu","puBuGn","puOr","puRd","purples","rainbow","rdBu","rdGy","rdPu","rdYlBu","rdYlGn","reds","sinebow","spectral","turbo","viridis","warm","ylGn","ylGnBu","ylOrBr","ylOrRd"],ga=fa.map(t=>({label:t,value:t}));function ja(){var u,x,h,f,b,l,g,p,C,j,I,k,L,v,A,F,V,G;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]=S.useState(((f=(h=t==null?void 0:t.preferences)==null?void 0:h.mapVisualOptions)==null?void 0:f.customTopoJsonUrl)||""),{setCardPreferences:o}=s.useEditorActions(),{data:c}=s.useTopoJson(t),i=Object.keys((c==null?void 0:c.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(xe,{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(xe,{open:!0,summary:"Settings",children:e.jsxs("div",{className:"space-y-3 px-2",children:[e.jsx(se,{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"}),c&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(s.Label,{children:"Map Object"}),e.jsx(se,{className:"h-9",options:i,value:((l=(b=t.preferences)==null?void 0:b.mapVisualOptions)==null?void 0:l.objectKey)||"",label:"Map Object",onValueChange:m=>{var E;o({...t.preferences,mapVisualOptions:{...(E=t.preferences)==null?void 0:E.mapVisualOptions,objectKey:m}})}})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(s.Label,{children:"Projection"}),e.jsx(se,{className:"h-9",options:pa,value:((p=(g=t.preferences)==null?void 0:g.mapVisualOptions)==null?void 0:p.projection)||"",label:"Projection",onValueChange:m=>{var E;o({...t.preferences,mapVisualOptions:{...(E=t.preferences)==null?void 0:E.mapVisualOptions,projection:m}})}})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(s.Label,{children:"Colors"}),e.jsx(se,{className:"h-9",options:ga,value:((j=(C=t.preferences)==null?void 0:C.mapVisualOptions)==null?void 0:j.colorScale)||"",label:"Select Color Scale",onValueChange:m=>{var E;o({...t.preferences,mapVisualOptions:{...(E=t.preferences)==null?void 0:E.mapVisualOptions,colorScale:m}})}})]})]})]})}),e.jsx(s.Separator,{className:"my-4"}),e.jsx(xe,{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:((k=(I=t.preferences)==null?void 0:I.mapVisualOptions)==null?void 0:k.projectionScale)||1,onChange:m=>{var E;o({...t.preferences,mapVisualOptions:{...(E=t.preferences)==null?void 0:E.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:((A=(v=(L=t.preferences)==null?void 0:L.mapVisualOptions)==null?void 0:v.projectionOffset)==null?void 0:A[0])||0,onChange:m=>{var E,q,z,B;o({...t.preferences,mapVisualOptions:{...(E=t.preferences)==null?void 0:E.mapVisualOptions,projectionOffset:[Number(m.target.value),((B=(z=(q=t.preferences)==null?void 0:q.mapVisualOptions)==null?void 0:z.projectionOffset)==null?void 0:B[1])||0]}})}}),e.jsx(s.Label,{children:"Y"}),e.jsx(s.Input,{className:`h-9 w-full ${s.removeRing}`,type:"number",step:10,value:((G=(V=(F=t.preferences)==null?void 0:F.mapVisualOptions)==null?void 0:V.projectionOffset)==null?void 0:G[1])||0,onChange:m=>{var E,q,z,B;o({...t.preferences,mapVisualOptions:{...(E=t.preferences)==null?void 0:E.mapVisualOptions,projectionOffset:[((B=(z=(q=t.preferences)==null?void 0:q.mapVisualOptions)==null?void 0:z.projectionOffset)==null?void 0:B[0])||0,Number(m.target.value)]}})}})]})}),e.jsx(s.Separator,{className:"my-4"}),e.jsx(le,{})]})}function ba(){var r;const t=s.useEditorStore(o=>o.card.preferences),{setCardPreferences:n}=s.useEditorStore(o=>o.actions);function a(o){n({...t,textVisualOptions:{...t==null?void 0:t.textVisualOptions,isDynamicText:o==="dynamic"}})}return e.jsxs(s.RadioGroup,{value:(r=t==null?void 0:t.textVisualOptions)!=null&&r.isDynamicText?"dynamic":"static",onValueChange:a,className:"flex gap-3",defaultValue:"x",children:[e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(s.RadioGroupItem,{value:"static",id:"r1"}),e.jsx("label",{className:"text-sm",htmlFor:"r1",children:"Static"})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(s.RadioGroupItem,{value:"dynamic",id:"r2"}),e.jsx("label",{className:"text-sm",htmlFor:"r2",children:"Dynamic"})]})]})}function ge({cardType:t,docContent:n,suffix:a="Chart"}){return e.jsx("div",{className:"space-y-6 px-6 py-2",children:e.jsxs(s.Accordion,{defaultValue:["item-2"],type:"multiple",children:[e.jsxs(s.AccordionItem,{value:"item-1",children:[e.jsx(s.AccordionTrigger,{children:`${s.titleCase(t)} ${a}`}),e.jsx(s.AccordionContent,{children:n||e.jsxs("div",{className:"space-y-4 font-mono text-xs",children:[e.jsx("div",{className:"rounded bg-muted px-2 py-1 text-xs",children:"SELECT label, measure FROM table"}),e.jsxs("ul",{className:"ml-6 list-disc text-xs [&>li]:mt-2",children:[e.jsx("li",{children:"label - category"}),e.jsx("li",{children:"measure - number"})]}),e.jsxs("div",{children:["See ",e.jsx("a",{target:"_blank",onClick:r=>r.stopPropagation(),className:"text-blue-700",href:"https://docs.semaphor.cloud/docs/charts/pie-donut-polar",children:"example"})," in the docs."]})]})})]}),e.jsxs(s.AccordionItem,{value:"item-2",children:[e.jsx(s.AccordionTrigger,{children:"Settings"}),e.jsxs(s.AccordionContent,{className:"space-y-4 px-2",children:[t!=="text"&&e.jsx(Ee,{}),t==="text"&&e.jsx(ba,{})]})]}),!["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(le,{}),e.jsx(he,{})]})]})]})})}function ya(){const t=s.useEditorStore(r=>{var o,c;return(c=(o=r==null?void 0:r.card)==null?void 0:o.preferences)==null?void 0:c.sortChart}),{setSortChart:n}=s.useEditorActions();function a(){return e.jsxs("div",{className:"space-y-2",children:[e.jsx(s.Label,{children:"Sort"}),e.jsx(se,{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:[a(),e.jsx(js,{})]})]}),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(le,{}),e.jsx(he,{})]})]})]})})}function Sa({cardType:t="table"}){console.log("cardType",t);const n=s.useEditorStore(o=>{var c;return(c=o.card)==null?void 0:c.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(le,{}),e.jsx(he,{})]})]})}),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 Ca=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."]})]}),va=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."]})]}),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 text FROM table limit 1"}),e.jsxs("div",{children:["See ",e.jsx("a",{target:"_blank",onClick:t=>t.stopPropagation(),className:"text-blue-700",href:"https://docs.semaphor.cloud/docs/charts/text",children:"example"})," in the docs."]})]});function wa(){const t=s.useEditorStore(a=>a.card.type);function n(a){switch(a){case"stackedBar":case"stackedLine":return e.jsx(ya,{});case"pyramid":return e.jsx(ge,{docContent:Ca,cardType:a});case"kpi":return e.jsx(xa,{});case"line":case"bar":return e.jsx(ia,{cardType:a});case"range":return e.jsx(ge,{docContent:va,cardType:a});case"pie":case"doughnut":case"polarArea":case"radar":return e.jsx(ge,{cardType:a});case"bubble":case"scatter":return e.jsx(la,{cardType:a});case"table":return e.jsx(Sa,{cardType:a});case"text":return e.jsx(ge,{docContent:Na,cardType:a,suffix:"Visual"});case"map":return e.jsx(ja,{});case"custom":return e.jsx(aa,{});default:return e.jsx(ua,{})}}return e.jsxs(s.ScrollArea,{className:"h-full w-full text-sm",children:[n(t),e.jsx(s.ScrollBar,{orientation:"horizontal"})]})}function ka(){const t=S.useRef(null),n=s.useEditorStore(r=>r.isShowingVisual),a=s.useEditorStore(r=>r.showAIDialog);return S.useEffect(()=>{var r,o;a?(r=t.current)==null||r.resize(0):(o=t.current)==null||o.resize(25)},[a]),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:n&&!a?e.jsxs(s.ResizablePanelGroup,{direction:"horizontal",children:[e.jsx(e.Fragment,{children:e.jsx(s.ResizablePanel,{ref:t,className:"flex",defaultSize:25,maxSize:30,children:e.jsx(wa,{})})}),!a&&e.jsx(s.ResizableHandle,{className:"border"}),e.jsx(s.ResizablePanel,{minSize:40,defaultSize:75,maxSize:100,children:e.jsx(Be,{})})]}):e.jsx(Be,{})})]})}const Ia=[{title:"Help me write a query for",subtitle:"orders by month"},{title:"Create a bar chart for",subtitle:"sales by category"}];function Ea(){const t=S.useRef(null),n=S.useRef(null),[a,r]=S.useState(!1),[o,c]=S.useState(s.isDev),[i,d]=S.useState(!1),u=s.useEditorStore(y=>y.actions.setCardSql),x=s.useEditorStore(y=>y.actions.setRunSql),h=s.useEditorStore(y=>y.showAIDialog),{setShowAIDialog:f}=s.useEditorActions(),{messages:b,setMessages:l,reload:g,append:p,input:C,setInput:j,isLoading:I,handleAddCurrentTableToScope:k,removeFromCurrentSelections:L,currentAssitantScope:v,handleInputChange:A,handleSubmit:F,stop:V,chatStatus:G,toolStatus:m,llmUsage:E}=ds();s.useAssistantScroll({scrollContainerRef:t,inputRef:n,messages:b}),S.useEffect(()=>{var y;h&&((y=n.current)==null||y.focus())},[h]);function q(y){u(y),x(!0)}function z(y){const O={role:"user",content:y.title+" "+y.subtitle};p(O)}function B(){return e.jsxs(s.DropdownMenu,{children:[e.jsx(s.DropdownMenuTrigger,{asChild:!0,children:e.jsx(s.Button,{className:"h-7 p-2",size:"sm",variant:"ghost",children:e.jsx(Qe,{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:a,onCheckedChange:r,children:"Token Usage"}),e.jsx(s.DropdownMenuCheckboxItem,{checked:o,onCheckedChange:c,children:"Tool Invocations"}),e.jsx(s.DropdownMenuCheckboxItem,{checked:i,onCheckedChange:d,children:"System Message"})]})]})}function _(){return e.jsxs("div",{"data-role":"header",children:[e.jsx("div",{className:"text-lg font-semibold",children:"Assistant"}),v&&v.length>0&&e.jsx("div",{className:"mt-2 flex flex-wrap items-center gap-2",children:v==null?void 0:v.map((y,O)=>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:y.schemaName||"",tableName:y.tableName||"",modelName:y.datamodelName||"",connectionType:y.connectionType||""}),e.jsx("button",{onClick:()=>{L(y)},children:e.jsx(s.X,{className:"size-3 text-muted-foreground hover:text-foreground"})})]},O))}),(v==null?void 0:v.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:k,children:[e.jsx(s.Plus,{className:"mr-2 size-3"}),"Current Table"]})]})]})}const N=(C==null?void 0:C.length)===0&&(b==null?void 0:b.filter(y=>y.role==="user").length)===0;return e.jsxs("div",{"data-role":"editor-assistant",className:"flex h-full w-full flex-col justify-between gap-2 px-6 py-4",children:[e.jsxs("div",{"data-role":"header-section",className:"flex items-start justify-between gap-2",children:[_(),e.jsxs("div",{"data-role":"header-actions",className:"flex items-center",children:[B(),e.jsx(s.Button,{className:"h-7 p-2",size:"sm",variant:"ghost",onClick:()=>{l([]),g()},children:e.jsx(s.RefreshCcw,{className:"size-3.5 text-muted-foreground"})}),e.jsx(s.Button,{className:"h-7 p-2",size:"sm",variant:"ghost",onClick:()=>{f(!1)},children:e.jsx(s.X,{className:"size-4"})})]})]}),e.jsx(s.CustomScrollArea,{ref:t,className:"flex w-full grow basis-0",children:e.jsxs("div",{className:"space-y-4 py-2 pr-3","data-role":"messages",children:[e.jsx(s.PrintMessages,{messages:b,showTools:o,handleRun:q,showSystemMessage:i}),e.jsx(s.ChatStatus,{status:s.getStatus(G,m),isLoading:I})]})}),N&&e.jsx(s.Placeholders,{onClick:z,placeholders:Ia}),e.jsx(s.ChatInput,{onFocus:()=>{k()},stop:V,ref:n,setInput:j,input:C,handleInputChange:A,handleSubmit:F,isLoading:I}),E&&a&&e.jsx("div",{className:"flex h-8 items-center justify-between",children:e.jsxs("div",{className:"text-xs text-muted-foreground",children:["Usage: ",E.promptTokens," prompt tokens,"," ",E.completionTokens," completion tokens,"," ",E.totalTokens," total tokens"]})})]})}function Da({authToken:t,onSave:n,onClose:a}){const r=S.useRef(null),o=s.useEditorStore(f=>f.showAIDialog),{setAuthToken:c}=s.useDashboardActions(),{setShowAIDialog:i,setOnSave:d,setOnClose:u}=s.useEditorActions();S.useEffect(()=>{n&&d(n),a&&u(a)},[n,d,a,u]),S.useEffect(()=>{t&&t.accessToken&&c(t)},[t,c]),S.useEffect(()=>{var f,b;o?((f=r.current)==null||f.resize(40),i(!0)):(i(!1),(b=r.current)==null||b.resize(0))},[o,i]);function x(f){f<1?i(!1):o||i(!0)}function h(){return e.jsxs(s.ResizablePanelGroup,{"data-content":"editor-main",className:"grow",direction:"horizontal",children:[e.jsx(s.ResizablePanel,{className:"min-w-[510px] rounded-none border-x-[1px]",children:e.jsx(ka,{})}),e.jsx(s.ResizableHandle,{}),e.jsx(s.ResizablePanel,{"data-role":"editor-assistant-panel",ref:r,onResize:x,defaultSize:0,children:e.jsx(Ea,{})})]})}return e.jsx(s.ErrorBoundary,{FallbackComponent:s.Fallback,children:e.jsxs("section",{className:"flex h-full grow","data-content":"editor-panel",children:[e.jsx(os,{}),h()]})})}function Ta(){s.useDashboardStore(i=>i.selectedCardId);const t=s.useDashboardStore(i=>i.selectedSheetId),{setIsVisualEditing:n}=s.useDashboardStore(i=>i.actions),a=s.useDashboardStore(i=>i.isVisualEditing),r=s.useDashboardStore(i=>i.actions.updateFrame);function o(i){t&&(r(t,i),n(!1))}function c(){n(!1)}return e.jsx("div",{role:"editor-container",className:s.cn("flex grow",{"max-h-0 overflow-hidden":!a}),children:e.jsx(Da,{onSave:o,onClose:c})})}function La(){const t=s.useEditorStore(c=>c.selectedDatabaseName),n=s.useEditorStore(c=>c.selectedTableName),a=s.useDashboardStore(c=>c.dashboard.filters)||[],{columns:r}=ne(),{assignFilter:o}=ys();return e.jsx(s.ScrollArea,{className:"flex-1 basis-0 flex-col px-3",children:r==null?void 0:r.map(c=>{const i=a==null?void 0:a.find(d=>d.column===s.fmt(c.column_name)&&d.table===n&&d.database===t);return e.jsx("div",{onClick:()=>o(c),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":i}),children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(rs,{column:c}),e.jsx("span",{children:c.column_name})]})},c.column_name)})})}function Aa(){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(os,{ColumnsComponent:()=>e.jsx(La,{})})})]})}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 za(){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(Aa,{})})]})}function Oa(){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(Oa,{}),e.jsxs(s.DashboardPanel,{...a,children:[t&&e.jsx(St,{}),e.jsx(Ta,{}),e.jsx(za,{})]})]})]})})}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.ScheduleDashboard=ns;exports.SelectComponent=ce;exports.Surfboard=Fa;exports.cleanCard=ss;exports.downloadPdf=as;exports.getDashbaordStateWithoutData=Ie;exports.useEditorAside=ne;
|
|
321
|
+
`;G(L)}function X(){return e.jsxs(e.Fragment,{children:[c&&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(Rt,{jsonString:JSON.stringify(g,null,2)})})}),g&&g.length>0&&e.jsx(s.Button,{variant:"ghost",onClick:()=>l(!c),className:"absolute bottom-0 right-6 size-7 p-1",children:c?e.jsx(s.X,{className:"size-3.5 text-muted-foreground"}):e.jsx(Je,{className:"size-3.5 text-muted-foreground"})})]})}function $(){return e.jsxs(s.ResizablePanelGroup,{className:"flex grow pb-1",direction:"vertical",role:"editor-resizable-group",children:[e.jsxs(s.ResizablePanel,{id:"1",order:1,defaultSize:r?20:100,className:"relative flex grow",children:[e.jsx("div",{id:"sql-container",className:"relative flex w-[99%]",children:e.jsx(Ot,{})}),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(Ft,{})}),e.jsx("code",{className:"absolute right-6 top-3 text-xs text-muted-foreground/70",children:"python"})]})]})]})}const W=(M==null?void 0:M.message)||((re=y==null?void 0:y.error)==null?void 0:re.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:[$(),X()]}),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:O||H,onClick:()=>{J()},className:"shrink-0",size:"sm",children:[O||H?e.jsx(ie,{className:"mr-2 h-4 w-4 animate-spin"}):e.jsx(s.Play,{className:"mr-2 h-4 w-4"}),"Run"]}),e.jsx(kt,{sql:y==null?void 0:y.sql,error:W,onClick:ae}),e.jsxs(s.Button,{onClick:P,className:"",size:"sm",variant:"secondary",children:[e.jsx(Bs,{className:"mr-2 size-4"}),"Clear"]}),e.jsx(s.Toggle,{pressed:r,onPressedChange:L=>o(L),className:"",size:"sm",children:e.jsx(zt,{className:"size-4 text-foreground/70"})}),e.jsx("button",{disabled:j,onClick:()=>{D(),m(!0)},className:"h-9 w-full cursor-text px-3 text-left text-sm text-muted-foreground",children:j?"":"Type your question..."})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(s.Button,{onClick:te,className:"w-full",size:"sm",variant:"secondary",children:[e.jsx(s.Cross2Icon,{className:"mr-2 size-4"}),"Close"]}),e.jsxs(s.Button,{onClick:K,size:"sm",variant:"secondary",children:[e.jsx(s.Check,{className:"mr-2 size-4 font-bold text-green-600"}),"Accept"]})]})]})]})}function qt({data:t}){var l;const[n,a]=S.useState([]),o=Object.keys(t[0]).map(d=>({accessorKey:d,header:({column:u})=>{const p=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,p==="asc"?e.jsx(s.TriangleUpIcon,{className:"ml-2 h-5 w-5"}):p==="desc"?e.jsx(s.TriangleDownIcon,{className:"ml-2 h-5 w-5"}):null]})})}})),c=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(s.CustomScrollArea,{className:"grow overflow-auto font-mono text-xs text-foreground/95",children:e.jsxs("table",{className:"w-full",children:[e.jsx(s.TableHeader,{className:"sticky top-0 z-50 h-0 bg-muted",children:c.getHeaderGroups().map(d=>e.jsx(s.TableRow,{className:"",children:d.headers.map(u=>e.jsx(s.TableHead,{className:"h-11 font-semibold text-foreground",children:u.isPlaceholder?null:s.flexRender(u.column.columnDef.header,u.getContext())},u.id))},d.id))}),e.jsx(s.TableBody,{children:(l=c.getRowModel().rows)!=null&&l.length?c.getRowModel().rows.map(d=>e.jsx(s.TableRow,{className:"h-11 whitespace-nowrap py-2","data-state":d.getIsSelected()&&"selected",children:d.getVisibleCells().map(u=>e.jsx(s.TableCell,{className:"py-2",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 Bt({card:t}){var I,k,T,v,A,F,V,G,m,E,q;const[n,a]=S.useState(!1),[r,o]=S.useState([]),{authToken:c}=s.useSemaphorContext(),l=s.getTokenParams(c==null?void 0:c.accessToken),d=s.useDashboardStore(z=>z.themeStyle),u={colors:((k=(I=d==null?void 0:d.chart)==null?void 0:I.dataset)==null?void 0:k.backgroundColor)||[]};(T=t.customCardPreferences)!=null&&T.inputData;const{getCard:p}=s.useCustomVisual(((v=t.customCardPreferences)==null?void 0:v.url)||""),h=((A=t.customCardPreferences)==null?void 0:A.visualType)||"single",f=s.useEditorStore(z=>z.frame),{setCustomCardPreferences:b}=s.useEditorActions(),{data:i}=s.useDashboardCardQuery(t),j=S.useCallback((z,B)=>{o(_=>({..._,[z]:B}))},[]);if(!((F=t.customCardPreferences)!=null&&F.componentName))return null;const x=p((V=t.customCardPreferences)==null?void 0:V.componentName);function C(z){a(z)}const g=Object.keys(((G=t.customCardPreferences)==null?void 0:G.dataInputCardIds)||{}).map(z=>{var N,y,O;const B=(y=(N=t.customCardPreferences)==null?void 0:N.dataInputCardIds)==null?void 0:y[z].cardId,_=(O=f==null?void 0:f.cards)==null?void 0:O.find(H=>H.id===B);return _||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(S.Suspense,{fallback:e.jsx(e.Fragment,{}),children:[x&&h==="single"&&e.jsx(x,{params:l,theme:u,settings:(m=t.customCardPreferences)==null?void 0:m.settings,onDataChange:j,data:(i==null?void 0:i.records)||[]}),x&&h==="multiple"&&e.jsxs(e.Fragment,{children:[Object.keys(((E=t.customCardPreferences)==null?void 0:E.dataInputCardIds)||{}).map(z=>{var N,y,O;const B=(y=(N=t.customCardPreferences)==null?void 0:N.dataInputCardIds)==null?void 0:y[z].cardId,_=(O=f==null?void 0:f.cards)==null?void 0:O.find(H=>H.id===B);if(_)return e.jsx(s.MultiInputEmptyRenderer,{onLoadingStatus:C,onDataChange:j,dataInputIndex:z,card:_},_.id+z)}),e.jsx("div",{className:"flex flex-col gap-2",children:e.jsx(x,{theme:u,onDataChange:j,settings:g.map(z=>{var B;return(B=z==null?void 0:z.customCardPreferences)==null?void 0:B.settings}),data:g.map(z=>z!=null&&z.id?r==null?void 0:r[z.id]:[])})})]})]},(q=t.customCardPreferences)==null?void 0:q.componentName)})}function us({className:t,...n}){var C;const a=s.useEditorStore(g=>g.card),r=((C=a.customCardPreferences)==null?void 0:C.showCardHeader)??!0,o=s.useEditorStore(g=>g.frame),c=s.useDashboardStore(g=>g.dashboard.filters);s.useEditorStore(g=>g.actions.setRunSql);const{updateFilter:l}=s.useDashboardActions(),d=c==null?void 0:c.find(g=>g.id===o.filterId),{data:u,isLoading:p,isFetching:h}=s.useDashboardCardQuery(a),{setCard:f}=s.useEditorActions(),{data:b}=s.useTopoJson(a),i=S.useMemo(()=>!a.id||!(u!=null&&u.records)?null:s.createChartConfig({data:u==null?void 0:u.records,cardType:a.type,customCfg:a.customCfg,preferences:a.preferences,topoJson:b}),[a.id,u==null?void 0:u.records,a.type,a.customCfg,a.preferences,b]);function j(g){return e.jsx(Bt,{card:g})}function x(){if(u!=null&&u.records&&(u==null?void 0:u.records.length)===0&&!p&&!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.id)return null;if(a.type==="custom")return j(a);if(!["table","custom"].includes(a.type)&&i)return e.jsx(e.Fragment,{children:p||h?e.jsx(e.Fragment,{}):e.jsx(s.ChartJsVisual,{cfg:i})});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:g=>f({...a,title:g}),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:g=>f({...a,description:g}),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:g=>l({...d,title:g}),children:e.jsx(s.Label,{children:d.title})}),e.jsx(s.FilterComponent,{filter:d})]})]}),e.jsx(s.CardContent,{className:"flex grow flex-col",children:x()})]})}const Ce=({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}),Pt=()=>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."})]})]}),_t=({customCode:t,cardCustomCfgString:n,mergedConfig:a,onConfigChange:r,onCodeChange:o})=>e.jsxs(s.Tabs,{defaultValue:"final-config",className:"flex w-1/2 flex-col",children:[e.jsxs(s.TabsList,{className:"justify-start rounded-sm rounded-b-none border border-b-0",children:[e.jsx(s.TabsTrigger,{value:"final-config",children:"Config"}),e.jsx(s.TabsTrigger,{value:"custom-config",children:"Changes"}),e.jsx(s.TabsTrigger,{value:"custom-code",children:"Custom Code"})]}),e.jsx(s.TabsContent,{value:"final-config",className:"mt-0 grow rounded-b border border-t-0",children:e.jsx(Ce,{language:"json",value:a,onChange:r})}),e.jsx(s.TabsContent,{value:"custom-config",className:"mt-0 grow rounded-b border border-t-0",children:e.jsx(Ce,{readonly:!0,language:"json",value:n,onChange:()=>{}})}),e.jsx(s.TabsContent,{value:"custom-code",className:"mt-0 grow rounded-b border border-t-0",children:e.jsx(Ce,{language:"javascript",value:t,onChange:o})})]}),Ht=({error:t,hasCardCustomConfig: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 Gt(){const[t,n]=S.useState(!1),[a,r]=S.useState(""),[o,c]=S.useState(""),[l,d]=S.useState(""),[u,p]=S.useState(""),h=s.useEditorStore(v=>v.card),f=s.useEditorStore(v=>v.card.customCfg),b=f?JSON.stringify(f,null,2):"",{data:i}=s.useDashboardCardQuery(h),{data:j}=s.useTopoJson(h),{setCardCustomCfg:x,setCustomVisualCode:C}=s.useEditorActions(),g=v=>{var A,F;return JSON.stringify({...v,data:{...v.data,datasets:(F=(A=v.data)==null?void 0:A.datasets)==null?void 0:F.map(V=>({...V,data:[]}))}},null,2)},I=()=>{var A,F;if(!((A=i==null?void 0:i.records)!=null&&A.length))return;const v=s.createChartConfig({data:i.records,cardType:h.type,preferences:h.preferences,topoJson:j});if(v){r(g(v)),d(((F=h.preferences)==null?void 0:F.customVisualCode)||"");const V=s.merge(v,f);c(g(V))}},k=()=>{try{if(l&&C(l),o){const v=JSON.parse(o),A=s.getObjectDiff(JSON.parse(a),v);x(A),p("")}}catch{p("Invalid JSON configuration")}},T=Object.keys(f||{}).length===0;return e.jsxs(s.Dialog,{open:t,onOpenChange:n,children:[e.jsx(s.DialogTrigger,{asChild:!0,children:e.jsx(s.IconButton,{tooltip:"Customize Visual",onClick:I,className:T?"":"text-green-600 hover:text-green-700",children:e.jsx(s.Settings,{className:"h-4 w-4"})})}),e.jsxs(s.DialogContent,{className:"flex h-[600px] grow flex-col overflow-auto sm:min-w-[900px] lg:min-w-[1200px]",children:[e.jsx(Pt,{}),e.jsxs("div",{className:"flex grow gap-2",children:[e.jsx(s.ErrorBoundary,{FallbackComponent:s.FallbackEditorCard,children:e.jsx(us,{className:"w-1/2 rounded shadow-none"})}),e.jsx(_t,{customCode:l,cardCustomCfgString:b,mergedConfig:o,onConfigChange:v=>c(v??""),onCodeChange:v=>d(v??"")})]}),e.jsx(Ht,{error:u,hasCardCustomConfig:!!f,onReset:()=>{c(a),x(null)},onApply:k,onClose:()=>n(!1)})]})]})}function hs(t){return ue({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 $t(t){return ue({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 ms(t){return ue({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 xs(t){return ue({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 ps(t){return ue({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 fs(t){const[n,a]=S.useState(null);return n}function gs(){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 Ut({onChartTypeChange:t}){const[n,a]=S.useState([]),{data:r}=gs();return S.useEffect(()=>{(async()=>{var c;if(r){const d=(await Promise.all((c=r==null?void 0:r.plugins)==null?void 0:c.map(async u=>(await s.loadManifest(u.value)).visuals.map(f=>({name:f.name,icon:f.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,c)=>e.jsx(Qt,{text:o.name,onClick:()=>t("custom",o),icon:o.icon},o.url+o.name+c))})]})}const Qt=({text:t,icon:n,onClick:a})=>{const r=fs(),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 Jt(){var f,b;const[t,n]=S.useState(!1),a=s.useEditorStore(i=>i.card),r=a.type,o=s.useDashboardStore(i=>i.isVisualEditing),{setCardType:c,setCardPreferences:l,setChartOrientation:d}=s.useEditorStore(i=>i.actions),{setCardCustomCfg:u,setCustomCardPreferences:p}=s.useEditorActions();function h(i,j){u(null),l({}),c(i),j&&p({type:"component",visualType:"single",url:j.url,componentName:j.name,icon:j.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:o?"ghost":"outline",children:e.jsx(Kt,{className:"size-4",chartType:r,customIcon:(f=a.customCardPreferences)==null?void 0:f.icon,componentName:(b=a.customCardPreferences)==null?void 0:b.componentName})})}),e.jsxs(s.PopoverContentCustom,{onOpenAutoFocus:i=>i.preventDefault(),className:"w-50",children:[e.jsxs("div",{className:"grid grid-cols-4 place-items-center",children:[e.jsx(s.IconButton,{tooltip:"Bar Chart",onClick:()=>h("bar"),className:"h-10 p-4",children:e.jsx(Ne,{className:"size-5"})}),e.jsx(s.IconButton,{tooltip:"Line Chart",onClick:()=>h("line"),className:"h-10 p-4",children:e.jsx(we,{className:"size-5"})}),e.jsx(s.IconButton,{tooltip:"Stacked Bar Chart",onClick:()=>h("stackedBar"),className:"h-10 p-4",children:e.jsx(Pe,{className:"size-5"})}),e.jsx(s.IconButton,{tooltip:"Stacked Line Chart",onClick:()=>h("stackedLine"),className:"h-10 p-4",children:e.jsx(xs,{className:"size-5",strokeWidth:0})}),e.jsx(s.IconButton,{tooltip:"Scatter Chart",onClick:()=>h("scatter"),className:"h-10 p-4",children:e.jsx(Ge,{className:"size-5"})}),e.jsx(s.IconButton,{tooltip:"Bubble Chart",onClick:()=>h("bubble"),className:"h-10 p-4",children:e.jsx(ms,{className:"size-5"})}),e.jsx(s.IconButton,{tooltip:"Pie Chart",onClick:()=>h("pie"),className:"h-10 p-4",children:e.jsx(He,{className:"size-5"})}),e.jsx(s.IconButton,{tooltip:"Doughnut Chart",onClick:()=>h("doughnut"),className:"h-10 p-4",children:e.jsx(Ue,{className:"size-5"})}),e.jsx(s.IconButton,{tooltip:"Radar Chart",onClick:()=>h("radar"),className:"h-10 p-4",children:e.jsx(We,{className:"size-5"})}),e.jsx(s.IconButton,{tooltip:"Polar Area Chart",onClick:()=>h("polarArea"),className:"h-10 p-4",children:e.jsx(hs,{className:"size-6"})}),e.jsx(s.IconButton,{tooltip:"Pyramid Chart",onClick:()=>h("pyramid"),className:"h-10 p-4",children:e.jsx(Xe,{className:"size-5"})}),e.jsx(s.IconButton,{tooltip:"Range Chart",onClick:()=>h("range"),className:"h-10 p-4",children:e.jsx(_e,{className:"size-5"})}),e.jsx(s.IconButton,{tooltip:"Table",onClick:()=>h("table"),className:"h-10 p-4",children:e.jsx(ke,{className:"size-5"})}),e.jsx(s.IconButton,{tooltip:"KPI",onClick:()=>h("kpi"),className:"h-10 p-4",children:e.jsx(ps,{className:"size-6"})}),e.jsx(s.IconButton,{tooltip:"Text",onClick:()=>h("text"),className:"h-10 p-4",children:e.jsx(Ls,{className:"size-5"})}),e.jsx(s.IconButton,{tooltip:"Map",onClick:()=>h("map"),className:"h-10 p-4",children:e.jsx(Ke,{className:"size-5"})}),e.jsx(s.IconButton,{tooltip:"Custom",onClick:()=>h("custom"),className:"h-10 p-4",children:e.jsx(Ye,{className:"size-5"})})]}),e.jsx(Ut,{onChartTypeChange:h})]})]})}function Kt({chartType:t,className:n,customIcon:a,componentName:r}){const o=fs();switch(t){case"bar":return e.jsx(Ne,{className:n});case"line":return e.jsx(we,{className:n});case"pie":return e.jsx(He,{className:n});case"radar":return e.jsx(We,{className:n});case"scatter":return e.jsx(Ge,{className:n});case"bubble":return e.jsx(ms,{className:n});case"doughnut":return e.jsx(Ue,{className:n});case"stackedBar":return e.jsx(Pe,{className:n});case"stackedLine":return e.jsx(xs,{className:n});case"polarArea":return e.jsx(hs,{className:n});case"pyramid":return e.jsx(Xe,{className:n});case"range":return e.jsx(_e,{className:n});case"kpi":return e.jsx(ps,{className:n});case"text":return e.jsx(es,{className:n});case"map":return e.jsx(Ke,{className:n});case"custom":return a&&o?e.jsx(o,{className:n}):r?r==null?void 0:r.charAt(0).toUpperCase():e.jsx(Ye,{className:n});default:return e.jsx(ke,{className:n})}}const fe="focus-visible:ring-0 focus-visible:ring-ring focus-visible:ring-offset-0";function qe(t,n){var r,o,c;const a=s.getNumberAxis(t,n);return((c=(o=(r=t==null?void 0:t.chartOptions)==null?void 0:r.scales)==null?void 0:o[a])==null?void 0:c.type)||"linear"}function Wt(){var _,N,y,O,H,Q;const[t,n]=S.useState(!1),a=s.useEditorStore(R=>{var M;return(M=R.card)==null?void 0:M.preferences}),r=s.getNumberAxis(a,{}),[o,c]=S.useState(qe(a)),[l,d]=S.useState(((y=(N=(_=a==null?void 0:a.chartOptions)==null?void 0:_.scales)==null?void 0:N[r])==null?void 0:y.min)||""),[u,p]=S.useState(((Q=(H=(O=a==null?void 0:a.chartOptions)==null?void 0:O.scales)==null?void 0:H[r])==null?void 0:Q.max)||""),[h,f]=S.useState(l||u?"custom":"auto"),[b,i]=S.useState(""),[j,x]=S.useState(0),[C,g]=S.useState(""),[I,k]=S.useState(""),[T,v]=S.useState(""),A=s.useEditorStore(R=>R.actions.setCardPreferences),{updateCardInFrame:F}=s.useEditorActions(),V=s.useEditorStore(R=>R.card),G=s.useEditorStore(R=>{var M;return(M=R.card)==null?void 0:M.type}),m=["pie","doughnut","polarArea"].includes(G);S.useEffect(()=>{var R,M,U,J,D,P,Z,K,te,ae,X,$,W,re;c(qe(a)),d(((U=(M=(R=a==null?void 0:a.chartOptions)==null?void 0:R.scales)==null?void 0:M[r])==null?void 0:U.min)===0?0:""),p(((P=(D=(J=a==null?void 0:a.chartOptions)==null?void 0:J.scales)==null?void 0:D[r])==null?void 0:P.max)||""),i(((ae=(te=(K=(Z=a==null?void 0:a.chartOptions)==null?void 0:Z.scales)==null?void 0:K[r])==null?void 0:te.ticks)==null?void 0:ae.stepSize)||""),x(((X=a==null?void 0:a.numberAxisFormat)==null?void 0:X.decimalPlaces)||0),g((($=a==null?void 0:a.numberAxisFormat)==null?void 0:$.suffix)||""),k(((W=a==null?void 0:a.numberAxisFormat)==null?void 0:W.currency)||""),v(((re=a==null?void 0:a.numberAxisFormat)==null?void 0:re.locale)||"")},[t,a,r]);function E(R,M){return M===""||/^[0-9\b]+$/.test(M)?Number(M):Number(R)}function q(){const R=[...new Set(s.LOCALE_CURRENCY_PAIRS.map(M=>M.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:I||"none",onValueChange:M=>k(M==="none"?"":M),children:[e.jsx(s.SelectTrigger,{className:"col-span-2 h-8 w-full focus:ring-1 focus:ring-offset-0",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{children:e.jsxs(s.SelectGroup,{children:[e.jsx(s.SelectLabel,{children:"Currency"}),e.jsx(s.SelectItem,{value:"none",children:"None"}),R.map(M=>e.jsx(s.SelectItem,{value:M,children:M},M))]})})]}),e.jsxs(s.Select,{value:T,onValueChange:M=>v(M),children:[e.jsx(s.SelectTrigger,{className:"col-span-2 h-8 w-full focus:ring-1 focus:ring-offset-0",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{children:e.jsxs(s.SelectGroup,{children:[e.jsx(s.SelectLabel,{children:"Locale"}),s.LOCALE_CURRENCY_PAIRS.map(M=>e.jsx(s.SelectItem,{value:M.locale,children:M.locale},M.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:j,onChange:M=>x(Number(M.target.value)),id:"format",className:`col-span-6 h-8 w-full tracking-wide ${fe}`})]})]})}function z(){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:l,onChange:R=>d(M=>E(M,R.target.value)),className:`col-span-1 h-8 w-full ${fe}`}),e.jsx(s.Input,{value:u,onChange:R=>p(M=>E(M,R.target.value)),id:"max",className:`col-span-1 h-8 w-full ${fe}`})]}),e.jsxs("div",{className:"grid grid-cols-3 items-center gap-2",children:[e.jsx(s.Label,{htmlFor:"step-size",children:"Step Size"}),e.jsx(s.Input,{value:b,onChange:R=>i(M=>E(M,R.target.value)),id:"step-size",className:`col-span-1 h-8 w-full ${fe}`})]})]})}function B(){var J;let R={};h==="custom"&&(R={min:l,max:u,ticks:{stepSize:b}});const M={...a||{},chartOptions:{...a==null?void 0:a.chartOptions,scales:{...(J=a==null?void 0:a.chartOptions)==null?void 0:J.scales,[r]:{type:o,...o==="linear"?R:{}}}},numberAxisFormat:{decimalPlaces:j,suffix:C,currency:I,locale:T}};console.log(M),A(M);const U={...V,preferences:M};F(U)}return e.jsxs(s.Popover,{onOpenChange:R=>n(R),children:[e.jsx(s.PopoverTrigger,{asChild:!0,children:e.jsx(s.IconButton,{tooltip:"Scale Options",children:e.jsx(ot,{className:"size-4 rotate-45"})})}),e.jsx(s.PopoverContentCustom,{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:m,value:o,onValueChange:R=>c(R),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"})]})})]})]}),o=="linear"&&e.jsxs("div",{className:"grid grid-cols-3 items-center gap-2 py-1",children:[e.jsx(s.Label,{htmlFor:"scale-option",children:"Setup"}),e.jsxs(s.RadioGroup,{disabled:m,id:"scale-option",value:h,onValueChange:R=>f(R),className:"col-span-2 flex gap-3",defaultValue:"x",children:[e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(s.RadioGroupItem,{value:"auto",id:"r1"}),e.jsx("label",{className:"text-sm",htmlFor:"r1",children:"Auto"})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(s.RadioGroupItem,{value:"custom",id:"r2"}),e.jsx("label",{className:"text-sm",htmlFor:"r2",children:"Custom"})]})]})]}),h==="custom"&&o=="linear"&&z(),q(),e.jsx(s.SelectSeparator,{}),e.jsx("div",{className:"grid grid-cols-3",children:e.jsx(s.Button,{onClick:B,variant:"secondary",className:"col-span-1 col-start-3 h-8 w-full",children:"Apply"})})]})]})})]})}function Zt(){const t=s.useEditorStore(d=>{var u,p,h,f;return(f=(h=(p=(u=d.card.preferences)==null?void 0:u.chartOptions)==null?void 0:p.plugins)==null?void 0:h.legend)==null?void 0:f.position}),n=s.useEditorStore(d=>{var u,p,h,f;return(f=(h=(p=(u=d.card.preferences)==null?void 0:u.chartOptions)==null?void 0:p.plugins)==null?void 0:h.legend)==null?void 0:f.align}),a=s.useEditorStore(d=>{var u,p,h,f;return(f=(h=(p=(u=d.card.preferences)==null?void 0:u.chartOptions)==null?void 0:p.plugins)==null?void 0:h.legend)==null?void 0:f.display}),{setLegendOptions:r}=s.useEditorActions(),o=d=>{r({display:d,position:t,align:n})},c=d=>{r({display:a,position:d,align:n})},l=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(Js,{className:"size-4"})})}),e.jsx(s.PopoverContentCustom,{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("div",{className:"col-span-2 flex h-8 items-center",children:[e.jsx(s.IconButton,{tooltip:"Top",onClick:()=>c("top"),children:e.jsx(s.ArrowUp,{className:"size-4"})}),e.jsx(s.IconButton,{tooltip:"Left",onClick:()=>c("left"),children:e.jsx(Es,{className:"size-4"})}),e.jsx(s.IconButton,{tooltip:"Bottom",onClick:()=>c("bottom"),children:e.jsx(Is,{className:"size-4"})}),e.jsx(s.IconButton,{tooltip:"Right",onClick:()=>c("right"),children:e.jsx(Ds,{className:"size-4"})})]})]}),e.jsxs("div",{className:"grid grid-cols-3 items-center gap-4",children:[e.jsx(s.Label,{htmlFor:"align",children:"Align"}),e.jsxs("div",{className:"col-span-2 flex h-8 items-center",children:[e.jsx(s.IconButton,{tooltip:"Start",onClick:()=>l("start"),children:e.jsx(ws,{className:"size-4"})}),e.jsx(s.IconButton,{tooltip:"Center",onClick:()=>l("center"),children:e.jsx(Ns,{className:"size-4"})}),e.jsx(s.IconButton,{tooltip:"End",onClick:()=>l("end"),children:e.jsx(ks,{className:"size-4"})})]})]})]})]})})]})}function Yt(){var c;const t=s.useEditorStore(l=>l.card.preferences),{setCardPreferences:n,setChartOrientation:a}=s.useEditorStore(l=>l.actions);function r(l){a(l)}const o=((c=t==null?void 0:t.chartOptions)==null?void 0:c.indexAxis)||"x";return e.jsx(s.IconButton,{onClick:()=>r(o==="y"?"x":"y"),tooltip:"Chart Orientation",children:o==="y"?e.jsx(tt,{className:"size-4"}):e.jsx(st,{className:"size-4"})})}function Xt(){const t=s.useEditorStore(l=>l.card),n=s.useEditorStore(l=>l.isShowingVisual),a=s.useEditorStore(l=>{var d,u;return(u=(d=l.card)==null?void 0:d.preferences)==null?void 0:u.chartOptions}),r=s.getChartGridStyle(a),{setChartGrid:o}=s.useEditorActions();function c(){const l=["xy","none","x","y"],u=(l.indexOf(r)+1)%l.length;o(l[u])}return n?e.jsxs("div",{"data-info":"visual-settings",className:"flex items-center",children:[["line","bar","range","stackedBar","stackedLine","horizontalBar"].includes(t.type)&&e.jsx(Yt,{}),!["kpi","text","custom","table"].includes(t.type)&&e.jsxs(e.Fragment,{children:[e.jsx(Wt,{}),e.jsx(Zt,{})]}),!["pie","doughnut","radar","polarArea","table","custom","kpi","text","map"].includes(t.type)&&e.jsxs(s.IconButton,{tooltip:"Grid Style",onClick:c,children:[(r==="xy"||!r)&&e.jsx(Gs,{className:"size-4"}),r==="x"&&e.jsx(Rs,{className:"size-4"}),r==="y"&&e.jsx(rt,{className:"size-4"}),r==="none"&&e.jsx(dt,{className:"size-4"})]})]}):null}function Be(){var _;const t=s.useEditorStore(N=>N.frame),n=s.useEditorStore(N=>N.card),a=s.useEditorStore(N=>N.isShowingVisual),r=s.useDashboardStore(N=>N.isVisualEditing),o=s.useEditorStore(N=>N.isSqlRunning),c=s.useEditorStore(N=>N.pythonStdOut),l=s.useEditorStore(N=>{var y;return(y=N.card.preferences)==null?void 0:y.chartOptions});s.useEditorStore(N=>N.actions.setRunSql),s.getChartGridStyle(l);const{setFrame:d,setCard:u,updateCardInFrame:p,setActiveTabCardId:h,runAssistant:f,setChartGrid:b}=s.useEditorActions(),{data:i,isLoading:j,isFetching:x,error:C}=s.useDashboardCardQuery(n);if(!n)return e.jsx(e.Fragment,{children:"No Active Card"});function g(){const N={connectionId:n.connectionId,id:s.v4(),title:"Title",description:"Description",preferences:{onClickFilter:[{columnIndex:0,expression:""}]},type:"bar",sql:"",data:[]};I(N)}function I(N){const y={...t,cards:[...t.cards,N],activeCardId:N.id};d(y),h(N.id)}function k(){const N={...n,id:s.v4(),title:`${n.title} Copy`,tabTitle:`${n.tabTitle||n.title} Copy`};I(N)}function T(N){const y=t.cards.filter(Q=>Q.id!==N),O=y[0],H={...t,cards:y,activeCardId:O.id};d(H),h(O.id),u(O)}function v(N){h(N)}const A=(N,y)=>{console.log("handleDragStart",y),N.dataTransfer.setData("tabIndex",y.toString())},F=N=>{N.preventDefault()},V=(N,y)=>{const O=N.dataTransfer.getData("tabIndex");if(O===y.toString())return;const H=Array.from(t.cards),[Q]=H.splice(parseInt(O),1);H.splice(y,0,Q),d({...t,cards:H})};function G(N,y){return N.cards.length===1&&(y.displayTab===!0||y.displayTab===void 0)||N.activeCardId!==y.id&&(y.displayTab===!0||y.displayTab===void 0)?null:e.jsx("div",{onClick:()=>{const O=y.displayTab===void 0?!1:!y.displayTab;u({...y,displayTab:O}),p({...y,displayTab:O})},children:y.displayTab===!0||y.displayTab===void 0?e.jsx(s.Eye,{className:"mr-2 size-3.5 text-muted-foreground hover:text-foreground"}):e.jsx(Ps,{className:"mr-2 size-3.5 text-muted-foreground hover:text-foreground"})})}function m(){return e.jsxs(s.Tabs,{onValueChange:v,value:t.activeCardId,className:"flex grow flex-col",children:[t.cards.map(N=>e.jsx(s.TabsContent,{className:"mt-0 grow",value:N.id,children:E()},N.id)),e.jsx(s.TabsList,{className:"group mx-6 justify-between overflow-x-auto",children:e.jsxs("div",{className:"flex items-center",children:[t.cards.map((N,y)=>e.jsx(s.Editable,{text:N.tabTitle||N.title,onSave:O=>{u({...n,tabTitle:O}),p({...n,tabTitle:O})},children:e.jsxs(s.TabsTrigger,{draggable:!0,onDragStart:O=>A(O,y),onDragOver:F,onDrop:O=>V(O,y),className:"",value:N.id,children:[G(t,N),N.tabTitle||N.title,t.activeCardId===N.id&&t.cards.length>1&&e.jsx(s.X,{className:"ml-2 size-3.5 text-muted-foreground hover:text-foreground",onClick:()=>T(N.id)})]})},N.id)),e.jsx(s.Button,{className:"ml-1 h-8 px-2 hover:bg-muted-foreground/50",variant:"outline",onClick:g,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:k,children:e.jsx(Vs,{className:"h-4 w-4"})})]})})]})}function E(){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:o,card:n,data:i==null?void 0:i.records})})})}):e.jsx(s.ErrorBoundary,{FallbackComponent:s.FallbackEditorCard,children:e.jsx(us,{className:"grow border-none shadow-none"})})}function q(){const N=JSON.stringify(i==null?void 0:i.records,null,2),y=new Blob([N],{type:"application/json"}),O=URL.createObjectURL(y),H=document.createElement("a");H.href=O,H.download=`${n.title}.json`,H.click()}function z(){const y=[Object.keys(i==null?void 0:i.records.reduce((R,M)=>({...R,...M}),{})).join(","),...((i==null?void 0:i.records)||[]).map(R=>Object.values(R).join(","))].join(`
|
|
322
|
+
`),O=new Blob([y],{type:"text/csv"}),H=URL.createObjectURL(O),Q=document.createElement("a");Q.href=H,Q.download=`${n.title}.csv`,Q.click()}function B(){const N=`Can you get the documentation for ${n.type} chart?`;f(N)}return e.jsxs("div",{className:"relative isolate flex h-full flex-col py-3",children:[(j||x)&&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(ie,{className:"h-8 w-8 animate-spin text-muted-foreground"})}),e.jsxs("div",{className:"z-10 mb-0 flex min-h-10 items-center justify-end gap-2 px-6",children:[a&&e.jsxs("div",{className:"flex grow items-center",children:[e.jsx(Jt,{}),r&&e.jsx(s.IconButton,{tooltip:"Visual Docs",onClick:B,children:e.jsx(Ts,{className:"size-4"})}),!["table","custom"].includes(n.type)&&r&&e.jsx(Gt,{})]}),!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:z,children:e.jsx($t,{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:q,children:e.jsx(_s,{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"})]}),e.jsx(Xt,{}),e.jsx(sa,{})]}),a?m():e.jsxs(s.ResizablePanelGroup,{className:"px-6",direction:"horizontal",children:[c&&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:c&&e.jsx(ea,{})}),e.jsx(s.ResizableHandle,{})]}),e.jsxs(s.ResizablePanel,{id:"2",order:2,minSize:10,className:"relative flex h-full min-h-0 w-full flex-1 basis-0",children:[(i==null?void 0:i.records)&&(i==null?void 0:i.records.length)>0&&e.jsx(qt,{data:(i==null?void 0:i.records)||[]}),(C||(i==null?void 0:i.error))&&e.jsx("span",{className:"font-mono text-xs",children:(C==null?void 0:C.message)||((_=i==null?void 0:i.error)==null?void 0:_.message)})]})]})]})}function ea(){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 sa(){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 ta({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 xe({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 aa(){var x,C;const t=s.useEditorStore(g=>g.card.customCardPreferences),{data:n}=gs(),a=(n==null?void 0:n.plugins)||[],r=s.useEditorStore(g=>g.card),o=s.useEditorStore(g=>g.frame),c=(t==null?void 0:t.visualType)||"single",{setCustomCardPreferences:l}=s.useEditorActions(),{components:d,manifest:u}=s.useCustomVisual((t==null?void 0:t.url)||""),p=(x=u==null?void 0:u.visuals)==null?void 0:x.find(g=>g.name===(t==null?void 0:t.componentName));function h(g,I){if(!t)return;const T={...(t==null?void 0:t.dataInputCardIds)||{},[g]:{cardId:I,hookRef:null}};l({...t,dataInputCardIds:T})}function f(g){var k,T;const I=(k=o==null?void 0:o.cards)==null?void 0:k.filter(v=>{var A;return((A=v==null?void 0:v.customCardPreferences)==null?void 0:A.visualType)!=="multiple"}).map(v=>({value:v.id,label:v.tabTitle||v.title}));return e.jsx("div",{className:"space-y-2",children:(T=g==null?void 0:g.dataInputs)==null?void 0:T.map((v,A)=>{var F,V;return e.jsxs("div",{className:"grid grid-cols-10 gap-2",children:[e.jsx("div",{className:"col-span-4 flex items-center",children:v}),e.jsx(se,{className:"col-span-6 h-8 w-full justify-between",label:"",options:I||[],value:((V=(F=t==null?void 0:t.dataInputCardIds)==null?void 0:F[A])==null?void 0:V.cardId)||"",onValueChange:G=>h(A,G)})]},A+Math.random())})})}function b(g,I,k=[]){var T,v;return t?g==="input"?e.jsx(s.Input,{className:`h-8 w-full ${s.removeRing}`,value:((T=t==null?void 0:t.settings)==null?void 0:T[I])||"",onChange:A=>{l({...t,settings:{...t==null?void 0:t.settings,[I]:A.target.value}})}},I):g==="select"?e.jsx(se,{className:"h-8 w-full",label:"",options:k,value:((v=t==null?void 0:t.settings)==null?void 0:v[I])||"",onValueChange:A=>{l({...t,settings:{...t==null?void 0:t.settings,[I]:A}})}}):null:null}function i(g){const I=Object.entries((g==null?void 0:g.settings)||{});return e.jsx("div",{className:"space-y-3",children:I.map(([k,T])=>e.jsxs("div",{className:"space-y-2",children:[e.jsx(s.Label,{children:T.title}),b(T.ui,k,T.options)]},k))})}function j(g){t&&l({...t,visualType:g,componentName:""})}return e.jsxs("div",{className:"p-6",children:[e.jsx(xe,{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(se,{className:"h-8 w-full",label:"",options:a,value:(t==null?void 0:t.url)||"",onValueChange:g=>l({...t||{url:"",componentName:""},url:g})})})}),((t==null?void 0:t.type)==="component"||(t==null?void 0:t.type)===void 0)&&e.jsx(ta,{options:[{value:"single",label:"Single Visual"},{value:"multiple",label:"Multi-Visual"}],value:c,onValueChange:j}),((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(se,{className:"h-8 w-full",label:"",options:(d==null?void 0:d.filter(g=>g.type===c).map(g=>({value:g.name,label:g.name})))||[],value:t.componentName,onValueChange:g=>{console.log("changing value",g),l({...t,componentName:g})}})})]})})]})})}),e.jsx(s.Separator,{className:"my-4"}),((C=r==null?void 0:r.customCardPreferences)==null?void 0:C.componentName)&&e.jsxs(xe,{summary:"Component Settings",children:[p&&p.dataInputs&&e.jsxs("div",{className:"space-y-3",children:[e.jsx(s.Label,{children:"Input Mapping"}),e.jsx("div",{className:"px-2",children:f(p)})]}),p&&p.settings&&e.jsx("div",{className:"space-y-3",children:e.jsx("div",{className:"px-2",children:i(p)})})]})]})}function le(){const[t,n]=S.useState([]),a=s.useEditorStore(p=>p.card.preferences),{setFilterOnClickColumnIndex:r,setCardPreferences:o}=s.useEditorStore(p=>p.actions),c=s.useEditorStore(p=>p.queryResultColumns);s.useEditorStore(p=>{var h;return(h=p.card.preferences)==null?void 0:h.filterOnClickColumnIndex}),S.useEffect(()=>{c&&n(new Array(c.length).fill(!1))},[c]);function l(p,h){var f,b;h?a!=null&&a.onClickFilter&&((f=a==null?void 0:a.onClickFilter)==null?void 0:f.length)>0?o({...a,onClickFilter:[...a.onClickFilter,{columnIndex:p,expression:""}]}):o({...a,onClickFilter:[{columnIndex:p,expression:""}]}):(o({...a,onClickFilter:(b=a==null?void 0:a.onClickFilter)==null?void 0:b.filter(i=>i.columnIndex!==p)}),n(i=>{const j=[...i];return j[p]=!1,j}))}function d(p,h){var b;const f=(b=a==null?void 0:a.onClickFilter)==null?void 0:b.map(i=>i.columnIndex===p?{...i,expression:h.target.value}:i);o({...a,onClickFilter:f})}function u(p){var h,f,b,i;if(t!=null&&t[p]||(f=(h=a==null?void 0:a.onClickFilter)==null?void 0:h.find(j=>j.columnIndex===p))!=null&&f.expression)return e.jsx(s.Input,{value:(i=(b=a==null?void 0:a.onClickFilter)==null?void 0:b.find(j=>j.columnIndex===p))==null?void 0:i.expression,onChange:j=>d(p,j),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((p,h)=>{var f,b;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:!!((f=a==null?void 0:a.onClickFilter)!=null&&f.find(i=>i.columnIndex===h)),onCheckedChange:i=>l(h,i)}),e.jsx("label",{className:"text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70",children:p}),e.jsx("div",{className:"flex items-center gap-2",children:((b=a==null?void 0:a.onClickFilter)==null?void 0:b.find(i=>i.columnIndex===h))&&e.jsx(s.Pencil,{onClick:()=>{n(i=>{const j=[...i];return j[h]=!i[h],j})},className:"invisible size-3 cursor-pointer text-gray-400 group-hover:visible"})})]}),u(h)]})},p)})]})}function na({idx:t}){var d;const n=s.useEditorStore(u=>{var p;return(p=u.card)==null?void 0:p.preferences}),a=s.useEditorStore(u=>{var p;return(p=u.card.preferences)==null?void 0:p.datasetOptions}),r=s.useEditorStore(u=>u.actions.setCardPreferences),o=(d=n==null?void 0:n.chartOptions)==null?void 0:d.indexAxis,c=a==null?void 0:a.find(u=>u.idx===t);function l(u,p){(u==="end"||u==="start")&&s.getContrastColor(s.getCanvasBackgroundColor());const h={display:u!=="none",align:u,anchor:u,clamp:!0};if(!c)r({...n,datasetOptions:[...a||[],{idx:p,datalabels:h}]});else{const f={...c};f.datalabels=h;const b=a==null?void 0:a.map(i=>i.idx===p?f:i);r({...n,datasetOptions:b})}}return e.jsxs(s.Popover,{children:[e.jsx(s.PopoverTrigger,{children:e.jsx(ut,{className:"invisible size-4 rotate-[135deg] cursor-pointer text-muted-foreground hover:text-foreground group-hover:visible"})}),e.jsx(s.PopoverContent,{className:"w-fit p-1",children:e.jsxs("div",{className:"flex gap-1",children:[e.jsx(s.Button,{onClick:()=>l("none",t),size:"sm",variant:"secondary",className:"h-7 p-1 text-xs font-normal",children:e.jsx(s.X,{className:"size-4"})}),e.jsx(s.Button,{onClick:()=>l("start",t),size:"sm",variant:"secondary",className:"h-7 p-1 text-xs font-normal",children:e.jsx(Ks,{className:s.cn("h-4 w-4",{"rotate-90":o==="y"})})}),e.jsx(s.Button,{onClick:()=>l("center",t),size:"sm",variant:"secondary",className:"h-7 p-1 text-xs font-normal",children:e.jsx(Zs,{className:s.cn("h-4 w-4",{"rotate-90":o==="y"})})}),e.jsx(s.Button,{onClick:()=>l("end",t),size:"sm",variant:"secondary",className:"h-7 p-1 text-xs font-normal",children:e.jsx(Ws,{className:s.cn("h-4 w-4",{"rotate-90":o==="y"})})})]})})]})}function js(){const t=s.useEditorStore(p=>p.card),n=s.useEditorStore(p=>{var h,f,b;return(b=(f=(h=p==null?void 0:p.card)==null?void 0:h.preferences)==null?void 0:f.chartOptions)==null?void 0:b.indexAxis}),{data:a}=s.useDashboardCardQuery(t),r=n==="y"?"Metric":"Dimension",o=n==="y"?"Dimension":"Metric",{keys:c,metricKeys:l,dimensionKeys:d}=s.getKeys((a==null?void 0:a.records)||[]);let u=l;if(["stackedBar","stackedLine"].includes(t.type)){const p=s.pivotData({dataArray:(a==null?void 0:a.records)||[],groupKey:d[0],pivotKey:d[1],valueKey:u[0]}),{metricKeys:h}=s.getKeys(p);u=h}return c.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:bs(d[0])})})})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(s.Label,{children:o}),e.jsx("div",{className:"my-1 max-h-[125px] space-y-1 overflow-y-auto",children:u.map((p,h)=>e.jsx(ra,{col:p,idx:h},p))})]})]})}function bs(t,n=30){return t.length>n?t.slice(0,n)+"...":t}function ra({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:c}=s.useEditorStore(d=>d.actions);function l(d){if(!o)c({...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 p=r==null?void 0:r.map(h=>h.idx===n?u:h);c({...a,datasetOptions:p})}}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:bs(t)}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(Ne,{onClick:()=>l("bar"),className:"invisible size-4 cursor-pointer text-muted-foreground hover:text-foreground group-hover:visible"}),e.jsx(we,{onClick:()=>l("line"),className:"invisible size-4 cursor-pointer text-muted-foreground hover:text-foreground group-hover:visible"}),e.jsx(zs,{onClick:()=>l("area"),className:"invisible size-4 cursor-pointer text-muted-foreground hover:text-foreground group-hover:visible"}),e.jsx(na,{idx:n})]})]})}function ys(){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),c=s.useDashboardStore(i=>i.dashboard.filters)||[],l=s.useDashboardStore(i=>i.actions.addFilter),d=s.useDashboardStore(i=>i.actions.removeFilter),{removeFilterValues:u}=s.useDashboardActions(),{modelItems:p,tableName:h,connectionType:f}=ne();function b(i,j="dashboard"){var F;const x=s.fmt(i.column_name),C=s.fmt(a||""),g=s.fmt(r||""),I=s.fmt(h);let k=s.getQualifiedTableName({schemaName:g,tableName:I,connectionType:f,databaseName:C}),T=`${k}.${x}`;const v=(F=p==null?void 0:p.find(V=>V.id===n))==null?void 0:F.name;n&&n!=="none"&&(T=`${s.DATAMODEL_NAMESPCACE}.${v}.${x}`,k=`${s.DATAMODEL_NAMESPCACE}.${v}`);const A=c==null?void 0:c.find(V=>V.column===T&&V.table===I&&(V.database===C||V.database===a));if(A)u(A.id),d(A.id);else{const V=s.v4();return h==="api"&&t?(l({location:j,id:V,column:T,title:i.column_name,dataType:i.data_type,table:"api",database:"",connectionId:t,operation:"in",sql:s.getDefaultFilterSql(i.data_type,k,x)}),V):(l({id:V,location:j,column:T,title:i.column_name,dataType:i.data_type,table:o||"",database:a||"",connectionId:t||"",operation:"in",sql:s.getDefaultFilterSql(i.data_type,k,x)}),V)}}return{assignFilter:b}}function he(){const t=s.useDashboardStore(d=>d.dashboard.filters),n=s.useEditorStore(d=>d.frame),{setFrame:a}=s.useEditorActions(),{columns:r}=ne(),{assignFilter:o}=ys();function c(d){const u=o(d,"frame");a({...n,filterId:u})}const l=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(oa,{onSelect:c,columns:r}),l&&e.jsx(s.FilterHeader,{filter:l})]})}function oa({columns:t,onSelect:n}){var l;const[a,r]=de.useState(!1),[o,c]=de.useState("");return e.jsxs(s.Popover,{open:a,onOpenChange:r,children:[e.jsx(s.PopoverTrigger,{asChild:!0,children:e.jsxs(s.Button,{size:"sm",variant:"outline",role:"combobox","aria-expanded":a,className:"w-full justify-between font-normal",children:[o?(l=t.find(d=>d.column_name===o))==null?void 0:l.column_name:"Select Column...",e.jsx(s.CaretSortIcon,{className:"ml-2 h-4 w-4 shrink-0 opacity-50"})]})}),e.jsx(s.PopoverContent,{className:"w-[200px] p-0",children:e.jsxs(s.Command,{children:[e.jsx(s.CommandInput,{placeholder:"Search column",className:"h-9"}),e.jsxs(s.CommandList,{children:[e.jsx(s.CommandEmpty,{children:"No framework found."}),e.jsx(s.CommandGroup,{children:t.map(d=>e.jsxs(s.CommandItem,{value:d.column_name,onSelect:u=>{const p=u===o?"":u;c(p),r(!1),p&&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 ia({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.jsx(s.AccordionContent,{className:"space-y-4 px-2",children:e.jsx(js,{})})]}),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(le,{}),e.jsx(he,{})]})]})]})})}function Ee(){var o,c,l;const t=s.useEditorStore(d=>d.card.type),n=s.useEditorStore(d=>d.card.preferences),{setCardPreferences:a}=s.useEditorStore(d=>d.actions);function r(d){var h;const u={datalabels:{display:d!=="none",align:d,anchor:d,clamp:!0}},p={...n,chartOptions:{...n==null?void 0:n.chartOptions,plugins:{...(h=n==null?void 0:n.chartOptions)==null?void 0:h.plugins,...u}}};a(p),console.log(d)}return e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"font-medium",children:"Data Labels"}),e.jsxs(s.Select,{value:((l=(c=(o=n==null?void 0:n.chartOptions)==null?void 0:o.plugins)==null?void 0:c.datalabels)==null?void 0:l.anchor)||"none",onValueChange:r,defaultValue:"none",children:[e.jsx(s.SelectTrigger,{className:"h-8 w-full focus:ring-1 focus:ring-offset-0",children:e.jsx(s.SelectValue,{placeholder:"Select position"})}),e.jsx(s.SelectContent,{children:e.jsxs(s.SelectGroup,{children:[e.jsx(s.SelectLabel,{children:"Data Labels"}),e.jsx(s.SelectItem,{value:"none",children:"None"}),t!=="pyramid"&&e.jsx(s.SelectItem,{value:"start",children:"Start"}),e.jsx(s.SelectItem,{value:"center",children:"Center"}),t!=="pyramid"&&e.jsx(s.SelectItem,{value:"end",children:"End"})]})})]})]})}function la({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:c=>c.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(Ee,{})})]}),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(le,{}),e.jsx(he,{})]})]})]})})}const ca={datasets:[{type:"line",label:"Sum_sales",data:[]},{type:"bar",label:"Sum_profit",data:[]}]},da={datasets:[{fill:"origin",type:"line",label:"Sum_sales",data:[]}]};function ua(){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:ha(t)}),!["kpi"].includes(t)&&e.jsxs("div",{className:"space-y-4",children:[e.jsx(Ee,{}),e.jsx(le,{}),e.jsx(he,{})]})]})}function ha(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(ca,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(da,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 ma(){var u,p,h,f,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 j,x;return(x=(j=i.card.preferences)==null?void 0:j.formatNumber)==null?void 0:x.decimalPlaces});const r=s.useEditorStore(i=>{var j,x;return(x=(j=i.card.preferences)==null?void 0:j.formatNumber)==null?void 0:x.locale}),o=s.useEditorStore(i=>{var j,x;return(x=(j=i.card.preferences)==null?void 0:j.formatNumber)==null?void 0:x.currency});s.useEditorStore(i=>i.actions.setFilterOnClickField);const c=s.useEditorStore(i=>{var j,x;return(x=(j=i.card.preferences)==null?void 0:j.formatNumber)==null?void 0:x.colorRanges})||[],l=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"})]}),((p=t==null?void 0:t.formatNumber)==null?void 0:p.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 j,x,C;return a(((j=t==null?void 0:t.formatNumber)==null?void 0:j.decimalPlaces)||0,((x=t==null?void 0:t.formatNumber)==null?void 0:x.currency)||"",i,((C=t==null?void 0:t.formatNumber)==null?void 0:C.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 j,x,C;console.log("currency",i),a(((j=t==null?void 0:t.formatNumber)==null?void 0:j.decimalPlaces)||0,i==="none"?"":i,((x=t==null?void 0:t.formatNumber)==null?void 0:x.locale)||"",((C=t==null?void 0:t.formatNumber)==null?void 0:C.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:((f=(h=t==null?void 0:t.formatNumber)==null?void 0:h.decimalPlaces)==null?void 0:f.toString())||"0",onValueChange:i=>{var j,x,C;return a(Number(i),((j=t==null?void 0:t.formatNumber)==null?void 0:j.currency)||"",((x=t==null?void 0:t.formatNumber)==null?void 0:x.locale)||"",((C=t==null?void 0:t.formatNumber)==null?void 0:C.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 j,x,C;return a(((j=t==null?void 0:t.formatNumber)==null?void 0:j.decimalPlaces)||0,((x=t==null?void 0:t.formatNumber)==null?void 0:x.currency)||"",((C=t==null?void 0:t.formatNumber)==null?void 0:C.locale)||"",i.target.value)}})]})]})]})}),e.jsx(s.Separator,{className:"my-3"}),e.jsx(s.ColorFormat,{colorRanges:c,setColorRanges:l})]})]})}function xa(){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(ma,{})}),e.jsx("div",{}),e.jsx("div",{})]})}const pa=[{label:"Mercator",value:"mercator"},{label:"Azimuthal Equidistant",value:"azimuthalEquidistant"},{label:"Gnomonic",value:"gnomonic"},{label:"Orthographic",value:"orthographic"},{label:"Stereographic",value:"stereographic"},{label:"Equal Earth",value:"equalEarth"},{label:"Albers",value:"albers"},{label:"Albers USA",value:"albersUsa"},{label:"Conic Conformal",value:"conicConformal"},{label:"Conic Equal Area",value:"conicEqualArea"},{label:"Conic Equidistant",value:"conicEquidistant"},{label:"Equirectangular",value:"equirectangular"},{label:"Transverse Mercator",value:"transverseMercator"},{label:"Natural Earth 1",value:"naturalEarth1"}],fa=["blues","brBG","buGn","buPu","cividis","cool","cubehelixDefault","gnBu","greens","greys","inferno","magma","orRd","oranges","pRGn","piYG","plasma","puBu","puBuGn","puOr","puRd","purples","rainbow","rdBu","rdGy","rdPu","rdYlBu","rdYlGn","reds","sinebow","spectral","turbo","viridis","warm","ylGn","ylGnBu","ylOrBr","ylOrRd"],ga=fa.map(t=>({label:t,value:t}));function ja(){var u,p,h,f,b,i,j,x,C,g,I,k,T,v,A,F,V,G;const t=s.useEditorStore(m=>m.card),n=(p=(u=t==null?void 0:t.preferences)==null?void 0:u.mapVisualOptions)==null?void 0:p.topoJsonUrl,[a,r]=S.useState(((f=(h=t==null?void 0:t.preferences)==null?void 0:h.mapVisualOptions)==null?void 0:f.customTopoJsonUrl)||""),{setCardPreferences:o}=s.useEditorActions(),{data:c}=s.useTopoJson(t),l=Object.keys((c==null?void 0:c.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(xe,{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(xe,{open:!0,summary:"Settings",children:e.jsxs("div",{className:"space-y-3 px-2",children:[e.jsx(se,{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"}),c&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(s.Label,{children:"Map Object"}),e.jsx(se,{className:"h-9",options:l,value:((i=(b=t.preferences)==null?void 0:b.mapVisualOptions)==null?void 0:i.objectKey)||"",label:"Map Object",onValueChange:m=>{var E;o({...t.preferences,mapVisualOptions:{...(E=t.preferences)==null?void 0:E.mapVisualOptions,objectKey:m}})}})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(s.Label,{children:"Projection"}),e.jsx(se,{className:"h-9",options:pa,value:((x=(j=t.preferences)==null?void 0:j.mapVisualOptions)==null?void 0:x.projection)||"",label:"Projection",onValueChange:m=>{var E;o({...t.preferences,mapVisualOptions:{...(E=t.preferences)==null?void 0:E.mapVisualOptions,projection:m}})}})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(s.Label,{children:"Colors"}),e.jsx(se,{className:"h-9",options:ga,value:((g=(C=t.preferences)==null?void 0:C.mapVisualOptions)==null?void 0:g.colorScale)||"",label:"Select Color Scale",onValueChange:m=>{var E;o({...t.preferences,mapVisualOptions:{...(E=t.preferences)==null?void 0:E.mapVisualOptions,colorScale:m}})}})]})]})]})}),e.jsx(s.Separator,{className:"my-4"}),e.jsx(xe,{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:((k=(I=t.preferences)==null?void 0:I.mapVisualOptions)==null?void 0:k.projectionScale)||1,onChange:m=>{var E;o({...t.preferences,mapVisualOptions:{...(E=t.preferences)==null?void 0:E.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:((A=(v=(T=t.preferences)==null?void 0:T.mapVisualOptions)==null?void 0:v.projectionOffset)==null?void 0:A[0])||0,onChange:m=>{var E,q,z,B;o({...t.preferences,mapVisualOptions:{...(E=t.preferences)==null?void 0:E.mapVisualOptions,projectionOffset:[Number(m.target.value),((B=(z=(q=t.preferences)==null?void 0:q.mapVisualOptions)==null?void 0:z.projectionOffset)==null?void 0:B[1])||0]}})}}),e.jsx(s.Label,{children:"Y"}),e.jsx(s.Input,{className:`h-9 w-full ${s.removeRing}`,type:"number",step:10,value:((G=(V=(F=t.preferences)==null?void 0:F.mapVisualOptions)==null?void 0:V.projectionOffset)==null?void 0:G[1])||0,onChange:m=>{var E,q,z,B;o({...t.preferences,mapVisualOptions:{...(E=t.preferences)==null?void 0:E.mapVisualOptions,projectionOffset:[((B=(z=(q=t.preferences)==null?void 0:q.mapVisualOptions)==null?void 0:z.projectionOffset)==null?void 0:B[0])||0,Number(m.target.value)]}})}})]})}),e.jsx(s.Separator,{className:"my-4"}),e.jsx(le,{})]})}function ba(){var r;const t=s.useEditorStore(o=>o.card.preferences),{setCardPreferences:n}=s.useEditorStore(o=>o.actions);function a(o){n({...t,textVisualOptions:{...t==null?void 0:t.textVisualOptions,isDynamicText:o==="dynamic"}})}return e.jsxs(s.RadioGroup,{value:(r=t==null?void 0:t.textVisualOptions)!=null&&r.isDynamicText?"dynamic":"static",onValueChange:a,className:"flex gap-3",defaultValue:"x",children:[e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(s.RadioGroupItem,{value:"static",id:"r1"}),e.jsx("label",{className:"text-sm",htmlFor:"r1",children:"Static"})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(s.RadioGroupItem,{value:"dynamic",id:"r2"}),e.jsx("label",{className:"text-sm",htmlFor:"r2",children:"Dynamic"})]})]})}function ge({cardType:t,docContent:n,suffix:a="Chart"}){return e.jsx("div",{className:"space-y-6 px-6 py-2",children:e.jsxs(s.Accordion,{defaultValue:["item-2"],type:"multiple",children:[e.jsxs(s.AccordionItem,{value:"item-1",children:[e.jsx(s.AccordionTrigger,{children:`${s.titleCase(t)} ${a}`}),e.jsx(s.AccordionContent,{children:n||e.jsxs("div",{className:"space-y-4 font-mono text-xs",children:[e.jsx("div",{className:"rounded bg-muted px-2 py-1 text-xs",children:"SELECT label, measure FROM table"}),e.jsxs("ul",{className:"ml-6 list-disc text-xs [&>li]:mt-2",children:[e.jsx("li",{children:"label - category"}),e.jsx("li",{children:"measure - number"})]}),e.jsxs("div",{children:["See ",e.jsx("a",{target:"_blank",onClick:r=>r.stopPropagation(),className:"text-blue-700",href:"https://docs.semaphor.cloud/docs/charts/pie-donut-polar",children:"example"})," in the docs."]})]})})]}),e.jsxs(s.AccordionItem,{value:"item-2",children:[e.jsx(s.AccordionTrigger,{children:"Settings"}),e.jsxs(s.AccordionContent,{className:"space-y-4 px-2",children:[t!=="text"&&e.jsx(Ee,{}),t==="text"&&e.jsx(ba,{})]})]}),!["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(le,{}),e.jsx(he,{})]})]})]})})}function ya(){const t=s.useEditorStore(r=>{var o,c;return(c=(o=r==null?void 0:r.card)==null?void 0:o.preferences)==null?void 0:c.sortChart}),{setSortChart:n}=s.useEditorActions();function a(){return e.jsxs("div",{className:"space-y-2",children:[e.jsx(s.Label,{children:"Sort"}),e.jsx(se,{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:[a(),e.jsx(js,{})]})]}),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(le,{}),e.jsx(he,{})]})]})]})})}function Sa({cardType:t="table"}){console.log("cardType",t);const n=s.useEditorStore(o=>{var c;return(c=o.card)==null?void 0:c.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(le,{}),e.jsx(he,{})]})]})}),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 Ca=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."]})]}),va=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."]})]}),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 text FROM table limit 1"}),e.jsxs("div",{children:["See ",e.jsx("a",{target:"_blank",onClick:t=>t.stopPropagation(),className:"text-blue-700",href:"https://docs.semaphor.cloud/docs/charts/text",children:"example"})," in the docs."]})]});function wa(){const t=s.useEditorStore(a=>a.card.type);function n(a){switch(a){case"stackedBar":case"stackedLine":return e.jsx(ya,{});case"pyramid":return e.jsx(ge,{docContent:Ca,cardType:a});case"kpi":return e.jsx(xa,{});case"line":case"bar":return e.jsx(ia,{cardType:a});case"range":return e.jsx(ge,{docContent:va,cardType:a});case"pie":case"doughnut":case"polarArea":case"radar":return e.jsx(ge,{cardType:a});case"bubble":case"scatter":return e.jsx(la,{cardType:a});case"table":return e.jsx(Sa,{cardType:a});case"text":return e.jsx(ge,{docContent:Na,cardType:a,suffix:"Visual"});case"map":return e.jsx(ja,{});case"custom":return e.jsx(aa,{});default:return e.jsx(ua,{})}}return e.jsxs(s.ScrollArea,{className:"h-full w-full text-sm",children:[n(t),e.jsx(s.ScrollBar,{orientation:"horizontal"})]})}function ka(){const t=S.useRef(null),n=s.useEditorStore(r=>r.isShowingVisual),a=s.useEditorStore(r=>r.showAIDialog);return S.useEffect(()=>{var r,o;a?(r=t.current)==null||r.resize(0):(o=t.current)==null||o.resize(25)},[a]),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:n&&!a?e.jsxs(s.ResizablePanelGroup,{direction:"horizontal",children:[e.jsx(e.Fragment,{children:e.jsx(s.ResizablePanel,{ref:t,className:"flex",defaultSize:25,maxSize:30,children:e.jsx(wa,{})})}),!a&&e.jsx(s.ResizableHandle,{className:"border"}),e.jsx(s.ResizablePanel,{minSize:40,defaultSize:75,maxSize:100,children:e.jsx(Be,{})})]}):e.jsx(Be,{})})]})}const Ia=[{title:"Help me write a query for",subtitle:"orders by month"},{title:"Create a bar chart for",subtitle:"sales by category"}];function Ea(){const t=S.useRef(null),n=S.useRef(null),[a,r]=S.useState(!1),[o,c]=S.useState(s.isDev),[l,d]=S.useState(!1),u=s.useEditorStore(y=>y.actions.setCardSql),p=s.useEditorStore(y=>y.actions.setRunSql),h=s.useEditorStore(y=>y.showAIDialog),{setShowAIDialog:f}=s.useEditorActions(),{messages:b,setMessages:i,reload:j,append:x,input:C,setInput:g,isLoading:I,handleAddCurrentTableToScope:k,removeFromCurrentSelections:T,currentAssitantScope:v,handleInputChange:A,handleSubmit:F,stop:V,chatStatus:G,toolStatus:m,llmUsage:E}=ds();s.useAssistantScroll({scrollContainerRef:t,inputRef:n,messages:b}),S.useEffect(()=>{var y;h&&((y=n.current)==null||y.focus())},[h]);function q(y){u(y),p(!0)}function z(y){const O={role:"user",content:y.title+" "+y.subtitle};x(O)}function B(){return e.jsxs(s.DropdownMenu,{children:[e.jsx(s.DropdownMenuTrigger,{asChild:!0,children:e.jsx(s.Button,{className:"h-7 p-2",size:"sm",variant:"ghost",children:e.jsx(Qe,{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:a,onCheckedChange:r,children:"Token Usage"}),e.jsx(s.DropdownMenuCheckboxItem,{checked:o,onCheckedChange:c,children:"Tool Invocations"}),e.jsx(s.DropdownMenuCheckboxItem,{checked:l,onCheckedChange:d,children:"System Message"})]})]})}function _(){return e.jsxs("div",{"data-role":"header",children:[e.jsx("div",{className:"text-lg font-semibold",children:"Assistant"}),v&&v.length>0&&e.jsx("div",{className:"mt-2 flex flex-wrap items-center gap-2",children:v==null?void 0:v.map((y,O)=>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:y.schemaName||"",tableName:y.tableName||"",modelName:y.datamodelName||"",connectionType:y.connectionType||"",databaseName:y.databaseName||""}),e.jsx("button",{onClick:()=>{T(y)},children:e.jsx(s.X,{className:"size-3 text-muted-foreground hover:text-foreground"})})]},O))}),(v==null?void 0:v.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:k,children:[e.jsx(s.Plus,{className:"mr-2 size-3"}),"Current Table"]})]})]})}const N=(C==null?void 0:C.length)===0&&(b==null?void 0:b.filter(y=>y.role==="user").length)===0;return e.jsxs("div",{"data-role":"editor-assistant",className:"flex h-full w-full flex-col justify-between gap-2 px-6 py-4",children:[e.jsxs("div",{"data-role":"header-section",className:"flex items-start justify-between gap-2",children:[_(),e.jsxs("div",{"data-role":"header-actions",className:"flex items-center",children:[B(),e.jsx(s.Button,{className:"h-7 p-2",size:"sm",variant:"ghost",onClick:()=>{i([]),j()},children:e.jsx(s.RefreshCcw,{className:"size-3.5 text-muted-foreground"})}),e.jsx(s.Button,{className:"h-7 p-2",size:"sm",variant:"ghost",onClick:()=>{f(!1)},children:e.jsx(s.X,{className:"size-4"})})]})]}),e.jsx(s.CustomScrollArea,{ref:t,className:"flex w-full grow basis-0",children:e.jsxs("div",{className:"space-y-4 py-2 pr-3","data-role":"messages",children:[e.jsx(s.PrintMessages,{messages:b,showTools:o,handleRun:q,showSystemMessage:l}),e.jsx(s.ChatStatus,{status:s.getStatus(G,m),isLoading:I})]})}),N&&e.jsx(s.Placeholders,{onClick:z,placeholders:Ia}),e.jsx(s.ChatInput,{onFocus:()=>{k()},stop:V,ref:n,setInput:g,input:C,handleInputChange:A,handleSubmit:F,isLoading:I}),E&&a&&e.jsx("div",{className:"flex h-8 items-center justify-between",children:e.jsxs("div",{className:"text-xs text-muted-foreground",children:["Usage: ",E.promptTokens," prompt tokens,"," ",E.completionTokens," completion tokens,"," ",E.totalTokens," total tokens"]})})]})}function Da({authToken:t,onSave:n,onClose:a}){const r=S.useRef(null),o=s.useEditorStore(f=>f.showAIDialog),{setAuthToken:c}=s.useDashboardActions(),{setShowAIDialog:l,setOnSave:d,setOnClose:u}=s.useEditorActions();S.useEffect(()=>{n&&d(n),a&&u(a)},[n,d,a,u]),S.useEffect(()=>{t&&t.accessToken&&c(t)},[t,c]),S.useEffect(()=>{var f,b;o?((f=r.current)==null||f.resize(40),l(!0)):(l(!1),(b=r.current)==null||b.resize(0))},[o,l]);function p(f){f<1?l(!1):o||l(!0)}function h(){return e.jsxs(s.ResizablePanelGroup,{"data-content":"editor-main",className:"grow",direction:"horizontal",children:[e.jsx(s.ResizablePanel,{className:"min-w-[510px] rounded-none border-x-[1px]",children:e.jsx(ka,{})}),e.jsx(s.ResizableHandle,{}),e.jsx(s.ResizablePanel,{"data-role":"editor-assistant-panel",ref:r,onResize:p,defaultSize:0,children:e.jsx(Ea,{})})]})}return e.jsx(s.ErrorBoundary,{FallbackComponent:s.Fallback,children:e.jsxs("section",{className:"flex h-full grow","data-content":"editor-panel",children:[e.jsx(os,{}),h()]})})}function Ta(){s.useDashboardStore(l=>l.selectedCardId);const t=s.useDashboardStore(l=>l.selectedSheetId),{setIsVisualEditing:n}=s.useDashboardStore(l=>l.actions),a=s.useDashboardStore(l=>l.isVisualEditing),r=s.useDashboardStore(l=>l.actions.updateFrame);function o(l){t&&(r(t,l),n(!1))}function c(){n(!1)}return e.jsx("div",{role:"editor-container",className:s.cn("flex grow",{"max-h-0 overflow-hidden":!a}),children:e.jsx(Da,{onSave:o,onClose:c})})}function La(){const t=s.useEditorStore(c=>c.selectedDatabaseName),n=s.useEditorStore(c=>c.selectedTableName),a=s.useDashboardStore(c=>c.dashboard.filters)||[],{columns:r}=ne(),{assignFilter:o}=ys();return e.jsx(s.ScrollArea,{className:"flex-1 basis-0 flex-col px-3",children:r==null?void 0:r.map(c=>{const l=a==null?void 0:a.find(d=>d.column===s.fmt(c.column_name)&&d.table===n&&d.database===t);return e.jsx("div",{onClick:()=>o(c),className:s.cn("group flex cursor-pointer items-center justify-between border border-dashed border-background px-3 py-[6px] text-sm transition-colors hover:bg-muted/50",{"bg-muted":l}),children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(rs,{column:c}),e.jsx("span",{children:c.column_name})]})},c.column_name)})})}function Aa(){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(os,{ColumnsComponent:()=>e.jsx(La,{})})})]})}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 za(){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(Aa,{})})]})}function Oa(){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(Oa,{}),e.jsxs(s.DashboardPanel,{...a,children:[t&&e.jsx(St,{}),e.jsx(Ta,{}),e.jsx(za,{})]})]})]})})}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.ScheduleDashboard=ns;exports.SelectComponent=ce;exports.Surfboard=Fa;exports.cleanCard=ss;exports.downloadPdf=as;exports.getDashbaordStateWithoutData=Ie;exports.useEditorAside=ne;
|