react-semaphor 0.0.181 → 0.0.183

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-kwpsiaJa.js"),g=require("react");/**
1
+ "use strict";const e=require("./index-O9LcZUoj.js"),g=require("react");/**
2
2
  * @license lucide-react v0.379.0 - ISC
3
3
  *
4
4
  * This source code is licensed under the ISC license.
@@ -148,7 +148,7 @@
148
148
  *
149
149
  * This source code is licensed under the ISC license.
150
150
  * See the LICENSE file in the root directory of this source tree.
151
- */const zs=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 Is(){const[s,n]=g.useState(""),[t,r]=g.useState(!1),[a,i]=g.useState(!1),o=e.useDashboardStore(c=>c.dashboard);function l(){const c=e.getDashbaordStateWithoutData(o),h=e.getBookmarkKey(o.id),u=JSON.parse(localStorage.getItem(h)||"[]");if(u.some(y=>y.name===s)){r(!0);return}u.push({name:s,template:c}),localStorage.setItem(h,JSON.stringify(u)),i(!1)}return e.jsxRuntimeExports.jsxs(e.Dialog,{open:a,onOpenChange:i,children:[e.jsxRuntimeExports.jsx(e.DialogTrigger,{asChild:!0,children:e.jsxRuntimeExports.jsxs(e.Button,{variant:"outline",className:"h-7 p-2",size:"sm",children:[e.jsxRuntimeExports.jsx(e.Plus,{className:" mr-2 h-4 w-4",strokeWidth:1.5}),"Add Lens"]})}),e.jsxRuntimeExports.jsxs(e.DialogContent,{className:"sm:max-w-[425px]",children:[e.jsxRuntimeExports.jsxs(e.DialogHeader,{children:[e.jsxRuntimeExports.jsx(e.DialogTitle,{children:"Add a 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:c=>{t&&r(!1),n(c.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 bookmark name already exists. Use a differnet name."}),e.jsxRuntimeExports.jsx(e.DialogFooter,{children:e.jsxRuntimeExports.jsx(e.Button,{variant:"outline",type:"submit",disabled:!s,onClick:l,children:"Save"})})]})]})}function Ds(){const[s,n]=g.useState(!1),[t,r]=g.useState(""),a=e.useDashboardStore(x=>x.dashboard),i=e.useDashboardStore(x=>x.bookmarkKey),[o,l]=g.useState([]),c=e.useDashboardStore(x=>x.actions.setDashboard),h=e.useDashboardStore(x=>x.actions.setFilterValues),u=e.useDashboardStore(x=>x.actions.setBookmarkKey);g.useEffect(()=>{const x=e.getBookmarkKey(a.id),m=JSON.parse(localStorage.getItem(x)||"[]");l(m);const j=m.find(E=>E.default);j&&j.name===i&&r(j.name)},[s,a,i]);function d(x){if(x===t)return;const m=o.find(E=>E.name===x),j=m==null?void 0:m.template;j&&(c(j),h(m.filterValues||[]),u(x==="Original"?"":x)),r(x)}function y(x){const m=e.getBookmarkKey(a.id),E=JSON.parse(localStorage.getItem(m)||"[]").filter(f=>f.name!==x);localStorage.setItem(m,JSON.stringify(E)),l(E)}return e.jsxRuntimeExports.jsxs(e.DropdownMenu,{open:s,onOpenChange:n,children:[e.jsxRuntimeExports.jsx(e.DropdownMenuTrigger,{asChild:!0,children:e.jsxRuntimeExports.jsx(e.Button,{variant:"outline",className:"h-7 p-2",children:e.jsxRuntimeExports.jsx(ms,{className:"h-4 w-4",strokeWidth:1.5})})}),e.jsxRuntimeExports.jsxs(e.DropdownMenuContent,{className:"w-56",children:[e.jsxRuntimeExports.jsx(e.DropdownMenuLabel,{children:"Lenses"}),e.jsxRuntimeExports.jsx(e.DropdownMenuSeparator,{}),e.jsxRuntimeExports.jsxs(e.DropdownMenuRadioGroup,{value:t,onValueChange:d,children:[e.jsxRuntimeExports.jsx(e.DropdownMenuRadioItem,{value:"Original",children:"Original"}),o.filter(x=>x.name!="Original").map((x,m)=>e.jsxRuntimeExports.jsxs(e.DropdownMenuRadioItem,{className:"xbg-red-100 flex justify-between",value:x.name,defaultChecked:x.name===i,children:[e.jsxRuntimeExports.jsx("p",{children:x.name}),e.jsxRuntimeExports.jsx(e.Cross2Icon,{onClick:j=>{j.preventDefault(),y(x.name)},className:"h-3 w-3 hover:cursor-pointer",strokeWidth:1.5})]},m))]})]})]})}function Ls(){const[s,n]=g.useState(!1),t=e.useDashboardStore(i=>i.dashboard),r=e.useDashboardStore(i=>i.bookmarkKey);g.useEffect(()=>{if(!r){n(!1);return}const i=e.getBookmarkKey(t.id),l=JSON.parse(localStorage.getItem(i)||"[]").find(c=>c.name===r);n(l?l.default:!1)},[r,t.id]);function a(i){if(n(i),!r)return;const o=e.getBookmarkKey(t.id),c=JSON.parse(localStorage.getItem(o)||"[]").map(h=>(h.name===r?h.default=i:h.default=!1,h));console.log(c),localStorage.setItem(o,JSON.stringify(c))}return e.jsxRuntimeExports.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsxRuntimeExports.jsx(e.Checkbox,{checked:s,onCheckedChange:a,id:"terms"}),e.jsxRuntimeExports.jsx("label",{htmlFor:"terms",className:"text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70",children:"Set as default"})]})}function Fs(){const s=e.useDashboardStore(f=>f.bookmarkKey),n=e.useDashboardStore(f=>f.dashboard);e.useDashboardStore(f=>f.selectedSheetId);const t=e.useDashboardStore(f=>f.isDashboardEditing),r=e.useDashboardStore(f=>f.filterValues),a=e.useDashboardStore(f=>f.isVisualEditing),i=e.useDashboardStore(f=>f.showFilters);e.useDashboardStore(f=>f.showDashboardJSON);const o=e.useDashboardStore(f=>f.onSaveFunction),l=e.useDashboardStore(f=>f.actions.setShowFilters),{addFrame:c,setSelectedFrameId:h}=e.useDashboardStore(f=>f.actions),{getSelectedSheet:u,setIsDashboardEditing:d,setShowDashboardJSON:y}=e.useDashboardStore(f=>f.actions),x=u(),m=()=>{if(!t||!x)return;const f={id:e.v4(),title:"Title",description:"Description",preferences:{onClickFilter:[{columnIndex:0,expression:""}]},type:"bar",sql:"select COUNT(*) from YOUR_TABLE",data:[]},T={id:e.v4(),cards:[f],activeCardId:f.id};c(x.id,T),h(T.id)},j=()=>{d(!0)};function E(){if(!s||s==="")return;const f=e.getDashbaordStateWithoutData(n),T=e.getBookmarkKey(n.id),w=JSON.parse(localStorage.getItem(T)||"[]"),k=w.findIndex(R=>R.name===s);k!==-1?w[k]={name:s,template:f,default:w[k].default,filterValues:r}:w.push({name:s,template:f,filterValues:r}),localStorage.setItem(T,JSON.stringify(w)),o==null||o(f)}return a?null:e.jsxRuntimeExports.jsxs("div",{className:"flex items-center justify-between gap-2 border-b bg-muted/50 px-2 py-2",role:"dashboard-controls",children:[!a&&e.jsxRuntimeExports.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxRuntimeExports.jsx(e.Label,{children:s}),!!s&&e.jsxRuntimeExports.jsxs(e.jsxRuntimeExports.Fragment,{children:[e.jsxRuntimeExports.jsx("span",{className:"text-muted-foreground",children:"|"}),e.jsxRuntimeExports.jsx(Ls,{})]})]}),e.jsxRuntimeExports.jsxs("div",{className:"flex gap-2",children:[t&&!a&&e.jsxRuntimeExports.jsx(Is,{}),!a&&e.jsxRuntimeExports.jsx(Ds,{}),t&&!a&&e.jsxRuntimeExports.jsxs(e.Button,{variant:"outline",className:"h-7 p-2",size:"sm",disabled:!t,onClick:m,children:[e.jsxRuntimeExports.jsx(e.Plus,{className:"mr-2 h-4 w-4",strokeWidth:1.5}),"Add Frame"]}),!t&&e.jsxRuntimeExports.jsx(e.Button,{variant:"outline",className:"h-7 p-2",onClick:j,size:"sm",children:e.jsxRuntimeExports.jsx(Oe,{className:"h-4 w-4",strokeWidth:1.5})}),t&&!a&&e.jsxRuntimeExports.jsx(e.Button,{variant:"outline",role:"close",className:"h-7 p-2",onClick:()=>{d(!1),y(!1)},size:"sm",children:e.jsxRuntimeExports.jsx(e.Cross2Icon,{className:"h-4 w-4",strokeWidth:1.5})}),t&&!a&&e.jsxRuntimeExports.jsx(e.Button,{className:"h-7 p-2",variant:"outline",onClick:E,size:"sm",children:e.jsxRuntimeExports.jsx(vs,{className:"h-4 w-4",strokeWidth:1.5})}),!i&&!a&&t&&e.jsxRuntimeExports.jsx(e.Button,{className:"h-7 p-2",variant:"outline",onClick:()=>l(!0),size:"sm",children:e.jsxRuntimeExports.jsx(Fe,{className:"h-4 w-4",strokeWidth:1.5})}),!a&&t&&!1,!a&&!1]})]})}function he({title:s,items:n,value:t,isLoading:r,isError:a,connectionTooltip:i,onChange:o,className:l,showIcon:c=!0,disabled:h=!1}){const u=r?"Loading...":a?"Error":t;function d(){if(s==="Connection")return e.jsxRuntimeExports.jsx(ys,{className:"size-4 rotate-90"});if(s==="Database")return e.jsxRuntimeExports.jsx(us,{className:"size-4"});if(s==="Schema")return e.jsxRuntimeExports.jsx(bs,{className:"size-4"});if(s==="Table")return e.jsxRuntimeExports.jsx(e.Table,{className:"size-4"})}return e.jsxRuntimeExports.jsxs("div",{className:"flex items-center gap-2",children:[c&&e.jsxRuntimeExports.jsx("div",{className:"shrink-0",children:i?e.jsxRuntimeExports.jsxs(e.Tooltip,{children:[e.jsxRuntimeExports.jsx(e.TooltipTrigger,{children:d()}),e.jsxRuntimeExports.jsx(e.TooltipContent,{className:"text-xs",align:"start",children:i})]}):d()}),e.jsxRuntimeExports.jsxs(e.Select,{disabled:h,value:u,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:r?"Loading...":a?"Error":`Select ${s}`})}),e.jsxRuntimeExports.jsx(e.SelectContent,{children:e.jsxRuntimeExports.jsxs(e.SelectGroup,{children:[r?e.jsxRuntimeExports.jsx(e.SelectLabel,{children:"Loading..."}):e.jsxRuntimeExports.jsx(e.SelectLabel,{children:s}),e.jsxRuntimeExports.jsx(e.jsxRuntimeExports.Fragment,{children:n&&n.map((y,x)=>e.jsxRuntimeExports.jsx(e.SelectItem,{value:y.id,children:y.name},x))}),(r||a)&&e.jsxRuntimeExports.jsx(e.SelectItem,{value:u,children:u})]})})]})]})}function Os({column:s}){const[n,t]=g.useState(!1),r=e.useEditorStore(u=>u.selectedTableName),a=e.useEditorStore(u=>u.selectedSchemaName),i=e.useEditorStore(u=>u.sqlGen),o=e.useEditorStore(u=>u.actions.setSqlGen),l=e.useEditorStore(u=>u.actions.setCardSql),c=e.useEditorStore(u=>u.actions.setRunSql);function h(u,d){const y=e.createSqlGenConfig(u,i,d);o(y);const x=e.getSql(y,e.fmt(a||""),e.fmt(r));x&&(l(x),c(!0)),t(!1)}return e.jsxRuntimeExports.jsxs(e.Popover,{open:n,onOpenChange:t,children:[e.jsxRuntimeExports.jsx(e.PopoverTrigger,{asChild:!0,children:e.jsxRuntimeExports.jsx(e.ChevronDown,{className:"h-4 w-4 cursor-pointer text-foreground/40"})}),e.jsxRuntimeExports.jsx(e.PopoverContent,{align:"center",className:"w-18 rounded-md p-0 shadow-none",children:e.jsxRuntimeExports.jsxs("ul",{className:"text-xs",children:[e.jsxRuntimeExports.jsx("li",{onClick:()=>h(s,"COUNT"),className:"cursor-pointer p-1 px-3 transition-colors hover:bg-muted",children:"Count"}),e.jsxRuntimeExports.jsx("li",{onClick:()=>h(s,"AVG"),className:"cursor-pointer p-1 px-3 transition-colors hover:bg-muted",children:"Avg"}),e.jsxRuntimeExports.jsx("li",{onClick:()=>h(s,"SUM"),className:"cursor-pointer p-1 px-3 transition-colors hover:bg-muted",children:"Sum"}),e.jsxRuntimeExports.jsx("li",{onClick:()=>h(s,"MAX"),className:"cursor-pointer p-1 px-3 transition-colors hover:bg-muted",children:"Max"}),e.jsxRuntimeExports.jsx("li",{onClick:()=>h(s,"MIN"),className:"cursor-pointer p-1 px-3 transition-colors hover:bg-muted",children:"Min"})]})})]})}function qe({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(Ts,{className:"size-3"}):e.NUMBER_DATA_TYPES.includes(s.data_type.toLowerCase())?e.jsxRuntimeExports.jsx(hs,{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(Cs,{className:"size-3"})}),e.jsxRuntimeExports.jsx(e.TooltipContent,{children:e.jsxRuntimeExports.jsx("p",{className:"font-mono text-xs",children:s.data_type})})]})}function Ms({schemaName:s,tableName:n,columns:t,status:r}){const a=e.useEditorStore(R=>R.sqlGen),i=e.useEditorStore(R=>R.selectedConnectionId),o=e.useEditorStore(R=>R.selectedDatabaseName),l=e.useEditorStore(R=>R.selectedSchemaName),c=e.useEditorStore(R=>R.selectedTableName),h=e.useDashboardStore(R=>R.dashboard.aiScopeTables),{setAIScopeTables:u}=e.useDashboardStore(R=>R.actions),d=e.useEditorStore(R=>R.actions.setRunSql),y=e.useEditorStore(R=>R.actions.setSqlGen),x=e.useEditorStore(R=>R.actions.setIsShowingVisual),m=e.useEditorStore(R=>R.actions.setCardSql),{connectionType:j}=Ce();function E(R){const C=e.createSqlGenConfig(R,a);y(C);const A=e.getSql(C,e.fmt(s),e.fmt(n));A&&(m(A),d(!0))}function f(){return(h==null?void 0:h.find(R=>R.connectinonId===i&&R.tableName===c))!==void 0}function T(R){if(R===!0&&c&&i){const C={connectinonId:i,connectionType:j,databaseName:o,schemaName:l,tableName:c},D=[...h||[],C].filter((_,F,O)=>O.findIndex(z=>z.connectinonId===_.connectinonId&&z.tableName===_.tableName)===F);u(D),e.Jt.success(`Added '${c}' to AI Scope`,{position:"top-right",duration:2500,richColors:!0})}else{const C=(h||[]).filter(A=>A.connectinonId!==i&&A.tableName!==c);u(C),e.Jt(`Removed '${c}' from AI Scope`,{position:"top-right",duration:2e3,richColors:!0})}}function w(){let C=e.getQualifiedTableName(s,n);(D=>D.charAt(0)===D.charAt(0).toUpperCase())(n)&&(C=`"${n}"`),x(!1),m(`SELECT * FROM ${C} LIMIT 10`),d(!0)}function k(){let C=e.getQualifiedTableName(s,n);(D=>D.charAt(0)===D.charAt(0).toUpperCase())(n)&&(C=`"${n}"`),x(!1),m(`SELECT COUNT(*) FROM ${C}`),d(!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:`${f()?"Remove from":"Add to"} AI Scope`,pressed:f(),onPressedChange:T,variant:"outline",className:"h-9 px-2",children:e.jsxRuntimeExports.jsx(e.Bot,{className:e.cn("size-4",{"text-primary":f(),"text-muted-foreground":!f()})})}),e.jsxRuntimeExports.jsxs(e.Button,{disabled:r!=="Success",onClick:w,size:"sm",variant:"secondary",className:"flex",children:[r!=="Success"?e.jsxRuntimeExports.jsx(e.LoaderCircle,{className:"mr-2 h-4 w-4 animate-spin text-foreground/50"}):e.jsxRuntimeExports.jsx(ks,{className:"mr-2 size-4"}),"Top 10"]}),e.jsxRuntimeExports.jsxs(e.Button,{disabled:r!=="Success",onClick:k,size:"sm",variant:"secondary",className:"flex",children:[r!=="Success"?e.jsxRuntimeExports.jsx(e.LoaderCircle,{className:"mr-2 h-4 w-4 animate-spin text-foreground/50"}):e.jsxRuntimeExports.jsx(Ns,{className:"mr-2 size-4"}),"Count"]})]}),e.jsxRuntimeExports.jsxs(e.ScrollArea,{className:"flex-1 basis-0 overflow-y-auto border-b border-t border-muted py-3",children:[t==null?void 0:t.map(R=>e.jsxRuntimeExports.jsxs("div",{onClick:()=>E(R),className:e.cn("mx-3 flex cursor-pointer items-center justify-between rounded px-2 py-[6px] text-sm transition-colors hover:bg-muted/50",{"bg-muted":e.isColumnInSqlGen(R,a)}),children:[e.jsxRuntimeExports.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsxRuntimeExports.jsx(qe,{column:R}),e.jsxRuntimeExports.jsx("span",{children:R.column_name})]}),e.NUMBER_DATA_TYPES.includes(R.data_type)&&e.jsxRuntimeExports.jsx("div",{onClick:C=>C.stopPropagation(),className:"flex items-center justify-end",children:e.jsxRuntimeExports.jsx(Os,{column:R})})]},R.column_name)),e.jsxRuntimeExports.jsx(e.ScrollBar,{orientation:"vertical"}),e.jsxRuntimeExports.jsx(e.ScrollBar,{orientation:"horizontal"})]})]})}function Ce(s,n){var ge,ae,je,me;let t=g.useMemo(()=>[],[]);const r=e.useSemaphorContext().authToken||s,a=e.useEditorStore(v=>v.selectedConnectionId),i=e.useEditorStore(v=>v.selectedDatabaseName),o=e.useEditorStore(v=>v.selectedSchemaName),l=e.useEditorStore(v=>v.selectedTableName),c=e.useEditorStore(v=>v.actions.setCurrentColumns),h=e.useEditorStore(v=>v.actions.setSelectedConnectionId),u=e.useEditorStore(v=>v.actions.setSelectedDatabaseName),d=e.useEditorStore(v=>v.actions.setSelectedSchemaName),y=e.useEditorStore(v=>v.actions.setSelectedTableName),x=e.useEditorStore(v=>v.actions.setCardSql);function m(v){return a&&i&&o&&i!=="NA"?!0:a&&v==="API"?!1:!!(a&&v==="S3")}function j(v){return!!(a&&i&&i!=="NA"&&o&&l||a&&(v==="S3"||v==="API"))}function E(v){return a&&v?!(v==="API"||v==="S3"):!1}const{data:f,isLoading:T,isError:w}=e.useQuery({queryKey:["connections"],queryFn:()=>e.getRequest("https://semaphor.cloud/api/v1/connections",(r==null?void 0:r.accessToken)||""),enabled:!!(r!=null&&r.accessToken)}),k=f==null?void 0:f.connections.find(v=>v.id===a),R=k==null?void 0:k.type,C=(k==null?void 0:k.type)==="API"||(k==null?void 0:k.type)==="S3",{data:A,isLoading:D,isFetching:_,isError:F,refetch:O}=e.useQuery({queryKey:["databases",a],queryFn:()=>e.getRequest("https://semaphor.cloud/api/v1/databases",(r==null?void 0:r.accessToken)||"",{connection_id:a}),enabled:E(R)}),{data:z,isLoading:K,isFetching:q,isError:$,refetch:H}=e.useQuery({queryKey:["schemas",a,i],queryFn:()=>e.getRequest("https://semaphor.cloud/api/v1/schemas",(r==null?void 0:r.accessToken)||"",{connection_id:a,database_name:i}),enabled:!!a&&!!i&&!C&&i!=="NA"}),{data:M,isLoading:I,isFetching:b,isError:S,refetch:N}=e.useQuery({queryKey:["tables",a,i,o],queryFn:()=>e.getRequest("https://semaphor.cloud/api/v1/tables",(r==null?void 0:r.accessToken)||"",{connection_id:a,database_name:i,schema_name:o}),enabled:m(R)}),{data:L,isLoading:Z,isFetching:P,isError:re}=e.useQuery({queryKey:["columns",a,i,o,l],queryFn:()=>e.getRequest("https://semaphor.cloud/api/v1/columns",(r==null?void 0:r.accessToken)||"",{connection_id:a,database_name:i,schema_name:o,table_name:l}),enabled:j(R)});g.useEffect(()=>{c(t)},[L,c,t]),g.useEffect(()=>{},[C,x,y,d,u,k]);const ne=(k==null?void 0:k.type)==="API"?(ge=k==null?void 0:k.type)==null?void 0:ge.toLowerCase():l||"",oe=C?"":o||"";function ee(v){d(v),y("")}function B(v){u(v),d(""),y("")}function G(v){h(v)}A&&((ae=A==null?void 0:A.databases)==null?void 0:ae.length)>0,z&&((je=z==null?void 0:z.schemas)==null?void 0:je.length)>0,L&&((me=L==null?void 0:L.columns)==null?void 0:me.length)>0&&(t=L.columns.map(v=>({...v,data_type:v.data_type.toLowerCase()}))),F&&(t=[]),(re||w)&&(t=[]);const U=f==null?void 0:f.connections.map(v=>({id:v.id,name:v.name,type:v.type})),ie=A==null?void 0:A.databases.map(v=>({id:v.database_name,name:v.database_name})),Q=z==null?void 0:z.schemas.map(v=>({id:v.schema_name,name:v.schema_name})),de=M==null?void 0:M.tables.map(v=>({id:v.table_name,name:v.table_name}));return{connectionItems:U,isConnectionsLoading:T,isConnectionsError:w,databaseItems:ie,isDatabasesLoadingOrFetching:D||_,isDatabaseError:F,schemaItems:Q,isSchemaLoadingOrFetching:K||q,isSchemaError:$,tableItems:de,isTableLoadingOrFetching:I||b,isTableError:S,columns:t,isColumnsLoadingOrFetching:Z||P,isColumnsError:re,isNonDbConnection:C,connectionType:R,tableName:ne,schemaName:oe,handleConnectionChange:G,handleDatabaseChange:B,handleSchemaChange:ee}}function Ve({ColumnsComponent:s}){var M;const n=e.useEditorStore(I=>I.selectedConnectionId),t=e.useEditorStore(I=>I.selectedDatabaseName),r=e.useEditorStore(I=>I.selectedSchemaName),a=e.useEditorStore(I=>I.selectedTableName),i=e.useEditorStore(I=>I.actions.setSelectedTableName),{connectionItems:o,schemaItems:l,databaseItems:c,tableItems:h,columns:u,isConnectionsLoading:d,isConnectionsError:y,isDatabasesLoadingOrFetching:x,isDatabaseError:m,isSchemaLoadingOrFetching:j,isSchemaError:E,isColumnsError:f,isColumnsLoadingOrFetching:T,isTableLoadingOrFetching:w,isTableError:k,connectionType:R,isNonDbConnection:C,handleConnectionChange:A,handleDatabaseChange:D,handleSchemaChange:_,tableName:F,schemaName:O}=Ce();function z(){return s?s(O,F,u):e.jsxRuntimeExports.jsx(Ms,{schemaName:O,tableName:F,columns:u,status:T?"Loading...":f?"Error":"Success"})}function K(){window.location.href="mailto:support@semaphor.cloud?subject=Help&body=I need help with..."}function q(){return R==="S3"||R==="API"?null:e.jsxRuntimeExports.jsx(he,{onChange:D,isError:m,isLoading:x,items:c,value:t||"",title:"Database"})}function $(){return R==="S3"||R==="API"?null:e.jsxRuntimeExports.jsx(he,{onChange:_,isError:E,isLoading:j,items:l,value:r||"",title:"Schema"})}function H(){return R==="API"?null:e.jsxRuntimeExports.jsx(he,{onChange:i,isError:k,items:h,isLoading:w,value:a||"",title:"Table"})}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(he,{items:o,title:"Connection",value:n||"",onChange:A,isLoading:d,isError:y,connectionTooltip:((M=o==null?void 0:o.find(I=>I.id===n))==null?void 0:M.type)||""}),q(),$(),H()]}),z(),e.jsxRuntimeExports.jsx("div",{className:"flex items-end justify-center gap-2 px-6 py-4",children:e.jsxRuntimeExports.jsxs(e.Button,{onClick:K,size:"sm",variant:"secondary",className:"w-full",children:[e.jsxRuntimeExports.jsx(Rs,{className:"mr-2 size-4"}),"Help"]})})]})}function Bs(s){const n=s.toUpperCase().indexOf("WHERE"),t=s.toUpperCase().indexOf("GROUP BY"),r=s.toUpperCase().indexOf("LIMIT"),a=s.toUpperCase().indexOf("ORDER BY");let i=s.length;if(a!==-1&&(i=a),r!==-1&&r<i&&(i=r),n!==-1){const o=s.substring(0,n),l=s.substring(n);return`${o} {{ filters | where }} AND ${l.substring(6)}`}else if(t!==-1){const o=s.substring(0,t),l=s.substring(t);return`${o} {{ filters | where }} ${l}`}else{const o=s.substring(0,i),l=s.substring(i);return`${o} {{ filters | where }} ${l}`}}function qs({error:s,setShowAIDialog:n,setUserInputforAI:t,setTriggerAIRun:r}){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:" p-0 h-5",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:"grow space-y-1 flex flex-col ",children:[e.jsxRuntimeExports.jsxs(e.Button,{onClick:()=>{n(!0),t(s),r(!0)},size:"sm",variant:"outline",children:[e.jsxRuntimeExports.jsx(ps,{className:"h-4 w-4 mr-2"}),"Fix It"]}),e.jsxRuntimeExports.jsx(e.ScrollArea,{className:" min-h-0 max-h-[250px] overflow-scroll ",children:e.jsxRuntimeExports.jsx("p",{className:" overflow-auto text-sm leading-relaxed font-mono ",children:s})})]})})})]})}function Vs({text:s,onCheckedChange:n,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:n}),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(),n=g.useRef(null),t=e.useEditorStore(l=>l.applyFilters),[r,a]=g.useState(""),i=e.useEditorStore(l=>l.filterValues),o=e.useEditorStore(l=>l.card.sql);return e.jsxRuntimeExports.jsxs(e.HoverCard,{openDelay:0,onOpenChange:async l=>{if(!l)return;console.log("onOpenChange");const c=await e.postRequest("https://semaphor.cloud/api/v1/filter-sql",(s==null?void 0:s.accessToken)||"",{sql:o,active_filters:i});console.log(c),c.sql?(console.log(c.records),a(c.sql)):a("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:n,className:"font-mono text-sm",children:[r,e.jsxRuntimeExports.jsx(e.ClipboardCopyIcon,{onClick:()=>e.copyToClipboard(n),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 Hs=`
151
+ */const zs=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 Is(){const[s,n]=g.useState(""),[t,r]=g.useState(!1),[i,a]=g.useState(!1),o=e.useDashboardStore(c=>c.dashboard);function l(){const c=e.getDashbaordStateWithoutData(o),h=e.getBookmarkKey(o.id),u=JSON.parse(localStorage.getItem(h)||"[]");if(u.some(y=>y.name===s)){r(!0);return}u.push({name:s,template:c}),localStorage.setItem(h,JSON.stringify(u)),a(!1)}return e.jsxRuntimeExports.jsxs(e.Dialog,{open:i,onOpenChange:a,children:[e.jsxRuntimeExports.jsx(e.DialogTrigger,{asChild:!0,children:e.jsxRuntimeExports.jsxs(e.Button,{variant:"outline",className:"h-7 p-2",size:"sm",children:[e.jsxRuntimeExports.jsx(e.Plus,{className:" mr-2 h-4 w-4",strokeWidth:1.5}),"Add Lens"]})}),e.jsxRuntimeExports.jsxs(e.DialogContent,{className:"sm:max-w-[425px]",children:[e.jsxRuntimeExports.jsxs(e.DialogHeader,{children:[e.jsxRuntimeExports.jsx(e.DialogTitle,{children:"Add a 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:c=>{t&&r(!1),n(c.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 bookmark name already exists. Use a differnet name."}),e.jsxRuntimeExports.jsx(e.DialogFooter,{children:e.jsxRuntimeExports.jsx(e.Button,{variant:"outline",type:"submit",disabled:!s,onClick:l,children:"Save"})})]})]})}function Ds(){const[s,n]=g.useState(!1),[t,r]=g.useState(""),i=e.useDashboardStore(x=>x.dashboard),a=e.useDashboardStore(x=>x.bookmarkKey),[o,l]=g.useState([]),c=e.useDashboardStore(x=>x.actions.setDashboard),h=e.useDashboardStore(x=>x.actions.setFilterValues),u=e.useDashboardStore(x=>x.actions.setBookmarkKey);g.useEffect(()=>{const x=e.getBookmarkKey(i.id),m=JSON.parse(localStorage.getItem(x)||"[]");l(m);const j=m.find(E=>E.default);j&&j.name===a&&r(j.name)},[s,i,a]);function d(x){if(x===t)return;const m=o.find(E=>E.name===x),j=m==null?void 0:m.template;j&&(c(j),h(m.filterValues||[]),u(x==="Original"?"":x)),r(x)}function y(x){const m=e.getBookmarkKey(i.id),E=JSON.parse(localStorage.getItem(m)||"[]").filter(f=>f.name!==x);localStorage.setItem(m,JSON.stringify(E)),l(E)}return e.jsxRuntimeExports.jsxs(e.DropdownMenu,{open:s,onOpenChange:n,children:[e.jsxRuntimeExports.jsx(e.DropdownMenuTrigger,{asChild:!0,children:e.jsxRuntimeExports.jsx(e.Button,{variant:"outline",className:"h-7 p-2",children:e.jsxRuntimeExports.jsx(ms,{className:"h-4 w-4",strokeWidth:1.5})})}),e.jsxRuntimeExports.jsxs(e.DropdownMenuContent,{className:"w-56",children:[e.jsxRuntimeExports.jsx(e.DropdownMenuLabel,{children:"Lenses"}),e.jsxRuntimeExports.jsx(e.DropdownMenuSeparator,{}),e.jsxRuntimeExports.jsxs(e.DropdownMenuRadioGroup,{value:t,onValueChange:d,children:[e.jsxRuntimeExports.jsx(e.DropdownMenuRadioItem,{value:"Original",children:"Original"}),o.filter(x=>x.name!="Original").map((x,m)=>e.jsxRuntimeExports.jsxs(e.DropdownMenuRadioItem,{className:"xbg-red-100 flex justify-between",value:x.name,defaultChecked:x.name===a,children:[e.jsxRuntimeExports.jsx("p",{children:x.name}),e.jsxRuntimeExports.jsx(e.Cross2Icon,{onClick:j=>{j.preventDefault(),y(x.name)},className:"h-3 w-3 hover:cursor-pointer",strokeWidth:1.5})]},m))]})]})]})}function Ls(){const[s,n]=g.useState(!1),t=e.useDashboardStore(a=>a.dashboard),r=e.useDashboardStore(a=>a.bookmarkKey);g.useEffect(()=>{if(!r){n(!1);return}const a=e.getBookmarkKey(t.id),l=JSON.parse(localStorage.getItem(a)||"[]").find(c=>c.name===r);n(l?l.default:!1)},[r,t.id]);function i(a){if(n(a),!r)return;const o=e.getBookmarkKey(t.id),c=JSON.parse(localStorage.getItem(o)||"[]").map(h=>(h.name===r?h.default=a:h.default=!1,h));console.log(c),localStorage.setItem(o,JSON.stringify(c))}return e.jsxRuntimeExports.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsxRuntimeExports.jsx(e.Checkbox,{checked:s,onCheckedChange:i,id:"terms"}),e.jsxRuntimeExports.jsx("label",{htmlFor:"terms",className:"text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70",children:"Set as default"})]})}function Fs(){const s=e.useDashboardStore(f=>f.bookmarkKey),n=e.useDashboardStore(f=>f.dashboard);e.useDashboardStore(f=>f.selectedSheetId);const t=e.useDashboardStore(f=>f.isDashboardEditing),r=e.useDashboardStore(f=>f.filterValues),i=e.useDashboardStore(f=>f.isVisualEditing),a=e.useDashboardStore(f=>f.showFilters);e.useDashboardStore(f=>f.showDashboardJSON);const o=e.useDashboardStore(f=>f.onSaveFunction),l=e.useDashboardStore(f=>f.actions.setShowFilters),{addFrame:c,setSelectedFrameId:h}=e.useDashboardStore(f=>f.actions),{getSelectedSheet:u,setIsDashboardEditing:d,setShowDashboardJSON:y}=e.useDashboardStore(f=>f.actions),x=u(),m=()=>{if(!t||!x)return;const f={id:e.v4(),title:"Title",description:"Description",preferences:{onClickFilter:[{columnIndex:0,expression:""}]},type:"bar",sql:"select COUNT(*) from YOUR_TABLE",data:[]},T={id:e.v4(),cards:[f],activeCardId:f.id};c(x.id,T),h(T.id)},j=()=>{d(!0)};function E(){if(!s||s==="")return;const f=e.getDashbaordStateWithoutData(n),T=e.getBookmarkKey(n.id),w=JSON.parse(localStorage.getItem(T)||"[]"),k=w.findIndex(R=>R.name===s);k!==-1?w[k]={name:s,template:f,default:w[k].default,filterValues:r}:w.push({name:s,template:f,filterValues:r}),localStorage.setItem(T,JSON.stringify(w)),o==null||o(f)}return i?null:e.jsxRuntimeExports.jsxs("div",{className:"flex items-center justify-between gap-2 border-b bg-muted/50 px-2 py-2",role:"dashboard-controls",children:[!i&&e.jsxRuntimeExports.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxRuntimeExports.jsx(e.Label,{children:s}),!!s&&e.jsxRuntimeExports.jsxs(e.jsxRuntimeExports.Fragment,{children:[e.jsxRuntimeExports.jsx("span",{className:"text-muted-foreground",children:"|"}),e.jsxRuntimeExports.jsx(Ls,{})]})]}),e.jsxRuntimeExports.jsxs("div",{className:"flex gap-2",children:[t&&!i&&e.jsxRuntimeExports.jsx(Is,{}),!i&&e.jsxRuntimeExports.jsx(Ds,{}),t&&!i&&e.jsxRuntimeExports.jsxs(e.Button,{variant:"outline",className:"h-7 p-2",size:"sm",disabled:!t,onClick:m,children:[e.jsxRuntimeExports.jsx(e.Plus,{className:"mr-2 h-4 w-4",strokeWidth:1.5}),"Add Frame"]}),!t&&e.jsxRuntimeExports.jsx(e.Button,{variant:"outline",className:"h-7 p-2",onClick:j,size:"sm",children:e.jsxRuntimeExports.jsx(Oe,{className:"h-4 w-4",strokeWidth:1.5})}),t&&!i&&e.jsxRuntimeExports.jsx(e.Button,{variant:"outline",role:"close",className:"h-7 p-2",onClick:()=>{d(!1),y(!1)},size:"sm",children:e.jsxRuntimeExports.jsx(e.Cross2Icon,{className:"h-4 w-4",strokeWidth:1.5})}),t&&!i&&e.jsxRuntimeExports.jsx(e.Button,{className:"h-7 p-2",variant:"outline",onClick:E,size:"sm",children:e.jsxRuntimeExports.jsx(vs,{className:"h-4 w-4",strokeWidth:1.5})}),!a&&!i&&t&&e.jsxRuntimeExports.jsx(e.Button,{className:"h-7 p-2",variant:"outline",onClick:()=>l(!0),size:"sm",children:e.jsxRuntimeExports.jsx(Fe,{className:"h-4 w-4",strokeWidth:1.5})}),!i&&t&&!1,!i&&!1]})]})}function he({title:s,items:n,value:t,isLoading:r,isError:i,connectionTooltip:a,onChange:o,className:l,showIcon:c=!0,disabled:h=!1}){const u=r?"Loading...":i?"Error":t;function d(){if(s==="Connection")return e.jsxRuntimeExports.jsx(ys,{className:"size-4 rotate-90"});if(s==="Database")return e.jsxRuntimeExports.jsx(us,{className:"size-4"});if(s==="Schema")return e.jsxRuntimeExports.jsx(bs,{className:"size-4"});if(s==="Table")return e.jsxRuntimeExports.jsx(e.Table,{className:"size-4"})}return e.jsxRuntimeExports.jsxs("div",{className:"flex items-center gap-2",children:[c&&e.jsxRuntimeExports.jsx("div",{className:"shrink-0",children:a?e.jsxRuntimeExports.jsxs(e.Tooltip,{children:[e.jsxRuntimeExports.jsx(e.TooltipTrigger,{children:d()}),e.jsxRuntimeExports.jsx(e.TooltipContent,{className:"text-xs",align:"start",children:a})]}):d()}),e.jsxRuntimeExports.jsxs(e.Select,{disabled:h,value:u,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:r?"Loading...":i?"Error":`Select ${s}`})}),e.jsxRuntimeExports.jsx(e.SelectContent,{children:e.jsxRuntimeExports.jsxs(e.SelectGroup,{children:[r?e.jsxRuntimeExports.jsx(e.SelectLabel,{children:"Loading..."}):e.jsxRuntimeExports.jsx(e.SelectLabel,{children:s}),e.jsxRuntimeExports.jsx(e.jsxRuntimeExports.Fragment,{children:n&&n.map((y,x)=>e.jsxRuntimeExports.jsx(e.SelectItem,{value:y.id,children:y.name},x))}),(r||i)&&e.jsxRuntimeExports.jsx(e.SelectItem,{value:u,children:u})]})})]})]})}function Os({column:s}){const[n,t]=g.useState(!1),r=e.useEditorStore(u=>u.selectedTableName),i=e.useEditorStore(u=>u.selectedSchemaName),a=e.useEditorStore(u=>u.sqlGen),o=e.useEditorStore(u=>u.actions.setSqlGen),l=e.useEditorStore(u=>u.actions.setCardSql),c=e.useEditorStore(u=>u.actions.setRunSql);function h(u,d){const y=e.createSqlGenConfig(u,a,d);o(y);const x=e.getSql(y,e.fmt(i||""),e.fmt(r));x&&(l(x),c(!0)),t(!1)}return e.jsxRuntimeExports.jsxs(e.Popover,{open:n,onOpenChange:t,children:[e.jsxRuntimeExports.jsx(e.PopoverTrigger,{asChild:!0,children:e.jsxRuntimeExports.jsx(e.ChevronDown,{className:"h-4 w-4 cursor-pointer text-foreground/40"})}),e.jsxRuntimeExports.jsx(e.PopoverContent,{align:"center",className:"w-18 rounded-md p-0 shadow-none",children:e.jsxRuntimeExports.jsxs("ul",{className:"text-xs",children:[e.jsxRuntimeExports.jsx("li",{onClick:()=>h(s,"COUNT"),className:"cursor-pointer p-1 px-3 transition-colors hover:bg-muted",children:"Count"}),e.jsxRuntimeExports.jsx("li",{onClick:()=>h(s,"AVG"),className:"cursor-pointer p-1 px-3 transition-colors hover:bg-muted",children:"Avg"}),e.jsxRuntimeExports.jsx("li",{onClick:()=>h(s,"SUM"),className:"cursor-pointer p-1 px-3 transition-colors hover:bg-muted",children:"Sum"}),e.jsxRuntimeExports.jsx("li",{onClick:()=>h(s,"MAX"),className:"cursor-pointer p-1 px-3 transition-colors hover:bg-muted",children:"Max"}),e.jsxRuntimeExports.jsx("li",{onClick:()=>h(s,"MIN"),className:"cursor-pointer p-1 px-3 transition-colors hover:bg-muted",children:"Min"})]})})]})}function qe({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(Ts,{className:"size-3"}):e.NUMBER_DATA_TYPES.includes(s.data_type.toLowerCase())?e.jsxRuntimeExports.jsx(hs,{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(Cs,{className:"size-3"})}),e.jsxRuntimeExports.jsx(e.TooltipContent,{children:e.jsxRuntimeExports.jsx("p",{className:"font-mono text-xs",children:s.data_type})})]})}function Ms({schemaName:s,tableName:n,columns:t,status:r}){const i=e.useEditorStore(R=>R.sqlGen),a=e.useEditorStore(R=>R.selectedConnectionId),o=e.useEditorStore(R=>R.selectedDatabaseName),l=e.useEditorStore(R=>R.selectedSchemaName),c=e.useEditorStore(R=>R.selectedTableName),h=e.useDashboardStore(R=>R.dashboard.aiScopeTables),{setAIScopeTables:u}=e.useDashboardStore(R=>R.actions),d=e.useEditorStore(R=>R.actions.setRunSql),y=e.useEditorStore(R=>R.actions.setSqlGen),x=e.useEditorStore(R=>R.actions.setIsShowingVisual),m=e.useEditorStore(R=>R.actions.setCardSql),{connectionType:j}=Ce();function E(R){const C=e.createSqlGenConfig(R,i);y(C);const A=e.getSql(C,e.fmt(s),e.fmt(n));A&&(m(A),d(!0))}function f(){return(h==null?void 0:h.find(R=>R.connectinonId===a&&R.tableName===c))!==void 0}function T(R){if(R===!0&&c&&a){const C={connectinonId:a,connectionType:j,databaseName:o,schemaName:l,tableName:c},D=[...h||[],C].filter((_,F,O)=>O.findIndex(z=>z.connectinonId===_.connectinonId&&z.tableName===_.tableName)===F);u(D),e.Jt.success(`Added '${c}' to AI Scope`,{position:"top-right",duration:2500,richColors:!0})}else{const C=(h||[]).filter(A=>A.connectinonId!==a&&A.tableName!==c);u(C),e.Jt(`Removed '${c}' from AI Scope`,{position:"top-right",duration:2e3,richColors:!0})}}function w(){let C=e.getQualifiedTableName(s,n);(D=>D.charAt(0)===D.charAt(0).toUpperCase())(n)&&(C=`"${n}"`),x(!1),m(`SELECT * FROM ${C} LIMIT 10`),d(!0)}function k(){let C=e.getQualifiedTableName(s,n);(D=>D.charAt(0)===D.charAt(0).toUpperCase())(n)&&(C=`"${n}"`),x(!1),m(`SELECT COUNT(*) FROM ${C}`),d(!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:`${f()?"Remove from":"Add to"} AI Scope`,pressed:f(),onPressedChange:T,variant:"outline",className:"h-9 px-2",children:e.jsxRuntimeExports.jsx(e.Bot,{className:e.cn("size-4",{"text-primary":f(),"text-muted-foreground":!f()})})}),e.jsxRuntimeExports.jsxs(e.Button,{disabled:r!=="Success",onClick:w,size:"sm",variant:"secondary",className:"flex",children:[r!=="Success"?e.jsxRuntimeExports.jsx(e.LoaderCircle,{className:"mr-2 h-4 w-4 animate-spin text-foreground/50"}):e.jsxRuntimeExports.jsx(ks,{className:"mr-2 size-4"}),"Top 10"]}),e.jsxRuntimeExports.jsxs(e.Button,{disabled:r!=="Success",onClick:k,size:"sm",variant:"secondary",className:"flex",children:[r!=="Success"?e.jsxRuntimeExports.jsx(e.LoaderCircle,{className:"mr-2 h-4 w-4 animate-spin text-foreground/50"}):e.jsxRuntimeExports.jsx(Ns,{className:"mr-2 size-4"}),"Count"]})]}),e.jsxRuntimeExports.jsxs(e.ScrollArea,{className:"flex-1 basis-0 overflow-y-auto border-b border-t border-muted py-3",children:[t==null?void 0:t.map(R=>e.jsxRuntimeExports.jsxs("div",{onClick:()=>E(R),className:e.cn("mx-3 flex cursor-pointer items-center justify-between rounded px-2 py-[6px] text-sm transition-colors hover:bg-muted/50",{"bg-muted":e.isColumnInSqlGen(R,i)}),children:[e.jsxRuntimeExports.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsxRuntimeExports.jsx(qe,{column:R}),e.jsxRuntimeExports.jsx("span",{children:R.column_name})]}),e.NUMBER_DATA_TYPES.includes(R.data_type)&&e.jsxRuntimeExports.jsx("div",{onClick:C=>C.stopPropagation(),className:"flex items-center justify-end",children:e.jsxRuntimeExports.jsx(Os,{column:R})})]},R.column_name)),e.jsxRuntimeExports.jsx(e.ScrollBar,{orientation:"vertical"}),e.jsxRuntimeExports.jsx(e.ScrollBar,{orientation:"horizontal"})]})]})}function Ce(s,n){var ge,ae,je,me;let t=g.useMemo(()=>[],[]);const r=e.useSemaphorContext().authToken||s,i=e.useEditorStore(v=>v.selectedConnectionId),a=e.useEditorStore(v=>v.selectedDatabaseName),o=e.useEditorStore(v=>v.selectedSchemaName),l=e.useEditorStore(v=>v.selectedTableName),c=e.useEditorStore(v=>v.actions.setCurrentColumns),h=e.useEditorStore(v=>v.actions.setSelectedConnectionId),u=e.useEditorStore(v=>v.actions.setSelectedDatabaseName),d=e.useEditorStore(v=>v.actions.setSelectedSchemaName),y=e.useEditorStore(v=>v.actions.setSelectedTableName),x=e.useEditorStore(v=>v.actions.setCardSql);function m(v){return i&&a&&o&&a!=="NA"?!0:i&&v==="API"?!1:!!(i&&v==="S3")}function j(v){return!!(i&&a&&a!=="NA"&&o&&l||i&&(v==="S3"||v==="API"))}function E(v){return i&&v?!(v==="API"||v==="S3"):!1}const{data:f,isLoading:T,isError:w}=e.useQuery({queryKey:["connections"],queryFn:()=>e.getRequest("https://semaphor.cloud/api/v1/connections",(r==null?void 0:r.accessToken)||""),enabled:!!(r!=null&&r.accessToken)}),k=f==null?void 0:f.connections.find(v=>v.id===i),R=k==null?void 0:k.type,C=(k==null?void 0:k.type)==="API"||(k==null?void 0:k.type)==="S3",{data:A,isLoading:D,isFetching:_,isError:F,refetch:O}=e.useQuery({queryKey:["databases",i],queryFn:()=>e.getRequest("https://semaphor.cloud/api/v1/databases",(r==null?void 0:r.accessToken)||"",{connection_id:i}),enabled:E(R)}),{data:z,isLoading:K,isFetching:q,isError:P,refetch:H}=e.useQuery({queryKey:["schemas",i,a],queryFn:()=>e.getRequest("https://semaphor.cloud/api/v1/schemas",(r==null?void 0:r.accessToken)||"",{connection_id:i,database_name:a}),enabled:!!i&&!!a&&!C&&a!=="NA"}),{data:M,isLoading:I,isFetching:b,isError:S,refetch:N}=e.useQuery({queryKey:["tables",i,a,o],queryFn:()=>e.getRequest("https://semaphor.cloud/api/v1/tables",(r==null?void 0:r.accessToken)||"",{connection_id:i,database_name:a,schema_name:o}),enabled:m(R)}),{data:L,isLoading:Z,isFetching:$,isError:re}=e.useQuery({queryKey:["columns",i,a,o,l],queryFn:()=>e.getRequest("https://semaphor.cloud/api/v1/columns",(r==null?void 0:r.accessToken)||"",{connection_id:i,database_name:a,schema_name:o,table_name:l}),enabled:j(R)});g.useEffect(()=>{c(t)},[L,c,t]),g.useEffect(()=>{},[C,x,y,d,u,k]);const ne=(k==null?void 0:k.type)==="API"?(ge=k==null?void 0:k.type)==null?void 0:ge.toLowerCase():l||"",oe=C?"":o||"";function ee(v){d(v),y("")}function B(v){u(v),d(""),y("")}function G(v){h(v)}A&&((ae=A==null?void 0:A.databases)==null?void 0:ae.length)>0,z&&((je=z==null?void 0:z.schemas)==null?void 0:je.length)>0,L&&((me=L==null?void 0:L.columns)==null?void 0:me.length)>0&&(t=L.columns.map(v=>({...v,data_type:v.data_type.toLowerCase()}))),F&&(t=[]),(re||w)&&(t=[]);const U=f==null?void 0:f.connections.map(v=>({id:v.id,name:v.name,type:v.type})),ie=A==null?void 0:A.databases.map(v=>({id:v.database_name,name:v.database_name})),Q=z==null?void 0:z.schemas.map(v=>({id:v.schema_name,name:v.schema_name})),de=M==null?void 0:M.tables.map(v=>({id:v.table_name,name:v.table_name}));return{connectionItems:U,isConnectionsLoading:T,isConnectionsError:w,databaseItems:ie,isDatabasesLoadingOrFetching:D||_,isDatabaseError:F,schemaItems:Q,isSchemaLoadingOrFetching:K||q,isSchemaError:P,tableItems:de,isTableLoadingOrFetching:I||b,isTableError:S,columns:t,isColumnsLoadingOrFetching:Z||$,isColumnsError:re,isNonDbConnection:C,connectionType:R,tableName:ne,schemaName:oe,handleConnectionChange:G,handleDatabaseChange:B,handleSchemaChange:ee}}function Ve({ColumnsComponent:s}){var M;const n=e.useEditorStore(I=>I.selectedConnectionId),t=e.useEditorStore(I=>I.selectedDatabaseName),r=e.useEditorStore(I=>I.selectedSchemaName),i=e.useEditorStore(I=>I.selectedTableName),a=e.useEditorStore(I=>I.actions.setSelectedTableName),{connectionItems:o,schemaItems:l,databaseItems:c,tableItems:h,columns:u,isConnectionsLoading:d,isConnectionsError:y,isDatabasesLoadingOrFetching:x,isDatabaseError:m,isSchemaLoadingOrFetching:j,isSchemaError:E,isColumnsError:f,isColumnsLoadingOrFetching:T,isTableLoadingOrFetching:w,isTableError:k,connectionType:R,isNonDbConnection:C,handleConnectionChange:A,handleDatabaseChange:D,handleSchemaChange:_,tableName:F,schemaName:O}=Ce();function z(){return s?s(O,F,u):e.jsxRuntimeExports.jsx(Ms,{schemaName:O,tableName:F,columns:u,status:T?"Loading...":f?"Error":"Success"})}function K(){window.location.href="mailto:support@semaphor.cloud?subject=Help&body=I need help with..."}function q(){return R==="S3"||R==="API"?null:e.jsxRuntimeExports.jsx(he,{onChange:D,isError:m,isLoading:x,items:c,value:t||"",title:"Database"})}function P(){return R==="S3"||R==="API"?null:e.jsxRuntimeExports.jsx(he,{onChange:_,isError:E,isLoading:j,items:l,value:r||"",title:"Schema"})}function H(){return R==="API"?null:e.jsxRuntimeExports.jsx(he,{onChange:a,isError:k,items:h,isLoading:w,value:i||"",title:"Table"})}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(he,{items:o,title:"Connection",value:n||"",onChange:A,isLoading:d,isError:y,connectionTooltip:((M=o==null?void 0:o.find(I=>I.id===n))==null?void 0:M.type)||""}),q(),P(),H()]}),z(),e.jsxRuntimeExports.jsx("div",{className:"flex items-end justify-center gap-2 px-6 py-4",children:e.jsxRuntimeExports.jsxs(e.Button,{onClick:K,size:"sm",variant:"secondary",className:"w-full",children:[e.jsxRuntimeExports.jsx(Rs,{className:"mr-2 size-4"}),"Help"]})})]})}function Bs(s){const n=s.toUpperCase().indexOf("WHERE"),t=s.toUpperCase().indexOf("GROUP BY"),r=s.toUpperCase().indexOf("LIMIT"),i=s.toUpperCase().indexOf("ORDER BY");let a=s.length;if(i!==-1&&(a=i),r!==-1&&r<a&&(a=r),n!==-1){const o=s.substring(0,n),l=s.substring(n);return`${o} {{ filters | where }} AND ${l.substring(6)}`}else if(t!==-1){const o=s.substring(0,t),l=s.substring(t);return`${o} {{ filters | where }} ${l}`}else{const o=s.substring(0,a),l=s.substring(a);return`${o} {{ filters | where }} ${l}`}}function qs({error:s,setShowAIDialog:n,setUserInputforAI:t,setTriggerAIRun:r}){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:" p-0 h-5",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:"grow space-y-1 flex flex-col ",children:[e.jsxRuntimeExports.jsxs(e.Button,{onClick:()=>{n(!0),t(s),r(!0)},size:"sm",variant:"outline",children:[e.jsxRuntimeExports.jsx(ps,{className:"h-4 w-4 mr-2"}),"Fix It"]}),e.jsxRuntimeExports.jsx(e.ScrollArea,{className:" min-h-0 max-h-[250px] overflow-scroll ",children:e.jsxRuntimeExports.jsx("p",{className:" overflow-auto text-sm leading-relaxed font-mono ",children:s})})]})})})]})}function Vs({text:s,onCheckedChange:n,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:n}),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(),n=g.useRef(null),t=e.useEditorStore(l=>l.applyFilters),[r,i]=g.useState(""),a=e.useEditorStore(l=>l.filterValues),o=e.useEditorStore(l=>l.card.sql);return e.jsxRuntimeExports.jsxs(e.HoverCard,{openDelay:0,onOpenChange:async l=>{if(!l)return;console.log("onOpenChange");const c=await e.postRequest("https://semaphor.cloud/api/v1/filter-sql",(s==null?void 0:s.accessToken)||"",{sql:o,active_filters:a});console.log(c),c.sql?(console.log(c.records),i(c.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:n,className:"font-mono text-sm",children:[r,e.jsxRuntimeExports.jsx(e.ClipboardCopyIcon,{onClick:()=>e.copyToClipboard(n),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 Hs=`
152
152
 
153
153
  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.
154
154
 
@@ -194,7 +194,7 @@ SELECT label, measure FROM table
194
194
 
195
195
  - Label - Category
196
196
  - Measure - Number
197
- `;function $s({open:s,setOpen:n,userInput:t,setUserInput:r,triggerAIRun:a,setTriggerAIRun:i}){const o=g.useRef(null),l=g.useRef(null),{authToken:c}=e.useSemaphorContext(),[h,u]=g.useState(!1),d=e.useEditorStore(b=>b.actions.setCardSql),y=e.useDashboardStore(b=>b.dashboard.baseQueries),x=e.useEditorStore(b=>b.actions.setRunSql),m=e.useEditorStore(b=>b.actions.setCardType),[j,E]=g.useState([]),f=e.useEditorStore(b=>b.currentColumns),T=e.useEditorStore(b=>b.card.sql),w=e.useEditorStore(b=>b.selectedTableName),k=`
197
+ `;function Ps({open:s,setOpen:n,userInput:t,setUserInput:r,triggerAIRun:i,setTriggerAIRun:a}){const o=g.useRef(null),l=g.useRef(null),{authToken:c}=e.useSemaphorContext(),[h,u]=g.useState(!1),d=e.useEditorStore(b=>b.actions.setCardSql),y=e.useDashboardStore(b=>b.dashboard.baseQueries),x=e.useEditorStore(b=>b.actions.setRunSql),m=e.useEditorStore(b=>b.actions.setCardType),[j,E]=g.useState([]),f=e.useEditorStore(b=>b.currentColumns),T=e.useEditorStore(b=>b.card.sql),w=e.useEditorStore(b=>b.selectedTableName),k=`
198
198
  ${t}
199
199
 
200
200
  Database Query Dialect: ${w==="api"||w==="s3"?"DuckDb":""}
@@ -202,4 +202,4 @@ SELECT label, measure FROM table
202
202
  Table Columns: ${f==null?void 0:f.map(b=>`${b.column_name} | ${b.data_type}`).join(", ")}
203
203
  User SQL: ${T}
204
204
  ${y&&`Base Queries: ${JSON.stringify(y)} `}`,R=` 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.
205
- Visual Query Syntax: ${Hs}`,{data:C,isLoading:A,isFetching:D,isError:_,refetch:F}=e.useQuery({queryKey:["ai-query"],queryFn:()=>e.getRequest("https://semaphor.cloud/api/v1/ai",(c==null?void 0:c.accessToken)||"",{user_content:`userContent: ${k} ${h?R:""}`}),enabled:!1});function O(b){if(b.toLowerCase().includes("bar"))m("bar");else if(b.toLowerCase().includes("line"))m("line");else if(b.toLowerCase().includes("bubble"))m("bubble");else if(b.toLowerCase().includes("scatter"))m("scatter");else if(b.toLowerCase().includes("stacked"))m("stackedBar");else if(b.toLowerCase().includes("pie"))m("pie");else if(b.toLowerCase().includes("donut")||b.toLowerCase().includes("doughnut"))m("doughnut");else if(b.toLowerCase().includes("radar"))m("radar");else return m("bar"),!1;return!0}g.useEffect(()=>{C&&E(b=>[...b,{role:"ai",content:C.response}])},[C]),g.useEffect(()=>{const b=setTimeout(()=>{var S;l.current&&(l.current.scroll({top:l.current.scrollHeight,behavior:"smooth"}),(S=o.current)==null||S.focus())},100);return()=>clearTimeout(b)},[j]);function z(){t&&(E(b=>[...b,{role:"user",content:t}]),O(t)&&u(!0),r(""),F())}g.useEffect(()=>{a&&(z(),i(!1))},[a,i]);const K={fontFamily:"Arial, sans-serif",lineHeight:1.6,fontSize:15,width:"100%"},q={fontFamily:"monospace",fontSize:14,lineHeight:1.6},$={fontFamily:"Arial, sans-serif",lineHeight:1.6,fontSize:15,padding:"2px 0",marginLeft:20,listStyleType:"disc"},H={p:({node:b,...S})=>e.jsxRuntimeExports.jsx("p",{style:K,...S}),code:({node:b,...S})=>e.jsxRuntimeExports.jsx("code",{className:"rounded-sm bg-muted px-2 py-1 text-sm",...S}),pre:({node:b,...S})=>e.jsxRuntimeExports.jsxs("pre",{className:"space-y-2 rounded-sm bg-muted/50 p-3",style:q,children:[e.jsxRuntimeExports.jsx("code",{className:"whitespace-normal text-sm",children:S.children}),e.jsxRuntimeExports.jsxs("div",{className:"flex justify-start gap-2",children:[e.jsxRuntimeExports.jsx(e.Button,{onClick:M,size:"sm",variant:"outline",children:e.jsxRuntimeExports.jsx(e.ClipboardCopyIcon,{})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:N=>{const L=M(N);L&&(n(!1),d(L),x(!0))},size:"sm",variant:"outline",children:e.jsxRuntimeExports.jsx(e.PlayIcon,{})})]})]}),li:({node:b,...S})=>e.jsxRuntimeExports.jsx("li",{style:$,...S})};function M(b){const S=b.currentTarget.closest("pre");if(!S)return;const N=S.textContent||S.innerText;return navigator.clipboard.writeText(N).then(()=>console.log("Text copied to clipboard")).catch(L=>console.error("Error in copying text: ",L)),N}function I(){return j==null?void 0:j.map((b,S)=>b.role==="user"?e.jsxRuntimeExports.jsxs("div",{className:"flex items-start rounded-md bg-muted p-3 text-sm",children:[e.jsxRuntimeExports.jsx(zs,{className:"mr-2 h-5 w-5"}),e.jsxRuntimeExports.jsx("div",{children:b.content})]},S):b.role==="ai"?e.jsxRuntimeExports.jsx(e.Markdown,{className:"w-full overflow-auto py-1",components:H,children:C==null?void 0:C.response.replace(/DuckDB/gi,"Semaphor")},S):e.jsxRuntimeExports.jsx("div",{},S))}return e.jsxRuntimeExports.jsxs(e.Dialog,{open:s,onOpenChange:n,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:l,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:I()})}),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:b=>{b.key==="Enter"&&!b.shiftKey&&(b.preventDefault(),r(""),z())},placeholder:"Type your question here...",onFocus:b=>{const S=b.target,N=S.value.length;S.setSelectionRange(N,N)},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:A||D,value:t,onChange:b=>r(b.target.value)})," ",e.jsxRuntimeExports.jsx(e.Button,{className:"h-8",size:"sm",variant:"ghost",onClick:z,children:!A&&!D?e.jsxRuntimeExports.jsx(e.PaperPlaneIcon,{}):e.jsxRuntimeExports.jsx(e.LoaderCircle,{className:"mr-2 h-4 w-4 animate-spin text-foreground/50"})})]})})]})]})}var _e={color:void 0,size:void 0,className:void 0,style:void 0,attr:void 0},Te=g.createContext&&g.createContext(_e),Ps=["attr","size","title"];function Ks(s,n){if(s==null)return{};var t=Gs(s,n),r,a;if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(s);for(a=0;a<i.length;a++)r=i[a],!(n.indexOf(r)>=0)&&Object.prototype.propertyIsEnumerable.call(s,r)&&(t[r]=s[r])}return t}function Gs(s,n){if(s==null)return{};var t={},r=Object.keys(s),a,i;for(i=0;i<r.length;i++)a=r[i],!(n.indexOf(a)>=0)&&(t[a]=s[a]);return t}function Ee(){return Ee=Object.assign?Object.assign.bind():function(s){for(var n=1;n<arguments.length;n++){var t=arguments[n];for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&(s[r]=t[r])}return s},Ee.apply(this,arguments)}function ze(s,n){var t=Object.keys(s);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(s);n&&(r=r.filter(function(a){return Object.getOwnPropertyDescriptor(s,a).enumerable})),t.push.apply(t,r)}return t}function fe(s){for(var n=1;n<arguments.length;n++){var t=arguments[n]!=null?arguments[n]:{};n%2?ze(Object(t),!0).forEach(function(r){Us(s,r,t[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(s,Object.getOwnPropertyDescriptors(t)):ze(Object(t)).forEach(function(r){Object.defineProperty(s,r,Object.getOwnPropertyDescriptor(t,r))})}return s}function Us(s,n,t){return n=Qs(n),n in s?Object.defineProperty(s,n,{value:t,enumerable:!0,configurable:!0,writable:!0}):s[n]=t,s}function Qs(s){var n=Js(s,"string");return typeof n=="symbol"?n:String(n)}function Js(s,n){if(typeof s!="object"||s===null)return s;var t=s[Symbol.toPrimitive];if(t!==void 0){var r=t.call(s,n||"default");if(typeof r!="object")return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return(n==="string"?String:Number)(s)}function He(s){return s&&s.map((n,t)=>g.createElement(n.tag,fe({key:t},n.attr),He(n.child)))}function te(s){return n=>g.createElement(Ws,Ee({attr:fe({},s.attr)},n),He(s.child))}function Ws(s){var n=t=>{var{attr:r,size:a,title:i}=s,o=Ks(s,Ps),l=a||t.size||"1em",c;return t.className&&(c=t.className),s.className&&(c=(c?c+" ":"")+s.className),g.createElement("svg",Ee({stroke:"currentColor",fill:"currentColor",strokeWidth:"0"},t.attr,r,o,{className:c,style:fe(fe({color:s.color||t.color},t.style),s.style),height:l,width:l,xmlns:"http://www.w3.org/2000/svg"}),i&&g.createElement("title",null,i),s.children)};return Te!==void 0?g.createElement(Te.Consumer,null,t=>n(t)):n(_e)}function Ys(s){return te({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 Xs(){const{theme:s}=e.useTheme(),n=g.useRef(),t=g.useRef(),[r,a]=g.useState(!1),[i,o]=g.useState(!1),[l,c]=g.useState(!1),[h,u]=g.useState(""),[d,y]=g.useState(!1),{authToken:x}=e.useSemaphorContext();e.useDashboardStore(p=>p.selectedSheetId);const m=e.useDashboardStore(p=>p.dashboard.baseQueries),j=e.useEditorStore(p=>p.card),E=e.useDashboardStore(p=>p.theme),f=e.useEditorStore(p=>p.isShowingVisual),T=e.useEditorStore(p=>p.selectedConnectionId),w=e.useEditorStore(p=>p.selectedDatabaseName),k=e.useEditorStore(p=>p.selectedSchemaName);e.useDashboardStore(p=>p.actions.updateFrameCard);const R=e.useEditorStore(p=>p.selectedTableName),C=e.useEditorStore(p=>p.card.sql),A=e.useEditorStore(p=>p.card.python),D=e.resolveBaseQuery(C,m),_=e.useEditorStore(p=>p.selectedConnectionId),F=e.useEditorStore(p=>p.frame),O=e.useEditorStore(p=>p.filterValues),z=e.useEditorStore(p=>p.applyFilters),{setCardCustomCfg:K,setQueryResultColumns:q,setFilterValues:$,setCardSql:H,setCardPython:M,setQueryError:I,setPythonStdOut:b,setCardPreferences:S}=e.useEditorStore(p=>p.actions),N=e.useEditorStore(p=>p.onSave),L=e.useEditorStore(p=>p.actions.setApplyFilters),Z=e.useEditorStore(p=>p.onClose),P=e.useEditorStore(p=>p.actions.setCardData),re=e.useEditorStore(p=>p.actions.setSqlGen),ne=e.useEditorStore(p=>p.runSql),oe=e.useEditorStore(p=>p.actions.setRunSql),ee=e.useEditorStore(p=>p.actions.setIsSqlRunning),{data:B,isLoading:G,isFetching:U,isSuccess:ie,isError:Q,error:de,status:ge,refetch:ae}=e.useQuery({queryKey:[D,A],queryFn:()=>e.postRequest("https://semaphor.cloud/api/v1/query",(x==null?void 0:x.accessToken)||"",{connection_id:_,sql:D,python:A===e.PYTHON_DEFAULT_CODE?"":A,active_filters:z?O:[]}),enabled:!1,retry:!1});g.useEffect(()=>{if(B&&(P(B.records),b((B==null?void 0:B.output)||""),B.records.length>0)){const{dimensionKeys:p}=e.getKeys(B.records);q(p)}},[B,P,q,b]),g.useEffect(()=>{ne&&(ae(),oe(!1))},[ne,ae,oe]),g.useEffect(()=>{(G||U)&&ee(!0),(Q||ie)&&ee(!1),Q?(I(de.message),P([]),q([]),b("")):I("")},[G,U,B,b,Q,ie,ee,P,q,I,de]);function je(){H(""),P([]),re({}),K(""),S({})}const me=p=>{t.current=p};function v(){let p=C;C&&!C.includes("{{")&&(p=Bs(C),H(p));const J={...j,lastSelectedSchema:k,lastSelectedDatabase:w,lastSelectedTable:R,connectionId:T,type:f?j.type:"table",sql:p,customCfg:f?j.customCfg:null},pe=F.cards.map(le=>le.id===j.id?J:le);N==null||N({...F,cards:pe})}function Ze(){Z==null||Z()}function es(p){const J=getComputedStyle(document.documentElement).getPropertyValue(p);return ss(J)}function ss(p){const[J,pe,le]=p.split(" "),V=parseFloat(J),ns=parseFloat(pe),os=parseFloat(le),is=ns/100,Ae=os/100,se=(1-Math.abs(2*Ae-1))*is,ce=se*(1-Math.abs(V/60%2-1)),Re=Ae-se/2;let W=0,Y=0,X=0;0<=V&&V<60?(W=se,Y=ce,X=0):60<=V&&V<120?(W=ce,Y=se,X=0):120<=V&&V<180?(W=0,Y=se,X=ce):180<=V&&V<240?(W=0,Y=ce,X=se):240<=V&&V<300?(W=ce,Y=0,X=se):300<=V&&V<360&&(W=se,Y=0,X=ce),W=Math.round((W+Re)*255),Y=Math.round((Y+Re)*255),X=Math.round((X+Re)*255);const be=as=>{const Se=as.toString(16);return Se.length==1?"0"+Se:Se};return`#${be(W)}${be(Y)}${be(X)}`}g.useEffect(()=>{const p=n.current,J=t.current;if(p){const pe=window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light",le=E==="system"?pe:E;p.editor.defineTheme("default",{base:le==="light"?"vs":"vs-dark",inherit:!0,rules:[],colors:{"editor.background":le==="light"?"#ffffff":es("--background")}}),p.editor.setTheme("default")}return J&&p&&J.addCommand(p.KeyMod.Shift|p.KeyCode.Enter,function(){return console.log("Executing query..."),ae(),!1}),()=>{}},[s,E,n.current]);function we(p){n.current=p}function ts(){return e.jsxRuntimeExports.jsxs(e.jsxRuntimeExports.Fragment,{children:[i&&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(Vs,{checked:z,onCheckedChange:()=>L(!z),text:"Apply Filters"}),e.jsxRuntimeExports.jsx(_s,{}),O&&i&&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),$(JSON.parse(p))}catch{}},defaultLanguage:"json",className:"mt-1 min-h-[220px]",value:JSON.stringify(O,null,2),options:{readOnly:!0,minimap:{enabled:!1},lineNumbers:"off",glyphMargin:!1,wordWrap:"on",scrollbar:{verticalScrollbarSize:0,horizontalScrollbarSize:0},fontSize:12,renderLineHighlight:"none"}})]})}),O&&!i&&e.jsxRuntimeExports.jsx(Fe,{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":z})})]})}function rs(){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:r?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=>{H(p)},value:C,options:{minimap:{enabled:!1},wordWrap:"on",scrollbar:{verticalScrollbarSize:0,horizontalScrollbarSize:0},fontSize:14,renderLineHighlight:"none"},defaultLanguage:"sql",defaultValue:"SELECT * FROM table",beforeMount:we,onMount:me})}),r&&e.jsxRuntimeExports.jsx("code",{className:"absolute right-6 top-3 text-sm text-muted-foreground/70",children:"sql"})]}),r&&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=>{M(p&&p.trim()||"")},value:A||e.PYTHON_DEFAULT_CODE,options:{minimap:{enabled:!1},wordWrap:"on",scrollbar:{verticalScrollbarSize:0,horizontalScrollbarSize:0},fontSize:14,renderLineHighlight:"none"},defaultLanguage:"python",beforeMount:we,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:[rs(),ts()]}),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:G||U,onClick:()=>{ae()},className:"shrink-0",size:"sm",variant:"outline",children:[G||U?e.jsxRuntimeExports.jsx(e.LoaderCircle,{className:"mr-2 h-4 w-4 animate-spin text-foreground/50"}):e.jsxRuntimeExports.jsx(Ss,{className:"mr-2 h-4 w-4"}),"Run"]}),Q&&e.jsxRuntimeExports.jsx(qs,{error:de.message,setShowAIDialog:c,setTriggerAIRun:y,setUserInputforAI:u}),e.jsxRuntimeExports.jsxs(e.Button,{onClick:je,className:"",size:"sm",variant:"outline",children:[e.jsxRuntimeExports.jsx(ds,{className:"mr-2 size-4"}),"Clear"]}),e.jsxRuntimeExports.jsx(e.Toggle,{pressed:r,onPressedChange:p=>a(p),className:"",size:"sm",variant:"outline",children:e.jsxRuntimeExports.jsx(Ys,{className:"size-4 text-foreground/70"})}),e.jsxRuntimeExports.jsx($s,{open:l,setOpen:c,userInput:h,triggerAIRun:d,setTriggerAIRun:y,setUserInput:p=>u(p)})]}),e.jsxRuntimeExports.jsxs("div",{className:"flex items-end gap-2",children:[e.jsxRuntimeExports.jsxs(e.Button,{onClick:v,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:Ze,className:"w-full",size:"sm",variant:"outline",children:[e.jsxRuntimeExports.jsx(e.Cross2Icon,{className:"mr-2 size-4"}),"Close"]})]})]})]})}function Zs({data:s}){var o;const[n,t]=g.useState([]),a=Object.keys(s[0]).map(l=>({accessorKey:l,header:({column:c})=>{const h=c.getIsSorted();return e.jsxRuntimeExports.jsx("div",{className:"flex gap-2",children:e.jsxRuntimeExports.jsxs("div",{className:"flex cursor-pointer items-center",onClick:()=>c.toggleSorting(c.getIsSorted()==="asc"),children:[l,h==="asc"?e.jsxRuntimeExports.jsx(e.TriangleUpIcon,{className:"ml-2 h-5 w-5"}):h==="desc"?e.jsxRuntimeExports.jsx(e.TriangleDownIcon,{className:"ml-2 h-5 w-5"}):null]})})}})),i=e.useReactTable({data:s,columns:a,getCoreRowModel:e.getCoreRowModel(),getPaginationRowModel:e.getPaginationRowModel(),onSortingChange:t,getSortedRowModel:e.getSortedRowModel(),manualPagination:!0,state:{sorting:n}});return e.jsxRuntimeExports.jsxs(e.Table$1,{children:[e.jsxRuntimeExports.jsx(e.TableHeader,{children:i.getHeaderGroups().map(l=>e.jsxRuntimeExports.jsx(e.TableRow,{children:l.headers.map(c=>e.jsxRuntimeExports.jsx(e.TableHead,{className:"sticky top-0 bg-muted",children:c.isPlaceholder?null:e.flexRender(c.column.columnDef.header,c.getContext())},c.id))},l.id))}),e.jsxRuntimeExports.jsx(e.TableBody,{children:(o=i.getRowModel().rows)!=null&&o.length?i.getRowModel().rows.map(l=>e.jsxRuntimeExports.jsx(e.TableRow,{className:"whitespace-nowrap py-2","data-state":l.getIsSelected()&&"selected",children:l.getVisibleCells().map(c=>e.jsxRuntimeExports.jsx(e.TableCell,{children:e.flexRender(c.column.columnDef.cell,c.getContext())},c.id))},l.id)):e.jsxRuntimeExports.jsx(e.TableRow,{children:e.jsxRuntimeExports.jsx(e.TableCell,{colSpan:a.length,className:"h-24 text-center",children:"No results."})})})]})}function $e({className:s,...n}){g.useState(0);const t=e.useDashboardStore(o=>o.themeStyle),r=e.useEditorStore(o=>o.card),a=e.useEditorStore(o=>o.actions.setCard);if(g.useEffect(()=>{},[r.data,r.type,r.cfg,r.customCfg,t,r.preferences]),!r.id)return null;let i;return r.data&&r.data.length>0&&(i=e.createChartConfig({data:r.data,cardType:r.type,cfg:r.cfg,customCfg:r.customCfg,preferences:r.preferences})),e.jsxRuntimeExports.jsxs(e.Card,{role:"editor-visual-card",className:e.cn("relative flex h-full flex-col rounded-none",s),...n,children:[e.jsxRuntimeExports.jsxs(e.CardHeader,{className:"py-4",children:[e.jsxRuntimeExports.jsx(e.Editable,{text:r.title,onSave:o=>a({...r,title:o}),children:e.jsxRuntimeExports.jsx("div",{className:"flex items-center gap-2",children:e.jsxRuntimeExports.jsx(e.CardTitle,{className:"text-base",children:r.title})})},r.title),e.jsxRuntimeExports.jsx(e.Editable,{text:r.description||"",onSave:o=>a({...r,description:o}),children:e.jsxRuntimeExports.jsxs(e.CardDescription,{children:[" ",r.description]})},r.description)]}),e.jsxRuntimeExports.jsxs(e.CardContent,{className:"flex grow flex-col pb-3",children:[r.type!=="table"&&i&&e.jsxRuntimeExports.jsx(e.ChartJsVisual,{cfg:i},JSON.stringify(i)+JSON.stringify(r.preferences)),r.type==="table"&&r.data&&r.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:r,data:r==null?void 0:r.data})})]})]})}function et(){const[s,n]=g.useState(!1),[t,r]=g.useState(""),[a,i]=g.useState(""),[o,l]=g.useState(""),c=e.useEditorStore(E=>E.card),h=e.useEditorStore(E=>E.card.customCfg),u=e.useEditorStore(E=>E.actions.setCardCustomCfg);function d(E){var w,k;const f={...E,data:{...E==null?void 0:E.data,datasets:(k=(w=E==null?void 0:E.data)==null?void 0:w.datasets)==null?void 0:k.map(R=>({...R,data:[]}))}};return JSON.stringify(f,null,1)}function y(){if(!c.data||c.data.length===0)return;const E=e.createChartConfig({data:c.data,cardType:c.type,cfg:c.cfg,preferences:c.preferences});E&&(r(JSON.stringify(E,null,1)),h&&i(JSON.stringify(h,null,1)))}function x(){if(a)try{const E=JSON.parse(a);return E?(u(E),l(""),i(""),E):void 0}catch(E){console.log(E),l("Invalid JSON")}}function m(){i(""),u(null)}function j(){let E;if(h){const f=e._.cloneDeep(c.cfg),T=e._.merge(f,h);return E=d(T),E}return t?(E=d(JSON.parse(t)),E):""}return e.jsxRuntimeExports.jsxs(e.Dialog,{open:s,onOpenChange:n,children:[e.jsxRuntimeExports.jsx(e.DialogTrigger,{asChild:!0,children:e.jsxRuntimeExports.jsx(e.Button,{onClick:y,className:` ${h&&"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] min-w-[900px] overflow-auto",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(js,{onClick:()=>{navigator.clipboard.writeText(c.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($e,{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:[h&&e.jsxRuntimeExports.jsx(e.CheckIcon,{className:"mr-1 h-5 w-5 text-green-600"}),h?"Custom Config":"Default Config"]}),e.jsxRuntimeExports.jsx(e.TabsTrigger,{className:"",value:"output",children:"Output"})]}),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:j(),onChange:E=>i(E)})})]})]}),e.jsxRuntimeExports.jsxs(e.DialogFooter,{className:"flex items-center",children:[e.jsxRuntimeExports.jsx(e.Label,{className:"mr-2 text-red-500",children:o}),e.jsxRuntimeExports.jsx(e.Button,{disabled:!h,onClick:m,variant:"outline",children:"Reset"}),e.jsxRuntimeExports.jsx(e.Button,{onClick:x,variant:"outline",children:"Apply"}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>n(!1),variant:"outline",children:"Close"})]})]})]})}function Pe(s){return te({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 Ke(s){return te({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 Ge(s){return te({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 Ue(s){return te({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 Qe(s){return te({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 Je(s){return te({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 We(s){return te({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 st(){const[s,n]=g.useState(!1),t=e.useEditorStore(l=>l.card.type),{setCardType:r,setCardPreferences:a}=e.useEditorStore(l=>l.actions),i=e.useEditorStore(l=>l.actions.setCardCustomCfg);function o(l){r(l),i(null),a({}),n(!1)}return e.jsxRuntimeExports.jsxs(e.Popover,{open:s,onOpenChange:n,children:[e.jsxRuntimeExports.jsx(e.PopoverTrigger,{asChild:!0,children:e.jsxRuntimeExports.jsx(e.Button,{size:"sm",variant:"outline",children:e.jsxRuntimeExports.jsx(tt,{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:()=>o("bar"),className:"font-normal",variant:"ghost",children:e.jsxRuntimeExports.jsx(ye,{className:"size-5"})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>o("line"),variant:"ghost",children:e.jsxRuntimeExports.jsx(ve,{className:"size-5"})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>o("stackedBar"),variant:"ghost",children:e.jsxRuntimeExports.jsx(Qe,{className:"size-5",strokeWidth:0})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>o("scatter"),variant:"ghost",children:e.jsxRuntimeExports.jsx(Be,{className:"size-5"})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>o("bubble"),variant:"ghost",children:e.jsxRuntimeExports.jsx(Ue,{className:"size-4"})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>o("pie"),variant:"ghost",children:e.jsxRuntimeExports.jsx(Me,{className:"size-5"})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>o("doughnut"),variant:"ghost",children:e.jsxRuntimeExports.jsx(Ke,{className:"size-5",strokeWidth:1})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>o("radar"),variant:"ghost",children:e.jsxRuntimeExports.jsx(Pe,{className:"size-5 font-extralight",strokeWidth:.5})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>o("polarArea"),variant:"ghost",children:e.jsxRuntimeExports.jsx(Ge,{className:"size-5"})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>o("pyramid"),variant:"ghost",children:e.jsxRuntimeExports.jsx(We,{className:"size-5"})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>o("table"),variant:"ghost",children:e.jsxRuntimeExports.jsx(e.Table,{className:"size-5"})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>o("kpi"),variant:"ghost",children:e.jsxRuntimeExports.jsx(Je,{className:"size-6"})})]})})]})}function tt({chartType:s,className:n}){switch(s){case"bar":return e.jsxRuntimeExports.jsx(ye,{className:n});case"line":return e.jsxRuntimeExports.jsx(ve,{className:n});case"pie":return e.jsxRuntimeExports.jsx(Me,{className:n});case"radar":return e.jsxRuntimeExports.jsx(Pe,{className:n});case"scatter":return e.jsxRuntimeExports.jsx(Be,{className:n});case"bubble":return e.jsxRuntimeExports.jsx(Ue,{className:n});case"doughnut":return e.jsxRuntimeExports.jsx(Ke,{className:n});case"stackedBar":return e.jsxRuntimeExports.jsx(Qe,{className:"size-4 text-foreground/70"});case"polarArea":return e.jsxRuntimeExports.jsx(Ge,{className:n});case"pyramid":return e.jsxRuntimeExports.jsx(We,{className:n});case"kpi":return e.jsxRuntimeExports.jsx(Je,{className:n});default:return e.jsxRuntimeExports.jsx(e.Table,{className:n})}}function rt(){const s=e.useEditorStore(t=>t.card.refreshInterval),n=e.useEditorStore(t=>t.actions.setCardRefreshInterval);return e.jsxRuntimeExports.jsxs(e.Popover,{children:[e.jsxRuntimeExports.jsx(e.PopoverTrigger,{asChild:!0,children:e.jsxRuntimeExports.jsx(e.Button,{size:"sm",variant:"outline",children:e.jsxRuntimeExports.jsx(ls,{className:"w-4 h-4"})})}),e.jsxRuntimeExports.jsx(e.PopoverContent,{className:"w-[200px]",children:e.jsxRuntimeExports.jsx("div",{className:"grid gap-4",children:e.jsxRuntimeExports.jsx("div",{className:"grid gap-2",children:e.jsxRuntimeExports.jsxs("div",{className:"grid grid-cols-5 items-center gap-1",children:[e.jsxRuntimeExports.jsx(e.Label,{className:"col-span-3",htmlFor:"width",children:"Refresh Every"}),e.jsxRuntimeExports.jsx(e.Input,{value:s||"",onChange:t=>n(t.target.value),id:"width",placeholder:"30s",className:"col-span-2 h-7 focus-visible:ring-1 focus-visible:ring-ring focus-visible:ring-offset-0"})]})})})})]})}function Ie(){e.useEditorStore(o=>o.frame);const s=e.useEditorStore(o=>o.card),n=e.useEditorStore(o=>o.card.data),t=e.useEditorStore(o=>o.isShowingVisual),r=e.useEditorStore(o=>o.isSqlRunning),a=e.useEditorStore(o=>o.queryError),i=e.useEditorStore(o=>o.pythonStdOut);return e.useEditorStore(o=>o.onSave),e.useEditorStore(o=>o.onClose),e.useEditorStore(o=>o.actions.setCardSql),e.useEditorStore(o=>o.actions.setCardType),e.useEditorStore(o=>o.actions.setSqlGen),s?e.jsxRuntimeExports.jsxs("div",{className:"relative flex h-full flex-col pt-3",children:[r&&e.jsxRuntimeExports.jsx(e.LoaderCircle,{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:[t&&e.jsxRuntimeExports.jsxs("div",{className:"flex grow items-center gap-2",children:[e.jsxRuntimeExports.jsx(st,{}),s.type!=="table"&&e.jsxRuntimeExports.jsx(et,{}),e.jsxRuntimeExports.jsx(rt,{})]}),e.jsxRuntimeExports.jsx(ot,{})]}),t?s.type==="kpi"?e.jsxRuntimeExports.jsx("div",{className:"flex grow items-center justify-center",children:e.jsxRuntimeExports.jsx("div",{className:"w-1/2 rounded-md border",children:e.jsxRuntimeExports.jsx(e.KPICard,{isLoading:r,card:s})})}):e.jsxRuntimeExports.jsx($e,{className:"grow border-none shadow-none"}):e.jsxRuntimeExports.jsxs("div",{className:"flex min-h-0 w-full flex-1 grow basis-0 px-6",children:[i&&e.jsxRuntimeExports.jsx(nt,{}),s.data&&s.data.length>0&&e.jsxRuntimeExports.jsx(Zs,{data:n||[]}),a&&e.jsxRuntimeExports.jsx("span",{className:"font-mono text-sm",children:a})]})]}):e.jsxRuntimeExports.jsx(e.jsxRuntimeExports.Fragment,{children:"No Active Card"})}function nt(){const s=e.useEditorStore(t=>t.pythonStdOut);if(!s)return null;const n=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:n},className:"bg-muted p-2 font-mono text-sm"}),e.jsxRuntimeExports.jsx(e.Separator,{className:"mb-2"})]})}function ot(){const s=e.useEditorStore(t=>t.isShowingVisual),n=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:()=>n(!s),id:"visualize",className:"data-[state=checked]:bg-foreground/50"})]})}function ue(){const[s,n]=g.useState([]);e.useEditorStore(u=>u.card.cfg);const t=e.useEditorStore(u=>u.card.preferences),{setCardCfg:r,setFilterOnClickColumnIndex:a,setCardPreferences:i}=e.useEditorStore(u=>u.actions),o=e.useEditorStore(u=>u.queryResultColumns);e.useEditorStore(u=>{var d;return(d=u.card.preferences)==null?void 0:d.filterOnClickColumnIndex}),g.useEffect(()=>{o&&n(new Array(o.length).fill(!1))},[o]);function l(u,d){var y,x;d?t!=null&&t.onClickFilter&&((y=t==null?void 0:t.onClickFilter)==null?void 0:y.length)>0?i({...t,onClickFilter:[...t.onClickFilter,{columnIndex:u,expression:""}]}):i({...t,onClickFilter:[{columnIndex:u,expression:""}]}):(i({...t,onClickFilter:(x=t==null?void 0:t.onClickFilter)==null?void 0:x.filter(m=>m.columnIndex!==u)}),n(m=>{const j=[...m];return j[u]=!1,j}))}function c(u,d){var x;const y=(x=t==null?void 0:t.onClickFilter)==null?void 0:x.map(m=>m.columnIndex===u?{...m,expression:d.target.value}:m);i({...t,onClickFilter:y})}function h(u){var d,y,x,m;if(s!=null&&s[u]||(y=(d=t==null?void 0:t.onClickFilter)==null?void 0:d.find(j=>j.columnIndex===u))!=null&&y.expression)return e.jsxRuntimeExports.jsx(e.Input,{value:(m=(x=t==null?void 0:t.onClickFilter)==null?void 0:x.find(j=>j.columnIndex===u))==null?void 0:m.expression,onChange:j=>c(u,j),type:"text",className:" h-9 w-full focus-visible:ring-0 focus-visible:ring-ring focus-visible:ring-offset-0 font-mono text-xs",placeholder:"Expression"})}return e.jsxRuntimeExports.jsx(e.jsxRuntimeExports.Fragment,{children:o==null?void 0:o.map((u,d)=>{var y,x;return e.jsxRuntimeExports.jsx("div",{className:"flex items-center justify-between space-y-2 xbg-red-100 group",children:e.jsxRuntimeExports.jsxs("div",{className:" grow",children:[e.jsxRuntimeExports.jsxs("div",{className:"flex items-center py-2 space-x-2",children:[e.jsxRuntimeExports.jsx(e.Checkbox,{checked:!!((y=t==null?void 0:t.onClickFilter)!=null&&y.find(m=>m.columnIndex===d)),onCheckedChange:m=>l(d,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 gap-2 items-center ",children:((x=t==null?void 0:t.onClickFilter)==null?void 0:x.find(m=>m.columnIndex===d))&&e.jsxRuntimeExports.jsx(Oe,{onClick:()=>{n(m=>{const j=[...m];return j[d]=!m[d],j})},className:" invisible group-hover:visible size-3 text-gray-400 cursor-pointer"})})]}),h(d)]})},u)})})}function Ne(){var i,o;const s=e.useEditorStore(l=>l.card.preferences),n=e.useEditorStore(l=>l.card.cfg),{setCardCfg:t,setCardPreferences:r}=e.useEditorStore(l=>l.actions);(i=n==null?void 0:n.options)!=null&&i.indexAxis;function a(l){var u,d,y,x,m,j;let c={};(u=s==null?void 0:s.chartOptions)!=null&&u.scales&&(c={x:(y=(d=s==null?void 0:s.chartOptions)==null?void 0:d.scales)==null?void 0:y.y,y:(m=(x=s==null?void 0:s.chartOptions)==null?void 0:x.scales)==null?void 0:m.x});const h={...s,chartOptions:{...s==null?void 0:s.chartOptions,scales:{...(j=s==null?void 0:s.chartOptions)==null?void 0:j.scales,...c},indexAxis:l}};r(h)}return e.jsxRuntimeExports.jsxs(e.RadioGroup,{value:((o=s==null?void 0:s.chartOptions)==null?void 0:o.indexAxis)||"x",onValueChange:a,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 xe="focus-visible:ring-0 focus-visible:ring-ring focus-visible:ring-offset-0";function De(s,n){var r,a,i;const t=e.getNumberAxis(s,n);return((i=(a=(r=s==null?void 0:s.chartOptions)==null?void 0:r.scales)==null?void 0:a[t])==null?void 0:i.type)||"linear"}function Ye(){var q,$,H,M,I,b;const[s,n]=g.useState(!1),t=e.useEditorStore(S=>{var N;return(N=S.card)==null?void 0:N.preferences}),r=e.useEditorStore(S=>{var N;return(N=S.card)==null?void 0:N.cfg}),a=e.getNumberAxis(t,r),[i,o]=g.useState(De(t)),[l,c]=g.useState(((H=($=(q=t==null?void 0:t.chartOptions)==null?void 0:q.scales)==null?void 0:$[a])==null?void 0:H.min)||""),[h,u]=g.useState(((b=(I=(M=t==null?void 0:t.chartOptions)==null?void 0:M.scales)==null?void 0:I[a])==null?void 0:b.max)||""),[d,y]=g.useState(l||h?"custom":"auto"),[x,m]=g.useState(""),[j,E]=g.useState(0),[f,T]=g.useState(""),[w,k]=g.useState(""),[R,C]=g.useState(""),A=e.useEditorStore(S=>S.actions.setCardPreferences),D=e.useEditorStore(S=>{var N;return(N=S.card)==null?void 0:N.type}),_=["pie","doughnut","polarArea"].includes(D);g.useEffect(()=>{var S,N,L,Z,P,re,ne,oe,ee,B,G,U,ie,Q;o(De(t)),c(((L=(N=(S=t==null?void 0:t.chartOptions)==null?void 0:S.scales)==null?void 0:N[a])==null?void 0:L.min)===0?0:""),u(((re=(P=(Z=t==null?void 0:t.chartOptions)==null?void 0:Z.scales)==null?void 0:P[a])==null?void 0:re.max)||""),m(((B=(ee=(oe=(ne=t==null?void 0:t.chartOptions)==null?void 0:ne.scales)==null?void 0:oe[a])==null?void 0:ee.ticks)==null?void 0:B.stepSize)||""),E(((G=t==null?void 0:t.numberAxisFormat)==null?void 0:G.decimalPlaces)||0),T(((U=t==null?void 0:t.numberAxisFormat)==null?void 0:U.suffix)||""),k(((ie=t==null?void 0:t.numberAxisFormat)==null?void 0:ie.currency)||""),C(((Q=t==null?void 0:t.numberAxisFormat)==null?void 0:Q.locale)||"")},[s,t,a]);function F(S,N){return N===""||/^[0-9\b]+$/.test(N)?Number(N):Number(S)}function O(){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:w,placeholder:"USD",onChange:S=>k(S.target.value),id:"currency",className:`col-span-2 h-8 w-full ${xe}`}),e.jsxRuntimeExports.jsx(e.Input,{value:R,placeholder:"en-US",onChange:S=>C(S.target.value),id:"locale",className:`col-span-2 h-8 w-full ${xe}`})]}),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:j,onChange:S=>E(Number(S.target.value)),id:"format",className:`col-span-6 h-8 w-full tracking-wide ${xe}`})]})]})}function z(){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:l,onChange:S=>c(N=>F(N,S.target.value)),className:`col-span-1 h-8 w-full ${xe}`}),e.jsxRuntimeExports.jsx(e.Input,{value:h,onChange:S=>u(N=>F(N,S.target.value)),id:"max",className:`col-span-1 h-8 w-full ${xe}`})]}),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:x,onChange:S=>m(N=>F(N,S.target.value)),id:"step-size",className:`col-span-1 h-8 w-full ${xe}`})]})]})}function K(){var L;let S={};d==="custom"&&(S={min:l,max:h,ticks:{stepSize:x}});const N={...t||{},chartOptions:{...t==null?void 0:t.chartOptions,scales:{...(L=t==null?void 0:t.chartOptions)==null?void 0:L.scales,[a]:{type:i,...i==="linear"?S:{}}}},numberAxisFormat:{decimalPlaces:j,suffix:f,currency:w,locale:R}};A(N)}return e.jsxRuntimeExports.jsxs(e.Popover,{onOpenChange:S=>n(S),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:_,value:i,onValueChange:S=>o(S),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"})]})})]})]}),i=="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:_,id:"scale-option",value:d,onValueChange:S=>y(S),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"})]})]})]}),d==="custom"&&i=="linear"&&z(),O(),e.jsxRuntimeExports.jsx(e.SelectSeparator,{}),e.jsxRuntimeExports.jsx("div",{className:"grid grid-cols-3",children:e.jsxRuntimeExports.jsx(e.Button,{onClick:K,variant:"secondary",className:"col-span-1 col-start-3 h-8 w-full",children:"Apply"})})]})]})})]})}function it({idx:s}){var l;const n=e.useEditorStore(c=>{var h;return(h=c.card)==null?void 0:h.preferences}),t=e.useEditorStore(c=>{var h;return(h=c.card.preferences)==null?void 0:h.datasetOptions}),r=e.useEditorStore(c=>c.actions.setCardPreferences),a=(l=n==null?void 0:n.chartOptions)==null?void 0:l.indexAxis,i=t==null?void 0:t.find(c=>c.idx===s);function o(c,h){(c==="end"||c==="start")&&e.getContrastColor(e.getCanvasBackgroundColor());const u={display:c!=="none",align:c,anchor:c,clamp:!0};if(!i)r({...n,datasetOptions:[...t||[],{idx:h,datalabels:u}]});else{const d={...i};d.datalabels=u;const y=t==null?void 0:t.map(x=>x.idx===h?d:x);r({...n,datasetOptions:y})}}return e.jsxRuntimeExports.jsxs(e.Popover,{children:[e.jsxRuntimeExports.jsx(e.PopoverTrigger,{children:e.jsxRuntimeExports.jsx(ws,{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(Es,{className:e.cn("h-4 w-4",{"rotate-90":a==="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(gs,{className:e.cn("h-4 w-4",{"rotate-90":a==="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(fs,{className:e.cn("h-4 w-4",{"rotate-90":a==="y"})})})]})})]})}function Xe(){const s=e.useEditorStore(c=>c.card),n=e.useEditorStore(c=>{var h,u,d;return(d=(u=(h=c==null?void 0:c.card)==null?void 0:h.preferences)==null?void 0:u.chartOptions)==null?void 0:d.indexAxis}),t=n==="y"?"Y axis":"X axis",r=n==="y"?"X axis":"Y axis",{keys:a,metricKeys:i,dimensionKeys:o}=e.getKeys(s.data||[]);let l=i;if(s.type==="stackedBar"){const c=e.pivotData({dataArray:s.data||[],groupKey:o[0],pivotKey:o[1],valueKey:l[0]}),{metricKeys:h}=e.getKeys(c);l=h}return a.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:r}),e.jsxRuntimeExports.jsx(Ye,{})]}),e.jsxRuntimeExports.jsx("div",{className:"my-1 space-y-1",children:l.map((c,h)=>e.jsxRuntimeExports.jsx(at,{col:c,idx:h},c))})]})]})}function at({col:s,idx:n}){const t=e.useEditorStore(l=>{var c;return(c=l.card)==null?void 0:c.preferences}),r=e.useEditorStore(l=>{var c;return(c=l.card.preferences)==null?void 0:c.datasetOptions}),a=r==null?void 0:r.find(l=>l.idx===n),{setCardPreferences:i}=e.useEditorStore(l=>l.actions);function o(l){if(!a)i({...t,datasetOptions:[...r||[],{idx:n,type:l==="area"?"line":l,fill:l==="area"?"origin":""}]});else{const c={...a};c.type=l==="area"?"line":l,c.fill=l==="area"?"origin":"";const h=r==null?void 0:r.map(u=>u.idx===n?c:u);i({...t,datasetOptions:h})}}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(ye,{onClick:()=>o("bar"),className:"invisible size-4 cursor-pointer text-muted-foreground hover:text-foreground group-hover:visible"}),e.jsxRuntimeExports.jsx(ve,{onClick:()=>o("line"),className:"invisible size-4 cursor-pointer text-muted-foreground hover:text-foreground group-hover:visible"}),e.jsxRuntimeExports.jsx(cs,{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(it,{idx:n})]})]})}function lt({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:n=>n.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(Ne,{}),e.jsxRuntimeExports.jsx(Xe,{})]})]}),e.jsxRuntimeExports.jsxs(e.AccordionItem,{value:"item-3",children:[e.jsxRuntimeExports.jsx(e.AccordionTrigger,{children:"Filter on click"}),e.jsxRuntimeExports.jsx(e.AccordionContent,{className:"px-2",children:e.jsxRuntimeExports.jsx(ue,{})})]})]})})}function ke(){var a,i,o;const s=e.useEditorStore(l=>l.card.cfg),n=e.useEditorStore(l=>l.actions.setCardCfg),t=e.useEditorStore(l=>l.card.type);function r(l){var u;const c={datalabels:{display:l!=="none",align:l,anchor:l,clamp:!0}},h={...s,options:{...s==null?void 0:s.options,plugins:{...(u=s==null?void 0:s.options)==null?void 0:u.plugins,...c}}};n(h),console.log(l)}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"}),t!=="pyramid"&&e.jsxRuntimeExports.jsx(Ye,{})]}),e.jsxRuntimeExports.jsxs(e.Select,{value:(o=(i=(a=s==null?void 0:s.options)==null?void 0:a.plugins)==null?void 0:i.datalabels)==null?void 0:o.anchor,onValueChange:r,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 ct({cardType:s}){function n(t){const r="SELECT label, [group], x-axis, y-axis, radius FROM table",a="SELECT label, [group], x-axis, y-axis FROM table";return e.jsxRuntimeExports.jsxs(e.jsxRuntimeExports.Fragment,{children:[e.jsxRuntimeExports.jsx("div",{className:"bg-muted px-2 py-1 rounded text-xs",children:t==="bubble"?r:a}),e.jsxRuntimeExports.jsxs("ul",{className:" ml-6 list-disc [&>li]:mt-2 text-xs",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:i=>i.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:"px-6 py-2 space-y-6",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:n(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(ke,{})})]}),e.jsxRuntimeExports.jsxs(e.AccordionItem,{value:"item-3",children:[e.jsxRuntimeExports.jsx(e.AccordionTrigger,{children:"Filter on click"}),e.jsxRuntimeExports.jsx(e.AccordionContent,{className:"px-2",children:e.jsxRuntimeExports.jsx(ue,{})})]})]})})}const xt={datasets:[{type:"line",label:"Sum_sales",data:[]},{type:"bar",label:"Sum_profit",data:[]}]},ut={datasets:[{fill:"origin",type:"line",label:"Sum_sales",data:[]}]};function dt(){const s=e.useEditorStore(n=>n.card.type);return e.jsxRuntimeExports.jsxs("div",{className:"p-6 space-y-6",children:[e.jsxRuntimeExports.jsx(e.Accordion,{className:" ",type:"single",collapsible:!0,children:mt(s)}),e.jsxRuntimeExports.jsx("section",{className:"",children:["line","bar"].includes(s)&&e.jsxRuntimeExports.jsx(Ne,{})}),e.jsxRuntimeExports.jsx("div",{children:!["kpi"].includes(s)&&e.jsxRuntimeExports.jsx(ke,{})}),e.jsxRuntimeExports.jsx("div",{children:!["kpi"].includes(s)&&e.jsxRuntimeExports.jsx(ue,{})})]})}function mt(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:"bg-muted px-2 py-1 rounded font-mono font-semibold text-xs",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 [&>li]:mt-2 font-normal text-xs",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:" text-xs space-y-2",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(xt,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:" text-xs space-y-2",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:"text-blue-500 hover:underline mx-1",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(ut,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:"bg-muted px-2 py-1 rounded font-mono font-semibold text-xs",children:"SELECT label, x-axis, y-axis, radius FROM table"}),e.jsxRuntimeExports.jsxs("ul",{className:"my-6 ml-6 list-disc [&>li]:mt-2 font-normal text-xs",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:"bg-muted px-2 py-1 rounded font-mono font-semibold text-xs",children:"SELECT label, x-axis, y-axis FROM table"}),e.jsxRuntimeExports.jsxs("ul",{className:"my-6 ml-6 list-disc [&>li]:mt-2 font-normal text-xs",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:"bg-muted px-2 py-1 rounded font-mono font-semibold text-xs",children:"SELECT label, measure FROM table"}),e.jsxRuntimeExports.jsxs("ul",{className:"my-6 ml-6 list-disc [&>li]:mt-2 font-normal text-xs",children:[e.jsxRuntimeExports.jsx("li",{children:"Label - Category (ex. city)"}),e.jsxRuntimeExports.jsx("li",{children:"Measure - Number (ex. population)"})]})]})]})})}function pt(){var c,h,u,d,y;const s=e.useEditorStore(x=>x.card.preferences),n=e.useEditorStore(x=>x.actions.setCardPreferences),t=e.useEditorStore(x=>x.actions.setNumberFormat);e.useEditorStore(x=>{var m,j;return(j=(m=x.card.preferences)==null?void 0:m.formatNumber)==null?void 0:j.decimalPlaces});const r=e.useEditorStore(x=>{var m,j;return(j=(m=x.card.preferences)==null?void 0:m.formatNumber)==null?void 0:j.locale}),a=e.useEditorStore(x=>{var m,j;return(j=(m=x.card.preferences)==null?void 0:m.formatNumber)==null?void 0:j.currency});e.useEditorStore(x=>x.actions.setFilterOnClickField);const i=e.useEditorStore(x=>{var m,j;return(j=(m=x.card.preferences)==null?void 0:m.formatNumber)==null?void 0:j.colorRanges})||[],o=e.useEditorStore(x=>x.actions.setColorRanges),l=[...new Set(e.LOCALE_CURRENCY_PAIRS.map(x=>x.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:!!((c=s==null?void 0:s.formatNumber)!=null&&c.enabled),onCheckedChange:x=>{n({...s,formatNumber:{...s==null?void 0:s.formatNumber,enabled:x}})}}),e.jsxRuntimeExports.jsx(e.Label,{children:"Format Number"})]}),((h=s==null?void 0:s.formatNumber)==null?void 0:h.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:r||"en-US",onValueChange:x=>{var m,j,E;return t(((m=s==null?void 0:s.formatNumber)==null?void 0:m.decimalPlaces)||0,((j=s==null?void 0:s.formatNumber)==null?void 0:j.currency)||"",x||"en-US",((E=s==null?void 0:s.formatNumber)==null?void 0:E.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(x=>e.jsxRuntimeExports.jsx(e.SelectItem,{value:x.locale,children:x.locale},x.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:a||"none",onValueChange:x=>{var m,j,E;return t(((m=s==null?void 0:s.formatNumber)==null?void 0:m.decimalPlaces)||0,x==="none"?"":x,((j=s==null?void 0:s.formatNumber)==null?void 0:j.locale)||"",((E=s==null?void 0:s.formatNumber)==null?void 0:E.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"),l.map(x=>e.jsxRuntimeExports.jsx(e.SelectItem,{value:x,children:x},x))]})})]})]})]}),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:((d=(u=s==null?void 0:s.formatNumber)==null?void 0:u.decimalPlaces)==null?void 0:d.toString())||"0",onValueChange:x=>{var m,j,E;return t(Number(x),((m=s==null?void 0:s.formatNumber)==null?void 0:m.currency)||"",((j=s==null?void 0:s.formatNumber)==null?void 0:j.locale)||"",((E=s==null?void 0:s.formatNumber)==null?void 0:E.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(x=>e.jsxRuntimeExports.jsx(e.SelectItem,{value:x,children:x},x))})]})]}),e.jsxRuntimeExports.jsxs("div",{className:"w-full space-y-1",children:[e.jsxRuntimeExports.jsx(e.Label,{children:"Suffix"}),e.jsxRuntimeExports.jsx(e.Input,{value:((y=s==null?void 0:s.formatNumber)==null?void 0:y.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:x=>{var m,j,E;return t(((m=s==null?void 0:s.formatNumber)==null?void 0:m.decimalPlaces)||0,((j=s==null?void 0:s.formatNumber)==null?void 0:j.currency)||"",((E=s==null?void 0:s.formatNumber)==null?void 0:E.locale)||"",x.target.value)}})]})]})]})}),e.jsxRuntimeExports.jsx(e.Separator,{className:"my-3"}),e.jsxRuntimeExports.jsx(e.ColorFormat,{colorRanges:i,setColorRanges:o})]})]})}function ht(){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(pt,{})}),e.jsxRuntimeExports.jsx("div",{}),e.jsxRuntimeExports.jsx("div",{})]})}function Le({cardType:s,docContent:n}){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,{children:n||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:t=>t.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.jsx(e.AccordionContent,{className:"px-2",children:e.jsxRuntimeExports.jsx(ke,{})})]}),e.jsxRuntimeExports.jsxs(e.AccordionItem,{value:"item-3",children:[e.jsxRuntimeExports.jsx(e.AccordionTrigger,{children:"Filter on click"}),e.jsxRuntimeExports.jsx(e.AccordionContent,{className:"px-2",children:e.jsxRuntimeExports.jsx(ue,{})})]})]})})}function jt(){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(Ne,{}),e.jsxRuntimeExports.jsx(Xe,{})]})]}),e.jsxRuntimeExports.jsxs(e.AccordionItem,{value:"item-3",children:[e.jsxRuntimeExports.jsx(e.AccordionTrigger,{children:"Filter on click"}),e.jsxRuntimeExports.jsx(e.AccordionContent,{className:"px-2",children:e.jsxRuntimeExports.jsx(ue,{})})]})]})})}function Et({}){return e.jsxRuntimeExports.jsx("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:"Filter on click"}),e.jsxRuntimeExports.jsx(e.AccordionContent,{className:"px-2",children:e.jsxRuntimeExports.jsx(ue,{})})]})})})}const ft=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."]})]});function gt(){const s=e.useEditorStore(t=>t.card.type);function n(t){switch(t){case"stackedBar":return e.jsxRuntimeExports.jsx(jt,{});case"pyramid":return e.jsxRuntimeExports.jsx(Le,{docContent:ft,cardType:t});case"kpi":return e.jsxRuntimeExports.jsx(ht,{});case"line":case"bar":return e.jsxRuntimeExports.jsx(lt,{cardType:t});case"pie":case"doughnut":case"polarArea":case"radar":return e.jsxRuntimeExports.jsx(Le,{cardType:t});case"bubble":case"scatter":return e.jsxRuntimeExports.jsx(ct,{cardType:t});case"table":return e.jsxRuntimeExports.jsx(Et,{cardType:t});default:return e.jsxRuntimeExports.jsx(dt,{})}}return e.jsxRuntimeExports.jsx(e.ScrollArea,{className:"h-full w-full text-sm",children:n(s)})}function Rt(){const s=e.useEditorStore(n=>n.isShowingVisual);return e.jsxRuntimeExports.jsxs(e.ResizablePanelGroup,{direction:"vertical",className:"min-w-full max-w-lg min-h-[250px]",children:[e.jsxRuntimeExports.jsx(e.ResizablePanel,{role:"query-section",className:"flex",minSize:20,defaultSize:40,children:e.jsxRuntimeExports.jsx(Xs,{})}),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(gt,{})})}),e.jsxRuntimeExports.jsx(e.ResizableHandle,{className:"border "}),e.jsxRuntimeExports.jsx(e.ResizablePanel,{minSize:40,defaultSize:75,maxSize:100,children:e.jsxRuntimeExports.jsx(Ie,{})})]}):e.jsxRuntimeExports.jsx(Ie,{})})]})}function bt({authToken:s,onSave:n,onClose:t}){const r=e.useEditorStore(o=>o.actions.setOnSave),a=e.useEditorStore(o=>o.actions.setOnClose),i=e.useDashboardStore(o=>o.actions.setAuthToken);return g.useEffect(()=>{n&&r(n),t&&a(t)},[n,r,t,a]),g.useEffect(()=>{s&&s.accessToken&&i(s)},[s,i]),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(Ve,{})}),e.jsxRuntimeExports.jsx(e.EditorMain,{children:e.jsxRuntimeExports.jsx(Rt,{})})]})}function St(){e.useDashboardStore(o=>o.selectedCardId);const s=e.useDashboardStore(o=>o.selectedSheetId),{setIsVisualEditing:n}=e.useDashboardStore(o=>o.actions),t=e.useDashboardStore(o=>o.isVisualEditing),r=e.useDashboardStore(o=>o.actions.updateFrame);function a(o){s&&(r(s,o),n(!1))}function i(){n(!1)}return e.jsxRuntimeExports.jsx("div",{role:"editor-container",className:e.cn("flex grow",{block:t,hidden:!t}),children:e.jsxRuntimeExports.jsx(bt,{onSave:a,onClose:i})})}function yt({columns:s,tableName:n}){const t=e.useEditorStore(d=>d.selectedConnectionId),r=e.useEditorStore(d=>d.selectedDatabaseName),a=e.useEditorStore(d=>d.selectedSchemaName),i=e.useEditorStore(d=>d.selectedTableName),o=e.useDashboardStore(d=>d.dashboard.filters)||[],l=e.useDashboardStore(d=>d.actions.addFilter),c=e.useDashboardStore(d=>d.actions.removeFilter),h=e.useDashboardStore(d=>d.actions.removeFilterValue);function u(d){const y=e.fmt(d.column_name),x=e.fmt(r||""),m=e.fmt(a||""),j=e.fmt(n),E=e.getQualifiedTableName(m,j),f=`${E}.${y}`;console.log("find",f,j,x);const T=o==null?void 0:o.find(w=>w.column===f&&w.table===j&&(w.database===x||w.database===r));if(T)h(T.id),c(T.id);else{if(n==="api"&&t){l({id:e.v4(),column:f,title:d.column_name,dataType:d.data_type,table:"api",database:"",connectionId:t,operation:"in",sql:e.getDefaultFilterSql(d.data_type,E,y)});return}l({id:e.v4(),column:`${E}.${y}`,title:d.column_name,dataType:d.data_type,table:i||"",database:r||"",connectionId:t||"",operation:"in",sql:e.getDefaultFilterSql(d.data_type,E,y)})}}return e.jsxRuntimeExports.jsx("div",{className:"xbg-red-100 flex-1 basis-0 flex-col overflow-scroll px-3",children:s==null?void 0:s.map(d=>{const y=o==null?void 0:o.find(x=>x.column===e.fmt(d.column_name)&&x.table===i&&x.database===r);return e.jsxRuntimeExports.jsx("div",{onClick:()=>u(d),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":y}),children:e.jsxRuntimeExports.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxRuntimeExports.jsx(qe,{column:d}),e.jsxRuntimeExports.jsx("span",{children:d.column_name})]})},d.column_name)})})}function vt(){e.useDashboardStore(n=>n.showFilters);const s=e.useDashboardStore(n=>n.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(Ve,{ColumnsComponent:(n,t,r)=>e.jsxRuntimeExports.jsx(yt,{schemaName:n,tableName:t,columns:r})})})]})}function Ct(){e.useDashboardStore(t=>t.dashboard);const s=e.useDashboardStore(t=>t.showFilters),n=e.useDashboardStore(t=>t.isVisualEditing);return e.useDashboardStore(t=>t.bookmarkKey),e.jsxRuntimeExports.jsxs("div",{role:"dashboard-plus-main",className:e.cn("grow",{hidden:n,flex:!n}),children:[e.jsxRuntimeExports.jsx(e.DashboardTabs,{}),s&&e.jsxRuntimeExports.jsx("div",{role:"filter-aside-container",className:"flex",children:e.jsxRuntimeExports.jsx(vt,{})})]})}function Nt(){const s=e.useDashboardStore(r=>r.dashboard),n=e.useDashboardStore(r=>r.actions.setDashboard),t=e.useDashboardStore(r=>r.showDashboardJSON);return e.useDashboardStore(r=>r.actions.setShowDashboardJSON),e.jsxRuntimeExports.jsx("div",{className:e.cn(" p-2",{hidden:!t}),children:e.jsxRuntimeExports.jsx(e.de,{onChange:r=>{if(r)try{JSON.parse(r),n(JSON.parse(r))}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 kt({showControls:s=!1,showFooter:n=!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(Nt,{}),e.jsxRuntimeExports.jsxs(e.DashboardPanel,{...t,children:[s&&e.jsxRuntimeExports.jsx(Fs,{}),e.jsxRuntimeExports.jsx(St,{}),e.jsxRuntimeExports.jsx(Ct,{})]})]})]})}exports.DashboardPlus=kt;exports.SelectComponent=he;exports.useEditorAside=Ce;
205
+ Visual Query Syntax: ${Hs}`,{data:C,isLoading:A,isFetching:D,isError:_,refetch:F}=e.useQuery({queryKey:["ai-query"],queryFn:()=>e.getRequest("https://semaphor.cloud/api/v1/ai",(c==null?void 0:c.accessToken)||"",{user_content:`userContent: ${k} ${h?R:""}`}),enabled:!1});function O(b){if(b.toLowerCase().includes("bar"))m("bar");else if(b.toLowerCase().includes("line"))m("line");else if(b.toLowerCase().includes("bubble"))m("bubble");else if(b.toLowerCase().includes("scatter"))m("scatter");else if(b.toLowerCase().includes("stacked"))m("stackedBar");else if(b.toLowerCase().includes("pie"))m("pie");else if(b.toLowerCase().includes("donut")||b.toLowerCase().includes("doughnut"))m("doughnut");else if(b.toLowerCase().includes("radar"))m("radar");else return m("bar"),!1;return!0}g.useEffect(()=>{C&&E(b=>[...b,{role:"ai",content:C.response}])},[C]),g.useEffect(()=>{const b=setTimeout(()=>{var S;l.current&&(l.current.scroll({top:l.current.scrollHeight,behavior:"smooth"}),(S=o.current)==null||S.focus())},100);return()=>clearTimeout(b)},[j]);function z(){t&&(E(b=>[...b,{role:"user",content:t}]),O(t)&&u(!0),r(""),F())}g.useEffect(()=>{i&&(z(),a(!1))},[i,a]);const K={fontFamily:"Arial, sans-serif",lineHeight:1.6,fontSize:15,width:"100%"},q={fontFamily:"monospace",fontSize:14,lineHeight:1.6},P={fontFamily:"Arial, sans-serif",lineHeight:1.6,fontSize:15,padding:"2px 0",marginLeft:20,listStyleType:"disc"},H={p:({node:b,...S})=>e.jsxRuntimeExports.jsx("p",{style:K,...S}),code:({node:b,...S})=>e.jsxRuntimeExports.jsx("code",{className:"rounded-sm bg-muted px-2 py-1 text-sm",...S}),pre:({node:b,...S})=>e.jsxRuntimeExports.jsxs("pre",{className:"space-y-2 rounded-sm bg-muted/50 p-3",style:q,children:[e.jsxRuntimeExports.jsx("code",{className:"whitespace-normal text-sm",children:S.children}),e.jsxRuntimeExports.jsxs("div",{className:"flex justify-start gap-2",children:[e.jsxRuntimeExports.jsx(e.Button,{onClick:M,size:"sm",variant:"outline",children:e.jsxRuntimeExports.jsx(e.ClipboardCopyIcon,{})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:N=>{const L=M(N);L&&(n(!1),d(L),x(!0))},size:"sm",variant:"outline",children:e.jsxRuntimeExports.jsx(e.PlayIcon,{})})]})]}),li:({node:b,...S})=>e.jsxRuntimeExports.jsx("li",{style:P,...S})};function M(b){const S=b.currentTarget.closest("pre");if(!S)return;const N=S.textContent||S.innerText;return navigator.clipboard.writeText(N).then(()=>console.log("Text copied to clipboard")).catch(L=>console.error("Error in copying text: ",L)),N}function I(){return j==null?void 0:j.map((b,S)=>b.role==="user"?e.jsxRuntimeExports.jsxs("div",{className:"flex items-start rounded-md bg-muted p-3 text-sm",children:[e.jsxRuntimeExports.jsx(zs,{className:"mr-2 h-5 w-5"}),e.jsxRuntimeExports.jsx("div",{children:b.content})]},S):b.role==="ai"?e.jsxRuntimeExports.jsx(e.Markdown,{className:"w-full overflow-auto py-1",components:H,children:C==null?void 0:C.response.replace(/DuckDB/gi,"Semaphor")},S):e.jsxRuntimeExports.jsx("div",{},S))}return e.jsxRuntimeExports.jsxs(e.Dialog,{open:s,onOpenChange:n,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:l,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:I()})}),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:b=>{b.key==="Enter"&&!b.shiftKey&&(b.preventDefault(),r(""),z())},placeholder:"Type your question here...",onFocus:b=>{const S=b.target,N=S.value.length;S.setSelectionRange(N,N)},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:A||D,value:t,onChange:b=>r(b.target.value)})," ",e.jsxRuntimeExports.jsx(e.Button,{className:"h-8",size:"sm",variant:"ghost",onClick:z,children:!A&&!D?e.jsxRuntimeExports.jsx(e.PaperPlaneIcon,{}):e.jsxRuntimeExports.jsx(e.LoaderCircle,{className:"mr-2 h-4 w-4 animate-spin text-foreground/50"})})]})})]})]})}var _e={color:void 0,size:void 0,className:void 0,style:void 0,attr:void 0},Te=g.createContext&&g.createContext(_e),$s=["attr","size","title"];function Ks(s,n){if(s==null)return{};var t=Gs(s,n),r,i;if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(s);for(i=0;i<a.length;i++)r=a[i],!(n.indexOf(r)>=0)&&Object.prototype.propertyIsEnumerable.call(s,r)&&(t[r]=s[r])}return t}function Gs(s,n){if(s==null)return{};var t={},r=Object.keys(s),i,a;for(a=0;a<r.length;a++)i=r[a],!(n.indexOf(i)>=0)&&(t[i]=s[i]);return t}function Ee(){return Ee=Object.assign?Object.assign.bind():function(s){for(var n=1;n<arguments.length;n++){var t=arguments[n];for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&(s[r]=t[r])}return s},Ee.apply(this,arguments)}function ze(s,n){var t=Object.keys(s);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(s);n&&(r=r.filter(function(i){return Object.getOwnPropertyDescriptor(s,i).enumerable})),t.push.apply(t,r)}return t}function fe(s){for(var n=1;n<arguments.length;n++){var t=arguments[n]!=null?arguments[n]:{};n%2?ze(Object(t),!0).forEach(function(r){Us(s,r,t[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(s,Object.getOwnPropertyDescriptors(t)):ze(Object(t)).forEach(function(r){Object.defineProperty(s,r,Object.getOwnPropertyDescriptor(t,r))})}return s}function Us(s,n,t){return n=Qs(n),n in s?Object.defineProperty(s,n,{value:t,enumerable:!0,configurable:!0,writable:!0}):s[n]=t,s}function Qs(s){var n=Js(s,"string");return typeof n=="symbol"?n:String(n)}function Js(s,n){if(typeof s!="object"||s===null)return s;var t=s[Symbol.toPrimitive];if(t!==void 0){var r=t.call(s,n||"default");if(typeof r!="object")return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return(n==="string"?String:Number)(s)}function He(s){return s&&s.map((n,t)=>g.createElement(n.tag,fe({key:t},n.attr),He(n.child)))}function te(s){return n=>g.createElement(Ws,Ee({attr:fe({},s.attr)},n),He(s.child))}function Ws(s){var n=t=>{var{attr:r,size:i,title:a}=s,o=Ks(s,$s),l=i||t.size||"1em",c;return t.className&&(c=t.className),s.className&&(c=(c?c+" ":"")+s.className),g.createElement("svg",Ee({stroke:"currentColor",fill:"currentColor",strokeWidth:"0"},t.attr,r,o,{className:c,style:fe(fe({color:s.color||t.color},t.style),s.style),height:l,width:l,xmlns:"http://www.w3.org/2000/svg"}),a&&g.createElement("title",null,a),s.children)};return Te!==void 0?g.createElement(Te.Consumer,null,t=>n(t)):n(_e)}function Ys(s){return te({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 Xs(){const{theme:s}=e.useTheme(),n=g.useRef(),t=g.useRef(),[r,i]=g.useState(!1),[a,o]=g.useState(!1),[l,c]=g.useState(!1),[h,u]=g.useState(""),[d,y]=g.useState(!1),{authToken:x}=e.useSemaphorContext();e.useDashboardStore(p=>p.selectedSheetId);const m=e.useDashboardStore(p=>p.dashboard.baseQueries),j=e.useEditorStore(p=>p.card),E=e.useDashboardStore(p=>p.theme),f=e.useEditorStore(p=>p.isShowingVisual),T=e.useEditorStore(p=>p.selectedConnectionId),w=e.useEditorStore(p=>p.selectedDatabaseName),k=e.useEditorStore(p=>p.selectedSchemaName);e.useDashboardStore(p=>p.actions.updateFrameCard);const R=e.useEditorStore(p=>p.selectedTableName),C=e.useEditorStore(p=>p.card.sql),A=e.useEditorStore(p=>p.card.python),D=e.resolveBaseQuery(C,m),_=e.useEditorStore(p=>p.selectedConnectionId),F=e.useEditorStore(p=>p.frame),O=e.useEditorStore(p=>p.filterValues),z=e.useEditorStore(p=>p.applyFilters),{setCardCustomCfg:K,setQueryResultColumns:q,setFilterValues:P,setCardSql:H,setCardPython:M,setQueryError:I,setPythonStdOut:b,setCardPreferences:S}=e.useEditorStore(p=>p.actions),N=e.useEditorStore(p=>p.onSave),L=e.useEditorStore(p=>p.actions.setApplyFilters),Z=e.useEditorStore(p=>p.onClose),$=e.useEditorStore(p=>p.actions.setCardData),re=e.useEditorStore(p=>p.actions.setSqlGen),ne=e.useEditorStore(p=>p.runSql),oe=e.useEditorStore(p=>p.actions.setRunSql),ee=e.useEditorStore(p=>p.actions.setIsSqlRunning),{data:B,isLoading:G,isFetching:U,isSuccess:ie,isError:Q,error:de,status:ge,refetch:ae}=e.useQuery({queryKey:[D,A],queryFn:()=>e.postRequest("https://semaphor.cloud/api/v1/query",(x==null?void 0:x.accessToken)||"",{connection_id:_,sql:D,python:A===e.PYTHON_DEFAULT_CODE?"":A,active_filters:z?O:[]}),enabled:!1,retry:!1});g.useEffect(()=>{if(B&&($(B.records),b((B==null?void 0:B.output)||""),B.records.length>0)){const{dimensionKeys:p}=e.getKeys(B.records);q(p)}},[B,$,q,b]),g.useEffect(()=>{ne&&(ae(),oe(!1))},[ne,ae,oe]),g.useEffect(()=>{(G||U)&&ee(!0),(Q||ie)&&ee(!1),Q?(I(de.message),$([]),q([]),b("")):I("")},[G,U,B,b,Q,ie,ee,$,q,I,de]);function je(){H(""),$([]),re({}),K(""),S({})}const me=p=>{t.current=p};function v(){let p=C;C&&!C.includes("{{")&&(p=Bs(C),H(p));const J={...j,lastSelectedSchema:k,lastSelectedDatabase:w,lastSelectedTable:R,connectionId:T,type:f?j.type:"table",sql:p,customCfg:f?j.customCfg:null},pe=F.cards.map(le=>le.id===j.id?J:le);N==null||N({...F,cards:pe})}function Ze(){Z==null||Z()}function es(p){const J=getComputedStyle(document.documentElement).getPropertyValue(p);return ss(J)}function ss(p){const[J,pe,le]=p.split(" "),V=parseFloat(J),ns=parseFloat(pe),os=parseFloat(le),is=ns/100,Ae=os/100,se=(1-Math.abs(2*Ae-1))*is,ce=se*(1-Math.abs(V/60%2-1)),Re=Ae-se/2;let W=0,Y=0,X=0;0<=V&&V<60?(W=se,Y=ce,X=0):60<=V&&V<120?(W=ce,Y=se,X=0):120<=V&&V<180?(W=0,Y=se,X=ce):180<=V&&V<240?(W=0,Y=ce,X=se):240<=V&&V<300?(W=ce,Y=0,X=se):300<=V&&V<360&&(W=se,Y=0,X=ce),W=Math.round((W+Re)*255),Y=Math.round((Y+Re)*255),X=Math.round((X+Re)*255);const be=as=>{const Se=as.toString(16);return Se.length==1?"0"+Se:Se};return`#${be(W)}${be(Y)}${be(X)}`}g.useEffect(()=>{const p=n.current,J=t.current;if(p){const pe=window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light",le=E==="system"?pe:E;p.editor.defineTheme("default",{base:le==="light"?"vs":"vs-dark",inherit:!0,rules:[],colors:{"editor.background":le==="light"?"#ffffff":es("--background")}}),p.editor.setTheme("default")}return J&&p&&J.addCommand(p.KeyMod.Shift|p.KeyCode.Enter,function(){return console.log("Executing query..."),ae(),!1}),()=>{}},[s,E,n.current]);function we(p){n.current=p}function ts(){return e.jsxRuntimeExports.jsxs(e.jsxRuntimeExports.Fragment,{children:[a&&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(Vs,{checked:z,onCheckedChange:()=>L(!z),text:"Apply Filters"}),e.jsxRuntimeExports.jsx(_s,{}),O&&a&&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),P(JSON.parse(p))}catch{}},defaultLanguage:"json",className:"mt-1 min-h-[220px]",value:JSON.stringify(O,null,2),options:{readOnly:!0,minimap:{enabled:!1},lineNumbers:"off",glyphMargin:!1,wordWrap:"on",scrollbar:{verticalScrollbarSize:0,horizontalScrollbarSize:0},fontSize:12,renderLineHighlight:"none"}})]})}),O&&!a&&e.jsxRuntimeExports.jsx(Fe,{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":z})})]})}function rs(){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:r?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=>{H(p)},value:C,options:{minimap:{enabled:!1},wordWrap:"on",scrollbar:{verticalScrollbarSize:0,horizontalScrollbarSize:0},fontSize:14,renderLineHighlight:"none"},defaultLanguage:"sql",defaultValue:"SELECT * FROM table",beforeMount:we,onMount:me})}),r&&e.jsxRuntimeExports.jsx("code",{className:"absolute right-6 top-3 text-sm text-muted-foreground/70",children:"sql"})]}),r&&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=>{M(p&&p.trim()||"")},value:A||e.PYTHON_DEFAULT_CODE,options:{minimap:{enabled:!1},wordWrap:"on",scrollbar:{verticalScrollbarSize:0,horizontalScrollbarSize:0},fontSize:14,renderLineHighlight:"none"},defaultLanguage:"python",beforeMount:we,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:[rs(),ts()]}),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:G||U,onClick:()=>{ae()},className:"shrink-0",size:"sm",variant:"outline",children:[G||U?e.jsxRuntimeExports.jsx(e.LoaderCircle,{className:"mr-2 h-4 w-4 animate-spin text-foreground/50"}):e.jsxRuntimeExports.jsx(Ss,{className:"mr-2 h-4 w-4"}),"Run"]}),Q&&e.jsxRuntimeExports.jsx(qs,{error:de.message,setShowAIDialog:c,setTriggerAIRun:y,setUserInputforAI:u}),e.jsxRuntimeExports.jsxs(e.Button,{onClick:je,className:"",size:"sm",variant:"outline",children:[e.jsxRuntimeExports.jsx(ds,{className:"mr-2 size-4"}),"Clear"]}),e.jsxRuntimeExports.jsx(e.Toggle,{pressed:r,onPressedChange:p=>i(p),className:"",size:"sm",variant:"outline",children:e.jsxRuntimeExports.jsx(Ys,{className:"size-4 text-foreground/70"})}),e.jsxRuntimeExports.jsx(Ps,{open:l,setOpen:c,userInput:h,triggerAIRun:d,setTriggerAIRun:y,setUserInput:p=>u(p)})]}),e.jsxRuntimeExports.jsxs("div",{className:"flex items-end gap-2",children:[e.jsxRuntimeExports.jsxs(e.Button,{onClick:v,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:Ze,className:"w-full",size:"sm",variant:"outline",children:[e.jsxRuntimeExports.jsx(e.Cross2Icon,{className:"mr-2 size-4"}),"Close"]})]})]})]})}function Zs({data:s}){var o;const[n,t]=g.useState([]),i=Object.keys(s[0]).map(l=>({accessorKey:l,header:({column:c})=>{const h=c.getIsSorted();return e.jsxRuntimeExports.jsx("div",{className:"flex gap-2",children:e.jsxRuntimeExports.jsxs("div",{className:"flex cursor-pointer items-center",onClick:()=>c.toggleSorting(c.getIsSorted()==="asc"),children:[l,h==="asc"?e.jsxRuntimeExports.jsx(e.TriangleUpIcon,{className:"ml-2 h-5 w-5"}):h==="desc"?e.jsxRuntimeExports.jsx(e.TriangleDownIcon,{className:"ml-2 h-5 w-5"}):null]})})}})),a=e.useReactTable({data:s,columns:i,getCoreRowModel:e.getCoreRowModel(),getPaginationRowModel:e.getPaginationRowModel(),onSortingChange:t,getSortedRowModel:e.getSortedRowModel(),manualPagination:!0,state:{sorting:n}});return e.jsxRuntimeExports.jsxs(e.Table$1,{children:[e.jsxRuntimeExports.jsx(e.TableHeader,{children:a.getHeaderGroups().map(l=>e.jsxRuntimeExports.jsx(e.TableRow,{children:l.headers.map(c=>e.jsxRuntimeExports.jsx(e.TableHead,{className:"sticky top-0 bg-muted",children:c.isPlaceholder?null:e.flexRender(c.column.columnDef.header,c.getContext())},c.id))},l.id))}),e.jsxRuntimeExports.jsx(e.TableBody,{children:(o=a.getRowModel().rows)!=null&&o.length?a.getRowModel().rows.map(l=>e.jsxRuntimeExports.jsx(e.TableRow,{className:"whitespace-nowrap py-2","data-state":l.getIsSelected()&&"selected",children:l.getVisibleCells().map(c=>e.jsxRuntimeExports.jsx(e.TableCell,{children:e.flexRender(c.column.columnDef.cell,c.getContext())},c.id))},l.id)):e.jsxRuntimeExports.jsx(e.TableRow,{children:e.jsxRuntimeExports.jsx(e.TableCell,{colSpan:i.length,className:"h-24 text-center",children:"No results."})})})]})}function Pe({className:s,...n}){g.useState(0);const t=e.useDashboardStore(o=>o.themeStyle),r=e.useEditorStore(o=>o.card),i=e.useEditorStore(o=>o.actions.setCard);if(g.useEffect(()=>{},[r.data,r.type,r.cfg,r.customCfg,t,r.preferences]),!r.id)return null;let a;return r.data&&r.data.length>0&&(a=e.createChartConfig({data:r.data,cardType:r.type,cfg:r.cfg,customCfg:r.customCfg,preferences:r.preferences})),e.jsxRuntimeExports.jsxs(e.Card,{role:"editor-visual-card",className:e.cn("relative flex h-full flex-col rounded-none",s),...n,children:[e.jsxRuntimeExports.jsxs(e.CardHeader,{className:"py-4",children:[e.jsxRuntimeExports.jsx(e.Editable,{text:r.title,onSave:o=>i({...r,title:o}),children:e.jsxRuntimeExports.jsx("div",{className:"flex items-center gap-2",children:e.jsxRuntimeExports.jsx(e.CardTitle,{className:"text-base",children:r.title})})},r.title),e.jsxRuntimeExports.jsx(e.Editable,{text:r.description||"",onSave:o=>i({...r,description:o}),children:e.jsxRuntimeExports.jsxs(e.CardDescription,{children:[" ",r.description]})},r.description)]}),e.jsxRuntimeExports.jsxs(e.CardContent,{className:"flex grow flex-col pb-3",children:[r.type!=="table"&&a&&e.jsxRuntimeExports.jsx(e.ChartJsVisual,{cfg:a},JSON.stringify(a)+JSON.stringify(r.preferences)),r.type==="table"&&r.data&&r.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:r,data:r==null?void 0:r.data})})]})]})}function et(){const[s,n]=g.useState(!1),[t,r]=g.useState(""),[i,a]=g.useState(""),[o,l]=g.useState(""),c=e.useEditorStore(E=>E.card),h=e.useEditorStore(E=>E.card.customCfg),u=e.useEditorStore(E=>E.actions.setCardCustomCfg);function d(E){var w,k;const f={...E,data:{...E==null?void 0:E.data,datasets:(k=(w=E==null?void 0:E.data)==null?void 0:w.datasets)==null?void 0:k.map(R=>({...R,data:[]}))}};return JSON.stringify(f,null,1)}function y(){if(!c.data||c.data.length===0)return;const E=e.createChartConfig({data:c.data,cardType:c.type,cfg:c.cfg,preferences:c.preferences});E&&(r(JSON.stringify(E,null,1)),h&&a(JSON.stringify(h,null,1)))}function x(){if(i)try{const E=JSON.parse(i);return E?(u(E),l(""),a(""),E):void 0}catch(E){console.log(E),l("Invalid JSON")}}function m(){a(""),u(null)}function j(){let E;if(h){const f=e._.cloneDeep(c.cfg),T=e._.merge(f,h);return E=d(T),E}return t?(E=d(JSON.parse(t)),E):""}return e.jsxRuntimeExports.jsxs(e.Dialog,{open:s,onOpenChange:n,children:[e.jsxRuntimeExports.jsx(e.DialogTrigger,{asChild:!0,children:e.jsxRuntimeExports.jsx(e.Button,{onClick:y,className:` ${h&&"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] min-w-[900px] overflow-auto",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(js,{onClick:()=>{navigator.clipboard.writeText(c.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(Pe,{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:[h&&e.jsxRuntimeExports.jsx(e.CheckIcon,{className:"mr-1 h-5 w-5 text-green-600"}),h?"Custom Config":"Default Config"]}),e.jsxRuntimeExports.jsx(e.TabsTrigger,{className:"",value:"output",children:"Output"})]}),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:j(),onChange:E=>a(E)})})]})]}),e.jsxRuntimeExports.jsxs(e.DialogFooter,{className:"flex items-center",children:[e.jsxRuntimeExports.jsx(e.Label,{className:"mr-2 text-red-500",children:o}),e.jsxRuntimeExports.jsx(e.Button,{disabled:!h,onClick:m,variant:"outline",children:"Reset"}),e.jsxRuntimeExports.jsx(e.Button,{onClick:x,variant:"outline",children:"Apply"}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>n(!1),variant:"outline",children:"Close"})]})]})]})}function $e(s){return te({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 Ke(s){return te({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 Ge(s){return te({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 Ue(s){return te({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 Qe(s){return te({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 Je(s){return te({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 We(s){return te({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 st(){const[s,n]=g.useState(!1),t=e.useEditorStore(l=>l.card.type),{setCardType:r,setCardPreferences:i}=e.useEditorStore(l=>l.actions),a=e.useEditorStore(l=>l.actions.setCardCustomCfg);function o(l){r(l),a(null),i({}),n(!1)}return e.jsxRuntimeExports.jsxs(e.Popover,{open:s,onOpenChange:n,children:[e.jsxRuntimeExports.jsx(e.PopoverTrigger,{asChild:!0,children:e.jsxRuntimeExports.jsx(e.Button,{size:"sm",variant:"outline",children:e.jsxRuntimeExports.jsx(tt,{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:()=>o("bar"),className:"font-normal",variant:"ghost",children:e.jsxRuntimeExports.jsx(ye,{className:"size-5"})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>o("line"),variant:"ghost",children:e.jsxRuntimeExports.jsx(ve,{className:"size-5"})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>o("stackedBar"),variant:"ghost",children:e.jsxRuntimeExports.jsx(Qe,{className:"size-5",strokeWidth:0})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>o("scatter"),variant:"ghost",children:e.jsxRuntimeExports.jsx(Be,{className:"size-5"})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>o("bubble"),variant:"ghost",children:e.jsxRuntimeExports.jsx(Ue,{className:"size-4"})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>o("pie"),variant:"ghost",children:e.jsxRuntimeExports.jsx(Me,{className:"size-5"})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>o("doughnut"),variant:"ghost",children:e.jsxRuntimeExports.jsx(Ke,{className:"size-5",strokeWidth:1})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>o("radar"),variant:"ghost",children:e.jsxRuntimeExports.jsx($e,{className:"size-5 font-extralight",strokeWidth:.5})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>o("polarArea"),variant:"ghost",children:e.jsxRuntimeExports.jsx(Ge,{className:"size-5"})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>o("pyramid"),variant:"ghost",children:e.jsxRuntimeExports.jsx(We,{className:"size-5"})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>o("table"),variant:"ghost",children:e.jsxRuntimeExports.jsx(e.Table,{className:"size-5"})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>o("kpi"),variant:"ghost",children:e.jsxRuntimeExports.jsx(Je,{className:"size-6"})})]})})]})}function tt({chartType:s,className:n}){switch(s){case"bar":return e.jsxRuntimeExports.jsx(ye,{className:n});case"line":return e.jsxRuntimeExports.jsx(ve,{className:n});case"pie":return e.jsxRuntimeExports.jsx(Me,{className:n});case"radar":return e.jsxRuntimeExports.jsx($e,{className:n});case"scatter":return e.jsxRuntimeExports.jsx(Be,{className:n});case"bubble":return e.jsxRuntimeExports.jsx(Ue,{className:n});case"doughnut":return e.jsxRuntimeExports.jsx(Ke,{className:n});case"stackedBar":return e.jsxRuntimeExports.jsx(Qe,{className:"size-4 text-foreground/70"});case"polarArea":return e.jsxRuntimeExports.jsx(Ge,{className:n});case"pyramid":return e.jsxRuntimeExports.jsx(We,{className:n});case"kpi":return e.jsxRuntimeExports.jsx(Je,{className:n});default:return e.jsxRuntimeExports.jsx(e.Table,{className:n})}}function rt(){const s=e.useEditorStore(t=>t.card.refreshInterval),n=e.useEditorStore(t=>t.actions.setCardRefreshInterval);return e.jsxRuntimeExports.jsxs(e.Popover,{children:[e.jsxRuntimeExports.jsx(e.PopoverTrigger,{asChild:!0,children:e.jsxRuntimeExports.jsx(e.Button,{size:"sm",variant:"outline",children:e.jsxRuntimeExports.jsx(ls,{className:"w-4 h-4"})})}),e.jsxRuntimeExports.jsx(e.PopoverContent,{className:"w-[200px]",children:e.jsxRuntimeExports.jsx("div",{className:"grid gap-4",children:e.jsxRuntimeExports.jsx("div",{className:"grid gap-2",children:e.jsxRuntimeExports.jsxs("div",{className:"grid grid-cols-5 items-center gap-1",children:[e.jsxRuntimeExports.jsx(e.Label,{className:"col-span-3",htmlFor:"width",children:"Refresh Every"}),e.jsxRuntimeExports.jsx(e.Input,{value:s||"",onChange:t=>n(t.target.value),id:"width",placeholder:"30s",className:"col-span-2 h-7 focus-visible:ring-1 focus-visible:ring-ring focus-visible:ring-offset-0"})]})})})})]})}function Ie(){e.useEditorStore(o=>o.frame);const s=e.useEditorStore(o=>o.card),n=e.useEditorStore(o=>o.card.data),t=e.useEditorStore(o=>o.isShowingVisual),r=e.useEditorStore(o=>o.isSqlRunning),i=e.useEditorStore(o=>o.queryError),a=e.useEditorStore(o=>o.pythonStdOut);return e.useEditorStore(o=>o.onSave),e.useEditorStore(o=>o.onClose),e.useEditorStore(o=>o.actions.setCardSql),e.useEditorStore(o=>o.actions.setCardType),e.useEditorStore(o=>o.actions.setSqlGen),s?e.jsxRuntimeExports.jsxs("div",{className:"relative flex h-full flex-col pt-3",children:[r&&e.jsxRuntimeExports.jsx(e.LoaderCircle,{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:[t&&e.jsxRuntimeExports.jsxs("div",{className:"flex grow items-center gap-2",children:[e.jsxRuntimeExports.jsx(st,{}),s.type!=="table"&&e.jsxRuntimeExports.jsx(et,{}),e.jsxRuntimeExports.jsx(rt,{})]}),e.jsxRuntimeExports.jsx(ot,{})]}),t?s.type==="kpi"?e.jsxRuntimeExports.jsx("div",{className:"flex grow items-center justify-center",children:e.jsxRuntimeExports.jsx("div",{className:"w-1/2 rounded-md border",children:e.jsxRuntimeExports.jsx(e.KPICard,{isLoading:r,card:s})})}):e.jsxRuntimeExports.jsx(Pe,{className:"grow border-none shadow-none"}):e.jsxRuntimeExports.jsxs("div",{className:"flex min-h-0 w-full flex-1 grow basis-0 px-6",children:[a&&e.jsxRuntimeExports.jsx(nt,{}),s.data&&s.data.length>0&&e.jsxRuntimeExports.jsx(Zs,{data:n||[]}),i&&e.jsxRuntimeExports.jsx("span",{className:"font-mono text-sm",children:i})]})]}):e.jsxRuntimeExports.jsx(e.jsxRuntimeExports.Fragment,{children:"No Active Card"})}function nt(){const s=e.useEditorStore(t=>t.pythonStdOut);if(!s)return null;const n=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:n},className:"bg-muted p-2 font-mono text-sm"}),e.jsxRuntimeExports.jsx(e.Separator,{className:"mb-2"})]})}function ot(){const s=e.useEditorStore(t=>t.isShowingVisual),n=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:()=>n(!s),id:"visualize",className:"data-[state=checked]:bg-foreground/50"})]})}function ue(){const[s,n]=g.useState([]);e.useEditorStore(u=>u.card.cfg);const t=e.useEditorStore(u=>u.card.preferences),{setCardCfg:r,setFilterOnClickColumnIndex:i,setCardPreferences:a}=e.useEditorStore(u=>u.actions),o=e.useEditorStore(u=>u.queryResultColumns);e.useEditorStore(u=>{var d;return(d=u.card.preferences)==null?void 0:d.filterOnClickColumnIndex}),g.useEffect(()=>{o&&n(new Array(o.length).fill(!1))},[o]);function l(u,d){var y,x;d?t!=null&&t.onClickFilter&&((y=t==null?void 0:t.onClickFilter)==null?void 0:y.length)>0?a({...t,onClickFilter:[...t.onClickFilter,{columnIndex:u,expression:""}]}):a({...t,onClickFilter:[{columnIndex:u,expression:""}]}):(a({...t,onClickFilter:(x=t==null?void 0:t.onClickFilter)==null?void 0:x.filter(m=>m.columnIndex!==u)}),n(m=>{const j=[...m];return j[u]=!1,j}))}function c(u,d){var x;const y=(x=t==null?void 0:t.onClickFilter)==null?void 0:x.map(m=>m.columnIndex===u?{...m,expression:d.target.value}:m);a({...t,onClickFilter:y})}function h(u){var d,y,x,m;if(s!=null&&s[u]||(y=(d=t==null?void 0:t.onClickFilter)==null?void 0:d.find(j=>j.columnIndex===u))!=null&&y.expression)return e.jsxRuntimeExports.jsx(e.Input,{value:(m=(x=t==null?void 0:t.onClickFilter)==null?void 0:x.find(j=>j.columnIndex===u))==null?void 0:m.expression,onChange:j=>c(u,j),type:"text",className:" h-9 w-full focus-visible:ring-0 focus-visible:ring-ring focus-visible:ring-offset-0 font-mono text-xs",placeholder:"Expression"})}return e.jsxRuntimeExports.jsx(e.jsxRuntimeExports.Fragment,{children:o==null?void 0:o.map((u,d)=>{var y,x;return e.jsxRuntimeExports.jsx("div",{className:"flex items-center justify-between space-y-2 xbg-red-100 group",children:e.jsxRuntimeExports.jsxs("div",{className:" grow",children:[e.jsxRuntimeExports.jsxs("div",{className:"flex items-center py-2 space-x-2",children:[e.jsxRuntimeExports.jsx(e.Checkbox,{checked:!!((y=t==null?void 0:t.onClickFilter)!=null&&y.find(m=>m.columnIndex===d)),onCheckedChange:m=>l(d,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 gap-2 items-center ",children:((x=t==null?void 0:t.onClickFilter)==null?void 0:x.find(m=>m.columnIndex===d))&&e.jsxRuntimeExports.jsx(Oe,{onClick:()=>{n(m=>{const j=[...m];return j[d]=!m[d],j})},className:" invisible group-hover:visible size-3 text-gray-400 cursor-pointer"})})]}),h(d)]})},u)})})}function Ne(){var a,o;const s=e.useEditorStore(l=>l.card.preferences),n=e.useEditorStore(l=>l.card.cfg),{setCardCfg:t,setCardPreferences:r}=e.useEditorStore(l=>l.actions);(a=n==null?void 0:n.options)!=null&&a.indexAxis;function i(l){var u,d,y,x,m,j;let c={};(u=s==null?void 0:s.chartOptions)!=null&&u.scales&&(c={x:(y=(d=s==null?void 0:s.chartOptions)==null?void 0:d.scales)==null?void 0:y.y,y:(m=(x=s==null?void 0:s.chartOptions)==null?void 0:x.scales)==null?void 0:m.x});const h={...s,chartOptions:{...s==null?void 0:s.chartOptions,scales:{...(j=s==null?void 0:s.chartOptions)==null?void 0:j.scales,...c},indexAxis:l}};r(h)}return e.jsxRuntimeExports.jsxs(e.RadioGroup,{value:((o=s==null?void 0:s.chartOptions)==null?void 0:o.indexAxis)||"x",onValueChange:i,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 xe="focus-visible:ring-0 focus-visible:ring-ring focus-visible:ring-offset-0";function De(s,n){var r,i,a;const t=e.getNumberAxis(s,n);return((a=(i=(r=s==null?void 0:s.chartOptions)==null?void 0:r.scales)==null?void 0:i[t])==null?void 0:a.type)||"linear"}function Ye(){var q,P,H,M,I,b;const[s,n]=g.useState(!1),t=e.useEditorStore(S=>{var N;return(N=S.card)==null?void 0:N.preferences}),r=e.useEditorStore(S=>{var N;return(N=S.card)==null?void 0:N.cfg}),i=e.getNumberAxis(t,r),[a,o]=g.useState(De(t)),[l,c]=g.useState(((H=(P=(q=t==null?void 0:t.chartOptions)==null?void 0:q.scales)==null?void 0:P[i])==null?void 0:H.min)||""),[h,u]=g.useState(((b=(I=(M=t==null?void 0:t.chartOptions)==null?void 0:M.scales)==null?void 0:I[i])==null?void 0:b.max)||""),[d,y]=g.useState(l||h?"custom":"auto"),[x,m]=g.useState(""),[j,E]=g.useState(0),[f,T]=g.useState(""),[w,k]=g.useState(""),[R,C]=g.useState(""),A=e.useEditorStore(S=>S.actions.setCardPreferences),D=e.useEditorStore(S=>{var N;return(N=S.card)==null?void 0:N.type}),_=["pie","doughnut","polarArea"].includes(D);g.useEffect(()=>{var S,N,L,Z,$,re,ne,oe,ee,B,G,U,ie,Q;o(De(t)),c(((L=(N=(S=t==null?void 0:t.chartOptions)==null?void 0:S.scales)==null?void 0:N[i])==null?void 0:L.min)===0?0:""),u(((re=($=(Z=t==null?void 0:t.chartOptions)==null?void 0:Z.scales)==null?void 0:$[i])==null?void 0:re.max)||""),m(((B=(ee=(oe=(ne=t==null?void 0:t.chartOptions)==null?void 0:ne.scales)==null?void 0:oe[i])==null?void 0:ee.ticks)==null?void 0:B.stepSize)||""),E(((G=t==null?void 0:t.numberAxisFormat)==null?void 0:G.decimalPlaces)||0),T(((U=t==null?void 0:t.numberAxisFormat)==null?void 0:U.suffix)||""),k(((ie=t==null?void 0:t.numberAxisFormat)==null?void 0:ie.currency)||""),C(((Q=t==null?void 0:t.numberAxisFormat)==null?void 0:Q.locale)||"")},[s,t,i]);function F(S,N){return N===""||/^[0-9\b]+$/.test(N)?Number(N):Number(S)}function O(){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:w,placeholder:"USD",onChange:S=>k(S.target.value),id:"currency",className:`col-span-2 h-8 w-full ${xe}`}),e.jsxRuntimeExports.jsx(e.Input,{value:R,placeholder:"en-US",onChange:S=>C(S.target.value),id:"locale",className:`col-span-2 h-8 w-full ${xe}`})]}),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:j,onChange:S=>E(Number(S.target.value)),id:"format",className:`col-span-6 h-8 w-full tracking-wide ${xe}`})]})]})}function z(){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:l,onChange:S=>c(N=>F(N,S.target.value)),className:`col-span-1 h-8 w-full ${xe}`}),e.jsxRuntimeExports.jsx(e.Input,{value:h,onChange:S=>u(N=>F(N,S.target.value)),id:"max",className:`col-span-1 h-8 w-full ${xe}`})]}),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:x,onChange:S=>m(N=>F(N,S.target.value)),id:"step-size",className:`col-span-1 h-8 w-full ${xe}`})]})]})}function K(){var L;let S={};d==="custom"&&(S={min:l,max:h,ticks:{stepSize:x}});const N={...t||{},chartOptions:{...t==null?void 0:t.chartOptions,scales:{...(L=t==null?void 0:t.chartOptions)==null?void 0:L.scales,[i]:{type:a,...a==="linear"?S:{}}}},numberAxisFormat:{decimalPlaces:j,suffix:f,currency:w,locale:R}};A(N)}return e.jsxRuntimeExports.jsxs(e.Popover,{onOpenChange:S=>n(S),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:_,value:a,onValueChange:S=>o(S),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"})]})})]})]}),a=="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:_,id:"scale-option",value:d,onValueChange:S=>y(S),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"})]})]})]}),d==="custom"&&a=="linear"&&z(),O(),e.jsxRuntimeExports.jsx(e.SelectSeparator,{}),e.jsxRuntimeExports.jsx("div",{className:"grid grid-cols-3",children:e.jsxRuntimeExports.jsx(e.Button,{onClick:K,variant:"secondary",className:"col-span-1 col-start-3 h-8 w-full",children:"Apply"})})]})]})})]})}function it({idx:s}){var l;const n=e.useEditorStore(c=>{var h;return(h=c.card)==null?void 0:h.preferences}),t=e.useEditorStore(c=>{var h;return(h=c.card.preferences)==null?void 0:h.datasetOptions}),r=e.useEditorStore(c=>c.actions.setCardPreferences),i=(l=n==null?void 0:n.chartOptions)==null?void 0:l.indexAxis,a=t==null?void 0:t.find(c=>c.idx===s);function o(c,h){(c==="end"||c==="start")&&e.getContrastColor(e.getCanvasBackgroundColor());const u={display:c!=="none",align:c,anchor:c,clamp:!0};if(!a)r({...n,datasetOptions:[...t||[],{idx:h,datalabels:u}]});else{const d={...a};d.datalabels=u;const y=t==null?void 0:t.map(x=>x.idx===h?d:x);r({...n,datasetOptions:y})}}return e.jsxRuntimeExports.jsxs(e.Popover,{children:[e.jsxRuntimeExports.jsx(e.PopoverTrigger,{children:e.jsxRuntimeExports.jsx(ws,{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(Es,{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(gs,{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(fs,{className:e.cn("h-4 w-4",{"rotate-90":i==="y"})})})]})})]})}function Xe(){const s=e.useEditorStore(c=>c.card),n=e.useEditorStore(c=>{var h,u,d;return(d=(u=(h=c==null?void 0:c.card)==null?void 0:h.preferences)==null?void 0:u.chartOptions)==null?void 0:d.indexAxis}),t=n==="y"?"Y axis":"X axis",r=n==="y"?"X axis":"Y axis",{keys:i,metricKeys:a,dimensionKeys:o}=e.getKeys(s.data||[]);let l=a;if(s.type==="stackedBar"){const c=e.pivotData({dataArray:s.data||[],groupKey:o[0],pivotKey:o[1],valueKey:l[0]}),{metricKeys:h}=e.getKeys(c);l=h}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:r}),e.jsxRuntimeExports.jsx(Ye,{})]}),e.jsxRuntimeExports.jsx("div",{className:"my-1 space-y-1",children:l.map((c,h)=>e.jsxRuntimeExports.jsx(at,{col:c,idx:h},c))})]})]})}function at({col:s,idx:n}){const t=e.useEditorStore(l=>{var c;return(c=l.card)==null?void 0:c.preferences}),r=e.useEditorStore(l=>{var c;return(c=l.card.preferences)==null?void 0:c.datasetOptions}),i=r==null?void 0:r.find(l=>l.idx===n),{setCardPreferences:a}=e.useEditorStore(l=>l.actions);function o(l){if(!i)a({...t,datasetOptions:[...r||[],{idx:n,type:l==="area"?"line":l,fill:l==="area"?"origin":""}]});else{const c={...i};c.type=l==="area"?"line":l,c.fill=l==="area"?"origin":"";const h=r==null?void 0:r.map(u=>u.idx===n?c:u);a({...t,datasetOptions:h})}}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(ye,{onClick:()=>o("bar"),className:"invisible size-4 cursor-pointer text-muted-foreground hover:text-foreground group-hover:visible"}),e.jsxRuntimeExports.jsx(ve,{onClick:()=>o("line"),className:"invisible size-4 cursor-pointer text-muted-foreground hover:text-foreground group-hover:visible"}),e.jsxRuntimeExports.jsx(cs,{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(it,{idx:n})]})]})}function lt({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:n=>n.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(Ne,{}),e.jsxRuntimeExports.jsx(Xe,{})]})]}),e.jsxRuntimeExports.jsxs(e.AccordionItem,{value:"item-3",children:[e.jsxRuntimeExports.jsx(e.AccordionTrigger,{children:"Filter on click"}),e.jsxRuntimeExports.jsx(e.AccordionContent,{className:"px-2",children:e.jsxRuntimeExports.jsx(ue,{})})]})]})})}function ke(){var i,a,o;const s=e.useEditorStore(l=>l.card.cfg),n=e.useEditorStore(l=>l.actions.setCardCfg),t=e.useEditorStore(l=>l.card.type);function r(l){var u;const c={datalabels:{display:l!=="none",align:l,anchor:l,clamp:!0}},h={...s,options:{...s==null?void 0:s.options,plugins:{...(u=s==null?void 0:s.options)==null?void 0:u.plugins,...c}}};n(h),console.log(l)}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"}),t!=="pyramid"&&e.jsxRuntimeExports.jsx(Ye,{})]}),e.jsxRuntimeExports.jsxs(e.Select,{value:(o=(a=(i=s==null?void 0:s.options)==null?void 0:i.plugins)==null?void 0:a.datalabels)==null?void 0:o.anchor,onValueChange:r,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 ct({cardType:s}){function n(t){const r="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:"bg-muted px-2 py-1 rounded text-xs",children:t==="bubble"?r:i}),e.jsxRuntimeExports.jsxs("ul",{className:" ml-6 list-disc [&>li]:mt-2 text-xs",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:a=>a.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:"px-6 py-2 space-y-6",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:n(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(ke,{})})]}),e.jsxRuntimeExports.jsxs(e.AccordionItem,{value:"item-3",children:[e.jsxRuntimeExports.jsx(e.AccordionTrigger,{children:"Filter on click"}),e.jsxRuntimeExports.jsx(e.AccordionContent,{className:"px-2",children:e.jsxRuntimeExports.jsx(ue,{})})]})]})})}const xt={datasets:[{type:"line",label:"Sum_sales",data:[]},{type:"bar",label:"Sum_profit",data:[]}]},ut={datasets:[{fill:"origin",type:"line",label:"Sum_sales",data:[]}]};function dt(){const s=e.useEditorStore(n=>n.card.type);return e.jsxRuntimeExports.jsxs("div",{className:"p-6 space-y-6",children:[e.jsxRuntimeExports.jsx(e.Accordion,{className:" ",type:"single",collapsible:!0,children:mt(s)}),e.jsxRuntimeExports.jsx("section",{className:"",children:["line","bar"].includes(s)&&e.jsxRuntimeExports.jsx(Ne,{})}),e.jsxRuntimeExports.jsx("div",{children:!["kpi"].includes(s)&&e.jsxRuntimeExports.jsx(ke,{})}),e.jsxRuntimeExports.jsx("div",{children:!["kpi"].includes(s)&&e.jsxRuntimeExports.jsx(ue,{})})]})}function mt(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:"bg-muted px-2 py-1 rounded font-mono font-semibold text-xs",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 [&>li]:mt-2 font-normal text-xs",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:" text-xs space-y-2",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(xt,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:" text-xs space-y-2",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:"text-blue-500 hover:underline mx-1",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(ut,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:"bg-muted px-2 py-1 rounded font-mono font-semibold text-xs",children:"SELECT label, x-axis, y-axis, radius FROM table"}),e.jsxRuntimeExports.jsxs("ul",{className:"my-6 ml-6 list-disc [&>li]:mt-2 font-normal text-xs",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:"bg-muted px-2 py-1 rounded font-mono font-semibold text-xs",children:"SELECT label, x-axis, y-axis FROM table"}),e.jsxRuntimeExports.jsxs("ul",{className:"my-6 ml-6 list-disc [&>li]:mt-2 font-normal text-xs",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:"bg-muted px-2 py-1 rounded font-mono font-semibold text-xs",children:"SELECT label, measure FROM table"}),e.jsxRuntimeExports.jsxs("ul",{className:"my-6 ml-6 list-disc [&>li]:mt-2 font-normal text-xs",children:[e.jsxRuntimeExports.jsx("li",{children:"Label - Category (ex. city)"}),e.jsxRuntimeExports.jsx("li",{children:"Measure - Number (ex. population)"})]})]})]})})}function pt(){var c,h,u,d,y;const s=e.useEditorStore(x=>x.card.preferences),n=e.useEditorStore(x=>x.actions.setCardPreferences),t=e.useEditorStore(x=>x.actions.setNumberFormat);e.useEditorStore(x=>{var m,j;return(j=(m=x.card.preferences)==null?void 0:m.formatNumber)==null?void 0:j.decimalPlaces});const r=e.useEditorStore(x=>{var m,j;return(j=(m=x.card.preferences)==null?void 0:m.formatNumber)==null?void 0:j.locale}),i=e.useEditorStore(x=>{var m,j;return(j=(m=x.card.preferences)==null?void 0:m.formatNumber)==null?void 0:j.currency});e.useEditorStore(x=>x.actions.setFilterOnClickField);const a=e.useEditorStore(x=>{var m,j;return(j=(m=x.card.preferences)==null?void 0:m.formatNumber)==null?void 0:j.colorRanges})||[],o=e.useEditorStore(x=>x.actions.setColorRanges),l=[...new Set(e.LOCALE_CURRENCY_PAIRS.map(x=>x.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:!!((c=s==null?void 0:s.formatNumber)!=null&&c.enabled),onCheckedChange:x=>{n({...s,formatNumber:{...s==null?void 0:s.formatNumber,enabled:x}})}}),e.jsxRuntimeExports.jsx(e.Label,{children:"Format Number"})]}),((h=s==null?void 0:s.formatNumber)==null?void 0:h.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:r||"en-US",onValueChange:x=>{var m,j,E;return t(((m=s==null?void 0:s.formatNumber)==null?void 0:m.decimalPlaces)||0,((j=s==null?void 0:s.formatNumber)==null?void 0:j.currency)||"",x||"en-US",((E=s==null?void 0:s.formatNumber)==null?void 0:E.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(x=>e.jsxRuntimeExports.jsx(e.SelectItem,{value:x.locale,children:x.locale},x.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:x=>{var m,j,E;return t(((m=s==null?void 0:s.formatNumber)==null?void 0:m.decimalPlaces)||0,x==="none"?"":x,((j=s==null?void 0:s.formatNumber)==null?void 0:j.locale)||"",((E=s==null?void 0:s.formatNumber)==null?void 0:E.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"),l.map(x=>e.jsxRuntimeExports.jsx(e.SelectItem,{value:x,children:x},x))]})})]})]})]}),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:((d=(u=s==null?void 0:s.formatNumber)==null?void 0:u.decimalPlaces)==null?void 0:d.toString())||"0",onValueChange:x=>{var m,j,E;return t(Number(x),((m=s==null?void 0:s.formatNumber)==null?void 0:m.currency)||"",((j=s==null?void 0:s.formatNumber)==null?void 0:j.locale)||"",((E=s==null?void 0:s.formatNumber)==null?void 0:E.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(x=>e.jsxRuntimeExports.jsx(e.SelectItem,{value:x,children:x},x))})]})]}),e.jsxRuntimeExports.jsxs("div",{className:"w-full space-y-1",children:[e.jsxRuntimeExports.jsx(e.Label,{children:"Suffix"}),e.jsxRuntimeExports.jsx(e.Input,{value:((y=s==null?void 0:s.formatNumber)==null?void 0:y.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:x=>{var m,j,E;return t(((m=s==null?void 0:s.formatNumber)==null?void 0:m.decimalPlaces)||0,((j=s==null?void 0:s.formatNumber)==null?void 0:j.currency)||"",((E=s==null?void 0:s.formatNumber)==null?void 0:E.locale)||"",x.target.value)}})]})]})]})}),e.jsxRuntimeExports.jsx(e.Separator,{className:"my-3"}),e.jsxRuntimeExports.jsx(e.ColorFormat,{colorRanges:a,setColorRanges:o})]})]})}function ht(){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(pt,{})}),e.jsxRuntimeExports.jsx("div",{}),e.jsxRuntimeExports.jsx("div",{})]})}function Le({cardType:s,docContent:n}){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,{children:n||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:t=>t.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.jsx(e.AccordionContent,{className:"px-2",children:e.jsxRuntimeExports.jsx(ke,{})})]}),e.jsxRuntimeExports.jsxs(e.AccordionItem,{value:"item-3",children:[e.jsxRuntimeExports.jsx(e.AccordionTrigger,{children:"Filter on click"}),e.jsxRuntimeExports.jsx(e.AccordionContent,{className:"px-2",children:e.jsxRuntimeExports.jsx(ue,{})})]})]})})}function jt(){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(Ne,{}),e.jsxRuntimeExports.jsx(Xe,{})]})]}),e.jsxRuntimeExports.jsxs(e.AccordionItem,{value:"item-3",children:[e.jsxRuntimeExports.jsx(e.AccordionTrigger,{children:"Filter on click"}),e.jsxRuntimeExports.jsx(e.AccordionContent,{className:"px-2",children:e.jsxRuntimeExports.jsx(ue,{})})]})]})})}function Et({}){const s=e.useEditorStore(r=>{var i;return(i=r.card)==null?void 0:i.preferences}),n=e.useEditorStore(r=>r.actions.setCardPreferences),t=r=>{n({...s,allowDownload:r})};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:"Filter on click"}),e.jsxRuntimeExports.jsx(e.AccordionContent,{className:"px-2",children: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 ft=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."]})]});function gt(){const s=e.useEditorStore(t=>t.card.type);function n(t){switch(t){case"stackedBar":return e.jsxRuntimeExports.jsx(jt,{});case"pyramid":return e.jsxRuntimeExports.jsx(Le,{docContent:ft,cardType:t});case"kpi":return e.jsxRuntimeExports.jsx(ht,{});case"line":case"bar":return e.jsxRuntimeExports.jsx(lt,{cardType:t});case"pie":case"doughnut":case"polarArea":case"radar":return e.jsxRuntimeExports.jsx(Le,{cardType:t});case"bubble":case"scatter":return e.jsxRuntimeExports.jsx(ct,{cardType:t});case"table":return e.jsxRuntimeExports.jsx(Et,{cardType:t});default:return e.jsxRuntimeExports.jsx(dt,{})}}return e.jsxRuntimeExports.jsx(e.ScrollArea,{className:"h-full w-full text-sm",children:n(s)})}function Rt(){const s=e.useEditorStore(n=>n.isShowingVisual);return e.jsxRuntimeExports.jsxs(e.ResizablePanelGroup,{direction:"vertical",className:"min-w-full max-w-lg min-h-[250px]",children:[e.jsxRuntimeExports.jsx(e.ResizablePanel,{role:"query-section",className:"flex",minSize:20,defaultSize:40,children:e.jsxRuntimeExports.jsx(Xs,{})}),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(gt,{})})}),e.jsxRuntimeExports.jsx(e.ResizableHandle,{className:"border "}),e.jsxRuntimeExports.jsx(e.ResizablePanel,{minSize:40,defaultSize:75,maxSize:100,children:e.jsxRuntimeExports.jsx(Ie,{})})]}):e.jsxRuntimeExports.jsx(Ie,{})})]})}function bt({authToken:s,onSave:n,onClose:t}){const r=e.useEditorStore(o=>o.actions.setOnSave),i=e.useEditorStore(o=>o.actions.setOnClose),a=e.useDashboardStore(o=>o.actions.setAuthToken);return g.useEffect(()=>{n&&r(n),t&&i(t)},[n,r,t,i]),g.useEffect(()=>{s&&s.accessToken&&a(s)},[s,a]),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(Ve,{})}),e.jsxRuntimeExports.jsx(e.EditorMain,{children:e.jsxRuntimeExports.jsx(Rt,{})})]})}function St(){e.useDashboardStore(o=>o.selectedCardId);const s=e.useDashboardStore(o=>o.selectedSheetId),{setIsVisualEditing:n}=e.useDashboardStore(o=>o.actions),t=e.useDashboardStore(o=>o.isVisualEditing),r=e.useDashboardStore(o=>o.actions.updateFrame);function i(o){s&&(r(s,o),n(!1))}function a(){n(!1)}return e.jsxRuntimeExports.jsx("div",{role:"editor-container",className:e.cn("flex grow",{block:t,hidden:!t}),children:e.jsxRuntimeExports.jsx(bt,{onSave:i,onClose:a})})}function yt({columns:s,tableName:n}){const t=e.useEditorStore(d=>d.selectedConnectionId),r=e.useEditorStore(d=>d.selectedDatabaseName),i=e.useEditorStore(d=>d.selectedSchemaName),a=e.useEditorStore(d=>d.selectedTableName),o=e.useDashboardStore(d=>d.dashboard.filters)||[],l=e.useDashboardStore(d=>d.actions.addFilter),c=e.useDashboardStore(d=>d.actions.removeFilter),h=e.useDashboardStore(d=>d.actions.removeFilterValue);function u(d){const y=e.fmt(d.column_name),x=e.fmt(r||""),m=e.fmt(i||""),j=e.fmt(n),E=e.getQualifiedTableName(m,j),f=`${E}.${y}`;console.log("find",f,j,x);const T=o==null?void 0:o.find(w=>w.column===f&&w.table===j&&(w.database===x||w.database===r));if(T)h(T.id),c(T.id);else{if(n==="api"&&t){l({id:e.v4(),column:f,title:d.column_name,dataType:d.data_type,table:"api",database:"",connectionId:t,operation:"in",sql:e.getDefaultFilterSql(d.data_type,E,y)});return}l({id:e.v4(),column:`${E}.${y}`,title:d.column_name,dataType:d.data_type,table:a||"",database:r||"",connectionId:t||"",operation:"in",sql:e.getDefaultFilterSql(d.data_type,E,y)})}}return e.jsxRuntimeExports.jsx("div",{className:"xbg-red-100 flex-1 basis-0 flex-col overflow-scroll px-3",children:s==null?void 0:s.map(d=>{const y=o==null?void 0:o.find(x=>x.column===e.fmt(d.column_name)&&x.table===a&&x.database===r);return e.jsxRuntimeExports.jsx("div",{onClick:()=>u(d),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":y}),children:e.jsxRuntimeExports.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxRuntimeExports.jsx(qe,{column:d}),e.jsxRuntimeExports.jsx("span",{children:d.column_name})]})},d.column_name)})})}function vt(){e.useDashboardStore(n=>n.showFilters);const s=e.useDashboardStore(n=>n.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(Ve,{ColumnsComponent:(n,t,r)=>e.jsxRuntimeExports.jsx(yt,{schemaName:n,tableName:t,columns:r})})})]})}function Ct(){e.useDashboardStore(t=>t.dashboard);const s=e.useDashboardStore(t=>t.showFilters),n=e.useDashboardStore(t=>t.isVisualEditing);return e.useDashboardStore(t=>t.bookmarkKey),e.jsxRuntimeExports.jsxs("div",{role:"dashboard-plus-main",className:e.cn("grow",{hidden:n,flex:!n}),children:[e.jsxRuntimeExports.jsx(e.DashboardTabs,{}),s&&e.jsxRuntimeExports.jsx("div",{role:"filter-aside-container",className:"flex",children:e.jsxRuntimeExports.jsx(vt,{})})]})}function Nt(){const s=e.useDashboardStore(r=>r.dashboard),n=e.useDashboardStore(r=>r.actions.setDashboard),t=e.useDashboardStore(r=>r.showDashboardJSON);return e.useDashboardStore(r=>r.actions.setShowDashboardJSON),e.jsxRuntimeExports.jsx("div",{className:e.cn(" p-2",{hidden:!t}),children:e.jsxRuntimeExports.jsx(e.de,{onChange:r=>{if(r)try{JSON.parse(r),n(JSON.parse(r))}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 kt({showControls:s=!1,showFooter:n=!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(Nt,{}),e.jsxRuntimeExports.jsxs(e.DashboardPanel,{...t,children:[s&&e.jsxRuntimeExports.jsx(Fs,{}),e.jsxRuntimeExports.jsx(St,{}),e.jsxRuntimeExports.jsx(Ct,{})]})]})]})}exports.DashboardPlus=kt;exports.SelectComponent=he;exports.useEditorAside=Ce;