react-semaphor 0.0.244 → 0.0.246

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 D, L as Pe, b as w, c as bs, u as je, j as e, M as ys, O as vs, P as z, Q as Ns, R as Cs, U as Ss, V as ws, W as ks, X as $, Y as de, Z as st, _ as Rt, $ as Ht, a0 as $t, a1 as Pt, a2 as Bt, a3 as Gt, a4 as $s, f as Z, a5 as Ve, a6 as Ut, a7 as tt, a8 as Ze, a9 as Xe, T as zs, e as at, g as Fs, aa as ke, ab as ze, ac as Fe, ad as Le, ae as _e, af as Me, ag as te, ah as Ls, G as o, ai as Ms, aj as Os, ak as Ds, w as nt, v as rt, t as ue, al as Kt, r as Wt, N as it, s as Qt, am as Jt, B as Yt, an as lt, ao as Zt, S as Ts, z as Xt, n as Ps, A as ot, ap as ms, aq as he, ar as ge, as as Re, at as ts, au as ct, av as ea, aw as sa, ax as dt, ay as ta, az as aa, aA as na, aB as ra, aC as ia, aD as xs, aE as la, aF as oa, aG as qe, aH as ps, aI as we, aJ as fs, aK as Bs, aL as ca, aM as da, aN as ha, aO as ua, aP as ma, aQ as us, aR as xa, aS as Gs, aT as pa, aU as Us, aV as fa, aW as ga, aX as ja, aY as ht, l as ba, C as ya, E as Qe, d as va, h as Na, aZ as Ca, i as Sa, o as wa, a_ as ka, m as za, H as as, a$ as Fa, b0 as ut, b1 as mt, b2 as Je, b3 as xt, b4 as Ye, b5 as Ks, b6 as ns, b7 as rs, b8 as is, b9 as pt, K as La, ba as Ma, bb as Oa, bc as As, bd as Oe, be as ft, bf as Da, bg as Ta, bh as Aa, bi as Ia, bj as Ea, bk as Ws, bl as qa, bm as Va, bn as _a, bo as Ra, bp as Ha, bq as $a, br as Pa, bs as Ba, bt as Ne, bu as B, bv as G, bw as Is, bx as U, by as Qs, bz as Ga, bA as Ua, bB as Ka, bC as Wa, bD as Qa, bE as Ja, bF as Ya, bG as Za, bH as Xa, bI as en } from "./index-iGlNQo-C.js";
1
+ import { J as D, L as Pe, b as w, c as bs, u as je, j as e, M as ys, O as vs, P as z, Q as Ns, R as Cs, U as Ss, V as ws, W as ks, X as $, Y as de, Z as st, _ as Rt, $ as Ht, a0 as $t, a1 as Pt, a2 as Bt, a3 as Gt, a4 as $s, f as Z, a5 as Ve, a6 as Ut, a7 as tt, a8 as Ze, a9 as Xe, T as zs, e as at, g as Fs, aa as ke, ab as ze, ac as Fe, ad as Le, ae as _e, af as Me, ag as te, ah as Ls, G as o, ai as Ms, aj as Os, ak as Ds, w as nt, v as rt, t as ue, al as Kt, r as Wt, N as it, s as Qt, am as Jt, B as Yt, an as lt, ao as Zt, S as Ts, z as Xt, n as Ps, A as ot, ap as ms, aq as he, ar as ge, as as Re, at as ts, au as ct, av as ea, aw as sa, ax as dt, ay as ta, az as aa, aA as na, aB as ra, aC as ia, aD as xs, aE as la, aF as oa, aG as qe, aH as ps, aI as we, aJ as fs, aK as Bs, aL as ca, aM as da, aN as ha, aO as ua, aP as ma, aQ as us, aR as xa, aS as Gs, aT as pa, aU as Us, aV as fa, aW as ga, aX as ja, aY as ht, l as ba, C as ya, E as Qe, d as va, h as Na, aZ as Ca, i as Sa, o as wa, a_ as ka, m as za, H as as, a$ as Fa, b0 as ut, b1 as mt, b2 as Je, b3 as xt, b4 as Ye, b5 as Ks, b6 as ns, b7 as rs, b8 as is, b9 as pt, K as La, ba as Ma, bb as Oa, bc as As, bd as Oe, be as ft, bf as Da, bg as Ta, bh as Aa, bi as Ia, bj as Ea, bk as Ws, bl as qa, bm as Va, bn as _a, bo as Ra, bp as Ha, bq as $a, br as Pa, bs as Ba, bt as Ne, bu as B, bv as G, bw as Is, bx as U, by as Qs, bz as Ga, bA as Ua, bB as Ka, bC as Wa, bD as Qa, bE as Ja, bF as Ya, bG as Za, bH as Xa, bI as en } from "./index-uCOEDYik.js";
2
2
  import * as Js from "react";
3
3
  import me, { useState as T, useMemo as gs, useEffect as Y, useRef as He } from "react";
4
4
  /**
@@ -618,7 +618,8 @@ function Dn() {
618
618
  className: Z(
619
619
  "size-3.5 text-muted-foreground hover:cursor-pointer hover:text-foreground group-hover:visible",
620
620
  {
621
- invisible: !u.isDefault
621
+ invisible: !u.isDefault,
622
+ "text-green-500": u.isDefault
622
623
  }
623
624
  ),
624
625
  strokeWidth: 1.5
@@ -1,4 +1,4 @@
1
- "use strict";const e=require("./index-4xK4D4qH.js"),S=require("react");function as(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 Te=as(S);/**
1
+ "use strict";const e=require("./index-vW_7Osti.js"),S=require("react");function as(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 Te=as(S);/**
2
2
  * @license lucide-react v0.379.0 - ISC
3
3
  *
4
4
  * This source code is licensed under the ISC license.
@@ -163,7 +163,7 @@
163
163
  *
164
164
  * This source code is licensed under the ISC license.
165
165
  * See the LICENSE file in the root directory of this source tree.
166
- */const Is=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 Le(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 x;return{...i,cards:(x=i.cards)==null?void 0:x.map(o=>He(o))}})}})}}function He(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(x=>({...x,data:[]}))}},customCfg:Ts(s.customCfg),data:[]}}function Ts(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 zs(s,r,t,n){if(!n)return null;const i=JSON.stringify(r),x="https://semaphor.cloud/api/v1/lens";return await e.postRequest(x,n,{name:s,template:i,filterValues:t,operation:"create"})}async function Ce(s,r){if(!r)return null;const{id:t,template:n,filterValues:i,isDefault:x,shared:o}=s,a="https://semaphor.cloud/api/v1/lens";return await e.postRequest(a,r,{lensId:t,template:n,filterValues:i,isDefault:x,shared:o,operation:"update"})}async function Fs(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 Ms(){const[s,r]=S.useState(""),[t,n]=S.useState(!1),i=e.useDashboardStore(R=>R.lenses),{setLenses:x,setSelectedLensId:o}=e.useDashboardActions(),[a,l]=S.useState(!1),[d,u]=S.useState(!1),j=e.useDashboardStore(R=>R.dashboard),E=e.useDashboardStore(R=>R.filterValues),{authToken:c}=e.useSemaphorContext();async function m(){l(!0);const R=Le(j),h=await zs(s,R,E,c==null?void 0:c.accessToken);h&&(x([...i||[],h]),o(h.id),u(!1)),l(!1)}return e.jsxRuntimeExports.jsxs(e.Dialog,{open:d,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:R=>{r(R.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:m,disabled:a,children:a?"Creating...":"Add"})})]})]})}function Os(){const[s,r]=S.useState(!1),t=e.useDashboardStore(u=>u.lenses),n=e.useDashboardStore(u=>u.selectedLensId),{setLenses:i,setSelectedLensId:x}=e.useDashboardActions(),{authToken:o}=e.useSemaphorContext();async function a(u){x(u)}async function l(u){if(await Fs(u,o==null?void 0:o.accessToken)){const E=t==null?void 0:t.filter(c=>c.id!==u);i(E||[]),x("original")}}async function d(u){const j=t==null?void 0:t.map(m=>m.id===u.id?{...m,isDefault:!u.isDefault}:{...m,isDefault:!1});i(j||[]);const E={...u,isDefault:!u.isDefault};await Ce(E,o==null?void 0:o.accessToken);const c=t==null?void 0:t.find(m=>m.isDefault);if(c&&c.id!==u.id){const m={...c,isDefault:!1};await Ce(m,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(ps,{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(Es,{onClick:j=>{j.preventDefault(),d(u)},className:e.cn("size-3.5 text-muted-foreground hover:cursor-pointer hover:text-foreground group-hover:visible",{invisible:!u.isDefault}),strokeWidth:1.5}),e.jsxRuntimeExports.jsx(e.Cross2Icon,{onClick:j=>{j.preventDefault(),l(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 qs(){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 x=e.useDashboardStore(f=>f.isDashboardEditing),[o,a]=S.useState(!1),l=e.useDashboardStore(f=>f.filterValues),d=e.useDashboardStore(f=>f.isVisualEditing),u=e.useDashboardStore(f=>f.showFilters);e.useDashboardStore(f=>f.showDashboardJSON);const j=e.useDashboardStore(f=>f.onSaveFunction),E=e.useDashboardStore(f=>f.actions.setShowFilters),{addFrame:c,setSelectedFrameId:m}=e.useDashboardStore(f=>f.actions),{getSelectedSheet:R,setIsDashboardEditing:h,setShowDashboardJSON:N}=e.useDashboardStore(f=>f.actions),k=R(),{tenantId:b,endUserId:z}=S.useMemo(()=>e.getTenantAndEndUserId(s==null?void 0:s.accessToken),[s==null?void 0:s.accessToken]),T=S.useMemo(()=>b||z,[b,z]),F=()=>{if(!x||!k)return;const f={id:e.v4(),title:"Title",description:"Description",preferences:{onClickFilter:[{columnIndex:0,expression:""}]},type:"bar",sql:"select COUNT(*) from YOUR_TABLE",data:[]},M={id:e.v4(),cards:[f],activeCardId:f.id};c(k.id,M),m(M.id)},w=()=>{h(!0)};async function y(){if(a(!0),!t||!n)return;const f=Le(i),M=JSON.stringify(f),O={...n,template:M,filterValues:l};await Ce(O,s==null?void 0:s.accessToken),e.Jt.success("Lens saved"),j==null||j(f),a(!1)}return d?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:[!d&&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:[x&&!d&&T&&e.jsxRuntimeExports.jsx(Ms,{}),!d&&T&&e.jsxRuntimeExports.jsx(Os,{}),x&&!d&&e.jsxRuntimeExports.jsxs(e.Button,{variant:"secondary",className:"h-7 p-2",size:"sm",disabled:!x,onClick:F,children:[e.jsxRuntimeExports.jsx(e.Plus,{className:"mr-2 h-4 w-4",strokeWidth:1.5}),"Frame"]}),!x&&e.jsxRuntimeExports.jsx(e.Button,{variant:"ghost",className:"h-7 p-2",onClick:w,size:"sm",children:e.jsxRuntimeExports.jsx(Ve,{className:"h-4 w-4",strokeWidth:1.5})}),x&&!d&&e.jsxRuntimeExports.jsx(e.Button,{variant:"ghost",role:"close",className:"h-7 p-2",onClick:()=>{h(!1),N(!1)},size:"sm",children:e.jsxRuntimeExports.jsx(e.Cross2Icon,{className:"h-4 w-4",strokeWidth:1.5})}),x&&!d&&T&&e.jsxRuntimeExports.jsx(e.Button,{className:"h-7 p-2",variant:"ghost",disabled:o,onClick:y,size:"sm",children:e.jsxRuntimeExports.jsx(Ns,{className:"h-4 w-4",strokeWidth:1.5})}),!u&&!d&&x&&e.jsxRuntimeExports.jsx(e.Button,{className:"h-7 p-2",variant:"ghost",onClick:()=>E(!0),size:"sm",children:e.jsxRuntimeExports.jsx(e.Filter,{className:"h-4 w-4",strokeWidth:1.5})}),!d&&x&&!1,!d&&!1]})]})}function le({title:s,items:r,value:t,isLoading:n,isError:i,connectionTooltip:x,onChange:o,showNone:a=!1,className:l,showIcon:d=!0,disabled:u=!1}){const j=n?"Loading...":i?"Error":t;function E(){if(s==="Connection")return e.jsxRuntimeExports.jsx(Cs,{className:"size-4 rotate-90"});if(s==="Database")return e.jsxRuntimeExports.jsx(us,{className:"size-4"});if(s==="Schema")return e.jsxRuntimeExports.jsx(ys,{className:"size-4"});if(s==="Table")return e.jsxRuntimeExports.jsx(e.Table,{className:"size-4"});if(s==="Model")return e.jsxRuntimeExports.jsx(cs,{className:"size-4"})}return e.jsxRuntimeExports.jsxs("div",{className:"flex items-center gap-2",children:[d&&e.jsxRuntimeExports.jsx("div",{className:"shrink-0",children:x?e.jsxRuntimeExports.jsxs(e.Tooltip,{children:[e.jsxRuntimeExports.jsx(e.TooltipTrigger,{children:E()}),e.jsxRuntimeExports.jsx(e.TooltipContent,{className:"text-xs",align:"start",children:x})]}):E()}),e.jsxRuntimeExports.jsxs(e.Select,{disabled:u,value:j,onValueChange:o,children:[e.jsxRuntimeExports.jsx(e.SelectTrigger,{className:e.cn("h-9 w-full focus:ring-1 focus:ring-offset-0",l),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((c,m)=>e.jsxRuntimeExports.jsx(e.SelectItem,{value:c.id,children:c.name},m))]}),(n||i)&&e.jsxRuntimeExports.jsx(e.SelectItem,{value:j,children:j})]})})]})]})}function Vs({column:s}){const[r,t]=S.useState(!1),n=e.useEditorStore(c=>c.selectedTableName),i=e.useEditorStore(c=>c.selectedSchemaName),x=e.useEditorStore(c=>c.selectedDatamodelId),o=e.useEditorStore(c=>c.sqlGen),{modelItems:a}=oe(),l=e.useEditorStore(c=>c.actions.setSqlGen),d=e.useEditorStore(c=>c.actions.setCardSql),u=e.useEditorStore(c=>c.actions.setRunSql);function j(c,m){var k;const R=e.createSqlGenConfig(c,o,m),h=(k=a==null?void 0:a.find(b=>b.id===x))==null?void 0:k.name;l(R);const N=e.getSql(R,e.fmt(i||""),e.fmt(n),h);N&&(d(N),u(!0)),t(!1)}function E(){return e.jsxRuntimeExports.jsxs("ul",{className:"text-xs",children:[e.jsxRuntimeExports.jsx("li",{onClick:()=>j(s,"COUNT"),className:"cursor-pointer p-1 px-3 transition-colors hover:bg-muted",children:"Count"}),e.jsxRuntimeExports.jsx("li",{onClick:()=>j(s,"AVG"),className:"cursor-pointer p-1 px-3 transition-colors hover:bg-muted",children:"Avg"}),e.jsxRuntimeExports.jsx("li",{onClick:()=>j(s,"SUM"),className:"cursor-pointer p-1 px-3 transition-colors hover:bg-muted",children:"Sum"}),e.jsxRuntimeExports.jsx("li",{onClick:()=>j(s,"MAX"),className:"cursor-pointer p-1 px-3 transition-colors hover:bg-muted",children:"Max"}),e.jsxRuntimeExports.jsx("li",{onClick:()=>j(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(ds,{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:E()})]})}function Pe({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(ke,{className:"size-3"}):e.NUMBER_DATA_TYPES.includes(s.data_type.toLowerCase())?e.jsxRuntimeExports.jsx(js,{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(As,{className:"size-3"}):e.jsxRuntimeExports.jsx(ws,{className:"size-3"})}),e.jsxRuntimeExports.jsx(e.TooltipContent,{children:e.jsxRuntimeExports.jsx("p",{className:"font-mono text-xs",children:s.data_type})})]})}function _s({schemaName:s,tableName:r,columns:t,status:n}){const i=e.useEditorStore(y=>y.sqlGen),x=e.useEditorStore(y=>y.selectedConnectionId),o=e.useEditorStore(y=>y.selectedDatabaseName),a=e.useEditorStore(y=>y.selectedSchemaName),l=e.useEditorStore(y=>y.selectedTableName),d=e.useEditorStore(y=>y.selectedDatamodelId),u=e.useDashboardStore(y=>y.dashboard.aiScopeTables),{setAIScopeTables:j}=e.useDashboardStore(y=>y.actions),E=e.useEditorStore(y=>y.actions.setRunSql),c=e.useEditorStore(y=>y.actions.setSqlGen),m=e.useEditorStore(y=>y.actions.setIsShowingVisual),R=e.useEditorStore(y=>y.actions.setCardSql),{connectionType:h,modelItems:N}=oe();function k(y){var D;const f=e.createSqlGenConfig(y,i);c(f);const M=(D=N==null?void 0:N.find(q=>q.id===d))==null?void 0:D.name,O=e.getSql(f,e.fmt(s),e.fmt(r),M);O&&(R(O),E(!0))}function b(){return(u==null?void 0:u.find(y=>y.connectinonId===x&&y.tableName===l))!==void 0}function z(y){if(y===!0&&l&&x){const f={connectinonId:x,connectionType:h,databaseName:o,schemaName:a,tableName:l},O=[...u||[],f].filter((D,q,P)=>P.findIndex(_=>_.connectinonId===D.connectinonId&&_.tableName===D.tableName)===q);j(O),e.Jt.success(`Added '${l}' to AI Scope`,{position:"top-right",duration:2500,richColors:!0})}else{const f=(u||[]).filter(M=>M.connectinonId!==x&&M.tableName!==l);j(f),e.Jt(`Removed '${l}' from AI Scope`,{position:"top-right",duration:2e3,richColors:!0})}}function T(){var D;let y=e.getQualifiedTableName(s,r);const f=(D=N==null?void 0:N.find(q=>q.id===d))==null?void 0:D.name;console.log("modelName",f),d&&d!=="none"&&(y=`${e.DATAMODEL_NAMESPCACE}.${f}`);let M=y;return(q=>/[A-Z]/.test(q))(r)&&(M=M.split(".").map(P=>`"${P}"`).join(".")),M}function F(){const y=T();m(!1);const f=h==="MSSQL"?`SELECT top 10 * FROM ${y}`:`SELECT * FROM ${y} LIMIT 10`;R(f),E(!0)}function w(){const y=T();R(`SELECT COUNT(*) as count FROM ${y}`),E(!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:z,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:F,size:"sm",variant:"secondary",className:"flex",children:[n!=="Success"?e.jsxRuntimeExports.jsx(ce,{className:"mr-2 h-4 w-4 animate-spin text-foreground/50"}):e.jsxRuntimeExports.jsx(Ls,{className:"mr-2 size-4"}),"Top 10"]}),e.jsxRuntimeExports.jsxs(e.Button,{disabled:n!=="Success",onClick:w,size:"sm",variant:"secondary",className:"flex",children:[n!=="Success"?e.jsxRuntimeExports.jsx(ce,{className:"mr-2 h-4 w-4 animate-spin text-foreground/50"}):e.jsxRuntimeExports.jsx(ks,{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(y=>e.jsxRuntimeExports.jsxs("div",{onClick:()=>k(y),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(y,i)}),children:[e.jsxRuntimeExports.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsxRuntimeExports.jsx(Pe,{column:y}),e.jsxRuntimeExports.jsx("span",{children:y.column_name})]}),e.jsxRuntimeExports.jsx("div",{onClick:f=>f.stopPropagation(),className:"flex items-center justify-end",children:e.NUMBER_DATA_TYPES.includes(y.data_type)&&e.jsxRuntimeExports.jsx(Vs,{column:y})})]},y.column_name)),e.jsxRuntimeExports.jsx(e.ScrollBar,{orientation:"vertical"}),e.jsxRuntimeExports.jsx(e.ScrollBar,{orientation:"horizontal"})]})]})}function oe(s,r){var pe,de,he,je,p;let t=S.useMemo(()=>[],[]);const n=e.useSemaphorContext().authToken||s,i=e.useEditorStore(g=>g.selectedConnectionId),x=e.useEditorStore(g=>g.selectedDatamodelId),o=e.useEditorStore(g=>g.selectedDatabaseName),a=e.useEditorStore(g=>g.selectedSchemaName),l=e.useEditorStore(g=>g.selectedTableName),d=e.useEditorStore(g=>g.actions.setCurrentColumns),u=e.useEditorStore(g=>g.actions.setSelectedConnectionId),j=e.useEditorStore(g=>g.actions.setSelectedDatamodelId),E=e.useEditorStore(g=>g.actions.setSelectedDatabaseName),c=e.useEditorStore(g=>g.actions.setSelectedSchemaName),m=e.useEditorStore(g=>g.actions.setSelectedTableName),R=e.useEditorStore(g=>g.actions.setCardSql);function h(g){return i&&o&&a&&o!=="NA"?!0:i&&g==="API"?!1:!!(i&&g==="S3")}function N(g){return!!(i&&o&&o!=="NA"&&a&&l||i&&(g==="S3"||g==="API")||x&&x)}function k(g){return i&&g?!(g==="API"||g==="S3"):!1}const{data:b,isLoading:z,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:F,isLoading:w,isError:y}=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(g=>g.id===i),M=f==null?void 0:f.type,O=(f==null?void 0:f.type)==="API"||(f==null?void 0:f.type)==="S3",{data:D,isLoading:q,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:k(M)}),{data:V,isLoading:W,isFetching:v,isError:L,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&&!O&&o!=="NA"}),{data:C,isLoading:A,isFetching:$,isError:I,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:h(M)}),{data:Q,isLoading:te,isFetching:ee,isError:B}=e.useQuery({queryKey:["columns",i,o,x,a,l],queryFn:()=>e.getRequest("https://semaphor.cloud/api/v1/columns",(n==null?void 0:n.accessToken)||"",{connection_id:i,datamodel_id:x||"",database_name:o,schema_name:a,table_name:l}),enabled:N(M)});S.useEffect(()=>{d(t)},[Q,d,t]),S.useEffect(()=>{},[O,R,m,c,E,f]);const J=(f==null?void 0:f.type)==="API"?(pe=f==null?void 0:f.type)==null?void 0:pe.toLowerCase():l||"",Y=O?"":a||"";function ne(g){c(g),m("")}function X(g){E(g==="none"?"":g),c(""),m(""),g!=="none"&&g!==""&&j("")}function se(g){u(g)}function Ae(g){j(g==="none"?"":g),g!=="none"&&g!==""&&E("")}D&&((de=D==null?void 0:D.databases)==null?void 0:de.length)>0,V&&((he=V==null?void 0:V.schemas)==null?void 0:he.length)>0,Q&&((je=Q==null?void 0:Q.columns)==null?void 0:je.length)>0&&(t=Q.columns.map(g=>({...g,data_type:g.data_type.toLowerCase()}))),_&&(t=[]),(B||T)&&(t=[]);const ie=b==null?void 0:b.connections.map(g=>({id:g.id,name:g.name,type:g.type})),be=(p=F==null?void 0:F.datamodels)==null?void 0:p.map(g=>({id:g.id,name:g.name})),me=D==null?void 0:D.databases.map(g=>({id:g.database_name,name:g.database_name})),Se=V==null?void 0:V.schemas.map(g=>({id:g.schema_name,name:g.schema_name})),ye=C==null?void 0:C.tables.map(g=>({id:g.table_name,name:g.table_name}));return{connectionItems:ie,isConnectionsLoading:z,isConnectionsError:T,modelItems:be,isModelsLoading:w,isModelsError:y,databaseItems:me,isDatabasesLoadingOrFetching:q||P,isDatabaseError:_,schemaItems:Se,isSchemaLoadingOrFetching:W||v,isSchemaError:L,tableItems:ye,isTableLoadingOrFetching:A||$,isTableError:I,columns:t,isColumnsLoadingOrFetching:te||ee,isColumnsError:B,isNonDbConnection:O,connectionType:M,tableName:J,schemaName:Y,handleConnectionChange:se,handleDatamodelChange:Ae,handleDatabaseChange:X,handleSchemaChange:ne}}function $e({ColumnsComponent:s}){var $;const r=e.useEditorStore(I=>I.selectedConnectionId),t=e.useEditorStore(I=>I.selectedDatamodelId),n=e.useEditorStore(I=>I.selectedDatabaseName),i=e.useEditorStore(I=>I.selectedSchemaName),x=e.useEditorStore(I=>I.selectedTableName),o=e.useEditorStore(I=>I.actions.setSelectedTableName),{connectionItems:a,modelItems:l,schemaItems:d,databaseItems:u,tableItems:j,columns:E,isConnectionsLoading:c,isModelsLoading:m,isConnectionsError:R,isModelsError:h,isDatabasesLoadingOrFetching:N,isDatabaseError:k,isSchemaLoadingOrFetching:b,isSchemaError:z,isColumnsError:T,isColumnsLoadingOrFetching:F,isTableLoadingOrFetching:w,isTableError:y,connectionType:f,isNonDbConnection:M,handleConnectionChange:O,handleDatabaseChange:D,handleSchemaChange:q,handleDatamodelChange:P,tableName:_,schemaName:K}=oe();function V(){return s?s(K,_,E):e.jsxRuntimeExports.jsx(_s,{schemaName:K,tableName:_,columns:E,status:F?"Loading...":T?"Error":"Success"})}function W(){window.location.href="mailto:support@semaphor.cloud?subject=Help&body=I need help with..."}function v(){if(!r||f==="S3"||f==="API")return null;if(!t||t==="none")return e.jsxRuntimeExports.jsx(le,{showNone:!0,onChange:D,isError:k,isLoading:N,items:u,value:n||"",title:"Database"})}function L(){if(r&&!M&&(!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(le,{showNone:!0,onChange:P,isError:h,isLoading:m,items:l,value:t||"",title:"Model"})}function C(){return!r||f==="S3"||f==="API"||!n||n==="none"?null:e.jsxRuntimeExports.jsx(le,{onChange:q,isError:z,isLoading:b,items:d,value:i||"",title:"Schema"})}function A(){function I(){let G=!1;return f==="API"?(G=!1,G):((f==="S3"||r&&n&&n!=="none"&&i)&&(G=!0),G)}return I()?e.jsxRuntimeExports.jsx(le,{onChange:o,isError:y,items:j,isLoading:w,value:x||"",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(le,{items:a,title:"Connection",value:r||"",onChange:O,isLoading:c,isError:R,connectionTooltip:(($=a==null?void 0:a.find(I=>I.id===r))==null?void 0:$.type)||""}),H(),L(),v(),C(),A()]}),V(),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(Ss,{className:"mr-2 size-4"}),"Help"]})})]})}function Bs(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 x=s.length;if(i!==-1&&(x=i),n!==-1&&n<x&&(x=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,x),a=s.substring(x);return`${o} {{ filters | where }} ${a}`}}function Hs({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(xs,{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(hs,{className:"mr-2 h-4 w-4"}),"Debug with AI"]})]})})})]})}function Ps({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 $s(){const{authToken:s}=e.useSemaphorContext(),r=e.useEditorStore(x=>x.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(x=>x.id===r);return n==null?void 0:n.type}function Gs(){const{authToken:s}=e.useSemaphorContext(),r=S.useRef(null),t=e.useEditorStore(l=>l.applyFilters),[n,i]=S.useState(""),x=e.useEditorStore(l=>l.filterValues),o=e.useEditorStore(l=>l.card.sql),a=$s();return e.jsxRuntimeExports.jsxs(e.HoverCard,{openDelay:0,onOpenChange:async l=>{if(!l)return;console.log("onOpenChange");const d=await e.postRequest("https://semaphor.cloud/api/v1/filter-sql",(s==null?void 0:s.accessToken)||"",{sql:o,active_filters:x,connection_type:a});console.log(d),d.sql?(console.log(d.records),i(d.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 Qs=`
166
+ */const Is=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 Le(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 x;return{...i,cards:(x=i.cards)==null?void 0:x.map(o=>He(o))}})}})}}function He(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(x=>({...x,data:[]}))}},customCfg:Ts(s.customCfg),data:[]}}function Ts(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 zs(s,r,t,n){if(!n)return null;const i=JSON.stringify(r),x="https://semaphor.cloud/api/v1/lens";return await e.postRequest(x,n,{name:s,template:i,filterValues:t,operation:"create"})}async function Ce(s,r){if(!r)return null;const{id:t,template:n,filterValues:i,isDefault:x,shared:o}=s,a="https://semaphor.cloud/api/v1/lens";return await e.postRequest(a,r,{lensId:t,template:n,filterValues:i,isDefault:x,shared:o,operation:"update"})}async function Fs(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 Ms(){const[s,r]=S.useState(""),[t,n]=S.useState(!1),i=e.useDashboardStore(R=>R.lenses),{setLenses:x,setSelectedLensId:o}=e.useDashboardActions(),[a,l]=S.useState(!1),[d,u]=S.useState(!1),j=e.useDashboardStore(R=>R.dashboard),E=e.useDashboardStore(R=>R.filterValues),{authToken:c}=e.useSemaphorContext();async function m(){l(!0);const R=Le(j),h=await zs(s,R,E,c==null?void 0:c.accessToken);h&&(x([...i||[],h]),o(h.id),u(!1)),l(!1)}return e.jsxRuntimeExports.jsxs(e.Dialog,{open:d,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:R=>{r(R.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:m,disabled:a,children:a?"Creating...":"Add"})})]})]})}function Os(){const[s,r]=S.useState(!1),t=e.useDashboardStore(u=>u.lenses),n=e.useDashboardStore(u=>u.selectedLensId),{setLenses:i,setSelectedLensId:x}=e.useDashboardActions(),{authToken:o}=e.useSemaphorContext();async function a(u){x(u)}async function l(u){if(await Fs(u,o==null?void 0:o.accessToken)){const E=t==null?void 0:t.filter(c=>c.id!==u);i(E||[]),x("original")}}async function d(u){const j=t==null?void 0:t.map(m=>m.id===u.id?{...m,isDefault:!u.isDefault}:{...m,isDefault:!1});i(j||[]);const E={...u,isDefault:!u.isDefault};await Ce(E,o==null?void 0:o.accessToken);const c=t==null?void 0:t.find(m=>m.isDefault);if(c&&c.id!==u.id){const m={...c,isDefault:!1};await Ce(m,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(ps,{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(Es,{onClick:j=>{j.preventDefault(),d(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:j=>{j.preventDefault(),l(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 qs(){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 x=e.useDashboardStore(f=>f.isDashboardEditing),[o,a]=S.useState(!1),l=e.useDashboardStore(f=>f.filterValues),d=e.useDashboardStore(f=>f.isVisualEditing),u=e.useDashboardStore(f=>f.showFilters);e.useDashboardStore(f=>f.showDashboardJSON);const j=e.useDashboardStore(f=>f.onSaveFunction),E=e.useDashboardStore(f=>f.actions.setShowFilters),{addFrame:c,setSelectedFrameId:m}=e.useDashboardStore(f=>f.actions),{getSelectedSheet:R,setIsDashboardEditing:h,setShowDashboardJSON:N}=e.useDashboardStore(f=>f.actions),k=R(),{tenantId:b,endUserId:z}=S.useMemo(()=>e.getTenantAndEndUserId(s==null?void 0:s.accessToken),[s==null?void 0:s.accessToken]),T=S.useMemo(()=>b||z,[b,z]),F=()=>{if(!x||!k)return;const f={id:e.v4(),title:"Title",description:"Description",preferences:{onClickFilter:[{columnIndex:0,expression:""}]},type:"bar",sql:"select COUNT(*) from YOUR_TABLE",data:[]},M={id:e.v4(),cards:[f],activeCardId:f.id};c(k.id,M),m(M.id)},w=()=>{h(!0)};async function y(){if(a(!0),!t||!n)return;const f=Le(i),M=JSON.stringify(f),O={...n,template:M,filterValues:l};await Ce(O,s==null?void 0:s.accessToken),e.Jt.success("Lens saved"),j==null||j(f),a(!1)}return d?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:[!d&&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:[x&&!d&&T&&e.jsxRuntimeExports.jsx(Ms,{}),!d&&T&&e.jsxRuntimeExports.jsx(Os,{}),x&&!d&&e.jsxRuntimeExports.jsxs(e.Button,{variant:"secondary",className:"h-7 p-2",size:"sm",disabled:!x,onClick:F,children:[e.jsxRuntimeExports.jsx(e.Plus,{className:"mr-2 h-4 w-4",strokeWidth:1.5}),"Frame"]}),!x&&e.jsxRuntimeExports.jsx(e.Button,{variant:"ghost",className:"h-7 p-2",onClick:w,size:"sm",children:e.jsxRuntimeExports.jsx(Ve,{className:"h-4 w-4",strokeWidth:1.5})}),x&&!d&&e.jsxRuntimeExports.jsx(e.Button,{variant:"ghost",role:"close",className:"h-7 p-2",onClick:()=>{h(!1),N(!1)},size:"sm",children:e.jsxRuntimeExports.jsx(e.Cross2Icon,{className:"h-4 w-4",strokeWidth:1.5})}),x&&!d&&T&&e.jsxRuntimeExports.jsx(e.Button,{className:"h-7 p-2",variant:"ghost",disabled:o,onClick:y,size:"sm",children:e.jsxRuntimeExports.jsx(Ns,{className:"h-4 w-4",strokeWidth:1.5})}),!u&&!d&&x&&e.jsxRuntimeExports.jsx(e.Button,{className:"h-7 p-2",variant:"ghost",onClick:()=>E(!0),size:"sm",children:e.jsxRuntimeExports.jsx(e.Filter,{className:"h-4 w-4",strokeWidth:1.5})}),!d&&x&&!1,!d&&!1]})]})}function le({title:s,items:r,value:t,isLoading:n,isError:i,connectionTooltip:x,onChange:o,showNone:a=!1,className:l,showIcon:d=!0,disabled:u=!1}){const j=n?"Loading...":i?"Error":t;function E(){if(s==="Connection")return e.jsxRuntimeExports.jsx(Cs,{className:"size-4 rotate-90"});if(s==="Database")return e.jsxRuntimeExports.jsx(us,{className:"size-4"});if(s==="Schema")return e.jsxRuntimeExports.jsx(ys,{className:"size-4"});if(s==="Table")return e.jsxRuntimeExports.jsx(e.Table,{className:"size-4"});if(s==="Model")return e.jsxRuntimeExports.jsx(cs,{className:"size-4"})}return e.jsxRuntimeExports.jsxs("div",{className:"flex items-center gap-2",children:[d&&e.jsxRuntimeExports.jsx("div",{className:"shrink-0",children:x?e.jsxRuntimeExports.jsxs(e.Tooltip,{children:[e.jsxRuntimeExports.jsx(e.TooltipTrigger,{children:E()}),e.jsxRuntimeExports.jsx(e.TooltipContent,{className:"text-xs",align:"start",children:x})]}):E()}),e.jsxRuntimeExports.jsxs(e.Select,{disabled:u,value:j,onValueChange:o,children:[e.jsxRuntimeExports.jsx(e.SelectTrigger,{className:e.cn("h-9 w-full focus:ring-1 focus:ring-offset-0",l),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((c,m)=>e.jsxRuntimeExports.jsx(e.SelectItem,{value:c.id,children:c.name},m))]}),(n||i)&&e.jsxRuntimeExports.jsx(e.SelectItem,{value:j,children:j})]})})]})]})}function Vs({column:s}){const[r,t]=S.useState(!1),n=e.useEditorStore(c=>c.selectedTableName),i=e.useEditorStore(c=>c.selectedSchemaName),x=e.useEditorStore(c=>c.selectedDatamodelId),o=e.useEditorStore(c=>c.sqlGen),{modelItems:a}=oe(),l=e.useEditorStore(c=>c.actions.setSqlGen),d=e.useEditorStore(c=>c.actions.setCardSql),u=e.useEditorStore(c=>c.actions.setRunSql);function j(c,m){var k;const R=e.createSqlGenConfig(c,o,m),h=(k=a==null?void 0:a.find(b=>b.id===x))==null?void 0:k.name;l(R);const N=e.getSql(R,e.fmt(i||""),e.fmt(n),h);N&&(d(N),u(!0)),t(!1)}function E(){return e.jsxRuntimeExports.jsxs("ul",{className:"text-xs",children:[e.jsxRuntimeExports.jsx("li",{onClick:()=>j(s,"COUNT"),className:"cursor-pointer p-1 px-3 transition-colors hover:bg-muted",children:"Count"}),e.jsxRuntimeExports.jsx("li",{onClick:()=>j(s,"AVG"),className:"cursor-pointer p-1 px-3 transition-colors hover:bg-muted",children:"Avg"}),e.jsxRuntimeExports.jsx("li",{onClick:()=>j(s,"SUM"),className:"cursor-pointer p-1 px-3 transition-colors hover:bg-muted",children:"Sum"}),e.jsxRuntimeExports.jsx("li",{onClick:()=>j(s,"MAX"),className:"cursor-pointer p-1 px-3 transition-colors hover:bg-muted",children:"Max"}),e.jsxRuntimeExports.jsx("li",{onClick:()=>j(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(ds,{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:E()})]})}function Pe({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(ke,{className:"size-3"}):e.NUMBER_DATA_TYPES.includes(s.data_type.toLowerCase())?e.jsxRuntimeExports.jsx(js,{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(As,{className:"size-3"}):e.jsxRuntimeExports.jsx(ws,{className:"size-3"})}),e.jsxRuntimeExports.jsx(e.TooltipContent,{children:e.jsxRuntimeExports.jsx("p",{className:"font-mono text-xs",children:s.data_type})})]})}function _s({schemaName:s,tableName:r,columns:t,status:n}){const i=e.useEditorStore(y=>y.sqlGen),x=e.useEditorStore(y=>y.selectedConnectionId),o=e.useEditorStore(y=>y.selectedDatabaseName),a=e.useEditorStore(y=>y.selectedSchemaName),l=e.useEditorStore(y=>y.selectedTableName),d=e.useEditorStore(y=>y.selectedDatamodelId),u=e.useDashboardStore(y=>y.dashboard.aiScopeTables),{setAIScopeTables:j}=e.useDashboardStore(y=>y.actions),E=e.useEditorStore(y=>y.actions.setRunSql),c=e.useEditorStore(y=>y.actions.setSqlGen),m=e.useEditorStore(y=>y.actions.setIsShowingVisual),R=e.useEditorStore(y=>y.actions.setCardSql),{connectionType:h,modelItems:N}=oe();function k(y){var D;const f=e.createSqlGenConfig(y,i);c(f);const M=(D=N==null?void 0:N.find(q=>q.id===d))==null?void 0:D.name,O=e.getSql(f,e.fmt(s),e.fmt(r),M);O&&(R(O),E(!0))}function b(){return(u==null?void 0:u.find(y=>y.connectinonId===x&&y.tableName===l))!==void 0}function z(y){if(y===!0&&l&&x){const f={connectinonId:x,connectionType:h,databaseName:o,schemaName:a,tableName:l},O=[...u||[],f].filter((D,q,P)=>P.findIndex(_=>_.connectinonId===D.connectinonId&&_.tableName===D.tableName)===q);j(O),e.Jt.success(`Added '${l}' to AI Scope`,{position:"top-right",duration:2500,richColors:!0})}else{const f=(u||[]).filter(M=>M.connectinonId!==x&&M.tableName!==l);j(f),e.Jt(`Removed '${l}' from AI Scope`,{position:"top-right",duration:2e3,richColors:!0})}}function T(){var D;let y=e.getQualifiedTableName(s,r);const f=(D=N==null?void 0:N.find(q=>q.id===d))==null?void 0:D.name;console.log("modelName",f),d&&d!=="none"&&(y=`${e.DATAMODEL_NAMESPCACE}.${f}`);let M=y;return(q=>/[A-Z]/.test(q))(r)&&(M=M.split(".").map(P=>`"${P}"`).join(".")),M}function F(){const y=T();m(!1);const f=h==="MSSQL"?`SELECT top 10 * FROM ${y}`:`SELECT * FROM ${y} LIMIT 10`;R(f),E(!0)}function w(){const y=T();R(`SELECT COUNT(*) as count FROM ${y}`),E(!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:z,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:F,size:"sm",variant:"secondary",className:"flex",children:[n!=="Success"?e.jsxRuntimeExports.jsx(ce,{className:"mr-2 h-4 w-4 animate-spin text-foreground/50"}):e.jsxRuntimeExports.jsx(Ls,{className:"mr-2 size-4"}),"Top 10"]}),e.jsxRuntimeExports.jsxs(e.Button,{disabled:n!=="Success",onClick:w,size:"sm",variant:"secondary",className:"flex",children:[n!=="Success"?e.jsxRuntimeExports.jsx(ce,{className:"mr-2 h-4 w-4 animate-spin text-foreground/50"}):e.jsxRuntimeExports.jsx(ks,{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(y=>e.jsxRuntimeExports.jsxs("div",{onClick:()=>k(y),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(y,i)}),children:[e.jsxRuntimeExports.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsxRuntimeExports.jsx(Pe,{column:y}),e.jsxRuntimeExports.jsx("span",{children:y.column_name})]}),e.jsxRuntimeExports.jsx("div",{onClick:f=>f.stopPropagation(),className:"flex items-center justify-end",children:e.NUMBER_DATA_TYPES.includes(y.data_type)&&e.jsxRuntimeExports.jsx(Vs,{column:y})})]},y.column_name)),e.jsxRuntimeExports.jsx(e.ScrollBar,{orientation:"vertical"}),e.jsxRuntimeExports.jsx(e.ScrollBar,{orientation:"horizontal"})]})]})}function oe(s,r){var pe,de,he,je,p;let t=S.useMemo(()=>[],[]);const n=e.useSemaphorContext().authToken||s,i=e.useEditorStore(g=>g.selectedConnectionId),x=e.useEditorStore(g=>g.selectedDatamodelId),o=e.useEditorStore(g=>g.selectedDatabaseName),a=e.useEditorStore(g=>g.selectedSchemaName),l=e.useEditorStore(g=>g.selectedTableName),d=e.useEditorStore(g=>g.actions.setCurrentColumns),u=e.useEditorStore(g=>g.actions.setSelectedConnectionId),j=e.useEditorStore(g=>g.actions.setSelectedDatamodelId),E=e.useEditorStore(g=>g.actions.setSelectedDatabaseName),c=e.useEditorStore(g=>g.actions.setSelectedSchemaName),m=e.useEditorStore(g=>g.actions.setSelectedTableName),R=e.useEditorStore(g=>g.actions.setCardSql);function h(g){return i&&o&&a&&o!=="NA"?!0:i&&g==="API"?!1:!!(i&&g==="S3")}function N(g){return!!(i&&o&&o!=="NA"&&a&&l||i&&(g==="S3"||g==="API")||x&&x)}function k(g){return i&&g?!(g==="API"||g==="S3"):!1}const{data:b,isLoading:z,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:F,isLoading:w,isError:y}=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(g=>g.id===i),M=f==null?void 0:f.type,O=(f==null?void 0:f.type)==="API"||(f==null?void 0:f.type)==="S3",{data:D,isLoading:q,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:k(M)}),{data:V,isLoading:W,isFetching:v,isError:L,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&&!O&&o!=="NA"}),{data:C,isLoading:A,isFetching:$,isError:I,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:h(M)}),{data:Q,isLoading:te,isFetching:ee,isError:B}=e.useQuery({queryKey:["columns",i,o,x,a,l],queryFn:()=>e.getRequest("https://semaphor.cloud/api/v1/columns",(n==null?void 0:n.accessToken)||"",{connection_id:i,datamodel_id:x||"",database_name:o,schema_name:a,table_name:l}),enabled:N(M)});S.useEffect(()=>{d(t)},[Q,d,t]),S.useEffect(()=>{},[O,R,m,c,E,f]);const J=(f==null?void 0:f.type)==="API"?(pe=f==null?void 0:f.type)==null?void 0:pe.toLowerCase():l||"",Y=O?"":a||"";function ne(g){c(g),m("")}function X(g){E(g==="none"?"":g),c(""),m(""),g!=="none"&&g!==""&&j("")}function se(g){u(g)}function Ae(g){j(g==="none"?"":g),g!=="none"&&g!==""&&E("")}D&&((de=D==null?void 0:D.databases)==null?void 0:de.length)>0,V&&((he=V==null?void 0:V.schemas)==null?void 0:he.length)>0,Q&&((je=Q==null?void 0:Q.columns)==null?void 0:je.length)>0&&(t=Q.columns.map(g=>({...g,data_type:g.data_type.toLowerCase()}))),_&&(t=[]),(B||T)&&(t=[]);const ie=b==null?void 0:b.connections.map(g=>({id:g.id,name:g.name,type:g.type})),be=(p=F==null?void 0:F.datamodels)==null?void 0:p.map(g=>({id:g.id,name:g.name})),me=D==null?void 0:D.databases.map(g=>({id:g.database_name,name:g.database_name})),Se=V==null?void 0:V.schemas.map(g=>({id:g.schema_name,name:g.schema_name})),ye=C==null?void 0:C.tables.map(g=>({id:g.table_name,name:g.table_name}));return{connectionItems:ie,isConnectionsLoading:z,isConnectionsError:T,modelItems:be,isModelsLoading:w,isModelsError:y,databaseItems:me,isDatabasesLoadingOrFetching:q||P,isDatabaseError:_,schemaItems:Se,isSchemaLoadingOrFetching:W||v,isSchemaError:L,tableItems:ye,isTableLoadingOrFetching:A||$,isTableError:I,columns:t,isColumnsLoadingOrFetching:te||ee,isColumnsError:B,isNonDbConnection:O,connectionType:M,tableName:J,schemaName:Y,handleConnectionChange:se,handleDatamodelChange:Ae,handleDatabaseChange:X,handleSchemaChange:ne}}function $e({ColumnsComponent:s}){var $;const r=e.useEditorStore(I=>I.selectedConnectionId),t=e.useEditorStore(I=>I.selectedDatamodelId),n=e.useEditorStore(I=>I.selectedDatabaseName),i=e.useEditorStore(I=>I.selectedSchemaName),x=e.useEditorStore(I=>I.selectedTableName),o=e.useEditorStore(I=>I.actions.setSelectedTableName),{connectionItems:a,modelItems:l,schemaItems:d,databaseItems:u,tableItems:j,columns:E,isConnectionsLoading:c,isModelsLoading:m,isConnectionsError:R,isModelsError:h,isDatabasesLoadingOrFetching:N,isDatabaseError:k,isSchemaLoadingOrFetching:b,isSchemaError:z,isColumnsError:T,isColumnsLoadingOrFetching:F,isTableLoadingOrFetching:w,isTableError:y,connectionType:f,isNonDbConnection:M,handleConnectionChange:O,handleDatabaseChange:D,handleSchemaChange:q,handleDatamodelChange:P,tableName:_,schemaName:K}=oe();function V(){return s?s(K,_,E):e.jsxRuntimeExports.jsx(_s,{schemaName:K,tableName:_,columns:E,status:F?"Loading...":T?"Error":"Success"})}function W(){window.location.href="mailto:support@semaphor.cloud?subject=Help&body=I need help with..."}function v(){if(!r||f==="S3"||f==="API")return null;if(!t||t==="none")return e.jsxRuntimeExports.jsx(le,{showNone:!0,onChange:D,isError:k,isLoading:N,items:u,value:n||"",title:"Database"})}function L(){if(r&&!M&&(!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(le,{showNone:!0,onChange:P,isError:h,isLoading:m,items:l,value:t||"",title:"Model"})}function C(){return!r||f==="S3"||f==="API"||!n||n==="none"?null:e.jsxRuntimeExports.jsx(le,{onChange:q,isError:z,isLoading:b,items:d,value:i||"",title:"Schema"})}function A(){function I(){let G=!1;return f==="API"?(G=!1,G):((f==="S3"||r&&n&&n!=="none"&&i)&&(G=!0),G)}return I()?e.jsxRuntimeExports.jsx(le,{onChange:o,isError:y,items:j,isLoading:w,value:x||"",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(le,{items:a,title:"Connection",value:r||"",onChange:O,isLoading:c,isError:R,connectionTooltip:(($=a==null?void 0:a.find(I=>I.id===r))==null?void 0:$.type)||""}),H(),L(),v(),C(),A()]}),V(),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(Ss,{className:"mr-2 size-4"}),"Help"]})})]})}function Bs(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 x=s.length;if(i!==-1&&(x=i),n!==-1&&n<x&&(x=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,x),a=s.substring(x);return`${o} {{ filters | where }} ${a}`}}function Hs({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(xs,{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(hs,{className:"mr-2 h-4 w-4"}),"Debug with AI"]})]})})})]})}function Ps({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 $s(){const{authToken:s}=e.useSemaphorContext(),r=e.useEditorStore(x=>x.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(x=>x.id===r);return n==null?void 0:n.type}function Gs(){const{authToken:s}=e.useSemaphorContext(),r=S.useRef(null),t=e.useEditorStore(l=>l.applyFilters),[n,i]=S.useState(""),x=e.useEditorStore(l=>l.filterValues),o=e.useEditorStore(l=>l.card.sql),a=$s();return e.jsxRuntimeExports.jsxs(e.HoverCard,{openDelay:0,onOpenChange:async l=>{if(!l)return;console.log("onOpenChange");const d=await e.postRequest("https://semaphor.cloud/api/v1/filter-sql",(s==null?void 0:s.accessToken)||"",{sql:o,active_filters:x,connection_type:a});console.log(d),d.sql?(console.log(d.records),i(d.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 Qs=`
167
167
 
168
168
  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.
169
169