react-semaphor 0.0.261 → 0.0.263

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,4 +1,4 @@
1
- import { J as O, L as Ue, b as z, c as Cs, u as je, j as e, M as Ss, O as ws, P as F, Q as ks, R as zs, U as Fs, V as Ls, W as Ts, X as H, Y as Ce, Z as aa, _ as Xa, $ as Za, a0 as et, a1 as st, a2 as at, a3 as tt, a4 as Gs, f as J, a5 as Re, a6 as nt, a7 as ta, a8 as _e, a9 as ts, T as Ds, e as na, g as Is, aa as he, ab as me, ac as xe, ad as pe, ae as Se, af as fe, ag as Q, ah as Ms, G as c, ai as Os, aj as As, ak as Es, w as la, v as ia, t as ue, al as lt, r as it, N as ra, s as rt, am as ot, B as ct, an as oa, ao as dt, S as Vs, z as ut, n as Ks, A as ca, ap as fs, aq as re, ar as Ne, as as He, at as rs, au as da, av as ht, aw as mt, ax as ua, ay as xt, az as pt, aA as ft, aB as gt, aC as jt, aD as gs, aE as bt, aF as ha, aG as qe, aH as js, aI as De, aJ as bs, aK as Ps, aL as yt, aM as vt, aN as Nt, aO as Ct, aP as St, aQ as xs, aR as wt, aS as Ws, aT as kt, aU as Qs, aV as zt, aW as Ft, aX as Lt, aY as ma, H as Ie, aZ as xa, l as Tt, C as Dt, E as es, d as It, h as Mt, a_ as Ot, i as At, o as Et, a$ as Vt, m as qt, b0 as Rt, b1 as pa, b2 as fa, b3 as ss, b4 as ga, b5 as as, b6 as Js, b7 as Ge, b8 as Ke, b9 as Pe, ba as ja, K as _t, bb as Ht, bc as $t, bd as ba, be as ya, bf as va, bg as Na, bh as Ca, bi as Sa, bj as os, bk as Fe, bl as Bt, bm as Ut, bn as wa, bo as Gt, bp as Kt, bq as ns, br as Pt, bs as Wt, bt as Qt, bu as Ys, bv as Jt, bw as Yt, bx as Le, by as U, bz as G, bA as qs, bB as K, bC as Xt, bD as ka, bE as za, bF as Zt, bG as en, bH as sn, bI as an, bJ as tn, bK as nn, bL as ln, bM as rn, bN as on } from "./index-iXSJ_L4M.js";
1
+ import { J as O, L as Ue, b as z, c as Cs, u as je, j as e, M as Ss, O as ws, P as F, Q as ks, R as zs, U as Fs, V as Ls, W as Ts, X as H, Y as Ce, Z as aa, _ as Xa, $ as Za, a0 as et, a1 as st, a2 as at, a3 as tt, a4 as Gs, f as J, a5 as Re, a6 as nt, a7 as ta, a8 as _e, a9 as ts, T as Ds, e as na, g as Is, aa as he, ab as me, ac as xe, ad as pe, ae as Se, af as fe, ag as Q, ah as Ms, G as c, ai as Os, aj as As, ak as Es, w as la, v as ia, t as ue, al as lt, r as it, N as ra, s as rt, am as ot, B as ct, an as oa, ao as dt, S as Vs, z as ut, n as Ks, A as ca, ap as fs, aq as re, ar as Ne, as as He, at as rs, au as da, av as ht, aw as mt, ax as ua, ay as xt, az as pt, aA as ft, aB as gt, aC as jt, aD as gs, aE as bt, aF as ha, aG as qe, aH as js, aI as De, aJ as bs, aK as Ps, aL as yt, aM as vt, aN as Nt, aO as Ct, aP as St, aQ as xs, aR as wt, aS as Ws, aT as kt, aU as Qs, aV as zt, aW as Ft, aX as Lt, aY as ma, H as Ie, aZ as xa, l as Tt, C as Dt, E as es, d as It, h as Mt, a_ as Ot, i as At, o as Et, a$ as Vt, m as qt, b0 as Rt, b1 as pa, b2 as fa, b3 as ss, b4 as ga, b5 as as, b6 as Js, b7 as Ge, b8 as Ke, b9 as Pe, ba as ja, K as _t, bb as Ht, bc as $t, bd as ba, be as ya, bf as va, bg as Na, bh as Ca, bi as Sa, bj as os, bk as Fe, bl as Bt, bm as Ut, bn as wa, bo as Gt, bp as Kt, bq as ns, br as Pt, bs as Wt, bt as Qt, bu as Ys, bv as Jt, bw as Yt, bx as Le, by as U, bz as G, bA as qs, bB as K, bC as Xt, bD as ka, bE as za, bF as Zt, bG as en, bH as sn, bI as an, bJ as tn, bK as nn, bL as ln, bM as rn, bN as on } from "./index-z9fsiD8I.js";
2
2
  import * as ys from "react";
3
3
  import ge, { useState as V, useMemo as vs, useEffect as Z, useRef as $e, Suspense as cn } from "react";
4
4
  import "react-dom";
@@ -703,7 +703,7 @@ function Un() {
703
703
  a == null ? void 0 : a.map((h) => /* @__PURE__ */ e.jsxs(
704
704
  Gs,
705
705
  {
706
- className: "group flex justify-between",
706
+ className: "group flex justify-between gap-2",
707
707
  value: h.id,
708
708
  children: [
709
709
  /* @__PURE__ */ e.jsx("p", { children: h.name }),
@@ -1,4 +1,4 @@
1
- "use strict";const e=require("./index-Aj7GYy-J.js"),v=require("react");require("react-dom");function cs(s){const r=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(s){for(const t in s)if(t!=="default"){const n=Object.getOwnPropertyDescriptor(s,t);Object.defineProperty(r,t,n.get?n:{enumerable:!0,get:()=>s[t]})}}return r.default=s,Object.freeze(r)}const Ne=cs(v);/**
1
+ "use strict";const e=require("./index-3AYZwwvx.js"),v=require("react");require("react-dom");function cs(s){const r=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(s){for(const t in s)if(t!=="default"){const n=Object.getOwnPropertyDescriptor(s,t);Object.defineProperty(r,t,n.get?n:{enumerable:!0,get:()=>s[t]})}}return r.default=s,Object.freeze(r)}const Ne=cs(v);/**
2
2
  * @license lucide-react v0.453.0 - ISC
3
3
  *
4
4
  * This source code is licensed under the ISC license.
@@ -188,7 +188,7 @@
188
188
  *
189
189
  * This source code is licensed under the ISC license.
190
190
  * See the LICENSE file in the root directory of this source tree.
191
- */const Vs=e.createLucideIcon("User",[["path",{d:"M19 21v-2a4 4 0 0 0-4-4H9a4 4 0 0 0-4 4v2",key:"975kel"}],["circle",{cx:"12",cy:"7",r:"4",key:"17ys0d"}]]);function De(s){var r;return{...s,sheets:(r=s==null?void 0:s.sheets)==null?void 0:r.map(t=>{var n;return{...t,frames:(n=t.frames)==null?void 0:n.map(i=>{var l;return{...i,cards:(l=i.cards)==null?void 0:l.map(o=>$e(o))}})}})}}function $e(s){var r,t,n,i;return{...s,cfg:{...s.cfg,data:{...(r=s.cfg)==null?void 0:r.data,labels:[],datasets:(i=(n=(t=s.cfg)==null?void 0:t.data)==null?void 0:n.datasets)==null?void 0:i.map(l=>({...l,data:[]}))}},customCfg:qs(s.customCfg),data:[]}}function qs(s){var r,t;return s?{...s,data:{...s==null?void 0:s.data,labels:[],datasets:(t=(r=s==null?void 0:s.data)==null?void 0:r.datasets)==null?void 0:t.map(n=>({...n,data:[]}))}}:null}async function _s(s,r,t,n){if(!n)return null;const i=JSON.stringify(r),l="https://semaphor.cloud/api/v1/lens";return await e.postRequest(l,n,{name:s,template:i,filterValues:t,operation:"create"})}async function we(s,r){if(!r)return null;const{id:t,template:n,filterValues:i,isDefault:l,shared:o}=s,a="https://semaphor.cloud/api/v1/lens";return await e.postRequest(a,r,{lensId:t,template:n,filterValues:i,isDefault:l,shared:o,operation:"update"})}async function Bs(s,r){if(!r)return null;const t="https://semaphor.cloud/api/v1/lens";return await e.postRequest(t,r,{operation:"delete",lensId:s})}function Hs(){const[s,r]=v.useState(""),[t,n]=v.useState(!1),i=e.useDashboardStore(x=>x.lenses),{setLenses:l,setSelectedLensId:o}=e.useDashboardActions(),[a,c]=v.useState(!1),[p,u]=v.useState(!1),g=e.useDashboardStore(x=>x.dashboard),m=e.useDashboardStore(x=>x.filterValues),{authToken:d}=e.useSemaphorContext();async function j(){c(!0);const x=De(g),N=await _s(s,x,m,d==null?void 0:d.accessToken);N&&(l([...i||[],N]),o(N.id),u(!1)),c(!1)}return e.jsxRuntimeExports.jsxs(e.Dialog,{open:p,onOpenChange:u,children:[e.jsxRuntimeExports.jsx(e.DialogTrigger,{asChild:!0,children:e.jsxRuntimeExports.jsxs(e.Button,{variant:"secondary",className:"h-7 p-2",size:"sm",children:[e.jsxRuntimeExports.jsx(e.Plus,{className:"mr-2 h-4 w-4",strokeWidth:1.5}),"Lens"]})}),e.jsxRuntimeExports.jsxs(e.DialogContent,{className:"sm:max-w-[425px]",children:[e.jsxRuntimeExports.jsxs(e.DialogHeader,{children:[e.jsxRuntimeExports.jsx(e.DialogTitle,{children:"Create Lens"}),e.jsxRuntimeExports.jsx(e.DialogDescription,{children:"Lenses are private by default and are only visible to you."})]}),e.jsxRuntimeExports.jsx("div",{className:"grid gap-4 py-4",children:e.jsxRuntimeExports.jsxs("div",{className:"grid grid-cols-8 items-center gap-4",children:[e.jsxRuntimeExports.jsx(e.Label,{className:"text-right",children:"Name"}),e.jsxRuntimeExports.jsx(e.Input,{value:s,onChange:x=>{r(x.target.value)},id:"name",className:"col-span-7 focus-visible:ring-0 focus-visible:ring-ring focus-visible:ring-offset-0"})]})}),t&&e.jsxRuntimeExports.jsx("p",{className:"text-sm",children:"The lens name already exists. Use a differnet name."}),e.jsxRuntimeExports.jsx(e.DialogFooter,{children:e.jsxRuntimeExports.jsx(e.Button,{size:"sm",variant:"outline",type:"submit",onClick:j,disabled:a,children:a?"Creating...":"Add"})})]})]})}function Ps(){const[s,r]=v.useState(!1),t=e.useDashboardStore(u=>u.lenses),n=e.useDashboardStore(u=>u.selectedLensId),{setLenses:i,setSelectedLensId:l}=e.useDashboardActions(),{authToken:o}=e.useSemaphorContext();async function a(u){l(u)}async function c(u){if(await Bs(u,o==null?void 0:o.accessToken)){const m=t==null?void 0:t.filter(d=>d.id!==u);i(m||[]),l("original")}}async function p(u){const g=t==null?void 0:t.map(j=>j.id===u.id?{...j,isDefault:!u.isDefault}:{...j,isDefault:!1});i(g||[]);const m={...u,isDefault:!u.isDefault};await we(m,o==null?void 0:o.accessToken);const d=t==null?void 0:t.find(j=>j.isDefault);if(d&&d.id!==u.id){const j={...d,isDefault:!1};await we(j,o==null?void 0:o.accessToken)}}return e.jsxRuntimeExports.jsxs(e.DropdownMenu,{open:s,onOpenChange:r,children:[e.jsxRuntimeExports.jsx(e.DropdownMenuTrigger,{asChild:!0,children:e.jsxRuntimeExports.jsx(e.Button,{variant:"ghost",className:"h-7 p-2",children:e.jsxRuntimeExports.jsx(Rs,{className:"h-4 w-4",strokeWidth:1.5})})}),e.jsxRuntimeExports.jsxs(e.DropdownMenuContent,{align:"end",className:"w-60",children:[e.jsxRuntimeExports.jsx(e.DropdownMenuLabel,{className:"px-3",children:"Lenses"}),e.jsxRuntimeExports.jsx(e.DropdownMenuSeparator,{}),e.jsxRuntimeExports.jsxs(e.DropdownMenuRadioGroup,{value:n,onValueChange:a,children:[e.jsxRuntimeExports.jsx(e.DropdownMenuRadioItem,{value:"original",children:"Original"}),t==null?void 0:t.map(u=>e.jsxRuntimeExports.jsxs(e.DropdownMenuRadioItem,{className:"group flex justify-between",value:u.id,children:[e.jsxRuntimeExports.jsx("p",{children:u.name}),e.jsxRuntimeExports.jsxs("span",{className:"flex items-center gap-3",children:[e.jsxRuntimeExports.jsx(Ss,{onClick:g=>{g.preventDefault(),p(u)},className:e.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.jsxRuntimeExports.jsx(e.Cross2Icon,{onClick:g=>{g.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 $s(){const{authToken:s}=e.useSemaphorContext(),r=e.useDashboardStore(f=>f.lenses),t=e.useDashboardStore(f=>f.selectedLensId),n=r==null?void 0:r.find(f=>f.id===t),i=e.useDashboardStore(f=>f.dashboard);e.useDashboardStore(f=>f.selectedSheetId);const l=e.useDashboardStore(f=>f.isDashboardEditing),[o,a]=v.useState(!1),c=e.useDashboardStore(f=>f.filterValues),p=e.useDashboardStore(f=>f.isVisualEditing),u=e.useDashboardStore(f=>f.showFilters);e.useDashboardStore(f=>f.showDashboardJSON);const g=e.useDashboardStore(f=>f.onSaveFunction),m=e.useDashboardStore(f=>f.actions.setShowFilters),{addFrame:d,setSelectedFrameId:j}=e.useDashboardStore(f=>f.actions),{getSelectedSheet:x,setIsDashboardEditing:N,setShowDashboardJSON:I}=e.useDashboardStore(f=>f.actions),L=x(),{tenantId:b,endUserId:D}=v.useMemo(()=>e.getTenantAndEndUserId(s==null?void 0:s.accessToken),[s==null?void 0:s.accessToken]),T=v.useMemo(()=>b||D,[b,D]),E=()=>{if(!l||!L)return;const f={id:e.v4(),title:"Title",description:"Description",preferences:{onClickFilter:[{columnIndex:0,expression:""}]},type:"bar",sql:"select COUNT(*) from YOUR_TABLE",data:[]},z={id:e.v4(),cards:[f],activeCardId:f.id};d(L.id,z),j(z.id)},S=()=>{N(!0)};async function R(){if(a(!0),!t||!n)return;const f=De(i),z=JSON.stringify(f),M={...n,template:z,filterValues:c};await we(M,s==null?void 0:s.accessToken),e.Jt.success("Lens saved"),g==null||g(f),a(!1)}return p?null:e.jsxRuntimeExports.jsxs("div",{className:"flex items-center justify-between gap-2 border-b bg-muted/50 py-2 pl-3 pr-2",role:"dashboard-controls",children:[!p&&e.jsxRuntimeExports.jsx("div",{className:"flex items-center gap-3",children:e.jsxRuntimeExports.jsx(e.Label,{children:n==null?void 0:n.name})}),e.jsxRuntimeExports.jsxs("div",{className:"flex gap-2",children:[l&&!p&&T&&e.jsxRuntimeExports.jsx(Hs,{}),!p&&T&&e.jsxRuntimeExports.jsx(Ps,{}),l&&!p&&e.jsxRuntimeExports.jsxs(e.Button,{variant:"secondary",className:"h-7 p-2",size:"sm",disabled:!l,onClick:E,children:[e.jsxRuntimeExports.jsx(e.Plus,{className:"mr-2 h-4 w-4",strokeWidth:1.5}),"Frame"]}),!l&&e.jsxRuntimeExports.jsx(e.Button,{variant:"ghost",className:"h-7 p-2",onClick:S,size:"sm",children:e.jsxRuntimeExports.jsx(He,{className:"h-4 w-4",strokeWidth:1.5})}),l&&!p&&e.jsxRuntimeExports.jsx(e.Button,{variant:"ghost",role:"close",className:"h-7 p-2",onClick:()=>{N(!1),I(!1)},size:"sm",children:e.jsxRuntimeExports.jsx(e.Cross2Icon,{className:"h-4 w-4",strokeWidth:1.5})}),l&&!p&&T&&e.jsxRuntimeExports.jsx(e.Button,{className:"h-7 p-2",variant:"ghost",disabled:o,onClick:R,size:"sm",children:e.jsxRuntimeExports.jsx(Ts,{className:"h-4 w-4",strokeWidth:1.5})}),!u&&!p&&l&&e.jsxRuntimeExports.jsx(e.Button,{className:"h-7 p-2",variant:"ghost",onClick:()=>m(!0),size:"sm",children:e.jsxRuntimeExports.jsx(e.Filter,{className:"h-4 w-4",strokeWidth:1.5})}),!p&&l&&!1,!p&&!1]})]})}function ae({title:s,items:r,value:t,isLoading:n,isError:i,connectionTooltip:l,onChange:o,showNone:a=!1,className:c,showIcon:p=!0,disabled:u=!1}){const g=n?"Loading...":i?"Error":t;function m(){if(s==="Connection")return e.jsxRuntimeExports.jsx(Ds,{className:"size-4 rotate-90"});if(s==="Database")return e.jsxRuntimeExports.jsx(js,{className:"size-4"});if(s==="Schema")return e.jsxRuntimeExports.jsx(Is,{className:"size-4"});if(s==="Table")return e.jsxRuntimeExports.jsx(e.Table,{className:"size-4"});if(s==="Model")return e.jsxRuntimeExports.jsx(xs,{className:"size-4"})}return e.jsxRuntimeExports.jsxs("div",{className:"flex items-center gap-2",children:[p&&e.jsxRuntimeExports.jsx("div",{className:"shrink-0",children:l?e.jsxRuntimeExports.jsxs(e.Tooltip,{children:[e.jsxRuntimeExports.jsx(e.TooltipTrigger,{children:m()}),e.jsxRuntimeExports.jsx(e.TooltipContent,{className:"text-xs",align:"start",children:l})]}):m()}),e.jsxRuntimeExports.jsxs(e.Select,{disabled:u,value:g,onValueChange:o,children:[e.jsxRuntimeExports.jsx(e.SelectTrigger,{className:e.cn("h-9 w-full focus:ring-1 focus:ring-offset-0",c),children:e.jsxRuntimeExports.jsx(e.SelectValue,{placeholder:n?"Loading...":i?"Error":`Select ${s}`})}),e.jsxRuntimeExports.jsx(e.SelectContent,{children:e.jsxRuntimeExports.jsxs(e.SelectGroup,{children:[n?e.jsxRuntimeExports.jsx(e.SelectLabel,{children:"Loading..."}):e.jsxRuntimeExports.jsx(e.SelectLabel,{children:s}),e.jsxRuntimeExports.jsxs(e.jsxRuntimeExports.Fragment,{children:[a&&e.jsxRuntimeExports.jsx(e.SelectItem,{value:"none",children:"None"},"none"),r&&r.map((d,j)=>e.jsxRuntimeExports.jsx(e.SelectItem,{value:d.id,children:d.name},j))]}),(n||i)&&e.jsxRuntimeExports.jsx(e.SelectItem,{value:g,children:g})]})})]})]})}function Gs({column:s}){const[r,t]=v.useState(!1),n=e.useEditorStore(d=>d.selectedTableName),i=e.useEditorStore(d=>d.selectedSchemaName),l=e.useEditorStore(d=>d.selectedDatamodelId),o=e.useEditorStore(d=>d.sqlGen),{modelItems:a}=oe(),c=e.useEditorStore(d=>d.actions.setSqlGen),p=e.useEditorStore(d=>d.actions.setCardSql),u=e.useEditorStore(d=>d.actions.setRunSql);function g(d,j){var L;const x=e.createSqlGenConfig(d,o,j),N=(L=a==null?void 0:a.find(b=>b.id===l))==null?void 0:L.name;c(x);const I=e.getSql(x,e.fmt(i||""),e.fmt(n),N);I&&(p(I),u(!0)),t(!1)}function m(){return e.jsxRuntimeExports.jsxs("ul",{className:"text-xs",children:[e.jsxRuntimeExports.jsx("li",{onClick:()=>g(s,"COUNT"),className:"cursor-pointer p-1 px-3 transition-colors hover:bg-muted",children:"Count"}),e.jsxRuntimeExports.jsx("li",{onClick:()=>g(s,"AVG"),className:"cursor-pointer p-1 px-3 transition-colors hover:bg-muted",children:"Avg"}),e.jsxRuntimeExports.jsx("li",{onClick:()=>g(s,"SUM"),className:"cursor-pointer p-1 px-3 transition-colors hover:bg-muted",children:"Sum"}),e.jsxRuntimeExports.jsx("li",{onClick:()=>g(s,"MAX"),className:"cursor-pointer p-1 px-3 transition-colors hover:bg-muted",children:"Max"}),e.jsxRuntimeExports.jsx("li",{onClick:()=>g(s,"MIN"),className:"cursor-pointer p-1 px-3 transition-colors hover:bg-muted",children:"Min"})]})}return e.jsxRuntimeExports.jsxs(e.HoverCard,{openDelay:0,open:r,onOpenChange:t,children:[e.jsxRuntimeExports.jsx(e.HoverCardTrigger,{asChild:!0,children:e.jsxRuntimeExports.jsx(hs,{className:"invisible size-3.5 cursor-pointer text-foreground/40 group-hover:visible"})}),e.jsxRuntimeExports.jsx(e.HoverCardContent,{align:"center",className:"w-20 rounded-md p-0 shadow-none",children:m()})]})}function Ge({column:s}){return e.jsxRuntimeExports.jsxs(e.Tooltip,{children:[e.jsxRuntimeExports.jsx(e.$a093c7e1ec25a057$export$8c610744efcf8a1d,{asChild:!0,children:e.TEXT_DATA_TYPES.includes(s.data_type.toLowerCase())?e.jsxRuntimeExports.jsx(Le,{className:"size-3"}):e.NUMBER_DATA_TYPES.includes(s.data_type.toLowerCase())?e.jsxRuntimeExports.jsx(ys,{className:"size-3"}):e.DATE_DATA_TYPES.includes(s.data_type.toLowerCase())?e.jsxRuntimeExports.jsx(e.Calendar,{className:"size-3"}):e.BOOLEAN_DATA_TYPES.includes(s.data_type.toLowerCase())?e.jsxRuntimeExports.jsx(Ms,{className:"size-3"}):e.jsxRuntimeExports.jsx(As,{className:"size-3"})}),e.jsxRuntimeExports.jsx(e.TooltipContent,{children:e.jsxRuntimeExports.jsx("p",{className:"font-mono text-xs",children:s.data_type})})]})}function Us({schemaName:s,tableName:r,columns:t,status:n}){const i=e.useEditorStore(R=>R.sqlGen),l=e.useEditorStore(R=>R.selectedConnectionId),o=e.useEditorStore(R=>R.selectedDatabaseName),a=e.useEditorStore(R=>R.selectedSchemaName),c=e.useEditorStore(R=>R.selectedTableName),p=e.useEditorStore(R=>R.selectedDatamodelId),u=e.useDashboardStore(R=>R.dashboard.aiScopeTables),{setAIScopeTables:g}=e.useDashboardStore(R=>R.actions),m=e.useEditorStore(R=>R.actions.setRunSql),d=e.useEditorStore(R=>R.actions.setSqlGen),j=e.useEditorStore(R=>R.actions.setIsShowingVisual),x=e.useEditorStore(R=>R.actions.setCardSql),{connectionType:N,modelItems:I}=oe();function L(R){var F;const f=e.createSqlGenConfig(R,i);d(f);const z=(F=I==null?void 0:I.find(V=>V.id===p))==null?void 0:F.name,M=e.getSql(f,e.fmt(s),e.fmt(r),z);M&&(x(M),m(!0))}function b(){return(u==null?void 0:u.find(R=>R.connectinonId===l&&R.tableName===c))!==void 0}function D(R){if(R===!0&&c&&l){const f={connectinonId:l,connectionType:N,databaseName:o,schemaName:a,tableName:c},M=[...u||[],f].filter((F,V,P)=>P.findIndex(_=>_.connectinonId===F.connectinonId&&_.tableName===F.tableName)===V);g(M),e.Jt.success(`Added '${c}' to AI Scope`,{position:"top-right",duration:2500,richColors:!0})}else{const f=(u||[]).filter(z=>z.connectinonId!==l&&z.tableName!==c);g(f),e.Jt(`Removed '${c}' from AI Scope`,{position:"top-right",duration:2e3,richColors:!0})}}function T(){var F;let R=e.getQualifiedTableName(s,r);const f=(F=I==null?void 0:I.find(V=>V.id===p))==null?void 0:F.name;console.log("modelName",f),p&&p!=="none"&&(R=`${e.DATAMODEL_NAMESPCACE}.${f}`);let z=R;return(V=>/[A-Z]/.test(V))(r)&&(z=z.split(".").map(P=>`"${P}"`).join(".")),z}function E(){const R=T();j(!1);const f=N==="MSSQL"?`SELECT top 10 * FROM ${R}`:`SELECT * FROM ${R} LIMIT 10`;x(f),m(!0)}function S(){const R=T();x(`SELECT COUNT(*) as count FROM ${R}`),m(!0)}return e.jsxRuntimeExports.jsxs("div",{className:"flex grow flex-col space-y-4 px-4",children:[e.jsxRuntimeExports.jsxs("div",{className:"flex items-center justify-center gap-1",children:[e.jsxRuntimeExports.jsx(e.Toggle,{title:`${b()?"Remove from":"Add to"} AI Scope`,pressed:b(),onPressedChange:D,variant:"outline",className:"h-9 px-2",children:e.jsxRuntimeExports.jsx(e.Bot,{className:e.cn("size-4",{"text-primary":b(),"text-muted-foreground":!b()})})}),e.jsxRuntimeExports.jsxs(e.Button,{disabled:n!=="Success",onClick:E,size:"sm",variant:"secondary",className:"flex",children:[n!=="Success"?e.jsxRuntimeExports.jsx(le,{className:"mr-2 h-4 w-4 animate-spin text-foreground/50"}):e.jsxRuntimeExports.jsx(Fs,{className:"mr-2 size-4"}),"Top 10"]}),e.jsxRuntimeExports.jsxs(e.Button,{disabled:n!=="Success",onClick:S,size:"sm",variant:"secondary",className:"flex",children:[n!=="Success"?e.jsxRuntimeExports.jsx(le,{className:"mr-2 h-4 w-4 animate-spin text-foreground/50"}):e.jsxRuntimeExports.jsx(zs,{className:"mr-2 size-4"}),"Count"]})]}),e.jsxRuntimeExports.jsxs(e.ScrollArea,{className:"flex-1 basis-0 overflow-y-auto border-b border-t border-muted py-3",children:[t==null?void 0:t.map(R=>e.jsxRuntimeExports.jsxs("div",{onClick:()=>L(R),className:e.cn("group mx-3 flex cursor-pointer items-center justify-between rounded px-2 py-[6px] text-sm transition-colors hover:bg-muted/50",{"bg-muted":e.isColumnInSqlGen(R,i)}),children:[e.jsxRuntimeExports.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsxRuntimeExports.jsx(Ge,{column:R}),e.jsxRuntimeExports.jsx("span",{children:R.column_name})]}),e.jsxRuntimeExports.jsx("div",{onClick:f=>f.stopPropagation(),className:"flex items-center justify-end",children:e.NUMBER_DATA_TYPES.includes(R.data_type)&&e.jsxRuntimeExports.jsx(Gs,{column:R})})]},R.column_name)),e.jsxRuntimeExports.jsx(e.ScrollBar,{orientation:"vertical"}),e.jsxRuntimeExports.jsx(e.ScrollBar,{orientation:"horizontal"})]})]})}function oe(s,r){var me,ue,pe,je,h;let t=v.useMemo(()=>[],[]);const n=e.useSemaphorContext().authToken||s,i=e.useEditorStore(y=>y.selectedConnectionId),l=e.useEditorStore(y=>y.selectedDatamodelId),o=e.useEditorStore(y=>y.selectedDatabaseName),a=e.useEditorStore(y=>y.selectedSchemaName),c=e.useEditorStore(y=>y.selectedTableName),p=e.useEditorStore(y=>y.actions.setCurrentColumns),u=e.useEditorStore(y=>y.actions.setSelectedConnectionId),g=e.useEditorStore(y=>y.actions.setSelectedDatamodelId),m=e.useEditorStore(y=>y.actions.setSelectedDatabaseName),d=e.useEditorStore(y=>y.actions.setSelectedSchemaName),j=e.useEditorStore(y=>y.actions.setSelectedTableName),x=e.useEditorStore(y=>y.actions.setCardSql);function N(y){return i&&o&&a&&o!=="NA"?!0:i&&y==="API"?!1:!!(i&&y==="S3")}function I(y){return!!(i&&o&&o!=="NA"&&a&&c||i&&(y==="S3"||y==="API")||l&&l)}function L(y){return i&&y?!(y==="API"||y==="S3"):!1}const{data:b,isLoading:D,isError:T}=e.useQuery({queryKey:["connections"],queryFn:()=>e.getRequest("https://semaphor.cloud/api/v1/connections",(n==null?void 0:n.accessToken)||""),enabled:!!(n!=null&&n.accessToken)}),{data:E,isLoading:S,isError:R}=e.useQuery({queryKey:["models",i],queryFn:()=>e.getRequest("https://semaphor.cloud/api/v1/datamodels",(n==null?void 0:n.accessToken)||"",{connection_id:i}),enabled:!!(n!=null&&n.accessToken)&&!!i}),f=b==null?void 0:b.connections.find(y=>y.id===i),z=f==null?void 0:f.type,M=(f==null?void 0:f.type)==="API"||(f==null?void 0:f.type)==="S3",{data:F,isLoading:V,isFetching:P,isError:_,refetch:K}=e.useQuery({queryKey:["databases",i],queryFn:()=>e.getRequest("https://semaphor.cloud/api/v1/databases",(n==null?void 0:n.accessToken)||"",{connection_id:i}),enabled:L(z)}),{data:q,isLoading:W,isFetching:C,isError:A,refetch:H}=e.useQuery({queryKey:["schemas",i,o],queryFn:()=>e.getRequest("https://semaphor.cloud/api/v1/schemas",(n==null?void 0:n.accessToken)||"",{connection_id:i,database_name:o}),enabled:!!i&&!!o&&!M&&o!=="NA"}),{data:k,isLoading:w,isFetching:$,isError:O,refetch:G}=e.useQuery({queryKey:["tables",i,o,a],queryFn:()=>e.getRequest("https://semaphor.cloud/api/v1/tables",(n==null?void 0:n.accessToken)||"",{connection_id:i,database_name:o,schema_name:a}),enabled:N(z)}),{data:U,isLoading:te,isFetching:ee,isError:B}=e.useQuery({queryKey:["columns",i,o,l,a,c],queryFn:()=>e.getRequest("https://semaphor.cloud/api/v1/columns",(n==null?void 0:n.accessToken)||"",{connection_id:i,datamodel_id:l||"",database_name:o,schema_name:a,table_name:c}),enabled:I(z)});v.useEffect(()=>{p(t)},[U,p,t]),v.useEffect(()=>{},[M,x,j,d,m,f]);const J=(f==null?void 0:f.type)==="API"?(me=f==null?void 0:f.type)==null?void 0:me.toLowerCase():c||"",Y=M?"":a||"";function ne(y){d(y),j("")}function X(y){m(y==="none"?"":y),d(""),j(""),y!=="none"&&y!==""&&g("")}function se(y){u(y)}function Ae(y){g(y==="none"?"":y),y!=="none"&&y!==""&&m("")}F&&((ue=F==null?void 0:F.databases)==null?void 0:ue.length)>0,q&&((pe=q==null?void 0:q.schemas)==null?void 0:pe.length)>0,U&&((je=U==null?void 0:U.columns)==null?void 0:je.length)>0&&(t=U.columns.map(y=>({...y,data_type:y.data_type.toLowerCase()}))),_&&(t=[]),(B||T)&&(t=[]);const ie=b==null?void 0:b.connections.map(y=>({id:y.id,name:y.name,type:y.type})),be=(h=E==null?void 0:E.datamodels)==null?void 0:h.map(y=>({id:y.id,name:y.name})),de=F==null?void 0:F.databases.map(y=>({id:y.database_name,name:y.database_name})),ye=q==null?void 0:q.schemas.map(y=>({id:y.schema_name,name:y.schema_name})),Se=k==null?void 0:k.tables.map(y=>({id:y.table_name,name:y.table_name}));return{connectionItems:ie,isConnectionsLoading:D,isConnectionsError:T,modelItems:be,isModelsLoading:S,isModelsError:R,databaseItems:de,isDatabasesLoadingOrFetching:V||P,isDatabaseError:_,schemaItems:ye,isSchemaLoadingOrFetching:W||C,isSchemaError:A,tableItems:Se,isTableLoadingOrFetching:w||$,isTableError:O,columns:t,isColumnsLoadingOrFetching:te||ee,isColumnsError:B,isNonDbConnection:M,connectionType:z,tableName:J,schemaName:Y,handleConnectionChange:se,handleDatamodelChange:Ae,handleDatabaseChange:X,handleSchemaChange:ne}}function Ue({ColumnsComponent:s}){var $;const r=e.useEditorStore(O=>O.selectedConnectionId),t=e.useEditorStore(O=>O.selectedDatamodelId),n=e.useEditorStore(O=>O.selectedDatabaseName),i=e.useEditorStore(O=>O.selectedSchemaName),l=e.useEditorStore(O=>O.selectedTableName),o=e.useEditorStore(O=>O.actions.setSelectedTableName),{connectionItems:a,modelItems:c,schemaItems:p,databaseItems:u,tableItems:g,columns:m,isConnectionsLoading:d,isModelsLoading:j,isConnectionsError:x,isModelsError:N,isDatabasesLoadingOrFetching:I,isDatabaseError:L,isSchemaLoadingOrFetching:b,isSchemaError:D,isColumnsError:T,isColumnsLoadingOrFetching:E,isTableLoadingOrFetching:S,isTableError:R,connectionType:f,isNonDbConnection:z,handleConnectionChange:M,handleDatabaseChange:F,handleSchemaChange:V,handleDatamodelChange:P,tableName:_,schemaName:K}=oe();function q(){return s?s(K,_,m):e.jsxRuntimeExports.jsx(Us,{schemaName:K,tableName:_,columns:m,status:E?"Loading...":T?"Error":"Success"})}function W(){window.location.href="mailto:support@semaphor.cloud?subject=Help&body=I need help with..."}function C(){if(!r||f==="S3"||f==="API")return null;if(!t||t==="none")return e.jsxRuntimeExports.jsx(ae,{showNone:!0,onChange:F,isError:L,isLoading:I,items:u,value:n||"",title:"Database"})}function A(){if(r&&!z&&(!n||n==="none")&&(!t||t==="none"))return e.jsxRuntimeExports.jsxs("div",{className:"grid grid-cols-3",children:[e.jsxRuntimeExports.jsx("div",{className:"col-span-1 grid place-items-center",children:e.jsxRuntimeExports.jsx(e.Separator,{})}),e.jsxRuntimeExports.jsx("div",{className:"col-span-1 grid place-items-center",children:e.jsxRuntimeExports.jsx(e.Label,{children:"OR"})}),e.jsxRuntimeExports.jsx("div",{className:"col-span-1 grid place-items-center",children:e.jsxRuntimeExports.jsx(e.Separator,{})})]})}function H(){if(!r||f==="S3"||f==="API")return null;if(!n||n==="none")return e.jsxRuntimeExports.jsx(ae,{showNone:!0,onChange:P,isError:N,isLoading:j,items:c,value:t||"",title:"Model"})}function k(){return!r||f==="S3"||f==="API"||!n||n==="none"?null:e.jsxRuntimeExports.jsx(ae,{onChange:V,isError:D,isLoading:b,items:p,value:i||"",title:"Schema"})}function w(){function O(){let G=!1;return f==="API"?(G=!1,G):((f==="S3"||r&&n&&n!=="none"&&i)&&(G=!0),G)}return O()?e.jsxRuntimeExports.jsx(ae,{onChange:o,isError:R,items:g,isLoading:S,value:l||"",title:"Table"}):null}return e.jsxRuntimeExports.jsxs("aside",{className:"xbg-red-100 flex grow flex-col justify-between",children:[e.jsxRuntimeExports.jsxs("section",{className:"space-y-3 px-6 py-4",children:[e.jsxRuntimeExports.jsx(ae,{items:a,title:"Connection",value:r||"",onChange:M,isLoading:d,isError:x,connectionTooltip:(($=a==null?void 0:a.find(O=>O.id===r))==null?void 0:$.type)||""}),H(),A(),C(),k(),w()]}),q(),e.jsxRuntimeExports.jsx("div",{className:"flex items-end justify-center gap-2 px-6 py-4",children:e.jsxRuntimeExports.jsxs(e.Button,{onClick:W,size:"sm",variant:"secondary",className:"w-full",children:[e.jsxRuntimeExports.jsx(ks,{className:"mr-2 size-4"}),"Help"]})})]})}function Qs(s){const r=s.toUpperCase().indexOf("WHERE"),t=s.toUpperCase().indexOf("GROUP BY"),n=s.toUpperCase().indexOf("LIMIT"),i=s.toUpperCase().indexOf("ORDER BY");let l=s.length;if(i!==-1&&(l=i),n!==-1&&n<l&&(l=n),r!==-1){const o=s.substring(0,r),a=s.substring(r);return`${o} {{ filters | where }} AND ${a.substring(6)}`}else if(t!==-1){const o=s.substring(0,t),a=s.substring(t);return`${o} {{ filters | where }} ${a}`}else{const o=s.substring(0,l),a=s.substring(l);return`${o} {{ filters | where }} ${a}`}}function Ks({error:s,setShowAIDialog:r,setUserInputforAI:t,setTriggerAIRun:n}){return e.jsxRuntimeExports.jsxs(e.HoverCard,{openDelay:0,children:[e.jsxRuntimeExports.jsx(e.HoverCardTrigger,{asChild:!0,children:e.jsxRuntimeExports.jsx(e.Button,{variant:"link",className:"h-5 p-0",children:e.jsxRuntimeExports.jsx(ms,{className:"h-4 w-4 text-red-500"})})}),e.jsxRuntimeExports.jsx(e.HoverCardContent,{align:"start",className:"min-w-fit max-w-[500px]",children:e.jsxRuntimeExports.jsx("div",{className:"flex justify-between space-x-4",children:e.jsxRuntimeExports.jsxs("div",{className:"flex grow flex-col space-y-2",children:[e.jsxRuntimeExports.jsx(e.ScrollArea,{className:"max-h-[250px] min-h-0 overflow-scroll",children:e.jsxRuntimeExports.jsx("p",{className:"overflow-auto rounded-md bg-muted p-2 text-xs leading-relaxed",children:s})}),e.jsxRuntimeExports.jsxs(e.Button,{onClick:()=>{r(!0),t(s),n(!0)},size:"sm",variant:"outline",children:[e.jsxRuntimeExports.jsx(bs,{className:"mr-2 h-4 w-4"}),"Debug with AI"]})]})})})]})}function Ws({text:s,onCheckedChange:r,checked:t}){return e.jsxRuntimeExports.jsxs("div",{className:"xbg-red-100 ml-6 flex items-center gap-2",children:[e.jsxRuntimeExports.jsx(e.Checkbox,{checked:t,onCheckedChange:r}),e.jsxRuntimeExports.jsx("label",{className:"text-xs leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70",children:s})]})}function Js(){const{authToken:s}=e.useSemaphorContext(),r=e.useEditorStore(l=>l.selectedConnectionId),{data:t}=e.useQuery({queryKey:["connections"],queryFn:()=>e.getRequest("https://semaphor.cloud/api/v1/connections",(s==null?void 0:s.accessToken)||""),enabled:!!(s!=null&&s.accessToken)}),n=t==null?void 0:t.connections.find(l=>l.id===r);return n==null?void 0:n.type}function Ys(){const{authToken:s}=e.useSemaphorContext(),r=v.useRef(null),t=e.useEditorStore(c=>c.applyFilters),[n,i]=v.useState(""),l=e.useEditorStore(c=>c.filterValues),o=e.useEditorStore(c=>c.card.sql),a=Js();return e.jsxRuntimeExports.jsxs(e.HoverCard,{openDelay:0,onOpenChange:async c=>{if(!c)return;console.log("onOpenChange");const p=await e.postRequest("https://semaphor.cloud/api/v1/filter-sql",(s==null?void 0:s.accessToken)||"",{sql:o,active_filters:l,connection_type:a});console.log(p),p.sql?(console.log(p.records),i(p.sql)):i("Error")},children:[e.jsxRuntimeExports.jsx(e.HoverCardTrigger,{asChild:!0,children:t&&e.jsxRuntimeExports.jsx("p",{className:"p-0 text-xs hover:cursor-pointer",children:"|  Filter Query"})}),e.jsxRuntimeExports.jsxs(e.HoverCardContent,{align:"end",className:"w-[600px]",children:[e.jsxRuntimeExports.jsx("div",{className:"flex justify-between space-x-4",children:e.jsxRuntimeExports.jsx("div",{className:"rounded-sm bg-muted p-2",children:e.jsxRuntimeExports.jsxs("code",{ref:r,className:"font-mono text-sm",children:[n,e.jsxRuntimeExports.jsx(e.ClipboardCopyIcon,{onClick:()=>e.copyToClipboard(r),className:"ml-3 inline-block h-4 w-4 opacity-70 hover:cursor-pointer hover:opacity-100"})]})})}),e.jsxRuntimeExports.jsxs("div",{className:"flex items-center gap-2 pt-2",children:[e.jsxRuntimeExports.jsx(e.InfoCircledIcon,{className:"h-4 w-4 opacity-70"}),e.jsxRuntimeExports.jsx("span",{className:"text-xs text-muted-foreground",children:"A preview of the query with filters applied."})]})]})]})}const Xs=`
191
+ */const Vs=e.createLucideIcon("User",[["path",{d:"M19 21v-2a4 4 0 0 0-4-4H9a4 4 0 0 0-4 4v2",key:"975kel"}],["circle",{cx:"12",cy:"7",r:"4",key:"17ys0d"}]]);function De(s){var r;return{...s,sheets:(r=s==null?void 0:s.sheets)==null?void 0:r.map(t=>{var n;return{...t,frames:(n=t.frames)==null?void 0:n.map(i=>{var l;return{...i,cards:(l=i.cards)==null?void 0:l.map(o=>$e(o))}})}})}}function $e(s){var r,t,n,i;return{...s,cfg:{...s.cfg,data:{...(r=s.cfg)==null?void 0:r.data,labels:[],datasets:(i=(n=(t=s.cfg)==null?void 0:t.data)==null?void 0:n.datasets)==null?void 0:i.map(l=>({...l,data:[]}))}},customCfg:qs(s.customCfg),data:[]}}function qs(s){var r,t;return s?{...s,data:{...s==null?void 0:s.data,labels:[],datasets:(t=(r=s==null?void 0:s.data)==null?void 0:r.datasets)==null?void 0:t.map(n=>({...n,data:[]}))}}:null}async function _s(s,r,t,n){if(!n)return null;const i=JSON.stringify(r),l="https://semaphor.cloud/api/v1/lens";return await e.postRequest(l,n,{name:s,template:i,filterValues:t,operation:"create"})}async function we(s,r){if(!r)return null;const{id:t,template:n,filterValues:i,isDefault:l,shared:o}=s,a="https://semaphor.cloud/api/v1/lens";return await e.postRequest(a,r,{lensId:t,template:n,filterValues:i,isDefault:l,shared:o,operation:"update"})}async function Bs(s,r){if(!r)return null;const t="https://semaphor.cloud/api/v1/lens";return await e.postRequest(t,r,{operation:"delete",lensId:s})}function Hs(){const[s,r]=v.useState(""),[t,n]=v.useState(!1),i=e.useDashboardStore(x=>x.lenses),{setLenses:l,setSelectedLensId:o}=e.useDashboardActions(),[a,c]=v.useState(!1),[p,u]=v.useState(!1),g=e.useDashboardStore(x=>x.dashboard),m=e.useDashboardStore(x=>x.filterValues),{authToken:d}=e.useSemaphorContext();async function j(){c(!0);const x=De(g),N=await _s(s,x,m,d==null?void 0:d.accessToken);N&&(l([...i||[],N]),o(N.id),u(!1)),c(!1)}return e.jsxRuntimeExports.jsxs(e.Dialog,{open:p,onOpenChange:u,children:[e.jsxRuntimeExports.jsx(e.DialogTrigger,{asChild:!0,children:e.jsxRuntimeExports.jsxs(e.Button,{variant:"secondary",className:"h-7 p-2",size:"sm",children:[e.jsxRuntimeExports.jsx(e.Plus,{className:"mr-2 h-4 w-4",strokeWidth:1.5}),"Lens"]})}),e.jsxRuntimeExports.jsxs(e.DialogContent,{className:"sm:max-w-[425px]",children:[e.jsxRuntimeExports.jsxs(e.DialogHeader,{children:[e.jsxRuntimeExports.jsx(e.DialogTitle,{children:"Create Lens"}),e.jsxRuntimeExports.jsx(e.DialogDescription,{children:"Lenses are private by default and are only visible to you."})]}),e.jsxRuntimeExports.jsx("div",{className:"grid gap-4 py-4",children:e.jsxRuntimeExports.jsxs("div",{className:"grid grid-cols-8 items-center gap-4",children:[e.jsxRuntimeExports.jsx(e.Label,{className:"text-right",children:"Name"}),e.jsxRuntimeExports.jsx(e.Input,{value:s,onChange:x=>{r(x.target.value)},id:"name",className:"col-span-7 focus-visible:ring-0 focus-visible:ring-ring focus-visible:ring-offset-0"})]})}),t&&e.jsxRuntimeExports.jsx("p",{className:"text-sm",children:"The lens name already exists. Use a differnet name."}),e.jsxRuntimeExports.jsx(e.DialogFooter,{children:e.jsxRuntimeExports.jsx(e.Button,{size:"sm",variant:"outline",type:"submit",onClick:j,disabled:a,children:a?"Creating...":"Add"})})]})]})}function Ps(){const[s,r]=v.useState(!1),t=e.useDashboardStore(u=>u.lenses),n=e.useDashboardStore(u=>u.selectedLensId),{setLenses:i,setSelectedLensId:l}=e.useDashboardActions(),{authToken:o}=e.useSemaphorContext();async function a(u){l(u)}async function c(u){if(await Bs(u,o==null?void 0:o.accessToken)){const m=t==null?void 0:t.filter(d=>d.id!==u);i(m||[]),l("original")}}async function p(u){const g=t==null?void 0:t.map(j=>j.id===u.id?{...j,isDefault:!u.isDefault}:{...j,isDefault:!1});i(g||[]);const m={...u,isDefault:!u.isDefault};await we(m,o==null?void 0:o.accessToken);const d=t==null?void 0:t.find(j=>j.isDefault);if(d&&d.id!==u.id){const j={...d,isDefault:!1};await we(j,o==null?void 0:o.accessToken)}}return e.jsxRuntimeExports.jsxs(e.DropdownMenu,{open:s,onOpenChange:r,children:[e.jsxRuntimeExports.jsx(e.DropdownMenuTrigger,{asChild:!0,children:e.jsxRuntimeExports.jsx(e.Button,{variant:"ghost",className:"h-7 p-2",children:e.jsxRuntimeExports.jsx(Rs,{className:"h-4 w-4",strokeWidth:1.5})})}),e.jsxRuntimeExports.jsxs(e.DropdownMenuContent,{align:"end",className:"w-60",children:[e.jsxRuntimeExports.jsx(e.DropdownMenuLabel,{className:"px-3",children:"Lenses"}),e.jsxRuntimeExports.jsx(e.DropdownMenuSeparator,{}),e.jsxRuntimeExports.jsxs(e.DropdownMenuRadioGroup,{value:n,onValueChange:a,children:[e.jsxRuntimeExports.jsx(e.DropdownMenuRadioItem,{value:"original",children:"Original"}),t==null?void 0:t.map(u=>e.jsxRuntimeExports.jsxs(e.DropdownMenuRadioItem,{className:"group flex justify-between gap-2",value:u.id,children:[e.jsxRuntimeExports.jsx("p",{children:u.name}),e.jsxRuntimeExports.jsxs("span",{className:"flex items-center gap-3",children:[e.jsxRuntimeExports.jsx(Ss,{onClick:g=>{g.preventDefault(),p(u)},className:e.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.jsxRuntimeExports.jsx(e.Cross2Icon,{onClick:g=>{g.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 $s(){const{authToken:s}=e.useSemaphorContext(),r=e.useDashboardStore(f=>f.lenses),t=e.useDashboardStore(f=>f.selectedLensId),n=r==null?void 0:r.find(f=>f.id===t),i=e.useDashboardStore(f=>f.dashboard);e.useDashboardStore(f=>f.selectedSheetId);const l=e.useDashboardStore(f=>f.isDashboardEditing),[o,a]=v.useState(!1),c=e.useDashboardStore(f=>f.filterValues),p=e.useDashboardStore(f=>f.isVisualEditing),u=e.useDashboardStore(f=>f.showFilters);e.useDashboardStore(f=>f.showDashboardJSON);const g=e.useDashboardStore(f=>f.onSaveFunction),m=e.useDashboardStore(f=>f.actions.setShowFilters),{addFrame:d,setSelectedFrameId:j}=e.useDashboardStore(f=>f.actions),{getSelectedSheet:x,setIsDashboardEditing:N,setShowDashboardJSON:I}=e.useDashboardStore(f=>f.actions),L=x(),{tenantId:b,endUserId:D}=v.useMemo(()=>e.getTenantAndEndUserId(s==null?void 0:s.accessToken),[s==null?void 0:s.accessToken]),T=v.useMemo(()=>b||D,[b,D]),E=()=>{if(!l||!L)return;const f={id:e.v4(),title:"Title",description:"Description",preferences:{onClickFilter:[{columnIndex:0,expression:""}]},type:"bar",sql:"select COUNT(*) from YOUR_TABLE",data:[]},z={id:e.v4(),cards:[f],activeCardId:f.id};d(L.id,z),j(z.id)},S=()=>{N(!0)};async function R(){if(a(!0),!t||!n)return;const f=De(i),z=JSON.stringify(f),M={...n,template:z,filterValues:c};await we(M,s==null?void 0:s.accessToken),e.Jt.success("Lens saved"),g==null||g(f),a(!1)}return p?null:e.jsxRuntimeExports.jsxs("div",{className:"flex items-center justify-between gap-2 border-b bg-muted/50 py-2 pl-3 pr-2",role:"dashboard-controls",children:[!p&&e.jsxRuntimeExports.jsx("div",{className:"flex items-center gap-3",children:e.jsxRuntimeExports.jsx(e.Label,{children:n==null?void 0:n.name})}),e.jsxRuntimeExports.jsxs("div",{className:"flex gap-2",children:[l&&!p&&T&&e.jsxRuntimeExports.jsx(Hs,{}),!p&&T&&e.jsxRuntimeExports.jsx(Ps,{}),l&&!p&&e.jsxRuntimeExports.jsxs(e.Button,{variant:"secondary",className:"h-7 p-2",size:"sm",disabled:!l,onClick:E,children:[e.jsxRuntimeExports.jsx(e.Plus,{className:"mr-2 h-4 w-4",strokeWidth:1.5}),"Frame"]}),!l&&e.jsxRuntimeExports.jsx(e.Button,{variant:"ghost",className:"h-7 p-2",onClick:S,size:"sm",children:e.jsxRuntimeExports.jsx(He,{className:"h-4 w-4",strokeWidth:1.5})}),l&&!p&&e.jsxRuntimeExports.jsx(e.Button,{variant:"ghost",role:"close",className:"h-7 p-2",onClick:()=>{N(!1),I(!1)},size:"sm",children:e.jsxRuntimeExports.jsx(e.Cross2Icon,{className:"h-4 w-4",strokeWidth:1.5})}),l&&!p&&T&&e.jsxRuntimeExports.jsx(e.Button,{className:"h-7 p-2",variant:"ghost",disabled:o,onClick:R,size:"sm",children:e.jsxRuntimeExports.jsx(Ts,{className:"h-4 w-4",strokeWidth:1.5})}),!u&&!p&&l&&e.jsxRuntimeExports.jsx(e.Button,{className:"h-7 p-2",variant:"ghost",onClick:()=>m(!0),size:"sm",children:e.jsxRuntimeExports.jsx(e.Filter,{className:"h-4 w-4",strokeWidth:1.5})}),!p&&l&&!1,!p&&!1]})]})}function ae({title:s,items:r,value:t,isLoading:n,isError:i,connectionTooltip:l,onChange:o,showNone:a=!1,className:c,showIcon:p=!0,disabled:u=!1}){const g=n?"Loading...":i?"Error":t;function m(){if(s==="Connection")return e.jsxRuntimeExports.jsx(Ds,{className:"size-4 rotate-90"});if(s==="Database")return e.jsxRuntimeExports.jsx(js,{className:"size-4"});if(s==="Schema")return e.jsxRuntimeExports.jsx(Is,{className:"size-4"});if(s==="Table")return e.jsxRuntimeExports.jsx(e.Table,{className:"size-4"});if(s==="Model")return e.jsxRuntimeExports.jsx(xs,{className:"size-4"})}return e.jsxRuntimeExports.jsxs("div",{className:"flex items-center gap-2",children:[p&&e.jsxRuntimeExports.jsx("div",{className:"shrink-0",children:l?e.jsxRuntimeExports.jsxs(e.Tooltip,{children:[e.jsxRuntimeExports.jsx(e.TooltipTrigger,{children:m()}),e.jsxRuntimeExports.jsx(e.TooltipContent,{className:"text-xs",align:"start",children:l})]}):m()}),e.jsxRuntimeExports.jsxs(e.Select,{disabled:u,value:g,onValueChange:o,children:[e.jsxRuntimeExports.jsx(e.SelectTrigger,{className:e.cn("h-9 w-full focus:ring-1 focus:ring-offset-0",c),children:e.jsxRuntimeExports.jsx(e.SelectValue,{placeholder:n?"Loading...":i?"Error":`Select ${s}`})}),e.jsxRuntimeExports.jsx(e.SelectContent,{children:e.jsxRuntimeExports.jsxs(e.SelectGroup,{children:[n?e.jsxRuntimeExports.jsx(e.SelectLabel,{children:"Loading..."}):e.jsxRuntimeExports.jsx(e.SelectLabel,{children:s}),e.jsxRuntimeExports.jsxs(e.jsxRuntimeExports.Fragment,{children:[a&&e.jsxRuntimeExports.jsx(e.SelectItem,{value:"none",children:"None"},"none"),r&&r.map((d,j)=>e.jsxRuntimeExports.jsx(e.SelectItem,{value:d.id,children:d.name},j))]}),(n||i)&&e.jsxRuntimeExports.jsx(e.SelectItem,{value:g,children:g})]})})]})]})}function Gs({column:s}){const[r,t]=v.useState(!1),n=e.useEditorStore(d=>d.selectedTableName),i=e.useEditorStore(d=>d.selectedSchemaName),l=e.useEditorStore(d=>d.selectedDatamodelId),o=e.useEditorStore(d=>d.sqlGen),{modelItems:a}=oe(),c=e.useEditorStore(d=>d.actions.setSqlGen),p=e.useEditorStore(d=>d.actions.setCardSql),u=e.useEditorStore(d=>d.actions.setRunSql);function g(d,j){var L;const x=e.createSqlGenConfig(d,o,j),N=(L=a==null?void 0:a.find(b=>b.id===l))==null?void 0:L.name;c(x);const I=e.getSql(x,e.fmt(i||""),e.fmt(n),N);I&&(p(I),u(!0)),t(!1)}function m(){return e.jsxRuntimeExports.jsxs("ul",{className:"text-xs",children:[e.jsxRuntimeExports.jsx("li",{onClick:()=>g(s,"COUNT"),className:"cursor-pointer p-1 px-3 transition-colors hover:bg-muted",children:"Count"}),e.jsxRuntimeExports.jsx("li",{onClick:()=>g(s,"AVG"),className:"cursor-pointer p-1 px-3 transition-colors hover:bg-muted",children:"Avg"}),e.jsxRuntimeExports.jsx("li",{onClick:()=>g(s,"SUM"),className:"cursor-pointer p-1 px-3 transition-colors hover:bg-muted",children:"Sum"}),e.jsxRuntimeExports.jsx("li",{onClick:()=>g(s,"MAX"),className:"cursor-pointer p-1 px-3 transition-colors hover:bg-muted",children:"Max"}),e.jsxRuntimeExports.jsx("li",{onClick:()=>g(s,"MIN"),className:"cursor-pointer p-1 px-3 transition-colors hover:bg-muted",children:"Min"})]})}return e.jsxRuntimeExports.jsxs(e.HoverCard,{openDelay:0,open:r,onOpenChange:t,children:[e.jsxRuntimeExports.jsx(e.HoverCardTrigger,{asChild:!0,children:e.jsxRuntimeExports.jsx(hs,{className:"invisible size-3.5 cursor-pointer text-foreground/40 group-hover:visible"})}),e.jsxRuntimeExports.jsx(e.HoverCardContent,{align:"center",className:"w-20 rounded-md p-0 shadow-none",children:m()})]})}function Ge({column:s}){return e.jsxRuntimeExports.jsxs(e.Tooltip,{children:[e.jsxRuntimeExports.jsx(e.$a093c7e1ec25a057$export$8c610744efcf8a1d,{asChild:!0,children:e.TEXT_DATA_TYPES.includes(s.data_type.toLowerCase())?e.jsxRuntimeExports.jsx(Le,{className:"size-3"}):e.NUMBER_DATA_TYPES.includes(s.data_type.toLowerCase())?e.jsxRuntimeExports.jsx(ys,{className:"size-3"}):e.DATE_DATA_TYPES.includes(s.data_type.toLowerCase())?e.jsxRuntimeExports.jsx(e.Calendar,{className:"size-3"}):e.BOOLEAN_DATA_TYPES.includes(s.data_type.toLowerCase())?e.jsxRuntimeExports.jsx(Ms,{className:"size-3"}):e.jsxRuntimeExports.jsx(As,{className:"size-3"})}),e.jsxRuntimeExports.jsx(e.TooltipContent,{children:e.jsxRuntimeExports.jsx("p",{className:"font-mono text-xs",children:s.data_type})})]})}function Us({schemaName:s,tableName:r,columns:t,status:n}){const i=e.useEditorStore(R=>R.sqlGen),l=e.useEditorStore(R=>R.selectedConnectionId),o=e.useEditorStore(R=>R.selectedDatabaseName),a=e.useEditorStore(R=>R.selectedSchemaName),c=e.useEditorStore(R=>R.selectedTableName),p=e.useEditorStore(R=>R.selectedDatamodelId),u=e.useDashboardStore(R=>R.dashboard.aiScopeTables),{setAIScopeTables:g}=e.useDashboardStore(R=>R.actions),m=e.useEditorStore(R=>R.actions.setRunSql),d=e.useEditorStore(R=>R.actions.setSqlGen),j=e.useEditorStore(R=>R.actions.setIsShowingVisual),x=e.useEditorStore(R=>R.actions.setCardSql),{connectionType:N,modelItems:I}=oe();function L(R){var F;const f=e.createSqlGenConfig(R,i);d(f);const z=(F=I==null?void 0:I.find(V=>V.id===p))==null?void 0:F.name,M=e.getSql(f,e.fmt(s),e.fmt(r),z);M&&(x(M),m(!0))}function b(){return(u==null?void 0:u.find(R=>R.connectinonId===l&&R.tableName===c))!==void 0}function D(R){if(R===!0&&c&&l){const f={connectinonId:l,connectionType:N,databaseName:o,schemaName:a,tableName:c},M=[...u||[],f].filter((F,V,P)=>P.findIndex(_=>_.connectinonId===F.connectinonId&&_.tableName===F.tableName)===V);g(M),e.Jt.success(`Added '${c}' to AI Scope`,{position:"top-right",duration:2500,richColors:!0})}else{const f=(u||[]).filter(z=>z.connectinonId!==l&&z.tableName!==c);g(f),e.Jt(`Removed '${c}' from AI Scope`,{position:"top-right",duration:2e3,richColors:!0})}}function T(){var F;let R=e.getQualifiedTableName(s,r);const f=(F=I==null?void 0:I.find(V=>V.id===p))==null?void 0:F.name;console.log("modelName",f),p&&p!=="none"&&(R=`${e.DATAMODEL_NAMESPCACE}.${f}`);let z=R;return(V=>/[A-Z]/.test(V))(r)&&(z=z.split(".").map(P=>`"${P}"`).join(".")),z}function E(){const R=T();j(!1);const f=N==="MSSQL"?`SELECT top 10 * FROM ${R}`:`SELECT * FROM ${R} LIMIT 10`;x(f),m(!0)}function S(){const R=T();x(`SELECT COUNT(*) as count FROM ${R}`),m(!0)}return e.jsxRuntimeExports.jsxs("div",{className:"flex grow flex-col space-y-4 px-4",children:[e.jsxRuntimeExports.jsxs("div",{className:"flex items-center justify-center gap-1",children:[e.jsxRuntimeExports.jsx(e.Toggle,{title:`${b()?"Remove from":"Add to"} AI Scope`,pressed:b(),onPressedChange:D,variant:"outline",className:"h-9 px-2",children:e.jsxRuntimeExports.jsx(e.Bot,{className:e.cn("size-4",{"text-primary":b(),"text-muted-foreground":!b()})})}),e.jsxRuntimeExports.jsxs(e.Button,{disabled:n!=="Success",onClick:E,size:"sm",variant:"secondary",className:"flex",children:[n!=="Success"?e.jsxRuntimeExports.jsx(le,{className:"mr-2 h-4 w-4 animate-spin text-foreground/50"}):e.jsxRuntimeExports.jsx(Fs,{className:"mr-2 size-4"}),"Top 10"]}),e.jsxRuntimeExports.jsxs(e.Button,{disabled:n!=="Success",onClick:S,size:"sm",variant:"secondary",className:"flex",children:[n!=="Success"?e.jsxRuntimeExports.jsx(le,{className:"mr-2 h-4 w-4 animate-spin text-foreground/50"}):e.jsxRuntimeExports.jsx(zs,{className:"mr-2 size-4"}),"Count"]})]}),e.jsxRuntimeExports.jsxs(e.ScrollArea,{className:"flex-1 basis-0 overflow-y-auto border-b border-t border-muted py-3",children:[t==null?void 0:t.map(R=>e.jsxRuntimeExports.jsxs("div",{onClick:()=>L(R),className:e.cn("group mx-3 flex cursor-pointer items-center justify-between rounded px-2 py-[6px] text-sm transition-colors hover:bg-muted/50",{"bg-muted":e.isColumnInSqlGen(R,i)}),children:[e.jsxRuntimeExports.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsxRuntimeExports.jsx(Ge,{column:R}),e.jsxRuntimeExports.jsx("span",{children:R.column_name})]}),e.jsxRuntimeExports.jsx("div",{onClick:f=>f.stopPropagation(),className:"flex items-center justify-end",children:e.NUMBER_DATA_TYPES.includes(R.data_type)&&e.jsxRuntimeExports.jsx(Gs,{column:R})})]},R.column_name)),e.jsxRuntimeExports.jsx(e.ScrollBar,{orientation:"vertical"}),e.jsxRuntimeExports.jsx(e.ScrollBar,{orientation:"horizontal"})]})]})}function oe(s,r){var me,ue,pe,je,h;let t=v.useMemo(()=>[],[]);const n=e.useSemaphorContext().authToken||s,i=e.useEditorStore(y=>y.selectedConnectionId),l=e.useEditorStore(y=>y.selectedDatamodelId),o=e.useEditorStore(y=>y.selectedDatabaseName),a=e.useEditorStore(y=>y.selectedSchemaName),c=e.useEditorStore(y=>y.selectedTableName),p=e.useEditorStore(y=>y.actions.setCurrentColumns),u=e.useEditorStore(y=>y.actions.setSelectedConnectionId),g=e.useEditorStore(y=>y.actions.setSelectedDatamodelId),m=e.useEditorStore(y=>y.actions.setSelectedDatabaseName),d=e.useEditorStore(y=>y.actions.setSelectedSchemaName),j=e.useEditorStore(y=>y.actions.setSelectedTableName),x=e.useEditorStore(y=>y.actions.setCardSql);function N(y){return i&&o&&a&&o!=="NA"?!0:i&&y==="API"?!1:!!(i&&y==="S3")}function I(y){return!!(i&&o&&o!=="NA"&&a&&c||i&&(y==="S3"||y==="API")||l&&l)}function L(y){return i&&y?!(y==="API"||y==="S3"):!1}const{data:b,isLoading:D,isError:T}=e.useQuery({queryKey:["connections"],queryFn:()=>e.getRequest("https://semaphor.cloud/api/v1/connections",(n==null?void 0:n.accessToken)||""),enabled:!!(n!=null&&n.accessToken)}),{data:E,isLoading:S,isError:R}=e.useQuery({queryKey:["models",i],queryFn:()=>e.getRequest("https://semaphor.cloud/api/v1/datamodels",(n==null?void 0:n.accessToken)||"",{connection_id:i}),enabled:!!(n!=null&&n.accessToken)&&!!i}),f=b==null?void 0:b.connections.find(y=>y.id===i),z=f==null?void 0:f.type,M=(f==null?void 0:f.type)==="API"||(f==null?void 0:f.type)==="S3",{data:F,isLoading:V,isFetching:P,isError:_,refetch:K}=e.useQuery({queryKey:["databases",i],queryFn:()=>e.getRequest("https://semaphor.cloud/api/v1/databases",(n==null?void 0:n.accessToken)||"",{connection_id:i}),enabled:L(z)}),{data:q,isLoading:W,isFetching:C,isError:A,refetch:H}=e.useQuery({queryKey:["schemas",i,o],queryFn:()=>e.getRequest("https://semaphor.cloud/api/v1/schemas",(n==null?void 0:n.accessToken)||"",{connection_id:i,database_name:o}),enabled:!!i&&!!o&&!M&&o!=="NA"}),{data:k,isLoading:w,isFetching:$,isError:O,refetch:G}=e.useQuery({queryKey:["tables",i,o,a],queryFn:()=>e.getRequest("https://semaphor.cloud/api/v1/tables",(n==null?void 0:n.accessToken)||"",{connection_id:i,database_name:o,schema_name:a}),enabled:N(z)}),{data:U,isLoading:te,isFetching:ee,isError:B}=e.useQuery({queryKey:["columns",i,o,l,a,c],queryFn:()=>e.getRequest("https://semaphor.cloud/api/v1/columns",(n==null?void 0:n.accessToken)||"",{connection_id:i,datamodel_id:l||"",database_name:o,schema_name:a,table_name:c}),enabled:I(z)});v.useEffect(()=>{p(t)},[U,p,t]),v.useEffect(()=>{},[M,x,j,d,m,f]);const J=(f==null?void 0:f.type)==="API"?(me=f==null?void 0:f.type)==null?void 0:me.toLowerCase():c||"",Y=M?"":a||"";function ne(y){d(y),j("")}function X(y){m(y==="none"?"":y),d(""),j(""),y!=="none"&&y!==""&&g("")}function se(y){u(y)}function Ae(y){g(y==="none"?"":y),y!=="none"&&y!==""&&m("")}F&&((ue=F==null?void 0:F.databases)==null?void 0:ue.length)>0,q&&((pe=q==null?void 0:q.schemas)==null?void 0:pe.length)>0,U&&((je=U==null?void 0:U.columns)==null?void 0:je.length)>0&&(t=U.columns.map(y=>({...y,data_type:y.data_type.toLowerCase()}))),_&&(t=[]),(B||T)&&(t=[]);const ie=b==null?void 0:b.connections.map(y=>({id:y.id,name:y.name,type:y.type})),be=(h=E==null?void 0:E.datamodels)==null?void 0:h.map(y=>({id:y.id,name:y.name})),de=F==null?void 0:F.databases.map(y=>({id:y.database_name,name:y.database_name})),ye=q==null?void 0:q.schemas.map(y=>({id:y.schema_name,name:y.schema_name})),Se=k==null?void 0:k.tables.map(y=>({id:y.table_name,name:y.table_name}));return{connectionItems:ie,isConnectionsLoading:D,isConnectionsError:T,modelItems:be,isModelsLoading:S,isModelsError:R,databaseItems:de,isDatabasesLoadingOrFetching:V||P,isDatabaseError:_,schemaItems:ye,isSchemaLoadingOrFetching:W||C,isSchemaError:A,tableItems:Se,isTableLoadingOrFetching:w||$,isTableError:O,columns:t,isColumnsLoadingOrFetching:te||ee,isColumnsError:B,isNonDbConnection:M,connectionType:z,tableName:J,schemaName:Y,handleConnectionChange:se,handleDatamodelChange:Ae,handleDatabaseChange:X,handleSchemaChange:ne}}function Ue({ColumnsComponent:s}){var $;const r=e.useEditorStore(O=>O.selectedConnectionId),t=e.useEditorStore(O=>O.selectedDatamodelId),n=e.useEditorStore(O=>O.selectedDatabaseName),i=e.useEditorStore(O=>O.selectedSchemaName),l=e.useEditorStore(O=>O.selectedTableName),o=e.useEditorStore(O=>O.actions.setSelectedTableName),{connectionItems:a,modelItems:c,schemaItems:p,databaseItems:u,tableItems:g,columns:m,isConnectionsLoading:d,isModelsLoading:j,isConnectionsError:x,isModelsError:N,isDatabasesLoadingOrFetching:I,isDatabaseError:L,isSchemaLoadingOrFetching:b,isSchemaError:D,isColumnsError:T,isColumnsLoadingOrFetching:E,isTableLoadingOrFetching:S,isTableError:R,connectionType:f,isNonDbConnection:z,handleConnectionChange:M,handleDatabaseChange:F,handleSchemaChange:V,handleDatamodelChange:P,tableName:_,schemaName:K}=oe();function q(){return s?s(K,_,m):e.jsxRuntimeExports.jsx(Us,{schemaName:K,tableName:_,columns:m,status:E?"Loading...":T?"Error":"Success"})}function W(){window.location.href="mailto:support@semaphor.cloud?subject=Help&body=I need help with..."}function C(){if(!r||f==="S3"||f==="API")return null;if(!t||t==="none")return e.jsxRuntimeExports.jsx(ae,{showNone:!0,onChange:F,isError:L,isLoading:I,items:u,value:n||"",title:"Database"})}function A(){if(r&&!z&&(!n||n==="none")&&(!t||t==="none"))return e.jsxRuntimeExports.jsxs("div",{className:"grid grid-cols-3",children:[e.jsxRuntimeExports.jsx("div",{className:"col-span-1 grid place-items-center",children:e.jsxRuntimeExports.jsx(e.Separator,{})}),e.jsxRuntimeExports.jsx("div",{className:"col-span-1 grid place-items-center",children:e.jsxRuntimeExports.jsx(e.Label,{children:"OR"})}),e.jsxRuntimeExports.jsx("div",{className:"col-span-1 grid place-items-center",children:e.jsxRuntimeExports.jsx(e.Separator,{})})]})}function H(){if(!r||f==="S3"||f==="API")return null;if(!n||n==="none")return e.jsxRuntimeExports.jsx(ae,{showNone:!0,onChange:P,isError:N,isLoading:j,items:c,value:t||"",title:"Model"})}function k(){return!r||f==="S3"||f==="API"||!n||n==="none"?null:e.jsxRuntimeExports.jsx(ae,{onChange:V,isError:D,isLoading:b,items:p,value:i||"",title:"Schema"})}function w(){function O(){let G=!1;return f==="API"?(G=!1,G):((f==="S3"||r&&n&&n!=="none"&&i)&&(G=!0),G)}return O()?e.jsxRuntimeExports.jsx(ae,{onChange:o,isError:R,items:g,isLoading:S,value:l||"",title:"Table"}):null}return e.jsxRuntimeExports.jsxs("aside",{className:"xbg-red-100 flex grow flex-col justify-between",children:[e.jsxRuntimeExports.jsxs("section",{className:"space-y-3 px-6 py-4",children:[e.jsxRuntimeExports.jsx(ae,{items:a,title:"Connection",value:r||"",onChange:M,isLoading:d,isError:x,connectionTooltip:(($=a==null?void 0:a.find(O=>O.id===r))==null?void 0:$.type)||""}),H(),A(),C(),k(),w()]}),q(),e.jsxRuntimeExports.jsx("div",{className:"flex items-end justify-center gap-2 px-6 py-4",children:e.jsxRuntimeExports.jsxs(e.Button,{onClick:W,size:"sm",variant:"secondary",className:"w-full",children:[e.jsxRuntimeExports.jsx(ks,{className:"mr-2 size-4"}),"Help"]})})]})}function Qs(s){const r=s.toUpperCase().indexOf("WHERE"),t=s.toUpperCase().indexOf("GROUP BY"),n=s.toUpperCase().indexOf("LIMIT"),i=s.toUpperCase().indexOf("ORDER BY");let l=s.length;if(i!==-1&&(l=i),n!==-1&&n<l&&(l=n),r!==-1){const o=s.substring(0,r),a=s.substring(r);return`${o} {{ filters | where }} AND ${a.substring(6)}`}else if(t!==-1){const o=s.substring(0,t),a=s.substring(t);return`${o} {{ filters | where }} ${a}`}else{const o=s.substring(0,l),a=s.substring(l);return`${o} {{ filters | where }} ${a}`}}function Ks({error:s,setShowAIDialog:r,setUserInputforAI:t,setTriggerAIRun:n}){return e.jsxRuntimeExports.jsxs(e.HoverCard,{openDelay:0,children:[e.jsxRuntimeExports.jsx(e.HoverCardTrigger,{asChild:!0,children:e.jsxRuntimeExports.jsx(e.Button,{variant:"link",className:"h-5 p-0",children:e.jsxRuntimeExports.jsx(ms,{className:"h-4 w-4 text-red-500"})})}),e.jsxRuntimeExports.jsx(e.HoverCardContent,{align:"start",className:"min-w-fit max-w-[500px]",children:e.jsxRuntimeExports.jsx("div",{className:"flex justify-between space-x-4",children:e.jsxRuntimeExports.jsxs("div",{className:"flex grow flex-col space-y-2",children:[e.jsxRuntimeExports.jsx(e.ScrollArea,{className:"max-h-[250px] min-h-0 overflow-scroll",children:e.jsxRuntimeExports.jsx("p",{className:"overflow-auto rounded-md bg-muted p-2 text-xs leading-relaxed",children:s})}),e.jsxRuntimeExports.jsxs(e.Button,{onClick:()=>{r(!0),t(s),n(!0)},size:"sm",variant:"outline",children:[e.jsxRuntimeExports.jsx(bs,{className:"mr-2 h-4 w-4"}),"Debug with AI"]})]})})})]})}function Ws({text:s,onCheckedChange:r,checked:t}){return e.jsxRuntimeExports.jsxs("div",{className:"xbg-red-100 ml-6 flex items-center gap-2",children:[e.jsxRuntimeExports.jsx(e.Checkbox,{checked:t,onCheckedChange:r}),e.jsxRuntimeExports.jsx("label",{className:"text-xs leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70",children:s})]})}function Js(){const{authToken:s}=e.useSemaphorContext(),r=e.useEditorStore(l=>l.selectedConnectionId),{data:t}=e.useQuery({queryKey:["connections"],queryFn:()=>e.getRequest("https://semaphor.cloud/api/v1/connections",(s==null?void 0:s.accessToken)||""),enabled:!!(s!=null&&s.accessToken)}),n=t==null?void 0:t.connections.find(l=>l.id===r);return n==null?void 0:n.type}function Ys(){const{authToken:s}=e.useSemaphorContext(),r=v.useRef(null),t=e.useEditorStore(c=>c.applyFilters),[n,i]=v.useState(""),l=e.useEditorStore(c=>c.filterValues),o=e.useEditorStore(c=>c.card.sql),a=Js();return e.jsxRuntimeExports.jsxs(e.HoverCard,{openDelay:0,onOpenChange:async c=>{if(!c)return;console.log("onOpenChange");const p=await e.postRequest("https://semaphor.cloud/api/v1/filter-sql",(s==null?void 0:s.accessToken)||"",{sql:o,active_filters:l,connection_type:a});console.log(p),p.sql?(console.log(p.records),i(p.sql)):i("Error")},children:[e.jsxRuntimeExports.jsx(e.HoverCardTrigger,{asChild:!0,children:t&&e.jsxRuntimeExports.jsx("p",{className:"p-0 text-xs hover:cursor-pointer",children:"|  Filter Query"})}),e.jsxRuntimeExports.jsxs(e.HoverCardContent,{align:"end",className:"w-[600px]",children:[e.jsxRuntimeExports.jsx("div",{className:"flex justify-between space-x-4",children:e.jsxRuntimeExports.jsx("div",{className:"rounded-sm bg-muted p-2",children:e.jsxRuntimeExports.jsxs("code",{ref:r,className:"font-mono text-sm",children:[n,e.jsxRuntimeExports.jsx(e.ClipboardCopyIcon,{onClick:()=>e.copyToClipboard(r),className:"ml-3 inline-block h-4 w-4 opacity-70 hover:cursor-pointer hover:opacity-100"})]})})}),e.jsxRuntimeExports.jsxs("div",{className:"flex items-center gap-2 pt-2",children:[e.jsxRuntimeExports.jsx(e.InfoCircledIcon,{className:"h-4 w-4 opacity-70"}),e.jsxRuntimeExports.jsx("span",{className:"text-xs text-muted-foreground",children:"A preview of the query with filters applied."})]})]})]})}const Xs=`
192
192
 
193
193
  Use the following syntax to create a chart query. Please replace the x-axis, y-axis, stack-by, label, and measure with the actual column names of the table.
194
194