react-semaphor 0.0.334 → 0.0.335
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.
- package/dist/chunks/{index-CUL2cB6L.js → index-BwB39h9U.js} +248 -229
- package/dist/chunks/{index-CW8qF0bl.js → index-CN4fv4y3.js} +3 -3
- package/dist/chunks/{index-B4Wv7Ers.js → index-D1MyNF8w.js} +75 -75
- package/dist/chunks/{index-BbJlIYmF.js → index-D4eCe4-j.js} +5071 -5057
- package/dist/chunks/{lucide-react-DN-djCId.js → lucide-react-B9ckGV4X.js} +3 -3
- package/dist/chunks/{lucide-react-BHyS8rYq.js → lucide-react-CtJJWo6V.js} +1 -1
- package/dist/dashboard/index.cjs +1 -1
- package/dist/dashboard/index.js +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.js +2 -2
- package/dist/style.css +1 -1
- package/dist/surfboard/index.cjs +1 -1
- package/dist/surfboard/index.js +1 -1
- package/dist/types/dashboard.d.ts +1 -0
- package/dist/types/main.d.ts +1 -0
- package/dist/types/surfboard.d.ts +1 -0
- package/dist/types/types.d.ts +1 -0
- package/package.json +1 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";const e=require("./index-
|
|
1
|
+
"use strict";const e=require("./index-D1MyNF8w.js"),S=require("react");require("react-dom");function _s(s){const n=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(s){for(const t in s)if(t!=="default"){const r=Object.getOwnPropertyDescriptor(s,t);Object.defineProperty(n,t,r.get?r:{enumerable:!0,get:()=>s[t]})}}return n.default=s,Object.freeze(n)}const Pe=_s(S);/**
|
|
2
2
|
* @license lucide-react v0.453.0 - ISC
|
|
3
3
|
*
|
|
4
4
|
* This source code is licensed under the ISC license.
|
|
@@ -178,7 +178,7 @@
|
|
|
178
178
|
*
|
|
179
179
|
* This source code is licensed under the ISC license.
|
|
180
180
|
* See the LICENSE file in the root directory of this source tree.
|
|
181
|
-
*/const fs=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 qe(s){var n;return{...s,sheets:(n=s==null?void 0:s.sheets)==null?void 0:n.map(t=>{var r;return{...t,frames:(r=t.frames)==null?void 0:r.map(o=>{var i;return{...o,cards:(i=o.cards)==null?void 0:i.map(u=>gs(u))}})}})}}function gs(s){var n,t,r,o;return{...s,cfg:{...s.cfg,data:{...(n=s.cfg)==null?void 0:n.data,labels:[],datasets:(o=(r=(t=s.cfg)==null?void 0:t.data)==null?void 0:r.datasets)==null?void 0:o.map(i=>({...i,data:[]}))}},customCfg:_s(s.customCfg),data:[]}}function _s(s){var n,t;return s?{...s,data:{...s==null?void 0:s.data,labels:[],datasets:(t=(n=s==null?void 0:s.data)==null?void 0:n.datasets)==null?void 0:t.map(r=>({...r,data:[]}))}}:null}async function Ps(s,n,t,r){if(!r)return null;const o=JSON.stringify(n);return await e.postRequest("https://semaphor.cloud/api/v1/lens",r,{name:s,template:o,filterValues:t,operation:"create"})}async function Te(s,n){if(!n)return null;const{id:t,template:r,filterValues:o,isDefault:i,shared:u}=s;return await e.postRequest("https://semaphor.cloud/api/v1/lens",n,{lensId:t,template:r,filterValues:o,isDefault:i,shared:u,operation:"update"})}async function Hs(s,n){return n?await e.postRequest("https://semaphor.cloud/api/v1/lens",n,{operation:"delete",lensId:s}):null}function Gs(){const[s,n]=S.useState(""),[t,r]=S.useState(!1),o=e.useDashboardStore(b=>b.lenses),{setLenses:i,setSelectedLensId:u}=e.useDashboardActions(),[l,c]=S.useState(!1),[p,x]=S.useState(!1),f=e.useDashboardStore(b=>b.dashboard),E=e.useDashboardStore(b=>b.filterValues),{authToken:d}=e.useSemaphorContext();async function h(){c(!0);const b=qe(f),w=await Ps(s,b,E,d==null?void 0:d.accessToken);w&&(i([...o||[],w]),u(w.id),x(!1)),c(!1)}return e.jsxRuntimeExports.jsxs(e.Dialog,{open:p,onOpenChange:x,children:[e.jsxRuntimeExports.jsx(e.DialogTrigger,{asChild:!0,children:e.jsxRuntimeExports.jsxs(e.Button,{variant:"secondary",className:"h-7 p-2",size:"sm",children:[e.jsxRuntimeExports.jsx(e.Plus,{className:"mr-2 h-4 w-4",strokeWidth:1.5}),"Lens"]})}),e.jsxRuntimeExports.jsxs(e.DialogContent,{className:"sm:max-w-[425px]",children:[e.jsxRuntimeExports.jsxs(e.DialogHeader,{children:[e.jsxRuntimeExports.jsx(e.DialogTitle,{children:"Create Lens"}),e.jsxRuntimeExports.jsx(e.DialogDescription,{children:"Lenses are private by default and are only visible to you."})]}),e.jsxRuntimeExports.jsx("div",{className:"grid gap-4 py-4",children:e.jsxRuntimeExports.jsxs("div",{className:"grid grid-cols-8 items-center gap-4",children:[e.jsxRuntimeExports.jsx(e.Label,{className:"text-right",children:"Name"}),e.jsxRuntimeExports.jsx(e.Input,{value:s,onChange:b=>{n(b.target.value)},id:"name",className:"col-span-7 focus-visible:ring-0 focus-visible:ring-ring focus-visible:ring-offset-0"})]})}),t&&e.jsxRuntimeExports.jsx("p",{className:"text-sm",children:"The lens name already exists. Use a differnet name."}),e.jsxRuntimeExports.jsx(e.DialogFooter,{children:e.jsxRuntimeExports.jsx(e.Button,{size:"sm",variant:"outline",type:"submit",onClick:h,disabled:l,children:l?"Creating...":"Add"})})]})]})}function $s(){const[s,n]=S.useState(!1),t=e.useDashboardStore(x=>x.lenses),r=e.useDashboardStore(x=>x.selectedLensId),{setLenses:o,setSelectedLensId:i}=e.useDashboardActions(),{authToken:u}=e.useSemaphorContext();async function l(x){i(x)}async function c(x){if(await Hs(x,u==null?void 0:u.accessToken)){const E=t==null?void 0:t.filter(d=>d.id!==x);o(E||[]),i("original")}}async function p(x){const f=t==null?void 0:t.map(h=>h.id===x.id?{...h,isDefault:!x.isDefault}:{...h,isDefault:!1});o(f||[]);const E={...x,isDefault:!x.isDefault};await Te(E,u==null?void 0:u.accessToken);const d=t==null?void 0:t.find(h=>h.isDefault);if(d&&d.id!==x.id){const h={...d,isDefault:!1};await Te(h,u==null?void 0:u.accessToken)}}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:"ghost",className:"h-7 p-2",children:e.jsxRuntimeExports.jsx(ss,{className:"h-4 w-4",strokeWidth:1.5})})}),e.jsxRuntimeExports.jsxs(e.DropdownMenuContent,{align:"end",className:"w-60",children:[e.jsxRuntimeExports.jsx(e.DropdownMenuLabel,{className:"px-3",children:"Lenses"}),e.jsxRuntimeExports.jsx(e.DropdownMenuSeparator,{}),e.jsxRuntimeExports.jsxs(e.DropdownMenuRadioGroup,{value:r,onValueChange:l,children:[e.jsxRuntimeExports.jsx(e.DropdownMenuRadioItem,{value:"original",children:"Original"}),t==null?void 0:t.map(x=>e.jsxRuntimeExports.jsxs(e.DropdownMenuRadioItem,{className:"group flex justify-between gap-2",value:x.id,children:[e.jsxRuntimeExports.jsx("p",{children:x.name}),e.jsxRuntimeExports.jsxs("span",{className:"flex items-center gap-3",children:[e.jsxRuntimeExports.jsx(rs,{onClick:f=>{f.preventDefault(),p(x)},className:e.cn("size-3.5 text-muted-foreground hover:cursor-pointer hover:text-foreground group-hover:visible",{invisible:!x.isDefault,"text-green-500":x.isDefault}),strokeWidth:1.5}),e.jsxRuntimeExports.jsx(e.Cross2Icon,{onClick:f=>{f.preventDefault(),c(x.id)},className:"invisible size-3.5 text-muted-foreground hover:cursor-pointer hover:text-foreground group-hover:visible",strokeWidth:1.5})]})]},x.id))]})]})]})}function Us({iconClassName:s}){const[n,t]=S.useState(!1),{authToken:r}=e.useSemaphorContext(),o=e.useDashboardStore(l=>l.theme),i=e.useDashboardStore(l=>l.filterValues);async function u(){{t(!0);const l=new URLSearchParams;l.set("token",(r==null?void 0:r.accessToken)||""),l.set("theme",o||"light"),l.set("filterValues",JSON.stringify(i));const c=`https://semaphor.cloud/api/v1/generate-pdf?params=${encodeURIComponent(l.toString())}`,x=await(await fetch(c,{method:"GET",headers:{Authorization:`Bearer ${r==null?void 0:r.accessToken}`}})).blob(),f=URL.createObjectURL(x);window.open(f,"_blank"),t(!1)}}return e.jsxRuntimeExports.jsx(e.Button,{variant:"link",className:"group h-7 p-2",size:"sm",onClick:u,children:n?e.jsxRuntimeExports.jsx(oe,{className:e.cn("size-3.5 animate-spin",s)}):e.jsxRuntimeExports.jsx(e.Download,{className:e.cn("size-3.5",s),strokeWidth:1.5})})}function Qs(){S.useState(!1);const{authToken:s}=e.useSemaphorContext();e.useDashboardStore(j=>j.theme);const n=e.useDashboardStore(j=>j.lenses),t=e.useDashboardStore(j=>j.selectedLensId),r=n==null?void 0:n.find(j=>j.id===t),o=e.useDashboardStore(j=>j.dashboard);e.useDashboardStore(j=>j.selectedSheetId);const i=e.useDashboardStore(j=>j.isDashboardEditing),u=e.useEditorStore(j=>j.selectedConnectionId),[l,c]=S.useState(!1),p=e.useDashboardStore(j=>j.filterValues),x=e.useDashboardStore(j=>j.isVisualEditing),f=e.useDashboardStore(j=>j.showFilters);e.useDashboardStore(j=>j.showDashboardJSON);const E=e.useDashboardStore(j=>j.onSaveFunction),d=e.useDashboardStore(j=>j.actions.setShowFilters),{addFrame:h,setSelectedFrameId:b}=e.useDashboardStore(j=>j.actions),{getSelectedSheet:w,setIsDashboardEditing:g,setShowDashboardJSON:L}=e.useDashboardStore(j=>j.actions),k=w(),{tenantId:z,endUserId:y}=S.useMemo(()=>e.getTenantAndEndUserId(s==null?void 0:s.accessToken),[s==null?void 0:s.accessToken]),I=S.useMemo(()=>z||y,[z,y]),A=()=>{if(!i||!k)return;const j={connectionId:u,id:e.v4(),title:"Title",description:"Description",preferences:{onClickFilter:[{columnIndex:0,expression:""}]},type:"bar",sql:"select COUNT(*) from YOUR_TABLE",data:[]},N={id:e.v4(),cards:[j],activeCardId:j.id};h(k.id,N),b(N.id)},m=()=>{g(!0)};async function R(){if(c(!0),!t||!r)return;const j=qe(o),N=JSON.stringify(j),v={...r,template:N,filterValues:p};await Te(v,s==null?void 0:s.accessToken),e.ce.success("Lens saved"),E==null||E(j),c(!1)}return x?null:e.jsxRuntimeExports.jsxs("div",{className:"flex items-center justify-between gap-2 border-b bg-muted/50 py-2 pl-3 pr-2",role:"dashboard-controls",children:[!x&&e.jsxRuntimeExports.jsx("div",{className:"flex items-center gap-3",children:e.jsxRuntimeExports.jsx(e.Label,{children:r==null?void 0:r.name})}),e.jsxRuntimeExports.jsxs("div",{className:"flex gap-2",children:[e.jsxRuntimeExports.jsx(Us,{}),i&&!x&&I&&e.jsxRuntimeExports.jsx(Gs,{}),!x&&I&&e.jsxRuntimeExports.jsx($s,{}),i&&!x&&e.jsxRuntimeExports.jsxs(e.Button,{variant:"secondary",className:"h-7 p-2",size:"sm",disabled:!i,onClick:A,children:[e.jsxRuntimeExports.jsx(e.Plus,{className:"mr-2 h-4 w-4",strokeWidth:1.5}),"Frame"]}),!i&&e.jsxRuntimeExports.jsx(e.Button,{variant:"ghost",className:"h-7 p-2",onClick:m,size:"sm",children:e.jsxRuntimeExports.jsx(e.Pencil,{className:"h-4 w-4",strokeWidth:1.5})}),i&&!x&&e.jsxRuntimeExports.jsx(e.Button,{variant:"ghost",role:"close",className:"h-7 p-2",onClick:()=>{g(!1),L(!1)},size:"sm",children:e.jsxRuntimeExports.jsx(e.Cross2Icon,{className:"h-4 w-4",strokeWidth:1.5})}),i&&!x&&I&&e.jsxRuntimeExports.jsx(e.Button,{className:"h-7 p-2",variant:"ghost",disabled:l,onClick:R,size:"sm",children:e.jsxRuntimeExports.jsx(ds,{className:"h-4 w-4",strokeWidth:1.5})}),!f&&!x&&i&&e.jsxRuntimeExports.jsx(e.Button,{className:"h-7 p-2",variant:"ghost",onClick:()=>d(!0),size:"sm",children:e.jsxRuntimeExports.jsx(e.Filter,{className:"h-4 w-4",strokeWidth:1.5})}),!x&&i&&!1,!x&&!1]})]})}function ue({title:s,items:n,value:t,isLoading:r,isError:o,connectionTooltip:i,onChange:u,showNone:l=!1,className:c,showIcon:p=!0,disabled:x=!1}){const f=r?"Loading...":o?"Error":t;function E(){if(s==="Connection")return e.jsxRuntimeExports.jsx(us,{className:"size-4 rotate-90"});if(s==="Database")return e.jsxRuntimeExports.jsx(Ye,{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==="Model")return e.jsxRuntimeExports.jsx(Qe,{className:"size-4"})}return e.jsxRuntimeExports.jsxs("div",{className:"flex items-center gap-2",children:[p&&e.jsxRuntimeExports.jsx("div",{className:"shrink-0",children:i?e.jsxRuntimeExports.jsxs(e.Tooltip,{children:[e.jsxRuntimeExports.jsx(e.TooltipTrigger,{children:E()}),e.jsxRuntimeExports.jsx(e.TooltipContent,{className:"text-xs",align:"start",children:i})]}):E()}),e.jsxRuntimeExports.jsxs(e.Select,{disabled:x,value:f,onValueChange:u,children:[e.jsxRuntimeExports.jsx(e.SelectTrigger,{className:e.cn("h-9 w-full focus:ring-1 focus:ring-offset-0",c),children:e.jsxRuntimeExports.jsx(e.SelectValue,{placeholder:r?"Loading...":o?"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:[l&&e.jsxRuntimeExports.jsx(e.SelectItem,{value:"none",children:"None"},"none"),n&&n.map((d,h)=>e.jsxRuntimeExports.jsx(e.SelectItem,{value:d.id,children:d.name},h))]}),(r||o)&&e.jsxRuntimeExports.jsx(e.SelectItem,{value:f,children:f})]})})]})]})}function Js({column:s}){const[n,t]=S.useState(!1),r=e.useEditorStore(d=>d.selectedTableName),o=e.useEditorStore(d=>d.selectedSchemaName),i=e.useEditorStore(d=>d.selectedDatamodelId),u=e.useEditorStore(d=>d.sqlGen),{modelItems:l}=ie(),c=e.useEditorStore(d=>d.actions.setSqlGen),p=e.useEditorStore(d=>d.actions.setCardSql),x=e.useEditorStore(d=>d.actions.setRunSql);function f(d,h){var L;const b=e.createSqlGenConfig(d,u,h),w=(L=l==null?void 0:l.find(k=>k.id===i))==null?void 0:L.name;c(b);const g=e.getSql(b,e.fmt(o||""),e.fmt(r),w);g&&(p(g),x(!0)),t(!1)}function E(){return e.jsxRuntimeExports.jsxs("ul",{className:"text-xs",children:[e.jsxRuntimeExports.jsx("li",{onClick:()=>f(s,"COUNT"),className:"cursor-pointer p-1 px-3 transition-colors hover:bg-muted",children:"Count"}),e.jsxRuntimeExports.jsx("li",{onClick:()=>f(s,"AVG"),className:"cursor-pointer p-1 px-3 transition-colors hover:bg-muted",children:"Avg"}),e.jsxRuntimeExports.jsx("li",{onClick:()=>f(s,"SUM"),className:"cursor-pointer p-1 px-3 transition-colors hover:bg-muted",children:"Sum"}),e.jsxRuntimeExports.jsx("li",{onClick:()=>f(s,"MAX"),className:"cursor-pointer p-1 px-3 transition-colors hover:bg-muted",children:"Max"}),e.jsxRuntimeExports.jsx("li",{onClick:()=>f(s,"MIN"),className:"cursor-pointer p-1 px-3 transition-colors hover:bg-muted",children:"Min"})]})}return e.jsxRuntimeExports.jsxs(e.HoverCard,{openDelay:0,open:n,onOpenChange:t,children:[e.jsxRuntimeExports.jsx(e.HoverCardTrigger,{asChild:!0,children:e.jsxRuntimeExports.jsx(Fe,{className:"invisible size-3.5 cursor-pointer text-foreground/40 group-hover:visible"})}),e.jsxRuntimeExports.jsx(e.HoverCardContent,{align:"center",className:"w-20 rounded-md p-0 shadow-none",children:E()})]})}function Rs({column:s}){return e.jsxRuntimeExports.jsxs(e.Tooltip,{children:[e.jsxRuntimeExports.jsx(e.TooltipTrigger$1,{asChild:!0,children:e.TEXT_DATA_TYPES.includes(s.data_type.toLowerCase())?e.jsxRuntimeExports.jsx(ke,{className:"size-3"}):e.NUMBER_DATA_TYPES.includes(s.data_type.toLowerCase())?e.jsxRuntimeExports.jsx(ns,{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(Es,{className:"size-3"}):e.jsxRuntimeExports.jsx(ms,{className:"size-3"})}),e.jsxRuntimeExports.jsx(e.TooltipContent,{children:e.jsxRuntimeExports.jsx("p",{className:"font-mono text-xs",children:s.data_type})})]})}function Ks({schemaName:s,tableName:n,columns:t,status:r}){const o=e.useEditorStore(m=>m.sqlGen),i=e.useEditorStore(m=>m.selectedConnectionId),u=e.useEditorStore(m=>m.selectedDatabaseName),l=e.useEditorStore(m=>m.selectedSchemaName),c=e.useEditorStore(m=>m.selectedTableName),p=e.useEditorStore(m=>m.selectedDatamodelId),x=e.useDashboardStore(m=>m.dashboard.aiScopeTables),{setAIScopeTables:f}=e.useDashboardStore(m=>m.actions),E=e.useEditorStore(m=>m.actions.setRunSql),d=e.useEditorStore(m=>m.actions.setSqlGen),h=e.useEditorStore(m=>m.actions.setIsShowingVisual),b=e.useEditorStore(m=>m.actions.setCardSql),{connectionType:w,modelItems:g}=ie();function L(m){var v;const R=e.createSqlGenConfig(m,o);d(R);const j=(v=g==null?void 0:g.find(O=>O.id===p))==null?void 0:v.name,N=e.getSql(R,e.fmt(s),e.fmt(n),j);N&&(b(N),E(!0))}function k(){return(x==null?void 0:x.find(m=>m.connectinonId===i&&m.tableName===c))!==void 0}function z(m){if(m===!0&&c&&i){const R={connectinonId:i,connectionType:w,databaseName:u,schemaName:l,tableName:c},N=[...x||[],R].filter((v,O,M)=>M.findIndex(B=>B.connectinonId===v.connectinonId&&B.tableName===v.tableName)===O);f(N),e.ce.success(`Added '${c}' to AI Scope`,{position:"top-right",duration:2500,richColors:!0})}else{const R=(x||[]).filter(j=>j.connectinonId!==i&&j.tableName!==c);f(R),e.ce(`Removed '${c}' from AI Scope`,{position:"top-right",duration:2e3,richColors:!0})}}function y(){var v;let m=e.getQualifiedTableName(s,n);const R=(v=g==null?void 0:g.find(O=>O.id===p))==null?void 0:v.name;p&&p!=="none"&&(m=`${e.DATAMODEL_NAMESPCACE}.${R}`);let j=m;return(O=>/[A-Z]/.test(O))(n)&&(j=j.split(".").map(M=>`"${M}"`).join(".")),j}function I(){const m=y();h(!1);const R=w==="MSSQL"?`SELECT top 10 * FROM ${m}`:`SELECT * FROM ${m} LIMIT 10`;b(R),E(!0)}function A(){const m=y();b(`SELECT COUNT(*) as count FROM ${m}`),E(!0)}return e.jsxRuntimeExports.jsxs("div",{className:"flex grow flex-col space-y-4 px-4",children:[e.jsxRuntimeExports.jsxs("div",{className:"flex items-center justify-center gap-1",children:[e.jsxRuntimeExports.jsx(e.Toggle,{title:`${k()?"Remove from":"Add to"} AI Scope`,pressed:k(),onPressedChange:z,variant:"outline",className:"h-9 px-2",children:e.jsxRuntimeExports.jsx(e.Bot,{className:e.cn("size-4",{"text-primary":k(),"text-muted-foreground":!k()})})}),e.jsxRuntimeExports.jsxs(e.Button,{disabled:r!=="Success",onClick:I,size:"sm",variant:"secondary",className:"flex",children:[r!=="Success"?e.jsxRuntimeExports.jsx(oe,{className:"mr-2 h-4 w-4 animate-spin text-foreground/50"}):e.jsxRuntimeExports.jsx(js,{className:"mr-2 size-4"}),"Top 10"]}),e.jsxRuntimeExports.jsxs(e.Button,{disabled:r!=="Success",onClick:A,size:"sm",variant:"secondary",className:"flex",children:[r!=="Success"?e.jsxRuntimeExports.jsx(oe,{className:"mr-2 h-4 w-4 animate-spin text-foreground/50"}):e.jsxRuntimeExports.jsx(ps,{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(m=>e.jsxRuntimeExports.jsxs("div",{onClick:()=>L(m),className:e.cn("group mx-3 flex cursor-pointer items-center justify-between rounded px-2 py-[6px] text-sm transition-colors hover:bg-muted/50",{"bg-muted":e.isColumnInSqlGen(m,o)}),children:[e.jsxRuntimeExports.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsxRuntimeExports.jsx(Rs,{column:m}),e.jsxRuntimeExports.jsx("span",{children:m.column_name})]}),e.jsxRuntimeExports.jsx("div",{onClick:R=>R.stopPropagation(),className:"flex items-center justify-end",children:e.NUMBER_DATA_TYPES.includes(m.data_type)&&e.jsxRuntimeExports.jsx(Js,{column:m})})]},m.column_name)),e.jsxRuntimeExports.jsx(e.ScrollBar,{orientation:"vertical"}),e.jsxRuntimeExports.jsx(e.ScrollBar,{orientation:"horizontal"})]})]})}function ie(s,n){var Ee,fe,ge,Re,be;let t=S.useMemo(()=>[],[]);const r=e.useSemaphorContext().authToken||s,o=e.useEditorStore(a=>a.selectedConnectionId),i=e.useEditorStore(a=>a.selectedDatamodelId),u=e.useEditorStore(a=>a.selectedDatabaseName),l=e.useEditorStore(a=>a.selectedSchemaName),c=e.useEditorStore(a=>a.selectedTableName),p=e.useEditorStore(a=>a.actions.setCurrentColumns),x=e.useEditorStore(a=>a.actions.setSelectedConnectionId),f=e.useEditorStore(a=>a.actions.setSelectedDatamodelId),E=e.useEditorStore(a=>a.actions.setSelectedDatabaseName),d=e.useEditorStore(a=>a.actions.setSelectedSchemaName),h=e.useEditorStore(a=>a.actions.setSelectedTableName),b=e.useEditorStore(a=>a.actions.setCardSql);function w(a){return o&&u&&l&&u!=="NA"?!0:o&&a==="API"?!1:!!(o&&a==="S3")}function g(a){return!!(o&&u&&u!=="NA"&&l&&c||o&&(a==="S3"||a==="API")||i&&i)}function L(a){return o&&a?!(a==="API"||a==="S3"):!1}const{data:k,isLoading:z,isError:y}=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:I,isLoading:A,isError:m}=e.useQuery({queryKey:["models",o],queryFn:()=>e.getRequest("https://semaphor.cloud/api/v1/datamodels",(r==null?void 0:r.accessToken)||"",{connection_id:o}),enabled:!!(r!=null&&r.accessToken)&&!!o}),R=k==null?void 0:k.connections.find(a=>a.id===o),j=R==null?void 0:R.type,N=(R==null?void 0:R.type)==="API"||(R==null?void 0:R.type)==="S3",{data:v,isLoading:O,isFetching:M,isError:B,refetch:H}=e.useQuery({queryKey:["databases",o],queryFn:()=>e.getRequest("https://semaphor.cloud/api/v1/databases",(r==null?void 0:r.accessToken)||"",{connection_id:o}),enabled:L(j)}),{data:q,isLoading:P,isFetching:C,isError:F,refetch:$}=e.useQuery({queryKey:["schemas",o,u],queryFn:()=>e.getRequest("https://semaphor.cloud/api/v1/schemas",(r==null?void 0:r.accessToken)||"",{connection_id:o,database_name:u}),enabled:!!o&&!!u&&!N&&u!=="NA"}),{data:T,isLoading:D,isFetching:U,isError:V,refetch:G}=e.useQuery({queryKey:["tables",o,u,l],queryFn:()=>e.getRequest("https://semaphor.cloud/api/v1/tables",(r==null?void 0:r.accessToken)||"",{connection_id:o,database_name:u,schema_name:l}),enabled:w(j)}),{data:Q,isLoading:le,isFetching:ne,isError:Z}=e.useQuery({queryKey:["columns",o,u,i,l,c],queryFn:()=>e.getRequest("https://semaphor.cloud/api/v1/columns",(r==null?void 0:r.accessToken)||"",{connection_id:o,datamodel_id:i||"",database_name:u,schema_name:l,table_name:c}),enabled:g(j)});S.useEffect(()=>{p(t)},[Q,p,t]),S.useEffect(()=>{},[N,b,h,d,E,R]);const ee=(R==null?void 0:R.type)==="API"?(Ee=R==null?void 0:R.type)==null?void 0:Ee.toLowerCase():c||"",_=N?"":l||"";function K(a){d(a),h("")}function W(a){E(a==="none"?"":a),d(""),h(""),a!=="none"&&a!==""&&f("")}function re(a){x(a)}function ce(a){f(a==="none"?"":a),a!=="none"&&a!==""&&E("")}v&&((fe=v==null?void 0:v.databases)==null?void 0:fe.length)>0,q&&((ge=q==null?void 0:q.schemas)==null?void 0:ge.length)>0,Q&&((Re=Q==null?void 0:Q.columns)==null?void 0:Re.length)>0&&(t=Q.columns.map(a=>({...a,data_type:a.data_type.toLowerCase()}))),B&&(t=[]),(Z||y)&&(t=[]);const me=k==null?void 0:k.connections.map(a=>({id:a.id,name:a.name,type:a.type})),pe=(be=I==null?void 0:I.datamodels)==null?void 0:be.map(a=>({id:a.id,name:a.name})),xe=v==null?void 0:v.databases.map(a=>({id:a.database_name,name:a.database_name})),De=q==null?void 0:q.schemas.map(a=>({id:a.schema_name,name:a.schema_name})),he=T==null?void 0:T.tables.map(a=>({id:a.table_name,name:a.table_name}));return{connectionItems:me,isConnectionsLoading:z,isConnectionsError:y,modelItems:pe,isModelsLoading:A,isModelsError:m,databaseItems:xe,isDatabasesLoadingOrFetching:O||M,isDatabaseError:B,schemaItems:De,isSchemaLoadingOrFetching:P||C,isSchemaError:F,tableItems:he,isTableLoadingOrFetching:D||U,isTableError:V,columns:t,isColumnsLoadingOrFetching:le||ne,isColumnsError:Z,isNonDbConnection:N,connectionType:j,tableName:ee,schemaName:_,handleConnectionChange:re,handleDatamodelChange:ce,handleDatabaseChange:W,handleSchemaChange:K}}function bs({ColumnsComponent:s}){var U;const n=e.useEditorStore(V=>V.selectedConnectionId),t=e.useEditorStore(V=>V.selectedDatamodelId),r=e.useEditorStore(V=>V.selectedDatabaseName),o=e.useEditorStore(V=>V.selectedSchemaName),i=e.useEditorStore(V=>V.selectedTableName),u=e.useEditorStore(V=>V.actions.setSelectedTableName),{connectionItems:l,modelItems:c,schemaItems:p,databaseItems:x,tableItems:f,columns:E,isConnectionsLoading:d,isModelsLoading:h,isConnectionsError:b,isModelsError:w,isDatabasesLoadingOrFetching:g,isDatabaseError:L,isSchemaLoadingOrFetching:k,isSchemaError:z,isColumnsError:y,isColumnsLoadingOrFetching:I,isTableLoadingOrFetching:A,isTableError:m,connectionType:R,isNonDbConnection:j,handleConnectionChange:N,handleDatabaseChange:v,handleSchemaChange:O,handleDatamodelChange:M,tableName:B,schemaName:H}=ie();function q(){return s?s(H,B,E):e.jsxRuntimeExports.jsx(Ks,{schemaName:H,tableName:B,columns:E,status:I?"Loading...":y?"Error":"Success"})}function P(){window.location.href="mailto:support@semaphor.cloud?subject=Help&body=I need help with..."}function C(){if(!n||R==="S3"||R==="API")return null;if(!t||t==="none")return e.jsxRuntimeExports.jsx(ue,{showNone:!0,onChange:v,isError:L,isLoading:g,items:x,value:r||"",title:"Database"})}function F(){if(n&&!j&&(!r||r==="none")&&(!t||t==="none"))return e.jsxRuntimeExports.jsxs("div",{className:"grid grid-cols-3",children:[e.jsxRuntimeExports.jsx("div",{className:"col-span-1 grid place-items-center",children:e.jsxRuntimeExports.jsx(e.Separator,{})}),e.jsxRuntimeExports.jsx("div",{className:"col-span-1 grid place-items-center",children:e.jsxRuntimeExports.jsx(e.Label,{children:"OR"})}),e.jsxRuntimeExports.jsx("div",{className:"col-span-1 grid place-items-center",children:e.jsxRuntimeExports.jsx(e.Separator,{})})]})}function $(){if(!n||R==="S3"||R==="API")return null;if(!r||r==="none")return e.jsxRuntimeExports.jsx(ue,{showNone:!0,onChange:M,isError:w,isLoading:h,items:c,value:t||"",title:"Model"})}function T(){return!n||R==="S3"||R==="API"||!r||r==="none"?null:e.jsxRuntimeExports.jsx(ue,{onChange:O,isError:z,isLoading:k,items:p,value:o||"",title:"Schema"})}function D(){function V(){let G=!1;return R==="API"?(G=!1,G):((R==="S3"||n&&r&&r!=="none"&&o)&&(G=!0),G)}return V()?e.jsxRuntimeExports.jsx(ue,{onChange:u,isError:m,items:f,isLoading:A,value:i||"",title:"Table"}):null}return e.jsxRuntimeExports.jsxs("aside",{className:"xbg-red-100 flex grow flex-col justify-between",children:[e.jsxRuntimeExports.jsxs("section",{className:"space-y-3 px-6 py-4",children:[e.jsxRuntimeExports.jsx(ue,{items:l,title:"Connection",value:n||"",onChange:N,isLoading:d,isError:b,connectionTooltip:((U=l==null?void 0:l.find(V=>V.id===n))==null?void 0:U.type)||""}),$(),F(),C(),T(),D()]}),q(),e.jsxRuntimeExports.jsx("div",{className:"flex items-end justify-center gap-2 px-6 py-4",children:e.jsxRuntimeExports.jsxs(e.Button,{onClick:P,size:"sm",variant:"secondary",className:"w-full",children:[e.jsxRuntimeExports.jsx(ls,{className:"mr-2 size-4"}),"Help"]})})]})}function Ws(s){const n=s.toUpperCase().indexOf("WHERE"),t=s.toUpperCase().indexOf("GROUP BY"),r=s.toUpperCase().indexOf("LIMIT"),o=s.toUpperCase().indexOf("ORDER BY");let i=s.length;if(o!==-1&&(i=o),r!==-1&&r<i&&(i=r),n!==-1){const u=s.substring(0,n),l=s.substring(n);return`${u} {{ filters | where }} AND ${l.substring(6)}`}else if(t!==-1){const u=s.substring(0,t),l=s.substring(t);return`${u} {{ filters | where }} ${l}`}else{const u=s.substring(0,i),l=s.substring(i);return`${u} {{ filters | where }} ${l}`}}function Ys({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:"h-5 p-0",children:e.jsxRuntimeExports.jsx(Ke,{className:"h-4 w-4 text-red-500"})})}),e.jsxRuntimeExports.jsx(e.HoverCardContent,{align:"start",className:"w-full min-w-fit max-w-[700px]",children:e.jsxRuntimeExports.jsx("div",{className:"flex justify-between space-x-4",children:e.jsxRuntimeExports.jsxs("div",{className:"flex grow flex-col space-y-2",children:[e.jsxRuntimeExports.jsx(e.ScrollArea,{className:"max-h-[250px] min-h-0 overflow-scroll",children:e.jsxRuntimeExports.jsx("p",{className:"overflow-auto rounded-md bg-muted p-2 text-xs leading-relaxed",children:s})}),e.jsxRuntimeExports.jsxs(e.Button,{onClick:()=>{n(!0),t(s),r(!0)},size:"sm",variant:"outline",children:[e.jsxRuntimeExports.jsx(ts,{className:"mr-2 h-4 w-4"}),"Debug with AI"]})]})})})]})}const Xs=`
|
|
181
|
+
*/const fs=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 qe(s){var n;return{...s,sheets:(n=s==null?void 0:s.sheets)==null?void 0:n.map(t=>{var r;return{...t,frames:(r=t.frames)==null?void 0:r.map(o=>{var i;return{...o,cards:(i=o.cards)==null?void 0:i.map(u=>gs(u))}})}})}}function gs(s){var n,t,r,o;return{...s,cfg:{...s.cfg,data:{...(n=s.cfg)==null?void 0:n.data,labels:[],datasets:(o=(r=(t=s.cfg)==null?void 0:t.data)==null?void 0:r.datasets)==null?void 0:o.map(i=>({...i,data:[]}))}},customCfg:Bs(s.customCfg),data:[]}}function Bs(s){var n,t;return s?{...s,data:{...s==null?void 0:s.data,labels:[],datasets:(t=(n=s==null?void 0:s.data)==null?void 0:n.datasets)==null?void 0:t.map(r=>({...r,data:[]}))}}:null}async function Ps(s,n,t,r){if(!r)return null;const o=JSON.stringify(n);return await e.postRequest("https://semaphor.cloud/api/v1/lens",r,{name:s,template:o,filterValues:t,operation:"create"})}async function Te(s,n){if(!n)return null;const{id:t,template:r,filterValues:o,isDefault:i,shared:u}=s;return await e.postRequest("https://semaphor.cloud/api/v1/lens",n,{lensId:t,template:r,filterValues:o,isDefault:i,shared:u,operation:"update"})}async function Hs(s,n){return n?await e.postRequest("https://semaphor.cloud/api/v1/lens",n,{operation:"delete",lensId:s}):null}function Gs(){const[s,n]=S.useState(""),[t,r]=S.useState(!1),o=e.useDashboardStore(b=>b.lenses),{setLenses:i,setSelectedLensId:u}=e.useDashboardActions(),[l,c]=S.useState(!1),[p,x]=S.useState(!1),f=e.useDashboardStore(b=>b.dashboard),E=e.useDashboardStore(b=>b.filterValues),{authToken:d}=e.useSemaphorContext();async function h(){c(!0);const b=qe(f),w=await Ps(s,b,E,d==null?void 0:d.accessToken);w&&(i([...o||[],w]),u(w.id),x(!1)),c(!1)}return e.jsxRuntimeExports.jsxs(e.Dialog,{open:p,onOpenChange:x,children:[e.jsxRuntimeExports.jsx(e.DialogTrigger,{asChild:!0,children:e.jsxRuntimeExports.jsxs(e.Button,{variant:"secondary",className:"h-7 p-2",size:"sm",children:[e.jsxRuntimeExports.jsx(e.Plus,{className:"mr-2 h-4 w-4",strokeWidth:1.5}),"Lens"]})}),e.jsxRuntimeExports.jsxs(e.DialogContent,{className:"sm:max-w-[425px]",children:[e.jsxRuntimeExports.jsxs(e.DialogHeader,{children:[e.jsxRuntimeExports.jsx(e.DialogTitle,{children:"Create Lens"}),e.jsxRuntimeExports.jsx(e.DialogDescription,{children:"Lenses are private by default and are only visible to you."})]}),e.jsxRuntimeExports.jsx("div",{className:"grid gap-4 py-4",children:e.jsxRuntimeExports.jsxs("div",{className:"grid grid-cols-8 items-center gap-4",children:[e.jsxRuntimeExports.jsx(e.Label,{className:"text-right",children:"Name"}),e.jsxRuntimeExports.jsx(e.Input,{value:s,onChange:b=>{n(b.target.value)},id:"name",className:"col-span-7 focus-visible:ring-0 focus-visible:ring-ring focus-visible:ring-offset-0"})]})}),t&&e.jsxRuntimeExports.jsx("p",{className:"text-sm",children:"The lens name already exists. Use a differnet name."}),e.jsxRuntimeExports.jsx(e.DialogFooter,{children:e.jsxRuntimeExports.jsx(e.Button,{size:"sm",variant:"outline",type:"submit",onClick:h,disabled:l,children:l?"Creating...":"Add"})})]})]})}function $s(){const[s,n]=S.useState(!1),t=e.useDashboardStore(x=>x.lenses),r=e.useDashboardStore(x=>x.selectedLensId),{setLenses:o,setSelectedLensId:i}=e.useDashboardActions(),{authToken:u}=e.useSemaphorContext();async function l(x){i(x)}async function c(x){if(await Hs(x,u==null?void 0:u.accessToken)){const E=t==null?void 0:t.filter(d=>d.id!==x);o(E||[]),i("original")}}async function p(x){const f=t==null?void 0:t.map(h=>h.id===x.id?{...h,isDefault:!x.isDefault}:{...h,isDefault:!1});o(f||[]);const E={...x,isDefault:!x.isDefault};await Te(E,u==null?void 0:u.accessToken);const d=t==null?void 0:t.find(h=>h.isDefault);if(d&&d.id!==x.id){const h={...d,isDefault:!1};await Te(h,u==null?void 0:u.accessToken)}}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:"ghost",className:"h-7 p-2",children:e.jsxRuntimeExports.jsx(ss,{className:"h-4 w-4",strokeWidth:1.5})})}),e.jsxRuntimeExports.jsxs(e.DropdownMenuContent,{align:"end",className:"w-60",children:[e.jsxRuntimeExports.jsx(e.DropdownMenuLabel,{className:"px-3",children:"Lenses"}),e.jsxRuntimeExports.jsx(e.DropdownMenuSeparator,{}),e.jsxRuntimeExports.jsxs(e.DropdownMenuRadioGroup,{value:r,onValueChange:l,children:[e.jsxRuntimeExports.jsx(e.DropdownMenuRadioItem,{value:"original",children:"Original"}),t==null?void 0:t.map(x=>e.jsxRuntimeExports.jsxs(e.DropdownMenuRadioItem,{className:"group flex justify-between gap-2",value:x.id,children:[e.jsxRuntimeExports.jsx("p",{children:x.name}),e.jsxRuntimeExports.jsxs("span",{className:"flex items-center gap-3",children:[e.jsxRuntimeExports.jsx(rs,{onClick:f=>{f.preventDefault(),p(x)},className:e.cn("size-3.5 text-muted-foreground hover:cursor-pointer hover:text-foreground group-hover:visible",{invisible:!x.isDefault,"text-green-500":x.isDefault}),strokeWidth:1.5}),e.jsxRuntimeExports.jsx(e.Cross2Icon,{onClick:f=>{f.preventDefault(),c(x.id)},className:"invisible size-3.5 text-muted-foreground hover:cursor-pointer hover:text-foreground group-hover:visible",strokeWidth:1.5})]})]},x.id))]})]})]})}function Us({iconClassName:s}){const[n,t]=S.useState(!1),{authToken:r}=e.useSemaphorContext(),o=e.useDashboardStore(l=>l.theme),i=e.useDashboardStore(l=>l.filterValues);async function u(){{t(!0);const l=new URLSearchParams;l.set("token",(r==null?void 0:r.accessToken)||""),l.set("theme",o||"light"),l.set("filterValues",JSON.stringify(i));const c=`https://semaphor.cloud/api/v1/generate-pdf?params=${encodeURIComponent(l.toString())}`,x=await(await fetch(c,{method:"GET",headers:{Authorization:`Bearer ${r==null?void 0:r.accessToken}`}})).blob(),f=URL.createObjectURL(x);window.open(f,"_blank"),t(!1)}}return e.jsxRuntimeExports.jsx(e.Button,{variant:"link",className:"group h-7 p-2",size:"sm",onClick:u,children:n?e.jsxRuntimeExports.jsx(oe,{className:e.cn("size-3.5 animate-spin",s)}):e.jsxRuntimeExports.jsx(e.Download,{className:e.cn("size-3.5",s),strokeWidth:1.5})})}function Qs(){S.useState(!1);const{authToken:s}=e.useSemaphorContext();e.useDashboardStore(j=>j.theme);const n=e.useDashboardStore(j=>j.lenses),t=e.useDashboardStore(j=>j.selectedLensId),r=n==null?void 0:n.find(j=>j.id===t),o=e.useDashboardStore(j=>j.dashboard);e.useDashboardStore(j=>j.selectedSheetId);const i=e.useDashboardStore(j=>j.isDashboardEditing),u=e.useEditorStore(j=>j.selectedConnectionId),[l,c]=S.useState(!1),p=e.useDashboardStore(j=>j.filterValues),x=e.useDashboardStore(j=>j.isVisualEditing),f=e.useDashboardStore(j=>j.showFilters);e.useDashboardStore(j=>j.showDashboardJSON);const E=e.useDashboardStore(j=>j.onSaveFunction),d=e.useDashboardStore(j=>j.actions.setShowFilters),{addFrame:h,setSelectedFrameId:b}=e.useDashboardStore(j=>j.actions),{getSelectedSheet:w,setIsDashboardEditing:g,setShowDashboardJSON:L}=e.useDashboardStore(j=>j.actions),k=w(),{tenantId:z,endUserId:y}=S.useMemo(()=>e.getTenantAndEndUserId(s==null?void 0:s.accessToken),[s==null?void 0:s.accessToken]),I=S.useMemo(()=>z||y,[z,y]),A=()=>{if(!i||!k)return;const j={connectionId:u,id:e.v4(),title:"Title",description:"Description",preferences:{onClickFilter:[{columnIndex:0,expression:""}]},type:"bar",sql:"select COUNT(*) from YOUR_TABLE",data:[]},N={id:e.v4(),cards:[j],activeCardId:j.id};h(k.id,N),b(N.id)},m=()=>{g(!0)};async function R(){if(c(!0),!t||!r)return;const j=qe(o),N=JSON.stringify(j),v={...r,template:N,filterValues:p};await Te(v,s==null?void 0:s.accessToken),e.ce.success("Lens saved"),E==null||E(j),c(!1)}return x?null:e.jsxRuntimeExports.jsxs("div",{className:"flex items-center justify-between gap-2 border-b bg-muted/50 py-2 pl-3 pr-2",role:"dashboard-controls",children:[!x&&e.jsxRuntimeExports.jsx("div",{className:"flex items-center gap-3",children:e.jsxRuntimeExports.jsx(e.Label,{children:r==null?void 0:r.name})}),e.jsxRuntimeExports.jsxs("div",{className:"flex gap-2",children:[e.jsxRuntimeExports.jsx(Us,{}),i&&!x&&I&&e.jsxRuntimeExports.jsx(Gs,{}),!x&&I&&e.jsxRuntimeExports.jsx($s,{}),i&&!x&&e.jsxRuntimeExports.jsxs(e.Button,{variant:"secondary",className:"h-7 p-2",size:"sm",disabled:!i,onClick:A,children:[e.jsxRuntimeExports.jsx(e.Plus,{className:"mr-2 h-4 w-4",strokeWidth:1.5}),"Frame"]}),!i&&e.jsxRuntimeExports.jsx(e.Button,{variant:"ghost",className:"h-7 p-2",onClick:m,size:"sm",children:e.jsxRuntimeExports.jsx(e.Pencil,{className:"h-4 w-4",strokeWidth:1.5})}),i&&!x&&e.jsxRuntimeExports.jsx(e.Button,{variant:"ghost",role:"close",className:"h-7 p-2",onClick:()=>{g(!1),L(!1)},size:"sm",children:e.jsxRuntimeExports.jsx(e.Cross2Icon,{className:"h-4 w-4",strokeWidth:1.5})}),i&&!x&&I&&e.jsxRuntimeExports.jsx(e.Button,{className:"h-7 p-2",variant:"ghost",disabled:l,onClick:R,size:"sm",children:e.jsxRuntimeExports.jsx(ds,{className:"h-4 w-4",strokeWidth:1.5})}),!f&&!x&&i&&e.jsxRuntimeExports.jsx(e.Button,{className:"h-7 p-2",variant:"ghost",onClick:()=>d(!0),size:"sm",children:e.jsxRuntimeExports.jsx(e.Filter,{className:"h-4 w-4",strokeWidth:1.5})}),!x&&i&&!1,!x&&!1]})]})}function ue({title:s,items:n,value:t,isLoading:r,isError:o,connectionTooltip:i,onChange:u,showNone:l=!1,className:c,showIcon:p=!0,disabled:x=!1}){const f=r?"Loading...":o?"Error":t;function E(){if(s==="Connection")return e.jsxRuntimeExports.jsx(us,{className:"size-4 rotate-90"});if(s==="Database")return e.jsxRuntimeExports.jsx(Ye,{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==="Model")return e.jsxRuntimeExports.jsx(Qe,{className:"size-4"})}return e.jsxRuntimeExports.jsxs("div",{className:"flex items-center gap-2",children:[p&&e.jsxRuntimeExports.jsx("div",{className:"shrink-0",children:i?e.jsxRuntimeExports.jsxs(e.Tooltip,{children:[e.jsxRuntimeExports.jsx(e.TooltipTrigger,{children:E()}),e.jsxRuntimeExports.jsx(e.TooltipContent,{className:"text-xs",align:"start",children:i})]}):E()}),e.jsxRuntimeExports.jsxs(e.Select,{disabled:x,value:f,onValueChange:u,children:[e.jsxRuntimeExports.jsx(e.SelectTrigger,{className:e.cn("h-9 w-full focus:ring-1 focus:ring-offset-0",c),children:e.jsxRuntimeExports.jsx(e.SelectValue,{placeholder:r?"Loading...":o?"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:[l&&e.jsxRuntimeExports.jsx(e.SelectItem,{value:"none",children:"None"},"none"),n&&n.map((d,h)=>e.jsxRuntimeExports.jsx(e.SelectItem,{value:d.id,children:d.name},h))]}),(r||o)&&e.jsxRuntimeExports.jsx(e.SelectItem,{value:f,children:f})]})})]})]})}function Js({column:s}){const[n,t]=S.useState(!1),r=e.useEditorStore(d=>d.selectedTableName),o=e.useEditorStore(d=>d.selectedSchemaName),i=e.useEditorStore(d=>d.selectedDatamodelId),u=e.useEditorStore(d=>d.sqlGen),{modelItems:l}=ie(),c=e.useEditorStore(d=>d.actions.setSqlGen),p=e.useEditorStore(d=>d.actions.setCardSql),x=e.useEditorStore(d=>d.actions.setRunSql);function f(d,h){var L;const b=e.createSqlGenConfig(d,u,h),w=(L=l==null?void 0:l.find(k=>k.id===i))==null?void 0:L.name;c(b);const g=e.getSql(b,e.fmt(o||""),e.fmt(r),w);g&&(p(g),x(!0)),t(!1)}function E(){return e.jsxRuntimeExports.jsxs("ul",{className:"text-xs",children:[e.jsxRuntimeExports.jsx("li",{onClick:()=>f(s,"COUNT"),className:"cursor-pointer p-1 px-3 transition-colors hover:bg-muted",children:"Count"}),e.jsxRuntimeExports.jsx("li",{onClick:()=>f(s,"AVG"),className:"cursor-pointer p-1 px-3 transition-colors hover:bg-muted",children:"Avg"}),e.jsxRuntimeExports.jsx("li",{onClick:()=>f(s,"SUM"),className:"cursor-pointer p-1 px-3 transition-colors hover:bg-muted",children:"Sum"}),e.jsxRuntimeExports.jsx("li",{onClick:()=>f(s,"MAX"),className:"cursor-pointer p-1 px-3 transition-colors hover:bg-muted",children:"Max"}),e.jsxRuntimeExports.jsx("li",{onClick:()=>f(s,"MIN"),className:"cursor-pointer p-1 px-3 transition-colors hover:bg-muted",children:"Min"})]})}return e.jsxRuntimeExports.jsxs(e.HoverCard,{openDelay:0,open:n,onOpenChange:t,children:[e.jsxRuntimeExports.jsx(e.HoverCardTrigger,{asChild:!0,children:e.jsxRuntimeExports.jsx(Fe,{className:"invisible size-3.5 cursor-pointer text-foreground/40 group-hover:visible"})}),e.jsxRuntimeExports.jsx(e.HoverCardContent,{align:"center",className:"w-20 rounded-md p-0 shadow-none",children:E()})]})}function Rs({column:s}){return e.jsxRuntimeExports.jsxs(e.Tooltip,{children:[e.jsxRuntimeExports.jsx(e.TooltipTrigger$1,{asChild:!0,children:e.TEXT_DATA_TYPES.includes(s.data_type.toLowerCase())?e.jsxRuntimeExports.jsx(ke,{className:"size-3"}):e.NUMBER_DATA_TYPES.includes(s.data_type.toLowerCase())?e.jsxRuntimeExports.jsx(ns,{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(Es,{className:"size-3"}):e.jsxRuntimeExports.jsx(ms,{className:"size-3"})}),e.jsxRuntimeExports.jsx(e.TooltipContent,{children:e.jsxRuntimeExports.jsx("p",{className:"font-mono text-xs",children:s.data_type})})]})}function Ks({schemaName:s,tableName:n,columns:t,status:r}){const o=e.useEditorStore(m=>m.sqlGen),i=e.useEditorStore(m=>m.selectedConnectionId),u=e.useEditorStore(m=>m.selectedDatabaseName),l=e.useEditorStore(m=>m.selectedSchemaName),c=e.useEditorStore(m=>m.selectedTableName),p=e.useEditorStore(m=>m.selectedDatamodelId),x=e.useDashboardStore(m=>m.dashboard.aiScopeTables),{setAIScopeTables:f}=e.useDashboardStore(m=>m.actions),E=e.useEditorStore(m=>m.actions.setRunSql),d=e.useEditorStore(m=>m.actions.setSqlGen),h=e.useEditorStore(m=>m.actions.setIsShowingVisual),b=e.useEditorStore(m=>m.actions.setCardSql),{connectionType:w,modelItems:g}=ie();function L(m){var v;const R=e.createSqlGenConfig(m,o);d(R);const j=(v=g==null?void 0:g.find(O=>O.id===p))==null?void 0:v.name,N=e.getSql(R,e.fmt(s),e.fmt(n),j);N&&(b(N),E(!0))}function k(){return(x==null?void 0:x.find(m=>m.connectinonId===i&&m.tableName===c))!==void 0}function z(m){if(m===!0&&c&&i){const R={connectinonId:i,connectionType:w,databaseName:u,schemaName:l,tableName:c},N=[...x||[],R].filter((v,O,M)=>M.findIndex(_=>_.connectinonId===v.connectinonId&&_.tableName===v.tableName)===O);f(N),e.ce.success(`Added '${c}' to AI Scope`,{position:"top-right",duration:2500,richColors:!0})}else{const R=(x||[]).filter(j=>j.connectinonId!==i&&j.tableName!==c);f(R),e.ce(`Removed '${c}' from AI Scope`,{position:"top-right",duration:2e3,richColors:!0})}}function y(){var v;let m=e.getQualifiedTableName(s,n);const R=(v=g==null?void 0:g.find(O=>O.id===p))==null?void 0:v.name;p&&p!=="none"&&(m=`${e.DATAMODEL_NAMESPCACE}.${R}`);let j=m;return(O=>/[A-Z]/.test(O))(n)&&(j=j.split(".").map(M=>`"${M}"`).join(".")),j}function I(){const m=y();h(!1);const R=w==="MSSQL"?`SELECT top 10 * FROM ${m}`:`SELECT * FROM ${m} LIMIT 10`;b(R),E(!0)}function A(){const m=y();b(`SELECT COUNT(*) as count FROM ${m}`),E(!0)}return e.jsxRuntimeExports.jsxs("div",{className:"flex grow flex-col space-y-4 px-4",children:[e.jsxRuntimeExports.jsxs("div",{className:"flex items-center justify-center gap-1",children:[e.jsxRuntimeExports.jsx(e.Toggle,{title:`${k()?"Remove from":"Add to"} AI Scope`,pressed:k(),onPressedChange:z,variant:"outline",className:"h-9 px-2",children:e.jsxRuntimeExports.jsx(e.Bot,{className:e.cn("size-4",{"text-primary":k(),"text-muted-foreground":!k()})})}),e.jsxRuntimeExports.jsxs(e.Button,{disabled:r!=="Success",onClick:I,size:"sm",variant:"secondary",className:"flex",children:[r!=="Success"?e.jsxRuntimeExports.jsx(oe,{className:"mr-2 h-4 w-4 animate-spin text-foreground/50"}):e.jsxRuntimeExports.jsx(js,{className:"mr-2 size-4"}),"Top 10"]}),e.jsxRuntimeExports.jsxs(e.Button,{disabled:r!=="Success",onClick:A,size:"sm",variant:"secondary",className:"flex",children:[r!=="Success"?e.jsxRuntimeExports.jsx(oe,{className:"mr-2 h-4 w-4 animate-spin text-foreground/50"}):e.jsxRuntimeExports.jsx(ps,{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(m=>e.jsxRuntimeExports.jsxs("div",{onClick:()=>L(m),className:e.cn("group mx-3 flex cursor-pointer items-center justify-between rounded px-2 py-[6px] text-sm transition-colors hover:bg-muted/50",{"bg-muted":e.isColumnInSqlGen(m,o)}),children:[e.jsxRuntimeExports.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsxRuntimeExports.jsx(Rs,{column:m}),e.jsxRuntimeExports.jsx("span",{children:m.column_name})]}),e.jsxRuntimeExports.jsx("div",{onClick:R=>R.stopPropagation(),className:"flex items-center justify-end",children:e.NUMBER_DATA_TYPES.includes(m.data_type)&&e.jsxRuntimeExports.jsx(Js,{column:m})})]},m.column_name)),e.jsxRuntimeExports.jsx(e.ScrollBar,{orientation:"vertical"}),e.jsxRuntimeExports.jsx(e.ScrollBar,{orientation:"horizontal"})]})]})}function ie(s,n){var Ee,fe,ge,Re,be;let t=S.useMemo(()=>[],[]);const r=e.useSemaphorContext().authToken||s,o=e.useEditorStore(a=>a.selectedConnectionId),i=e.useEditorStore(a=>a.selectedDatamodelId),u=e.useEditorStore(a=>a.selectedDatabaseName),l=e.useEditorStore(a=>a.selectedSchemaName),c=e.useEditorStore(a=>a.selectedTableName),p=e.useEditorStore(a=>a.actions.setCurrentColumns),x=e.useEditorStore(a=>a.actions.setSelectedConnectionId),f=e.useEditorStore(a=>a.actions.setSelectedDatamodelId),E=e.useEditorStore(a=>a.actions.setSelectedDatabaseName),d=e.useEditorStore(a=>a.actions.setSelectedSchemaName),h=e.useEditorStore(a=>a.actions.setSelectedTableName),b=e.useEditorStore(a=>a.actions.setCardSql);function w(a){return o&&u&&l&&u!=="NA"?!0:o&&a==="API"?!1:!!(o&&a==="S3")}function g(a){return!!(o&&u&&u!=="NA"&&l&&c||o&&(a==="S3"||a==="API")||i&&i)}function L(a){return o&&a?!(a==="API"||a==="S3"):!1}const{data:k,isLoading:z,isError:y}=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:I,isLoading:A,isError:m}=e.useQuery({queryKey:["models",o],queryFn:()=>e.getRequest("https://semaphor.cloud/api/v1/datamodels",(r==null?void 0:r.accessToken)||"",{connection_id:o}),enabled:!!(r!=null&&r.accessToken)&&!!o}),R=k==null?void 0:k.connections.find(a=>a.id===o),j=R==null?void 0:R.type,N=(R==null?void 0:R.type)==="API"||(R==null?void 0:R.type)==="S3",{data:v,isLoading:O,isFetching:M,isError:_,refetch:H}=e.useQuery({queryKey:["databases",o],queryFn:()=>e.getRequest("https://semaphor.cloud/api/v1/databases",(r==null?void 0:r.accessToken)||"",{connection_id:o}),enabled:L(j)}),{data:q,isLoading:P,isFetching:C,isError:F,refetch:$}=e.useQuery({queryKey:["schemas",o,u],queryFn:()=>e.getRequest("https://semaphor.cloud/api/v1/schemas",(r==null?void 0:r.accessToken)||"",{connection_id:o,database_name:u}),enabled:!!o&&!!u&&!N&&u!=="NA"}),{data:T,isLoading:D,isFetching:U,isError:V,refetch:G}=e.useQuery({queryKey:["tables",o,u,l],queryFn:()=>e.getRequest("https://semaphor.cloud/api/v1/tables",(r==null?void 0:r.accessToken)||"",{connection_id:o,database_name:u,schema_name:l}),enabled:w(j)}),{data:Q,isLoading:le,isFetching:ne,isError:Z}=e.useQuery({queryKey:["columns",o,u,i,l,c],queryFn:()=>e.getRequest("https://semaphor.cloud/api/v1/columns",(r==null?void 0:r.accessToken)||"",{connection_id:o,datamodel_id:i||"",database_name:u,schema_name:l,table_name:c}),enabled:g(j)});S.useEffect(()=>{p(t)},[Q,p,t]),S.useEffect(()=>{},[N,b,h,d,E,R]);const ee=(R==null?void 0:R.type)==="API"?(Ee=R==null?void 0:R.type)==null?void 0:Ee.toLowerCase():c||"",B=N?"":l||"";function K(a){d(a),h("")}function W(a){E(a==="none"?"":a),d(""),h(""),a!=="none"&&a!==""&&f("")}function re(a){x(a)}function ce(a){f(a==="none"?"":a),a!=="none"&&a!==""&&E("")}v&&((fe=v==null?void 0:v.databases)==null?void 0:fe.length)>0,q&&((ge=q==null?void 0:q.schemas)==null?void 0:ge.length)>0,Q&&((Re=Q==null?void 0:Q.columns)==null?void 0:Re.length)>0&&(t=Q.columns.map(a=>({...a,data_type:a.data_type.toLowerCase()}))),_&&(t=[]),(Z||y)&&(t=[]);const me=k==null?void 0:k.connections.map(a=>({id:a.id,name:a.name,type:a.type})),pe=(be=I==null?void 0:I.datamodels)==null?void 0:be.map(a=>({id:a.id,name:a.name})),xe=v==null?void 0:v.databases.map(a=>({id:a.database_name,name:a.database_name})),De=q==null?void 0:q.schemas.map(a=>({id:a.schema_name,name:a.schema_name})),he=T==null?void 0:T.tables.map(a=>({id:a.table_name,name:a.table_name}));return{connectionItems:me,isConnectionsLoading:z,isConnectionsError:y,modelItems:pe,isModelsLoading:A,isModelsError:m,databaseItems:xe,isDatabasesLoadingOrFetching:O||M,isDatabaseError:_,schemaItems:De,isSchemaLoadingOrFetching:P||C,isSchemaError:F,tableItems:he,isTableLoadingOrFetching:D||U,isTableError:V,columns:t,isColumnsLoadingOrFetching:le||ne,isColumnsError:Z,isNonDbConnection:N,connectionType:j,tableName:ee,schemaName:B,handleConnectionChange:re,handleDatamodelChange:ce,handleDatabaseChange:W,handleSchemaChange:K}}function bs({ColumnsComponent:s}){var U;const n=e.useEditorStore(V=>V.selectedConnectionId),t=e.useEditorStore(V=>V.selectedDatamodelId),r=e.useEditorStore(V=>V.selectedDatabaseName),o=e.useEditorStore(V=>V.selectedSchemaName),i=e.useEditorStore(V=>V.selectedTableName),u=e.useEditorStore(V=>V.actions.setSelectedTableName),{connectionItems:l,modelItems:c,schemaItems:p,databaseItems:x,tableItems:f,columns:E,isConnectionsLoading:d,isModelsLoading:h,isConnectionsError:b,isModelsError:w,isDatabasesLoadingOrFetching:g,isDatabaseError:L,isSchemaLoadingOrFetching:k,isSchemaError:z,isColumnsError:y,isColumnsLoadingOrFetching:I,isTableLoadingOrFetching:A,isTableError:m,connectionType:R,isNonDbConnection:j,handleConnectionChange:N,handleDatabaseChange:v,handleSchemaChange:O,handleDatamodelChange:M,tableName:_,schemaName:H}=ie();function q(){return s?s(H,_,E):e.jsxRuntimeExports.jsx(Ks,{schemaName:H,tableName:_,columns:E,status:I?"Loading...":y?"Error":"Success"})}function P(){window.location.href="mailto:support@semaphor.cloud?subject=Help&body=I need help with..."}function C(){if(!n||R==="S3"||R==="API")return null;if(!t||t==="none")return e.jsxRuntimeExports.jsx(ue,{showNone:!0,onChange:v,isError:L,isLoading:g,items:x,value:r||"",title:"Database"})}function F(){if(n&&!j&&(!r||r==="none")&&(!t||t==="none"))return e.jsxRuntimeExports.jsxs("div",{className:"grid grid-cols-3",children:[e.jsxRuntimeExports.jsx("div",{className:"col-span-1 grid place-items-center",children:e.jsxRuntimeExports.jsx(e.Separator,{})}),e.jsxRuntimeExports.jsx("div",{className:"col-span-1 grid place-items-center",children:e.jsxRuntimeExports.jsx(e.Label,{children:"OR"})}),e.jsxRuntimeExports.jsx("div",{className:"col-span-1 grid place-items-center",children:e.jsxRuntimeExports.jsx(e.Separator,{})})]})}function $(){if(!n||R==="S3"||R==="API")return null;if(!r||r==="none")return e.jsxRuntimeExports.jsx(ue,{showNone:!0,onChange:M,isError:w,isLoading:h,items:c,value:t||"",title:"Model"})}function T(){return!n||R==="S3"||R==="API"||!r||r==="none"?null:e.jsxRuntimeExports.jsx(ue,{onChange:O,isError:z,isLoading:k,items:p,value:o||"",title:"Schema"})}function D(){function V(){let G=!1;return R==="API"?(G=!1,G):((R==="S3"||n&&r&&r!=="none"&&o)&&(G=!0),G)}return V()?e.jsxRuntimeExports.jsx(ue,{onChange:u,isError:m,items:f,isLoading:A,value:i||"",title:"Table"}):null}return e.jsxRuntimeExports.jsxs("aside",{className:"xbg-red-100 flex grow flex-col justify-between",children:[e.jsxRuntimeExports.jsxs("section",{className:"space-y-3 px-6 py-4",children:[e.jsxRuntimeExports.jsx(ue,{items:l,title:"Connection",value:n||"",onChange:N,isLoading:d,isError:b,connectionTooltip:((U=l==null?void 0:l.find(V=>V.id===n))==null?void 0:U.type)||""}),$(),F(),C(),T(),D()]}),q(),e.jsxRuntimeExports.jsx("div",{className:"flex items-end justify-center gap-2 px-6 py-4",children:e.jsxRuntimeExports.jsxs(e.Button,{onClick:P,size:"sm",variant:"secondary",className:"w-full",children:[e.jsxRuntimeExports.jsx(ls,{className:"mr-2 size-4"}),"Help"]})})]})}function Ws(s){const n=s.toUpperCase().indexOf("WHERE"),t=s.toUpperCase().indexOf("GROUP BY"),r=s.toUpperCase().indexOf("LIMIT"),o=s.toUpperCase().indexOf("ORDER BY");let i=s.length;if(o!==-1&&(i=o),r!==-1&&r<i&&(i=r),n!==-1){const u=s.substring(0,n),l=s.substring(n);return`${u} {{ filters | where }} AND ${l.substring(6)}`}else if(t!==-1){const u=s.substring(0,t),l=s.substring(t);return`${u} {{ filters | where }} ${l}`}else{const u=s.substring(0,i),l=s.substring(i);return`${u} {{ filters | where }} ${l}`}}function Ys({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:"h-5 p-0",children:e.jsxRuntimeExports.jsx(Ke,{className:"h-4 w-4 text-red-500"})})}),e.jsxRuntimeExports.jsx(e.HoverCardContent,{align:"start",className:"w-full min-w-fit max-w-[700px]",children:e.jsxRuntimeExports.jsx("div",{className:"flex justify-between space-x-4",children:e.jsxRuntimeExports.jsxs("div",{className:"flex grow flex-col space-y-2",children:[e.jsxRuntimeExports.jsx(e.ScrollArea,{className:"max-h-[250px] min-h-0 overflow-scroll",children:e.jsxRuntimeExports.jsx("p",{className:"overflow-auto rounded-md bg-muted p-2 text-xs leading-relaxed",children:s})}),e.jsxRuntimeExports.jsxs(e.Button,{onClick:()=>{n(!0),t(s),r(!0)},size:"sm",variant:"outline",children:[e.jsxRuntimeExports.jsx(ts,{className:"mr-2 h-4 w-4"}),"Debug with AI"]})]})})})]})}const Xs=`
|
|
182
182
|
|
|
183
183
|
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.
|
|
184
184
|
|
|
@@ -232,4 +232,4 @@ SELECT label, measure FROM table
|
|
|
232
232
|
Table Columns: ${g==null?void 0:g.map(C=>`${C.column_name} | ${C.data_type}`).join(", ")}
|
|
233
233
|
User SQL: ${L}
|
|
234
234
|
${E&&`Base Queries: ${JSON.stringify(E)} `}`,y=` 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.
|
|
235
|
-
Visual Query Syntax: ${Xs}`,{data:I,isLoading:A,isFetching:m,isError:R,refetch:j}=e.useQuery({queryKey:["ai-query"],queryFn:()=>e.getRequest("https://semaphor.cloud/api/v1/ai",(c==null?void 0:c.accessToken)||"",{user_content:`userContent: ${z} ${p?y:""}`}),enabled:!1});function N(C){if(C.toLowerCase().includes("bar"))h("bar");else if(C.toLowerCase().includes("line"))h("line");else if(C.toLowerCase().includes("bubble"))h("bubble");else if(C.toLowerCase().includes("scatter"))h("scatter");else if(C.toLowerCase().includes("stacked"))h("stackedBar");else if(C.toLowerCase().includes("pie"))h("pie");else if(C.toLowerCase().includes("donut")||C.toLowerCase().includes("doughnut"))h("doughnut");else if(C.toLowerCase().includes("radar"))h("radar");else return h("bar"),!1;return!0}S.useEffect(()=>{I&&w(C=>[...C,{role:"ai",content:I.response}])},[I]),S.useEffect(()=>{const C=setTimeout(()=>{var F;l.current&&(l.current.scroll({top:l.current.scrollHeight,behavior:"smooth"}),(F=u.current)==null||F.focus())},100);return()=>clearTimeout(C)},[b]);function v(){t&&(w(C=>[...C,{role:"user",content:t}]),N(t)&&x(!0),r(""),j())}S.useEffect(()=>{o&&(v(),i(!1))},[o,i]);const O={fontFamily:"Arial, sans-serif",lineHeight:1.6,fontSize:15,width:"100%"},M={fontFamily:"monospace",fontSize:14,lineHeight:1.6},B={fontFamily:"Arial, sans-serif",lineHeight:1.6,fontSize:15,padding:"2px 0",marginLeft:20,listStyleType:"disc"},H={p:({node:C,...F})=>e.jsxRuntimeExports.jsx("p",{style:O,...F}),code:({node:C,...F})=>e.jsxRuntimeExports.jsx("code",{className:"rounded-sm bg-muted px-2 py-1 text-sm",...F}),pre:({node:C,...F})=>e.jsxRuntimeExports.jsxs("pre",{className:"space-y-2 rounded-sm bg-muted/50 p-3",style:M,children:[e.jsxRuntimeExports.jsx("code",{className:"whitespace-normal text-sm",children:F.children}),e.jsxRuntimeExports.jsxs("div",{className:"flex justify-start gap-2",children:[e.jsxRuntimeExports.jsx(e.Button,{onClick:q,size:"sm",variant:"outline",children:e.jsxRuntimeExports.jsx(e.ClipboardCopyIcon,{})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:$=>{const T=q($);T&&(n(!1),f(T),d(!0))},size:"sm",variant:"outline",children:e.jsxRuntimeExports.jsx(e.PlayIcon,{})})]})]}),li:({node:C,...F})=>e.jsxRuntimeExports.jsx("li",{style:B,...F})};function q(C){const F=C.currentTarget.closest("pre");if(!F)return;const $=F.textContent||F.innerText;return navigator.clipboard.writeText($).then(()=>console.log("Text copied to clipboard")).catch(T=>console.error("Error in copying text: ",T)),$}function P(){return b==null?void 0:b.map((C,F)=>C.role==="user"?e.jsxRuntimeExports.jsxs("div",{className:"flex items-start rounded-md bg-muted p-3 text-sm",children:[e.jsxRuntimeExports.jsx(fs,{className:"mr-2 h-5 w-5"}),e.jsxRuntimeExports.jsx("div",{children:C.content})]},F):C.role==="ai"?e.jsxRuntimeExports.jsx(e.Markdown,{className:"w-full overflow-auto py-1",components:H,children:I==null?void 0:I.response.replace(/DuckDB/gi,"Semaphor")},F):e.jsxRuntimeExports.jsx("div",{},F))}return e.jsxRuntimeExports.jsxs(e.Dialog,{open:s,onOpenChange:n,children:[e.jsxRuntimeExports.jsx(e.DialogTrigger,{asChild:!0,children:e.jsxRuntimeExports.jsx(e.Button,{size:"sm",className:"w-full justify-start border font-normal text-muted-foreground focus-visible:ring-0 focus-visible:ring-offset-0",variant:"secondary",children:"Type your question here..."})}),e.jsxRuntimeExports.jsxs(e.DialogContent,{className:"flex flex-col justify-between overflow-auto sm:max-w-[425px] md:max-h-[625px] md:min-w-[625px]",children:[e.jsxRuntimeExports.jsxs(e.DialogHeader,{children:[e.jsxRuntimeExports.jsx(e.DialogTitle,{children:"Assistant"}),e.jsxRuntimeExports.jsx(e.DialogDescription,{children:"What can I help you with?"})]}),e.jsxRuntimeExports.jsx("div",{ref:l,className:"h-[625px] w-full overflow-auto border-t border-t-muted",children:e.jsxRuntimeExports.jsx("div",{className:"space-y-4 py-2 pr-3",role:"messages",children:P()})}),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:u,onKeyDown:C=>{C.key==="Enter"&&!C.shiftKey&&(C.preventDefault(),r(""),v())},placeholder:"Type your question here...",onFocus:C=>{const F=C.target,$=F.value.length;F.setSelectionRange($,$)},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||m,value:t,onChange:C=>r(C.target.value)})," ",e.jsxRuntimeExports.jsx(e.Button,{className:"h-8",size:"sm",variant:"ghost",onClick:v,children:!A&&!m?e.jsxRuntimeExports.jsx(e.PaperPlaneIcon,{}):e.jsxRuntimeExports.jsx(oe,{className:"mr-2 h-4 w-4 animate-spin text-foreground/50"})})]})})]})]})}var ys={color:void 0,size:void 0,className:void 0,style:void 0,attr:void 0},He=S.createContext&&S.createContext(ys),et=["attr","size","title"];function st(s,n){if(s==null)return{};var t=tt(s,n),r,o;if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(s);for(o=0;o<i.length;o++)r=i[o],!(n.indexOf(r)>=0)&&Object.prototype.propertyIsEnumerable.call(s,r)&&(t[r]=s[r])}return t}function tt(s,n){if(s==null)return{};var t={};for(var r in s)if(Object.prototype.hasOwnProperty.call(s,r)){if(n.indexOf(r)>=0)continue;t[r]=s[r]}return t}function ve(){return ve=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},ve.apply(this,arguments)}function Ge(s,n){var t=Object.keys(s);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(s);n&&(r=r.filter(function(o){return Object.getOwnPropertyDescriptor(s,o).enumerable})),t.push.apply(t,r)}return t}function Ce(s){for(var n=1;n<arguments.length;n++){var t=arguments[n]!=null?arguments[n]:{};n%2?Ge(Object(t),!0).forEach(function(r){nt(s,r,t[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(s,Object.getOwnPropertyDescriptors(t)):Ge(Object(t)).forEach(function(r){Object.defineProperty(s,r,Object.getOwnPropertyDescriptor(t,r))})}return s}function nt(s,n,t){return n=rt(n),n in s?Object.defineProperty(s,n,{value:t,enumerable:!0,configurable:!0,writable:!0}):s[n]=t,s}function rt(s){var n=ot(s,"string");return typeof n=="symbol"?n:n+""}function ot(s,n){if(typeof s!="object"||!s)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 Ss(s){return s&&s.map((n,t)=>S.createElement(n.tag,Ce({key:t},n.attr),Ss(n.child)))}function X(s){return n=>S.createElement(it,ve({attr:Ce({},s.attr)},n),Ss(s.child))}function it(s){var n=t=>{var{attr:r,size:o,title:i}=s,u=st(s,et),l=o||t.size||"1em",c;return t.className&&(c=t.className),s.className&&(c=(c?c+" ":"")+s.className),S.createElement("svg",ve({stroke:"currentColor",fill:"currentColor",strokeWidth:"0"},t.attr,r,u,{className:c,style:Ce(Ce({color:s.color||t.color},t.style),s.style),height:l,width:l,xmlns:"http://www.w3.org/2000/svg"}),i&&S.createElement("title",null,i),s.children)};return He!==void 0?S.createElement(He.Consumer,null,t=>n(t)):n(ys)}function at(s){return X({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 lt({sql:s}){return e.jsxRuntimeExports.jsxs(e.HoverCard,{children:[e.jsxRuntimeExports.jsx(e.HoverCardTrigger,{asChild:!0,children:e.jsxRuntimeExports.jsx(e.Button,{variant:"link",className:"h-5 p-0",children:e.jsxRuntimeExports.jsx(e.Info,{className:"h-4 w-4 text-muted-foreground"})})}),e.jsxRuntimeExports.jsx(e.HoverCardContent,{align:"end",className:"w-full min-w-fit max-w-[700px] p-3 pt-2",children:e.jsxRuntimeExports.jsxs("div",{className:"space-y-2",children:[e.jsxRuntimeExports.jsx(e.Label,{className:"text-xs font-semibold",children:"Resolved Query"}),e.jsxRuntimeExports.jsx("div",{className:"flex grow flex-col space-y-2",children:e.jsxRuntimeExports.jsx(e.ScrollArea,{className:"max-h-[250px] min-h-0 overflow-scroll",children:e.jsxRuntimeExports.jsx("p",{className:"overflow-auto rounded-md bg-muted p-2 font-mono text-xs leading-relaxed",children:s})})})]})})]})}function ct(){const[s,n]=S.useState({queryKey:[],queryData:null}),{theme:t}=e.useTheme(),r=e.useQueryClient(),o=S.useRef(),i=e.Le(),[u,l]=S.useState(!1),[c,p]=S.useState(!1),[x,f]=S.useState(!1),[E,d]=S.useState(""),[h,b]=S.useState(!1),w=e.useDashboardStore(a=>a.selectedSheetId);e.useDashboardStore(a=>a.dashboard.baseQueries);const g=e.useEditorStore(a=>a.card),L=e.useDashboardStore(a=>a.theme),k=e.useEditorStore(a=>a.isShowingVisual);e.useDashboardStore(a=>a.onAcceptChanges);const z=e.useEditorStore(a=>a.selectedConnectionId),y=e.useEditorStore(a=>a.selectedDatabaseName),I=e.useEditorStore(a=>a.selectedDatamodelId),A=e.useEditorStore(a=>a.selectedSchemaName);e.useDashboardStore(a=>a.actions.updateFrameCard);const m=e.useEditorStore(a=>a.selectedTableName),R=e.useEditorStore(a=>a.card.sql),j=e.useEditorStore(a=>a.card.python),N=e.useEditorStore(a=>a.frame),v=e.useDashboardStore(a=>a.dashboard.filters),O=e.useDashboardStore(a=>a.filterValues),M=v==null?void 0:v.filter(a=>a.sheetId===w||!a.sheetId),B=O==null?void 0:O.filter(a=>(M==null?void 0:M.some(J=>J.id===a.filterId))||a.filterId.endsWith(w)),H=e.useEditorStore(a=>a.applyFilters),{setCardCustomCfg:q,setQueryResultColumns:P,setFilterValues:C,setCardSql:F,setCard:$,setCardPython:T,setQueryError:D,setPythonStdOut:U,setCardPreferences:V}=e.useEditorStore(a=>a.actions),G=e.useEditorStore(a=>a.onSave);e.useEditorStore(a=>a.actions.setApplyFilters);const Q=e.useEditorStore(a=>a.onClose),le=e.useEditorStore(a=>a.actions.setSqlGen),ne=e.useEditorStore(a=>a.runSql),Z=e.useEditorStore(a=>a.actions.setRunSql);e.useEditorStore(a=>a.actions.setCardCfg);const ee=e.useEditorStore(a=>a.actions.setIsSqlRunning),{data:_,isLoading:K,isFetching:W,isSuccess:re,isError:ce,error:me,queryKey:pe,refetch:xe}=e.useDashboardCardQuery(g);S.useEffect(()=>{if(_&&(_.rowLimitExceeded&&e.ce.error("Row limit (10,000) exceeded. Refine your query.",{position:"top-center",richColors:!0}),U((_==null?void 0:_.output)||""),_.records.length>0)){const{dimensionKeys:a}=e.getKeys(_.records);P(a)}},[_,P,U]),S.useEffect(()=>{(K||W)&&ee(!0),(ce||re)&&ee(!1),ce?(D(me.message),P([]),U("")):D("")},[K,W,_,U,ce,re,ee,P,D,me]),S.useEffect(()=>{ne&&(xe(),Z(!1))},[ne,xe,Z]);function De(){const a=r.getQueryData(pe);s.queryData||n({queryKey:pe,queryData:a}),r.setQueryData(pe,null),F(""),le({}),q(""),V({})}const he=a=>{o.current=a};function Ee(a,J){if(a.length===0)return"";if(J){const se=a.find(te=>te.id===J);if(se){const te=se.tabTitle;if(te=="All__Header")return a[0].id;if(te&&te.endsWith("__Header")){const Vs=te.split("__")[0],_e=a.find(qs=>qs.tabTitle===Vs);return _e?_e.id:a[0].id}return J}}return a[0].id}function fe(){let a=R;R&&!R.includes("{{")&&(a=Ws(R),F(a));const J={...g,lastSelectedSchema:A,lastSelectedDatamodelId:I,lastSelectedDatabase:y,lastSelectedTable:m,connectionId:z,type:k?g.type:"table",sql:a,customCfg:k?g.customCfg:null},se=N.cards.map(Le=>Le.id===g.id?J:Le),te={...N,cards:se,activeCardId:Ee(se,N.activeCardId)};G==null||G(te)}function ge(){const{queryKey:a,queryData:J}=s;a&&J&&r.setQueryData(a,J),Q==null||Q()}S.useEffect(()=>{if(!i)return;const a=o.current,J=window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light",se=L==="system"?J:L;return i.editor.defineTheme("default",{base:se==="light"?"vs":"vs-dark",inherit:!0,rules:[],colors:{"editor.background":se==="light"?"#ffffff":e.hslStringToHex("240 10% 10%")}}),i.editor.setTheme("default"),a&&i&&a.addCommand(i.KeyMod.Shift|i.KeyCode.Enter,function(){return xe(),!1}),()=>{}},[t,L,i]);function Re(){return e.jsxRuntimeExports.jsxs(e.jsxRuntimeExports.Fragment,{children:[c&&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(e.Label,{className:"ml-6 text-xs font-semibold",children:"Filters"}),B&&c&&e.jsxRuntimeExports.jsx(e.Cross2Icon,{onClick:()=>p(!1),className:"bg-background/50 text-foreground/50 hover:cursor-pointer hover:text-foreground"})]}),e.jsxRuntimeExports.jsx(e.Ft,{theme:"default",onChange:a=>{if(a)try{JSON.parse(a),C(JSON.parse(a))}catch{}},defaultLanguage:"json",className:"mt-1 min-h-[220px]",value:JSON.stringify(B,null,2),options:{readOnly:!0,minimap:{enabled:!1},lineNumbers:"off",glyphMargin:!1,wordWrap:"on",scrollbar:{verticalScrollbarSize:0,horizontalScrollbarSize:0},fontSize:12,renderLineHighlight:"none"}},L)]})}),B&&!c&&e.jsxRuntimeExports.jsx(e.Filter,{onClick:()=>p(!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":H})})]})}function be(){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:u?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:a=>{F(a)},value:R,options:{minimap:{enabled:!1},wordWrap:"on",scrollbar:{verticalScrollbarSize:0,horizontalScrollbarSize:0},fontSize:14,renderLineHighlight:"none"},defaultLanguage:"sql",onMount:he})}),u&&e.jsxRuntimeExports.jsx("code",{className:"absolute right-6 top-3 text-sm text-muted-foreground/70",children:"sql"})]}),u&&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:a=>{T(a&&a.trim()||"")},value:j||e.PYTHON_DEFAULT_CODE,options:{minimap:{enabled:!1},wordWrap:"on",scrollbar:{verticalScrollbarSize:0,horizontalScrollbarSize:0},fontSize:14,renderLineHighlight:"none"},defaultLanguage:"python",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:[be(),Re()]}),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:K||W,onClick:()=>{xe()},className:"shrink-0",size:"sm",variant:"outline",children:[K||W?e.jsxRuntimeExports.jsx(oe,{className:"mr-2 h-4 w-4 animate-spin text-foreground/50"}):e.jsxRuntimeExports.jsx(xs,{className:"mr-2 h-4 w-4"}),"Run"]}),ce&&e.jsxRuntimeExports.jsx(Ys,{error:me.message,setShowAIDialog:f,setTriggerAIRun:b,setUserInputforAI:d}),e.jsxRuntimeExports.jsxs(e.Button,{onClick:De,className:"",size:"sm",variant:"outline",children:[e.jsxRuntimeExports.jsx(Xe,{className:"mr-2 size-4"}),"Clear"]}),e.jsxRuntimeExports.jsx(e.Toggle,{pressed:u,onPressedChange:a=>l(a),className:"",size:"sm",variant:"outline",children:e.jsxRuntimeExports.jsx(at,{className:"size-4 text-foreground/70"})}),e.jsxRuntimeExports.jsx(Zs,{open:x,setOpen:f,userInput:E,triggerAIRun:h,setTriggerAIRun:b,setUserInput:a=>d(a)})]}),e.jsxRuntimeExports.jsxs("div",{className:"flex items-center gap-2",children:[(_==null?void 0:_.sql)&&e.jsxRuntimeExports.jsx(lt,{sql:_.sql}),e.jsxRuntimeExports.jsxs(e.Button,{onClick:ge,className:"w-full",size:"sm",variant:"outline",children:[e.jsxRuntimeExports.jsx(e.Cross2Icon,{className:"mr-2 size-4"}),"Close"]}),e.jsxRuntimeExports.jsxs(e.Button,{onClick:fe,size:"sm",variant:"outline",children:[e.jsxRuntimeExports.jsx(e.Check,{className:"mr-2 size-4 font-bold text-green-600"}),"Accept"]})]})]})]})}function xt({data:s}){var u;const[n,t]=S.useState([]),o=Object.keys(s[0]).map(l=>({accessorKey:l,header:({column:c})=>{const p=c.getIsSorted();return e.jsxRuntimeExports.jsx("div",{className:"flex gap-2",children:e.jsxRuntimeExports.jsxs("div",{className:"flex cursor-pointer items-center",onClick:()=>c.toggleSorting(c.getIsSorted()==="asc"),children:[l,p==="asc"?e.jsxRuntimeExports.jsx(e.TriangleUpIcon,{className:"ml-2 h-5 w-5"}):p==="desc"?e.jsxRuntimeExports.jsx(e.TriangleDownIcon,{className:"ml-2 h-5 w-5"}):null]})})}})),i=e.useReactTable({data:s,columns:o,getCoreRowModel:e.getCoreRowModel(),getPaginationRowModel:e.getPaginationRowModel(),onSortingChange:t,getSortedRowModel:e.getSortedRowModel(),manualPagination:!0,state:{sorting:n}});return e.jsxRuntimeExports.jsx("div",{className:"font-mono text-xs text-foreground/95",children:e.jsxRuntimeExports.jsxs("table",{className:"w-full",children:[e.jsxRuntimeExports.jsx(e.TableHeader,{children:i.getHeaderGroups().map(l=>e.jsxRuntimeExports.jsx(e.TableRow,{children:l.headers.map(c=>e.jsxRuntimeExports.jsx(e.TableHead,{className:"sticky top-0 h-11 bg-muted font-semibold",children:c.isPlaceholder?null:e.flexRender(c.column.columnDef.header,c.getContext())},c.id))},l.id))}),e.jsxRuntimeExports.jsx(e.TableBody,{children:(u=i.getRowModel().rows)!=null&&u.length?i.getRowModel().rows.map(l=>e.jsxRuntimeExports.jsx(e.TableRow,{className:"whitespace-nowrap py-2","data-state":l.getIsSelected()&&"selected",children:l.getVisibleCells().map(c=>e.jsxRuntimeExports.jsx(e.TableCell,{className:"py-3",children:e.flexRender(c.column.columnDef.cell,c.getContext())},c.id))},l.id)):e.jsxRuntimeExports.jsx(e.TableRow,{children:e.jsxRuntimeExports.jsx(e.TableCell,{colSpan:o.length,className:"h-24 text-center",children:"No results."})})})]})})}function ut({card:s}){var g,L,k,z,y,I,A,m,R,j,N;const[n,t]=S.useState(!1),[r,o]=S.useState([]),{authToken:i}=e.useSemaphorContext(),u=e.getTokenParams(i==null?void 0:i.accessToken),l=e.useDashboardStore(v=>v.themeStyle),c={colors:((L=(g=l==null?void 0:l.chart)==null?void 0:g.dataset)==null?void 0:L.backgroundColor)||[]};(k=s.customCardPreferences)!=null&&k.inputData;const{getCard:p}=e.useCustomVisual(((z=s.customCardPreferences)==null?void 0:z.url)||""),x=((y=s.customCardPreferences)==null?void 0:y.visualType)||"single",f=e.useEditorStore(v=>v.frame);e.useEditorActions();const{data:E}=e.useDashboardCardQuery(s),d=S.useCallback((v,O)=>{o(M=>({...M,[v]:O}))},[]);if(!((I=s.customCardPreferences)!=null&&I.componentName))return null;const h=p((A=s.customCardPreferences)==null?void 0:A.componentName);function b(v){t(v)}const w=Object.keys(((m=s.customCardPreferences)==null?void 0:m.dataInputCardIds)||{}).map(v=>{var B,H,q;const O=(H=(B=s.customCardPreferences)==null?void 0:B.dataInputCardIds)==null?void 0:H[v].cardId,M=(q=f==null?void 0:f.cards)==null?void 0:q.find(P=>P.id===O);return M||null});return e.jsxRuntimeExports.jsx("div",{className:"semaphor-custom mb-3 flex grow basis-0 flex-col space-y-2 overflow-y-auto",children:e.jsxRuntimeExports.jsxs(S.Suspense,{fallback:e.jsxRuntimeExports.jsx(e.jsxRuntimeExports.Fragment,{}),children:[h&&x==="single"&&e.jsxRuntimeExports.jsx(h,{params:u,theme:c,settings:(R=s.customCardPreferences)==null?void 0:R.settings,onDataChange:d,data:(E==null?void 0:E.records)||[]}),h&&x==="multiple"&&e.jsxRuntimeExports.jsxs(e.jsxRuntimeExports.Fragment,{children:[Object.keys(((j=s.customCardPreferences)==null?void 0:j.dataInputCardIds)||{}).map(v=>{var B,H,q;const O=(H=(B=s.customCardPreferences)==null?void 0:B.dataInputCardIds)==null?void 0:H[v].cardId,M=(q=f==null?void 0:f.cards)==null?void 0:q.find(P=>P.id===O);if(M)return e.jsxRuntimeExports.jsx(e.MultiInputEmptyRenderer,{onLoadingStatus:b,onDataChange:d,dataInputIndex:v,card:M},M.id+v)}),e.jsxRuntimeExports.jsx("div",{className:"flex flex-col gap-2",children:e.jsxRuntimeExports.jsx(h,{theme:c,onDataChange:d,settings:w.map(v=>{var O;return(O=v==null?void 0:v.customCardPreferences)==null?void 0:O.settings}),data:w.map(v=>v!=null&&v.id?r==null?void 0:r[v.id]:[])})})]})]},(N=s.customCardPreferences)==null?void 0:N.componentName)})}function vs({className:s,...n}){var w;const t=e.useEditorStore(g=>g.card),r=((w=t.customCardPreferences)==null?void 0:w.showCardHeader)??!0,o=e.useEditorStore(g=>g.frame),i=e.useDashboardStore(g=>g.dashboard.filters);e.useEditorStore(g=>g.actions.setRunSql);const{updateFilter:u}=e.useDashboardActions(),l=i==null?void 0:i.find(g=>g.id===o.filterId),{data:c,isLoading:p,isFetching:x}=e.useDashboardCardQuery(t),{setCard:f}=e.useEditorActions(),{data:E}=e.useTopoJson(t);if(!t.id)return null;let d;c!=null&&c.records&&(c==null?void 0:c.records.length)>0&&(d=e.createChartConfig({data:c==null?void 0:c.records,cardType:t.type,cfg:t.cfg,customCfg:t.customCfg,preferences:t.preferences,topoJson:E}));function h(g){return e.jsxRuntimeExports.jsx(ut,{card:g})}function b(){var g;if(c!=null&&c.records&&(c==null?void 0:c.records.length)===0&&!p&&!x)return e.jsxRuntimeExports.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-2",children:[e.jsxRuntimeExports.jsx(e.TreePalm,{className:"size-8 text-muted-foreground"}),e.jsxRuntimeExports.jsx("p",{className:"text-sm text-muted-foreground",children:"No records to display"})]});if(t.type==="custom")return h(t);if(!["table","custom"].includes(t.type)&&d)return e.jsxRuntimeExports.jsx(e.ChartJsVisual,{cfg:d},JSON.stringify(d)+JSON.stringify(t.preferences)+((g=t==null?void 0:t.preferences)==null?void 0:g.customVisualCode));if(t.type==="table"&&(c!=null&&c.records)&&(c==null?void 0:c.records.length)>0)return e.jsxRuntimeExports.jsxs(e.ScrollArea,{className:"relative mb-2 flex h-full min-h-0 w-full flex-1 grow basis-0",children:[e.jsxRuntimeExports.jsx(e.TableVisual,{card:t,data:c==null?void 0:c.records}),e.jsxRuntimeExports.jsx(e.ScrollBar,{orientation:"horizontal"})]})}return e.jsxRuntimeExports.jsxs(e.Card,{role:"editor-visual-card",className:e.cn("relative flex h-full flex-col rounded-none",s),...n,children:[r&&e.jsxRuntimeExports.jsxs(e.CardHeader,{className:"flex flex-row items-start justify-between py-4",children:[e.jsxRuntimeExports.jsxs("div",{children:[e.jsxRuntimeExports.jsx(e.Editable,{text:t.title,onSave:g=>f({...t,title:g}),children:e.jsxRuntimeExports.jsx("div",{className:"flex items-center gap-5",children:e.jsxRuntimeExports.jsx(e.CardTitle,{className:"text-base",children:t.title||"Edit title..."})})},t.title),e.jsxRuntimeExports.jsx(e.Editable,{text:t.description||"",onSave:g=>f({...t,description:g}),children:e.jsxRuntimeExports.jsx(e.CardDescription,{children:t.description||"Edit description..."})},t.description)]}),l&&e.jsxRuntimeExports.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxRuntimeExports.jsx(e.Editable,{className:"my-1",text:l.title||l.column,onSave:g=>u({...l,title:g}),children:e.jsxRuntimeExports.jsx(e.Label,{children:l.title})}),e.jsxRuntimeExports.jsx(e.FilterComponent,{filter:l})]})]}),e.jsxRuntimeExports.jsx(e.CardContent,{className:"flex grow flex-col",children:b()})]})}function dt(){const[s,n]=S.useState(!1),[t,r]=S.useState(""),[o,i]=S.useState(""),[u,l]=S.useState(""),[c,p]=S.useState(""),x=e.useEditorStore(y=>y.card),f=e.useEditorStore(y=>y.card.customCfg),{data:E}=e.useDashboardCardQuery(x),{data:d}=e.useTopoJson(x),{setCardCustomCfg:h,setCustomVisualCode:b}=e.useEditorActions();function w(y){var m,R;const I={...y,data:{...y==null?void 0:y.data,datasets:(R=(m=y==null?void 0:y.data)==null?void 0:m.datasets)==null?void 0:R.map(j=>({...j,data:[]}))}};return JSON.stringify(I,null,1)}function g(){var I,A;if(!(E!=null&&E.records)||(E==null?void 0:E.records.length)===0)return;const y=e.createChartConfig({data:E==null?void 0:E.records,cardType:x.type,cfg:x.cfg,preferences:x.preferences,topoJson:d});y&&(r(JSON.stringify(y,null,1)),(I=x==null?void 0:x.preferences)!=null&&I.customVisualCode&&l((A=x==null?void 0:x.preferences)==null?void 0:A.customVisualCode),f&&i(JSON.stringify(f,null,1)))}function L(){if(u&&b(u),!!o)try{const y=JSON.parse(o);return y?(h(y),p(""),i(""),y):void 0}catch(y){console.log(y),p("Invalid JSON")}}function k(){i(""),h(null)}function z(){let y;if(f){const I=e._.cloneDeep(x.cfg),A=e._.merge(I,f);return y=w(A),y}return t?(y=w(JSON.parse(t)),y):""}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:g,className:` ${f&&"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.jsx("div",{className:"flex items-center gap-2",children:e.jsxRuntimeExports.jsx(e.DialogTitle,{children:"Customize Card"})}),e.jsxRuntimeExports.jsxs(e.DialogDescription,{children:["See the configuration options and documentation",e.jsxRuntimeExports.jsx("a",{target:"_blank",className:"ml-1 text-blue-500 underline",href:"https://www.chartjs.org/docs/latest/samples/bar/vertical.html",children:"here."})]})]}),e.jsxRuntimeExports.jsxs("div",{className:"flex grow gap-2",children:[e.jsxRuntimeExports.jsx(e.ErrorBoundary,{FallbackComponent:e.FallbackEditorCard,children:e.jsxRuntimeExports.jsx(vs,{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:[f&&e.jsxRuntimeExports.jsx(e.CheckIcon,{className:"mr-1 h-5 w-5 text-green-600"}),f?"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:y=>i(y)})}),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:u,onChange:y=>l(y||"")})})]})]}),e.jsxRuntimeExports.jsxs(e.DialogFooter,{className:"flex items-center",children:[e.jsxRuntimeExports.jsx(e.Label,{className:"mr-2 text-red-500",children:c}),e.jsxRuntimeExports.jsx(e.Button,{disabled:!f,onClick:k,variant:"outline",children:"Reset"}),e.jsxRuntimeExports.jsx(e.Button,{onClick:L,variant:"outline",children:"Apply"}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>n(!1),variant:"outline",children:"Close"})]})]})]})}function Cs(s){return X({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 Ns(s){return X({tag:"svg",attr:{viewBox:"0 0 256 256",fill:"currentColor"},child:[{tag:"path",attr:{d:"M128,24a8,8,0,0,0-8,8V88a8,8,0,0,0,8,8,32,32,0,1,1-27.72,16,8,8,0,0,0-2.93-10.93l-48.5-28A8,8,0,0,0,37.92,76,104,104,0,1,0,128,24ZM48.09,91.1,83,111.26A48.09,48.09,0,0,0,80,128c0,1.53.08,3,.22,4.52L41.28,143A88.16,88.16,0,0,1,48.09,91.1Zm-2.67,67.31,39-10.44A48.1,48.1,0,0,0,120,175.32v40.31A88.2,88.2,0,0,1,45.42,158.41ZM136,215.63V175.32a48,48,0,0,0,0-94.65V40.36a88,88,0,0,1,0,175.27Z"},child:[]}]})(s)}function ws(s){return X({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 ks(s){return X({tag:"svg",attr:{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"},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 Is(s){return X({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 Ds(s){return X({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 Ls(s){return X({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 Ts(s){return X({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 As(s){const[n,t]=S.useState(null);return S.useEffect(()=>{s&&(async()=>{const i=(await Promise.resolve().then(()=>require("./lucide-react-BHyS8rYq.js")))[s];t(i)})()},[s]),n}function zs(){const{authToken:s}=e.useSemaphorContext(),{data:n,isLoading:t,isFetching:r,isError:o}=e.useQuery({queryKey:["plugins",s==null?void 0:s.accessToken],queryFn:()=>e.getPlugins(s==null?void 0:s.accessToken)});return{data:n,isLoading:t,isFetching:r,isError:o}}function mt({onChartTypeChange:s}){const[n,t]=S.useState([]),{data:r}=zs();return S.useEffect(()=>{(async()=>{var i;if(r){const l=(await Promise.all((i=r==null?void 0:r.plugins)==null?void 0:i.map(async c=>(await e.loadManifest(c.value)).visuals.map(f=>({name:f.name,icon:f.icon,url:c.value}))))).flat();t(l)}})()},[r]),n.length===0?null:e.jsxRuntimeExports.jsxs(e.jsxRuntimeExports.Fragment,{children:[e.jsxRuntimeExports.jsx(e.Separator,{className:"my-2"}),e.jsxRuntimeExports.jsx("div",{className:"grid grid-cols-4 place-items-center",children:n.map((o,i)=>e.jsxRuntimeExports.jsx(pt,{text:o.name,onClick:()=>s("custom",o),icon:o.icon},o.url+o.name+i))})]})}const pt=({text:s,icon:n,onClick:t})=>{const r=As(n||""),o=s.charAt(0).toUpperCase();return e.jsxRuntimeExports.jsx(e.Button,{onClick:t,title:s,variant:"ghost",children:r?e.jsxRuntimeExports.jsx(r,{className:"h-4 w-4"}):o})};function jt(){var x,f;const[s,n]=S.useState(!1),t=e.useEditorStore(E=>E.card),r=t.type,{setCardType:o,setCardPreferences:i,setChartOrientation:u}=e.useEditorStore(E=>E.actions),{setCardCustomCfg:l,setCustomCardPreferences:c}=e.useEditorActions();function p(E,d){l(null),i({}),o(E),d&&c({type:"component",visualType:"single",url:d.url,componentName:d.name,icon:d.icon}),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(ht,{className:"h-4 w-4",chartType:r,customIcon:(x=t.customCardPreferences)==null?void 0:x.icon,componentName:(f=t.customCardPreferences)==null?void 0:f.componentName})})}),e.jsxRuntimeExports.jsxs(e.PopoverContent,{className:"w-50",children:[e.jsxRuntimeExports.jsxs("div",{className:"grid grid-cols-4 place-items-center",children:[e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>p("bar"),className:"font-normal",variant:"ghost",children:e.jsxRuntimeExports.jsx(Ne,{className:"size-5"})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>p("line"),variant:"ghost",children:e.jsxRuntimeExports.jsx(we,{className:"size-5"})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>p("stackedBar"),variant:"ghost",children:e.jsxRuntimeExports.jsx(Ds,{className:"size-5",strokeWidth:0})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>p("stackedLine"),variant:"ghost",children:e.jsxRuntimeExports.jsx(Is,{className:"size-5",strokeWidth:0})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>p("scatter"),variant:"ghost",children:e.jsxRuntimeExports.jsx(Oe,{className:"size-5"})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>p("bubble"),variant:"ghost",children:e.jsxRuntimeExports.jsx(ks,{className:"size-4"})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>p("pie"),variant:"ghost",children:e.jsxRuntimeExports.jsx(ze,{className:"size-5"})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>p("doughnut"),variant:"ghost",children:e.jsxRuntimeExports.jsx(Ns,{className:"size-5",strokeWidth:1})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>p("radar"),variant:"ghost",children:e.jsxRuntimeExports.jsx(Cs,{className:"size-5 font-extralight",strokeWidth:.5})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>p("polarArea"),variant:"ghost",children:e.jsxRuntimeExports.jsx(ws,{className:"size-5"})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>p("pyramid"),variant:"ghost",children:e.jsxRuntimeExports.jsx(Ts,{className:"size-5"})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>p("range"),variant:"ghost",children:e.jsxRuntimeExports.jsx(Ae,{className:"size-5"})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>p("table"),variant:"ghost",children:e.jsxRuntimeExports.jsx(e.Table,{className:"size-5"})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>p("kpi"),variant:"ghost",children:e.jsxRuntimeExports.jsx(Ls,{className:"size-6"})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>p("text"),variant:"ghost",children:e.jsxRuntimeExports.jsx(ke,{className:"size-4"})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>p("map"),variant:"ghost",children:e.jsxRuntimeExports.jsx(Me,{className:"size-4"})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>p("custom"),variant:"ghost",children:e.jsxRuntimeExports.jsx(Ve,{className:"size-4"})})]}),e.jsxRuntimeExports.jsx(mt,{onChartTypeChange:p})]})]})}function ht({chartType:s,className:n,customIcon:t,componentName:r}){const o=As(t||"");switch(s){case"bar":return e.jsxRuntimeExports.jsx(Ne,{className:n});case"line":return e.jsxRuntimeExports.jsx(we,{className:n});case"pie":return e.jsxRuntimeExports.jsx(ze,{className:n});case"radar":return e.jsxRuntimeExports.jsx(Cs,{className:n});case"scatter":return e.jsxRuntimeExports.jsx(Oe,{className:n});case"bubble":return e.jsxRuntimeExports.jsx(ks,{className:n});case"doughnut":return e.jsxRuntimeExports.jsx(Ns,{className:n});case"stackedBar":return e.jsxRuntimeExports.jsx(Ds,{className:"size-4 text-foreground/70"});case"stackedLine":return e.jsxRuntimeExports.jsx(Is,{className:"size-4 text-foreground/70"});case"polarArea":return e.jsxRuntimeExports.jsx(ws,{className:n});case"pyramid":return e.jsxRuntimeExports.jsx(Ts,{className:n});case"range":return e.jsxRuntimeExports.jsx(Ae,{className:n});case"kpi":return e.jsxRuntimeExports.jsx(Ls,{className:n});case"text":return e.jsxRuntimeExports.jsx(ke,{className:n});case"map":return e.jsxRuntimeExports.jsx(Me,{className:n});case"custom":return t&&o?e.jsxRuntimeExports.jsx(o,{className:n}):r?r==null?void 0:r.charAt(0).toUpperCase():e.jsxRuntimeExports.jsx(Ve,{className:n});default:return e.jsxRuntimeExports.jsx(e.Table,{className:n})}}function Et(){var n;const s=e.useEditorStore(t=>t.card);return(n=s.customCardPreferences)==null||n.showCardHeader,e.useEditorActions(),e.jsxRuntimeExports.jsxs(e.DropdownMenu,{children:[e.jsxRuntimeExports.jsx(e.DropdownMenuTrigger,{asChild:!0,children:e.jsxRuntimeExports.jsx(Fe,{className:"size-4 cursor-pointer text-muted-foreground/70 transition-colors hover:text-muted-foreground"})}),e.jsxRuntimeExports.jsx(e.DropdownMenuContent,{align:"start",className:"w-40 text-muted-foreground",children:e.jsxRuntimeExports.jsxs(e.DropdownMenuItem,{onClick:()=>{navigator.clipboard.writeText(s.id),e.ce.success("Card ID copied to clipboard")},className:"cursor-pointer space-x-2",children:[e.jsxRuntimeExports.jsx(e.IdCard,{className:"size-5"}),e.jsxRuntimeExports.jsx("span",{children:"Copy Card ID"})]})})]})}function $e(){const s=e.useEditorStore(m=>m.frame),n=e.useEditorStore(m=>m.card),t=e.useEditorStore(m=>m.isShowingVisual),r=e.useEditorStore(m=>m.isSqlRunning),o=e.useEditorStore(m=>m.queryError),i=e.useEditorStore(m=>m.pythonStdOut),u=e.useEditorStore(m=>m.actions.setRunSql);e.useEditorStore(m=>m.onSave),e.useEditorStore(m=>m.onClose),e.useEditorStore(m=>m.actions.setCardSql),e.useEditorStore(m=>m.actions.setCardType),e.useEditorStore(m=>m.actions.setSqlGen);const{setFrame:l,setCard:c,updateCardInFrame:p}=e.useEditorActions(),{data:x,isLoading:f,isFetching:E}=e.useDashboardCardQuery(n);if(!n)return e.jsxRuntimeExports.jsx(e.jsxRuntimeExports.Fragment,{children:"No Active Card"});function d(){const m={connectionId:n.connectionId,id:e.v4(),title:"Title",description:"Description",preferences:{onClickFilter:[{columnIndex:0,expression:""}]},type:"bar",sql:"",data:[]};h(m)}function h(m){const R={...s,cards:[...s.cards,m],activeCardId:m.id};l(R),c(m)}function b(){const m={...n,id:e.v4(),title:`${n.title} Copy`,tabTitle:`${n.tabTitle||n.title} Copy`};h(m)}function w(m){const R=s.cards.filter(v=>v.id!==m),j=R[0],N={...s,cards:R,activeCardId:j.id};l(N),c(j)}function g(m){const R={...s,cards:s.cards.map(N=>N.id===n.id?n:N),activeCardId:m};l(R);const j=R.cards.find(N=>N.id===m);j.sql&&u(!0),c(j)}const L=(m,R)=>{console.log("handleDragStart",R),m.dataTransfer.setData("tabIndex",R.toString())},k=m=>{m.preventDefault()},z=(m,R)=>{const j=m.dataTransfer.getData("tabIndex");if(j===R.toString())return;const N=Array.from(s.cards),[v]=N.splice(parseInt(j),1);N.splice(R,0,v),l({...s,cards:N})};function y(m,R){return m.cards.length===1&&(R.displayTab===!0||R.displayTab===void 0)||m.activeCardId!==R.id&&(R.displayTab===!0||R.displayTab===void 0)?null:e.jsxRuntimeExports.jsx("div",{onClick:()=>{const j=R.displayTab===void 0?!1:!R.displayTab;c({...R,displayTab:j}),p({...R,displayTab:j})},children:R.displayTab===!0||R.displayTab===void 0?e.jsxRuntimeExports.jsx(es,{className:"mr-2 size-3.5 text-muted-foreground hover:text-foreground"}):e.jsxRuntimeExports.jsx(Ze,{className:"mr-2 size-3.5 text-muted-foreground hover:text-foreground"})})}function I(){return e.jsxRuntimeExports.jsxs(e.Tabs,{onValueChange:g,value:s.activeCardId,className:"flex grow flex-col",children:[s.cards.map(m=>e.jsxRuntimeExports.jsx(e.TabsContent,{className:"mt-0 grow",value:m.id,children:A()},m.id)),e.jsxRuntimeExports.jsx(e.TabsList,{className:"group mx-6 justify-between",children:e.jsxRuntimeExports.jsxs("div",{className:"flex items-center",children:[s.cards.map((m,R)=>e.jsxRuntimeExports.jsx(e.Editable,{text:m.tabTitle||m.title,onSave:j=>{c({...n,tabTitle:j}),p({...n,tabTitle:j})},children:e.jsxRuntimeExports.jsxs(e.TabsTrigger,{draggable:!0,onDragStart:j=>L(j,R),onDragOver:k,onDrop:j=>z(j,R),className:"",value:m.id,children:[y(s,m),m.tabTitle||m.title,s.activeCardId===m.id&&s.cards.length>1&&e.jsxRuntimeExports.jsx(e.X,{className:"ml-2 size-3.5 text-muted-foreground hover:text-foreground",onClick:()=>w(m.id)})]})},m.id)),e.jsxRuntimeExports.jsx(e.Button,{className:"ml-1 h-8 px-2 hover:bg-muted-foreground/50",variant:"outline",onClick:d,children:e.jsxRuntimeExports.jsx(e.Plus,{className:"h-4 w-4"})}),e.jsxRuntimeExports.jsx(e.Button,{className:"invisible ml-1 h-8 px-2 hover:bg-muted-foreground/50 group-hover:visible",variant:"outline",onClick:b,children:e.jsxRuntimeExports.jsx(We,{className:"h-4 w-4"})})]})})]})}function A(){return n.type==="kpi"?e.jsxRuntimeExports.jsx("div",{className:"flex h-full items-center justify-center",children:e.jsxRuntimeExports.jsx("div",{className:"w-1/2 rounded-md border",children:e.jsxRuntimeExports.jsx(e.KPICard,{card:n,data:x==null?void 0:x.records})})}):n.type==="text"?e.jsxRuntimeExports.jsx("div",{className:"flex h-full items-center justify-center",children:e.jsxRuntimeExports.jsx("div",{className:"w-1/2 rounded-md border",children:e.jsxRuntimeExports.jsx(e.ScrollArea,{className:"mx-3 my-6 h-[300px] overflow-y-auto break-words px-3",children:e.jsxRuntimeExports.jsx(e.TextCard,{isLoading:r,card:n,data:x==null?void 0:x.records})})})}):e.jsxRuntimeExports.jsx(e.ErrorBoundary,{FallbackComponent:e.FallbackEditorCard,children:e.jsxRuntimeExports.jsx(vs,{className:"grow border-none shadow-none"})})}return e.jsxRuntimeExports.jsxs("div",{className:"relative flex h-full flex-col py-3",children:[(f||E)&&e.jsxRuntimeExports.jsx(oe,{className:"absolute bottom-0 left-0 right-0 top-0 z-50 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(jt,{}),!["table","custom"].includes(n.type)&&e.jsxRuntimeExports.jsx(dt,{}),e.jsxRuntimeExports.jsx(Et,{})]}),e.jsxRuntimeExports.jsx(gt,{})]}),t?I():e.jsxRuntimeExports.jsxs(e.ResizablePanelGroup,{className:"px-6",direction:"horizontal",children:[i&&e.jsxRuntimeExports.jsxs(e.jsxRuntimeExports.Fragment,{children:[e.jsxRuntimeExports.jsx(e.ResizablePanel,{id:"1",order:1,defaultSize:30,minSize:10,className:"relative flex h-full min-h-0 w-full flex-1 basis-0",children:i&&e.jsxRuntimeExports.jsx(ft,{})}),e.jsxRuntimeExports.jsx(e.ResizableHandle,{})]}),e.jsxRuntimeExports.jsx(e.ResizablePanel,{id:"2",order:2,minSize:10,className:"relative flex h-full min-h-0 w-full flex-1 basis-0",children:e.jsxRuntimeExports.jsxs(e.ScrollArea,{className:"relative flex h-full min-h-0 w-full flex-1 basis-0",children:[(x==null?void 0:x.records)&&(x==null?void 0:x.records.length)>0&&e.jsxRuntimeExports.jsx(xt,{data:(x==null?void 0:x.records)||[]}),o&&e.jsxRuntimeExports.jsx("span",{className:"font-mono text-xs",children:o}),e.jsxRuntimeExports.jsx(e.ScrollBar,{orientation:"horizontal"})]})})]})]})}function ft(){const s=e.useEditorStore(t=>t.pythonStdOut);if(!s)return null;const n=s.replace(/\n/g,"<br>");return e.jsxRuntimeExports.jsxs("div",{className:"relative flex w-full flex-col border-r",children:[e.jsxRuntimeExports.jsx("div",{className:"sticky top-0 flex max-h-11 min-h-11 grow items-center border-b bg-muted px-3 font-mono text-xs font-semibold text-foreground/70",children:"Python Output"}),e.jsxRuntimeExports.jsxs(e.ScrollArea,{className:"overflow-y-auto px-2 pt-1 font-mono text-xs text-foreground/90",children:[e.jsxRuntimeExports.jsx("div",{dangerouslySetInnerHTML:{__html:n}}),e.jsxRuntimeExports.jsx(e.ScrollBar,{orientation:"horizontal"})]})]})}function gt(){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 Rt({options:s,value:n,onValueChange:t}){return e.jsxRuntimeExports.jsx(e.RadioGroup,{value:n,onValueChange:t,className:"flex gap-4",defaultValue:s[0].value,children:s.map(r=>e.jsxRuntimeExports.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsxRuntimeExports.jsx(e.RadioGroupItem,{value:r.value,id:r.value}),e.jsxRuntimeExports.jsx("label",{className:"text-sm",htmlFor:r.value,children:r.label})]},r.value))})}function Y({label:s,options:n,value:t,onValueChange:r,className:o}){return e.jsxRuntimeExports.jsxs(e.Select,{value:t,onValueChange:r,children:[e.jsxRuntimeExports.jsx(e.SelectTrigger,{className:e.cn("w-full focus:ring-0 focus:ring-offset-0",o),children:e.jsxRuntimeExports.jsx(e.SelectValue,{placeholder:s})}),e.jsxRuntimeExports.jsx(e.SelectContent,{children:e.jsxRuntimeExports.jsxs(e.SelectGroup,{children:[e.jsxRuntimeExports.jsx(e.SelectLabel,{children:s}),n.map(i=>e.jsxRuntimeExports.jsx(e.SelectItem,{value:i.value,children:i.label},i.value))]})})]})}function je({children:s,summary:n,open:t,className:r}){return e.jsxRuntimeExports.jsxs("details",{open:t,className:e.cn("space-y-4 [&_summary>svg]:open:-rotate-180",r),children:[e.jsxRuntimeExports.jsxs("summary",{className:"flex cursor-pointer list-none items-center justify-between gap-4",children:[e.jsxRuntimeExports.jsx(e.Label,{children:n}),e.jsxRuntimeExports.jsx(e.ChevronUp,{className:"h-4 w-4"})]}),e.jsxRuntimeExports.jsx("div",{className:"transition-all ease-in-out",children:s})]})}function bt(){var b,w;const s=e.useEditorStore(g=>g.card.customCardPreferences),{data:n}=zs(),t=(n==null?void 0:n.plugins)||[],r=e.useEditorStore(g=>g.card),o=e.useEditorStore(g=>g.frame),i=(s==null?void 0:s.visualType)||"single",{setCustomCardPreferences:u}=e.useEditorActions(),{components:l,manifest:c}=e.useCustomVisual((s==null?void 0:s.url)||""),p=(b=c==null?void 0:c.visuals)==null?void 0:b.find(g=>g.name===(s==null?void 0:s.componentName));function x(g,L){if(!s)return;const z={...(s==null?void 0:s.dataInputCardIds)||{},[g]:{cardId:L,hookRef:null}};u({...s,dataInputCardIds:z})}function f(g){var k,z;const L=(k=o==null?void 0:o.cards)==null?void 0:k.filter(y=>{var I;return((I=y==null?void 0:y.customCardPreferences)==null?void 0:I.visualType)!=="multiple"}).map(y=>({value:y.id,label:y.tabTitle||y.title}));return e.jsxRuntimeExports.jsx("div",{className:"space-y-2",children:(z=g==null?void 0:g.dataInputs)==null?void 0:z.map((y,I)=>{var A,m;return e.jsxRuntimeExports.jsxs("div",{className:"grid grid-cols-10 gap-2",children:[e.jsxRuntimeExports.jsx("div",{className:"col-span-4 flex items-center",children:y}),e.jsxRuntimeExports.jsx(Y,{className:"col-span-6 h-8 w-full justify-between",label:"",options:L||[],value:((m=(A=s==null?void 0:s.dataInputCardIds)==null?void 0:A[I])==null?void 0:m.cardId)||"",onValueChange:R=>x(I,R)})]},I+Math.random())})})}function E(g,L,k=[]){var z,y;return s?g==="input"?e.jsxRuntimeExports.jsx(e.Input,{className:`h-8 w-full ${e.removeRing}`,value:((z=s==null?void 0:s.settings)==null?void 0:z[L])||"",onChange:I=>{u({...s,settings:{...s==null?void 0:s.settings,[L]:I.target.value}})}},L):g==="select"?e.jsxRuntimeExports.jsx(Y,{className:"h-8 w-full",label:"",options:k,value:((y=s==null?void 0:s.settings)==null?void 0:y[L])||"",onValueChange:I=>{u({...s,settings:{...s==null?void 0:s.settings,[L]:I}})}}):null:null}function d(g){const L=Object.entries((g==null?void 0:g.settings)||{});return e.jsxRuntimeExports.jsx("div",{className:"space-y-3",children:L.map(([k,z])=>e.jsxRuntimeExports.jsxs("div",{className:"space-y-2",children:[e.jsxRuntimeExports.jsx(e.Label,{children:z.title}),E(z.ui,k,z.options)]},k))})}function h(g){s&&u({...s,visualType:g,componentName:""})}return e.jsxRuntimeExports.jsxs("div",{className:"p-6",children:[e.jsxRuntimeExports.jsx(je,{summary:"Plugin Settings",children:e.jsxRuntimeExports.jsx("div",{className:"space-y-4 text-sm",children:e.jsxRuntimeExports.jsxs("div",{className:"space-y-4 text-sm",children:[e.jsxRuntimeExports.jsx("div",{className:"space-y-2",children:e.jsxRuntimeExports.jsx("div",{className:"px-2",children:e.jsxRuntimeExports.jsx(Y,{className:"h-8 w-full",label:"",options:t,value:(s==null?void 0:s.url)||"",onValueChange:g=>u({...s||{url:"",componentName:""},url:g})})})}),((s==null?void 0:s.type)==="component"||(s==null?void 0:s.type)===void 0)&&e.jsxRuntimeExports.jsx(Rt,{options:[{value:"single",label:"Single Visual"},{value:"multiple",label:"Multi-Visual"}],value:i,onValueChange:h}),((s==null?void 0:s.type)==="component"||(s==null?void 0:s.type)===void 0)&&s&&e.jsxRuntimeExports.jsx(e.jsxRuntimeExports.Fragment,{children:e.jsxRuntimeExports.jsxs("div",{className:"space-y-2",children:[e.jsxRuntimeExports.jsx(e.Label,{children:"Component"}),e.jsxRuntimeExports.jsx("div",{className:"space-y-2 px-2",children:l&&e.jsxRuntimeExports.jsx(Y,{className:"h-8 w-full",label:"",options:(l==null?void 0:l.filter(g=>g.type===i).map(g=>({value:g.name,label:g.name})))||[],value:s.componentName,onValueChange:g=>{console.log("changing value",g),u({...s,componentName:g})}})})]})})]})})}),e.jsxRuntimeExports.jsx(e.Separator,{className:"my-4"}),((w=r==null?void 0:r.customCardPreferences)==null?void 0:w.componentName)&&e.jsxRuntimeExports.jsxs(je,{summary:"Component Settings",children:[p&&p.dataInputs&&e.jsxRuntimeExports.jsxs("div",{className:"space-y-3",children:[e.jsxRuntimeExports.jsx(e.Label,{children:"Input Mapping"}),e.jsxRuntimeExports.jsx("div",{className:"px-2",children:f(p)})]}),p&&p.settings&&e.jsxRuntimeExports.jsx("div",{className:"space-y-3",children:e.jsxRuntimeExports.jsx("div",{className:"px-2",children:d(p)})})]})]})}function ae(){const[s,n]=S.useState([]);e.useEditorStore(x=>x.card.cfg);const t=e.useEditorStore(x=>x.card.preferences),{setCardCfg:r,setFilterOnClickColumnIndex:o,setCardPreferences:i}=e.useEditorStore(x=>x.actions),u=e.useEditorStore(x=>x.queryResultColumns);e.useEditorStore(x=>{var f;return(f=x.card.preferences)==null?void 0:f.filterOnClickColumnIndex}),S.useEffect(()=>{u&&n(new Array(u.length).fill(!1))},[u]);function l(x,f){var E,d;f?t!=null&&t.onClickFilter&&((E=t==null?void 0:t.onClickFilter)==null?void 0:E.length)>0?i({...t,onClickFilter:[...t.onClickFilter,{columnIndex:x,expression:""}]}):i({...t,onClickFilter:[{columnIndex:x,expression:""}]}):(i({...t,onClickFilter:(d=t==null?void 0:t.onClickFilter)==null?void 0:d.filter(h=>h.columnIndex!==x)}),n(h=>{const b=[...h];return b[x]=!1,b}))}function c(x,f){var d;const E=(d=t==null?void 0:t.onClickFilter)==null?void 0:d.map(h=>h.columnIndex===x?{...h,expression:f.target.value}:h);i({...t,onClickFilter:E})}function p(x){var f,E,d,h;if(s!=null&&s[x]||(E=(f=t==null?void 0:t.onClickFilter)==null?void 0:f.find(b=>b.columnIndex===x))!=null&&E.expression)return e.jsxRuntimeExports.jsx(e.Input,{value:(h=(d=t==null?void 0:t.onClickFilter)==null?void 0:d.find(b=>b.columnIndex===x))==null?void 0:h.expression,onChange:b=>c(x,b),type:"text",className:"h-9 w-full font-mono text-xs focus-visible:ring-0 focus-visible:ring-ring focus-visible:ring-offset-0",placeholder:"Expression"})}return e.jsxRuntimeExports.jsxs("div",{className:"space-y-2",children:[e.jsxRuntimeExports.jsx(e.Label,{children:"On Click"}),u==null?void 0:u.map((x,f)=>{var E,d;return e.jsxRuntimeExports.jsx("div",{className:"xbg-red-100 group flex items-center justify-between space-y-2",children:e.jsxRuntimeExports.jsxs("div",{className:"grow",children:[e.jsxRuntimeExports.jsxs("div",{className:"flex items-center space-x-2 py-2",children:[e.jsxRuntimeExports.jsx(e.Checkbox,{checked:!!((E=t==null?void 0:t.onClickFilter)!=null&&E.find(h=>h.columnIndex===f)),onCheckedChange:h=>l(f,h)}),e.jsxRuntimeExports.jsx("label",{className:"text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70",children:x}),e.jsxRuntimeExports.jsx("div",{className:"flex items-center gap-2",children:((d=t==null?void 0:t.onClickFilter)==null?void 0:d.find(h=>h.columnIndex===f))&&e.jsxRuntimeExports.jsx(e.Pencil,{onClick:()=>{n(h=>{const b=[...h];return b[f]=!h[f],b})},className:"invisible size-3 cursor-pointer text-gray-400 group-hover:visible"})})]}),p(f)]})},x)})]})}function Ie(){var u,l,c;const s=e.useEditorStore(p=>p.card.preferences),n=e.useEditorStore(p=>p.card.cfg),{setCardCfg:t,setCardPreferences:r,setChartOrientation:o}=e.useEditorStore(p=>p.actions);(u=n==null?void 0:n.options)!=null&&u.indexAxis;function i(p){o(p)}return e.jsxRuntimeExports.jsxs(e.RadioGroup,{value:((l=s==null?void 0:s.chartOptions)==null?void 0:l.indexAxis)||((c=n==null?void 0:n.options)==null?void 0:c.indexAxis)||"x",onValueChange:i,className:"flex gap-3",defaultValue:"x",children:[e.jsxRuntimeExports.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsxRuntimeExports.jsx(e.RadioGroupItem,{value:"x",id:"r1"}),e.jsxRuntimeExports.jsx("label",{className:"text-sm",htmlFor:"r1",children:"Vertical"})]}),e.jsxRuntimeExports.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsxRuntimeExports.jsx(e.RadioGroupItem,{value:"y",id:"r2"}),e.jsxRuntimeExports.jsx("label",{className:"text-sm",htmlFor:"r2",children:"Horizontal"})]})]})}const ye="focus-visible:ring-0 focus-visible:ring-ring focus-visible:ring-offset-0";function Ue(s,n){var r,o,i;const t=e.getNumberAxis(s,n);return((i=(o=(r=s==null?void 0:s.chartOptions)==null?void 0:r.scales)==null?void 0:o[t])==null?void 0:i.type)||"linear"}function Os(){var H,q,P,C,F,$;const[s,n]=S.useState(!1),t=e.useEditorStore(T=>{var D;return(D=T.card)==null?void 0:D.preferences}),r=e.useEditorStore(T=>{var D;return(D=T.card)==null?void 0:D.cfg}),o=e.getNumberAxis(t,r),[i,u]=S.useState(Ue(t)),[l,c]=S.useState(((P=(q=(H=t==null?void 0:t.chartOptions)==null?void 0:H.scales)==null?void 0:q[o])==null?void 0:P.min)||""),[p,x]=S.useState((($=(F=(C=t==null?void 0:t.chartOptions)==null?void 0:C.scales)==null?void 0:F[o])==null?void 0:$.max)||""),[f,E]=S.useState(l||p?"custom":"auto"),[d,h]=S.useState(""),[b,w]=S.useState(0),[g,L]=S.useState(""),[k,z]=S.useState(""),[y,I]=S.useState(""),A=e.useEditorStore(T=>T.actions.setCardPreferences),{updateCardInFrame:m}=e.useEditorActions(),R=e.useEditorStore(T=>T.card),j=e.useEditorStore(T=>{var D;return(D=T.card)==null?void 0:D.type}),N=["pie","doughnut","polarArea"].includes(j);S.useEffect(()=>{var T,D,U,V,G,Q,le,ne,Z,ee,_,K,W,re;u(Ue(t)),c(((U=(D=(T=t==null?void 0:t.chartOptions)==null?void 0:T.scales)==null?void 0:D[o])==null?void 0:U.min)===0?0:""),x(((Q=(G=(V=t==null?void 0:t.chartOptions)==null?void 0:V.scales)==null?void 0:G[o])==null?void 0:Q.max)||""),h(((ee=(Z=(ne=(le=t==null?void 0:t.chartOptions)==null?void 0:le.scales)==null?void 0:ne[o])==null?void 0:Z.ticks)==null?void 0:ee.stepSize)||""),w(((_=t==null?void 0:t.numberAxisFormat)==null?void 0:_.decimalPlaces)||0),L(((K=t==null?void 0:t.numberAxisFormat)==null?void 0:K.suffix)||""),z(((W=t==null?void 0:t.numberAxisFormat)==null?void 0:W.currency)||""),I(((re=t==null?void 0:t.numberAxisFormat)==null?void 0:re.locale)||"")},[s,t,o]);function v(T,D){return D===""||/^[0-9\b]+$/.test(D)?Number(D):Number(T)}function O(){const T=[...new Set(e.LOCALE_CURRENCY_PAIRS.map(D=>D.currency))];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.jsxs(e.Select,{value:k||"none",onValueChange:D=>z(D==="none"?"":D),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,{children:e.jsxRuntimeExports.jsxs(e.SelectGroup,{children:[e.jsxRuntimeExports.jsx(e.SelectLabel,{children:"Currency"}),e.jsxRuntimeExports.jsx(e.SelectItem,{value:"none",children:"None"}),T.map(D=>e.jsxRuntimeExports.jsx(e.SelectItem,{value:D,children:D},D))]})})]}),e.jsxRuntimeExports.jsxs(e.Select,{value:y,onValueChange:D=>I(D),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,{children:e.jsxRuntimeExports.jsxs(e.SelectGroup,{children:[e.jsxRuntimeExports.jsx(e.SelectLabel,{children:"Locale"}),e.LOCALE_CURRENCY_PAIRS.map(D=>e.jsxRuntimeExports.jsx(e.SelectItem,{value:D.locale,children:D.locale},D.locale))]})})]})]}),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:b,onChange:D=>w(Number(D.target.value)),id:"format",className:`col-span-6 h-8 w-full tracking-wide ${ye}`})]})]})}function M(){return e.jsxRuntimeExports.jsxs(e.jsxRuntimeExports.Fragment,{children:[e.jsxRuntimeExports.jsxs("div",{className:"grid grid-cols-3 items-center gap-2",children:[e.jsxRuntimeExports.jsx(e.Label,{htmlFor:"range",children:"Range"}),e.jsxRuntimeExports.jsx(e.Input,{id:"min",value:l,onChange:T=>c(D=>v(D,T.target.value)),className:`col-span-1 h-8 w-full ${ye}`}),e.jsxRuntimeExports.jsx(e.Input,{value:p,onChange:T=>x(D=>v(D,T.target.value)),id:"max",className:`col-span-1 h-8 w-full ${ye}`})]}),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:d,onChange:T=>h(D=>v(D,T.target.value)),id:"step-size",className:`col-span-1 h-8 w-full ${ye}`})]})]})}function B(){var V;let T={};f==="custom"&&(T={min:l,max:p,ticks:{stepSize:d}});const D={...t||{},chartOptions:{...t==null?void 0:t.chartOptions,scales:{...(V=t==null?void 0:t.chartOptions)==null?void 0:V.scales,[o]:{type:i,...i==="linear"?T:{}}}},numberAxisFormat:{decimalPlaces:b,suffix:g,currency:k,locale:y}};console.log(D),A(D);const U={...R,preferences:D};m(U)}return e.jsxRuntimeExports.jsxs(e.Popover,{onOpenChange:T=>n(T),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:N,value:i,onValueChange:T=>u(T),children:[e.jsxRuntimeExports.jsx(e.SelectTrigger,{className:"col-span-2 h-8 w-full focus:ring-1 focus:ring-offset-0",children:e.jsxRuntimeExports.jsx(e.SelectValue,{})}),e.jsxRuntimeExports.jsx(e.SelectContent,{id:"type",children:e.jsxRuntimeExports.jsxs(e.SelectGroup,{children:[e.jsxRuntimeExports.jsx(e.SelectLabel,{children:"Option"}),e.jsxRuntimeExports.jsx(e.SelectItem,{value:"linear",children:"Linear"}),e.jsxRuntimeExports.jsx(e.SelectItem,{value:"logarithmic",children:"Logarithmic"})]})})]})]}),i=="linear"&&e.jsxRuntimeExports.jsxs("div",{className:"grid grid-cols-3 items-center gap-2 py-1",children:[e.jsxRuntimeExports.jsx(e.Label,{htmlFor:"scale-option",children:"Setup"}),e.jsxRuntimeExports.jsxs(e.RadioGroup,{disabled:N,id:"scale-option",value:f,onValueChange:T=>E(T),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"})]})]})]}),f==="custom"&&i=="linear"&&M(),O(),e.jsxRuntimeExports.jsx(e.SelectSeparator,{}),e.jsxRuntimeExports.jsx("div",{className:"grid grid-cols-3",children:e.jsxRuntimeExports.jsx(e.Button,{onClick:B,variant:"secondary",className:"col-span-1 col-start-3 h-8 w-full",children:"Apply"})})]})]})})]})}function yt({idx:s}){var l;const n=e.useEditorStore(c=>{var p;return(p=c.card)==null?void 0:p.preferences}),t=e.useEditorStore(c=>{var p;return(p=c.card.preferences)==null?void 0:p.datasetOptions}),r=e.useEditorStore(c=>c.actions.setCardPreferences),o=(l=n==null?void 0:n.chartOptions)==null?void 0:l.indexAxis,i=t==null?void 0:t.find(c=>c.idx===s);function u(c,p){(c==="end"||c==="start")&&e.getContrastColor(e.getCanvasBackgroundColor());const x={display:c!=="none",align:c,anchor:c,clamp:!0};if(!i)r({...n,datasetOptions:[...t||[],{idx:p,datalabels:x}]});else{const f={...i};f.datalabels=x;const E=t==null?void 0:t.map(d=>d.idx===p?f:d);r({...n,datasetOptions:E})}}return e.jsxRuntimeExports.jsxs(e.Popover,{children:[e.jsxRuntimeExports.jsx(e.PopoverTrigger,{children:e.jsxRuntimeExports.jsx(hs,{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:()=>u("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:()=>u("start",s),size:"sm",variant:"secondary",className:"h-7 p-1 text-xs font-normal",children:e.jsxRuntimeExports.jsx(os,{className:e.cn("h-4 w-4",{"rotate-90":o==="y"})})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>u("center",s),size:"sm",variant:"secondary",className:"h-7 p-1 text-xs font-normal",children:e.jsxRuntimeExports.jsx(as,{className:e.cn("h-4 w-4",{"rotate-90":o==="y"})})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>u("end",s),size:"sm",variant:"secondary",className:"h-7 p-1 text-xs font-normal",children:e.jsxRuntimeExports.jsx(is,{className:e.cn("h-4 w-4",{"rotate-90":o==="y"})})})]})})]})}function Fs(){const s=e.useEditorStore(p=>p.card),n=e.useEditorStore(p=>{var x,f,E;return(E=(f=(x=p==null?void 0:p.card)==null?void 0:x.preferences)==null?void 0:f.chartOptions)==null?void 0:E.indexAxis}),{data:t}=e.useDashboardCardQuery(s),r=n==="y"?"Y axis":"X axis",o=n==="y"?"X axis":"Y axis",{keys:i,metricKeys:u,dimensionKeys:l}=e.getKeys((t==null?void 0:t.records)||[]);let c=u;if(["stackedBar","stackedLine"].includes(s.type)){const p=e.pivotData({dataArray:(t==null?void 0:t.records)||[],groupKey:l[0],pivotKey:l[1],valueKey:c[0]}),{metricKeys:x}=e.getKeys(p);c=x}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:r}),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:o}),e.jsxRuntimeExports.jsx(Os,{})]}),e.jsxRuntimeExports.jsx("div",{className:"my-1 space-y-1",children:c.map((p,x)=>e.jsxRuntimeExports.jsx(St,{col:p,idx:x},p))})]})]})}function St({col:s,idx:n}){const t=e.useEditorStore(l=>{var c;return(c=l.card)==null?void 0:c.preferences}),r=e.useEditorStore(l=>{var c;return(c=l.card.preferences)==null?void 0:c.datasetOptions}),o=r==null?void 0:r.find(l=>l.idx===n),{setCardPreferences:i}=e.useEditorStore(l=>l.actions);function u(l){if(!o)i({...t,datasetOptions:[...r||[],{idx:n,type:l==="area"?"line":l,fill:l==="area"?"origin":""}]});else{const c={...o};c.type=l==="area"?"line":l,c.fill=l==="area"?"origin":"";const p=r==null?void 0:r.map(x=>x.idx===n?c:x);i({...t,datasetOptions:p})}}return e.jsxRuntimeExports.jsxs("div",{className:"group flex items-center justify-between gap-5 rounded-md bg-muted/70 px-2 py-1 hover:bg-muted",children:[e.jsxRuntimeExports.jsx("p",{children:s}),e.jsxRuntimeExports.jsxs("div",{className:"flex gap-2",children:[e.jsxRuntimeExports.jsx(Ne,{onClick:()=>u("bar"),className:"invisible size-4 cursor-pointer text-muted-foreground hover:text-foreground group-hover:visible"}),e.jsxRuntimeExports.jsx(we,{onClick:()=>u("line"),className:"invisible size-4 cursor-pointer text-muted-foreground hover:text-foreground group-hover:visible"}),e.jsxRuntimeExports.jsx(Je,{onClick:()=>u("area"),className:"invisible size-4 cursor-pointer text-muted-foreground hover:text-foreground group-hover:visible"}),e.jsxRuntimeExports.jsx(yt,{idx:n})]})]})}function Ms(){const s=e.useEditorStore(E=>E.selectedConnectionId),n=e.useEditorStore(E=>E.selectedDatamodelId),t=e.useEditorStore(E=>E.selectedDatabaseName),r=e.useEditorStore(E=>E.selectedSchemaName),o=e.useEditorStore(E=>E.selectedTableName),i=e.useDashboardStore(E=>E.dashboard.filters)||[],u=e.useDashboardStore(E=>E.actions.addFilter),l=e.useDashboardStore(E=>E.actions.removeFilter),{removeFilterValues:c}=e.useDashboardActions(),{modelItems:p,tableName:x}=ie();function f(E,d="dashboard"){var I;const h=e.fmt(E.column_name),b=e.fmt(t||""),w=e.fmt(r||""),g=e.fmt(x);let L=e.getQualifiedTableName(w,g),k=`${L}.${h}`;const z=(I=p==null?void 0:p.find(A=>A.id===n))==null?void 0:I.name;n&&n!=="none"&&(k=`${e.DATAMODEL_NAMESPCACE}.${z}.${h}`,L=`${e.DATAMODEL_NAMESPCACE}.${z}`);const y=i==null?void 0:i.find(A=>A.column===k&&A.table===g&&(A.database===b||A.database===t));if(y)c(y.id),l(y.id);else{const A=e.v4();return x==="api"&&s?(u({location:d,id:A,column:k,title:E.column_name,dataType:E.data_type,table:"api",database:"",connectionId:s,operation:"in",sql:e.getDefaultFilterSql(E.data_type,L,h)}),A):(u({id:A,location:d,column:k,title:E.column_name,dataType:E.data_type,table:o||"",database:t||"",connectionId:s||"",operation:"in",sql:e.getDefaultFilterSql(E.data_type,L,h)}),A)}}return{assignFilter:f}}function de(){const s=e.useDashboardStore(l=>l.dashboard.filters),n=e.useEditorStore(l=>l.frame),{setFrame:t}=e.useEditorActions(),{columns:r}=ie(),{assignFilter:o}=Ms();function i(l){const c=o(l,"frame");t({...n,filterId:c})}const u=s==null?void 0:s.find(l=>l.id===n.filterId);return e.jsxRuntimeExports.jsxs("div",{className:"space-y-3",children:[e.jsxRuntimeExports.jsx(e.Label,{children:"Card Filter"}),e.jsxRuntimeExports.jsx(vt,{onSelect:i,columns:r}),u&&e.jsxRuntimeExports.jsx(e.FilterHeader,{filter:u})]})}function vt({columns:s,onSelect:n}){var u;const[t,r]=Pe.useState(!1),[o,i]=Pe.useState("");return e.jsxRuntimeExports.jsxs(e.Popover,{open:t,onOpenChange:r,children:[e.jsxRuntimeExports.jsx(e.PopoverTrigger,{asChild:!0,children:e.jsxRuntimeExports.jsxs(e.Button,{size:"sm",variant:"outline",role:"combobox","aria-expanded":t,className:"w-full justify-between font-normal",children:[o?(u=s.find(l=>l.column_name===o))==null?void 0:u.column_name:"Select Column...",e.jsxRuntimeExports.jsx(e.CaretSortIcon,{className:"ml-2 h-4 w-4 shrink-0 opacity-50"})]})}),e.jsxRuntimeExports.jsx(e.PopoverContent,{className:"w-[200px] p-0",children:e.jsxRuntimeExports.jsxs(e.Command,{children:[e.jsxRuntimeExports.jsx(e.CommandInput,{placeholder:"Search column",className:"h-9"}),e.jsxRuntimeExports.jsxs(e.CommandList,{children:[e.jsxRuntimeExports.jsx(e.CommandEmpty,{children:"No framework found."}),e.jsxRuntimeExports.jsx(e.CommandGroup,{children:s.map(l=>e.jsxRuntimeExports.jsxs(e.CommandItem,{value:l.column_name,onSelect:c=>{const p=c===o?"":c;i(p),r(!1),p&&n(l)},children:[l.column_name,e.jsxRuntimeExports.jsx(e.CheckIcon,{className:e.cn("ml-auto h-4 w-4",o===l.column_name?"opacity-100":"opacity-0")})]},l.column_name))})]})]})})]})}function Ct({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(Ie,{}),e.jsxRuntimeExports.jsx(Fs,{})]})]}),e.jsxRuntimeExports.jsxs(e.AccordionItem,{value:"item-3",children:[e.jsxRuntimeExports.jsx(e.AccordionTrigger,{children:"Filters"}),e.jsxRuntimeExports.jsxs(e.AccordionContent,{className:"space-y-4 px-2",children:[e.jsxRuntimeExports.jsx(ae,{}),e.jsxRuntimeExports.jsx(de,{})]})]})]})})}function Be(){var o,i,u;const s=e.useEditorStore(l=>l.card.cfg),n=e.useEditorStore(l=>l.actions.setCardCfg),t=e.useEditorStore(l=>l.card.type);function r(l){var x;const c={datalabels:{display:l!=="none",align:l,anchor:l,clamp:!0}},p={...s,options:{...s==null?void 0:s.options,plugins:{...(x=s==null?void 0:s.options)==null?void 0:x.plugins,...c}}};n(p),console.log(l)}return e.jsxRuntimeExports.jsxs("div",{className:"space-y-2",children:[e.jsxRuntimeExports.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxRuntimeExports.jsx("label",{className:"font-medium",children:"Data Labels"}),!["pyramid"].includes(t)&&e.jsxRuntimeExports.jsx(Os,{})]}),e.jsxRuntimeExports.jsxs(e.Select,{value:(u=(i=(o=s==null?void 0:s.options)==null?void 0:o.plugins)==null?void 0:i.datalabels)==null?void 0:u.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 Nt({cardType:s}){function n(t){return e.jsxRuntimeExports.jsxs(e.jsxRuntimeExports.Fragment,{children:[e.jsxRuntimeExports.jsx("div",{className:"rounded bg-muted px-2 py-1 text-xs",children:t==="bubble"?"SELECT label, [group], x-axis, y-axis, radius FROM table":"SELECT label, [group], x-axis, y-axis 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:"group - category"}),e.jsxRuntimeExports.jsx("li",{children:"x-axis - category"}),e.jsxRuntimeExports.jsx("li",{children:"y-axis - category"}),t==="bubble"&&e.jsxRuntimeExports.jsx("li",{children:"radius - number"})]}),e.jsxRuntimeExports.jsxs("div",{children:["See ",e.jsxRuntimeExports.jsx("a",{target:"_blank",onClick:i=>i.stopPropagation(),className:"text-blue-700",href:"https://docs.semaphor.cloud/concepts/visuals#pie-chart",children:"example"})," in the docs."]})]})}return e.jsxRuntimeExports.jsx("div",{className:"space-y-6 px-6 py-2",children:e.jsxRuntimeExports.jsxs(e.Accordion,{defaultValue:["item-2"],type:"multiple",children:[e.jsxRuntimeExports.jsxs(e.AccordionItem,{value:"item-1",children:[e.jsxRuntimeExports.jsx(e.AccordionTrigger,{children:`${e.titleCase(s)} Chart`}),e.jsxRuntimeExports.jsx(e.AccordionContent,{className:"space-y-4 font-mono text-xs",children: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(Be,{})})]}),e.jsxRuntimeExports.jsxs(e.AccordionItem,{value:"item-3",children:[e.jsxRuntimeExports.jsx(e.AccordionTrigger,{children:"Filters"}),e.jsxRuntimeExports.jsxs(e.AccordionContent,{className:"space-y-4 px-2",children:[e.jsxRuntimeExports.jsx(ae,{}),e.jsxRuntimeExports.jsx(de,{})]})]})]})})}const wt={datasets:[{type:"line",label:"Sum_sales",data:[]},{type:"bar",label:"Sum_profit",data:[]}]},kt={datasets:[{fill:"origin",type:"line",label:"Sum_sales",data:[]}]};function It(){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:Dt(s)}),e.jsxRuntimeExports.jsx("section",{className:"",children:["line","bar"].includes(s)&&e.jsxRuntimeExports.jsx(Ie,{})}),!["kpi"].includes(s)&&e.jsxRuntimeExports.jsxs("div",{className:"space-y-4",children:[e.jsxRuntimeExports.jsx(Be,{}),e.jsxRuntimeExports.jsx(ae,{}),e.jsxRuntimeExports.jsx(de,{})]})]})}function Dt(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(wt,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(kt,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 Lt(){var c,p,x,f,E;const s=e.useEditorStore(d=>d.card.preferences),n=e.useEditorStore(d=>d.actions.setCardPreferences),t=e.useEditorStore(d=>d.actions.setNumberFormat);e.useEditorStore(d=>{var h,b;return(b=(h=d.card.preferences)==null?void 0:h.formatNumber)==null?void 0:b.decimalPlaces});const r=e.useEditorStore(d=>{var h,b;return(b=(h=d.card.preferences)==null?void 0:h.formatNumber)==null?void 0:b.locale}),o=e.useEditorStore(d=>{var h,b;return(b=(h=d.card.preferences)==null?void 0:h.formatNumber)==null?void 0:b.currency});e.useEditorStore(d=>d.actions.setFilterOnClickField);const i=e.useEditorStore(d=>{var h,b;return(b=(h=d.card.preferences)==null?void 0:h.formatNumber)==null?void 0:b.colorRanges})||[],u=e.useEditorStore(d=>d.actions.setColorRanges),l=[...new Set(e.LOCALE_CURRENCY_PAIRS.map(d=>d.currency))];return e.jsxRuntimeExports.jsxs("div",{children:[e.jsxRuntimeExports.jsxs("div",{className:"mb-3 flex items-center gap-2",children:[e.jsxRuntimeExports.jsx(e.Checkbox,{checked:!!((c=s==null?void 0:s.formatNumber)!=null&&c.enabled),onCheckedChange:d=>{n({...s,formatNumber:{...s==null?void 0:s.formatNumber,enabled:d}})}}),e.jsxRuntimeExports.jsx(e.Label,{children:"Format Number"})]}),((p=s==null?void 0:s.formatNumber)==null?void 0:p.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||"none",onValueChange:d=>{var h,b,w;return t(((h=s==null?void 0:s.formatNumber)==null?void 0:h.decimalPlaces)||0,((b=s==null?void 0:s.formatNumber)==null?void 0:b.currency)||"",d,((w=s==null?void 0:s.formatNumber)==null?void 0:w.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.jsxRuntimeExports.jsx(e.SelectItem,{value:"none",children:"None"},"none"),e.LOCALE_CURRENCY_PAIRS.map(d=>e.jsxRuntimeExports.jsx(e.SelectItem,{value:d.locale,children:d.locale},d.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:o||"none",onValueChange:d=>{var h,b,w;console.log("currency",d),t(((h=s==null?void 0:s.formatNumber)==null?void 0:h.decimalPlaces)||0,d==="none"?"":d,((b=s==null?void 0:s.formatNumber)==null?void 0:b.locale)||"",((w=s==null?void 0:s.formatNumber)==null?void 0:w.suffix)||"")},children:[e.jsxRuntimeExports.jsx(e.SelectTrigger,{className:"col-span-6 h-8 w-full focus:ring-1 focus:ring-offset-0",children:e.jsxRuntimeExports.jsx(e.SelectValue,{})}),e.jsxRuntimeExports.jsx(e.SelectContent,{children:e.jsxRuntimeExports.jsxs(e.SelectGroup,{children:[e.jsxRuntimeExports.jsx(e.SelectLabel,{children:"Currency"}),e.jsxRuntimeExports.jsx(e.SelectItem,{value:"none",children:"None"},"none"),l.map(d=>e.jsxRuntimeExports.jsx(e.SelectItem,{value:d,children:d},d))]})})]})]})]}),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:((f=(x=s==null?void 0:s.formatNumber)==null?void 0:x.decimalPlaces)==null?void 0:f.toString())||"0",onValueChange:d=>{var h,b,w;return t(Number(d),((h=s==null?void 0:s.formatNumber)==null?void 0:h.currency)||"",((b=s==null?void 0:s.formatNumber)==null?void 0:b.locale)||"",((w=s==null?void 0:s.formatNumber)==null?void 0:w.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(d=>e.jsxRuntimeExports.jsx(e.SelectItem,{value:d,children:d},d))})]})]}),e.jsxRuntimeExports.jsxs("div",{className:"w-full space-y-1",children:[e.jsxRuntimeExports.jsx(e.Label,{children:"Suffix"}),e.jsxRuntimeExports.jsx(e.Input,{value:((E=s==null?void 0:s.formatNumber)==null?void 0:E.suffix)||"",className:"h-8 font-mono text-xs focus-visible:ring-0 focus-visible:ring-ring focus-visible:ring-offset-0",placeholder:"K, M, B, %",onChange:d=>{var h,b,w;return t(((h=s==null?void 0:s.formatNumber)==null?void 0:h.decimalPlaces)||0,((b=s==null?void 0:s.formatNumber)==null?void 0:b.currency)||"",((w=s==null?void 0:s.formatNumber)==null?void 0:w.locale)||"",d.target.value)}})]})]})]})}),e.jsxRuntimeExports.jsx(e.Separator,{className:"my-3"}),e.jsxRuntimeExports.jsx(e.ColorFormat,{colorRanges:i,setColorRanges:u})]})]})}function Tt(){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(Lt,{})}),e.jsxRuntimeExports.jsx("div",{}),e.jsxRuntimeExports.jsx("div",{})]})}const At=[{label:"Mercator",value:"mercator"},{label:"Azimuthal Equidistant",value:"azimuthalEquidistant"},{label:"Gnomonic",value:"gnomonic"},{label:"Orthographic",value:"orthographic"},{label:"Stereographic",value:"stereographic"},{label:"Equal Earth",value:"equalEarth"},{label:"Albers",value:"albers"},{label:"Albers USA",value:"albersUsa"},{label:"Conic Conformal",value:"conicConformal"},{label:"Conic Equal Area",value:"conicEqualArea"},{label:"Conic Equidistant",value:"conicEquidistant"},{label:"Equirectangular",value:"equirectangular"},{label:"Transverse Mercator",value:"transverseMercator"},{label:"Natural Earth 1",value:"naturalEarth1"}],zt=["blues","brBG","buGn","buPu","cividis","cool","cubehelixDefault","gnBu","greens","greys","inferno","magma","orRd","oranges","pRGn","piYG","plasma","puBu","puBuGn","puOr","puRd","purples","rainbow","rdBu","rdGy","rdPu","rdYlBu","rdYlGn","reds","sinebow","spectral","turbo","viridis","warm","ylGn","ylGnBu","ylOrBr","ylOrRd"],Ot=zt.map(s=>({label:s,value:s}));function Ft(){var c,p,x,f,E,d,h,b,w,g,L,k,z,y,I,A,m,R;const s=e.useEditorStore(j=>j.card),n=(p=(c=s==null?void 0:s.preferences)==null?void 0:c.mapVisualOptions)==null?void 0:p.topoJsonUrl,[t,r]=S.useState(((f=(x=s==null?void 0:s.preferences)==null?void 0:x.mapVisualOptions)==null?void 0:f.customTopoJsonUrl)||""),{setCardPreferences:o}=e.useEditorActions(),{data:i}=e.useTopoJson(s),u=Object.keys((i==null?void 0:i.objects)||{}).map(j=>({label:j,value:j}))||[],l=[{label:"US States 10m",value:"https://unpkg.com/us-atlas/states-10m.json"},{label:"Countries 50m",value:"https://unpkg.com/world-atlas/countries-50m.json"},{label:"Custom",value:"custom"}];return e.jsxRuntimeExports.jsxs("div",{className:"p-6",children:[e.jsxRuntimeExports.jsx(je,{summary:"Map Query",children:e.jsxRuntimeExports.jsx("p",{className:"rounded-md bg-muted p-2 font-mono text-xs",children:"SELECT country, value FROM table"})}),e.jsxRuntimeExports.jsx(e.Separator,{className:"my-4"}),e.jsxRuntimeExports.jsx(je,{open:!0,summary:"Settings",children:e.jsxRuntimeExports.jsxs("div",{className:"space-y-3 px-2",children:[e.jsxRuntimeExports.jsx(Y,{className:"h-9",options:l,onValueChange:j=>{console.log("value",j),o({...s.preferences,mapVisualOptions:{topoJsonUrl:j}})},value:n||"",label:"Select Map"}),n==="custom"&&e.jsxRuntimeExports.jsx(e.Input,{onChange:j=>{r(j.target.value)},onBlur:()=>{var j;console.log("onBlur",t),o({...s.preferences,mapVisualOptions:{...(j=s.preferences)==null?void 0:j.mapVisualOptions,customTopoJsonUrl:t}})},value:t,className:`h-9 w-full ${e.removeRing}`,placeholder:"Custom URL"}),i&&e.jsxRuntimeExports.jsxs(e.jsxRuntimeExports.Fragment,{children:[e.jsxRuntimeExports.jsxs("div",{className:"space-y-1",children:[e.jsxRuntimeExports.jsx(e.Label,{children:"Map Object"}),e.jsxRuntimeExports.jsx(Y,{className:"h-9",options:u,value:((d=(E=s.preferences)==null?void 0:E.mapVisualOptions)==null?void 0:d.objectKey)||"",label:"Map Object",onValueChange:j=>{var N;o({...s.preferences,mapVisualOptions:{...(N=s.preferences)==null?void 0:N.mapVisualOptions,objectKey:j}})}})]}),e.jsxRuntimeExports.jsxs("div",{className:"space-y-1",children:[e.jsxRuntimeExports.jsx(e.Label,{children:"Projection"}),e.jsxRuntimeExports.jsx(Y,{className:"h-9",options:At,value:((b=(h=s.preferences)==null?void 0:h.mapVisualOptions)==null?void 0:b.projection)||"",label:"Projection",onValueChange:j=>{var N;o({...s.preferences,mapVisualOptions:{...(N=s.preferences)==null?void 0:N.mapVisualOptions,projection:j}})}})]}),e.jsxRuntimeExports.jsxs("div",{className:"space-y-1",children:[e.jsxRuntimeExports.jsx(e.Label,{children:"Colors"}),e.jsxRuntimeExports.jsx(Y,{className:"h-9",options:Ot,value:((g=(w=s.preferences)==null?void 0:w.mapVisualOptions)==null?void 0:g.colorScale)||"",label:"Select Color Scale",onValueChange:j=>{var N;o({...s.preferences,mapVisualOptions:{...(N=s.preferences)==null?void 0:N.mapVisualOptions,colorScale:j}})}})]})]})]})}),e.jsxRuntimeExports.jsx(e.Separator,{className:"my-4"}),e.jsxRuntimeExports.jsx(je,{className:"",summary:"Scale Options",children:e.jsxRuntimeExports.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxRuntimeExports.jsx(e.Input,{className:`h-9 w-full ${e.removeRing}`,type:"number",step:.1,value:((k=(L=s.preferences)==null?void 0:L.mapVisualOptions)==null?void 0:k.projectionScale)||1,onChange:j=>{var N;o({...s.preferences,mapVisualOptions:{...(N=s.preferences)==null?void 0:N.mapVisualOptions,projectionScale:Number(j.target.value)}})}}),e.jsxRuntimeExports.jsx(e.Label,{children:"X"}),e.jsxRuntimeExports.jsx(e.Input,{className:`h-9 w-full ${e.removeRing}`,type:"number",step:10,value:((I=(y=(z=s.preferences)==null?void 0:z.mapVisualOptions)==null?void 0:y.projectionOffset)==null?void 0:I[0])||0,onChange:j=>{var N,v,O,M;o({...s.preferences,mapVisualOptions:{...(N=s.preferences)==null?void 0:N.mapVisualOptions,projectionOffset:[Number(j.target.value),((M=(O=(v=s.preferences)==null?void 0:v.mapVisualOptions)==null?void 0:O.projectionOffset)==null?void 0:M[1])||0]}})}}),e.jsxRuntimeExports.jsx(e.Label,{children:"Y"}),e.jsxRuntimeExports.jsx(e.Input,{className:`h-9 w-full ${e.removeRing}`,type:"number",step:10,value:((R=(m=(A=s.preferences)==null?void 0:A.mapVisualOptions)==null?void 0:m.projectionOffset)==null?void 0:R[1])||0,onChange:j=>{var N,v,O,M;o({...s.preferences,mapVisualOptions:{...(N=s.preferences)==null?void 0:N.mapVisualOptions,projectionOffset:[((M=(O=(v=s.preferences)==null?void 0:v.mapVisualOptions)==null?void 0:O.projectionOffset)==null?void 0:M[0])||0,Number(j.target.value)]}})}})]})}),e.jsxRuntimeExports.jsx(e.Separator,{className:"my-4"}),e.jsxRuntimeExports.jsx(ae,{})]})}function Mt(){var r;const s=e.useEditorStore(o=>o.card.preferences),{setCardPreferences:n}=e.useEditorStore(o=>o.actions);function t(o){n({...s,textVisualOptions:{...s==null?void 0:s.textVisualOptions,isDynamicText:o==="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 Se({cardType:s,docContent:n,suffix:t="Chart"}){let r="pie-chart";return s==="radar"&&(r="radar-chart"),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:o=>o.stopPropagation(),className:"text-blue-700",href:`https://docs.semaphor.cloud/concepts/visuals#${r}`,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(Ie,{}),s!=="text"&&e.jsxRuntimeExports.jsx(Be,{}),s==="text"&&e.jsxRuntimeExports.jsx(Mt,{})]})]}),!["range","text"].includes(s)&&e.jsxRuntimeExports.jsxs(e.AccordionItem,{value:"item-3",children:[e.jsxRuntimeExports.jsx(e.AccordionTrigger,{children:"Filters"}),e.jsxRuntimeExports.jsxs(e.AccordionContent,{className:"space-y-4 px-2",children:[e.jsxRuntimeExports.jsx(ae,{}),e.jsxRuntimeExports.jsx(de,{})]})]})]})})}function Vt(){const s=e.useEditorStore(r=>{var o,i;return(i=(o=r==null?void 0:r.card)==null?void 0:o.preferences)==null?void 0:i.sortChart}),{setSortChart:n}=e.useEditorActions();function t(){return e.jsxRuntimeExports.jsxs("div",{className:"space-y-2",children:[e.jsxRuntimeExports.jsx(e.Label,{children:"Sort"}),e.jsxRuntimeExports.jsx(Y,{className:"h-8",label:"Sort Chart",options:[{label:"None",value:"none"},{label:"ASC",value:"asc"},{label:"DESC",value:"desc"}],value:s||"none",onValueChange:r=>{n(r)}})]})}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:r=>r.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(Ie,{}),t(),e.jsxRuntimeExports.jsx(Fs,{})]})]}),e.jsxRuntimeExports.jsxs(e.AccordionItem,{value:"item-3",children:[e.jsxRuntimeExports.jsx(e.AccordionTrigger,{children:"Filters"}),e.jsxRuntimeExports.jsxs(e.AccordionContent,{className:"space-y-4 px-2",children:[e.jsxRuntimeExports.jsx(ae,{}),e.jsxRuntimeExports.jsx(de,{})]})]})]})})}function qt({}){const s=e.useEditorStore(r=>{var o;return(o=r.card)==null?void 0:o.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:"Filters"}),e.jsxRuntimeExports.jsxs(e.AccordionContent,{className:"space-y-4 px-2",children:[e.jsxRuntimeExports.jsx(ae,{}),e.jsxRuntimeExports.jsx(de,{})]})]})}),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 Bt=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."]})]}),_t=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."]})]}),Pt=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 Ht(){const s=e.useEditorStore(t=>t.card.type);function n(t){switch(t){case"stackedBar":case"stackedLine":return e.jsxRuntimeExports.jsx(Vt,{});case"pyramid":return e.jsxRuntimeExports.jsx(Se,{docContent:Bt,cardType:t});case"kpi":return e.jsxRuntimeExports.jsx(Tt,{});case"line":case"bar":return e.jsxRuntimeExports.jsx(Ct,{cardType:t});case"range":return e.jsxRuntimeExports.jsx(Se,{docContent:_t,cardType:t});case"pie":case"doughnut":case"polarArea":case"radar":return e.jsxRuntimeExports.jsx(Se,{cardType:t});case"bubble":case"scatter":return e.jsxRuntimeExports.jsx(Nt,{cardType:t});case"table":return e.jsxRuntimeExports.jsx(qt,{cardType:t});case"text":return e.jsxRuntimeExports.jsx(Se,{docContent:Pt,cardType:t,suffix:"Visual"});case"map":return e.jsxRuntimeExports.jsx(Ft,{});case"custom":return e.jsxRuntimeExports.jsx(bt,{});default:return e.jsxRuntimeExports.jsx(It,{})}}return e.jsxRuntimeExports.jsx(e.ScrollArea,{className:"h-full w-full text-sm",children:n(s)})}function Gt(){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(ct,{})}),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(Ht,{})})}),e.jsxRuntimeExports.jsx(e.ResizableHandle,{className:"border"}),e.jsxRuntimeExports.jsx(e.ResizablePanel,{minSize:40,defaultSize:75,maxSize:100,children:e.jsxRuntimeExports.jsx($e,{})})]}):e.jsxRuntimeExports.jsx($e,{})})]})}function $t({authToken:s,onSave:n,onClose:t}){e.useDashboardStore(u=>u.themeStyle);const r=e.useEditorStore(u=>u.actions.setOnSave),o=e.useEditorStore(u=>u.actions.setOnClose),i=e.useDashboardStore(u=>u.actions.setAuthToken);return S.useEffect(()=>{n&&r(n),t&&o(t)},[n,r,t,o]),S.useEffect(()=>{s&&s.accessToken&&i(s)},[s,i]),e.jsxRuntimeExports.jsx(e.ErrorBoundary,{FallbackComponent:e.Fallback,children:e.jsxRuntimeExports.jsxs(e.EditorPanel,{style:{},className:"rounded-none",role:"editor-panel",children:[e.jsxRuntimeExports.jsx(e.EditorAside,{className:"rounded-none border-r-[1.5px]",children:e.jsxRuntimeExports.jsx(bs,{})}),e.jsxRuntimeExports.jsx(e.EditorMain,{children:e.jsxRuntimeExports.jsx(Gt,{})})]})})}function Ut(){e.useDashboardStore(u=>u.selectedCardId);const s=e.useDashboardStore(u=>u.selectedSheetId),{setIsVisualEditing:n}=e.useDashboardStore(u=>u.actions),t=e.useDashboardStore(u=>u.isVisualEditing),r=e.useDashboardStore(u=>u.actions.updateFrame);function o(u){s&&(r(s,u),n(!1))}function i(){n(!1)}return e.jsxRuntimeExports.jsx("div",{role:"editor-container",className:e.cn("flex grow",{"max-h-0 overflow-hidden":!t}),children:e.jsxRuntimeExports.jsx($t,{onSave:o,onClose:i})})}function Qt(){const s=e.useEditorStore(i=>i.selectedDatabaseName),n=e.useEditorStore(i=>i.selectedTableName),t=e.useDashboardStore(i=>i.dashboard.filters)||[],{columns:r}=ie(),{assignFilter:o}=Ms();return e.jsxRuntimeExports.jsx("div",{className:"xbg-red-100 flex-1 basis-0 flex-col overflow-scroll px-3",children:r==null?void 0:r.map(i=>{const u=t==null?void 0:t.find(l=>l.column===e.fmt(i.column_name)&&l.table===n&&l.database===s);return e.jsxRuntimeExports.jsx("div",{onClick:()=>o(i),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":u}),children:e.jsxRuntimeExports.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxRuntimeExports.jsx(Rs,{column:i}),e.jsxRuntimeExports.jsx("span",{children:i.column_name})]})},i.column_name)})})}function Jt(){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(bs,{ColumnsComponent:()=>e.jsxRuntimeExports.jsx(Qt,{})})})]})}function Kt(){const s=e.useDashboardStore(t=>t.showFilters),n=e.useDashboardStore(t=>t.isVisualEditing);return e.jsxRuntimeExports.jsxs("div",{role:"dashboard-plus-main",className:e.cn("",{"max-h-0 overflow-hidden":n,"flex grow":!n}),children:[e.jsxRuntimeExports.jsx(e.DashboardTabs,{}),s&&e.jsxRuntimeExports.jsx("div",{role:"filter-aside-container",className:"flex",children:e.jsxRuntimeExports.jsx(Jt,{})})]})}function Wt(){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 Yt({showControls:s=!1,showFooter:n=!0,...t}){return e.jsxRuntimeExports.jsx(e.ErrorBoundary,{FallbackComponent:e.Fallback,children:e.jsxRuntimeExports.jsxs(e.SemaphorContextProvider,{dashboardProps:t,children:[e.jsxRuntimeExports.jsx(e.Oe,{}),e.jsxRuntimeExports.jsxs(e.UXProvider,{children:[e.jsxRuntimeExports.jsx(Wt,{}),e.jsxRuntimeExports.jsxs(e.DashboardPanel,{...t,children:[s&&e.jsxRuntimeExports.jsx(Qs,{}),e.jsxRuntimeExports.jsx(Ut,{}),e.jsxRuntimeExports.jsx(Kt,{})]})]})]})})}exports.Box=Qe;exports.ChartArea=Je;exports.ChartColumnIncreasing=Ne;exports.ChartLine=we;exports.ChartNoAxesGantt=Ae;exports.ChartPie=ze;exports.ChartScatter=Oe;exports.CircleX=Ke;exports.CopyPlus=We;exports.DashboardPlus=Yt;exports.Database=Ye;exports.EllipsisVertical=Fe;exports.Eraser=Xe;exports.Eye=es;exports.EyeClosed=Ze;exports.Glasses=ss;exports.Hammer=ts;exports.Hash=ns;exports.House=rs;exports.ListEnd=os;exports.ListStart=is;exports.ListX=as;exports.LoaderCircle=oe;exports.Map=Me;exports.MessageSquareMore=ls;exports.Network=cs;exports.Play=xs;exports.Plug2=us;exports.Save=ds;exports.SelectComponent=ue;exports.Shapes=Ve;exports.ShieldQuestion=ms;exports.Sigma=ps;exports.SwatchBook=js;exports.Tag=hs;exports.ToggleLeft=Es;exports.Type=ke;exports.User=fs;exports.cleanCard=gs;exports.getDashbaordStateWithoutData=qe;exports.useEditorAside=ie;
|
|
235
|
+
Visual Query Syntax: ${Xs}`,{data:I,isLoading:A,isFetching:m,isError:R,refetch:j}=e.useQuery({queryKey:["ai-query"],queryFn:()=>e.getRequest("https://semaphor.cloud/api/v1/ai",(c==null?void 0:c.accessToken)||"",{user_content:`userContent: ${z} ${p?y:""}`}),enabled:!1});function N(C){if(C.toLowerCase().includes("bar"))h("bar");else if(C.toLowerCase().includes("line"))h("line");else if(C.toLowerCase().includes("bubble"))h("bubble");else if(C.toLowerCase().includes("scatter"))h("scatter");else if(C.toLowerCase().includes("stacked"))h("stackedBar");else if(C.toLowerCase().includes("pie"))h("pie");else if(C.toLowerCase().includes("donut")||C.toLowerCase().includes("doughnut"))h("doughnut");else if(C.toLowerCase().includes("radar"))h("radar");else return h("bar"),!1;return!0}S.useEffect(()=>{I&&w(C=>[...C,{role:"ai",content:I.response}])},[I]),S.useEffect(()=>{const C=setTimeout(()=>{var F;l.current&&(l.current.scroll({top:l.current.scrollHeight,behavior:"smooth"}),(F=u.current)==null||F.focus())},100);return()=>clearTimeout(C)},[b]);function v(){t&&(w(C=>[...C,{role:"user",content:t}]),N(t)&&x(!0),r(""),j())}S.useEffect(()=>{o&&(v(),i(!1))},[o,i]);const O={fontFamily:"Arial, sans-serif",lineHeight:1.6,fontSize:15,width:"100%"},M={fontFamily:"monospace",fontSize:14,lineHeight:1.6},_={fontFamily:"Arial, sans-serif",lineHeight:1.6,fontSize:15,padding:"2px 0",marginLeft:20,listStyleType:"disc"},H={p:({node:C,...F})=>e.jsxRuntimeExports.jsx("p",{style:O,...F}),code:({node:C,...F})=>e.jsxRuntimeExports.jsx("code",{className:"rounded-sm bg-muted px-2 py-1 text-sm",...F}),pre:({node:C,...F})=>e.jsxRuntimeExports.jsxs("pre",{className:"space-y-2 rounded-sm bg-muted/50 p-3",style:M,children:[e.jsxRuntimeExports.jsx("code",{className:"whitespace-normal text-sm",children:F.children}),e.jsxRuntimeExports.jsxs("div",{className:"flex justify-start gap-2",children:[e.jsxRuntimeExports.jsx(e.Button,{onClick:q,size:"sm",variant:"outline",children:e.jsxRuntimeExports.jsx(e.ClipboardCopyIcon,{})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:$=>{const T=q($);T&&(n(!1),f(T),d(!0))},size:"sm",variant:"outline",children:e.jsxRuntimeExports.jsx(e.PlayIcon,{})})]})]}),li:({node:C,...F})=>e.jsxRuntimeExports.jsx("li",{style:_,...F})};function q(C){const F=C.currentTarget.closest("pre");if(!F)return;const $=F.textContent||F.innerText;return navigator.clipboard.writeText($).then(()=>console.log("Text copied to clipboard")).catch(T=>console.error("Error in copying text: ",T)),$}function P(){return b==null?void 0:b.map((C,F)=>C.role==="user"?e.jsxRuntimeExports.jsxs("div",{className:"flex items-start rounded-md bg-muted p-3 text-sm",children:[e.jsxRuntimeExports.jsx(fs,{className:"mr-2 h-5 w-5"}),e.jsxRuntimeExports.jsx("div",{children:C.content})]},F):C.role==="ai"?e.jsxRuntimeExports.jsx(e.Markdown,{className:"w-full overflow-auto py-1",components:H,children:I==null?void 0:I.response.replace(/DuckDB/gi,"Semaphor")},F):e.jsxRuntimeExports.jsx("div",{},F))}return e.jsxRuntimeExports.jsxs(e.Dialog,{open:s,onOpenChange:n,children:[e.jsxRuntimeExports.jsx(e.DialogTrigger,{asChild:!0,children:e.jsxRuntimeExports.jsx(e.Button,{size:"sm",className:"w-full justify-start border font-normal text-muted-foreground focus-visible:ring-0 focus-visible:ring-offset-0",variant:"secondary",children:"Type your question here..."})}),e.jsxRuntimeExports.jsxs(e.DialogContent,{className:"flex flex-col justify-between overflow-auto sm:max-w-[425px] md:max-h-[625px] md:min-w-[625px]",children:[e.jsxRuntimeExports.jsxs(e.DialogHeader,{children:[e.jsxRuntimeExports.jsx(e.DialogTitle,{children:"Assistant"}),e.jsxRuntimeExports.jsx(e.DialogDescription,{children:"What can I help you with?"})]}),e.jsxRuntimeExports.jsx("div",{ref:l,className:"h-[625px] w-full overflow-auto border-t border-t-muted",children:e.jsxRuntimeExports.jsx("div",{className:"space-y-4 py-2 pr-3",role:"messages",children:P()})}),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:u,onKeyDown:C=>{C.key==="Enter"&&!C.shiftKey&&(C.preventDefault(),r(""),v())},placeholder:"Type your question here...",onFocus:C=>{const F=C.target,$=F.value.length;F.setSelectionRange($,$)},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||m,value:t,onChange:C=>r(C.target.value)})," ",e.jsxRuntimeExports.jsx(e.Button,{className:"h-8",size:"sm",variant:"ghost",onClick:v,children:!A&&!m?e.jsxRuntimeExports.jsx(e.PaperPlaneIcon,{}):e.jsxRuntimeExports.jsx(oe,{className:"mr-2 h-4 w-4 animate-spin text-foreground/50"})})]})})]})]})}var ys={color:void 0,size:void 0,className:void 0,style:void 0,attr:void 0},He=S.createContext&&S.createContext(ys),et=["attr","size","title"];function st(s,n){if(s==null)return{};var t=tt(s,n),r,o;if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(s);for(o=0;o<i.length;o++)r=i[o],!(n.indexOf(r)>=0)&&Object.prototype.propertyIsEnumerable.call(s,r)&&(t[r]=s[r])}return t}function tt(s,n){if(s==null)return{};var t={};for(var r in s)if(Object.prototype.hasOwnProperty.call(s,r)){if(n.indexOf(r)>=0)continue;t[r]=s[r]}return t}function ve(){return ve=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},ve.apply(this,arguments)}function Ge(s,n){var t=Object.keys(s);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(s);n&&(r=r.filter(function(o){return Object.getOwnPropertyDescriptor(s,o).enumerable})),t.push.apply(t,r)}return t}function Ce(s){for(var n=1;n<arguments.length;n++){var t=arguments[n]!=null?arguments[n]:{};n%2?Ge(Object(t),!0).forEach(function(r){nt(s,r,t[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(s,Object.getOwnPropertyDescriptors(t)):Ge(Object(t)).forEach(function(r){Object.defineProperty(s,r,Object.getOwnPropertyDescriptor(t,r))})}return s}function nt(s,n,t){return n=rt(n),n in s?Object.defineProperty(s,n,{value:t,enumerable:!0,configurable:!0,writable:!0}):s[n]=t,s}function rt(s){var n=ot(s,"string");return typeof n=="symbol"?n:n+""}function ot(s,n){if(typeof s!="object"||!s)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 Ss(s){return s&&s.map((n,t)=>S.createElement(n.tag,Ce({key:t},n.attr),Ss(n.child)))}function X(s){return n=>S.createElement(it,ve({attr:Ce({},s.attr)},n),Ss(s.child))}function it(s){var n=t=>{var{attr:r,size:o,title:i}=s,u=st(s,et),l=o||t.size||"1em",c;return t.className&&(c=t.className),s.className&&(c=(c?c+" ":"")+s.className),S.createElement("svg",ve({stroke:"currentColor",fill:"currentColor",strokeWidth:"0"},t.attr,r,u,{className:c,style:Ce(Ce({color:s.color||t.color},t.style),s.style),height:l,width:l,xmlns:"http://www.w3.org/2000/svg"}),i&&S.createElement("title",null,i),s.children)};return He!==void 0?S.createElement(He.Consumer,null,t=>n(t)):n(ys)}function at(s){return X({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 lt({sql:s}){return e.jsxRuntimeExports.jsxs(e.HoverCard,{children:[e.jsxRuntimeExports.jsx(e.HoverCardTrigger,{asChild:!0,children:e.jsxRuntimeExports.jsx(e.Button,{variant:"link",className:"h-5 p-0",children:e.jsxRuntimeExports.jsx(e.Info,{className:"h-4 w-4 text-muted-foreground"})})}),e.jsxRuntimeExports.jsx(e.HoverCardContent,{align:"end",className:"w-full min-w-fit max-w-[700px] p-3 pt-2",children:e.jsxRuntimeExports.jsxs("div",{className:"space-y-2",children:[e.jsxRuntimeExports.jsx(e.Label,{className:"text-xs font-semibold",children:"Resolved Query"}),e.jsxRuntimeExports.jsx("div",{className:"flex grow flex-col space-y-2",children:e.jsxRuntimeExports.jsx(e.ScrollArea,{className:"max-h-[250px] min-h-0 overflow-scroll",children:e.jsxRuntimeExports.jsx("p",{className:"overflow-auto rounded-md bg-muted p-2 font-mono text-xs leading-relaxed",children:s})})})]})})]})}function ct(){const[s,n]=S.useState({queryKey:[],queryData:null}),{theme:t}=e.useTheme(),r=e.useQueryClient(),o=S.useRef(),i=e.Le(),[u,l]=S.useState(!1),[c,p]=S.useState(!1),[x,f]=S.useState(!1),[E,d]=S.useState(""),[h,b]=S.useState(!1),w=e.useDashboardStore(a=>a.selectedSheetId);e.useDashboardStore(a=>a.dashboard.baseQueries);const g=e.useEditorStore(a=>a.card),L=e.useDashboardStore(a=>a.theme),k=e.useEditorStore(a=>a.isShowingVisual);e.useDashboardStore(a=>a.onAcceptChanges);const z=e.useEditorStore(a=>a.selectedConnectionId),y=e.useEditorStore(a=>a.selectedDatabaseName),I=e.useEditorStore(a=>a.selectedDatamodelId),A=e.useEditorStore(a=>a.selectedSchemaName);e.useDashboardStore(a=>a.actions.updateFrameCard);const m=e.useEditorStore(a=>a.selectedTableName),R=e.useEditorStore(a=>a.card.sql),j=e.useEditorStore(a=>a.card.python),N=e.useEditorStore(a=>a.frame),v=e.useDashboardStore(a=>a.dashboard.filters),O=e.useDashboardStore(a=>a.filterValues),M=v==null?void 0:v.filter(a=>a.sheetId===w||!a.sheetId),_=O==null?void 0:O.filter(a=>(M==null?void 0:M.some(J=>J.id===a.filterId))||a.filterId.endsWith(w)),H=e.useEditorStore(a=>a.applyFilters),{setCardCustomCfg:q,setQueryResultColumns:P,setFilterValues:C,setCardSql:F,setCard:$,setCardPython:T,setQueryError:D,setPythonStdOut:U,setCardPreferences:V}=e.useEditorStore(a=>a.actions),G=e.useEditorStore(a=>a.onSave);e.useEditorStore(a=>a.actions.setApplyFilters);const Q=e.useEditorStore(a=>a.onClose),le=e.useEditorStore(a=>a.actions.setSqlGen),ne=e.useEditorStore(a=>a.runSql),Z=e.useEditorStore(a=>a.actions.setRunSql);e.useEditorStore(a=>a.actions.setCardCfg);const ee=e.useEditorStore(a=>a.actions.setIsSqlRunning),{data:B,isLoading:K,isFetching:W,isSuccess:re,isError:ce,error:me,queryKey:pe,refetch:xe}=e.useDashboardCardQuery(g);S.useEffect(()=>{if(B&&(B.rowLimitExceeded&&e.ce.error("Row limit (10,000) exceeded. Refine your query.",{position:"top-center",richColors:!0}),U((B==null?void 0:B.output)||""),B.records.length>0)){const{dimensionKeys:a}=e.getKeys(B.records);P(a)}},[B,P,U]),S.useEffect(()=>{(K||W)&&ee(!0),(ce||re)&&ee(!1),ce?(D(me.message),P([]),U("")):D("")},[K,W,B,U,ce,re,ee,P,D,me]),S.useEffect(()=>{ne&&(xe(),Z(!1))},[ne,xe,Z]);function De(){const a=r.getQueryData(pe);s.queryData||n({queryKey:pe,queryData:a}),r.setQueryData(pe,null),F(""),le({}),q(""),V({})}const he=a=>{o.current=a};function Ee(a,J){if(a.length===0)return"";if(J){const se=a.find(te=>te.id===J);if(se){const te=se.tabTitle;if(te=="All__Header")return a[0].id;if(te&&te.endsWith("__Header")){const Vs=te.split("__")[0],Be=a.find(qs=>qs.tabTitle===Vs);return Be?Be.id:a[0].id}return J}}return a[0].id}function fe(){let a=R;R&&!R.includes("{{")&&(a=Ws(R),F(a));const J={...g,lastSelectedSchema:A,lastSelectedDatamodelId:I,lastSelectedDatabase:y,lastSelectedTable:m,connectionId:z,type:k?g.type:"table",sql:a,customCfg:k?g.customCfg:null},se=N.cards.map(Le=>Le.id===g.id?J:Le),te={...N,cards:se,activeCardId:Ee(se,N.activeCardId)};G==null||G(te)}function ge(){const{queryKey:a,queryData:J}=s;a&&J&&r.setQueryData(a,J),Q==null||Q()}S.useEffect(()=>{if(!i)return;const a=o.current,J=window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light",se=L==="system"?J:L;return i.editor.defineTheme("default",{base:se==="light"?"vs":"vs-dark",inherit:!0,rules:[],colors:{"editor.background":se==="light"?"#ffffff":e.hslStringToHex("240 10% 10%")}}),i.editor.setTheme("default"),a&&i&&a.addCommand(i.KeyMod.Shift|i.KeyCode.Enter,function(){return xe(),!1}),()=>{}},[t,L,i]);function Re(){return e.jsxRuntimeExports.jsxs(e.jsxRuntimeExports.Fragment,{children:[c&&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(e.Label,{className:"ml-6 text-xs font-semibold",children:"Filters"}),_&&c&&e.jsxRuntimeExports.jsx(e.Cross2Icon,{onClick:()=>p(!1),className:"bg-background/50 text-foreground/50 hover:cursor-pointer hover:text-foreground"})]}),e.jsxRuntimeExports.jsx(e.Ft,{theme:"default",onChange:a=>{if(a)try{JSON.parse(a),C(JSON.parse(a))}catch{}},defaultLanguage:"json",className:"mt-1 min-h-[220px]",value:JSON.stringify(_,null,2),options:{readOnly:!0,minimap:{enabled:!1},lineNumbers:"off",glyphMargin:!1,wordWrap:"on",scrollbar:{verticalScrollbarSize:0,horizontalScrollbarSize:0},fontSize:12,renderLineHighlight:"none"}},L)]})}),_&&!c&&e.jsxRuntimeExports.jsx(e.Filter,{onClick:()=>p(!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":H})})]})}function be(){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:u?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:a=>{F(a)},value:R,options:{minimap:{enabled:!1},wordWrap:"on",scrollbar:{verticalScrollbarSize:0,horizontalScrollbarSize:0},fontSize:14,renderLineHighlight:"none"},defaultLanguage:"sql",onMount:he})}),u&&e.jsxRuntimeExports.jsx("code",{className:"absolute right-6 top-3 text-sm text-muted-foreground/70",children:"sql"})]}),u&&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:a=>{T(a&&a.trim()||"")},value:j||e.PYTHON_DEFAULT_CODE,options:{minimap:{enabled:!1},wordWrap:"on",scrollbar:{verticalScrollbarSize:0,horizontalScrollbarSize:0},fontSize:14,renderLineHighlight:"none"},defaultLanguage:"python",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:[be(),Re()]}),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:K||W,onClick:()=>{xe()},className:"shrink-0",size:"sm",variant:"outline",children:[K||W?e.jsxRuntimeExports.jsx(oe,{className:"mr-2 h-4 w-4 animate-spin text-foreground/50"}):e.jsxRuntimeExports.jsx(xs,{className:"mr-2 h-4 w-4"}),"Run"]}),ce&&e.jsxRuntimeExports.jsx(Ys,{error:me.message,setShowAIDialog:f,setTriggerAIRun:b,setUserInputforAI:d}),e.jsxRuntimeExports.jsxs(e.Button,{onClick:De,className:"",size:"sm",variant:"outline",children:[e.jsxRuntimeExports.jsx(Xe,{className:"mr-2 size-4"}),"Clear"]}),e.jsxRuntimeExports.jsx(e.Toggle,{pressed:u,onPressedChange:a=>l(a),className:"",size:"sm",variant:"outline",children:e.jsxRuntimeExports.jsx(at,{className:"size-4 text-foreground/70"})}),e.jsxRuntimeExports.jsx(Zs,{open:x,setOpen:f,userInput:E,triggerAIRun:h,setTriggerAIRun:b,setUserInput:a=>d(a)})]}),e.jsxRuntimeExports.jsxs("div",{className:"flex items-center gap-2",children:[(B==null?void 0:B.sql)&&e.jsxRuntimeExports.jsx(lt,{sql:B.sql}),e.jsxRuntimeExports.jsxs(e.Button,{onClick:ge,className:"w-full",size:"sm",variant:"outline",children:[e.jsxRuntimeExports.jsx(e.Cross2Icon,{className:"mr-2 size-4"}),"Close"]}),e.jsxRuntimeExports.jsxs(e.Button,{onClick:fe,size:"sm",variant:"outline",children:[e.jsxRuntimeExports.jsx(e.Check,{className:"mr-2 size-4 font-bold text-green-600"}),"Accept"]})]})]})]})}function xt({data:s}){var u;const[n,t]=S.useState([]),o=Object.keys(s[0]).map(l=>({accessorKey:l,header:({column:c})=>{const p=c.getIsSorted();return e.jsxRuntimeExports.jsx("div",{className:"flex gap-2",children:e.jsxRuntimeExports.jsxs("div",{className:"flex cursor-pointer items-center",onClick:()=>c.toggleSorting(c.getIsSorted()==="asc"),children:[l,p==="asc"?e.jsxRuntimeExports.jsx(e.TriangleUpIcon,{className:"ml-2 h-5 w-5"}):p==="desc"?e.jsxRuntimeExports.jsx(e.TriangleDownIcon,{className:"ml-2 h-5 w-5"}):null]})})}})),i=e.useReactTable({data:s,columns:o,getCoreRowModel:e.getCoreRowModel(),getPaginationRowModel:e.getPaginationRowModel(),onSortingChange:t,getSortedRowModel:e.getSortedRowModel(),manualPagination:!0,state:{sorting:n}});return e.jsxRuntimeExports.jsx("div",{className:"font-mono text-xs text-foreground/95",children:e.jsxRuntimeExports.jsxs("table",{className:"w-full",children:[e.jsxRuntimeExports.jsx(e.TableHeader,{children:i.getHeaderGroups().map(l=>e.jsxRuntimeExports.jsx(e.TableRow,{children:l.headers.map(c=>e.jsxRuntimeExports.jsx(e.TableHead,{className:"sticky top-0 h-11 bg-muted font-semibold",children:c.isPlaceholder?null:e.flexRender(c.column.columnDef.header,c.getContext())},c.id))},l.id))}),e.jsxRuntimeExports.jsx(e.TableBody,{children:(u=i.getRowModel().rows)!=null&&u.length?i.getRowModel().rows.map(l=>e.jsxRuntimeExports.jsx(e.TableRow,{className:"whitespace-nowrap py-2","data-state":l.getIsSelected()&&"selected",children:l.getVisibleCells().map(c=>e.jsxRuntimeExports.jsx(e.TableCell,{className:"py-3",children:e.flexRender(c.column.columnDef.cell,c.getContext())},c.id))},l.id)):e.jsxRuntimeExports.jsx(e.TableRow,{children:e.jsxRuntimeExports.jsx(e.TableCell,{colSpan:o.length,className:"h-24 text-center",children:"No results."})})})]})})}function ut({card:s}){var g,L,k,z,y,I,A,m,R,j,N;const[n,t]=S.useState(!1),[r,o]=S.useState([]),{authToken:i}=e.useSemaphorContext(),u=e.getTokenParams(i==null?void 0:i.accessToken),l=e.useDashboardStore(v=>v.themeStyle),c={colors:((L=(g=l==null?void 0:l.chart)==null?void 0:g.dataset)==null?void 0:L.backgroundColor)||[]};(k=s.customCardPreferences)!=null&&k.inputData;const{getCard:p}=e.useCustomVisual(((z=s.customCardPreferences)==null?void 0:z.url)||""),x=((y=s.customCardPreferences)==null?void 0:y.visualType)||"single",f=e.useEditorStore(v=>v.frame);e.useEditorActions();const{data:E}=e.useDashboardCardQuery(s),d=S.useCallback((v,O)=>{o(M=>({...M,[v]:O}))},[]);if(!((I=s.customCardPreferences)!=null&&I.componentName))return null;const h=p((A=s.customCardPreferences)==null?void 0:A.componentName);function b(v){t(v)}const w=Object.keys(((m=s.customCardPreferences)==null?void 0:m.dataInputCardIds)||{}).map(v=>{var _,H,q;const O=(H=(_=s.customCardPreferences)==null?void 0:_.dataInputCardIds)==null?void 0:H[v].cardId,M=(q=f==null?void 0:f.cards)==null?void 0:q.find(P=>P.id===O);return M||null});return e.jsxRuntimeExports.jsx("div",{className:"semaphor-custom mb-3 flex grow basis-0 flex-col space-y-2 overflow-y-auto",children:e.jsxRuntimeExports.jsxs(S.Suspense,{fallback:e.jsxRuntimeExports.jsx(e.jsxRuntimeExports.Fragment,{}),children:[h&&x==="single"&&e.jsxRuntimeExports.jsx(h,{params:u,theme:c,settings:(R=s.customCardPreferences)==null?void 0:R.settings,onDataChange:d,data:(E==null?void 0:E.records)||[]}),h&&x==="multiple"&&e.jsxRuntimeExports.jsxs(e.jsxRuntimeExports.Fragment,{children:[Object.keys(((j=s.customCardPreferences)==null?void 0:j.dataInputCardIds)||{}).map(v=>{var _,H,q;const O=(H=(_=s.customCardPreferences)==null?void 0:_.dataInputCardIds)==null?void 0:H[v].cardId,M=(q=f==null?void 0:f.cards)==null?void 0:q.find(P=>P.id===O);if(M)return e.jsxRuntimeExports.jsx(e.MultiInputEmptyRenderer,{onLoadingStatus:b,onDataChange:d,dataInputIndex:v,card:M},M.id+v)}),e.jsxRuntimeExports.jsx("div",{className:"flex flex-col gap-2",children:e.jsxRuntimeExports.jsx(h,{theme:c,onDataChange:d,settings:w.map(v=>{var O;return(O=v==null?void 0:v.customCardPreferences)==null?void 0:O.settings}),data:w.map(v=>v!=null&&v.id?r==null?void 0:r[v.id]:[])})})]})]},(N=s.customCardPreferences)==null?void 0:N.componentName)})}function vs({className:s,...n}){var w;const t=e.useEditorStore(g=>g.card),r=((w=t.customCardPreferences)==null?void 0:w.showCardHeader)??!0,o=e.useEditorStore(g=>g.frame),i=e.useDashboardStore(g=>g.dashboard.filters);e.useEditorStore(g=>g.actions.setRunSql);const{updateFilter:u}=e.useDashboardActions(),l=i==null?void 0:i.find(g=>g.id===o.filterId),{data:c,isLoading:p,isFetching:x}=e.useDashboardCardQuery(t),{setCard:f}=e.useEditorActions(),{data:E}=e.useTopoJson(t);if(!t.id)return null;let d;c!=null&&c.records&&(c==null?void 0:c.records.length)>0&&(d=e.createChartConfig({data:c==null?void 0:c.records,cardType:t.type,cfg:t.cfg,customCfg:t.customCfg,preferences:t.preferences,topoJson:E}));function h(g){return e.jsxRuntimeExports.jsx(ut,{card:g})}function b(){var g;if(c!=null&&c.records&&(c==null?void 0:c.records.length)===0&&!p&&!x)return e.jsxRuntimeExports.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-2",children:[e.jsxRuntimeExports.jsx(e.TreePalm,{className:"size-8 text-muted-foreground"}),e.jsxRuntimeExports.jsx("p",{className:"text-sm text-muted-foreground",children:"No records to display"})]});if(t.type==="custom")return h(t);if(!["table","custom"].includes(t.type)&&d)return e.jsxRuntimeExports.jsx(e.ChartJsVisual,{cfg:d},JSON.stringify(d)+JSON.stringify(t.preferences)+((g=t==null?void 0:t.preferences)==null?void 0:g.customVisualCode));if(t.type==="table"&&(c!=null&&c.records)&&(c==null?void 0:c.records.length)>0)return e.jsxRuntimeExports.jsxs(e.ScrollArea,{className:"relative mb-2 flex h-full min-h-0 w-full flex-1 grow basis-0",children:[e.jsxRuntimeExports.jsx(e.TableVisual,{card:t,data:c==null?void 0:c.records}),e.jsxRuntimeExports.jsx(e.ScrollBar,{orientation:"horizontal"})]})}return e.jsxRuntimeExports.jsxs(e.Card,{role:"editor-visual-card",className:e.cn("relative flex h-full flex-col rounded-none",s),...n,children:[r&&e.jsxRuntimeExports.jsxs(e.CardHeader,{className:"flex flex-row items-start justify-between py-4",children:[e.jsxRuntimeExports.jsxs("div",{children:[e.jsxRuntimeExports.jsx(e.Editable,{text:t.title,onSave:g=>f({...t,title:g}),children:e.jsxRuntimeExports.jsx("div",{className:"flex items-center gap-5",children:e.jsxRuntimeExports.jsx(e.CardTitle,{className:"text-base",children:t.title||"Edit title..."})})},t.title),e.jsxRuntimeExports.jsx(e.Editable,{text:t.description||"",onSave:g=>f({...t,description:g}),children:e.jsxRuntimeExports.jsx(e.CardDescription,{children:t.description||"Edit description..."})},t.description)]}),l&&e.jsxRuntimeExports.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxRuntimeExports.jsx(e.Editable,{className:"my-1",text:l.title||l.column,onSave:g=>u({...l,title:g}),children:e.jsxRuntimeExports.jsx(e.Label,{children:l.title})}),e.jsxRuntimeExports.jsx(e.FilterComponent,{filter:l})]})]}),e.jsxRuntimeExports.jsx(e.CardContent,{className:"flex grow flex-col",children:b()})]})}function dt(){const[s,n]=S.useState(!1),[t,r]=S.useState(""),[o,i]=S.useState(""),[u,l]=S.useState(""),[c,p]=S.useState(""),x=e.useEditorStore(y=>y.card),f=e.useEditorStore(y=>y.card.customCfg),{data:E}=e.useDashboardCardQuery(x),{data:d}=e.useTopoJson(x),{setCardCustomCfg:h,setCustomVisualCode:b}=e.useEditorActions();function w(y){var m,R;const I={...y,data:{...y==null?void 0:y.data,datasets:(R=(m=y==null?void 0:y.data)==null?void 0:m.datasets)==null?void 0:R.map(j=>({...j,data:[]}))}};return JSON.stringify(I,null,1)}function g(){var I,A;if(!(E!=null&&E.records)||(E==null?void 0:E.records.length)===0)return;const y=e.createChartConfig({data:E==null?void 0:E.records,cardType:x.type,cfg:x.cfg,preferences:x.preferences,topoJson:d});y&&(r(JSON.stringify(y,null,1)),(I=x==null?void 0:x.preferences)!=null&&I.customVisualCode&&l((A=x==null?void 0:x.preferences)==null?void 0:A.customVisualCode),f&&i(JSON.stringify(f,null,1)))}function L(){if(u&&b(u),!!o)try{const y=JSON.parse(o);return y?(h(y),p(""),i(""),y):void 0}catch(y){console.log(y),p("Invalid JSON")}}function k(){i(""),h(null)}function z(){let y;if(f){const I=e._.cloneDeep(x.cfg),A=e._.merge(I,f);return y=w(A),y}return t?(y=w(JSON.parse(t)),y):""}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:g,className:` ${f&&"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.jsx("div",{className:"flex items-center gap-2",children:e.jsxRuntimeExports.jsx(e.DialogTitle,{children:"Customize Card"})}),e.jsxRuntimeExports.jsxs(e.DialogDescription,{children:["See the configuration options and documentation",e.jsxRuntimeExports.jsx("a",{target:"_blank",className:"ml-1 text-blue-500 underline",href:"https://www.chartjs.org/docs/latest/samples/bar/vertical.html",children:"here."})]})]}),e.jsxRuntimeExports.jsxs("div",{className:"flex grow gap-2",children:[e.jsxRuntimeExports.jsx(e.ErrorBoundary,{FallbackComponent:e.FallbackEditorCard,children:e.jsxRuntimeExports.jsx(vs,{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:[f&&e.jsxRuntimeExports.jsx(e.CheckIcon,{className:"mr-1 h-5 w-5 text-green-600"}),f?"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:y=>i(y)})}),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:u,onChange:y=>l(y||"")})})]})]}),e.jsxRuntimeExports.jsxs(e.DialogFooter,{className:"flex items-center",children:[e.jsxRuntimeExports.jsx(e.Label,{className:"mr-2 text-red-500",children:c}),e.jsxRuntimeExports.jsx(e.Button,{disabled:!f,onClick:k,variant:"outline",children:"Reset"}),e.jsxRuntimeExports.jsx(e.Button,{onClick:L,variant:"outline",children:"Apply"}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>n(!1),variant:"outline",children:"Close"})]})]})]})}function Cs(s){return X({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 Ns(s){return X({tag:"svg",attr:{viewBox:"0 0 256 256",fill:"currentColor"},child:[{tag:"path",attr:{d:"M128,24a8,8,0,0,0-8,8V88a8,8,0,0,0,8,8,32,32,0,1,1-27.72,16,8,8,0,0,0-2.93-10.93l-48.5-28A8,8,0,0,0,37.92,76,104,104,0,1,0,128,24ZM48.09,91.1,83,111.26A48.09,48.09,0,0,0,80,128c0,1.53.08,3,.22,4.52L41.28,143A88.16,88.16,0,0,1,48.09,91.1Zm-2.67,67.31,39-10.44A48.1,48.1,0,0,0,120,175.32v40.31A88.2,88.2,0,0,1,45.42,158.41ZM136,215.63V175.32a48,48,0,0,0,0-94.65V40.36a88,88,0,0,1,0,175.27Z"},child:[]}]})(s)}function ws(s){return X({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 ks(s){return X({tag:"svg",attr:{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"},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 Is(s){return X({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 Ds(s){return X({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 Ls(s){return X({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 Ts(s){return X({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 As(s){const[n,t]=S.useState(null);return S.useEffect(()=>{s&&(async()=>{const i=(await Promise.resolve().then(()=>require("./lucide-react-CtJJWo6V.js")))[s];t(i)})()},[s]),n}function zs(){const{authToken:s}=e.useSemaphorContext(),{data:n,isLoading:t,isFetching:r,isError:o}=e.useQuery({queryKey:["plugins",s==null?void 0:s.accessToken],queryFn:()=>e.getPlugins(s==null?void 0:s.accessToken)});return{data:n,isLoading:t,isFetching:r,isError:o}}function mt({onChartTypeChange:s}){const[n,t]=S.useState([]),{data:r}=zs();return S.useEffect(()=>{(async()=>{var i;if(r){const l=(await Promise.all((i=r==null?void 0:r.plugins)==null?void 0:i.map(async c=>(await e.loadManifest(c.value)).visuals.map(f=>({name:f.name,icon:f.icon,url:c.value}))))).flat();t(l)}})()},[r]),n.length===0?null:e.jsxRuntimeExports.jsxs(e.jsxRuntimeExports.Fragment,{children:[e.jsxRuntimeExports.jsx(e.Separator,{className:"my-2"}),e.jsxRuntimeExports.jsx("div",{className:"grid grid-cols-4 place-items-center",children:n.map((o,i)=>e.jsxRuntimeExports.jsx(pt,{text:o.name,onClick:()=>s("custom",o),icon:o.icon},o.url+o.name+i))})]})}const pt=({text:s,icon:n,onClick:t})=>{const r=As(n||""),o=s.charAt(0).toUpperCase();return e.jsxRuntimeExports.jsx(e.Button,{onClick:t,title:s,variant:"ghost",children:r?e.jsxRuntimeExports.jsx(r,{className:"h-4 w-4"}):o})};function jt(){var x,f;const[s,n]=S.useState(!1),t=e.useEditorStore(E=>E.card),r=t.type,{setCardType:o,setCardPreferences:i,setChartOrientation:u}=e.useEditorStore(E=>E.actions),{setCardCustomCfg:l,setCustomCardPreferences:c}=e.useEditorActions();function p(E,d){l(null),i({}),o(E),d&&c({type:"component",visualType:"single",url:d.url,componentName:d.name,icon:d.icon}),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(ht,{className:"h-4 w-4",chartType:r,customIcon:(x=t.customCardPreferences)==null?void 0:x.icon,componentName:(f=t.customCardPreferences)==null?void 0:f.componentName})})}),e.jsxRuntimeExports.jsxs(e.PopoverContent,{className:"w-50",children:[e.jsxRuntimeExports.jsxs("div",{className:"grid grid-cols-4 place-items-center",children:[e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>p("bar"),className:"font-normal",variant:"ghost",children:e.jsxRuntimeExports.jsx(Ne,{className:"size-5"})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>p("line"),variant:"ghost",children:e.jsxRuntimeExports.jsx(we,{className:"size-5"})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>p("stackedBar"),variant:"ghost",children:e.jsxRuntimeExports.jsx(Ds,{className:"size-5",strokeWidth:0})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>p("stackedLine"),variant:"ghost",children:e.jsxRuntimeExports.jsx(Is,{className:"size-5",strokeWidth:0})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>p("scatter"),variant:"ghost",children:e.jsxRuntimeExports.jsx(Oe,{className:"size-5"})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>p("bubble"),variant:"ghost",children:e.jsxRuntimeExports.jsx(ks,{className:"size-4"})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>p("pie"),variant:"ghost",children:e.jsxRuntimeExports.jsx(ze,{className:"size-5"})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>p("doughnut"),variant:"ghost",children:e.jsxRuntimeExports.jsx(Ns,{className:"size-5",strokeWidth:1})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>p("radar"),variant:"ghost",children:e.jsxRuntimeExports.jsx(Cs,{className:"size-5 font-extralight",strokeWidth:.5})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>p("polarArea"),variant:"ghost",children:e.jsxRuntimeExports.jsx(ws,{className:"size-5"})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>p("pyramid"),variant:"ghost",children:e.jsxRuntimeExports.jsx(Ts,{className:"size-5"})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>p("range"),variant:"ghost",children:e.jsxRuntimeExports.jsx(Ae,{className:"size-5"})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>p("table"),variant:"ghost",children:e.jsxRuntimeExports.jsx(e.Table,{className:"size-5"})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>p("kpi"),variant:"ghost",children:e.jsxRuntimeExports.jsx(Ls,{className:"size-6"})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>p("text"),variant:"ghost",children:e.jsxRuntimeExports.jsx(ke,{className:"size-4"})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>p("map"),variant:"ghost",children:e.jsxRuntimeExports.jsx(Me,{className:"size-4"})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>p("custom"),variant:"ghost",children:e.jsxRuntimeExports.jsx(Ve,{className:"size-4"})})]}),e.jsxRuntimeExports.jsx(mt,{onChartTypeChange:p})]})]})}function ht({chartType:s,className:n,customIcon:t,componentName:r}){const o=As(t||"");switch(s){case"bar":return e.jsxRuntimeExports.jsx(Ne,{className:n});case"line":return e.jsxRuntimeExports.jsx(we,{className:n});case"pie":return e.jsxRuntimeExports.jsx(ze,{className:n});case"radar":return e.jsxRuntimeExports.jsx(Cs,{className:n});case"scatter":return e.jsxRuntimeExports.jsx(Oe,{className:n});case"bubble":return e.jsxRuntimeExports.jsx(ks,{className:n});case"doughnut":return e.jsxRuntimeExports.jsx(Ns,{className:n});case"stackedBar":return e.jsxRuntimeExports.jsx(Ds,{className:"size-4 text-foreground/70"});case"stackedLine":return e.jsxRuntimeExports.jsx(Is,{className:"size-4 text-foreground/70"});case"polarArea":return e.jsxRuntimeExports.jsx(ws,{className:n});case"pyramid":return e.jsxRuntimeExports.jsx(Ts,{className:n});case"range":return e.jsxRuntimeExports.jsx(Ae,{className:n});case"kpi":return e.jsxRuntimeExports.jsx(Ls,{className:n});case"text":return e.jsxRuntimeExports.jsx(ke,{className:n});case"map":return e.jsxRuntimeExports.jsx(Me,{className:n});case"custom":return t&&o?e.jsxRuntimeExports.jsx(o,{className:n}):r?r==null?void 0:r.charAt(0).toUpperCase():e.jsxRuntimeExports.jsx(Ve,{className:n});default:return e.jsxRuntimeExports.jsx(e.Table,{className:n})}}function Et(){var n;const s=e.useEditorStore(t=>t.card);return(n=s.customCardPreferences)==null||n.showCardHeader,e.useEditorActions(),e.jsxRuntimeExports.jsxs(e.DropdownMenu,{children:[e.jsxRuntimeExports.jsx(e.DropdownMenuTrigger,{asChild:!0,children:e.jsxRuntimeExports.jsx(Fe,{className:"size-4 cursor-pointer text-muted-foreground/70 transition-colors hover:text-muted-foreground"})}),e.jsxRuntimeExports.jsx(e.DropdownMenuContent,{align:"start",className:"w-40 text-muted-foreground",children:e.jsxRuntimeExports.jsxs(e.DropdownMenuItem,{onClick:()=>{navigator.clipboard.writeText(s.id),e.ce.success("Card ID copied to clipboard")},className:"cursor-pointer space-x-2",children:[e.jsxRuntimeExports.jsx(e.IdCard,{className:"size-5"}),e.jsxRuntimeExports.jsx("span",{children:"Copy Card ID"})]})})]})}function $e(){const s=e.useEditorStore(m=>m.frame),n=e.useEditorStore(m=>m.card),t=e.useEditorStore(m=>m.isShowingVisual),r=e.useEditorStore(m=>m.isSqlRunning),o=e.useEditorStore(m=>m.queryError),i=e.useEditorStore(m=>m.pythonStdOut),u=e.useEditorStore(m=>m.actions.setRunSql);e.useEditorStore(m=>m.onSave),e.useEditorStore(m=>m.onClose),e.useEditorStore(m=>m.actions.setCardSql),e.useEditorStore(m=>m.actions.setCardType),e.useEditorStore(m=>m.actions.setSqlGen);const{setFrame:l,setCard:c,updateCardInFrame:p}=e.useEditorActions(),{data:x,isLoading:f,isFetching:E}=e.useDashboardCardQuery(n);if(!n)return e.jsxRuntimeExports.jsx(e.jsxRuntimeExports.Fragment,{children:"No Active Card"});function d(){const m={connectionId:n.connectionId,id:e.v4(),title:"Title",description:"Description",preferences:{onClickFilter:[{columnIndex:0,expression:""}]},type:"bar",sql:"",data:[]};h(m)}function h(m){const R={...s,cards:[...s.cards,m],activeCardId:m.id};l(R),c(m)}function b(){const m={...n,id:e.v4(),title:`${n.title} Copy`,tabTitle:`${n.tabTitle||n.title} Copy`};h(m)}function w(m){const R=s.cards.filter(v=>v.id!==m),j=R[0],N={...s,cards:R,activeCardId:j.id};l(N),c(j)}function g(m){const R={...s,cards:s.cards.map(N=>N.id===n.id?n:N),activeCardId:m};l(R);const j=R.cards.find(N=>N.id===m);j.sql&&u(!0),c(j)}const L=(m,R)=>{console.log("handleDragStart",R),m.dataTransfer.setData("tabIndex",R.toString())},k=m=>{m.preventDefault()},z=(m,R)=>{const j=m.dataTransfer.getData("tabIndex");if(j===R.toString())return;const N=Array.from(s.cards),[v]=N.splice(parseInt(j),1);N.splice(R,0,v),l({...s,cards:N})};function y(m,R){return m.cards.length===1&&(R.displayTab===!0||R.displayTab===void 0)||m.activeCardId!==R.id&&(R.displayTab===!0||R.displayTab===void 0)?null:e.jsxRuntimeExports.jsx("div",{onClick:()=>{const j=R.displayTab===void 0?!1:!R.displayTab;c({...R,displayTab:j}),p({...R,displayTab:j})},children:R.displayTab===!0||R.displayTab===void 0?e.jsxRuntimeExports.jsx(es,{className:"mr-2 size-3.5 text-muted-foreground hover:text-foreground"}):e.jsxRuntimeExports.jsx(Ze,{className:"mr-2 size-3.5 text-muted-foreground hover:text-foreground"})})}function I(){return e.jsxRuntimeExports.jsxs(e.Tabs,{onValueChange:g,value:s.activeCardId,className:"flex grow flex-col",children:[s.cards.map(m=>e.jsxRuntimeExports.jsx(e.TabsContent,{className:"mt-0 grow",value:m.id,children:A()},m.id)),e.jsxRuntimeExports.jsx(e.TabsList,{className:"group mx-6 justify-between",children:e.jsxRuntimeExports.jsxs("div",{className:"flex items-center",children:[s.cards.map((m,R)=>e.jsxRuntimeExports.jsx(e.Editable,{text:m.tabTitle||m.title,onSave:j=>{c({...n,tabTitle:j}),p({...n,tabTitle:j})},children:e.jsxRuntimeExports.jsxs(e.TabsTrigger,{draggable:!0,onDragStart:j=>L(j,R),onDragOver:k,onDrop:j=>z(j,R),className:"",value:m.id,children:[y(s,m),m.tabTitle||m.title,s.activeCardId===m.id&&s.cards.length>1&&e.jsxRuntimeExports.jsx(e.X,{className:"ml-2 size-3.5 text-muted-foreground hover:text-foreground",onClick:()=>w(m.id)})]})},m.id)),e.jsxRuntimeExports.jsx(e.Button,{className:"ml-1 h-8 px-2 hover:bg-muted-foreground/50",variant:"outline",onClick:d,children:e.jsxRuntimeExports.jsx(e.Plus,{className:"h-4 w-4"})}),e.jsxRuntimeExports.jsx(e.Button,{className:"invisible ml-1 h-8 px-2 hover:bg-muted-foreground/50 group-hover:visible",variant:"outline",onClick:b,children:e.jsxRuntimeExports.jsx(We,{className:"h-4 w-4"})})]})})]})}function A(){return n.type==="kpi"?e.jsxRuntimeExports.jsx("div",{className:"flex h-full items-center justify-center",children:e.jsxRuntimeExports.jsx("div",{className:"w-1/2 rounded-md border",children:e.jsxRuntimeExports.jsx(e.KPICard,{card:n,data:x==null?void 0:x.records})})}):n.type==="text"?e.jsxRuntimeExports.jsx("div",{className:"flex h-full items-center justify-center",children:e.jsxRuntimeExports.jsx("div",{className:"w-1/2 rounded-md border",children:e.jsxRuntimeExports.jsx(e.ScrollArea,{className:"mx-3 my-6 h-[300px] overflow-y-auto break-words px-3",children:e.jsxRuntimeExports.jsx(e.TextCard,{isLoading:r,card:n,data:x==null?void 0:x.records})})})}):e.jsxRuntimeExports.jsx(e.ErrorBoundary,{FallbackComponent:e.FallbackEditorCard,children:e.jsxRuntimeExports.jsx(vs,{className:"grow border-none shadow-none"})})}return e.jsxRuntimeExports.jsxs("div",{className:"relative flex h-full flex-col py-3",children:[(f||E)&&e.jsxRuntimeExports.jsx(oe,{className:"absolute bottom-0 left-0 right-0 top-0 z-50 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(jt,{}),!["table","custom"].includes(n.type)&&e.jsxRuntimeExports.jsx(dt,{}),e.jsxRuntimeExports.jsx(Et,{})]}),e.jsxRuntimeExports.jsx(gt,{})]}),t?I():e.jsxRuntimeExports.jsxs(e.ResizablePanelGroup,{className:"px-6",direction:"horizontal",children:[i&&e.jsxRuntimeExports.jsxs(e.jsxRuntimeExports.Fragment,{children:[e.jsxRuntimeExports.jsx(e.ResizablePanel,{id:"1",order:1,defaultSize:30,minSize:10,className:"relative flex h-full min-h-0 w-full flex-1 basis-0",children:i&&e.jsxRuntimeExports.jsx(ft,{})}),e.jsxRuntimeExports.jsx(e.ResizableHandle,{})]}),e.jsxRuntimeExports.jsx(e.ResizablePanel,{id:"2",order:2,minSize:10,className:"relative flex h-full min-h-0 w-full flex-1 basis-0",children:e.jsxRuntimeExports.jsxs(e.ScrollArea,{className:"relative flex h-full min-h-0 w-full flex-1 basis-0",children:[(x==null?void 0:x.records)&&(x==null?void 0:x.records.length)>0&&e.jsxRuntimeExports.jsx(xt,{data:(x==null?void 0:x.records)||[]}),o&&e.jsxRuntimeExports.jsx("span",{className:"font-mono text-xs",children:o}),e.jsxRuntimeExports.jsx(e.ScrollBar,{orientation:"horizontal"})]})})]})]})}function ft(){const s=e.useEditorStore(t=>t.pythonStdOut);if(!s)return null;const n=s.replace(/\n/g,"<br>");return e.jsxRuntimeExports.jsxs("div",{className:"relative flex w-full flex-col border-r",children:[e.jsxRuntimeExports.jsx("div",{className:"sticky top-0 flex max-h-11 min-h-11 grow items-center border-b bg-muted px-3 font-mono text-xs font-semibold text-foreground/70",children:"Python Output"}),e.jsxRuntimeExports.jsxs(e.ScrollArea,{className:"overflow-y-auto px-2 pt-1 font-mono text-xs text-foreground/90",children:[e.jsxRuntimeExports.jsx("div",{dangerouslySetInnerHTML:{__html:n}}),e.jsxRuntimeExports.jsx(e.ScrollBar,{orientation:"horizontal"})]})]})}function gt(){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 Rt({options:s,value:n,onValueChange:t}){return e.jsxRuntimeExports.jsx(e.RadioGroup,{value:n,onValueChange:t,className:"flex gap-4",defaultValue:s[0].value,children:s.map(r=>e.jsxRuntimeExports.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsxRuntimeExports.jsx(e.RadioGroupItem,{value:r.value,id:r.value}),e.jsxRuntimeExports.jsx("label",{className:"text-sm",htmlFor:r.value,children:r.label})]},r.value))})}function Y({label:s,options:n,value:t,onValueChange:r,className:o}){return e.jsxRuntimeExports.jsxs(e.Select,{value:t,onValueChange:r,children:[e.jsxRuntimeExports.jsx(e.SelectTrigger,{className:e.cn("w-full focus:ring-0 focus:ring-offset-0",o),children:e.jsxRuntimeExports.jsx(e.SelectValue,{placeholder:s})}),e.jsxRuntimeExports.jsx(e.SelectContent,{children:e.jsxRuntimeExports.jsxs(e.SelectGroup,{children:[e.jsxRuntimeExports.jsx(e.SelectLabel,{children:s}),n.map(i=>e.jsxRuntimeExports.jsx(e.SelectItem,{value:i.value,children:i.label},i.value))]})})]})}function je({children:s,summary:n,open:t,className:r}){return e.jsxRuntimeExports.jsxs("details",{open:t,className:e.cn("space-y-4 [&_summary>svg]:open:-rotate-180",r),children:[e.jsxRuntimeExports.jsxs("summary",{className:"flex cursor-pointer list-none items-center justify-between gap-4",children:[e.jsxRuntimeExports.jsx(e.Label,{children:n}),e.jsxRuntimeExports.jsx(e.ChevronUp,{className:"h-4 w-4"})]}),e.jsxRuntimeExports.jsx("div",{className:"transition-all ease-in-out",children:s})]})}function bt(){var b,w;const s=e.useEditorStore(g=>g.card.customCardPreferences),{data:n}=zs(),t=(n==null?void 0:n.plugins)||[],r=e.useEditorStore(g=>g.card),o=e.useEditorStore(g=>g.frame),i=(s==null?void 0:s.visualType)||"single",{setCustomCardPreferences:u}=e.useEditorActions(),{components:l,manifest:c}=e.useCustomVisual((s==null?void 0:s.url)||""),p=(b=c==null?void 0:c.visuals)==null?void 0:b.find(g=>g.name===(s==null?void 0:s.componentName));function x(g,L){if(!s)return;const z={...(s==null?void 0:s.dataInputCardIds)||{},[g]:{cardId:L,hookRef:null}};u({...s,dataInputCardIds:z})}function f(g){var k,z;const L=(k=o==null?void 0:o.cards)==null?void 0:k.filter(y=>{var I;return((I=y==null?void 0:y.customCardPreferences)==null?void 0:I.visualType)!=="multiple"}).map(y=>({value:y.id,label:y.tabTitle||y.title}));return e.jsxRuntimeExports.jsx("div",{className:"space-y-2",children:(z=g==null?void 0:g.dataInputs)==null?void 0:z.map((y,I)=>{var A,m;return e.jsxRuntimeExports.jsxs("div",{className:"grid grid-cols-10 gap-2",children:[e.jsxRuntimeExports.jsx("div",{className:"col-span-4 flex items-center",children:y}),e.jsxRuntimeExports.jsx(Y,{className:"col-span-6 h-8 w-full justify-between",label:"",options:L||[],value:((m=(A=s==null?void 0:s.dataInputCardIds)==null?void 0:A[I])==null?void 0:m.cardId)||"",onValueChange:R=>x(I,R)})]},I+Math.random())})})}function E(g,L,k=[]){var z,y;return s?g==="input"?e.jsxRuntimeExports.jsx(e.Input,{className:`h-8 w-full ${e.removeRing}`,value:((z=s==null?void 0:s.settings)==null?void 0:z[L])||"",onChange:I=>{u({...s,settings:{...s==null?void 0:s.settings,[L]:I.target.value}})}},L):g==="select"?e.jsxRuntimeExports.jsx(Y,{className:"h-8 w-full",label:"",options:k,value:((y=s==null?void 0:s.settings)==null?void 0:y[L])||"",onValueChange:I=>{u({...s,settings:{...s==null?void 0:s.settings,[L]:I}})}}):null:null}function d(g){const L=Object.entries((g==null?void 0:g.settings)||{});return e.jsxRuntimeExports.jsx("div",{className:"space-y-3",children:L.map(([k,z])=>e.jsxRuntimeExports.jsxs("div",{className:"space-y-2",children:[e.jsxRuntimeExports.jsx(e.Label,{children:z.title}),E(z.ui,k,z.options)]},k))})}function h(g){s&&u({...s,visualType:g,componentName:""})}return e.jsxRuntimeExports.jsxs("div",{className:"p-6",children:[e.jsxRuntimeExports.jsx(je,{summary:"Plugin Settings",children:e.jsxRuntimeExports.jsx("div",{className:"space-y-4 text-sm",children:e.jsxRuntimeExports.jsxs("div",{className:"space-y-4 text-sm",children:[e.jsxRuntimeExports.jsx("div",{className:"space-y-2",children:e.jsxRuntimeExports.jsx("div",{className:"px-2",children:e.jsxRuntimeExports.jsx(Y,{className:"h-8 w-full",label:"",options:t,value:(s==null?void 0:s.url)||"",onValueChange:g=>u({...s||{url:"",componentName:""},url:g})})})}),((s==null?void 0:s.type)==="component"||(s==null?void 0:s.type)===void 0)&&e.jsxRuntimeExports.jsx(Rt,{options:[{value:"single",label:"Single Visual"},{value:"multiple",label:"Multi-Visual"}],value:i,onValueChange:h}),((s==null?void 0:s.type)==="component"||(s==null?void 0:s.type)===void 0)&&s&&e.jsxRuntimeExports.jsx(e.jsxRuntimeExports.Fragment,{children:e.jsxRuntimeExports.jsxs("div",{className:"space-y-2",children:[e.jsxRuntimeExports.jsx(e.Label,{children:"Component"}),e.jsxRuntimeExports.jsx("div",{className:"space-y-2 px-2",children:l&&e.jsxRuntimeExports.jsx(Y,{className:"h-8 w-full",label:"",options:(l==null?void 0:l.filter(g=>g.type===i).map(g=>({value:g.name,label:g.name})))||[],value:s.componentName,onValueChange:g=>{console.log("changing value",g),u({...s,componentName:g})}})})]})})]})})}),e.jsxRuntimeExports.jsx(e.Separator,{className:"my-4"}),((w=r==null?void 0:r.customCardPreferences)==null?void 0:w.componentName)&&e.jsxRuntimeExports.jsxs(je,{summary:"Component Settings",children:[p&&p.dataInputs&&e.jsxRuntimeExports.jsxs("div",{className:"space-y-3",children:[e.jsxRuntimeExports.jsx(e.Label,{children:"Input Mapping"}),e.jsxRuntimeExports.jsx("div",{className:"px-2",children:f(p)})]}),p&&p.settings&&e.jsxRuntimeExports.jsx("div",{className:"space-y-3",children:e.jsxRuntimeExports.jsx("div",{className:"px-2",children:d(p)})})]})]})}function ae(){const[s,n]=S.useState([]);e.useEditorStore(x=>x.card.cfg);const t=e.useEditorStore(x=>x.card.preferences),{setCardCfg:r,setFilterOnClickColumnIndex:o,setCardPreferences:i}=e.useEditorStore(x=>x.actions),u=e.useEditorStore(x=>x.queryResultColumns);e.useEditorStore(x=>{var f;return(f=x.card.preferences)==null?void 0:f.filterOnClickColumnIndex}),S.useEffect(()=>{u&&n(new Array(u.length).fill(!1))},[u]);function l(x,f){var E,d;f?t!=null&&t.onClickFilter&&((E=t==null?void 0:t.onClickFilter)==null?void 0:E.length)>0?i({...t,onClickFilter:[...t.onClickFilter,{columnIndex:x,expression:""}]}):i({...t,onClickFilter:[{columnIndex:x,expression:""}]}):(i({...t,onClickFilter:(d=t==null?void 0:t.onClickFilter)==null?void 0:d.filter(h=>h.columnIndex!==x)}),n(h=>{const b=[...h];return b[x]=!1,b}))}function c(x,f){var d;const E=(d=t==null?void 0:t.onClickFilter)==null?void 0:d.map(h=>h.columnIndex===x?{...h,expression:f.target.value}:h);i({...t,onClickFilter:E})}function p(x){var f,E,d,h;if(s!=null&&s[x]||(E=(f=t==null?void 0:t.onClickFilter)==null?void 0:f.find(b=>b.columnIndex===x))!=null&&E.expression)return e.jsxRuntimeExports.jsx(e.Input,{value:(h=(d=t==null?void 0:t.onClickFilter)==null?void 0:d.find(b=>b.columnIndex===x))==null?void 0:h.expression,onChange:b=>c(x,b),type:"text",className:"h-9 w-full font-mono text-xs focus-visible:ring-0 focus-visible:ring-ring focus-visible:ring-offset-0",placeholder:"Expression"})}return e.jsxRuntimeExports.jsxs("div",{className:"space-y-2",children:[e.jsxRuntimeExports.jsx(e.Label,{children:"On Click"}),u==null?void 0:u.map((x,f)=>{var E,d;return e.jsxRuntimeExports.jsx("div",{className:"xbg-red-100 group flex items-center justify-between space-y-2",children:e.jsxRuntimeExports.jsxs("div",{className:"grow",children:[e.jsxRuntimeExports.jsxs("div",{className:"flex items-center space-x-2 py-2",children:[e.jsxRuntimeExports.jsx(e.Checkbox,{checked:!!((E=t==null?void 0:t.onClickFilter)!=null&&E.find(h=>h.columnIndex===f)),onCheckedChange:h=>l(f,h)}),e.jsxRuntimeExports.jsx("label",{className:"text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70",children:x}),e.jsxRuntimeExports.jsx("div",{className:"flex items-center gap-2",children:((d=t==null?void 0:t.onClickFilter)==null?void 0:d.find(h=>h.columnIndex===f))&&e.jsxRuntimeExports.jsx(e.Pencil,{onClick:()=>{n(h=>{const b=[...h];return b[f]=!h[f],b})},className:"invisible size-3 cursor-pointer text-gray-400 group-hover:visible"})})]}),p(f)]})},x)})]})}function Ie(){var u,l,c;const s=e.useEditorStore(p=>p.card.preferences),n=e.useEditorStore(p=>p.card.cfg),{setCardCfg:t,setCardPreferences:r,setChartOrientation:o}=e.useEditorStore(p=>p.actions);(u=n==null?void 0:n.options)!=null&&u.indexAxis;function i(p){o(p)}return e.jsxRuntimeExports.jsxs(e.RadioGroup,{value:((l=s==null?void 0:s.chartOptions)==null?void 0:l.indexAxis)||((c=n==null?void 0:n.options)==null?void 0:c.indexAxis)||"x",onValueChange:i,className:"flex gap-3",defaultValue:"x",children:[e.jsxRuntimeExports.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsxRuntimeExports.jsx(e.RadioGroupItem,{value:"x",id:"r1"}),e.jsxRuntimeExports.jsx("label",{className:"text-sm",htmlFor:"r1",children:"Vertical"})]}),e.jsxRuntimeExports.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsxRuntimeExports.jsx(e.RadioGroupItem,{value:"y",id:"r2"}),e.jsxRuntimeExports.jsx("label",{className:"text-sm",htmlFor:"r2",children:"Horizontal"})]})]})}const ye="focus-visible:ring-0 focus-visible:ring-ring focus-visible:ring-offset-0";function Ue(s,n){var r,o,i;const t=e.getNumberAxis(s,n);return((i=(o=(r=s==null?void 0:s.chartOptions)==null?void 0:r.scales)==null?void 0:o[t])==null?void 0:i.type)||"linear"}function Os(){var H,q,P,C,F,$;const[s,n]=S.useState(!1),t=e.useEditorStore(T=>{var D;return(D=T.card)==null?void 0:D.preferences}),r=e.useEditorStore(T=>{var D;return(D=T.card)==null?void 0:D.cfg}),o=e.getNumberAxis(t,r),[i,u]=S.useState(Ue(t)),[l,c]=S.useState(((P=(q=(H=t==null?void 0:t.chartOptions)==null?void 0:H.scales)==null?void 0:q[o])==null?void 0:P.min)||""),[p,x]=S.useState((($=(F=(C=t==null?void 0:t.chartOptions)==null?void 0:C.scales)==null?void 0:F[o])==null?void 0:$.max)||""),[f,E]=S.useState(l||p?"custom":"auto"),[d,h]=S.useState(""),[b,w]=S.useState(0),[g,L]=S.useState(""),[k,z]=S.useState(""),[y,I]=S.useState(""),A=e.useEditorStore(T=>T.actions.setCardPreferences),{updateCardInFrame:m}=e.useEditorActions(),R=e.useEditorStore(T=>T.card),j=e.useEditorStore(T=>{var D;return(D=T.card)==null?void 0:D.type}),N=["pie","doughnut","polarArea"].includes(j);S.useEffect(()=>{var T,D,U,V,G,Q,le,ne,Z,ee,B,K,W,re;u(Ue(t)),c(((U=(D=(T=t==null?void 0:t.chartOptions)==null?void 0:T.scales)==null?void 0:D[o])==null?void 0:U.min)===0?0:""),x(((Q=(G=(V=t==null?void 0:t.chartOptions)==null?void 0:V.scales)==null?void 0:G[o])==null?void 0:Q.max)||""),h(((ee=(Z=(ne=(le=t==null?void 0:t.chartOptions)==null?void 0:le.scales)==null?void 0:ne[o])==null?void 0:Z.ticks)==null?void 0:ee.stepSize)||""),w(((B=t==null?void 0:t.numberAxisFormat)==null?void 0:B.decimalPlaces)||0),L(((K=t==null?void 0:t.numberAxisFormat)==null?void 0:K.suffix)||""),z(((W=t==null?void 0:t.numberAxisFormat)==null?void 0:W.currency)||""),I(((re=t==null?void 0:t.numberAxisFormat)==null?void 0:re.locale)||"")},[s,t,o]);function v(T,D){return D===""||/^[0-9\b]+$/.test(D)?Number(D):Number(T)}function O(){const T=[...new Set(e.LOCALE_CURRENCY_PAIRS.map(D=>D.currency))];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.jsxs(e.Select,{value:k||"none",onValueChange:D=>z(D==="none"?"":D),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,{children:e.jsxRuntimeExports.jsxs(e.SelectGroup,{children:[e.jsxRuntimeExports.jsx(e.SelectLabel,{children:"Currency"}),e.jsxRuntimeExports.jsx(e.SelectItem,{value:"none",children:"None"}),T.map(D=>e.jsxRuntimeExports.jsx(e.SelectItem,{value:D,children:D},D))]})})]}),e.jsxRuntimeExports.jsxs(e.Select,{value:y,onValueChange:D=>I(D),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,{children:e.jsxRuntimeExports.jsxs(e.SelectGroup,{children:[e.jsxRuntimeExports.jsx(e.SelectLabel,{children:"Locale"}),e.LOCALE_CURRENCY_PAIRS.map(D=>e.jsxRuntimeExports.jsx(e.SelectItem,{value:D.locale,children:D.locale},D.locale))]})})]})]}),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:b,onChange:D=>w(Number(D.target.value)),id:"format",className:`col-span-6 h-8 w-full tracking-wide ${ye}`})]})]})}function M(){return e.jsxRuntimeExports.jsxs(e.jsxRuntimeExports.Fragment,{children:[e.jsxRuntimeExports.jsxs("div",{className:"grid grid-cols-3 items-center gap-2",children:[e.jsxRuntimeExports.jsx(e.Label,{htmlFor:"range",children:"Range"}),e.jsxRuntimeExports.jsx(e.Input,{id:"min",value:l,onChange:T=>c(D=>v(D,T.target.value)),className:`col-span-1 h-8 w-full ${ye}`}),e.jsxRuntimeExports.jsx(e.Input,{value:p,onChange:T=>x(D=>v(D,T.target.value)),id:"max",className:`col-span-1 h-8 w-full ${ye}`})]}),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:d,onChange:T=>h(D=>v(D,T.target.value)),id:"step-size",className:`col-span-1 h-8 w-full ${ye}`})]})]})}function _(){var V;let T={};f==="custom"&&(T={min:l,max:p,ticks:{stepSize:d}});const D={...t||{},chartOptions:{...t==null?void 0:t.chartOptions,scales:{...(V=t==null?void 0:t.chartOptions)==null?void 0:V.scales,[o]:{type:i,...i==="linear"?T:{}}}},numberAxisFormat:{decimalPlaces:b,suffix:g,currency:k,locale:y}};console.log(D),A(D);const U={...R,preferences:D};m(U)}return e.jsxRuntimeExports.jsxs(e.Popover,{onOpenChange:T=>n(T),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:N,value:i,onValueChange:T=>u(T),children:[e.jsxRuntimeExports.jsx(e.SelectTrigger,{className:"col-span-2 h-8 w-full focus:ring-1 focus:ring-offset-0",children:e.jsxRuntimeExports.jsx(e.SelectValue,{})}),e.jsxRuntimeExports.jsx(e.SelectContent,{id:"type",children:e.jsxRuntimeExports.jsxs(e.SelectGroup,{children:[e.jsxRuntimeExports.jsx(e.SelectLabel,{children:"Option"}),e.jsxRuntimeExports.jsx(e.SelectItem,{value:"linear",children:"Linear"}),e.jsxRuntimeExports.jsx(e.SelectItem,{value:"logarithmic",children:"Logarithmic"})]})})]})]}),i=="linear"&&e.jsxRuntimeExports.jsxs("div",{className:"grid grid-cols-3 items-center gap-2 py-1",children:[e.jsxRuntimeExports.jsx(e.Label,{htmlFor:"scale-option",children:"Setup"}),e.jsxRuntimeExports.jsxs(e.RadioGroup,{disabled:N,id:"scale-option",value:f,onValueChange:T=>E(T),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"})]})]})]}),f==="custom"&&i=="linear"&&M(),O(),e.jsxRuntimeExports.jsx(e.SelectSeparator,{}),e.jsxRuntimeExports.jsx("div",{className:"grid grid-cols-3",children:e.jsxRuntimeExports.jsx(e.Button,{onClick:_,variant:"secondary",className:"col-span-1 col-start-3 h-8 w-full",children:"Apply"})})]})]})})]})}function yt({idx:s}){var l;const n=e.useEditorStore(c=>{var p;return(p=c.card)==null?void 0:p.preferences}),t=e.useEditorStore(c=>{var p;return(p=c.card.preferences)==null?void 0:p.datasetOptions}),r=e.useEditorStore(c=>c.actions.setCardPreferences),o=(l=n==null?void 0:n.chartOptions)==null?void 0:l.indexAxis,i=t==null?void 0:t.find(c=>c.idx===s);function u(c,p){(c==="end"||c==="start")&&e.getContrastColor(e.getCanvasBackgroundColor());const x={display:c!=="none",align:c,anchor:c,clamp:!0};if(!i)r({...n,datasetOptions:[...t||[],{idx:p,datalabels:x}]});else{const f={...i};f.datalabels=x;const E=t==null?void 0:t.map(d=>d.idx===p?f:d);r({...n,datasetOptions:E})}}return e.jsxRuntimeExports.jsxs(e.Popover,{children:[e.jsxRuntimeExports.jsx(e.PopoverTrigger,{children:e.jsxRuntimeExports.jsx(hs,{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:()=>u("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:()=>u("start",s),size:"sm",variant:"secondary",className:"h-7 p-1 text-xs font-normal",children:e.jsxRuntimeExports.jsx(os,{className:e.cn("h-4 w-4",{"rotate-90":o==="y"})})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>u("center",s),size:"sm",variant:"secondary",className:"h-7 p-1 text-xs font-normal",children:e.jsxRuntimeExports.jsx(as,{className:e.cn("h-4 w-4",{"rotate-90":o==="y"})})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>u("end",s),size:"sm",variant:"secondary",className:"h-7 p-1 text-xs font-normal",children:e.jsxRuntimeExports.jsx(is,{className:e.cn("h-4 w-4",{"rotate-90":o==="y"})})})]})})]})}function Fs(){const s=e.useEditorStore(p=>p.card),n=e.useEditorStore(p=>{var x,f,E;return(E=(f=(x=p==null?void 0:p.card)==null?void 0:x.preferences)==null?void 0:f.chartOptions)==null?void 0:E.indexAxis}),{data:t}=e.useDashboardCardQuery(s),r=n==="y"?"Y axis":"X axis",o=n==="y"?"X axis":"Y axis",{keys:i,metricKeys:u,dimensionKeys:l}=e.getKeys((t==null?void 0:t.records)||[]);let c=u;if(["stackedBar","stackedLine"].includes(s.type)){const p=e.pivotData({dataArray:(t==null?void 0:t.records)||[],groupKey:l[0],pivotKey:l[1],valueKey:c[0]}),{metricKeys:x}=e.getKeys(p);c=x}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:r}),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:o}),e.jsxRuntimeExports.jsx(Os,{})]}),e.jsxRuntimeExports.jsx("div",{className:"my-1 space-y-1",children:c.map((p,x)=>e.jsxRuntimeExports.jsx(St,{col:p,idx:x},p))})]})]})}function St({col:s,idx:n}){const t=e.useEditorStore(l=>{var c;return(c=l.card)==null?void 0:c.preferences}),r=e.useEditorStore(l=>{var c;return(c=l.card.preferences)==null?void 0:c.datasetOptions}),o=r==null?void 0:r.find(l=>l.idx===n),{setCardPreferences:i}=e.useEditorStore(l=>l.actions);function u(l){if(!o)i({...t,datasetOptions:[...r||[],{idx:n,type:l==="area"?"line":l,fill:l==="area"?"origin":""}]});else{const c={...o};c.type=l==="area"?"line":l,c.fill=l==="area"?"origin":"";const p=r==null?void 0:r.map(x=>x.idx===n?c:x);i({...t,datasetOptions:p})}}return e.jsxRuntimeExports.jsxs("div",{className:"group flex items-center justify-between gap-5 rounded-md bg-muted/70 px-2 py-1 hover:bg-muted",children:[e.jsxRuntimeExports.jsx("p",{children:s}),e.jsxRuntimeExports.jsxs("div",{className:"flex gap-2",children:[e.jsxRuntimeExports.jsx(Ne,{onClick:()=>u("bar"),className:"invisible size-4 cursor-pointer text-muted-foreground hover:text-foreground group-hover:visible"}),e.jsxRuntimeExports.jsx(we,{onClick:()=>u("line"),className:"invisible size-4 cursor-pointer text-muted-foreground hover:text-foreground group-hover:visible"}),e.jsxRuntimeExports.jsx(Je,{onClick:()=>u("area"),className:"invisible size-4 cursor-pointer text-muted-foreground hover:text-foreground group-hover:visible"}),e.jsxRuntimeExports.jsx(yt,{idx:n})]})]})}function Ms(){const s=e.useEditorStore(E=>E.selectedConnectionId),n=e.useEditorStore(E=>E.selectedDatamodelId),t=e.useEditorStore(E=>E.selectedDatabaseName),r=e.useEditorStore(E=>E.selectedSchemaName),o=e.useEditorStore(E=>E.selectedTableName),i=e.useDashboardStore(E=>E.dashboard.filters)||[],u=e.useDashboardStore(E=>E.actions.addFilter),l=e.useDashboardStore(E=>E.actions.removeFilter),{removeFilterValues:c}=e.useDashboardActions(),{modelItems:p,tableName:x}=ie();function f(E,d="dashboard"){var I;const h=e.fmt(E.column_name),b=e.fmt(t||""),w=e.fmt(r||""),g=e.fmt(x);let L=e.getQualifiedTableName(w,g),k=`${L}.${h}`;const z=(I=p==null?void 0:p.find(A=>A.id===n))==null?void 0:I.name;n&&n!=="none"&&(k=`${e.DATAMODEL_NAMESPCACE}.${z}.${h}`,L=`${e.DATAMODEL_NAMESPCACE}.${z}`);const y=i==null?void 0:i.find(A=>A.column===k&&A.table===g&&(A.database===b||A.database===t));if(y)c(y.id),l(y.id);else{const A=e.v4();return x==="api"&&s?(u({location:d,id:A,column:k,title:E.column_name,dataType:E.data_type,table:"api",database:"",connectionId:s,operation:"in",sql:e.getDefaultFilterSql(E.data_type,L,h)}),A):(u({id:A,location:d,column:k,title:E.column_name,dataType:E.data_type,table:o||"",database:t||"",connectionId:s||"",operation:"in",sql:e.getDefaultFilterSql(E.data_type,L,h)}),A)}}return{assignFilter:f}}function de(){const s=e.useDashboardStore(l=>l.dashboard.filters),n=e.useEditorStore(l=>l.frame),{setFrame:t}=e.useEditorActions(),{columns:r}=ie(),{assignFilter:o}=Ms();function i(l){const c=o(l,"frame");t({...n,filterId:c})}const u=s==null?void 0:s.find(l=>l.id===n.filterId);return e.jsxRuntimeExports.jsxs("div",{className:"space-y-3",children:[e.jsxRuntimeExports.jsx(e.Label,{children:"Card Filter"}),e.jsxRuntimeExports.jsx(vt,{onSelect:i,columns:r}),u&&e.jsxRuntimeExports.jsx(e.FilterHeader,{filter:u})]})}function vt({columns:s,onSelect:n}){var u;const[t,r]=Pe.useState(!1),[o,i]=Pe.useState("");return e.jsxRuntimeExports.jsxs(e.Popover,{open:t,onOpenChange:r,children:[e.jsxRuntimeExports.jsx(e.PopoverTrigger,{asChild:!0,children:e.jsxRuntimeExports.jsxs(e.Button,{size:"sm",variant:"outline",role:"combobox","aria-expanded":t,className:"w-full justify-between font-normal",children:[o?(u=s.find(l=>l.column_name===o))==null?void 0:u.column_name:"Select Column...",e.jsxRuntimeExports.jsx(e.CaretSortIcon,{className:"ml-2 h-4 w-4 shrink-0 opacity-50"})]})}),e.jsxRuntimeExports.jsx(e.PopoverContent,{className:"w-[200px] p-0",children:e.jsxRuntimeExports.jsxs(e.Command,{children:[e.jsxRuntimeExports.jsx(e.CommandInput,{placeholder:"Search column",className:"h-9"}),e.jsxRuntimeExports.jsxs(e.CommandList,{children:[e.jsxRuntimeExports.jsx(e.CommandEmpty,{children:"No framework found."}),e.jsxRuntimeExports.jsx(e.CommandGroup,{children:s.map(l=>e.jsxRuntimeExports.jsxs(e.CommandItem,{value:l.column_name,onSelect:c=>{const p=c===o?"":c;i(p),r(!1),p&&n(l)},children:[l.column_name,e.jsxRuntimeExports.jsx(e.CheckIcon,{className:e.cn("ml-auto h-4 w-4",o===l.column_name?"opacity-100":"opacity-0")})]},l.column_name))})]})]})})]})}function Ct({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(Ie,{}),e.jsxRuntimeExports.jsx(Fs,{})]})]}),e.jsxRuntimeExports.jsxs(e.AccordionItem,{value:"item-3",children:[e.jsxRuntimeExports.jsx(e.AccordionTrigger,{children:"Filters"}),e.jsxRuntimeExports.jsxs(e.AccordionContent,{className:"space-y-4 px-2",children:[e.jsxRuntimeExports.jsx(ae,{}),e.jsxRuntimeExports.jsx(de,{})]})]})]})})}function _e(){var o,i,u;const s=e.useEditorStore(l=>l.card.cfg),n=e.useEditorStore(l=>l.actions.setCardCfg),t=e.useEditorStore(l=>l.card.type);function r(l){var x;const c={datalabels:{display:l!=="none",align:l,anchor:l,clamp:!0}},p={...s,options:{...s==null?void 0:s.options,plugins:{...(x=s==null?void 0:s.options)==null?void 0:x.plugins,...c}}};n(p),console.log(l)}return e.jsxRuntimeExports.jsxs("div",{className:"space-y-2",children:[e.jsxRuntimeExports.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxRuntimeExports.jsx("label",{className:"font-medium",children:"Data Labels"}),!["pyramid"].includes(t)&&e.jsxRuntimeExports.jsx(Os,{})]}),e.jsxRuntimeExports.jsxs(e.Select,{value:(u=(i=(o=s==null?void 0:s.options)==null?void 0:o.plugins)==null?void 0:i.datalabels)==null?void 0:u.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 Nt({cardType:s}){function n(t){return e.jsxRuntimeExports.jsxs(e.jsxRuntimeExports.Fragment,{children:[e.jsxRuntimeExports.jsx("div",{className:"rounded bg-muted px-2 py-1 text-xs",children:t==="bubble"?"SELECT label, [group], x-axis, y-axis, radius FROM table":"SELECT label, [group], x-axis, y-axis 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:"group - category"}),e.jsxRuntimeExports.jsx("li",{children:"x-axis - category"}),e.jsxRuntimeExports.jsx("li",{children:"y-axis - category"}),t==="bubble"&&e.jsxRuntimeExports.jsx("li",{children:"radius - number"})]}),e.jsxRuntimeExports.jsxs("div",{children:["See ",e.jsxRuntimeExports.jsx("a",{target:"_blank",onClick:i=>i.stopPropagation(),className:"text-blue-700",href:"https://docs.semaphor.cloud/concepts/visuals#pie-chart",children:"example"})," in the docs."]})]})}return e.jsxRuntimeExports.jsx("div",{className:"space-y-6 px-6 py-2",children:e.jsxRuntimeExports.jsxs(e.Accordion,{defaultValue:["item-2"],type:"multiple",children:[e.jsxRuntimeExports.jsxs(e.AccordionItem,{value:"item-1",children:[e.jsxRuntimeExports.jsx(e.AccordionTrigger,{children:`${e.titleCase(s)} Chart`}),e.jsxRuntimeExports.jsx(e.AccordionContent,{className:"space-y-4 font-mono text-xs",children: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(_e,{})})]}),e.jsxRuntimeExports.jsxs(e.AccordionItem,{value:"item-3",children:[e.jsxRuntimeExports.jsx(e.AccordionTrigger,{children:"Filters"}),e.jsxRuntimeExports.jsxs(e.AccordionContent,{className:"space-y-4 px-2",children:[e.jsxRuntimeExports.jsx(ae,{}),e.jsxRuntimeExports.jsx(de,{})]})]})]})})}const wt={datasets:[{type:"line",label:"Sum_sales",data:[]},{type:"bar",label:"Sum_profit",data:[]}]},kt={datasets:[{fill:"origin",type:"line",label:"Sum_sales",data:[]}]};function It(){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:Dt(s)}),e.jsxRuntimeExports.jsx("section",{className:"",children:["line","bar"].includes(s)&&e.jsxRuntimeExports.jsx(Ie,{})}),!["kpi"].includes(s)&&e.jsxRuntimeExports.jsxs("div",{className:"space-y-4",children:[e.jsxRuntimeExports.jsx(_e,{}),e.jsxRuntimeExports.jsx(ae,{}),e.jsxRuntimeExports.jsx(de,{})]})]})}function Dt(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(wt,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(kt,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 Lt(){var c,p,x,f,E;const s=e.useEditorStore(d=>d.card.preferences),n=e.useEditorStore(d=>d.actions.setCardPreferences),t=e.useEditorStore(d=>d.actions.setNumberFormat);e.useEditorStore(d=>{var h,b;return(b=(h=d.card.preferences)==null?void 0:h.formatNumber)==null?void 0:b.decimalPlaces});const r=e.useEditorStore(d=>{var h,b;return(b=(h=d.card.preferences)==null?void 0:h.formatNumber)==null?void 0:b.locale}),o=e.useEditorStore(d=>{var h,b;return(b=(h=d.card.preferences)==null?void 0:h.formatNumber)==null?void 0:b.currency});e.useEditorStore(d=>d.actions.setFilterOnClickField);const i=e.useEditorStore(d=>{var h,b;return(b=(h=d.card.preferences)==null?void 0:h.formatNumber)==null?void 0:b.colorRanges})||[],u=e.useEditorStore(d=>d.actions.setColorRanges),l=[...new Set(e.LOCALE_CURRENCY_PAIRS.map(d=>d.currency))];return e.jsxRuntimeExports.jsxs("div",{children:[e.jsxRuntimeExports.jsxs("div",{className:"mb-3 flex items-center gap-2",children:[e.jsxRuntimeExports.jsx(e.Checkbox,{checked:!!((c=s==null?void 0:s.formatNumber)!=null&&c.enabled),onCheckedChange:d=>{n({...s,formatNumber:{...s==null?void 0:s.formatNumber,enabled:d}})}}),e.jsxRuntimeExports.jsx(e.Label,{children:"Format Number"})]}),((p=s==null?void 0:s.formatNumber)==null?void 0:p.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||"none",onValueChange:d=>{var h,b,w;return t(((h=s==null?void 0:s.formatNumber)==null?void 0:h.decimalPlaces)||0,((b=s==null?void 0:s.formatNumber)==null?void 0:b.currency)||"",d,((w=s==null?void 0:s.formatNumber)==null?void 0:w.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.jsxRuntimeExports.jsx(e.SelectItem,{value:"none",children:"None"},"none"),e.LOCALE_CURRENCY_PAIRS.map(d=>e.jsxRuntimeExports.jsx(e.SelectItem,{value:d.locale,children:d.locale},d.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:o||"none",onValueChange:d=>{var h,b,w;console.log("currency",d),t(((h=s==null?void 0:s.formatNumber)==null?void 0:h.decimalPlaces)||0,d==="none"?"":d,((b=s==null?void 0:s.formatNumber)==null?void 0:b.locale)||"",((w=s==null?void 0:s.formatNumber)==null?void 0:w.suffix)||"")},children:[e.jsxRuntimeExports.jsx(e.SelectTrigger,{className:"col-span-6 h-8 w-full focus:ring-1 focus:ring-offset-0",children:e.jsxRuntimeExports.jsx(e.SelectValue,{})}),e.jsxRuntimeExports.jsx(e.SelectContent,{children:e.jsxRuntimeExports.jsxs(e.SelectGroup,{children:[e.jsxRuntimeExports.jsx(e.SelectLabel,{children:"Currency"}),e.jsxRuntimeExports.jsx(e.SelectItem,{value:"none",children:"None"},"none"),l.map(d=>e.jsxRuntimeExports.jsx(e.SelectItem,{value:d,children:d},d))]})})]})]})]}),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:((f=(x=s==null?void 0:s.formatNumber)==null?void 0:x.decimalPlaces)==null?void 0:f.toString())||"0",onValueChange:d=>{var h,b,w;return t(Number(d),((h=s==null?void 0:s.formatNumber)==null?void 0:h.currency)||"",((b=s==null?void 0:s.formatNumber)==null?void 0:b.locale)||"",((w=s==null?void 0:s.formatNumber)==null?void 0:w.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(d=>e.jsxRuntimeExports.jsx(e.SelectItem,{value:d,children:d},d))})]})]}),e.jsxRuntimeExports.jsxs("div",{className:"w-full space-y-1",children:[e.jsxRuntimeExports.jsx(e.Label,{children:"Suffix"}),e.jsxRuntimeExports.jsx(e.Input,{value:((E=s==null?void 0:s.formatNumber)==null?void 0:E.suffix)||"",className:"h-8 font-mono text-xs focus-visible:ring-0 focus-visible:ring-ring focus-visible:ring-offset-0",placeholder:"K, M, B, %",onChange:d=>{var h,b,w;return t(((h=s==null?void 0:s.formatNumber)==null?void 0:h.decimalPlaces)||0,((b=s==null?void 0:s.formatNumber)==null?void 0:b.currency)||"",((w=s==null?void 0:s.formatNumber)==null?void 0:w.locale)||"",d.target.value)}})]})]})]})}),e.jsxRuntimeExports.jsx(e.Separator,{className:"my-3"}),e.jsxRuntimeExports.jsx(e.ColorFormat,{colorRanges:i,setColorRanges:u})]})]})}function Tt(){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(Lt,{})}),e.jsxRuntimeExports.jsx("div",{}),e.jsxRuntimeExports.jsx("div",{})]})}const At=[{label:"Mercator",value:"mercator"},{label:"Azimuthal Equidistant",value:"azimuthalEquidistant"},{label:"Gnomonic",value:"gnomonic"},{label:"Orthographic",value:"orthographic"},{label:"Stereographic",value:"stereographic"},{label:"Equal Earth",value:"equalEarth"},{label:"Albers",value:"albers"},{label:"Albers USA",value:"albersUsa"},{label:"Conic Conformal",value:"conicConformal"},{label:"Conic Equal Area",value:"conicEqualArea"},{label:"Conic Equidistant",value:"conicEquidistant"},{label:"Equirectangular",value:"equirectangular"},{label:"Transverse Mercator",value:"transverseMercator"},{label:"Natural Earth 1",value:"naturalEarth1"}],zt=["blues","brBG","buGn","buPu","cividis","cool","cubehelixDefault","gnBu","greens","greys","inferno","magma","orRd","oranges","pRGn","piYG","plasma","puBu","puBuGn","puOr","puRd","purples","rainbow","rdBu","rdGy","rdPu","rdYlBu","rdYlGn","reds","sinebow","spectral","turbo","viridis","warm","ylGn","ylGnBu","ylOrBr","ylOrRd"],Ot=zt.map(s=>({label:s,value:s}));function Ft(){var c,p,x,f,E,d,h,b,w,g,L,k,z,y,I,A,m,R;const s=e.useEditorStore(j=>j.card),n=(p=(c=s==null?void 0:s.preferences)==null?void 0:c.mapVisualOptions)==null?void 0:p.topoJsonUrl,[t,r]=S.useState(((f=(x=s==null?void 0:s.preferences)==null?void 0:x.mapVisualOptions)==null?void 0:f.customTopoJsonUrl)||""),{setCardPreferences:o}=e.useEditorActions(),{data:i}=e.useTopoJson(s),u=Object.keys((i==null?void 0:i.objects)||{}).map(j=>({label:j,value:j}))||[],l=[{label:"US States 10m",value:"https://unpkg.com/us-atlas/states-10m.json"},{label:"Countries 50m",value:"https://unpkg.com/world-atlas/countries-50m.json"},{label:"Custom",value:"custom"}];return e.jsxRuntimeExports.jsxs("div",{className:"p-6",children:[e.jsxRuntimeExports.jsx(je,{summary:"Map Query",children:e.jsxRuntimeExports.jsx("p",{className:"rounded-md bg-muted p-2 font-mono text-xs",children:"SELECT country, value FROM table"})}),e.jsxRuntimeExports.jsx(e.Separator,{className:"my-4"}),e.jsxRuntimeExports.jsx(je,{open:!0,summary:"Settings",children:e.jsxRuntimeExports.jsxs("div",{className:"space-y-3 px-2",children:[e.jsxRuntimeExports.jsx(Y,{className:"h-9",options:l,onValueChange:j=>{console.log("value",j),o({...s.preferences,mapVisualOptions:{topoJsonUrl:j}})},value:n||"",label:"Select Map"}),n==="custom"&&e.jsxRuntimeExports.jsx(e.Input,{onChange:j=>{r(j.target.value)},onBlur:()=>{var j;console.log("onBlur",t),o({...s.preferences,mapVisualOptions:{...(j=s.preferences)==null?void 0:j.mapVisualOptions,customTopoJsonUrl:t}})},value:t,className:`h-9 w-full ${e.removeRing}`,placeholder:"Custom URL"}),i&&e.jsxRuntimeExports.jsxs(e.jsxRuntimeExports.Fragment,{children:[e.jsxRuntimeExports.jsxs("div",{className:"space-y-1",children:[e.jsxRuntimeExports.jsx(e.Label,{children:"Map Object"}),e.jsxRuntimeExports.jsx(Y,{className:"h-9",options:u,value:((d=(E=s.preferences)==null?void 0:E.mapVisualOptions)==null?void 0:d.objectKey)||"",label:"Map Object",onValueChange:j=>{var N;o({...s.preferences,mapVisualOptions:{...(N=s.preferences)==null?void 0:N.mapVisualOptions,objectKey:j}})}})]}),e.jsxRuntimeExports.jsxs("div",{className:"space-y-1",children:[e.jsxRuntimeExports.jsx(e.Label,{children:"Projection"}),e.jsxRuntimeExports.jsx(Y,{className:"h-9",options:At,value:((b=(h=s.preferences)==null?void 0:h.mapVisualOptions)==null?void 0:b.projection)||"",label:"Projection",onValueChange:j=>{var N;o({...s.preferences,mapVisualOptions:{...(N=s.preferences)==null?void 0:N.mapVisualOptions,projection:j}})}})]}),e.jsxRuntimeExports.jsxs("div",{className:"space-y-1",children:[e.jsxRuntimeExports.jsx(e.Label,{children:"Colors"}),e.jsxRuntimeExports.jsx(Y,{className:"h-9",options:Ot,value:((g=(w=s.preferences)==null?void 0:w.mapVisualOptions)==null?void 0:g.colorScale)||"",label:"Select Color Scale",onValueChange:j=>{var N;o({...s.preferences,mapVisualOptions:{...(N=s.preferences)==null?void 0:N.mapVisualOptions,colorScale:j}})}})]})]})]})}),e.jsxRuntimeExports.jsx(e.Separator,{className:"my-4"}),e.jsxRuntimeExports.jsx(je,{className:"",summary:"Scale Options",children:e.jsxRuntimeExports.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxRuntimeExports.jsx(e.Input,{className:`h-9 w-full ${e.removeRing}`,type:"number",step:.1,value:((k=(L=s.preferences)==null?void 0:L.mapVisualOptions)==null?void 0:k.projectionScale)||1,onChange:j=>{var N;o({...s.preferences,mapVisualOptions:{...(N=s.preferences)==null?void 0:N.mapVisualOptions,projectionScale:Number(j.target.value)}})}}),e.jsxRuntimeExports.jsx(e.Label,{children:"X"}),e.jsxRuntimeExports.jsx(e.Input,{className:`h-9 w-full ${e.removeRing}`,type:"number",step:10,value:((I=(y=(z=s.preferences)==null?void 0:z.mapVisualOptions)==null?void 0:y.projectionOffset)==null?void 0:I[0])||0,onChange:j=>{var N,v,O,M;o({...s.preferences,mapVisualOptions:{...(N=s.preferences)==null?void 0:N.mapVisualOptions,projectionOffset:[Number(j.target.value),((M=(O=(v=s.preferences)==null?void 0:v.mapVisualOptions)==null?void 0:O.projectionOffset)==null?void 0:M[1])||0]}})}}),e.jsxRuntimeExports.jsx(e.Label,{children:"Y"}),e.jsxRuntimeExports.jsx(e.Input,{className:`h-9 w-full ${e.removeRing}`,type:"number",step:10,value:((R=(m=(A=s.preferences)==null?void 0:A.mapVisualOptions)==null?void 0:m.projectionOffset)==null?void 0:R[1])||0,onChange:j=>{var N,v,O,M;o({...s.preferences,mapVisualOptions:{...(N=s.preferences)==null?void 0:N.mapVisualOptions,projectionOffset:[((M=(O=(v=s.preferences)==null?void 0:v.mapVisualOptions)==null?void 0:O.projectionOffset)==null?void 0:M[0])||0,Number(j.target.value)]}})}})]})}),e.jsxRuntimeExports.jsx(e.Separator,{className:"my-4"}),e.jsxRuntimeExports.jsx(ae,{})]})}function Mt(){var r;const s=e.useEditorStore(o=>o.card.preferences),{setCardPreferences:n}=e.useEditorStore(o=>o.actions);function t(o){n({...s,textVisualOptions:{...s==null?void 0:s.textVisualOptions,isDynamicText:o==="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 Se({cardType:s,docContent:n,suffix:t="Chart"}){let r="pie-chart";return s==="radar"&&(r="radar-chart"),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:o=>o.stopPropagation(),className:"text-blue-700",href:`https://docs.semaphor.cloud/concepts/visuals#${r}`,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(Ie,{}),s!=="text"&&e.jsxRuntimeExports.jsx(_e,{}),s==="text"&&e.jsxRuntimeExports.jsx(Mt,{})]})]}),!["range","text"].includes(s)&&e.jsxRuntimeExports.jsxs(e.AccordionItem,{value:"item-3",children:[e.jsxRuntimeExports.jsx(e.AccordionTrigger,{children:"Filters"}),e.jsxRuntimeExports.jsxs(e.AccordionContent,{className:"space-y-4 px-2",children:[e.jsxRuntimeExports.jsx(ae,{}),e.jsxRuntimeExports.jsx(de,{})]})]})]})})}function Vt(){const s=e.useEditorStore(r=>{var o,i;return(i=(o=r==null?void 0:r.card)==null?void 0:o.preferences)==null?void 0:i.sortChart}),{setSortChart:n}=e.useEditorActions();function t(){return e.jsxRuntimeExports.jsxs("div",{className:"space-y-2",children:[e.jsxRuntimeExports.jsx(e.Label,{children:"Sort"}),e.jsxRuntimeExports.jsx(Y,{className:"h-8",label:"Sort Chart",options:[{label:"None",value:"none"},{label:"ASC",value:"asc"},{label:"DESC",value:"desc"}],value:s||"none",onValueChange:r=>{n(r)}})]})}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:r=>r.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(Ie,{}),t(),e.jsxRuntimeExports.jsx(Fs,{})]})]}),e.jsxRuntimeExports.jsxs(e.AccordionItem,{value:"item-3",children:[e.jsxRuntimeExports.jsx(e.AccordionTrigger,{children:"Filters"}),e.jsxRuntimeExports.jsxs(e.AccordionContent,{className:"space-y-4 px-2",children:[e.jsxRuntimeExports.jsx(ae,{}),e.jsxRuntimeExports.jsx(de,{})]})]})]})})}function qt({}){const s=e.useEditorStore(r=>{var o;return(o=r.card)==null?void 0:o.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:"Filters"}),e.jsxRuntimeExports.jsxs(e.AccordionContent,{className:"space-y-4 px-2",children:[e.jsxRuntimeExports.jsx(ae,{}),e.jsxRuntimeExports.jsx(de,{})]})]})}),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 _t=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."]})]}),Bt=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."]})]}),Pt=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 Ht(){const s=e.useEditorStore(t=>t.card.type);function n(t){switch(t){case"stackedBar":case"stackedLine":return e.jsxRuntimeExports.jsx(Vt,{});case"pyramid":return e.jsxRuntimeExports.jsx(Se,{docContent:_t,cardType:t});case"kpi":return e.jsxRuntimeExports.jsx(Tt,{});case"line":case"bar":return e.jsxRuntimeExports.jsx(Ct,{cardType:t});case"range":return e.jsxRuntimeExports.jsx(Se,{docContent:Bt,cardType:t});case"pie":case"doughnut":case"polarArea":case"radar":return e.jsxRuntimeExports.jsx(Se,{cardType:t});case"bubble":case"scatter":return e.jsxRuntimeExports.jsx(Nt,{cardType:t});case"table":return e.jsxRuntimeExports.jsx(qt,{cardType:t});case"text":return e.jsxRuntimeExports.jsx(Se,{docContent:Pt,cardType:t,suffix:"Visual"});case"map":return e.jsxRuntimeExports.jsx(Ft,{});case"custom":return e.jsxRuntimeExports.jsx(bt,{});default:return e.jsxRuntimeExports.jsx(It,{})}}return e.jsxRuntimeExports.jsx(e.ScrollArea,{className:"h-full w-full text-sm",children:n(s)})}function Gt(){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(ct,{})}),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(Ht,{})})}),e.jsxRuntimeExports.jsx(e.ResizableHandle,{className:"border"}),e.jsxRuntimeExports.jsx(e.ResizablePanel,{minSize:40,defaultSize:75,maxSize:100,children:e.jsxRuntimeExports.jsx($e,{})})]}):e.jsxRuntimeExports.jsx($e,{})})]})}function $t({authToken:s,onSave:n,onClose:t}){e.useDashboardStore(u=>u.themeStyle);const r=e.useEditorStore(u=>u.actions.setOnSave),o=e.useEditorStore(u=>u.actions.setOnClose),i=e.useDashboardStore(u=>u.actions.setAuthToken);return S.useEffect(()=>{n&&r(n),t&&o(t)},[n,r,t,o]),S.useEffect(()=>{s&&s.accessToken&&i(s)},[s,i]),e.jsxRuntimeExports.jsx(e.ErrorBoundary,{FallbackComponent:e.Fallback,children:e.jsxRuntimeExports.jsxs(e.EditorPanel,{style:{},className:"rounded-none",role:"editor-panel",children:[e.jsxRuntimeExports.jsx(e.EditorAside,{className:"rounded-none border-r-[1.5px]",children:e.jsxRuntimeExports.jsx(bs,{})}),e.jsxRuntimeExports.jsx(e.EditorMain,{children:e.jsxRuntimeExports.jsx(Gt,{})})]})})}function Ut(){e.useDashboardStore(u=>u.selectedCardId);const s=e.useDashboardStore(u=>u.selectedSheetId),{setIsVisualEditing:n}=e.useDashboardStore(u=>u.actions),t=e.useDashboardStore(u=>u.isVisualEditing),r=e.useDashboardStore(u=>u.actions.updateFrame);function o(u){s&&(r(s,u),n(!1))}function i(){n(!1)}return e.jsxRuntimeExports.jsx("div",{role:"editor-container",className:e.cn("flex grow",{"max-h-0 overflow-hidden":!t}),children:e.jsxRuntimeExports.jsx($t,{onSave:o,onClose:i})})}function Qt(){const s=e.useEditorStore(i=>i.selectedDatabaseName),n=e.useEditorStore(i=>i.selectedTableName),t=e.useDashboardStore(i=>i.dashboard.filters)||[],{columns:r}=ie(),{assignFilter:o}=Ms();return e.jsxRuntimeExports.jsx("div",{className:"xbg-red-100 flex-1 basis-0 flex-col overflow-scroll px-3",children:r==null?void 0:r.map(i=>{const u=t==null?void 0:t.find(l=>l.column===e.fmt(i.column_name)&&l.table===n&&l.database===s);return e.jsxRuntimeExports.jsx("div",{onClick:()=>o(i),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":u}),children:e.jsxRuntimeExports.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxRuntimeExports.jsx(Rs,{column:i}),e.jsxRuntimeExports.jsx("span",{children:i.column_name})]})},i.column_name)})})}function Jt(){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(bs,{ColumnsComponent:()=>e.jsxRuntimeExports.jsx(Qt,{})})})]})}function Kt(){const s=e.useDashboardStore(r=>r.dashboard.filters),n=e.useDashboardStore(r=>r.theme),t=s==null?void 0:s.filter(r=>r.hide);return t!=null&&t.length?e.jsxRuntimeExports.jsx(e.jsxRuntimeExports.Fragment,{children:e.jsxRuntimeExports.jsx("div",{className:e.cn("mb-2 flex items-center gap-2 border-b px-1",{"bg-[repeating-linear-gradient(45deg,_#ffffff_0_3px,_#f3f3f3_3px_6px)]":n==="light","bg-[repeating-linear-gradient(45deg,_#18171d_0_3px,_#272729_3px_6px)]":n==="dark"}),children:t==null?void 0:t.map(r=>e.jsxRuntimeExports.jsxs("div",{className:"flex w-[250px] flex-col gap-1 p-2",children:[e.jsxRuntimeExports.jsx(e.FilterHeader,{filter:r}),e.jsxRuntimeExports.jsx(e.FilterComponent,{filter:r})]},r.id))})}):null}function Wt(){const s=e.useDashboardStore(t=>t.showFilters),n=e.useDashboardStore(t=>t.isVisualEditing);return e.jsxRuntimeExports.jsxs("div",{role:"dashboard-plus-main",className:e.cn("",{"max-h-0 overflow-hidden":n,"flex grow":!n}),children:[e.jsxRuntimeExports.jsxs("section",{className:"flex grow flex-col",children:[e.jsxRuntimeExports.jsx(Kt,{}),e.jsxRuntimeExports.jsx(e.DashboardTabs,{})]}),s&&e.jsxRuntimeExports.jsx("div",{role:"filter-aside-container",className:"flex",children:e.jsxRuntimeExports.jsx(Jt,{})})]})}function Yt(){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 Xt({showControls:s=!1,showFooter:n=!0,...t}){return e.jsxRuntimeExports.jsx(e.ErrorBoundary,{FallbackComponent:e.Fallback,children:e.jsxRuntimeExports.jsxs(e.SemaphorContextProvider,{dashboardProps:t,children:[e.jsxRuntimeExports.jsx(e.Oe,{}),e.jsxRuntimeExports.jsxs(e.UXProvider,{children:[e.jsxRuntimeExports.jsx(Yt,{}),e.jsxRuntimeExports.jsxs(e.DashboardPanel,{...t,children:[s&&e.jsxRuntimeExports.jsx(Qs,{}),e.jsxRuntimeExports.jsx(Ut,{}),e.jsxRuntimeExports.jsx(Wt,{})]})]})]})})}exports.Box=Qe;exports.ChartArea=Je;exports.ChartColumnIncreasing=Ne;exports.ChartLine=we;exports.ChartNoAxesGantt=Ae;exports.ChartPie=ze;exports.ChartScatter=Oe;exports.CircleX=Ke;exports.CopyPlus=We;exports.DashboardPlus=Xt;exports.Database=Ye;exports.EllipsisVertical=Fe;exports.Eraser=Xe;exports.Eye=es;exports.EyeClosed=Ze;exports.Glasses=ss;exports.Hammer=ts;exports.Hash=ns;exports.House=rs;exports.ListEnd=os;exports.ListStart=is;exports.ListX=as;exports.LoaderCircle=oe;exports.Map=Me;exports.MessageSquareMore=ls;exports.Network=cs;exports.Play=xs;exports.Plug2=us;exports.Save=ds;exports.SelectComponent=ue;exports.Shapes=Ve;exports.ShieldQuestion=ms;exports.Sigma=ps;exports.SwatchBook=js;exports.Tag=hs;exports.ToggleLeft=Es;exports.Type=ke;exports.User=fs;exports.cleanCard=gs;exports.getDashbaordStateWithoutData=qe;exports.useEditorAside=ie;
|