react-semaphor 0.0.213 → 0.0.215

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.
@@ -158,7 +158,7 @@
158
158
  *
159
159
  * This source code is licensed under the ISC license.
160
160
  * See the LICENSE file in the root directory of this source tree.
161
- */const Ds=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 Fs(){const[s,n]=f.useState(""),[t,r]=f.useState(!1),[i,x]=f.useState(!1),c=e.useDashboardStore(a=>a.dashboard);function o(){const a=e.getDashbaordStateWithoutData(c),h=e.getBookmarkKey(c.id),u=JSON.parse(localStorage.getItem(h)||"[]");if(u.some(v=>v.name===s)){r(!0);return}u.push({name:s,template:a}),localStorage.setItem(h,JSON.stringify(u)),x(!1)}return e.jsxRuntimeExports.jsxs(e.Dialog,{open:i,onOpenChange:x,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:a=>{t&&r(!1),n(a.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:o,children:"Save"})})]})]})}function Os(){const[s,n]=f.useState(!1),[t,r]=f.useState(""),i=e.useDashboardStore(l=>l.dashboard),x=e.useDashboardStore(l=>l.bookmarkKey),[c,o]=f.useState([]),a=e.useDashboardStore(l=>l.actions.setDashboard),h=e.useDashboardStore(l=>l.actions.setFilterValues),u=e.useDashboardStore(l=>l.actions.setBookmarkKey);f.useEffect(()=>{const l=e.getBookmarkKey(i.id),m=JSON.parse(localStorage.getItem(l)||"[]");o(m);const E=m.find(C=>C.default);E&&E.name===x&&r(E.name)},[s,i,x]);function d(l){if(l===t)return;const m=c.find(C=>C.name===l),E=m==null?void 0:m.template;E&&(a(E),h(m.filterValues||[]),u(l==="Original"?"":l)),r(l)}function v(l){const m=e.getBookmarkKey(i.id),C=JSON.parse(localStorage.getItem(m)||"[]").filter(y=>y.name!==l);localStorage.setItem(m,JSON.stringify(C)),o(C)}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(Es,{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"}),c.filter(l=>l.name!="Original").map((l,m)=>e.jsxRuntimeExports.jsxs(e.DropdownMenuRadioItem,{className:"xbg-red-100 flex justify-between",value:l.name,defaultChecked:l.name===x,children:[e.jsxRuntimeExports.jsx("p",{children:l.name}),e.jsxRuntimeExports.jsx(e.Cross2Icon,{onClick:E=>{E.preventDefault(),v(l.name)},className:"h-3 w-3 hover:cursor-pointer",strokeWidth:1.5})]},m))]})]})]})}function Ms(){const[s,n]=f.useState(!1),t=e.useDashboardStore(x=>x.dashboard),r=e.useDashboardStore(x=>x.bookmarkKey);f.useEffect(()=>{if(!r){n(!1);return}const x=e.getBookmarkKey(t.id),o=JSON.parse(localStorage.getItem(x)||"[]").find(a=>a.name===r);n(o?o.default:!1)},[r,t.id]);function i(x){if(n(x),!r)return;const c=e.getBookmarkKey(t.id),a=JSON.parse(localStorage.getItem(c)||"[]").map(h=>(h.name===r?h.default=x:h.default=!1,h));console.log(a),localStorage.setItem(c,JSON.stringify(a))}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 Bs(){const s=e.useDashboardStore(y=>y.bookmarkKey),n=e.useDashboardStore(y=>y.dashboard);e.useDashboardStore(y=>y.selectedSheetId);const t=e.useDashboardStore(y=>y.isDashboardEditing),r=e.useDashboardStore(y=>y.filterValues),i=e.useDashboardStore(y=>y.isVisualEditing),x=e.useDashboardStore(y=>y.showFilters);e.useDashboardStore(y=>y.showDashboardJSON);const c=e.useDashboardStore(y=>y.onSaveFunction),o=e.useDashboardStore(y=>y.actions.setShowFilters),{addFrame:a,setSelectedFrameId:h}=e.useDashboardStore(y=>y.actions),{getSelectedSheet:u,setIsDashboardEditing:d,setShowDashboardJSON:v}=e.useDashboardStore(y=>y.actions),l=u(),m=()=>{if(!t||!l)return;const y={id:e.v4(),title:"Title",description:"Description",preferences:{onClickFilter:[{columnIndex:0,expression:""}]},type:"bar",sql:"select COUNT(*) from YOUR_TABLE",data:[]},z={id:e.v4(),cards:[y],activeCardId:y.id};a(l.id,z),h(z.id)},E=()=>{d(!0)};function C(){if(!s||s==="")return;const y=e.getDashbaordStateWithoutData(n),z=e.getBookmarkKey(n.id),b=JSON.parse(localStorage.getItem(z)||"[]"),I=b.findIndex(S=>S.name===s);I!==-1?b[I]={name:s,template:y,default:b[I].default,filterValues:r}:b.push({name:s,template:y,filterValues:r}),localStorage.setItem(z,JSON.stringify(b)),c==null||c(y)}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(Ms,{})]})]}),e.jsxRuntimeExports.jsxs("div",{className:"flex gap-2",children:[t&&!i&&e.jsxRuntimeExports.jsx(Fs,{}),!i&&e.jsxRuntimeExports.jsx(Os,{}),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:E,size:"sm",children:e.jsxRuntimeExports.jsx(Pe,{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),v(!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:C,size:"sm",children:e.jsxRuntimeExports.jsx(ws,{className:"h-4 w-4",strokeWidth:1.5})}),!x&&!i&&t&&e.jsxRuntimeExports.jsx(e.Button,{className:"h-7 p-2",variant:"outline",onClick:()=>o(!0),size:"sm",children:e.jsxRuntimeExports.jsx(_e,{className:"h-4 w-4",strokeWidth:1.5})}),!i&&t&&!1,!i&&!1]})]})}function pe({title:s,items:n,value:t,isLoading:r,isError:i,connectionTooltip:x,onChange:c,showNone:o=!1,className:a,showIcon:h=!0,disabled:u=!1}){const d=r?"Loading...":i?"Error":t;function v(){if(s==="Connection")return e.jsxRuntimeExports.jsx(ks,{className:"size-4 rotate-90"});if(s==="Database")return e.jsxRuntimeExports.jsx(hs,{className:"size-4"});if(s==="Schema")return e.jsxRuntimeExports.jsx(Cs,{className:"size-4"});if(s==="Table")return e.jsxRuntimeExports.jsx(e.Table,{className:"size-4"});if(s==="Dataset")return e.jsxRuntimeExports.jsx(ms,{className:"size-4"})}return e.jsxRuntimeExports.jsxs("div",{className:"flex items-center gap-2",children:[h&&e.jsxRuntimeExports.jsx("div",{className:"shrink-0",children:x?e.jsxRuntimeExports.jsxs(e.Tooltip,{children:[e.jsxRuntimeExports.jsx(e.TooltipTrigger,{children:v()}),e.jsxRuntimeExports.jsx(e.TooltipContent,{className:"text-xs",align:"start",children:x})]}):v()}),e.jsxRuntimeExports.jsxs(e.Select,{disabled:u,value:d,onValueChange:c,children:[e.jsxRuntimeExports.jsx(e.SelectTrigger,{className:e.cn("h-9 w-full focus:ring-1 focus:ring-offset-0",a),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.jsxs(e.jsxRuntimeExports.Fragment,{children:[o&&e.jsxRuntimeExports.jsx(e.SelectItem,{value:"none",children:"None"},"none"),n&&n.map((l,m)=>e.jsxRuntimeExports.jsx(e.SelectItem,{value:l.id,children:l.name},m))]}),(r||i)&&e.jsxRuntimeExports.jsx(e.SelectItem,{value:d,children:d})]})})]})]})}function qs({column:s}){const[n,t]=f.useState(!1),r=e.useEditorStore(u=>u.selectedTableName),i=e.useEditorStore(u=>u.selectedSchemaName),x=e.useEditorStore(u=>u.sqlGen),c=e.useEditorStore(u=>u.actions.setSqlGen),o=e.useEditorStore(u=>u.actions.setCardSql),a=e.useEditorStore(u=>u.actions.setRunSql);function h(u,d){const v=e.createSqlGenConfig(u,x,d);c(v);const l=e.getSql(v,e.fmt(i||""),e.fmt(r));l&&(o(l),a(!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 Ke({column:s}){return e.jsxRuntimeExports.jsxs(e.Tooltip,{children:[e.jsxRuntimeExports.jsx(e.$a093c7e1ec25a057$export$8c610744efcf8a1d,{asChild:!0,children:e.TEXT_DATA_TYPES.includes(s.data_type.toLowerCase())?e.jsxRuntimeExports.jsx(Le,{className:"size-3"}):e.NUMBER_DATA_TYPES.includes(s.data_type.toLowerCase())?e.jsxRuntimeExports.jsx(gs,{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(Ts,{className:"size-3"}):e.jsxRuntimeExports.jsx(As,{className:"size-3"})}),e.jsxRuntimeExports.jsx(e.TooltipContent,{children:e.jsxRuntimeExports.jsx("p",{className:"font-mono text-xs",children:s.data_type})})]})}function Vs({schemaName:s,tableName:n,columns:t,status:r}){const i=e.useEditorStore(S=>S.sqlGen),x=e.useEditorStore(S=>S.selectedConnectionId),c=e.useEditorStore(S=>S.selectedDatabaseName),o=e.useEditorStore(S=>S.selectedSchemaName),a=e.useEditorStore(S=>S.selectedTableName),h=e.useDashboardStore(S=>S.dashboard.aiScopeTables),{setAIScopeTables:u}=e.useDashboardStore(S=>S.actions),d=e.useEditorStore(S=>S.actions.setRunSql),v=e.useEditorStore(S=>S.actions.setSqlGen),l=e.useEditorStore(S=>S.actions.setIsShowingVisual),m=e.useEditorStore(S=>S.actions.setCardSql),{connectionType:E}=Te();function C(S){const N=e.createSqlGenConfig(S,i);v(N);const A=e.getSql(N,e.fmt(s),e.fmt(n));A&&(m(A),d(!0))}function y(){return(h==null?void 0:h.find(S=>S.connectinonId===x&&S.tableName===a))!==void 0}function z(S){if(S===!0&&a&&x){const N={connectinonId:x,connectionType:E,databaseName:c,schemaName:o,tableName:a},D=[...h||[],N].filter((w,B,O)=>O.findIndex(L=>L.connectinonId===w.connectinonId&&L.tableName===w.tableName)===B);u(D),e.Jt.success(`Added '${a}' to AI Scope`,{position:"top-right",duration:2500,richColors:!0})}else{const N=(h||[]).filter(A=>A.connectinonId!==x&&A.tableName!==a);u(N),e.Jt(`Removed '${a}' from AI Scope`,{position:"top-right",duration:2e3,richColors:!0})}}function b(){let N=e.getQualifiedTableName(s,n);(w=>w.charAt(0)===w.charAt(0).toUpperCase())(n)&&(N=`"${n}"`),l(!1);const D=E==="MSSQL"?`SELECT top 10 * FROM ${N}`:`SELECT * FROM ${N} LIMIT 10`;m(D),d(!0)}function I(){let N=e.getQualifiedTableName(s,n);(D=>D.charAt(0)===D.charAt(0).toUpperCase())(n)&&(N=`"${n}"`),l(!1),m(`SELECT COUNT(*) as count FROM ${N}`),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:`${y()?"Remove from":"Add to"} AI Scope`,pressed:y(),onPressedChange:z,variant:"outline",className:"h-9 px-2",children:e.jsxRuntimeExports.jsx(e.Bot,{className:e.cn("size-4",{"text-primary":y(),"text-muted-foreground":!y()})})}),e.jsxRuntimeExports.jsxs(e.Button,{disabled:r!=="Success",onClick:b,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(Is,{className:"mr-2 size-4"}),"Top 10"]}),e.jsxRuntimeExports.jsxs(e.Button,{disabled:r!=="Success",onClick:I,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(zs,{className:"mr-2 size-4"}),"Count"]})]}),e.jsxRuntimeExports.jsxs(e.ScrollArea,{className:"flex-1 basis-0 overflow-y-auto border-b border-t border-muted py-3",children:[t==null?void 0:t.map(S=>e.jsxRuntimeExports.jsxs("div",{onClick:()=>C(S),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(S,i)}),children:[e.jsxRuntimeExports.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsxRuntimeExports.jsx(Ke,{column:S}),e.jsxRuntimeExports.jsx("span",{children:S.column_name})]}),e.NUMBER_DATA_TYPES.includes(S.data_type)&&e.jsxRuntimeExports.jsx("div",{onClick:N=>N.stopPropagation(),className:"flex items-center justify-end",children:e.jsxRuntimeExports.jsx(qs,{column:S})})]},S.column_name)),e.jsxRuntimeExports.jsx(e.ScrollBar,{orientation:"vertical"}),e.jsxRuntimeExports.jsx(e.ScrollBar,{orientation:"horizontal"})]})]})}function Te(s,n){var je,de,Ee,fe,p;let t=f.useMemo(()=>[],[]);const r=e.useSemaphorContext().authToken||s,i=e.useEditorStore(j=>j.selectedConnectionId),x=e.useEditorStore(j=>j.selectedDatamodelId),c=e.useEditorStore(j=>j.selectedDatabaseName),o=e.useEditorStore(j=>j.selectedSchemaName),a=e.useEditorStore(j=>j.selectedTableName),h=e.useEditorStore(j=>j.actions.setCurrentColumns),u=e.useEditorStore(j=>j.actions.setSelectedConnectionId),d=e.useEditorStore(j=>j.actions.setSelectedDatamodelId),v=e.useEditorStore(j=>j.actions.setSelectedDatabaseName),l=e.useEditorStore(j=>j.actions.setSelectedSchemaName),m=e.useEditorStore(j=>j.actions.setSelectedTableName),E=e.useEditorStore(j=>j.actions.setCardSql);function C(j){return i&&c&&o&&c!=="NA"?!0:i&&j==="API"?!1:!!(i&&j==="S3")}function y(j){return!!(i&&c&&c!=="NA"&&o&&a||i&&(j==="S3"||j==="API")||x&&x)}function z(j){return i&&j?!(j==="API"||j==="S3"):!1}const{data:b,isLoading:I,isError:S}=e.useQuery({queryKey:["connections"],queryFn:()=>e.getRequest("https://semaphor.cloud/api/v1/connections",(r==null?void 0:r.accessToken)||""),enabled:!!(r!=null&&r.accessToken)}),{data:N,isLoading:A,isError:D}=e.useQuery({queryKey:["models",i],queryFn:()=>e.getRequest("https://semaphor.cloud/api/v1/datamodels",(r==null?void 0:r.accessToken)||"",{connection_id:i}),enabled:!!(r!=null&&r.accessToken)&&!!i}),w=b==null?void 0:b.connections.find(j=>j.id===i),B=w==null?void 0:w.type,O=(w==null?void 0:w.type)==="API"||(w==null?void 0:w.type)==="S3",{data:L,isLoading:U,isFetching:_,isError:H,refetch:P}=e.useQuery({queryKey:["databases",i],queryFn:()=>e.getRequest("https://semaphor.cloud/api/v1/databases",(r==null?void 0:r.accessToken)||"",{connection_id:i}),enabled:z(B)}),{data:M,isLoading:$,isFetching:g,isError:R,refetch:k}=e.useQuery({queryKey:["schemas",i,c],queryFn:()=>e.getRequest("https://semaphor.cloud/api/v1/schemas",(r==null?void 0:r.accessToken)||"",{connection_id:i,database_name:c}),enabled:!!i&&!!c&&!O&&c!=="NA"}),{data:F,isLoading:T,isFetching:K,isError:oe,refetch:ie}=e.useQuery({queryKey:["tables",i,c,o],queryFn:()=>e.getRequest("https://semaphor.cloud/api/v1/tables",(r==null?void 0:r.accessToken)||"",{connection_id:i,database_name:c,schema_name:o}),enabled:C(B)}),{data:G,isLoading:se,isFetching:q,isError:Q}=e.useQuery({queryKey:["columns",i,c,o,a],queryFn:()=>e.getRequest("https://semaphor.cloud/api/v1/columns",(r==null?void 0:r.accessToken)||"",{connection_id:i,datamodel_id:x||"",database_name:c,schema_name:o,table_name:a}),enabled:y(B)});f.useEffect(()=>{h(t)},[G,h,t]),f.useEffect(()=>{},[O,E,m,l,v,w]);const J=(w==null?void 0:w.type)==="API"?(je=w==null?void 0:w.type)==null?void 0:je.toLowerCase():a||"",re=O?"":o||"";function W(j){l(j),m("")}function ue(j){v(j==="none"?"":j),l(""),m(""),j!=="none"&&j!==""&&d("")}function Fe(j){u(j),v(""),d(""),l(""),m("")}function ae(j){d(j==="none"?"":j),j!=="none"&&j!==""&&v("")}L&&((de=L==null?void 0:L.databases)==null?void 0:de.length)>0,M&&((Ee=M==null?void 0:M.schemas)==null?void 0:Ee.length)>0,G&&((fe=G==null?void 0:G.columns)==null?void 0:fe.length)>0&&(t=G.columns.map(j=>({...j,data_type:j.data_type.toLowerCase()}))),H&&(t=[]),(Q||S)&&(t=[]);const ye=b==null?void 0:b.connections.map(j=>({id:j.id,name:j.name,type:j.type})),he=(p=N==null?void 0:N.datamodels)==null?void 0:p.map(j=>({id:j.id,name:j.name})),ve=L==null?void 0:L.databases.map(j=>({id:j.database_name,name:j.database_name})),Ce=M==null?void 0:M.schemas.map(j=>({id:j.schema_name,name:j.schema_name})),Ne=F==null?void 0:F.tables.map(j=>({id:j.table_name,name:j.table_name}));return{connectionItems:ye,isConnectionsLoading:I,isConnectionsError:S,modelItems:he,isModelsLoading:A,isModelsError:D,databaseItems:ve,isDatabasesLoadingOrFetching:U||_,isDatabaseError:H,schemaItems:Ce,isSchemaLoadingOrFetching:$||g,isSchemaError:R,tableItems:Ne,isTableLoadingOrFetching:T||K,isTableError:oe,columns:t,isColumnsLoadingOrFetching:se||q,isColumnsError:Q,isNonDbConnection:O,connectionType:B,tableName:J,schemaName:re,handleConnectionChange:Fe,handleDatamodelChange:ae,handleDatabaseChange:ue,handleSchemaChange:W}}function Qe({ColumnsComponent:s}){var F;const n=e.useEditorStore(T=>T.selectedConnectionId),t=e.useEditorStore(T=>T.selectedDatamodelId),r=e.useEditorStore(T=>T.selectedDatabaseName),i=e.useEditorStore(T=>T.selectedSchemaName),x=e.useEditorStore(T=>T.selectedTableName),c=e.useEditorStore(T=>T.actions.setSelectedTableName),{connectionItems:o,modelItems:a,schemaItems:h,databaseItems:u,tableItems:d,columns:v,isConnectionsLoading:l,isModelsLoading:m,isConnectionsError:E,isModelsError:C,isDatabasesLoadingOrFetching:y,isDatabaseError:z,isSchemaLoadingOrFetching:b,isSchemaError:I,isColumnsError:S,isColumnsLoadingOrFetching:N,isTableLoadingOrFetching:A,isTableError:D,connectionType:w,isNonDbConnection:B,handleConnectionChange:O,handleDatabaseChange:L,handleSchemaChange:U,handleDatamodelChange:_,tableName:H,schemaName:P}=Te();function M(){return s?s(P,H,v):e.jsxRuntimeExports.jsx(Vs,{schemaName:P,tableName:H,columns:v,status:N?"Loading...":S?"Error":"Success"})}function $(){window.location.href="mailto:support@semaphor.cloud?subject=Help&body=I need help with..."}function g(){return w==="S3"||w==="API"||!n||n==="none"||t&&t!=="none"?null:e.jsxRuntimeExports.jsx(pe,{showNone:!0,onChange:L,isError:z,isLoading:y,items:u,value:r||"",title:"Database"})}function R(){return w==="S3"||w==="API"||!r||n==="none"||r==="none"?null:e.jsxRuntimeExports.jsx(pe,{onChange:U,isError:I,isLoading:b,items:h,value:i||"",title:"Schema"})}function k(){return w==="API"||!i||i==="none"||n==="none"||r==="none"?null:e.jsxRuntimeExports.jsx(pe,{onChange:c,isError:D,items:d,isLoading:A,value:x||"",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(pe,{items:o,title:"Connection",value:n||"",onChange:O,isLoading:l,isError:E,connectionTooltip:((F=o==null?void 0:o.find(T=>T.id===n))==null?void 0:F.type)||""}),g(),R(),k()]}),M(),e.jsxRuntimeExports.jsx("div",{className:"flex items-end justify-center gap-2 px-6 py-4",children:e.jsxRuntimeExports.jsxs(e.Button,{onClick:$,size:"sm",variant:"secondary",className:"w-full",children:[e.jsxRuntimeExports.jsx(vs,{className:"mr-2 size-4"}),"Help"]})})]})}function _s(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 x=s.length;if(i!==-1&&(x=i),r!==-1&&r<x&&(x=r),n!==-1){const c=s.substring(0,n),o=s.substring(n);return`${c} {{ filters | where }} AND ${o.substring(6)}`}else if(t!==-1){const c=s.substring(0,t),o=s.substring(t);return`${c} {{ filters | where }} ${o}`}else{const c=s.substring(0,x),o=s.substring(x);return`${c} {{ filters | where }} ${o}`}}function Hs({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(ps,{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(fs,{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 Ps({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=f.useRef(null),t=e.useEditorStore(o=>o.applyFilters),[r,i]=f.useState(""),x=e.useEditorStore(o=>o.filterValues),c=e.useEditorStore(o=>o.card.sql);return e.jsxRuntimeExports.jsxs(e.HoverCard,{openDelay:0,onOpenChange:async o=>{if(!o)return;console.log("onOpenChange");const a=await e.postRequest("https://semaphor.cloud/api/v1/filter-sql",(s==null?void 0:s.accessToken)||"",{sql:c,active_filters:x});console.log(a),a.sql?(console.log(a.records),i(a.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 Gs=`
161
+ */const Ds=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 Fs(){const[s,n]=f.useState(""),[t,r]=f.useState(!1),[i,x]=f.useState(!1),l=e.useDashboardStore(a=>a.dashboard);function o(){const a=e.getDashbaordStateWithoutData(l),h=e.getBookmarkKey(l.id),u=JSON.parse(localStorage.getItem(h)||"[]");if(u.some(v=>v.name===s)){r(!0);return}u.push({name:s,template:a}),localStorage.setItem(h,JSON.stringify(u)),x(!1)}return e.jsxRuntimeExports.jsxs(e.Dialog,{open:i,onOpenChange:x,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:a=>{t&&r(!1),n(a.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:o,children:"Save"})})]})]})}function Os(){const[s,n]=f.useState(!1),[t,r]=f.useState(""),i=e.useDashboardStore(c=>c.dashboard),x=e.useDashboardStore(c=>c.bookmarkKey),[l,o]=f.useState([]),a=e.useDashboardStore(c=>c.actions.setDashboard),h=e.useDashboardStore(c=>c.actions.setFilterValues),u=e.useDashboardStore(c=>c.actions.setBookmarkKey);f.useEffect(()=>{const c=e.getBookmarkKey(i.id),m=JSON.parse(localStorage.getItem(c)||"[]");o(m);const E=m.find(C=>C.default);E&&E.name===x&&r(E.name)},[s,i,x]);function d(c){if(c===t)return;const m=l.find(C=>C.name===c),E=m==null?void 0:m.template;E&&(a(E),h(m.filterValues||[]),u(c==="Original"?"":c)),r(c)}function v(c){const m=e.getBookmarkKey(i.id),C=JSON.parse(localStorage.getItem(m)||"[]").filter(y=>y.name!==c);localStorage.setItem(m,JSON.stringify(C)),o(C)}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(Es,{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"}),l.filter(c=>c.name!="Original").map((c,m)=>e.jsxRuntimeExports.jsxs(e.DropdownMenuRadioItem,{className:"xbg-red-100 flex justify-between",value:c.name,defaultChecked:c.name===x,children:[e.jsxRuntimeExports.jsx("p",{children:c.name}),e.jsxRuntimeExports.jsx(e.Cross2Icon,{onClick:E=>{E.preventDefault(),v(c.name)},className:"h-3 w-3 hover:cursor-pointer",strokeWidth:1.5})]},m))]})]})]})}function Ms(){const[s,n]=f.useState(!1),t=e.useDashboardStore(x=>x.dashboard),r=e.useDashboardStore(x=>x.bookmarkKey);f.useEffect(()=>{if(!r){n(!1);return}const x=e.getBookmarkKey(t.id),o=JSON.parse(localStorage.getItem(x)||"[]").find(a=>a.name===r);n(o?o.default:!1)},[r,t.id]);function i(x){if(n(x),!r)return;const l=e.getBookmarkKey(t.id),a=JSON.parse(localStorage.getItem(l)||"[]").map(h=>(h.name===r?h.default=x:h.default=!1,h));console.log(a),localStorage.setItem(l,JSON.stringify(a))}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 Bs(){const s=e.useDashboardStore(y=>y.bookmarkKey),n=e.useDashboardStore(y=>y.dashboard);e.useDashboardStore(y=>y.selectedSheetId);const t=e.useDashboardStore(y=>y.isDashboardEditing),r=e.useDashboardStore(y=>y.filterValues),i=e.useDashboardStore(y=>y.isVisualEditing),x=e.useDashboardStore(y=>y.showFilters);e.useDashboardStore(y=>y.showDashboardJSON);const l=e.useDashboardStore(y=>y.onSaveFunction),o=e.useDashboardStore(y=>y.actions.setShowFilters),{addFrame:a,setSelectedFrameId:h}=e.useDashboardStore(y=>y.actions),{getSelectedSheet:u,setIsDashboardEditing:d,setShowDashboardJSON:v}=e.useDashboardStore(y=>y.actions),c=u(),m=()=>{if(!t||!c)return;const y={id:e.v4(),title:"Title",description:"Description",preferences:{onClickFilter:[{columnIndex:0,expression:""}]},type:"bar",sql:"select COUNT(*) from YOUR_TABLE",data:[]},z={id:e.v4(),cards:[y],activeCardId:y.id};a(c.id,z),h(z.id)},E=()=>{d(!0)};function C(){if(!s||s==="")return;const y=e.getDashbaordStateWithoutData(n),z=e.getBookmarkKey(n.id),b=JSON.parse(localStorage.getItem(z)||"[]"),I=b.findIndex(S=>S.name===s);I!==-1?b[I]={name:s,template:y,default:b[I].default,filterValues:r}:b.push({name:s,template:y,filterValues:r}),localStorage.setItem(z,JSON.stringify(b)),l==null||l(y)}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(Ms,{})]})]}),e.jsxRuntimeExports.jsxs("div",{className:"flex gap-2",children:[t&&!i&&e.jsxRuntimeExports.jsx(Fs,{}),!i&&e.jsxRuntimeExports.jsx(Os,{}),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:E,size:"sm",children:e.jsxRuntimeExports.jsx(Pe,{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),v(!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:C,size:"sm",children:e.jsxRuntimeExports.jsx(ws,{className:"h-4 w-4",strokeWidth:1.5})}),!x&&!i&&t&&e.jsxRuntimeExports.jsx(e.Button,{className:"h-7 p-2",variant:"outline",onClick:()=>o(!0),size:"sm",children:e.jsxRuntimeExports.jsx(_e,{className:"h-4 w-4",strokeWidth:1.5})}),!i&&t&&!1,!i&&!1]})]})}function pe({title:s,items:n,value:t,isLoading:r,isError:i,connectionTooltip:x,onChange:l,showNone:o=!1,className:a,showIcon:h=!0,disabled:u=!1}){const d=r?"Loading...":i?"Error":t;function v(){if(s==="Connection")return e.jsxRuntimeExports.jsx(ks,{className:"size-4 rotate-90"});if(s==="Database")return e.jsxRuntimeExports.jsx(hs,{className:"size-4"});if(s==="Schema")return e.jsxRuntimeExports.jsx(Cs,{className:"size-4"});if(s==="Table")return e.jsxRuntimeExports.jsx(e.Table,{className:"size-4"});if(s==="Dataset")return e.jsxRuntimeExports.jsx(ms,{className:"size-4"})}return e.jsxRuntimeExports.jsxs("div",{className:"flex items-center gap-2",children:[h&&e.jsxRuntimeExports.jsx("div",{className:"shrink-0",children:x?e.jsxRuntimeExports.jsxs(e.Tooltip,{children:[e.jsxRuntimeExports.jsx(e.TooltipTrigger,{children:v()}),e.jsxRuntimeExports.jsx(e.TooltipContent,{className:"text-xs",align:"start",children:x})]}):v()}),e.jsxRuntimeExports.jsxs(e.Select,{disabled:u,value:d,onValueChange:l,children:[e.jsxRuntimeExports.jsx(e.SelectTrigger,{className:e.cn("h-9 w-full focus:ring-1 focus:ring-offset-0",a),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.jsxs(e.jsxRuntimeExports.Fragment,{children:[o&&e.jsxRuntimeExports.jsx(e.SelectItem,{value:"none",children:"None"},"none"),n&&n.map((c,m)=>e.jsxRuntimeExports.jsx(e.SelectItem,{value:c.id,children:c.name},m))]}),(r||i)&&e.jsxRuntimeExports.jsx(e.SelectItem,{value:d,children:d})]})})]})]})}function qs({column:s}){const[n,t]=f.useState(!1),r=e.useEditorStore(u=>u.selectedTableName),i=e.useEditorStore(u=>u.selectedSchemaName),x=e.useEditorStore(u=>u.sqlGen),l=e.useEditorStore(u=>u.actions.setSqlGen),o=e.useEditorStore(u=>u.actions.setCardSql),a=e.useEditorStore(u=>u.actions.setRunSql);function h(u,d){const v=e.createSqlGenConfig(u,x,d);l(v);const c=e.getSql(v,e.fmt(i||""),e.fmt(r));c&&(o(c),a(!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 Ke({column:s}){return e.jsxRuntimeExports.jsxs(e.Tooltip,{children:[e.jsxRuntimeExports.jsx(e.$a093c7e1ec25a057$export$8c610744efcf8a1d,{asChild:!0,children:e.TEXT_DATA_TYPES.includes(s.data_type.toLowerCase())?e.jsxRuntimeExports.jsx(Le,{className:"size-3"}):e.NUMBER_DATA_TYPES.includes(s.data_type.toLowerCase())?e.jsxRuntimeExports.jsx(gs,{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(Ts,{className:"size-3"}):e.jsxRuntimeExports.jsx(As,{className:"size-3"})}),e.jsxRuntimeExports.jsx(e.TooltipContent,{children:e.jsxRuntimeExports.jsx("p",{className:"font-mono text-xs",children:s.data_type})})]})}function Vs({schemaName:s,tableName:n,columns:t,status:r}){const i=e.useEditorStore(S=>S.sqlGen),x=e.useEditorStore(S=>S.selectedConnectionId),l=e.useEditorStore(S=>S.selectedDatabaseName),o=e.useEditorStore(S=>S.selectedSchemaName),a=e.useEditorStore(S=>S.selectedTableName),h=e.useDashboardStore(S=>S.dashboard.aiScopeTables),{setAIScopeTables:u}=e.useDashboardStore(S=>S.actions),d=e.useEditorStore(S=>S.actions.setRunSql),v=e.useEditorStore(S=>S.actions.setSqlGen),c=e.useEditorStore(S=>S.actions.setIsShowingVisual),m=e.useEditorStore(S=>S.actions.setCardSql),{connectionType:E}=Te();function C(S){const N=e.createSqlGenConfig(S,i);v(N);const A=e.getSql(N,e.fmt(s),e.fmt(n));A&&(m(A),d(!0))}function y(){return(h==null?void 0:h.find(S=>S.connectinonId===x&&S.tableName===a))!==void 0}function z(S){if(S===!0&&a&&x){const N={connectinonId:x,connectionType:E,databaseName:l,schemaName:o,tableName:a},D=[...h||[],N].filter((w,B,O)=>O.findIndex(L=>L.connectinonId===w.connectinonId&&L.tableName===w.tableName)===B);u(D),e.Jt.success(`Added '${a}' to AI Scope`,{position:"top-right",duration:2500,richColors:!0})}else{const N=(h||[]).filter(A=>A.connectinonId!==x&&A.tableName!==a);u(N),e.Jt(`Removed '${a}' from AI Scope`,{position:"top-right",duration:2e3,richColors:!0})}}function b(){let N=e.getQualifiedTableName(s,n);(w=>w.charAt(0)===w.charAt(0).toUpperCase())(n)&&(N=`"${n}"`),c(!1);const D=E==="MSSQL"?`SELECT top 10 * FROM ${N}`:`SELECT * FROM ${N} LIMIT 10`;m(D),d(!0)}function I(){let N=e.getQualifiedTableName(s,n);(D=>D.charAt(0)===D.charAt(0).toUpperCase())(n)&&(N=`"${n}"`),c(!1),m(`SELECT COUNT(*) as count FROM ${N}`),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:`${y()?"Remove from":"Add to"} AI Scope`,pressed:y(),onPressedChange:z,variant:"outline",className:"h-9 px-2",children:e.jsxRuntimeExports.jsx(e.Bot,{className:e.cn("size-4",{"text-primary":y(),"text-muted-foreground":!y()})})}),e.jsxRuntimeExports.jsxs(e.Button,{disabled:r!=="Success",onClick:b,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(Is,{className:"mr-2 size-4"}),"Top 10"]}),e.jsxRuntimeExports.jsxs(e.Button,{disabled:r!=="Success",onClick:I,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(zs,{className:"mr-2 size-4"}),"Count"]})]}),e.jsxRuntimeExports.jsxs(e.ScrollArea,{className:"flex-1 basis-0 overflow-y-auto border-b border-t border-muted py-3",children:[t==null?void 0:t.map(S=>e.jsxRuntimeExports.jsxs("div",{onClick:()=>C(S),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(S,i)}),children:[e.jsxRuntimeExports.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsxRuntimeExports.jsx(Ke,{column:S}),e.jsxRuntimeExports.jsx("span",{children:S.column_name})]}),e.NUMBER_DATA_TYPES.includes(S.data_type)&&e.jsxRuntimeExports.jsx("div",{onClick:N=>N.stopPropagation(),className:"flex items-center justify-end",children:e.jsxRuntimeExports.jsx(qs,{column:S})})]},S.column_name)),e.jsxRuntimeExports.jsx(e.ScrollBar,{orientation:"vertical"}),e.jsxRuntimeExports.jsx(e.ScrollBar,{orientation:"horizontal"})]})]})}function Te(s,n){var je,de,Ee,fe,p;let t=f.useMemo(()=>[],[]);const r=e.useSemaphorContext().authToken||s,i=e.useEditorStore(j=>j.selectedConnectionId),x=e.useEditorStore(j=>j.selectedDatamodelId),l=e.useEditorStore(j=>j.selectedDatabaseName),o=e.useEditorStore(j=>j.selectedSchemaName),a=e.useEditorStore(j=>j.selectedTableName),h=e.useEditorStore(j=>j.actions.setCurrentColumns),u=e.useEditorStore(j=>j.actions.setSelectedConnectionId),d=e.useEditorStore(j=>j.actions.setSelectedDatamodelId),v=e.useEditorStore(j=>j.actions.setSelectedDatabaseName),c=e.useEditorStore(j=>j.actions.setSelectedSchemaName),m=e.useEditorStore(j=>j.actions.setSelectedTableName),E=e.useEditorStore(j=>j.actions.setCardSql);function C(j){return i&&l&&o&&l!=="NA"?!0:i&&j==="API"?!1:!!(i&&j==="S3")}function y(j){return!!(i&&l&&l!=="NA"&&o&&a||i&&(j==="S3"||j==="API")||x&&x)}function z(j){return i&&j?!(j==="API"||j==="S3"):!1}const{data:b,isLoading:I,isError:S}=e.useQuery({queryKey:["connections"],queryFn:()=>e.getRequest("https://semaphor.cloud/api/v1/connections",(r==null?void 0:r.accessToken)||""),enabled:!!(r!=null&&r.accessToken)}),{data:N,isLoading:A,isError:D}=e.useQuery({queryKey:["models",i],queryFn:()=>e.getRequest("https://semaphor.cloud/api/v1/datamodels",(r==null?void 0:r.accessToken)||"",{connection_id:i}),enabled:!!(r!=null&&r.accessToken)&&!!i}),w=b==null?void 0:b.connections.find(j=>j.id===i),B=w==null?void 0:w.type,O=(w==null?void 0:w.type)==="API"||(w==null?void 0:w.type)==="S3",{data:L,isLoading:U,isFetching:_,isError:H,refetch:P}=e.useQuery({queryKey:["databases",i],queryFn:()=>e.getRequest("https://semaphor.cloud/api/v1/databases",(r==null?void 0:r.accessToken)||"",{connection_id:i}),enabled:z(B)}),{data:M,isLoading:$,isFetching:g,isError:R,refetch:k}=e.useQuery({queryKey:["schemas",i,l],queryFn:()=>e.getRequest("https://semaphor.cloud/api/v1/schemas",(r==null?void 0:r.accessToken)||"",{connection_id:i,database_name:l}),enabled:!!i&&!!l&&!O&&l!=="NA"}),{data:F,isLoading:T,isFetching:K,isError:oe,refetch:ie}=e.useQuery({queryKey:["tables",i,l,o],queryFn:()=>e.getRequest("https://semaphor.cloud/api/v1/tables",(r==null?void 0:r.accessToken)||"",{connection_id:i,database_name:l,schema_name:o}),enabled:C(B)}),{data:G,isLoading:se,isFetching:q,isError:Q}=e.useQuery({queryKey:["columns",i,l,o,a],queryFn:()=>e.getRequest("https://semaphor.cloud/api/v1/columns",(r==null?void 0:r.accessToken)||"",{connection_id:i,datamodel_id:x||"",database_name:l,schema_name:o,table_name:a}),enabled:y(B)});f.useEffect(()=>{h(t)},[G,h,t]),f.useEffect(()=>{},[O,E,m,c,v,w]);const J=(w==null?void 0:w.type)==="API"?(je=w==null?void 0:w.type)==null?void 0:je.toLowerCase():a||"",re=O?"":o||"";function W(j){c(j),m("")}function ue(j){v(j==="none"?"":j),c(""),m(""),j!=="none"&&j!==""&&d("")}function Fe(j){u(j)}function ae(j){d(j==="none"?"":j),j!=="none"&&j!==""&&v("")}L&&((de=L==null?void 0:L.databases)==null?void 0:de.length)>0,M&&((Ee=M==null?void 0:M.schemas)==null?void 0:Ee.length)>0,G&&((fe=G==null?void 0:G.columns)==null?void 0:fe.length)>0&&(t=G.columns.map(j=>({...j,data_type:j.data_type.toLowerCase()}))),H&&(t=[]),(Q||S)&&(t=[]);const ye=b==null?void 0:b.connections.map(j=>({id:j.id,name:j.name,type:j.type})),he=(p=N==null?void 0:N.datamodels)==null?void 0:p.map(j=>({id:j.id,name:j.name})),ve=L==null?void 0:L.databases.map(j=>({id:j.database_name,name:j.database_name})),Ce=M==null?void 0:M.schemas.map(j=>({id:j.schema_name,name:j.schema_name})),Ne=F==null?void 0:F.tables.map(j=>({id:j.table_name,name:j.table_name}));return{connectionItems:ye,isConnectionsLoading:I,isConnectionsError:S,modelItems:he,isModelsLoading:A,isModelsError:D,databaseItems:ve,isDatabasesLoadingOrFetching:U||_,isDatabaseError:H,schemaItems:Ce,isSchemaLoadingOrFetching:$||g,isSchemaError:R,tableItems:Ne,isTableLoadingOrFetching:T||K,isTableError:oe,columns:t,isColumnsLoadingOrFetching:se||q,isColumnsError:Q,isNonDbConnection:O,connectionType:B,tableName:J,schemaName:re,handleConnectionChange:Fe,handleDatamodelChange:ae,handleDatabaseChange:ue,handleSchemaChange:W}}function Qe({ColumnsComponent:s}){var F;const n=e.useEditorStore(T=>T.selectedConnectionId),t=e.useEditorStore(T=>T.selectedDatamodelId),r=e.useEditorStore(T=>T.selectedDatabaseName),i=e.useEditorStore(T=>T.selectedSchemaName),x=e.useEditorStore(T=>T.selectedTableName),l=e.useEditorStore(T=>T.actions.setSelectedTableName),{connectionItems:o,modelItems:a,schemaItems:h,databaseItems:u,tableItems:d,columns:v,isConnectionsLoading:c,isModelsLoading:m,isConnectionsError:E,isModelsError:C,isDatabasesLoadingOrFetching:y,isDatabaseError:z,isSchemaLoadingOrFetching:b,isSchemaError:I,isColumnsError:S,isColumnsLoadingOrFetching:N,isTableLoadingOrFetching:A,isTableError:D,connectionType:w,isNonDbConnection:B,handleConnectionChange:O,handleDatabaseChange:L,handleSchemaChange:U,handleDatamodelChange:_,tableName:H,schemaName:P}=Te();function M(){return s?s(P,H,v):e.jsxRuntimeExports.jsx(Vs,{schemaName:P,tableName:H,columns:v,status:N?"Loading...":S?"Error":"Success"})}function $(){window.location.href="mailto:support@semaphor.cloud?subject=Help&body=I need help with..."}function g(){return w==="S3"||w==="API"||!n||n==="none"||t&&t!=="none"?null:e.jsxRuntimeExports.jsx(pe,{showNone:!0,onChange:L,isError:z,isLoading:y,items:u,value:r||"",title:"Database"})}function R(){return w==="S3"||w==="API"||!r||n==="none"||r==="none"?null:e.jsxRuntimeExports.jsx(pe,{onChange:U,isError:I,isLoading:b,items:h,value:i||"",title:"Schema"})}function k(){return w==="API"||!i||i==="none"||n==="none"||r==="none"?null:e.jsxRuntimeExports.jsx(pe,{onChange:l,isError:D,items:d,isLoading:A,value:x||"",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(pe,{items:o,title:"Connection",value:n||"",onChange:O,isLoading:c,isError:E,connectionTooltip:((F=o==null?void 0:o.find(T=>T.id===n))==null?void 0:F.type)||""}),g(),R(),k()]}),M(),e.jsxRuntimeExports.jsx("div",{className:"flex items-end justify-center gap-2 px-6 py-4",children:e.jsxRuntimeExports.jsxs(e.Button,{onClick:$,size:"sm",variant:"secondary",className:"w-full",children:[e.jsxRuntimeExports.jsx(vs,{className:"mr-2 size-4"}),"Help"]})})]})}function _s(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 x=s.length;if(i!==-1&&(x=i),r!==-1&&r<x&&(x=r),n!==-1){const l=s.substring(0,n),o=s.substring(n);return`${l} {{ filters | where }} AND ${o.substring(6)}`}else if(t!==-1){const l=s.substring(0,t),o=s.substring(t);return`${l} {{ filters | where }} ${o}`}else{const l=s.substring(0,x),o=s.substring(x);return`${l} {{ filters | where }} ${o}`}}function Hs({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(ps,{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(fs,{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 Ps({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=f.useRef(null),t=e.useEditorStore(o=>o.applyFilters),[r,i]=f.useState(""),x=e.useEditorStore(o=>o.filterValues),l=e.useEditorStore(o=>o.card.sql);return e.jsxRuntimeExports.jsxs(e.HoverCard,{openDelay:0,onOpenChange:async o=>{if(!o)return;console.log("onOpenChange");const a=await e.postRequest("https://semaphor.cloud/api/v1/filter-sql",(s==null?void 0:s.accessToken)||"",{sql:l,active_filters:x});console.log(a),a.sql?(console.log(a.records),i(a.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 Gs=`
162
162
 
163
163
  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.
164
164
 
@@ -204,7 +204,7 @@ SELECT label, measure FROM table
204
204
 
205
205
  - Label - Category
206
206
  - Measure - Number
207
- `;function Ks({open:s,setOpen:n,userInput:t,setUserInput:r,triggerAIRun:i,setTriggerAIRun:x}){const c=f.useRef(null),o=f.useRef(null),{authToken:a}=e.useSemaphorContext(),[h,u]=f.useState(!1),d=e.useEditorStore(g=>g.actions.setCardSql),v=e.useDashboardStore(g=>g.dashboard.baseQueries),l=e.useEditorStore(g=>g.actions.setRunSql),m=e.useEditorStore(g=>g.actions.setCardType),[E,C]=f.useState([]),y=e.useEditorStore(g=>g.currentColumns),z=e.useEditorStore(g=>g.card.sql),b=e.useEditorStore(g=>g.selectedTableName),I=`
207
+ `;function Ks({open:s,setOpen:n,userInput:t,setUserInput:r,triggerAIRun:i,setTriggerAIRun:x}){const l=f.useRef(null),o=f.useRef(null),{authToken:a}=e.useSemaphorContext(),[h,u]=f.useState(!1),d=e.useEditorStore(g=>g.actions.setCardSql),v=e.useDashboardStore(g=>g.dashboard.baseQueries),c=e.useEditorStore(g=>g.actions.setRunSql),m=e.useEditorStore(g=>g.actions.setCardType),[E,C]=f.useState([]),y=e.useEditorStore(g=>g.currentColumns),z=e.useEditorStore(g=>g.card.sql),b=e.useEditorStore(g=>g.selectedTableName),I=`
208
208
  ${t}
209
209
 
210
210
  Database Query Dialect: ${b==="api"||b==="s3"?"DuckDb":""}
@@ -212,4 +212,4 @@ SELECT label, measure FROM table
212
212
  Table Columns: ${y==null?void 0:y.map(g=>`${g.column_name} | ${g.data_type}`).join(", ")}
213
213
  User SQL: ${z}
214
214
  ${v&&`Base Queries: ${JSON.stringify(v)} `}`,S=` 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.
215
- Visual Query Syntax: ${Gs}`,{data:N,isLoading:A,isFetching:D,isError:w,refetch:B}=e.useQuery({queryKey:["ai-query"],queryFn:()=>e.getRequest("https://semaphor.cloud/api/v1/ai",(a==null?void 0:a.accessToken)||"",{user_content:`userContent: ${I} ${h?S:""}`}),enabled:!1});function O(g){if(g.toLowerCase().includes("bar"))m("bar");else if(g.toLowerCase().includes("line"))m("line");else if(g.toLowerCase().includes("bubble"))m("bubble");else if(g.toLowerCase().includes("scatter"))m("scatter");else if(g.toLowerCase().includes("stacked"))m("stackedBar");else if(g.toLowerCase().includes("pie"))m("pie");else if(g.toLowerCase().includes("donut")||g.toLowerCase().includes("doughnut"))m("doughnut");else if(g.toLowerCase().includes("radar"))m("radar");else return m("bar"),!1;return!0}f.useEffect(()=>{N&&C(g=>[...g,{role:"ai",content:N.response}])},[N]),f.useEffect(()=>{const g=setTimeout(()=>{var R;o.current&&(o.current.scroll({top:o.current.scrollHeight,behavior:"smooth"}),(R=c.current)==null||R.focus())},100);return()=>clearTimeout(g)},[E]);function L(){t&&(C(g=>[...g,{role:"user",content:t}]),O(t)&&u(!0),r(""),B())}f.useEffect(()=>{i&&(L(),x(!1))},[i,x]);const U={fontFamily:"Arial, sans-serif",lineHeight:1.6,fontSize:15,width:"100%"},_={fontFamily:"monospace",fontSize:14,lineHeight:1.6},H={fontFamily:"Arial, sans-serif",lineHeight:1.6,fontSize:15,padding:"2px 0",marginLeft:20,listStyleType:"disc"},P={p:({node:g,...R})=>e.jsxRuntimeExports.jsx("p",{style:U,...R}),code:({node:g,...R})=>e.jsxRuntimeExports.jsx("code",{className:"rounded-sm bg-muted px-2 py-1 text-sm",...R}),pre:({node:g,...R})=>e.jsxRuntimeExports.jsxs("pre",{className:"space-y-2 rounded-sm bg-muted/50 p-3",style:_,children:[e.jsxRuntimeExports.jsx("code",{className:"whitespace-normal text-sm",children:R.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:k=>{const F=M(k);F&&(n(!1),d(F),l(!0))},size:"sm",variant:"outline",children:e.jsxRuntimeExports.jsx(e.PlayIcon,{})})]})]}),li:({node:g,...R})=>e.jsxRuntimeExports.jsx("li",{style:H,...R})};function M(g){const R=g.currentTarget.closest("pre");if(!R)return;const k=R.textContent||R.innerText;return navigator.clipboard.writeText(k).then(()=>console.log("Text copied to clipboard")).catch(F=>console.error("Error in copying text: ",F)),k}function $(){return E==null?void 0:E.map((g,R)=>g.role==="user"?e.jsxRuntimeExports.jsxs("div",{className:"flex items-start rounded-md bg-muted p-3 text-sm",children:[e.jsxRuntimeExports.jsx(Ds,{className:"mr-2 h-5 w-5"}),e.jsxRuntimeExports.jsx("div",{children:g.content})]},R):g.role==="ai"?e.jsxRuntimeExports.jsx(e.Markdown,{className:"w-full overflow-auto py-1",components:P,children:N==null?void 0:N.response.replace(/DuckDB/gi,"Semaphor")},R):e.jsxRuntimeExports.jsx("div",{},R))}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:o,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:$()})}),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:c,onKeyDown:g=>{g.key==="Enter"&&!g.shiftKey&&(g.preventDefault(),r(""),L())},placeholder:"Type your question here...",onFocus:g=>{const R=g.target,k=R.value.length;R.setSelectionRange(k,k)},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:g=>r(g.target.value)})," ",e.jsxRuntimeExports.jsx(e.Button,{className:"h-8",size:"sm",variant:"ghost",onClick:L,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 Ue={color:void 0,size:void 0,className:void 0,style:void 0,attr:void 0},Me=f.createContext&&f.createContext(Ue),Qs=["attr","size","title"];function Us(s,n){if(s==null)return{};var t=Js(s,n),r,i;if(Object.getOwnPropertySymbols){var x=Object.getOwnPropertySymbols(s);for(i=0;i<x.length;i++)r=x[i],!(n.indexOf(r)>=0)&&Object.prototype.propertyIsEnumerable.call(s,r)&&(t[r]=s[r])}return t}function Js(s,n){if(s==null)return{};var t={},r=Object.keys(s),i,x;for(x=0;x<r.length;x++)i=r[x],!(n.indexOf(i)>=0)&&(t[i]=s[i]);return t}function Re(){return Re=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},Re.apply(this,arguments)}function Be(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 be(s){for(var n=1;n<arguments.length;n++){var t=arguments[n]!=null?arguments[n]:{};n%2?Be(Object(t),!0).forEach(function(r){Ws(s,r,t[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(s,Object.getOwnPropertyDescriptors(t)):Be(Object(t)).forEach(function(r){Object.defineProperty(s,r,Object.getOwnPropertyDescriptor(t,r))})}return s}function Ws(s,n,t){return n=Ys(n),n in s?Object.defineProperty(s,n,{value:t,enumerable:!0,configurable:!0,writable:!0}):s[n]=t,s}function Ys(s){var n=Xs(s,"string");return typeof n=="symbol"?n:String(n)}function Xs(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 Je(s){return s&&s.map((n,t)=>f.createElement(n.tag,be({key:t},n.attr),Je(n.child)))}function ee(s){return n=>f.createElement(Zs,Re({attr:be({},s.attr)},n),Je(s.child))}function Zs(s){var n=t=>{var{attr:r,size:i,title:x}=s,c=Us(s,Qs),o=i||t.size||"1em",a;return t.className&&(a=t.className),s.className&&(a=(a?a+" ":"")+s.className),f.createElement("svg",Re({stroke:"currentColor",fill:"currentColor",strokeWidth:"0"},t.attr,r,c,{className:a,style:be(be({color:s.color||t.color},t.style),s.style),height:o,width:o,xmlns:"http://www.w3.org/2000/svg"}),x&&f.createElement("title",null,x),s.children)};return Me!==void 0?f.createElement(Me.Consumer,null,t=>n(t)):n(Ue)}function et(s){return ee({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 st(){const{theme:s}=e.useTheme(),n=f.useRef(),t=f.useRef(),[r,i]=f.useState(!1),[x,c]=f.useState(!1),[o,a]=f.useState(!1),[h,u]=f.useState(""),[d,v]=f.useState(!1),{authToken:l}=e.useSemaphorContext();e.useDashboardStore(p=>p.selectedSheetId);const m=e.useDashboardStore(p=>p.dashboard.baseQueries),E=e.useEditorStore(p=>p.card),C=e.useDashboardStore(p=>p.theme),y=e.useEditorStore(p=>p.isShowingVisual),z=e.useEditorStore(p=>p.selectedConnectionId),b=e.useEditorStore(p=>p.selectedDatabaseName),I=e.useEditorStore(p=>p.selectedSchemaName);e.useDashboardStore(p=>p.actions.updateFrameCard);const S=e.useEditorStore(p=>p.selectedTableName),N=e.useEditorStore(p=>p.card.sql),A=e.useEditorStore(p=>p.card.python),D=e.resolveBaseQuery(N,m),w=e.useEditorStore(p=>p.selectedConnectionId),B=e.useEditorStore(p=>p.frame),O=e.useEditorStore(p=>p.filterValues),L=e.useEditorStore(p=>p.applyFilters),{setCardCustomCfg:U,setQueryResultColumns:_,setFilterValues:H,setCardSql:P,setCardPython:M,setQueryError:$,setPythonStdOut:g,setCardPreferences:R}=e.useEditorStore(p=>p.actions),k=e.useEditorStore(p=>p.onSave),F=e.useEditorStore(p=>p.actions.setApplyFilters),T=e.useEditorStore(p=>p.onClose),K=e.useEditorStore(p=>p.actions.setCardData),oe=e.useEditorStore(p=>p.actions.setSqlGen),ie=e.useEditorStore(p=>p.runSql),G=e.useEditorStore(p=>p.actions.setRunSql),se=e.useEditorStore(p=>p.actions.setIsSqlRunning),{data:q,isLoading:Q,isFetching:J,isSuccess:re,isError:W,error:ue,status:Fe,refetch:ae}=e.useQuery({queryKey:[D,A],queryFn:()=>e.postRequest("https://semaphor.cloud/api/v1/query",(l==null?void 0:l.accessToken)||"",{connection_id:w,sql:D,python:A===e.PYTHON_DEFAULT_CODE?"":A,active_filters:L?O:[]}),enabled:!1,retry:!1});f.useEffect(()=>{if(q&&(K(q.records),q.rowLimitExceeded&&e.Jt.error("Row limit (10,000) exceeded. Refine your query.",{position:"top-center",richColors:!0}),g((q==null?void 0:q.output)||""),q.records.length>0)){const{dimensionKeys:p}=e.getKeys(q.records);_(p)}},[q,K,_,g]),f.useEffect(()=>{ie&&(ae(),G(!1))},[ie,ae,G]),f.useEffect(()=>{(Q||J)&&se(!0),(W||re)&&se(!1),W?($(ue.message),K([]),_([]),g("")):$("")},[Q,J,q,g,W,re,se,K,_,$,ue]);function ye(){P(""),K([]),oe({}),U(""),R({})}const he=p=>{t.current=p};function ve(){let p=N;N&&!N.includes("{{")&&(p=_s(N),P(p));const j={...E,lastSelectedSchema:I,lastSelectedDatabase:b,lastSelectedTable:S,connectionId:z,type:y?E.type:"table",sql:p,customCfg:y?E.customCfg:null},me=B.cards.map(ne=>ne.id===E.id?j:ne);k==null||k({...B,cards:me})}function Ce(){T==null||T()}function Ne(p){const j=getComputedStyle(document.documentElement).getPropertyValue(p);return je(j)}function je(p){const[j,me,ne]=p.split(" "),V=parseFloat(j),as=parseFloat(me),ls=parseFloat(ne),cs=as/100,Oe=ls/100,te=(1-Math.abs(2*Oe-1))*cs,le=te*(1-Math.abs(V/60%2-1)),ke=Oe-te/2;let Y=0,X=0,Z=0;0<=V&&V<60?(Y=te,X=le,Z=0):60<=V&&V<120?(Y=le,X=te,Z=0):120<=V&&V<180?(Y=0,X=te,Z=le):180<=V&&V<240?(Y=0,X=le,Z=te):240<=V&&V<300?(Y=le,X=0,Z=te):300<=V&&V<360&&(Y=te,X=0,Z=le),Y=Math.round((Y+ke)*255),X=Math.round((X+ke)*255),Z=Math.round((Z+ke)*255);const we=xs=>{const Ae=xs.toString(16);return Ae.length==1?"0"+Ae:Ae};return`#${we(Y)}${we(X)}${we(Z)}`}f.useEffect(()=>{const p=n.current,j=t.current;if(p){const me=window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light",ne=C==="system"?me:C;p.editor.defineTheme("default",{base:ne==="light"?"vs":"vs-dark",inherit:!0,rules:[],colors:{"editor.background":ne==="light"?"#ffffff":Ne("--semaphor-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,C,n.current]);function de(p){n.current=p}function Ee(){return e.jsxRuntimeExports.jsxs(e.jsxRuntimeExports.Fragment,{children:[x&&e.jsxRuntimeExports.jsx("div",{className:"xbg-yellow-100 relative flex w-1/3 min-w-0 grow overflow-hidden border-l p-1 text-xs",role:"editor-filter-container",children:e.jsxRuntimeExports.jsxs("div",{className:"w-[99%]",children:[e.jsxRuntimeExports.jsxs("div",{className:"flex items-center gap-2 pt-3",children:[e.jsxRuntimeExports.jsx(Ps,{checked:L,onCheckedChange:()=>F(!L),text:"Apply Filters"}),e.jsxRuntimeExports.jsx($s,{}),O&&x&&e.jsxRuntimeExports.jsx(e.Cross2Icon,{onClick:()=>c(!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),H(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&&!x&&e.jsxRuntimeExports.jsx(_e,{onClick:()=>c(!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":L})})]})}function fe(){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=>{P(p)},value:N,options:{minimap:{enabled:!1},wordWrap:"on",scrollbar:{verticalScrollbarSize:0,horizontalScrollbarSize:0},fontSize:14,renderLineHighlight:"none"},defaultLanguage:"sql",defaultValue:"SELECT * FROM table",beforeMount:de,onMount:he})}),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:de,onMount:he})}),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:[fe(),Ee()]}),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:Q||J,onClick:()=>{ae()},className:"shrink-0",size:"sm",variant:"outline",children:[Q||J?e.jsxRuntimeExports.jsx(e.LoaderCircle,{className:"mr-2 h-4 w-4 animate-spin text-foreground/50"}):e.jsxRuntimeExports.jsx(Ns,{className:"mr-2 h-4 w-4"}),"Run"]}),W&&e.jsxRuntimeExports.jsx(Hs,{error:ue.message,setShowAIDialog:a,setTriggerAIRun:v,setUserInputforAI:u}),e.jsxRuntimeExports.jsxs(e.Button,{onClick:ye,className:"",size:"sm",variant:"outline",children:[e.jsxRuntimeExports.jsx(js,{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(et,{className:"size-4 text-foreground/70"})}),e.jsxRuntimeExports.jsx(Ks,{open:o,setOpen:a,userInput:h,triggerAIRun:d,setTriggerAIRun:v,setUserInput:p=>u(p)})]}),e.jsxRuntimeExports.jsxs("div",{className:"flex items-end gap-2",children:[e.jsxRuntimeExports.jsxs(e.Button,{onClick:ve,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:Ce,className:"w-full",size:"sm",variant:"outline",children:[e.jsxRuntimeExports.jsx(e.Cross2Icon,{className:"mr-2 size-4"}),"Close"]})]})]})]})}function tt({data:s}){var c;const[n,t]=f.useState([]),i=Object.keys(s[0]).map(o=>({accessorKey:o,header:({column:a})=>{const h=a.getIsSorted();return e.jsxRuntimeExports.jsx("div",{className:"flex gap-2",children:e.jsxRuntimeExports.jsxs("div",{className:"flex cursor-pointer items-center",onClick:()=>a.toggleSorting(a.getIsSorted()==="asc"),children:[o,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]})})}})),x=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:x.getHeaderGroups().map(o=>e.jsxRuntimeExports.jsx(e.TableRow,{children:o.headers.map(a=>e.jsxRuntimeExports.jsx(e.TableHead,{className:"sticky top-0 bg-muted",children:a.isPlaceholder?null:e.flexRender(a.column.columnDef.header,a.getContext())},a.id))},o.id))}),e.jsxRuntimeExports.jsx(e.TableBody,{children:(c=x.getRowModel().rows)!=null&&c.length?x.getRowModel().rows.map(o=>e.jsxRuntimeExports.jsx(e.TableRow,{className:"whitespace-nowrap py-2","data-state":o.getIsSelected()&&"selected",children:o.getVisibleCells().map(a=>e.jsxRuntimeExports.jsx(e.TableCell,{children:e.flexRender(a.column.columnDef.cell,a.getContext())},a.id))},o.id)):e.jsxRuntimeExports.jsx(e.TableRow,{children:e.jsxRuntimeExports.jsx(e.TableCell,{colSpan:i.length,className:"h-24 text-center",children:"No results."})})})]})}function We({className:s,...n}){var c;f.useState(0);const t=e.useDashboardStore(o=>o.themeStyle),r=e.useEditorStore(o=>o.card),i=e.useEditorStore(o=>o.actions.setCard);if(f.useEffect(()=>{},[r.data,r.type,r.cfg,r.customCfg,t,r.preferences]),!r.id)return null;let x;return r.data&&r.data.length>0&&(x=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"&&x&&e.jsxRuntimeExports.jsx(e.ChartJsVisual,{cfg:x},JSON.stringify(x)+JSON.stringify(r.preferences)+((c=r==null?void 0:r.preferences)==null?void 0:c.customVisualCode)),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 rt(){const[s,n]=f.useState(!1),[t,r]=f.useState(""),[i,x]=f.useState(""),[c,o]=f.useState(""),[a,h]=f.useState(""),u=e.useEditorStore(b=>b.card),d=e.useEditorStore(b=>b.card.customCfg),{setCardCustomCfg:v,setCustomVisualCode:l}=e.useEditorActions();function m(b){var N,A;const I={...b,data:{...b==null?void 0:b.data,datasets:(A=(N=b==null?void 0:b.data)==null?void 0:N.datasets)==null?void 0:A.map(D=>({...D,data:[]}))}};return JSON.stringify(I,null,1)}function E(){var I,S;if(!u.data||u.data.length===0)return;const b=e.createChartConfig({data:u.data,cardType:u.type,cfg:u.cfg,preferences:u.preferences});b&&(r(JSON.stringify(b,null,1)),(I=u==null?void 0:u.preferences)!=null&&I.customVisualCode&&o((S=u==null?void 0:u.preferences)==null?void 0:S.customVisualCode),d&&x(JSON.stringify(d,null,1)))}function C(){if(c&&l(c),!!i)try{const b=JSON.parse(i);return b?(v(b),h(""),x(""),b):void 0}catch(b){console.log(b),h("Invalid JSON")}}function y(){x(""),v(null)}function z(){let b;if(d){const I=e._.cloneDeep(u.cfg),S=e._.merge(I,d);return b=m(S),b}return t?(b=m(JSON.parse(t)),b):""}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:E,className:` ${d&&"border-foreground/50 dark:border-foreground/70"}`,size:"sm",variant:"outline",children:e.jsxRuntimeExports.jsx(e.Settings,{className:"h-4 w-4"})})}),e.jsxRuntimeExports.jsxs(e.DialogContent,{className:"max-h-[70vh] min-h-[70vh] overflow-auto sm:min-w-[900px] lg:min-w-[1200px]",children:[e.jsxRuntimeExports.jsxs(e.DialogHeader,{className:"",children:[e.jsxRuntimeExports.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxRuntimeExports.jsx(e.DialogTitle,{children:"Customize Card"}),e.jsxRuntimeExports.jsxs(e.Tooltip,{children:[e.jsxRuntimeExports.jsx(e.TooltipTrigger,{children:e.jsxRuntimeExports.jsx(Rs,{onClick:()=>{navigator.clipboard.writeText(u.id)},className:"size-3 cursor-pointer text-muted-foreground/70 transition-colors hover:text-muted-foreground"})}),e.jsxRuntimeExports.jsx(e.TooltipContent,{side:"right",align:"center",children:e.jsxRuntimeExports.jsx("p",{className:"text-xs",children:"Copy Card ID"})})]})]}),e.jsxRuntimeExports.jsxs(e.DialogDescription,{children:["See the configuration options and documentation",e.jsxRuntimeExports.jsx("a",{target:"_blank",className:"ml-1 text-blue-500 underline",href:"https://www.chartjs.org/docs/latest/samples/bar/vertical.html",children:"here."})]})]}),e.jsxRuntimeExports.jsxs("div",{className:"flex grow gap-2",children:[e.jsxRuntimeExports.jsx(We,{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:[d&&e.jsxRuntimeExports.jsx(e.CheckIcon,{className:"mr-1 h-5 w-5 text-green-600"}),d?"Custom Config":"Default Config"]}),e.jsxRuntimeExports.jsx(e.TabsTrigger,{className:"",value:"output",children:"Output"}),e.jsxRuntimeExports.jsx(e.TabsTrigger,{className:"",value:"custom-code",children:"Custom Code"})]}),e.jsxRuntimeExports.jsx(e.TabsContent,{className:"bg-red-x mt-0 grow rounded-b border border-t-0 p-2",value:"output",children:e.jsxRuntimeExports.jsx(e.Textarea,{disabled:!0,value:t,className:"h-full resize-none border-none font-mono focus-visible:ring-0 focus-visible:ring-offset-0"})}),e.jsxRuntimeExports.jsx(e.TabsContent,{className:"mt-0 grow rounded-b border border-t-0",value:"custom-config",children:e.jsxRuntimeExports.jsx(e.Ft,{className:"h-full w-full overflow-hidden",theme:"default",options:{minimap:{enabled:!1},wordWrap:"on",scrollbar:{verticalScrollbarSize:0,horizontalScrollbarSize:0},fontSize:14,renderLineHighlight:"none"},defaultLanguage:"json",value:z(),onChange:b=>x(b)})}),e.jsxRuntimeExports.jsx(e.TabsContent,{className:"mt-0 grow rounded-b border border-t-0",value:"custom-code",children:e.jsxRuntimeExports.jsx(e.Ft,{className:"h-full w-full overflow-hidden",theme:"default",options:{minimap:{enabled:!1},wordWrap:"on",scrollbar:{verticalScrollbarSize:0,horizontalScrollbarSize:0},fontSize:14,renderLineHighlight:"none"},defaultLanguage:"javascript",value:c,onChange:b=>o(b||"")})})]})]}),e.jsxRuntimeExports.jsxs(e.DialogFooter,{className:"flex items-center",children:[e.jsxRuntimeExports.jsx(e.Label,{className:"mr-2 text-red-500",children:a}),e.jsxRuntimeExports.jsx(e.Button,{disabled:!d,onClick:y,variant:"outline",children:"Reset"}),e.jsxRuntimeExports.jsx(e.Button,{onClick:C,variant:"outline",children:"Apply"}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>n(!1),variant:"outline",children:"Close"})]})]})]})}function Ye(s){return ee({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 Xe(s){return ee({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 Ze(s){return ee({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 es(s){return ee({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 ss(s){return ee({tag:"svg",attr:{viewBox:"0 0 24 24"},child:[{tag:"path",attr:{fill:"none",d:"M0 0h24v24H0z"},child:[]},{tag:"path",attr:{d:"m2 19.99 7.5-7.51 4 4 7.09-7.97L22 9.92l-8.5 9.56-4-4-6 6.01-1.5-1.5zm1.5-4.5 6-6.01 4 4L22 3.92l-1.41-1.41-7.09 7.97-4-4L2 13.99l1.5 1.5z"},child:[]}]})(s)}function ts(s){return ee({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 rs(s){return ee({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 ns(s){return ee({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 nt(){const[s,n]=f.useState(!1),t=e.useEditorStore(a=>a.card.type),{setCardType:r,setCardPreferences:i,setChartOrientation:x}=e.useEditorStore(a=>a.actions),c=e.useEditorStore(a=>a.actions.setCardCustomCfg);function o(a){c(null),i({}),r(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(ot,{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(ze,{className:"size-5"})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>o("line"),variant:"ghost",children:e.jsxRuntimeExports.jsx(Ie,{className:"size-5"})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>o("stackedBar"),variant:"ghost",children:e.jsxRuntimeExports.jsx(ts,{className:"size-5",strokeWidth:0})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>o("stackedLine"),variant:"ghost",children:e.jsxRuntimeExports.jsx(ss,{className:"size-5",strokeWidth:0})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>o("scatter"),variant:"ghost",children:e.jsxRuntimeExports.jsx(Ge,{className:"size-5"})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>o("bubble"),variant:"ghost",children:e.jsxRuntimeExports.jsx(es,{className:"size-4"})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>o("pie"),variant:"ghost",children:e.jsxRuntimeExports.jsx($e,{className:"size-5"})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>o("doughnut"),variant:"ghost",children:e.jsxRuntimeExports.jsx(Xe,{className:"size-5",strokeWidth:1})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>o("radar"),variant:"ghost",children:e.jsxRuntimeExports.jsx(Ye,{className:"size-5 font-extralight",strokeWidth:.5})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>o("polarArea"),variant:"ghost",children:e.jsxRuntimeExports.jsx(Ze,{className:"size-5"})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>o("pyramid"),variant:"ghost",children:e.jsxRuntimeExports.jsx(ns,{className:"size-5"})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>o("range"),variant:"ghost",children:e.jsxRuntimeExports.jsx(He,{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(rs,{className:"size-6"})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>o("text"),variant:"ghost",children:e.jsxRuntimeExports.jsx(Le,{className:"size-4"})})]})})]})}function ot({chartType:s,className:n}){switch(s){case"bar":return e.jsxRuntimeExports.jsx(ze,{className:n});case"line":return e.jsxRuntimeExports.jsx(Ie,{className:n});case"pie":return e.jsxRuntimeExports.jsx($e,{className:n});case"radar":return e.jsxRuntimeExports.jsx(Ye,{className:n});case"scatter":return e.jsxRuntimeExports.jsx(Ge,{className:n});case"bubble":return e.jsxRuntimeExports.jsx(es,{className:n});case"doughnut":return e.jsxRuntimeExports.jsx(Xe,{className:n});case"stackedBar":return e.jsxRuntimeExports.jsx(ts,{className:"size-4 text-foreground/70"});case"stackedLine":return e.jsxRuntimeExports.jsx(ss,{className:"size-4 text-foreground/70"});case"polarArea":return e.jsxRuntimeExports.jsx(Ze,{className:n});case"pyramid":return e.jsxRuntimeExports.jsx(ns,{className:n});case"range":return e.jsxRuntimeExports.jsx(He,{className:n});case"kpi":return e.jsxRuntimeExports.jsx(rs,{className:n});case"text":return e.jsxRuntimeExports.jsx(Le,{className:n});default:return e.jsxRuntimeExports.jsx(e.Table,{className:n})}}function it(){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(us,{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 qe(){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),x=e.useEditorStore(o=>o.pythonStdOut);if(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)return e.jsxRuntimeExports.jsx(e.jsxRuntimeExports.Fragment,{children:"No Active Card"});function c(){return 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})})}):s.type==="text"?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.TextCard,{isLoading:r,card:s})})}):e.jsxRuntimeExports.jsx(We,{className:"grow border-none shadow-none"})}return 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(nt,{}),s.type!=="table"&&e.jsxRuntimeExports.jsx(rt,{}),e.jsxRuntimeExports.jsx(it,{})]}),e.jsxRuntimeExports.jsx(lt,{})]}),t?c():e.jsxRuntimeExports.jsxs("div",{className:"flex min-h-0 w-full flex-1 grow basis-0 px-6",children:[x&&e.jsxRuntimeExports.jsx(at,{}),s.data&&s.data.length>0&&e.jsxRuntimeExports.jsx(tt,{data:n||[]}),i&&e.jsxRuntimeExports.jsx("span",{className:"font-mono text-sm",children:i})]})]})}function at(){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 lt(){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 xe(){const[s,n]=f.useState([]);e.useEditorStore(u=>u.card.cfg);const t=e.useEditorStore(u=>u.card.preferences),{setCardCfg:r,setFilterOnClickColumnIndex:i,setCardPreferences:x}=e.useEditorStore(u=>u.actions),c=e.useEditorStore(u=>u.queryResultColumns);e.useEditorStore(u=>{var d;return(d=u.card.preferences)==null?void 0:d.filterOnClickColumnIndex}),f.useEffect(()=>{c&&n(new Array(c.length).fill(!1))},[c]);function o(u,d){var v,l;d?t!=null&&t.onClickFilter&&((v=t==null?void 0:t.onClickFilter)==null?void 0:v.length)>0?x({...t,onClickFilter:[...t.onClickFilter,{columnIndex:u,expression:""}]}):x({...t,onClickFilter:[{columnIndex:u,expression:""}]}):(x({...t,onClickFilter:(l=t==null?void 0:t.onClickFilter)==null?void 0:l.filter(m=>m.columnIndex!==u)}),n(m=>{const E=[...m];return E[u]=!1,E}))}function a(u,d){var l;const v=(l=t==null?void 0:t.onClickFilter)==null?void 0:l.map(m=>m.columnIndex===u?{...m,expression:d.target.value}:m);x({...t,onClickFilter:v})}function h(u){var d,v,l,m;if(s!=null&&s[u]||(v=(d=t==null?void 0:t.onClickFilter)==null?void 0:d.find(E=>E.columnIndex===u))!=null&&v.expression)return e.jsxRuntimeExports.jsx(e.Input,{value:(m=(l=t==null?void 0:t.onClickFilter)==null?void 0:l.find(E=>E.columnIndex===u))==null?void 0:m.expression,onChange:E=>a(u,E),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:c==null?void 0:c.map((u,d)=>{var v,l;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:!!((v=t==null?void 0:t.onClickFilter)!=null&&v.find(m=>m.columnIndex===d)),onCheckedChange:m=>o(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:((l=t==null?void 0:t.onClickFilter)==null?void 0:l.find(m=>m.columnIndex===d))&&e.jsxRuntimeExports.jsx(Pe,{onClick:()=>{n(m=>{const E=[...m];return E[d]=!m[d],E})},className:" invisible group-hover:visible size-3 text-gray-400 cursor-pointer"})})]}),h(d)]})},u)})})}function Se(){var c,o,a;const s=e.useEditorStore(h=>h.card.preferences),n=e.useEditorStore(h=>h.card.cfg),{setCardCfg:t,setCardPreferences:r,setChartOrientation:i}=e.useEditorStore(h=>h.actions);(c=n==null?void 0:n.options)!=null&&c.indexAxis;function x(h){i(h)}return e.jsxRuntimeExports.jsxs(e.RadioGroup,{value:((o=s==null?void 0:s.chartOptions)==null?void 0:o.indexAxis)||((a=n==null?void 0:n.options)==null?void 0:a.indexAxis)||"x",onValueChange:x,className:"flex gap-3",defaultValue:"x",children:[e.jsxRuntimeExports.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsxRuntimeExports.jsx(e.RadioGroupItem,{value:"x",id:"r1"}),e.jsxRuntimeExports.jsx("label",{className:"text-sm",htmlFor:"r1",children:"Vertical"})]}),e.jsxRuntimeExports.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsxRuntimeExports.jsx(e.RadioGroupItem,{value:"y",id:"r2"}),e.jsxRuntimeExports.jsx("label",{className:"text-sm",htmlFor:"r2",children:"Horizontal"})]})]})}const ce="focus-visible:ring-0 focus-visible:ring-ring focus-visible:ring-offset-0";function Ve(s,n){var r,i,x;const t=e.getNumberAxis(s,n);return((x=(i=(r=s==null?void 0:s.chartOptions)==null?void 0:r.scales)==null?void 0:i[t])==null?void 0:x.type)||"linear"}function os(){var _,H,P,M,$,g;const[s,n]=f.useState(!1),t=e.useEditorStore(R=>{var k;return(k=R.card)==null?void 0:k.preferences}),r=e.useEditorStore(R=>{var k;return(k=R.card)==null?void 0:k.cfg}),i=e.getNumberAxis(t,r),[x,c]=f.useState(Ve(t)),[o,a]=f.useState(((P=(H=(_=t==null?void 0:t.chartOptions)==null?void 0:_.scales)==null?void 0:H[i])==null?void 0:P.min)||""),[h,u]=f.useState(((g=($=(M=t==null?void 0:t.chartOptions)==null?void 0:M.scales)==null?void 0:$[i])==null?void 0:g.max)||""),[d,v]=f.useState(o||h?"custom":"auto"),[l,m]=f.useState(""),[E,C]=f.useState(0),[y,z]=f.useState(""),[b,I]=f.useState(""),[S,N]=f.useState(""),A=e.useEditorStore(R=>R.actions.setCardPreferences),D=e.useEditorStore(R=>{var k;return(k=R.card)==null?void 0:k.type}),w=["pie","doughnut","polarArea"].includes(D);f.useEffect(()=>{var R,k,F,T,K,oe,ie,G,se,q,Q,J,re,W;c(Ve(t)),a(((F=(k=(R=t==null?void 0:t.chartOptions)==null?void 0:R.scales)==null?void 0:k[i])==null?void 0:F.min)===0?0:""),u(((oe=(K=(T=t==null?void 0:t.chartOptions)==null?void 0:T.scales)==null?void 0:K[i])==null?void 0:oe.max)||""),m(((q=(se=(G=(ie=t==null?void 0:t.chartOptions)==null?void 0:ie.scales)==null?void 0:G[i])==null?void 0:se.ticks)==null?void 0:q.stepSize)||""),C(((Q=t==null?void 0:t.numberAxisFormat)==null?void 0:Q.decimalPlaces)||0),z(((J=t==null?void 0:t.numberAxisFormat)==null?void 0:J.suffix)||""),I(((re=t==null?void 0:t.numberAxisFormat)==null?void 0:re.currency)||""),N(((W=t==null?void 0:t.numberAxisFormat)==null?void 0:W.locale)||"")},[s,t,i]);function B(R,k){return k===""||/^[0-9\b]+$/.test(k)?Number(k):Number(R)}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:b,placeholder:"USD",onChange:R=>I(R.target.value),id:"currency",className:`col-span-2 h-8 w-full ${ce}`}),e.jsxRuntimeExports.jsx(e.Input,{value:S,placeholder:"en-US",onChange:R=>N(R.target.value),id:"locale",className:`col-span-2 h-8 w-full ${ce}`})]}),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:E,onChange:R=>C(Number(R.target.value)),id:"format",className:`col-span-6 h-8 w-full tracking-wide ${ce}`})]})]})}function L(){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:o,onChange:R=>a(k=>B(k,R.target.value)),className:`col-span-1 h-8 w-full ${ce}`}),e.jsxRuntimeExports.jsx(e.Input,{value:h,onChange:R=>u(k=>B(k,R.target.value)),id:"max",className:`col-span-1 h-8 w-full ${ce}`})]}),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:l,onChange:R=>m(k=>B(k,R.target.value)),id:"step-size",className:`col-span-1 h-8 w-full ${ce}`})]})]})}function U(){var F;let R={};d==="custom"&&(R={min:o,max:h,ticks:{stepSize:l}});const k={...t||{},chartOptions:{...t==null?void 0:t.chartOptions,scales:{...(F=t==null?void 0:t.chartOptions)==null?void 0:F.scales,[i]:{type:x,...x==="linear"?R:{}}}},numberAxisFormat:{decimalPlaces:E,suffix:y,currency:b,locale:S}};console.log(k),A(k)}return e.jsxRuntimeExports.jsxs(e.Popover,{onOpenChange:R=>n(R),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:w,value:x,onValueChange:R=>c(R),children:[e.jsxRuntimeExports.jsx(e.SelectTrigger,{className:"col-span-2 h-8 w-full focus:ring-1 focus:ring-offset-0",children:e.jsxRuntimeExports.jsx(e.SelectValue,{})}),e.jsxRuntimeExports.jsx(e.SelectContent,{id:"type",children:e.jsxRuntimeExports.jsxs(e.SelectGroup,{children:[e.jsxRuntimeExports.jsx(e.SelectLabel,{children:"Option"}),e.jsxRuntimeExports.jsx(e.SelectItem,{value:"linear",children:"Linear"}),e.jsxRuntimeExports.jsx(e.SelectItem,{value:"logarithmic",children:"Logarithmic"})]})})]})]}),x=="linear"&&e.jsxRuntimeExports.jsxs("div",{className:"grid grid-cols-3 items-center gap-2 py-1",children:[e.jsxRuntimeExports.jsx(e.Label,{htmlFor:"scale-option",children:"Setup"}),e.jsxRuntimeExports.jsxs(e.RadioGroup,{disabled:w,id:"scale-option",value:d,onValueChange:R=>v(R),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"&&x=="linear"&&L(),O(),e.jsxRuntimeExports.jsx(e.SelectSeparator,{}),e.jsxRuntimeExports.jsx("div",{className:"grid grid-cols-3",children:e.jsxRuntimeExports.jsx(e.Button,{onClick:U,variant:"secondary",className:"col-span-1 col-start-3 h-8 w-full",children:"Apply"})})]})]})})]})}function ct({idx:s}){var o;const n=e.useEditorStore(a=>{var h;return(h=a.card)==null?void 0:h.preferences}),t=e.useEditorStore(a=>{var h;return(h=a.card.preferences)==null?void 0:h.datasetOptions}),r=e.useEditorStore(a=>a.actions.setCardPreferences),i=(o=n==null?void 0:n.chartOptions)==null?void 0:o.indexAxis,x=t==null?void 0:t.find(a=>a.idx===s);function c(a,h){(a==="end"||a==="start")&&e.getContrastColor(e.getCanvasBackgroundColor());const u={display:a!=="none",align:a,anchor:a,clamp:!0};if(!x)r({...n,datasetOptions:[...t||[],{idx:h,datalabels:u}]});else{const d={...x};d.datalabels=u;const v=t==null?void 0:t.map(l=>l.idx===h?d:l);r({...n,datasetOptions:v})}}return e.jsxRuntimeExports.jsxs(e.Popover,{children:[e.jsxRuntimeExports.jsx(e.PopoverTrigger,{children:e.jsxRuntimeExports.jsx(Ls,{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:()=>c("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:()=>c("start",s),size:"sm",variant:"secondary",className:"h-7 p-1 text-xs font-normal",children:e.jsxRuntimeExports.jsx(bs,{className:e.cn("h-4 w-4",{"rotate-90":i==="y"})})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>c("center",s),size:"sm",variant:"secondary",className:"h-7 p-1 text-xs font-normal",children:e.jsxRuntimeExports.jsx(ys,{className:e.cn("h-4 w-4",{"rotate-90":i==="y"})})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>c("end",s),size:"sm",variant:"secondary",className:"h-7 p-1 text-xs font-normal",children:e.jsxRuntimeExports.jsx(Ss,{className:e.cn("h-4 w-4",{"rotate-90":i==="y"})})})]})})]})}function is(){const s=e.useEditorStore(a=>a.card),n=e.useEditorStore(a=>{var h,u,d;return(d=(u=(h=a==null?void 0:a.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:x,dimensionKeys:c}=e.getKeys(s.data||[]);let o=x;if(["stackedBar","stackedLine"].includes(s.type)){const a=e.pivotData({dataArray:s.data||[],groupKey:c[0],pivotKey:c[1],valueKey:o[0]}),{metricKeys:h}=e.getKeys(a);o=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:c[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(os,{})]}),e.jsxRuntimeExports.jsx("div",{className:"my-1 space-y-1",children:o.map((a,h)=>e.jsxRuntimeExports.jsx(xt,{col:a,idx:h},a))})]})]})}function xt({col:s,idx:n}){const t=e.useEditorStore(o=>{var a;return(a=o.card)==null?void 0:a.preferences}),r=e.useEditorStore(o=>{var a;return(a=o.card.preferences)==null?void 0:a.datasetOptions}),i=r==null?void 0:r.find(o=>o.idx===n),{setCardPreferences:x}=e.useEditorStore(o=>o.actions);function c(o){if(!i)x({...t,datasetOptions:[...r||[],{idx:n,type:o==="area"?"line":o,fill:o==="area"?"origin":""}]});else{const a={...i};a.type=o==="area"?"line":o,a.fill=o==="area"?"origin":"";const h=r==null?void 0:r.map(u=>u.idx===n?a:u);x({...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(ze,{onClick:()=>c("bar"),className:"invisible size-4 cursor-pointer text-muted-foreground hover:text-foreground group-hover:visible"}),e.jsxRuntimeExports.jsx(Ie,{onClick:()=>c("line"),className:"invisible size-4 cursor-pointer text-muted-foreground hover:text-foreground group-hover:visible"}),e.jsxRuntimeExports.jsx(ds,{onClick:()=>c("area"),className:"invisible size-4 cursor-pointer text-muted-foreground hover:text-foreground group-hover:visible"}),e.jsxRuntimeExports.jsx(e.Separator,{orientation:"vertical",className:"invisible size-4 cursor-pointer py-2 text-muted-foreground hover:text-foreground group-hover:visible"}),e.jsxRuntimeExports.jsx(ct,{idx:n})]})]})}function ut({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(Se,{}),e.jsxRuntimeExports.jsx(is,{})]})]}),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(xe,{})})]})]})})}function De(){var i,x,c;const s=e.useEditorStore(o=>o.card.cfg),n=e.useEditorStore(o=>o.actions.setCardCfg),t=e.useEditorStore(o=>o.card.type);function r(o){var u;const a={datalabels:{display:o!=="none",align:o,anchor:o,clamp:!0}},h={...s,options:{...s==null?void 0:s.options,plugins:{...(u=s==null?void 0:s.options)==null?void 0:u.plugins,...a}}};n(h),console.log(o)}return e.jsxRuntimeExports.jsxs("div",{className:"space-y-2",children:[e.jsxRuntimeExports.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxRuntimeExports.jsx("label",{className:"font-medium",children:"Data Labels"}),!["pyramid"].includes(t)&&e.jsxRuntimeExports.jsx(os,{})]}),e.jsxRuntimeExports.jsxs(e.Select,{value:(c=(x=(i=s==null?void 0:s.options)==null?void 0:i.plugins)==null?void 0:x.datalabels)==null?void 0:c.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 dt({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:x=>x.stopPropagation(),className:"text-blue-700",href:"https://docs.semaphor.cloud/concepts/visuals#pie-chart",children:"example"})," in the docs."]})]})}return e.jsxRuntimeExports.jsx("div",{className:"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(De,{})})]}),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(xe,{})})]})]})})}const mt={datasets:[{type:"line",label:"Sum_sales",data:[]},{type:"bar",label:"Sum_profit",data:[]}]},pt={datasets:[{fill:"origin",type:"line",label:"Sum_sales",data:[]}]};function ht(){const s=e.useEditorStore(n=>n.card.type);return e.jsxRuntimeExports.jsxs("div",{className:"space-y-6 p-6",children:[e.jsxRuntimeExports.jsx(e.Accordion,{className:" ",type:"single",collapsible:!0,children:jt(s)}),e.jsxRuntimeExports.jsx("section",{className:"",children:["line","bar"].includes(s)&&e.jsxRuntimeExports.jsx(Se,{})}),e.jsxRuntimeExports.jsx("div",{children:!["kpi"].includes(s)&&e.jsxRuntimeExports.jsx(De,{})}),e.jsxRuntimeExports.jsx("div",{children:!["kpi"].includes(s)&&e.jsxRuntimeExports.jsx(xe,{})})]})}function jt(s){if(["line","bar"].includes(s))return e.jsxRuntimeExports.jsxs(e.jsxRuntimeExports.Fragment,{children:[e.jsxRuntimeExports.jsxs(e.AccordionItem,{value:"item-1",children:[e.jsxRuntimeExports.jsx(e.AccordionTrigger,{className:"font-normal",children:e.jsxRuntimeExports.jsx("p",{children:"Chart Query"})}),e.jsxRuntimeExports.jsxs(e.AccordionContent,{className:" ",children:[e.jsxRuntimeExports.jsx("div",{className:"rounded bg-muted px-2 py-1 font-mono text-xs font-semibold",children:"SELECT x-axis, y-axis-1, y-axis-2, y-axis-3,... FROM table"}),e.jsxRuntimeExports.jsxs("ul",{className:"my-6 ml-6 list-disc text-xs font-normal [&>li]:mt-2",children:[e.jsxRuntimeExports.jsx("li",{children:"X-axis - Category (ex. city)"}),e.jsxRuntimeExports.jsx("li",{children:"Y-axis - Number (ex. population)"})]})]})]}),e.jsxRuntimeExports.jsxs(e.AccordionItem,{value:"item-2",children:[e.jsxRuntimeExports.jsx(e.AccordionTrigger,{className:"font-normal",children:"Mixed Chart"}),e.jsxRuntimeExports.jsxs(e.AccordionContent,{className:"space-y-2 text-xs",children:[e.jsxRuntimeExports.jsxs("p",{children:["Click ",e.jsxRuntimeExports.jsx("b",{children:"Customize"})," and change the `type` property in the dataset."]}),e.jsxRuntimeExports.jsx("pre",{children:JSON.stringify(mt,null,2)})]})]}),e.jsxRuntimeExports.jsxs(e.AccordionItem,{value:"item-3",children:[e.jsxRuntimeExports.jsx(e.AccordionTrigger,{className:"font-normal",children:"Area Chart"}),e.jsxRuntimeExports.jsxs(e.AccordionContent,{className:"space-y-2 text-xs",children:[e.jsxRuntimeExports.jsxs("p",{children:["Click ",e.jsxRuntimeExports.jsx("b",{children:"Customize"})," and add `fill` property to the dataset. See",e.jsxRuntimeExports.jsx("a",{className:"mx-1 text-blue-500 hover:underline",href:"https://www.chartjs.org/docs/latest/samples/area/line-boundaries.html",target:"_blank",children:"docs"}),"for more options."]}),e.jsxRuntimeExports.jsx("pre",{children:JSON.stringify(pt,null,2)})]})]})]});if(s==="bubble")return e.jsxRuntimeExports.jsx(e.jsxRuntimeExports.Fragment,{children:e.jsxRuntimeExports.jsxs(e.AccordionItem,{value:"item-1",children:[e.jsxRuntimeExports.jsx(e.AccordionTrigger,{className:"font-normal",children:e.jsxRuntimeExports.jsxs("p",{children:["How to create a ",e.jsxRuntimeExports.jsx("span",{children:s})," chart query?"]})}),e.jsxRuntimeExports.jsxs(e.AccordionContent,{className:" ",children:[e.jsxRuntimeExports.jsx("div",{className:"rounded bg-muted px-2 py-1 font-mono text-xs font-semibold",children:"SELECT label, x-axis, y-axis, radius FROM table"}),e.jsxRuntimeExports.jsxs("ul",{className:"my-6 ml-6 list-disc text-xs font-normal [&>li]:mt-2",children:[e.jsxRuntimeExports.jsx("li",{children:"Label - Category (ex. city)"}),e.jsxRuntimeExports.jsx("li",{children:"Bubble Group (opt) - Category (ex. state)"}),e.jsxRuntimeExports.jsx("li",{children:"X-axis - Number (ex. avg. age)"}),e.jsxRuntimeExports.jsx("li",{children:"Y-axis - Number (ex. avg. weight)"}),e.jsxRuntimeExports.jsx("li",{children:"Radius - Number (ex. population)"})]})]})]})});if(s==="scatter")return e.jsxRuntimeExports.jsx(e.jsxRuntimeExports.Fragment,{children:e.jsxRuntimeExports.jsxs(e.AccordionItem,{value:"item-1",children:[e.jsxRuntimeExports.jsx(e.AccordionTrigger,{className:"font-normal",children:e.jsxRuntimeExports.jsxs("p",{children:["How to create a ",e.jsxRuntimeExports.jsx("span",{children:s})," chart query?"]})}),e.jsxRuntimeExports.jsxs(e.AccordionContent,{className:" ",children:[e.jsxRuntimeExports.jsx("div",{className:"rounded bg-muted px-2 py-1 font-mono text-xs font-semibold",children:"SELECT label, x-axis, y-axis FROM table"}),e.jsxRuntimeExports.jsxs("ul",{className:"my-6 ml-6 list-disc text-xs font-normal [&>li]:mt-2",children:[e.jsxRuntimeExports.jsx("li",{children:"Label - Category (ex. city)"}),e.jsxRuntimeExports.jsx("li",{children:"Group (opt) - Category (ex. state)"}),e.jsxRuntimeExports.jsx("li",{children:"X-axis - Number (ex. avg. age)"}),e.jsxRuntimeExports.jsx("li",{children:"Y-axis - Number (ex. avg. weight)"})]})]})]})});if(["pie","doughnut","polarArea"].includes(s))return e.jsxRuntimeExports.jsx(e.jsxRuntimeExports.Fragment,{children:e.jsxRuntimeExports.jsxs(e.AccordionItem,{value:"item-1",children:[e.jsxRuntimeExports.jsx(e.AccordionTrigger,{className:"font-normal",children:e.jsxRuntimeExports.jsxs("p",{children:[e.jsxRuntimeExports.jsx("span",{children:s==="polarArea"?"Polar":s.charAt(0).toUpperCase()+s.slice(1)})," ","chart query"]})}),e.jsxRuntimeExports.jsxs(e.AccordionContent,{className:" ",children:[e.jsxRuntimeExports.jsx("div",{className:"rounded bg-muted px-2 py-1 font-mono text-xs font-semibold",children:"SELECT label, measure FROM table"}),e.jsxRuntimeExports.jsxs("ul",{className:"my-6 ml-6 list-disc text-xs font-normal [&>li]:mt-2",children:[e.jsxRuntimeExports.jsx("li",{children:"Label - Category (ex. city)"}),e.jsxRuntimeExports.jsx("li",{children:"Measure - Number (ex. population)"})]})]})]})})}function Et(){var a,h,u,d,v;const s=e.useEditorStore(l=>l.card.preferences),n=e.useEditorStore(l=>l.actions.setCardPreferences),t=e.useEditorStore(l=>l.actions.setNumberFormat);e.useEditorStore(l=>{var m,E;return(E=(m=l.card.preferences)==null?void 0:m.formatNumber)==null?void 0:E.decimalPlaces});const r=e.useEditorStore(l=>{var m,E;return(E=(m=l.card.preferences)==null?void 0:m.formatNumber)==null?void 0:E.locale}),i=e.useEditorStore(l=>{var m,E;return(E=(m=l.card.preferences)==null?void 0:m.formatNumber)==null?void 0:E.currency});e.useEditorStore(l=>l.actions.setFilterOnClickField);const x=e.useEditorStore(l=>{var m,E;return(E=(m=l.card.preferences)==null?void 0:m.formatNumber)==null?void 0:E.colorRanges})||[],c=e.useEditorStore(l=>l.actions.setColorRanges),o=[...new Set(e.LOCALE_CURRENCY_PAIRS.map(l=>l.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:!!((a=s==null?void 0:s.formatNumber)!=null&&a.enabled),onCheckedChange:l=>{n({...s,formatNumber:{...s==null?void 0:s.formatNumber,enabled:l}})}}),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:l=>{var m,E,C;return t(((m=s==null?void 0:s.formatNumber)==null?void 0:m.decimalPlaces)||0,((E=s==null?void 0:s.formatNumber)==null?void 0:E.currency)||"",l||"en-US",((C=s==null?void 0:s.formatNumber)==null?void 0:C.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(l=>e.jsxRuntimeExports.jsx(e.SelectItem,{value:l.locale,children:l.locale},l.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:l=>{var m,E,C;return t(((m=s==null?void 0:s.formatNumber)==null?void 0:m.decimalPlaces)||0,l==="none"?"":l,((E=s==null?void 0:s.formatNumber)==null?void 0:E.locale)||"",((C=s==null?void 0:s.formatNumber)==null?void 0:C.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"),o.map(l=>e.jsxRuntimeExports.jsx(e.SelectItem,{value:l,children:l},l))]})})]})]})]}),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:l=>{var m,E,C;return t(Number(l),((m=s==null?void 0:s.formatNumber)==null?void 0:m.currency)||"",((E=s==null?void 0:s.formatNumber)==null?void 0:E.locale)||"",((C=s==null?void 0:s.formatNumber)==null?void 0:C.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(l=>e.jsxRuntimeExports.jsx(e.SelectItem,{value:l,children:l},l))})]})]}),e.jsxRuntimeExports.jsxs("div",{className:"w-full space-y-1",children:[e.jsxRuntimeExports.jsx(e.Label,{children:"Suffix"}),e.jsxRuntimeExports.jsx(e.Input,{value:((v=s==null?void 0:s.formatNumber)==null?void 0:v.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:l=>{var m,E,C;return t(((m=s==null?void 0:s.formatNumber)==null?void 0:m.decimalPlaces)||0,((E=s==null?void 0:s.formatNumber)==null?void 0:E.currency)||"",((C=s==null?void 0:s.formatNumber)==null?void 0:C.locale)||"",l.target.value)}})]})]})]})}),e.jsxRuntimeExports.jsx(e.Separator,{className:"my-3"}),e.jsxRuntimeExports.jsx(e.ColorFormat,{colorRanges:x,setColorRanges:c})]})]})}function ft(){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(Et,{})}),e.jsxRuntimeExports.jsx("div",{}),e.jsxRuntimeExports.jsx("div",{})]})}function gt(){var r;const s=e.useEditorStore(i=>i.card.preferences),{setCardPreferences:n}=e.useEditorStore(i=>i.actions);function t(i){n({...s,textVisualOptions:{...s==null?void 0:s.textVisualOptions,isDynamicText:i==="dynamic"}})}return e.jsxRuntimeExports.jsxs(e.RadioGroup,{value:(r=s==null?void 0:s.textVisualOptions)!=null&&r.isDynamicText?"dynamic":"static",onValueChange:t,className:"flex gap-3",defaultValue:"x",children:[e.jsxRuntimeExports.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsxRuntimeExports.jsx(e.RadioGroupItem,{value:"static",id:"r1"}),e.jsxRuntimeExports.jsx("label",{className:"text-sm",htmlFor:"r1",children:"Static"})]}),e.jsxRuntimeExports.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsxRuntimeExports.jsx(e.RadioGroupItem,{value:"dynamic",id:"r2"}),e.jsxRuntimeExports.jsx("label",{className:"text-sm",htmlFor:"r2",children:"Dynamic"})]})]})}function ge({cardType:s,docContent:n,suffix:t="Chart"}){return e.jsxRuntimeExports.jsx("div",{className:"space-y-6 px-6 py-2",children:e.jsxRuntimeExports.jsxs(e.Accordion,{defaultValue:["item-2"],type:"multiple",children:[e.jsxRuntimeExports.jsxs(e.AccordionItem,{value:"item-1",children:[e.jsxRuntimeExports.jsx(e.AccordionTrigger,{children:`${e.titleCase(s)} ${t}`}),e.jsxRuntimeExports.jsx(e.AccordionContent,{children: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:r=>r.stopPropagation(),className:"text-blue-700",href:"https://docs.semaphor.cloud/concepts/visuals#pie-chart",children:"example"})," in the docs."]})]})})]}),e.jsxRuntimeExports.jsxs(e.AccordionItem,{value:"item-2",children:[e.jsxRuntimeExports.jsx(e.AccordionTrigger,{children:"Settings"}),e.jsxRuntimeExports.jsxs(e.AccordionContent,{className:"space-y-4 px-2",children:[s==="range"&&e.jsxRuntimeExports.jsx(Se,{}),s!=="text"&&e.jsxRuntimeExports.jsx(De,{}),s==="text"&&e.jsxRuntimeExports.jsx(gt,{})]})]}),!["range","text"].includes(s)&&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(xe,{})})]})]})})}function Rt(){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(Se,{}),e.jsxRuntimeExports.jsx(is,{})]})]}),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(xe,{})})]})]})})}function bt({}){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(xe,{})})]})}),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 St=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."]})]}),yt=e.jsxRuntimeExports.jsxs("div",{className:"space-y-4 font-mono text-xs",children:[e.jsxRuntimeExports.jsx("div",{className:"rounded bg-muted px-2 py-1 text-xs",children:"SELECT y-axis, label, range-from, range-to, range-value FROM table"}),e.jsxRuntimeExports.jsxs("div",{children:["See ",e.jsxRuntimeExports.jsx("a",{target:"_blank",onClick:s=>s.stopPropagation(),className:"text-blue-700",href:"https://docs.semaphor.cloud/concepts/visuals#range-charts",children:"example"})," in the docs."]})]}),vt=e.jsxRuntimeExports.jsxs("div",{className:"space-y-4 font-mono text-xs",children:[e.jsxRuntimeExports.jsx("div",{className:"rounded bg-muted px-2 py-1 text-xs",children:"SELECT text FROM table limit 1"}),e.jsxRuntimeExports.jsxs("div",{children:["See ",e.jsxRuntimeExports.jsx("a",{target:"_blank",onClick:s=>s.stopPropagation(),className:"text-blue-700",href:"https://docs.semaphor.cloud/concepts/visuals#text-visual",children:"example"})," in the docs."]})]});function Ct(){const s=e.useEditorStore(t=>t.card.type);function n(t){switch(t){case"stackedBar":case"stackedLine":return e.jsxRuntimeExports.jsx(Rt,{});case"pyramid":return e.jsxRuntimeExports.jsx(ge,{docContent:St,cardType:t});case"kpi":return e.jsxRuntimeExports.jsx(ft,{});case"line":case"bar":return e.jsxRuntimeExports.jsx(ut,{cardType:t});case"range":return e.jsxRuntimeExports.jsx(ge,{docContent:yt,cardType:t});case"pie":case"doughnut":case"polarArea":case"radar":return e.jsxRuntimeExports.jsx(ge,{cardType:t});case"bubble":case"scatter":return e.jsxRuntimeExports.jsx(dt,{cardType:t});case"table":return e.jsxRuntimeExports.jsx(bt,{cardType:t});case"text":return e.jsxRuntimeExports.jsx(ge,{docContent:vt,cardType:t,suffix:"Visual"});default:return e.jsxRuntimeExports.jsx(ht,{})}}return e.jsxRuntimeExports.jsx(e.ScrollArea,{className:"h-full w-full text-sm",children:n(s)})}function Nt(){const s=e.useEditorStore(n=>n.isShowingVisual);return e.jsxRuntimeExports.jsxs(e.ResizablePanelGroup,{direction:"vertical",className:"min-h-[250px] min-w-full max-w-lg",children:[e.jsxRuntimeExports.jsx(e.ResizablePanel,{role:"query-section",className:"flex",minSize:20,defaultSize:40,children:e.jsxRuntimeExports.jsx(st,{})}),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(Ct,{})})}),e.jsxRuntimeExports.jsx(e.ResizableHandle,{className:"border"}),e.jsxRuntimeExports.jsx(e.ResizablePanel,{minSize:40,defaultSize:75,maxSize:100,children:e.jsxRuntimeExports.jsx(qe,{})})]}):e.jsxRuntimeExports.jsx(qe,{})})]})}function kt({authToken:s,onSave:n,onClose:t}){const r=e.useEditorStore(c=>c.actions.setOnSave),i=e.useEditorStore(c=>c.actions.setOnClose),x=e.useDashboardStore(c=>c.actions.setAuthToken);return f.useEffect(()=>{n&&r(n),t&&i(t)},[n,r,t,i]),f.useEffect(()=>{s&&s.accessToken&&x(s)},[s,x]),e.jsxRuntimeExports.jsxs(e.EditorPanel,{className:"rounded-none",role:"editor-panel",children:[e.jsxRuntimeExports.jsx(e.EditorAside,{className:"rounded-none border-r-[1.5px]",children:e.jsxRuntimeExports.jsx(Qe,{})}),e.jsxRuntimeExports.jsx(e.EditorMain,{children:e.jsxRuntimeExports.jsx(Nt,{})})]})}function wt(){e.useDashboardStore(c=>c.selectedCardId);const s=e.useDashboardStore(c=>c.selectedSheetId),{setIsVisualEditing:n}=e.useDashboardStore(c=>c.actions),t=e.useDashboardStore(c=>c.isVisualEditing),r=e.useDashboardStore(c=>c.actions.updateFrame);function i(c){s&&(r(s,c),n(!1))}function x(){n(!1)}return e.jsxRuntimeExports.jsx("div",{role:"editor-container",className:e.cn("flex grow",{block:t,hidden:!t}),children:e.jsxRuntimeExports.jsx(kt,{onSave:i,onClose:x})})}function At({columns:s,tableName:n}){const t=e.useEditorStore(d=>d.selectedConnectionId),r=e.useEditorStore(d=>d.selectedDatabaseName),i=e.useEditorStore(d=>d.selectedSchemaName),x=e.useEditorStore(d=>d.selectedTableName),c=e.useDashboardStore(d=>d.dashboard.filters)||[],o=e.useDashboardStore(d=>d.actions.addFilter),a=e.useDashboardStore(d=>d.actions.removeFilter),h=e.useDashboardStore(d=>d.actions.removeFilterValue);function u(d){const v=e.fmt(d.column_name),l=e.fmt(r||""),m=e.fmt(i||""),E=e.fmt(n),C=e.getQualifiedTableName(m,E),y=`${C}.${v}`;console.log("find",y,E,l);const z=c==null?void 0:c.find(b=>b.column===y&&b.table===E&&(b.database===l||b.database===r));if(z)h(z.id),a(z.id);else{if(n==="api"&&t){o({id:e.v4(),column:y,title:d.column_name,dataType:d.data_type,table:"api",database:"",connectionId:t,operation:"in",sql:e.getDefaultFilterSql(d.data_type,C,v)});return}o({id:e.v4(),column:`${C}.${v}`,title:d.column_name,dataType:d.data_type,table:x||"",database:r||"",connectionId:t||"",operation:"in",sql:e.getDefaultFilterSql(d.data_type,C,v)})}}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 v=c==null?void 0:c.find(l=>l.column===e.fmt(d.column_name)&&l.table===x&&l.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":v}),children:e.jsxRuntimeExports.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxRuntimeExports.jsx(Ke,{column:d}),e.jsxRuntimeExports.jsx("span",{children:d.column_name})]})},d.column_name)})})}function zt(){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(Qe,{ColumnsComponent:(n,t,r)=>e.jsxRuntimeExports.jsx(At,{schemaName:n,tableName:t,columns:r})})})]})}function It(){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(zt,{})})]})}function Lt(){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 Tt({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(Lt,{}),e.jsxRuntimeExports.jsxs(e.DashboardPanel,{...t,children:[s&&e.jsxRuntimeExports.jsx(Bs,{}),e.jsxRuntimeExports.jsx(wt,{}),e.jsxRuntimeExports.jsx(It,{})]})]})]})}exports.DashboardPlus=Tt;exports.SelectComponent=pe;exports.useEditorAside=Te;
215
+ Visual Query Syntax: ${Gs}`,{data:N,isLoading:A,isFetching:D,isError:w,refetch:B}=e.useQuery({queryKey:["ai-query"],queryFn:()=>e.getRequest("https://semaphor.cloud/api/v1/ai",(a==null?void 0:a.accessToken)||"",{user_content:`userContent: ${I} ${h?S:""}`}),enabled:!1});function O(g){if(g.toLowerCase().includes("bar"))m("bar");else if(g.toLowerCase().includes("line"))m("line");else if(g.toLowerCase().includes("bubble"))m("bubble");else if(g.toLowerCase().includes("scatter"))m("scatter");else if(g.toLowerCase().includes("stacked"))m("stackedBar");else if(g.toLowerCase().includes("pie"))m("pie");else if(g.toLowerCase().includes("donut")||g.toLowerCase().includes("doughnut"))m("doughnut");else if(g.toLowerCase().includes("radar"))m("radar");else return m("bar"),!1;return!0}f.useEffect(()=>{N&&C(g=>[...g,{role:"ai",content:N.response}])},[N]),f.useEffect(()=>{const g=setTimeout(()=>{var R;o.current&&(o.current.scroll({top:o.current.scrollHeight,behavior:"smooth"}),(R=l.current)==null||R.focus())},100);return()=>clearTimeout(g)},[E]);function L(){t&&(C(g=>[...g,{role:"user",content:t}]),O(t)&&u(!0),r(""),B())}f.useEffect(()=>{i&&(L(),x(!1))},[i,x]);const U={fontFamily:"Arial, sans-serif",lineHeight:1.6,fontSize:15,width:"100%"},_={fontFamily:"monospace",fontSize:14,lineHeight:1.6},H={fontFamily:"Arial, sans-serif",lineHeight:1.6,fontSize:15,padding:"2px 0",marginLeft:20,listStyleType:"disc"},P={p:({node:g,...R})=>e.jsxRuntimeExports.jsx("p",{style:U,...R}),code:({node:g,...R})=>e.jsxRuntimeExports.jsx("code",{className:"rounded-sm bg-muted px-2 py-1 text-sm",...R}),pre:({node:g,...R})=>e.jsxRuntimeExports.jsxs("pre",{className:"space-y-2 rounded-sm bg-muted/50 p-3",style:_,children:[e.jsxRuntimeExports.jsx("code",{className:"whitespace-normal text-sm",children:R.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:k=>{const F=M(k);F&&(n(!1),d(F),c(!0))},size:"sm",variant:"outline",children:e.jsxRuntimeExports.jsx(e.PlayIcon,{})})]})]}),li:({node:g,...R})=>e.jsxRuntimeExports.jsx("li",{style:H,...R})};function M(g){const R=g.currentTarget.closest("pre");if(!R)return;const k=R.textContent||R.innerText;return navigator.clipboard.writeText(k).then(()=>console.log("Text copied to clipboard")).catch(F=>console.error("Error in copying text: ",F)),k}function $(){return E==null?void 0:E.map((g,R)=>g.role==="user"?e.jsxRuntimeExports.jsxs("div",{className:"flex items-start rounded-md bg-muted p-3 text-sm",children:[e.jsxRuntimeExports.jsx(Ds,{className:"mr-2 h-5 w-5"}),e.jsxRuntimeExports.jsx("div",{children:g.content})]},R):g.role==="ai"?e.jsxRuntimeExports.jsx(e.Markdown,{className:"w-full overflow-auto py-1",components:P,children:N==null?void 0:N.response.replace(/DuckDB/gi,"Semaphor")},R):e.jsxRuntimeExports.jsx("div",{},R))}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:o,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:$()})}),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:l,onKeyDown:g=>{g.key==="Enter"&&!g.shiftKey&&(g.preventDefault(),r(""),L())},placeholder:"Type your question here...",onFocus:g=>{const R=g.target,k=R.value.length;R.setSelectionRange(k,k)},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:g=>r(g.target.value)})," ",e.jsxRuntimeExports.jsx(e.Button,{className:"h-8",size:"sm",variant:"ghost",onClick:L,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 Ue={color:void 0,size:void 0,className:void 0,style:void 0,attr:void 0},Me=f.createContext&&f.createContext(Ue),Qs=["attr","size","title"];function Us(s,n){if(s==null)return{};var t=Js(s,n),r,i;if(Object.getOwnPropertySymbols){var x=Object.getOwnPropertySymbols(s);for(i=0;i<x.length;i++)r=x[i],!(n.indexOf(r)>=0)&&Object.prototype.propertyIsEnumerable.call(s,r)&&(t[r]=s[r])}return t}function Js(s,n){if(s==null)return{};var t={},r=Object.keys(s),i,x;for(x=0;x<r.length;x++)i=r[x],!(n.indexOf(i)>=0)&&(t[i]=s[i]);return t}function Re(){return Re=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},Re.apply(this,arguments)}function Be(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 be(s){for(var n=1;n<arguments.length;n++){var t=arguments[n]!=null?arguments[n]:{};n%2?Be(Object(t),!0).forEach(function(r){Ws(s,r,t[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(s,Object.getOwnPropertyDescriptors(t)):Be(Object(t)).forEach(function(r){Object.defineProperty(s,r,Object.getOwnPropertyDescriptor(t,r))})}return s}function Ws(s,n,t){return n=Ys(n),n in s?Object.defineProperty(s,n,{value:t,enumerable:!0,configurable:!0,writable:!0}):s[n]=t,s}function Ys(s){var n=Xs(s,"string");return typeof n=="symbol"?n:String(n)}function Xs(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 Je(s){return s&&s.map((n,t)=>f.createElement(n.tag,be({key:t},n.attr),Je(n.child)))}function ee(s){return n=>f.createElement(Zs,Re({attr:be({},s.attr)},n),Je(s.child))}function Zs(s){var n=t=>{var{attr:r,size:i,title:x}=s,l=Us(s,Qs),o=i||t.size||"1em",a;return t.className&&(a=t.className),s.className&&(a=(a?a+" ":"")+s.className),f.createElement("svg",Re({stroke:"currentColor",fill:"currentColor",strokeWidth:"0"},t.attr,r,l,{className:a,style:be(be({color:s.color||t.color},t.style),s.style),height:o,width:o,xmlns:"http://www.w3.org/2000/svg"}),x&&f.createElement("title",null,x),s.children)};return Me!==void 0?f.createElement(Me.Consumer,null,t=>n(t)):n(Ue)}function et(s){return ee({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 st(){const{theme:s}=e.useTheme(),n=f.useRef(),t=f.useRef(),[r,i]=f.useState(!1),[x,l]=f.useState(!1),[o,a]=f.useState(!1),[h,u]=f.useState(""),[d,v]=f.useState(!1),{authToken:c}=e.useSemaphorContext();e.useDashboardStore(p=>p.selectedSheetId);const m=e.useDashboardStore(p=>p.dashboard.baseQueries),E=e.useEditorStore(p=>p.card),C=e.useDashboardStore(p=>p.theme),y=e.useEditorStore(p=>p.isShowingVisual),z=e.useEditorStore(p=>p.selectedConnectionId),b=e.useEditorStore(p=>p.selectedDatabaseName),I=e.useEditorStore(p=>p.selectedSchemaName);e.useDashboardStore(p=>p.actions.updateFrameCard);const S=e.useEditorStore(p=>p.selectedTableName),N=e.useEditorStore(p=>p.card.sql),A=e.useEditorStore(p=>p.card.python),D=e.resolveBaseQuery(N,m),w=e.useEditorStore(p=>p.selectedConnectionId),B=e.useEditorStore(p=>p.frame),O=e.useEditorStore(p=>p.filterValues),L=e.useEditorStore(p=>p.applyFilters),{setCardCustomCfg:U,setQueryResultColumns:_,setFilterValues:H,setCardSql:P,setCardPython:M,setQueryError:$,setPythonStdOut:g,setCardPreferences:R}=e.useEditorStore(p=>p.actions),k=e.useEditorStore(p=>p.onSave),F=e.useEditorStore(p=>p.actions.setApplyFilters),T=e.useEditorStore(p=>p.onClose),K=e.useEditorStore(p=>p.actions.setCardData),oe=e.useEditorStore(p=>p.actions.setSqlGen),ie=e.useEditorStore(p=>p.runSql),G=e.useEditorStore(p=>p.actions.setRunSql),se=e.useEditorStore(p=>p.actions.setIsSqlRunning),{data:q,isLoading:Q,isFetching:J,isSuccess:re,isError:W,error:ue,status:Fe,refetch:ae}=e.useQuery({queryKey:[D,A],queryFn:()=>e.postRequest("https://semaphor.cloud/api/v1/query",(c==null?void 0:c.accessToken)||"",{connection_id:w,sql:D,python:A===e.PYTHON_DEFAULT_CODE?"":A,active_filters:L?O:[]}),enabled:!1,retry:!1});f.useEffect(()=>{if(q&&(K(q.records),q.rowLimitExceeded&&e.Jt.error("Row limit (10,000) exceeded. Refine your query.",{position:"top-center",richColors:!0}),g((q==null?void 0:q.output)||""),q.records.length>0)){const{dimensionKeys:p}=e.getKeys(q.records);_(p)}},[q,K,_,g]),f.useEffect(()=>{ie&&(ae(),G(!1))},[ie,ae,G]),f.useEffect(()=>{(Q||J)&&se(!0),(W||re)&&se(!1),W?($(ue.message),K([]),_([]),g("")):$("")},[Q,J,q,g,W,re,se,K,_,$,ue]);function ye(){P(""),K([]),oe({}),U(""),R({})}const he=p=>{t.current=p};function ve(){let p=N;N&&!N.includes("{{")&&(p=_s(N),P(p));const j={...E,lastSelectedSchema:I,lastSelectedDatabase:b,lastSelectedTable:S,connectionId:z,type:y?E.type:"table",sql:p,customCfg:y?E.customCfg:null},me=B.cards.map(ne=>ne.id===E.id?j:ne);k==null||k({...B,cards:me})}function Ce(){T==null||T()}function Ne(p){const j=getComputedStyle(document.documentElement).getPropertyValue(p);return je(j)}function je(p){const[j,me,ne]=p.split(" "),V=parseFloat(j),as=parseFloat(me),ls=parseFloat(ne),cs=as/100,Oe=ls/100,te=(1-Math.abs(2*Oe-1))*cs,le=te*(1-Math.abs(V/60%2-1)),ke=Oe-te/2;let Y=0,X=0,Z=0;0<=V&&V<60?(Y=te,X=le,Z=0):60<=V&&V<120?(Y=le,X=te,Z=0):120<=V&&V<180?(Y=0,X=te,Z=le):180<=V&&V<240?(Y=0,X=le,Z=te):240<=V&&V<300?(Y=le,X=0,Z=te):300<=V&&V<360&&(Y=te,X=0,Z=le),Y=Math.round((Y+ke)*255),X=Math.round((X+ke)*255),Z=Math.round((Z+ke)*255);const we=xs=>{const Ae=xs.toString(16);return Ae.length==1?"0"+Ae:Ae};return`#${we(Y)}${we(X)}${we(Z)}`}f.useEffect(()=>{const p=n.current,j=t.current;if(p){const me=window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light",ne=C==="system"?me:C;p.editor.defineTheme("default",{base:ne==="light"?"vs":"vs-dark",inherit:!0,rules:[],colors:{"editor.background":ne==="light"?"#ffffff":Ne("--semaphor-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,C,n.current]);function de(p){n.current=p}function Ee(){return e.jsxRuntimeExports.jsxs(e.jsxRuntimeExports.Fragment,{children:[x&&e.jsxRuntimeExports.jsx("div",{className:"xbg-yellow-100 relative flex w-1/3 min-w-0 grow overflow-hidden border-l p-1 text-xs",role:"editor-filter-container",children:e.jsxRuntimeExports.jsxs("div",{className:"w-[99%]",children:[e.jsxRuntimeExports.jsxs("div",{className:"flex items-center gap-2 pt-3",children:[e.jsxRuntimeExports.jsx(Ps,{checked:L,onCheckedChange:()=>F(!L),text:"Apply Filters"}),e.jsxRuntimeExports.jsx($s,{}),O&&x&&e.jsxRuntimeExports.jsx(e.Cross2Icon,{onClick:()=>l(!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),H(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&&!x&&e.jsxRuntimeExports.jsx(_e,{onClick:()=>l(!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":L})})]})}function fe(){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=>{P(p)},value:N,options:{minimap:{enabled:!1},wordWrap:"on",scrollbar:{verticalScrollbarSize:0,horizontalScrollbarSize:0},fontSize:14,renderLineHighlight:"none"},defaultLanguage:"sql",defaultValue:"SELECT * FROM table",beforeMount:de,onMount:he})}),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:de,onMount:he})}),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:[fe(),Ee()]}),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:Q||J,onClick:()=>{ae()},className:"shrink-0",size:"sm",variant:"outline",children:[Q||J?e.jsxRuntimeExports.jsx(e.LoaderCircle,{className:"mr-2 h-4 w-4 animate-spin text-foreground/50"}):e.jsxRuntimeExports.jsx(Ns,{className:"mr-2 h-4 w-4"}),"Run"]}),W&&e.jsxRuntimeExports.jsx(Hs,{error:ue.message,setShowAIDialog:a,setTriggerAIRun:v,setUserInputforAI:u}),e.jsxRuntimeExports.jsxs(e.Button,{onClick:ye,className:"",size:"sm",variant:"outline",children:[e.jsxRuntimeExports.jsx(js,{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(et,{className:"size-4 text-foreground/70"})}),e.jsxRuntimeExports.jsx(Ks,{open:o,setOpen:a,userInput:h,triggerAIRun:d,setTriggerAIRun:v,setUserInput:p=>u(p)})]}),e.jsxRuntimeExports.jsxs("div",{className:"flex items-end gap-2",children:[e.jsxRuntimeExports.jsxs(e.Button,{onClick:ve,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:Ce,className:"w-full",size:"sm",variant:"outline",children:[e.jsxRuntimeExports.jsx(e.Cross2Icon,{className:"mr-2 size-4"}),"Close"]})]})]})]})}function tt({data:s}){var l;const[n,t]=f.useState([]),i=Object.keys(s[0]).map(o=>({accessorKey:o,header:({column:a})=>{const h=a.getIsSorted();return e.jsxRuntimeExports.jsx("div",{className:"flex gap-2",children:e.jsxRuntimeExports.jsxs("div",{className:"flex cursor-pointer items-center",onClick:()=>a.toggleSorting(a.getIsSorted()==="asc"),children:[o,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]})})}})),x=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:x.getHeaderGroups().map(o=>e.jsxRuntimeExports.jsx(e.TableRow,{children:o.headers.map(a=>e.jsxRuntimeExports.jsx(e.TableHead,{className:"sticky top-0 bg-muted",children:a.isPlaceholder?null:e.flexRender(a.column.columnDef.header,a.getContext())},a.id))},o.id))}),e.jsxRuntimeExports.jsx(e.TableBody,{children:(l=x.getRowModel().rows)!=null&&l.length?x.getRowModel().rows.map(o=>e.jsxRuntimeExports.jsx(e.TableRow,{className:"whitespace-nowrap py-2","data-state":o.getIsSelected()&&"selected",children:o.getVisibleCells().map(a=>e.jsxRuntimeExports.jsx(e.TableCell,{children:e.flexRender(a.column.columnDef.cell,a.getContext())},a.id))},o.id)):e.jsxRuntimeExports.jsx(e.TableRow,{children:e.jsxRuntimeExports.jsx(e.TableCell,{colSpan:i.length,className:"h-24 text-center",children:"No results."})})})]})}function We({className:s,...n}){var l;f.useState(0);const t=e.useDashboardStore(o=>o.themeStyle),r=e.useEditorStore(o=>o.card),i=e.useEditorStore(o=>o.actions.setCard);if(f.useEffect(()=>{},[r.data,r.type,r.cfg,r.customCfg,t,r.preferences]),!r.id)return null;let x;return r.data&&r.data.length>0&&(x=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"&&x&&e.jsxRuntimeExports.jsx(e.ChartJsVisual,{cfg:x},JSON.stringify(x)+JSON.stringify(r.preferences)+((l=r==null?void 0:r.preferences)==null?void 0:l.customVisualCode)),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 rt(){const[s,n]=f.useState(!1),[t,r]=f.useState(""),[i,x]=f.useState(""),[l,o]=f.useState(""),[a,h]=f.useState(""),u=e.useEditorStore(b=>b.card),d=e.useEditorStore(b=>b.card.customCfg),{setCardCustomCfg:v,setCustomVisualCode:c}=e.useEditorActions();function m(b){var N,A;const I={...b,data:{...b==null?void 0:b.data,datasets:(A=(N=b==null?void 0:b.data)==null?void 0:N.datasets)==null?void 0:A.map(D=>({...D,data:[]}))}};return JSON.stringify(I,null,1)}function E(){var I,S;if(!u.data||u.data.length===0)return;const b=e.createChartConfig({data:u.data,cardType:u.type,cfg:u.cfg,preferences:u.preferences});b&&(r(JSON.stringify(b,null,1)),(I=u==null?void 0:u.preferences)!=null&&I.customVisualCode&&o((S=u==null?void 0:u.preferences)==null?void 0:S.customVisualCode),d&&x(JSON.stringify(d,null,1)))}function C(){if(l&&c(l),!!i)try{const b=JSON.parse(i);return b?(v(b),h(""),x(""),b):void 0}catch(b){console.log(b),h("Invalid JSON")}}function y(){x(""),v(null)}function z(){let b;if(d){const I=e._.cloneDeep(u.cfg),S=e._.merge(I,d);return b=m(S),b}return t?(b=m(JSON.parse(t)),b):""}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:E,className:` ${d&&"border-foreground/50 dark:border-foreground/70"}`,size:"sm",variant:"outline",children:e.jsxRuntimeExports.jsx(e.Settings,{className:"h-4 w-4"})})}),e.jsxRuntimeExports.jsxs(e.DialogContent,{className:"max-h-[70vh] min-h-[70vh] overflow-auto sm:min-w-[900px] lg:min-w-[1200px]",children:[e.jsxRuntimeExports.jsxs(e.DialogHeader,{className:"",children:[e.jsxRuntimeExports.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxRuntimeExports.jsx(e.DialogTitle,{children:"Customize Card"}),e.jsxRuntimeExports.jsxs(e.Tooltip,{children:[e.jsxRuntimeExports.jsx(e.TooltipTrigger,{children:e.jsxRuntimeExports.jsx(Rs,{onClick:()=>{navigator.clipboard.writeText(u.id)},className:"size-3 cursor-pointer text-muted-foreground/70 transition-colors hover:text-muted-foreground"})}),e.jsxRuntimeExports.jsx(e.TooltipContent,{side:"right",align:"center",children:e.jsxRuntimeExports.jsx("p",{className:"text-xs",children:"Copy Card ID"})})]})]}),e.jsxRuntimeExports.jsxs(e.DialogDescription,{children:["See the configuration options and documentation",e.jsxRuntimeExports.jsx("a",{target:"_blank",className:"ml-1 text-blue-500 underline",href:"https://www.chartjs.org/docs/latest/samples/bar/vertical.html",children:"here."})]})]}),e.jsxRuntimeExports.jsxs("div",{className:"flex grow gap-2",children:[e.jsxRuntimeExports.jsx(We,{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:[d&&e.jsxRuntimeExports.jsx(e.CheckIcon,{className:"mr-1 h-5 w-5 text-green-600"}),d?"Custom Config":"Default Config"]}),e.jsxRuntimeExports.jsx(e.TabsTrigger,{className:"",value:"output",children:"Output"}),e.jsxRuntimeExports.jsx(e.TabsTrigger,{className:"",value:"custom-code",children:"Custom Code"})]}),e.jsxRuntimeExports.jsx(e.TabsContent,{className:"bg-red-x mt-0 grow rounded-b border border-t-0 p-2",value:"output",children:e.jsxRuntimeExports.jsx(e.Textarea,{disabled:!0,value:t,className:"h-full resize-none border-none font-mono focus-visible:ring-0 focus-visible:ring-offset-0"})}),e.jsxRuntimeExports.jsx(e.TabsContent,{className:"mt-0 grow rounded-b border border-t-0",value:"custom-config",children:e.jsxRuntimeExports.jsx(e.Ft,{className:"h-full w-full overflow-hidden",theme:"default",options:{minimap:{enabled:!1},wordWrap:"on",scrollbar:{verticalScrollbarSize:0,horizontalScrollbarSize:0},fontSize:14,renderLineHighlight:"none"},defaultLanguage:"json",value:z(),onChange:b=>x(b)})}),e.jsxRuntimeExports.jsx(e.TabsContent,{className:"mt-0 grow rounded-b border border-t-0",value:"custom-code",children:e.jsxRuntimeExports.jsx(e.Ft,{className:"h-full w-full overflow-hidden",theme:"default",options:{minimap:{enabled:!1},wordWrap:"on",scrollbar:{verticalScrollbarSize:0,horizontalScrollbarSize:0},fontSize:14,renderLineHighlight:"none"},defaultLanguage:"javascript",value:l,onChange:b=>o(b||"")})})]})]}),e.jsxRuntimeExports.jsxs(e.DialogFooter,{className:"flex items-center",children:[e.jsxRuntimeExports.jsx(e.Label,{className:"mr-2 text-red-500",children:a}),e.jsxRuntimeExports.jsx(e.Button,{disabled:!d,onClick:y,variant:"outline",children:"Reset"}),e.jsxRuntimeExports.jsx(e.Button,{onClick:C,variant:"outline",children:"Apply"}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>n(!1),variant:"outline",children:"Close"})]})]})]})}function Ye(s){return ee({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 Xe(s){return ee({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 Ze(s){return ee({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 es(s){return ee({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 ss(s){return ee({tag:"svg",attr:{viewBox:"0 0 24 24"},child:[{tag:"path",attr:{fill:"none",d:"M0 0h24v24H0z"},child:[]},{tag:"path",attr:{d:"m2 19.99 7.5-7.51 4 4 7.09-7.97L22 9.92l-8.5 9.56-4-4-6 6.01-1.5-1.5zm1.5-4.5 6-6.01 4 4L22 3.92l-1.41-1.41-7.09 7.97-4-4L2 13.99l1.5 1.5z"},child:[]}]})(s)}function ts(s){return ee({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 rs(s){return ee({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 ns(s){return ee({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 nt(){const[s,n]=f.useState(!1),t=e.useEditorStore(a=>a.card.type),{setCardType:r,setCardPreferences:i,setChartOrientation:x}=e.useEditorStore(a=>a.actions),l=e.useEditorStore(a=>a.actions.setCardCustomCfg);function o(a){l(null),i({}),r(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(ot,{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(ze,{className:"size-5"})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>o("line"),variant:"ghost",children:e.jsxRuntimeExports.jsx(Ie,{className:"size-5"})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>o("stackedBar"),variant:"ghost",children:e.jsxRuntimeExports.jsx(ts,{className:"size-5",strokeWidth:0})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>o("stackedLine"),variant:"ghost",children:e.jsxRuntimeExports.jsx(ss,{className:"size-5",strokeWidth:0})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>o("scatter"),variant:"ghost",children:e.jsxRuntimeExports.jsx(Ge,{className:"size-5"})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>o("bubble"),variant:"ghost",children:e.jsxRuntimeExports.jsx(es,{className:"size-4"})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>o("pie"),variant:"ghost",children:e.jsxRuntimeExports.jsx($e,{className:"size-5"})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>o("doughnut"),variant:"ghost",children:e.jsxRuntimeExports.jsx(Xe,{className:"size-5",strokeWidth:1})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>o("radar"),variant:"ghost",children:e.jsxRuntimeExports.jsx(Ye,{className:"size-5 font-extralight",strokeWidth:.5})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>o("polarArea"),variant:"ghost",children:e.jsxRuntimeExports.jsx(Ze,{className:"size-5"})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>o("pyramid"),variant:"ghost",children:e.jsxRuntimeExports.jsx(ns,{className:"size-5"})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>o("range"),variant:"ghost",children:e.jsxRuntimeExports.jsx(He,{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(rs,{className:"size-6"})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>o("text"),variant:"ghost",children:e.jsxRuntimeExports.jsx(Le,{className:"size-4"})})]})})]})}function ot({chartType:s,className:n}){switch(s){case"bar":return e.jsxRuntimeExports.jsx(ze,{className:n});case"line":return e.jsxRuntimeExports.jsx(Ie,{className:n});case"pie":return e.jsxRuntimeExports.jsx($e,{className:n});case"radar":return e.jsxRuntimeExports.jsx(Ye,{className:n});case"scatter":return e.jsxRuntimeExports.jsx(Ge,{className:n});case"bubble":return e.jsxRuntimeExports.jsx(es,{className:n});case"doughnut":return e.jsxRuntimeExports.jsx(Xe,{className:n});case"stackedBar":return e.jsxRuntimeExports.jsx(ts,{className:"size-4 text-foreground/70"});case"stackedLine":return e.jsxRuntimeExports.jsx(ss,{className:"size-4 text-foreground/70"});case"polarArea":return e.jsxRuntimeExports.jsx(Ze,{className:n});case"pyramid":return e.jsxRuntimeExports.jsx(ns,{className:n});case"range":return e.jsxRuntimeExports.jsx(He,{className:n});case"kpi":return e.jsxRuntimeExports.jsx(rs,{className:n});case"text":return e.jsxRuntimeExports.jsx(Le,{className:n});default:return e.jsxRuntimeExports.jsx(e.Table,{className:n})}}function it(){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(us,{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 qe(){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),x=e.useEditorStore(o=>o.pythonStdOut);if(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)return e.jsxRuntimeExports.jsx(e.jsxRuntimeExports.Fragment,{children:"No Active Card"});function l(){return 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})})}):s.type==="text"?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.TextCard,{isLoading:r,card:s})})}):e.jsxRuntimeExports.jsx(We,{className:"grow border-none shadow-none"})}return 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(nt,{}),s.type!=="table"&&e.jsxRuntimeExports.jsx(rt,{}),e.jsxRuntimeExports.jsx(it,{})]}),e.jsxRuntimeExports.jsx(lt,{})]}),t?l():e.jsxRuntimeExports.jsxs("div",{className:"flex min-h-0 w-full flex-1 grow basis-0 px-6",children:[x&&e.jsxRuntimeExports.jsx(at,{}),s.data&&s.data.length>0&&e.jsxRuntimeExports.jsx(tt,{data:n||[]}),i&&e.jsxRuntimeExports.jsx("span",{className:"font-mono text-sm",children:i})]})]})}function at(){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 lt(){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 xe(){const[s,n]=f.useState([]);e.useEditorStore(u=>u.card.cfg);const t=e.useEditorStore(u=>u.card.preferences),{setCardCfg:r,setFilterOnClickColumnIndex:i,setCardPreferences:x}=e.useEditorStore(u=>u.actions),l=e.useEditorStore(u=>u.queryResultColumns);e.useEditorStore(u=>{var d;return(d=u.card.preferences)==null?void 0:d.filterOnClickColumnIndex}),f.useEffect(()=>{l&&n(new Array(l.length).fill(!1))},[l]);function o(u,d){var v,c;d?t!=null&&t.onClickFilter&&((v=t==null?void 0:t.onClickFilter)==null?void 0:v.length)>0?x({...t,onClickFilter:[...t.onClickFilter,{columnIndex:u,expression:""}]}):x({...t,onClickFilter:[{columnIndex:u,expression:""}]}):(x({...t,onClickFilter:(c=t==null?void 0:t.onClickFilter)==null?void 0:c.filter(m=>m.columnIndex!==u)}),n(m=>{const E=[...m];return E[u]=!1,E}))}function a(u,d){var c;const v=(c=t==null?void 0:t.onClickFilter)==null?void 0:c.map(m=>m.columnIndex===u?{...m,expression:d.target.value}:m);x({...t,onClickFilter:v})}function h(u){var d,v,c,m;if(s!=null&&s[u]||(v=(d=t==null?void 0:t.onClickFilter)==null?void 0:d.find(E=>E.columnIndex===u))!=null&&v.expression)return e.jsxRuntimeExports.jsx(e.Input,{value:(m=(c=t==null?void 0:t.onClickFilter)==null?void 0:c.find(E=>E.columnIndex===u))==null?void 0:m.expression,onChange:E=>a(u,E),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:l==null?void 0:l.map((u,d)=>{var v,c;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:!!((v=t==null?void 0:t.onClickFilter)!=null&&v.find(m=>m.columnIndex===d)),onCheckedChange:m=>o(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:((c=t==null?void 0:t.onClickFilter)==null?void 0:c.find(m=>m.columnIndex===d))&&e.jsxRuntimeExports.jsx(Pe,{onClick:()=>{n(m=>{const E=[...m];return E[d]=!m[d],E})},className:" invisible group-hover:visible size-3 text-gray-400 cursor-pointer"})})]}),h(d)]})},u)})})}function Se(){var l,o,a;const s=e.useEditorStore(h=>h.card.preferences),n=e.useEditorStore(h=>h.card.cfg),{setCardCfg:t,setCardPreferences:r,setChartOrientation:i}=e.useEditorStore(h=>h.actions);(l=n==null?void 0:n.options)!=null&&l.indexAxis;function x(h){i(h)}return e.jsxRuntimeExports.jsxs(e.RadioGroup,{value:((o=s==null?void 0:s.chartOptions)==null?void 0:o.indexAxis)||((a=n==null?void 0:n.options)==null?void 0:a.indexAxis)||"x",onValueChange:x,className:"flex gap-3",defaultValue:"x",children:[e.jsxRuntimeExports.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsxRuntimeExports.jsx(e.RadioGroupItem,{value:"x",id:"r1"}),e.jsxRuntimeExports.jsx("label",{className:"text-sm",htmlFor:"r1",children:"Vertical"})]}),e.jsxRuntimeExports.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsxRuntimeExports.jsx(e.RadioGroupItem,{value:"y",id:"r2"}),e.jsxRuntimeExports.jsx("label",{className:"text-sm",htmlFor:"r2",children:"Horizontal"})]})]})}const ce="focus-visible:ring-0 focus-visible:ring-ring focus-visible:ring-offset-0";function Ve(s,n){var r,i,x;const t=e.getNumberAxis(s,n);return((x=(i=(r=s==null?void 0:s.chartOptions)==null?void 0:r.scales)==null?void 0:i[t])==null?void 0:x.type)||"linear"}function os(){var _,H,P,M,$,g;const[s,n]=f.useState(!1),t=e.useEditorStore(R=>{var k;return(k=R.card)==null?void 0:k.preferences}),r=e.useEditorStore(R=>{var k;return(k=R.card)==null?void 0:k.cfg}),i=e.getNumberAxis(t,r),[x,l]=f.useState(Ve(t)),[o,a]=f.useState(((P=(H=(_=t==null?void 0:t.chartOptions)==null?void 0:_.scales)==null?void 0:H[i])==null?void 0:P.min)||""),[h,u]=f.useState(((g=($=(M=t==null?void 0:t.chartOptions)==null?void 0:M.scales)==null?void 0:$[i])==null?void 0:g.max)||""),[d,v]=f.useState(o||h?"custom":"auto"),[c,m]=f.useState(""),[E,C]=f.useState(0),[y,z]=f.useState(""),[b,I]=f.useState(""),[S,N]=f.useState(""),A=e.useEditorStore(R=>R.actions.setCardPreferences),D=e.useEditorStore(R=>{var k;return(k=R.card)==null?void 0:k.type}),w=["pie","doughnut","polarArea"].includes(D);f.useEffect(()=>{var R,k,F,T,K,oe,ie,G,se,q,Q,J,re,W;l(Ve(t)),a(((F=(k=(R=t==null?void 0:t.chartOptions)==null?void 0:R.scales)==null?void 0:k[i])==null?void 0:F.min)===0?0:""),u(((oe=(K=(T=t==null?void 0:t.chartOptions)==null?void 0:T.scales)==null?void 0:K[i])==null?void 0:oe.max)||""),m(((q=(se=(G=(ie=t==null?void 0:t.chartOptions)==null?void 0:ie.scales)==null?void 0:G[i])==null?void 0:se.ticks)==null?void 0:q.stepSize)||""),C(((Q=t==null?void 0:t.numberAxisFormat)==null?void 0:Q.decimalPlaces)||0),z(((J=t==null?void 0:t.numberAxisFormat)==null?void 0:J.suffix)||""),I(((re=t==null?void 0:t.numberAxisFormat)==null?void 0:re.currency)||""),N(((W=t==null?void 0:t.numberAxisFormat)==null?void 0:W.locale)||"")},[s,t,i]);function B(R,k){return k===""||/^[0-9\b]+$/.test(k)?Number(k):Number(R)}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:b,placeholder:"USD",onChange:R=>I(R.target.value),id:"currency",className:`col-span-2 h-8 w-full ${ce}`}),e.jsxRuntimeExports.jsx(e.Input,{value:S,placeholder:"en-US",onChange:R=>N(R.target.value),id:"locale",className:`col-span-2 h-8 w-full ${ce}`})]}),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:E,onChange:R=>C(Number(R.target.value)),id:"format",className:`col-span-6 h-8 w-full tracking-wide ${ce}`})]})]})}function L(){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:o,onChange:R=>a(k=>B(k,R.target.value)),className:`col-span-1 h-8 w-full ${ce}`}),e.jsxRuntimeExports.jsx(e.Input,{value:h,onChange:R=>u(k=>B(k,R.target.value)),id:"max",className:`col-span-1 h-8 w-full ${ce}`})]}),e.jsxRuntimeExports.jsxs("div",{className:"grid grid-cols-3 items-center gap-2",children:[e.jsxRuntimeExports.jsx(e.Label,{htmlFor:"step-size",children:"Step Size"}),e.jsxRuntimeExports.jsx(e.Input,{value:c,onChange:R=>m(k=>B(k,R.target.value)),id:"step-size",className:`col-span-1 h-8 w-full ${ce}`})]})]})}function U(){var F;let R={};d==="custom"&&(R={min:o,max:h,ticks:{stepSize:c}});const k={...t||{},chartOptions:{...t==null?void 0:t.chartOptions,scales:{...(F=t==null?void 0:t.chartOptions)==null?void 0:F.scales,[i]:{type:x,...x==="linear"?R:{}}}},numberAxisFormat:{decimalPlaces:E,suffix:y,currency:b,locale:S}};console.log(k),A(k)}return e.jsxRuntimeExports.jsxs(e.Popover,{onOpenChange:R=>n(R),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:w,value:x,onValueChange:R=>l(R),children:[e.jsxRuntimeExports.jsx(e.SelectTrigger,{className:"col-span-2 h-8 w-full focus:ring-1 focus:ring-offset-0",children:e.jsxRuntimeExports.jsx(e.SelectValue,{})}),e.jsxRuntimeExports.jsx(e.SelectContent,{id:"type",children:e.jsxRuntimeExports.jsxs(e.SelectGroup,{children:[e.jsxRuntimeExports.jsx(e.SelectLabel,{children:"Option"}),e.jsxRuntimeExports.jsx(e.SelectItem,{value:"linear",children:"Linear"}),e.jsxRuntimeExports.jsx(e.SelectItem,{value:"logarithmic",children:"Logarithmic"})]})})]})]}),x=="linear"&&e.jsxRuntimeExports.jsxs("div",{className:"grid grid-cols-3 items-center gap-2 py-1",children:[e.jsxRuntimeExports.jsx(e.Label,{htmlFor:"scale-option",children:"Setup"}),e.jsxRuntimeExports.jsxs(e.RadioGroup,{disabled:w,id:"scale-option",value:d,onValueChange:R=>v(R),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"&&x=="linear"&&L(),O(),e.jsxRuntimeExports.jsx(e.SelectSeparator,{}),e.jsxRuntimeExports.jsx("div",{className:"grid grid-cols-3",children:e.jsxRuntimeExports.jsx(e.Button,{onClick:U,variant:"secondary",className:"col-span-1 col-start-3 h-8 w-full",children:"Apply"})})]})]})})]})}function ct({idx:s}){var o;const n=e.useEditorStore(a=>{var h;return(h=a.card)==null?void 0:h.preferences}),t=e.useEditorStore(a=>{var h;return(h=a.card.preferences)==null?void 0:h.datasetOptions}),r=e.useEditorStore(a=>a.actions.setCardPreferences),i=(o=n==null?void 0:n.chartOptions)==null?void 0:o.indexAxis,x=t==null?void 0:t.find(a=>a.idx===s);function l(a,h){(a==="end"||a==="start")&&e.getContrastColor(e.getCanvasBackgroundColor());const u={display:a!=="none",align:a,anchor:a,clamp:!0};if(!x)r({...n,datasetOptions:[...t||[],{idx:h,datalabels:u}]});else{const d={...x};d.datalabels=u;const v=t==null?void 0:t.map(c=>c.idx===h?d:c);r({...n,datasetOptions:v})}}return e.jsxRuntimeExports.jsxs(e.Popover,{children:[e.jsxRuntimeExports.jsx(e.PopoverTrigger,{children:e.jsxRuntimeExports.jsx(Ls,{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:()=>l("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:()=>l("start",s),size:"sm",variant:"secondary",className:"h-7 p-1 text-xs font-normal",children:e.jsxRuntimeExports.jsx(bs,{className:e.cn("h-4 w-4",{"rotate-90":i==="y"})})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>l("center",s),size:"sm",variant:"secondary",className:"h-7 p-1 text-xs font-normal",children:e.jsxRuntimeExports.jsx(ys,{className:e.cn("h-4 w-4",{"rotate-90":i==="y"})})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>l("end",s),size:"sm",variant:"secondary",className:"h-7 p-1 text-xs font-normal",children:e.jsxRuntimeExports.jsx(Ss,{className:e.cn("h-4 w-4",{"rotate-90":i==="y"})})})]})})]})}function is(){const s=e.useEditorStore(a=>a.card),n=e.useEditorStore(a=>{var h,u,d;return(d=(u=(h=a==null?void 0:a.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:x,dimensionKeys:l}=e.getKeys(s.data||[]);let o=x;if(["stackedBar","stackedLine"].includes(s.type)){const a=e.pivotData({dataArray:s.data||[],groupKey:l[0],pivotKey:l[1],valueKey:o[0]}),{metricKeys:h}=e.getKeys(a);o=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:l[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(os,{})]}),e.jsxRuntimeExports.jsx("div",{className:"my-1 space-y-1",children:o.map((a,h)=>e.jsxRuntimeExports.jsx(xt,{col:a,idx:h},a))})]})]})}function xt({col:s,idx:n}){const t=e.useEditorStore(o=>{var a;return(a=o.card)==null?void 0:a.preferences}),r=e.useEditorStore(o=>{var a;return(a=o.card.preferences)==null?void 0:a.datasetOptions}),i=r==null?void 0:r.find(o=>o.idx===n),{setCardPreferences:x}=e.useEditorStore(o=>o.actions);function l(o){if(!i)x({...t,datasetOptions:[...r||[],{idx:n,type:o==="area"?"line":o,fill:o==="area"?"origin":""}]});else{const a={...i};a.type=o==="area"?"line":o,a.fill=o==="area"?"origin":"";const h=r==null?void 0:r.map(u=>u.idx===n?a:u);x({...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(ze,{onClick:()=>l("bar"),className:"invisible size-4 cursor-pointer text-muted-foreground hover:text-foreground group-hover:visible"}),e.jsxRuntimeExports.jsx(Ie,{onClick:()=>l("line"),className:"invisible size-4 cursor-pointer text-muted-foreground hover:text-foreground group-hover:visible"}),e.jsxRuntimeExports.jsx(ds,{onClick:()=>l("area"),className:"invisible size-4 cursor-pointer text-muted-foreground hover:text-foreground group-hover:visible"}),e.jsxRuntimeExports.jsx(e.Separator,{orientation:"vertical",className:"invisible size-4 cursor-pointer py-2 text-muted-foreground hover:text-foreground group-hover:visible"}),e.jsxRuntimeExports.jsx(ct,{idx:n})]})]})}function ut({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(Se,{}),e.jsxRuntimeExports.jsx(is,{})]})]}),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(xe,{})})]})]})})}function De(){var i,x,l;const s=e.useEditorStore(o=>o.card.cfg),n=e.useEditorStore(o=>o.actions.setCardCfg),t=e.useEditorStore(o=>o.card.type);function r(o){var u;const a={datalabels:{display:o!=="none",align:o,anchor:o,clamp:!0}},h={...s,options:{...s==null?void 0:s.options,plugins:{...(u=s==null?void 0:s.options)==null?void 0:u.plugins,...a}}};n(h),console.log(o)}return e.jsxRuntimeExports.jsxs("div",{className:"space-y-2",children:[e.jsxRuntimeExports.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxRuntimeExports.jsx("label",{className:"font-medium",children:"Data Labels"}),!["pyramid"].includes(t)&&e.jsxRuntimeExports.jsx(os,{})]}),e.jsxRuntimeExports.jsxs(e.Select,{value:(l=(x=(i=s==null?void 0:s.options)==null?void 0:i.plugins)==null?void 0:x.datalabels)==null?void 0:l.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 dt({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:x=>x.stopPropagation(),className:"text-blue-700",href:"https://docs.semaphor.cloud/concepts/visuals#pie-chart",children:"example"})," in the docs."]})]})}return e.jsxRuntimeExports.jsx("div",{className:"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(De,{})})]}),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(xe,{})})]})]})})}const mt={datasets:[{type:"line",label:"Sum_sales",data:[]},{type:"bar",label:"Sum_profit",data:[]}]},pt={datasets:[{fill:"origin",type:"line",label:"Sum_sales",data:[]}]};function ht(){const s=e.useEditorStore(n=>n.card.type);return e.jsxRuntimeExports.jsxs("div",{className:"space-y-6 p-6",children:[e.jsxRuntimeExports.jsx(e.Accordion,{className:" ",type:"single",collapsible:!0,children:jt(s)}),e.jsxRuntimeExports.jsx("section",{className:"",children:["line","bar"].includes(s)&&e.jsxRuntimeExports.jsx(Se,{})}),e.jsxRuntimeExports.jsx("div",{children:!["kpi"].includes(s)&&e.jsxRuntimeExports.jsx(De,{})}),e.jsxRuntimeExports.jsx("div",{children:!["kpi"].includes(s)&&e.jsxRuntimeExports.jsx(xe,{})})]})}function jt(s){if(["line","bar"].includes(s))return e.jsxRuntimeExports.jsxs(e.jsxRuntimeExports.Fragment,{children:[e.jsxRuntimeExports.jsxs(e.AccordionItem,{value:"item-1",children:[e.jsxRuntimeExports.jsx(e.AccordionTrigger,{className:"font-normal",children:e.jsxRuntimeExports.jsx("p",{children:"Chart Query"})}),e.jsxRuntimeExports.jsxs(e.AccordionContent,{className:" ",children:[e.jsxRuntimeExports.jsx("div",{className:"rounded bg-muted px-2 py-1 font-mono text-xs font-semibold",children:"SELECT x-axis, y-axis-1, y-axis-2, y-axis-3,... FROM table"}),e.jsxRuntimeExports.jsxs("ul",{className:"my-6 ml-6 list-disc text-xs font-normal [&>li]:mt-2",children:[e.jsxRuntimeExports.jsx("li",{children:"X-axis - Category (ex. city)"}),e.jsxRuntimeExports.jsx("li",{children:"Y-axis - Number (ex. population)"})]})]})]}),e.jsxRuntimeExports.jsxs(e.AccordionItem,{value:"item-2",children:[e.jsxRuntimeExports.jsx(e.AccordionTrigger,{className:"font-normal",children:"Mixed Chart"}),e.jsxRuntimeExports.jsxs(e.AccordionContent,{className:"space-y-2 text-xs",children:[e.jsxRuntimeExports.jsxs("p",{children:["Click ",e.jsxRuntimeExports.jsx("b",{children:"Customize"})," and change the `type` property in the dataset."]}),e.jsxRuntimeExports.jsx("pre",{children:JSON.stringify(mt,null,2)})]})]}),e.jsxRuntimeExports.jsxs(e.AccordionItem,{value:"item-3",children:[e.jsxRuntimeExports.jsx(e.AccordionTrigger,{className:"font-normal",children:"Area Chart"}),e.jsxRuntimeExports.jsxs(e.AccordionContent,{className:"space-y-2 text-xs",children:[e.jsxRuntimeExports.jsxs("p",{children:["Click ",e.jsxRuntimeExports.jsx("b",{children:"Customize"})," and add `fill` property to the dataset. See",e.jsxRuntimeExports.jsx("a",{className:"mx-1 text-blue-500 hover:underline",href:"https://www.chartjs.org/docs/latest/samples/area/line-boundaries.html",target:"_blank",children:"docs"}),"for more options."]}),e.jsxRuntimeExports.jsx("pre",{children:JSON.stringify(pt,null,2)})]})]})]});if(s==="bubble")return e.jsxRuntimeExports.jsx(e.jsxRuntimeExports.Fragment,{children:e.jsxRuntimeExports.jsxs(e.AccordionItem,{value:"item-1",children:[e.jsxRuntimeExports.jsx(e.AccordionTrigger,{className:"font-normal",children:e.jsxRuntimeExports.jsxs("p",{children:["How to create a ",e.jsxRuntimeExports.jsx("span",{children:s})," chart query?"]})}),e.jsxRuntimeExports.jsxs(e.AccordionContent,{className:" ",children:[e.jsxRuntimeExports.jsx("div",{className:"rounded bg-muted px-2 py-1 font-mono text-xs font-semibold",children:"SELECT label, x-axis, y-axis, radius FROM table"}),e.jsxRuntimeExports.jsxs("ul",{className:"my-6 ml-6 list-disc text-xs font-normal [&>li]:mt-2",children:[e.jsxRuntimeExports.jsx("li",{children:"Label - Category (ex. city)"}),e.jsxRuntimeExports.jsx("li",{children:"Bubble Group (opt) - Category (ex. state)"}),e.jsxRuntimeExports.jsx("li",{children:"X-axis - Number (ex. avg. age)"}),e.jsxRuntimeExports.jsx("li",{children:"Y-axis - Number (ex. avg. weight)"}),e.jsxRuntimeExports.jsx("li",{children:"Radius - Number (ex. population)"})]})]})]})});if(s==="scatter")return e.jsxRuntimeExports.jsx(e.jsxRuntimeExports.Fragment,{children:e.jsxRuntimeExports.jsxs(e.AccordionItem,{value:"item-1",children:[e.jsxRuntimeExports.jsx(e.AccordionTrigger,{className:"font-normal",children:e.jsxRuntimeExports.jsxs("p",{children:["How to create a ",e.jsxRuntimeExports.jsx("span",{children:s})," chart query?"]})}),e.jsxRuntimeExports.jsxs(e.AccordionContent,{className:" ",children:[e.jsxRuntimeExports.jsx("div",{className:"rounded bg-muted px-2 py-1 font-mono text-xs font-semibold",children:"SELECT label, x-axis, y-axis FROM table"}),e.jsxRuntimeExports.jsxs("ul",{className:"my-6 ml-6 list-disc text-xs font-normal [&>li]:mt-2",children:[e.jsxRuntimeExports.jsx("li",{children:"Label - Category (ex. city)"}),e.jsxRuntimeExports.jsx("li",{children:"Group (opt) - Category (ex. state)"}),e.jsxRuntimeExports.jsx("li",{children:"X-axis - Number (ex. avg. age)"}),e.jsxRuntimeExports.jsx("li",{children:"Y-axis - Number (ex. avg. weight)"})]})]})]})});if(["pie","doughnut","polarArea"].includes(s))return e.jsxRuntimeExports.jsx(e.jsxRuntimeExports.Fragment,{children:e.jsxRuntimeExports.jsxs(e.AccordionItem,{value:"item-1",children:[e.jsxRuntimeExports.jsx(e.AccordionTrigger,{className:"font-normal",children:e.jsxRuntimeExports.jsxs("p",{children:[e.jsxRuntimeExports.jsx("span",{children:s==="polarArea"?"Polar":s.charAt(0).toUpperCase()+s.slice(1)})," ","chart query"]})}),e.jsxRuntimeExports.jsxs(e.AccordionContent,{className:" ",children:[e.jsxRuntimeExports.jsx("div",{className:"rounded bg-muted px-2 py-1 font-mono text-xs font-semibold",children:"SELECT label, measure FROM table"}),e.jsxRuntimeExports.jsxs("ul",{className:"my-6 ml-6 list-disc text-xs font-normal [&>li]:mt-2",children:[e.jsxRuntimeExports.jsx("li",{children:"Label - Category (ex. city)"}),e.jsxRuntimeExports.jsx("li",{children:"Measure - Number (ex. population)"})]})]})]})})}function Et(){var a,h,u,d,v;const s=e.useEditorStore(c=>c.card.preferences),n=e.useEditorStore(c=>c.actions.setCardPreferences),t=e.useEditorStore(c=>c.actions.setNumberFormat);e.useEditorStore(c=>{var m,E;return(E=(m=c.card.preferences)==null?void 0:m.formatNumber)==null?void 0:E.decimalPlaces});const r=e.useEditorStore(c=>{var m,E;return(E=(m=c.card.preferences)==null?void 0:m.formatNumber)==null?void 0:E.locale}),i=e.useEditorStore(c=>{var m,E;return(E=(m=c.card.preferences)==null?void 0:m.formatNumber)==null?void 0:E.currency});e.useEditorStore(c=>c.actions.setFilterOnClickField);const x=e.useEditorStore(c=>{var m,E;return(E=(m=c.card.preferences)==null?void 0:m.formatNumber)==null?void 0:E.colorRanges})||[],l=e.useEditorStore(c=>c.actions.setColorRanges),o=[...new Set(e.LOCALE_CURRENCY_PAIRS.map(c=>c.currency))];return e.jsxRuntimeExports.jsxs("div",{children:[e.jsxRuntimeExports.jsxs("div",{className:"mb-3 flex items-center gap-2",children:[e.jsxRuntimeExports.jsx(e.Checkbox,{checked:!!((a=s==null?void 0:s.formatNumber)!=null&&a.enabled),onCheckedChange:c=>{n({...s,formatNumber:{...s==null?void 0:s.formatNumber,enabled:c}})}}),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:c=>{var m,E,C;return t(((m=s==null?void 0:s.formatNumber)==null?void 0:m.decimalPlaces)||0,((E=s==null?void 0:s.formatNumber)==null?void 0:E.currency)||"",c||"en-US",((C=s==null?void 0:s.formatNumber)==null?void 0:C.suffix)||"")},children:[e.jsxRuntimeExports.jsx(e.SelectTrigger,{className:"col-span-6 h-8 w-full focus:ring-1 focus:ring-offset-0",children:e.jsxRuntimeExports.jsx(e.SelectValue,{})}),e.jsxRuntimeExports.jsx(e.SelectContent,{children:e.jsxRuntimeExports.jsxs(e.SelectGroup,{children:[e.jsxRuntimeExports.jsx(e.SelectLabel,{children:"Format"}),e.LOCALE_CURRENCY_PAIRS.map(c=>e.jsxRuntimeExports.jsx(e.SelectItem,{value:c.locale,children:c.locale},c.locale))]})})]})]}),e.jsxRuntimeExports.jsxs("div",{className:"w-full space-y-1",children:[e.jsxRuntimeExports.jsx(e.Label,{children:"Currency"}),e.jsxRuntimeExports.jsxs(e.Select,{value:i||"none",onValueChange:c=>{var m,E,C;return t(((m=s==null?void 0:s.formatNumber)==null?void 0:m.decimalPlaces)||0,c==="none"?"":c,((E=s==null?void 0:s.formatNumber)==null?void 0:E.locale)||"",((C=s==null?void 0:s.formatNumber)==null?void 0:C.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"),o.map(c=>e.jsxRuntimeExports.jsx(e.SelectItem,{value:c,children:c},c))]})})]})]})]}),e.jsxRuntimeExports.jsxs("div",{className:"flex gap-2",children:[e.jsxRuntimeExports.jsxs("div",{className:"w-full space-y-1",children:[e.jsxRuntimeExports.jsx(e.Label,{children:"Decimals"}),e.jsxRuntimeExports.jsxs(e.Select,{value:((d=(u=s==null?void 0:s.formatNumber)==null?void 0:u.decimalPlaces)==null?void 0:d.toString())||"0",onValueChange:c=>{var m,E,C;return t(Number(c),((m=s==null?void 0:s.formatNumber)==null?void 0:m.currency)||"",((E=s==null?void 0:s.formatNumber)==null?void 0:E.locale)||"",((C=s==null?void 0:s.formatNumber)==null?void 0:C.suffix)||"")},children:[e.jsxRuntimeExports.jsx(e.SelectTrigger,{className:"col-span-3 h-8 w-full focus:ring-1 focus:ring-offset-0",children:e.jsxRuntimeExports.jsx(e.SelectValue,{})}),e.jsxRuntimeExports.jsx(e.SelectContent,{children:["0","1","2","3","4"].map(c=>e.jsxRuntimeExports.jsx(e.SelectItem,{value:c,children:c},c))})]})]}),e.jsxRuntimeExports.jsxs("div",{className:"w-full space-y-1",children:[e.jsxRuntimeExports.jsx(e.Label,{children:"Suffix"}),e.jsxRuntimeExports.jsx(e.Input,{value:((v=s==null?void 0:s.formatNumber)==null?void 0:v.suffix)||"",className:"h-8 font-mono text-xs focus-visible:ring-0 focus-visible:ring-ring focus-visible:ring-offset-0",placeholder:"K, M, B, %",onChange:c=>{var m,E,C;return t(((m=s==null?void 0:s.formatNumber)==null?void 0:m.decimalPlaces)||0,((E=s==null?void 0:s.formatNumber)==null?void 0:E.currency)||"",((C=s==null?void 0:s.formatNumber)==null?void 0:C.locale)||"",c.target.value)}})]})]})]})}),e.jsxRuntimeExports.jsx(e.Separator,{className:"my-3"}),e.jsxRuntimeExports.jsx(e.ColorFormat,{colorRanges:x,setColorRanges:l})]})]})}function ft(){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(Et,{})}),e.jsxRuntimeExports.jsx("div",{}),e.jsxRuntimeExports.jsx("div",{})]})}function gt(){var r;const s=e.useEditorStore(i=>i.card.preferences),{setCardPreferences:n}=e.useEditorStore(i=>i.actions);function t(i){n({...s,textVisualOptions:{...s==null?void 0:s.textVisualOptions,isDynamicText:i==="dynamic"}})}return e.jsxRuntimeExports.jsxs(e.RadioGroup,{value:(r=s==null?void 0:s.textVisualOptions)!=null&&r.isDynamicText?"dynamic":"static",onValueChange:t,className:"flex gap-3",defaultValue:"x",children:[e.jsxRuntimeExports.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsxRuntimeExports.jsx(e.RadioGroupItem,{value:"static",id:"r1"}),e.jsxRuntimeExports.jsx("label",{className:"text-sm",htmlFor:"r1",children:"Static"})]}),e.jsxRuntimeExports.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsxRuntimeExports.jsx(e.RadioGroupItem,{value:"dynamic",id:"r2"}),e.jsxRuntimeExports.jsx("label",{className:"text-sm",htmlFor:"r2",children:"Dynamic"})]})]})}function ge({cardType:s,docContent:n,suffix:t="Chart"}){return e.jsxRuntimeExports.jsx("div",{className:"space-y-6 px-6 py-2",children:e.jsxRuntimeExports.jsxs(e.Accordion,{defaultValue:["item-2"],type:"multiple",children:[e.jsxRuntimeExports.jsxs(e.AccordionItem,{value:"item-1",children:[e.jsxRuntimeExports.jsx(e.AccordionTrigger,{children:`${e.titleCase(s)} ${t}`}),e.jsxRuntimeExports.jsx(e.AccordionContent,{children: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:r=>r.stopPropagation(),className:"text-blue-700",href:"https://docs.semaphor.cloud/concepts/visuals#pie-chart",children:"example"})," in the docs."]})]})})]}),e.jsxRuntimeExports.jsxs(e.AccordionItem,{value:"item-2",children:[e.jsxRuntimeExports.jsx(e.AccordionTrigger,{children:"Settings"}),e.jsxRuntimeExports.jsxs(e.AccordionContent,{className:"space-y-4 px-2",children:[s==="range"&&e.jsxRuntimeExports.jsx(Se,{}),s!=="text"&&e.jsxRuntimeExports.jsx(De,{}),s==="text"&&e.jsxRuntimeExports.jsx(gt,{})]})]}),!["range","text"].includes(s)&&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(xe,{})})]})]})})}function Rt(){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(Se,{}),e.jsxRuntimeExports.jsx(is,{})]})]}),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(xe,{})})]})]})})}function bt({}){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(xe,{})})]})}),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 St=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."]})]}),yt=e.jsxRuntimeExports.jsxs("div",{className:"space-y-4 font-mono text-xs",children:[e.jsxRuntimeExports.jsx("div",{className:"rounded bg-muted px-2 py-1 text-xs",children:"SELECT y-axis, label, range-from, range-to, range-value FROM table"}),e.jsxRuntimeExports.jsxs("div",{children:["See ",e.jsxRuntimeExports.jsx("a",{target:"_blank",onClick:s=>s.stopPropagation(),className:"text-blue-700",href:"https://docs.semaphor.cloud/concepts/visuals#range-charts",children:"example"})," in the docs."]})]}),vt=e.jsxRuntimeExports.jsxs("div",{className:"space-y-4 font-mono text-xs",children:[e.jsxRuntimeExports.jsx("div",{className:"rounded bg-muted px-2 py-1 text-xs",children:"SELECT text FROM table limit 1"}),e.jsxRuntimeExports.jsxs("div",{children:["See ",e.jsxRuntimeExports.jsx("a",{target:"_blank",onClick:s=>s.stopPropagation(),className:"text-blue-700",href:"https://docs.semaphor.cloud/concepts/visuals#text-visual",children:"example"})," in the docs."]})]});function Ct(){const s=e.useEditorStore(t=>t.card.type);function n(t){switch(t){case"stackedBar":case"stackedLine":return e.jsxRuntimeExports.jsx(Rt,{});case"pyramid":return e.jsxRuntimeExports.jsx(ge,{docContent:St,cardType:t});case"kpi":return e.jsxRuntimeExports.jsx(ft,{});case"line":case"bar":return e.jsxRuntimeExports.jsx(ut,{cardType:t});case"range":return e.jsxRuntimeExports.jsx(ge,{docContent:yt,cardType:t});case"pie":case"doughnut":case"polarArea":case"radar":return e.jsxRuntimeExports.jsx(ge,{cardType:t});case"bubble":case"scatter":return e.jsxRuntimeExports.jsx(dt,{cardType:t});case"table":return e.jsxRuntimeExports.jsx(bt,{cardType:t});case"text":return e.jsxRuntimeExports.jsx(ge,{docContent:vt,cardType:t,suffix:"Visual"});default:return e.jsxRuntimeExports.jsx(ht,{})}}return e.jsxRuntimeExports.jsx(e.ScrollArea,{className:"h-full w-full text-sm",children:n(s)})}function Nt(){const s=e.useEditorStore(n=>n.isShowingVisual);return e.jsxRuntimeExports.jsxs(e.ResizablePanelGroup,{direction:"vertical",className:"min-h-[250px] min-w-full max-w-lg",children:[e.jsxRuntimeExports.jsx(e.ResizablePanel,{role:"query-section",className:"flex",minSize:20,defaultSize:40,children:e.jsxRuntimeExports.jsx(st,{})}),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(Ct,{})})}),e.jsxRuntimeExports.jsx(e.ResizableHandle,{className:"border"}),e.jsxRuntimeExports.jsx(e.ResizablePanel,{minSize:40,defaultSize:75,maxSize:100,children:e.jsxRuntimeExports.jsx(qe,{})})]}):e.jsxRuntimeExports.jsx(qe,{})})]})}function kt({authToken:s,onSave:n,onClose:t}){const r=e.useEditorStore(l=>l.actions.setOnSave),i=e.useEditorStore(l=>l.actions.setOnClose),x=e.useDashboardStore(l=>l.actions.setAuthToken);return f.useEffect(()=>{n&&r(n),t&&i(t)},[n,r,t,i]),f.useEffect(()=>{s&&s.accessToken&&x(s)},[s,x]),e.jsxRuntimeExports.jsxs(e.EditorPanel,{className:"rounded-none",role:"editor-panel",children:[e.jsxRuntimeExports.jsx(e.EditorAside,{className:"rounded-none border-r-[1.5px]",children:e.jsxRuntimeExports.jsx(Qe,{})}),e.jsxRuntimeExports.jsx(e.EditorMain,{children:e.jsxRuntimeExports.jsx(Nt,{})})]})}function wt(){e.useDashboardStore(l=>l.selectedCardId);const s=e.useDashboardStore(l=>l.selectedSheetId),{setIsVisualEditing:n}=e.useDashboardStore(l=>l.actions),t=e.useDashboardStore(l=>l.isVisualEditing),r=e.useDashboardStore(l=>l.actions.updateFrame);function i(l){s&&(r(s,l),n(!1))}function x(){n(!1)}return e.jsxRuntimeExports.jsx("div",{role:"editor-container",className:e.cn("flex grow",{block:t,hidden:!t}),children:e.jsxRuntimeExports.jsx(kt,{onSave:i,onClose:x})})}function At({columns:s,tableName:n}){const t=e.useEditorStore(d=>d.selectedConnectionId),r=e.useEditorStore(d=>d.selectedDatabaseName),i=e.useEditorStore(d=>d.selectedSchemaName),x=e.useEditorStore(d=>d.selectedTableName),l=e.useDashboardStore(d=>d.dashboard.filters)||[],o=e.useDashboardStore(d=>d.actions.addFilter),a=e.useDashboardStore(d=>d.actions.removeFilter),h=e.useDashboardStore(d=>d.actions.removeFilterValue);function u(d){const v=e.fmt(d.column_name),c=e.fmt(r||""),m=e.fmt(i||""),E=e.fmt(n),C=e.getQualifiedTableName(m,E),y=`${C}.${v}`;console.log("find",y,E,c);const z=l==null?void 0:l.find(b=>b.column===y&&b.table===E&&(b.database===c||b.database===r));if(z)h(z.id),a(z.id);else{if(n==="api"&&t){o({id:e.v4(),column:y,title:d.column_name,dataType:d.data_type,table:"api",database:"",connectionId:t,operation:"in",sql:e.getDefaultFilterSql(d.data_type,C,v)});return}o({id:e.v4(),column:`${C}.${v}`,title:d.column_name,dataType:d.data_type,table:x||"",database:r||"",connectionId:t||"",operation:"in",sql:e.getDefaultFilterSql(d.data_type,C,v)})}}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 v=l==null?void 0:l.find(c=>c.column===e.fmt(d.column_name)&&c.table===x&&c.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":v}),children:e.jsxRuntimeExports.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxRuntimeExports.jsx(Ke,{column:d}),e.jsxRuntimeExports.jsx("span",{children:d.column_name})]})},d.column_name)})})}function zt(){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(Qe,{ColumnsComponent:(n,t,r)=>e.jsxRuntimeExports.jsx(At,{schemaName:n,tableName:t,columns:r})})})]})}function It(){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(zt,{})})]})}function Lt(){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 Tt({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(Lt,{}),e.jsxRuntimeExports.jsxs(e.DashboardPanel,{...t,children:[s&&e.jsxRuntimeExports.jsx(Bs,{}),e.jsxRuntimeExports.jsx(wt,{}),e.jsxRuntimeExports.jsx(It,{})]})]})]})}exports.DashboardPlus=Tt;exports.SelectComponent=pe;exports.useEditorAside=Te;