react-semaphor 0.0.376 → 0.0.3771
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-BOpp3w2L.js → index-BO95GMa_.js} +1489 -1470
- package/dist/chunks/{index-F8s-l6Wu.js → index-BoTz0wgQ.js} +37 -37
- package/dist/chunks/{index-CrjQ8QqC.js → index-De5ny3c9.js} +3 -3
- package/dist/chunks/{index-BHFp3m2S.js → index-DeoC8wP6.js} +112 -113
- package/dist/chunks/{lucide-react-BCNS53ze.js → lucide-react-CslBFmME.js} +3 -3
- package/dist/chunks/{lucide-react-CxAXGpsK.js → lucide-react-Dd51A2C_.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/surfboard/index.cjs +1 -1
- package/dist/surfboard/index.js +1 -1
- package/package.json +3 -3
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";const e=require("./index-
|
|
1
|
+
"use strict";const e=require("./index-BoTz0wgQ.js"),S=require("react");require("react-dom");function Hs(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 _e=Hs(S);/**
|
|
2
2
|
* @license lucide-react v0.453.0 - ISC
|
|
3
3
|
*
|
|
4
4
|
* This source code is licensed under the ISC license.
|
|
@@ -188,5 +188,5 @@
|
|
|
188
188
|
*
|
|
189
189
|
* This source code is licensed under the ISC license.
|
|
190
190
|
* See the LICENSE file in the root directory of this source tree.
|
|
191
|
-
*/const ve=e.createLucideIcon("Type",[["polyline",{points:"4 7 4 4 20 4 20 7",key:"1nosan"}],["line",{x1:"9",x2:"15",y1:"20",y2:"20",key:"swin9y"}],["line",{x1:"12",x2:"12",y1:"4",y2:"20",key:"1tx1rr"}]]);function Ae(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(a=>Rs(a))}})}})}}function Rs(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:Gs(s.customCfg),data:[]}}function Gs(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 Us(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 we(s,n){if(!n)return null;const{id:t,template:r,filterValues:o,isDefault:i,shared:a}=s;return await e.postRequest("https://semaphor.cloud/api/v1/lens",n,{lensId:t,template:r,filterValues:o,isDefault:i,shared:a,operation:"update"})}async function $s(s,n){return n?await e.postRequest("https://semaphor.cloud/api/v1/lens",n,{operation:"delete",lensId:s}):null}function Qs(){const[s,n]=S.useState(""),[t,r]=S.useState(!1),o=e.useDashboardStore(p=>p.lenses),{setLenses:i,setSelectedLensId:a}=e.useDashboardActions(),[l,x]=S.useState(!1),[u,d]=S.useState(!1),h=e.useDashboardStore(p=>p.dashboard),g=e.useDashboardStore(p=>p.filterValues),{authToken:c}=e.useSemaphorContext();async function m(){x(!0);const p=Ae(h),y=await Us(s,p,g,c==null?void 0:c.accessToken);y&&(i([...o||[],y]),a(y.id),d(!1)),x(!1)}return e.jsxRuntimeExports.jsxs(e.Dialog,{open:u,onOpenChange:d,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:p=>{n(p.target.value)},id:"name",className:"col-span-7 focus-visible:ring-0 focus-visible:ring-ring focus-visible:ring-offset-0"})]})}),t&&e.jsxRuntimeExports.jsx("p",{className:"text-sm",children:"The lens name already exists. Use a differnet name."}),e.jsxRuntimeExports.jsx(e.DialogFooter,{children:e.jsxRuntimeExports.jsx(e.Button,{size:"sm",variant:"outline",type:"submit",onClick:m,disabled:l,children:l?"Creating...":"Add"})})]})]})}function Js(){const[s,n]=S.useState(!1),t=e.useDashboardStore(d=>d.lenses),r=e.useDashboardStore(d=>d.selectedLensId),{setLenses:o,setSelectedLensId:i}=e.useDashboardActions(),{authToken:a}=e.useSemaphorContext();async function l(d){i(d)}async function x(d){if(await $s(d,a==null?void 0:a.accessToken)){const g=t==null?void 0:t.filter(c=>c.id!==d);o(g||[]),i("original")}}async function u(d){const h=t==null?void 0:t.map(m=>m.id===d.id?{...m,isDefault:!d.isDefault}:{...m,isDefault:!1});o(h||[]);const g={...d,isDefault:!d.isDefault};await we(g,a==null?void 0:a.accessToken);const c=t==null?void 0:t.find(m=>m.isDefault);if(c&&c.id!==d.id){const m={...c,isDefault:!1};await we(m,a==null?void 0:a.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(ts,{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(d=>e.jsxRuntimeExports.jsxs(e.DropdownMenuRadioItem,{className:"group flex justify-between gap-2",value:d.id,children:[e.jsxRuntimeExports.jsx("p",{children:d.name}),e.jsxRuntimeExports.jsxs("span",{className:"flex items-center gap-3",children:[e.jsxRuntimeExports.jsx(os,{onClick:h=>{h.preventDefault(),u(d)},className:e.cn("size-3.5 text-muted-foreground hover:cursor-pointer hover:text-foreground group-hover:visible",{invisible:!d.isDefault,"text-green-500":d.isDefault}),strokeWidth:1.5}),e.jsxRuntimeExports.jsx(e.Cross2Icon,{onClick:h=>{h.preventDefault(),x(d.id)},className:"invisible size-3.5 text-muted-foreground hover:cursor-pointer hover:text-foreground group-hover:visible",strokeWidth:1.5})]})]},d.id))]})]})]})}async function bs(){var c;const s=e.useDashboardStore.getState().authToken,n=e.useDashboardStore.getState().theme,t=e.useDashboardStore.getState().filterValues,r=(c=e.useDashboardStore.getState().dashboard)==null?void 0:c.title,o=e.useDashboardStore.getState().isDownloadingPdf,i=e.useDashboardStore.getState().selectedSheetId;if(o)return;const a=new URLSearchParams;a.set("token",(s==null?void 0:s.accessToken)||""),a.set("theme",n||"light"),a.set("filterValues",JSON.stringify(t)),a.set("selectedSheetId",i||"");const l=`https://semaphor.cloud/api/v1/generate-pdf?params=${encodeURIComponent(a.toString())}`;e.useDashboardStore.setState({isDownloadingPdf:!0});const d=(await(await fetch(l,{method:"GET",headers:{Authorization:`Bearer ${s==null?void 0:s.accessToken}`}})).json()).url,h=document.createElement("a");h.href=d;const g=`${r}-${new Date().toISOString()}.pdf`;h.download=g,h.click(),e.useDashboardStore.setState({isDownloadingPdf:!1})}function Ws({iconClassName:s}){e.useSemaphorContext(),e.useDashboardStore(r=>{var o;return(o=r.dashboard)==null?void 0:o.title}),e.useDashboardStore(r=>r.theme),e.useDashboardStore(r=>r.filterValues);const n=e.useDashboardStore(r=>r.isDownloadingPdf);async function t(){await bs()}return e.jsxRuntimeExports.jsx(e.Button,{variant:"link",className:"group h-7 p-2",size:"sm",onClick:t,children:n?e.jsxRuntimeExports.jsx(xe,{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 Ks(){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),a=e.useEditorStore(j=>j.selectedConnectionId),[l,x]=S.useState(!1),u=e.useDashboardStore(j=>j.filterValues),d=e.useDashboardStore(j=>j.isVisualEditing),h=e.useDashboardStore(j=>j.showFilters);e.useDashboardStore(j=>j.showDashboardJSON);const g=e.useDashboardStore(j=>j.onSaveFunction),c=e.useDashboardStore(j=>j.actions.setShowFilters),{addFrame:m,setSelectedFrameId:p}=e.useDashboardStore(j=>j.actions),{getSelectedSheet:y,setIsDashboardEditing:f,setShowDashboardJSON:O}=e.useDashboardStore(j=>j.actions),D=y(),{tenantId:N,endUserId:v}=S.useMemo(()=>e.getTenantAndEndUserId(s==null?void 0:s.accessToken),[s==null?void 0:s.accessToken]),A=S.useMemo(()=>N||v,[N,v]),F=()=>{if(!i||!D)return;const j={connectionId:a,id:e.v4(),title:"Title",description:"Description",preferences:{onClickFilter:[{columnIndex:0,expression:""}]},type:"bar",sql:"select COUNT(*) from YOUR_TABLE",data:[]},E={id:e.v4(),cards:[j],activeCardId:j.id};m(D.id,E),p(E.id)},z=()=>{f(!0)};async function R(){if(x(!0),!t||!r)return;const j=Ae(o),E=JSON.stringify(j),b={...r,template:E,filterValues:u};await we(b,s==null?void 0:s.accessToken),e.ce.success("Lens saved"),g==null||g(j),x(!1)}return d?null:e.jsxRuntimeExports.jsxs("div",{className:"flex items-center justify-between gap-2 border-b bg-muted/50 py-2 pl-3 pr-2",role:"dashboard-controls",children:[!d&&e.jsxRuntimeExports.jsx("div",{className:"flex items-center gap-3",children:e.jsxRuntimeExports.jsx(e.Label,{children:r==null?void 0:r.name})}),e.jsxRuntimeExports.jsxs("div",{className:"flex gap-2",children:[e.jsxRuntimeExports.jsx("button",{onClick:e.invalidateToken,children:e.jsxRuntimeExports.jsx(Es,{className:"h-4 w-4",strokeWidth:1.5})}),e.jsxRuntimeExports.jsx(Ws,{}),i&&!d&&A&&e.jsxRuntimeExports.jsx(Qs,{}),!d&&A&&e.jsxRuntimeExports.jsx(Js,{}),i&&!d&&e.jsxRuntimeExports.jsxs(e.Button,{variant:"secondary",className:"h-7 p-2",size:"sm",disabled:!i,onClick:F,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:z,size:"sm",children:e.jsxRuntimeExports.jsx(e.Pencil,{className:"h-4 w-4",strokeWidth:1.5})}),i&&!d&&e.jsxRuntimeExports.jsx(e.Button,{variant:"ghost",role:"close",className:"h-7 p-2",onClick:()=>{f(!1),O(!1)},size:"sm",children:e.jsxRuntimeExports.jsx(e.Cross2Icon,{className:"h-4 w-4",strokeWidth:1.5})}),i&&!d&&A&&e.jsxRuntimeExports.jsx(e.Button,{className:"h-7 p-2",variant:"ghost",disabled:l,onClick:R,size:"sm",children:e.jsxRuntimeExports.jsx(ms,{className:"h-4 w-4",strokeWidth:1.5})}),!h&&!d&&i&&e.jsxRuntimeExports.jsx(e.Button,{className:"h-7 p-2",variant:"ghost",onClick:()=>c(!0),size:"sm",children:e.jsxRuntimeExports.jsx(e.Filter,{className:"h-4 w-4",strokeWidth:1.5})}),!d&&i&&!1,!d&&!1]})]})}function ce({title:s,items:n,value:t,isLoading:r,isError:o,refetch:i,connectionTooltip:a,onChange:l,showNone:x=!1,className:u,showIcon:d=!0,disabled:h=!1}){const g=r?"Loading...":o?"Error":t;function c(){if(s==="Connection")return e.jsxRuntimeExports.jsx(us,{className:"size-4 rotate-90"});if(s==="Database")return e.jsxRuntimeExports.jsx(Xe,{className:"size-4"});if(s==="Schema")return e.jsxRuntimeExports.jsx(xs,{className:"size-4"});if(s==="Table")return e.jsxRuntimeExports.jsx(Se,{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:[d&&e.jsxRuntimeExports.jsx("div",{className:"shrink-0",children:a?e.jsxRuntimeExports.jsxs(e.Tooltip,{children:[e.jsxRuntimeExports.jsx(e.TooltipTrigger,{children:c()}),e.jsxRuntimeExports.jsx(e.TooltipContent,{className:"text-xs",align:"start",children:a})]}):c()}),e.jsxRuntimeExports.jsxs(e.Select,{disabled:h,value:g,onValueChange:l,children:[e.jsxRuntimeExports.jsx(e.SelectTrigger,{className:e.cn("h-9 w-full focus:ring-1 focus:ring-offset-0",u),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.jsxs(e.SelectLabel,{className:"flex items-center justify-between gap-2",children:[s,e.jsxRuntimeExports.jsx(ds,{className:"mr-1 size-3 cursor-pointer text-muted-foreground hover:text-foreground",onClick:i})]}),e.jsxRuntimeExports.jsxs(e.jsxRuntimeExports.Fragment,{children:[x&&e.jsxRuntimeExports.jsx(e.SelectItem,{value:"none",children:"None"},"none"),n&&n.map((m,p)=>e.jsxRuntimeExports.jsx(e.SelectItem,{value:m.id,children:m.name},p))]}),(r||o)&&e.jsxRuntimeExports.jsx(e.SelectItem,{value:g,children:g})]})})]})]})}function Zs({column:s}){const[n,t]=S.useState(!1),r=e.useEditorStore(m=>m.selectedTableName),o=e.useEditorStore(m=>m.selectedSchemaName),i=e.useEditorStore(m=>m.selectedDatamodelId),a=e.useEditorStore(m=>m.sqlGen),{modelItems:l,connectionType:x}=re(),u=e.useEditorStore(m=>m.actions.setSqlGen),d=e.useEditorStore(m=>m.actions.setCardSql),h=e.useEditorStore(m=>m.actions.setRunSql);function g(m,p){var D;const y=e.createSqlGenConfig(m,a,p),f=(D=l==null?void 0:l.find(N=>N.id===i))==null?void 0:D.name;u(y);const O=e.getSql(y,e.fmt(o||""),e.fmt(r),f,x);O&&(d(O),h(!0)),t(!1)}function c(){return e.jsxRuntimeExports.jsxs("ul",{className:"text-xs",children:[e.jsxRuntimeExports.jsx("li",{onClick:()=>g(s,"COUNT"),className:"cursor-pointer p-1 px-3 transition-colors hover:bg-muted",children:"Count"}),e.jsxRuntimeExports.jsx("li",{onClick:()=>g(s,"AVG"),className:"cursor-pointer p-1 px-3 transition-colors hover:bg-muted",children:"Avg"}),e.jsxRuntimeExports.jsx("li",{onClick:()=>g(s,"SUM"),className:"cursor-pointer p-1 px-3 transition-colors hover:bg-muted",children:"Sum"}),e.jsxRuntimeExports.jsx("li",{onClick:()=>g(s,"MAX"),className:"cursor-pointer p-1 px-3 transition-colors hover:bg-muted",children:"Max"}),e.jsxRuntimeExports.jsx("li",{onClick:()=>g(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(be,{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:c()})]})}function Ss({column:s}){return e.jsxRuntimeExports.jsxs(e.Tooltip,{children:[e.jsxRuntimeExports.jsx(e.TooltipTrigger$1,{asChild:!0,children:e.isTextDataType(s.data_type)?e.jsxRuntimeExports.jsx(ve,{className:"size-3"}):e.isNumberDataType(s.data_type)?e.jsxRuntimeExports.jsx(rs,{className:"size-3"}):e.isDateDataType(s.data_type)?e.jsxRuntimeExports.jsx(e.Calendar,{className:"size-3"}):e.isBooleanDataType(s.data_type)?e.jsxRuntimeExports.jsx(gs,{className:"size-3"}):s.data_type.toLowerCase()==="json"?e.jsxRuntimeExports.jsx(Je,{className:"size-3"}):e.jsxRuntimeExports.jsx(ps,{className:"size-3"})}),e.jsxRuntimeExports.jsx(e.TooltipContent,{children:e.jsxRuntimeExports.jsx("p",{className:"font-mono text-xs",children:s.data_type})})]})}function Xs({schemaName:s,tableName:n,columns:t,status:r}){const o=e.useEditorStore(R=>R.sqlGen),i=e.useEditorStore(R=>R.selectedConnectionId),a=e.useEditorStore(R=>R.selectedDatabaseName),l=e.useEditorStore(R=>R.selectedSchemaName),x=e.useEditorStore(R=>R.selectedTableName),u=e.useEditorStore(R=>R.selectedDatamodelId),d=e.useDashboardStore(R=>R.dashboard.aiScopeTables),{addToAIScope:h,removeFromAIScope:g}=e.useDashboardActions();e.useDashboardStore(R=>R.actions);const c=e.useEditorStore(R=>R.actions.setRunSql),m=e.useEditorStore(R=>R.actions.setSqlGen),p=e.useEditorStore(R=>R.actions.setIsShowingVisual),y=e.useEditorStore(R=>R.actions.setCardSql),{connectionType:f,modelItems:O,selectedDatamodelName:D}=re();function N(R){var I;const j=e.createSqlGenConfig(R,o);m(j);const E=(I=O==null?void 0:O.find(M=>M.id===u))==null?void 0:I.name,b=e.getSql(j,e.fmt(s),e.fmt(n),E,f);b&&(y(b),c(!0))}function v(){return(d==null?void 0:d.find(R=>R.connectionId===i&&(R.tableName===x||R.datamodelName===D)))!==void 0}function A(R){R===!0&&(x||D)&&i?(h({connectionId:i,connectionType:f==="S3"||f==="API"?"DuckDb":f,databaseName:a,schemaName:l,tableName:x,datamodelName:D}),e.ce.success("Added to Assistant Scope",{position:"top-right",duration:2500,richColors:!0})):(g({connectionId:i||"",connectionType:f||"",tableName:x||"",datamodelName:D||""}),e.ce("Removed from Assistant Scope",{position:"top-right",duration:2e3,richColors:!0}))}function F(){const R=e.getFormattedTableNameForQuery({schemaName:s,tableName:n,modelName:D,connectionType:f});p(!1);const j=f==="MSSQL"?`SELECT top 10 * FROM ${R}`:`SELECT * FROM ${R} LIMIT 10`;y(j),c(!0)}function z(){const R=e.getFormattedTableNameForQuery({schemaName:s,tableName:n,modelName:D,connectionType:f});y(`SELECT COUNT(*) as count FROM ${R}`),c(!0)}return e.jsxRuntimeExports.jsxs("div",{className:"flex grow flex-col space-y-4 px-4",children:[e.jsxRuntimeExports.jsxs("div",{className:"mx-2 flex items-center justify-center gap-2",children:[e.jsxRuntimeExports.jsxs(e.Toggle,{title:`${v()?"Remove from":"Add to"} Assistant Scope`,pressed:v(),onPressedChange:A,variant:"outline",className:e.cn("h-9 px-2",{}),children:[e.jsxRuntimeExports.jsx(e.Plus,{className:e.cn("mr-1 size-4",{"text-green-400":v(),"text-muted-foreground":!v()})}),"AI"]}),e.jsxRuntimeExports.jsxs(e.Button,{disabled:r!=="Success",onClick:F,size:"sm",variant:"secondary",className:"flex",children:[r!=="Success"?e.jsxRuntimeExports.jsx(xe,{className:"mr-2 h-4 w-4 animate-spin text-foreground/50"}):e.jsxRuntimeExports.jsx(hs,{className:"mr-2 size-4"}),"Top 10"]}),e.jsxRuntimeExports.jsxs(e.Button,{disabled:r!=="Success",onClick:z,size:"sm",variant:"secondary",className:"w-full",children:[r!=="Success"?e.jsxRuntimeExports.jsx(xe,{className:"mr-2 h-4 w-4 animate-spin text-foreground/50"}):e.jsxRuntimeExports.jsx(js,{className:"mr-2 size-4"}),"Count"]})]}),e.jsxRuntimeExports.jsxs(e.ScrollArea,{className:"flex-1 basis-0 border-b border-t border-muted py-3",children:[e.jsxRuntimeExports.jsx("div",{className:"flex flex-col gap-1",children:t==null?void 0:t.map(R=>e.jsxRuntimeExports.jsxs("div",{onClick:()=>N(R),className:e.cn("group mx-3 flex cursor-pointer items-center justify-between rounded px-2 py-1 text-sm transition-colors hover:bg-muted/50",{"border border-dashed border-muted-foreground bg-muted":e.isColumnInSqlGen(R,o)}),children:[e.jsxRuntimeExports.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsxRuntimeExports.jsx(Ss,{column:R}),e.jsxRuntimeExports.jsx("span",{children:R.column_name})]}),e.jsxRuntimeExports.jsx("div",{onClick:j=>j.stopPropagation(),className:"flex items-center justify-end",children:e.isNumberDataType(R.data_type)&&e.jsxRuntimeExports.jsx(Zs,{column:R})})]},R.column_name))}),e.jsxRuntimeExports.jsx(e.ScrollBar,{orientation:"vertical"}),e.jsxRuntimeExports.jsx(e.ScrollBar,{orientation:"horizontal"})]})]})}function re(s,n){var Oe,Me,Fe,Ve,qe,Be;let t=S.useMemo(()=>[],[]);const r=e.useSemaphorContext().authToken||s,o=e.useEditorStore(C=>C.selectedConnectionId),i=e.useEditorStore(C=>C.selectedDatamodelId),a=e.useEditorStore(C=>C.selectedDatabaseName),l=e.useEditorStore(C=>C.selectedSchemaName),x=e.useEditorStore(C=>C.selectedTableName),u=e.useEditorStore(C=>C.actions.setCurrentColumns),d=e.useEditorStore(C=>C.actions.setSelectedConnectionId),h=e.useEditorStore(C=>C.actions.setSelectedDatamodelId),g=e.useEditorStore(C=>C.actions.setSelectedDatabaseName),c=e.useEditorStore(C=>C.actions.setSelectedSchemaName),m=e.useEditorStore(C=>C.actions.setSelectedTableName);e.useEditorStore(C=>C.actions.setCardSql);function p(C){return o&&a&&l&&a!=="NA"?!0:o&&C==="API"?!1:!!(o&&C==="S3")}function y(C){return!!(o&&a&&a!=="NA"&&l&&x||o&&(C==="S3"||C==="API")||i&&i)}function f(C){return o&&C?!(C==="API"||C==="S3"):!1}const{refetch:O,data:D,isLoading:N,isError:v}=e.useQuery({queryKey:["connections"],queryFn:()=>e.getRequest("https://semaphor.cloud/api/v1/connections",(r==null?void 0:r.accessToken)||""),enabled:!!(r!=null&&r.accessToken)}),{refetch:A,data:F,isLoading:z,isError:R}=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}),j=D==null?void 0:D.connections.find(C=>C.id===o),E=j==null?void 0:j.type,b=(j==null?void 0:j.type)==="API"||(j==null?void 0:j.type)==="S3",{data:I,isLoading:M,isFetching:P,isError:q,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:f(E)}),{data:G,isLoading:X,isFetching:J,isError:B,refetch:V}=e.useQuery({queryKey:["schemas",o,a],queryFn:()=>e.getRequest("https://semaphor.cloud/api/v1/schemas",(r==null?void 0:r.accessToken)||"",{connection_id:o,database_name:a}),enabled:!!o&&!!a&&!b&&a!=="NA"}),{data:T,isLoading:W,isFetching:U,isError:K,refetch:Q}=e.useQuery({queryKey:["tables",o,a,l],queryFn:()=>e.getRequest("https://semaphor.cloud/api/v1/tables",(r==null?void 0:r.accessToken)||"",{connection_id:o,database_name:a,schema_name:l}),enabled:p(E)}),{data:$,isLoading:Y,isFetching:w,isError:L,refetch:_}=e.useQuery({queryKey:["columns",o,a,i,l,x],queryFn:()=>e.getRequest("https://semaphor.cloud/api/v1/columns",(r==null?void 0:r.accessToken)||"",{connection_id:o,datamodel_id:i||"",database_name:a,schema_name:l,table_name:x}),enabled:y(E)});S.useEffect(()=>{u(t)},[$,u,t]),S.useEffect(()=>{(E==="S3"||E==="API")&&(g(""),c(""),h(""),E==="API"&&m("api"))},[E,m,g,c,h]);const ne=(j==null?void 0:j.type)==="API"?(Oe=j==null?void 0:j.type)==null?void 0:Oe.toLowerCase():x||"",le=b?"":l||"";function oe(C){c(C),m("")}function k(C){g(C==="none"?"":C),c(""),m(""),C!=="none"&&C!==""&&h("")}function Z(C){d(C)}function ie(C){h(C==="none"?"":C),C!=="none"&&C!==""&&g("")}I&&((Me=I==null?void 0:I.databases)==null?void 0:Me.length)>0,G&&((Fe=G==null?void 0:G.schemas)==null?void 0:Fe.length)>0,$&&((Ve=$==null?void 0:$.columns)==null?void 0:Ve.length)>0&&(t=$.columns.map(C=>({...C,data_type:C.data_type.toLowerCase()}))),q&&(t=[]),(L||v)&&(t=[]);const ee=D==null?void 0:D.connections.map(C=>({id:C.id,name:C.name,type:C.type})),de=(qe=F==null?void 0:F.datamodels)==null?void 0:qe.map(C=>({id:C.id,name:C.name})),Ce=I==null?void 0:I.databases.map(C=>({id:C.database_name,name:C.database_name})),pe=G==null?void 0:G.schemas.map(C=>({id:C.schema_name,name:C.schema_name})),Ne=T==null?void 0:T.tables.map(C=>({id:C.table_name,name:C.table_name})),Ps=(Be=F==null?void 0:F.datamodels.find(C=>C.id===i))==null?void 0:Be.name;return{connectionItems:ee,isConnectionsLoading:N,isConnectionsError:v,modelItems:de,selectedDatamodelId:i,selectedDatamodelName:Ps,isModelsLoading:z,isModelsError:R,databaseItems:Ce,isDatabasesLoadingOrFetching:M||P,isDatabaseError:q,schemaItems:pe,isSchemaLoadingOrFetching:X||J,isSchemaError:B,tableItems:Ne,isTableLoadingOrFetching:W||U,isTableError:K,columns:t,isColumnsLoadingOrFetching:Y||w,isColumnsError:L,isNonDbConnection:b,connectionType:E,tableName:ne,schemaName:le,refetchConnections:O,refetchModels:A,refetchDatabases:H,refetchSchemas:V,refetchTables:Q,refetchColumns:_,handleConnectionChange:Z,handleDatamodelChange:ie,handleDatabaseChange:k,handleSchemaChange:oe}}function vs({ColumnsComponent:s}){var w;const n=e.useEditorStore(L=>L.selectedConnectionId),t=e.useEditorStore(L=>L.selectedDatamodelId),r=e.useEditorStore(L=>L.selectedDatabaseName),o=e.useEditorStore(L=>L.selectedSchemaName),i=e.useEditorStore(L=>L.selectedTableName),a=e.useEditorStore(L=>L.actions.setSelectedTableName),{connectionItems:l,modelItems:x,schemaItems:u,databaseItems:d,tableItems:h,columns:g,isConnectionsLoading:c,isModelsLoading:m,isConnectionsError:p,isModelsError:y,isDatabasesLoadingOrFetching:f,isDatabaseError:O,isSchemaLoadingOrFetching:D,isSchemaError:N,isColumnsError:v,isColumnsLoadingOrFetching:A,isTableLoadingOrFetching:F,isTableError:z,connectionType:R,isNonDbConnection:j,refetchDatabases:E,refetchModels:b,refetchSchemas:I,refetchTables:M,refetchColumns:P,refetchConnections:q,handleConnectionChange:H,handleDatabaseChange:G,handleSchemaChange:X,handleDatamodelChange:J,tableName:B,schemaName:V}=re();function T(){return s?s(V,B,g):e.jsxRuntimeExports.jsx(Xs,{schemaName:V,tableName:B,columns:g,status:A?"Loading...":v?"Error":"Success"})}function W(){window.location.href="mailto:support@semaphor.cloud?subject=Help&body=I need help with..."}function U(){if(!n||R==="S3"||R==="API")return null;if(!t||t==="none")return e.jsxRuntimeExports.jsx(ce,{refetch:E,showNone:!0,onChange:G,isError:O,isLoading:f,items:d,value:r||"",title:"Database"})}function K(){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 Q(){if(!n||R==="S3"||R==="API")return null;if(!r||r==="none")return e.jsxRuntimeExports.jsx(ce,{refetch:b,showNone:!0,onChange:J,isError:y,isLoading:m,items:x,value:t||"",title:"Model"})}function $(){return!n||R==="S3"||R==="API"||!r||r==="none"?null:e.jsxRuntimeExports.jsx(ce,{refetch:I,onChange:X,isError:N,isLoading:D,items:u,value:o||"",title:"Schema"})}function Y(){function L(){let _=!1;return R==="API"?(_=!1,_):((R==="S3"||n&&r&&r!=="none"&&o)&&(_=!0),_)}return L()?e.jsxRuntimeExports.jsx(ce,{refetch:M,onChange:a,isError:z,items:h,isLoading:F,value:i||"",title:"Table"}):null}return e.jsxRuntimeExports.jsxs("aside",{className:"flex grow flex-col justify-between",children:[e.jsxRuntimeExports.jsxs("section",{className:"space-y-3 px-6 py-4",children:[e.jsxRuntimeExports.jsx(ce,{refetch:q,items:l,title:"Connection",value:n||"",onChange:H,isLoading:c,isError:p,connectionTooltip:((w=l==null?void 0:l.find(L=>L.id===n))==null?void 0:w.type)||""}),U(),K(),Q(),$(),Y()]}),T(),e.jsxRuntimeExports.jsx("div",{className:"flex items-end justify-center gap-2 px-6 py-4",children:e.jsxRuntimeExports.jsxs(e.Button,{onClick:W,size:"sm",variant:"secondary",className:"w-full",children:[e.jsxRuntimeExports.jsx(cs,{className:"mr-2 size-4"}),"Help"]})})]})}function Ys(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 a=s.substring(0,n),l=s.substring(n);return`${a} {{ filters | where }} AND ${l.substring(6)}`}else if(t!==-1){const a=s.substring(0,t),l=s.substring(t);return`${a} {{ filters | where }} ${l}`}else{const a=s.substring(0,i),l=s.substring(i);return console.log("beforeClause",a),console.log("afterClause",l),l?`${a} {{ filters | where }} ${l}`:`${a.replace(/;$/,"")} {{ filters | where }}`}}function et({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(ns,{className:"mr-2 h-4 w-4"}),"Debug with AI"]})]})})})]})}function st({userInput:s,triggerAIRun:n,setTriggerAIRun:t,open:r,setOpen:o}){const i=S.useRef(null),a=S.useRef(null),[l,x]=S.useState([]),[u,d]=S.useState(""),[h,g]=S.useState(null),{authToken:c}=e.useSemaphorContext(),m=e.useEditorStore(w=>{var L;return(L=w==null?void 0:w.card)==null?void 0:L.sql}),p=e.useEditorStore(w=>{var L;return(L=w==null?void 0:w.card)==null?void 0:L.python}),y=e.useEditorStore(w=>w.actions.setCardSql),f=e.useEditorStore(w=>w.actions.setRunSql),O=e.useEditorStore(w=>w.actions.switchCardType),D=e.useEditorStore(w=>w.selectedDatabaseName),N=e.useEditorStore(w=>w.selectedTableName),v=e.useEditorStore(w=>w.selectedConnectionId),A=e.useEditorStore(w=>w.selectedSchemaName),F=e.useDashboardStore(w=>w.dashboard.aiScopeTables),{selectedDatamodelName:z,connectionType:R}=re(),{messages:j,setMessages:E,reload:b,append:I,input:M,status:P,handleInputChange:q,handleSubmit:H,addToolResult:G,stop:X}=e.useChat({api:"https://semaphor.cloud/api/v1/assistant",headers:{Authorization:`Bearer ${c==null?void 0:c.accessToken}`},body:{random:Math.random()},maxSteps:10,onToolCall:T,onFinish(w,L){B(L.usage),d(""),console.log("onFinish",w,L),L.finishReason==="stop"&&d("")}});S.useEffect(()=>{n&&s&&(q({target:{value:s}}),setTimeout(()=>{H(),t(!1)},100))},[n,H,s,t,q]);const J=S.useRef(r);S.useEffect(()=>{const w=J.current?"smooth":"auto";J.current=r;const L=setTimeout(()=>{var _;a.current&&(a.current.scroll({top:a.current.scrollHeight,behavior:w}),(_=i.current)==null||_.focus())},50);return()=>clearTimeout(L)},[j,r]);function B(w){g(L=>L?{promptTokens:L.promptTokens+w.promptTokens,completionTokens:L.completionTokens+w.completionTokens,totalTokens:L.totalTokens+w.totalTokens}:w)}function V(w){const L=e.removeFromScopeArray(l,w);U(L)}async function T({toolCall:w}){if(w.toolName==="createChart"){console.log("createChart",w.args);const L=w.args.sql,_=w.args.chartType;return O(_),y(L),f(!0),{status:"success",message:"Let the user know that chart is created"}}else if(w.toolName==="getTableColumns")d("Getting table columns...");else{if(w.toolName==="getUserSql")return m?(console.log("cardSql",m),console.log("cardPython",p),{status:"success",sql:m,python:p||""}):{status:"error",message:"No SQL found"};d("Thinking...")}}function W(w){return w.map(_=>({..._,connectionType:_.connectionType==="API"||_.connectionType==="S3"?"DuckDb":_.connectionType}))}function U(w){const L=W(w);x(L),E(_=>[..._,{id:crypto.randomUUID(),role:"system",content:`Current scope of tables | ${JSON.stringify(L)}`}])}function K(){const w={databaseName:D||"",schemaName:A||"",tableName:N||"",datamodelName:z||"",connectionId:v||"",connectionType:R||""},L=e.dedup([...l,w]);U(L)}function Q(){const w={databaseName:D||"",schemaName:A||"",tableName:N||"",datamodelName:z||"",connectionId:v||"",connectionType:R||""},L=e.isInAiScopeArray([...F||[],...l],w);if(console.log("isInScope",L),!L||l.length===0){const _=e.dedup([...F||[],...l,w]).filter(ne=>ne.connectionId===w.connectionId);U(_)}}function $(w){o(!1),y(w),f(!0)}const Y=!["ready","error"].includes(P);return{messages:j,setMessages:E,reload:b,append:I,input:M,isLoading:Y,handleRun:$,handleOpenDialogAndSetScope:Q,handleAddCurrentTableToScope:K,removeFromCurrentSelections:V,currentScope:l,setCurrentScope:x,containerRef:a,inputRef:i,handleInputChange:q,handleSubmit:H,stop:X,chatStatus:P,toolStatus:u,llmUsage:h}}const tt=!1;function nt({open:s,setOpen:n,userInput:t,triggerAIRun:r,setTriggerAIRun:o}){const[i,a]=S.useState(!1),[l,x]=S.useState(tt),[u,d]=S.useState(!1),{messages:h,setMessages:g,reload:c,append:m,input:p,isLoading:y,handleRun:f,handleOpenDialogAndSetScope:O,handleAddCurrentTableToScope:D,removeFromCurrentSelections:N,currentScope:v,setCurrentScope:A,containerRef:F,inputRef:z,handleInputChange:R,handleSubmit:j,stop:E,chatStatus:b,toolStatus:I,llmUsage:M}=st({userInput:t,triggerAIRun:r,setTriggerAIRun:o,open:s,setOpen:n});function P(){return e.jsxRuntimeExports.jsxs(e.DropdownMenu,{children:[e.jsxRuntimeExports.jsx(e.DropdownMenuTrigger,{children:e.jsxRuntimeExports.jsx(be,{className:"size-3.5 text-muted-foreground/70 hover:text-muted-foreground"})}),e.jsxRuntimeExports.jsxs(e.DropdownMenuContent,{align:"end",children:[e.jsxRuntimeExports.jsx(e.DropdownMenuLabel,{children:"Options"}),e.jsxRuntimeExports.jsx(e.DropdownMenuSeparator,{}),e.jsxRuntimeExports.jsx(e.DropdownMenuCheckboxItem,{checked:i,onCheckedChange:a,children:"Token Usage"}),e.jsxRuntimeExports.jsx(e.DropdownMenuCheckboxItem,{checked:l,onCheckedChange:x,children:"Tool Invocations"}),e.jsxRuntimeExports.jsx(e.DropdownMenuCheckboxItem,{checked:u,onCheckedChange:d,children:"System Message"})]})]})}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:O,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..."})}),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.jsx(e.DialogHeader,{children:e.jsxRuntimeExports.jsxs("div",{className:"flex items-start justify-between gap-2 pr-5",children:[e.jsxRuntimeExports.jsxs("div",{children:[e.jsxRuntimeExports.jsx(e.DialogTitle,{children:"Assistant"}),e.jsxRuntimeExports.jsx(e.DialogDescription,{children:"What can I help you with?"}),v&&v.length>0&&e.jsxRuntimeExports.jsxs("div",{className:"mt-2 flex flex-wrap items-center gap-2",children:[e.jsxRuntimeExports.jsx("span",{className:"text-xs text-muted-foreground",children:"Tables in scope:"}),v==null?void 0:v.map((q,H)=>e.jsxRuntimeExports.jsxs("div",{className:"flex items-center gap-2 rounded-md bg-muted px-2 py-1 text-xs",children:[e.getFormattedTableNameForQuery({schemaName:q.schemaName||"",tableName:q.tableName||"",modelName:q.datamodelName||"",connectionType:q.connectionType||""}),e.jsxRuntimeExports.jsx("button",{onClick:()=>{N(q)},children:e.jsxRuntimeExports.jsx(e.X,{className:"size-3 text-muted-foreground hover:text-foreground"})})]},H))]}),(v==null?void 0:v.length)===0&&e.jsxRuntimeExports.jsxs("div",{className:"mt-2 flex items-center gap-2",children:[e.jsxRuntimeExports.jsx("span",{className:"text-xs text-muted-foreground",children:"Tables in scope: None"}),e.jsxRuntimeExports.jsxs(e.Button,{className:"h-6 text-xs",size:"sm",variant:"secondary",onClick:D,children:[e.jsxRuntimeExports.jsx(e.Plus,{className:"mr-2 size-3"}),"Current Table"]})]})]}),e.jsxRuntimeExports.jsxs("div",{className:"flex items-center gap-2",children:[P(),e.jsxRuntimeExports.jsx(e.Button,{className:"h-8",size:"sm",variant:"secondary",onClick:()=>{g([]),A([]),c()},children:"Clear"})]})]})}),e.jsxRuntimeExports.jsx("div",{ref:F,className:"h-[625px] w-full overflow-auto border-t border-t-muted",children:e.jsxRuntimeExports.jsxs("div",{className:"space-y-4 py-2 pr-3",role:"messages",children:[e.jsxRuntimeExports.jsx(e.PrintMessages,{messages:h,showTools:l,handleRun:f,showSystemMessage:u}),e.jsxRuntimeExports.jsx(e.ChatStatus,{status:e.getStatus(b,I),isLoading:y})]})}),e.jsxRuntimeExports.jsx(e.ChatInput,{stop:E,ref:z,input:p,handleInputChange:R,handleSubmit:j,isLoading:y}),M&&i&&e.jsxRuntimeExports.jsx("div",{className:"flex h-8 items-center justify-between",children:e.jsxRuntimeExports.jsxs("div",{className:"text-xs text-muted-foreground",children:["Usage: ",M.promptTokens," prompt tokens,"," ",M.completionTokens," completion tokens,"," ",M.totalTokens," total tokens"]})})]})]})}var ys={color:void 0,size:void 0,className:void 0,style:void 0,attr:void 0},Pe=S.createContext&&S.createContext(ys),rt=["attr","size","title"];function ot(s,n){if(s==null)return{};var t=it(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 it(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 fe(){return fe=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},fe.apply(this,arguments)}function He(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 Ee(s){for(var n=1;n<arguments.length;n++){var t=arguments[n]!=null?arguments[n]:{};n%2?He(Object(t),!0).forEach(function(r){at(s,r,t[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(s,Object.getOwnPropertyDescriptors(t)):He(Object(t)).forEach(function(r){Object.defineProperty(s,r,Object.getOwnPropertyDescriptor(t,r))})}return s}function at(s,n,t){return n=lt(n),n in s?Object.defineProperty(s,n,{value:t,enumerable:!0,configurable:!0,writable:!0}):s[n]=t,s}function lt(s){var n=ct(s,"string");return typeof n=="symbol"?n:n+""}function ct(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 Cs(s){return s&&s.map((n,t)=>S.createElement(n.tag,Ee({key:t},n.attr),Cs(n.child)))}function se(s){return n=>S.createElement(xt,fe({attr:Ee({},s.attr)},n),Cs(s.child))}function xt(s){var n=t=>{var{attr:r,size:o,title:i}=s,a=ot(s,rt),l=o||t.size||"1em",x;return t.className&&(x=t.className),s.className&&(x=(x?x+" ":"")+s.className),S.createElement("svg",fe({stroke:"currentColor",fill:"currentColor",strokeWidth:"0"},t.attr,r,a,{className:x,style:Ee(Ee({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 Pe!==void 0?S.createElement(Pe.Consumer,null,t=>n(t)):n(ys)}function ut(s){return se({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 dt({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 Ns(s){const{theme:n}=e.useTheme(),t=e.useDashboardStore(p=>p.theme),r=e.useEditorStore(p=>p.frame),o=e.useEditorStore(p=>p.card),i=e.useEditorStore(p=>p.activeTabCardId),a=e.Le(),{refetch:l}=e.useDashboardCardQuery(o),{updateCardTab:x,setRunSql:u}=e.useEditorActions(),d=S.useRef(),h=S.useRef({}),g=r.cards.find(p=>p.id===i),c=S.useCallback(()=>{let p="";return s==="python"&&(p=(g==null?void 0:g.python)||e.PYTHON_DEFAULT_CODE),s==="sql"&&(p=(g==null?void 0:g.sql)||""),p},[s,g]);S.useEffect(()=>{if(i&&o.id&&o.id!==i){if(d.current&&a){const p=d.current.getModel();p&&(h.current[o.id]=p);let y=h.current[i];if(!y){const f=c();y=a.editor.createModel(f,s),h.current[i]=y}d.current.setModel(y)}x(i,o),u(!0)}},[i,o,x,a,u,s,c]),S.useEffect(()=>{if(!a)return;const p=window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light",y=t==="system"?p:t;a.editor.defineTheme("default",{base:y==="light"?"vs":"vs-dark",inherit:!0,rules:[],colors:{"editor.background":y==="light"?"#ffffff":e.hslStringToHex("240 10% 10%")}}),a.editor.setTheme("default")},[n,t,a]),S.useEffect(()=>{const p=d.current;p&&a&&o&&p.addCommand(a.KeyMod.Shift|a.KeyCode.Enter,function(){return l(),!1})},[a,l,o]);function m(p,y){if(d.current=p,!h.current[o.id]){const f=p.getModel(),O=c();h.current[o.id]=f||(y==null?void 0:y.editor.createModel(O,s))||p.getModel()}p.setModel(h.current[o.id])}return{handleEditorDidMount:m}}function mt(){const s=e.useEditorStore(a=>a.card.sql),n=e.useEditorStore(a=>a.sqlGen),{setCardSql:t,setSqlGen:r}=e.useEditorActions(),{handleEditorDidMount:o}=Ns("sql");function i(a){t(a),e.isObjectEmpty(n)||r({})}return e.jsxRuntimeExports.jsx(e.Ft,{theme:"default",className:"pt-3",onChange:i,value:s||"",options:{minimap:{enabled:!1},wordWrap:"on",scrollbar:{verticalScrollbarSize:0,horizontalScrollbarSize:0},fontSize:13,renderLineHighlight:"none"},defaultLanguage:"sql",onMount:o})}function pt(){const s=e.useEditorStore(o=>o.card.python),{setCardPython:n}=e.useEditorActions(),{handleEditorDidMount:t}=Ns("python");function r(o){n(o)}return e.jsxRuntimeExports.jsx(e.Ft,{className:"pt-3",theme:"default",onChange:r,value:s||e.PYTHON_DEFAULT_CODE,options:{minimap:{enabled:!1},wordWrap:"on",scrollbar:{verticalScrollbarSize:0,horizontalScrollbarSize:0},fontSize:13,renderLineHighlight:"none"},defaultLanguage:"python",onMount:t})}function jt(){const s=e.useDashboardStore(i=>i.dashboard.filters),n=e.useDashboardStore(i=>i.filterValues),t=e.useDashboardStore(i=>i.selectedSheetId),r=s==null?void 0:s.filter(i=>i.sheetId===t||!i.sheetId),o=n==null?void 0:n.filter(i=>(r==null?void 0:r.some(a=>a.id===i.filterId))||i.filterId.endsWith(t));return e.jsxRuntimeExports.jsx(e.Ft,{theme:"default",defaultLanguage:"json",className:"mt-1 min-h-[220px]",value:JSON.stringify(o,null,2),options:{readOnly:!0,minimap:{enabled:!1},lineNumbers:"off",glyphMargin:!1,wordWrap:"on",scrollbar:{verticalScrollbarSize:0,horizontalScrollbarSize:0},fontSize:12,renderLineHighlight:"none"}})}function ht(){var oe;const[s,n]=S.useState({queryKey:[],queryData:null}),t=e.useQueryClient(),[r,o]=S.useState(!1),[i,a]=S.useState(!1),[l,x]=S.useState(!1),[u,d]=S.useState(""),[h,g]=S.useState(!1),c=e.useEditorStore(k=>k.frame),m=e.useEditorStore(k=>k.card),p=e.useEditorStore(k=>k.isShowingVisual),y=e.useEditorStore(k=>k.selectedConnectionId),f=e.useEditorStore(k=>k.selectedDatabaseName),O=e.useEditorStore(k=>k.selectedDatamodelId),D=e.useEditorStore(k=>k.selectedSchemaName),N=e.useEditorStore(k=>k.selectedTableName),v=e.useEditorStore(k=>{var Z;return(Z=k==null?void 0:k.card)==null?void 0:Z.sql}),A=e.useEditorStore(k=>k.applyFilters),{setCardCustomCfg:F,setQueryResultColumns:z,setCardSql:R,setPythonStdOut:j,setCardPreferences:E,setCardType:b,setCardPython:I}=e.useEditorActions(),M=e.useEditorStore(k=>k.onSave),P=e.useEditorStore(k=>k.onClose),q=e.useEditorStore(k=>k.actions.setSqlGen),H=e.useEditorStore(k=>k.runSql),G=e.useEditorStore(k=>k.actions.setRunSql),X=e.useEditorStore(k=>k.actions.setCardCfg),J=e.useEditorStore(k=>k.actions.setIsSqlRunning),{data:B,isLoading:V,isFetching:T,isSuccess:W,isError:U,error:K,queryKey:Q,refetch:$}=e.useDashboardCardQuery(m);S.useEffect(()=>{if(B&&(B.rowLimitExceeded&&e.ce.error("Row limit (10,000) exceeded. Refine your query.",{position:"top-center",richColors:!0}),j((B==null?void 0:B.output)||""),B.records.length>0)){const{dimensionKeys:k}=e.getKeys(B.records);z(k)}},[B,z,j]),S.useEffect(()=>{(V||T)&&J(!0),(U||W)&&J(!1),U&&(z([]),j(""))},[V,T,B,j,U,W,J,z,K]),S.useEffect(()=>{H&&(t.getQueryData(Q)||$(),G(!1))},[H,$,G,Q,t]);function Y(){const k=t.getQueryData(Q);s.queryData||n({queryKey:Q,queryData:k}),t.setQueryData(Q,null),t.removeQueries({queryKey:Q,exact:!0}),R(""),q({}),I(""),X(void 0),F(""),E({}),b("bar")}function w(k,Z){if(k.length===0)return"";if(Z){const ie=k.find(ee=>ee.id===Z);if(ie){const ee=ie.tabTitle;if(ee=="All__Header")return k[0].id;if(ee&&ee.endsWith("__Header")){const Ce=ee.split("__")[0],pe=k.find(Ne=>Ne.tabTitle===Ce);return pe?pe.id:k[0].id}return Z}}return k[0].id}function L(){let k=v;v&&!v.includes("{{")&&(k=Ys(v),R(k));const Z={...m,lastSelectedSchema:D,lastSelectedDatamodelId:O,lastSelectedDatabase:f,lastSelectedTable:N,connectionId:y,type:p?m.type:"table",sql:k,customCfg:p?m.customCfg:null},ie=c.cards.map(de=>de.id===m.id?Z:de),ee={...c,cards:ie,activeCardId:w(ie,c.activeCardId)};M==null||M(ee)}function _(){const{queryKey:k,queryData:Z}=s;k&&Z&&t.setQueryData(k,Z),q({}),P==null||P()}function ne(){return e.jsxRuntimeExports.jsxs(e.jsxRuntimeExports.Fragment,{children:[i&&e.jsxRuntimeExports.jsx("div",{className:"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"}),i&&e.jsxRuntimeExports.jsx(e.Cross2Icon,{onClick:()=>a(!1),className:"bg-background/50 text-foreground/50 hover:cursor-pointer hover:text-foreground"})]}),e.jsxRuntimeExports.jsx(jt,{})]})}),!i&&e.jsxRuntimeExports.jsx(e.Filter,{onClick:()=>a(!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":A})})]})}function le(){return e.jsxRuntimeExports.jsxs(e.ResizablePanelGroup,{className:"flex grow pb-1",direction:"vertical",role:"editor-resizable-group",children:[e.jsxRuntimeExports.jsxs(e.ResizablePanel,{id:"1",order:1,defaultSize:r?20:100,className:"relative flex grow",children:[e.jsxRuntimeExports.jsx("div",{id:"sql-container",className:"relative flex w-[99%]",children:e.jsxRuntimeExports.jsx(mt,{})}),r&&e.jsxRuntimeExports.jsx("code",{className:"absolute right-6 top-3 text-xs text-muted-foreground/70",children:"sql"})]}),r&&e.jsxRuntimeExports.jsxs(e.jsxRuntimeExports.Fragment,{children:[e.jsxRuntimeExports.jsx(e.ResizableHandle,{withHandle:!0,className:"border"}),e.jsxRuntimeExports.jsxs(e.ResizablePanel,{id:"2",order:2,defaultSize:80,className:"relative flex grow",children:[e.jsxRuntimeExports.jsx("div",{id:"python-container",className:"relative flex w-[99%] pt-0",children:e.jsxRuntimeExports.jsx(pt,{})}),e.jsxRuntimeExports.jsx("code",{className:"absolute right-6 top-3 text-xs 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",{className:"relative flex grow justify-between overflow-y-scroll",children:[le(),ne()]}),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:V||T,onClick:()=>{$()},className:"shrink-0",size:"sm",variant:"outline",children:[V||T?e.jsxRuntimeExports.jsx(xe,{className:"mr-2 h-4 w-4 animate-spin text-foreground/50"}):e.jsxRuntimeExports.jsx(e.Play,{className:"mr-2 h-4 w-4"}),"Run"]}),(U||(B==null?void 0:B.error))&&e.jsxRuntimeExports.jsx(et,{error:(K==null?void 0:K.message)||((oe=B==null?void 0:B.error)==null?void 0:oe.message),setShowAIDialog:x,setTriggerAIRun:g,setUserInputforAI:d}),e.jsxRuntimeExports.jsxs(e.Button,{onClick:Y,className:"",size:"sm",variant:"outline",children:[e.jsxRuntimeExports.jsx(Ye,{className:"mr-2 size-4"}),"Clear"]}),e.jsxRuntimeExports.jsx(e.Toggle,{pressed:r,onPressedChange:k=>o(k),className:"",size:"sm",variant:"outline",children:e.jsxRuntimeExports.jsx(ut,{className:"size-4 text-foreground/70"})}),e.jsxRuntimeExports.jsx(nt,{open:l,setOpen:x,userInput:u,triggerAIRun:h,setTriggerAIRun:g})]}),e.jsxRuntimeExports.jsxs("div",{className:"flex items-center gap-2",children:[(B==null?void 0:B.sql)&&e.jsxRuntimeExports.jsx(dt,{sql:B.sql}),e.jsxRuntimeExports.jsxs(e.Button,{onClick:_,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:L,size:"sm",variant:"outline",children:[e.jsxRuntimeExports.jsx(e.Check,{className:"mr-2 size-4 font-bold text-green-600"}),"Accept"]})]})]})]})}function ft({data:s}){var a;const[n,t]=S.useState([]),o=Object.keys(s[0]).map(l=>({accessorKey:l,header:({column:x})=>{const u=x.getIsSorted();return e.jsxRuntimeExports.jsx("div",{className:"flex gap-2",children:e.jsxRuntimeExports.jsxs("div",{className:"flex cursor-pointer items-center",onClick:()=>x.toggleSorting(x.getIsSorted()==="asc"),children:[l,u==="asc"?e.jsxRuntimeExports.jsx(e.TriangleUpIcon,{className:"ml-2 h-5 w-5"}):u==="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(x=>e.jsxRuntimeExports.jsx(e.TableHead,{className:"sticky top-0 h-11 bg-muted font-semibold",children:x.isPlaceholder?null:e.flexRender(x.column.columnDef.header,x.getContext())},x.id))},l.id))}),e.jsxRuntimeExports.jsx(e.TableBody,{children:(a=i.getRowModel().rows)!=null&&a.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(x=>e.jsxRuntimeExports.jsx(e.TableCell,{className:"py-3",children:e.flexRender(x.column.columnDef.cell,x.getContext())},x.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 Et({card:s}){var f,O,D,N,v,A,F,z,R,j,E;const[n,t]=S.useState(!1),[r,o]=S.useState([]),{authToken:i}=e.useSemaphorContext(),a=e.getTokenParams(i==null?void 0:i.accessToken),l=e.useDashboardStore(b=>b.themeStyle),x={colors:((O=(f=l==null?void 0:l.chart)==null?void 0:f.dataset)==null?void 0:O.backgroundColor)||[]};(D=s.customCardPreferences)!=null&&D.inputData;const{getCard:u}=e.useCustomVisual(((N=s.customCardPreferences)==null?void 0:N.url)||""),d=((v=s.customCardPreferences)==null?void 0:v.visualType)||"single",h=e.useEditorStore(b=>b.frame);e.useEditorActions();const{data:g}=e.useDashboardCardQuery(s),c=S.useCallback((b,I)=>{o(M=>({...M,[b]:I}))},[]);if(!((A=s.customCardPreferences)!=null&&A.componentName))return null;const m=u((F=s.customCardPreferences)==null?void 0:F.componentName);function p(b){t(b)}const y=Object.keys(((z=s.customCardPreferences)==null?void 0:z.dataInputCardIds)||{}).map(b=>{var P,q,H;const I=(q=(P=s.customCardPreferences)==null?void 0:P.dataInputCardIds)==null?void 0:q[b].cardId,M=(H=h==null?void 0:h.cards)==null?void 0:H.find(G=>G.id===I);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:[m&&d==="single"&&e.jsxRuntimeExports.jsx(m,{params:a,theme:x,settings:(R=s.customCardPreferences)==null?void 0:R.settings,onDataChange:c,data:(g==null?void 0:g.records)||[]}),m&&d==="multiple"&&e.jsxRuntimeExports.jsxs(e.jsxRuntimeExports.Fragment,{children:[Object.keys(((j=s.customCardPreferences)==null?void 0:j.dataInputCardIds)||{}).map(b=>{var P,q,H;const I=(q=(P=s.customCardPreferences)==null?void 0:P.dataInputCardIds)==null?void 0:q[b].cardId,M=(H=h==null?void 0:h.cards)==null?void 0:H.find(G=>G.id===I);if(M)return e.jsxRuntimeExports.jsx(e.MultiInputEmptyRenderer,{onLoadingStatus:p,onDataChange:c,dataInputIndex:b,card:M},M.id+b)}),e.jsxRuntimeExports.jsx("div",{className:"flex flex-col gap-2",children:e.jsxRuntimeExports.jsx(m,{theme:x,onDataChange:c,settings:y.map(b=>{var I;return(I=b==null?void 0:b.customCardPreferences)==null?void 0:I.settings}),data:y.map(b=>b!=null&&b.id?r==null?void 0:r[b.id]:[])})})]})]},(E=s.customCardPreferences)==null?void 0:E.componentName)})}function ws({className:s,...n}){var y;const t=e.useEditorStore(f=>f.card),r=((y=t.customCardPreferences)==null?void 0:y.showCardHeader)??!0,o=e.useEditorStore(f=>f.frame),i=e.useDashboardStore(f=>f.dashboard.filters);e.useEditorStore(f=>f.actions.setRunSql);const{updateFilter:a}=e.useDashboardActions(),l=i==null?void 0:i.find(f=>f.id===o.filterId),{data:x,isLoading:u,isFetching:d}=e.useDashboardCardQuery(t),{setCard:h}=e.useEditorActions(),{data:g}=e.useTopoJson(t);if(!t.id)return null;let c;x!=null&&x.records&&(x==null?void 0:x.records.length)>0&&(c=e.createChartConfig({data:x==null?void 0:x.records,cardType:t.type,cfg:t.cfg,customCfg:t.customCfg,preferences:t.preferences,topoJson:g}));function m(f){return e.jsxRuntimeExports.jsx(Et,{card:f})}function p(){var f;if(x!=null&&x.records&&(x==null?void 0:x.records.length)===0&&!u&&!d)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 m(t);if(!["table","custom"].includes(t.type)&&c)return e.jsxRuntimeExports.jsx(e.ChartJsVisual,{cfg:c},JSON.stringify(c)+JSON.stringify(t.preferences)+((f=t==null?void 0:t.preferences)==null?void 0:f.customVisualCode));if(t.type==="table"&&(x!=null&&x.records)&&(x==null?void 0:x.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:x==null?void 0:x.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:f=>h({...t,title:f}),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:f=>h({...t,description:f}),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:f=>a({...l,title:f}),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:p()})]})}const Ge=({language:s,value:n,onChange:t})=>e.jsxRuntimeExports.jsx(e.Ft,{className:"h-full w-full overflow-hidden text-xs",theme:"default",options:{minimap:{enabled:!1},wordWrap:"on",scrollbar:{verticalScrollbarSize:0,horizontalScrollbarSize:0},fontSize:12,lineHeight:16,renderLineHighlight:"none"},defaultLanguage:s,value:n,onChange:t}),gt=()=>e.jsxRuntimeExports.jsxs(e.DialogHeader,{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."})]})]}),Rt=({defaultConfig:s,customCode:n,customConfig:t,onConfigChange:r,onCodeChange:o})=>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.jsx(e.TabsTrigger,{value:"custom-config",children:t?"Custom Config":"Default Config"}),e.jsxRuntimeExports.jsx(e.TabsTrigger,{value:"output",children:"Output"}),e.jsxRuntimeExports.jsx(e.TabsTrigger,{value:"custom-code",children:"Custom Code"})]}),e.jsxRuntimeExports.jsx(e.TabsContent,{value:"output",className:"mt-0 grow rounded-b border border-t-0 p-2",children:e.jsxRuntimeExports.jsx(e.Textarea,{readOnly:!0,value:s,className:"h-full resize-none border-none font-mono focus-visible:ring-0"})}),e.jsxRuntimeExports.jsx(e.TabsContent,{value:"custom-config",className:"mt-0 grow rounded-b border border-t-0",children:e.jsxRuntimeExports.jsx(Ge,{language:"json",value:t,onChange:r})}),e.jsxRuntimeExports.jsx(e.TabsContent,{value:"custom-code",className:"mt-0 grow rounded-b border border-t-0",children:e.jsxRuntimeExports.jsx(Ge,{language:"javascript",value:n,onChange:o})})]}),bt=({error:s,hasCustomConfig:n,onReset:t,onApply:r,onClose:o})=>e.jsxRuntimeExports.jsxs(e.DialogFooter,{className:"flex items-center",children:[e.jsxRuntimeExports.jsx(e.Label,{className:"mr-2 text-red-500",children:s}),e.jsxRuntimeExports.jsx(e.Button,{disabled:!n,onClick:t,variant:"outline",children:"Reset"}),e.jsxRuntimeExports.jsx(e.Button,{onClick:r,variant:"outline",children:"Apply"}),e.jsxRuntimeExports.jsx(e.Button,{onClick:o,variant:"outline",children:"Close"})]});function St(){const[s,n]=S.useState(!1),[t,r]=S.useState(""),[o,i]=S.useState(""),[a,l]=S.useState(""),[x,u]=S.useState(""),d=e.useEditorStore(N=>N.card),h=e.useEditorStore(N=>N.card.customCfg),{data:g}=e.useDashboardCardQuery(d),{data:c}=e.useTopoJson(d),{setCardCustomCfg:m,setCustomVisualCode:p}=e.useEditorActions(),y=(N,v)=>e._.transform(N,(A,F,z)=>{if(!e._.isEqual(F,v[z]))if(e._.isArray(F)&&e._.isArray(v[z]))A[z]=v[z];else if(e._.isObject(F)&&e._.isObject(v[z])){const R=y(F,v[z]);e._.isEmpty(R)||(A[z]=R)}else A[z]=v[z]}),f=N=>{var v,A;return JSON.stringify({...N,data:{...N.data,datasets:(A=(v=N.data)==null?void 0:v.datasets)==null?void 0:A.map(F=>({...F,data:[]}))}},null,2)},O=()=>{var v,A;if(!((v=g==null?void 0:g.records)!=null&&v.length))return;const N=e.createChartConfig({data:g.records,cardType:d.type,cfg:d.cfg,preferences:d.preferences,topoJson:c});if(N){r(f(N)),l(((A=d.preferences)==null?void 0:A.customVisualCode)||"");const F=e._.merge(N,h);i(f(F))}},D=()=>{try{if(a&&p(a),o){const N=JSON.parse(o),v=y(JSON.parse(t),N);m(v),u("")}}catch{u("Invalid JSON configuration")}};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:O,size:"sm",variant:"outline",className:h?"border-foreground/50 dark:border-foreground/70":"",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.jsx(gt,{}),e.jsxRuntimeExports.jsxs("div",{className:"flex grow gap-2",children:[e.jsxRuntimeExports.jsx(e.ErrorBoundary,{FallbackComponent:e.FallbackEditorCard,children:e.jsxRuntimeExports.jsx(ws,{className:"w-1/2 rounded shadow-none"})}),e.jsxRuntimeExports.jsx(Rt,{defaultConfig:t,customCode:a,customConfig:o,onConfigChange:N=>i(N??""),onCodeChange:N=>l(N??"")})]}),e.jsxRuntimeExports.jsx(bt,{error:x,hasCustomConfig:!!h,onReset:()=>{i(t),m(null)},onApply:D,onClose:()=>n(!1)})]})]})}function ks(s){return se({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 Is(s){return se({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 Ds(s){return se({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 vt(s){return se({tag:"svg",attr:{viewBox:"0 0 256 256",fill:"currentColor"},child:[{tag:"path",attr:{d:"M48,180c0,11,7.18,20,16,20a14.24,14.24,0,0,0,10.22-4.66A8,8,0,0,1,85.78,206.4,30.06,30.06,0,0,1,64,216c-17.65,0-32-16.15-32-36s14.35-36,32-36a30.06,30.06,0,0,1,21.78,9.6,8,8,0,0,1-11.56,11.06A14.24,14.24,0,0,0,64,160C55.18,160,48,169,48,180Zm79.6-8.69c-4-1.16-8.14-2.35-10.45-3.84-1.25-.81-1.23-1-1.12-1.9a4.57,4.57,0,0,1,2-3.67c4.6-3.12,15.34-1.73,19.82-.56A8,8,0,0,0,142,145.86c-2.12-.55-21-5.22-32.84,2.76a20.58,20.58,0,0,0-9,14.95c-2,15.88,13.65,20.41,23,23.11,12.06,3.49,13.12,4.92,12.78,7.59-.31,2.41-1.26,3.34-2.14,3.93-4.6,3.06-15.17,1.56-19.55.36A8,8,0,0,0,109.94,214a61.34,61.34,0,0,0,15.19,2c5.82,0,12.3-1,17.49-4.46a20.82,20.82,0,0,0,9.19-15.23C154,179,137.49,174.17,127.6,171.31Zm83.09-26.84a8,8,0,0,0-10.23,4.84L188,184.21l-12.47-34.9a8,8,0,0,0-15.07,5.38l20,56a8,8,0,0,0,15.07,0l20-56A8,8,0,0,0,210.69,144.47ZM216,88v24a8,8,0,0,1-16,0V96H152a8,8,0,0,1-8-8V40H56v72a8,8,0,0,1-16,0V40A16,16,0,0,1,56,24h96a8,8,0,0,1,5.66,2.34l56,56A8,8,0,0,1,216,88Zm-27.31-8L160,51.31V80Z"},child:[]}]})(s)}function Ts(s){return se({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 Ls(s){return se({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 As(s){return se({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 zs(s){return se({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 Os(s){return se({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 Ms(s){const[n,t]=S.useState(null);return S.useEffect(()=>{s&&(async()=>{const i=(await Promise.resolve().then(()=>require("./lucide-react-CxAXGpsK.js")))[s];t(i)})()},[s]),n}function Fs(){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 yt({onChartTypeChange:s}){const[n,t]=S.useState([]),{data:r}=Fs();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 x=>(await e.loadManifest(x.value)).visuals.map(h=>({name:h.name,icon:h.icon,url:x.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(Ct,{text:o.name,onClick:()=>s("custom",o),icon:o.icon},o.url+o.name+i))})]})}const Ct=({text:s,icon:n,onClick:t})=>{const r=Ms(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 Nt(){var d,h;const[s,n]=S.useState(!1),t=e.useEditorStore(g=>g.card),r=t.type,{setCardType:o,setCardPreferences:i,setChartOrientation:a}=e.useEditorStore(g=>g.actions),{setCardCustomCfg:l,setCustomCardPreferences:x}=e.useEditorActions();function u(g,c){l(null),i({}),o(g),c&&x({type:"component",visualType:"single",url:c.url,componentName:c.name,icon:c.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(wt,{className:"h-4 w-4",chartType:r,customIcon:(d=t.customCardPreferences)==null?void 0:d.icon,componentName:(h=t.customCardPreferences)==null?void 0:h.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:()=>u("bar"),className:"font-normal",variant:"ghost",children:e.jsxRuntimeExports.jsx(ge,{className:"size-5"})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>u("line"),variant:"ghost",children:e.jsxRuntimeExports.jsx(Re,{className:"size-5"})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>u("stackedBar"),variant:"ghost",children:e.jsxRuntimeExports.jsx(As,{className:"size-5",strokeWidth:0})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>u("stackedLine"),variant:"ghost",children:e.jsxRuntimeExports.jsx(Ls,{className:"size-5",strokeWidth:0})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>u("scatter"),variant:"ghost",children:e.jsxRuntimeExports.jsx(De,{className:"size-5"})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>u("bubble"),variant:"ghost",children:e.jsxRuntimeExports.jsx(Ts,{className:"size-4"})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>u("pie"),variant:"ghost",children:e.jsxRuntimeExports.jsx(Ie,{className:"size-5"})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>u("doughnut"),variant:"ghost",children:e.jsxRuntimeExports.jsx(Is,{className:"size-5",strokeWidth:1})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>u("radar"),variant:"ghost",children:e.jsxRuntimeExports.jsx(ks,{className:"size-5 font-extralight",strokeWidth:.5})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>u("polarArea"),variant:"ghost",children:e.jsxRuntimeExports.jsx(Ds,{className:"size-5"})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>u("pyramid"),variant:"ghost",children:e.jsxRuntimeExports.jsx(Os,{className:"size-5"})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>u("range"),variant:"ghost",children:e.jsxRuntimeExports.jsx(ke,{className:"size-5"})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>u("table"),variant:"ghost",children:e.jsxRuntimeExports.jsx(Se,{className:"size-5"})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>u("kpi"),variant:"ghost",children:e.jsxRuntimeExports.jsx(zs,{className:"size-6"})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>u("text"),variant:"ghost",children:e.jsxRuntimeExports.jsx(ve,{className:"size-4"})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>u("map"),variant:"ghost",children:e.jsxRuntimeExports.jsx(Te,{className:"size-4"})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>u("custom"),variant:"ghost",children:e.jsxRuntimeExports.jsx(Le,{className:"size-4"})})]}),e.jsxRuntimeExports.jsx(yt,{onChartTypeChange:u})]})]})}function wt({chartType:s,className:n,customIcon:t,componentName:r}){const o=Ms(t||"");switch(s){case"bar":return e.jsxRuntimeExports.jsx(ge,{className:n});case"line":return e.jsxRuntimeExports.jsx(Re,{className:n});case"pie":return e.jsxRuntimeExports.jsx(Ie,{className:n});case"radar":return e.jsxRuntimeExports.jsx(ks,{className:n});case"scatter":return e.jsxRuntimeExports.jsx(De,{className:n});case"bubble":return e.jsxRuntimeExports.jsx(Ts,{className:n});case"doughnut":return e.jsxRuntimeExports.jsx(Is,{className:n});case"stackedBar":return e.jsxRuntimeExports.jsx(As,{className:"size-4 text-foreground/70"});case"stackedLine":return e.jsxRuntimeExports.jsx(Ls,{className:"size-4 text-foreground/70"});case"polarArea":return e.jsxRuntimeExports.jsx(Ds,{className:n});case"pyramid":return e.jsxRuntimeExports.jsx(Os,{className:n});case"range":return e.jsxRuntimeExports.jsx(ke,{className:n});case"kpi":return e.jsxRuntimeExports.jsx(zs,{className:n});case"text":return e.jsxRuntimeExports.jsx(ve,{className:n});case"map":return e.jsxRuntimeExports.jsx(Te,{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(Le,{className:n});default:return e.jsxRuntimeExports.jsx(Se,{className:n})}}function kt(){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(be,{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 Ue(){var j;const s=e.useEditorStore(E=>E.frame),n=e.useEditorStore(E=>E.card),t=e.useEditorStore(E=>E.isShowingVisual),r=e.useEditorStore(E=>E.isSqlRunning),o=e.useEditorStore(E=>E.pythonStdOut);e.useEditorStore(E=>E.actions.setRunSql);const{setFrame:i,setCard:a,updateCardInFrame:l,setActiveTabCardId:x}=e.useEditorActions(),{data:u,isLoading:d,isFetching:h,error:g}=e.useDashboardCardQuery(n);if(!n)return e.jsxRuntimeExports.jsx(e.jsxRuntimeExports.Fragment,{children:"No Active Card"});function c(){const E={connectionId:n.connectionId,id:e.v4(),title:"Title",description:"Description",preferences:{onClickFilter:[{columnIndex:0,expression:""}]},type:"bar",sql:"",data:[]};m(E)}function m(E){const b={...s,cards:[...s.cards,E],activeCardId:E.id};i(b),x(E.id)}function p(){const E={...n,id:e.v4(),title:`${n.title} Copy`,tabTitle:`${n.tabTitle||n.title} Copy`};m(E)}function y(E){const b=s.cards.filter(P=>P.id!==E),I=b[0],M={...s,cards:b,activeCardId:I.id};i(M),x(I.id),a(I)}function f(E){x(E)}const O=(E,b)=>{console.log("handleDragStart",b),E.dataTransfer.setData("tabIndex",b.toString())},D=E=>{E.preventDefault()},N=(E,b)=>{const I=E.dataTransfer.getData("tabIndex");if(I===b.toString())return;const M=Array.from(s.cards),[P]=M.splice(parseInt(I),1);M.splice(b,0,P),i({...s,cards:M})};function v(E,b){return E.cards.length===1&&(b.displayTab===!0||b.displayTab===void 0)||E.activeCardId!==b.id&&(b.displayTab===!0||b.displayTab===void 0)?null:e.jsxRuntimeExports.jsx("div",{onClick:()=>{const I=b.displayTab===void 0?!1:!b.displayTab;a({...b,displayTab:I}),l({...b,displayTab:I})},children:b.displayTab===!0||b.displayTab===void 0?e.jsxRuntimeExports.jsx(e.Eye,{className:"mr-2 size-3.5 text-muted-foreground hover:text-foreground"}):e.jsxRuntimeExports.jsx(es,{className:"mr-2 size-3.5 text-muted-foreground hover:text-foreground"})})}function A(){return e.jsxRuntimeExports.jsxs(e.Tabs,{onValueChange:f,value:s.activeCardId,className:"flex grow flex-col",children:[s.cards.map(E=>e.jsxRuntimeExports.jsx(e.TabsContent,{className:"mt-0 grow",value:E.id,children:F()},E.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((E,b)=>e.jsxRuntimeExports.jsx(e.Editable,{text:E.tabTitle||E.title,onSave:I=>{a({...n,tabTitle:I}),l({...n,tabTitle:I})},children:e.jsxRuntimeExports.jsxs(e.TabsTrigger,{draggable:!0,onDragStart:I=>O(I,b),onDragOver:D,onDrop:I=>N(I,b),className:"",value:E.id,children:[v(s,E),E.tabTitle||E.title,s.activeCardId===E.id&&s.cards.length>1&&e.jsxRuntimeExports.jsx(e.X,{className:"ml-2 size-3.5 text-muted-foreground hover:text-foreground",onClick:()=>y(E.id)})]})},E.id)),e.jsxRuntimeExports.jsx(e.Button,{className:"ml-1 h-8 px-2 hover:bg-muted-foreground/50",variant:"outline",onClick:c,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:p,children:e.jsxRuntimeExports.jsx(Ze,{className:"h-4 w-4"})})]})})]})}function F(){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:u==null?void 0:u.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:u==null?void 0:u.records})})})}):e.jsxRuntimeExports.jsx(e.ErrorBoundary,{FallbackComponent:e.FallbackEditorCard,children:e.jsxRuntimeExports.jsx(ws,{className:"grow border-none shadow-none"})})}function z(){const E=JSON.stringify(u==null?void 0:u.records,null,2),b=new Blob([E],{type:"application/json"}),I=URL.createObjectURL(b),M=document.createElement("a");M.href=I,M.download=`${n.title}.json`,M.click()}function R(){const b=[Object.keys(u==null?void 0:u.records.reduce((q,H)=>({...q,...H}),{})).join(","),...((u==null?void 0:u.records)||[]).map(q=>Object.values(q).join(","))].join(`
|
|
192
|
-
`),I=new Blob([b],{type:"text/csv"}),M=URL.createObjectURL(I),P=document.createElement("a");P.href=M,P.download=`${n.title}.csv`,P.click()}return e.jsxRuntimeExports.jsxs("div",{className:"relative flex h-full flex-col py-3",children:[(d||h)&&e.jsxRuntimeExports.jsx("div",{className:"absolute bottom-0 left-0 right-0 top-0 z-50 m-auto flex h-10 w-10 items-center justify-center rounded-md bg-muted",children:e.jsxRuntimeExports.jsx(xe,{className:"h-8 w-8 animate-spin text-muted-foreground"})}),e.jsxRuntimeExports.jsxs("div",{className:"mb-0 flex min-h-10 items-center justify-end gap-2 px-6",children:[t&&e.jsxRuntimeExports.jsxs("div",{className:"flex grow items-center gap-2",children:[e.jsxRuntimeExports.jsx(Nt,{}),!["table","custom"].includes(n.type)&&e.jsxRuntimeExports.jsx(St,{}),e.jsxRuntimeExports.jsx(kt,{})]}),!t&&e.jsxRuntimeExports.jsxs("div",{className:"flex grow items-center gap-1",children:[e.jsxRuntimeExports.jsx(e.Button,{className:"h-7 w-fit px-1 font-mono text-xs text-muted-foreground/70",variant:"ghost",size:"icon",onClick:R,children:e.jsxRuntimeExports.jsx(vt,{className:"size-4"})}),e.jsxRuntimeExports.jsx(e.Button,{className:"h-7 w-fit px-1 font-mono text-xs text-muted-foreground/70",variant:"ghost",size:"icon",onClick:z,children:e.jsxRuntimeExports.jsx(ss,{strokeWidth:1.5,className:"size-4"})}),e.jsxRuntimeExports.jsx(e.CopyButton,{text:JSON.stringify(u==null?void 0:u.records,null,2),className:"h-7 w-fit px-1 font-mono text-xs text-muted-foreground/70"})]}),e.jsxRuntimeExports.jsx(Dt,{})]}),t?A():e.jsxRuntimeExports.jsxs(e.ResizablePanelGroup,{className:"px-6",direction:"horizontal",children:[o&&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:o&&e.jsxRuntimeExports.jsx(It,{})}),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:[(u==null?void 0:u.records)&&(u==null?void 0:u.records.length)>0&&e.jsxRuntimeExports.jsx(ft,{data:(u==null?void 0:u.records)||[]}),(g||(u==null?void 0:u.error))&&e.jsxRuntimeExports.jsx("span",{className:"font-mono text-xs",children:(g==null?void 0:g.message)||((j=u==null?void 0:u.error)==null?void 0:j.message)}),e.jsxRuntimeExports.jsx(e.ScrollBar,{orientation:"horizontal"})]})})]})]})}function It(){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 Dt(){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 Tt({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 te({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 me({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 Lt(){var p,y;const s=e.useEditorStore(f=>f.card.customCardPreferences),{data:n}=Fs(),t=(n==null?void 0:n.plugins)||[],r=e.useEditorStore(f=>f.card),o=e.useEditorStore(f=>f.frame),i=(s==null?void 0:s.visualType)||"single",{setCustomCardPreferences:a}=e.useEditorActions(),{components:l,manifest:x}=e.useCustomVisual((s==null?void 0:s.url)||""),u=(p=x==null?void 0:x.visuals)==null?void 0:p.find(f=>f.name===(s==null?void 0:s.componentName));function d(f,O){if(!s)return;const N={...(s==null?void 0:s.dataInputCardIds)||{},[f]:{cardId:O,hookRef:null}};a({...s,dataInputCardIds:N})}function h(f){var D,N;const O=(D=o==null?void 0:o.cards)==null?void 0:D.filter(v=>{var A;return((A=v==null?void 0:v.customCardPreferences)==null?void 0:A.visualType)!=="multiple"}).map(v=>({value:v.id,label:v.tabTitle||v.title}));return e.jsxRuntimeExports.jsx("div",{className:"space-y-2",children:(N=f==null?void 0:f.dataInputs)==null?void 0:N.map((v,A)=>{var F,z;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:v}),e.jsxRuntimeExports.jsx(te,{className:"col-span-6 h-8 w-full justify-between",label:"",options:O||[],value:((z=(F=s==null?void 0:s.dataInputCardIds)==null?void 0:F[A])==null?void 0:z.cardId)||"",onValueChange:R=>d(A,R)})]},A+Math.random())})})}function g(f,O,D=[]){var N,v;return s?f==="input"?e.jsxRuntimeExports.jsx(e.Input,{className:`h-8 w-full ${e.removeRing}`,value:((N=s==null?void 0:s.settings)==null?void 0:N[O])||"",onChange:A=>{a({...s,settings:{...s==null?void 0:s.settings,[O]:A.target.value}})}},O):f==="select"?e.jsxRuntimeExports.jsx(te,{className:"h-8 w-full",label:"",options:D,value:((v=s==null?void 0:s.settings)==null?void 0:v[O])||"",onValueChange:A=>{a({...s,settings:{...s==null?void 0:s.settings,[O]:A}})}}):null:null}function c(f){const O=Object.entries((f==null?void 0:f.settings)||{});return e.jsxRuntimeExports.jsx("div",{className:"space-y-3",children:O.map(([D,N])=>e.jsxRuntimeExports.jsxs("div",{className:"space-y-2",children:[e.jsxRuntimeExports.jsx(e.Label,{children:N.title}),g(N.ui,D,N.options)]},D))})}function m(f){s&&a({...s,visualType:f,componentName:""})}return e.jsxRuntimeExports.jsxs("div",{className:"p-6",children:[e.jsxRuntimeExports.jsx(me,{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(te,{className:"h-8 w-full",label:"",options:t,value:(s==null?void 0:s.url)||"",onValueChange:f=>a({...s||{url:"",componentName:""},url:f})})})}),((s==null?void 0:s.type)==="component"||(s==null?void 0:s.type)===void 0)&&e.jsxRuntimeExports.jsx(Tt,{options:[{value:"single",label:"Single Visual"},{value:"multiple",label:"Multi-Visual"}],value:i,onValueChange:m}),((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(te,{className:"h-8 w-full",label:"",options:(l==null?void 0:l.filter(f=>f.type===i).map(f=>({value:f.name,label:f.name})))||[],value:s.componentName,onValueChange:f=>{console.log("changing value",f),a({...s,componentName:f})}})})]})})]})})}),e.jsxRuntimeExports.jsx(e.Separator,{className:"my-4"}),((y=r==null?void 0:r.customCardPreferences)==null?void 0:y.componentName)&&e.jsxRuntimeExports.jsxs(me,{summary:"Component Settings",children:[u&&u.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:h(u)})]}),u&&u.settings&&e.jsxRuntimeExports.jsx("div",{className:"space-y-3",children:e.jsxRuntimeExports.jsx("div",{className:"px-2",children:c(u)})})]})]})}function ae(){const[s,n]=S.useState([]);e.useEditorStore(d=>d.card.cfg);const t=e.useEditorStore(d=>d.card.preferences),{setCardCfg:r,setFilterOnClickColumnIndex:o,setCardPreferences:i}=e.useEditorStore(d=>d.actions),a=e.useEditorStore(d=>d.queryResultColumns);e.useEditorStore(d=>{var h;return(h=d.card.preferences)==null?void 0:h.filterOnClickColumnIndex}),S.useEffect(()=>{a&&n(new Array(a.length).fill(!1))},[a]);function l(d,h){var g,c;h?t!=null&&t.onClickFilter&&((g=t==null?void 0:t.onClickFilter)==null?void 0:g.length)>0?i({...t,onClickFilter:[...t.onClickFilter,{columnIndex:d,expression:""}]}):i({...t,onClickFilter:[{columnIndex:d,expression:""}]}):(i({...t,onClickFilter:(c=t==null?void 0:t.onClickFilter)==null?void 0:c.filter(m=>m.columnIndex!==d)}),n(m=>{const p=[...m];return p[d]=!1,p}))}function x(d,h){var c;const g=(c=t==null?void 0:t.onClickFilter)==null?void 0:c.map(m=>m.columnIndex===d?{...m,expression:h.target.value}:m);i({...t,onClickFilter:g})}function u(d){var h,g,c,m;if(s!=null&&s[d]||(g=(h=t==null?void 0:t.onClickFilter)==null?void 0:h.find(p=>p.columnIndex===d))!=null&&g.expression)return e.jsxRuntimeExports.jsx(e.Input,{value:(m=(c=t==null?void 0:t.onClickFilter)==null?void 0:c.find(p=>p.columnIndex===d))==null?void 0:m.expression,onChange:p=>x(d,p),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"}),a==null?void 0:a.map((d,h)=>{var g,c;return e.jsxRuntimeExports.jsx("div",{className:"xbg-red-100 group flex items-center justify-between space-y-2",children:e.jsxRuntimeExports.jsxs("div",{className:"grow",children:[e.jsxRuntimeExports.jsxs("div",{className:"flex items-center space-x-2 py-2",children:[e.jsxRuntimeExports.jsx(e.Checkbox,{checked:!!((g=t==null?void 0:t.onClickFilter)!=null&&g.find(m=>m.columnIndex===h)),onCheckedChange:m=>l(h,m)}),e.jsxRuntimeExports.jsx("label",{className:"text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70",children:d}),e.jsxRuntimeExports.jsx("div",{className:"flex items-center gap-2",children:((c=t==null?void 0:t.onClickFilter)==null?void 0:c.find(m=>m.columnIndex===h))&&e.jsxRuntimeExports.jsx(e.Pencil,{onClick:()=>{n(m=>{const p=[...m];return p[h]=!m[h],p})},className:"invisible size-3 cursor-pointer text-gray-400 group-hover:visible"})})]}),u(h)]})},d)})]})}function ye(){var a,l,x;const s=e.useEditorStore(u=>u.card.preferences),n=e.useEditorStore(u=>u.card.cfg),{setCardCfg:t,setCardPreferences:r,setChartOrientation:o}=e.useEditorStore(u=>u.actions);(a=n==null?void 0:n.options)!=null&&a.indexAxis;function i(u){o(u)}return e.jsxRuntimeExports.jsxs(e.RadioGroup,{value:((l=s==null?void 0:s.chartOptions)==null?void 0:l.indexAxis)||((x=n==null?void 0:n.options)==null?void 0:x.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 je="focus-visible:ring-0 focus-visible:ring-ring focus-visible:ring-offset-0";function $e(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 Vs(){var q,H,G,X,J,B;const[s,n]=S.useState(!1),t=e.useEditorStore(V=>{var T;return(T=V.card)==null?void 0:T.preferences}),r=e.useEditorStore(V=>{var T;return(T=V.card)==null?void 0:T.cfg}),o=e.getNumberAxis(t,r),[i,a]=S.useState($e(t)),[l,x]=S.useState(((G=(H=(q=t==null?void 0:t.chartOptions)==null?void 0:q.scales)==null?void 0:H[o])==null?void 0:G.min)||""),[u,d]=S.useState(((B=(J=(X=t==null?void 0:t.chartOptions)==null?void 0:X.scales)==null?void 0:J[o])==null?void 0:B.max)||""),[h,g]=S.useState(l||u?"custom":"auto"),[c,m]=S.useState(""),[p,y]=S.useState(0),[f,O]=S.useState(""),[D,N]=S.useState(""),[v,A]=S.useState(""),F=e.useEditorStore(V=>V.actions.setCardPreferences),{updateCardInFrame:z}=e.useEditorActions(),R=e.useEditorStore(V=>V.card),j=e.useEditorStore(V=>{var T;return(T=V.card)==null?void 0:T.type}),E=["pie","doughnut","polarArea"].includes(j);S.useEffect(()=>{var V,T,W,U,K,Q,$,Y,w,L,_,ne,le,oe;a($e(t)),x(((W=(T=(V=t==null?void 0:t.chartOptions)==null?void 0:V.scales)==null?void 0:T[o])==null?void 0:W.min)===0?0:""),d(((Q=(K=(U=t==null?void 0:t.chartOptions)==null?void 0:U.scales)==null?void 0:K[o])==null?void 0:Q.max)||""),m(((L=(w=(Y=($=t==null?void 0:t.chartOptions)==null?void 0:$.scales)==null?void 0:Y[o])==null?void 0:w.ticks)==null?void 0:L.stepSize)||""),y(((_=t==null?void 0:t.numberAxisFormat)==null?void 0:_.decimalPlaces)||0),O(((ne=t==null?void 0:t.numberAxisFormat)==null?void 0:ne.suffix)||""),N(((le=t==null?void 0:t.numberAxisFormat)==null?void 0:le.currency)||""),A(((oe=t==null?void 0:t.numberAxisFormat)==null?void 0:oe.locale)||"")},[s,t,o]);function b(V,T){return T===""||/^[0-9\b]+$/.test(T)?Number(T):Number(V)}function I(){const V=[...new Set(e.LOCALE_CURRENCY_PAIRS.map(T=>T.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:D||"none",onValueChange:T=>N(T==="none"?"":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,{children:e.jsxRuntimeExports.jsxs(e.SelectGroup,{children:[e.jsxRuntimeExports.jsx(e.SelectLabel,{children:"Currency"}),e.jsxRuntimeExports.jsx(e.SelectItem,{value:"none",children:"None"}),V.map(T=>e.jsxRuntimeExports.jsx(e.SelectItem,{value:T,children:T},T))]})})]}),e.jsxRuntimeExports.jsxs(e.Select,{value:v,onValueChange:T=>A(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,{children:e.jsxRuntimeExports.jsxs(e.SelectGroup,{children:[e.jsxRuntimeExports.jsx(e.SelectLabel,{children:"Locale"}),e.LOCALE_CURRENCY_PAIRS.map(T=>e.jsxRuntimeExports.jsx(e.SelectItem,{value:T.locale,children:T.locale},T.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:p,onChange:T=>y(Number(T.target.value)),id:"format",className:`col-span-6 h-8 w-full tracking-wide ${je}`})]})]})}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:V=>x(T=>b(T,V.target.value)),className:`col-span-1 h-8 w-full ${je}`}),e.jsxRuntimeExports.jsx(e.Input,{value:u,onChange:V=>d(T=>b(T,V.target.value)),id:"max",className:`col-span-1 h-8 w-full ${je}`})]}),e.jsxRuntimeExports.jsxs("div",{className:"grid grid-cols-3 items-center gap-2",children:[e.jsxRuntimeExports.jsx(e.Label,{htmlFor:"step-size",children:"Step Size"}),e.jsxRuntimeExports.jsx(e.Input,{value:c,onChange:V=>m(T=>b(T,V.target.value)),id:"step-size",className:`col-span-1 h-8 w-full ${je}`})]})]})}function P(){var U;let V={};h==="custom"&&(V={min:l,max:u,ticks:{stepSize:c}});const T={...t||{},chartOptions:{...t==null?void 0:t.chartOptions,scales:{...(U=t==null?void 0:t.chartOptions)==null?void 0:U.scales,[o]:{type:i,...i==="linear"?V:{}}}},numberAxisFormat:{decimalPlaces:p,suffix:f,currency:D,locale:v}};console.log(T),F(T);const W={...R,preferences:T};z(W)}return e.jsxRuntimeExports.jsxs(e.Popover,{onOpenChange:V=>n(V),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:E,value:i,onValueChange:V=>a(V),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:E,id:"scale-option",value:h,onValueChange:V=>g(V),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"})]})]})]}),h==="custom"&&i=="linear"&&M(),I(),e.jsxRuntimeExports.jsx(e.SelectSeparator,{}),e.jsxRuntimeExports.jsx("div",{className:"grid grid-cols-3",children:e.jsxRuntimeExports.jsx(e.Button,{onClick:P,variant:"secondary",className:"col-span-1 col-start-3 h-8 w-full",children:"Apply"})})]})]})})]})}function At({idx:s}){var l;const n=e.useEditorStore(x=>{var u;return(u=x.card)==null?void 0:u.preferences}),t=e.useEditorStore(x=>{var u;return(u=x.card.preferences)==null?void 0:u.datasetOptions}),r=e.useEditorStore(x=>x.actions.setCardPreferences),o=(l=n==null?void 0:n.chartOptions)==null?void 0:l.indexAxis,i=t==null?void 0:t.find(x=>x.idx===s);function a(x,u){(x==="end"||x==="start")&&e.getContrastColor(e.getCanvasBackgroundColor());const d={display:x!=="none",align:x,anchor:x,clamp:!0};if(!i)r({...n,datasetOptions:[...t||[],{idx:u,datalabels:d}]});else{const h={...i};h.datalabels=d;const g=t==null?void 0:t.map(c=>c.idx===u?h:c);r({...n,datasetOptions:g})}}return e.jsxRuntimeExports.jsxs(e.Popover,{children:[e.jsxRuntimeExports.jsx(e.PopoverTrigger,{children:e.jsxRuntimeExports.jsx(fs,{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:()=>a("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:()=>a("start",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"})})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>a("center",s),size:"sm",variant:"secondary",className:"h-7 p-1 text-xs font-normal",children:e.jsxRuntimeExports.jsx(ls,{className:e.cn("h-4 w-4",{"rotate-90":o==="y"})})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>a("end",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"})})})]})})]})}function qs(){const s=e.useEditorStore(u=>u.card),n=e.useEditorStore(u=>{var d,h,g;return(g=(h=(d=u==null?void 0:u.card)==null?void 0:d.preferences)==null?void 0:h.chartOptions)==null?void 0:g.indexAxis}),{data:t}=e.useDashboardCardQuery(s),r=n==="y"?"Y axis":"X axis",o=n==="y"?"X axis":"Y axis",{keys:i,metricKeys:a,dimensionKeys:l}=e.getKeys((t==null?void 0:t.records)||[]);let x=a;if(["stackedBar","stackedLine"].includes(s.type)){const u=e.pivotData({dataArray:(t==null?void 0:t.records)||[],groupKey:l[0],pivotKey:l[1],valueKey:x[0]}),{metricKeys:d}=e.getKeys(u);x=d}return i.length===0?null:e.jsxRuntimeExports.jsxs("div",{className:"space-y-4",children:[e.jsxRuntimeExports.jsxs("div",{className:"space-y-2",children:[e.jsxRuntimeExports.jsx(e.Label,{children:r}),e.jsxRuntimeExports.jsx("div",{className:"my-1 space-y-1",children:e.jsxRuntimeExports.jsx("div",{className:"rounded-md bg-muted/70 px-3 py-2 hover:bg-muted",children:e.jsxRuntimeExports.jsx("p",{title:l[0],children:Bs(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(Vs,{})]}),e.jsxRuntimeExports.jsx("div",{className:"my-1 max-h-[125px] space-y-1 overflow-y-auto",children:x.map((u,d)=>e.jsxRuntimeExports.jsx(zt,{col:u,idx:d},u))})]})]})}function Bs(s,n=30){return s.length>n?s.slice(0,n)+"...":s}function zt({col:s,idx:n}){const t=e.useEditorStore(l=>{var x;return(x=l.card)==null?void 0:x.preferences}),r=e.useEditorStore(l=>{var x;return(x=l.card.preferences)==null?void 0:x.datasetOptions}),o=r==null?void 0:r.find(l=>l.idx===n),{setCardPreferences:i}=e.useEditorStore(l=>l.actions);function a(l){if(!o)i({...t,datasetOptions:[...r||[],{idx:n,type:l==="area"?"line":l,fill:l==="area"?"origin":""}]});else{const x={...o};x.type=l==="area"?"line":l,x.fill=l==="area"?"origin":"";const u=r==null?void 0:r.map(d=>d.idx===n?x:d);i({...t,datasetOptions:u})}}return e.jsxRuntimeExports.jsxs("div",{className:"group flex items-center justify-between gap-5 rounded-md bg-muted/70 px-3 py-2 hover:bg-muted",children:[e.jsxRuntimeExports.jsx("p",{title:s,children:Bs(s)}),e.jsxRuntimeExports.jsxs("div",{className:"flex gap-2",children:[e.jsxRuntimeExports.jsx(ge,{onClick:()=>a("bar"),className:"invisible size-4 cursor-pointer text-muted-foreground hover:text-foreground group-hover:visible"}),e.jsxRuntimeExports.jsx(Re,{onClick:()=>a("line"),className:"invisible size-4 cursor-pointer text-muted-foreground hover:text-foreground group-hover:visible"}),e.jsxRuntimeExports.jsx(We,{onClick:()=>a("area"),className:"invisible size-4 cursor-pointer text-muted-foreground hover:text-foreground group-hover:visible"}),e.jsxRuntimeExports.jsx(At,{idx:n})]})]})}function _s(){const s=e.useEditorStore(c=>c.selectedConnectionId),n=e.useEditorStore(c=>c.selectedDatamodelId),t=e.useEditorStore(c=>c.selectedDatabaseName),r=e.useEditorStore(c=>c.selectedSchemaName),o=e.useEditorStore(c=>c.selectedTableName),i=e.useDashboardStore(c=>c.dashboard.filters)||[],a=e.useDashboardStore(c=>c.actions.addFilter),l=e.useDashboardStore(c=>c.actions.removeFilter),{removeFilterValues:x}=e.useDashboardActions(),{modelItems:u,tableName:d,connectionType:h}=re();function g(c,m="dashboard"){var F;const p=e.fmt(c.column_name),y=e.fmt(t||""),f=e.fmt(r||""),O=e.fmt(d);let D=e.getQualifiedTableName(f,O,h),N=`${D}.${p}`;const v=(F=u==null?void 0:u.find(z=>z.id===n))==null?void 0:F.name;n&&n!=="none"&&(N=`${e.DATAMODEL_NAMESPCACE}.${v}.${p}`,D=`${e.DATAMODEL_NAMESPCACE}.${v}`);const A=i==null?void 0:i.find(z=>z.column===N&&z.table===O&&(z.database===y||z.database===t));if(A)x(A.id),l(A.id);else{const z=e.v4();return d==="api"&&s?(a({location:m,id:z,column:N,title:c.column_name,dataType:c.data_type,table:"api",database:"",connectionId:s,operation:"in",sql:e.getDefaultFilterSql(c.data_type,D,p)}),z):(a({id:z,location:m,column:N,title:c.column_name,dataType:c.data_type,table:o||"",database:t||"",connectionId:s||"",operation:"in",sql:e.getDefaultFilterSql(c.data_type,D,p)}),z)}}return{assignFilter:g}}function ue(){const s=e.useDashboardStore(l=>l.dashboard.filters),n=e.useEditorStore(l=>l.frame),{setFrame:t}=e.useEditorActions(),{columns:r}=re(),{assignFilter:o}=_s();function i(l){const x=o(l,"frame");t({...n,filterId:x})}const a=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(Ot,{onSelect:i,columns:r}),a&&e.jsxRuntimeExports.jsx(e.FilterHeader,{filter:a})]})}function Ot({columns:s,onSelect:n}){var a;const[t,r]=_e.useState(!1),[o,i]=_e.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?(a=s.find(l=>l.column_name===o))==null?void 0:a.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:x=>{const u=x===o?"":x;i(u),r(!1),u&&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 Mt({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(ye,{}),e.jsxRuntimeExports.jsx(qs,{})]})]}),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(ue,{})]})]})]})})}function ze(){var o,i,a;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 d;const x={datalabels:{display:l!=="none",align:l,anchor:l,clamp:!0}},u={...s,options:{...s==null?void 0:s.options,plugins:{...(d=s==null?void 0:s.options)==null?void 0:d.plugins,...x}}};n(u),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(Vs,{})]}),e.jsxRuntimeExports.jsxs(e.Select,{value:(a=(i=(o=s==null?void 0:s.options)==null?void 0:o.plugins)==null?void 0:i.datalabels)==null?void 0:a.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 Ft({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(ze,{})})]}),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(ue,{})]})]})]})})}const Vt={datasets:[{type:"line",label:"Sum_sales",data:[]},{type:"bar",label:"Sum_profit",data:[]}]},qt={datasets:[{fill:"origin",type:"line",label:"Sum_sales",data:[]}]};function Bt(){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:_t(s)}),e.jsxRuntimeExports.jsx("section",{className:"",children:["line","bar"].includes(s)&&e.jsxRuntimeExports.jsx(ye,{})}),!["kpi"].includes(s)&&e.jsxRuntimeExports.jsxs("div",{className:"space-y-4",children:[e.jsxRuntimeExports.jsx(ze,{}),e.jsxRuntimeExports.jsx(ae,{}),e.jsxRuntimeExports.jsx(ue,{})]})]})}function _t(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(Vt,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(qt,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 Pt(){var x,u,d,h,g;const s=e.useEditorStore(c=>c.card.preferences),n=e.useEditorStore(c=>c.actions.setCardPreferences),t=e.useEditorStore(c=>c.actions.setNumberFormat);e.useEditorStore(c=>{var m,p;return(p=(m=c.card.preferences)==null?void 0:m.formatNumber)==null?void 0:p.decimalPlaces});const r=e.useEditorStore(c=>{var m,p;return(p=(m=c.card.preferences)==null?void 0:m.formatNumber)==null?void 0:p.locale}),o=e.useEditorStore(c=>{var m,p;return(p=(m=c.card.preferences)==null?void 0:m.formatNumber)==null?void 0:p.currency});e.useEditorStore(c=>c.actions.setFilterOnClickField);const i=e.useEditorStore(c=>{var m,p;return(p=(m=c.card.preferences)==null?void 0:m.formatNumber)==null?void 0:p.colorRanges})||[],a=e.useEditorStore(c=>c.actions.setColorRanges),l=[...new Set(e.LOCALE_CURRENCY_PAIRS.map(c=>c.currency))];return e.jsxRuntimeExports.jsxs("div",{children:[e.jsxRuntimeExports.jsxs("div",{className:"mb-3 flex items-center gap-2",children:[e.jsxRuntimeExports.jsx(e.Checkbox,{checked:!!((x=s==null?void 0:s.formatNumber)!=null&&x.enabled),onCheckedChange:c=>{n({...s,formatNumber:{...s==null?void 0:s.formatNumber,enabled:c}})}}),e.jsxRuntimeExports.jsx(e.Label,{children:"Format Number"})]}),((u=s==null?void 0:s.formatNumber)==null?void 0:u.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:c=>{var m,p,y;return t(((m=s==null?void 0:s.formatNumber)==null?void 0:m.decimalPlaces)||0,((p=s==null?void 0:s.formatNumber)==null?void 0:p.currency)||"",c,((y=s==null?void 0:s.formatNumber)==null?void 0:y.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(c=>e.jsxRuntimeExports.jsx(e.SelectItem,{value:c.locale,children:c.locale},c.locale))]})})]})]}),e.jsxRuntimeExports.jsxs("div",{className:"w-full space-y-1",children:[e.jsxRuntimeExports.jsx(e.Label,{children:"Currency"}),e.jsxRuntimeExports.jsxs(e.Select,{value:o||"none",onValueChange:c=>{var m,p,y;console.log("currency",c),t(((m=s==null?void 0:s.formatNumber)==null?void 0:m.decimalPlaces)||0,c==="none"?"":c,((p=s==null?void 0:s.formatNumber)==null?void 0:p.locale)||"",((y=s==null?void 0:s.formatNumber)==null?void 0:y.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(c=>e.jsxRuntimeExports.jsx(e.SelectItem,{value:c,children:c},c))]})})]})]})]}),e.jsxRuntimeExports.jsxs("div",{className:"flex gap-2",children:[e.jsxRuntimeExports.jsxs("div",{className:"w-full space-y-1",children:[e.jsxRuntimeExports.jsx(e.Label,{children:"Decimals"}),e.jsxRuntimeExports.jsxs(e.Select,{value:((h=(d=s==null?void 0:s.formatNumber)==null?void 0:d.decimalPlaces)==null?void 0:h.toString())||"0",onValueChange:c=>{var m,p,y;return t(Number(c),((m=s==null?void 0:s.formatNumber)==null?void 0:m.currency)||"",((p=s==null?void 0:s.formatNumber)==null?void 0:p.locale)||"",((y=s==null?void 0:s.formatNumber)==null?void 0:y.suffix)||"")},children:[e.jsxRuntimeExports.jsx(e.SelectTrigger,{className:"col-span-3 h-8 w-full focus:ring-1 focus:ring-offset-0",children:e.jsxRuntimeExports.jsx(e.SelectValue,{})}),e.jsxRuntimeExports.jsx(e.SelectContent,{children:["0","1","2","3","4"].map(c=>e.jsxRuntimeExports.jsx(e.SelectItem,{value:c,children:c},c))})]})]}),e.jsxRuntimeExports.jsxs("div",{className:"w-full space-y-1",children:[e.jsxRuntimeExports.jsx(e.Label,{children:"Suffix"}),e.jsxRuntimeExports.jsx(e.Input,{value:((g=s==null?void 0:s.formatNumber)==null?void 0:g.suffix)||"",className:"h-8 font-mono text-xs focus-visible:ring-0 focus-visible:ring-ring focus-visible:ring-offset-0",placeholder:"K, M, B, %",onChange:c=>{var m,p,y;return t(((m=s==null?void 0:s.formatNumber)==null?void 0:m.decimalPlaces)||0,((p=s==null?void 0:s.formatNumber)==null?void 0:p.currency)||"",((y=s==null?void 0:s.formatNumber)==null?void 0:y.locale)||"",c.target.value)}})]})]})]})}),e.jsxRuntimeExports.jsx(e.Separator,{className:"my-3"}),e.jsxRuntimeExports.jsx(e.ColorFormat,{colorRanges:i,setColorRanges:a})]})]})}function Ht(){return e.jsxRuntimeExports.jsxs("div",{className:"space-y-6 px-6 py-2",children:[e.jsxRuntimeExports.jsx(e.Accordion,{type:"single",collapsible:!0,children:e.jsxRuntimeExports.jsxs(e.AccordionItem,{value:"item-1",children:[e.jsxRuntimeExports.jsx(e.AccordionTrigger,{className:"",children:"KPI Query"}),e.jsxRuntimeExports.jsxs(e.AccordionContent,{className:"font-mono",children:[e.jsxRuntimeExports.jsx("div",{className:"rounded bg-muted px-2 py-1 font-mono text-xs",children:"SELECT current, previous FROM table"}),e.jsxRuntimeExports.jsxs("ul",{className:"my-6 ml-6 list-disc text-xs [&>li]:mt-2",children:[e.jsxRuntimeExports.jsx("li",{children:"current - number"}),e.jsxRuntimeExports.jsx("li",{children:"previous - number"})]}),e.jsxRuntimeExports.jsxs("div",{children:["See ",e.jsxRuntimeExports.jsx("a",{target:"_blank",onClick:s=>s.stopPropagation(),className:"text-blue-700",href:"https://docs.semaphor.cloud/concepts/visuals#kpi",children:"example"})," in the docs."]})]})]})}),e.jsxRuntimeExports.jsx("section",{className:"",children:e.jsxRuntimeExports.jsx(Pt,{})}),e.jsxRuntimeExports.jsx("div",{}),e.jsxRuntimeExports.jsx("div",{})]})}const Gt=[{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"}],Ut=["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"],$t=Ut.map(s=>({label:s,value:s}));function Qt(){var x,u,d,h,g,c,m,p,y,f,O,D,N,v,A,F,z,R;const s=e.useEditorStore(j=>j.card),n=(u=(x=s==null?void 0:s.preferences)==null?void 0:x.mapVisualOptions)==null?void 0:u.topoJsonUrl,[t,r]=S.useState(((h=(d=s==null?void 0:s.preferences)==null?void 0:d.mapVisualOptions)==null?void 0:h.customTopoJsonUrl)||""),{setCardPreferences:o}=e.useEditorActions(),{data:i}=e.useTopoJson(s),a=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(me,{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(me,{open:!0,summary:"Settings",children:e.jsxRuntimeExports.jsxs("div",{className:"space-y-3 px-2",children:[e.jsxRuntimeExports.jsx(te,{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(te,{className:"h-9",options:a,value:((c=(g=s.preferences)==null?void 0:g.mapVisualOptions)==null?void 0:c.objectKey)||"",label:"Map Object",onValueChange:j=>{var E;o({...s.preferences,mapVisualOptions:{...(E=s.preferences)==null?void 0:E.mapVisualOptions,objectKey:j}})}})]}),e.jsxRuntimeExports.jsxs("div",{className:"space-y-1",children:[e.jsxRuntimeExports.jsx(e.Label,{children:"Projection"}),e.jsxRuntimeExports.jsx(te,{className:"h-9",options:Gt,value:((p=(m=s.preferences)==null?void 0:m.mapVisualOptions)==null?void 0:p.projection)||"",label:"Projection",onValueChange:j=>{var E;o({...s.preferences,mapVisualOptions:{...(E=s.preferences)==null?void 0:E.mapVisualOptions,projection:j}})}})]}),e.jsxRuntimeExports.jsxs("div",{className:"space-y-1",children:[e.jsxRuntimeExports.jsx(e.Label,{children:"Colors"}),e.jsxRuntimeExports.jsx(te,{className:"h-9",options:$t,value:((f=(y=s.preferences)==null?void 0:y.mapVisualOptions)==null?void 0:f.colorScale)||"",label:"Select Color Scale",onValueChange:j=>{var E;o({...s.preferences,mapVisualOptions:{...(E=s.preferences)==null?void 0:E.mapVisualOptions,colorScale:j}})}})]})]})]})}),e.jsxRuntimeExports.jsx(e.Separator,{className:"my-4"}),e.jsxRuntimeExports.jsx(me,{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:((D=(O=s.preferences)==null?void 0:O.mapVisualOptions)==null?void 0:D.projectionScale)||1,onChange:j=>{var E;o({...s.preferences,mapVisualOptions:{...(E=s.preferences)==null?void 0:E.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:((A=(v=(N=s.preferences)==null?void 0:N.mapVisualOptions)==null?void 0:v.projectionOffset)==null?void 0:A[0])||0,onChange:j=>{var E,b,I,M;o({...s.preferences,mapVisualOptions:{...(E=s.preferences)==null?void 0:E.mapVisualOptions,projectionOffset:[Number(j.target.value),((M=(I=(b=s.preferences)==null?void 0:b.mapVisualOptions)==null?void 0:I.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=(z=(F=s.preferences)==null?void 0:F.mapVisualOptions)==null?void 0:z.projectionOffset)==null?void 0:R[1])||0,onChange:j=>{var E,b,I,M;o({...s.preferences,mapVisualOptions:{...(E=s.preferences)==null?void 0:E.mapVisualOptions,projectionOffset:[((M=(I=(b=s.preferences)==null?void 0:b.mapVisualOptions)==null?void 0:I.projectionOffset)==null?void 0:M[0])||0,Number(j.target.value)]}})}})]})}),e.jsxRuntimeExports.jsx(e.Separator,{className:"my-4"}),e.jsxRuntimeExports.jsx(ae,{})]})}function Jt(){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 he({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(ye,{}),s!=="text"&&e.jsxRuntimeExports.jsx(ze,{}),s==="text"&&e.jsxRuntimeExports.jsx(Jt,{})]})]}),!["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(ue,{})]})]})]})})}function Wt(){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(te,{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(ye,{}),t(),e.jsxRuntimeExports.jsx(qs,{})]})]}),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(ue,{})]})]})]})})}function Kt({}){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(ue,{})]})]})}),e.jsxRuntimeExports.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsxRuntimeExports.jsx(e.Checkbox,{onCheckedChange:t,id:"allow-download"}),e.jsxRuntimeExports.jsx("label",{htmlFor:"allow-download",className:"text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70",children:"Allow Download"})]})]})}const Zt=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."]})]}),Xt=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."]})]}),Yt=e.jsxRuntimeExports.jsxs("div",{className:"space-y-4 font-mono text-xs",children:[e.jsxRuntimeExports.jsx("div",{className:"rounded bg-muted px-2 py-1 text-xs",children:"SELECT 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 en(){const s=e.useEditorStore(t=>t.card.type);function n(t){switch(t){case"stackedBar":case"stackedLine":return e.jsxRuntimeExports.jsx(Wt,{});case"pyramid":return e.jsxRuntimeExports.jsx(he,{docContent:Zt,cardType:t});case"kpi":return e.jsxRuntimeExports.jsx(Ht,{});case"line":case"bar":return e.jsxRuntimeExports.jsx(Mt,{cardType:t});case"range":return e.jsxRuntimeExports.jsx(he,{docContent:Xt,cardType:t});case"pie":case"doughnut":case"polarArea":case"radar":return e.jsxRuntimeExports.jsx(he,{cardType:t});case"bubble":case"scatter":return e.jsxRuntimeExports.jsx(Ft,{cardType:t});case"table":return e.jsxRuntimeExports.jsx(Kt,{cardType:t});case"text":return e.jsxRuntimeExports.jsx(he,{docContent:Yt,cardType:t,suffix:"Visual"});case"map":return e.jsxRuntimeExports.jsx(Qt,{});case"custom":return e.jsxRuntimeExports.jsx(Lt,{});default:return e.jsxRuntimeExports.jsx(Bt,{})}}return e.jsxRuntimeExports.jsxs(e.ScrollArea,{className:"h-full w-full text-sm",children:[n(s),e.jsxRuntimeExports.jsx(e.ScrollBar,{orientation:"horizontal"})]})}function sn(){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(ht,{})}),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(en,{})})}),e.jsxRuntimeExports.jsx(e.ResizableHandle,{className:"border"}),e.jsxRuntimeExports.jsx(e.ResizablePanel,{minSize:40,defaultSize:75,maxSize:100,children:e.jsxRuntimeExports.jsx(Ue,{})})]}):e.jsxRuntimeExports.jsx(Ue,{})})]})}function tn({authToken:s,onSave:n,onClose:t}){e.useDashboardStore(a=>a.themeStyle);const r=e.useEditorStore(a=>a.actions.setOnSave),o=e.useEditorStore(a=>a.actions.setOnClose),i=e.useDashboardStore(a=>a.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(vs,{})}),e.jsxRuntimeExports.jsx(e.EditorMain,{children:e.jsxRuntimeExports.jsx(sn,{})})]})})}function nn(){e.useDashboardStore(a=>a.selectedCardId);const s=e.useDashboardStore(a=>a.selectedSheetId),{setIsVisualEditing:n}=e.useDashboardStore(a=>a.actions),t=e.useDashboardStore(a=>a.isVisualEditing),r=e.useDashboardStore(a=>a.actions.updateFrame);function o(a){s&&(r(s,a),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(tn,{onSave:o,onClose:i})})}function rn(){const s=e.useEditorStore(i=>i.selectedDatabaseName),n=e.useEditorStore(i=>i.selectedTableName),t=e.useDashboardStore(i=>i.dashboard.filters)||[],{columns:r}=re(),{assignFilter:o}=_s();return e.jsxRuntimeExports.jsx(e.ScrollArea,{className:"flex-1 basis-0 flex-col px-3",children:r==null?void 0:r.map(i=>{const a=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":a}),children:e.jsxRuntimeExports.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxRuntimeExports.jsx(Ss,{column:i}),e.jsxRuntimeExports.jsx("span",{children:i.column_name})]})},i.column_name)})})}function on(){e.useDashboardStore(n=>n.showFilters);const s=e.useDashboardStore(n=>n.actions.setShowFilters);return e.jsxRuntimeExports.jsxs("section",{className:"relative flex min-w-[320px] grow flex-col border-l px-1",children:[e.jsxRuntimeExports.jsxs("div",{className:"mt-4 flex items-center justify-between gap-2 px-3",children:[e.jsxRuntimeExports.jsx(e.Label,{className:"px-2 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(vs,{ColumnsComponent:()=>e.jsxRuntimeExports.jsx(rn,{})})})]})}function an(){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("div",{className:e.cn("mb-1 flex items-center gap-2 border-y px-0.5 pb-0.5",{"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 min-w-[250px] max-w-fit 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 ln(){const s=e.useDashboardStore(r=>r.showFilters),n=e.useDashboardStore(r=>r.isVisualEditing),t=e.useDashboardStore(r=>r.isDashboardEditing);return e.jsxRuntimeExports.jsxs("div",{role:"dashboard-plus-main",className:e.cn("",{"max-h-0 overflow-hidden":n,"flex grow overflow-auto":!n}),children:[e.jsxRuntimeExports.jsxs("section",{className:"flex grow flex-col",children:[t&&e.jsxRuntimeExports.jsx(an,{}),e.jsxRuntimeExports.jsx(e.DashboardTabs,{})]}),s&&e.jsxRuntimeExports.jsx("div",{role:"filter-aside-container",className:"flex",children:e.jsxRuntimeExports.jsx(on,{})})]})}function cn(){const s=e.useDashboardStore(o=>o.dashboard),n=e.useDashboardStore(o=>o.actions.setDashboard),t=e.useDashboardStore(o=>o.showDashboardJSON),r=e.useDashboardStore(o=>o.actions.setShowDashboardJSON);return e.jsxRuntimeExports.jsxs("div",{className:e.cn("relative p-2",{hidden:!t}),children:[e.jsxRuntimeExports.jsxs(e.Button,{variant:"secondary",size:"sm",className:"absolute right-2 top-2 z-10 h-8",onClick:()=>r(!1),children:[e.jsxRuntimeExports.jsx(e.X,{className:"mr-2 h-4 w-4"}),"Close"]}),e.jsxRuntimeExports.jsx(e.de,{onChange:o=>{if(o)try{JSON.parse(o),n(JSON.parse(o))}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 xn({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(cn,{}),e.jsxRuntimeExports.jsxs(e.DashboardPanel,{...t,children:[s&&e.jsxRuntimeExports.jsx(Ks,{}),e.jsxRuntimeExports.jsx(nn,{}),e.jsxRuntimeExports.jsx(ln,{})]})]})]})})}exports.Box=Qe;exports.Braces=Je;exports.ChartArea=We;exports.ChartColumnIncreasing=ge;exports.ChartLine=Re;exports.ChartNoAxesGantt=ke;exports.ChartPie=Ie;exports.ChartScatter=De;exports.CircleX=Ke;exports.CopyPlus=Ze;exports.DashboardPlus=xn;exports.Database=Xe;exports.EllipsisVertical=be;exports.Eraser=Ye;exports.EyeClosed=es;exports.FileJson2=ss;exports.Glasses=ts;exports.Hammer=ns;exports.Hash=rs;exports.House=os;exports.ListEnd=is;exports.ListStart=as;exports.ListX=ls;exports.LoaderCircle=xe;exports.Map=Te;exports.MessageSquareMore=cs;exports.Network=xs;exports.Plug2=us;exports.RefreshCw=ds;exports.Save=ms;exports.SelectComponent=ce;exports.Shapes=Le;exports.ShieldQuestion=ps;exports.Sigma=js;exports.SwatchBook=hs;exports.Table=Se;exports.Tag=fs;exports.TicketX=Es;exports.ToggleLeft=gs;exports.Type=ve;exports.cleanCard=Rs;exports.downloadPdf=bs;exports.getDashbaordStateWithoutData=Ae;exports.useEditorAside=re;
|
|
191
|
+
*/const ve=e.createLucideIcon("Type",[["polyline",{points:"4 7 4 4 20 4 20 7",key:"1nosan"}],["line",{x1:"9",x2:"15",y1:"20",y2:"20",key:"swin9y"}],["line",{x1:"12",x2:"12",y1:"4",y2:"20",key:"1tx1rr"}]]);function Ae(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(a=>Rs(a))}})}})}}function Rs(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:Gs(s.customCfg),data:[]}}function Gs(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 Us(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 we(s,n){if(!n)return null;const{id:t,template:r,filterValues:o,isDefault:i,shared:a}=s;return await e.postRequest("https://semaphor.cloud/api/v1/lens",n,{lensId:t,template:r,filterValues:o,isDefault:i,shared:a,operation:"update"})}async function $s(s,n){return n?await e.postRequest("https://semaphor.cloud/api/v1/lens",n,{operation:"delete",lensId:s}):null}function Qs(){const[s,n]=S.useState(""),[t,r]=S.useState(!1),o=e.useDashboardStore(p=>p.lenses),{setLenses:i,setSelectedLensId:a}=e.useDashboardActions(),[l,x]=S.useState(!1),[u,d]=S.useState(!1),h=e.useDashboardStore(p=>p.dashboard),g=e.useDashboardStore(p=>p.filterValues),{authToken:c}=e.useSemaphorContext();async function m(){x(!0);const p=Ae(h),y=await Us(s,p,g,c==null?void 0:c.accessToken);y&&(i([...o||[],y]),a(y.id),d(!1)),x(!1)}return e.jsxRuntimeExports.jsxs(e.Dialog,{open:u,onOpenChange:d,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:p=>{n(p.target.value)},id:"name",className:"col-span-7 focus-visible:ring-0 focus-visible:ring-ring focus-visible:ring-offset-0"})]})}),t&&e.jsxRuntimeExports.jsx("p",{className:"text-sm",children:"The lens name already exists. Use a differnet name."}),e.jsxRuntimeExports.jsx(e.DialogFooter,{children:e.jsxRuntimeExports.jsx(e.Button,{size:"sm",variant:"outline",type:"submit",onClick:m,disabled:l,children:l?"Creating...":"Add"})})]})]})}function Js(){const[s,n]=S.useState(!1),t=e.useDashboardStore(d=>d.lenses),r=e.useDashboardStore(d=>d.selectedLensId),{setLenses:o,setSelectedLensId:i}=e.useDashboardActions(),{authToken:a}=e.useSemaphorContext();async function l(d){i(d)}async function x(d){if(await $s(d,a==null?void 0:a.accessToken)){const g=t==null?void 0:t.filter(c=>c.id!==d);o(g||[]),i("original")}}async function u(d){const h=t==null?void 0:t.map(m=>m.id===d.id?{...m,isDefault:!d.isDefault}:{...m,isDefault:!1});o(h||[]);const g={...d,isDefault:!d.isDefault};await we(g,a==null?void 0:a.accessToken);const c=t==null?void 0:t.find(m=>m.isDefault);if(c&&c.id!==d.id){const m={...c,isDefault:!1};await we(m,a==null?void 0:a.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(ts,{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(d=>e.jsxRuntimeExports.jsxs(e.DropdownMenuRadioItem,{className:"group flex justify-between gap-2",value:d.id,children:[e.jsxRuntimeExports.jsx("p",{children:d.name}),e.jsxRuntimeExports.jsxs("span",{className:"flex items-center gap-3",children:[e.jsxRuntimeExports.jsx(os,{onClick:h=>{h.preventDefault(),u(d)},className:e.cn("size-3.5 text-muted-foreground hover:cursor-pointer hover:text-foreground group-hover:visible",{invisible:!d.isDefault,"text-green-500":d.isDefault}),strokeWidth:1.5}),e.jsxRuntimeExports.jsx(e.Cross2Icon,{onClick:h=>{h.preventDefault(),x(d.id)},className:"invisible size-3.5 text-muted-foreground hover:cursor-pointer hover:text-foreground group-hover:visible",strokeWidth:1.5})]})]},d.id))]})]})]})}async function bs(){var c;const s=e.useDashboardStore.getState().authToken,n=e.useDashboardStore.getState().theme,t=e.useDashboardStore.getState().filterValues,r=(c=e.useDashboardStore.getState().dashboard)==null?void 0:c.title,o=e.useDashboardStore.getState().isDownloadingPdf,i=e.useDashboardStore.getState().selectedSheetId;if(o)return;const a=new URLSearchParams;a.set("token",(s==null?void 0:s.accessToken)||""),a.set("theme",n||"light"),a.set("filterValues",JSON.stringify(t)),a.set("selectedSheetId",i||"");const l=`https://semaphor.cloud/api/v1/generate-pdf?params=${encodeURIComponent(a.toString())}`;e.useDashboardStore.setState({isDownloadingPdf:!0});const d=(await(await fetch(l,{method:"GET",headers:{Authorization:`Bearer ${s==null?void 0:s.accessToken}`}})).json()).url,h=document.createElement("a");h.href=d;const g=`${r}-${new Date().toISOString()}.pdf`;h.download=g,h.click(),e.useDashboardStore.setState({isDownloadingPdf:!1})}function Ws({iconClassName:s}){e.useSemaphorContext(),e.useDashboardStore(r=>{var o;return(o=r.dashboard)==null?void 0:o.title}),e.useDashboardStore(r=>r.theme),e.useDashboardStore(r=>r.filterValues);const n=e.useDashboardStore(r=>r.isDownloadingPdf);async function t(){await bs()}return e.jsxRuntimeExports.jsx(e.Button,{variant:"link",className:"group h-7 p-2",size:"sm",onClick:t,children:n?e.jsxRuntimeExports.jsx(xe,{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 Ks(){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),a=e.useEditorStore(j=>j.selectedConnectionId),[l,x]=S.useState(!1),u=e.useDashboardStore(j=>j.filterValues),d=e.useDashboardStore(j=>j.isVisualEditing),h=e.useDashboardStore(j=>j.showFilters);e.useDashboardStore(j=>j.showDashboardJSON);const g=e.useDashboardStore(j=>j.onSaveFunction),c=e.useDashboardStore(j=>j.actions.setShowFilters),{addFrame:m,setSelectedFrameId:p}=e.useDashboardStore(j=>j.actions),{getSelectedSheet:y,setIsDashboardEditing:f,setShowDashboardJSON:O}=e.useDashboardStore(j=>j.actions),D=y(),{tenantId:N,endUserId:v}=S.useMemo(()=>e.getTenantAndEndUserId(s==null?void 0:s.accessToken),[s==null?void 0:s.accessToken]),A=S.useMemo(()=>N||v,[N,v]),F=()=>{if(!i||!D)return;const j={connectionId:a,id:e.v4(),title:"Title",description:"Description",preferences:{onClickFilter:[{columnIndex:0,expression:""}]},type:"bar",sql:"select COUNT(*) from YOUR_TABLE",data:[]},E={id:e.v4(),cards:[j],activeCardId:j.id};m(D.id,E),p(E.id)},z=()=>{f(!0)};async function R(){if(x(!0),!t||!r)return;const j=Ae(o),E=JSON.stringify(j),b={...r,template:E,filterValues:u};await we(b,s==null?void 0:s.accessToken),e.ce.success("Lens saved"),g==null||g(j),x(!1)}return d?null:e.jsxRuntimeExports.jsxs("div",{className:"flex items-center justify-between gap-2 border-b bg-muted/50 py-2 pl-3 pr-2",role:"dashboard-controls",children:[!d&&e.jsxRuntimeExports.jsx("div",{className:"flex items-center gap-3",children:e.jsxRuntimeExports.jsx(e.Label,{children:r==null?void 0:r.name})}),e.jsxRuntimeExports.jsxs("div",{className:"flex gap-2",children:[e.jsxRuntimeExports.jsx("button",{onClick:e.invalidateToken,children:e.jsxRuntimeExports.jsx(Es,{className:"h-4 w-4",strokeWidth:1.5})}),e.jsxRuntimeExports.jsx(Ws,{}),i&&!d&&A&&e.jsxRuntimeExports.jsx(Qs,{}),!d&&A&&e.jsxRuntimeExports.jsx(Js,{}),i&&!d&&e.jsxRuntimeExports.jsxs(e.Button,{variant:"secondary",className:"h-7 p-2",size:"sm",disabled:!i,onClick:F,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:z,size:"sm",children:e.jsxRuntimeExports.jsx(e.Pencil,{className:"h-4 w-4",strokeWidth:1.5})}),i&&!d&&e.jsxRuntimeExports.jsx(e.Button,{variant:"ghost",role:"close",className:"h-7 p-2",onClick:()=>{f(!1),O(!1)},size:"sm",children:e.jsxRuntimeExports.jsx(e.Cross2Icon,{className:"h-4 w-4",strokeWidth:1.5})}),i&&!d&&A&&e.jsxRuntimeExports.jsx(e.Button,{className:"h-7 p-2",variant:"ghost",disabled:l,onClick:R,size:"sm",children:e.jsxRuntimeExports.jsx(ms,{className:"h-4 w-4",strokeWidth:1.5})}),!h&&!d&&i&&e.jsxRuntimeExports.jsx(e.Button,{className:"h-7 p-2",variant:"ghost",onClick:()=>c(!0),size:"sm",children:e.jsxRuntimeExports.jsx(e.Filter,{className:"h-4 w-4",strokeWidth:1.5})}),!d&&i&&!1,!d&&!1]})]})}function ce({title:s,items:n,value:t,isLoading:r,isError:o,refetch:i,connectionTooltip:a,onChange:l,showNone:x=!1,className:u,showIcon:d=!0,disabled:h=!1}){const g=r?"Loading...":o?"Error":t;function c(){if(s==="Connection")return e.jsxRuntimeExports.jsx(us,{className:"size-4 rotate-90"});if(s==="Database")return e.jsxRuntimeExports.jsx(Xe,{className:"size-4"});if(s==="Schema")return e.jsxRuntimeExports.jsx(xs,{className:"size-4"});if(s==="Table")return e.jsxRuntimeExports.jsx(Se,{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:[d&&e.jsxRuntimeExports.jsx("div",{className:"shrink-0",children:a?e.jsxRuntimeExports.jsxs(e.Tooltip,{children:[e.jsxRuntimeExports.jsx(e.TooltipTrigger,{children:c()}),e.jsxRuntimeExports.jsx(e.TooltipContent,{className:"text-xs",align:"start",children:a})]}):c()}),e.jsxRuntimeExports.jsxs(e.Select,{disabled:h,value:g,onValueChange:l,children:[e.jsxRuntimeExports.jsx(e.SelectTrigger,{className:e.cn("h-9 w-full focus:ring-1 focus:ring-offset-0",u),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.jsxs(e.SelectLabel,{className:"flex items-center justify-between gap-2",children:[s,e.jsxRuntimeExports.jsx(ds,{className:"mr-1 size-3 cursor-pointer text-muted-foreground hover:text-foreground",onClick:i})]}),e.jsxRuntimeExports.jsxs(e.jsxRuntimeExports.Fragment,{children:[x&&e.jsxRuntimeExports.jsx(e.SelectItem,{value:"none",children:"None"},"none"),n&&n.map((m,p)=>e.jsxRuntimeExports.jsx(e.SelectItem,{value:m.id,children:m.name},p))]}),(r||o)&&e.jsxRuntimeExports.jsx(e.SelectItem,{value:g,children:g})]})})]})]})}function Zs({column:s}){const[n,t]=S.useState(!1),r=e.useEditorStore(m=>m.selectedTableName),o=e.useEditorStore(m=>m.selectedSchemaName),i=e.useEditorStore(m=>m.selectedDatamodelId),a=e.useEditorStore(m=>m.sqlGen),{modelItems:l,connectionType:x}=re(),u=e.useEditorStore(m=>m.actions.setSqlGen),d=e.useEditorStore(m=>m.actions.setCardSql),h=e.useEditorStore(m=>m.actions.setRunSql);function g(m,p){var D;const y=e.createSqlGenConfig(m,a,p),f=(D=l==null?void 0:l.find(N=>N.id===i))==null?void 0:D.name;u(y);const O=e.getSql(y,e.fmt(o||""),e.fmt(r),f,x);O&&(d(O),h(!0)),t(!1)}function c(){return e.jsxRuntimeExports.jsxs("ul",{className:"text-xs",children:[e.jsxRuntimeExports.jsx("li",{onClick:()=>g(s,"COUNT"),className:"cursor-pointer p-1 px-3 transition-colors hover:bg-muted",children:"Count"}),e.jsxRuntimeExports.jsx("li",{onClick:()=>g(s,"AVG"),className:"cursor-pointer p-1 px-3 transition-colors hover:bg-muted",children:"Avg"}),e.jsxRuntimeExports.jsx("li",{onClick:()=>g(s,"SUM"),className:"cursor-pointer p-1 px-3 transition-colors hover:bg-muted",children:"Sum"}),e.jsxRuntimeExports.jsx("li",{onClick:()=>g(s,"MAX"),className:"cursor-pointer p-1 px-3 transition-colors hover:bg-muted",children:"Max"}),e.jsxRuntimeExports.jsx("li",{onClick:()=>g(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(be,{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:c()})]})}function Ss({column:s}){return e.jsxRuntimeExports.jsxs(e.Tooltip,{children:[e.jsxRuntimeExports.jsx(e.TooltipTrigger$1,{asChild:!0,children:e.isTextDataType(s.data_type)?e.jsxRuntimeExports.jsx(ve,{className:"size-3"}):e.isNumberDataType(s.data_type)?e.jsxRuntimeExports.jsx(rs,{className:"size-3"}):e.isDateDataType(s.data_type)?e.jsxRuntimeExports.jsx(e.Calendar,{className:"size-3"}):e.isBooleanDataType(s.data_type)?e.jsxRuntimeExports.jsx(gs,{className:"size-3"}):s.data_type.toLowerCase()==="json"?e.jsxRuntimeExports.jsx(Je,{className:"size-3"}):e.jsxRuntimeExports.jsx(ps,{className:"size-3"})}),e.jsxRuntimeExports.jsx(e.TooltipContent,{children:e.jsxRuntimeExports.jsx("p",{className:"font-mono text-xs",children:s.data_type})})]})}function Xs({schemaName:s,tableName:n,columns:t,status:r}){const o=e.useEditorStore(R=>R.sqlGen),i=e.useEditorStore(R=>R.selectedConnectionId),a=e.useEditorStore(R=>R.selectedDatabaseName),l=e.useEditorStore(R=>R.selectedSchemaName),x=e.useEditorStore(R=>R.selectedTableName),u=e.useEditorStore(R=>R.selectedDatamodelId),d=e.useDashboardStore(R=>R.dashboard.aiScopeTables),{addToAIScope:h,removeFromAIScope:g}=e.useDashboardActions();e.useDashboardStore(R=>R.actions);const c=e.useEditorStore(R=>R.actions.setRunSql),m=e.useEditorStore(R=>R.actions.setSqlGen),p=e.useEditorStore(R=>R.actions.setIsShowingVisual),y=e.useEditorStore(R=>R.actions.setCardSql),{connectionType:f,modelItems:O,selectedDatamodelName:D}=re();function N(R){var I;const j=e.createSqlGenConfig(R,o);m(j);const E=(I=O==null?void 0:O.find(M=>M.id===u))==null?void 0:I.name,b=e.getSql(j,e.fmt(s),e.fmt(n),E,f);b&&(y(b),c(!0))}function v(){return(d==null?void 0:d.find(R=>R.connectionId===i&&(R.tableName===x||R.datamodelName===D)))!==void 0}function A(R){R===!0&&(x||D)&&i?(h({connectionId:i,connectionType:f==="S3"||f==="API"?"DuckDb":f,databaseName:a,schemaName:l,tableName:x,datamodelName:D}),e.ce.success("Added to Assistant Scope",{position:"top-right",duration:2500,richColors:!0})):(g({connectionId:i||"",connectionType:f||"",tableName:x||"",datamodelName:D||""}),e.ce("Removed from Assistant Scope",{position:"top-right",duration:2e3,richColors:!0}))}function F(){const R=e.getFormattedTableNameForQuery({schemaName:s,tableName:n,modelName:D,connectionType:f});p(!1);const j=f==="MSSQL"?`SELECT top 10 * FROM ${R}`:`SELECT * FROM ${R} LIMIT 10`;y(j),c(!0)}function z(){const R=e.getFormattedTableNameForQuery({schemaName:s,tableName:n,modelName:D,connectionType:f});y(`SELECT COUNT(*) as count FROM ${R}`),c(!0)}return e.jsxRuntimeExports.jsxs("div",{className:"flex grow flex-col space-y-4 px-4",children:[e.jsxRuntimeExports.jsxs("div",{className:"mx-2 flex items-center justify-center gap-2",children:[e.jsxRuntimeExports.jsxs(e.Toggle,{title:`${v()?"Remove from":"Add to"} Assistant Scope`,pressed:v(),onPressedChange:A,variant:"outline",className:e.cn("h-9 px-2",{}),children:[e.jsxRuntimeExports.jsx(e.Plus,{className:e.cn("mr-1 size-4",{"text-green-400":v(),"text-muted-foreground":!v()})}),"AI"]}),e.jsxRuntimeExports.jsxs(e.Button,{disabled:r!=="Success",onClick:F,size:"sm",variant:"secondary",className:"flex",children:[r!=="Success"?e.jsxRuntimeExports.jsx(xe,{className:"mr-2 h-4 w-4 animate-spin text-foreground/50"}):e.jsxRuntimeExports.jsx(hs,{className:"mr-2 size-4"}),"Top 10"]}),e.jsxRuntimeExports.jsxs(e.Button,{disabled:r!=="Success",onClick:z,size:"sm",variant:"secondary",className:"w-full",children:[r!=="Success"?e.jsxRuntimeExports.jsx(xe,{className:"mr-2 h-4 w-4 animate-spin text-foreground/50"}):e.jsxRuntimeExports.jsx(js,{className:"mr-2 size-4"}),"Count"]})]}),e.jsxRuntimeExports.jsxs(e.ScrollArea,{className:"flex-1 basis-0 border-b border-t border-muted py-3",children:[e.jsxRuntimeExports.jsx("div",{className:"flex flex-col gap-1",children:t==null?void 0:t.map(R=>e.jsxRuntimeExports.jsxs("div",{onClick:()=>N(R),className:e.cn("group mx-3 flex cursor-pointer items-center justify-between rounded px-2 py-1 text-sm transition-colors hover:bg-muted/50",{"border border-dashed border-muted-foreground bg-muted":e.isColumnInSqlGen(R,o)}),children:[e.jsxRuntimeExports.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsxRuntimeExports.jsx(Ss,{column:R}),e.jsxRuntimeExports.jsx("span",{children:R.column_name})]}),e.jsxRuntimeExports.jsx("div",{onClick:j=>j.stopPropagation(),className:"flex items-center justify-end",children:e.isNumberDataType(R.data_type)&&e.jsxRuntimeExports.jsx(Zs,{column:R})})]},R.column_name))}),e.jsxRuntimeExports.jsx(e.ScrollBar,{orientation:"vertical"}),e.jsxRuntimeExports.jsx(e.ScrollBar,{orientation:"horizontal"})]})]})}function re(s,n){var Oe,Me,Fe,Ve,qe,Be;let t=S.useMemo(()=>[],[]);const r=e.useSemaphorContext().authToken||s,o=e.useEditorStore(C=>C.selectedConnectionId),i=e.useEditorStore(C=>C.selectedDatamodelId),a=e.useEditorStore(C=>C.selectedDatabaseName),l=e.useEditorStore(C=>C.selectedSchemaName),x=e.useEditorStore(C=>C.selectedTableName),u=e.useEditorStore(C=>C.actions.setCurrentColumns),d=e.useEditorStore(C=>C.actions.setSelectedConnectionId),h=e.useEditorStore(C=>C.actions.setSelectedDatamodelId),g=e.useEditorStore(C=>C.actions.setSelectedDatabaseName),c=e.useEditorStore(C=>C.actions.setSelectedSchemaName),m=e.useEditorStore(C=>C.actions.setSelectedTableName);e.useEditorStore(C=>C.actions.setCardSql);function p(C){return o&&a&&l&&a!=="NA"?!0:o&&C==="API"?!1:!!(o&&C==="S3")}function y(C){return!!(o&&a&&a!=="NA"&&l&&x||o&&(C==="S3"||C==="API")||i&&i)}function f(C){return o&&C?!(C==="API"||C==="S3"):!1}const{refetch:O,data:D,isLoading:N,isError:v}=e.useQuery({queryKey:["connections"],queryFn:()=>e.getRequest("https://semaphor.cloud/api/v1/connections",(r==null?void 0:r.accessToken)||""),enabled:!!(r!=null&&r.accessToken)}),{refetch:A,data:F,isLoading:z,isError:R}=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}),j=D==null?void 0:D.connections.find(C=>C.id===o),E=j==null?void 0:j.type,b=(j==null?void 0:j.type)==="API"||(j==null?void 0:j.type)==="S3",{data:I,isLoading:M,isFetching:P,isError:q,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:f(E)}),{data:G,isLoading:X,isFetching:J,isError:B,refetch:V}=e.useQuery({queryKey:["schemas",o,a],queryFn:()=>e.getRequest("https://semaphor.cloud/api/v1/schemas",(r==null?void 0:r.accessToken)||"",{connection_id:o,database_name:a}),enabled:!!o&&!!a&&!b&&a!=="NA"}),{data:T,isLoading:W,isFetching:U,isError:K,refetch:Q}=e.useQuery({queryKey:["tables",o,a,l],queryFn:()=>e.getRequest("https://semaphor.cloud/api/v1/tables",(r==null?void 0:r.accessToken)||"",{connection_id:o,database_name:a,schema_name:l}),enabled:p(E)}),{data:$,isLoading:Y,isFetching:w,isError:L,refetch:_}=e.useQuery({queryKey:["columns",o,a,i,l,x],queryFn:()=>e.getRequest("https://semaphor.cloud/api/v1/columns",(r==null?void 0:r.accessToken)||"",{connection_id:o,datamodel_id:i||"",database_name:a,schema_name:l,table_name:x}),enabled:y(E)});S.useEffect(()=>{u(t)},[$,u,t]),S.useEffect(()=>{(E==="S3"||E==="API")&&(g(""),c(""),h(""),E==="API"&&m("api"))},[E,m,g,c,h]);const ne=(j==null?void 0:j.type)==="API"?(Oe=j==null?void 0:j.type)==null?void 0:Oe.toLowerCase():x||"",le=b?"":l||"";function oe(C){c(C),m("")}function k(C){g(C==="none"?"":C),c(""),m(""),C!=="none"&&C!==""&&h("")}function Z(C){d(C)}function ie(C){h(C==="none"?"":C),C!=="none"&&C!==""&&g("")}I&&((Me=I==null?void 0:I.databases)==null?void 0:Me.length)>0,G&&((Fe=G==null?void 0:G.schemas)==null?void 0:Fe.length)>0,$&&((Ve=$==null?void 0:$.columns)==null?void 0:Ve.length)>0&&(t=$.columns.map(C=>({...C,data_type:C.data_type.toLowerCase()}))),q&&(t=[]),(L||v)&&(t=[]);const ee=D==null?void 0:D.connections.map(C=>({id:C.id,name:C.name,type:C.type})),de=(qe=F==null?void 0:F.datamodels)==null?void 0:qe.map(C=>({id:C.id,name:C.name})),Ce=I==null?void 0:I.databases.map(C=>({id:C.database_name,name:C.database_name})),pe=G==null?void 0:G.schemas.map(C=>({id:C.schema_name,name:C.schema_name})),Ne=T==null?void 0:T.tables.map(C=>({id:C.table_name,name:C.table_name})),Ps=(Be=F==null?void 0:F.datamodels.find(C=>C.id===i))==null?void 0:Be.name;return{connectionItems:ee,isConnectionsLoading:N,isConnectionsError:v,modelItems:de,selectedDatamodelId:i,selectedDatamodelName:Ps,isModelsLoading:z,isModelsError:R,databaseItems:Ce,isDatabasesLoadingOrFetching:M||P,isDatabaseError:q,schemaItems:pe,isSchemaLoadingOrFetching:X||J,isSchemaError:B,tableItems:Ne,isTableLoadingOrFetching:W||U,isTableError:K,columns:t,isColumnsLoadingOrFetching:Y||w,isColumnsError:L,isNonDbConnection:b,connectionType:E,tableName:ne,schemaName:le,refetchConnections:O,refetchModels:A,refetchDatabases:H,refetchSchemas:V,refetchTables:Q,refetchColumns:_,handleConnectionChange:Z,handleDatamodelChange:ie,handleDatabaseChange:k,handleSchemaChange:oe}}function vs({ColumnsComponent:s}){var w;const n=e.useEditorStore(L=>L.selectedConnectionId),t=e.useEditorStore(L=>L.selectedDatamodelId),r=e.useEditorStore(L=>L.selectedDatabaseName),o=e.useEditorStore(L=>L.selectedSchemaName),i=e.useEditorStore(L=>L.selectedTableName),a=e.useEditorStore(L=>L.actions.setSelectedTableName),{connectionItems:l,modelItems:x,schemaItems:u,databaseItems:d,tableItems:h,columns:g,isConnectionsLoading:c,isModelsLoading:m,isConnectionsError:p,isModelsError:y,isDatabasesLoadingOrFetching:f,isDatabaseError:O,isSchemaLoadingOrFetching:D,isSchemaError:N,isColumnsError:v,isColumnsLoadingOrFetching:A,isTableLoadingOrFetching:F,isTableError:z,connectionType:R,isNonDbConnection:j,refetchDatabases:E,refetchModels:b,refetchSchemas:I,refetchTables:M,refetchColumns:P,refetchConnections:q,handleConnectionChange:H,handleDatabaseChange:G,handleSchemaChange:X,handleDatamodelChange:J,tableName:B,schemaName:V}=re();function T(){return s?s(V,B,g):e.jsxRuntimeExports.jsx(Xs,{schemaName:V,tableName:B,columns:g,status:A?"Loading...":v?"Error":"Success"})}function W(){window.location.href="mailto:support@semaphor.cloud?subject=Help&body=I need help with..."}function U(){if(!n||R==="S3"||R==="API")return null;if(!t||t==="none")return e.jsxRuntimeExports.jsx(ce,{refetch:E,showNone:!0,onChange:G,isError:O,isLoading:f,items:d,value:r||"",title:"Database"})}function K(){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 Q(){if(!n||R==="S3"||R==="API")return null;if(!r||r==="none")return e.jsxRuntimeExports.jsx(ce,{refetch:b,showNone:!0,onChange:J,isError:y,isLoading:m,items:x,value:t||"",title:"Model"})}function $(){return!n||R==="S3"||R==="API"||!r||r==="none"?null:e.jsxRuntimeExports.jsx(ce,{refetch:I,onChange:X,isError:N,isLoading:D,items:u,value:o||"",title:"Schema"})}function Y(){function L(){let _=!1;return R==="API"?(_=!1,_):((R==="S3"||n&&r&&r!=="none"&&o)&&(_=!0),_)}return L()?e.jsxRuntimeExports.jsx(ce,{refetch:M,onChange:a,isError:z,items:h,isLoading:F,value:i||"",title:"Table"}):null}return e.jsxRuntimeExports.jsxs("aside",{className:"flex grow flex-col justify-between",children:[e.jsxRuntimeExports.jsxs("section",{className:"space-y-3 px-6 py-4",children:[e.jsxRuntimeExports.jsx(ce,{refetch:q,items:l,title:"Connection",value:n||"",onChange:H,isLoading:c,isError:p,connectionTooltip:((w=l==null?void 0:l.find(L=>L.id===n))==null?void 0:w.type)||""}),U(),K(),Q(),$(),Y()]}),T(),e.jsxRuntimeExports.jsx("div",{className:"flex items-end justify-center gap-2 px-6 py-4",children:e.jsxRuntimeExports.jsxs(e.Button,{onClick:W,size:"sm",variant:"secondary",className:"w-full",children:[e.jsxRuntimeExports.jsx(cs,{className:"mr-2 size-4"}),"Help"]})})]})}function Ys(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 a=s.substring(0,n),l=s.substring(n);return`${a} {{ filters | where }} AND ${l.substring(6)}`}else if(t!==-1){const a=s.substring(0,t),l=s.substring(t);return`${a} {{ filters | where }} ${l}`}else{const a=s.substring(0,i),l=s.substring(i);return console.log("beforeClause",a),console.log("afterClause",l),l?`${a} {{ filters | where }} ${l}`:`${a.replace(/;$/,"")} {{ filters | where }}`}}function et({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(ns,{className:"mr-2 h-4 w-4"}),"Debug with AI"]})]})})})]})}function st({userInput:s,triggerAIRun:n,setTriggerAIRun:t,open:r,setOpen:o}){const i=S.useRef(null),a=S.useRef(null),[l,x]=S.useState([]),[u,d]=S.useState(""),[h,g]=S.useState(null),{authToken:c}=e.useSemaphorContext(),m=e.useEditorStore(w=>{var L;return(L=w==null?void 0:w.card)==null?void 0:L.sql}),p=e.useEditorStore(w=>{var L;return(L=w==null?void 0:w.card)==null?void 0:L.python}),y=e.useEditorStore(w=>w.actions.setCardSql),f=e.useEditorStore(w=>w.actions.setRunSql),O=e.useEditorStore(w=>w.actions.switchCardType),D=e.useEditorStore(w=>w.selectedDatabaseName),N=e.useEditorStore(w=>w.selectedTableName),v=e.useEditorStore(w=>w.selectedConnectionId),A=e.useEditorStore(w=>w.selectedSchemaName),F=e.useDashboardStore(w=>w.dashboard.aiScopeTables),{selectedDatamodelName:z,connectionType:R}=re(),{messages:j,setMessages:E,reload:b,append:I,input:M,status:P,handleInputChange:q,handleSubmit:H,addToolResult:G,stop:X}=e.useChat({api:"https://semaphor.cloud/api/v1/assistant",headers:{Authorization:`Bearer ${c==null?void 0:c.accessToken}`},body:{random:Math.random()},maxSteps:10,onToolCall:T,onFinish(w,L){B(L.usage),d(""),console.log("onFinish",w,L),L.finishReason==="stop"&&d("")}});S.useEffect(()=>{n&&s&&(q({target:{value:s}}),setTimeout(()=>{H(),t(!1)},100))},[n,H,s,t,q]);const J=S.useRef(r);S.useEffect(()=>{const w=J.current?"smooth":"auto";J.current=r;const L=setTimeout(()=>{var _;a.current&&(a.current.scroll({top:a.current.scrollHeight,behavior:w}),(_=i.current)==null||_.focus())},50);return()=>clearTimeout(L)},[j,r]);function B(w){g(L=>L?{promptTokens:L.promptTokens+w.promptTokens,completionTokens:L.completionTokens+w.completionTokens,totalTokens:L.totalTokens+w.totalTokens}:w)}function V(w){const L=e.removeFromScopeArray(l,w);U(L)}async function T({toolCall:w}){if(w.toolName==="createChart"){console.log("createChart",w.args);const L=w.args.sql,_=w.args.chartType;return O(_),y(L),f(!0),{status:"success",message:"Let the user know that chart is created"}}else if(w.toolName==="getTableColumns")d("Getting table columns...");else{if(w.toolName==="getUserSql")return m?(console.log("cardSql",m),console.log("cardPython",p),{status:"success",sql:m,python:p||""}):{status:"error",message:"No SQL found"};d("Thinking...")}}function W(w){return w.map(_=>({..._,connectionType:_.connectionType==="API"||_.connectionType==="S3"?"DuckDb":_.connectionType}))}function U(w){const L=W(w);x(L),E(_=>[..._,{id:crypto.randomUUID(),role:"system",content:`Current scope of tables | ${JSON.stringify(L)}`}])}function K(){const w={databaseName:D||"",schemaName:A||"",tableName:N||"",datamodelName:z||"",connectionId:v||"",connectionType:R||""},L=e.dedup([...l,w]);U(L)}function Q(){const w={databaseName:D||"",schemaName:A||"",tableName:N||"",datamodelName:z||"",connectionId:v||"",connectionType:R||""},L=e.isInAiScopeArray([...F||[],...l],w);if(console.log("isInScope",L),!L||l.length===0){const _=e.dedup([...F||[],...l,w]).filter(ne=>ne.connectionId===w.connectionId);U(_)}}function $(w){o(!1),y(w),f(!0)}const Y=!["ready","error"].includes(P);return{messages:j,setMessages:E,reload:b,append:I,input:M,isLoading:Y,handleRun:$,handleOpenDialogAndSetScope:Q,handleAddCurrentTableToScope:K,removeFromCurrentSelections:V,currentScope:l,setCurrentScope:x,containerRef:a,inputRef:i,handleInputChange:q,handleSubmit:H,stop:X,chatStatus:P,toolStatus:u,llmUsage:h}}const tt=!1;function nt({open:s,setOpen:n,userInput:t,triggerAIRun:r,setTriggerAIRun:o}){const[i,a]=S.useState(!1),[l,x]=S.useState(tt),[u,d]=S.useState(!1),{messages:h,setMessages:g,reload:c,append:m,input:p,isLoading:y,handleRun:f,handleOpenDialogAndSetScope:O,handleAddCurrentTableToScope:D,removeFromCurrentSelections:N,currentScope:v,setCurrentScope:A,containerRef:F,inputRef:z,handleInputChange:R,handleSubmit:j,stop:E,chatStatus:b,toolStatus:I,llmUsage:M}=st({userInput:t,triggerAIRun:r,setTriggerAIRun:o,open:s,setOpen:n});function P(){return e.jsxRuntimeExports.jsxs(e.DropdownMenu,{children:[e.jsxRuntimeExports.jsx(e.DropdownMenuTrigger,{children:e.jsxRuntimeExports.jsx(be,{className:"size-3.5 text-muted-foreground/70 hover:text-muted-foreground"})}),e.jsxRuntimeExports.jsxs(e.DropdownMenuContent,{align:"end",children:[e.jsxRuntimeExports.jsx(e.DropdownMenuLabel,{children:"Options"}),e.jsxRuntimeExports.jsx(e.DropdownMenuSeparator,{}),e.jsxRuntimeExports.jsx(e.DropdownMenuCheckboxItem,{checked:i,onCheckedChange:a,children:"Token Usage"}),e.jsxRuntimeExports.jsx(e.DropdownMenuCheckboxItem,{checked:l,onCheckedChange:x,children:"Tool Invocations"}),e.jsxRuntimeExports.jsx(e.DropdownMenuCheckboxItem,{checked:u,onCheckedChange:d,children:"System Message"})]})]})}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:O,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..."})}),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.jsx(e.DialogHeader,{children:e.jsxRuntimeExports.jsxs("div",{className:"flex items-start justify-between gap-2 pr-5",children:[e.jsxRuntimeExports.jsxs("div",{children:[e.jsxRuntimeExports.jsx(e.DialogTitle,{children:"Assistant"}),e.jsxRuntimeExports.jsx(e.DialogDescription,{children:"What can I help you with?"}),v&&v.length>0&&e.jsxRuntimeExports.jsxs("div",{className:"mt-2 flex flex-wrap items-center gap-2",children:[e.jsxRuntimeExports.jsx("span",{className:"text-xs text-muted-foreground",children:"Tables in scope:"}),v==null?void 0:v.map((q,H)=>e.jsxRuntimeExports.jsxs("div",{className:"flex items-center gap-2 rounded-md bg-muted px-2 py-1 text-xs",children:[e.getFormattedTableNameForQuery({schemaName:q.schemaName||"",tableName:q.tableName||"",modelName:q.datamodelName||"",connectionType:q.connectionType||""}),e.jsxRuntimeExports.jsx("button",{onClick:()=>{N(q)},children:e.jsxRuntimeExports.jsx(e.X,{className:"size-3 text-muted-foreground hover:text-foreground"})})]},H))]}),(v==null?void 0:v.length)===0&&e.jsxRuntimeExports.jsxs("div",{className:"mt-2 flex items-center gap-2",children:[e.jsxRuntimeExports.jsx("span",{className:"text-xs text-muted-foreground",children:"Tables in scope: None"}),e.jsxRuntimeExports.jsxs(e.Button,{className:"h-6 text-xs",size:"sm",variant:"secondary",onClick:D,children:[e.jsxRuntimeExports.jsx(e.Plus,{className:"mr-2 size-3"}),"Current Table"]})]})]}),e.jsxRuntimeExports.jsxs("div",{className:"flex items-center gap-2",children:[P(),e.jsxRuntimeExports.jsx(e.Button,{className:"h-8",size:"sm",variant:"secondary",onClick:()=>{g([]),A([]),c()},children:"Clear"})]})]})}),e.jsxRuntimeExports.jsx("div",{ref:F,className:"h-[625px] w-full overflow-auto border-t border-t-muted",children:e.jsxRuntimeExports.jsxs("div",{className:"space-y-4 py-2 pr-3",role:"messages",children:[e.jsxRuntimeExports.jsx(e.PrintMessages,{messages:h,showTools:l,handleRun:f,showSystemMessage:u}),e.jsxRuntimeExports.jsx(e.ChatStatus,{status:e.getStatus(b,I),isLoading:y})]})}),e.jsxRuntimeExports.jsx(e.ChatInput,{stop:E,ref:z,input:p,handleInputChange:R,handleSubmit:j,isLoading:y}),M&&i&&e.jsxRuntimeExports.jsx("div",{className:"flex h-8 items-center justify-between",children:e.jsxRuntimeExports.jsxs("div",{className:"text-xs text-muted-foreground",children:["Usage: ",M.promptTokens," prompt tokens,"," ",M.completionTokens," completion tokens,"," ",M.totalTokens," total tokens"]})})]})]})}var ys={color:void 0,size:void 0,className:void 0,style:void 0,attr:void 0},Pe=S.createContext&&S.createContext(ys),rt=["attr","size","title"];function ot(s,n){if(s==null)return{};var t=it(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 it(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 fe(){return fe=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},fe.apply(this,arguments)}function He(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 Ee(s){for(var n=1;n<arguments.length;n++){var t=arguments[n]!=null?arguments[n]:{};n%2?He(Object(t),!0).forEach(function(r){at(s,r,t[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(s,Object.getOwnPropertyDescriptors(t)):He(Object(t)).forEach(function(r){Object.defineProperty(s,r,Object.getOwnPropertyDescriptor(t,r))})}return s}function at(s,n,t){return n=lt(n),n in s?Object.defineProperty(s,n,{value:t,enumerable:!0,configurable:!0,writable:!0}):s[n]=t,s}function lt(s){var n=ct(s,"string");return typeof n=="symbol"?n:n+""}function ct(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 Cs(s){return s&&s.map((n,t)=>S.createElement(n.tag,Ee({key:t},n.attr),Cs(n.child)))}function se(s){return n=>S.createElement(xt,fe({attr:Ee({},s.attr)},n),Cs(s.child))}function xt(s){var n=t=>{var{attr:r,size:o,title:i}=s,a=ot(s,rt),l=o||t.size||"1em",x;return t.className&&(x=t.className),s.className&&(x=(x?x+" ":"")+s.className),S.createElement("svg",fe({stroke:"currentColor",fill:"currentColor",strokeWidth:"0"},t.attr,r,a,{className:x,style:Ee(Ee({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 Pe!==void 0?S.createElement(Pe.Consumer,null,t=>n(t)):n(ys)}function ut(s){return se({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 dt({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 Ns(s){const{theme:n}=e.useTheme(),t=e.useDashboardStore(p=>p.theme),r=e.useEditorStore(p=>p.frame),o=e.useEditorStore(p=>p.card),i=e.useEditorStore(p=>p.activeTabCardId),a=e.Le(),{refetch:l}=e.useDashboardCardQuery(o),{updateCardTab:x,setRunSql:u}=e.useEditorActions(),d=S.useRef(),h=S.useRef({}),g=r.cards.find(p=>p.id===i),c=S.useCallback(()=>{let p="";return s==="python"&&(p=(g==null?void 0:g.python)||e.PYTHON_DEFAULT_CODE),s==="sql"&&(p=(g==null?void 0:g.sql)||""),p},[s,g]);S.useEffect(()=>{if(i&&o.id&&o.id!==i){if(d.current&&a){const p=d.current.getModel();p&&(h.current[o.id]=p);let y=h.current[i];if(!y){const f=c();y=a.editor.createModel(f,s),h.current[i]=y}d.current.setModel(y)}x(i,o),u(!0)}},[i,o,x,a,u,s,c]),S.useEffect(()=>{if(!a)return;const p=window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light",y=t==="system"?p:t;a.editor.defineTheme("default",{base:y==="light"?"vs":"vs-dark",inherit:!0,rules:[],colors:{"editor.background":y==="light"?"#ffffff":e.hslStringToHex("240 10% 10%")}}),a.editor.setTheme("default")},[n,t,a]),S.useEffect(()=>{const p=d.current;p&&a&&o&&p.addCommand(a.KeyMod.Shift|a.KeyCode.Enter,function(){return l(),!1})},[a,l,o]);function m(p,y){if(d.current=p,!h.current[o.id]){const f=p.getModel(),O=c();h.current[o.id]=f||(y==null?void 0:y.editor.createModel(O,s))||p.getModel()}p.setModel(h.current[o.id])}return{handleEditorDidMount:m}}function mt(){const s=e.useEditorStore(a=>a.card.sql),n=e.useEditorStore(a=>a.sqlGen),{setCardSql:t,setSqlGen:r}=e.useEditorActions(),{handleEditorDidMount:o}=Ns("sql");function i(a){t(a),e.isObjectEmpty(n)||r({})}return e.jsxRuntimeExports.jsx(e.Ft,{theme:"default",className:"pt-3",onChange:i,value:s||"",options:{minimap:{enabled:!1},wordWrap:"on",scrollbar:{verticalScrollbarSize:0,horizontalScrollbarSize:0},fontSize:13,renderLineHighlight:"none"},defaultLanguage:"sql",onMount:o})}function pt(){const s=e.useEditorStore(o=>o.card.python),{setCardPython:n}=e.useEditorActions(),{handleEditorDidMount:t}=Ns("python");function r(o){n(o)}return e.jsxRuntimeExports.jsx(e.Ft,{className:"pt-3",theme:"default",onChange:r,value:s||e.PYTHON_DEFAULT_CODE,options:{minimap:{enabled:!1},wordWrap:"on",scrollbar:{verticalScrollbarSize:0,horizontalScrollbarSize:0},fontSize:13,renderLineHighlight:"none"},defaultLanguage:"python",onMount:t})}function jt(){const s=e.useDashboardStore(i=>i.dashboard.filters),n=e.useDashboardStore(i=>i.filterValues),t=e.useDashboardStore(i=>i.selectedSheetId),r=s==null?void 0:s.filter(i=>i.sheetId===t||!i.sheetId),o=n==null?void 0:n.filter(i=>(r==null?void 0:r.some(a=>a.id===i.filterId))||i.filterId.endsWith(t));return e.jsxRuntimeExports.jsx(e.Ft,{theme:"default",defaultLanguage:"json",className:"mt-1 min-h-[220px]",value:JSON.stringify(o,null,2),options:{readOnly:!0,minimap:{enabled:!1},lineNumbers:"off",glyphMargin:!1,wordWrap:"on",scrollbar:{verticalScrollbarSize:0,horizontalScrollbarSize:0},fontSize:12,renderLineHighlight:"none"}})}function ht(){var oe;const[s,n]=S.useState({queryKey:[],queryData:null}),t=e.useQueryClient(),[r,o]=S.useState(!1),[i,a]=S.useState(!1),[l,x]=S.useState(!1),[u,d]=S.useState(""),[h,g]=S.useState(!1),c=e.useEditorStore(k=>k.frame),m=e.useEditorStore(k=>k.card),p=e.useEditorStore(k=>k.isShowingVisual),y=e.useEditorStore(k=>k.selectedConnectionId),f=e.useEditorStore(k=>k.selectedDatabaseName),O=e.useEditorStore(k=>k.selectedDatamodelId),D=e.useEditorStore(k=>k.selectedSchemaName),N=e.useEditorStore(k=>k.selectedTableName),v=e.useEditorStore(k=>{var Z;return(Z=k==null?void 0:k.card)==null?void 0:Z.sql}),A=e.useEditorStore(k=>k.applyFilters),{setCardCustomCfg:F,setQueryResultColumns:z,setCardSql:R,setPythonStdOut:j,setCardPreferences:E,setCardType:b,setCardPython:I}=e.useEditorActions(),M=e.useEditorStore(k=>k.onSave),P=e.useEditorStore(k=>k.onClose),q=e.useEditorStore(k=>k.actions.setSqlGen),H=e.useEditorStore(k=>k.runSql),G=e.useEditorStore(k=>k.actions.setRunSql),X=e.useEditorStore(k=>k.actions.setCardCfg),J=e.useEditorStore(k=>k.actions.setIsSqlRunning),{data:B,isLoading:V,isFetching:T,isSuccess:W,isError:U,error:K,queryKey:Q,refetch:$}=e.useDashboardCardQuery(m);S.useEffect(()=>{if(B&&(B.rowLimitExceeded&&e.ce.error("Row limit (10,000) exceeded. Refine your query.",{position:"top-center",richColors:!0}),j((B==null?void 0:B.output)||""),B.records.length>0)){const{dimensionKeys:k}=e.getKeys(B.records);z(k)}},[B,z,j]),S.useEffect(()=>{(V||T)&&J(!0),(U||W)&&J(!1),U&&(z([]),j(""))},[V,T,B,j,U,W,J,z,K]),S.useEffect(()=>{H&&(t.getQueryData(Q)||$(),G(!1))},[H,$,G,Q,t]);function Y(){const k=t.getQueryData(Q);s.queryData||n({queryKey:Q,queryData:k}),t.setQueryData(Q,null),t.removeQueries({queryKey:Q,exact:!0}),R(""),q({}),I(""),X(void 0),F(""),E({}),b("bar")}function w(k,Z){if(k.length===0)return"";if(Z){const ie=k.find(ee=>ee.id===Z);if(ie){const ee=ie.tabTitle;if(ee=="All__Header")return k[0].id;if(ee&&ee.endsWith("__Header")){const Ce=ee.split("__")[0],pe=k.find(Ne=>Ne.tabTitle===Ce);return pe?pe.id:k[0].id}return Z}}return k[0].id}function L(){let k=v;v&&!v.includes("{{")&&(k=Ys(v),R(k));const Z={...m,lastSelectedSchema:D,lastSelectedDatamodelId:O,lastSelectedDatabase:f,lastSelectedTable:N,connectionId:y,type:p?m.type:"table",sql:k,customCfg:p?m.customCfg:null},ie=c.cards.map(de=>de.id===m.id?Z:de),ee={...c,cards:ie,activeCardId:w(ie,c.activeCardId)};M==null||M(ee)}function _(){const{queryKey:k,queryData:Z}=s;k&&Z&&t.setQueryData(k,Z),q({}),P==null||P()}function ne(){return e.jsxRuntimeExports.jsxs(e.jsxRuntimeExports.Fragment,{children:[i&&e.jsxRuntimeExports.jsx("div",{className:"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"}),i&&e.jsxRuntimeExports.jsx(e.Cross2Icon,{onClick:()=>a(!1),className:"bg-background/50 text-foreground/50 hover:cursor-pointer hover:text-foreground"})]}),e.jsxRuntimeExports.jsx(jt,{})]})}),!i&&e.jsxRuntimeExports.jsx(e.Filter,{onClick:()=>a(!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":A})})]})}function le(){return e.jsxRuntimeExports.jsxs(e.ResizablePanelGroup,{className:"flex grow pb-1",direction:"vertical",role:"editor-resizable-group",children:[e.jsxRuntimeExports.jsxs(e.ResizablePanel,{id:"1",order:1,defaultSize:r?20:100,className:"relative flex grow",children:[e.jsxRuntimeExports.jsx("div",{id:"sql-container",className:"relative flex w-[99%]",children:e.jsxRuntimeExports.jsx(mt,{})}),r&&e.jsxRuntimeExports.jsx("code",{className:"absolute right-6 top-3 text-xs text-muted-foreground/70",children:"sql"})]}),r&&e.jsxRuntimeExports.jsxs(e.jsxRuntimeExports.Fragment,{children:[e.jsxRuntimeExports.jsx(e.ResizableHandle,{withHandle:!0,className:"border"}),e.jsxRuntimeExports.jsxs(e.ResizablePanel,{id:"2",order:2,defaultSize:80,className:"relative flex grow",children:[e.jsxRuntimeExports.jsx("div",{id:"python-container",className:"relative flex w-[99%] pt-0",children:e.jsxRuntimeExports.jsx(pt,{})}),e.jsxRuntimeExports.jsx("code",{className:"absolute right-6 top-3 text-xs 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",{className:"relative flex grow justify-between overflow-y-scroll",children:[le(),ne()]}),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:V||T,onClick:()=>{$()},className:"shrink-0",size:"sm",variant:"outline",children:[V||T?e.jsxRuntimeExports.jsx(xe,{className:"mr-2 h-4 w-4 animate-spin text-foreground/50"}):e.jsxRuntimeExports.jsx(e.Play,{className:"mr-2 h-4 w-4"}),"Run"]}),(U||(B==null?void 0:B.error))&&e.jsxRuntimeExports.jsx(et,{error:(K==null?void 0:K.message)||((oe=B==null?void 0:B.error)==null?void 0:oe.message),setShowAIDialog:x,setTriggerAIRun:g,setUserInputforAI:d}),e.jsxRuntimeExports.jsxs(e.Button,{onClick:Y,className:"",size:"sm",variant:"outline",children:[e.jsxRuntimeExports.jsx(Ye,{className:"mr-2 size-4"}),"Clear"]}),e.jsxRuntimeExports.jsx(e.Toggle,{pressed:r,onPressedChange:k=>o(k),className:"",size:"sm",variant:"outline",children:e.jsxRuntimeExports.jsx(ut,{className:"size-4 text-foreground/70"})}),e.jsxRuntimeExports.jsx(nt,{open:l,setOpen:x,userInput:u,triggerAIRun:h,setTriggerAIRun:g})]}),e.jsxRuntimeExports.jsxs("div",{className:"flex items-center gap-2",children:[(B==null?void 0:B.sql)&&e.jsxRuntimeExports.jsx(dt,{sql:B.sql}),e.jsxRuntimeExports.jsxs(e.Button,{onClick:_,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:L,size:"sm",variant:"outline",children:[e.jsxRuntimeExports.jsx(e.Check,{className:"mr-2 size-4 font-bold text-green-600"}),"Accept"]})]})]})]})}function ft({data:s}){var a;const[n,t]=S.useState([]),o=Object.keys(s[0]).map(l=>({accessorKey:l,header:({column:x})=>{const u=x.getIsSorted();return e.jsxRuntimeExports.jsx("div",{className:"flex gap-2",children:e.jsxRuntimeExports.jsxs("div",{className:"flex cursor-pointer items-center",onClick:()=>x.toggleSorting(x.getIsSorted()==="asc"),children:[l,u==="asc"?e.jsxRuntimeExports.jsx(e.TriangleUpIcon,{className:"ml-2 h-5 w-5"}):u==="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(x=>e.jsxRuntimeExports.jsx(e.TableHead,{className:"sticky top-0 h-11 bg-muted font-semibold",children:x.isPlaceholder?null:e.flexRender(x.column.columnDef.header,x.getContext())},x.id))},l.id))}),e.jsxRuntimeExports.jsx(e.TableBody,{children:(a=i.getRowModel().rows)!=null&&a.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(x=>e.jsxRuntimeExports.jsx(e.TableCell,{className:"py-3",children:e.flexRender(x.column.columnDef.cell,x.getContext())},x.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 Et({card:s}){var f,O,D,N,v,A,F,z,R,j,E;const[n,t]=S.useState(!1),[r,o]=S.useState([]),{authToken:i}=e.useSemaphorContext(),a=e.getTokenParams(i==null?void 0:i.accessToken),l=e.useDashboardStore(b=>b.themeStyle),x={colors:((O=(f=l==null?void 0:l.chart)==null?void 0:f.dataset)==null?void 0:O.backgroundColor)||[]};(D=s.customCardPreferences)!=null&&D.inputData;const{getCard:u}=e.useCustomVisual(((N=s.customCardPreferences)==null?void 0:N.url)||""),d=((v=s.customCardPreferences)==null?void 0:v.visualType)||"single",h=e.useEditorStore(b=>b.frame);e.useEditorActions();const{data:g}=e.useDashboardCardQuery(s),c=S.useCallback((b,I)=>{o(M=>({...M,[b]:I}))},[]);if(!((A=s.customCardPreferences)!=null&&A.componentName))return null;const m=u((F=s.customCardPreferences)==null?void 0:F.componentName);function p(b){t(b)}const y=Object.keys(((z=s.customCardPreferences)==null?void 0:z.dataInputCardIds)||{}).map(b=>{var P,q,H;const I=(q=(P=s.customCardPreferences)==null?void 0:P.dataInputCardIds)==null?void 0:q[b].cardId,M=(H=h==null?void 0:h.cards)==null?void 0:H.find(G=>G.id===I);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:[m&&d==="single"&&e.jsxRuntimeExports.jsx(m,{params:a,theme:x,settings:(R=s.customCardPreferences)==null?void 0:R.settings,onDataChange:c,data:(g==null?void 0:g.records)||[]}),m&&d==="multiple"&&e.jsxRuntimeExports.jsxs(e.jsxRuntimeExports.Fragment,{children:[Object.keys(((j=s.customCardPreferences)==null?void 0:j.dataInputCardIds)||{}).map(b=>{var P,q,H;const I=(q=(P=s.customCardPreferences)==null?void 0:P.dataInputCardIds)==null?void 0:q[b].cardId,M=(H=h==null?void 0:h.cards)==null?void 0:H.find(G=>G.id===I);if(M)return e.jsxRuntimeExports.jsx(e.MultiInputEmptyRenderer,{onLoadingStatus:p,onDataChange:c,dataInputIndex:b,card:M},M.id+b)}),e.jsxRuntimeExports.jsx("div",{className:"flex flex-col gap-2",children:e.jsxRuntimeExports.jsx(m,{theme:x,onDataChange:c,settings:y.map(b=>{var I;return(I=b==null?void 0:b.customCardPreferences)==null?void 0:I.settings}),data:y.map(b=>b!=null&&b.id?r==null?void 0:r[b.id]:[])})})]})]},(E=s.customCardPreferences)==null?void 0:E.componentName)})}function ws({className:s,...n}){var y;const t=e.useEditorStore(f=>f.card),r=((y=t.customCardPreferences)==null?void 0:y.showCardHeader)??!0,o=e.useEditorStore(f=>f.frame),i=e.useDashboardStore(f=>f.dashboard.filters);e.useEditorStore(f=>f.actions.setRunSql);const{updateFilter:a}=e.useDashboardActions(),l=i==null?void 0:i.find(f=>f.id===o.filterId),{data:x,isLoading:u,isFetching:d}=e.useDashboardCardQuery(t),{setCard:h}=e.useEditorActions(),{data:g}=e.useTopoJson(t);if(!t.id)return null;let c;x!=null&&x.records&&(x==null?void 0:x.records.length)>0&&(c=e.createChartConfig({data:x==null?void 0:x.records,cardType:t.type,cfg:t.cfg,customCfg:t.customCfg,preferences:t.preferences,topoJson:g}));function m(f){return e.jsxRuntimeExports.jsx(Et,{card:f})}function p(){var f;if(x!=null&&x.records&&(x==null?void 0:x.records.length)===0&&!u&&!d)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 m(t);if(!["table","custom"].includes(t.type)&&c)return e.jsxRuntimeExports.jsx(e.ChartJsVisual,{cfg:c},JSON.stringify(c)+JSON.stringify(t.preferences)+((f=t==null?void 0:t.preferences)==null?void 0:f.customVisualCode));if(t.type==="table"&&(x!=null&&x.records)&&(x==null?void 0:x.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:x==null?void 0:x.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:f=>h({...t,title:f}),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:f=>h({...t,description:f}),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:f=>a({...l,title:f}),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:p()})]})}const Ge=({language:s,value:n,onChange:t})=>e.jsxRuntimeExports.jsx(e.Ft,{className:"h-full w-full overflow-hidden text-xs",theme:"default",options:{minimap:{enabled:!1},wordWrap:"on",scrollbar:{verticalScrollbarSize:0,horizontalScrollbarSize:0},fontSize:12,lineHeight:16,renderLineHighlight:"none"},defaultLanguage:s,value:n,onChange:t}),gt=()=>e.jsxRuntimeExports.jsxs(e.DialogHeader,{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."})]})]}),Rt=({defaultConfig:s,customCode:n,customConfig:t,onConfigChange:r,onCodeChange:o})=>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.jsx(e.TabsTrigger,{value:"custom-config",children:t?"Custom Config":"Default Config"}),e.jsxRuntimeExports.jsx(e.TabsTrigger,{value:"output",children:"Output"}),e.jsxRuntimeExports.jsx(e.TabsTrigger,{value:"custom-code",children:"Custom Code"})]}),e.jsxRuntimeExports.jsx(e.TabsContent,{value:"output",className:"mt-0 grow rounded-b border border-t-0 p-2",children:e.jsxRuntimeExports.jsx(e.Textarea,{readOnly:!0,value:s,className:"h-full resize-none border-none font-mono focus-visible:ring-0"})}),e.jsxRuntimeExports.jsx(e.TabsContent,{value:"custom-config",className:"mt-0 grow rounded-b border border-t-0",children:e.jsxRuntimeExports.jsx(Ge,{language:"json",value:t,onChange:r})}),e.jsxRuntimeExports.jsx(e.TabsContent,{value:"custom-code",className:"mt-0 grow rounded-b border border-t-0",children:e.jsxRuntimeExports.jsx(Ge,{language:"javascript",value:n,onChange:o})})]}),bt=({error:s,hasCustomConfig:n,onReset:t,onApply:r,onClose:o})=>e.jsxRuntimeExports.jsxs(e.DialogFooter,{className:"flex items-center",children:[e.jsxRuntimeExports.jsx(e.Label,{className:"mr-2 text-red-500",children:s}),e.jsxRuntimeExports.jsx(e.Button,{disabled:!n,onClick:t,variant:"outline",children:"Reset"}),e.jsxRuntimeExports.jsx(e.Button,{onClick:r,variant:"outline",children:"Apply"}),e.jsxRuntimeExports.jsx(e.Button,{onClick:o,variant:"outline",children:"Close"})]});function St(){const[s,n]=S.useState(!1),[t,r]=S.useState(""),[o,i]=S.useState(""),[a,l]=S.useState(""),[x,u]=S.useState(""),d=e.useEditorStore(N=>N.card),h=e.useEditorStore(N=>N.card.customCfg),{data:g}=e.useDashboardCardQuery(d),{data:c}=e.useTopoJson(d),{setCardCustomCfg:m,setCustomVisualCode:p}=e.useEditorActions(),y=(N,v)=>e._.transform(N,(A,F,z)=>{if(!e._.isEqual(F,v[z]))if(e._.isArray(F)&&e._.isArray(v[z]))A[z]=v[z];else if(e._.isObject(F)&&e._.isObject(v[z])){const R=y(F,v[z]);e._.isEmpty(R)||(A[z]=R)}else A[z]=v[z]}),f=N=>{var v,A;return JSON.stringify({...N,data:{...N.data,datasets:(A=(v=N.data)==null?void 0:v.datasets)==null?void 0:A.map(F=>({...F,data:[]}))}},null,2)},O=()=>{var v,A;if(!((v=g==null?void 0:g.records)!=null&&v.length))return;const N=e.createChartConfig({data:g.records,cardType:d.type,cfg:d.cfg,preferences:d.preferences,topoJson:c});if(N){r(f(N)),l(((A=d.preferences)==null?void 0:A.customVisualCode)||"");const F=e._.merge(N,h);i(f(F))}},D=()=>{try{if(a&&p(a),o){const N=JSON.parse(o),v=y(JSON.parse(t),N);m(v),u("")}}catch{u("Invalid JSON configuration")}};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:O,size:"sm",variant:"outline",className:h?"border-foreground/50 dark:border-foreground/70":"",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.jsx(gt,{}),e.jsxRuntimeExports.jsxs("div",{className:"flex grow gap-2",children:[e.jsxRuntimeExports.jsx(e.ErrorBoundary,{FallbackComponent:e.FallbackEditorCard,children:e.jsxRuntimeExports.jsx(ws,{className:"w-1/2 rounded shadow-none"})}),e.jsxRuntimeExports.jsx(Rt,{defaultConfig:t,customCode:a,customConfig:o,onConfigChange:N=>i(N??""),onCodeChange:N=>l(N??"")})]}),e.jsxRuntimeExports.jsx(bt,{error:x,hasCustomConfig:!!h,onReset:()=>{i(t),m(null)},onApply:D,onClose:()=>n(!1)})]})]})}function ks(s){return se({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 Is(s){return se({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 Ds(s){return se({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 vt(s){return se({tag:"svg",attr:{viewBox:"0 0 256 256",fill:"currentColor"},child:[{tag:"path",attr:{d:"M48,180c0,11,7.18,20,16,20a14.24,14.24,0,0,0,10.22-4.66A8,8,0,0,1,85.78,206.4,30.06,30.06,0,0,1,64,216c-17.65,0-32-16.15-32-36s14.35-36,32-36a30.06,30.06,0,0,1,21.78,9.6,8,8,0,0,1-11.56,11.06A14.24,14.24,0,0,0,64,160C55.18,160,48,169,48,180Zm79.6-8.69c-4-1.16-8.14-2.35-10.45-3.84-1.25-.81-1.23-1-1.12-1.9a4.57,4.57,0,0,1,2-3.67c4.6-3.12,15.34-1.73,19.82-.56A8,8,0,0,0,142,145.86c-2.12-.55-21-5.22-32.84,2.76a20.58,20.58,0,0,0-9,14.95c-2,15.88,13.65,20.41,23,23.11,12.06,3.49,13.12,4.92,12.78,7.59-.31,2.41-1.26,3.34-2.14,3.93-4.6,3.06-15.17,1.56-19.55.36A8,8,0,0,0,109.94,214a61.34,61.34,0,0,0,15.19,2c5.82,0,12.3-1,17.49-4.46a20.82,20.82,0,0,0,9.19-15.23C154,179,137.49,174.17,127.6,171.31Zm83.09-26.84a8,8,0,0,0-10.23,4.84L188,184.21l-12.47-34.9a8,8,0,0,0-15.07,5.38l20,56a8,8,0,0,0,15.07,0l20-56A8,8,0,0,0,210.69,144.47ZM216,88v24a8,8,0,0,1-16,0V96H152a8,8,0,0,1-8-8V40H56v72a8,8,0,0,1-16,0V40A16,16,0,0,1,56,24h96a8,8,0,0,1,5.66,2.34l56,56A8,8,0,0,1,216,88Zm-27.31-8L160,51.31V80Z"},child:[]}]})(s)}function Ts(s){return se({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 Ls(s){return se({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 As(s){return se({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 zs(s){return se({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 Os(s){return se({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 Ms(s){const[n,t]=S.useState(null);return S.useEffect(()=>{s&&(async()=>{const i=(await Promise.resolve().then(()=>require("./lucide-react-Dd51A2C_.js")))[s];t(i)})()},[s]),n}function Fs(){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 yt({onChartTypeChange:s}){const[n,t]=S.useState([]),{data:r}=Fs();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 x=>(await e.loadManifest(x.value)).visuals.map(h=>({name:h.name,icon:h.icon,url:x.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(Ct,{text:o.name,onClick:()=>s("custom",o),icon:o.icon},o.url+o.name+i))})]})}const Ct=({text:s,icon:n,onClick:t})=>{const r=Ms(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 Nt(){var d,h;const[s,n]=S.useState(!1),t=e.useEditorStore(g=>g.card),r=t.type,{setCardType:o,setCardPreferences:i,setChartOrientation:a}=e.useEditorStore(g=>g.actions),{setCardCustomCfg:l,setCustomCardPreferences:x}=e.useEditorActions();function u(g,c){l(null),i({}),o(g),c&&x({type:"component",visualType:"single",url:c.url,componentName:c.name,icon:c.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(wt,{className:"h-4 w-4",chartType:r,customIcon:(d=t.customCardPreferences)==null?void 0:d.icon,componentName:(h=t.customCardPreferences)==null?void 0:h.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:()=>u("bar"),className:"font-normal",variant:"ghost",children:e.jsxRuntimeExports.jsx(ge,{className:"size-5"})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>u("line"),variant:"ghost",children:e.jsxRuntimeExports.jsx(Re,{className:"size-5"})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>u("stackedBar"),variant:"ghost",children:e.jsxRuntimeExports.jsx(As,{className:"size-5",strokeWidth:0})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>u("stackedLine"),variant:"ghost",children:e.jsxRuntimeExports.jsx(Ls,{className:"size-5",strokeWidth:0})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>u("scatter"),variant:"ghost",children:e.jsxRuntimeExports.jsx(De,{className:"size-5"})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>u("bubble"),variant:"ghost",children:e.jsxRuntimeExports.jsx(Ts,{className:"size-4"})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>u("pie"),variant:"ghost",children:e.jsxRuntimeExports.jsx(Ie,{className:"size-5"})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>u("doughnut"),variant:"ghost",children:e.jsxRuntimeExports.jsx(Is,{className:"size-5",strokeWidth:1})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>u("radar"),variant:"ghost",children:e.jsxRuntimeExports.jsx(ks,{className:"size-5 font-extralight",strokeWidth:.5})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>u("polarArea"),variant:"ghost",children:e.jsxRuntimeExports.jsx(Ds,{className:"size-5"})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>u("pyramid"),variant:"ghost",children:e.jsxRuntimeExports.jsx(Os,{className:"size-5"})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>u("range"),variant:"ghost",children:e.jsxRuntimeExports.jsx(ke,{className:"size-5"})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>u("table"),variant:"ghost",children:e.jsxRuntimeExports.jsx(Se,{className:"size-5"})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>u("kpi"),variant:"ghost",children:e.jsxRuntimeExports.jsx(zs,{className:"size-6"})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>u("text"),variant:"ghost",children:e.jsxRuntimeExports.jsx(ve,{className:"size-4"})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>u("map"),variant:"ghost",children:e.jsxRuntimeExports.jsx(Te,{className:"size-4"})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>u("custom"),variant:"ghost",children:e.jsxRuntimeExports.jsx(Le,{className:"size-4"})})]}),e.jsxRuntimeExports.jsx(yt,{onChartTypeChange:u})]})]})}function wt({chartType:s,className:n,customIcon:t,componentName:r}){const o=Ms(t||"");switch(s){case"bar":return e.jsxRuntimeExports.jsx(ge,{className:n});case"line":return e.jsxRuntimeExports.jsx(Re,{className:n});case"pie":return e.jsxRuntimeExports.jsx(Ie,{className:n});case"radar":return e.jsxRuntimeExports.jsx(ks,{className:n});case"scatter":return e.jsxRuntimeExports.jsx(De,{className:n});case"bubble":return e.jsxRuntimeExports.jsx(Ts,{className:n});case"doughnut":return e.jsxRuntimeExports.jsx(Is,{className:n});case"stackedBar":return e.jsxRuntimeExports.jsx(As,{className:"size-4 text-foreground/70"});case"stackedLine":return e.jsxRuntimeExports.jsx(Ls,{className:"size-4 text-foreground/70"});case"polarArea":return e.jsxRuntimeExports.jsx(Ds,{className:n});case"pyramid":return e.jsxRuntimeExports.jsx(Os,{className:n});case"range":return e.jsxRuntimeExports.jsx(ke,{className:n});case"kpi":return e.jsxRuntimeExports.jsx(zs,{className:n});case"text":return e.jsxRuntimeExports.jsx(ve,{className:n});case"map":return e.jsxRuntimeExports.jsx(Te,{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(Le,{className:n});default:return e.jsxRuntimeExports.jsx(Se,{className:n})}}function kt(){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(be,{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 Ue(){var j;const s=e.useEditorStore(E=>E.frame),n=e.useEditorStore(E=>E.card),t=e.useEditorStore(E=>E.isShowingVisual),r=e.useEditorStore(E=>E.isSqlRunning),o=e.useEditorStore(E=>E.pythonStdOut);e.useEditorStore(E=>E.actions.setRunSql);const{setFrame:i,setCard:a,updateCardInFrame:l,setActiveTabCardId:x}=e.useEditorActions(),{data:u,isLoading:d,isFetching:h,error:g}=e.useDashboardCardQuery(n);if(!n)return e.jsxRuntimeExports.jsx(e.jsxRuntimeExports.Fragment,{children:"No Active Card"});function c(){const E={connectionId:n.connectionId,id:e.v4(),title:"Title",description:"Description",preferences:{onClickFilter:[{columnIndex:0,expression:""}]},type:"bar",sql:"",data:[]};m(E)}function m(E){const b={...s,cards:[...s.cards,E],activeCardId:E.id};i(b),x(E.id)}function p(){const E={...n,id:e.v4(),title:`${n.title} Copy`,tabTitle:`${n.tabTitle||n.title} Copy`};m(E)}function y(E){const b=s.cards.filter(P=>P.id!==E),I=b[0],M={...s,cards:b,activeCardId:I.id};i(M),x(I.id),a(I)}function f(E){x(E)}const O=(E,b)=>{console.log("handleDragStart",b),E.dataTransfer.setData("tabIndex",b.toString())},D=E=>{E.preventDefault()},N=(E,b)=>{const I=E.dataTransfer.getData("tabIndex");if(I===b.toString())return;const M=Array.from(s.cards),[P]=M.splice(parseInt(I),1);M.splice(b,0,P),i({...s,cards:M})};function v(E,b){return E.cards.length===1&&(b.displayTab===!0||b.displayTab===void 0)||E.activeCardId!==b.id&&(b.displayTab===!0||b.displayTab===void 0)?null:e.jsxRuntimeExports.jsx("div",{onClick:()=>{const I=b.displayTab===void 0?!1:!b.displayTab;a({...b,displayTab:I}),l({...b,displayTab:I})},children:b.displayTab===!0||b.displayTab===void 0?e.jsxRuntimeExports.jsx(e.Eye,{className:"mr-2 size-3.5 text-muted-foreground hover:text-foreground"}):e.jsxRuntimeExports.jsx(es,{className:"mr-2 size-3.5 text-muted-foreground hover:text-foreground"})})}function A(){return e.jsxRuntimeExports.jsxs(e.Tabs,{onValueChange:f,value:s.activeCardId,className:"flex grow flex-col",children:[s.cards.map(E=>e.jsxRuntimeExports.jsx(e.TabsContent,{className:"mt-0 grow",value:E.id,children:F()},E.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((E,b)=>e.jsxRuntimeExports.jsx(e.Editable,{text:E.tabTitle||E.title,onSave:I=>{a({...n,tabTitle:I}),l({...n,tabTitle:I})},children:e.jsxRuntimeExports.jsxs(e.TabsTrigger,{draggable:!0,onDragStart:I=>O(I,b),onDragOver:D,onDrop:I=>N(I,b),className:"",value:E.id,children:[v(s,E),E.tabTitle||E.title,s.activeCardId===E.id&&s.cards.length>1&&e.jsxRuntimeExports.jsx(e.X,{className:"ml-2 size-3.5 text-muted-foreground hover:text-foreground",onClick:()=>y(E.id)})]})},E.id)),e.jsxRuntimeExports.jsx(e.Button,{className:"ml-1 h-8 px-2 hover:bg-muted-foreground/50",variant:"outline",onClick:c,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:p,children:e.jsxRuntimeExports.jsx(Ze,{className:"h-4 w-4"})})]})})]})}function F(){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:u==null?void 0:u.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:u==null?void 0:u.records})})})}):e.jsxRuntimeExports.jsx(e.ErrorBoundary,{FallbackComponent:e.FallbackEditorCard,children:e.jsxRuntimeExports.jsx(ws,{className:"grow border-none shadow-none"})})}function z(){const E=JSON.stringify(u==null?void 0:u.records,null,2),b=new Blob([E],{type:"application/json"}),I=URL.createObjectURL(b),M=document.createElement("a");M.href=I,M.download=`${n.title}.json`,M.click()}function R(){const b=[Object.keys(u==null?void 0:u.records.reduce((q,H)=>({...q,...H}),{})).join(","),...((u==null?void 0:u.records)||[]).map(q=>Object.values(q).join(","))].join(`
|
|
192
|
+
`),I=new Blob([b],{type:"text/csv"}),M=URL.createObjectURL(I),P=document.createElement("a");P.href=M,P.download=`${n.title}.csv`,P.click()}return e.jsxRuntimeExports.jsxs("div",{className:"relative flex h-full flex-col py-3",children:[(d||h)&&e.jsxRuntimeExports.jsx("div",{className:"absolute bottom-0 left-0 right-0 top-0 z-50 m-auto flex h-10 w-10 items-center justify-center rounded-md bg-muted",children:e.jsxRuntimeExports.jsx(xe,{className:"h-8 w-8 animate-spin text-muted-foreground"})}),e.jsxRuntimeExports.jsxs("div",{className:"mb-0 flex min-h-10 items-center justify-end gap-2 px-6",children:[t&&e.jsxRuntimeExports.jsxs("div",{className:"flex grow items-center gap-2",children:[e.jsxRuntimeExports.jsx(Nt,{}),!["table","custom"].includes(n.type)&&e.jsxRuntimeExports.jsx(St,{}),e.jsxRuntimeExports.jsx(kt,{})]}),!t&&e.jsxRuntimeExports.jsxs("div",{className:"flex grow items-center gap-1",children:[e.jsxRuntimeExports.jsx(e.Button,{className:"h-7 w-fit px-1 font-mono text-xs text-muted-foreground/70",variant:"ghost",size:"icon",onClick:R,children:e.jsxRuntimeExports.jsx(vt,{className:"size-4"})}),e.jsxRuntimeExports.jsx(e.Button,{className:"h-7 w-fit px-1 font-mono text-xs text-muted-foreground/70",variant:"ghost",size:"icon",onClick:z,children:e.jsxRuntimeExports.jsx(ss,{strokeWidth:1.5,className:"size-4"})}),e.jsxRuntimeExports.jsx(e.CopyButton,{text:JSON.stringify(u==null?void 0:u.records,null,2),className:"h-7 w-fit px-1 font-mono text-xs text-muted-foreground/70"})]}),e.jsxRuntimeExports.jsx(Dt,{})]}),t?A():e.jsxRuntimeExports.jsxs(e.ResizablePanelGroup,{className:"px-6",direction:"horizontal",children:[o&&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:o&&e.jsxRuntimeExports.jsx(It,{})}),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:[(u==null?void 0:u.records)&&(u==null?void 0:u.records.length)>0&&e.jsxRuntimeExports.jsx(ft,{data:(u==null?void 0:u.records)||[]}),(g||(u==null?void 0:u.error))&&e.jsxRuntimeExports.jsx("span",{className:"font-mono text-xs",children:(g==null?void 0:g.message)||((j=u==null?void 0:u.error)==null?void 0:j.message)}),e.jsxRuntimeExports.jsx(e.ScrollBar,{orientation:"horizontal"})]})})]})]})}function It(){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 Dt(){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 Tt({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 te({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 me({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 Lt(){var p,y;const s=e.useEditorStore(f=>f.card.customCardPreferences),{data:n}=Fs(),t=(n==null?void 0:n.plugins)||[],r=e.useEditorStore(f=>f.card),o=e.useEditorStore(f=>f.frame),i=(s==null?void 0:s.visualType)||"single",{setCustomCardPreferences:a}=e.useEditorActions(),{components:l,manifest:x}=e.useCustomVisual((s==null?void 0:s.url)||""),u=(p=x==null?void 0:x.visuals)==null?void 0:p.find(f=>f.name===(s==null?void 0:s.componentName));function d(f,O){if(!s)return;const N={...(s==null?void 0:s.dataInputCardIds)||{},[f]:{cardId:O,hookRef:null}};a({...s,dataInputCardIds:N})}function h(f){var D,N;const O=(D=o==null?void 0:o.cards)==null?void 0:D.filter(v=>{var A;return((A=v==null?void 0:v.customCardPreferences)==null?void 0:A.visualType)!=="multiple"}).map(v=>({value:v.id,label:v.tabTitle||v.title}));return e.jsxRuntimeExports.jsx("div",{className:"space-y-2",children:(N=f==null?void 0:f.dataInputs)==null?void 0:N.map((v,A)=>{var F,z;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:v}),e.jsxRuntimeExports.jsx(te,{className:"col-span-6 h-8 w-full justify-between",label:"",options:O||[],value:((z=(F=s==null?void 0:s.dataInputCardIds)==null?void 0:F[A])==null?void 0:z.cardId)||"",onValueChange:R=>d(A,R)})]},A+Math.random())})})}function g(f,O,D=[]){var N,v;return s?f==="input"?e.jsxRuntimeExports.jsx(e.Input,{className:`h-8 w-full ${e.removeRing}`,value:((N=s==null?void 0:s.settings)==null?void 0:N[O])||"",onChange:A=>{a({...s,settings:{...s==null?void 0:s.settings,[O]:A.target.value}})}},O):f==="select"?e.jsxRuntimeExports.jsx(te,{className:"h-8 w-full",label:"",options:D,value:((v=s==null?void 0:s.settings)==null?void 0:v[O])||"",onValueChange:A=>{a({...s,settings:{...s==null?void 0:s.settings,[O]:A}})}}):null:null}function c(f){const O=Object.entries((f==null?void 0:f.settings)||{});return e.jsxRuntimeExports.jsx("div",{className:"space-y-3",children:O.map(([D,N])=>e.jsxRuntimeExports.jsxs("div",{className:"space-y-2",children:[e.jsxRuntimeExports.jsx(e.Label,{children:N.title}),g(N.ui,D,N.options)]},D))})}function m(f){s&&a({...s,visualType:f,componentName:""})}return e.jsxRuntimeExports.jsxs("div",{className:"p-6",children:[e.jsxRuntimeExports.jsx(me,{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(te,{className:"h-8 w-full",label:"",options:t,value:(s==null?void 0:s.url)||"",onValueChange:f=>a({...s||{url:"",componentName:""},url:f})})})}),((s==null?void 0:s.type)==="component"||(s==null?void 0:s.type)===void 0)&&e.jsxRuntimeExports.jsx(Tt,{options:[{value:"single",label:"Single Visual"},{value:"multiple",label:"Multi-Visual"}],value:i,onValueChange:m}),((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(te,{className:"h-8 w-full",label:"",options:(l==null?void 0:l.filter(f=>f.type===i).map(f=>({value:f.name,label:f.name})))||[],value:s.componentName,onValueChange:f=>{console.log("changing value",f),a({...s,componentName:f})}})})]})})]})})}),e.jsxRuntimeExports.jsx(e.Separator,{className:"my-4"}),((y=r==null?void 0:r.customCardPreferences)==null?void 0:y.componentName)&&e.jsxRuntimeExports.jsxs(me,{summary:"Component Settings",children:[u&&u.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:h(u)})]}),u&&u.settings&&e.jsxRuntimeExports.jsx("div",{className:"space-y-3",children:e.jsxRuntimeExports.jsx("div",{className:"px-2",children:c(u)})})]})]})}function ae(){const[s,n]=S.useState([]);e.useEditorStore(d=>d.card.cfg);const t=e.useEditorStore(d=>d.card.preferences),{setCardCfg:r,setFilterOnClickColumnIndex:o,setCardPreferences:i}=e.useEditorStore(d=>d.actions),a=e.useEditorStore(d=>d.queryResultColumns);e.useEditorStore(d=>{var h;return(h=d.card.preferences)==null?void 0:h.filterOnClickColumnIndex}),S.useEffect(()=>{a&&n(new Array(a.length).fill(!1))},[a]);function l(d,h){var g,c;h?t!=null&&t.onClickFilter&&((g=t==null?void 0:t.onClickFilter)==null?void 0:g.length)>0?i({...t,onClickFilter:[...t.onClickFilter,{columnIndex:d,expression:""}]}):i({...t,onClickFilter:[{columnIndex:d,expression:""}]}):(i({...t,onClickFilter:(c=t==null?void 0:t.onClickFilter)==null?void 0:c.filter(m=>m.columnIndex!==d)}),n(m=>{const p=[...m];return p[d]=!1,p}))}function x(d,h){var c;const g=(c=t==null?void 0:t.onClickFilter)==null?void 0:c.map(m=>m.columnIndex===d?{...m,expression:h.target.value}:m);i({...t,onClickFilter:g})}function u(d){var h,g,c,m;if(s!=null&&s[d]||(g=(h=t==null?void 0:t.onClickFilter)==null?void 0:h.find(p=>p.columnIndex===d))!=null&&g.expression)return e.jsxRuntimeExports.jsx(e.Input,{value:(m=(c=t==null?void 0:t.onClickFilter)==null?void 0:c.find(p=>p.columnIndex===d))==null?void 0:m.expression,onChange:p=>x(d,p),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"}),a==null?void 0:a.map((d,h)=>{var g,c;return e.jsxRuntimeExports.jsx("div",{className:"xbg-red-100 group flex items-center justify-between space-y-2",children:e.jsxRuntimeExports.jsxs("div",{className:"grow",children:[e.jsxRuntimeExports.jsxs("div",{className:"flex items-center space-x-2 py-2",children:[e.jsxRuntimeExports.jsx(e.Checkbox,{checked:!!((g=t==null?void 0:t.onClickFilter)!=null&&g.find(m=>m.columnIndex===h)),onCheckedChange:m=>l(h,m)}),e.jsxRuntimeExports.jsx("label",{className:"text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70",children:d}),e.jsxRuntimeExports.jsx("div",{className:"flex items-center gap-2",children:((c=t==null?void 0:t.onClickFilter)==null?void 0:c.find(m=>m.columnIndex===h))&&e.jsxRuntimeExports.jsx(e.Pencil,{onClick:()=>{n(m=>{const p=[...m];return p[h]=!m[h],p})},className:"invisible size-3 cursor-pointer text-gray-400 group-hover:visible"})})]}),u(h)]})},d)})]})}function ye(){var a,l,x;const s=e.useEditorStore(u=>u.card.preferences),n=e.useEditorStore(u=>u.card.cfg),{setCardCfg:t,setCardPreferences:r,setChartOrientation:o}=e.useEditorStore(u=>u.actions);(a=n==null?void 0:n.options)!=null&&a.indexAxis;function i(u){o(u)}return e.jsxRuntimeExports.jsxs(e.RadioGroup,{value:((l=s==null?void 0:s.chartOptions)==null?void 0:l.indexAxis)||((x=n==null?void 0:n.options)==null?void 0:x.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 je="focus-visible:ring-0 focus-visible:ring-ring focus-visible:ring-offset-0";function $e(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 Vs(){var q,H,G,X,J,B;const[s,n]=S.useState(!1),t=e.useEditorStore(V=>{var T;return(T=V.card)==null?void 0:T.preferences}),r=e.useEditorStore(V=>{var T;return(T=V.card)==null?void 0:T.cfg}),o=e.getNumberAxis(t,r),[i,a]=S.useState($e(t)),[l,x]=S.useState(((G=(H=(q=t==null?void 0:t.chartOptions)==null?void 0:q.scales)==null?void 0:H[o])==null?void 0:G.min)||""),[u,d]=S.useState(((B=(J=(X=t==null?void 0:t.chartOptions)==null?void 0:X.scales)==null?void 0:J[o])==null?void 0:B.max)||""),[h,g]=S.useState(l||u?"custom":"auto"),[c,m]=S.useState(""),[p,y]=S.useState(0),[f,O]=S.useState(""),[D,N]=S.useState(""),[v,A]=S.useState(""),F=e.useEditorStore(V=>V.actions.setCardPreferences),{updateCardInFrame:z}=e.useEditorActions(),R=e.useEditorStore(V=>V.card),j=e.useEditorStore(V=>{var T;return(T=V.card)==null?void 0:T.type}),E=["pie","doughnut","polarArea"].includes(j);S.useEffect(()=>{var V,T,W,U,K,Q,$,Y,w,L,_,ne,le,oe;a($e(t)),x(((W=(T=(V=t==null?void 0:t.chartOptions)==null?void 0:V.scales)==null?void 0:T[o])==null?void 0:W.min)===0?0:""),d(((Q=(K=(U=t==null?void 0:t.chartOptions)==null?void 0:U.scales)==null?void 0:K[o])==null?void 0:Q.max)||""),m(((L=(w=(Y=($=t==null?void 0:t.chartOptions)==null?void 0:$.scales)==null?void 0:Y[o])==null?void 0:w.ticks)==null?void 0:L.stepSize)||""),y(((_=t==null?void 0:t.numberAxisFormat)==null?void 0:_.decimalPlaces)||0),O(((ne=t==null?void 0:t.numberAxisFormat)==null?void 0:ne.suffix)||""),N(((le=t==null?void 0:t.numberAxisFormat)==null?void 0:le.currency)||""),A(((oe=t==null?void 0:t.numberAxisFormat)==null?void 0:oe.locale)||"")},[s,t,o]);function b(V,T){return T===""||/^[0-9\b]+$/.test(T)?Number(T):Number(V)}function I(){const V=[...new Set(e.LOCALE_CURRENCY_PAIRS.map(T=>T.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:D||"none",onValueChange:T=>N(T==="none"?"":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,{children:e.jsxRuntimeExports.jsxs(e.SelectGroup,{children:[e.jsxRuntimeExports.jsx(e.SelectLabel,{children:"Currency"}),e.jsxRuntimeExports.jsx(e.SelectItem,{value:"none",children:"None"}),V.map(T=>e.jsxRuntimeExports.jsx(e.SelectItem,{value:T,children:T},T))]})})]}),e.jsxRuntimeExports.jsxs(e.Select,{value:v,onValueChange:T=>A(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,{children:e.jsxRuntimeExports.jsxs(e.SelectGroup,{children:[e.jsxRuntimeExports.jsx(e.SelectLabel,{children:"Locale"}),e.LOCALE_CURRENCY_PAIRS.map(T=>e.jsxRuntimeExports.jsx(e.SelectItem,{value:T.locale,children:T.locale},T.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:p,onChange:T=>y(Number(T.target.value)),id:"format",className:`col-span-6 h-8 w-full tracking-wide ${je}`})]})]})}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:V=>x(T=>b(T,V.target.value)),className:`col-span-1 h-8 w-full ${je}`}),e.jsxRuntimeExports.jsx(e.Input,{value:u,onChange:V=>d(T=>b(T,V.target.value)),id:"max",className:`col-span-1 h-8 w-full ${je}`})]}),e.jsxRuntimeExports.jsxs("div",{className:"grid grid-cols-3 items-center gap-2",children:[e.jsxRuntimeExports.jsx(e.Label,{htmlFor:"step-size",children:"Step Size"}),e.jsxRuntimeExports.jsx(e.Input,{value:c,onChange:V=>m(T=>b(T,V.target.value)),id:"step-size",className:`col-span-1 h-8 w-full ${je}`})]})]})}function P(){var U;let V={};h==="custom"&&(V={min:l,max:u,ticks:{stepSize:c}});const T={...t||{},chartOptions:{...t==null?void 0:t.chartOptions,scales:{...(U=t==null?void 0:t.chartOptions)==null?void 0:U.scales,[o]:{type:i,...i==="linear"?V:{}}}},numberAxisFormat:{decimalPlaces:p,suffix:f,currency:D,locale:v}};console.log(T),F(T);const W={...R,preferences:T};z(W)}return e.jsxRuntimeExports.jsxs(e.Popover,{onOpenChange:V=>n(V),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:E,value:i,onValueChange:V=>a(V),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:E,id:"scale-option",value:h,onValueChange:V=>g(V),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"})]})]})]}),h==="custom"&&i=="linear"&&M(),I(),e.jsxRuntimeExports.jsx(e.SelectSeparator,{}),e.jsxRuntimeExports.jsx("div",{className:"grid grid-cols-3",children:e.jsxRuntimeExports.jsx(e.Button,{onClick:P,variant:"secondary",className:"col-span-1 col-start-3 h-8 w-full",children:"Apply"})})]})]})})]})}function At({idx:s}){var l;const n=e.useEditorStore(x=>{var u;return(u=x.card)==null?void 0:u.preferences}),t=e.useEditorStore(x=>{var u;return(u=x.card.preferences)==null?void 0:u.datasetOptions}),r=e.useEditorStore(x=>x.actions.setCardPreferences),o=(l=n==null?void 0:n.chartOptions)==null?void 0:l.indexAxis,i=t==null?void 0:t.find(x=>x.idx===s);function a(x,u){(x==="end"||x==="start")&&e.getContrastColor(e.getCanvasBackgroundColor());const d={display:x!=="none",align:x,anchor:x,clamp:!0};if(!i)r({...n,datasetOptions:[...t||[],{idx:u,datalabels:d}]});else{const h={...i};h.datalabels=d;const g=t==null?void 0:t.map(c=>c.idx===u?h:c);r({...n,datasetOptions:g})}}return e.jsxRuntimeExports.jsxs(e.Popover,{children:[e.jsxRuntimeExports.jsx(e.PopoverTrigger,{children:e.jsxRuntimeExports.jsx(fs,{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:()=>a("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:()=>a("start",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"})})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>a("center",s),size:"sm",variant:"secondary",className:"h-7 p-1 text-xs font-normal",children:e.jsxRuntimeExports.jsx(ls,{className:e.cn("h-4 w-4",{"rotate-90":o==="y"})})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>a("end",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"})})})]})})]})}function qs(){const s=e.useEditorStore(u=>u.card),n=e.useEditorStore(u=>{var d,h,g;return(g=(h=(d=u==null?void 0:u.card)==null?void 0:d.preferences)==null?void 0:h.chartOptions)==null?void 0:g.indexAxis}),{data:t}=e.useDashboardCardQuery(s),r=n==="y"?"Y axis":"X axis",o=n==="y"?"X axis":"Y axis",{keys:i,metricKeys:a,dimensionKeys:l}=e.getKeys((t==null?void 0:t.records)||[]);let x=a;if(["stackedBar","stackedLine"].includes(s.type)){const u=e.pivotData({dataArray:(t==null?void 0:t.records)||[],groupKey:l[0],pivotKey:l[1],valueKey:x[0]}),{metricKeys:d}=e.getKeys(u);x=d}return i.length===0?null:e.jsxRuntimeExports.jsxs("div",{className:"space-y-4",children:[e.jsxRuntimeExports.jsxs("div",{className:"space-y-2",children:[e.jsxRuntimeExports.jsx(e.Label,{children:r}),e.jsxRuntimeExports.jsx("div",{className:"my-1 space-y-1",children:e.jsxRuntimeExports.jsx("div",{className:"rounded-md bg-muted/70 px-3 py-2 hover:bg-muted",children:e.jsxRuntimeExports.jsx("p",{title:l[0],children:Bs(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(Vs,{})]}),e.jsxRuntimeExports.jsx("div",{className:"my-1 max-h-[125px] space-y-1 overflow-y-auto",children:x.map((u,d)=>e.jsxRuntimeExports.jsx(zt,{col:u,idx:d},u))})]})]})}function Bs(s,n=30){return s.length>n?s.slice(0,n)+"...":s}function zt({col:s,idx:n}){const t=e.useEditorStore(l=>{var x;return(x=l.card)==null?void 0:x.preferences}),r=e.useEditorStore(l=>{var x;return(x=l.card.preferences)==null?void 0:x.datasetOptions}),o=r==null?void 0:r.find(l=>l.idx===n),{setCardPreferences:i}=e.useEditorStore(l=>l.actions);function a(l){if(!o)i({...t,datasetOptions:[...r||[],{idx:n,type:l==="area"?"line":l,fill:l==="area"?"origin":""}]});else{const x={...o};x.type=l==="area"?"line":l,x.fill=l==="area"?"origin":"";const u=r==null?void 0:r.map(d=>d.idx===n?x:d);i({...t,datasetOptions:u})}}return e.jsxRuntimeExports.jsxs("div",{className:"group flex items-center justify-between gap-5 rounded-md bg-muted/70 px-3 py-2 hover:bg-muted",children:[e.jsxRuntimeExports.jsx("p",{title:s,children:Bs(s)}),e.jsxRuntimeExports.jsxs("div",{className:"flex gap-2",children:[e.jsxRuntimeExports.jsx(ge,{onClick:()=>a("bar"),className:"invisible size-4 cursor-pointer text-muted-foreground hover:text-foreground group-hover:visible"}),e.jsxRuntimeExports.jsx(Re,{onClick:()=>a("line"),className:"invisible size-4 cursor-pointer text-muted-foreground hover:text-foreground group-hover:visible"}),e.jsxRuntimeExports.jsx(We,{onClick:()=>a("area"),className:"invisible size-4 cursor-pointer text-muted-foreground hover:text-foreground group-hover:visible"}),e.jsxRuntimeExports.jsx(At,{idx:n})]})]})}function _s(){const s=e.useEditorStore(c=>c.selectedConnectionId),n=e.useEditorStore(c=>c.selectedDatamodelId),t=e.useEditorStore(c=>c.selectedDatabaseName),r=e.useEditorStore(c=>c.selectedSchemaName),o=e.useEditorStore(c=>c.selectedTableName),i=e.useDashboardStore(c=>c.dashboard.filters)||[],a=e.useDashboardStore(c=>c.actions.addFilter),l=e.useDashboardStore(c=>c.actions.removeFilter),{removeFilterValues:x}=e.useDashboardActions(),{modelItems:u,tableName:d,connectionType:h}=re();function g(c,m="dashboard"){var F;const p=e.fmt(c.column_name),y=e.fmt(t||""),f=e.fmt(r||""),O=e.fmt(d);let D=e.getQualifiedTableName(f,O,h),N=`${D}.${p}`;const v=(F=u==null?void 0:u.find(z=>z.id===n))==null?void 0:F.name;n&&n!=="none"&&(N=`${e.DATAMODEL_NAMESPCACE}.${v}.${p}`,D=`${e.DATAMODEL_NAMESPCACE}.${v}`);const A=i==null?void 0:i.find(z=>z.column===N&&z.table===O&&(z.database===y||z.database===t));if(A)x(A.id),l(A.id);else{const z=e.v4();return d==="api"&&s?(a({location:m,id:z,column:N,title:c.column_name,dataType:c.data_type,table:"api",database:"",connectionId:s,operation:"in",sql:e.getDefaultFilterSql(c.data_type,D,p)}),z):(a({id:z,location:m,column:N,title:c.column_name,dataType:c.data_type,table:o||"",database:t||"",connectionId:s||"",operation:"in",sql:e.getDefaultFilterSql(c.data_type,D,p)}),z)}}return{assignFilter:g}}function ue(){const s=e.useDashboardStore(l=>l.dashboard.filters),n=e.useEditorStore(l=>l.frame),{setFrame:t}=e.useEditorActions(),{columns:r}=re(),{assignFilter:o}=_s();function i(l){const x=o(l,"frame");t({...n,filterId:x})}const a=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(Ot,{onSelect:i,columns:r}),a&&e.jsxRuntimeExports.jsx(e.FilterHeader,{filter:a})]})}function Ot({columns:s,onSelect:n}){var a;const[t,r]=_e.useState(!1),[o,i]=_e.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?(a=s.find(l=>l.column_name===o))==null?void 0:a.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:x=>{const u=x===o?"":x;i(u),r(!1),u&&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 Mt({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/docs/charts/bar-line-area",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(ye,{}),e.jsxRuntimeExports.jsx(qs,{})]})]}),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(ue,{})]})]})]})})}function ze(){var o,i,a;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 d;const x={datalabels:{display:l!=="none",align:l,anchor:l,clamp:!0}},u={...s,options:{...s==null?void 0:s.options,plugins:{...(d=s==null?void 0:s.options)==null?void 0:d.plugins,...x}}};n(u),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(Vs,{})]}),e.jsxRuntimeExports.jsxs(e.Select,{value:(a=(i=(o=s==null?void 0:s.options)==null?void 0:o.plugins)==null?void 0:i.datalabels)==null?void 0:a.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 Ft({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/docs/charts/bubble",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(ze,{})})]}),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(ue,{})]})]})]})})}const Vt={datasets:[{type:"line",label:"Sum_sales",data:[]},{type:"bar",label:"Sum_profit",data:[]}]},qt={datasets:[{fill:"origin",type:"line",label:"Sum_sales",data:[]}]};function Bt(){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:_t(s)}),e.jsxRuntimeExports.jsx("section",{className:"",children:["line","bar"].includes(s)&&e.jsxRuntimeExports.jsx(ye,{})}),!["kpi"].includes(s)&&e.jsxRuntimeExports.jsxs("div",{className:"space-y-4",children:[e.jsxRuntimeExports.jsx(ze,{}),e.jsxRuntimeExports.jsx(ae,{}),e.jsxRuntimeExports.jsx(ue,{})]})]})}function _t(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(Vt,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(qt,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 Pt(){var x,u,d,h,g;const s=e.useEditorStore(c=>c.card.preferences),n=e.useEditorStore(c=>c.actions.setCardPreferences),t=e.useEditorStore(c=>c.actions.setNumberFormat);e.useEditorStore(c=>{var m,p;return(p=(m=c.card.preferences)==null?void 0:m.formatNumber)==null?void 0:p.decimalPlaces});const r=e.useEditorStore(c=>{var m,p;return(p=(m=c.card.preferences)==null?void 0:m.formatNumber)==null?void 0:p.locale}),o=e.useEditorStore(c=>{var m,p;return(p=(m=c.card.preferences)==null?void 0:m.formatNumber)==null?void 0:p.currency});e.useEditorStore(c=>c.actions.setFilterOnClickField);const i=e.useEditorStore(c=>{var m,p;return(p=(m=c.card.preferences)==null?void 0:m.formatNumber)==null?void 0:p.colorRanges})||[],a=e.useEditorStore(c=>c.actions.setColorRanges),l=[...new Set(e.LOCALE_CURRENCY_PAIRS.map(c=>c.currency))];return e.jsxRuntimeExports.jsxs("div",{children:[e.jsxRuntimeExports.jsxs("div",{className:"mb-3 flex items-center gap-2",children:[e.jsxRuntimeExports.jsx(e.Checkbox,{checked:!!((x=s==null?void 0:s.formatNumber)!=null&&x.enabled),onCheckedChange:c=>{n({...s,formatNumber:{...s==null?void 0:s.formatNumber,enabled:c}})}}),e.jsxRuntimeExports.jsx(e.Label,{children:"Format Number"})]}),((u=s==null?void 0:s.formatNumber)==null?void 0:u.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:c=>{var m,p,y;return t(((m=s==null?void 0:s.formatNumber)==null?void 0:m.decimalPlaces)||0,((p=s==null?void 0:s.formatNumber)==null?void 0:p.currency)||"",c,((y=s==null?void 0:s.formatNumber)==null?void 0:y.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(c=>e.jsxRuntimeExports.jsx(e.SelectItem,{value:c.locale,children:c.locale},c.locale))]})})]})]}),e.jsxRuntimeExports.jsxs("div",{className:"w-full space-y-1",children:[e.jsxRuntimeExports.jsx(e.Label,{children:"Currency"}),e.jsxRuntimeExports.jsxs(e.Select,{value:o||"none",onValueChange:c=>{var m,p,y;console.log("currency",c),t(((m=s==null?void 0:s.formatNumber)==null?void 0:m.decimalPlaces)||0,c==="none"?"":c,((p=s==null?void 0:s.formatNumber)==null?void 0:p.locale)||"",((y=s==null?void 0:s.formatNumber)==null?void 0:y.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(c=>e.jsxRuntimeExports.jsx(e.SelectItem,{value:c,children:c},c))]})})]})]})]}),e.jsxRuntimeExports.jsxs("div",{className:"flex gap-2",children:[e.jsxRuntimeExports.jsxs("div",{className:"w-full space-y-1",children:[e.jsxRuntimeExports.jsx(e.Label,{children:"Decimals"}),e.jsxRuntimeExports.jsxs(e.Select,{value:((h=(d=s==null?void 0:s.formatNumber)==null?void 0:d.decimalPlaces)==null?void 0:h.toString())||"0",onValueChange:c=>{var m,p,y;return t(Number(c),((m=s==null?void 0:s.formatNumber)==null?void 0:m.currency)||"",((p=s==null?void 0:s.formatNumber)==null?void 0:p.locale)||"",((y=s==null?void 0:s.formatNumber)==null?void 0:y.suffix)||"")},children:[e.jsxRuntimeExports.jsx(e.SelectTrigger,{className:"col-span-3 h-8 w-full focus:ring-1 focus:ring-offset-0",children:e.jsxRuntimeExports.jsx(e.SelectValue,{})}),e.jsxRuntimeExports.jsx(e.SelectContent,{children:["0","1","2","3","4"].map(c=>e.jsxRuntimeExports.jsx(e.SelectItem,{value:c,children:c},c))})]})]}),e.jsxRuntimeExports.jsxs("div",{className:"w-full space-y-1",children:[e.jsxRuntimeExports.jsx(e.Label,{children:"Suffix"}),e.jsxRuntimeExports.jsx(e.Input,{value:((g=s==null?void 0:s.formatNumber)==null?void 0:g.suffix)||"",className:"h-8 font-mono text-xs focus-visible:ring-0 focus-visible:ring-ring focus-visible:ring-offset-0",placeholder:"K, M, B, %",onChange:c=>{var m,p,y;return t(((m=s==null?void 0:s.formatNumber)==null?void 0:m.decimalPlaces)||0,((p=s==null?void 0:s.formatNumber)==null?void 0:p.currency)||"",((y=s==null?void 0:s.formatNumber)==null?void 0:y.locale)||"",c.target.value)}})]})]})]})}),e.jsxRuntimeExports.jsx(e.Separator,{className:"my-3"}),e.jsxRuntimeExports.jsx(e.ColorFormat,{colorRanges:i,setColorRanges:a})]})]})}function Ht(){return e.jsxRuntimeExports.jsxs("div",{className:"space-y-6 px-6 py-2",children:[e.jsxRuntimeExports.jsx(e.Accordion,{type:"single",collapsible:!0,children:e.jsxRuntimeExports.jsxs(e.AccordionItem,{value:"item-1",children:[e.jsxRuntimeExports.jsx(e.AccordionTrigger,{className:"",children:"KPI Query"}),e.jsxRuntimeExports.jsxs(e.AccordionContent,{className:"font-mono",children:[e.jsxRuntimeExports.jsx("div",{className:"rounded bg-muted px-2 py-1 font-mono text-xs",children:"SELECT current, previous FROM table"}),e.jsxRuntimeExports.jsxs("ul",{className:"my-6 ml-6 list-disc text-xs [&>li]:mt-2",children:[e.jsxRuntimeExports.jsx("li",{children:"current - number"}),e.jsxRuntimeExports.jsx("li",{children:"previous - number"})]}),e.jsxRuntimeExports.jsxs("div",{children:["See ",e.jsxRuntimeExports.jsx("a",{target:"_blank",onClick:s=>s.stopPropagation(),className:"text-blue-700",href:"https://docs.semaphor.cloud/docs/charts/kpi",children:"example"})," in the docs."]})]})]})}),e.jsxRuntimeExports.jsx("section",{className:"",children:e.jsxRuntimeExports.jsx(Pt,{})}),e.jsxRuntimeExports.jsx("div",{}),e.jsxRuntimeExports.jsx("div",{})]})}const Gt=[{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"}],Ut=["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"],$t=Ut.map(s=>({label:s,value:s}));function Qt(){var x,u,d,h,g,c,m,p,y,f,O,D,N,v,A,F,z,R;const s=e.useEditorStore(j=>j.card),n=(u=(x=s==null?void 0:s.preferences)==null?void 0:x.mapVisualOptions)==null?void 0:u.topoJsonUrl,[t,r]=S.useState(((h=(d=s==null?void 0:s.preferences)==null?void 0:d.mapVisualOptions)==null?void 0:h.customTopoJsonUrl)||""),{setCardPreferences:o}=e.useEditorActions(),{data:i}=e.useTopoJson(s),a=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(me,{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(me,{open:!0,summary:"Settings",children:e.jsxRuntimeExports.jsxs("div",{className:"space-y-3 px-2",children:[e.jsxRuntimeExports.jsx(te,{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(te,{className:"h-9",options:a,value:((c=(g=s.preferences)==null?void 0:g.mapVisualOptions)==null?void 0:c.objectKey)||"",label:"Map Object",onValueChange:j=>{var E;o({...s.preferences,mapVisualOptions:{...(E=s.preferences)==null?void 0:E.mapVisualOptions,objectKey:j}})}})]}),e.jsxRuntimeExports.jsxs("div",{className:"space-y-1",children:[e.jsxRuntimeExports.jsx(e.Label,{children:"Projection"}),e.jsxRuntimeExports.jsx(te,{className:"h-9",options:Gt,value:((p=(m=s.preferences)==null?void 0:m.mapVisualOptions)==null?void 0:p.projection)||"",label:"Projection",onValueChange:j=>{var E;o({...s.preferences,mapVisualOptions:{...(E=s.preferences)==null?void 0:E.mapVisualOptions,projection:j}})}})]}),e.jsxRuntimeExports.jsxs("div",{className:"space-y-1",children:[e.jsxRuntimeExports.jsx(e.Label,{children:"Colors"}),e.jsxRuntimeExports.jsx(te,{className:"h-9",options:$t,value:((f=(y=s.preferences)==null?void 0:y.mapVisualOptions)==null?void 0:f.colorScale)||"",label:"Select Color Scale",onValueChange:j=>{var E;o({...s.preferences,mapVisualOptions:{...(E=s.preferences)==null?void 0:E.mapVisualOptions,colorScale:j}})}})]})]})]})}),e.jsxRuntimeExports.jsx(e.Separator,{className:"my-4"}),e.jsxRuntimeExports.jsx(me,{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:((D=(O=s.preferences)==null?void 0:O.mapVisualOptions)==null?void 0:D.projectionScale)||1,onChange:j=>{var E;o({...s.preferences,mapVisualOptions:{...(E=s.preferences)==null?void 0:E.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:((A=(v=(N=s.preferences)==null?void 0:N.mapVisualOptions)==null?void 0:v.projectionOffset)==null?void 0:A[0])||0,onChange:j=>{var E,b,I,M;o({...s.preferences,mapVisualOptions:{...(E=s.preferences)==null?void 0:E.mapVisualOptions,projectionOffset:[Number(j.target.value),((M=(I=(b=s.preferences)==null?void 0:b.mapVisualOptions)==null?void 0:I.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=(z=(F=s.preferences)==null?void 0:F.mapVisualOptions)==null?void 0:z.projectionOffset)==null?void 0:R[1])||0,onChange:j=>{var E,b,I,M;o({...s.preferences,mapVisualOptions:{...(E=s.preferences)==null?void 0:E.mapVisualOptions,projectionOffset:[((M=(I=(b=s.preferences)==null?void 0:b.mapVisualOptions)==null?void 0:I.projectionOffset)==null?void 0:M[0])||0,Number(j.target.value)]}})}})]})}),e.jsxRuntimeExports.jsx(e.Separator,{className:"my-4"}),e.jsxRuntimeExports.jsx(ae,{})]})}function Jt(){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 he({cardType:s,docContent:n,suffix:t="Chart"}){return e.jsxRuntimeExports.jsx("div",{className:"space-y-6 px-6 py-2",children:e.jsxRuntimeExports.jsxs(e.Accordion,{defaultValue:["item-2"],type:"multiple",children:[e.jsxRuntimeExports.jsxs(e.AccordionItem,{value:"item-1",children:[e.jsxRuntimeExports.jsx(e.AccordionTrigger,{children:`${e.titleCase(s)} ${t}`}),e.jsxRuntimeExports.jsx(e.AccordionContent,{children:n||e.jsxRuntimeExports.jsxs("div",{className:"space-y-4 font-mono text-xs",children:[e.jsxRuntimeExports.jsx("div",{className:"rounded bg-muted px-2 py-1 text-xs",children:"SELECT label, measure FROM table"}),e.jsxRuntimeExports.jsxs("ul",{className:"ml-6 list-disc text-xs [&>li]:mt-2",children:[e.jsxRuntimeExports.jsx("li",{children:"label - category"}),e.jsxRuntimeExports.jsx("li",{children:"measure - number"})]}),e.jsxRuntimeExports.jsxs("div",{children:["See ",e.jsxRuntimeExports.jsx("a",{target:"_blank",onClick:r=>r.stopPropagation(),className:"text-blue-700",href:"https://docs.semaphor.cloud/docs/charts/pie-donut-polar",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(ye,{}),s!=="text"&&e.jsxRuntimeExports.jsx(ze,{}),s==="text"&&e.jsxRuntimeExports.jsx(Jt,{})]})]}),!["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(ue,{})]})]})]})})}function Wt(){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(te,{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/docs/charts/stacked",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(ye,{}),t(),e.jsxRuntimeExports.jsx(qs,{})]})]}),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(ue,{})]})]})]})})}function Kt({}){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(ue,{})]})]})}),e.jsxRuntimeExports.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsxRuntimeExports.jsx(e.Checkbox,{onCheckedChange:t,id:"allow-download"}),e.jsxRuntimeExports.jsx("label",{htmlFor:"allow-download",className:"text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70",children:"Allow Download"})]})]})}const Zt=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/docs/charts/tornado",children:"example"})," in the docs."]})]}),Xt=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/docs/charts/range",children:"example"})," in the docs."]})]}),Yt=e.jsxRuntimeExports.jsxs("div",{className:"space-y-4 font-mono text-xs",children:[e.jsxRuntimeExports.jsx("div",{className:"rounded bg-muted px-2 py-1 text-xs",children:"SELECT 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/docs/charts/text",children:"example"})," in the docs."]})]});function en(){const s=e.useEditorStore(t=>t.card.type);function n(t){switch(t){case"stackedBar":case"stackedLine":return e.jsxRuntimeExports.jsx(Wt,{});case"pyramid":return e.jsxRuntimeExports.jsx(he,{docContent:Zt,cardType:t});case"kpi":return e.jsxRuntimeExports.jsx(Ht,{});case"line":case"bar":return e.jsxRuntimeExports.jsx(Mt,{cardType:t});case"range":return e.jsxRuntimeExports.jsx(he,{docContent:Xt,cardType:t});case"pie":case"doughnut":case"polarArea":case"radar":return e.jsxRuntimeExports.jsx(he,{cardType:t});case"bubble":case"scatter":return e.jsxRuntimeExports.jsx(Ft,{cardType:t});case"table":return e.jsxRuntimeExports.jsx(Kt,{cardType:t});case"text":return e.jsxRuntimeExports.jsx(he,{docContent:Yt,cardType:t,suffix:"Visual"});case"map":return e.jsxRuntimeExports.jsx(Qt,{});case"custom":return e.jsxRuntimeExports.jsx(Lt,{});default:return e.jsxRuntimeExports.jsx(Bt,{})}}return e.jsxRuntimeExports.jsxs(e.ScrollArea,{className:"h-full w-full text-sm",children:[n(s),e.jsxRuntimeExports.jsx(e.ScrollBar,{orientation:"horizontal"})]})}function sn(){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(ht,{})}),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(en,{})})}),e.jsxRuntimeExports.jsx(e.ResizableHandle,{className:"border"}),e.jsxRuntimeExports.jsx(e.ResizablePanel,{minSize:40,defaultSize:75,maxSize:100,children:e.jsxRuntimeExports.jsx(Ue,{})})]}):e.jsxRuntimeExports.jsx(Ue,{})})]})}function tn({authToken:s,onSave:n,onClose:t}){e.useDashboardStore(a=>a.themeStyle);const r=e.useEditorStore(a=>a.actions.setOnSave),o=e.useEditorStore(a=>a.actions.setOnClose),i=e.useDashboardStore(a=>a.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(vs,{})}),e.jsxRuntimeExports.jsx(e.EditorMain,{children:e.jsxRuntimeExports.jsx(sn,{})})]})})}function nn(){e.useDashboardStore(a=>a.selectedCardId);const s=e.useDashboardStore(a=>a.selectedSheetId),{setIsVisualEditing:n}=e.useDashboardStore(a=>a.actions),t=e.useDashboardStore(a=>a.isVisualEditing),r=e.useDashboardStore(a=>a.actions.updateFrame);function o(a){s&&(r(s,a),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(tn,{onSave:o,onClose:i})})}function rn(){const s=e.useEditorStore(i=>i.selectedDatabaseName),n=e.useEditorStore(i=>i.selectedTableName),t=e.useDashboardStore(i=>i.dashboard.filters)||[],{columns:r}=re(),{assignFilter:o}=_s();return e.jsxRuntimeExports.jsx(e.ScrollArea,{className:"flex-1 basis-0 flex-col px-3",children:r==null?void 0:r.map(i=>{const a=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":a}),children:e.jsxRuntimeExports.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxRuntimeExports.jsx(Ss,{column:i}),e.jsxRuntimeExports.jsx("span",{children:i.column_name})]})},i.column_name)})})}function on(){e.useDashboardStore(n=>n.showFilters);const s=e.useDashboardStore(n=>n.actions.setShowFilters);return e.jsxRuntimeExports.jsxs("section",{className:"relative flex min-w-[320px] grow flex-col border-l px-1",children:[e.jsxRuntimeExports.jsxs("div",{className:"mt-4 flex items-center justify-between gap-2 px-3",children:[e.jsxRuntimeExports.jsx(e.Label,{className:"px-2 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(vs,{ColumnsComponent:()=>e.jsxRuntimeExports.jsx(rn,{})})})]})}function an(){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("div",{className:e.cn("mb-1 flex items-center gap-2 border-y px-0.5 pb-0.5",{"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 min-w-[250px] max-w-fit 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 ln(){const s=e.useDashboardStore(r=>r.showFilters),n=e.useDashboardStore(r=>r.isVisualEditing),t=e.useDashboardStore(r=>r.isDashboardEditing);return e.jsxRuntimeExports.jsxs("div",{role:"dashboard-plus-main",className:e.cn("",{"max-h-0 overflow-hidden":n,"flex grow overflow-auto":!n}),children:[e.jsxRuntimeExports.jsxs("section",{className:"flex grow flex-col",children:[t&&e.jsxRuntimeExports.jsx(an,{}),e.jsxRuntimeExports.jsx(e.DashboardTabs,{})]}),s&&e.jsxRuntimeExports.jsx("div",{role:"filter-aside-container",className:"flex",children:e.jsxRuntimeExports.jsx(on,{})})]})}function cn(){const s=e.useDashboardStore(o=>o.dashboard),n=e.useDashboardStore(o=>o.actions.setDashboard),t=e.useDashboardStore(o=>o.showDashboardJSON),r=e.useDashboardStore(o=>o.actions.setShowDashboardJSON);return e.jsxRuntimeExports.jsxs("div",{className:e.cn("relative p-2",{hidden:!t}),children:[e.jsxRuntimeExports.jsxs(e.Button,{variant:"secondary",size:"sm",className:"absolute right-2 top-2 z-10 h-8",onClick:()=>r(!1),children:[e.jsxRuntimeExports.jsx(e.X,{className:"mr-2 h-4 w-4"}),"Close"]}),e.jsxRuntimeExports.jsx(e.de,{onChange:o=>{if(o)try{JSON.parse(o),n(JSON.parse(o))}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 xn({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(cn,{}),e.jsxRuntimeExports.jsxs(e.DashboardPanel,{...t,children:[s&&e.jsxRuntimeExports.jsx(Ks,{}),e.jsxRuntimeExports.jsx(nn,{}),e.jsxRuntimeExports.jsx(ln,{})]})]})]})})}exports.Box=Qe;exports.Braces=Je;exports.ChartArea=We;exports.ChartColumnIncreasing=ge;exports.ChartLine=Re;exports.ChartNoAxesGantt=ke;exports.ChartPie=Ie;exports.ChartScatter=De;exports.CircleX=Ke;exports.CopyPlus=Ze;exports.DashboardPlus=xn;exports.Database=Xe;exports.EllipsisVertical=be;exports.Eraser=Ye;exports.EyeClosed=es;exports.FileJson2=ss;exports.Glasses=ts;exports.Hammer=ns;exports.Hash=rs;exports.House=os;exports.ListEnd=is;exports.ListStart=as;exports.ListX=ls;exports.LoaderCircle=xe;exports.Map=Te;exports.MessageSquareMore=cs;exports.Network=xs;exports.Plug2=us;exports.RefreshCw=ds;exports.Save=ms;exports.SelectComponent=ce;exports.Shapes=Le;exports.ShieldQuestion=ps;exports.Sigma=js;exports.SwatchBook=hs;exports.Table=Se;exports.Tag=fs;exports.TicketX=Es;exports.ToggleLeft=gs;exports.Type=ve;exports.cleanCard=Rs;exports.downloadPdf=bs;exports.getDashbaordStateWithoutData=Ae;exports.useEditorAside=re;
|