react-semaphor 0.0.473 → 0.0.475

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.
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("../chunks/index-CbdRGp6N.js"),r=require("../types/index.cjs");exports.Dashboard=e.Dashboard;exports.EMPTY_SELECTION=r.EMPTY_SELECTION;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("../chunks/index-DucZThMp.js"),r=require("../types/index.cjs");exports.Dashboard=e.Dashboard;exports.EMPTY_SELECTION=r.EMPTY_SELECTION;
@@ -1,4 +1,4 @@
1
- import { D as a } from "../chunks/index-Dtc6AzZx.js";
1
+ import { D as a } from "../chunks/index-BioC5I8T.js";
2
2
  import { EMPTY_SELECTION as e } from "../types/index.js";
3
3
  export {
4
4
  a as Dashboard,
package/dist/index.cjs CHANGED
@@ -1,4 +1,4 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("./chunks/index-CbdRGp6N.js"),Wt=require("./types/index.cjs"),e=require("react/jsx-runtime"),T=require("react");require("react-dom");function Kt(s){const a=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(s){for(const n in s)if(n!=="default"){const r=Object.getOwnPropertyDescriptor(s,n);Object.defineProperty(a,n,r.get?r:{enumerable:!0,get:()=>s[n]})}}return a.default=s,Object.freeze(a)}const le=Kt(T);/**
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("./chunks/index-DucZThMp.js"),Wt=require("./types/index.cjs"),e=require("react/jsx-runtime"),T=require("react");require("react-dom");function Kt(s){const a=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(s){for(const n in s)if(n!=="default"){const r=Object.getOwnPropertyDescriptor(s,n);Object.defineProperty(a,n,r.get?r:{enumerable:!0,get:()=>s[n]})}}return a.default=s,Object.freeze(a)}const le=Kt(T);/**
2
2
  * @license lucide-react v0.453.0 - ISC
3
3
  *
4
4
  * This source code is licensed under the ISC license.
@@ -353,7 +353,7 @@
353
353
  *
354
354
  * This source code is licensed under the ISC license.
355
355
  * See the LICENSE file in the root directory of this source tree.
356
- */const Us=t.createLucideIcon("Type",[["polyline",{points:"4 7 4 4 20 4 20 7",key:"1nosan"}],["line",{x1:"9",x2:"15",y1:"20",y2:"20",key:"swin9y"}],["line",{x1:"12",x2:"12",y1:"4",y2:"20",key:"1tx1rr"}]]);function _e(s){var a;return{...s,sheets:(a=s==null?void 0:s.sheets)==null?void 0:a.map(n=>{var r;return{...n,frames:(r=n.frames)==null?void 0:r.map(o=>{var l;return{...o,cards:(l=o.cards)==null?void 0:l.map(i=>pt(i))}})}})}}function pt(s){return{...s,customCfg:$s(s.customCfg),data:[]}}function $s(s){var a,n;return s?{...s,data:{...s==null?void 0:s.data,labels:[],datasets:(n=(a=s==null?void 0:s.data)==null?void 0:a.datasets)==null?void 0:n.map(r=>({...r,data:[]}))}}:null}async function Qs(s,a,n,r){if(!r)return null;const o=JSON.stringify(a);return await t.postRequest("https://semaphor.cloud/api/v1/lens",r,{name:s,template:o,filterValues:n,operation:"create"})}async function Le(s,a){if(!a)return null;const{id:n,template:r,filterValues:o,isDefault:l,shared:i}=s;return await t.postRequest("https://semaphor.cloud/api/v1/lens",a,{lensId:n,template:r,filterValues:o,isDefault:l,shared:i,operation:"update"})}async function Js(s,a){return a?await t.postRequest("https://semaphor.cloud/api/v1/lens",a,{operation:"delete",lensId:s}):null}function Ws(){const[s,a]=T.useState(""),[n,r]=T.useState(!1),o=t.useDashboardStore(p=>p.lenses),{setLenses:l,setSelectedLensId:i}=t.useDashboardActions(),[d,c]=T.useState(!1),[h,u]=T.useState(!1),x=t.useDashboardStore(p=>p.dashboard),b=t.useDashboardStore(p=>p.filterValues),{authToken:m}=t.useSemaphorContext();async function v(){c(!0);const p=_e(x),f=await Qs(s,p,b,m==null?void 0:m.accessToken);f&&(l([...o||[],f]),i(f.id),u(!1)),c(!1)}return e.jsxs(t.Dialog,{open:h,onOpenChange:u,children:[e.jsx(t.DialogTrigger,{asChild:!0,children:e.jsxs(t.Button,{variant:"secondary",className:"h-7 p-2",size:"sm",children:[e.jsx(t.Plus,{className:"mr-2 h-4 w-4"}),"Lens"]})}),e.jsxs(t.DialogContent,{className:"sm:max-w-[425px]",children:[e.jsxs(t.DialogHeader,{children:[e.jsx(t.DialogTitle,{children:"Create Lens"}),e.jsx(t.DialogDescription,{children:"Lenses are private by default and are only visible to you."})]}),e.jsx("div",{className:"grid gap-4 py-4",children:e.jsxs("div",{className:"grid grid-cols-8 items-center gap-4",children:[e.jsx(t.Label,{className:"text-right",children:"Name"}),e.jsx(t.Input,{value:s,onChange:p=>{a(p.target.value)},id:"name",className:"col-span-7 focus-visible:ring-0 focus-visible:ring-ring focus-visible:ring-offset-0"})]})}),n&&e.jsx("p",{className:"text-sm",children:"The lens name already exists. Use a differnet name."}),e.jsx(t.DialogFooter,{children:e.jsx(t.Button,{size:"sm",variant:"outline",type:"submit",onClick:v,disabled:d,children:d?"Creating...":"Add"})})]})]})}function Ks(){const[s,a]=T.useState(!1),n=t.useDashboardStore(u=>u.lenses),r=t.useDashboardStore(u=>u.selectedLensId),{setLenses:o,setSelectedLensId:l}=t.useDashboardActions(),{authToken:i}=t.useSemaphorContext();async function d(u){l(u)}async function c(u){if(await Js(u,i==null?void 0:i.accessToken)){const b=n==null?void 0:n.filter(m=>m.id!==u);o(b||[]),l("original")}}async function h(u){const x=n==null?void 0:n.map(v=>v.id===u.id?{...v,isDefault:!u.isDefault}:{...v,isDefault:!1});o(x||[]);const b={...u,isDefault:!u.isDefault};await Le(b,i==null?void 0:i.accessToken);const m=n==null?void 0:n.find(v=>v.isDefault);if(m&&m.id!==u.id){const v={...m,isDefault:!1};await Le(v,i==null?void 0:i.accessToken)}}return e.jsxs(t.DropdownMenu,{open:s,onOpenChange:a,children:[e.jsx(t.DropdownMenuTrigger,{asChild:!0,children:e.jsx(t.IconButton,{tooltip:"Lenses",className:"h-7 p-2",children:e.jsx(ws,{className:"h-4 w-4"})})}),e.jsxs(t.DropdownMenuContent,{align:"end",className:"w-60",children:[e.jsx(t.DropdownMenuLabel,{className:"px-3",children:"Lenses"}),e.jsx(t.DropdownMenuSeparator,{}),e.jsxs(t.DropdownMenuRadioGroup,{value:r,onValueChange:d,children:[e.jsx(t.DropdownMenuRadioItem,{value:"original",children:"Original"}),n==null?void 0:n.map(u=>e.jsxs(t.DropdownMenuRadioItem,{className:"group flex justify-between gap-2",value:u.id,children:[e.jsx("p",{children:u.name}),e.jsxs("span",{className:"flex items-center gap-3",children:[e.jsx(Is,{onClick:x=>{x.preventDefault(),h(u)},className:t.cn("size-3.5 text-muted-foreground hover:cursor-pointer hover:text-foreground group-hover:visible",{invisible:!u.isDefault,"text-green-500":u.isDefault}),strokeWidth:1.5}),e.jsx(t.Cross2Icon,{onClick:x=>{x.preventDefault(),c(u.id)},className:"invisible size-3.5 text-muted-foreground hover:cursor-pointer hover:text-foreground group-hover:visible",strokeWidth:1.5})]})]},u.id))]})]})]})}function ft(){var l;const s=t.useDashboardStore.getState().authToken,a=t.useDashboardStore.getState().theme,n=t.useDashboardStore.getState().filterValues,r=(l=t.useDashboardStore.getState().dashboard)==null?void 0:l.title,o=t.useDashboardStore.getState().selectedSheetId;return{authToken:s,theme:a||"light",filterValues:n,dashboardTitle:r||"",selectedSheetId:o||""}}async function gt(){const s=t.useDashboardStore.getState().isDownloadingPdf,{authToken:a,theme:n,filterValues:r,dashboardTitle:o,selectedSheetId:l}=ft();if(s)return;const i=new URLSearchParams;i.set("token",(a==null?void 0:a.accessToken)||""),i.set("theme",n),i.set("filterValues",JSON.stringify(r)),i.set("selectedSheetId",l||"");const d=`https://semaphor.cloud/api/v1/generate-pdf?params=${encodeURIComponent(i.toString())}`;t.useDashboardStore.setState({isDownloadingPdf:!0});const u=(await(await fetch(d,{method:"GET",headers:{Authorization:`Bearer ${a==null?void 0:a.accessToken}`}})).json()).url,x=document.createElement("a");x.href=u;const b=`${o}-${new Date().toISOString()}.pdf`;x.download=b,x.click(),t.useDashboardStore.setState({isDownloadingPdf:!1})}function Ys({iconClassName:s}){const{authToken:a}=t.useSemaphorContext();t.useDashboardStore(o=>{var l;return(l=o.dashboard)==null?void 0:l.title}),t.useDashboardStore(o=>o.theme),t.useDashboardStore(o=>o.filterValues);const n=t.useDashboardStore(o=>o.isDownloadingPdf);async function r(){await gt()}return e.jsx(t.IconButton,{tooltip:"Download PDF",className:"h-7 p-2",onClick:r,children:n?e.jsx(ae,{className:t.cn("size-3.5 animate-spin",s)}):e.jsx(t.Download,{className:t.cn("size-4",s)})})}function Y({defaultValue:s,label:a,options:n,value:r,onValueChange:o,className:l,icon:i,showPlaceholderLabel:d=!0}){return e.jsxs(t.Select,{defaultValue:s,value:r,onValueChange:o,children:[e.jsx(t.SelectTrigger,{className:t.cn("w-full focus:ring-0 focus:ring-offset-0",l),children:e.jsxs("div",{className:"flex items-center gap-2",children:[i&&e.jsx("span",{children:i}),d&&e.jsx(t.SelectValue,{placeholder:a})]})}),e.jsx(t.SelectContent,{children:e.jsxs(t.SelectGroup,{children:[e.jsx(t.SelectLabel,{children:a}),n.map(c=>e.jsx(t.SelectItem,{value:c.value,children:c.label},c.value))]})})]})}const Je=[{value:"daily",label:"Daily"},{value:"weekly",label:"Weekly"},{value:"biweekly",label:"Bi-Weekly"},{value:"monthly",label:"Monthly"}];function jt({triggerButtonClassName:s}){const{data:a,handleScheduleSubscription:n,handleDeleteSubscription:r,status:o,error:l,isDeleting:i}=Zs(),[d,c]=T.useState(""),[h,u]=T.useState(Je[0].value),[x,b]=T.useState("06:00"),[m,v]=T.useState("");return e.jsx(t.TooltipProvider,{delayDuration:0,children:e.jsxs(t.Popover,{children:[e.jsx(t.PopoverTrigger,{asChild:!0,children:e.jsx(t.IconButton,{tooltip:"Schedule Dashboard",className:t.cn("h-7 p-2",s),children:e.jsx(xs,{className:"size-4"})})}),e.jsx(t.PopoverContent,{align:"end",className:"w-80",children:e.jsxs("div",{className:"grid gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("h4",{className:"font-medium leading-none",children:"Schedule Subscription"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Subscribe to receive dashboard via email"})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsxs("div",{className:"grid grid-cols-3 items-center gap-4",children:[e.jsx(t.Label,{htmlFor:"email",children:"Email"}),e.jsx(t.Input,{id:"email",value:d,onChange:p=>c(p.target.value),className:`col-span-2 h-8 ${t.removeRing}`})]}),e.jsxs("div",{className:"grid grid-cols-3 items-center gap-4",children:[e.jsx(t.Label,{htmlFor:"subject",children:"Subject"}),e.jsx(t.Input,{id:"subject",placeholder:"Monthly Sales Report",value:m,onChange:p=>{v(p.target.value.replace(/[^a-zA-Z0-9\s-_]/g,""))},className:`col-span-2 h-8 ${t.removeRing}`})]}),e.jsxs("div",{className:"grid grid-cols-3 items-center gap-4",children:[e.jsx(t.Label,{htmlFor:"frequency",children:"Frequency"}),e.jsx(Y,{className:"col-span-2 h-8",label:"Select Frequency",options:Je,value:h,onValueChange:p=>u(p)})]}),e.jsxs("div",{className:"grid grid-cols-3 items-center gap-4",children:[e.jsx(t.Label,{htmlFor:"time",children:"Time"}),e.jsx(t.Input,{id:"time",type:"time",value:x,onChange:p=>b(p.target.value),className:`col-span-2 h-8 ${t.removeRing}`})]}),e.jsx("div",{className:"mt-2 flex justify-end",children:e.jsxs(t.Button,{onClick:async()=>{await n({email:d,frequency:h,time:x,subject:m}),b("00:00"),c(""),v("")},className:"h-8 p-2",disabled:o==="loading"||!d,children:[o==="loading"&&e.jsx(ae,{className:"mr-2 size-4 animate-spin"}),o==="success"&&e.jsx(t.Check,{className:"mr-2 size-4"}),o==="error"&&e.jsxs(t.Tooltip,{children:[e.jsx(t.TooltipTrigger,{children:e.jsx(at,{className:"mr-2 size-4 text-destructive"})}),e.jsx(t.TooltipContent,{children:e.jsx("p",{children:l})})]}),"Schedule"]})}),a&&a.length>0&&e.jsxs("div",{className:"space-y-4",children:[e.jsx(t.Separator,{className:"my-2"}),e.jsx("div",{className:"space-y-2",children:e.jsxs("div",{className:"flex items-start justify-between",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("h4",{className:"font-medium leading-none",children:"Subscriptions"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Active email subscriptions"})]}),t.isDevEnv]})}),e.jsx("div",{className:"grid gap-2",children:a==null?void 0:a.map(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:[t.titleCase(p.frequency)," "]}),e.jsx(t.Label,{children:p.time})]})}),e.jsxs("div",{className:"col-span-2 flex items-center justify-end gap-4",children:[e.jsx(We,{tooltip:`Next Run: ${new Date(p.nextRun).toLocaleString()} ${p.timezone}`,children:e.jsx(hs,{className:"size-3.5"})}),e.jsx(We,{tooltip:`${p.endUserEmail}`,children:e.jsx(Os,{className:"size-3.5"})}),i===p.id?e.jsx(ae,{className:"size-3.5 animate-spin"}):e.jsx(Gs,{onClick:()=>r(p.id),className:"size-3.5 cursor-pointer"})]})]},p.id))})]})]})]})})]})})}const We=({children:s,tooltip:a})=>e.jsx(t.TooltipProvider,{delayDuration:0,children:e.jsxs(t.Tooltip,{children:[e.jsx(t.TooltipTrigger,{asChild:!0,children:s}),e.jsx(t.TooltipContent,{children:a})]})});function Zs(){const[s,a]=T.useState("idle"),[n,r]=T.useState(""),[o,l]=T.useState(null),i=t.useDashboardStore(S=>S.authToken),d=t.useDashboardStore(S=>S.dashboard.id),c=t.useDashboardStore(S=>S.dashboard.title),{endUserId:h}=t.getTenantAndEndUserId((i==null?void 0:i.accessToken)||""),u="https://semaphor.cloud/api/v1/subscriptions/get",x={dashboardId:d,endUserId:h},{data:b,isLoading:m,isError:v,isFetching:p,refetch:f}=t.useQuery({queryKey:["subscriptions",d,h],queryFn:()=>t.getRequest(u,(i==null?void 0:i.accessToken)||"",x),enabled:!!(i!=null&&i.accessToken)&&!!d&&!!h});async function g({email:S,subject:L,frequency:k,time:M}){const{authToken:O,...F}=ft(),H=Intl.DateTimeFormat().resolvedOptions().timeZone,w={email:S,frequency:k,time:M,timezone:H,endUserId:h,endUserEmail:S,subject:L||c||"Scheduled Dashboard",dashboardId:d,dashboardParams:F};a("loading");const R="https://semaphor.cloud/api/v1/subscriptions/create";try{const U=await t.postRequestRegular(R,(O==null?void 0:O.accessToken)||"",{...w});a("success"),r(""),f(),setTimeout(()=>{a("idle")},2e3)}catch(U){console.error(U),a("error"),r(U.message)}}async function N(S){const L="https://semaphor.cloud/api/v1/subscriptions/delete";l(S);try{await t.postRequestRegular(L,(i==null?void 0:i.accessToken)||"",{id:S}),f(),setTimeout(()=>{l(null)},2e3)}catch(k){console.error(k),l(null),a("error"),r(k.message)}}return{data:b,isLoading:m,isFetching:p,isError:v,isDeleting:o,refetch:f,handleScheduleSubscription:g,handleDeleteSubscription:N,status:s,error:n}}function Xs(){const{authToken:s}=t.useSemaphorContext();t.useDashboardStore(w=>w.theme);const a=t.useDashboardStore(w=>w.lenses),n=t.useDashboardStore(w=>w.selectedLensId),r=a==null?void 0:a.find(w=>w.id===n),o=t.useDashboardStore(w=>w.dashboard);t.useDashboardStore(w=>w.selectedSheetId);const l=t.useDashboardStore(w=>w.isDashboardEditing),i=t.useEditorStore(w=>w.selectedConnectionId),[d,c]=T.useState(!1),h=t.useDashboardStore(w=>w.filterValues),u=t.useDashboardStore(w=>w.isVisualEditing),x=t.useDashboardStore(w=>w.showFilters);t.useDashboardStore(w=>w.showDashboardJSON);const b=t.useDashboardStore(w=>w.onSaveFunction),m=t.useDashboardStore(w=>w.actions.setShowFilters),{addFrame:v,setSelectedFrameId:p}=t.useDashboardStore(w=>w.actions),{getSelectedSheet:f,setIsDashboardEditing:g,setShowDashboardJSON:N}=t.useDashboardStore(w=>w.actions),S=f(),{tenantId:L,endUserId:k}=T.useMemo(()=>t.getTenantAndEndUserId(s==null?void 0:s.accessToken),[s==null?void 0:s.accessToken]),M=T.useMemo(()=>L||k,[L,k]),O=()=>{if(!l||!S)return;const w={connectionId:i,id:t.v4(),title:"Title",preferences:{onClickFilter:[{columnIndex:0,expression:""}]},type:"bar",sql:"",data:[]},R={id:t.v4(),cards:[w],activeCardId:w.id};v(S.id,R),p(R.id)},F=()=>{g(!0)};async function H(){if(c(!0),!n||!r)return;const w=_e(o),R=JSON.stringify(w),U={...r,template:R,filterValues:h};await Le(U,s==null?void 0:s.accessToken),t.ue.success("Lens saved"),b==null||b(w),c(!1)}return u?null:e.jsxs("div",{className:"flex items-center justify-between gap-2 border-b py-1 pl-3 pr-2",role:"dashboard-controls",children:[!u&&e.jsx("div",{className:"flex items-center gap-3",children:e.jsx(t.Label,{children:r==null?void 0:r.name})}),e.jsxs("div",{className:"flex gap-2",children:[!1,!u&&e.jsx(Ys,{}),!u&&e.jsx(jt,{}),l&&!u&&M&&e.jsx(Ws,{}),!u&&M&&e.jsx(Ks,{}),l&&!u&&e.jsxs(t.Button,{variant:"secondary",className:"h-7 p-2",size:"sm",disabled:!l,onClick:O,children:[e.jsx(t.Plus,{className:"mr-2 h-4 w-4"}),"Frame"]}),!l&&e.jsx(t.Button,{variant:"ghost",className:"h-7 p-2",onClick:F,size:"sm",children:e.jsx(t.Pencil,{className:"h-4 w-4"})}),l&&!u&&e.jsx(t.IconButton,{className:"h-7 p-2",onClick:()=>{g(!1),N(!1)},children:e.jsx(t.Cross2Icon,{className:"h-4 w-4"})}),l&&!u&&M&&e.jsx(t.Button,{className:"h-7 p-2",variant:"ghost",disabled:d,onClick:H,size:"sm",children:e.jsx(Vs,{className:"h-4 w-4"})}),!x&&!u&&l&&e.jsx(t.Button,{className:"h-7 p-2",variant:"ghost",onClick:()=>m(!0),size:"sm",children:e.jsx(it,{className:"h-4 w-4"})}),!u&&l&&!1,!u&&!1]})]})}function en({name:s,items:a,value:n,onChange:r,isLoading:o,isError:l,refetch:i,className:d,icon:c,showNone:h=!1}){const u=le.useRef(null),[x,b]=le.useState(!1),[m,v]=le.useState("100%"),p=h?[...a||[],{id:"none",name:"None"}]:a;le.useLayoutEffect(()=>{u.current&&v(u.current.offsetWidth)},[]);function f(){var N;return o?"Loading...":l?"Error":n?(N=a==null?void 0:a.find(S=>S.id===n))==null?void 0:N.name:`Select ${s}`}function g(N,S){r(S),b(!1)}return e.jsxs(t.Popover,{open:x,onOpenChange:b,children:[e.jsx(t.PopoverTrigger,{asChild:!0,children:e.jsxs(t.Button,{ref:u,variant:"outline",role:"combobox","aria-expanded":x,className:t.cn("flex h-9 w-full justify-between",d),children:[e.jsxs("div",{className:"flex items-center gap-2",children:[c&&e.jsx("div",{className:"mr-2",children:c}),e.jsx("span",{className:"max-w-[150px] overflow-hidden truncate text-ellipsis whitespace-nowrap",children:f()})]}),e.jsx(t.ChevronDown,{className:"size-4 opacity-50"})]})}),e.jsx(t.PopoverContent,{className:"w-full p-0",style:{minWidth:m},children:e.jsxs(t.Command,{children:[e.jsxs("div",{className:"flex h-9 items-center justify-between border-b pr-1",children:[e.jsx(t.CommandInput,{className:"h-9",placeholder:"Search..."}),e.jsx(t.IconButton,{className:"h-7",onClick:i,children:e.jsx(ut,{className:t.cn("size-3.5 opacity-50",o&&"animate-spin")})})]}),e.jsxs(t.CommandList,{children:[e.jsxs(t.CommandEmpty,{children:["No ",s==null?void 0:s.toLowerCase()," found."]}),e.jsx(t.CommandGroup,{children:p==null?void 0:p.map(N=>e.jsx(t.CommandItem,{className:"overflow-x-auto",value:N.name,onSelect:S=>g(S,N.id),children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(t.Check,{className:t.cn("size-4",n===N.id?"opacity-100":"opacity-0")}),e.jsx("div",{title:N.name,children:N.name})]})},N.id))})]})]})})]})}function ie({title:s,items:a,value:n,isLoading:r,isError:o,refetch:l,onChange:i,showNone:d=!1,className:c,disabled:h=!1,type:u="combobox"}){const x=r?"Loading...":o?"Error":n;function b(){if(s==="Connection")return e.jsx(Rs,{className:"size-4"});if(s==="Database")return e.jsx(js,{className:"size-4"});if(s==="Schema")return e.jsx(Fs,{className:"size-4"});if(s==="Table")return e.jsx(Ve,{className:"size-4"});if(s==="Model")return e.jsx(ds,{className:"size-4"})}function m(){return e.jsxs(t.Select,{disabled:h,value:x,onValueChange:i,children:[e.jsx(t.SelectTrigger,{className:t.cn("h-9 w-full border-muted focus:ring-1 focus:ring-offset-0",c),children:e.jsx(t.SelectValue,{placeholder:r?"Loading...":o?"Error":`Select ${s}`})}),e.jsx(t.SelectContent,{children:e.jsxs(t.SelectGroup,{children:[r?e.jsx(t.SelectLabel,{children:"Loading..."}):e.jsxs(t.SelectLabel,{className:"flex items-center justify-between gap-2",children:[s,e.jsx(ut,{className:t.cn("mr-1 size-3 cursor-pointer text-muted-foreground hover:text-foreground",r&&"animate-spin"),onClick:l})]}),e.jsxs(e.Fragment,{children:[d&&e.jsx(t.SelectItem,{value:"none",children:"None"},"none"),a&&a.map((p,f)=>e.jsx(t.SelectItem,{value:p.id,children:p.name},f))]}),(r||o)&&e.jsx(t.SelectItem,{value:x,children:x})]})})]})}function v(){return e.jsx(en,{icon:b(),items:a,value:x,onChange:i||(()=>{}),isLoading:r,isError:o,refetch:l,name:s,showNone:d})}return e.jsx(t.TooltipProvider$1,{delayDuration:0,children:e.jsx("div",{className:"flex items-center gap-2",children:u==="select"?m():v()})})}function tn({column:s}){const[a,n]=T.useState(!1),r=t.useEditorStore(p=>p.selectedTableName),o=t.useEditorStore(p=>p.selectedSchemaName),l=t.useEditorStore(p=>p.selectedDatabaseName),i=t.useEditorStore(p=>p.selectedDatamodelId),d=t.useEditorStore(p=>p.sqlGen),{modelItems:c,connectionType:h}=t.useEditorAside(),u=t.useEditorStore(p=>p.actions.setSqlGen),x=t.useEditorStore(p=>p.actions.setCardSql),b=t.useEditorStore(p=>p.actions.setRunSql);function m(p,f){var L;const g=t.createSqlGenConfig(p,d,f),N=(L=c==null?void 0:c.find(k=>k.id===i))==null?void 0:L.name;u(g);const S=t.getSql(g,t.fmt(o||""),t.fmt(r),N,h,l||"");S&&(x(S),b(!0)),n(!1)}function v(){return e.jsxs("ul",{className:"text-xs",children:[e.jsx("li",{onClick:()=>m(s,"COUNT"),className:"cursor-pointer p-1 px-3 transition-colors hover:bg-muted",children:"Count"}),e.jsx("li",{onClick:()=>m(s,"AVG"),className:"cursor-pointer p-1 px-3 transition-colors hover:bg-muted",children:"Avg"}),e.jsx("li",{onClick:()=>m(s,"SUM"),className:"cursor-pointer p-1 px-3 transition-colors hover:bg-muted",children:"Sum"}),e.jsx("li",{onClick:()=>m(s,"MAX"),className:"cursor-pointer p-1 px-3 transition-colors hover:bg-muted",children:"Max"}),e.jsx("li",{onClick:()=>m(s,"MIN"),className:"cursor-pointer p-1 px-3 transition-colors hover:bg-muted",children:"Min"})]})}return e.jsxs(t.HoverCard,{openDelay:0,open:a,onOpenChange:n,children:[e.jsx(t.HoverCardTrigger,{asChild:!0,children:e.jsx(t.EllipsisVertical,{className:"invisible size-3.5 cursor-pointer text-foreground/40 group-hover:visible"})}),e.jsx(t.HoverCardContent,{align:"center",className:"w-20 rounded-md p-0 shadow-none",children:v()})]})}function qe({column:s}){return e.jsxs(t.Tooltip,{children:[e.jsx(t.TooltipTrigger$1,{className:"shrink-0",asChild:!0,children:t.isTextDataType(s.data_type)?e.jsx(t.TextIcon,{className:"size-3 text-muted-foreground"}):t.isNumberDataType(s.data_type)?e.jsx(lt,{className:"size-3 text-muted-foreground"}):t.isDateDataType(s.data_type)?e.jsx(t.Calendar,{className:"size-3 text-muted-foreground"}):t.isBooleanDataType(s.data_type)?e.jsx(Hs,{className:"size-3 text-muted-foreground"}):s.data_type.startsWith("json")?e.jsx(us,{className:"size-3 text-muted-foreground"}):e.jsx(t.QuestionMarkIcon,{className:"size-3 text-muted-foreground"})}),e.jsx(t.TooltipContent,{children:e.jsx("p",{className:"text-xs",children:s.data_type})})]})}function we({column:s,className:a}){return e.jsxs("div",{className:t.cn("flex min-h-8 grow items-center space-x-2 px-2 text-sm",a),children:[e.jsx(qe,{column:s}),e.jsx("span",{children:s.column_name})]})}function sn({id:s,children:a,type:n="column"}){const{attributes:r,listeners:o,setNodeRef:l,transform:i}=t.useDraggable({id:s,data:{type:n}}),d=i?{translate:t.CSS.Translate.toString(i),transform:t.CSS.Transform.toString(i)}:void 0;return e.jsx("div",{ref:l,style:d,...o,...r,children:a})}function nn({onClick:s,column:a}){const n=t.useDndStore(u=>u.activeId),r=t.useEditorStore(u=>{var x;return(x=u.card.queryConfig)==null?void 0:x.groupByColumns}),o=t.useEditorStore(u=>{var x;return(x=u.card.queryConfig)==null?void 0:x.metricColumns}),l=t.useEditorStore(u=>{var x;return(x=u.card.queryConfig)==null?void 0:x.filterColumns});function i(u){return d(u)||c(u)||h(u)}function d(u){return r==null?void 0:r.some(x=>x.name===u.column_name)}function c(u){return o==null?void 0:o.some(x=>x.name===u.column_name)}function h(u){return l==null?void 0:l.some(x=>x.name===u.column_name)}return e.jsxs("div",{onClick:()=>s(a),className:t.cn("relative grow overflow-x-hidden overflow-y-hidden rounded-md active:border active:border-dashed active:border-muted-foreground",{"bg-muted-foreground/10":i(a)}),children:[n===a.column_name&&e.jsx(t.DragOverlay,{children:e.jsx(we,{column:a,className:"rounded-md border-2 border-dashed border-muted-foreground bg-muted shadow-md"})}),n===a.column_name&&e.jsx("div",{className:"absolute inset-0",children:n===a.column_name&&e.jsx(we,{column:a})}),e.jsx(sn,{id:a.column_name,type:"column",children:e.jsx(we,{column:a})})]})}const ke={id:"__placeholder__",role:"groupby",type:"string"},De={id:"__placeholder__",role:"groupby",type:"string"},Ie={id:"__placeholder__",role:"metric",type:"number"},Ee={name:"Filter",id:"__placeholder__",role:"filter",type:"string"},yt={id:"__placeholder__"},te="droppable-group-by",se="droppable-metrics",ne="droppable-pivot-by",be="sortable-group-by",Oe="sortable-metrics",ve="sortable-pivot-by",ze="droppable-filters",Fe="sortable-filters",Pe="sortable-order-by";function an(){const s=t.useDndStore(E=>E.insertIndex),a=t.useEditorStore(E=>{var j;return((j=E.card.queryConfig)==null?void 0:j.groupByColumns)||[]}),n=t.useEditorStore(E=>{var j;return((j=E.card.queryConfig)==null?void 0:j.metricColumns)||[]}),r=t.useEditorStore(E=>{var j;return((j=E.card.queryConfig)==null?void 0:j.filterColumns)||[]}),o=t.useEditorStore(E=>{var j;return((j=E.card.queryConfig)==null?void 0:j.orderBy)||[]}),l=t.useEditorStore(E=>{var j;return((j=E.card.queryConfig)==null?void 0:j.pivotColumns)||[]}),{setInsertIndex:i,setActiveId:d,setPreviewGroupByColumns:c,setPreviewMetricColumns:h,setPreviewFilterColumns:u,setPreviewPivotColumns:x}=t.useDndActions(),{setGroupByColumns:b,setMetricColumns:m,setFilterColumns:v,setOrderByColumns:p,setPivotByColumns:f}=t.useEditorActions(),{columns:g}=t.useDataColumns(),{formattedTableName:N}=t.useEditorAside(),S=t.useSensors(t.useSensor(t.MouseSensor,{activationConstraint:{distance:1}})),L=E=>{var B;const{active:j,over:A}=E;if(((B=j.data.current)==null?void 0:B.type)==="column"&&A){const _=A.id,G=g.find(I=>I.column_name===j.id);if(!G)return;const Q=t.isNumberDataType(G.data_type),y=t.isTextDataType(G.data_type),C=t.isDateDataType(G.data_type);if(y||C){if(a.some(V=>V.id===_)){const V=a.findIndex(z=>z.id===_);i(V);const $=a.filter(z=>z.id!==ke.id);$.splice(V,0,ke),c($)}else if(A.id===te){i(a.length);const V=[...a,ke];c(V),h(n),u(r)}}if(y||C){if(l.some(V=>V.id===_)){const V=l.findIndex(z=>z.id===_);i(V);const $=l.filter(z=>z.id!==De.id);$.splice(V,0,De),x($)}else if(A.id===ne){i(l.length);const V=[...l,De];x(V),c(a),h(n),u(r)}}if(Q||y){if(n.some(V=>V.id===_)){console.log("isOverMetricSortable",_);const V=n.findIndex(z=>z.id===_);i(V);const $=n.filter(z=>z.id!==Ie.id);$.splice(V,0,Ie),h($)}else if(A.id===se){i(n.length);const V=[...n,Ie];h(V),u(r),c(a),x(l)}}if(M(G)){if(r.some(V=>V.id===_)){const V=r.findIndex(z=>z.id===_);i(V);const $=r.filter(z=>z.id!==Ee.id);$.splice(V,0,Ee),u($)}else if(A.id===ze){i(r.length);const V=[...r,Ee];u(V),h(n),c(a),x(l)}}}else c(a),h(n),u(r),x(l)};function k(E){d(E.active.id),i(null),c(a),h(n),u(r),x(l)}function M(E){return!r.some(j=>j.name===E.column_name)}function O(E,j="SUM"){const{column_name:A,data_type:B}=E,_=[...n],G=s!==null?s:n.length,Q={...E,id:Z(A),name:A,label:me(A,j),type:B,role:"metric",aggregate:j};_.splice(G,0,Q),m(_)}function F(E){const j=t.isTextDataType(E.data_type);t.isDateDataType(E.data_type);const A=[...l],B=s!==null?s:l.length;let _;j?_={...E,id:Z(E.column_name),name:E.column_name,type:E.data_type,role:"groupby"}:_={...E,id:Z(E.column_name),name:E.column_name,type:E.data_type,role:"groupby",label:ce(E.column_name,"month"),granularity:"month"},A.splice(B,0,_),f(A)}function H(E){const j=t.isTextDataType(E.data_type);t.isDateDataType(E.data_type);const A=[...a],B=s!==null?s:a.length;let _;j?_={...E,id:Z(E.column_name),name:E.column_name,type:E.data_type,role:"groupby"}:_={...E,id:Z(E.column_name),name:E.column_name,type:E.data_type,role:"groupby",label:ce(E.column_name,"month"),granularity:"month"},A.splice(B,0,_),b(A)}function w(E){const j=[...r],A=s!==null?s:r.length,B={...E,id:Z(E.column_name),name:E.column_name,type:E.data_type,sql:t.getDefaultFilterSql(E.data_type,N,t.fmt(E.column_name)),role:"filter"};j.splice(A,0,B),v(j)}function R(E){var _,G,Q,y,C,I,V,$;const{active:j,over:A}=E,B=j.data.current;if((B==null?void 0:B.type)==="column"&&A){const z=g.find(K=>K.column_name===j.id);if(!z)return;const J=t.isNumberDataType(z.data_type),D=t.isTextDataType(z.data_type),P=t.isDateDataType(z.data_type);(D||P)&&(A.id===te||((_=A.data.current)==null?void 0:_.type)===be)&&H(z),(D||P)&&(A.id===ne||((G=A.data.current)==null?void 0:G.type)===ve)?F(z):(J||D)&&(A.id===se||((Q=A.data.current)==null?void 0:Q.type)===Oe)?(J&&O(z),D&&O(z,"COUNT")):M(z)&&(A.id===ze||((y=A.data.current)==null?void 0:y.type)===Fe)&&w(z)}if(A&&((C=A.data.current)==null?void 0:C.type)===be&&a.some(z=>z.id===j.id)){const z=a.findIndex(D=>D.id===j.id),J=a.findIndex(D=>D.id===A.id);if(z!==-1&&J!==-1&&z!==J){const D=[...a],[P]=D.splice(z,1);D.splice(J,0,P),b(D)}}if(A&&((I=A.data.current)==null?void 0:I.type)===ve&&l.some(z=>z.id===j.id)){const z=l.findIndex(D=>D.id===j.id),J=l.findIndex(D=>D.id===A.id);if(z!==-1&&J!==-1&&z!==J){const D=[...l],[P]=D.splice(z,1);D.splice(J,0,P),f(D)}}if(A&&((V=A.data.current)==null?void 0:V.type)===Oe&&n.some(z=>z.id===j.id)){const z=n.findIndex(D=>D.id===j.id),J=n.findIndex(D=>D.id===A.id);if(z!==-1&&J!==-1&&z!==J){const D=[...n],[P]=D.splice(z,1);D.splice(J,0,P),m(D)}}if(A&&(($=A.data.current)==null?void 0:$.type)===Fe&&r.some(z=>z.id===j.id)){const z=r.findIndex(D=>D.id===j.id),J=r.findIndex(D=>D.id===A.id);if(z!==-1&&J!==-1&&z!==J){const D=[...r],[P]=D.splice(z,1);D.splice(J,0,P),v(D)}}U(E),d(null),i(null),c(a),h(n),u(r),x(l)}function U(E){const{active:j,over:A}=E,B=j.data.current;if((B==null?void 0:B.type)===Pe&&A){const _=o.findIndex(Q=>ue(Q.columnId)===j.id),G=o.findIndex(Q=>ue(Q.columnId)===A.id);if(_!==-1&&G!==-1&&_!==G){const Q=[...o],[y]=Q.splice(_,1);Q.splice(G,0,y),p(Q)}}}function q(){d(null),i(null),c(a),h(n),u(r)}return{handleDragOver:L,handleDragEnd:R,handleDragStart:k,handleDragCancel:q,sensors:S}}function Z(s){return`${s}-${t.v4()}`}function me(s,a){const n=t.toTitleCase(s.replace(/_/g," "));switch(a){case"SUM":return`Sum of ${n}`;case"COUNT":return`Count of ${n}`;case"DISTINCT":return`Unique ${n}`;case"AVG":return`Average of ${n}`;case"MIN":return`Min of ${n}`;case"MAX":return`Max of ${n}`;default:return n}}function ue(s){return`${Pe}-${s}`}function ce(s,a){const n=t.toTitleCase(s.replace(/_/g," "));switch(a){case"day":return`Date of ${n}`;case"week":return`Week of ${n}`;case"month":return`Month of ${n}`;case"year":return`Year of ${n}`;default:return n}}function rn({schemaName:s,tableName:a,columns:n,status:r}){const o=t.useEditorStore(j=>j.sqlGen),l=t.useEditorStore(j=>j.isDevMode),i=t.useEditorStore(j=>j.selectedConnectionId),d=t.useEditorStore(j=>{var A,B;return(B=(A=j.card)==null?void 0:A.queryConfig)==null?void 0:B.metricColumns});t.useEditorStore(j=>{var A,B;return(B=(A=j.card)==null?void 0:A.queryConfig)==null?void 0:B.groupByColumns});const c=t.useEditorStore(j=>j.selectedDatabaseName),h=t.useEditorStore(j=>j.selectedSchemaName),u=t.useEditorStore(j=>j.selectedTableName),x=t.useEditorStore(j=>j.selectedDatamodelId),b=t.useDashboardStore(j=>j.dashboard.aiScopeTables),{addToAIScope:m,removeFromAIScope:v}=t.useDashboardActions(),{addColumnToMetricColumns:p,addColumnToGroupBy:f,setCardSql:g,setRunSql:N,setSqlGen:S,setIsShowingVisual:L}=t.useEditorActions(),{connectionType:k,modelItems:M,selectedDatamodelName:O}=t.useEditorAside();function F(j){var A;if(l){const B=t.createSqlGenConfig(j,o);S(B);const _=(A=M==null?void 0:M.find(Q=>Q.id===x))==null?void 0:A.name,G=t.getSql(B,t.fmt(s),t.fmt(a),_,k,c||"");G&&(g(G),N(!0))}if(!l){if(t.isTextDataType(j.data_type))if(d&&d.length>0){const B={...j,role:"groupby",id:Z(j.column_name),name:j.column_name,type:j.data_type};f(B)}else{const B={...j,role:"metric",id:Z(j.column_name),name:j.column_name,label:me(j.column_name,"COUNT"),type:j.data_type,aggregate:"COUNT"};p(B)}if(t.isDateDataType(j.data_type)){const B={...j,role:"groupby",id:Z(j.column_name),name:j.column_name,type:j.data_type,label:ce(j.column_name,"month"),granularity:"month"};f(B)}if(t.isNumberDataType(j.data_type)){const B={...j,role:"metric",id:Z(j.column_name),name:j.column_name,label:me(j.column_name,"SUM"),type:j.data_type,aggregate:"SUM"};p(B)}}}function H(j){j===!0&&(u||O)&&i?(m({connectionId:i,connectionType:k==="S3"||k==="API"?"DuckDb":k,databaseName:c||"",schemaName:h||"",tableName:u||"",datamodelName:t.resolveDatamodelName(O),datamodelId:x||""}),t.ue.success("Added to Assistant Scope",{position:"top-right",duration:2500,richColors:!0})):(v({connectionId:i||"",connectionType:k||"",tableName:u||"",datamodelName:t.resolveDatamodelName(O),datamodelId:x||"",databaseName:c||"",schemaName:h||""}),t.ue("Removed from Assistant Scope",{position:"top-right",duration:2e3,richColors:!0}))}function w(){const j=t.getFormattedTableNameForQuery({schemaName:s,tableName:a,modelName:O,connectionType:k,databaseName:c||""});L(!1);const A=k==="MSSQL"?`SELECT top 10 * FROM ${j}`:`SELECT * FROM ${j} LIMIT 10`;g(A),N(!0)}function R(){const j=t.getFormattedTableNameForQuery({schemaName:s,tableName:a,modelName:O,connectionType:k,databaseName:c||""});g(`SELECT COUNT(*) as count FROM ${j}`),N(!0)}function U(){return(b==null?void 0:b.find(j=>j.connectionId===i&&(j.tableName===u||j.datamodelName===O)))!==void 0}function q(j){return l?e.jsxs("div",{className:"flex grow items-center justify-between space-x-2 rounded-md px-2 py-1",onClick:()=>F(j),children:[e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(qe,{column:j}),e.jsx("span",{children:j.column_name})]}),e.jsx("div",{onClick:A=>A.stopPropagation(),className:"flex items-center justify-end",children:t.isNumberDataType(j.data_type)&&e.jsx(tn,{column:j})})]}):e.jsx(nn,{onClick:F,column:j})}function E(){return e.jsxs(e.Fragment,{children:[e.jsxs(t.Toggle,{title:`${U()?"Remove from":"Add to"} Assistant Scope`,pressed:U(),onPressedChange:H,variant:"outline",className:t.cn("h-9 px-2",{}),children:[e.jsx(t.Plus,{className:t.cn("mr-1 size-4",{"text-green-400":U(),"text-muted-foreground":!U()})}),"AI"]}),e.jsxs(t.Button,{disabled:r!=="Success",onClick:w,size:"sm",variant:"secondary",className:"flex",children:[r!=="Success"?e.jsx(ae,{className:"mr-2 h-4 w-4 animate-spin text-foreground/50"}):e.jsx(Ls,{className:"mr-2 size-4"}),"Top 10"]}),e.jsxs(t.Button,{disabled:r!=="Success",onClick:R,size:"sm",variant:"secondary",className:"w-full",children:[r!=="Success"?e.jsx(ae,{className:"mr-2 h-4 w-4 animate-spin text-foreground/50"}):e.jsx(ht,{className:"mr-2 size-4"}),"Count"]})]})}return r!=="Success"?e.jsx("div",{className:"flex grow flex-col justify-start gap-2 px-6",children:Array.from({length:3}).map((j,A)=>e.jsx(t.Skeleton,{className:"h-7 w-full"},A))}):e.jsxs("div",{className:"flex grow flex-col space-y-4 px-4",children:[l&&e.jsx("div",{className:"mx-2 flex items-center justify-center gap-2",children:E()}),e.jsxs(t.CustomScrollArea,{className:"flex-1 basis-0 overflow-y-auto px-2 py-0",children:[e.jsx("div",{className:"flex flex-col gap-1",children:n==null?void 0:n.map(j=>e.jsx("div",{className:t.cn("mr-2 cursor-pointer rounded-md text-sm transition-colors hover:bg-muted"),children:q(j)},j.column_name))}),e.jsx(t.ScrollBar,{orientation:"vertical"}),e.jsx(t.ScrollBar,{orientation:"horizontal"})]})]})}function bt({ColumnsComponent:s,type:a}){var Ue;const n=t.useEditorStore(W=>W.card),r=t.useEditorStore(W=>W.selectedConnectionId),o=t.useDashboardStore(W=>W.showFilters),l=t.useEditorStore(W=>W.selectedDatamodelId),i=t.useEditorStore(W=>W.selectedDatabaseName),d=t.useEditorStore(W=>W.selectedSchemaName),c=t.useEditorStore(W=>W.selectedTableName),h=t.useEditorStore(W=>W.isDevMode),{setSelectedTableName:u,setIsDevMode:x,setCardSql:b}=t.useEditorActions(),{connectionItems:m,modelItems:v,schemaItems:p,databaseItems:f,tableItems:g,columns:N,isConnectionsLoading:S,isModelsLoading:L,isConnectionsError:k,isModelsError:M,isDatabasesLoadingOrFetching:O,isDatabaseError:F,isSchemaLoadingOrFetching:H,isSchemaError:w,isColumnsError:R,isColumnsLoadingOrFetching:U,isTableLoadingOrFetching:q,isTableError:E,connectionType:j,isNonDbConnection:A,refetchDatabases:B,refetchModels:_,refetchSchemas:G,refetchTables:Q,refetchColumns:y,refetchConnections:C,handleConnectionChange:I,handleDatabaseChange:V,handleSchemaChange:$,handleDatamodelChange:z,handleTableChange:J,tableName:D,schemaName:P}=t.useEditorAside(),{data:K,refetch:X}=t.useDashboardCardQuery(n);function he(){return s?s(P,D,N):e.jsx(rn,{schemaName:P,tableName:D,columns:N,status:U?"Loading...":R?"Error":"Success"})}function xe(){window.location.href="mailto:support@semaphor.cloud?subject=Help&body=I need help with..."}function pe(W){W===!0?K&&(b(K.userSql),setTimeout(()=>{X()},100)):b(""),x(W)}function fe(){if(!r||j==="S3"||j==="API")return null;if(!l||l==="none")return e.jsx(ie,{refetch:B,showNone:!0,onChange:V,isError:F,isLoading:O,items:f,value:i||"",title:"Database",type:"combobox"})}function Ut(){if(r&&!A&&(!i||i==="none")&&(!l||l==="none"))return e.jsxs("div",{className:"grid grid-cols-3",children:[e.jsx("div",{className:"col-span-1 grid place-items-center",children:e.jsx(t.Separator,{})}),e.jsx("div",{className:"col-span-1 grid place-items-center",children:e.jsx(t.Label,{children:"OR"})}),e.jsx("div",{className:"col-span-1 grid place-items-center",children:e.jsx(t.Separator,{})})]})}function $t(){if(!r||j==="S3"||j==="API")return null;if(!i||i==="none")return e.jsx(ie,{refetch:_,showNone:!0,onChange:z,isError:M,isLoading:L,items:v,value:l||"",title:"Model",type:"combobox"})}function Qt(){return!r||j==="S3"||j==="API"||!i||i==="none"?null:e.jsx(ie,{refetch:G,onChange:$,isError:w,isLoading:H,items:p,value:d||"",title:"Schema",type:"combobox"})}function Jt(){function W(){let ee=!1;return j==="API"?(ee=!1,ee):((j==="S3"||r&&i&&i!=="none"&&d)&&(ee=!0),ee)}return W()?e.jsx(ie,{refetch:Q,onChange:J,isError:E,items:g,isLoading:q,value:c||"",title:"Table",type:"combobox"}):null}return e.jsxs("aside",{className:t.cn("flex h-full min-w-[310px] max-w-[310px] flex-col justify-between rounded-none",{"border-r-[1px]":!o}),children:[e.jsxs("section",{className:"space-y-3 px-6 py-4",children:[e.jsx(ie,{refetch:C,items:m,title:"Connection",value:r||"",onChange:I,isLoading:S,isError:k,type:"combobox",connectionTooltip:((Ue=m==null?void 0:m.find(W=>W.id===r))==null?void 0:Ue.type)||""}),fe(),Ut(),$t(),Qt(),Jt()]}),he(),e.jsx("div",{className:"flex items-center justify-between gap-2 px-6 py-4",children:a==="main"&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(t.Switch,{className:"data-[state=checked]:bg-muted-foreground/80",checked:h,onCheckedChange:pe,id:"dev-mode"}),e.jsx(t.Label,{htmlFor:"dev-mode",children:"Dev Mode"})]}),e.jsxs(t.Button,{onClick:xe,size:"sm",variant:"secondary",className:"group flex items-center gap-2 rounded-full",children:[e.jsx(zs,{className:"size-4"}),e.jsx("span",{className:"hidden group-hover:block",children:"Help"})]})]})})]})}function vt({sql:s,error:a,onClick:n}){const r=t.useEditorStore(c=>c.isDevMode);t.useEditorStore(c=>c.card);const{setIsDevMode:o,setCardSql:l,setRunSql:i}=t.useEditorActions();if(!s&&!a)return null;function d(){o(!r),l(s),setTimeout(()=>{i(!0)},100)}return e.jsxs(t.HoverCard,{openDelay:a?0:500,children:[e.jsx(t.HoverCardTrigger,{asChild:!0,children:e.jsx(t.Button,{variant:"link",className:"h-5 p-0",children:a?e.jsx(at,{className:"h-4 w-4 text-red-500"}):e.jsx(t.Info,{className:"h-4 w-4 text-muted-foreground"})})}),e.jsx(t.HoverCardContent,{align:"start",className:"w-full min-w-fit max-w-[700px]",children:e.jsx("div",{className:"flex justify-between space-x-4",children:e.jsxs("div",{className:"flex grow flex-col space-y-2",children:[e.jsxs(t.ScrollArea,{className:"max-h-[250px] min-h-0 overflow-scroll text-xs leading-relaxed text-foreground/80",children:[a&&a,s&&e.jsxs("div",{className:"flex flex-col space-y-1.5",children:[e.jsx("span",{className:"text-xs font-semibold",children:"Resolved SQL"}),e.jsx("div",{className:"rounded-md",children:e.jsx(t.CodeHighlighter,{code:s,language:"sql"})})]})]}),!r&&e.jsxs(t.Button,{onClick:d,variant:"secondary",size:"sm",children:[e.jsx(Cs,{className:"mr-2 h-4 w-4"}),"View in SQL Editor"]}),a&&n&&e.jsxs(t.Button,{onClick:n,size:"sm",variant:"secondary",children:[e.jsx(Ds,{className:"mr-2 h-4 w-4"}),"Debug with Assistant"]})]})})})]})}var Ct={color:void 0,size:void 0,className:void 0,style:void 0,attr:void 0},Ke=T.createContext&&T.createContext(Ct),on=["attr","size","title"];function ln(s,a){if(s==null)return{};var n=cn(s,a),r,o;if(Object.getOwnPropertySymbols){var l=Object.getOwnPropertySymbols(s);for(o=0;o<l.length;o++)r=l[o],!(a.indexOf(r)>=0)&&Object.prototype.propertyIsEnumerable.call(s,r)&&(n[r]=s[r])}return n}function cn(s,a){if(s==null)return{};var n={};for(var r in s)if(Object.prototype.hasOwnProperty.call(s,r)){if(a.indexOf(r)>=0)continue;n[r]=s[r]}return n}function Ce(){return Ce=Object.assign?Object.assign.bind():function(s){for(var a=1;a<arguments.length;a++){var n=arguments[a];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(s[r]=n[r])}return s},Ce.apply(this,arguments)}function Ye(s,a){var n=Object.keys(s);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(s);a&&(r=r.filter(function(o){return Object.getOwnPropertyDescriptor(s,o).enumerable})),n.push.apply(n,r)}return n}function Se(s){for(var a=1;a<arguments.length;a++){var n=arguments[a]!=null?arguments[a]:{};a%2?Ye(Object(n),!0).forEach(function(r){dn(s,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(s,Object.getOwnPropertyDescriptors(n)):Ye(Object(n)).forEach(function(r){Object.defineProperty(s,r,Object.getOwnPropertyDescriptor(n,r))})}return s}function dn(s,a,n){return a=un(a),a in s?Object.defineProperty(s,a,{value:n,enumerable:!0,configurable:!0,writable:!0}):s[a]=n,s}function un(s){var a=mn(s,"string");return typeof a=="symbol"?a:a+""}function mn(s,a){if(typeof s!="object"||!s)return s;var n=s[Symbol.toPrimitive];if(n!==void 0){var r=n.call(s,a);if(typeof r!="object")return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return(a==="string"?String:Number)(s)}function St(s){return s&&s.map((a,n)=>T.createElement(a.tag,Se({key:n},a.attr),St(a.child)))}function re(s){return a=>T.createElement(hn,Ce({attr:Se({},s.attr)},a),St(s.child))}function hn(s){var a=n=>{var{attr:r,size:o,title:l}=s,i=ln(s,on),d=o||n.size||"1em",c;return n.className&&(c=n.className),s.className&&(c=(c?c+" ":"")+s.className),T.createElement("svg",Ce({stroke:"currentColor",fill:"currentColor",strokeWidth:"0"},n.attr,r,i,{className:c,style:Se(Se({color:s.color||n.color},n.style),s.style),height:d,width:d,xmlns:"http://www.w3.org/2000/svg"}),l&&T.createElement("title",null,l),s.children)};return Ke!==void 0?T.createElement(Ke.Consumer,null,n=>a(n)):a(Ct)}function xn(s){return re({attr:{viewBox:"0 0 448 512"},child:[{tag:"path",attr:{d:"M439.8 200.5c-7.7-30.9-22.3-54.2-53.4-54.2h-40.1v47.4c0 36.8-31.2 67.8-66.8 67.8H172.7c-29.2 0-53.4 25-53.4 54.3v101.8c0 29 25.2 46 53.4 54.3 33.8 9.9 66.3 11.7 106.8 0 26.9-7.8 53.4-23.5 53.4-54.3v-40.7H226.2v-13.6h160.2c31.1 0 42.6-21.7 53.4-54.2 11.2-33.5 10.7-65.7 0-108.6zM286.2 404c11.1 0 20.1 9.1 20.1 20.3 0 11.3-9 20.4-20.1 20.4-11 0-20.1-9.2-20.1-20.4.1-11.3 9.1-20.3 20.1-20.3zM167.8 248.1h106.8c29.7 0 53.4-24.5 53.4-54.3V91.9c0-29-24.4-50.7-53.4-55.6-35.8-5.9-74.7-5.6-106.8.1-45.2 8-53.4 24.7-53.4 55.6v40.7h106.9v13.6h-147c-31.1 0-58.3 18.7-66.8 54.2-9.8 40.7-10.2 66.1 0 108.6 7.6 31.6 25.7 54.2 56.8 54.2H101v-48.8c0-35.3 30.5-66.4 66.8-66.4zm-6.7-142.6c-11.1 0-20.1-9.1-20.1-20.3.1-11.3 9-20.4 20.1-20.4 11 0 20.1 9.2 20.1 20.4s-9 20.3-20.1 20.3z"},child:[]}]})(s)}function Nt(s){const{theme:a}=t.useTheme(),n=t.useDashboardStore(p=>p.theme),r=t.useEditorStore(p=>p.frame),o=t.useEditorStore(p=>p.card),l=t.useEditorStore(p=>p.activeTabCardId),i=t.Le(),{refetch:d}=t.useDashboardCardQuery(o),{updateCardTab:c,setRunSql:h}=t.useEditorActions(),u=T.useRef(),x=T.useRef({}),b=r.cards.find(p=>p.id===l),m=T.useCallback(()=>{let p="";return s==="python"&&(p=(b==null?void 0:b.python)||t.PYTHON_DEFAULT_CODE),s==="sql"&&(p=(b==null?void 0:b.sql)||""),p},[s,b]);T.useEffect(()=>{if(l&&o.id&&o.id!==l){if(u.current&&i){const p=u.current.getModel();p&&(x.current[o.id]=p);let f=x.current[l];if(!f){const g=m();f=i.editor.createModel(g,s),x.current[l]=f}u.current.setModel(f)}c(l,o),h(!0)}},[l,o,c,i,h,s,m]),T.useEffect(()=>{if(!i)return;const p=window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light",f=n==="system"?p:n;i.editor.defineTheme("default",{base:f==="light"?"vs":"vs-dark",inherit:!0,rules:[],colors:{"editor.background":f==="light"?"#ffffff":t.hslStringToHex("240 10% 10%")}}),i.editor.setTheme("default")},[a,n,i]),T.useEffect(()=>{const p=u.current;p&&i&&o&&p.addCommand(i.KeyMod.Shift|i.KeyCode.Enter,function(){return d(),!1})},[i,d,o]);function v(p,f){if(u.current=p,!x.current[o.id]){const g=p.getModel(),N=m();x.current[o.id]=g||(f==null?void 0:f.editor.createModel(N,s))||p.getModel()}p.setModel(x.current[o.id])}return{handleEditorDidMount:v}}function pn(){const s=t.useEditorStore(i=>i.card.sql),a=t.useEditorStore(i=>i.sqlGen),{setCardSql:n,setSqlGen:r}=t.useEditorActions(),{handleEditorDidMount:o}=Nt("sql");function l(i){n(i),t.isObjectEmpty(a)||r({})}return e.jsxs("div",{className:"relative h-full w-full",children:[!s&&e.jsx("div",{className:"pointer-events-none absolute left-[65px] top-3 z-10 font-mono text-sm text-muted-foreground",children:"Write your SQL here"}),e.jsx(t.Ft,{theme:"default",className:"pt-3",onChange:l,value:s||"",options:{minimap:{enabled:!1},wordWrap:"on",scrollbar:{verticalScrollbarSize:0,horizontalScrollbarSize:0},fontSize:13,renderLineHighlight:"none"},defaultLanguage:"sql",onMount:o})]})}function fn(){const s=t.useEditorStore(o=>o.card.python),{setCardPython:a}=t.useEditorActions(),{handleEditorDidMount:n}=Nt("python");function r(o){a(o)}return e.jsx(t.Ft,{className:"pt-3",theme:"default",onChange:r,value:s||t.PYTHON_DEFAULT_CODE,options:{minimap:{enabled:!1},wordWrap:"on",scrollbar:{verticalScrollbarSize:0,horizontalScrollbarSize:0},fontSize:13,renderLineHighlight:"none"},defaultLanguage:"python",onMount:n})}function gn({jsonString:s}){return e.jsx(t.Ft,{theme:"default",defaultLanguage:"json",className:"mt-1 min-h-[220px]",value:s,options:{readOnly:!0,minimap:{enabled:!1},lineNumbers:"off",glyphMargin:!1,wordWrap:"on",scrollbar:{verticalScrollbarSize:0,horizontalScrollbarSize:0},fontSize:12,renderLineHighlight:"none"}})}function wt(s){const[a,n]=T.useState(""),[r,o]=T.useState(null),{authToken:l}=t.useSemaphorContext(),i=t.useEditorStore(D=>{var P;return(P=D==null?void 0:D.card)==null?void 0:P.sql}),d=t.useEditorStore(D=>{var P;return(P=D==null?void 0:D.card)==null?void 0:P.python}),{setCardPython:c,setCardSql:h,setRunSql:u,switchCardType:x}=t.useEditorActions(),b=t.useEditorStore(D=>D.currentAssitantScope)||[],m=t.useEditorStore(D=>D.userInputForAI),v=t.useEditorStore(D=>D.triggerAIRun),p=t.useEditorStore(D=>D.selectedDatabaseName),f=t.useEditorStore(D=>D.selectedTableName),g=t.useEditorStore(D=>D.selectedConnectionId),N=t.useEditorStore(D=>D.selectedSchemaName),S=t.useDashboardStore(D=>D.dashboard.aiScopeTables),{setTriggerAIRun:L,setCurrentAssitantScope:k}=t.useEditorActions(),{selectedDatamodelName:M,connectionType:O,selectedDatamodelId:F}=t.useEditorAside(),{messages:H,setMessages:w,reload:R,error:U,append:q,input:E,setInput:j,status:A,handleInputChange:B,handleSubmit:_,stop:G}=t.useChat({api:"https://semaphor.cloud/api/v1/assistant",headers:{Authorization:`Bearer ${l==null?void 0:l.accessToken}`},body:{random:Math.random(),assistantId:"editor-assistant"},maxSteps:10,onError:D=>{console.log("on error",D)},onToolCall:Q,onFinish(D,P){y(P.usage),n(""),P.finishReason==="stop"&&n("")}});T.useEffect(()=>{v&&m&&(B({target:{value:m}}),setTimeout(()=>{_(),L(!1)},100))},[v,_,m,L,B]);async function Q({toolCall:D}){if(["createChartFromSql","createForecast"].includes(D.toolName)){const P=D.args.sql,K=D.args.python,X=D.args.chartType;return x(X),h(P),c(K),u(!0),{status:"success",message:"Let the user know that chart is created"}}else if(D.toolName==="getTableColumns")n("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 n("Getting table scope..."),$(),{status:"success",tables:b};n("Analyzing...")}}function y(D){o(P=>P?{promptTokens:P.promptTokens+D.promptTokens,completionTokens:P.completionTokens+D.completionTokens,totalTokens:P.totalTokens+D.totalTokens}:D)}function C(D){const P=t.removeFromScopeArray(b,D);I(P)}function I(D){const P=t.sanitizeAIScope(D);k(P),w(K=>[...K,{id:crypto.randomUUID(),role:"system",content:`Current scope of tables | ${JSON.stringify(P)}`}])}function V(){const D={databaseName:p||"",schemaName:N||"",tableName:f||"",datamodelId:F||"",datamodelName:t.resolveDatamodelName(M),connectionId:g||"",connectionType:O||""},P=t.dedup([...b,D]);I(P)}function $(){const D={databaseName:p||"",schemaName:N||"",tableName:f||"",datamodelName:t.resolveDatamodelName(M),connectionId:g||"",connectionType:O||"",datamodelId:F||""};if(!t.isInAiScopeArray([...S||[],...b],D)||b.length===0){const K=t.dedup([...S||[],...b,D]).filter(X=>X.connectionId===D.connectionId);I(K)}}const z=!["ready","error"].includes(A),J=t.getErrorMessage(U);return{messages:H,setMessages:w,reload:R,append:q,input:E,setInput:j,isLoading:z,handleSetAIScope:$,handleAddCurrentTableToScope:V,removeFromCurrentSelections:C,currentAssitantScope:b,setCurrentAssitantScope:k,handleInputChange:B,handleSubmit:_,stop:G,chatStatus:A,toolStatus:a,llmUsage:r,onFinish:s,errorMessage:J}}function jn(s){const a=s.toUpperCase().indexOf("WHERE"),n=s.toUpperCase().indexOf("GROUP BY"),r=s.toUpperCase().indexOf("LIMIT"),o=s.toUpperCase().indexOf("ORDER BY");let l=s.length;if(o!==-1&&(l=o),r!==-1&&r<l&&(l=r),a!==-1){const i=s.substring(0,a),d=s.substring(a);return`${i} {{ filters | where }} AND ${d.substring(6)}`}else if(n!==-1){const i=s.substring(0,n),d=s.substring(n);return`${i} {{ filters | where }} ${d}`}else{const i=s.substring(0,l),d=s.substring(l);return console.log("beforeClause",i),console.log("afterClause",d),d?`${i} {{ filters | where }} ${d}`:`${i.replace(/;$/,"")} {{ filters | where }}`}}function kt({variant:s="secondary"}){const{setCardSql:a}=t.useEditorActions(),n=t.useEditorStore(m=>m.frame),r=t.useEditorStore(m=>m.card),o=t.useEditorStore(m=>m.selectedSchemaName),l=t.useEditorStore(m=>m.selectedDatamodelId),i=t.useEditorStore(m=>m.selectedDatabaseName),d=t.useEditorStore(m=>m.selectedTableName),c=t.useEditorStore(m=>m.selectedConnectionId),h=t.useEditorStore(m=>m.isShowingVisual),u=r.sql,x=t.useEditorStore(m=>m.onSave);function b(){let m=u;u&&!u.includes("{{")&&(m=jn(u),a(m));const v={...r,lastSelectedSchema:o,lastSelectedDatamodelId:l,lastSelectedDatabase:i,lastSelectedTable:d,connectionId:c,type:h?r.type:"table",sql:m,customCfg:h?r.customCfg:null},p=n.cards.map(g=>g.id===r.id?v:g),f={...n,cards:p,activeCardId:yn(p,n.activeCardId)};x==null||x(f)}return e.jsxs(t.Button,{onClick:b,size:"sm",variant:s,children:[e.jsx(t.Check,{className:"mr-2 size-4 font-bold"}),"Accept"]})}function Dt(){const{setTempQueryData:s,setSqlGen:a}=t.useEditorActions(),n=t.useQueryClient(),r=t.useEditorStore(c=>c.tempQueryData),o=t.useEditorStore(c=>c.onClose),l=t.useEditorStore(c=>c.card),{queryKey:i}=t.useDashboardCardQuery(l);function d(){if(r){const{queryKey:c,queryData:h}=r;c&&h&&n.setQueryData(c,h)}a({}),o==null||o()}return e.jsxs(t.Button,{onClick:d,size:"sm",variant:"secondary",children:[e.jsx(t.X,{className:"mr-2 size-4"}),"Close"]})}function It(){const{setTempQueryData:s}=t.useEditorActions(),a=t.useQueryClient(),n=t.useEditorStore(m=>m.tempQueryData),r=t.useEditorStore(m=>m.card),{queryKey:o}=t.useDashboardCardQuery(r),{setCardSql:l,setSqlGen:i,setCardPython:d,setCardCustomCfg:c,setCardPreferences:h,setCardType:u,clearQueryConfig:x}=t.useEditorActions();function b(){const m=a.getQueryData(o);n!=null&&n.queryData||s({queryKey:o,queryData:m}),a.setQueryData(o,null),a.removeQueries({queryKey:o,exact:!0}),l(""),i({}),x(),d(""),c(""),h({})}return e.jsxs(t.Button,{onClick:b,className:"",size:"sm",variant:"secondary",children:[e.jsx(bs,{className:"mr-2 size-4"}),"Clear"]})}function yn(s,a){if(s.length===0)return"";if(a){const n=s.find(r=>r.id===a);if(n){const r=n.tabTitle;if(r=="All__Header")return s[0].id;if(r&&r.endsWith("__Header")){const l=r.split("__")[0],i=s.find(d=>d.tabTitle===l);return i?i.id:s[0].id}return a}}return s[0].id}function bn(){const s=t.useQueryClient(),[a,n]=T.useState(!1),[r,o]=T.useState(!1);t.useEditorStore(y=>y.frame);const l=t.useEditorStore(y=>y.card);t.useEditorStore(y=>y.isShowingVisual),t.useEditorStore(y=>y.selectedConnectionId),t.useEditorStore(y=>y.tempQueryData),t.useEditorStore(y=>y.selectedDatabaseName),t.useEditorStore(y=>y.selectedDatamodelId),t.useEditorStore(y=>y.selectedSchemaName);const i=t.useEditorStore(y=>y.showAIDialog);t.useEditorStore(y=>y.selectedTableName);const d=t.useEditorStore(y=>{var C;return(C=y==null?void 0:y.card)==null?void 0:C.sql}),c=t.useEditorStore(y=>{var C;return(C=y==null?void 0:y.card)==null?void 0:C.python}),{sheetFilterValues:h}=t.useSheetFilterValues(),{setCardCustomCfg:u,setQueryResultColumns:x,setCardSql:b,setTempQueryData:m,setPythonStdOut:v,setCardPreferences:p,setCardType:f,setCardPython:g,runAssistant:N,setShowAIDialog:S}=t.useEditorActions();t.useEditorStore(y=>y.onSave),t.useEditorStore(y=>y.onClose),t.useEditorStore(y=>y.actions.setSqlGen);const L=t.useEditorStore(y=>y.runSql),k=t.useEditorStore(y=>y.actions.setRunSql),M=t.useEditorStore(y=>y.actions.setIsSqlRunning),{data:O,isLoading:F,isFetching:H,isSuccess:w,isError:R,error:U,queryKey:q,refetch:E,errorMessage:j}=t.useDashboardCardQuery(l),{handleSetAIScope:A}=wt();T.useEffect(()=>{if(O&&(O.rowLimitExceeded&&t.ue.error("Row limit (10,000) exceeded. Refine your query.",{position:"top-center",richColors:!0}),v((O==null?void 0:O.output)||""),O.records.length>0)){const{dimensionKeys:y}=t.getKeys(O.records);x(y)}},[O,x,v]),T.useEffect(()=>{(F||H)&&M(!0),(R||w)&&M(!1),R&&(x([]),v(""))},[F,H,O,v,R,w,M,x,U]),T.useEffect(()=>{L&&(s.getQueryData(q)||E(),k(!1))},[L,E,k,q,s]);async function B(){const y=`Can you help me debug this query in the current table scope?
356
+ */const Us=t.createLucideIcon("Type",[["polyline",{points:"4 7 4 4 20 4 20 7",key:"1nosan"}],["line",{x1:"9",x2:"15",y1:"20",y2:"20",key:"swin9y"}],["line",{x1:"12",x2:"12",y1:"4",y2:"20",key:"1tx1rr"}]]);function _e(s){var a;return{...s,sheets:(a=s==null?void 0:s.sheets)==null?void 0:a.map(n=>{var r;return{...n,frames:(r=n.frames)==null?void 0:r.map(o=>{var l;return{...o,cards:(l=o.cards)==null?void 0:l.map(i=>pt(i))}})}})}}function pt(s){return{...s,customCfg:$s(s.customCfg),data:[]}}function $s(s){var a,n;return s?{...s,data:{...s==null?void 0:s.data,labels:[],datasets:(n=(a=s==null?void 0:s.data)==null?void 0:a.datasets)==null?void 0:n.map(r=>({...r,data:[]}))}}:null}async function Qs(s,a,n,r){if(!r)return null;const o=JSON.stringify(a);return await t.postRequest("https://semaphor.cloud/api/v1/lens",r,{name:s,template:o,filterValues:n,operation:"create"})}async function Le(s,a){if(!a)return null;const{id:n,template:r,filterValues:o,isDefault:l,shared:i}=s;return await t.postRequest("https://semaphor.cloud/api/v1/lens",a,{lensId:n,template:r,filterValues:o,isDefault:l,shared:i,operation:"update"})}async function Js(s,a){return a?await t.postRequest("https://semaphor.cloud/api/v1/lens",a,{operation:"delete",lensId:s}):null}function Ws(){const[s,a]=T.useState(""),[n,r]=T.useState(!1),o=t.useDashboardStore(p=>p.lenses),{setLenses:l,setSelectedLensId:i}=t.useDashboardActions(),[d,c]=T.useState(!1),[h,u]=T.useState(!1),x=t.useDashboardStore(p=>p.dashboard),b=t.useDashboardStore(p=>p.filterValues),{authToken:m}=t.useSemaphorContext();async function v(){c(!0);const p=_e(x),f=await Qs(s,p,b,m==null?void 0:m.accessToken);f&&(l([...o||[],f]),i(f.id),u(!1)),c(!1)}return e.jsxs(t.Dialog,{open:h,onOpenChange:u,children:[e.jsx(t.DialogTrigger,{asChild:!0,children:e.jsxs(t.Button,{variant:"secondary",className:"h-7 p-2",size:"sm",children:[e.jsx(t.Plus,{className:"mr-2 h-4 w-4"}),"Lens"]})}),e.jsxs(t.DialogContent,{className:"sm:max-w-[425px]",children:[e.jsxs(t.DialogHeader,{children:[e.jsx(t.DialogTitle,{children:"Create Lens"}),e.jsx(t.DialogDescription,{children:"Lenses are private by default and are only visible to you."})]}),e.jsx("div",{className:"grid gap-4 py-4",children:e.jsxs("div",{className:"grid grid-cols-8 items-center gap-4",children:[e.jsx(t.Label,{className:"text-right",children:"Name"}),e.jsx(t.Input,{value:s,onChange:p=>{a(p.target.value)},id:"name",className:"col-span-7 focus-visible:ring-0 focus-visible:ring-ring focus-visible:ring-offset-0"})]})}),n&&e.jsx("p",{className:"text-sm",children:"The lens name already exists. Use a differnet name."}),e.jsx(t.DialogFooter,{children:e.jsx(t.Button,{size:"sm",variant:"outline",type:"submit",onClick:v,disabled:d,children:d?"Creating...":"Add"})})]})]})}function Ks(){const[s,a]=T.useState(!1),n=t.useDashboardStore(u=>u.lenses),r=t.useDashboardStore(u=>u.selectedLensId),{setLenses:o,setSelectedLensId:l}=t.useDashboardActions(),{authToken:i}=t.useSemaphorContext();async function d(u){l(u)}async function c(u){if(await Js(u,i==null?void 0:i.accessToken)){const b=n==null?void 0:n.filter(m=>m.id!==u);o(b||[]),l("original")}}async function h(u){const x=n==null?void 0:n.map(v=>v.id===u.id?{...v,isDefault:!u.isDefault}:{...v,isDefault:!1});o(x||[]);const b={...u,isDefault:!u.isDefault};await Le(b,i==null?void 0:i.accessToken);const m=n==null?void 0:n.find(v=>v.isDefault);if(m&&m.id!==u.id){const v={...m,isDefault:!1};await Le(v,i==null?void 0:i.accessToken)}}return e.jsxs(t.DropdownMenu,{open:s,onOpenChange:a,children:[e.jsx(t.DropdownMenuTrigger,{asChild:!0,children:e.jsx(t.IconButton,{tooltip:"Lenses",className:"h-7 p-2",children:e.jsx(ws,{className:"h-4 w-4"})})}),e.jsxs(t.DropdownMenuContent,{align:"end",className:"w-60",children:[e.jsx(t.DropdownMenuLabel,{className:"px-3",children:"Lenses"}),e.jsx(t.DropdownMenuSeparator,{}),e.jsxs(t.DropdownMenuRadioGroup,{value:r,onValueChange:d,children:[e.jsx(t.DropdownMenuRadioItem,{value:"original",children:"Original"}),n==null?void 0:n.map(u=>e.jsxs(t.DropdownMenuRadioItem,{className:"group flex justify-between gap-2",value:u.id,children:[e.jsx("p",{children:u.name}),e.jsxs("span",{className:"flex items-center gap-3",children:[e.jsx(Is,{onClick:x=>{x.preventDefault(),h(u)},className:t.cn("size-3.5 text-muted-foreground hover:cursor-pointer hover:text-foreground group-hover:visible",{invisible:!u.isDefault,"text-green-500":u.isDefault}),strokeWidth:1.5}),e.jsx(t.Cross2Icon,{onClick:x=>{x.preventDefault(),c(u.id)},className:"invisible size-3.5 text-muted-foreground hover:cursor-pointer hover:text-foreground group-hover:visible",strokeWidth:1.5})]})]},u.id))]})]})]})}function ft(){var l;const s=t.useDashboardStore.getState().authToken,a=t.useDashboardStore.getState().theme,n=t.useDashboardStore.getState().filterValues,r=(l=t.useDashboardStore.getState().dashboard)==null?void 0:l.title,o=t.useDashboardStore.getState().selectedSheetId;return{authToken:s,theme:a||"light",filterValues:n,dashboardTitle:r||"",selectedSheetId:o||""}}async function gt(){const s=t.useDashboardStore.getState().isDownloadingPdf,{authToken:a,theme:n,filterValues:r,dashboardTitle:o,selectedSheetId:l}=ft();if(s)return;const i=new URLSearchParams;i.set("token",(a==null?void 0:a.accessToken)||""),i.set("theme",n),i.set("filterValues",JSON.stringify(r)),i.set("selectedSheetId",l||"");const d=`https://semaphor.cloud/api/v1/generate-pdf?params=${encodeURIComponent(i.toString())}`;t.useDashboardStore.setState({isDownloadingPdf:!0});const u=(await(await fetch(d,{method:"GET",headers:{Authorization:`Bearer ${a==null?void 0:a.accessToken}`}})).json()).url,x=document.createElement("a");x.href=u;const b=`${o}-${new Date().toISOString()}.pdf`;x.download=b,x.click(),t.useDashboardStore.setState({isDownloadingPdf:!1})}function Ys({iconClassName:s}){const{authToken:a}=t.useSemaphorContext();t.useDashboardStore(o=>{var l;return(l=o.dashboard)==null?void 0:l.title}),t.useDashboardStore(o=>o.theme),t.useDashboardStore(o=>o.filterValues);const n=t.useDashboardStore(o=>o.isDownloadingPdf);async function r(){await gt()}return e.jsx(t.IconButton,{tooltip:"Download PDF",className:"h-7 p-2",onClick:r,children:n?e.jsx(ae,{className:t.cn("size-3.5 animate-spin",s)}):e.jsx(t.Download,{className:t.cn("size-4",s)})})}function Y({defaultValue:s,label:a,options:n,value:r,onValueChange:o,className:l,icon:i,showPlaceholderLabel:d=!0}){return e.jsxs(t.Select,{defaultValue:s,value:r,onValueChange:o,children:[e.jsx(t.SelectTrigger,{className:t.cn("w-full focus:ring-0 focus:ring-offset-0",l),children:e.jsxs("div",{className:"flex items-center gap-2",children:[i&&e.jsx("span",{children:i}),d&&e.jsx(t.SelectValue,{placeholder:a})]})}),e.jsx(t.SelectContent,{children:e.jsxs(t.SelectGroup,{children:[e.jsx(t.SelectLabel,{children:a}),n.map(c=>e.jsx(t.SelectItem,{value:c.value,children:c.label},c.value))]})})]})}const Je=[{value:"daily",label:"Daily"},{value:"weekly",label:"Weekly"},{value:"biweekly",label:"Bi-Weekly"},{value:"monthly",label:"Monthly"}];function jt({triggerButtonClassName:s}){const{data:a,handleScheduleSubscription:n,handleDeleteSubscription:r,status:o,error:l,isDeleting:i}=Zs(),[d,c]=T.useState(""),[h,u]=T.useState(Je[0].value),[x,b]=T.useState("06:00"),[m,v]=T.useState("");return e.jsx(t.TooltipProvider,{delayDuration:0,children:e.jsxs(t.Popover,{children:[e.jsx(t.PopoverTrigger,{asChild:!0,children:e.jsx(t.IconButton,{tooltip:"Schedule Dashboard",className:t.cn("h-7 p-2",s),children:e.jsx(xs,{className:"size-4"})})}),e.jsx(t.PopoverContent,{align:"end",className:"w-80",children:e.jsxs("div",{className:"grid gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("h4",{className:"font-medium leading-none",children:"Schedule Subscription"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Subscribe to receive dashboard via email"})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsxs("div",{className:"grid grid-cols-3 items-center gap-4",children:[e.jsx(t.Label,{htmlFor:"email",children:"Email"}),e.jsx(t.Input,{id:"email",value:d,onChange:p=>c(p.target.value),className:`col-span-2 h-8 ${t.removeRing}`})]}),e.jsxs("div",{className:"grid grid-cols-3 items-center gap-4",children:[e.jsx(t.Label,{htmlFor:"subject",children:"Subject"}),e.jsx(t.Input,{id:"subject",placeholder:"Monthly Sales Report",value:m,onChange:p=>{v(p.target.value.replace(/[^a-zA-Z0-9\s-_]/g,""))},className:`col-span-2 h-8 ${t.removeRing}`})]}),e.jsxs("div",{className:"grid grid-cols-3 items-center gap-4",children:[e.jsx(t.Label,{htmlFor:"frequency",children:"Frequency"}),e.jsx(Y,{className:"col-span-2 h-8",label:"Select Frequency",options:Je,value:h,onValueChange:p=>u(p)})]}),e.jsxs("div",{className:"grid grid-cols-3 items-center gap-4",children:[e.jsx(t.Label,{htmlFor:"time",children:"Time"}),e.jsx(t.Input,{id:"time",type:"time",value:x,onChange:p=>b(p.target.value),className:`col-span-2 h-8 ${t.removeRing}`})]}),e.jsx("div",{className:"mt-2 flex justify-end",children:e.jsxs(t.Button,{onClick:async()=>{await n({email:d,frequency:h,time:x,subject:m}),b("00:00"),c(""),v("")},className:"h-8 p-2",disabled:o==="loading"||!d,children:[o==="loading"&&e.jsx(ae,{className:"mr-2 size-4 animate-spin"}),o==="success"&&e.jsx(t.Check,{className:"mr-2 size-4"}),o==="error"&&e.jsxs(t.Tooltip,{children:[e.jsx(t.TooltipTrigger,{children:e.jsx(at,{className:"mr-2 size-4 text-destructive"})}),e.jsx(t.TooltipContent,{children:e.jsx("p",{children:l})})]}),"Schedule"]})}),a&&a.length>0&&e.jsxs("div",{className:"space-y-4",children:[e.jsx(t.Separator,{className:"my-2"}),e.jsx("div",{className:"space-y-2",children:e.jsxs("div",{className:"flex items-start justify-between",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("h4",{className:"font-medium leading-none",children:"Subscriptions"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Active email subscriptions"})]}),t.isDevEnv]})}),e.jsx("div",{className:"grid gap-2",children:a==null?void 0:a.map(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:[t.titleCase(p.frequency)," "]}),e.jsx(t.Label,{children:p.time})]})}),e.jsxs("div",{className:"col-span-2 flex items-center justify-end gap-4",children:[e.jsx(We,{tooltip:`Next Run: ${new Date(p.nextRun).toLocaleString()} ${p.timezone}`,children:e.jsx(hs,{className:"size-3.5"})}),e.jsx(We,{tooltip:`${p.endUserEmail}`,children:e.jsx(Os,{className:"size-3.5"})}),i===p.id?e.jsx(ae,{className:"size-3.5 animate-spin"}):e.jsx(Gs,{onClick:()=>r(p.id),className:"size-3.5 cursor-pointer"})]})]},p.id))})]})]})]})})]})})}const We=({children:s,tooltip:a})=>e.jsx(t.TooltipProvider,{delayDuration:0,children:e.jsxs(t.Tooltip,{children:[e.jsx(t.TooltipTrigger,{asChild:!0,children:s}),e.jsx(t.TooltipContent,{children:a})]})});function Zs(){const[s,a]=T.useState("idle"),[n,r]=T.useState(""),[o,l]=T.useState(null),i=t.useDashboardStore(S=>S.authToken),d=t.useDashboardStore(S=>S.dashboard.id),c=t.useDashboardStore(S=>S.dashboard.title),{endUserId:h}=t.getTenantAndEndUserId((i==null?void 0:i.accessToken)||""),u="https://semaphor.cloud/api/v1/subscriptions/get",x={dashboardId:d,endUserId:h},{data:b,isLoading:m,isError:v,isFetching:p,refetch:f}=t.useQuery({queryKey:["subscriptions",d,h],queryFn:()=>t.getRequest(u,(i==null?void 0:i.accessToken)||"",x),enabled:!!(i!=null&&i.accessToken)&&!!d&&!!h});async function g({email:S,subject:L,frequency:k,time:M}){const{authToken:O,...F}=ft(),H=Intl.DateTimeFormat().resolvedOptions().timeZone,w={email:S,frequency:k,time:M,timezone:H,endUserId:h,endUserEmail:S,subject:L||c||"Scheduled Dashboard",dashboardId:d,dashboardParams:F};a("loading");const R="https://semaphor.cloud/api/v1/subscriptions/create";try{const U=await t.postRequestRegular(R,(O==null?void 0:O.accessToken)||"",{...w});a("success"),r(""),f(),setTimeout(()=>{a("idle")},2e3)}catch(U){console.error(U),a("error"),r(U.message)}}async function N(S){const L="https://semaphor.cloud/api/v1/subscriptions/delete";l(S);try{await t.postRequestRegular(L,(i==null?void 0:i.accessToken)||"",{id:S}),f(),setTimeout(()=>{l(null)},2e3)}catch(k){console.error(k),l(null),a("error"),r(k.message)}}return{data:b,isLoading:m,isFetching:p,isError:v,isDeleting:o,refetch:f,handleScheduleSubscription:g,handleDeleteSubscription:N,status:s,error:n}}function Xs(){const{authToken:s}=t.useSemaphorContext();t.useDashboardStore(w=>w.theme);const a=t.useDashboardStore(w=>w.lenses),n=t.useDashboardStore(w=>w.selectedLensId),r=a==null?void 0:a.find(w=>w.id===n),o=t.useDashboardStore(w=>w.dashboard);t.useDashboardStore(w=>w.selectedSheetId);const l=t.useDashboardStore(w=>w.isDashboardEditing),i=t.useEditorStore(w=>w.selectedConnectionId),[d,c]=T.useState(!1),h=t.useDashboardStore(w=>w.filterValues),u=t.useDashboardStore(w=>w.isVisualEditing),x=t.useDashboardStore(w=>w.showFilters);t.useDashboardStore(w=>w.showDashboardJSON);const b=t.useDashboardStore(w=>w.onSaveFunction),m=t.useDashboardStore(w=>w.actions.setShowFilters),{addFrame:v,setSelectedFrameId:p}=t.useDashboardStore(w=>w.actions),{getSelectedSheet:f,setIsDashboardEditing:g,setShowDashboardJSON:N}=t.useDashboardStore(w=>w.actions),S=f(),{tenantId:L,endUserId:k}=T.useMemo(()=>t.getTenantAndEndUserId(s==null?void 0:s.accessToken),[s==null?void 0:s.accessToken]),M=T.useMemo(()=>L||k,[L,k]),O=()=>{if(!l||!S)return;const w={connectionId:i,id:t.v4(),title:"Title",preferences:{onClickFilter:[{columnIndex:0,expression:""}]},type:"bar",sql:"",data:[]},R={id:t.v4(),cards:[w],activeCardId:w.id};v(S.id,R),p(R.id)},F=()=>{g(!0)};async function H(){if(c(!0),!n||!r)return;const w=_e(o),R=JSON.stringify(w),U={...r,template:R,filterValues:h};await Le(U,s==null?void 0:s.accessToken),t.ue.success("Lens saved"),b==null||b(w),c(!1)}return u?null:e.jsxs("div",{className:"flex items-center justify-between gap-2 border-b py-1 pl-3 pr-2",role:"dashboard-controls",children:[!u&&e.jsx("div",{className:"flex items-center gap-3",children:e.jsx(t.Label,{children:r==null?void 0:r.name})}),e.jsxs("div",{className:"flex gap-2",children:[!1,!u&&e.jsx(Ys,{}),!u&&e.jsx(jt,{}),l&&!u&&M&&e.jsx(Ws,{}),!u&&M&&e.jsx(Ks,{}),l&&!u&&e.jsxs(t.Button,{variant:"secondary",className:"h-7 p-2",size:"sm",disabled:!l,onClick:O,children:[e.jsx(t.Plus,{className:"mr-2 h-4 w-4"}),"Frame"]}),!l&&e.jsx(t.Button,{variant:"ghost",className:"h-7 p-2",onClick:F,size:"sm",children:e.jsx(t.Pencil,{className:"h-4 w-4"})}),l&&!u&&e.jsx(t.IconButton,{className:"h-7 p-2",onClick:()=>{g(!1),N(!1)},children:e.jsx(t.Cross2Icon,{className:"h-4 w-4"})}),l&&!u&&M&&e.jsx(t.Button,{className:"h-7 p-2",variant:"ghost",disabled:d,onClick:H,size:"sm",children:e.jsx(Vs,{className:"h-4 w-4"})}),!x&&!u&&l&&e.jsx(t.Button,{className:"h-7 p-2",variant:"ghost",onClick:()=>m(!0),size:"sm",children:e.jsx(it,{className:"h-4 w-4"})}),!u&&l&&!1,!u&&!1]})]})}function en({name:s,items:a,value:n,onChange:r,isLoading:o,isError:l,refetch:i,className:d,icon:c,showNone:h=!1}){const u=le.useRef(null),[x,b]=le.useState(!1),[m,v]=le.useState("100%"),p=h?[...a||[],{id:"none",name:"None"}]:a;le.useLayoutEffect(()=>{u.current&&v(u.current.offsetWidth)},[]);function f(){var N;return o?"Loading...":l?"Error":n?(N=a==null?void 0:a.find(S=>S.id===n))==null?void 0:N.name:`Select ${s}`}function g(N,S){r(S),b(!1)}return e.jsxs(t.Popover,{open:x,onOpenChange:b,children:[e.jsx(t.PopoverTrigger,{asChild:!0,children:e.jsxs(t.Button,{ref:u,variant:"outline",role:"combobox","aria-expanded":x,className:t.cn("flex h-9 w-full justify-between",d),children:[e.jsxs("div",{className:"flex items-center gap-2",children:[c&&e.jsx("div",{className:"mr-2",children:c}),e.jsx("span",{className:"max-w-[150px] overflow-hidden truncate text-ellipsis whitespace-nowrap",children:f()})]}),e.jsx(t.ChevronDown,{className:"size-4 opacity-50"})]})}),e.jsx(t.PopoverContent,{className:"w-full p-0",style:{minWidth:m},children:e.jsxs(t.Command,{children:[e.jsxs("div",{className:"flex h-9 items-center justify-between border-b pr-1",children:[e.jsx(t.CommandInput,{className:"h-9",placeholder:"Search..."}),e.jsx(t.IconButton,{className:"h-7",onClick:i,children:e.jsx(ut,{className:t.cn("size-3.5 opacity-50",o&&"animate-spin")})})]}),e.jsxs(t.CommandList,{children:[e.jsxs(t.CommandEmpty,{children:["No ",s==null?void 0:s.toLowerCase()," found."]}),e.jsx(t.CommandGroup,{children:p==null?void 0:p.map(N=>e.jsx(t.CommandItem,{className:"overflow-x-auto",value:N.name,onSelect:S=>g(S,N.id),children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(t.Check,{className:t.cn("size-4",n===N.id?"opacity-100":"opacity-0")}),e.jsx("div",{title:N.name,children:N.name})]})},N.id))})]})]})})]})}function ie({title:s,items:a,value:n,isLoading:r,isError:o,refetch:l,onChange:i,showNone:d=!1,className:c,disabled:h=!1,type:u="combobox"}){const x=r?"Loading...":o?"Error":n;function b(){if(s==="Connection")return e.jsx(Rs,{className:"size-4"});if(s==="Database")return e.jsx(js,{className:"size-4"});if(s==="Schema")return e.jsx(Fs,{className:"size-4"});if(s==="Table")return e.jsx(Ve,{className:"size-4"});if(s==="Model")return e.jsx(ds,{className:"size-4"})}function m(){return e.jsxs(t.Select,{disabled:h,value:x,onValueChange:i,children:[e.jsx(t.SelectTrigger,{className:t.cn("h-9 w-full border-muted focus:ring-1 focus:ring-offset-0",c),children:e.jsx(t.SelectValue,{placeholder:r?"Loading...":o?"Error":`Select ${s}`})}),e.jsx(t.SelectContent,{children:e.jsxs(t.SelectGroup,{children:[r?e.jsx(t.SelectLabel,{children:"Loading..."}):e.jsxs(t.SelectLabel,{className:"flex items-center justify-between gap-2",children:[s,e.jsx(ut,{className:t.cn("mr-1 size-3 cursor-pointer text-muted-foreground hover:text-foreground",r&&"animate-spin"),onClick:l})]}),e.jsxs(e.Fragment,{children:[d&&e.jsx(t.SelectItem,{value:"none",children:"None"},"none"),a&&a.map((p,f)=>e.jsx(t.SelectItem,{value:p.id,children:p.name},f))]}),(r||o)&&e.jsx(t.SelectItem,{value:x,children:x})]})})]})}function v(){return e.jsx(en,{icon:b(),items:a,value:x,onChange:i||(()=>{}),isLoading:r,isError:o,refetch:l,name:s,showNone:d})}return e.jsx(t.TooltipProvider$1,{delayDuration:0,children:e.jsx("div",{className:"flex items-center gap-2",children:u==="select"?m():v()})})}function tn({column:s}){const[a,n]=T.useState(!1),r=t.useEditorStore(p=>p.selectedTableName),o=t.useEditorStore(p=>p.selectedSchemaName),l=t.useEditorStore(p=>p.selectedDatabaseName),i=t.useEditorStore(p=>p.selectedDatamodelId),d=t.useEditorStore(p=>p.sqlGen),{modelItems:c,connectionType:h}=t.useEditorAside(),u=t.useEditorStore(p=>p.actions.setSqlGen),x=t.useEditorStore(p=>p.actions.setCardSql),b=t.useEditorStore(p=>p.actions.setRunSql);function m(p,f){var L;const g=t.createSqlGenConfig(p,d,f),N=(L=c==null?void 0:c.find(k=>k.id===i))==null?void 0:L.name;u(g);const S=t.getSql(g,t.fmt(o||""),t.fmt(r),N,h,l||"");S&&(x(S),b(!0)),n(!1)}function v(){return e.jsxs("ul",{className:"text-xs",children:[e.jsx("li",{onClick:()=>m(s,"COUNT"),className:"cursor-pointer p-1 px-3 transition-colors hover:bg-muted",children:"Count"}),e.jsx("li",{onClick:()=>m(s,"AVG"),className:"cursor-pointer p-1 px-3 transition-colors hover:bg-muted",children:"Avg"}),e.jsx("li",{onClick:()=>m(s,"SUM"),className:"cursor-pointer p-1 px-3 transition-colors hover:bg-muted",children:"Sum"}),e.jsx("li",{onClick:()=>m(s,"MAX"),className:"cursor-pointer p-1 px-3 transition-colors hover:bg-muted",children:"Max"}),e.jsx("li",{onClick:()=>m(s,"MIN"),className:"cursor-pointer p-1 px-3 transition-colors hover:bg-muted",children:"Min"})]})}return e.jsxs(t.HoverCard,{openDelay:0,open:a,onOpenChange:n,children:[e.jsx(t.HoverCardTrigger,{asChild:!0,children:e.jsx(t.EllipsisVertical,{className:"invisible size-3.5 cursor-pointer text-foreground/40 group-hover:visible"})}),e.jsx(t.HoverCardContent,{align:"center",className:"w-20 rounded-md p-0 shadow-none",children:v()})]})}function qe({column:s}){return e.jsxs(t.Tooltip,{children:[e.jsx(t.TooltipTrigger$1,{className:"shrink-0",asChild:!0,children:t.isTextDataType(s.data_type)?e.jsx(t.TextIcon,{className:"size-3 text-muted-foreground"}):t.isNumberDataType(s.data_type)?e.jsx(lt,{className:"size-3 text-muted-foreground"}):t.isDateDataType(s.data_type)?e.jsx(t.Calendar,{className:"size-3 text-muted-foreground"}):t.isBooleanDataType(s.data_type)?e.jsx(Hs,{className:"size-3 text-muted-foreground"}):s.data_type.startsWith("json")?e.jsx(us,{className:"size-3 text-muted-foreground"}):e.jsx(t.QuestionMarkIcon,{className:"size-3 text-muted-foreground"})}),e.jsx(t.TooltipContent,{children:e.jsx("p",{className:"text-xs",children:s.data_type})})]})}function we({column:s,className:a}){return e.jsxs("div",{className:t.cn("flex min-h-8 grow items-center space-x-2 px-2 text-sm",a),children:[e.jsx(qe,{column:s}),e.jsx("span",{children:s.column_name})]})}function sn({id:s,children:a,type:n="column"}){const{attributes:r,listeners:o,setNodeRef:l,transform:i}=t.useDraggable({id:s,data:{type:n}}),d=i?{translate:t.CSS.Translate.toString(i),transform:t.CSS.Transform.toString(i)}:void 0;return e.jsx("div",{ref:l,style:d,...o,...r,children:a})}function nn({onClick:s,column:a}){const n=t.useDndStore(u=>u.activeId),r=t.useEditorStore(u=>{var x;return(x=u.card.queryConfig)==null?void 0:x.groupByColumns}),o=t.useEditorStore(u=>{var x;return(x=u.card.queryConfig)==null?void 0:x.metricColumns}),l=t.useEditorStore(u=>{var x;return(x=u.card.queryConfig)==null?void 0:x.filterColumns});function i(u){return d(u)||c(u)||h(u)}function d(u){return r==null?void 0:r.some(x=>x.name===u.column_name)}function c(u){return o==null?void 0:o.some(x=>x.name===u.column_name)}function h(u){return l==null?void 0:l.some(x=>x.name===u.column_name)}return e.jsxs("div",{onClick:()=>s(a),className:t.cn("relative grow overflow-x-hidden overflow-y-hidden rounded-md active:border active:border-dashed active:border-muted-foreground",{"bg-muted-foreground/10":i(a)}),children:[n===a.column_name&&e.jsx(t.DragOverlay,{children:e.jsx(we,{column:a,className:"rounded-md border-2 border-dashed border-muted-foreground bg-muted shadow-md"})}),n===a.column_name&&e.jsx("div",{className:"absolute inset-0",children:n===a.column_name&&e.jsx(we,{column:a})}),e.jsx(sn,{id:a.column_name,type:"column",children:e.jsx(we,{column:a})})]})}const ke={id:"__placeholder__",role:"groupby",type:"string"},De={id:"__placeholder__",role:"groupby",type:"string"},Ie={id:"__placeholder__",role:"metric",type:"number"},Ee={name:"Filter",id:"__placeholder__",role:"filter",type:"string"},yt={id:"__placeholder__"},te="droppable-group-by",se="droppable-metrics",ne="droppable-pivot-by",be="sortable-group-by",Oe="sortable-metrics",ve="sortable-pivot-by",ze="droppable-filters",Fe="sortable-filters",Pe="sortable-order-by";function an(){const s=t.useDndStore(E=>E.insertIndex),a=t.useEditorStore(E=>{var j;return((j=E.card.queryConfig)==null?void 0:j.groupByColumns)||[]}),n=t.useEditorStore(E=>{var j;return((j=E.card.queryConfig)==null?void 0:j.metricColumns)||[]}),r=t.useEditorStore(E=>{var j;return((j=E.card.queryConfig)==null?void 0:j.filterColumns)||[]}),o=t.useEditorStore(E=>{var j;return((j=E.card.queryConfig)==null?void 0:j.orderBy)||[]}),l=t.useEditorStore(E=>{var j;return((j=E.card.queryConfig)==null?void 0:j.pivotColumns)||[]}),{setInsertIndex:i,setActiveId:d,setPreviewGroupByColumns:c,setPreviewMetricColumns:h,setPreviewFilterColumns:u,setPreviewPivotColumns:x}=t.useDndActions(),{setGroupByColumns:b,setMetricColumns:m,setFilterColumns:v,setOrderByColumns:p,setPivotByColumns:f}=t.useEditorActions(),{columns:g}=t.useDataColumns(),{formattedTableName:N}=t.useEditorAside(),S=t.useSensors(t.useSensor(t.MouseSensor,{activationConstraint:{distance:1}})),L=E=>{var B;const{active:j,over:A}=E;if(((B=j.data.current)==null?void 0:B.type)==="column"&&A){const _=A.id,G=g.find(I=>I.column_name===j.id);if(!G)return;const Q=t.isNumberDataType(G.data_type),y=t.isTextDataType(G.data_type),C=t.isDateDataType(G.data_type);if(y||C){if(a.some(V=>V.id===_)){const V=a.findIndex(z=>z.id===_);i(V);const $=a.filter(z=>z.id!==ke.id);$.splice(V,0,ke),c($)}else if(A.id===te){i(a.length);const V=[...a,ke];c(V),h(n),u(r)}}if(y||C){if(l.some(V=>V.id===_)){const V=l.findIndex(z=>z.id===_);i(V);const $=l.filter(z=>z.id!==De.id);$.splice(V,0,De),x($)}else if(A.id===ne){i(l.length);const V=[...l,De];x(V),c(a),h(n),u(r)}}if(Q||y){if(n.some(V=>V.id===_)){console.log("isOverMetricSortable",_);const V=n.findIndex(z=>z.id===_);i(V);const $=n.filter(z=>z.id!==Ie.id);$.splice(V,0,Ie),h($)}else if(A.id===se){i(n.length);const V=[...n,Ie];h(V),u(r),c(a),x(l)}}if(M(G)){if(r.some(V=>V.id===_)){const V=r.findIndex(z=>z.id===_);i(V);const $=r.filter(z=>z.id!==Ee.id);$.splice(V,0,Ee),u($)}else if(A.id===ze){i(r.length);const V=[...r,Ee];u(V),h(n),c(a),x(l)}}}else c(a),h(n),u(r),x(l)};function k(E){d(E.active.id),i(null),c(a),h(n),u(r),x(l)}function M(E){return!r.some(j=>j.name===E.column_name)}function O(E,j="SUM"){const{column_name:A,data_type:B}=E,_=[...n],G=s!==null?s:n.length,Q={...E,id:Z(A),name:A,label:me(A,j),type:B,role:"metric",aggregate:j};_.splice(G,0,Q),m(_)}function F(E){const j=t.isTextDataType(E.data_type);t.isDateDataType(E.data_type);const A=[...l],B=s!==null?s:l.length;let _;j?_={...E,id:Z(E.column_name),name:E.column_name,type:E.data_type,role:"groupby"}:_={...E,id:Z(E.column_name),name:E.column_name,type:E.data_type,role:"groupby",label:ce(E.column_name,"month"),granularity:"month"},A.splice(B,0,_),f(A)}function H(E){const j=t.isTextDataType(E.data_type);t.isDateDataType(E.data_type);const A=[...a],B=s!==null?s:a.length;let _;j?_={...E,id:Z(E.column_name),name:E.column_name,type:E.data_type,role:"groupby"}:_={...E,id:Z(E.column_name),name:E.column_name,type:E.data_type,role:"groupby",label:ce(E.column_name,"month"),granularity:"month"},A.splice(B,0,_),b(A)}function w(E){const j=[...r],A=s!==null?s:r.length,B={...E,id:Z(E.column_name),name:E.column_name,type:E.data_type,sql:t.getDefaultFilterSql(E.data_type,N,t.fmt(E.column_name)),role:"filter"};j.splice(A,0,B),v(j)}function R(E){var _,G,Q,y,C,I,V,$;const{active:j,over:A}=E,B=j.data.current;if((B==null?void 0:B.type)==="column"&&A){const z=g.find(K=>K.column_name===j.id);if(!z)return;const J=t.isNumberDataType(z.data_type),D=t.isTextDataType(z.data_type),P=t.isDateDataType(z.data_type);(D||P)&&(A.id===te||((_=A.data.current)==null?void 0:_.type)===be)&&H(z),(D||P)&&(A.id===ne||((G=A.data.current)==null?void 0:G.type)===ve)?F(z):(J||D)&&(A.id===se||((Q=A.data.current)==null?void 0:Q.type)===Oe)?(J&&O(z),D&&O(z,"COUNT")):M(z)&&(A.id===ze||((y=A.data.current)==null?void 0:y.type)===Fe)&&w(z)}if(A&&((C=A.data.current)==null?void 0:C.type)===be&&a.some(z=>z.id===j.id)){const z=a.findIndex(D=>D.id===j.id),J=a.findIndex(D=>D.id===A.id);if(z!==-1&&J!==-1&&z!==J){const D=[...a],[P]=D.splice(z,1);D.splice(J,0,P),b(D)}}if(A&&((I=A.data.current)==null?void 0:I.type)===ve&&l.some(z=>z.id===j.id)){const z=l.findIndex(D=>D.id===j.id),J=l.findIndex(D=>D.id===A.id);if(z!==-1&&J!==-1&&z!==J){const D=[...l],[P]=D.splice(z,1);D.splice(J,0,P),f(D)}}if(A&&((V=A.data.current)==null?void 0:V.type)===Oe&&n.some(z=>z.id===j.id)){const z=n.findIndex(D=>D.id===j.id),J=n.findIndex(D=>D.id===A.id);if(z!==-1&&J!==-1&&z!==J){const D=[...n],[P]=D.splice(z,1);D.splice(J,0,P),m(D)}}if(A&&(($=A.data.current)==null?void 0:$.type)===Fe&&r.some(z=>z.id===j.id)){const z=r.findIndex(D=>D.id===j.id),J=r.findIndex(D=>D.id===A.id);if(z!==-1&&J!==-1&&z!==J){const D=[...r],[P]=D.splice(z,1);D.splice(J,0,P),v(D)}}U(E),d(null),i(null),c(a),h(n),u(r),x(l)}function U(E){const{active:j,over:A}=E,B=j.data.current;if((B==null?void 0:B.type)===Pe&&A){const _=o.findIndex(Q=>ue(Q.columnId)===j.id),G=o.findIndex(Q=>ue(Q.columnId)===A.id);if(_!==-1&&G!==-1&&_!==G){const Q=[...o],[y]=Q.splice(_,1);Q.splice(G,0,y),p(Q)}}}function q(){d(null),i(null),c(a),h(n),u(r)}return{handleDragOver:L,handleDragEnd:R,handleDragStart:k,handleDragCancel:q,sensors:S}}function Z(s){return`${s}-${t.v4()}`}function me(s,a){const n=t.toTitleCase(s.replace(/_/g," "));switch(a){case"SUM":return`Sum of ${n}`;case"COUNT":return`Count of ${n}`;case"DISTINCT":return`Unique ${n}`;case"AVG":return`Average of ${n}`;case"MIN":return`Min of ${n}`;case"MAX":return`Max of ${n}`;default:return n}}function ue(s){return`${Pe}-${s}`}function ce(s,a){const n=t.toTitleCase(s.replace(/_/g," "));switch(a){case"day":return`Date of ${n}`;case"week":return`Week of ${n}`;case"month":return`Month of ${n}`;case"year":return`Year of ${n}`;default:return n}}function rn({schemaName:s,tableName:a,columns:n,status:r}){const o=t.useEditorStore(j=>j.sqlGen),l=t.useEditorStore(j=>j.isDevMode),i=t.useEditorStore(j=>j.selectedConnectionId),d=t.useEditorStore(j=>{var A,B;return(B=(A=j.card)==null?void 0:A.queryConfig)==null?void 0:B.metricColumns});t.useEditorStore(j=>{var A,B;return(B=(A=j.card)==null?void 0:A.queryConfig)==null?void 0:B.groupByColumns});const c=t.useEditorStore(j=>j.selectedDatabaseName),h=t.useEditorStore(j=>j.selectedSchemaName),u=t.useEditorStore(j=>j.selectedTableName),x=t.useEditorStore(j=>j.selectedDatamodelId),b=t.useDashboardStore(j=>j.dashboard.aiScopeTables),{addToAIScope:m,removeFromAIScope:v}=t.useDashboardActions(),{addColumnToMetricColumns:p,addColumnToGroupBy:f,setCardSql:g,setRunSql:N,setSqlGen:S,setIsShowingVisual:L}=t.useEditorActions(),{connectionType:k,modelItems:M,selectedDatamodelName:O}=t.useEditorAside();function F(j){var A;if(l){const B=t.createSqlGenConfig(j,o);S(B);const _=(A=M==null?void 0:M.find(Q=>Q.id===x))==null?void 0:A.name,G=t.getSql(B,t.fmt(s),t.fmt(a),_,k,c||"");G&&(g(G),N(!0))}if(!l){if(t.isTextDataType(j.data_type))if(d&&d.length>0){const B={...j,role:"groupby",id:Z(j.column_name),name:j.column_name,type:j.data_type};f(B)}else{const B={...j,role:"metric",id:Z(j.column_name),name:j.column_name,label:me(j.column_name,"COUNT"),type:j.data_type,aggregate:"COUNT"};p(B)}if(t.isDateDataType(j.data_type)){const B={...j,role:"groupby",id:Z(j.column_name),name:j.column_name,type:j.data_type,label:ce(j.column_name,"month"),granularity:"month"};f(B)}if(t.isNumberDataType(j.data_type)){const B={...j,role:"metric",id:Z(j.column_name),name:j.column_name,label:me(j.column_name,"SUM"),type:j.data_type,aggregate:"SUM"};p(B)}}}function H(j){j===!0&&(u||O)&&i?(m({connectionId:i,connectionType:k==="S3"||k==="API"?"DuckDb":k,databaseName:c||"",schemaName:h||"",tableName:u||"",datamodelName:t.resolveDatamodelName(O),datamodelId:x||""}),t.ue.success("Added to Assistant Scope",{position:"top-right",duration:2500,richColors:!0})):(v({connectionId:i||"",connectionType:k||"",tableName:u||"",datamodelName:t.resolveDatamodelName(O),datamodelId:x||"",databaseName:c||"",schemaName:h||""}),t.ue("Removed from Assistant Scope",{position:"top-right",duration:2e3,richColors:!0}))}function w(){const j=t.getFormattedTableNameForQuery({schemaName:s,tableName:a,modelName:O,connectionType:k,databaseName:c||""});L(!1);const A=k==="MSSQL"?`SELECT top 10 * FROM ${j}`:`SELECT * FROM ${j} LIMIT 10`;g(A),N(!0)}function R(){const j=t.getFormattedTableNameForQuery({schemaName:s,tableName:a,modelName:O,connectionType:k,databaseName:c||""});g(`SELECT COUNT(*) as count FROM ${j}`),N(!0)}function U(){return(b==null?void 0:b.find(j=>j.connectionId===i&&(j.tableName===u||j.datamodelName===O)))!==void 0}function q(j){return l?e.jsxs("div",{className:"flex grow items-center justify-between space-x-2 rounded-md px-2 py-1",onClick:()=>F(j),children:[e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(qe,{column:j}),e.jsx("span",{children:j.column_name})]}),e.jsx("div",{onClick:A=>A.stopPropagation(),className:"flex items-center justify-end",children:t.isNumberDataType(j.data_type)&&e.jsx(tn,{column:j})})]}):e.jsx(nn,{onClick:F,column:j})}function E(){return e.jsxs(e.Fragment,{children:[e.jsxs(t.Toggle,{title:`${U()?"Remove from":"Add to"} Assistant Scope`,pressed:U(),onPressedChange:H,variant:"outline",className:t.cn("h-9 px-2",{}),children:[e.jsx(t.Plus,{className:t.cn("mr-1 size-4",{"text-green-400":U(),"text-muted-foreground":!U()})}),"AI"]}),e.jsxs(t.Button,{disabled:r!=="Success",onClick:w,size:"sm",variant:"secondary",className:"flex",children:[r!=="Success"?e.jsx(ae,{className:"mr-2 h-4 w-4 animate-spin text-foreground/50"}):e.jsx(Ls,{className:"mr-2 size-4"}),"Top 10"]}),e.jsxs(t.Button,{disabled:r!=="Success",onClick:R,size:"sm",variant:"secondary",className:"w-full",children:[r!=="Success"?e.jsx(ae,{className:"mr-2 h-4 w-4 animate-spin text-foreground/50"}):e.jsx(ht,{className:"mr-2 size-4"}),"Count"]})]})}return r!=="Success"?e.jsx("div",{className:"flex grow flex-col justify-start gap-2 px-6",children:Array.from({length:3}).map((j,A)=>e.jsx(t.Skeleton,{className:"h-7 w-full"},A))}):e.jsxs("div",{className:"flex grow flex-col space-y-4 px-4",children:[l&&e.jsx("div",{className:"mx-2 flex items-center justify-center gap-2",children:E()}),e.jsxs(t.CustomScrollArea,{className:"flex-1 basis-0 overflow-y-auto px-2 py-0",children:[e.jsx("div",{className:"flex flex-col gap-1",children:n==null?void 0:n.map(j=>e.jsx("div",{className:t.cn("mr-2 cursor-pointer rounded-md text-sm transition-colors hover:bg-muted"),children:q(j)},j.column_name))}),e.jsx(t.ScrollBar,{orientation:"vertical"}),e.jsx(t.ScrollBar,{orientation:"horizontal"})]})]})}function bt({ColumnsComponent:s,type:a}){var Ue;const n=t.useEditorStore(W=>W.card),r=t.useEditorStore(W=>W.selectedConnectionId),o=t.useDashboardStore(W=>W.showFilters),l=t.useEditorStore(W=>W.selectedDatamodelId),i=t.useEditorStore(W=>W.selectedDatabaseName),d=t.useEditorStore(W=>W.selectedSchemaName),c=t.useEditorStore(W=>W.selectedTableName),h=t.useEditorStore(W=>W.isDevMode),{setSelectedTableName:u,setIsDevMode:x,setCardSql:b}=t.useEditorActions(),{connectionItems:m,modelItems:v,schemaItems:p,databaseItems:f,tableItems:g,columns:N,isConnectionsLoading:S,isModelsLoading:L,isConnectionsError:k,isModelsError:M,isDatabasesLoadingOrFetching:O,isDatabaseError:F,isSchemaLoadingOrFetching:H,isSchemaError:w,isColumnsError:R,isColumnsLoadingOrFetching:U,isTableLoadingOrFetching:q,isTableError:E,connectionType:j,isNonDbConnection:A,refetchDatabases:B,refetchModels:_,refetchSchemas:G,refetchTables:Q,refetchColumns:y,refetchConnections:C,handleConnectionChange:I,handleDatabaseChange:V,handleSchemaChange:$,handleDatamodelChange:z,handleTableChange:J,tableName:D,schemaName:P}=t.useEditorAside(),{data:K,refetch:X}=t.useDashboardCardQuery(n);function he(){return s?s(P,D,N):e.jsx(rn,{schemaName:P,tableName:D,columns:N,status:U?"Loading...":R?"Error":"Success"})}function xe(){window.location.href="mailto:support@semaphor.cloud?subject=Help&body=I need help with..."}function pe(W){W===!0?K&&(b(K.userSql),setTimeout(()=>{X()},100)):b(""),x(W)}function fe(){if(!r||j==="S3"||j==="API")return null;if(!l||l==="none")return e.jsx(ie,{refetch:B,showNone:!0,onChange:V,isError:F,isLoading:O,items:f,value:i||"",title:"Database",type:"combobox"})}function Ut(){if(r&&!A&&(!i||i==="none")&&(!l||l==="none"))return e.jsxs("div",{className:"grid grid-cols-3",children:[e.jsx("div",{className:"col-span-1 grid place-items-center",children:e.jsx(t.Separator,{})}),e.jsx("div",{className:"col-span-1 grid place-items-center",children:e.jsx(t.Label,{children:"OR"})}),e.jsx("div",{className:"col-span-1 grid place-items-center",children:e.jsx(t.Separator,{})})]})}function $t(){if(!r||j==="S3"||j==="API")return null;if(!i||i==="none")return e.jsx(ie,{refetch:_,showNone:!0,onChange:z,isError:M,isLoading:L,items:v,value:l||"",title:"Model",type:"combobox"})}function Qt(){return!r||j==="S3"||j==="API"||!i||i==="none"?null:e.jsx(ie,{refetch:G,onChange:$,isError:w,isLoading:H,items:p,value:d||"",title:"Schema",type:"combobox"})}function Jt(){function W(){let ee=!1;return j==="API"?(ee=!1,ee):((j==="S3"||r&&i&&i!=="none"&&d)&&(ee=!0),ee)}return W()?e.jsx(ie,{refetch:Q,onChange:J,isError:E,items:g,isLoading:q,value:c||"",title:"Table",type:"combobox"}):null}return e.jsxs("aside",{className:t.cn("flex h-full min-w-[310px] max-w-[310px] flex-col justify-between rounded-none",{"border-r-[1px]":!o}),children:[e.jsxs("section",{className:"space-y-3 px-6 py-4",children:[e.jsx(ie,{refetch:C,items:m,title:"Connection",value:r||"",onChange:I,isLoading:S,isError:k,type:"combobox",connectionTooltip:((Ue=m==null?void 0:m.find(W=>W.id===r))==null?void 0:Ue.type)||""}),fe(),Ut(),$t(),Qt(),Jt()]}),he(),e.jsx("div",{className:"flex items-center justify-between gap-2 px-6 py-4",children:a==="main"&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(t.Switch,{className:"data-[state=checked]:bg-muted-foreground/80",checked:h,onCheckedChange:pe,id:"dev-mode"}),e.jsx(t.Label,{htmlFor:"dev-mode",children:"Dev Mode"})]}),e.jsxs(t.Button,{onClick:xe,size:"sm",variant:"secondary",className:"group flex items-center gap-2 rounded-full",children:[e.jsx(zs,{className:"size-4"}),e.jsx("span",{className:"hidden group-hover:block",children:"Help"})]})]})})]})}function vt({sql:s,error:a,onClick:n}){const r=t.useEditorStore(c=>c.isDevMode);t.useEditorStore(c=>c.card);const{setIsDevMode:o,setCardSql:l,setRunSql:i}=t.useEditorActions();if(!s&&!a)return null;function d(){o(!r),l(s),setTimeout(()=>{i(!0)},100)}return e.jsxs(t.HoverCard,{openDelay:a?0:500,children:[e.jsx(t.HoverCardTrigger,{asChild:!0,children:e.jsx(t.Button,{variant:"link",className:"h-5 p-0",children:a?e.jsx(at,{className:"h-4 w-4 text-red-500"}):e.jsx(t.Info,{className:"h-4 w-4 text-muted-foreground"})})}),e.jsx(t.HoverCardContent,{align:"start",className:"w-full min-w-fit max-w-[700px]",children:e.jsx("div",{className:"flex justify-between space-x-4",children:e.jsxs("div",{className:"flex grow flex-col space-y-2",children:[e.jsxs(t.ScrollArea,{className:"max-h-[250px] min-h-0 overflow-scroll text-xs leading-relaxed text-foreground/80",children:[a&&a,s&&e.jsxs("div",{className:"flex flex-col space-y-1.5",children:[e.jsx("span",{className:"text-xs font-semibold",children:"Resolved SQL"}),e.jsx("div",{className:"rounded-md",children:e.jsx(t.CodeHighlighter,{code:s,language:"sql"})})]})]}),!r&&e.jsxs(t.Button,{onClick:d,variant:"secondary",size:"sm",children:[e.jsx(Cs,{className:"mr-2 h-4 w-4"}),"View in SQL Editor"]}),a&&n&&e.jsxs(t.Button,{onClick:n,size:"sm",variant:"secondary",children:[e.jsx(Ds,{className:"mr-2 h-4 w-4"}),"Debug with Assistant"]})]})})})]})}var Ct={color:void 0,size:void 0,className:void 0,style:void 0,attr:void 0},Ke=T.createContext&&T.createContext(Ct),on=["attr","size","title"];function ln(s,a){if(s==null)return{};var n=cn(s,a),r,o;if(Object.getOwnPropertySymbols){var l=Object.getOwnPropertySymbols(s);for(o=0;o<l.length;o++)r=l[o],!(a.indexOf(r)>=0)&&Object.prototype.propertyIsEnumerable.call(s,r)&&(n[r]=s[r])}return n}function cn(s,a){if(s==null)return{};var n={};for(var r in s)if(Object.prototype.hasOwnProperty.call(s,r)){if(a.indexOf(r)>=0)continue;n[r]=s[r]}return n}function Ce(){return Ce=Object.assign?Object.assign.bind():function(s){for(var a=1;a<arguments.length;a++){var n=arguments[a];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(s[r]=n[r])}return s},Ce.apply(this,arguments)}function Ye(s,a){var n=Object.keys(s);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(s);a&&(r=r.filter(function(o){return Object.getOwnPropertyDescriptor(s,o).enumerable})),n.push.apply(n,r)}return n}function Se(s){for(var a=1;a<arguments.length;a++){var n=arguments[a]!=null?arguments[a]:{};a%2?Ye(Object(n),!0).forEach(function(r){dn(s,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(s,Object.getOwnPropertyDescriptors(n)):Ye(Object(n)).forEach(function(r){Object.defineProperty(s,r,Object.getOwnPropertyDescriptor(n,r))})}return s}function dn(s,a,n){return a=un(a),a in s?Object.defineProperty(s,a,{value:n,enumerable:!0,configurable:!0,writable:!0}):s[a]=n,s}function un(s){var a=mn(s,"string");return typeof a=="symbol"?a:a+""}function mn(s,a){if(typeof s!="object"||!s)return s;var n=s[Symbol.toPrimitive];if(n!==void 0){var r=n.call(s,a);if(typeof r!="object")return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return(a==="string"?String:Number)(s)}function St(s){return s&&s.map((a,n)=>T.createElement(a.tag,Se({key:n},a.attr),St(a.child)))}function re(s){return a=>T.createElement(hn,Ce({attr:Se({},s.attr)},a),St(s.child))}function hn(s){var a=n=>{var{attr:r,size:o,title:l}=s,i=ln(s,on),d=o||n.size||"1em",c;return n.className&&(c=n.className),s.className&&(c=(c?c+" ":"")+s.className),T.createElement("svg",Ce({stroke:"currentColor",fill:"currentColor",strokeWidth:"0"},n.attr,r,i,{className:c,style:Se(Se({color:s.color||n.color},n.style),s.style),height:d,width:d,xmlns:"http://www.w3.org/2000/svg"}),l&&T.createElement("title",null,l),s.children)};return Ke!==void 0?T.createElement(Ke.Consumer,null,n=>a(n)):a(Ct)}function xn(s){return re({attr:{viewBox:"0 0 448 512"},child:[{tag:"path",attr:{d:"M439.8 200.5c-7.7-30.9-22.3-54.2-53.4-54.2h-40.1v47.4c0 36.8-31.2 67.8-66.8 67.8H172.7c-29.2 0-53.4 25-53.4 54.3v101.8c0 29 25.2 46 53.4 54.3 33.8 9.9 66.3 11.7 106.8 0 26.9-7.8 53.4-23.5 53.4-54.3v-40.7H226.2v-13.6h160.2c31.1 0 42.6-21.7 53.4-54.2 11.2-33.5 10.7-65.7 0-108.6zM286.2 404c11.1 0 20.1 9.1 20.1 20.3 0 11.3-9 20.4-20.1 20.4-11 0-20.1-9.2-20.1-20.4.1-11.3 9.1-20.3 20.1-20.3zM167.8 248.1h106.8c29.7 0 53.4-24.5 53.4-54.3V91.9c0-29-24.4-50.7-53.4-55.6-35.8-5.9-74.7-5.6-106.8.1-45.2 8-53.4 24.7-53.4 55.6v40.7h106.9v13.6h-147c-31.1 0-58.3 18.7-66.8 54.2-9.8 40.7-10.2 66.1 0 108.6 7.6 31.6 25.7 54.2 56.8 54.2H101v-48.8c0-35.3 30.5-66.4 66.8-66.4zm-6.7-142.6c-11.1 0-20.1-9.1-20.1-20.3.1-11.3 9-20.4 20.1-20.4 11 0 20.1 9.2 20.1 20.4s-9 20.3-20.1 20.3z"},child:[]}]})(s)}function Nt(s){const{theme:a}=t.useTheme(),n=t.useDashboardStore(p=>p.theme),r=t.useEditorStore(p=>p.frame),o=t.useEditorStore(p=>p.card),l=t.useEditorStore(p=>p.activeTabCardId),i=t.Le(),{refetch:d}=t.useDashboardCardQuery(o),{updateCardTab:c,setRunSql:h}=t.useEditorActions(),u=T.useRef(),x=T.useRef({}),b=r.cards.find(p=>p.id===l),m=T.useCallback(()=>{let p="";return s==="python"&&(p=(b==null?void 0:b.python)||t.PYTHON_DEFAULT_CODE),s==="sql"&&(p=(b==null?void 0:b.sql)||""),p},[s,b]);T.useEffect(()=>{if(l&&o.id&&o.id!==l){if(u.current&&i){const p=u.current.getModel();p&&(x.current[o.id]=p);let f=x.current[l];if(!f){const g=m();f=i.editor.createModel(g,s),x.current[l]=f}u.current.setModel(f)}c(l,o),h(!0)}},[l,o,c,i,h,s,m]),T.useEffect(()=>{if(!i)return;const p=window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light",f=n==="system"?p:n;i.editor.defineTheme("default",{base:f==="light"?"vs":"vs-dark",inherit:!0,rules:[],colors:{"editor.background":f==="light"?"#ffffff":t.hslStringToHex("240 10% 10%")}}),i.editor.setTheme("default")},[a,n,i]),T.useEffect(()=>{const p=u.current;p&&i&&o&&p.addCommand(i.KeyMod.Shift|i.KeyCode.Enter,function(){return d(),!1})},[i,d,o]);function v(p,f){if(u.current=p,!x.current[o.id]){const g=p.getModel(),N=m();x.current[o.id]=g||(f==null?void 0:f.editor.createModel(N,s))||p.getModel()}p.setModel(x.current[o.id])}return{handleEditorDidMount:v}}function pn(){const s=t.useEditorStore(i=>i.card.sql),a=t.useEditorStore(i=>i.sqlGen),{setCardSql:n,setSqlGen:r}=t.useEditorActions(),{handleEditorDidMount:o}=Nt("sql");function l(i){n(i),t.isObjectEmpty(a)||r({})}return e.jsxs("div",{className:"relative h-full w-full",children:[!s&&e.jsx("div",{className:"pointer-events-none absolute left-[65px] top-3 z-10 font-mono text-sm text-muted-foreground",children:"Write your SQL here"}),e.jsx(t.Ft,{theme:"default",className:"pt-3",onChange:l,value:s||"",options:{minimap:{enabled:!1},wordWrap:"on",scrollbar:{verticalScrollbarSize:0,horizontalScrollbarSize:0},fontSize:13,renderLineHighlight:"none"},defaultLanguage:"sql",onMount:o})]})}function fn(){const s=t.useEditorStore(o=>o.card.python),{setCardPython:a}=t.useEditorActions(),{handleEditorDidMount:n}=Nt("python");function r(o){a(o)}return e.jsx(t.Ft,{className:"pt-3",theme:"default",onChange:r,value:s||t.PYTHON_DEFAULT_CODE,options:{minimap:{enabled:!1},wordWrap:"on",scrollbar:{verticalScrollbarSize:0,horizontalScrollbarSize:0},fontSize:13,renderLineHighlight:"none"},defaultLanguage:"python",onMount:n})}function gn({jsonString:s}){return e.jsx(t.Ft,{theme:"default",defaultLanguage:"json",className:"mt-1 min-h-[220px]",value:s,options:{readOnly:!0,minimap:{enabled:!1},lineNumbers:"off",glyphMargin:!1,wordWrap:"on",scrollbar:{verticalScrollbarSize:0,horizontalScrollbarSize:0},fontSize:12,renderLineHighlight:"none"}})}function wt(s){const[a,n]=T.useState(""),[r,o]=T.useState(null),{authToken:l}=t.useSemaphorContext(),i=t.useEditorStore(D=>{var P;return(P=D==null?void 0:D.card)==null?void 0:P.sql}),d=t.useEditorStore(D=>{var P;return(P=D==null?void 0:D.card)==null?void 0:P.python}),{setCardPython:c,setCardSql:h,setRunSql:u,switchCardType:x}=t.useEditorActions(),b=t.useEditorStore(D=>D.currentAssitantScope)||[],m=t.useEditorStore(D=>D.userInputForAI),v=t.useEditorStore(D=>D.triggerAIRun),p=t.useEditorStore(D=>D.selectedDatabaseName),f=t.useEditorStore(D=>D.selectedTableName),g=t.useEditorStore(D=>D.selectedConnectionId),N=t.useEditorStore(D=>D.selectedSchemaName),S=t.useDashboardStore(D=>D.dashboard.aiScopeTables),{setTriggerAIRun:L,setCurrentAssitantScope:k}=t.useEditorActions(),{selectedDatamodelName:M,connectionType:O,selectedDatamodelId:F}=t.useEditorAside(),{messages:H,setMessages:w,reload:R,error:U,append:q,input:E,setInput:j,status:A,handleInputChange:B,handleSubmit:_,stop:G}=t.useChat({api:"https://semaphor.cloud/api/v1/assistant",headers:{Authorization:`Bearer ${l==null?void 0:l.accessToken}`},body:{random:Math.random(),assistantId:"editor-assistant"},maxSteps:10,onError:D=>{console.log("on error",D)},onToolCall:Q,onFinish(D,P){y(P.usage),n(""),P.finishReason==="stop"&&n("")}});T.useEffect(()=>{v&&m&&(B({target:{value:m}}),setTimeout(()=>{_(),L(!1)},100))},[v,_,m,L,B]);async function Q({toolCall:D}){if(["createChartFromSql","createForecast"].includes(D.toolName)){const P=D.args.sql,K=D.args.python,X=D.args.chartType;return x(X),h(P),c(K),u(!0),{status:"success",message:"Let the user know that chart is created"}}else if(D.toolName==="getTableColumns")n("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 n("Getting table scope..."),$(),{status:"success",tables:b};n("Analyzing...")}}function y(D){o(P=>P?{promptTokens:P.promptTokens+D.promptTokens,completionTokens:P.completionTokens+D.completionTokens,totalTokens:P.totalTokens+D.totalTokens}:D)}function C(D){const P=t.removeFromScopeArray(b,D);I(P)}function I(D){const P=t.sanitizeAIScope(D);k(P),w(K=>[...K,{id:crypto.randomUUID(),role:"system",content:`Current scope of tables. Always use the table reference format when generating SQL | ${JSON.stringify(P)}`}])}function V(){const D={databaseName:p||"",schemaName:N||"",tableName:f||"",datamodelId:F||"",datamodelName:t.resolveDatamodelName(M),connectionId:g||"",connectionType:O||""},P=t.dedup([...b,D]);I(P)}function $(){const D={databaseName:p||"",schemaName:N||"",tableName:f||"",datamodelName:t.resolveDatamodelName(M),connectionId:g||"",connectionType:O||"",datamodelId:F||""};if(!t.isInAiScopeArray([...S||[],...b],D)||b.length===0){const K=t.dedup([...S||[],...b,D]).filter(X=>X.connectionId===D.connectionId);I(K)}}const z=!["ready","error"].includes(A),J=t.getErrorMessage(U);return{messages:H,setMessages:w,reload:R,append:q,input:E,setInput:j,isLoading:z,handleSetAIScope:$,handleAddCurrentTableToScope:V,removeFromCurrentSelections:C,currentAssitantScope:b,setCurrentAssitantScope:k,handleInputChange:B,handleSubmit:_,stop:G,chatStatus:A,toolStatus:a,llmUsage:r,onFinish:s,errorMessage:J}}function jn(s){const a=s.toUpperCase().indexOf("WHERE"),n=s.toUpperCase().indexOf("GROUP BY"),r=s.toUpperCase().indexOf("LIMIT"),o=s.toUpperCase().indexOf("ORDER BY");let l=s.length;if(o!==-1&&(l=o),r!==-1&&r<l&&(l=r),a!==-1){const i=s.substring(0,a),d=s.substring(a);return`${i} {{ filters | where }} AND ${d.substring(6)}`}else if(n!==-1){const i=s.substring(0,n),d=s.substring(n);return`${i} {{ filters | where }} ${d}`}else{const i=s.substring(0,l),d=s.substring(l);return console.log("beforeClause",i),console.log("afterClause",d),d?`${i} {{ filters | where }} ${d}`:`${i.replace(/;$/,"")} {{ filters | where }}`}}function kt({variant:s="secondary"}){const{setCardSql:a}=t.useEditorActions(),n=t.useEditorStore(m=>m.frame),r=t.useEditorStore(m=>m.card),o=t.useEditorStore(m=>m.selectedSchemaName),l=t.useEditorStore(m=>m.selectedDatamodelId),i=t.useEditorStore(m=>m.selectedDatabaseName),d=t.useEditorStore(m=>m.selectedTableName),c=t.useEditorStore(m=>m.selectedConnectionId),h=t.useEditorStore(m=>m.isShowingVisual),u=r.sql,x=t.useEditorStore(m=>m.onSave);function b(){let m=u;u&&!u.includes("{{")&&(m=jn(u),a(m));const v={...r,lastSelectedSchema:o,lastSelectedDatamodelId:l,lastSelectedDatabase:i,lastSelectedTable:d,connectionId:c,type:h?r.type:"table",sql:m,customCfg:h?r.customCfg:null},p=n.cards.map(g=>g.id===r.id?v:g),f={...n,cards:p,activeCardId:yn(p,n.activeCardId)};x==null||x(f)}return e.jsxs(t.Button,{onClick:b,size:"sm",variant:s,children:[e.jsx(t.Check,{className:"mr-2 size-4 font-bold"}),"Accept"]})}function Dt(){const{setTempQueryData:s,setSqlGen:a}=t.useEditorActions(),n=t.useQueryClient(),r=t.useEditorStore(c=>c.tempQueryData),o=t.useEditorStore(c=>c.onClose),l=t.useEditorStore(c=>c.card),{queryKey:i}=t.useDashboardCardQuery(l);function d(){if(r){const{queryKey:c,queryData:h}=r;c&&h&&n.setQueryData(c,h)}a({}),o==null||o()}return e.jsxs(t.Button,{onClick:d,size:"sm",variant:"secondary",children:[e.jsx(t.X,{className:"mr-2 size-4"}),"Close"]})}function It(){const{setTempQueryData:s}=t.useEditorActions(),a=t.useQueryClient(),n=t.useEditorStore(m=>m.tempQueryData),r=t.useEditorStore(m=>m.card),{queryKey:o}=t.useDashboardCardQuery(r),{setCardSql:l,setSqlGen:i,setCardPython:d,setCardCustomCfg:c,setCardPreferences:h,setCardType:u,clearQueryConfig:x}=t.useEditorActions();function b(){const m=a.getQueryData(o);n!=null&&n.queryData||s({queryKey:o,queryData:m}),a.setQueryData(o,null),a.removeQueries({queryKey:o,exact:!0}),l(""),i({}),x(),d(""),c(""),h({})}return e.jsxs(t.Button,{onClick:b,className:"",size:"sm",variant:"secondary",children:[e.jsx(bs,{className:"mr-2 size-4"}),"Clear"]})}function yn(s,a){if(s.length===0)return"";if(a){const n=s.find(r=>r.id===a);if(n){const r=n.tabTitle;if(r=="All__Header")return s[0].id;if(r&&r.endsWith("__Header")){const l=r.split("__")[0],i=s.find(d=>d.tabTitle===l);return i?i.id:s[0].id}return a}}return s[0].id}function bn(){const s=t.useQueryClient(),[a,n]=T.useState(!1),[r,o]=T.useState(!1);t.useEditorStore(y=>y.frame);const l=t.useEditorStore(y=>y.card);t.useEditorStore(y=>y.isShowingVisual),t.useEditorStore(y=>y.selectedConnectionId),t.useEditorStore(y=>y.tempQueryData),t.useEditorStore(y=>y.selectedDatabaseName),t.useEditorStore(y=>y.selectedDatamodelId),t.useEditorStore(y=>y.selectedSchemaName);const i=t.useEditorStore(y=>y.showAIDialog);t.useEditorStore(y=>y.selectedTableName);const d=t.useEditorStore(y=>{var C;return(C=y==null?void 0:y.card)==null?void 0:C.sql}),c=t.useEditorStore(y=>{var C;return(C=y==null?void 0:y.card)==null?void 0:C.python}),{sheetFilterValues:h}=t.useSheetFilterValues(),{setCardCustomCfg:u,setQueryResultColumns:x,setCardSql:b,setTempQueryData:m,setPythonStdOut:v,setCardPreferences:p,setCardType:f,setCardPython:g,runAssistant:N,setShowAIDialog:S}=t.useEditorActions();t.useEditorStore(y=>y.onSave),t.useEditorStore(y=>y.onClose),t.useEditorStore(y=>y.actions.setSqlGen);const L=t.useEditorStore(y=>y.runSql),k=t.useEditorStore(y=>y.actions.setRunSql),M=t.useEditorStore(y=>y.actions.setIsSqlRunning),{data:O,isLoading:F,isFetching:H,isSuccess:w,isError:R,error:U,queryKey:q,refetch:E,errorMessage:j}=t.useDashboardCardQuery(l),{handleSetAIScope:A}=wt();T.useEffect(()=>{if(O&&(O.rowLimitExceeded&&t.ue.error("Row limit (10,000) exceeded. Refine your query.",{position:"top-center",richColors:!0}),v((O==null?void 0:O.output)||""),O.records.length>0)){const{dimensionKeys:y}=t.getKeys(O.records);x(y)}},[O,x,v]),T.useEffect(()=>{(F||H)&&M(!0),(R||w)&&M(!1),R&&(x([]),v(""))},[F,H,O,v,R,w,M,x,U]),T.useEffect(()=>{L&&(s.getQueryData(q)||E(),k(!1))},[L,E,k,q,s]);async function B(){const y=`Can you help me debug this query in the current table scope?
357
357
 
358
358
  Error:
359
359
 
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
- import { c as E, p as Wt, u as V, a as tt, b as Pe, d as Tn, e as zn, B as K, P as Ke, f as An, g as Fn, h as En, i as Ln, L as G, I as ce, j as Vn, k as _n, l as qn, m as W, n as Rn, o as jn, q as Bn, r as vs, s as yn, t as R, C as Kt, v as xs, S as Ce, w as Ne, x as we, y as Se, z as Ie, A as ke, E as oe, T as Pn, F as He, G as Ge, H as Mt, J as De, K as Yt, M as Dt, N as Zt, O as It, Q as Oe, R as Hn, U as lt, V as Gn, W as Un, X as bn, Y as Cs, Z as p, _ as $n, $ as Ye, a0 as gt, a1 as Ns, a2 as Qn, a3 as Jn, a4 as Wn, a5 as Kn, a6 as Yn, a7 as Zn, a8 as Xn, a9 as be, aa as ea, ab as ta, ac as na, ad as aa, ae as sa, af as ra, ag as ge, ah as ws, ai as ve, aj as Ss, ak as je, al as xe, am as ks, an as Ms, ao as Ds, ap as Is, aq as yt, ar as Te, as as Os, at as Ts, au as J, av as la, aw as zs, ax as As, ay as Fs, az as Pt, aA as ia, aB as Xt, aC as Ot, aD as Ze, aE as oa, aF as bt, aG as Ht, aH as he, aI as Es, aJ as Ls, aK as it, aL as Vs, aM as _s, aN as qs, aO as ca, aP as Rs, aQ as Tt, aR as js, aS as Bs, aT as Ps, aU as vn, aV as Hs, aW as Gs, aX as Us, aY as en, aZ as ye, a_ as $s, a$ as Gt, b0 as Ee, b1 as ue, b2 as Le, b3 as Qs, b4 as Js, b5 as Ws, b6 as Ks, b7 as Ys, b8 as At, b9 as Zs, ba as xn, bb as Xs, bc as Cn, bd as er, be as tr, bf as nr, bg as ar, bh as da, bi as sr, bj as tn, bk as ua, bl as rr, bm as lr, bn as Je, bo as ir, bp as or, bq as ma, br as cr, bs as dr, bt as ur, bu as mr, bv as hr, bw as zt, bx as ha, by as pr, bz as nn, bA as an, bB as We, bC as ft, bD as fr, bE as gr, bF as yr, bG as sn, bH as pa, bI as br, bJ as vt, bK as fa, bL as xt, bM as ga, bN as ya, bO as ba, bP as vr, bQ as xr, bR as Cr, bS as Nr, bT as Ae, bU as re, bV as le, bW as ie, bX as rn, bY as wr, bZ as Sr, b_ as kr, b$ as Mr, c0 as Dr, c1 as Nn, c2 as va, c3 as Ir, c4 as Or, c5 as Tr, c6 as zr, c7 as ln, c8 as xa, c9 as Ca, ca as on, cb as Ar, cc as Fr, cd as Na, ce as Er, cf as Lr, cg as Vr, ch as _r, ci as qr, cj as Rr, ck as jr, cl as Br, cm as Pr, cn as Ft, co as wa, cp as Hr, cq as Gr, cr as Ur, cs as $r, ct as Qr, cu as Jr, cv as Wr } from "./chunks/index-Dtc6AzZx.js";
2
- import { D as Ho, cA as Go, cy as Uo, cy as $o, cD as Qo, cC as Jo, cB as Wo, cE as Ko, cF as Yo, cz as Zo, cw as Xo, cx as ec } from "./chunks/index-Dtc6AzZx.js";
1
+ import { c as E, p as Wt, u as V, a as tt, b as Pe, d as Tn, e as zn, B as K, P as Ke, f as An, g as Fn, h as En, i as Ln, L as G, I as ce, j as Vn, k as _n, l as qn, m as W, n as Rn, o as jn, q as Bn, r as vs, s as yn, t as R, C as Kt, v as xs, S as Ce, w as Ne, x as we, y as Se, z as Ie, A as ke, E as oe, T as Pn, F as He, G as Ge, H as Mt, J as De, K as Yt, M as Dt, N as Zt, O as It, Q as Oe, R as Hn, U as lt, V as Gn, W as Un, X as bn, Y as Cs, Z as p, _ as $n, $ as Ye, a0 as gt, a1 as Ns, a2 as Qn, a3 as Jn, a4 as Wn, a5 as Kn, a6 as Yn, a7 as Zn, a8 as Xn, a9 as be, aa as ea, ab as ta, ac as na, ad as aa, ae as sa, af as ra, ag as ge, ah as ws, ai as ve, aj as Ss, ak as je, al as xe, am as ks, an as Ms, ao as Ds, ap as Is, aq as yt, ar as Te, as as Os, at as Ts, au as J, av as la, aw as zs, ax as As, ay as Fs, az as Pt, aA as ia, aB as Xt, aC as Ot, aD as Ze, aE as oa, aF as bt, aG as Ht, aH as he, aI as Es, aJ as Ls, aK as it, aL as Vs, aM as _s, aN as qs, aO as ca, aP as Rs, aQ as Tt, aR as js, aS as Bs, aT as Ps, aU as vn, aV as Hs, aW as Gs, aX as Us, aY as en, aZ as ye, a_ as $s, a$ as Gt, b0 as Ee, b1 as ue, b2 as Le, b3 as Qs, b4 as Js, b5 as Ws, b6 as Ks, b7 as Ys, b8 as At, b9 as Zs, ba as xn, bb as Xs, bc as Cn, bd as er, be as tr, bf as nr, bg as ar, bh as da, bi as sr, bj as tn, bk as ua, bl as rr, bm as lr, bn as Je, bo as ir, bp as or, bq as ma, br as cr, bs as dr, bt as ur, bu as mr, bv as hr, bw as zt, bx as ha, by as pr, bz as nn, bA as an, bB as We, bC as ft, bD as fr, bE as gr, bF as yr, bG as sn, bH as pa, bI as br, bJ as vt, bK as fa, bL as xt, bM as ga, bN as ya, bO as ba, bP as vr, bQ as xr, bR as Cr, bS as Nr, bT as Ae, bU as re, bV as le, bW as ie, bX as rn, bY as wr, bZ as Sr, b_ as kr, b$ as Mr, c0 as Dr, c1 as Nn, c2 as va, c3 as Ir, c4 as Or, c5 as Tr, c6 as zr, c7 as ln, c8 as xa, c9 as Ca, ca as on, cb as Ar, cc as Fr, cd as Na, ce as Er, cf as Lr, cg as Vr, ch as _r, ci as qr, cj as Rr, ck as jr, cl as Br, cm as Pr, cn as Ft, co as wa, cp as Hr, cq as Gr, cr as Ur, cs as $r, ct as Qr, cu as Jr, cv as Wr } from "./chunks/index-BioC5I8T.js";
2
+ import { D as Ho, cA as Go, cy as Uo, cy as $o, cD as Qo, cC as Jo, cB as Wo, cE as Ko, cF as Yo, cz as Zo, cw as Xo, cx as ec } from "./chunks/index-BioC5I8T.js";
3
3
  import { EMPTY_SELECTION as nc } from "./types/index.js";
4
4
  import { jsxs as r, jsx as e, Fragment as ne } from "react/jsx-runtime";
5
5
  import * as Qe from "react";
@@ -3231,7 +3231,7 @@ function Wa(t) {
3231
3231
  {
3232
3232
  id: crypto.randomUUID(),
3233
3233
  role: "system",
3234
- content: `Current scope of tables | ${JSON.stringify(Q)}`
3234
+ content: `Current scope of tables. Always use the table reference format when generating SQL | ${JSON.stringify(Q)}`
3235
3235
  }
3236
3236
  ]);
3237
3237
  }
package/package.json CHANGED
@@ -5,7 +5,7 @@
5
5
  "email": "support@semaphor.cloud"
6
6
  },
7
7
  "license": "MIT",
8
- "version": "0.0.473",
8
+ "version": "0.0.475",
9
9
  "description": "Fully interactive and customizable dashboards for your apps.",
10
10
  "keywords": [
11
11
  "react",