semaphor 0.0.63 → 0.0.64

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
- "use strict";const e=require("./index-bprH5a0e.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-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);/**
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 Os(){const[s,r]=S.useState(""),[t,n]=S.useState(!1),i=e.useDashboardStore(g=>g.lenses),{setLenses:x,setSelectedLensId:o}=e.useDashboardActions(),[a,l]=S.useState(!1),[d,u]=S.useState(!1),j=e.useDashboardStore(g=>g.dashboard),E=e.useDashboardStore(g=>g.filterValues),{authToken:c}=e.useSemaphorContext();async function m(){l(!0);const g=Le(j),h=await zs(s,g,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:g=>{r(g.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 Ms(){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(v=>v.lenses),t=e.useDashboardStore(v=>v.selectedLensId),n=r==null?void 0:r.find(v=>v.id===t),i=e.useDashboardStore(v=>v.dashboard);e.useDashboardStore(v=>v.selectedSheetId);const x=e.useDashboardStore(v=>v.isDashboardEditing),[o,a]=S.useState(!1),l=e.useDashboardStore(v=>v.filterValues),d=e.useDashboardStore(v=>v.isVisualEditing),u=e.useDashboardStore(v=>v.showFilters);e.useDashboardStore(v=>v.showDashboardJSON);const j=e.useDashboardStore(v=>v.onSaveFunction),E=e.useDashboardStore(v=>v.actions.setShowFilters),{addFrame:c,setSelectedFrameId:m}=e.useDashboardStore(v=>v.actions),{getSelectedSheet:g,setIsDashboardEditing:h,setShowDashboardJSON:w}=e.useDashboardStore(v=>v.actions),L=g(),R=()=>{if(!x||!L)return;const v={id:e.v4(),title:"Title",description:"Description",preferences:{onClickFilter:[{columnIndex:0,expression:""}]},type:"bar",sql:"select COUNT(*) from YOUR_TABLE",data:[]},k={id:e.v4(),cards:[v],activeCardId:v.id};c(L.id,k),m(k.id)},z=()=>{h(!0)};async function F(){if(a(!0),!t||!n)return;const v=Le(i),k=JSON.stringify(v),b={...n,template:k,filterValues:l};await Ce(b,s==null?void 0:s.accessToken),e.Jt.success("Lens saved"),j==null||j(v),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&&e.jsxRuntimeExports.jsx(Os,{}),!d&&e.jsxRuntimeExports.jsx(Ms,{}),x&&!d&&e.jsxRuntimeExports.jsxs(e.Button,{variant:"secondary",className:"h-7 p-2",size:"sm",disabled:!x,onClick:R,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:z,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),w(!1)},size:"sm",children:e.jsxRuntimeExports.jsx(e.Cross2Icon,{className:"h-4 w-4",strokeWidth:1.5})}),x&&!d&&e.jsxRuntimeExports.jsx(e.Button,{className:"h-7 p-2",variant:"ghost",disabled:o,onClick:F,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 L;const g=e.createSqlGenConfig(c,o,m),h=(L=a==null?void 0:a.find(R=>R.id===x))==null?void 0:L.name;l(g);const w=e.getSql(g,e.fmt(i||""),e.fmt(n),h);w&&(d(w),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(b=>b.sqlGen),x=e.useEditorStore(b=>b.selectedConnectionId),o=e.useEditorStore(b=>b.selectedDatabaseName),a=e.useEditorStore(b=>b.selectedSchemaName),l=e.useEditorStore(b=>b.selectedTableName),d=e.useEditorStore(b=>b.selectedDatamodelId),u=e.useDashboardStore(b=>b.dashboard.aiScopeTables),{setAIScopeTables:j}=e.useDashboardStore(b=>b.actions),E=e.useEditorStore(b=>b.actions.setRunSql),c=e.useEditorStore(b=>b.actions.setSqlGen),m=e.useEditorStore(b=>b.actions.setIsShowingVisual),g=e.useEditorStore(b=>b.actions.setCardSql),{connectionType:h,modelItems:w}=oe();function L(b){var A;const N=e.createSqlGenConfig(b,i);c(N);const O=(A=w==null?void 0:w.find(q=>q.id===d))==null?void 0:A.name,M=e.getSql(N,e.fmt(s),e.fmt(r),O);M&&(g(M),E(!0))}function R(){return(u==null?void 0:u.find(b=>b.connectinonId===x&&b.tableName===l))!==void 0}function z(b){if(b===!0&&l&&x){const N={connectinonId:x,connectionType:h,databaseName:o,schemaName:a,tableName:l},M=[...u||[],N].filter((A,q,P)=>P.findIndex(_=>_.connectinonId===A.connectinonId&&_.tableName===A.tableName)===q);j(M),e.Jt.success(`Added '${l}' to AI Scope`,{position:"top-right",duration:2500,richColors:!0})}else{const N=(u||[]).filter(O=>O.connectinonId!==x&&O.tableName!==l);j(N),e.Jt(`Removed '${l}' from AI Scope`,{position:"top-right",duration:2e3,richColors:!0})}}function F(){var A;let b=e.getQualifiedTableName(s,r);const N=(A=w==null?void 0:w.find(q=>q.id===d))==null?void 0:A.name;console.log("modelName",N),d&&d!=="none"&&(b=`${e.DATAMODEL_NAMESPCACE}.${N}`);let O=b;return(q=>/[A-Z]/.test(q))(r)&&(O=O.split(".").map(P=>`"${P}"`).join(".")),O}function v(){const b=F();m(!1);const N=h==="MSSQL"?`SELECT top 10 * FROM ${b}`:`SELECT * FROM ${b} LIMIT 10`;g(N),E(!0)}function k(){const b=F();g(`SELECT COUNT(*) as count FROM ${b}`),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:`${R()?"Remove from":"Add to"} AI Scope`,pressed:R(),onPressedChange:z,variant:"outline",className:"h-9 px-2",children:e.jsxRuntimeExports.jsx(e.Bot,{className:e.cn("size-4",{"text-primary":R(),"text-muted-foreground":!R()})})}),e.jsxRuntimeExports.jsxs(e.Button,{disabled:n!=="Success",onClick:v,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:k,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(b=>e.jsxRuntimeExports.jsxs("div",{onClick:()=>L(b),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(b,i)}),children:[e.jsxRuntimeExports.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsxRuntimeExports.jsx(Pe,{column:b}),e.jsxRuntimeExports.jsx("span",{children:b.column_name})]}),e.jsxRuntimeExports.jsx("div",{onClick:N=>N.stopPropagation(),className:"flex items-center justify-end",children:e.NUMBER_DATA_TYPES.includes(b.data_type)&&e.jsxRuntimeExports.jsx(Vs,{column:b})})]},b.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(f=>f.selectedConnectionId),x=e.useEditorStore(f=>f.selectedDatamodelId),o=e.useEditorStore(f=>f.selectedDatabaseName),a=e.useEditorStore(f=>f.selectedSchemaName),l=e.useEditorStore(f=>f.selectedTableName),d=e.useEditorStore(f=>f.actions.setCurrentColumns),u=e.useEditorStore(f=>f.actions.setSelectedConnectionId),j=e.useEditorStore(f=>f.actions.setSelectedDatamodelId),E=e.useEditorStore(f=>f.actions.setSelectedDatabaseName),c=e.useEditorStore(f=>f.actions.setSelectedSchemaName),m=e.useEditorStore(f=>f.actions.setSelectedTableName),g=e.useEditorStore(f=>f.actions.setCardSql);function h(f){return i&&o&&a&&o!=="NA"?!0:i&&f==="API"?!1:!!(i&&f==="S3")}function w(f){return!!(i&&o&&o!=="NA"&&a&&l||i&&(f==="S3"||f==="API")||x&&x)}function L(f){return i&&f?!(f==="API"||f==="S3"):!1}const{data:R,isLoading:z,isError:F}=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:v,isLoading:k,isError:b}=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}),N=R==null?void 0:R.connections.find(f=>f.id===i),O=N==null?void 0:N.type,M=(N==null?void 0:N.type)==="API"||(N==null?void 0:N.type)==="S3",{data:A,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:L(O)}),{data:V,isLoading:W,isFetching:y,isError:D,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:C,isLoading:I,isFetching:$,isError:T,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(O)}),{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:w(O)});S.useEffect(()=>{d(t)},[Q,d,t]),S.useEffect(()=>{},[M,g,m,c,E,N]);const J=(N==null?void 0:N.type)==="API"?(pe=N==null?void 0:N.type)==null?void 0:pe.toLowerCase():l||"",Y=M?"":a||"";function ne(f){c(f),m("")}function X(f){E(f==="none"?"":f),c(""),m(""),f!=="none"&&f!==""&&j("")}function se(f){u(f)}function Ae(f){j(f==="none"?"":f),f!=="none"&&f!==""&&E("")}A&&((de=A==null?void 0:A.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(f=>({...f,data_type:f.data_type.toLowerCase()}))),_&&(t=[]),(B||F)&&(t=[]);const ie=R==null?void 0:R.connections.map(f=>({id:f.id,name:f.name,type:f.type})),be=(p=v==null?void 0:v.datamodels)==null?void 0:p.map(f=>({id:f.id,name:f.name})),me=A==null?void 0:A.databases.map(f=>({id:f.database_name,name:f.database_name})),Se=V==null?void 0:V.schemas.map(f=>({id:f.schema_name,name:f.schema_name})),ye=C==null?void 0:C.tables.map(f=>({id:f.table_name,name:f.table_name}));return{connectionItems:ie,isConnectionsLoading:z,isConnectionsError:F,modelItems:be,isModelsLoading:k,isModelsError:b,databaseItems:me,isDatabasesLoadingOrFetching:q||P,isDatabaseError:_,schemaItems:Se,isSchemaLoadingOrFetching:W||y,isSchemaError:D,tableItems:ye,isTableLoadingOrFetching:I||$,isTableError:T,columns:t,isColumnsLoadingOrFetching:te||ee,isColumnsError:B,isNonDbConnection:M,connectionType:O,tableName:J,schemaName:Y,handleConnectionChange:se,handleDatamodelChange:Ae,handleDatabaseChange:X,handleSchemaChange:ne}}function $e({ColumnsComponent:s}){var $;const r=e.useEditorStore(T=>T.selectedConnectionId),t=e.useEditorStore(T=>T.selectedDatamodelId),n=e.useEditorStore(T=>T.selectedDatabaseName),i=e.useEditorStore(T=>T.selectedSchemaName),x=e.useEditorStore(T=>T.selectedTableName),o=e.useEditorStore(T=>T.actions.setSelectedTableName),{connectionItems:a,modelItems:l,schemaItems:d,databaseItems:u,tableItems:j,columns:E,isConnectionsLoading:c,isModelsLoading:m,isConnectionsError:g,isModelsError:h,isDatabasesLoadingOrFetching:w,isDatabaseError:L,isSchemaLoadingOrFetching:R,isSchemaError:z,isColumnsError:F,isColumnsLoadingOrFetching:v,isTableLoadingOrFetching:k,isTableError:b,connectionType:N,isNonDbConnection:O,handleConnectionChange:M,handleDatabaseChange:A,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:v?"Loading...":F?"Error":"Success"})}function W(){window.location.href="mailto:support@semaphor.cloud?subject=Help&body=I need help with..."}function y(){if(!r||N==="S3"||N==="API")return null;if(!t||t==="none")return e.jsxRuntimeExports.jsx(le,{showNone:!0,onChange:A,isError:L,isLoading:w,items:u,value:n||"",title:"Database"})}function D(){if(r&&!O&&(!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||N==="S3"||N==="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||N==="S3"||N==="API"||!n||n==="none"?null:e.jsxRuntimeExports.jsx(le,{onChange:q,isError:z,isLoading:R,items:d,value:i||"",title:"Schema"})}function I(){function T(){let G=!1;return N==="API"?(G=!1,G):((N==="S3"||r&&n&&n!=="none"&&i)&&(G=!0),G)}return T()?e.jsxRuntimeExports.jsx(le,{onChange:o,isError:b,items:j,isLoading:k,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:M,isLoading:c,isError:g,connectionTooltip:(($=a==null?void 0:a.find(T=>T.id===r))==null?void 0:$.type)||""}),H(),D(),y(),C(),I()]}),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}),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
 
@@ -209,12 +209,12 @@ SELECT label, measure FROM table
209
209
 
210
210
  - Label - Category
211
211
  - Measure - Number
212
- `;function Us({open:s,setOpen:r,userInput:t,setUserInput:n,triggerAIRun:i,setTriggerAIRun:x}){const o=S.useRef(null),a=S.useRef(null),{authToken:l}=e.useSemaphorContext(),[d,u]=S.useState(!1),j=e.useEditorStore(y=>y.actions.setCardSql),E=e.useDashboardStore(y=>y.dashboard.baseQueries),c=e.useEditorStore(y=>y.actions.setRunSql),m=e.useEditorStore(y=>y.actions.setCardType),[g,h]=S.useState([]),w=e.useEditorStore(y=>y.currentColumns),L=e.useEditorStore(y=>y.card.sql),R=e.useEditorStore(y=>y.selectedTableName),z=`
212
+ `;function Us({open:s,setOpen:r,userInput:t,setUserInput:n,triggerAIRun:i,setTriggerAIRun:x}){const o=S.useRef(null),a=S.useRef(null),{authToken:l}=e.useSemaphorContext(),[d,u]=S.useState(!1),j=e.useEditorStore(v=>v.actions.setCardSql),E=e.useDashboardStore(v=>v.dashboard.baseQueries),c=e.useEditorStore(v=>v.actions.setRunSql),m=e.useEditorStore(v=>v.actions.setCardType),[R,h]=S.useState([]),N=e.useEditorStore(v=>v.currentColumns),k=e.useEditorStore(v=>v.card.sql),b=e.useEditorStore(v=>v.selectedTableName),z=`
213
213
  ${t}
214
214
 
215
- Database Query Dialect: ${R==="api"||R==="s3"?"DuckDb":""}
216
- Table Name: ${R}
217
- Table Columns: ${w==null?void 0:w.map(y=>`${y.column_name} | ${y.data_type}`).join(", ")}
218
- User SQL: ${L}
219
- ${E&&`Base Queries: ${JSON.stringify(E)} `}`,F=` When the user asks for a specific chart please use the following query structure to generate the chart query. Do not make up the column names. Use only the table columns provided above for the query. Replace x-axis, y-axis, and lables with the appropriate column names.
220
- Visual Query Syntax: ${Qs}`,{data:v,isLoading:k,isFetching:b,isError:N,refetch:O}=e.useQuery({queryKey:["ai-query"],queryFn:()=>e.getRequest("https://semaphor.cloud/api/v1/ai",(l==null?void 0:l.accessToken)||"",{user_content:`userContent: ${z} ${d?F:""}`}),enabled:!1});function M(y){if(y.toLowerCase().includes("bar"))m("bar");else if(y.toLowerCase().includes("line"))m("line");else if(y.toLowerCase().includes("bubble"))m("bubble");else if(y.toLowerCase().includes("scatter"))m("scatter");else if(y.toLowerCase().includes("stacked"))m("stackedBar");else if(y.toLowerCase().includes("pie"))m("pie");else if(y.toLowerCase().includes("donut")||y.toLowerCase().includes("doughnut"))m("doughnut");else if(y.toLowerCase().includes("radar"))m("radar");else return m("bar"),!1;return!0}S.useEffect(()=>{v&&h(y=>[...y,{role:"ai",content:v.response}])},[v]),S.useEffect(()=>{const y=setTimeout(()=>{var D;a.current&&(a.current.scroll({top:a.current.scrollHeight,behavior:"smooth"}),(D=o.current)==null||D.focus())},100);return()=>clearTimeout(y)},[g]);function A(){t&&(h(y=>[...y,{role:"user",content:t}]),M(t)&&u(!0),n(""),O())}S.useEffect(()=>{i&&(A(),x(!1))},[i,x]);const q={fontFamily:"Arial, sans-serif",lineHeight:1.6,fontSize:15,width:"100%"},P={fontFamily:"monospace",fontSize:14,lineHeight:1.6},_={fontFamily:"Arial, sans-serif",lineHeight:1.6,fontSize:15,padding:"2px 0",marginLeft:20,listStyleType:"disc"},K={p:({node:y,...D})=>e.jsxRuntimeExports.jsx("p",{style:q,...D}),code:({node:y,...D})=>e.jsxRuntimeExports.jsx("code",{className:"rounded-sm bg-muted px-2 py-1 text-sm",...D}),pre:({node:y,...D})=>e.jsxRuntimeExports.jsxs("pre",{className:"space-y-2 rounded-sm bg-muted/50 p-3",style:P,children:[e.jsxRuntimeExports.jsx("code",{className:"whitespace-normal text-sm",children:D.children}),e.jsxRuntimeExports.jsxs("div",{className:"flex justify-start gap-2",children:[e.jsxRuntimeExports.jsx(e.Button,{onClick:V,size:"sm",variant:"outline",children:e.jsxRuntimeExports.jsx(e.ClipboardCopyIcon,{})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:H=>{const C=V(H);C&&(r(!1),j(C),c(!0))},size:"sm",variant:"outline",children:e.jsxRuntimeExports.jsx(e.PlayIcon,{})})]})]}),li:({node:y,...D})=>e.jsxRuntimeExports.jsx("li",{style:_,...D})};function V(y){const D=y.currentTarget.closest("pre");if(!D)return;const H=D.textContent||D.innerText;return navigator.clipboard.writeText(H).then(()=>console.log("Text copied to clipboard")).catch(C=>console.error("Error in copying text: ",C)),H}function W(){return g==null?void 0:g.map((y,D)=>y.role==="user"?e.jsxRuntimeExports.jsxs("div",{className:"flex items-start rounded-md bg-muted p-3 text-sm",children:[e.jsxRuntimeExports.jsx(Is,{className:"mr-2 h-5 w-5"}),e.jsxRuntimeExports.jsx("div",{children:y.content})]},D):y.role==="ai"?e.jsxRuntimeExports.jsx(e.Markdown,{className:"w-full overflow-auto py-1",components:K,children:v==null?void 0:v.response.replace(/DuckDB/gi,"Semaphor")},D):e.jsxRuntimeExports.jsx("div",{},D))}return e.jsxRuntimeExports.jsxs(e.Dialog,{open:s,onOpenChange:r,children:[e.jsxRuntimeExports.jsx(e.DialogTrigger,{asChild:!0,children:e.jsxRuntimeExports.jsx(e.Button,{size:"sm",className:"w-full justify-start border font-normal text-muted-foreground focus-visible:ring-0 focus-visible:ring-offset-0",variant:"secondary",children:"Type your question here..."})}),e.jsxRuntimeExports.jsxs(e.DialogContent,{className:"flex flex-col justify-between overflow-auto sm:max-w-[425px] md:max-h-[625px] md:min-w-[625px]",children:[e.jsxRuntimeExports.jsxs(e.DialogHeader,{children:[e.jsxRuntimeExports.jsx(e.DialogTitle,{children:"Assistant"}),e.jsxRuntimeExports.jsx(e.DialogDescription,{children:"What can I help you with?"})]}),e.jsxRuntimeExports.jsx("div",{ref:a,className:"h-[625px] w-full overflow-auto border-t border-t-muted",children:e.jsxRuntimeExports.jsx("div",{className:"space-y-4 py-2 pr-3",role:"messages",children:W()})}),e.jsxRuntimeExports.jsx("div",{children:e.jsxRuntimeExports.jsxs("div",{className:"flex w-full items-center rounded-md border",children:[e.jsxRuntimeExports.jsx(e.Textarea,{autoFocus:!0,ref:o,onKeyDown:y=>{y.key==="Enter"&&!y.shiftKey&&(y.preventDefault(),n(""),A())},placeholder:"Type your question here...",onFocus:y=>{const D=y.target,H=D.value.length;D.setSelectionRange(H,H)},className:e.cn("max-h-10 min-h-7 resize-none border-none focus-visible:ring-0 focus-visible:ring-ring focus-visible:ring-offset-0"),disabled:k||b,value:t,onChange:y=>n(y.target.value)})," ",e.jsxRuntimeExports.jsx(e.Button,{className:"h-8",size:"sm",variant:"ghost",onClick:A,children:!k&&!b?e.jsxRuntimeExports.jsx(e.PaperPlaneIcon,{}):e.jsxRuntimeExports.jsx(ce,{className:"mr-2 h-4 w-4 animate-spin text-foreground/50"})})]})})]})]})}var Ge={color:void 0,size:void 0,className:void 0,style:void 0,attr:void 0},ze=S.createContext&&S.createContext(Ge),Ks=["attr","size","title"];function Ws(s,r){if(s==null)return{};var t=Js(s,r),n,i;if(Object.getOwnPropertySymbols){var x=Object.getOwnPropertySymbols(s);for(i=0;i<x.length;i++)n=x[i],!(r.indexOf(n)>=0)&&Object.prototype.propertyIsEnumerable.call(s,n)&&(t[n]=s[n])}return t}function Js(s,r){if(s==null)return{};var t={},n=Object.keys(s),i,x;for(x=0;x<n.length;x++)i=n[x],!(r.indexOf(i)>=0)&&(t[i]=s[i]);return t}function fe(){return fe=Object.assign?Object.assign.bind():function(s){for(var r=1;r<arguments.length;r++){var t=arguments[r];for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(s[n]=t[n])}return s},fe.apply(this,arguments)}function Fe(s,r){var t=Object.keys(s);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(s);r&&(n=n.filter(function(i){return Object.getOwnPropertyDescriptor(s,i).enumerable})),t.push.apply(t,n)}return t}function ge(s){for(var r=1;r<arguments.length;r++){var t=arguments[r]!=null?arguments[r]:{};r%2?Fe(Object(t),!0).forEach(function(n){Ys(s,n,t[n])}):Object.getOwnPropertyDescriptors?Object.defineProperties(s,Object.getOwnPropertyDescriptors(t)):Fe(Object(t)).forEach(function(n){Object.defineProperty(s,n,Object.getOwnPropertyDescriptor(t,n))})}return s}function Ys(s,r,t){return r=Xs(r),r in s?Object.defineProperty(s,r,{value:t,enumerable:!0,configurable:!0,writable:!0}):s[r]=t,s}function Xs(s){var r=Zs(s,"string");return typeof r=="symbol"?r:String(r)}function Zs(s,r){if(typeof s!="object"||s===null)return s;var t=s[Symbol.toPrimitive];if(t!==void 0){var n=t.call(s,r||"default");if(typeof n!="object")return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return(r==="string"?String:Number)(s)}function Qe(s){return s&&s.map((r,t)=>S.createElement(r.tag,ge({key:t},r.attr),Qe(r.child)))}function Z(s){return r=>S.createElement(et,fe({attr:ge({},s.attr)},r),Qe(s.child))}function et(s){var r=t=>{var{attr:n,size:i,title:x}=s,o=Ws(s,Ks),a=i||t.size||"1em",l;return t.className&&(l=t.className),s.className&&(l=(l?l+" ":"")+s.className),S.createElement("svg",fe({stroke:"currentColor",fill:"currentColor",strokeWidth:"0"},t.attr,n,o,{className:l,style:ge(ge({color:s.color||t.color},t.style),s.style),height:a,width:a,xmlns:"http://www.w3.org/2000/svg"}),x&&S.createElement("title",null,x),s.children)};return ze!==void 0?S.createElement(ze.Consumer,null,t=>r(t)):r(Ge)}function st(s){return Z({tag:"svg",attr:{viewBox:"0 0 448 512"},child:[{tag:"path",attr:{d:"M439.8 200.5c-7.7-30.9-22.3-54.2-53.4-54.2h-40.1v47.4c0 36.8-31.2 67.8-66.8 67.8H172.7c-29.2 0-53.4 25-53.4 54.3v101.8c0 29 25.2 46 53.4 54.3 33.8 9.9 66.3 11.7 106.8 0 26.9-7.8 53.4-23.5 53.4-54.3v-40.7H226.2v-13.6h160.2c31.1 0 42.6-21.7 53.4-54.2 11.2-33.5 10.7-65.7 0-108.6zM286.2 404c11.1 0 20.1 9.1 20.1 20.3 0 11.3-9 20.4-20.1 20.4-11 0-20.1-9.2-20.1-20.4.1-11.3 9.1-20.3 20.1-20.3zM167.8 248.1h106.8c29.7 0 53.4-24.5 53.4-54.3V91.9c0-29-24.4-50.7-53.4-55.6-35.8-5.9-74.7-5.6-106.8.1-45.2 8-53.4 24.7-53.4 55.6v40.7h106.9v13.6h-147c-31.1 0-58.3 18.7-66.8 54.2-9.8 40.7-10.2 66.1 0 108.6 7.6 31.6 25.7 54.2 56.8 54.2H101v-48.8c0-35.3 30.5-66.4 66.8-66.4zm-6.7-142.6c-11.1 0-20.1-9.1-20.1-20.3.1-11.3 9-20.4 20.1-20.4 11 0 20.1 9.2 20.1 20.4s-9 20.3-20.1 20.3z"},child:[]}]})(s)}function tt(){const{theme:s}=e.useTheme(),r=S.useRef(),t=S.useRef(),[n,i]=S.useState(!1),[x,o]=S.useState(!1),[a,l]=S.useState(!1),[d,u]=S.useState(""),[j,E]=S.useState(!1),{authToken:c}=e.useSemaphorContext();e.useDashboardStore(p=>p.selectedSheetId);const m=e.useDashboardStore(p=>p.dashboard.baseQueries),g=e.useEditorStore(p=>p.card),h=e.useDashboardStore(p=>p.theme),w=e.useEditorStore(p=>p.isShowingVisual),L=e.useEditorStore(p=>p.selectedConnectionId),R=e.useEditorStore(p=>p.selectedDatabaseName),z=e.useEditorStore(p=>p.selectedDatamodelId),F=e.useEditorStore(p=>p.selectedSchemaName);e.useDashboardStore(p=>p.actions.updateFrameCard);const v=e.useEditorStore(p=>p.selectedTableName),k=e.useEditorStore(p=>p.card.sql),b=e.useEditorStore(p=>p.card.python),N=e.resolveBaseQuery(k,m),O=e.useEditorStore(p=>p.selectedConnectionId),M=e.useEditorStore(p=>p.frame),A=e.useDashboardStore(p=>p.filterValues),q=e.useEditorStore(p=>p.applyFilters),{setCardCustomCfg:P,setQueryResultColumns:_,setFilterValues:K,setCardSql:V,setCardPython:W,setQueryError:y,setPythonStdOut:D,setCardPreferences:H}=e.useEditorStore(p=>p.actions),C=e.useEditorStore(p=>p.onSave),I=e.useEditorStore(p=>p.actions.setApplyFilters),$=e.useEditorStore(p=>p.onClose),T=e.useEditorStore(p=>p.actions.setCardData),G=e.useEditorStore(p=>p.actions.setSqlGen),Q=e.useEditorStore(p=>p.runSql),te=e.useEditorStore(p=>p.actions.setRunSql),ee=e.useEditorStore(p=>p.actions.setIsSqlRunning),{data:B,isLoading:J,isFetching:Y,isSuccess:ne,isError:X,error:se,status:Ae,refetch:ie}=e.useQuery({queryKey:[N,b],queryFn:()=>e.postRequest("https://semaphor.cloud/api/v1/query",(c==null?void 0:c.accessToken)||"",{connection_id:O,sql:N,python:b===e.PYTHON_DEFAULT_CODE?"":b,active_filters:q?A:[]}),enabled:!1,retry:!1});S.useEffect(()=>{if(B&&(T(B.records),B.rowLimitExceeded&&e.Jt.error("Row limit (10,000) exceeded. Refine your query.",{position:"top-center",richColors:!0}),D((B==null?void 0:B.output)||""),B.records.length>0)){const{dimensionKeys:p}=e.getKeys(B.records);_(p)}},[B,T,_,D]),S.useEffect(()=>{Q&&(ie(),te(!1))},[Q,ie,te]),S.useEffect(()=>{(J||Y)&&ee(!0),(X||ne)&&ee(!1),X?(y(se.message),T([]),_([]),D("")):y("")},[J,Y,B,D,X,ne,ee,T,_,y,se]);function be(){V(""),T([]),G({}),P(""),H({})}const me=p=>{t.current=p};function Se(p,f){if(p.length===0)return"";if(f){const re=p.find(U=>U.id===f);if(re){const U=re.tabTitle;if(U=="All__Header")return p[0].id;if(U&&U.endsWith("__Header")){const os=U.split("__")[0],Ie=p.find(is=>is.tabTitle===os);return Ie?Ie.id:p[0].id}return f}}return p[0].id}function ye(){let p=k;k&&!k.includes("{{")&&(p=Bs(k),V(p));const f={...g,lastSelectedSchema:F,lastSelectedDatamodelId:z,lastSelectedDatabase:R,lastSelectedTable:v,connectionId:L,type:w?g.type:"table",sql:p,customCfg:w?g.customCfg:null},re=M.cards.map(ve=>ve.id===g.id?f:ve),U={...M,cards:re,activeCardId:Se(re,M.activeCardId)};C==null||C(U)}function pe(){$==null||$()}S.useEffect(()=>{const p=r.current,f=t.current;if(p){const re=window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light",U=h==="system"?re:h;p.editor.defineTheme("default",{base:U==="light"?"vs":"vs-dark",inherit:!0,rules:[],colors:{"editor.background":U==="light"?"#ffffff":e.getCssVariableValue("--semaphor-background")}}),p.editor.setTheme("default")}return f&&p&&f.addCommand(p.KeyMod.Shift|p.KeyCode.Enter,function(){return console.log("Executing query..."),ie(),!1}),()=>{}},[s,h,r.current]);function de(p){r.current=p}function he(){return e.jsxRuntimeExports.jsxs(e.jsxRuntimeExports.Fragment,{children:[x&&e.jsxRuntimeExports.jsx("div",{className:"xbg-yellow-100 relative flex w-1/3 min-w-0 grow overflow-hidden border-l p-1 text-xs",role:"editor-filter-container",children:e.jsxRuntimeExports.jsxs("div",{className:"w-[99%]",children:[e.jsxRuntimeExports.jsxs("div",{className:"flex items-center gap-2 pt-3",children:[e.jsxRuntimeExports.jsx(Ps,{checked:q,onCheckedChange:()=>I(!q),text:"Apply Filters"}),e.jsxRuntimeExports.jsx(Gs,{}),A&&x&&e.jsxRuntimeExports.jsx(e.Cross2Icon,{onClick:()=>o(!1),className:"bg-background/50 text-foreground/50 hover:cursor-pointer hover:text-foreground"})]}),e.jsxRuntimeExports.jsx(e.Ft,{theme:"default",onChange:p=>{if(p)try{JSON.parse(p),K(JSON.parse(p))}catch{}},defaultLanguage:"json",className:"mt-1 min-h-[220px]",value:JSON.stringify(A,null,2),options:{readOnly:!0,minimap:{enabled:!1},lineNumbers:"off",glyphMargin:!1,wordWrap:"on",scrollbar:{verticalScrollbarSize:0,horizontalScrollbarSize:0},fontSize:12,renderLineHighlight:"none"}})]})}),A&&!x&&e.jsxRuntimeExports.jsx(e.Filter,{onClick:()=>o(!0),className:e.cn("absolute bottom-4 right-6 h-3 w-3 text-foreground/50 hover:cursor-pointer hover:text-foreground",{"font-bold text-red-800":q})})]})}function je(){return e.jsxRuntimeExports.jsxs(e.ResizablePanelGroup,{className:"flex grow pb-1",direction:"vertical",role:"editor-resizable-group",children:[e.jsxRuntimeExports.jsxs(e.ResizablePanel,{id:"1",order:1,defaultSize:n?20:100,className:"relative flex grow",children:[e.jsxRuntimeExports.jsx("div",{role:"sql-container",className:"relative flex w-[99%]",children:e.jsxRuntimeExports.jsx(e.Ft,{theme:"default",className:"pt-3",onChange:p=>{V(p)},value:k,options:{minimap:{enabled:!1},wordWrap:"on",scrollbar:{verticalScrollbarSize:0,horizontalScrollbarSize:0},fontSize:14,renderLineHighlight:"none"},defaultLanguage:"sql",beforeMount:de,onMount:me})}),n&&e.jsxRuntimeExports.jsx("code",{className:"absolute right-6 top-3 text-sm text-muted-foreground/70",children:"sql"})]}),n&&e.jsxRuntimeExports.jsxs(e.jsxRuntimeExports.Fragment,{children:[e.jsxRuntimeExports.jsx(e.ResizableHandle,{withHandle:!0,className:"border"}),e.jsxRuntimeExports.jsxs(e.ResizablePanel,{id:"2",order:2,defaultSize:80,className:"relative flex grow",children:[e.jsxRuntimeExports.jsx("div",{role:"python-container",className:"relative flex w-[99%] pt-0",children:e.jsxRuntimeExports.jsx(e.Ft,{className:"pt-3",theme:"default",onChange:p=>{W(p&&p.trim()||"")},value:b||e.PYTHON_DEFAULT_CODE,options:{minimap:{enabled:!1},wordWrap:"on",scrollbar:{verticalScrollbarSize:0,horizontalScrollbarSize:0},fontSize:14,renderLineHighlight:"none"},defaultLanguage:"python",beforeMount:de,onMount:me})}),e.jsxRuntimeExports.jsx("code",{className:"absolute right-6 top-3 text-sm text-muted-foreground/70",children:"python"})]})]})]})}return e.jsxRuntimeExports.jsxs("section",{role:"editor-section",className:"flex grow flex-col justify-end",children:[e.jsxRuntimeExports.jsxs("div",{role:"sql-editor",className:"relative flex grow justify-between overflow-y-scroll",children:[je(),he()]}),e.jsxRuntimeExports.jsxs("div",{role:"editor-controls",className:"item-center flex flex-wrap justify-between gap-2 px-6 py-4",children:[e.jsxRuntimeExports.jsxs("div",{className:"flex grow items-center gap-2",children:[e.jsxRuntimeExports.jsxs(e.Button,{title:"Shift + Enter",disabled:J||Y,onClick:()=>{ie()},className:"shrink-0",size:"sm",variant:"outline",children:[J||Y?e.jsxRuntimeExports.jsx(ce,{className:"mr-2 h-4 w-4 animate-spin text-foreground/50"}):e.jsxRuntimeExports.jsx(vs,{className:"mr-2 h-4 w-4"}),"Run"]}),X&&e.jsxRuntimeExports.jsx(Hs,{error:se.message,setShowAIDialog:l,setTriggerAIRun:E,setUserInputforAI:u}),e.jsxRuntimeExports.jsxs(e.Button,{onClick:be,className:"",size:"sm",variant:"outline",children:[e.jsxRuntimeExports.jsx(ms,{className:"mr-2 size-4"}),"Clear"]}),e.jsxRuntimeExports.jsx(e.Toggle,{pressed:n,onPressedChange:p=>i(p),className:"",size:"sm",variant:"outline",children:e.jsxRuntimeExports.jsx(st,{className:"size-4 text-foreground/70"})}),e.jsxRuntimeExports.jsx(Us,{open:a,setOpen:l,userInput:d,triggerAIRun:j,setTriggerAIRun:E,setUserInput:p=>u(p)})]}),e.jsxRuntimeExports.jsxs("div",{className:"flex items-end gap-2",children:[e.jsxRuntimeExports.jsxs(e.Button,{onClick:ye,size:"sm",variant:"outline",children:[e.jsxRuntimeExports.jsx(e.Check,{className:"mr-2 size-4 font-bold text-green-600"}),"Accept"]}),e.jsxRuntimeExports.jsxs(e.Button,{onClick:pe,className:"w-full",size:"sm",variant:"outline",children:[e.jsxRuntimeExports.jsx(e.Cross2Icon,{className:"mr-2 size-4"}),"Close"]})]})]})]})}function nt({data:s}){var o;const[r,t]=S.useState([]),i=Object.keys(s[0]).map(a=>({accessorKey:a,header:({column:l})=>{const d=l.getIsSorted();return e.jsxRuntimeExports.jsx("div",{className:"flex gap-2",children:e.jsxRuntimeExports.jsxs("div",{className:"flex cursor-pointer items-center",onClick:()=>l.toggleSorting(l.getIsSorted()==="asc"),children:[a,d==="asc"?e.jsxRuntimeExports.jsx(e.TriangleUpIcon,{className:"ml-2 h-5 w-5"}):d==="desc"?e.jsxRuntimeExports.jsx(e.TriangleDownIcon,{className:"ml-2 h-5 w-5"}):null]})})}})),x=e.useReactTable({data:s,columns:i,getCoreRowModel:e.getCoreRowModel(),getPaginationRowModel:e.getPaginationRowModel(),onSortingChange:t,getSortedRowModel:e.getSortedRowModel(),manualPagination:!0,state:{sorting:r}});return e.jsxRuntimeExports.jsxs(e.Table$1,{children:[e.jsxRuntimeExports.jsx(e.TableHeader,{children:x.getHeaderGroups().map(a=>e.jsxRuntimeExports.jsx(e.TableRow,{children:a.headers.map(l=>e.jsxRuntimeExports.jsx(e.TableHead,{className:"sticky top-0 bg-muted",children:l.isPlaceholder?null:e.flexRender(l.column.columnDef.header,l.getContext())},l.id))},a.id))}),e.jsxRuntimeExports.jsx(e.TableBody,{children:(o=x.getRowModel().rows)!=null&&o.length?x.getRowModel().rows.map(a=>e.jsxRuntimeExports.jsx(e.TableRow,{className:"whitespace-nowrap py-2","data-state":a.getIsSelected()&&"selected",children:a.getVisibleCells().map(l=>e.jsxRuntimeExports.jsx(e.TableCell,{children:e.flexRender(l.column.columnDef.cell,l.getContext())},l.id))},a.id)):e.jsxRuntimeExports.jsx(e.TableRow,{children:e.jsxRuntimeExports.jsx(e.TableCell,{colSpan:i.length,className:"h-24 text-center",children:"No results."})})})]})}function Ue({className:s,...r}){var E;S.useState(0);const t=e.useDashboardStore(c=>c.themeStyle),n=e.useEditorStore(c=>c.card),i=e.useEditorStore(c=>c.frame),x=e.useDashboardStore(c=>c.dashboard.filters),o=e.useDashboardStore(c=>c.filterValues),a=e.useEditorStore(c=>c.actions.setRunSql),{updateFilter:l}=e.useDashboardActions(),d=x==null?void 0:x.find(c=>c.id===i.filterId),u=e.useEditorStore(c=>c.actions.setCard);if(S.useEffect(()=>{n.sql&&a(!0)},[o]),S.useEffect(()=>{},[n.data,n.type,n.cfg,n.customCfg,t,n.preferences]),!n.id)return null;let j;return n.data&&n.data.length>0&&(j=e.createChartConfig({data:n.data,cardType:n.type,cfg:n.cfg,customCfg:n.customCfg,preferences:n.preferences})),e.jsxRuntimeExports.jsxs(e.Card,{role:"editor-visual-card",className:e.cn("relative flex h-full flex-col rounded-none",s),...r,children:[e.jsxRuntimeExports.jsxs(e.CardHeader,{className:"flex flex-row items-start justify-between py-4",children:[e.jsxRuntimeExports.jsxs("div",{children:[e.jsxRuntimeExports.jsx(e.Editable,{text:n.title,onSave:c=>u({...n,title:c}),children:e.jsxRuntimeExports.jsx("div",{className:"flex items-center gap-2",children:e.jsxRuntimeExports.jsx(e.CardTitle,{className:"text-base",children:n.title})})},n.title),e.jsxRuntimeExports.jsx(e.Editable,{text:n.description||"",onSave:c=>u({...n,description:c}),children:e.jsxRuntimeExports.jsxs(e.CardDescription,{children:[" ",n.description]})},n.description)]}),d&&e.jsxRuntimeExports.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxRuntimeExports.jsx(e.Editable,{className:"my-1",text:d.title||d.column,onSave:c=>l({...d,title:c}),children:e.jsxRuntimeExports.jsx(e.Label,{children:d.title})}),e.getFilterComponent(d)]})]}),e.jsxRuntimeExports.jsxs(e.CardContent,{className:"flex grow flex-col pb-3",children:[n.type!=="table"&&j&&e.jsxRuntimeExports.jsx(e.ChartJsVisual,{cfg:j},JSON.stringify(j)+JSON.stringify(n.preferences)+((E=n==null?void 0:n.preferences)==null?void 0:E.customVisualCode)),n.type==="table"&&n.data&&n.data.length>0&&e.jsxRuntimeExports.jsx(e.$57acba87d6e25586$export$ccf8d8d7bbf3c2cc,{className:"flex min-h-0 flex-1 grow basis-0",children:e.jsxRuntimeExports.jsx(e.TableVisual,{card:n,data:n==null?void 0:n.data})})]})]})}function rt(){const[s,r]=S.useState(!1),[t,n]=S.useState(""),[i,x]=S.useState(""),[o,a]=S.useState(""),[l,d]=S.useState(""),u=e.useEditorStore(R=>R.card),j=e.useEditorStore(R=>R.card.customCfg),{setCardCustomCfg:E,setCustomVisualCode:c}=e.useEditorActions();function m(R){var v,k;const z={...R,data:{...R==null?void 0:R.data,datasets:(k=(v=R==null?void 0:R.data)==null?void 0:v.datasets)==null?void 0:k.map(b=>({...b,data:[]}))}};return JSON.stringify(z,null,1)}function g(){var z,F;if(!u.data||u.data.length===0)return;const R=e.createChartConfig({data:u.data,cardType:u.type,cfg:u.cfg,preferences:u.preferences});R&&(n(JSON.stringify(R,null,1)),(z=u==null?void 0:u.preferences)!=null&&z.customVisualCode&&a((F=u==null?void 0:u.preferences)==null?void 0:F.customVisualCode),j&&x(JSON.stringify(j,null,1)))}function h(){if(o&&c(o),!!i)try{const R=JSON.parse(i);return R?(E(R),d(""),x(""),R):void 0}catch(R){console.log(R),d("Invalid JSON")}}function w(){x(""),E(null)}function L(){let R;if(j){const z=e._.cloneDeep(u.cfg),F=e._.merge(z,j);return R=m(F),R}return t?(R=m(JSON.parse(t)),R):""}return e.jsxRuntimeExports.jsxs(e.Dialog,{open:s,onOpenChange:r,children:[e.jsxRuntimeExports.jsx(e.DialogTrigger,{asChild:!0,children:e.jsxRuntimeExports.jsx(e.Button,{onClick:g,className:` ${j&&"border-foreground/50 dark:border-foreground/70"}`,size:"sm",variant:"outline",children:e.jsxRuntimeExports.jsx(e.Settings,{className:"h-4 w-4"})})}),e.jsxRuntimeExports.jsxs(e.DialogContent,{className:"max-h-[70vh] min-h-[70vh] overflow-auto sm:min-w-[900px] lg:min-w-[1200px]",children:[e.jsxRuntimeExports.jsxs(e.DialogHeader,{className:"",children:[e.jsxRuntimeExports.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxRuntimeExports.jsx(e.DialogTitle,{children:"Customize Card"}),e.jsxRuntimeExports.jsxs(e.Tooltip,{children:[e.jsxRuntimeExports.jsx(e.TooltipTrigger,{children:e.jsxRuntimeExports.jsx(fs,{onClick:()=>{navigator.clipboard.writeText(u.id)},className:"size-3 cursor-pointer text-muted-foreground/70 transition-colors hover:text-muted-foreground"})}),e.jsxRuntimeExports.jsx(e.TooltipContent,{side:"right",align:"center",children:e.jsxRuntimeExports.jsx("p",{className:"text-xs",children:"Copy Card ID"})})]})]}),e.jsxRuntimeExports.jsxs(e.DialogDescription,{children:["See the configuration options and documentation",e.jsxRuntimeExports.jsx("a",{target:"_blank",className:"ml-1 text-blue-500 underline",href:"https://www.chartjs.org/docs/latest/samples/bar/vertical.html",children:"here."})]})]}),e.jsxRuntimeExports.jsxs("div",{className:"flex grow gap-2",children:[e.jsxRuntimeExports.jsx(Ue,{className:"w-1/2 rounded shadow-none"}),e.jsxRuntimeExports.jsxs(e.Tabs,{defaultValue:"custom-config",className:"flex w-1/2 flex-col",children:[e.jsxRuntimeExports.jsxs(e.TabsList,{className:"justify-start rounded-sm rounded-b-none border border-b-0",children:[e.jsxRuntimeExports.jsxs(e.TabsTrigger,{value:"custom-config",children:[j&&e.jsxRuntimeExports.jsx(e.CheckIcon,{className:"mr-1 h-5 w-5 text-green-600"}),j?"Custom Config":"Default Config"]}),e.jsxRuntimeExports.jsx(e.TabsTrigger,{className:"",value:"output",children:"Output"}),e.jsxRuntimeExports.jsx(e.TabsTrigger,{className:"",value:"custom-code",children:"Custom Code"})]}),e.jsxRuntimeExports.jsx(e.TabsContent,{className:"bg-red-x mt-0 grow rounded-b border border-t-0 p-2",value:"output",children:e.jsxRuntimeExports.jsx(e.Textarea,{disabled:!0,value:t,className:"h-full resize-none border-none font-mono focus-visible:ring-0 focus-visible:ring-offset-0"})}),e.jsxRuntimeExports.jsx(e.TabsContent,{className:"mt-0 grow rounded-b border border-t-0",value:"custom-config",children:e.jsxRuntimeExports.jsx(e.Ft,{className:"h-full w-full overflow-hidden",theme:"default",options:{minimap:{enabled:!1},wordWrap:"on",scrollbar:{verticalScrollbarSize:0,horizontalScrollbarSize:0},fontSize:14,renderLineHighlight:"none"},defaultLanguage:"json",value:L(),onChange:R=>x(R)})}),e.jsxRuntimeExports.jsx(e.TabsContent,{className:"mt-0 grow rounded-b border border-t-0",value:"custom-code",children:e.jsxRuntimeExports.jsx(e.Ft,{className:"h-full w-full overflow-hidden",theme:"default",options:{minimap:{enabled:!1},wordWrap:"on",scrollbar:{verticalScrollbarSize:0,horizontalScrollbarSize:0},fontSize:14,renderLineHighlight:"none"},defaultLanguage:"javascript",value:o,onChange:R=>a(R||"")})})]})]}),e.jsxRuntimeExports.jsxs(e.DialogFooter,{className:"flex items-center",children:[e.jsxRuntimeExports.jsx(e.Label,{className:"mr-2 text-red-500",children:l}),e.jsxRuntimeExports.jsx(e.Button,{disabled:!j,onClick:w,variant:"outline",children:"Reset"}),e.jsxRuntimeExports.jsx(e.Button,{onClick:h,variant:"outline",children:"Apply"}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>r(!1),variant:"outline",children:"Close"})]})]})]})}function Ke(s){return Z({tag:"svg",attr:{viewBox:"0 0 1024 1024"},child:[{tag:"path",attr:{d:"M926.8 397.1l-396-288a31.81 31.81 0 0 0-37.6 0l-396 288a31.99 31.99 0 0 0-11.6 35.8l151.3 466a32 32 0 0 0 30.4 22.1h489.5c13.9 0 26.1-8.9 30.4-22.1l151.3-466c4.2-13.2-.5-27.6-11.7-35.8zM838.6 417l-98.5 32-200-144.7V199.9L838.6 417zM466 567.2l-89.1 122.3-55.2-169.2L466 567.2zm-116.3-96.8L484 373.3v140.8l-134.3-43.7zM512 599.2l93.9 128.9H418.1L512 599.2zm28.1-225.9l134.2 97.1L540.1 514V373.3zM558 567.2l144.3-46.9-55.2 169.2L558 567.2zm-74-367.3v104.4L283.9 449l-98.5-32L484 199.9zM169.3 470.8l86.5 28.1 80.4 246.4-53.8 73.9-113.1-348.4zM327.1 853l50.3-69h269.3l50.3 69H327.1zm414.5-33.8l-53.8-73.9 80.4-246.4 86.5-28.1-113.1 348.4z"},child:[]}]})(s)}function We(s){return Z({tag:"svg",attr:{viewBox:"0 0 256 256",fill:"currentColor"},child:[{tag:"path",attr:{d:"M137.39,24.06A16,16,0,0,0,120,40V80.67a15.86,15.86,0,0,0,13.25,15.76A32,32,0,1,1,96,129.68c-.41-8.22,1.27-15,5-20.26h0a15.86,15.86,0,0,0-1.69-20.47L71.69,60.68a16,16,0,0,0-23.63,1.1A103.6,103.6,0,0,0,55,202.05,103.24,103.24,0,0,0,128,232h1.49A104.3,104.3,0,0,0,232,129.48C232.75,75.18,191.19,28.88,137.39,24.06ZM60.32,71.94l27.61,28.19,0,.06A43.29,43.29,0,0,0,80.44,120H40.36A87.13,87.13,0,0,1,60.32,71.94ZM40.37,136h40.3A48,48,0,0,0,120,175.34v40.3A88,88,0,0,1,40.37,136Zm149.77,54.14A87.45,87.45,0,0,1,136,215.61V175.34a47.55,47.55,0,0,0,24.73-12.23A48,48,0,0,0,136,80.66L136,40c45.52,4.08,80.67,43.28,80,89.25A87.45,87.45,0,0,1,190.14,190.14Z"},child:[]}]})(s)}function Je(s){return Z({tag:"svg",attr:{viewBox:"0 0 256 256",fill:"currentColor"},child:[{tag:"path",attr:{d:"M128,24A104,104,0,1,0,232,128,104.11,104.11,0,0,0,128,24Zm87.63,96H191.48A64.1,64.1,0,0,0,136,64.52V40.37A88.13,88.13,0,0,1,215.63,120ZM120,120H80.68A48.09,48.09,0,0,1,120,80.68Zm0,16v39.32A48.09,48.09,0,0,1,80.68,136Zm16,0h39.32A48.09,48.09,0,0,1,136,175.32Zm0-16V80.68A48.09,48.09,0,0,1,175.32,120ZM120,40.37V64.52A64.1,64.1,0,0,0,64.52,120H40.37A88.13,88.13,0,0,1,120,40.37ZM40.37,136H64.52A64.1,64.1,0,0,0,120,191.48v24.15A88.13,88.13,0,0,1,40.37,136ZM136,215.63V191.48A64.1,64.1,0,0,0,191.48,136h24.15A88.13,88.13,0,0,1,136,215.63Z"},child:[]}]})(s)}function Ye(s){return Z({tag:"svg",attr:{viewBox:"0 0 24 24",strokeWidth:"2",stroke:"currentColor",fill:"none",strokeLinecap:"round",strokeLinejoin:"round"},child:[{tag:"path",attr:{stroke:"none",d:"M0 0h24v24H0z",fill:"none"},child:[]},{tag:"path",attr:{d:"M6 16m-3 0a3 3 0 1 0 6 0a3 3 0 1 0 -6 0"},child:[]},{tag:"path",attr:{d:"M16 19m-2 0a2 2 0 1 0 4 0a2 2 0 1 0 -4 0"},child:[]},{tag:"path",attr:{d:"M14.5 7.5m-4.5 0a4.5 4.5 0 1 0 9 0a4.5 4.5 0 1 0 -9 0"},child:[]}]})(s)}function Xe(s){return Z({tag:"svg",attr:{viewBox:"0 0 24 24"},child:[{tag:"path",attr:{fill:"none",d:"M0 0h24v24H0z"},child:[]},{tag:"path",attr:{d:"m2 19.99 7.5-7.51 4 4 7.09-7.97L22 9.92l-8.5 9.56-4-4-6 6.01-1.5-1.5zm1.5-4.5 6-6.01 4 4L22 3.92l-1.41-1.41-7.09 7.97-4-4L2 13.99l1.5 1.5z"},child:[]}]})(s)}function Ze(s){return Z({tag:"svg",attr:{viewBox:"0 0 24 24"},child:[{tag:"path",attr:{fill:"none",d:"M0 0h24v24H0z"},child:[]},{tag:"path",attr:{d:"M4 9h4v11H4zM4 4h4v4H4zM10 7h4v4h-4zM16 10h4v4h-4zM16 15h4v5h-4zM10 12h4v8h-4z"},child:[]}]})(s)}function es(s){return Z({tag:"svg",attr:{version:"1.2",baseProfile:"tiny",viewBox:"0 0 24 24"},child:[{tag:"path",attr:{d:"M4 18c-.552 0-1-.448-1-1v-6.382l-.553.276c-.495.248-1.095.046-1.342-.447-.247-.494-.046-1.094.448-1.342l2-1c.31-.155.678-.139.973.044.294.183.474.504.474.851v8c0 .552-.448 1-1 1zM13 18h-5c-.404 0-.769-.244-.924-.617-.155-.374-.069-.804.217-1.09l4-4c.254-.254.394-.591.394-.95 0-.358-.14-.695-.394-.949-.508-.508-1.39-.508-1.9.001-.253.252-.393.589-.393.948 0 .552-.448 1-1 1s-1-.448-1-1c0-.894.348-1.733.98-2.364 1.265-1.263 3.464-1.263 4.727.001.632.631.979 1.471.979 2.363 0 .893-.348 1.733-.979 2.364l-2.293 2.293h2.586c.552 0 1 .448 1 1s-.448 1-1 1zM20.955 12.377c.338-.457.545-1.016.545-1.627 0-1.517-1.234-2.75-2.75-2.75-1.031 0-1.966.569-2.44 1.484-.254.49-.063 1.094.428 1.348.49.254 1.094.062 1.348-.428.128-.249.383-.404.664-.404.414 0 .75.336.75.75s-.336.75-.75.75c-.552 0-1 .448-1 1s.448 1 1 1c.689 0 1.25.561 1.25 1.25s-.561 1.25-1.25 1.25-1.25-.561-1.25-1.25c0-.552-.448-1-1-1s-1 .448-1 1c0 1.792 1.458 3.25 3.25 3.25s3.25-1.458 3.25-3.25c0-.939-.406-1.779-1.045-2.373z"},child:[]}]})(s)}function ss(s){return Z({tag:"svg",attr:{viewBox:"0 0 512 512"},child:[{tag:"path",attr:{d:"M217 25v14h78V25h-78zm0 32v46h14V71h50v32h14V57h-78zm32 32v14h14V89h-14zm-64 32v46h30v-46h-30zm48 0v14h46v-14h-46zm64 0v46h30v-46h-30zm-64 32v14h46v-14h-46zm-80 32v46h62v-46h-62zm80 0v14h46v-14h-46zm64 0v46h62v-46h-62zm-64 32v14h46v-14h-46zm-112 32v46h94v-46h-94zm112 0v14h46v-14h-46zm64 0v46h94v-46h-94zm-64 32v14h46v-14h-46zM89 313v46h126v-46H89zm144 0v14h46v-14h-46zm64 0v46h126v-46H297zm-64 32v14h46v-14h-46zM57 377v46h158v-46H57zm176 0v14h46v-14h-46zm64 0v46h158v-46H297zm-64 32v14h46v-14h-46zM25 441v46h190v-46H25zm208 0v14h46v-14h-46zm64 0v46h190v-46H297zm-64 32v14h46v-14h-46z"},child:[]}]})(s)}function ot(){const[s,r]=S.useState(!1),t=e.useEditorStore(l=>l.card.type),{setCardType:n,setCardPreferences:i,setChartOrientation:x}=e.useEditorStore(l=>l.actions),o=e.useEditorStore(l=>l.actions.setCardCustomCfg);function a(l){o(null),i({}),n(l),r(!1)}return e.jsxRuntimeExports.jsxs(e.Popover,{open:s,onOpenChange:r,children:[e.jsxRuntimeExports.jsx(e.PopoverTrigger,{asChild:!0,children:e.jsxRuntimeExports.jsx(e.Button,{size:"sm",variant:"outline",children:e.jsxRuntimeExports.jsx(it,{className:"h-4 w-4",chartType:t})})}),e.jsxRuntimeExports.jsx(e.PopoverContent,{className:"w-50",children:e.jsxRuntimeExports.jsxs("div",{className:"grid grid-cols-3 place-items-center",children:[e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>a("bar"),className:"font-normal",variant:"ghost",children:e.jsxRuntimeExports.jsx(Ne,{className:"size-5"})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>a("line"),variant:"ghost",children:e.jsxRuntimeExports.jsx(we,{className:"size-5"})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>a("stackedBar"),variant:"ghost",children:e.jsxRuntimeExports.jsx(Ze,{className:"size-5",strokeWidth:0})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>a("stackedLine"),variant:"ghost",children:e.jsxRuntimeExports.jsx(Xe,{className:"size-5",strokeWidth:0})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>a("scatter"),variant:"ghost",children:e.jsxRuntimeExports.jsx(Be,{className:"size-5"})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>a("bubble"),variant:"ghost",children:e.jsxRuntimeExports.jsx(Ye,{className:"size-4"})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>a("pie"),variant:"ghost",children:e.jsxRuntimeExports.jsx(_e,{className:"size-5"})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>a("doughnut"),variant:"ghost",children:e.jsxRuntimeExports.jsx(We,{className:"size-5",strokeWidth:1})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>a("radar"),variant:"ghost",children:e.jsxRuntimeExports.jsx(Ke,{className:"size-5 font-extralight",strokeWidth:.5})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>a("polarArea"),variant:"ghost",children:e.jsxRuntimeExports.jsx(Je,{className:"size-5"})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>a("pyramid"),variant:"ghost",children:e.jsxRuntimeExports.jsx(ss,{className:"size-5"})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>a("range"),variant:"ghost",children:e.jsxRuntimeExports.jsx(qe,{className:"size-5"})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>a("table"),variant:"ghost",children:e.jsxRuntimeExports.jsx(e.Table,{className:"size-5"})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>a("kpi"),variant:"ghost",children:e.jsxRuntimeExports.jsx(es,{className:"size-6"})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>a("text"),variant:"ghost",children:e.jsxRuntimeExports.jsx(ke,{className:"size-4"})})]})})]})}function it({chartType:s,className:r}){switch(s){case"bar":return e.jsxRuntimeExports.jsx(Ne,{className:r});case"line":return e.jsxRuntimeExports.jsx(we,{className:r});case"pie":return e.jsxRuntimeExports.jsx(_e,{className:r});case"radar":return e.jsxRuntimeExports.jsx(Ke,{className:r});case"scatter":return e.jsxRuntimeExports.jsx(Be,{className:r});case"bubble":return e.jsxRuntimeExports.jsx(Ye,{className:r});case"doughnut":return e.jsxRuntimeExports.jsx(We,{className:r});case"stackedBar":return e.jsxRuntimeExports.jsx(Ze,{className:"size-4 text-foreground/70"});case"stackedLine":return e.jsxRuntimeExports.jsx(Xe,{className:"size-4 text-foreground/70"});case"polarArea":return e.jsxRuntimeExports.jsx(Je,{className:r});case"pyramid":return e.jsxRuntimeExports.jsx(ss,{className:r});case"range":return e.jsxRuntimeExports.jsx(qe,{className:r});case"kpi":return e.jsxRuntimeExports.jsx(es,{className:r});case"text":return e.jsxRuntimeExports.jsx(ke,{className:r});default:return e.jsxRuntimeExports.jsx(e.Table,{className:r})}}function Oe(){const s=e.useEditorStore(h=>h.frame),r=e.useEditorStore(h=>h.card),t=e.useEditorStore(h=>h.card.data),n=e.useEditorStore(h=>h.isShowingVisual),i=e.useEditorStore(h=>h.isSqlRunning),x=e.useEditorStore(h=>h.queryError),o=e.useEditorStore(h=>h.pythonStdOut),a=e.useEditorStore(h=>h.actions.setRunSql);e.useEditorStore(h=>h.onSave),e.useEditorStore(h=>h.onClose),e.useEditorStore(h=>h.actions.setCardSql),e.useEditorStore(h=>h.actions.setCardType),e.useEditorStore(h=>h.actions.setSqlGen);const{setFrame:l,setCard:d,updateCardInFrame:u}=e.useEditorActions();if(!r)return e.jsxRuntimeExports.jsx(e.jsxRuntimeExports.Fragment,{children:"No Active Card"});function j(){const h={id:e.v4(),title:"Title",description:"Description",preferences:{onClickFilter:[{columnIndex:0,expression:""}]},type:"bar",sql:"",data:[]},w={...s,cards:[...s.cards,h],activeCardId:h.id};l(w),d(h)}function E(h){const w=s.cards.filter(z=>z.id!==h),L=w[0],R={...s,cards:w,activeCardId:L.id};l(R),d(L)}function c(h){const w={...s,cards:s.cards.map(R=>R.id===r.id?r:R),activeCardId:h};l(w);const L=w.cards.find(R=>R.id===h);d(L),L.sql&&(console.log("newActiveCard.sql",L.sql),L.data&&L.data.length===0&&a(!0))}function m(){return e.jsxRuntimeExports.jsxs(e.Tabs,{onValueChange:c,value:s.activeCardId,className:"flex grow flex-col pb-3",children:[s.cards.map(h=>e.jsxRuntimeExports.jsx(e.TabsContent,{className:"mt-0 grow",value:h.id,children:g()},h.id)),e.jsxRuntimeExports.jsx(e.TabsList,{className:"mx-6 justify-between",children:e.jsxRuntimeExports.jsxs("div",{className:"flex items-center",children:[s.cards.map(h=>e.jsxRuntimeExports.jsx(e.Editable,{text:h.tabTitle||h.title,onSave:w=>{d({...r,tabTitle:w}),u({...r,tabTitle:w})},children:e.jsxRuntimeExports.jsxs(e.TabsTrigger,{className:"",value:h.id,children:[h.tabTitle||h.title,s.activeCardId===h.id&&s.cards.length>1&&e.jsxRuntimeExports.jsx(e.X,{className:"ml-2 size-3.5 text-muted-foreground hover:text-foreground",onClick:()=>E(h.id)})]})},h.id)),e.jsxRuntimeExports.jsx(e.Button,{className:"ml-1 h-8 px-2 hover:bg-muted-foreground/50",variant:"outline",onClick:j,children:e.jsxRuntimeExports.jsx(e.Plus,{className:"h-4 w-4"})})]})})]})}function g(){return r.type==="kpi"?e.jsxRuntimeExports.jsx("div",{className:"flex h-full items-center justify-center",children:e.jsxRuntimeExports.jsx("div",{className:"w-1/2 rounded-md border",children:e.jsxRuntimeExports.jsx(e.KPICard,{isLoading:i,card:r})})}):r.type==="text"?e.jsxRuntimeExports.jsx("div",{className:"flex h-full items-center justify-center",children:e.jsxRuntimeExports.jsx("div",{className:"w-1/2 rounded-md border",children:e.jsxRuntimeExports.jsx(e.TextCard,{isLoading:i,card:r})})}):e.jsxRuntimeExports.jsx(Ue,{className:"grow border-none shadow-none"})}return e.jsxRuntimeExports.jsxs("div",{className:"relative flex h-full flex-col pt-3",children:[i&&e.jsxRuntimeExports.jsx(ce,{className:"absolute bottom-0 left-0 right-0 top-0 z-10 m-auto h-10 w-10 animate-spin text-foreground/10"}),e.jsxRuntimeExports.jsxs("div",{className:"mb-0 flex min-h-10 items-center justify-end gap-2 px-6",children:[n&&e.jsxRuntimeExports.jsxs("div",{className:"flex grow items-center gap-2",children:[e.jsxRuntimeExports.jsx(ot,{}),r.type!=="table"&&e.jsxRuntimeExports.jsx(rt,{})]}),e.jsxRuntimeExports.jsx(lt,{})]}),n?m():e.jsxRuntimeExports.jsxs("div",{className:"flex min-h-0 w-full flex-1 grow basis-0 px-6",children:[o&&e.jsxRuntimeExports.jsx(at,{}),r.data&&r.data.length>0&&e.jsxRuntimeExports.jsx(nt,{data:t||[]}),x&&e.jsxRuntimeExports.jsx("span",{className:"font-mono text-sm",children:x})]})]})}function at(){const s=e.useEditorStore(t=>t.pythonStdOut);if(!s)return null;const r=s.replace(/\n/g,"<br>");return e.jsxRuntimeExports.jsxs(e.jsxRuntimeExports.Fragment,{children:[e.jsxRuntimeExports.jsx("p",{className:"font-mono text-sm",children:"Output:"}),e.jsxRuntimeExports.jsx("div",{dangerouslySetInnerHTML:{__html:r},className:"bg-muted p-2 font-mono text-sm"}),e.jsxRuntimeExports.jsx(e.Separator,{className:"mb-2"})]})}function lt(){const s=e.useEditorStore(t=>t.isShowingVisual),r=e.useEditorStore(t=>t.actions.setIsShowingVisual);return e.jsxRuntimeExports.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsxRuntimeExports.jsx(e.Label,{htmlFor:"visualize",children:"Chart"}),e.jsxRuntimeExports.jsx(e.Switch,{checked:s,onCheckedChange:()=>r(!s),id:"visualize",className:"data-[state=checked]:bg-foreground/50"})]})}function xe(){const[s,r]=S.useState([]);e.useEditorStore(u=>u.card.cfg);const t=e.useEditorStore(u=>u.card.preferences),{setCardCfg:n,setFilterOnClickColumnIndex:i,setCardPreferences:x}=e.useEditorStore(u=>u.actions),o=e.useEditorStore(u=>u.queryResultColumns);e.useEditorStore(u=>{var j;return(j=u.card.preferences)==null?void 0:j.filterOnClickColumnIndex}),S.useEffect(()=>{o&&r(new Array(o.length).fill(!1))},[o]);function a(u,j){var E,c;j?t!=null&&t.onClickFilter&&((E=t==null?void 0:t.onClickFilter)==null?void 0:E.length)>0?x({...t,onClickFilter:[...t.onClickFilter,{columnIndex:u,expression:""}]}):x({...t,onClickFilter:[{columnIndex:u,expression:""}]}):(x({...t,onClickFilter:(c=t==null?void 0:t.onClickFilter)==null?void 0:c.filter(m=>m.columnIndex!==u)}),r(m=>{const g=[...m];return g[u]=!1,g}))}function l(u,j){var c;const E=(c=t==null?void 0:t.onClickFilter)==null?void 0:c.map(m=>m.columnIndex===u?{...m,expression:j.target.value}:m);x({...t,onClickFilter:E})}function d(u){var j,E,c,m;if(s!=null&&s[u]||(E=(j=t==null?void 0:t.onClickFilter)==null?void 0:j.find(g=>g.columnIndex===u))!=null&&E.expression)return e.jsxRuntimeExports.jsx(e.Input,{value:(m=(c=t==null?void 0:t.onClickFilter)==null?void 0:c.find(g=>g.columnIndex===u))==null?void 0:m.expression,onChange:g=>l(u,g),type:"text",className:"h-9 w-full font-mono text-xs focus-visible:ring-0 focus-visible:ring-ring focus-visible:ring-offset-0",placeholder:"Expression"})}return e.jsxRuntimeExports.jsxs("div",{className:"space-y-2",children:[e.jsxRuntimeExports.jsx(e.Label,{children:"On Click"}),o==null?void 0:o.map((u,j)=>{var E,c;return e.jsxRuntimeExports.jsx("div",{className:"xbg-red-100 group flex items-center justify-between space-y-2",children:e.jsxRuntimeExports.jsxs("div",{className:"grow",children:[e.jsxRuntimeExports.jsxs("div",{className:"flex items-center space-x-2 py-2",children:[e.jsxRuntimeExports.jsx(e.Checkbox,{checked:!!((E=t==null?void 0:t.onClickFilter)!=null&&E.find(m=>m.columnIndex===j)),onCheckedChange:m=>a(j,m)}),e.jsxRuntimeExports.jsx("label",{className:"text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70",children:u}),e.jsxRuntimeExports.jsx("div",{className:"flex items-center gap-2",children:((c=t==null?void 0:t.onClickFilter)==null?void 0:c.find(m=>m.columnIndex===j))&&e.jsxRuntimeExports.jsx(Ve,{onClick:()=>{r(m=>{const g=[...m];return g[j]=!m[j],g})},className:"invisible size-3 cursor-pointer text-gray-400 group-hover:visible"})})]}),d(j)]})},u)})]})}function Re(){var o,a,l;const s=e.useEditorStore(d=>d.card.preferences),r=e.useEditorStore(d=>d.card.cfg),{setCardCfg:t,setCardPreferences:n,setChartOrientation:i}=e.useEditorStore(d=>d.actions);(o=r==null?void 0:r.options)!=null&&o.indexAxis;function x(d){i(d)}return e.jsxRuntimeExports.jsxs(e.RadioGroup,{value:((a=s==null?void 0:s.chartOptions)==null?void 0:a.indexAxis)||((l=r==null?void 0:r.options)==null?void 0:l.indexAxis)||"x",onValueChange:x,className:"flex gap-3",defaultValue:"x",children:[e.jsxRuntimeExports.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsxRuntimeExports.jsx(e.RadioGroupItem,{value:"x",id:"r1"}),e.jsxRuntimeExports.jsx("label",{className:"text-sm",htmlFor:"r1",children:"Vertical"})]}),e.jsxRuntimeExports.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsxRuntimeExports.jsx(e.RadioGroupItem,{value:"y",id:"r2"}),e.jsxRuntimeExports.jsx("label",{className:"text-sm",htmlFor:"r2",children:"Horizontal"})]})]})}const ae="focus-visible:ring-0 focus-visible:ring-ring focus-visible:ring-offset-0";function Me(s,r){var n,i,x;const t=e.getNumberAxis(s,r);return((x=(i=(n=s==null?void 0:s.chartOptions)==null?void 0:n.scales)==null?void 0:i[t])==null?void 0:x.type)||"linear"}function ts(){var K,V,W,y,D,H;const[s,r]=S.useState(!1),t=e.useEditorStore(C=>{var I;return(I=C.card)==null?void 0:I.preferences}),n=e.useEditorStore(C=>{var I;return(I=C.card)==null?void 0:I.cfg}),i=e.getNumberAxis(t,n),[x,o]=S.useState(Me(t)),[a,l]=S.useState(((W=(V=(K=t==null?void 0:t.chartOptions)==null?void 0:K.scales)==null?void 0:V[i])==null?void 0:W.min)||""),[d,u]=S.useState(((H=(D=(y=t==null?void 0:t.chartOptions)==null?void 0:y.scales)==null?void 0:D[i])==null?void 0:H.max)||""),[j,E]=S.useState(a||d?"custom":"auto"),[c,m]=S.useState(""),[g,h]=S.useState(0),[w,L]=S.useState(""),[R,z]=S.useState(""),[F,v]=S.useState(""),k=e.useEditorStore(C=>C.actions.setCardPreferences),{updateCardInFrame:b}=e.useEditorActions(),N=e.useEditorStore(C=>C.card),O=e.useEditorStore(C=>{var I;return(I=C.card)==null?void 0:I.type}),M=["pie","doughnut","polarArea"].includes(O);S.useEffect(()=>{var C,I,$,T,G,Q,te,ee,B,J,Y,ne,X,se;o(Me(t)),l((($=(I=(C=t==null?void 0:t.chartOptions)==null?void 0:C.scales)==null?void 0:I[i])==null?void 0:$.min)===0?0:""),u(((Q=(G=(T=t==null?void 0:t.chartOptions)==null?void 0:T.scales)==null?void 0:G[i])==null?void 0:Q.max)||""),m(((J=(B=(ee=(te=t==null?void 0:t.chartOptions)==null?void 0:te.scales)==null?void 0:ee[i])==null?void 0:B.ticks)==null?void 0:J.stepSize)||""),h(((Y=t==null?void 0:t.numberAxisFormat)==null?void 0:Y.decimalPlaces)||0),L(((ne=t==null?void 0:t.numberAxisFormat)==null?void 0:ne.suffix)||""),z(((X=t==null?void 0:t.numberAxisFormat)==null?void 0:X.currency)||""),v(((se=t==null?void 0:t.numberAxisFormat)==null?void 0:se.locale)||"")},[s,t,i]);function A(C,I){return I===""||/^[0-9\b]+$/.test(I)?Number(I):Number(C)}function q(){return e.jsxRuntimeExports.jsxs(e.jsxRuntimeExports.Fragment,{children:[e.jsxRuntimeExports.jsxs("div",{className:"grid grid-cols-6 items-center gap-2",children:[e.jsxRuntimeExports.jsx(e.Label,{className:"col-span-2 hover:cursor-pointer hover:underline",htmlFor:"currency",children:e.jsxRuntimeExports.jsx("a",{target:"_blank",href:"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat",children:"Currency"})}),e.jsxRuntimeExports.jsx(e.Input,{value:R,placeholder:"USD",onChange:C=>z(C.target.value),id:"currency",className:`col-span-2 h-8 w-full ${ae}`}),e.jsxRuntimeExports.jsx(e.Input,{value:F,placeholder:"en-US",onChange:C=>v(C.target.value),id:"locale",className:`col-span-2 h-8 w-full ${ae}`})]}),e.jsxRuntimeExports.jsxs("div",{className:"grid grid-cols-9 items-center gap-2",children:[e.jsxRuntimeExports.jsx(e.Label,{className:"col-span-3",htmlFor:"format",children:"Decimals"}),e.jsxRuntimeExports.jsx(e.Input,{value:g,onChange:C=>h(Number(C.target.value)),id:"format",className:`col-span-6 h-8 w-full tracking-wide ${ae}`})]})]})}function P(){return e.jsxRuntimeExports.jsxs(e.jsxRuntimeExports.Fragment,{children:[e.jsxRuntimeExports.jsxs("div",{className:"grid grid-cols-3 items-center gap-2",children:[e.jsxRuntimeExports.jsx(e.Label,{htmlFor:"range",children:"Range"}),e.jsxRuntimeExports.jsx(e.Input,{id:"min",value:a,onChange:C=>l(I=>A(I,C.target.value)),className:`col-span-1 h-8 w-full ${ae}`}),e.jsxRuntimeExports.jsx(e.Input,{value:d,onChange:C=>u(I=>A(I,C.target.value)),id:"max",className:`col-span-1 h-8 w-full ${ae}`})]}),e.jsxRuntimeExports.jsxs("div",{className:"grid grid-cols-3 items-center gap-2",children:[e.jsxRuntimeExports.jsx(e.Label,{htmlFor:"step-size",children:"Step Size"}),e.jsxRuntimeExports.jsx(e.Input,{value:c,onChange:C=>m(I=>A(I,C.target.value)),id:"step-size",className:`col-span-1 h-8 w-full ${ae}`})]})]})}function _(){var T;let C={};j==="custom"&&(C={min:a,max:d,ticks:{stepSize:c}});const I={...t||{},chartOptions:{...t==null?void 0:t.chartOptions,scales:{...(T=t==null?void 0:t.chartOptions)==null?void 0:T.scales,[i]:{type:x,...x==="linear"?C:{}}}},numberAxisFormat:{decimalPlaces:g,suffix:w,currency:R,locale:F}};console.log(I),k(I);const $={...N,preferences:I};b($)}return e.jsxRuntimeExports.jsxs(e.Popover,{onOpenChange:C=>r(C),children:[e.jsxRuntimeExports.jsx(e.PopoverTrigger,{asChild:!0,children:e.jsxRuntimeExports.jsx(e.SliderIcon,{className:"size-4 cursor-pointer text-muted-foreground hover:text-foreground"})}),e.jsxRuntimeExports.jsx(e.PopoverContent,{align:"center",className:"max-w-65",children:e.jsxRuntimeExports.jsxs("div",{className:"grid gap-4",children:[e.jsxRuntimeExports.jsxs("div",{className:"space-y-2",children:[e.jsxRuntimeExports.jsx("h4",{className:"font-medium leading-none",children:"Scale Options"}),e.jsxRuntimeExports.jsx("p",{className:"text-sm text-muted-foreground",children:"Set the scale for the number axis"})]}),e.jsxRuntimeExports.jsxs("div",{className:"grid gap-2",children:[e.jsxRuntimeExports.jsxs("div",{className:"grid grid-cols-3 items-center gap-2",children:[e.jsxRuntimeExports.jsx(e.Label,{htmlFor:"scale",children:"Type"}),e.jsxRuntimeExports.jsxs(e.Select,{disabled:M,value:x,onValueChange:C=>o(C),children:[e.jsxRuntimeExports.jsx(e.SelectTrigger,{className:"col-span-2 h-8 w-full focus:ring-1 focus:ring-offset-0",children:e.jsxRuntimeExports.jsx(e.SelectValue,{})}),e.jsxRuntimeExports.jsx(e.SelectContent,{id:"type",children:e.jsxRuntimeExports.jsxs(e.SelectGroup,{children:[e.jsxRuntimeExports.jsx(e.SelectLabel,{children:"Option"}),e.jsxRuntimeExports.jsx(e.SelectItem,{value:"linear",children:"Linear"}),e.jsxRuntimeExports.jsx(e.SelectItem,{value:"logarithmic",children:"Logarithmic"})]})})]})]}),x=="linear"&&e.jsxRuntimeExports.jsxs("div",{className:"grid grid-cols-3 items-center gap-2 py-1",children:[e.jsxRuntimeExports.jsx(e.Label,{htmlFor:"scale-option",children:"Setup"}),e.jsxRuntimeExports.jsxs(e.RadioGroup,{disabled:M,id:"scale-option",value:j,onValueChange:C=>E(C),className:"col-span-2 flex gap-3",defaultValue:"x",children:[e.jsxRuntimeExports.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsxRuntimeExports.jsx(e.RadioGroupItem,{value:"auto",id:"r1"}),e.jsxRuntimeExports.jsx("label",{className:"text-sm",htmlFor:"r1",children:"Auto"})]}),e.jsxRuntimeExports.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsxRuntimeExports.jsx(e.RadioGroupItem,{value:"custom",id:"r2"}),e.jsxRuntimeExports.jsx("label",{className:"text-sm",htmlFor:"r2",children:"Custom"})]})]})]}),j==="custom"&&x=="linear"&&P(),q(),e.jsxRuntimeExports.jsx(e.SelectSeparator,{}),e.jsxRuntimeExports.jsx("div",{className:"grid grid-cols-3",children:e.jsxRuntimeExports.jsx(e.Button,{onClick:_,variant:"secondary",className:"col-span-1 col-start-3 h-8 w-full",children:"Apply"})})]})]})})]})}function ct({idx:s}){var a;const r=e.useEditorStore(l=>{var d;return(d=l.card)==null?void 0:d.preferences}),t=e.useEditorStore(l=>{var d;return(d=l.card.preferences)==null?void 0:d.datasetOptions}),n=e.useEditorStore(l=>l.actions.setCardPreferences),i=(a=r==null?void 0:r.chartOptions)==null?void 0:a.indexAxis,x=t==null?void 0:t.find(l=>l.idx===s);function o(l,d){(l==="end"||l==="start")&&e.getContrastColor(e.getCanvasBackgroundColor());const u={display:l!=="none",align:l,anchor:l,clamp:!0};if(!x)n({...r,datasetOptions:[...t||[],{idx:d,datalabels:u}]});else{const j={...x};j.datalabels=u;const E=t==null?void 0:t.map(c=>c.idx===d?j:c);n({...r,datasetOptions:E})}}return e.jsxRuntimeExports.jsxs(e.Popover,{children:[e.jsxRuntimeExports.jsx(e.PopoverTrigger,{children:e.jsxRuntimeExports.jsx(Ds,{className:"invisible size-4 rotate-[135deg] cursor-pointer text-muted-foreground hover:text-foreground group-hover:visible"})}),e.jsxRuntimeExports.jsx(e.PopoverContent,{className:"w-fit p-1",children:e.jsxRuntimeExports.jsxs("div",{className:"flex gap-1",children:[e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>o("none",s),size:"sm",variant:"secondary",className:"h-7 p-1 text-xs font-normal",children:e.jsxRuntimeExports.jsx(e.X,{className:"size-4"})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>o("start",s),size:"sm",variant:"secondary",className:"h-7 p-1 text-xs font-normal",children:e.jsxRuntimeExports.jsx(gs,{className:e.cn("h-4 w-4",{"rotate-90":i==="y"})})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>o("center",s),size:"sm",variant:"secondary",className:"h-7 p-1 text-xs font-normal",children:e.jsxRuntimeExports.jsx(bs,{className:e.cn("h-4 w-4",{"rotate-90":i==="y"})})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>o("end",s),size:"sm",variant:"secondary",className:"h-7 p-1 text-xs font-normal",children:e.jsxRuntimeExports.jsx(Rs,{className:e.cn("h-4 w-4",{"rotate-90":i==="y"})})})]})})]})}function ns(){const s=e.useEditorStore(l=>l.card),r=e.useEditorStore(l=>{var d,u,j;return(j=(u=(d=l==null?void 0:l.card)==null?void 0:d.preferences)==null?void 0:u.chartOptions)==null?void 0:j.indexAxis}),t=r==="y"?"Y axis":"X axis",n=r==="y"?"X axis":"Y axis",{keys:i,metricKeys:x,dimensionKeys:o}=e.getKeys(s.data||[]);let a=x;if(["stackedBar","stackedLine"].includes(s.type)){const l=e.pivotData({dataArray:s.data||[],groupKey:o[0],pivotKey:o[1],valueKey:a[0]}),{metricKeys:d}=e.getKeys(l);a=d}return i.length===0?null:e.jsxRuntimeExports.jsxs("div",{className:"space-y-4",children:[e.jsxRuntimeExports.jsxs("div",{className:"space-y-2",children:[e.jsxRuntimeExports.jsx(e.Label,{children:t}),e.jsxRuntimeExports.jsx("div",{className:"my-1 space-y-1",children:e.jsxRuntimeExports.jsx("div",{className:"rounded-md bg-muted/70 px-2 py-1 hover:bg-muted",children:e.jsxRuntimeExports.jsx("p",{children:o[0]})})})]}),e.jsxRuntimeExports.jsxs("div",{className:"space-y-2",children:[e.jsxRuntimeExports.jsxs("div",{className:"flex items-center justify-between gap-5",children:[e.jsxRuntimeExports.jsx(e.Label,{children:n}),e.jsxRuntimeExports.jsx(ts,{})]}),e.jsxRuntimeExports.jsx("div",{className:"my-1 space-y-1",children:a.map((l,d)=>e.jsxRuntimeExports.jsx(xt,{col:l,idx:d},l))})]})]})}function xt({col:s,idx:r}){const t=e.useEditorStore(a=>{var l;return(l=a.card)==null?void 0:l.preferences}),n=e.useEditorStore(a=>{var l;return(l=a.card.preferences)==null?void 0:l.datasetOptions}),i=n==null?void 0:n.find(a=>a.idx===r),{setCardPreferences:x}=e.useEditorStore(a=>a.actions);function o(a){if(!i)x({...t,datasetOptions:[...n||[],{idx:r,type:a==="area"?"line":a,fill:a==="area"?"origin":""}]});else{const l={...i};l.type=a==="area"?"line":a,l.fill=a==="area"?"origin":"";const d=n==null?void 0:n.map(u=>u.idx===r?l:u);x({...t,datasetOptions:d})}}return e.jsxRuntimeExports.jsxs("div",{className:"group flex items-center justify-between gap-5 rounded-md bg-muted/70 px-2 py-1 hover:bg-muted",children:[e.jsxRuntimeExports.jsx("p",{children:s}),e.jsxRuntimeExports.jsxs("div",{className:"flex gap-2",children:[e.jsxRuntimeExports.jsx(Ne,{onClick:()=>o("bar"),className:"invisible size-4 cursor-pointer text-muted-foreground hover:text-foreground group-hover:visible"}),e.jsxRuntimeExports.jsx(we,{onClick:()=>o("line"),className:"invisible size-4 cursor-pointer text-muted-foreground hover:text-foreground group-hover:visible"}),e.jsxRuntimeExports.jsx(ls,{onClick:()=>o("area"),className:"invisible size-4 cursor-pointer text-muted-foreground hover:text-foreground group-hover:visible"}),e.jsxRuntimeExports.jsx(e.Separator,{orientation:"vertical",className:"invisible size-4 cursor-pointer py-2 text-muted-foreground hover:text-foreground group-hover:visible"}),e.jsxRuntimeExports.jsx(ct,{idx:r})]})]})}function rs(){const s=e.useEditorStore(E=>E.selectedConnectionId),r=e.useEditorStore(E=>E.selectedDatamodelId),t=e.useEditorStore(E=>E.selectedDatabaseName),n=e.useEditorStore(E=>E.selectedSchemaName),i=e.useEditorStore(E=>E.selectedTableName),x=e.useDashboardStore(E=>E.dashboard.filters)||[],o=e.useDashboardStore(E=>E.actions.addFilter),a=e.useDashboardStore(E=>E.actions.removeFilter),l=e.useDashboardStore(E=>E.actions.removeFilterValue),{modelItems:d,tableName:u}=oe();function j(E,c="dashboard"){var v;const m=e.fmt(E.column_name),g=e.fmt(t||""),h=e.fmt(n||""),w=e.fmt(u);let L=e.getQualifiedTableName(h,w),R=`${L}.${m}`;const z=(v=d==null?void 0:d.find(k=>k.id===r))==null?void 0:v.name;r&&r!=="none"&&(R=`${e.DATAMODEL_NAMESPCACE}.${z}.${m}`,L=`${e.DATAMODEL_NAMESPCACE}.${z}`);const F=x==null?void 0:x.find(k=>k.column===R&&k.table===w&&(k.database===g||k.database===t));if(F)l(F.id),a(F.id);else{const k=e.v4();return u==="api"&&s?(o({location:c,id:k,column:R,title:E.column_name,dataType:E.data_type,table:"api",database:"",connectionId:s,operation:"in",sql:e.getDefaultFilterSql(E.data_type,L,m)}),k):(o({id:k,location:c,column:R,title:E.column_name,dataType:E.data_type,table:i||"",database:t||"",connectionId:s||"",operation:"in",sql:e.getDefaultFilterSql(E.data_type,L,m)}),k)}}return{assignFilter:j}}function ue(){const s=e.useDashboardStore(a=>a.dashboard.filters),r=e.useEditorStore(a=>a.frame),{setFrame:t}=e.useEditorActions(),{columns:n}=oe(),{assignFilter:i}=rs();function x(a){const l=i(a,"frame");t({...r,filterId:l})}const o=s==null?void 0:s.find(a=>a.id===r.filterId);return e.jsxRuntimeExports.jsxs("div",{className:"space-y-3",children:[e.jsxRuntimeExports.jsx(e.Label,{children:"Card Filter"}),e.jsxRuntimeExports.jsx(ut,{onSelect:x,columns:n}),o&&e.jsxRuntimeExports.jsx(e.FilterHeader,{filter:o})]})}function ut({columns:s,onSelect:r}){var o;const[t,n]=Te.useState(!1),[i,x]=Te.useState("");return e.jsxRuntimeExports.jsxs(e.Popover,{open:t,onOpenChange:n,children:[e.jsxRuntimeExports.jsx(e.PopoverTrigger,{asChild:!0,children:e.jsxRuntimeExports.jsxs(e.Button,{size:"sm",variant:"outline",role:"combobox","aria-expanded":t,className:"w-full justify-between font-normal",children:[i?(o=s.find(a=>a.column_name===i))==null?void 0:o.column_name:"Select Column...",e.jsxRuntimeExports.jsx(e.CaretSortIcon,{className:"ml-2 h-4 w-4 shrink-0 opacity-50"})]})}),e.jsxRuntimeExports.jsx(e.PopoverContent,{className:"w-[200px] p-0",children:e.jsxRuntimeExports.jsxs(e.Command,{children:[e.jsxRuntimeExports.jsx(e.CommandInput,{placeholder:"Search column",className:"h-9"}),e.jsxRuntimeExports.jsxs(e.CommandList,{children:[e.jsxRuntimeExports.jsx(e.CommandEmpty,{children:"No framework found."}),e.jsxRuntimeExports.jsx(e.CommandGroup,{children:s.map(a=>e.jsxRuntimeExports.jsxs(e.CommandItem,{value:a.column_name,onSelect:l=>{const d=l===i?"":l;x(d),n(!1),d&&r(a)},children:[a.column_name,e.jsxRuntimeExports.jsx(e.CheckIcon,{className:e.cn("ml-auto h-4 w-4",i===a.column_name?"opacity-100":"opacity-0")})]},a.column_name))})]})]})})]})}function dt({cardType:s}){return e.jsxRuntimeExports.jsx("div",{className:"space-y-6 px-6 py-2",children:e.jsxRuntimeExports.jsxs(e.Accordion,{defaultValue:["item-2"],type:"multiple",children:[e.jsxRuntimeExports.jsxs(e.AccordionItem,{value:"item-1",children:[e.jsxRuntimeExports.jsx(e.AccordionTrigger,{children:`${e.titleCase(s)} Chart`}),e.jsxRuntimeExports.jsxs(e.AccordionContent,{className:"space-y-4 font-mono text-xs",children:[e.jsxRuntimeExports.jsx("div",{className:"rounded bg-muted px-2 py-1 text-xs",children:"SELECT x-axis, y-axis-1, y-axis-2,... FROM table"}),e.jsxRuntimeExports.jsxs("ul",{className:"ml-6 list-disc text-xs [&>li]:mt-2",children:[e.jsxRuntimeExports.jsx("li",{children:"x-axis - category"}),e.jsxRuntimeExports.jsx("li",{children:"y-axis1 - number"}),e.jsxRuntimeExports.jsx("li",{children:"y-axis2 - number"})]}),e.jsxRuntimeExports.jsxs("div",{children:["See ",e.jsxRuntimeExports.jsx("a",{target:"_blank",onClick:r=>r.stopPropagation(),className:"text-blue-700",href:"https://docs.semaphor.cloud/concepts/visuals#line-chart",children:"example"})," in the docs."]})]})]}),e.jsxRuntimeExports.jsxs(e.AccordionItem,{value:"item-2",children:[e.jsxRuntimeExports.jsx(e.AccordionTrigger,{children:"Settings"}),e.jsxRuntimeExports.jsxs(e.AccordionContent,{className:"space-y-4 px-2",children:[e.jsxRuntimeExports.jsx(Re,{}),e.jsxRuntimeExports.jsx(ns,{})]})]}),e.jsxRuntimeExports.jsxs(e.AccordionItem,{value:"item-3",children:[e.jsxRuntimeExports.jsx(e.AccordionTrigger,{children:"Filters"}),e.jsxRuntimeExports.jsxs(e.AccordionContent,{className:"space-y-4 px-2",children:[e.jsxRuntimeExports.jsx(xe,{}),e.jsxRuntimeExports.jsx(ue,{})]})]})]})})}function De(){var i,x,o;const s=e.useEditorStore(a=>a.card.cfg),r=e.useEditorStore(a=>a.actions.setCardCfg),t=e.useEditorStore(a=>a.card.type);function n(a){var u;const l={datalabels:{display:a!=="none",align:a,anchor:a,clamp:!0}},d={...s,options:{...s==null?void 0:s.options,plugins:{...(u=s==null?void 0:s.options)==null?void 0:u.plugins,...l}}};r(d),console.log(a)}return e.jsxRuntimeExports.jsxs("div",{className:"space-y-2",children:[e.jsxRuntimeExports.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxRuntimeExports.jsx("label",{className:"font-medium",children:"Data Labels"}),!["pyramid"].includes(t)&&e.jsxRuntimeExports.jsx(ts,{})]}),e.jsxRuntimeExports.jsxs(e.Select,{value:(o=(x=(i=s==null?void 0:s.options)==null?void 0:i.plugins)==null?void 0:x.datalabels)==null?void 0:o.anchor,onValueChange:n,defaultValue:"none",children:[e.jsxRuntimeExports.jsx(e.SelectTrigger,{className:"h-8 w-full focus:ring-1 focus:ring-offset-0",children:e.jsxRuntimeExports.jsx(e.SelectValue,{placeholder:"Select position"})}),e.jsxRuntimeExports.jsx(e.SelectContent,{children:e.jsxRuntimeExports.jsxs(e.SelectGroup,{children:[e.jsxRuntimeExports.jsx(e.SelectLabel,{children:"Data Labels"}),e.jsxRuntimeExports.jsx(e.SelectItem,{value:"none",children:"None"}),t!=="pyramid"&&e.jsxRuntimeExports.jsx(e.SelectItem,{value:"start",children:"Start"}),e.jsxRuntimeExports.jsx(e.SelectItem,{value:"center",children:"Center"}),t!=="pyramid"&&e.jsxRuntimeExports.jsx(e.SelectItem,{value:"end",children:"End"})]})})]})]})}function mt({cardType:s}){function r(t){const n="SELECT label, [group], x-axis, y-axis, radius FROM table",i="SELECT label, [group], x-axis, y-axis FROM table";return e.jsxRuntimeExports.jsxs(e.jsxRuntimeExports.Fragment,{children:[e.jsxRuntimeExports.jsx("div",{className:"rounded bg-muted px-2 py-1 text-xs",children:t==="bubble"?n:i}),e.jsxRuntimeExports.jsxs("ul",{className:"ml-6 list-disc text-xs [&>li]:mt-2",children:[e.jsxRuntimeExports.jsx("li",{children:"label - category"}),e.jsxRuntimeExports.jsx("li",{children:"group - category"}),e.jsxRuntimeExports.jsx("li",{children:"x-axis - category"}),e.jsxRuntimeExports.jsx("li",{children:"y-axis - category"}),t==="bubble"&&e.jsxRuntimeExports.jsx("li",{children:"radius - number"})]}),e.jsxRuntimeExports.jsxs("div",{children:["See ",e.jsxRuntimeExports.jsx("a",{target:"_blank",onClick:x=>x.stopPropagation(),className:"text-blue-700",href:"https://docs.semaphor.cloud/concepts/visuals#pie-chart",children:"example"})," in the docs."]})]})}return e.jsxRuntimeExports.jsx("div",{className:"space-y-6 px-6 py-2",children:e.jsxRuntimeExports.jsxs(e.Accordion,{defaultValue:["item-2"],type:"multiple",children:[e.jsxRuntimeExports.jsxs(e.AccordionItem,{value:"item-1",children:[e.jsxRuntimeExports.jsx(e.AccordionTrigger,{children:`${e.titleCase(s)} Chart`}),e.jsxRuntimeExports.jsx(e.AccordionContent,{className:"space-y-4 font-mono text-xs",children:r(s)})]}),e.jsxRuntimeExports.jsxs(e.AccordionItem,{value:"item-2",children:[e.jsxRuntimeExports.jsx(e.AccordionTrigger,{children:"Settings"}),e.jsxRuntimeExports.jsx(e.AccordionContent,{className:"px-2",children:e.jsxRuntimeExports.jsx(De,{})})]}),e.jsxRuntimeExports.jsxs(e.AccordionItem,{value:"item-3",children:[e.jsxRuntimeExports.jsx(e.AccordionTrigger,{children:"Filters"}),e.jsxRuntimeExports.jsxs(e.AccordionContent,{className:"space-y-4 px-2",children:[e.jsxRuntimeExports.jsx(xe,{}),e.jsxRuntimeExports.jsx(ue,{})]})]})]})})}const pt={datasets:[{type:"line",label:"Sum_sales",data:[]},{type:"bar",label:"Sum_profit",data:[]}]},ht={datasets:[{fill:"origin",type:"line",label:"Sum_sales",data:[]}]};function jt(){const s=e.useEditorStore(r=>r.card.type);return e.jsxRuntimeExports.jsxs("div",{className:"space-y-6 p-6",children:[e.jsxRuntimeExports.jsx(e.Accordion,{className:" ",type:"single",collapsible:!0,children:Et(s)}),e.jsxRuntimeExports.jsx("section",{className:"",children:["line","bar"].includes(s)&&e.jsxRuntimeExports.jsx(Re,{})}),!["kpi"].includes(s)&&e.jsxRuntimeExports.jsxs("div",{className:"space-y-4",children:[e.jsxRuntimeExports.jsx(De,{}),e.jsxRuntimeExports.jsx(xe,{}),e.jsxRuntimeExports.jsx(ue,{})]})]})}function Et(s){if(["line","bar"].includes(s))return e.jsxRuntimeExports.jsxs(e.jsxRuntimeExports.Fragment,{children:[e.jsxRuntimeExports.jsxs(e.AccordionItem,{value:"item-1",children:[e.jsxRuntimeExports.jsx(e.AccordionTrigger,{className:"font-normal",children:e.jsxRuntimeExports.jsx("p",{children:"Chart Query"})}),e.jsxRuntimeExports.jsxs(e.AccordionContent,{className:" ",children:[e.jsxRuntimeExports.jsx("div",{className:"rounded bg-muted px-2 py-1 font-mono text-xs font-semibold",children:"SELECT x-axis, y-axis-1, y-axis-2, y-axis-3,... FROM table"}),e.jsxRuntimeExports.jsxs("ul",{className:"my-6 ml-6 list-disc text-xs font-normal [&>li]:mt-2",children:[e.jsxRuntimeExports.jsx("li",{children:"X-axis - Category (ex. city)"}),e.jsxRuntimeExports.jsx("li",{children:"Y-axis - Number (ex. population)"})]})]})]}),e.jsxRuntimeExports.jsxs(e.AccordionItem,{value:"item-2",children:[e.jsxRuntimeExports.jsx(e.AccordionTrigger,{className:"font-normal",children:"Mixed Chart"}),e.jsxRuntimeExports.jsxs(e.AccordionContent,{className:"space-y-2 text-xs",children:[e.jsxRuntimeExports.jsxs("p",{children:["Click ",e.jsxRuntimeExports.jsx("b",{children:"Customize"})," and change the `type` property in the dataset."]}),e.jsxRuntimeExports.jsx("pre",{children:JSON.stringify(pt,null,2)})]})]}),e.jsxRuntimeExports.jsxs(e.AccordionItem,{value:"item-3",children:[e.jsxRuntimeExports.jsx(e.AccordionTrigger,{className:"font-normal",children:"Area Chart"}),e.jsxRuntimeExports.jsxs(e.AccordionContent,{className:"space-y-2 text-xs",children:[e.jsxRuntimeExports.jsxs("p",{children:["Click ",e.jsxRuntimeExports.jsx("b",{children:"Customize"})," and add `fill` property to the dataset. See",e.jsxRuntimeExports.jsx("a",{className:"mx-1 text-blue-500 hover:underline",href:"https://www.chartjs.org/docs/latest/samples/area/line-boundaries.html",target:"_blank",children:"docs"}),"for more options."]}),e.jsxRuntimeExports.jsx("pre",{children:JSON.stringify(ht,null,2)})]})]})]});if(s==="bubble")return e.jsxRuntimeExports.jsx(e.jsxRuntimeExports.Fragment,{children:e.jsxRuntimeExports.jsxs(e.AccordionItem,{value:"item-1",children:[e.jsxRuntimeExports.jsx(e.AccordionTrigger,{className:"font-normal",children:e.jsxRuntimeExports.jsxs("p",{children:["How to create a ",e.jsxRuntimeExports.jsx("span",{children:s})," chart query?"]})}),e.jsxRuntimeExports.jsxs(e.AccordionContent,{className:" ",children:[e.jsxRuntimeExports.jsx("div",{className:"rounded bg-muted px-2 py-1 font-mono text-xs font-semibold",children:"SELECT label, x-axis, y-axis, radius FROM table"}),e.jsxRuntimeExports.jsxs("ul",{className:"my-6 ml-6 list-disc text-xs font-normal [&>li]:mt-2",children:[e.jsxRuntimeExports.jsx("li",{children:"Label - Category (ex. city)"}),e.jsxRuntimeExports.jsx("li",{children:"Bubble Group (opt) - Category (ex. state)"}),e.jsxRuntimeExports.jsx("li",{children:"X-axis - Number (ex. avg. age)"}),e.jsxRuntimeExports.jsx("li",{children:"Y-axis - Number (ex. avg. weight)"}),e.jsxRuntimeExports.jsx("li",{children:"Radius - Number (ex. population)"})]})]})]})});if(s==="scatter")return e.jsxRuntimeExports.jsx(e.jsxRuntimeExports.Fragment,{children:e.jsxRuntimeExports.jsxs(e.AccordionItem,{value:"item-1",children:[e.jsxRuntimeExports.jsx(e.AccordionTrigger,{className:"font-normal",children:e.jsxRuntimeExports.jsxs("p",{children:["How to create a ",e.jsxRuntimeExports.jsx("span",{children:s})," chart query?"]})}),e.jsxRuntimeExports.jsxs(e.AccordionContent,{className:" ",children:[e.jsxRuntimeExports.jsx("div",{className:"rounded bg-muted px-2 py-1 font-mono text-xs font-semibold",children:"SELECT label, x-axis, y-axis FROM table"}),e.jsxRuntimeExports.jsxs("ul",{className:"my-6 ml-6 list-disc text-xs font-normal [&>li]:mt-2",children:[e.jsxRuntimeExports.jsx("li",{children:"Label - Category (ex. city)"}),e.jsxRuntimeExports.jsx("li",{children:"Group (opt) - Category (ex. state)"}),e.jsxRuntimeExports.jsx("li",{children:"X-axis - Number (ex. avg. age)"}),e.jsxRuntimeExports.jsx("li",{children:"Y-axis - Number (ex. avg. weight)"})]})]})]})});if(["pie","doughnut","polarArea"].includes(s))return e.jsxRuntimeExports.jsx(e.jsxRuntimeExports.Fragment,{children:e.jsxRuntimeExports.jsxs(e.AccordionItem,{value:"item-1",children:[e.jsxRuntimeExports.jsx(e.AccordionTrigger,{className:"font-normal",children:e.jsxRuntimeExports.jsxs("p",{children:[e.jsxRuntimeExports.jsx("span",{children:s==="polarArea"?"Polar":s.charAt(0).toUpperCase()+s.slice(1)})," ","chart query"]})}),e.jsxRuntimeExports.jsxs(e.AccordionContent,{className:" ",children:[e.jsxRuntimeExports.jsx("div",{className:"rounded bg-muted px-2 py-1 font-mono text-xs font-semibold",children:"SELECT label, measure FROM table"}),e.jsxRuntimeExports.jsxs("ul",{className:"my-6 ml-6 list-disc text-xs font-normal [&>li]:mt-2",children:[e.jsxRuntimeExports.jsx("li",{children:"Label - Category (ex. city)"}),e.jsxRuntimeExports.jsx("li",{children:"Measure - Number (ex. population)"})]})]})]})})}function ft(){var l,d,u,j,E;const s=e.useEditorStore(c=>c.card.preferences),r=e.useEditorStore(c=>c.actions.setCardPreferences),t=e.useEditorStore(c=>c.actions.setNumberFormat);e.useEditorStore(c=>{var m,g;return(g=(m=c.card.preferences)==null?void 0:m.formatNumber)==null?void 0:g.decimalPlaces});const n=e.useEditorStore(c=>{var m,g;return(g=(m=c.card.preferences)==null?void 0:m.formatNumber)==null?void 0:g.locale}),i=e.useEditorStore(c=>{var m,g;return(g=(m=c.card.preferences)==null?void 0:m.formatNumber)==null?void 0:g.currency});e.useEditorStore(c=>c.actions.setFilterOnClickField);const x=e.useEditorStore(c=>{var m,g;return(g=(m=c.card.preferences)==null?void 0:m.formatNumber)==null?void 0:g.colorRanges})||[],o=e.useEditorStore(c=>c.actions.setColorRanges),a=[...new Set(e.LOCALE_CURRENCY_PAIRS.map(c=>c.currency))];return e.jsxRuntimeExports.jsxs("div",{children:[e.jsxRuntimeExports.jsxs("div",{className:"mb-3 flex items-center gap-2",children:[e.jsxRuntimeExports.jsx(e.Checkbox,{checked:!!((l=s==null?void 0:s.formatNumber)!=null&&l.enabled),onCheckedChange:c=>{r({...s,formatNumber:{...s==null?void 0:s.formatNumber,enabled:c}})}}),e.jsxRuntimeExports.jsx(e.Label,{children:"Format Number"})]}),((d=s==null?void 0:s.formatNumber)==null?void 0:d.enabled)===!0&&e.jsxRuntimeExports.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsxRuntimeExports.jsx("div",{children:e.jsxRuntimeExports.jsxs("div",{className:"space-y-4 p-2",children:[e.jsxRuntimeExports.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxRuntimeExports.jsxs("div",{className:"w-full space-y-1",children:[e.jsxRuntimeExports.jsx(e.Label,{children:"Locale"}),e.jsxRuntimeExports.jsxs(e.Select,{value:n||"en-US",onValueChange:c=>{var m,g,h;return t(((m=s==null?void 0:s.formatNumber)==null?void 0:m.decimalPlaces)||0,((g=s==null?void 0:s.formatNumber)==null?void 0:g.currency)||"",c||"en-US",((h=s==null?void 0:s.formatNumber)==null?void 0:h.suffix)||"")},children:[e.jsxRuntimeExports.jsx(e.SelectTrigger,{className:"col-span-6 h-8 w-full focus:ring-1 focus:ring-offset-0",children:e.jsxRuntimeExports.jsx(e.SelectValue,{})}),e.jsxRuntimeExports.jsx(e.SelectContent,{children:e.jsxRuntimeExports.jsxs(e.SelectGroup,{children:[e.jsxRuntimeExports.jsx(e.SelectLabel,{children:"Format"}),e.LOCALE_CURRENCY_PAIRS.map(c=>e.jsxRuntimeExports.jsx(e.SelectItem,{value:c.locale,children:c.locale},c.locale))]})})]})]}),e.jsxRuntimeExports.jsxs("div",{className:"w-full space-y-1",children:[e.jsxRuntimeExports.jsx(e.Label,{children:"Currency"}),e.jsxRuntimeExports.jsxs(e.Select,{value:i||"none",onValueChange:c=>{var m,g,h;return t(((m=s==null?void 0:s.formatNumber)==null?void 0:m.decimalPlaces)||0,c==="none"?"":c,((g=s==null?void 0:s.formatNumber)==null?void 0:g.locale)||"",((h=s==null?void 0:s.formatNumber)==null?void 0:h.suffix)||"")},children:[e.jsxRuntimeExports.jsx(e.SelectTrigger,{className:"col-span-6 h-8 w-full focus:ring-1 focus:ring-offset-0",children:e.jsxRuntimeExports.jsx(e.SelectValue,{})}),e.jsxRuntimeExports.jsx(e.SelectContent,{children:e.jsxRuntimeExports.jsxs(e.SelectGroup,{children:[e.jsxRuntimeExports.jsx(e.SelectLabel,{children:"Currency"}),e.jsxRuntimeExports.jsx(e.SelectItem,{value:"none",children:"None"},"none"),a.map(c=>e.jsxRuntimeExports.jsx(e.SelectItem,{value:c,children:c},c))]})})]})]})]}),e.jsxRuntimeExports.jsxs("div",{className:"flex gap-2",children:[e.jsxRuntimeExports.jsxs("div",{className:"w-full space-y-1",children:[e.jsxRuntimeExports.jsx(e.Label,{children:"Decimals"}),e.jsxRuntimeExports.jsxs(e.Select,{value:((j=(u=s==null?void 0:s.formatNumber)==null?void 0:u.decimalPlaces)==null?void 0:j.toString())||"0",onValueChange:c=>{var m,g,h;return t(Number(c),((m=s==null?void 0:s.formatNumber)==null?void 0:m.currency)||"",((g=s==null?void 0:s.formatNumber)==null?void 0:g.locale)||"",((h=s==null?void 0:s.formatNumber)==null?void 0:h.suffix)||"")},children:[e.jsxRuntimeExports.jsx(e.SelectTrigger,{className:"col-span-3 h-8 w-full focus:ring-1 focus:ring-offset-0",children:e.jsxRuntimeExports.jsx(e.SelectValue,{})}),e.jsxRuntimeExports.jsx(e.SelectContent,{children:["0","1","2","3","4"].map(c=>e.jsxRuntimeExports.jsx(e.SelectItem,{value:c,children:c},c))})]})]}),e.jsxRuntimeExports.jsxs("div",{className:"w-full space-y-1",children:[e.jsxRuntimeExports.jsx(e.Label,{children:"Suffix"}),e.jsxRuntimeExports.jsx(e.Input,{value:((E=s==null?void 0:s.formatNumber)==null?void 0:E.suffix)||"",className:"h-8 font-mono text-xs focus-visible:ring-0 focus-visible:ring-ring focus-visible:ring-offset-0",placeholder:"K, M, B, %",onChange:c=>{var m,g,h;return t(((m=s==null?void 0:s.formatNumber)==null?void 0:m.decimalPlaces)||0,((g=s==null?void 0:s.formatNumber)==null?void 0:g.currency)||"",((h=s==null?void 0:s.formatNumber)==null?void 0:h.locale)||"",c.target.value)}})]})]})]})}),e.jsxRuntimeExports.jsx(e.Separator,{className:"my-3"}),e.jsxRuntimeExports.jsx(e.ColorFormat,{colorRanges:x,setColorRanges:o})]})]})}function gt(){return e.jsxRuntimeExports.jsxs("div",{className:"space-y-6 px-6 py-2",children:[e.jsxRuntimeExports.jsx(e.Accordion,{type:"single",collapsible:!0,children:e.jsxRuntimeExports.jsxs(e.AccordionItem,{value:"item-1",children:[e.jsxRuntimeExports.jsx(e.AccordionTrigger,{className:"",children:"KPI Query"}),e.jsxRuntimeExports.jsxs(e.AccordionContent,{className:"font-mono",children:[e.jsxRuntimeExports.jsx("div",{className:"rounded bg-muted px-2 py-1 font-mono text-xs",children:"SELECT current, previous FROM table"}),e.jsxRuntimeExports.jsxs("ul",{className:"my-6 ml-6 list-disc text-xs [&>li]:mt-2",children:[e.jsxRuntimeExports.jsx("li",{children:"current - number"}),e.jsxRuntimeExports.jsx("li",{children:"previous - number"})]}),e.jsxRuntimeExports.jsxs("div",{children:["See ",e.jsxRuntimeExports.jsx("a",{target:"_blank",onClick:s=>s.stopPropagation(),className:"text-blue-700",href:"https://docs.semaphor.cloud/concepts/visuals#kpi",children:"example"})," in the docs."]})]})]})}),e.jsxRuntimeExports.jsx("section",{className:"",children:e.jsxRuntimeExports.jsx(ft,{})}),e.jsxRuntimeExports.jsx("div",{}),e.jsxRuntimeExports.jsx("div",{})]})}function Rt(){var n;const s=e.useEditorStore(i=>i.card.preferences),{setCardPreferences:r}=e.useEditorStore(i=>i.actions);function t(i){r({...s,textVisualOptions:{...s==null?void 0:s.textVisualOptions,isDynamicText:i==="dynamic"}})}return e.jsxRuntimeExports.jsxs(e.RadioGroup,{value:(n=s==null?void 0:s.textVisualOptions)!=null&&n.isDynamicText?"dynamic":"static",onValueChange:t,className:"flex gap-3",defaultValue:"x",children:[e.jsxRuntimeExports.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsxRuntimeExports.jsx(e.RadioGroupItem,{value:"static",id:"r1"}),e.jsxRuntimeExports.jsx("label",{className:"text-sm",htmlFor:"r1",children:"Static"})]}),e.jsxRuntimeExports.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsxRuntimeExports.jsx(e.RadioGroupItem,{value:"dynamic",id:"r2"}),e.jsxRuntimeExports.jsx("label",{className:"text-sm",htmlFor:"r2",children:"Dynamic"})]})]})}function Ee({cardType:s,docContent:r,suffix:t="Chart"}){return e.jsxRuntimeExports.jsx("div",{className:"space-y-6 px-6 py-2",children:e.jsxRuntimeExports.jsxs(e.Accordion,{defaultValue:["item-2"],type:"multiple",children:[e.jsxRuntimeExports.jsxs(e.AccordionItem,{value:"item-1",children:[e.jsxRuntimeExports.jsx(e.AccordionTrigger,{children:`${e.titleCase(s)} ${t}`}),e.jsxRuntimeExports.jsx(e.AccordionContent,{children:r||e.jsxRuntimeExports.jsxs("div",{className:"space-y-4 font-mono text-xs",children:[e.jsxRuntimeExports.jsx("div",{className:"rounded bg-muted px-2 py-1 text-xs",children:"SELECT label, measure FROM table"}),e.jsxRuntimeExports.jsxs("ul",{className:"ml-6 list-disc text-xs [&>li]:mt-2",children:[e.jsxRuntimeExports.jsx("li",{children:"label - category"}),e.jsxRuntimeExports.jsx("li",{children:"measure - number"})]}),e.jsxRuntimeExports.jsxs("div",{children:["See ",e.jsxRuntimeExports.jsx("a",{target:"_blank",onClick:n=>n.stopPropagation(),className:"text-blue-700",href:"https://docs.semaphor.cloud/concepts/visuals#pie-chart",children:"example"})," in the docs."]})]})})]}),e.jsxRuntimeExports.jsxs(e.AccordionItem,{value:"item-2",children:[e.jsxRuntimeExports.jsx(e.AccordionTrigger,{children:"Settings"}),e.jsxRuntimeExports.jsxs(e.AccordionContent,{className:"space-y-4 px-2",children:[s==="range"&&e.jsxRuntimeExports.jsx(Re,{}),s!=="text"&&e.jsxRuntimeExports.jsx(De,{}),s==="text"&&e.jsxRuntimeExports.jsx(Rt,{})]})]}),!["range","text"].includes(s)&&e.jsxRuntimeExports.jsxs(e.AccordionItem,{value:"item-3",children:[e.jsxRuntimeExports.jsx(e.AccordionTrigger,{children:"Filters"}),e.jsxRuntimeExports.jsxs(e.AccordionContent,{className:"space-y-4 px-2",children:[e.jsxRuntimeExports.jsx(xe,{}),e.jsxRuntimeExports.jsx(ue,{})]})]})]})})}function bt(){return e.jsxRuntimeExports.jsx("div",{className:"space-y-6 px-6 py-2",children:e.jsxRuntimeExports.jsxs(e.Accordion,{defaultValue:["item-2"],type:"multiple",children:[e.jsxRuntimeExports.jsxs(e.AccordionItem,{value:"item-1",children:[e.jsxRuntimeExports.jsx(e.AccordionTrigger,{children:"Stacked Chart"}),e.jsxRuntimeExports.jsxs(e.AccordionContent,{className:"space-y-4 font-mono text-xs",children:[e.jsxRuntimeExports.jsx("div",{className:"rounded bg-muted px-2 py-1 text-xs",children:"SELECT x-axis, stack-by, y-axis FROM table"}),e.jsxRuntimeExports.jsxs("ul",{className:"ml-6 list-disc text-xs [&>li]:mt-2",children:[e.jsxRuntimeExports.jsx("li",{children:"x-axis - category"}),e.jsxRuntimeExports.jsx("li",{children:"stack by - category"}),e.jsxRuntimeExports.jsx("li",{children:"y-axis - number"})]}),e.jsxRuntimeExports.jsxs("div",{children:["See ",e.jsxRuntimeExports.jsx("a",{target:"_blank",onClick:s=>s.stopPropagation(),className:"text-blue-700",href:"https://docs.semaphor.cloud/concepts/visuals#stacked-chart",children:"example"})," in the docs."]})]})]}),e.jsxRuntimeExports.jsxs(e.AccordionItem,{value:"item-2",children:[e.jsxRuntimeExports.jsx(e.AccordionTrigger,{children:"Settings"}),e.jsxRuntimeExports.jsxs(e.AccordionContent,{className:"space-y-4 px-2",children:[e.jsxRuntimeExports.jsx(Re,{}),e.jsxRuntimeExports.jsx(ns,{})]})]}),e.jsxRuntimeExports.jsxs(e.AccordionItem,{value:"item-3",children:[e.jsxRuntimeExports.jsx(e.AccordionTrigger,{children:"Filters"}),e.jsxRuntimeExports.jsxs(e.AccordionContent,{className:"space-y-4 px-2",children:[e.jsxRuntimeExports.jsx(xe,{}),e.jsxRuntimeExports.jsx(ue,{})]})]})]})})}function St({}){const s=e.useEditorStore(n=>{var i;return(i=n.card)==null?void 0:i.preferences}),r=e.useEditorStore(n=>n.actions.setCardPreferences),t=n=>{r({...s,allowDownload:n})};return e.jsxRuntimeExports.jsxs("div",{className:"space-y-6 px-6 py-2",children:[e.jsxRuntimeExports.jsx(e.Accordion,{defaultValue:["item-3"],type:"multiple",children:e.jsxRuntimeExports.jsxs(e.AccordionItem,{value:"item-3",children:[e.jsxRuntimeExports.jsx(e.AccordionTrigger,{children:"Filters"}),e.jsxRuntimeExports.jsxs(e.AccordionContent,{className:"space-y-4 px-2",children:[e.jsxRuntimeExports.jsx(xe,{}),e.jsxRuntimeExports.jsx(ue,{})]})]})}),e.jsxRuntimeExports.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsxRuntimeExports.jsx(e.Checkbox,{onCheckedChange:t,id:"allow-download"}),e.jsxRuntimeExports.jsx("label",{htmlFor:"allow-download",className:"text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70",children:"Allow Download"})]})]})}const yt=e.jsxRuntimeExports.jsxs("div",{className:"space-y-4 font-mono text-xs",children:[e.jsxRuntimeExports.jsx("div",{className:"rounded bg-muted px-2 py-1 text-xs",children:"SELECT dimension, cohort, metric FROM table"}),e.jsxRuntimeExports.jsxs("div",{children:["See ",e.jsxRuntimeExports.jsx("a",{target:"_blank",onClick:s=>s.stopPropagation(),className:"text-blue-700",href:"https://docs.semaphor.cloud/concepts/visuals#pyramid-chart",children:"example"})," in the docs."]})]}),vt=e.jsxRuntimeExports.jsxs("div",{className:"space-y-4 font-mono text-xs",children:[e.jsxRuntimeExports.jsx("div",{className:"rounded bg-muted px-2 py-1 text-xs",children:"SELECT y-axis, label, range-from, range-to, range-value FROM table"}),e.jsxRuntimeExports.jsxs("div",{children:["See ",e.jsxRuntimeExports.jsx("a",{target:"_blank",onClick:s=>s.stopPropagation(),className:"text-blue-700",href:"https://docs.semaphor.cloud/concepts/visuals#range-charts",children:"example"})," in the docs."]})]}),Ct=e.jsxRuntimeExports.jsxs("div",{className:"space-y-4 font-mono text-xs",children:[e.jsxRuntimeExports.jsx("div",{className:"rounded bg-muted px-2 py-1 text-xs",children:"SELECT text FROM table limit 1"}),e.jsxRuntimeExports.jsxs("div",{children:["See ",e.jsxRuntimeExports.jsx("a",{target:"_blank",onClick:s=>s.stopPropagation(),className:"text-blue-700",href:"https://docs.semaphor.cloud/concepts/visuals#text-visual",children:"example"})," in the docs."]})]});function Nt(){const s=e.useEditorStore(t=>t.card.type);function r(t){switch(t){case"stackedBar":case"stackedLine":return e.jsxRuntimeExports.jsx(bt,{});case"pyramid":return e.jsxRuntimeExports.jsx(Ee,{docContent:yt,cardType:t});case"kpi":return e.jsxRuntimeExports.jsx(gt,{});case"line":case"bar":return e.jsxRuntimeExports.jsx(dt,{cardType:t});case"range":return e.jsxRuntimeExports.jsx(Ee,{docContent:vt,cardType:t});case"pie":case"doughnut":case"polarArea":case"radar":return e.jsxRuntimeExports.jsx(Ee,{cardType:t});case"bubble":case"scatter":return e.jsxRuntimeExports.jsx(mt,{cardType:t});case"table":return e.jsxRuntimeExports.jsx(St,{cardType:t});case"text":return e.jsxRuntimeExports.jsx(Ee,{docContent:Ct,cardType:t,suffix:"Visual"});default:return e.jsxRuntimeExports.jsx(jt,{})}}return e.jsxRuntimeExports.jsx(e.ScrollArea,{className:"h-full w-full text-sm",children:r(s)})}function wt(){const s=e.useEditorStore(r=>r.isShowingVisual);return e.jsxRuntimeExports.jsxs(e.ResizablePanelGroup,{direction:"vertical",className:"min-h-[250px] min-w-full max-w-lg",children:[e.jsxRuntimeExports.jsx(e.ResizablePanel,{role:"query-section",className:"flex",minSize:20,defaultSize:40,children:e.jsxRuntimeExports.jsx(tt,{})}),e.jsxRuntimeExports.jsx(e.ResizableHandle,{withHandle:!0,className:"border"}),e.jsxRuntimeExports.jsx(e.ResizablePanel,{className:"pb-1",role:"visual-section",minSize:0,defaultSize:60,children:s?e.jsxRuntimeExports.jsxs(e.ResizablePanelGroup,{direction:"horizontal",children:[e.jsxRuntimeExports.jsx(e.jsxRuntimeExports.Fragment,{children:e.jsxRuntimeExports.jsx(e.ResizablePanel,{className:"flex min-w-[275px]",minSize:20,defaultSize:25,maxSize:30,children:e.jsxRuntimeExports.jsx(Nt,{})})}),e.jsxRuntimeExports.jsx(e.ResizableHandle,{className:"border"}),e.jsxRuntimeExports.jsx(e.ResizablePanel,{minSize:40,defaultSize:75,maxSize:100,children:e.jsxRuntimeExports.jsx(Oe,{})})]}):e.jsxRuntimeExports.jsx(Oe,{})})]})}function kt({authToken:s,onSave:r,onClose:t}){const n=e.useEditorStore(o=>o.actions.setOnSave),i=e.useEditorStore(o=>o.actions.setOnClose),x=e.useDashboardStore(o=>o.actions.setAuthToken);return S.useEffect(()=>{r&&n(r),t&&i(t)},[r,n,t,i]),S.useEffect(()=>{s&&s.accessToken&&x(s)},[s,x]),e.jsxRuntimeExports.jsxs(e.EditorPanel,{className:"rounded-none",role:"editor-panel",children:[e.jsxRuntimeExports.jsx(e.EditorAside,{className:"rounded-none border-r-[1.5px]",children:e.jsxRuntimeExports.jsx($e,{})}),e.jsxRuntimeExports.jsx(e.EditorMain,{children:e.jsxRuntimeExports.jsx(wt,{})})]})}function Lt(){e.useDashboardStore(o=>o.selectedCardId);const s=e.useDashboardStore(o=>o.selectedSheetId),{setIsVisualEditing:r}=e.useDashboardStore(o=>o.actions),t=e.useDashboardStore(o=>o.isVisualEditing),n=e.useDashboardStore(o=>o.actions.updateFrame);function i(o){s&&(n(s,o),r(!1))}function x(){r(!1)}return e.jsxRuntimeExports.jsx("div",{role:"editor-container",className:e.cn("flex grow",{block:t,hidden:!t}),children:e.jsxRuntimeExports.jsx(kt,{onSave:i,onClose:x})})}function Dt(){e.useEditorStore(o=>o.selectedConnectionId),e.useEditorStore(o=>o.selectedDatamodelId);const s=e.useEditorStore(o=>o.selectedDatabaseName);e.useEditorStore(o=>o.selectedSchemaName);const r=e.useEditorStore(o=>o.selectedTableName),t=e.useDashboardStore(o=>o.dashboard.filters)||[];e.useDashboardStore(o=>o.actions.addFilter),e.useDashboardStore(o=>o.actions.removeFilter),e.useDashboardStore(o=>o.actions.removeFilterValue);const{modelItems:n,columns:i}=oe(),{assignFilter:x}=rs();return e.jsxRuntimeExports.jsx("div",{className:"xbg-red-100 flex-1 basis-0 flex-col overflow-scroll px-3",children:i==null?void 0:i.map(o=>{const a=t==null?void 0:t.find(l=>l.column===e.fmt(o.column_name)&&l.table===r&&l.database===s);return e.jsxRuntimeExports.jsx("div",{onClick:()=>x(o),className:e.cn("group flex cursor-pointer items-center justify-between border border-dashed border-background px-3 py-[6px] text-sm transition-colors hover:bg-muted/50",{"bg-muted":a}),children:e.jsxRuntimeExports.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxRuntimeExports.jsx(Pe,{column:o}),e.jsxRuntimeExports.jsx("span",{children:o.column_name})]})},o.column_name)})})}function At(){e.useDashboardStore(r=>r.showFilters);const s=e.useDashboardStore(r=>r.actions.setShowFilters);return e.jsxRuntimeExports.jsxs("section",{className:"relative flex grow flex-col border-l px-4",children:[e.jsxRuntimeExports.jsxs("div",{className:"mt-4 flex items-center justify-between gap-2 px-3",children:[e.jsxRuntimeExports.jsx(e.Label,{className:"text-lg",children:"Filters"}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>s(!1),className:"h-7 w-7 p-0",variant:"ghost",children:e.jsxRuntimeExports.jsx(e.Cross2Icon,{})})]}),e.jsxRuntimeExports.jsx("div",{className:"flex grow",children:e.jsxRuntimeExports.jsx($e,{ColumnsComponent:()=>e.jsxRuntimeExports.jsx(Dt,{})})})]})}function It(){const s=e.useDashboardStore(t=>t.showFilters),r=e.useDashboardStore(t=>t.isVisualEditing);return e.jsxRuntimeExports.jsxs("div",{role:"dashboard-plus-main",className:e.cn("grow",{hidden:r,flex:!r}),children:[e.jsxRuntimeExports.jsx(e.DashboardTabs,{}),s&&e.jsxRuntimeExports.jsx("div",{role:"filter-aside-container",className:"flex",children:e.jsxRuntimeExports.jsx(At,{})})]})}function Tt(){const s=e.useDashboardStore(n=>n.dashboard),r=e.useDashboardStore(n=>n.actions.setDashboard),t=e.useDashboardStore(n=>n.showDashboardJSON);return e.useDashboardStore(n=>n.actions.setShowDashboardJSON),e.jsxRuntimeExports.jsx("div",{className:e.cn(" p-2",{hidden:!t}),children:e.jsxRuntimeExports.jsx(e.de,{onChange:n=>{if(n)try{JSON.parse(n),r(JSON.parse(n))}catch{}},defaultLanguage:"json",className:"h-[550px] overflow-y-auto ",value:JSON.stringify(s,null,2),options:{minimap:{enabled:!1},glyphMargin:!1,wordWrap:"on",scrollbar:{verticalScrollbarSize:0,horizontalScrollbarSize:0},fontSize:12,renderLineHighlight:"none"}})})}function zt({showControls:s=!1,showFooter:r=!0,...t}){return e.jsxRuntimeExports.jsxs(e.SemaphorContextProvider,{dashboardProps:t,children:[e.jsxRuntimeExports.jsx(e.Te,{}),e.jsxRuntimeExports.jsxs(e.UXProvider,{children:[e.jsxRuntimeExports.jsx(Tt,{}),e.jsxRuntimeExports.jsxs(e.DashboardPanel,{...t,children:[s&&e.jsxRuntimeExports.jsx(qs,{}),e.jsxRuntimeExports.jsx(Lt,{}),e.jsxRuntimeExports.jsx(It,{})]})]})]})}exports.DashboardPlus=zt;exports.LoaderCircle=ce;exports.SelectComponent=le;exports.cleanCard=He;exports.getDashbaordStateWithoutData=Le;exports.useEditorAside=oe;
215
+ Database Query Dialect: ${b==="api"||b==="s3"?"DuckDb":""}
216
+ Table Name: ${b}
217
+ Table Columns: ${N==null?void 0:N.map(v=>`${v.column_name} | ${v.data_type}`).join(", ")}
218
+ User SQL: ${k}
219
+ ${E&&`Base Queries: ${JSON.stringify(E)} `}`,T=` When the user asks for a specific chart please use the following query structure to generate the chart query. Do not make up the column names. Use only the table columns provided above for the query. Replace x-axis, y-axis, and lables with the appropriate column names.
220
+ Visual Query Syntax: ${Qs}`,{data:F,isLoading:w,isFetching:y,isError:f,refetch:M}=e.useQuery({queryKey:["ai-query"],queryFn:()=>e.getRequest("https://semaphor.cloud/api/v1/ai",(l==null?void 0:l.accessToken)||"",{user_content:`userContent: ${z} ${d?T:""}`}),enabled:!1});function O(v){if(v.toLowerCase().includes("bar"))m("bar");else if(v.toLowerCase().includes("line"))m("line");else if(v.toLowerCase().includes("bubble"))m("bubble");else if(v.toLowerCase().includes("scatter"))m("scatter");else if(v.toLowerCase().includes("stacked"))m("stackedBar");else if(v.toLowerCase().includes("pie"))m("pie");else if(v.toLowerCase().includes("donut")||v.toLowerCase().includes("doughnut"))m("doughnut");else if(v.toLowerCase().includes("radar"))m("radar");else return m("bar"),!1;return!0}S.useEffect(()=>{F&&h(v=>[...v,{role:"ai",content:F.response}])},[F]),S.useEffect(()=>{const v=setTimeout(()=>{var L;a.current&&(a.current.scroll({top:a.current.scrollHeight,behavior:"smooth"}),(L=o.current)==null||L.focus())},100);return()=>clearTimeout(v)},[R]);function D(){t&&(h(v=>[...v,{role:"user",content:t}]),O(t)&&u(!0),n(""),M())}S.useEffect(()=>{i&&(D(),x(!1))},[i,x]);const q={fontFamily:"Arial, sans-serif",lineHeight:1.6,fontSize:15,width:"100%"},P={fontFamily:"monospace",fontSize:14,lineHeight:1.6},_={fontFamily:"Arial, sans-serif",lineHeight:1.6,fontSize:15,padding:"2px 0",marginLeft:20,listStyleType:"disc"},K={p:({node:v,...L})=>e.jsxRuntimeExports.jsx("p",{style:q,...L}),code:({node:v,...L})=>e.jsxRuntimeExports.jsx("code",{className:"rounded-sm bg-muted px-2 py-1 text-sm",...L}),pre:({node:v,...L})=>e.jsxRuntimeExports.jsxs("pre",{className:"space-y-2 rounded-sm bg-muted/50 p-3",style:P,children:[e.jsxRuntimeExports.jsx("code",{className:"whitespace-normal text-sm",children:L.children}),e.jsxRuntimeExports.jsxs("div",{className:"flex justify-start gap-2",children:[e.jsxRuntimeExports.jsx(e.Button,{onClick:V,size:"sm",variant:"outline",children:e.jsxRuntimeExports.jsx(e.ClipboardCopyIcon,{})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:H=>{const C=V(H);C&&(r(!1),j(C),c(!0))},size:"sm",variant:"outline",children:e.jsxRuntimeExports.jsx(e.PlayIcon,{})})]})]}),li:({node:v,...L})=>e.jsxRuntimeExports.jsx("li",{style:_,...L})};function V(v){const L=v.currentTarget.closest("pre");if(!L)return;const H=L.textContent||L.innerText;return navigator.clipboard.writeText(H).then(()=>console.log("Text copied to clipboard")).catch(C=>console.error("Error in copying text: ",C)),H}function W(){return R==null?void 0:R.map((v,L)=>v.role==="user"?e.jsxRuntimeExports.jsxs("div",{className:"flex items-start rounded-md bg-muted p-3 text-sm",children:[e.jsxRuntimeExports.jsx(Is,{className:"mr-2 h-5 w-5"}),e.jsxRuntimeExports.jsx("div",{children:v.content})]},L):v.role==="ai"?e.jsxRuntimeExports.jsx(e.Markdown,{className:"w-full overflow-auto py-1",components:K,children:F==null?void 0:F.response.replace(/DuckDB/gi,"Semaphor")},L):e.jsxRuntimeExports.jsx("div",{},L))}return e.jsxRuntimeExports.jsxs(e.Dialog,{open:s,onOpenChange:r,children:[e.jsxRuntimeExports.jsx(e.DialogTrigger,{asChild:!0,children:e.jsxRuntimeExports.jsx(e.Button,{size:"sm",className:"w-full justify-start border font-normal text-muted-foreground focus-visible:ring-0 focus-visible:ring-offset-0",variant:"secondary",children:"Type your question here..."})}),e.jsxRuntimeExports.jsxs(e.DialogContent,{className:"flex flex-col justify-between overflow-auto sm:max-w-[425px] md:max-h-[625px] md:min-w-[625px]",children:[e.jsxRuntimeExports.jsxs(e.DialogHeader,{children:[e.jsxRuntimeExports.jsx(e.DialogTitle,{children:"Assistant"}),e.jsxRuntimeExports.jsx(e.DialogDescription,{children:"What can I help you with?"})]}),e.jsxRuntimeExports.jsx("div",{ref:a,className:"h-[625px] w-full overflow-auto border-t border-t-muted",children:e.jsxRuntimeExports.jsx("div",{className:"space-y-4 py-2 pr-3",role:"messages",children:W()})}),e.jsxRuntimeExports.jsx("div",{children:e.jsxRuntimeExports.jsxs("div",{className:"flex w-full items-center rounded-md border",children:[e.jsxRuntimeExports.jsx(e.Textarea,{autoFocus:!0,ref:o,onKeyDown:v=>{v.key==="Enter"&&!v.shiftKey&&(v.preventDefault(),n(""),D())},placeholder:"Type your question here...",onFocus:v=>{const L=v.target,H=L.value.length;L.setSelectionRange(H,H)},className:e.cn("max-h-10 min-h-7 resize-none border-none focus-visible:ring-0 focus-visible:ring-ring focus-visible:ring-offset-0"),disabled:w||y,value:t,onChange:v=>n(v.target.value)})," ",e.jsxRuntimeExports.jsx(e.Button,{className:"h-8",size:"sm",variant:"ghost",onClick:D,children:!w&&!y?e.jsxRuntimeExports.jsx(e.PaperPlaneIcon,{}):e.jsxRuntimeExports.jsx(ce,{className:"mr-2 h-4 w-4 animate-spin text-foreground/50"})})]})})]})]})}var Ge={color:void 0,size:void 0,className:void 0,style:void 0,attr:void 0},ze=S.createContext&&S.createContext(Ge),Ks=["attr","size","title"];function Ws(s,r){if(s==null)return{};var t=Js(s,r),n,i;if(Object.getOwnPropertySymbols){var x=Object.getOwnPropertySymbols(s);for(i=0;i<x.length;i++)n=x[i],!(r.indexOf(n)>=0)&&Object.prototype.propertyIsEnumerable.call(s,n)&&(t[n]=s[n])}return t}function Js(s,r){if(s==null)return{};var t={},n=Object.keys(s),i,x;for(x=0;x<n.length;x++)i=n[x],!(r.indexOf(i)>=0)&&(t[i]=s[i]);return t}function fe(){return fe=Object.assign?Object.assign.bind():function(s){for(var r=1;r<arguments.length;r++){var t=arguments[r];for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(s[n]=t[n])}return s},fe.apply(this,arguments)}function Fe(s,r){var t=Object.keys(s);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(s);r&&(n=n.filter(function(i){return Object.getOwnPropertyDescriptor(s,i).enumerable})),t.push.apply(t,n)}return t}function ge(s){for(var r=1;r<arguments.length;r++){var t=arguments[r]!=null?arguments[r]:{};r%2?Fe(Object(t),!0).forEach(function(n){Ys(s,n,t[n])}):Object.getOwnPropertyDescriptors?Object.defineProperties(s,Object.getOwnPropertyDescriptors(t)):Fe(Object(t)).forEach(function(n){Object.defineProperty(s,n,Object.getOwnPropertyDescriptor(t,n))})}return s}function Ys(s,r,t){return r=Xs(r),r in s?Object.defineProperty(s,r,{value:t,enumerable:!0,configurable:!0,writable:!0}):s[r]=t,s}function Xs(s){var r=Zs(s,"string");return typeof r=="symbol"?r:String(r)}function Zs(s,r){if(typeof s!="object"||s===null)return s;var t=s[Symbol.toPrimitive];if(t!==void 0){var n=t.call(s,r||"default");if(typeof n!="object")return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return(r==="string"?String:Number)(s)}function Qe(s){return s&&s.map((r,t)=>S.createElement(r.tag,ge({key:t},r.attr),Qe(r.child)))}function Z(s){return r=>S.createElement(et,fe({attr:ge({},s.attr)},r),Qe(s.child))}function et(s){var r=t=>{var{attr:n,size:i,title:x}=s,o=Ws(s,Ks),a=i||t.size||"1em",l;return t.className&&(l=t.className),s.className&&(l=(l?l+" ":"")+s.className),S.createElement("svg",fe({stroke:"currentColor",fill:"currentColor",strokeWidth:"0"},t.attr,n,o,{className:l,style:ge(ge({color:s.color||t.color},t.style),s.style),height:a,width:a,xmlns:"http://www.w3.org/2000/svg"}),x&&S.createElement("title",null,x),s.children)};return ze!==void 0?S.createElement(ze.Consumer,null,t=>r(t)):r(Ge)}function st(s){return Z({tag:"svg",attr:{viewBox:"0 0 448 512"},child:[{tag:"path",attr:{d:"M439.8 200.5c-7.7-30.9-22.3-54.2-53.4-54.2h-40.1v47.4c0 36.8-31.2 67.8-66.8 67.8H172.7c-29.2 0-53.4 25-53.4 54.3v101.8c0 29 25.2 46 53.4 54.3 33.8 9.9 66.3 11.7 106.8 0 26.9-7.8 53.4-23.5 53.4-54.3v-40.7H226.2v-13.6h160.2c31.1 0 42.6-21.7 53.4-54.2 11.2-33.5 10.7-65.7 0-108.6zM286.2 404c11.1 0 20.1 9.1 20.1 20.3 0 11.3-9 20.4-20.1 20.4-11 0-20.1-9.2-20.1-20.4.1-11.3 9.1-20.3 20.1-20.3zM167.8 248.1h106.8c29.7 0 53.4-24.5 53.4-54.3V91.9c0-29-24.4-50.7-53.4-55.6-35.8-5.9-74.7-5.6-106.8.1-45.2 8-53.4 24.7-53.4 55.6v40.7h106.9v13.6h-147c-31.1 0-58.3 18.7-66.8 54.2-9.8 40.7-10.2 66.1 0 108.6 7.6 31.6 25.7 54.2 56.8 54.2H101v-48.8c0-35.3 30.5-66.4 66.8-66.4zm-6.7-142.6c-11.1 0-20.1-9.1-20.1-20.3.1-11.3 9-20.4 20.1-20.4 11 0 20.1 9.2 20.1 20.4s-9 20.3-20.1 20.3z"},child:[]}]})(s)}function tt(){const{theme:s}=e.useTheme(),r=S.useRef(),t=S.useRef(),[n,i]=S.useState(!1),[x,o]=S.useState(!1),[a,l]=S.useState(!1),[d,u]=S.useState(""),[j,E]=S.useState(!1),{authToken:c}=e.useSemaphorContext();e.useDashboardStore(p=>p.selectedSheetId);const m=e.useDashboardStore(p=>p.dashboard.baseQueries),R=e.useEditorStore(p=>p.card),h=e.useDashboardStore(p=>p.theme),N=e.useEditorStore(p=>p.isShowingVisual),k=e.useEditorStore(p=>p.selectedConnectionId),b=e.useEditorStore(p=>p.selectedDatabaseName),z=e.useEditorStore(p=>p.selectedDatamodelId),T=e.useEditorStore(p=>p.selectedSchemaName);e.useDashboardStore(p=>p.actions.updateFrameCard);const F=e.useEditorStore(p=>p.selectedTableName),w=e.useEditorStore(p=>p.card.sql),y=e.useEditorStore(p=>p.card.python),f=e.resolveBaseQuery(w,m),M=e.useEditorStore(p=>p.selectedConnectionId),O=e.useEditorStore(p=>p.frame),D=e.useDashboardStore(p=>p.filterValues),q=e.useEditorStore(p=>p.applyFilters),{setCardCustomCfg:P,setQueryResultColumns:_,setFilterValues:K,setCardSql:V,setCardPython:W,setQueryError:v,setPythonStdOut:L,setCardPreferences:H}=e.useEditorStore(p=>p.actions),C=e.useEditorStore(p=>p.onSave),A=e.useEditorStore(p=>p.actions.setApplyFilters),$=e.useEditorStore(p=>p.onClose),I=e.useEditorStore(p=>p.actions.setCardData),G=e.useEditorStore(p=>p.actions.setSqlGen),Q=e.useEditorStore(p=>p.runSql),te=e.useEditorStore(p=>p.actions.setRunSql),ee=e.useEditorStore(p=>p.actions.setIsSqlRunning),{data:B,isLoading:J,isFetching:Y,isSuccess:ne,isError:X,error:se,status:Ae,refetch:ie}=e.useQuery({queryKey:[f,y],queryFn:()=>e.postRequest("https://semaphor.cloud/api/v1/query",(c==null?void 0:c.accessToken)||"",{connection_id:M,sql:f,python:y===e.PYTHON_DEFAULT_CODE?"":y,active_filters:q?D:[]}),enabled:!1,retry:!1});S.useEffect(()=>{if(B&&(I(B.records),B.rowLimitExceeded&&e.Jt.error("Row limit (10,000) exceeded. Refine your query.",{position:"top-center",richColors:!0}),L((B==null?void 0:B.output)||""),B.records.length>0)){const{dimensionKeys:p}=e.getKeys(B.records);_(p)}},[B,I,_,L]),S.useEffect(()=>{Q&&(ie(),te(!1))},[Q,ie,te]),S.useEffect(()=>{(J||Y)&&ee(!0),(X||ne)&&ee(!1),X?(v(se.message),I([]),_([]),L("")):v("")},[J,Y,B,L,X,ne,ee,I,_,v,se]);function be(){V(""),I([]),G({}),P(""),H({})}const me=p=>{t.current=p};function Se(p,g){if(p.length===0)return"";if(g){const re=p.find(U=>U.id===g);if(re){const U=re.tabTitle;if(U=="All__Header")return p[0].id;if(U&&U.endsWith("__Header")){const os=U.split("__")[0],Ie=p.find(is=>is.tabTitle===os);return Ie?Ie.id:p[0].id}return g}}return p[0].id}function ye(){let p=w;w&&!w.includes("{{")&&(p=Bs(w),V(p));const g={...R,lastSelectedSchema:T,lastSelectedDatamodelId:z,lastSelectedDatabase:b,lastSelectedTable:F,connectionId:k,type:N?R.type:"table",sql:p,customCfg:N?R.customCfg:null},re=O.cards.map(ve=>ve.id===R.id?g:ve),U={...O,cards:re,activeCardId:Se(re,O.activeCardId)};C==null||C(U)}function pe(){$==null||$()}S.useEffect(()=>{const p=r.current,g=t.current;if(p){const re=window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light",U=h==="system"?re:h;p.editor.defineTheme("default",{base:U==="light"?"vs":"vs-dark",inherit:!0,rules:[],colors:{"editor.background":U==="light"?"#ffffff":e.getCssVariableValue("--semaphor-background")}}),p.editor.setTheme("default")}return g&&p&&g.addCommand(p.KeyMod.Shift|p.KeyCode.Enter,function(){return console.log("Executing query..."),ie(),!1}),()=>{}},[s,h,r.current]);function de(p){r.current=p}function he(){return e.jsxRuntimeExports.jsxs(e.jsxRuntimeExports.Fragment,{children:[x&&e.jsxRuntimeExports.jsx("div",{className:"xbg-yellow-100 relative flex w-1/3 min-w-0 grow overflow-hidden border-l p-1 text-xs",role:"editor-filter-container",children:e.jsxRuntimeExports.jsxs("div",{className:"w-[99%]",children:[e.jsxRuntimeExports.jsxs("div",{className:"flex items-center gap-2 pt-3",children:[e.jsxRuntimeExports.jsx(Ps,{checked:q,onCheckedChange:()=>A(!q),text:"Apply Filters"}),e.jsxRuntimeExports.jsx(Gs,{}),D&&x&&e.jsxRuntimeExports.jsx(e.Cross2Icon,{onClick:()=>o(!1),className:"bg-background/50 text-foreground/50 hover:cursor-pointer hover:text-foreground"})]}),e.jsxRuntimeExports.jsx(e.Ft,{theme:"default",onChange:p=>{if(p)try{JSON.parse(p),K(JSON.parse(p))}catch{}},defaultLanguage:"json",className:"mt-1 min-h-[220px]",value:JSON.stringify(D,null,2),options:{readOnly:!0,minimap:{enabled:!1},lineNumbers:"off",glyphMargin:!1,wordWrap:"on",scrollbar:{verticalScrollbarSize:0,horizontalScrollbarSize:0},fontSize:12,renderLineHighlight:"none"}})]})}),D&&!x&&e.jsxRuntimeExports.jsx(e.Filter,{onClick:()=>o(!0),className:e.cn("absolute bottom-4 right-6 h-3 w-3 text-foreground/50 hover:cursor-pointer hover:text-foreground",{"font-bold text-red-800":q})})]})}function je(){return e.jsxRuntimeExports.jsxs(e.ResizablePanelGroup,{className:"flex grow pb-1",direction:"vertical",role:"editor-resizable-group",children:[e.jsxRuntimeExports.jsxs(e.ResizablePanel,{id:"1",order:1,defaultSize:n?20:100,className:"relative flex grow",children:[e.jsxRuntimeExports.jsx("div",{role:"sql-container",className:"relative flex w-[99%]",children:e.jsxRuntimeExports.jsx(e.Ft,{theme:"default",className:"pt-3",onChange:p=>{V(p)},value:w,options:{minimap:{enabled:!1},wordWrap:"on",scrollbar:{verticalScrollbarSize:0,horizontalScrollbarSize:0},fontSize:14,renderLineHighlight:"none"},defaultLanguage:"sql",beforeMount:de,onMount:me})}),n&&e.jsxRuntimeExports.jsx("code",{className:"absolute right-6 top-3 text-sm text-muted-foreground/70",children:"sql"})]}),n&&e.jsxRuntimeExports.jsxs(e.jsxRuntimeExports.Fragment,{children:[e.jsxRuntimeExports.jsx(e.ResizableHandle,{withHandle:!0,className:"border"}),e.jsxRuntimeExports.jsxs(e.ResizablePanel,{id:"2",order:2,defaultSize:80,className:"relative flex grow",children:[e.jsxRuntimeExports.jsx("div",{role:"python-container",className:"relative flex w-[99%] pt-0",children:e.jsxRuntimeExports.jsx(e.Ft,{className:"pt-3",theme:"default",onChange:p=>{W(p&&p.trim()||"")},value:y||e.PYTHON_DEFAULT_CODE,options:{minimap:{enabled:!1},wordWrap:"on",scrollbar:{verticalScrollbarSize:0,horizontalScrollbarSize:0},fontSize:14,renderLineHighlight:"none"},defaultLanguage:"python",beforeMount:de,onMount:me})}),e.jsxRuntimeExports.jsx("code",{className:"absolute right-6 top-3 text-sm text-muted-foreground/70",children:"python"})]})]})]})}return e.jsxRuntimeExports.jsxs("section",{role:"editor-section",className:"flex grow flex-col justify-end",children:[e.jsxRuntimeExports.jsxs("div",{role:"sql-editor",className:"relative flex grow justify-between overflow-y-scroll",children:[je(),he()]}),e.jsxRuntimeExports.jsxs("div",{role:"editor-controls",className:"item-center flex flex-wrap justify-between gap-2 px-6 py-4",children:[e.jsxRuntimeExports.jsxs("div",{className:"flex grow items-center gap-2",children:[e.jsxRuntimeExports.jsxs(e.Button,{title:"Shift + Enter",disabled:J||Y,onClick:()=>{ie()},className:"shrink-0",size:"sm",variant:"outline",children:[J||Y?e.jsxRuntimeExports.jsx(ce,{className:"mr-2 h-4 w-4 animate-spin text-foreground/50"}):e.jsxRuntimeExports.jsx(vs,{className:"mr-2 h-4 w-4"}),"Run"]}),X&&e.jsxRuntimeExports.jsx(Hs,{error:se.message,setShowAIDialog:l,setTriggerAIRun:E,setUserInputforAI:u}),e.jsxRuntimeExports.jsxs(e.Button,{onClick:be,className:"",size:"sm",variant:"outline",children:[e.jsxRuntimeExports.jsx(ms,{className:"mr-2 size-4"}),"Clear"]}),e.jsxRuntimeExports.jsx(e.Toggle,{pressed:n,onPressedChange:p=>i(p),className:"",size:"sm",variant:"outline",children:e.jsxRuntimeExports.jsx(st,{className:"size-4 text-foreground/70"})}),e.jsxRuntimeExports.jsx(Us,{open:a,setOpen:l,userInput:d,triggerAIRun:j,setTriggerAIRun:E,setUserInput:p=>u(p)})]}),e.jsxRuntimeExports.jsxs("div",{className:"flex items-end gap-2",children:[e.jsxRuntimeExports.jsxs(e.Button,{onClick:ye,size:"sm",variant:"outline",children:[e.jsxRuntimeExports.jsx(e.Check,{className:"mr-2 size-4 font-bold text-green-600"}),"Accept"]}),e.jsxRuntimeExports.jsxs(e.Button,{onClick:pe,className:"w-full",size:"sm",variant:"outline",children:[e.jsxRuntimeExports.jsx(e.Cross2Icon,{className:"mr-2 size-4"}),"Close"]})]})]})]})}function nt({data:s}){var o;const[r,t]=S.useState([]),i=Object.keys(s[0]).map(a=>({accessorKey:a,header:({column:l})=>{const d=l.getIsSorted();return e.jsxRuntimeExports.jsx("div",{className:"flex gap-2",children:e.jsxRuntimeExports.jsxs("div",{className:"flex cursor-pointer items-center",onClick:()=>l.toggleSorting(l.getIsSorted()==="asc"),children:[a,d==="asc"?e.jsxRuntimeExports.jsx(e.TriangleUpIcon,{className:"ml-2 h-5 w-5"}):d==="desc"?e.jsxRuntimeExports.jsx(e.TriangleDownIcon,{className:"ml-2 h-5 w-5"}):null]})})}})),x=e.useReactTable({data:s,columns:i,getCoreRowModel:e.getCoreRowModel(),getPaginationRowModel:e.getPaginationRowModel(),onSortingChange:t,getSortedRowModel:e.getSortedRowModel(),manualPagination:!0,state:{sorting:r}});return e.jsxRuntimeExports.jsxs(e.Table$1,{children:[e.jsxRuntimeExports.jsx(e.TableHeader,{children:x.getHeaderGroups().map(a=>e.jsxRuntimeExports.jsx(e.TableRow,{children:a.headers.map(l=>e.jsxRuntimeExports.jsx(e.TableHead,{className:"sticky top-0 bg-muted",children:l.isPlaceholder?null:e.flexRender(l.column.columnDef.header,l.getContext())},l.id))},a.id))}),e.jsxRuntimeExports.jsx(e.TableBody,{children:(o=x.getRowModel().rows)!=null&&o.length?x.getRowModel().rows.map(a=>e.jsxRuntimeExports.jsx(e.TableRow,{className:"whitespace-nowrap py-2","data-state":a.getIsSelected()&&"selected",children:a.getVisibleCells().map(l=>e.jsxRuntimeExports.jsx(e.TableCell,{children:e.flexRender(l.column.columnDef.cell,l.getContext())},l.id))},a.id)):e.jsxRuntimeExports.jsx(e.TableRow,{children:e.jsxRuntimeExports.jsx(e.TableCell,{colSpan:i.length,className:"h-24 text-center",children:"No results."})})})]})}function Ue({className:s,...r}){var E;S.useState(0);const t=e.useDashboardStore(c=>c.themeStyle),n=e.useEditorStore(c=>c.card),i=e.useEditorStore(c=>c.frame),x=e.useDashboardStore(c=>c.dashboard.filters),o=e.useDashboardStore(c=>c.filterValues),a=e.useEditorStore(c=>c.actions.setRunSql),{updateFilter:l}=e.useDashboardActions(),d=x==null?void 0:x.find(c=>c.id===i.filterId),u=e.useEditorStore(c=>c.actions.setCard);if(S.useEffect(()=>{n.sql&&a(!0)},[o]),S.useEffect(()=>{},[n.data,n.type,n.cfg,n.customCfg,t,n.preferences]),!n.id)return null;let j;return n.data&&n.data.length>0&&(j=e.createChartConfig({data:n.data,cardType:n.type,cfg:n.cfg,customCfg:n.customCfg,preferences:n.preferences})),e.jsxRuntimeExports.jsxs(e.Card,{role:"editor-visual-card",className:e.cn("relative flex h-full flex-col rounded-none",s),...r,children:[e.jsxRuntimeExports.jsxs(e.CardHeader,{className:"flex flex-row items-start justify-between py-4",children:[e.jsxRuntimeExports.jsxs("div",{children:[e.jsxRuntimeExports.jsx(e.Editable,{text:n.title,onSave:c=>u({...n,title:c}),children:e.jsxRuntimeExports.jsx("div",{className:"flex items-center gap-2",children:e.jsxRuntimeExports.jsx(e.CardTitle,{className:"text-base",children:n.title})})},n.title),e.jsxRuntimeExports.jsx(e.Editable,{text:n.description||"",onSave:c=>u({...n,description:c}),children:e.jsxRuntimeExports.jsxs(e.CardDescription,{children:[" ",n.description]})},n.description)]}),d&&e.jsxRuntimeExports.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxRuntimeExports.jsx(e.Editable,{className:"my-1",text:d.title||d.column,onSave:c=>l({...d,title:c}),children:e.jsxRuntimeExports.jsx(e.Label,{children:d.title})}),e.getFilterComponent(d)]})]}),e.jsxRuntimeExports.jsxs(e.CardContent,{className:"flex grow flex-col pb-3",children:[n.type!=="table"&&j&&e.jsxRuntimeExports.jsx(e.ChartJsVisual,{cfg:j},JSON.stringify(j)+JSON.stringify(n.preferences)+((E=n==null?void 0:n.preferences)==null?void 0:E.customVisualCode)),n.type==="table"&&n.data&&n.data.length>0&&e.jsxRuntimeExports.jsx(e.$57acba87d6e25586$export$ccf8d8d7bbf3c2cc,{className:"flex min-h-0 flex-1 grow basis-0",children:e.jsxRuntimeExports.jsx(e.TableVisual,{card:n,data:n==null?void 0:n.data})})]})]})}function rt(){const[s,r]=S.useState(!1),[t,n]=S.useState(""),[i,x]=S.useState(""),[o,a]=S.useState(""),[l,d]=S.useState(""),u=e.useEditorStore(b=>b.card),j=e.useEditorStore(b=>b.card.customCfg),{setCardCustomCfg:E,setCustomVisualCode:c}=e.useEditorActions();function m(b){var F,w;const z={...b,data:{...b==null?void 0:b.data,datasets:(w=(F=b==null?void 0:b.data)==null?void 0:F.datasets)==null?void 0:w.map(y=>({...y,data:[]}))}};return JSON.stringify(z,null,1)}function R(){var z,T;if(!u.data||u.data.length===0)return;const b=e.createChartConfig({data:u.data,cardType:u.type,cfg:u.cfg,preferences:u.preferences});b&&(n(JSON.stringify(b,null,1)),(z=u==null?void 0:u.preferences)!=null&&z.customVisualCode&&a((T=u==null?void 0:u.preferences)==null?void 0:T.customVisualCode),j&&x(JSON.stringify(j,null,1)))}function h(){if(o&&c(o),!!i)try{const b=JSON.parse(i);return b?(E(b),d(""),x(""),b):void 0}catch(b){console.log(b),d("Invalid JSON")}}function N(){x(""),E(null)}function k(){let b;if(j){const z=e._.cloneDeep(u.cfg),T=e._.merge(z,j);return b=m(T),b}return t?(b=m(JSON.parse(t)),b):""}return e.jsxRuntimeExports.jsxs(e.Dialog,{open:s,onOpenChange:r,children:[e.jsxRuntimeExports.jsx(e.DialogTrigger,{asChild:!0,children:e.jsxRuntimeExports.jsx(e.Button,{onClick:R,className:` ${j&&"border-foreground/50 dark:border-foreground/70"}`,size:"sm",variant:"outline",children:e.jsxRuntimeExports.jsx(e.Settings,{className:"h-4 w-4"})})}),e.jsxRuntimeExports.jsxs(e.DialogContent,{className:"max-h-[70vh] min-h-[70vh] overflow-auto sm:min-w-[900px] lg:min-w-[1200px]",children:[e.jsxRuntimeExports.jsxs(e.DialogHeader,{className:"",children:[e.jsxRuntimeExports.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxRuntimeExports.jsx(e.DialogTitle,{children:"Customize Card"}),e.jsxRuntimeExports.jsxs(e.Tooltip,{children:[e.jsxRuntimeExports.jsx(e.TooltipTrigger,{children:e.jsxRuntimeExports.jsx(fs,{onClick:()=>{navigator.clipboard.writeText(u.id)},className:"size-3 cursor-pointer text-muted-foreground/70 transition-colors hover:text-muted-foreground"})}),e.jsxRuntimeExports.jsx(e.TooltipContent,{side:"right",align:"center",children:e.jsxRuntimeExports.jsx("p",{className:"text-xs",children:"Copy Card ID"})})]})]}),e.jsxRuntimeExports.jsxs(e.DialogDescription,{children:["See the configuration options and documentation",e.jsxRuntimeExports.jsx("a",{target:"_blank",className:"ml-1 text-blue-500 underline",href:"https://www.chartjs.org/docs/latest/samples/bar/vertical.html",children:"here."})]})]}),e.jsxRuntimeExports.jsxs("div",{className:"flex grow gap-2",children:[e.jsxRuntimeExports.jsx(Ue,{className:"w-1/2 rounded shadow-none"}),e.jsxRuntimeExports.jsxs(e.Tabs,{defaultValue:"custom-config",className:"flex w-1/2 flex-col",children:[e.jsxRuntimeExports.jsxs(e.TabsList,{className:"justify-start rounded-sm rounded-b-none border border-b-0",children:[e.jsxRuntimeExports.jsxs(e.TabsTrigger,{value:"custom-config",children:[j&&e.jsxRuntimeExports.jsx(e.CheckIcon,{className:"mr-1 h-5 w-5 text-green-600"}),j?"Custom Config":"Default Config"]}),e.jsxRuntimeExports.jsx(e.TabsTrigger,{className:"",value:"output",children:"Output"}),e.jsxRuntimeExports.jsx(e.TabsTrigger,{className:"",value:"custom-code",children:"Custom Code"})]}),e.jsxRuntimeExports.jsx(e.TabsContent,{className:"bg-red-x mt-0 grow rounded-b border border-t-0 p-2",value:"output",children:e.jsxRuntimeExports.jsx(e.Textarea,{disabled:!0,value:t,className:"h-full resize-none border-none font-mono focus-visible:ring-0 focus-visible:ring-offset-0"})}),e.jsxRuntimeExports.jsx(e.TabsContent,{className:"mt-0 grow rounded-b border border-t-0",value:"custom-config",children:e.jsxRuntimeExports.jsx(e.Ft,{className:"h-full w-full overflow-hidden",theme:"default",options:{minimap:{enabled:!1},wordWrap:"on",scrollbar:{verticalScrollbarSize:0,horizontalScrollbarSize:0},fontSize:14,renderLineHighlight:"none"},defaultLanguage:"json",value:k(),onChange:b=>x(b)})}),e.jsxRuntimeExports.jsx(e.TabsContent,{className:"mt-0 grow rounded-b border border-t-0",value:"custom-code",children:e.jsxRuntimeExports.jsx(e.Ft,{className:"h-full w-full overflow-hidden",theme:"default",options:{minimap:{enabled:!1},wordWrap:"on",scrollbar:{verticalScrollbarSize:0,horizontalScrollbarSize:0},fontSize:14,renderLineHighlight:"none"},defaultLanguage:"javascript",value:o,onChange:b=>a(b||"")})})]})]}),e.jsxRuntimeExports.jsxs(e.DialogFooter,{className:"flex items-center",children:[e.jsxRuntimeExports.jsx(e.Label,{className:"mr-2 text-red-500",children:l}),e.jsxRuntimeExports.jsx(e.Button,{disabled:!j,onClick:N,variant:"outline",children:"Reset"}),e.jsxRuntimeExports.jsx(e.Button,{onClick:h,variant:"outline",children:"Apply"}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>r(!1),variant:"outline",children:"Close"})]})]})]})}function Ke(s){return Z({tag:"svg",attr:{viewBox:"0 0 1024 1024"},child:[{tag:"path",attr:{d:"M926.8 397.1l-396-288a31.81 31.81 0 0 0-37.6 0l-396 288a31.99 31.99 0 0 0-11.6 35.8l151.3 466a32 32 0 0 0 30.4 22.1h489.5c13.9 0 26.1-8.9 30.4-22.1l151.3-466c4.2-13.2-.5-27.6-11.7-35.8zM838.6 417l-98.5 32-200-144.7V199.9L838.6 417zM466 567.2l-89.1 122.3-55.2-169.2L466 567.2zm-116.3-96.8L484 373.3v140.8l-134.3-43.7zM512 599.2l93.9 128.9H418.1L512 599.2zm28.1-225.9l134.2 97.1L540.1 514V373.3zM558 567.2l144.3-46.9-55.2 169.2L558 567.2zm-74-367.3v104.4L283.9 449l-98.5-32L484 199.9zM169.3 470.8l86.5 28.1 80.4 246.4-53.8 73.9-113.1-348.4zM327.1 853l50.3-69h269.3l50.3 69H327.1zm414.5-33.8l-53.8-73.9 80.4-246.4 86.5-28.1-113.1 348.4z"},child:[]}]})(s)}function We(s){return Z({tag:"svg",attr:{viewBox:"0 0 256 256",fill:"currentColor"},child:[{tag:"path",attr:{d:"M137.39,24.06A16,16,0,0,0,120,40V80.67a15.86,15.86,0,0,0,13.25,15.76A32,32,0,1,1,96,129.68c-.41-8.22,1.27-15,5-20.26h0a15.86,15.86,0,0,0-1.69-20.47L71.69,60.68a16,16,0,0,0-23.63,1.1A103.6,103.6,0,0,0,55,202.05,103.24,103.24,0,0,0,128,232h1.49A104.3,104.3,0,0,0,232,129.48C232.75,75.18,191.19,28.88,137.39,24.06ZM60.32,71.94l27.61,28.19,0,.06A43.29,43.29,0,0,0,80.44,120H40.36A87.13,87.13,0,0,1,60.32,71.94ZM40.37,136h40.3A48,48,0,0,0,120,175.34v40.3A88,88,0,0,1,40.37,136Zm149.77,54.14A87.45,87.45,0,0,1,136,215.61V175.34a47.55,47.55,0,0,0,24.73-12.23A48,48,0,0,0,136,80.66L136,40c45.52,4.08,80.67,43.28,80,89.25A87.45,87.45,0,0,1,190.14,190.14Z"},child:[]}]})(s)}function Je(s){return Z({tag:"svg",attr:{viewBox:"0 0 256 256",fill:"currentColor"},child:[{tag:"path",attr:{d:"M128,24A104,104,0,1,0,232,128,104.11,104.11,0,0,0,128,24Zm87.63,96H191.48A64.1,64.1,0,0,0,136,64.52V40.37A88.13,88.13,0,0,1,215.63,120ZM120,120H80.68A48.09,48.09,0,0,1,120,80.68Zm0,16v39.32A48.09,48.09,0,0,1,80.68,136Zm16,0h39.32A48.09,48.09,0,0,1,136,175.32Zm0-16V80.68A48.09,48.09,0,0,1,175.32,120ZM120,40.37V64.52A64.1,64.1,0,0,0,64.52,120H40.37A88.13,88.13,0,0,1,120,40.37ZM40.37,136H64.52A64.1,64.1,0,0,0,120,191.48v24.15A88.13,88.13,0,0,1,40.37,136ZM136,215.63V191.48A64.1,64.1,0,0,0,191.48,136h24.15A88.13,88.13,0,0,1,136,215.63Z"},child:[]}]})(s)}function Ye(s){return Z({tag:"svg",attr:{viewBox:"0 0 24 24",strokeWidth:"2",stroke:"currentColor",fill:"none",strokeLinecap:"round",strokeLinejoin:"round"},child:[{tag:"path",attr:{stroke:"none",d:"M0 0h24v24H0z",fill:"none"},child:[]},{tag:"path",attr:{d:"M6 16m-3 0a3 3 0 1 0 6 0a3 3 0 1 0 -6 0"},child:[]},{tag:"path",attr:{d:"M16 19m-2 0a2 2 0 1 0 4 0a2 2 0 1 0 -4 0"},child:[]},{tag:"path",attr:{d:"M14.5 7.5m-4.5 0a4.5 4.5 0 1 0 9 0a4.5 4.5 0 1 0 -9 0"},child:[]}]})(s)}function Xe(s){return Z({tag:"svg",attr:{viewBox:"0 0 24 24"},child:[{tag:"path",attr:{fill:"none",d:"M0 0h24v24H0z"},child:[]},{tag:"path",attr:{d:"m2 19.99 7.5-7.51 4 4 7.09-7.97L22 9.92l-8.5 9.56-4-4-6 6.01-1.5-1.5zm1.5-4.5 6-6.01 4 4L22 3.92l-1.41-1.41-7.09 7.97-4-4L2 13.99l1.5 1.5z"},child:[]}]})(s)}function Ze(s){return Z({tag:"svg",attr:{viewBox:"0 0 24 24"},child:[{tag:"path",attr:{fill:"none",d:"M0 0h24v24H0z"},child:[]},{tag:"path",attr:{d:"M4 9h4v11H4zM4 4h4v4H4zM10 7h4v4h-4zM16 10h4v4h-4zM16 15h4v5h-4zM10 12h4v8h-4z"},child:[]}]})(s)}function es(s){return Z({tag:"svg",attr:{version:"1.2",baseProfile:"tiny",viewBox:"0 0 24 24"},child:[{tag:"path",attr:{d:"M4 18c-.552 0-1-.448-1-1v-6.382l-.553.276c-.495.248-1.095.046-1.342-.447-.247-.494-.046-1.094.448-1.342l2-1c.31-.155.678-.139.973.044.294.183.474.504.474.851v8c0 .552-.448 1-1 1zM13 18h-5c-.404 0-.769-.244-.924-.617-.155-.374-.069-.804.217-1.09l4-4c.254-.254.394-.591.394-.95 0-.358-.14-.695-.394-.949-.508-.508-1.39-.508-1.9.001-.253.252-.393.589-.393.948 0 .552-.448 1-1 1s-1-.448-1-1c0-.894.348-1.733.98-2.364 1.265-1.263 3.464-1.263 4.727.001.632.631.979 1.471.979 2.363 0 .893-.348 1.733-.979 2.364l-2.293 2.293h2.586c.552 0 1 .448 1 1s-.448 1-1 1zM20.955 12.377c.338-.457.545-1.016.545-1.627 0-1.517-1.234-2.75-2.75-2.75-1.031 0-1.966.569-2.44 1.484-.254.49-.063 1.094.428 1.348.49.254 1.094.062 1.348-.428.128-.249.383-.404.664-.404.414 0 .75.336.75.75s-.336.75-.75.75c-.552 0-1 .448-1 1s.448 1 1 1c.689 0 1.25.561 1.25 1.25s-.561 1.25-1.25 1.25-1.25-.561-1.25-1.25c0-.552-.448-1-1-1s-1 .448-1 1c0 1.792 1.458 3.25 3.25 3.25s3.25-1.458 3.25-3.25c0-.939-.406-1.779-1.045-2.373z"},child:[]}]})(s)}function ss(s){return Z({tag:"svg",attr:{viewBox:"0 0 512 512"},child:[{tag:"path",attr:{d:"M217 25v14h78V25h-78zm0 32v46h14V71h50v32h14V57h-78zm32 32v14h14V89h-14zm-64 32v46h30v-46h-30zm48 0v14h46v-14h-46zm64 0v46h30v-46h-30zm-64 32v14h46v-14h-46zm-80 32v46h62v-46h-62zm80 0v14h46v-14h-46zm64 0v46h62v-46h-62zm-64 32v14h46v-14h-46zm-112 32v46h94v-46h-94zm112 0v14h46v-14h-46zm64 0v46h94v-46h-94zm-64 32v14h46v-14h-46zM89 313v46h126v-46H89zm144 0v14h46v-14h-46zm64 0v46h126v-46H297zm-64 32v14h46v-14h-46zM57 377v46h158v-46H57zm176 0v14h46v-14h-46zm64 0v46h158v-46H297zm-64 32v14h46v-14h-46zM25 441v46h190v-46H25zm208 0v14h46v-14h-46zm64 0v46h190v-46H297zm-64 32v14h46v-14h-46z"},child:[]}]})(s)}function ot(){const[s,r]=S.useState(!1),t=e.useEditorStore(l=>l.card.type),{setCardType:n,setCardPreferences:i,setChartOrientation:x}=e.useEditorStore(l=>l.actions),o=e.useEditorStore(l=>l.actions.setCardCustomCfg);function a(l){o(null),i({}),n(l),r(!1)}return e.jsxRuntimeExports.jsxs(e.Popover,{open:s,onOpenChange:r,children:[e.jsxRuntimeExports.jsx(e.PopoverTrigger,{asChild:!0,children:e.jsxRuntimeExports.jsx(e.Button,{size:"sm",variant:"outline",children:e.jsxRuntimeExports.jsx(it,{className:"h-4 w-4",chartType:t})})}),e.jsxRuntimeExports.jsx(e.PopoverContent,{className:"w-50",children:e.jsxRuntimeExports.jsxs("div",{className:"grid grid-cols-3 place-items-center",children:[e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>a("bar"),className:"font-normal",variant:"ghost",children:e.jsxRuntimeExports.jsx(Ne,{className:"size-5"})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>a("line"),variant:"ghost",children:e.jsxRuntimeExports.jsx(we,{className:"size-5"})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>a("stackedBar"),variant:"ghost",children:e.jsxRuntimeExports.jsx(Ze,{className:"size-5",strokeWidth:0})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>a("stackedLine"),variant:"ghost",children:e.jsxRuntimeExports.jsx(Xe,{className:"size-5",strokeWidth:0})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>a("scatter"),variant:"ghost",children:e.jsxRuntimeExports.jsx(Be,{className:"size-5"})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>a("bubble"),variant:"ghost",children:e.jsxRuntimeExports.jsx(Ye,{className:"size-4"})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>a("pie"),variant:"ghost",children:e.jsxRuntimeExports.jsx(_e,{className:"size-5"})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>a("doughnut"),variant:"ghost",children:e.jsxRuntimeExports.jsx(We,{className:"size-5",strokeWidth:1})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>a("radar"),variant:"ghost",children:e.jsxRuntimeExports.jsx(Ke,{className:"size-5 font-extralight",strokeWidth:.5})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>a("polarArea"),variant:"ghost",children:e.jsxRuntimeExports.jsx(Je,{className:"size-5"})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>a("pyramid"),variant:"ghost",children:e.jsxRuntimeExports.jsx(ss,{className:"size-5"})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>a("range"),variant:"ghost",children:e.jsxRuntimeExports.jsx(qe,{className:"size-5"})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>a("table"),variant:"ghost",children:e.jsxRuntimeExports.jsx(e.Table,{className:"size-5"})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>a("kpi"),variant:"ghost",children:e.jsxRuntimeExports.jsx(es,{className:"size-6"})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>a("text"),variant:"ghost",children:e.jsxRuntimeExports.jsx(ke,{className:"size-4"})})]})})]})}function it({chartType:s,className:r}){switch(s){case"bar":return e.jsxRuntimeExports.jsx(Ne,{className:r});case"line":return e.jsxRuntimeExports.jsx(we,{className:r});case"pie":return e.jsxRuntimeExports.jsx(_e,{className:r});case"radar":return e.jsxRuntimeExports.jsx(Ke,{className:r});case"scatter":return e.jsxRuntimeExports.jsx(Be,{className:r});case"bubble":return e.jsxRuntimeExports.jsx(Ye,{className:r});case"doughnut":return e.jsxRuntimeExports.jsx(We,{className:r});case"stackedBar":return e.jsxRuntimeExports.jsx(Ze,{className:"size-4 text-foreground/70"});case"stackedLine":return e.jsxRuntimeExports.jsx(Xe,{className:"size-4 text-foreground/70"});case"polarArea":return e.jsxRuntimeExports.jsx(Je,{className:r});case"pyramid":return e.jsxRuntimeExports.jsx(ss,{className:r});case"range":return e.jsxRuntimeExports.jsx(qe,{className:r});case"kpi":return e.jsxRuntimeExports.jsx(es,{className:r});case"text":return e.jsxRuntimeExports.jsx(ke,{className:r});default:return e.jsxRuntimeExports.jsx(e.Table,{className:r})}}function Me(){const s=e.useEditorStore(h=>h.frame),r=e.useEditorStore(h=>h.card),t=e.useEditorStore(h=>h.card.data),n=e.useEditorStore(h=>h.isShowingVisual),i=e.useEditorStore(h=>h.isSqlRunning),x=e.useEditorStore(h=>h.queryError),o=e.useEditorStore(h=>h.pythonStdOut),a=e.useEditorStore(h=>h.actions.setRunSql);e.useEditorStore(h=>h.onSave),e.useEditorStore(h=>h.onClose),e.useEditorStore(h=>h.actions.setCardSql),e.useEditorStore(h=>h.actions.setCardType),e.useEditorStore(h=>h.actions.setSqlGen);const{setFrame:l,setCard:d,updateCardInFrame:u}=e.useEditorActions();if(!r)return e.jsxRuntimeExports.jsx(e.jsxRuntimeExports.Fragment,{children:"No Active Card"});function j(){const h={id:e.v4(),title:"Title",description:"Description",preferences:{onClickFilter:[{columnIndex:0,expression:""}]},type:"bar",sql:"",data:[]},N={...s,cards:[...s.cards,h],activeCardId:h.id};l(N),d(h)}function E(h){const N=s.cards.filter(z=>z.id!==h),k=N[0],b={...s,cards:N,activeCardId:k.id};l(b),d(k)}function c(h){const N={...s,cards:s.cards.map(b=>b.id===r.id?r:b),activeCardId:h};l(N);const k=N.cards.find(b=>b.id===h);d(k),k.sql&&(console.log("newActiveCard.sql",k.sql),k.data&&k.data.length===0&&a(!0))}function m(){return e.jsxRuntimeExports.jsxs(e.Tabs,{onValueChange:c,value:s.activeCardId,className:"flex grow flex-col pb-3",children:[s.cards.map(h=>e.jsxRuntimeExports.jsx(e.TabsContent,{className:"mt-0 grow",value:h.id,children:R()},h.id)),e.jsxRuntimeExports.jsx(e.TabsList,{className:"mx-6 justify-between",children:e.jsxRuntimeExports.jsxs("div",{className:"flex items-center",children:[s.cards.map(h=>e.jsxRuntimeExports.jsx(e.Editable,{text:h.tabTitle||h.title,onSave:N=>{d({...r,tabTitle:N}),u({...r,tabTitle:N})},children:e.jsxRuntimeExports.jsxs(e.TabsTrigger,{className:"",value:h.id,children:[h.tabTitle||h.title,s.activeCardId===h.id&&s.cards.length>1&&e.jsxRuntimeExports.jsx(e.X,{className:"ml-2 size-3.5 text-muted-foreground hover:text-foreground",onClick:()=>E(h.id)})]})},h.id)),e.jsxRuntimeExports.jsx(e.Button,{className:"ml-1 h-8 px-2 hover:bg-muted-foreground/50",variant:"outline",onClick:j,children:e.jsxRuntimeExports.jsx(e.Plus,{className:"h-4 w-4"})})]})})]})}function R(){return r.type==="kpi"?e.jsxRuntimeExports.jsx("div",{className:"flex h-full items-center justify-center",children:e.jsxRuntimeExports.jsx("div",{className:"w-1/2 rounded-md border",children:e.jsxRuntimeExports.jsx(e.KPICard,{isLoading:i,card:r})})}):r.type==="text"?e.jsxRuntimeExports.jsx("div",{className:"flex h-full items-center justify-center",children:e.jsxRuntimeExports.jsx("div",{className:"w-1/2 rounded-md border",children:e.jsxRuntimeExports.jsx(e.TextCard,{isLoading:i,card:r})})}):e.jsxRuntimeExports.jsx(Ue,{className:"grow border-none shadow-none"})}return e.jsxRuntimeExports.jsxs("div",{className:"relative flex h-full flex-col pt-3",children:[i&&e.jsxRuntimeExports.jsx(ce,{className:"absolute bottom-0 left-0 right-0 top-0 z-10 m-auto h-10 w-10 animate-spin text-foreground/10"}),e.jsxRuntimeExports.jsxs("div",{className:"mb-0 flex min-h-10 items-center justify-end gap-2 px-6",children:[n&&e.jsxRuntimeExports.jsxs("div",{className:"flex grow items-center gap-2",children:[e.jsxRuntimeExports.jsx(ot,{}),r.type!=="table"&&e.jsxRuntimeExports.jsx(rt,{})]}),e.jsxRuntimeExports.jsx(lt,{})]}),n?m():e.jsxRuntimeExports.jsxs("div",{className:"flex min-h-0 w-full flex-1 grow basis-0 px-6",children:[o&&e.jsxRuntimeExports.jsx(at,{}),r.data&&r.data.length>0&&e.jsxRuntimeExports.jsx(nt,{data:t||[]}),x&&e.jsxRuntimeExports.jsx("span",{className:"font-mono text-sm",children:x})]})]})}function at(){const s=e.useEditorStore(t=>t.pythonStdOut);if(!s)return null;const r=s.replace(/\n/g,"<br>");return e.jsxRuntimeExports.jsxs(e.jsxRuntimeExports.Fragment,{children:[e.jsxRuntimeExports.jsx("p",{className:"font-mono text-sm",children:"Output:"}),e.jsxRuntimeExports.jsx("div",{dangerouslySetInnerHTML:{__html:r},className:"bg-muted p-2 font-mono text-sm"}),e.jsxRuntimeExports.jsx(e.Separator,{className:"mb-2"})]})}function lt(){const s=e.useEditorStore(t=>t.isShowingVisual),r=e.useEditorStore(t=>t.actions.setIsShowingVisual);return e.jsxRuntimeExports.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsxRuntimeExports.jsx(e.Label,{htmlFor:"visualize",children:"Chart"}),e.jsxRuntimeExports.jsx(e.Switch,{checked:s,onCheckedChange:()=>r(!s),id:"visualize",className:"data-[state=checked]:bg-foreground/50"})]})}function xe(){const[s,r]=S.useState([]);e.useEditorStore(u=>u.card.cfg);const t=e.useEditorStore(u=>u.card.preferences),{setCardCfg:n,setFilterOnClickColumnIndex:i,setCardPreferences:x}=e.useEditorStore(u=>u.actions),o=e.useEditorStore(u=>u.queryResultColumns);e.useEditorStore(u=>{var j;return(j=u.card.preferences)==null?void 0:j.filterOnClickColumnIndex}),S.useEffect(()=>{o&&r(new Array(o.length).fill(!1))},[o]);function a(u,j){var E,c;j?t!=null&&t.onClickFilter&&((E=t==null?void 0:t.onClickFilter)==null?void 0:E.length)>0?x({...t,onClickFilter:[...t.onClickFilter,{columnIndex:u,expression:""}]}):x({...t,onClickFilter:[{columnIndex:u,expression:""}]}):(x({...t,onClickFilter:(c=t==null?void 0:t.onClickFilter)==null?void 0:c.filter(m=>m.columnIndex!==u)}),r(m=>{const R=[...m];return R[u]=!1,R}))}function l(u,j){var c;const E=(c=t==null?void 0:t.onClickFilter)==null?void 0:c.map(m=>m.columnIndex===u?{...m,expression:j.target.value}:m);x({...t,onClickFilter:E})}function d(u){var j,E,c,m;if(s!=null&&s[u]||(E=(j=t==null?void 0:t.onClickFilter)==null?void 0:j.find(R=>R.columnIndex===u))!=null&&E.expression)return e.jsxRuntimeExports.jsx(e.Input,{value:(m=(c=t==null?void 0:t.onClickFilter)==null?void 0:c.find(R=>R.columnIndex===u))==null?void 0:m.expression,onChange:R=>l(u,R),type:"text",className:"h-9 w-full font-mono text-xs focus-visible:ring-0 focus-visible:ring-ring focus-visible:ring-offset-0",placeholder:"Expression"})}return e.jsxRuntimeExports.jsxs("div",{className:"space-y-2",children:[e.jsxRuntimeExports.jsx(e.Label,{children:"On Click"}),o==null?void 0:o.map((u,j)=>{var E,c;return e.jsxRuntimeExports.jsx("div",{className:"xbg-red-100 group flex items-center justify-between space-y-2",children:e.jsxRuntimeExports.jsxs("div",{className:"grow",children:[e.jsxRuntimeExports.jsxs("div",{className:"flex items-center space-x-2 py-2",children:[e.jsxRuntimeExports.jsx(e.Checkbox,{checked:!!((E=t==null?void 0:t.onClickFilter)!=null&&E.find(m=>m.columnIndex===j)),onCheckedChange:m=>a(j,m)}),e.jsxRuntimeExports.jsx("label",{className:"text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70",children:u}),e.jsxRuntimeExports.jsx("div",{className:"flex items-center gap-2",children:((c=t==null?void 0:t.onClickFilter)==null?void 0:c.find(m=>m.columnIndex===j))&&e.jsxRuntimeExports.jsx(Ve,{onClick:()=>{r(m=>{const R=[...m];return R[j]=!m[j],R})},className:"invisible size-3 cursor-pointer text-gray-400 group-hover:visible"})})]}),d(j)]})},u)})]})}function Re(){var o,a,l;const s=e.useEditorStore(d=>d.card.preferences),r=e.useEditorStore(d=>d.card.cfg),{setCardCfg:t,setCardPreferences:n,setChartOrientation:i}=e.useEditorStore(d=>d.actions);(o=r==null?void 0:r.options)!=null&&o.indexAxis;function x(d){i(d)}return e.jsxRuntimeExports.jsxs(e.RadioGroup,{value:((a=s==null?void 0:s.chartOptions)==null?void 0:a.indexAxis)||((l=r==null?void 0:r.options)==null?void 0:l.indexAxis)||"x",onValueChange:x,className:"flex gap-3",defaultValue:"x",children:[e.jsxRuntimeExports.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsxRuntimeExports.jsx(e.RadioGroupItem,{value:"x",id:"r1"}),e.jsxRuntimeExports.jsx("label",{className:"text-sm",htmlFor:"r1",children:"Vertical"})]}),e.jsxRuntimeExports.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsxRuntimeExports.jsx(e.RadioGroupItem,{value:"y",id:"r2"}),e.jsxRuntimeExports.jsx("label",{className:"text-sm",htmlFor:"r2",children:"Horizontal"})]})]})}const ae="focus-visible:ring-0 focus-visible:ring-ring focus-visible:ring-offset-0";function Oe(s,r){var n,i,x;const t=e.getNumberAxis(s,r);return((x=(i=(n=s==null?void 0:s.chartOptions)==null?void 0:n.scales)==null?void 0:i[t])==null?void 0:x.type)||"linear"}function ts(){var K,V,W,v,L,H;const[s,r]=S.useState(!1),t=e.useEditorStore(C=>{var A;return(A=C.card)==null?void 0:A.preferences}),n=e.useEditorStore(C=>{var A;return(A=C.card)==null?void 0:A.cfg}),i=e.getNumberAxis(t,n),[x,o]=S.useState(Oe(t)),[a,l]=S.useState(((W=(V=(K=t==null?void 0:t.chartOptions)==null?void 0:K.scales)==null?void 0:V[i])==null?void 0:W.min)||""),[d,u]=S.useState(((H=(L=(v=t==null?void 0:t.chartOptions)==null?void 0:v.scales)==null?void 0:L[i])==null?void 0:H.max)||""),[j,E]=S.useState(a||d?"custom":"auto"),[c,m]=S.useState(""),[R,h]=S.useState(0),[N,k]=S.useState(""),[b,z]=S.useState(""),[T,F]=S.useState(""),w=e.useEditorStore(C=>C.actions.setCardPreferences),{updateCardInFrame:y}=e.useEditorActions(),f=e.useEditorStore(C=>C.card),M=e.useEditorStore(C=>{var A;return(A=C.card)==null?void 0:A.type}),O=["pie","doughnut","polarArea"].includes(M);S.useEffect(()=>{var C,A,$,I,G,Q,te,ee,B,J,Y,ne,X,se;o(Oe(t)),l((($=(A=(C=t==null?void 0:t.chartOptions)==null?void 0:C.scales)==null?void 0:A[i])==null?void 0:$.min)===0?0:""),u(((Q=(G=(I=t==null?void 0:t.chartOptions)==null?void 0:I.scales)==null?void 0:G[i])==null?void 0:Q.max)||""),m(((J=(B=(ee=(te=t==null?void 0:t.chartOptions)==null?void 0:te.scales)==null?void 0:ee[i])==null?void 0:B.ticks)==null?void 0:J.stepSize)||""),h(((Y=t==null?void 0:t.numberAxisFormat)==null?void 0:Y.decimalPlaces)||0),k(((ne=t==null?void 0:t.numberAxisFormat)==null?void 0:ne.suffix)||""),z(((X=t==null?void 0:t.numberAxisFormat)==null?void 0:X.currency)||""),F(((se=t==null?void 0:t.numberAxisFormat)==null?void 0:se.locale)||"")},[s,t,i]);function D(C,A){return A===""||/^[0-9\b]+$/.test(A)?Number(A):Number(C)}function q(){return e.jsxRuntimeExports.jsxs(e.jsxRuntimeExports.Fragment,{children:[e.jsxRuntimeExports.jsxs("div",{className:"grid grid-cols-6 items-center gap-2",children:[e.jsxRuntimeExports.jsx(e.Label,{className:"col-span-2 hover:cursor-pointer hover:underline",htmlFor:"currency",children:e.jsxRuntimeExports.jsx("a",{target:"_blank",href:"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat",children:"Currency"})}),e.jsxRuntimeExports.jsx(e.Input,{value:b,placeholder:"USD",onChange:C=>z(C.target.value),id:"currency",className:`col-span-2 h-8 w-full ${ae}`}),e.jsxRuntimeExports.jsx(e.Input,{value:T,placeholder:"en-US",onChange:C=>F(C.target.value),id:"locale",className:`col-span-2 h-8 w-full ${ae}`})]}),e.jsxRuntimeExports.jsxs("div",{className:"grid grid-cols-9 items-center gap-2",children:[e.jsxRuntimeExports.jsx(e.Label,{className:"col-span-3",htmlFor:"format",children:"Decimals"}),e.jsxRuntimeExports.jsx(e.Input,{value:R,onChange:C=>h(Number(C.target.value)),id:"format",className:`col-span-6 h-8 w-full tracking-wide ${ae}`})]})]})}function P(){return e.jsxRuntimeExports.jsxs(e.jsxRuntimeExports.Fragment,{children:[e.jsxRuntimeExports.jsxs("div",{className:"grid grid-cols-3 items-center gap-2",children:[e.jsxRuntimeExports.jsx(e.Label,{htmlFor:"range",children:"Range"}),e.jsxRuntimeExports.jsx(e.Input,{id:"min",value:a,onChange:C=>l(A=>D(A,C.target.value)),className:`col-span-1 h-8 w-full ${ae}`}),e.jsxRuntimeExports.jsx(e.Input,{value:d,onChange:C=>u(A=>D(A,C.target.value)),id:"max",className:`col-span-1 h-8 w-full ${ae}`})]}),e.jsxRuntimeExports.jsxs("div",{className:"grid grid-cols-3 items-center gap-2",children:[e.jsxRuntimeExports.jsx(e.Label,{htmlFor:"step-size",children:"Step Size"}),e.jsxRuntimeExports.jsx(e.Input,{value:c,onChange:C=>m(A=>D(A,C.target.value)),id:"step-size",className:`col-span-1 h-8 w-full ${ae}`})]})]})}function _(){var I;let C={};j==="custom"&&(C={min:a,max:d,ticks:{stepSize:c}});const A={...t||{},chartOptions:{...t==null?void 0:t.chartOptions,scales:{...(I=t==null?void 0:t.chartOptions)==null?void 0:I.scales,[i]:{type:x,...x==="linear"?C:{}}}},numberAxisFormat:{decimalPlaces:R,suffix:N,currency:b,locale:T}};console.log(A),w(A);const $={...f,preferences:A};y($)}return e.jsxRuntimeExports.jsxs(e.Popover,{onOpenChange:C=>r(C),children:[e.jsxRuntimeExports.jsx(e.PopoverTrigger,{asChild:!0,children:e.jsxRuntimeExports.jsx(e.SliderIcon,{className:"size-4 cursor-pointer text-muted-foreground hover:text-foreground"})}),e.jsxRuntimeExports.jsx(e.PopoverContent,{align:"center",className:"max-w-65",children:e.jsxRuntimeExports.jsxs("div",{className:"grid gap-4",children:[e.jsxRuntimeExports.jsxs("div",{className:"space-y-2",children:[e.jsxRuntimeExports.jsx("h4",{className:"font-medium leading-none",children:"Scale Options"}),e.jsxRuntimeExports.jsx("p",{className:"text-sm text-muted-foreground",children:"Set the scale for the number axis"})]}),e.jsxRuntimeExports.jsxs("div",{className:"grid gap-2",children:[e.jsxRuntimeExports.jsxs("div",{className:"grid grid-cols-3 items-center gap-2",children:[e.jsxRuntimeExports.jsx(e.Label,{htmlFor:"scale",children:"Type"}),e.jsxRuntimeExports.jsxs(e.Select,{disabled:O,value:x,onValueChange:C=>o(C),children:[e.jsxRuntimeExports.jsx(e.SelectTrigger,{className:"col-span-2 h-8 w-full focus:ring-1 focus:ring-offset-0",children:e.jsxRuntimeExports.jsx(e.SelectValue,{})}),e.jsxRuntimeExports.jsx(e.SelectContent,{id:"type",children:e.jsxRuntimeExports.jsxs(e.SelectGroup,{children:[e.jsxRuntimeExports.jsx(e.SelectLabel,{children:"Option"}),e.jsxRuntimeExports.jsx(e.SelectItem,{value:"linear",children:"Linear"}),e.jsxRuntimeExports.jsx(e.SelectItem,{value:"logarithmic",children:"Logarithmic"})]})})]})]}),x=="linear"&&e.jsxRuntimeExports.jsxs("div",{className:"grid grid-cols-3 items-center gap-2 py-1",children:[e.jsxRuntimeExports.jsx(e.Label,{htmlFor:"scale-option",children:"Setup"}),e.jsxRuntimeExports.jsxs(e.RadioGroup,{disabled:O,id:"scale-option",value:j,onValueChange:C=>E(C),className:"col-span-2 flex gap-3",defaultValue:"x",children:[e.jsxRuntimeExports.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsxRuntimeExports.jsx(e.RadioGroupItem,{value:"auto",id:"r1"}),e.jsxRuntimeExports.jsx("label",{className:"text-sm",htmlFor:"r1",children:"Auto"})]}),e.jsxRuntimeExports.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsxRuntimeExports.jsx(e.RadioGroupItem,{value:"custom",id:"r2"}),e.jsxRuntimeExports.jsx("label",{className:"text-sm",htmlFor:"r2",children:"Custom"})]})]})]}),j==="custom"&&x=="linear"&&P(),q(),e.jsxRuntimeExports.jsx(e.SelectSeparator,{}),e.jsxRuntimeExports.jsx("div",{className:"grid grid-cols-3",children:e.jsxRuntimeExports.jsx(e.Button,{onClick:_,variant:"secondary",className:"col-span-1 col-start-3 h-8 w-full",children:"Apply"})})]})]})})]})}function ct({idx:s}){var a;const r=e.useEditorStore(l=>{var d;return(d=l.card)==null?void 0:d.preferences}),t=e.useEditorStore(l=>{var d;return(d=l.card.preferences)==null?void 0:d.datasetOptions}),n=e.useEditorStore(l=>l.actions.setCardPreferences),i=(a=r==null?void 0:r.chartOptions)==null?void 0:a.indexAxis,x=t==null?void 0:t.find(l=>l.idx===s);function o(l,d){(l==="end"||l==="start")&&e.getContrastColor(e.getCanvasBackgroundColor());const u={display:l!=="none",align:l,anchor:l,clamp:!0};if(!x)n({...r,datasetOptions:[...t||[],{idx:d,datalabels:u}]});else{const j={...x};j.datalabels=u;const E=t==null?void 0:t.map(c=>c.idx===d?j:c);n({...r,datasetOptions:E})}}return e.jsxRuntimeExports.jsxs(e.Popover,{children:[e.jsxRuntimeExports.jsx(e.PopoverTrigger,{children:e.jsxRuntimeExports.jsx(Ds,{className:"invisible size-4 rotate-[135deg] cursor-pointer text-muted-foreground hover:text-foreground group-hover:visible"})}),e.jsxRuntimeExports.jsx(e.PopoverContent,{className:"w-fit p-1",children:e.jsxRuntimeExports.jsxs("div",{className:"flex gap-1",children:[e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>o("none",s),size:"sm",variant:"secondary",className:"h-7 p-1 text-xs font-normal",children:e.jsxRuntimeExports.jsx(e.X,{className:"size-4"})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>o("start",s),size:"sm",variant:"secondary",className:"h-7 p-1 text-xs font-normal",children:e.jsxRuntimeExports.jsx(gs,{className:e.cn("h-4 w-4",{"rotate-90":i==="y"})})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>o("center",s),size:"sm",variant:"secondary",className:"h-7 p-1 text-xs font-normal",children:e.jsxRuntimeExports.jsx(bs,{className:e.cn("h-4 w-4",{"rotate-90":i==="y"})})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>o("end",s),size:"sm",variant:"secondary",className:"h-7 p-1 text-xs font-normal",children:e.jsxRuntimeExports.jsx(Rs,{className:e.cn("h-4 w-4",{"rotate-90":i==="y"})})})]})})]})}function ns(){const s=e.useEditorStore(l=>l.card),r=e.useEditorStore(l=>{var d,u,j;return(j=(u=(d=l==null?void 0:l.card)==null?void 0:d.preferences)==null?void 0:u.chartOptions)==null?void 0:j.indexAxis}),t=r==="y"?"Y axis":"X axis",n=r==="y"?"X axis":"Y axis",{keys:i,metricKeys:x,dimensionKeys:o}=e.getKeys(s.data||[]);let a=x;if(["stackedBar","stackedLine"].includes(s.type)){const l=e.pivotData({dataArray:s.data||[],groupKey:o[0],pivotKey:o[1],valueKey:a[0]}),{metricKeys:d}=e.getKeys(l);a=d}return i.length===0?null:e.jsxRuntimeExports.jsxs("div",{className:"space-y-4",children:[e.jsxRuntimeExports.jsxs("div",{className:"space-y-2",children:[e.jsxRuntimeExports.jsx(e.Label,{children:t}),e.jsxRuntimeExports.jsx("div",{className:"my-1 space-y-1",children:e.jsxRuntimeExports.jsx("div",{className:"rounded-md bg-muted/70 px-2 py-1 hover:bg-muted",children:e.jsxRuntimeExports.jsx("p",{children:o[0]})})})]}),e.jsxRuntimeExports.jsxs("div",{className:"space-y-2",children:[e.jsxRuntimeExports.jsxs("div",{className:"flex items-center justify-between gap-5",children:[e.jsxRuntimeExports.jsx(e.Label,{children:n}),e.jsxRuntimeExports.jsx(ts,{})]}),e.jsxRuntimeExports.jsx("div",{className:"my-1 space-y-1",children:a.map((l,d)=>e.jsxRuntimeExports.jsx(xt,{col:l,idx:d},l))})]})]})}function xt({col:s,idx:r}){const t=e.useEditorStore(a=>{var l;return(l=a.card)==null?void 0:l.preferences}),n=e.useEditorStore(a=>{var l;return(l=a.card.preferences)==null?void 0:l.datasetOptions}),i=n==null?void 0:n.find(a=>a.idx===r),{setCardPreferences:x}=e.useEditorStore(a=>a.actions);function o(a){if(!i)x({...t,datasetOptions:[...n||[],{idx:r,type:a==="area"?"line":a,fill:a==="area"?"origin":""}]});else{const l={...i};l.type=a==="area"?"line":a,l.fill=a==="area"?"origin":"";const d=n==null?void 0:n.map(u=>u.idx===r?l:u);x({...t,datasetOptions:d})}}return e.jsxRuntimeExports.jsxs("div",{className:"group flex items-center justify-between gap-5 rounded-md bg-muted/70 px-2 py-1 hover:bg-muted",children:[e.jsxRuntimeExports.jsx("p",{children:s}),e.jsxRuntimeExports.jsxs("div",{className:"flex gap-2",children:[e.jsxRuntimeExports.jsx(Ne,{onClick:()=>o("bar"),className:"invisible size-4 cursor-pointer text-muted-foreground hover:text-foreground group-hover:visible"}),e.jsxRuntimeExports.jsx(we,{onClick:()=>o("line"),className:"invisible size-4 cursor-pointer text-muted-foreground hover:text-foreground group-hover:visible"}),e.jsxRuntimeExports.jsx(ls,{onClick:()=>o("area"),className:"invisible size-4 cursor-pointer text-muted-foreground hover:text-foreground group-hover:visible"}),e.jsxRuntimeExports.jsx(e.Separator,{orientation:"vertical",className:"invisible size-4 cursor-pointer py-2 text-muted-foreground hover:text-foreground group-hover:visible"}),e.jsxRuntimeExports.jsx(ct,{idx:r})]})]})}function rs(){const s=e.useEditorStore(E=>E.selectedConnectionId),r=e.useEditorStore(E=>E.selectedDatamodelId),t=e.useEditorStore(E=>E.selectedDatabaseName),n=e.useEditorStore(E=>E.selectedSchemaName),i=e.useEditorStore(E=>E.selectedTableName),x=e.useDashboardStore(E=>E.dashboard.filters)||[],o=e.useDashboardStore(E=>E.actions.addFilter),a=e.useDashboardStore(E=>E.actions.removeFilter),l=e.useDashboardStore(E=>E.actions.removeFilterValue),{modelItems:d,tableName:u}=oe();function j(E,c="dashboard"){var F;const m=e.fmt(E.column_name),R=e.fmt(t||""),h=e.fmt(n||""),N=e.fmt(u);let k=e.getQualifiedTableName(h,N),b=`${k}.${m}`;const z=(F=d==null?void 0:d.find(w=>w.id===r))==null?void 0:F.name;r&&r!=="none"&&(b=`${e.DATAMODEL_NAMESPCACE}.${z}.${m}`,k=`${e.DATAMODEL_NAMESPCACE}.${z}`);const T=x==null?void 0:x.find(w=>w.column===b&&w.table===N&&(w.database===R||w.database===t));if(T)l(T.id),a(T.id);else{const w=e.v4();return u==="api"&&s?(o({location:c,id:w,column:b,title:E.column_name,dataType:E.data_type,table:"api",database:"",connectionId:s,operation:"in",sql:e.getDefaultFilterSql(E.data_type,k,m)}),w):(o({id:w,location:c,column:b,title:E.column_name,dataType:E.data_type,table:i||"",database:t||"",connectionId:s||"",operation:"in",sql:e.getDefaultFilterSql(E.data_type,k,m)}),w)}}return{assignFilter:j}}function ue(){const s=e.useDashboardStore(a=>a.dashboard.filters),r=e.useEditorStore(a=>a.frame),{setFrame:t}=e.useEditorActions(),{columns:n}=oe(),{assignFilter:i}=rs();function x(a){const l=i(a,"frame");t({...r,filterId:l})}const o=s==null?void 0:s.find(a=>a.id===r.filterId);return e.jsxRuntimeExports.jsxs("div",{className:"space-y-3",children:[e.jsxRuntimeExports.jsx(e.Label,{children:"Card Filter"}),e.jsxRuntimeExports.jsx(ut,{onSelect:x,columns:n}),o&&e.jsxRuntimeExports.jsx(e.FilterHeader,{filter:o})]})}function ut({columns:s,onSelect:r}){var o;const[t,n]=Te.useState(!1),[i,x]=Te.useState("");return e.jsxRuntimeExports.jsxs(e.Popover,{open:t,onOpenChange:n,children:[e.jsxRuntimeExports.jsx(e.PopoverTrigger,{asChild:!0,children:e.jsxRuntimeExports.jsxs(e.Button,{size:"sm",variant:"outline",role:"combobox","aria-expanded":t,className:"w-full justify-between font-normal",children:[i?(o=s.find(a=>a.column_name===i))==null?void 0:o.column_name:"Select Column...",e.jsxRuntimeExports.jsx(e.CaretSortIcon,{className:"ml-2 h-4 w-4 shrink-0 opacity-50"})]})}),e.jsxRuntimeExports.jsx(e.PopoverContent,{className:"w-[200px] p-0",children:e.jsxRuntimeExports.jsxs(e.Command,{children:[e.jsxRuntimeExports.jsx(e.CommandInput,{placeholder:"Search column",className:"h-9"}),e.jsxRuntimeExports.jsxs(e.CommandList,{children:[e.jsxRuntimeExports.jsx(e.CommandEmpty,{children:"No framework found."}),e.jsxRuntimeExports.jsx(e.CommandGroup,{children:s.map(a=>e.jsxRuntimeExports.jsxs(e.CommandItem,{value:a.column_name,onSelect:l=>{const d=l===i?"":l;x(d),n(!1),d&&r(a)},children:[a.column_name,e.jsxRuntimeExports.jsx(e.CheckIcon,{className:e.cn("ml-auto h-4 w-4",i===a.column_name?"opacity-100":"opacity-0")})]},a.column_name))})]})]})})]})}function dt({cardType:s}){return e.jsxRuntimeExports.jsx("div",{className:"space-y-6 px-6 py-2",children:e.jsxRuntimeExports.jsxs(e.Accordion,{defaultValue:["item-2"],type:"multiple",children:[e.jsxRuntimeExports.jsxs(e.AccordionItem,{value:"item-1",children:[e.jsxRuntimeExports.jsx(e.AccordionTrigger,{children:`${e.titleCase(s)} Chart`}),e.jsxRuntimeExports.jsxs(e.AccordionContent,{className:"space-y-4 font-mono text-xs",children:[e.jsxRuntimeExports.jsx("div",{className:"rounded bg-muted px-2 py-1 text-xs",children:"SELECT x-axis, y-axis-1, y-axis-2,... FROM table"}),e.jsxRuntimeExports.jsxs("ul",{className:"ml-6 list-disc text-xs [&>li]:mt-2",children:[e.jsxRuntimeExports.jsx("li",{children:"x-axis - category"}),e.jsxRuntimeExports.jsx("li",{children:"y-axis1 - number"}),e.jsxRuntimeExports.jsx("li",{children:"y-axis2 - number"})]}),e.jsxRuntimeExports.jsxs("div",{children:["See ",e.jsxRuntimeExports.jsx("a",{target:"_blank",onClick:r=>r.stopPropagation(),className:"text-blue-700",href:"https://docs.semaphor.cloud/concepts/visuals#line-chart",children:"example"})," in the docs."]})]})]}),e.jsxRuntimeExports.jsxs(e.AccordionItem,{value:"item-2",children:[e.jsxRuntimeExports.jsx(e.AccordionTrigger,{children:"Settings"}),e.jsxRuntimeExports.jsxs(e.AccordionContent,{className:"space-y-4 px-2",children:[e.jsxRuntimeExports.jsx(Re,{}),e.jsxRuntimeExports.jsx(ns,{})]})]}),e.jsxRuntimeExports.jsxs(e.AccordionItem,{value:"item-3",children:[e.jsxRuntimeExports.jsx(e.AccordionTrigger,{children:"Filters"}),e.jsxRuntimeExports.jsxs(e.AccordionContent,{className:"space-y-4 px-2",children:[e.jsxRuntimeExports.jsx(xe,{}),e.jsxRuntimeExports.jsx(ue,{})]})]})]})})}function De(){var i,x,o;const s=e.useEditorStore(a=>a.card.cfg),r=e.useEditorStore(a=>a.actions.setCardCfg),t=e.useEditorStore(a=>a.card.type);function n(a){var u;const l={datalabels:{display:a!=="none",align:a,anchor:a,clamp:!0}},d={...s,options:{...s==null?void 0:s.options,plugins:{...(u=s==null?void 0:s.options)==null?void 0:u.plugins,...l}}};r(d),console.log(a)}return e.jsxRuntimeExports.jsxs("div",{className:"space-y-2",children:[e.jsxRuntimeExports.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxRuntimeExports.jsx("label",{className:"font-medium",children:"Data Labels"}),!["pyramid"].includes(t)&&e.jsxRuntimeExports.jsx(ts,{})]}),e.jsxRuntimeExports.jsxs(e.Select,{value:(o=(x=(i=s==null?void 0:s.options)==null?void 0:i.plugins)==null?void 0:x.datalabels)==null?void 0:o.anchor,onValueChange:n,defaultValue:"none",children:[e.jsxRuntimeExports.jsx(e.SelectTrigger,{className:"h-8 w-full focus:ring-1 focus:ring-offset-0",children:e.jsxRuntimeExports.jsx(e.SelectValue,{placeholder:"Select position"})}),e.jsxRuntimeExports.jsx(e.SelectContent,{children:e.jsxRuntimeExports.jsxs(e.SelectGroup,{children:[e.jsxRuntimeExports.jsx(e.SelectLabel,{children:"Data Labels"}),e.jsxRuntimeExports.jsx(e.SelectItem,{value:"none",children:"None"}),t!=="pyramid"&&e.jsxRuntimeExports.jsx(e.SelectItem,{value:"start",children:"Start"}),e.jsxRuntimeExports.jsx(e.SelectItem,{value:"center",children:"Center"}),t!=="pyramid"&&e.jsxRuntimeExports.jsx(e.SelectItem,{value:"end",children:"End"})]})})]})]})}function mt({cardType:s}){function r(t){const n="SELECT label, [group], x-axis, y-axis, radius FROM table",i="SELECT label, [group], x-axis, y-axis FROM table";return e.jsxRuntimeExports.jsxs(e.jsxRuntimeExports.Fragment,{children:[e.jsxRuntimeExports.jsx("div",{className:"rounded bg-muted px-2 py-1 text-xs",children:t==="bubble"?n:i}),e.jsxRuntimeExports.jsxs("ul",{className:"ml-6 list-disc text-xs [&>li]:mt-2",children:[e.jsxRuntimeExports.jsx("li",{children:"label - category"}),e.jsxRuntimeExports.jsx("li",{children:"group - category"}),e.jsxRuntimeExports.jsx("li",{children:"x-axis - category"}),e.jsxRuntimeExports.jsx("li",{children:"y-axis - category"}),t==="bubble"&&e.jsxRuntimeExports.jsx("li",{children:"radius - number"})]}),e.jsxRuntimeExports.jsxs("div",{children:["See ",e.jsxRuntimeExports.jsx("a",{target:"_blank",onClick:x=>x.stopPropagation(),className:"text-blue-700",href:"https://docs.semaphor.cloud/concepts/visuals#pie-chart",children:"example"})," in the docs."]})]})}return e.jsxRuntimeExports.jsx("div",{className:"space-y-6 px-6 py-2",children:e.jsxRuntimeExports.jsxs(e.Accordion,{defaultValue:["item-2"],type:"multiple",children:[e.jsxRuntimeExports.jsxs(e.AccordionItem,{value:"item-1",children:[e.jsxRuntimeExports.jsx(e.AccordionTrigger,{children:`${e.titleCase(s)} Chart`}),e.jsxRuntimeExports.jsx(e.AccordionContent,{className:"space-y-4 font-mono text-xs",children:r(s)})]}),e.jsxRuntimeExports.jsxs(e.AccordionItem,{value:"item-2",children:[e.jsxRuntimeExports.jsx(e.AccordionTrigger,{children:"Settings"}),e.jsxRuntimeExports.jsx(e.AccordionContent,{className:"px-2",children:e.jsxRuntimeExports.jsx(De,{})})]}),e.jsxRuntimeExports.jsxs(e.AccordionItem,{value:"item-3",children:[e.jsxRuntimeExports.jsx(e.AccordionTrigger,{children:"Filters"}),e.jsxRuntimeExports.jsxs(e.AccordionContent,{className:"space-y-4 px-2",children:[e.jsxRuntimeExports.jsx(xe,{}),e.jsxRuntimeExports.jsx(ue,{})]})]})]})})}const pt={datasets:[{type:"line",label:"Sum_sales",data:[]},{type:"bar",label:"Sum_profit",data:[]}]},ht={datasets:[{fill:"origin",type:"line",label:"Sum_sales",data:[]}]};function jt(){const s=e.useEditorStore(r=>r.card.type);return e.jsxRuntimeExports.jsxs("div",{className:"space-y-6 p-6",children:[e.jsxRuntimeExports.jsx(e.Accordion,{className:" ",type:"single",collapsible:!0,children:Et(s)}),e.jsxRuntimeExports.jsx("section",{className:"",children:["line","bar"].includes(s)&&e.jsxRuntimeExports.jsx(Re,{})}),!["kpi"].includes(s)&&e.jsxRuntimeExports.jsxs("div",{className:"space-y-4",children:[e.jsxRuntimeExports.jsx(De,{}),e.jsxRuntimeExports.jsx(xe,{}),e.jsxRuntimeExports.jsx(ue,{})]})]})}function Et(s){if(["line","bar"].includes(s))return e.jsxRuntimeExports.jsxs(e.jsxRuntimeExports.Fragment,{children:[e.jsxRuntimeExports.jsxs(e.AccordionItem,{value:"item-1",children:[e.jsxRuntimeExports.jsx(e.AccordionTrigger,{className:"font-normal",children:e.jsxRuntimeExports.jsx("p",{children:"Chart Query"})}),e.jsxRuntimeExports.jsxs(e.AccordionContent,{className:" ",children:[e.jsxRuntimeExports.jsx("div",{className:"rounded bg-muted px-2 py-1 font-mono text-xs font-semibold",children:"SELECT x-axis, y-axis-1, y-axis-2, y-axis-3,... FROM table"}),e.jsxRuntimeExports.jsxs("ul",{className:"my-6 ml-6 list-disc text-xs font-normal [&>li]:mt-2",children:[e.jsxRuntimeExports.jsx("li",{children:"X-axis - Category (ex. city)"}),e.jsxRuntimeExports.jsx("li",{children:"Y-axis - Number (ex. population)"})]})]})]}),e.jsxRuntimeExports.jsxs(e.AccordionItem,{value:"item-2",children:[e.jsxRuntimeExports.jsx(e.AccordionTrigger,{className:"font-normal",children:"Mixed Chart"}),e.jsxRuntimeExports.jsxs(e.AccordionContent,{className:"space-y-2 text-xs",children:[e.jsxRuntimeExports.jsxs("p",{children:["Click ",e.jsxRuntimeExports.jsx("b",{children:"Customize"})," and change the `type` property in the dataset."]}),e.jsxRuntimeExports.jsx("pre",{children:JSON.stringify(pt,null,2)})]})]}),e.jsxRuntimeExports.jsxs(e.AccordionItem,{value:"item-3",children:[e.jsxRuntimeExports.jsx(e.AccordionTrigger,{className:"font-normal",children:"Area Chart"}),e.jsxRuntimeExports.jsxs(e.AccordionContent,{className:"space-y-2 text-xs",children:[e.jsxRuntimeExports.jsxs("p",{children:["Click ",e.jsxRuntimeExports.jsx("b",{children:"Customize"})," and add `fill` property to the dataset. See",e.jsxRuntimeExports.jsx("a",{className:"mx-1 text-blue-500 hover:underline",href:"https://www.chartjs.org/docs/latest/samples/area/line-boundaries.html",target:"_blank",children:"docs"}),"for more options."]}),e.jsxRuntimeExports.jsx("pre",{children:JSON.stringify(ht,null,2)})]})]})]});if(s==="bubble")return e.jsxRuntimeExports.jsx(e.jsxRuntimeExports.Fragment,{children:e.jsxRuntimeExports.jsxs(e.AccordionItem,{value:"item-1",children:[e.jsxRuntimeExports.jsx(e.AccordionTrigger,{className:"font-normal",children:e.jsxRuntimeExports.jsxs("p",{children:["How to create a ",e.jsxRuntimeExports.jsx("span",{children:s})," chart query?"]})}),e.jsxRuntimeExports.jsxs(e.AccordionContent,{className:" ",children:[e.jsxRuntimeExports.jsx("div",{className:"rounded bg-muted px-2 py-1 font-mono text-xs font-semibold",children:"SELECT label, x-axis, y-axis, radius FROM table"}),e.jsxRuntimeExports.jsxs("ul",{className:"my-6 ml-6 list-disc text-xs font-normal [&>li]:mt-2",children:[e.jsxRuntimeExports.jsx("li",{children:"Label - Category (ex. city)"}),e.jsxRuntimeExports.jsx("li",{children:"Bubble Group (opt) - Category (ex. state)"}),e.jsxRuntimeExports.jsx("li",{children:"X-axis - Number (ex. avg. age)"}),e.jsxRuntimeExports.jsx("li",{children:"Y-axis - Number (ex. avg. weight)"}),e.jsxRuntimeExports.jsx("li",{children:"Radius - Number (ex. population)"})]})]})]})});if(s==="scatter")return e.jsxRuntimeExports.jsx(e.jsxRuntimeExports.Fragment,{children:e.jsxRuntimeExports.jsxs(e.AccordionItem,{value:"item-1",children:[e.jsxRuntimeExports.jsx(e.AccordionTrigger,{className:"font-normal",children:e.jsxRuntimeExports.jsxs("p",{children:["How to create a ",e.jsxRuntimeExports.jsx("span",{children:s})," chart query?"]})}),e.jsxRuntimeExports.jsxs(e.AccordionContent,{className:" ",children:[e.jsxRuntimeExports.jsx("div",{className:"rounded bg-muted px-2 py-1 font-mono text-xs font-semibold",children:"SELECT label, x-axis, y-axis FROM table"}),e.jsxRuntimeExports.jsxs("ul",{className:"my-6 ml-6 list-disc text-xs font-normal [&>li]:mt-2",children:[e.jsxRuntimeExports.jsx("li",{children:"Label - Category (ex. city)"}),e.jsxRuntimeExports.jsx("li",{children:"Group (opt) - Category (ex. state)"}),e.jsxRuntimeExports.jsx("li",{children:"X-axis - Number (ex. avg. age)"}),e.jsxRuntimeExports.jsx("li",{children:"Y-axis - Number (ex. avg. weight)"})]})]})]})});if(["pie","doughnut","polarArea"].includes(s))return e.jsxRuntimeExports.jsx(e.jsxRuntimeExports.Fragment,{children:e.jsxRuntimeExports.jsxs(e.AccordionItem,{value:"item-1",children:[e.jsxRuntimeExports.jsx(e.AccordionTrigger,{className:"font-normal",children:e.jsxRuntimeExports.jsxs("p",{children:[e.jsxRuntimeExports.jsx("span",{children:s==="polarArea"?"Polar":s.charAt(0).toUpperCase()+s.slice(1)})," ","chart query"]})}),e.jsxRuntimeExports.jsxs(e.AccordionContent,{className:" ",children:[e.jsxRuntimeExports.jsx("div",{className:"rounded bg-muted px-2 py-1 font-mono text-xs font-semibold",children:"SELECT label, measure FROM table"}),e.jsxRuntimeExports.jsxs("ul",{className:"my-6 ml-6 list-disc text-xs font-normal [&>li]:mt-2",children:[e.jsxRuntimeExports.jsx("li",{children:"Label - Category (ex. city)"}),e.jsxRuntimeExports.jsx("li",{children:"Measure - Number (ex. population)"})]})]})]})})}function ft(){var l,d,u,j,E;const s=e.useEditorStore(c=>c.card.preferences),r=e.useEditorStore(c=>c.actions.setCardPreferences),t=e.useEditorStore(c=>c.actions.setNumberFormat);e.useEditorStore(c=>{var m,R;return(R=(m=c.card.preferences)==null?void 0:m.formatNumber)==null?void 0:R.decimalPlaces});const n=e.useEditorStore(c=>{var m,R;return(R=(m=c.card.preferences)==null?void 0:m.formatNumber)==null?void 0:R.locale}),i=e.useEditorStore(c=>{var m,R;return(R=(m=c.card.preferences)==null?void 0:m.formatNumber)==null?void 0:R.currency});e.useEditorStore(c=>c.actions.setFilterOnClickField);const x=e.useEditorStore(c=>{var m,R;return(R=(m=c.card.preferences)==null?void 0:m.formatNumber)==null?void 0:R.colorRanges})||[],o=e.useEditorStore(c=>c.actions.setColorRanges),a=[...new Set(e.LOCALE_CURRENCY_PAIRS.map(c=>c.currency))];return e.jsxRuntimeExports.jsxs("div",{children:[e.jsxRuntimeExports.jsxs("div",{className:"mb-3 flex items-center gap-2",children:[e.jsxRuntimeExports.jsx(e.Checkbox,{checked:!!((l=s==null?void 0:s.formatNumber)!=null&&l.enabled),onCheckedChange:c=>{r({...s,formatNumber:{...s==null?void 0:s.formatNumber,enabled:c}})}}),e.jsxRuntimeExports.jsx(e.Label,{children:"Format Number"})]}),((d=s==null?void 0:s.formatNumber)==null?void 0:d.enabled)===!0&&e.jsxRuntimeExports.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsxRuntimeExports.jsx("div",{children:e.jsxRuntimeExports.jsxs("div",{className:"space-y-4 p-2",children:[e.jsxRuntimeExports.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxRuntimeExports.jsxs("div",{className:"w-full space-y-1",children:[e.jsxRuntimeExports.jsx(e.Label,{children:"Locale"}),e.jsxRuntimeExports.jsxs(e.Select,{value:n||"en-US",onValueChange:c=>{var m,R,h;return t(((m=s==null?void 0:s.formatNumber)==null?void 0:m.decimalPlaces)||0,((R=s==null?void 0:s.formatNumber)==null?void 0:R.currency)||"",c||"en-US",((h=s==null?void 0:s.formatNumber)==null?void 0:h.suffix)||"")},children:[e.jsxRuntimeExports.jsx(e.SelectTrigger,{className:"col-span-6 h-8 w-full focus:ring-1 focus:ring-offset-0",children:e.jsxRuntimeExports.jsx(e.SelectValue,{})}),e.jsxRuntimeExports.jsx(e.SelectContent,{children:e.jsxRuntimeExports.jsxs(e.SelectGroup,{children:[e.jsxRuntimeExports.jsx(e.SelectLabel,{children:"Format"}),e.LOCALE_CURRENCY_PAIRS.map(c=>e.jsxRuntimeExports.jsx(e.SelectItem,{value:c.locale,children:c.locale},c.locale))]})})]})]}),e.jsxRuntimeExports.jsxs("div",{className:"w-full space-y-1",children:[e.jsxRuntimeExports.jsx(e.Label,{children:"Currency"}),e.jsxRuntimeExports.jsxs(e.Select,{value:i||"none",onValueChange:c=>{var m,R,h;return t(((m=s==null?void 0:s.formatNumber)==null?void 0:m.decimalPlaces)||0,c==="none"?"":c,((R=s==null?void 0:s.formatNumber)==null?void 0:R.locale)||"",((h=s==null?void 0:s.formatNumber)==null?void 0:h.suffix)||"")},children:[e.jsxRuntimeExports.jsx(e.SelectTrigger,{className:"col-span-6 h-8 w-full focus:ring-1 focus:ring-offset-0",children:e.jsxRuntimeExports.jsx(e.SelectValue,{})}),e.jsxRuntimeExports.jsx(e.SelectContent,{children:e.jsxRuntimeExports.jsxs(e.SelectGroup,{children:[e.jsxRuntimeExports.jsx(e.SelectLabel,{children:"Currency"}),e.jsxRuntimeExports.jsx(e.SelectItem,{value:"none",children:"None"},"none"),a.map(c=>e.jsxRuntimeExports.jsx(e.SelectItem,{value:c,children:c},c))]})})]})]})]}),e.jsxRuntimeExports.jsxs("div",{className:"flex gap-2",children:[e.jsxRuntimeExports.jsxs("div",{className:"w-full space-y-1",children:[e.jsxRuntimeExports.jsx(e.Label,{children:"Decimals"}),e.jsxRuntimeExports.jsxs(e.Select,{value:((j=(u=s==null?void 0:s.formatNumber)==null?void 0:u.decimalPlaces)==null?void 0:j.toString())||"0",onValueChange:c=>{var m,R,h;return t(Number(c),((m=s==null?void 0:s.formatNumber)==null?void 0:m.currency)||"",((R=s==null?void 0:s.formatNumber)==null?void 0:R.locale)||"",((h=s==null?void 0:s.formatNumber)==null?void 0:h.suffix)||"")},children:[e.jsxRuntimeExports.jsx(e.SelectTrigger,{className:"col-span-3 h-8 w-full focus:ring-1 focus:ring-offset-0",children:e.jsxRuntimeExports.jsx(e.SelectValue,{})}),e.jsxRuntimeExports.jsx(e.SelectContent,{children:["0","1","2","3","4"].map(c=>e.jsxRuntimeExports.jsx(e.SelectItem,{value:c,children:c},c))})]})]}),e.jsxRuntimeExports.jsxs("div",{className:"w-full space-y-1",children:[e.jsxRuntimeExports.jsx(e.Label,{children:"Suffix"}),e.jsxRuntimeExports.jsx(e.Input,{value:((E=s==null?void 0:s.formatNumber)==null?void 0:E.suffix)||"",className:"h-8 font-mono text-xs focus-visible:ring-0 focus-visible:ring-ring focus-visible:ring-offset-0",placeholder:"K, M, B, %",onChange:c=>{var m,R,h;return t(((m=s==null?void 0:s.formatNumber)==null?void 0:m.decimalPlaces)||0,((R=s==null?void 0:s.formatNumber)==null?void 0:R.currency)||"",((h=s==null?void 0:s.formatNumber)==null?void 0:h.locale)||"",c.target.value)}})]})]})]})}),e.jsxRuntimeExports.jsx(e.Separator,{className:"my-3"}),e.jsxRuntimeExports.jsx(e.ColorFormat,{colorRanges:x,setColorRanges:o})]})]})}function gt(){return e.jsxRuntimeExports.jsxs("div",{className:"space-y-6 px-6 py-2",children:[e.jsxRuntimeExports.jsx(e.Accordion,{type:"single",collapsible:!0,children:e.jsxRuntimeExports.jsxs(e.AccordionItem,{value:"item-1",children:[e.jsxRuntimeExports.jsx(e.AccordionTrigger,{className:"",children:"KPI Query"}),e.jsxRuntimeExports.jsxs(e.AccordionContent,{className:"font-mono",children:[e.jsxRuntimeExports.jsx("div",{className:"rounded bg-muted px-2 py-1 font-mono text-xs",children:"SELECT current, previous FROM table"}),e.jsxRuntimeExports.jsxs("ul",{className:"my-6 ml-6 list-disc text-xs [&>li]:mt-2",children:[e.jsxRuntimeExports.jsx("li",{children:"current - number"}),e.jsxRuntimeExports.jsx("li",{children:"previous - number"})]}),e.jsxRuntimeExports.jsxs("div",{children:["See ",e.jsxRuntimeExports.jsx("a",{target:"_blank",onClick:s=>s.stopPropagation(),className:"text-blue-700",href:"https://docs.semaphor.cloud/concepts/visuals#kpi",children:"example"})," in the docs."]})]})]})}),e.jsxRuntimeExports.jsx("section",{className:"",children:e.jsxRuntimeExports.jsx(ft,{})}),e.jsxRuntimeExports.jsx("div",{}),e.jsxRuntimeExports.jsx("div",{})]})}function Rt(){var n;const s=e.useEditorStore(i=>i.card.preferences),{setCardPreferences:r}=e.useEditorStore(i=>i.actions);function t(i){r({...s,textVisualOptions:{...s==null?void 0:s.textVisualOptions,isDynamicText:i==="dynamic"}})}return e.jsxRuntimeExports.jsxs(e.RadioGroup,{value:(n=s==null?void 0:s.textVisualOptions)!=null&&n.isDynamicText?"dynamic":"static",onValueChange:t,className:"flex gap-3",defaultValue:"x",children:[e.jsxRuntimeExports.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsxRuntimeExports.jsx(e.RadioGroupItem,{value:"static",id:"r1"}),e.jsxRuntimeExports.jsx("label",{className:"text-sm",htmlFor:"r1",children:"Static"})]}),e.jsxRuntimeExports.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsxRuntimeExports.jsx(e.RadioGroupItem,{value:"dynamic",id:"r2"}),e.jsxRuntimeExports.jsx("label",{className:"text-sm",htmlFor:"r2",children:"Dynamic"})]})]})}function Ee({cardType:s,docContent:r,suffix:t="Chart"}){return e.jsxRuntimeExports.jsx("div",{className:"space-y-6 px-6 py-2",children:e.jsxRuntimeExports.jsxs(e.Accordion,{defaultValue:["item-2"],type:"multiple",children:[e.jsxRuntimeExports.jsxs(e.AccordionItem,{value:"item-1",children:[e.jsxRuntimeExports.jsx(e.AccordionTrigger,{children:`${e.titleCase(s)} ${t}`}),e.jsxRuntimeExports.jsx(e.AccordionContent,{children:r||e.jsxRuntimeExports.jsxs("div",{className:"space-y-4 font-mono text-xs",children:[e.jsxRuntimeExports.jsx("div",{className:"rounded bg-muted px-2 py-1 text-xs",children:"SELECT label, measure FROM table"}),e.jsxRuntimeExports.jsxs("ul",{className:"ml-6 list-disc text-xs [&>li]:mt-2",children:[e.jsxRuntimeExports.jsx("li",{children:"label - category"}),e.jsxRuntimeExports.jsx("li",{children:"measure - number"})]}),e.jsxRuntimeExports.jsxs("div",{children:["See ",e.jsxRuntimeExports.jsx("a",{target:"_blank",onClick:n=>n.stopPropagation(),className:"text-blue-700",href:"https://docs.semaphor.cloud/concepts/visuals#pie-chart",children:"example"})," in the docs."]})]})})]}),e.jsxRuntimeExports.jsxs(e.AccordionItem,{value:"item-2",children:[e.jsxRuntimeExports.jsx(e.AccordionTrigger,{children:"Settings"}),e.jsxRuntimeExports.jsxs(e.AccordionContent,{className:"space-y-4 px-2",children:[s==="range"&&e.jsxRuntimeExports.jsx(Re,{}),s!=="text"&&e.jsxRuntimeExports.jsx(De,{}),s==="text"&&e.jsxRuntimeExports.jsx(Rt,{})]})]}),!["range","text"].includes(s)&&e.jsxRuntimeExports.jsxs(e.AccordionItem,{value:"item-3",children:[e.jsxRuntimeExports.jsx(e.AccordionTrigger,{children:"Filters"}),e.jsxRuntimeExports.jsxs(e.AccordionContent,{className:"space-y-4 px-2",children:[e.jsxRuntimeExports.jsx(xe,{}),e.jsxRuntimeExports.jsx(ue,{})]})]})]})})}function bt(){return e.jsxRuntimeExports.jsx("div",{className:"space-y-6 px-6 py-2",children:e.jsxRuntimeExports.jsxs(e.Accordion,{defaultValue:["item-2"],type:"multiple",children:[e.jsxRuntimeExports.jsxs(e.AccordionItem,{value:"item-1",children:[e.jsxRuntimeExports.jsx(e.AccordionTrigger,{children:"Stacked Chart"}),e.jsxRuntimeExports.jsxs(e.AccordionContent,{className:"space-y-4 font-mono text-xs",children:[e.jsxRuntimeExports.jsx("div",{className:"rounded bg-muted px-2 py-1 text-xs",children:"SELECT x-axis, stack-by, y-axis FROM table"}),e.jsxRuntimeExports.jsxs("ul",{className:"ml-6 list-disc text-xs [&>li]:mt-2",children:[e.jsxRuntimeExports.jsx("li",{children:"x-axis - category"}),e.jsxRuntimeExports.jsx("li",{children:"stack by - category"}),e.jsxRuntimeExports.jsx("li",{children:"y-axis - number"})]}),e.jsxRuntimeExports.jsxs("div",{children:["See ",e.jsxRuntimeExports.jsx("a",{target:"_blank",onClick:s=>s.stopPropagation(),className:"text-blue-700",href:"https://docs.semaphor.cloud/concepts/visuals#stacked-chart",children:"example"})," in the docs."]})]})]}),e.jsxRuntimeExports.jsxs(e.AccordionItem,{value:"item-2",children:[e.jsxRuntimeExports.jsx(e.AccordionTrigger,{children:"Settings"}),e.jsxRuntimeExports.jsxs(e.AccordionContent,{className:"space-y-4 px-2",children:[e.jsxRuntimeExports.jsx(Re,{}),e.jsxRuntimeExports.jsx(ns,{})]})]}),e.jsxRuntimeExports.jsxs(e.AccordionItem,{value:"item-3",children:[e.jsxRuntimeExports.jsx(e.AccordionTrigger,{children:"Filters"}),e.jsxRuntimeExports.jsxs(e.AccordionContent,{className:"space-y-4 px-2",children:[e.jsxRuntimeExports.jsx(xe,{}),e.jsxRuntimeExports.jsx(ue,{})]})]})]})})}function St({}){const s=e.useEditorStore(n=>{var i;return(i=n.card)==null?void 0:i.preferences}),r=e.useEditorStore(n=>n.actions.setCardPreferences),t=n=>{r({...s,allowDownload:n})};return e.jsxRuntimeExports.jsxs("div",{className:"space-y-6 px-6 py-2",children:[e.jsxRuntimeExports.jsx(e.Accordion,{defaultValue:["item-3"],type:"multiple",children:e.jsxRuntimeExports.jsxs(e.AccordionItem,{value:"item-3",children:[e.jsxRuntimeExports.jsx(e.AccordionTrigger,{children:"Filters"}),e.jsxRuntimeExports.jsxs(e.AccordionContent,{className:"space-y-4 px-2",children:[e.jsxRuntimeExports.jsx(xe,{}),e.jsxRuntimeExports.jsx(ue,{})]})]})}),e.jsxRuntimeExports.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsxRuntimeExports.jsx(e.Checkbox,{onCheckedChange:t,id:"allow-download"}),e.jsxRuntimeExports.jsx("label",{htmlFor:"allow-download",className:"text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70",children:"Allow Download"})]})]})}const yt=e.jsxRuntimeExports.jsxs("div",{className:"space-y-4 font-mono text-xs",children:[e.jsxRuntimeExports.jsx("div",{className:"rounded bg-muted px-2 py-1 text-xs",children:"SELECT dimension, cohort, metric FROM table"}),e.jsxRuntimeExports.jsxs("div",{children:["See ",e.jsxRuntimeExports.jsx("a",{target:"_blank",onClick:s=>s.stopPropagation(),className:"text-blue-700",href:"https://docs.semaphor.cloud/concepts/visuals#pyramid-chart",children:"example"})," in the docs."]})]}),vt=e.jsxRuntimeExports.jsxs("div",{className:"space-y-4 font-mono text-xs",children:[e.jsxRuntimeExports.jsx("div",{className:"rounded bg-muted px-2 py-1 text-xs",children:"SELECT y-axis, label, range-from, range-to, range-value FROM table"}),e.jsxRuntimeExports.jsxs("div",{children:["See ",e.jsxRuntimeExports.jsx("a",{target:"_blank",onClick:s=>s.stopPropagation(),className:"text-blue-700",href:"https://docs.semaphor.cloud/concepts/visuals#range-charts",children:"example"})," in the docs."]})]}),Ct=e.jsxRuntimeExports.jsxs("div",{className:"space-y-4 font-mono text-xs",children:[e.jsxRuntimeExports.jsx("div",{className:"rounded bg-muted px-2 py-1 text-xs",children:"SELECT text FROM table limit 1"}),e.jsxRuntimeExports.jsxs("div",{children:["See ",e.jsxRuntimeExports.jsx("a",{target:"_blank",onClick:s=>s.stopPropagation(),className:"text-blue-700",href:"https://docs.semaphor.cloud/concepts/visuals#text-visual",children:"example"})," in the docs."]})]});function Nt(){const s=e.useEditorStore(t=>t.card.type);function r(t){switch(t){case"stackedBar":case"stackedLine":return e.jsxRuntimeExports.jsx(bt,{});case"pyramid":return e.jsxRuntimeExports.jsx(Ee,{docContent:yt,cardType:t});case"kpi":return e.jsxRuntimeExports.jsx(gt,{});case"line":case"bar":return e.jsxRuntimeExports.jsx(dt,{cardType:t});case"range":return e.jsxRuntimeExports.jsx(Ee,{docContent:vt,cardType:t});case"pie":case"doughnut":case"polarArea":case"radar":return e.jsxRuntimeExports.jsx(Ee,{cardType:t});case"bubble":case"scatter":return e.jsxRuntimeExports.jsx(mt,{cardType:t});case"table":return e.jsxRuntimeExports.jsx(St,{cardType:t});case"text":return e.jsxRuntimeExports.jsx(Ee,{docContent:Ct,cardType:t,suffix:"Visual"});default:return e.jsxRuntimeExports.jsx(jt,{})}}return e.jsxRuntimeExports.jsx(e.ScrollArea,{className:"h-full w-full text-sm",children:r(s)})}function wt(){const s=e.useEditorStore(r=>r.isShowingVisual);return e.jsxRuntimeExports.jsxs(e.ResizablePanelGroup,{direction:"vertical",className:"min-h-[250px] min-w-full max-w-lg",children:[e.jsxRuntimeExports.jsx(e.ResizablePanel,{role:"query-section",className:"flex",minSize:20,defaultSize:40,children:e.jsxRuntimeExports.jsx(tt,{})}),e.jsxRuntimeExports.jsx(e.ResizableHandle,{withHandle:!0,className:"border"}),e.jsxRuntimeExports.jsx(e.ResizablePanel,{className:"pb-1",role:"visual-section",minSize:0,defaultSize:60,children:s?e.jsxRuntimeExports.jsxs(e.ResizablePanelGroup,{direction:"horizontal",children:[e.jsxRuntimeExports.jsx(e.jsxRuntimeExports.Fragment,{children:e.jsxRuntimeExports.jsx(e.ResizablePanel,{className:"flex min-w-[275px]",minSize:20,defaultSize:25,maxSize:30,children:e.jsxRuntimeExports.jsx(Nt,{})})}),e.jsxRuntimeExports.jsx(e.ResizableHandle,{className:"border"}),e.jsxRuntimeExports.jsx(e.ResizablePanel,{minSize:40,defaultSize:75,maxSize:100,children:e.jsxRuntimeExports.jsx(Me,{})})]}):e.jsxRuntimeExports.jsx(Me,{})})]})}function kt({authToken:s,onSave:r,onClose:t}){const n=e.useEditorStore(o=>o.actions.setOnSave),i=e.useEditorStore(o=>o.actions.setOnClose),x=e.useDashboardStore(o=>o.actions.setAuthToken);return S.useEffect(()=>{r&&n(r),t&&i(t)},[r,n,t,i]),S.useEffect(()=>{s&&s.accessToken&&x(s)},[s,x]),e.jsxRuntimeExports.jsxs(e.EditorPanel,{className:"rounded-none",role:"editor-panel",children:[e.jsxRuntimeExports.jsx(e.EditorAside,{className:"rounded-none border-r-[1.5px]",children:e.jsxRuntimeExports.jsx($e,{})}),e.jsxRuntimeExports.jsx(e.EditorMain,{children:e.jsxRuntimeExports.jsx(wt,{})})]})}function Lt(){e.useDashboardStore(o=>o.selectedCardId);const s=e.useDashboardStore(o=>o.selectedSheetId),{setIsVisualEditing:r}=e.useDashboardStore(o=>o.actions),t=e.useDashboardStore(o=>o.isVisualEditing),n=e.useDashboardStore(o=>o.actions.updateFrame);function i(o){s&&(n(s,o),r(!1))}function x(){r(!1)}return e.jsxRuntimeExports.jsx("div",{role:"editor-container",className:e.cn("flex grow",{block:t,hidden:!t}),children:e.jsxRuntimeExports.jsx(kt,{onSave:i,onClose:x})})}function Dt(){e.useEditorStore(o=>o.selectedConnectionId),e.useEditorStore(o=>o.selectedDatamodelId);const s=e.useEditorStore(o=>o.selectedDatabaseName);e.useEditorStore(o=>o.selectedSchemaName);const r=e.useEditorStore(o=>o.selectedTableName),t=e.useDashboardStore(o=>o.dashboard.filters)||[];e.useDashboardStore(o=>o.actions.addFilter),e.useDashboardStore(o=>o.actions.removeFilter),e.useDashboardStore(o=>o.actions.removeFilterValue);const{modelItems:n,columns:i}=oe(),{assignFilter:x}=rs();return e.jsxRuntimeExports.jsx("div",{className:"xbg-red-100 flex-1 basis-0 flex-col overflow-scroll px-3",children:i==null?void 0:i.map(o=>{const a=t==null?void 0:t.find(l=>l.column===e.fmt(o.column_name)&&l.table===r&&l.database===s);return e.jsxRuntimeExports.jsx("div",{onClick:()=>x(o),className:e.cn("group flex cursor-pointer items-center justify-between border border-dashed border-background px-3 py-[6px] text-sm transition-colors hover:bg-muted/50",{"bg-muted":a}),children:e.jsxRuntimeExports.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxRuntimeExports.jsx(Pe,{column:o}),e.jsxRuntimeExports.jsx("span",{children:o.column_name})]})},o.column_name)})})}function At(){e.useDashboardStore(r=>r.showFilters);const s=e.useDashboardStore(r=>r.actions.setShowFilters);return e.jsxRuntimeExports.jsxs("section",{className:"relative flex grow flex-col border-l px-4",children:[e.jsxRuntimeExports.jsxs("div",{className:"mt-4 flex items-center justify-between gap-2 px-3",children:[e.jsxRuntimeExports.jsx(e.Label,{className:"text-lg",children:"Filters"}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>s(!1),className:"h-7 w-7 p-0",variant:"ghost",children:e.jsxRuntimeExports.jsx(e.Cross2Icon,{})})]}),e.jsxRuntimeExports.jsx("div",{className:"flex grow",children:e.jsxRuntimeExports.jsx($e,{ColumnsComponent:()=>e.jsxRuntimeExports.jsx(Dt,{})})})]})}function It(){const s=e.useDashboardStore(t=>t.showFilters),r=e.useDashboardStore(t=>t.isVisualEditing);return e.jsxRuntimeExports.jsxs("div",{role:"dashboard-plus-main",className:e.cn("grow",{hidden:r,flex:!r}),children:[e.jsxRuntimeExports.jsx(e.DashboardTabs,{}),s&&e.jsxRuntimeExports.jsx("div",{role:"filter-aside-container",className:"flex",children:e.jsxRuntimeExports.jsx(At,{})})]})}function Tt(){const s=e.useDashboardStore(n=>n.dashboard),r=e.useDashboardStore(n=>n.actions.setDashboard),t=e.useDashboardStore(n=>n.showDashboardJSON);return e.useDashboardStore(n=>n.actions.setShowDashboardJSON),e.jsxRuntimeExports.jsx("div",{className:e.cn(" p-2",{hidden:!t}),children:e.jsxRuntimeExports.jsx(e.de,{onChange:n=>{if(n)try{JSON.parse(n),r(JSON.parse(n))}catch{}},defaultLanguage:"json",className:"h-[550px] overflow-y-auto ",value:JSON.stringify(s,null,2),options:{minimap:{enabled:!1},glyphMargin:!1,wordWrap:"on",scrollbar:{verticalScrollbarSize:0,horizontalScrollbarSize:0},fontSize:12,renderLineHighlight:"none"}})})}function zt({showControls:s=!1,showFooter:r=!0,...t}){return e.jsxRuntimeExports.jsxs(e.SemaphorContextProvider,{dashboardProps:t,children:[e.jsxRuntimeExports.jsx(e.Te,{}),e.jsxRuntimeExports.jsxs(e.UXProvider,{children:[e.jsxRuntimeExports.jsx(Tt,{}),e.jsxRuntimeExports.jsxs(e.DashboardPanel,{...t,children:[s&&e.jsxRuntimeExports.jsx(qs,{}),e.jsxRuntimeExports.jsx(Lt,{}),e.jsxRuntimeExports.jsx(It,{})]})]})]})}exports.DashboardPlus=zt;exports.LoaderCircle=ce;exports.SelectComponent=le;exports.cleanCard=He;exports.getDashbaordStateWithoutData=Le;exports.useEditorAside=oe;