react-semaphor 0.0.425 → 0.0.426
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/index.cjs +1 -1
- package/dist/index.js +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -349,4 +349,4 @@
|
|
|
349
349
|
${d}
|
|
350
350
|
|
|
351
351
|
`;b(C)}function $(){return e.jsxs(e.Fragment,{children:[r&&e.jsx("div",{className:"relative flex w-1/3 min-w-0 grow overflow-hidden text-xs",role:"editor-filter-container",children:e.jsx("div",{className:"mt-2 w-[99%]",children:e.jsx(mn,{jsonString:JSON.stringify(m,null,2)})})}),m&&m.length>0&&e.jsx(t.Button,{variant:"ghost",onClick:()=>o(!r),className:"absolute bottom-0 right-6 size-7 p-1",children:r?e.jsx(t.X,{className:"size-3.5 text-muted-foreground"}):e.jsx(ut,{className:"size-3.5 text-muted-foreground"})})]})}function B(){return e.jsxs(t.ResizablePanelGroup,{className:"flex grow pb-1",direction:"vertical",role:"editor-resizable-group",children:[e.jsxs(t.ResizablePanel,{id:"1",order:1,defaultSize:a?20:100,className:"relative flex grow",children:[e.jsx("div",{id:"sql-container",className:"relative flex w-[99%]",children:e.jsx(dn,{})}),a&&e.jsx("code",{className:"absolute right-6 top-3 text-xs text-muted-foreground/70",children:"sql"})]}),a&&e.jsxs(e.Fragment,{children:[e.jsx(t.ResizableHandle,{withHandle:!0,className:"border"}),e.jsxs(t.ResizablePanel,{id:"2",order:2,defaultSize:80,className:"relative flex grow",children:[e.jsx("div",{id:"python-container",className:"relative flex w-[99%] pt-0",children:e.jsx(un,{})}),e.jsx("code",{className:"absolute right-6 top-3 text-xs text-muted-foreground/70",children:"python"})]})]})]})}function I(){return e.jsxs("div",{role:"editor-controls",className:"item-center flex flex-wrap justify-between gap-2 px-6 py-4",children:[e.jsxs("div",{className:"flex grow items-center gap-2",children:[e.jsxs(t.Button,{title:"Shift + Enter",disabled:R||F,onClick:()=>{D()},className:"shrink-0",size:"sm",children:[R||F?e.jsx(re,{className:"mr-2 h-4 w-4 animate-spin"}):e.jsx(t.Play,{className:"mr-2 h-4 w-4"}),"Run"]}),e.jsx(It,{sql:M==null?void 0:M.sql,error:y,onClick:G}),e.jsx(Ot,{}),e.jsx(t.Toggle,{pressed:a,onPressedChange:C=>n(C),className:"",size:"sm",children:e.jsx(cn,{className:"size-4 text-foreground/70"})}),e.jsx("button",{disabled:i,onClick:()=>{_(),O(!0)},className:"h-9 w-full cursor-text px-3 text-left text-sm text-muted-foreground",children:i?"":"Type your question..."})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Lt,{}),e.jsx(Mt,{})]})]})}return e.jsxs("section",{role:"editor-section",className:"flex grow flex-col justify-end",children:[e.jsxs("div",{className:"relative flex grow justify-between overflow-y-scroll",children:[B(),$()]}),I()]})}function fn({data:s}){var i;const[a,n]=k.useState([]),o=Object.keys(s[0]).map(d=>({accessorKey:d,header:({column:m})=>{const p=m.getIsSorted();return e.jsx("div",{className:"flex gap-2",children:e.jsxs("div",{className:"flex cursor-pointer items-center",onClick:()=>m.toggleSorting(m.getIsSorted()==="asc"),children:[d,p==="asc"?e.jsx(t.TriangleUpIcon,{className:"ml-2 h-5 w-5"}):p==="desc"?e.jsx(t.TriangleDownIcon,{className:"ml-2 h-5 w-5"}):null]})})}})),l=t.useReactTable({data:s,columns:o,getCoreRowModel:t.getCoreRowModel(),getPaginationRowModel:t.getPaginationRowModel(),onSortingChange:n,getSortedRowModel:t.getSortedRowModel(),manualPagination:!0,state:{sorting:a}});return e.jsx(t.CustomScrollArea,{className:"grow overflow-auto font-mono text-xs text-foreground/95",children:e.jsxs("table",{className:"w-full",children:[e.jsx(t.TableHeader,{className:"sticky top-0 z-50 h-0 bg-muted",children:l.getHeaderGroups().map(d=>e.jsx(t.TableRow,{className:"",children:d.headers.map(m=>e.jsx(t.TableHead,{className:"h-11 font-semibold text-foreground",children:m.isPlaceholder?null:t.flexRender(m.column.columnDef.header,m.getContext())},m.id))},d.id))}),e.jsx(t.TableBody,{children:(i=l.getRowModel().rows)!=null&&i.length?l.getRowModel().rows.map(d=>e.jsx(t.TableRow,{className:"h-11 whitespace-nowrap py-2","data-state":d.getIsSelected()&&"selected",children:d.getVisibleCells().map(m=>e.jsx(t.TableCell,{className:"py-2",children:t.flexRender(m.column.columnDef.cell,m.getContext())},m.id))},d.id)):e.jsx(t.TableRow,{children:e.jsx(t.TableCell,{colSpan:o.length,className:"h-24 text-center",children:"No results."})})})]})})}function gn({card:s}){var O,E,z,w,M,R,F,H,S,v,A;const[a,n]=k.useState(!1),[r,o]=k.useState([]),{authToken:l}=t.useSemaphorContext(),i=t.getTokenParams(l==null?void 0:l.accessToken),d=t.useDashboardStore(D=>D.themeStyle),m={colors:((E=(O=d==null?void 0:d.chart)==null?void 0:O.dataset)==null?void 0:E.backgroundColor)||[]};(z=s.customCardPreferences)!=null&&z.inputData;const{getCard:p}=t.useCustomVisual(((w=s.customCardPreferences)==null?void 0:w.url)||""),u=((M=s.customCardPreferences)==null?void 0:M.visualType)||"single",x=t.useEditorStore(D=>D.frame),{setCustomCardPreferences:f}=t.useEditorActions(),{data:c}=t.useDashboardCardQuery(s),g=k.useCallback((D,y)=>{o(_=>({..._,[D]:y}))},[]);if(!((R=s.customCardPreferences)!=null&&R.componentName))return null;const h=p((F=s.customCardPreferences)==null?void 0:F.componentName);function j(D){n(D)}const b=Object.keys(((H=s.customCardPreferences)==null?void 0:H.dataInputCardIds)||{}).map(D=>{var G,$,B;const y=($=(G=s.customCardPreferences)==null?void 0:G.dataInputCardIds)==null?void 0:$[D].cardId,_=(B=x==null?void 0:x.cards)==null?void 0:B.find(I=>I.id===y);return _||null});return e.jsx("div",{className:"semaphor-custom mb-3 flex grow basis-0 flex-col space-y-2 overflow-y-auto",children:e.jsxs(k.Suspense,{fallback:e.jsx(e.Fragment,{}),children:[h&&u==="single"&&e.jsx(h,{params:i,theme:m,settings:(S=s.customCardPreferences)==null?void 0:S.settings,onDataChange:g,data:(c==null?void 0:c.records)||[]}),h&&u==="multiple"&&e.jsxs(e.Fragment,{children:[Object.keys(((v=s.customCardPreferences)==null?void 0:v.dataInputCardIds)||{}).map(D=>{var G,$,B;const y=($=(G=s.customCardPreferences)==null?void 0:G.dataInputCardIds)==null?void 0:$[D].cardId,_=(B=x==null?void 0:x.cards)==null?void 0:B.find(I=>I.id===y);if(_)return e.jsx(t.MultiInputEmptyRenderer,{onLoadingStatus:j,onDataChange:g,dataInputIndex:D,card:_},_.id+D)}),e.jsx("div",{className:"flex flex-col gap-2",children:e.jsx(h,{theme:m,onDataChange:g,settings:b.map(D=>{var y;return(y=D==null?void 0:D.customCardPreferences)==null?void 0:y.settings}),data:b.map(D=>D!=null&&D.id?r==null?void 0:r[D.id]:[])})})]})]},(A=s.customCardPreferences)==null?void 0:A.componentName)})}function zt({className:s,...a}){var j;const n=t.useEditorStore(b=>b.card),r=((j=n.customCardPreferences)==null?void 0:j.showCardHeader)??!0,o=t.useEditorStore(b=>b.frame),l=t.useDashboardStore(b=>b.dashboard.filters);t.useEditorStore(b=>b.actions.setRunSql);const{updateFilter:i}=t.useDashboardActions(),d=l==null?void 0:l.find(b=>b.id===o.filterId),{data:m,isLoading:p,isFetching:u}=t.useDashboardCardQuery(n),{setCard:x}=t.useEditorActions(),{data:f}=t.useTopoJson(n),c=k.useMemo(()=>!n.id||!(m!=null&&m.records)?null:t.createChartConfig({data:m==null?void 0:m.records,cardType:n.type,customCfg:n.customCfg,preferences:n.preferences,topoJson:f}),[n.id,m==null?void 0:m.records,n.type,n.customCfg,n.preferences,f]);function g(b){return e.jsx(gn,{card:b})}function h(){if(m!=null&&m.records&&(m==null?void 0:m.records.length)===0&&!p&&!u)return e.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-2",children:[e.jsx(t.TreePalm,{className:"size-8 text-muted-foreground"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"No records to display"})]});if(!n.id)return null;if(n.type==="custom")return g(n);if(!["table","custom"].includes(n.type)&&c)return e.jsx(e.Fragment,{children:p||u?e.jsx(e.Fragment,{}):e.jsx(t.ChartJsVisual,{cfg:c})});if(n.type==="table"&&(m!=null&&m.records)&&(m==null?void 0:m.records.length)>0)return e.jsxs(t.ScrollArea,{className:"relative mb-2 flex h-full min-h-0 w-full flex-1 grow basis-0",children:[e.jsx(t.TableVisual,{card:n,data:m==null?void 0:m.records}),e.jsx(t.ScrollBar,{orientation:"horizontal"})]})}return e.jsxs(t.Card,{role:"editor-visual-card",className:t.cn("relative flex h-full flex-col rounded-none",s),...a,children:[r&&e.jsxs(t.CardHeader,{className:"flex flex-row items-start justify-between py-4",children:[e.jsxs("div",{children:[e.jsx(t.Editable,{text:n.title,onSave:b=>x({...n,title:b}),children:e.jsx("div",{className:"flex items-center gap-5",children:e.jsx(t.CardTitle,{className:"text-base",children:n.title||"Edit title..."})})},n.title),e.jsx(t.Editable,{text:n.description||"",onSave:b=>x({...n,description:b}),children:e.jsx(t.CardDescription,{children:n.description||"Edit description..."})},n.description)]}),d&&e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(t.Editable,{className:"my-1",text:d.title||d.column,onSave:b=>i({...d,title:b}),children:e.jsx(t.Label,{children:d.title})}),e.jsx(t.FilterComponent,{filter:d})]})]}),e.jsx(t.CardContent,{className:"flex grow flex-col",children:h()})]})}const Ie=({language:s,value:a,onChange:n,readonly:r})=>e.jsx(t.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",readOnly:r},defaultLanguage:s,value:a,onChange:n}),jn=()=>e.jsxs(t.DialogHeader,{children:[e.jsx("div",{className:"flex items-center gap-2",children:e.jsx(t.DialogTitle,{children:"Customize Card"})}),e.jsxs(t.DialogDescription,{children:["See the configuration options and documentation",e.jsx("a",{target:"_blank",className:"ml-1 text-blue-500 underline",href:"https://www.chartjs.org/docs/latest/samples/bar/vertical.html",children:"here."})]})]}),bn=({customCode:s,cardCustomCfgString:a,mergedConfig:n,onConfigChange:r,onCodeChange:o})=>e.jsxs(t.Tabs,{defaultValue:"final-config",className:"flex w-1/2 flex-col",children:[e.jsxs(t.TabsList,{className:"justify-start rounded-sm rounded-b-none border border-b-0",children:[e.jsx(t.TabsTrigger,{value:"final-config",children:"Config"}),e.jsx(t.TabsTrigger,{value:"custom-config",children:"Changes"}),e.jsx(t.TabsTrigger,{value:"custom-code",children:"Custom Code"})]}),e.jsx(t.TabsContent,{value:"final-config",className:"mt-0 grow rounded-b border border-t-0",children:e.jsx(Ie,{language:"json",value:n,onChange:r})}),e.jsx(t.TabsContent,{value:"custom-config",className:"mt-0 grow rounded-b border border-t-0",children:e.jsx(Ie,{readonly:!0,language:"json",value:a,onChange:()=>{}})}),e.jsx(t.TabsContent,{value:"custom-code",className:"mt-0 grow rounded-b border border-t-0",children:e.jsx(Ie,{language:"javascript",value:s,onChange:o})})]}),yn=({error:s,hasCardCustomConfig:a,onReset:n,onApply:r,onClose:o})=>e.jsxs(t.DialogFooter,{className:"flex items-center",children:[e.jsx(t.Label,{className:"mr-2 text-red-500",children:s}),e.jsx(t.Button,{disabled:!a,onClick:n,variant:"outline",children:"Reset"}),e.jsx(t.Button,{onClick:r,variant:"outline",children:"Apply"}),e.jsx(t.Button,{onClick:o,variant:"outline",children:"Close"})]});function Sn(){const[s,a]=k.useState(!1),[n,r]=k.useState(""),[o,l]=k.useState(""),[i,d]=k.useState(""),[m,p]=k.useState(""),u=t.useEditorStore(w=>w.card),x=t.useEditorStore(w=>w.card.customCfg),f=x?JSON.stringify(x,null,2):"",{data:c}=t.useDashboardCardQuery(u),{data:g}=t.useTopoJson(u),{setCardCustomCfg:h,setCustomVisualCode:j}=t.useEditorActions(),b=w=>{var M,R;return JSON.stringify({...w,data:{...w.data,datasets:(R=(M=w.data)==null?void 0:M.datasets)==null?void 0:R.map(F=>({...F,data:[]}))}},null,2)},O=()=>{var M,R;if(!((M=c==null?void 0:c.records)!=null&&M.length))return;const w=t.createChartConfig({data:c.records,cardType:u.type,preferences:u.preferences,topoJson:g});if(w){r(b(w)),d(((R=u.preferences)==null?void 0:R.customVisualCode)||"");const F=t.merge(w,x);l(b(F))}},E=()=>{try{if(i&&j(i),o){const w=JSON.parse(o),M=t.getObjectDiff(JSON.parse(n),w);h(M),p("")}}catch{p("Invalid JSON configuration")}},z=Object.keys(x||{}).length===0;return e.jsxs(t.Dialog,{open:s,onOpenChange:a,children:[e.jsx(t.DialogTrigger,{asChild:!0,children:e.jsx(t.IconButton,{tooltip:"Customize Visual",onClick:O,className:z?"":"text-green-600 hover:text-green-700",children:e.jsx(t.Settings,{className:"h-4 w-4"})})}),e.jsxs(t.DialogContent,{className:"flex h-[600px] grow flex-col overflow-auto sm:min-w-[900px] lg:min-w-[1200px]",children:[e.jsx(jn,{}),e.jsxs("div",{className:"flex grow gap-2",children:[e.jsx(t.ErrorBoundary,{FallbackComponent:t.FallbackEditorCard,children:e.jsx(zt,{className:"w-1/2 rounded shadow-none"})}),e.jsx(bn,{customCode:i,cardCustomCfgString:f,mergedConfig:o,onConfigChange:w=>l(w??""),onCodeChange:w=>d(w??"")})]}),e.jsx(yn,{error:m,hasCardCustomConfig:!!x,onReset:()=>{l(n),h(null)},onApply:E,onClose:()=>a(!1)})]})]})}function Ft(s){return ue({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 Cn(s){return ue({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 Rt(s){return ue({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 _t(s){return ue({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 Vt(s){return ue({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 qt(s){const[a,n]=k.useState(null);return a}function Bt(){const{authToken:s}=t.useSemaphorContext(),{data:a,isLoading:n,isFetching:r,isError:o}=t.useQuery({queryKey:["plugins",s==null?void 0:s.accessToken],queryFn:()=>t.getPlugins(s==null?void 0:s.accessToken)});return{data:a,isLoading:n,isFetching:r,isError:o}}function vn({onChartTypeChange:s}){const[a,n]=k.useState([]),{data:r}=Bt();return k.useEffect(()=>{(async()=>{var l;if(r){const d=(await Promise.all((l=r==null?void 0:r.plugins)==null?void 0:l.map(async m=>(await t.loadManifest(m.value)).visuals.map(x=>({name:x.name,icon:x.icon,url:m.value}))))).flat();n(d)}})()},[r]),a.length===0?null:e.jsxs(e.Fragment,{children:[e.jsx(t.Separator,{className:"my-2"}),e.jsx("div",{className:"grid grid-cols-4 place-items-center",children:a.map((o,l)=>e.jsx(Nn,{text:o.name,onClick:()=>s("custom",o),icon:o.icon},o.url+o.name+l))})]})}const Nn=({text:s,icon:a,onClick:n})=>{const r=qt(),o=s.charAt(0).toUpperCase();return e.jsx(t.IconButton,{onClick:n,tooltip:s,children:r?e.jsx(r,{className:"h-4 w-4"}):o})};function wn(){var x,f;const[s,a]=k.useState(!1),n=t.useEditorStore(c=>c.card),r=n.type,o=t.useDashboardStore(c=>c.isVisualEditing),{setCardType:l,setCardPreferences:i,setChartOrientation:d}=t.useEditorStore(c=>c.actions),{setCardCustomCfg:m,setCustomCardPreferences:p}=t.useEditorActions();function u(c,g){m(null),i({}),l(c),g&&p({type:"component",visualType:"single",url:g.url,componentName:g.name,icon:g.icon}),a(!1)}return e.jsxs(t.Popover,{open:s,onOpenChange:a,children:[e.jsx(t.PopoverTrigger,{asChild:!0,children:e.jsx(t.Button,{size:"sm",variant:o?"ghost":"outline",children:e.jsx(kn,{className:"size-4",chartType:r,customIcon:(x=n.customCardPreferences)==null?void 0:x.icon,componentName:(f=n.customCardPreferences)==null?void 0:f.componentName})})}),e.jsxs(t.PopoverContentCustom,{onOpenAutoFocus:c=>c.preventDefault(),className:"w-50",children:[e.jsxs("div",{className:"grid grid-cols-4 place-items-center",children:[e.jsx(t.IconButton,{tooltip:"Bar Chart",onClick:()=>u("bar"),className:"h-10 p-4",children:e.jsx(Be,{className:"size-5"})}),e.jsx(t.IconButton,{tooltip:"Line Chart",onClick:()=>u("line"),className:"h-10 p-4",children:e.jsx(Pe,{className:"size-5"})}),e.jsx(t.IconButton,{tooltip:"Stacked Bar Chart",onClick:()=>u("stackedBar"),className:"h-10 p-4",children:e.jsx(at,{className:"size-5"})}),e.jsx(t.IconButton,{tooltip:"Stacked Line Chart",onClick:()=>u("stackedLine"),className:"h-10 p-4",children:e.jsx(_t,{className:"size-5",strokeWidth:0})}),e.jsx(t.IconButton,{tooltip:"Scatter Chart",onClick:()=>u("scatter"),className:"h-10 p-4",children:e.jsx(it,{className:"size-5"})}),e.jsx(t.IconButton,{tooltip:"Bubble Chart",onClick:()=>u("bubble"),className:"h-10 p-4",children:e.jsx(Rt,{className:"size-5"})}),e.jsx(t.IconButton,{tooltip:"Pie Chart",onClick:()=>u("pie"),className:"h-10 p-4",children:e.jsx(ot,{className:"size-5"})}),e.jsx(t.IconButton,{tooltip:"Doughnut Chart",onClick:()=>u("doughnut"),className:"h-10 p-4",children:e.jsx(ct,{className:"size-5"})}),e.jsx(t.IconButton,{tooltip:"Radar Chart",onClick:()=>u("radar"),className:"h-10 p-4",children:e.jsx(pt,{className:"size-5"})}),e.jsx(t.IconButton,{tooltip:"Polar Area Chart",onClick:()=>u("polarArea"),className:"h-10 p-4",children:e.jsx(Ft,{className:"size-6"})}),e.jsx(t.IconButton,{tooltip:"Pyramid Chart",onClick:()=>u("pyramid"),className:"h-10 p-4",children:e.jsx(jt,{className:"size-5"})}),e.jsx(t.IconButton,{tooltip:"Range Chart",onClick:()=>u("range"),className:"h-10 p-4",children:e.jsx(rt,{className:"size-5"})}),e.jsx(t.IconButton,{tooltip:"Table",onClick:()=>u("table"),className:"h-10 p-4",children:e.jsx(He,{className:"size-5"})}),e.jsx(t.IconButton,{tooltip:"KPI",onClick:()=>u("kpi"),className:"h-10 p-4",children:e.jsx(Vt,{className:"size-6"})}),e.jsx(t.IconButton,{tooltip:"Text",onClick:()=>u("text"),className:"h-10 p-4",children:e.jsx(rs,{className:"size-5"})}),e.jsx(t.IconButton,{tooltip:"Map",onClick:()=>u("map"),className:"h-10 p-4",children:e.jsx(ht,{className:"size-5"})}),e.jsx(t.IconButton,{tooltip:"Custom",onClick:()=>u("custom"),className:"h-10 p-4",children:e.jsx(ft,{className:"size-5"})})]}),e.jsx(vn,{onChartTypeChange:u})]})]})}function kn({chartType:s,className:a,customIcon:n,componentName:r}){const o=qt();switch(s){case"bar":return e.jsx(Be,{className:a});case"line":return e.jsx(Pe,{className:a});case"pie":return e.jsx(ot,{className:a});case"radar":return e.jsx(pt,{className:a});case"scatter":return e.jsx(it,{className:a});case"bubble":return e.jsx(Rt,{className:a});case"doughnut":return e.jsx(ct,{className:a});case"stackedBar":return e.jsx(at,{className:a});case"stackedLine":return e.jsx(_t,{className:a});case"polarArea":return e.jsx(Ft,{className:a});case"pyramid":return e.jsx(jt,{className:a});case"range":return e.jsx(rt,{className:a});case"kpi":return e.jsx(Vt,{className:a});case"text":return e.jsx(bt,{className:a});case"map":return e.jsx(ht,{className:a});case"custom":return n&&o?e.jsx(o,{className:a}):r?r==null?void 0:r.charAt(0).toUpperCase():e.jsx(ft,{className:a});default:return e.jsx(He,{className:a})}}const pe="focus-visible:ring-0 focus-visible:ring-ring focus-visible:ring-offset-0";function st(s,a){var r,o,l;const n=t.getNumberAxis(s,a);return((l=(o=(r=s==null?void 0:s.chartOptions)==null?void 0:r.scales)==null?void 0:o[n])==null?void 0:l.type)||"linear"}function In(){var _,G,$,B,I,C;const[s,a]=k.useState(!1),n=t.useEditorStore(N=>{var T;return(T=N.card)==null?void 0:T.preferences}),r=t.getNumberAxis(n,{}),[o,l]=k.useState(st(n)),[i,d]=k.useState((($=(G=(_=n==null?void 0:n.chartOptions)==null?void 0:_.scales)==null?void 0:G[r])==null?void 0:$.min)||""),[m,p]=k.useState(((C=(I=(B=n==null?void 0:n.chartOptions)==null?void 0:B.scales)==null?void 0:I[r])==null?void 0:C.max)||""),[u,x]=k.useState(i||m?"custom":"auto"),[f,c]=k.useState(""),[g,h]=k.useState(0),[j,b]=k.useState(""),[O,E]=k.useState(""),[z,w]=k.useState(""),M=t.useEditorStore(N=>N.actions.setCardPreferences),{updateCardInFrame:R}=t.useEditorActions(),F=t.useEditorStore(N=>N.card),H=t.useEditorStore(N=>{var T;return(T=N.card)==null?void 0:T.type}),S=["pie","doughnut","polarArea"].includes(H);k.useEffect(()=>{var N,T,L,U,P,K,W,Z,ee,V,Q,Y,ne,ie;l(st(n)),d(((L=(T=(N=n==null?void 0:n.chartOptions)==null?void 0:N.scales)==null?void 0:T[r])==null?void 0:L.min)===0?0:""),p(((K=(P=(U=n==null?void 0:n.chartOptions)==null?void 0:U.scales)==null?void 0:P[r])==null?void 0:K.max)||""),c(((V=(ee=(Z=(W=n==null?void 0:n.chartOptions)==null?void 0:W.scales)==null?void 0:Z[r])==null?void 0:ee.ticks)==null?void 0:V.stepSize)||""),h(((Q=n==null?void 0:n.numberAxisFormat)==null?void 0:Q.decimalPlaces)||0),b(((Y=n==null?void 0:n.numberAxisFormat)==null?void 0:Y.suffix)||""),E(((ne=n==null?void 0:n.numberAxisFormat)==null?void 0:ne.currency)||""),w(((ie=n==null?void 0:n.numberAxisFormat)==null?void 0:ie.locale)||"")},[s,n,r]);function v(N,T){return T===""||/^[0-9\b]+$/.test(T)?Number(T):Number(N)}function A(){const N=[...new Set(t.LOCALE_CURRENCY_PAIRS.map(T=>T.currency))];return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"grid grid-cols-6 items-center gap-2",children:[e.jsx(t.Label,{className:"col-span-2 hover:cursor-pointer hover:underline",htmlFor:"currency",children:e.jsx("a",{target:"_blank",href:"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat",children:"Currency"})}),e.jsxs(t.Select,{value:O||"none",onValueChange:T=>E(T==="none"?"":T),children:[e.jsx(t.SelectTrigger,{className:"col-span-2 h-8 w-full focus:ring-1 focus:ring-offset-0",children:e.jsx(t.SelectValue,{})}),e.jsx(t.SelectContent,{children:e.jsxs(t.SelectGroup,{children:[e.jsx(t.SelectLabel,{children:"Currency"}),e.jsx(t.SelectItem,{value:"none",children:"None"}),N.map(T=>e.jsx(t.SelectItem,{value:T,children:T},T))]})})]}),e.jsxs(t.Select,{value:z,onValueChange:T=>w(T),children:[e.jsx(t.SelectTrigger,{className:"col-span-2 h-8 w-full focus:ring-1 focus:ring-offset-0",children:e.jsx(t.SelectValue,{})}),e.jsx(t.SelectContent,{children:e.jsxs(t.SelectGroup,{children:[e.jsx(t.SelectLabel,{children:"Locale"}),t.LOCALE_CURRENCY_PAIRS.map(T=>e.jsx(t.SelectItem,{value:T.locale,children:T.locale},T.locale))]})})]})]}),e.jsxs("div",{className:"grid grid-cols-9 items-center gap-2",children:[e.jsx(t.Label,{className:"col-span-3",htmlFor:"format",children:"Decimals"}),e.jsx(t.Input,{value:g,onChange:T=>h(Number(T.target.value)),id:"format",className:`col-span-6 h-8 w-full tracking-wide ${pe}`})]})]})}function D(){return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"grid grid-cols-3 items-center gap-2",children:[e.jsx(t.Label,{htmlFor:"range",children:"Range"}),e.jsx(t.Input,{id:"min",value:i,onChange:N=>d(T=>v(T,N.target.value)),className:`col-span-1 h-8 w-full ${pe}`}),e.jsx(t.Input,{value:m,onChange:N=>p(T=>v(T,N.target.value)),id:"max",className:`col-span-1 h-8 w-full ${pe}`})]}),e.jsxs("div",{className:"grid grid-cols-3 items-center gap-2",children:[e.jsx(t.Label,{htmlFor:"step-size",children:"Step Size"}),e.jsx(t.Input,{value:f,onChange:N=>c(T=>v(T,N.target.value)),id:"step-size",className:`col-span-1 h-8 w-full ${pe}`})]})]})}function y(){var U;let N={};u==="custom"&&(N={min:i,max:m,ticks:{stepSize:f}});const T={...n||{},chartOptions:{...n==null?void 0:n.chartOptions,scales:{...(U=n==null?void 0:n.chartOptions)==null?void 0:U.scales,[r]:{type:o,...o==="linear"?N:{}}}},numberAxisFormat:{decimalPlaces:g,suffix:j,currency:O,locale:z}};console.log(T),M(T);const L={...F,preferences:T};R(L)}return e.jsxs(t.Popover,{onOpenChange:N=>a(N),children:[e.jsx(t.PopoverTrigger,{asChild:!0,children:e.jsx(t.IconButton,{tooltip:"Scale Options",children:e.jsx(zs,{className:"size-4 rotate-45"})})}),e.jsx(t.PopoverContentCustom,{align:"center",className:"max-w-65",children:e.jsxs("div",{className:"grid gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("h4",{className:"font-medium leading-none",children:"Scale Options"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Set the scale for the number axis"})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsxs("div",{className:"grid grid-cols-3 items-center gap-2",children:[e.jsx(t.Label,{htmlFor:"scale",children:"Type"}),e.jsxs(t.Select,{disabled:S,value:o,onValueChange:N=>l(N),children:[e.jsx(t.SelectTrigger,{className:"col-span-2 h-8 w-full focus:ring-1 focus:ring-offset-0",children:e.jsx(t.SelectValue,{})}),e.jsx(t.SelectContent,{id:"type",children:e.jsxs(t.SelectGroup,{children:[e.jsx(t.SelectLabel,{children:"Option"}),e.jsx(t.SelectItem,{value:"linear",children:"Linear"}),e.jsx(t.SelectItem,{value:"logarithmic",children:"Logarithmic"})]})})]})]}),o=="linear"&&e.jsxs("div",{className:"grid grid-cols-3 items-center gap-2 py-1",children:[e.jsx(t.Label,{htmlFor:"scale-option",children:"Setup"}),e.jsxs(t.RadioGroup,{disabled:S,id:"scale-option",value:u,onValueChange:N=>x(N),className:"col-span-2 flex gap-3",defaultValue:"x",children:[e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(t.RadioGroupItem,{value:"auto",id:"r1"}),e.jsx("label",{className:"text-sm",htmlFor:"r1",children:"Auto"})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(t.RadioGroupItem,{value:"custom",id:"r2"}),e.jsx("label",{className:"text-sm",htmlFor:"r2",children:"Custom"})]})]})]}),u==="custom"&&o=="linear"&&D(),A(),e.jsx(t.SelectSeparator,{}),e.jsx("div",{className:"grid grid-cols-3",children:e.jsx(t.Button,{onClick:y,variant:"secondary",className:"col-span-1 col-start-3 h-8 w-full",children:"Apply"})})]})]})})]})}function Dn(){const s=t.useEditorStore(d=>{var m,p,u,x;return(x=(u=(p=(m=d.card.preferences)==null?void 0:m.chartOptions)==null?void 0:p.plugins)==null?void 0:u.legend)==null?void 0:x.position}),a=t.useEditorStore(d=>{var m,p,u,x;return(x=(u=(p=(m=d.card.preferences)==null?void 0:m.chartOptions)==null?void 0:p.plugins)==null?void 0:u.legend)==null?void 0:x.align}),n=t.useEditorStore(d=>{var m,p,u,x;return(x=(u=(p=(m=d.card.preferences)==null?void 0:m.chartOptions)==null?void 0:p.plugins)==null?void 0:u.legend)==null?void 0:x.display}),{setLegendOptions:r}=t.useEditorActions(),o=d=>{r({display:d,position:s,align:a})},l=d=>{r({display:n,position:d,align:a})},i=d=>{r({display:n,position:s,align:d})};return e.jsxs(t.Popover,{children:[e.jsx(t.PopoverTrigger,{asChild:!0,children:e.jsx(t.IconButton,{tooltip:"Legend Settings",children:e.jsx(vs,{className:"size-4"})})}),e.jsx(t.PopoverContentCustom,{className:"w-72",children:e.jsxs("div",{className:"grid gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("h4",{className:"font-medium leading-none",children:"Legend Options"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Set the legend options for the chart."})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsxs("div",{className:"grid grid-cols-3 items-center gap-4",children:[e.jsx(t.Label,{htmlFor:"displayLegend",children:"Display"}),e.jsx("div",{className:"col-span-2 flex h-8 items-center",children:e.jsx(t.SmallSwitch,{checked:n,onCheckedChange:o,defaultChecked:!0,id:"displayLegend"})})]}),e.jsxs("div",{className:"grid grid-cols-3 items-center gap-4",children:[e.jsx(t.Label,{htmlFor:"position",children:"Position"}),e.jsxs("div",{className:"col-span-2 flex h-8 items-center",children:[e.jsx(t.IconButton,{tooltip:"Top",onClick:()=>l("top"),children:e.jsx(t.ArrowUp,{className:"size-4"})}),e.jsx(t.IconButton,{tooltip:"Left",onClick:()=>l("left"),children:e.jsx(es,{className:"size-4"})}),e.jsx(t.IconButton,{tooltip:"Bottom",onClick:()=>l("bottom"),children:e.jsx(Xt,{className:"size-4"})}),e.jsx(t.IconButton,{tooltip:"Right",onClick:()=>l("right"),children:e.jsx(ts,{className:"size-4"})})]})]}),e.jsxs("div",{className:"grid grid-cols-3 items-center gap-4",children:[e.jsx(t.Label,{htmlFor:"align",children:"Align"}),e.jsxs("div",{className:"col-span-2 flex h-8 items-center",children:[e.jsx(t.IconButton,{tooltip:"Start",onClick:()=>i("start"),children:e.jsx(Kt,{className:"size-4"})}),e.jsx(t.IconButton,{tooltip:"Center",onClick:()=>i("center"),children:e.jsx(Jt,{className:"size-4"})}),e.jsx(t.IconButton,{tooltip:"End",onClick:()=>i("end"),children:e.jsx(Wt,{className:"size-4"})})]})]})]})]})})]})}function En(){var l;const s=t.useEditorStore(i=>i.card.preferences),{setCardPreferences:a,setChartOrientation:n}=t.useEditorStore(i=>i.actions);function r(i){n(i)}const o=((l=s==null?void 0:s.chartOptions)==null?void 0:l.indexAxis)||"x";return e.jsx(t.IconButton,{onClick:()=>r(o==="y"?"x":"y"),tooltip:"Chart Orientation",children:o==="y"?e.jsx(As,{className:"size-4"}):e.jsx(Ts,{className:"size-4"})})}function Tn(){const s=t.useEditorStore(i=>i.card),a=t.useEditorStore(i=>i.isShowingVisual),n=t.useEditorStore(i=>{var d,m;return(m=(d=i.card)==null?void 0:d.preferences)==null?void 0:m.chartOptions}),r=t.getChartGridStyle(n),{setChartGrid:o}=t.useEditorActions();function l(){const i=["xy","none","x","y"],m=(i.indexOf(r)+1)%i.length;o(i[m])}return a?e.jsxs("div",{"data-info":"visual-settings",className:"flex items-center",children:[["line","bar","range","stackedBar","stackedLine","horizontalBar"].includes(s.type)&&e.jsx(En,{}),!["kpi","text","custom","table"].includes(s.type)&&e.jsxs(e.Fragment,{children:[e.jsx(In,{}),e.jsx(Dn,{})]}),!["pie","doughnut","radar","polarArea","table","custom","kpi","text","map"].includes(s.type)&&e.jsxs(t.IconButton,{tooltip:"Grid Style",onClick:l,children:[(r==="xy"||!r)&&e.jsx(ys,{className:"size-4"}),r==="x"&&e.jsx(us,{className:"size-4"}),r==="y"&&e.jsx(Os,{className:"size-4"}),r==="none"&&e.jsx(_s,{className:"size-4"})]})]}):null}function xe(){var B;const s=t.useEditorStore(I=>I.frame),a=t.useEditorStore(I=>I.card),n=t.useEditorStore(I=>I.isDevMode),r=t.useEditorStore(I=>I.isShowingVisual),o=t.useDashboardStore(I=>I.isVisualEditing),l=t.useEditorStore(I=>I.isSqlRunning),i=t.useEditorStore(I=>I.pythonStdOut),d=t.useEditorStore(I=>{var C;return(C=I.card.preferences)==null?void 0:C.chartOptions}),m=t.useEditorStore(I=>I.actions.setRunSql);t.getChartGridStyle(d);const{setFrame:p,setCard:u,updateCardInFrame:x,setActiveTabCardId:f,runAssistant:c,setChartGrid:g}=t.useEditorActions(),{data:h,isLoading:j,isFetching:b,error:O}=t.useDashboardCardQuery(a);if(!a)return e.jsx(e.Fragment,{children:"No Active Card"});function E(){const I={connectionId:a.connectionId,lastSelectedDatabase:a.lastSelectedDatabase,lastSelectedSchema:a.lastSelectedSchema,lastSelectedTable:a.lastSelectedTable,lastSelectedDatamodelId:a.lastSelectedDatamodelId,id:t.v4(),title:"Title",description:"Description",preferences:{onClickFilter:[{columnIndex:0,expression:""}]},type:"bar",sql:"",data:[]};z(I)}function z(I){const C={...s,cards:[...s.cards,I],activeCardId:I.id};p(C),u(I),f(I.id)}function w(){const I={...a,id:t.v4(),title:`${a.title} Copy`,tabTitle:`${a.tabTitle||a.title} Copy`};z(I)}function M(I){const C=s.cards.filter(L=>L.id!==I),N=C[0],T={...s,cards:C,activeCardId:N.id};p(T),f(N.id),u(N)}function R(I){n||F(I),f(I)}function F(I){const C={...s,cards:s.cards.map(T=>T.id===a.id?a:T),activeCardId:I};p(C);const N=C.cards.find(T=>T.id===I);N.sql&&m(!0),u(N)}const H=(I,C)=>{console.log("handleDragStart",C),I.dataTransfer.setData("tabIndex",C.toString())},S=I=>{I.preventDefault()},v=(I,C)=>{const N=I.dataTransfer.getData("tabIndex");if(N===C.toString())return;const T=Array.from(s.cards),[L]=T.splice(parseInt(N),1);T.splice(C,0,L),p({...s,cards:T})};function A(I,C){return I.cards.length===1&&(C.displayTab===!0||C.displayTab===void 0)||I.activeCardId!==C.id&&(C.displayTab===!0||C.displayTab===void 0)?null:e.jsx("div",{onClick:()=>{const N=C.displayTab===void 0?!1:!C.displayTab;u({...C,displayTab:N}),x({...C,displayTab:N})},children:C.displayTab===!0||C.displayTab===void 0?e.jsx(t.Eye,{className:"mr-2 size-3.5 text-muted-foreground hover:text-foreground"}):e.jsx(fs,{className:"mr-2 size-3.5 text-muted-foreground hover:text-foreground"})})}function D(){return e.jsxs(t.Tabs,{onValueChange:R,value:s.activeCardId,className:"flex grow flex-col",children:[s.cards.map(I=>e.jsx(t.TabsContent,{className:"mt-0 grow",value:I.id,children:y()},I.id)),e.jsx(t.TabsList,{className:"group mx-6 justify-between overflow-x-auto",children:e.jsxs("div",{className:"flex items-center",children:[s.cards.map((I,C)=>e.jsx(t.Editable,{text:I.tabTitle||I.title,onSave:N=>{u({...a,tabTitle:N}),x({...a,tabTitle:N})},children:e.jsxs(t.TabsTrigger,{draggable:!0,onDragStart:N=>H(N,C),onDragOver:S,onDrop:N=>v(N,C),className:"",value:I.id,children:[A(s,I),I.tabTitle||I.title,s.activeCardId===I.id&&s.cards.length>1&&e.jsx(t.X,{className:"ml-2 size-3.5 text-muted-foreground hover:text-foreground",onClick:()=>M(I.id)})]})},I.id)),e.jsx(t.Button,{className:"ml-1 h-8 px-2 hover:bg-muted-foreground/50",variant:"outline",onClick:E,children:e.jsx(t.Plus,{className:"h-4 w-4"})}),e.jsx(t.Button,{className:"invisible ml-1 h-8 px-2 hover:bg-muted-foreground/50 group-hover:visible",variant:"outline",onClick:w,children:e.jsx(hs,{className:"h-4 w-4"})})]})})]})}function y(){return a.type==="kpi"?e.jsx("div",{className:"flex h-full items-center justify-center",children:e.jsx("div",{className:"w-1/2 rounded-md border",children:e.jsx(t.KPICard,{card:a,data:h==null?void 0:h.records})})}):a.type==="text"?e.jsx("div",{className:"flex h-full items-center justify-center",children:e.jsx("div",{className:"w-1/2 rounded-md border",children:e.jsx(t.ScrollArea,{className:"mx-3 my-6 h-[300px] overflow-y-auto break-words px-3",children:e.jsx(t.TextCard,{isLoading:l,card:a,data:h==null?void 0:h.records})})})}):e.jsx(t.ErrorBoundary,{FallbackComponent:t.FallbackEditorCard,children:e.jsx(zt,{className:"grow border-none shadow-none"})})}function _(){const I=JSON.stringify(h==null?void 0:h.records,null,2),C=new Blob([I],{type:"application/json"}),N=URL.createObjectURL(C),T=document.createElement("a");T.href=N,T.download=`${a.title}.json`,T.click()}function G(){const C=[Object.keys(h==null?void 0:h.records.reduce((U,P)=>({...U,...P}),{})).join(","),...((h==null?void 0:h.records)||[]).map(U=>Object.values(U).join(","))].join(`
|
|
352
|
-
`),N=new Blob([C],{type:"text/csv"}),T=URL.createObjectURL(N),L=document.createElement("a");L.href=T,L.download=`${a.title}.csv`,L.click()}function $(){const I=`Can you get the documentation for ${a.type} chart?`;c(I)}return e.jsxs("div",{className:"relative isolate flex h-full flex-col py-3",children:[(j||b)&&e.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.jsx(re,{className:"h-8 w-8 animate-spin text-muted-foreground"})}),e.jsxs("div",{className:"z-10 mb-0 flex min-h-10 items-center justify-end gap-2 px-6",children:[r&&e.jsxs("div",{className:"flex grow items-center",children:[e.jsx(wn,{}),o&&e.jsx(t.IconButton,{tooltip:"Visual Docs",onClick:$,children:e.jsx(as,{className:"size-4"})}),!["table","custom"].includes(a.type)&&o&&e.jsx(Sn,{})]}),!r&&e.jsxs("div",{className:"flex grow items-center gap-1",children:[e.jsx(t.Button,{className:"h-7 w-fit px-1 font-mono text-xs text-muted-foreground/70",variant:"ghost",size:"icon",onClick:G,children:e.jsx(Cn,{className:"size-4"})}),e.jsx(t.Button,{className:"h-7 w-fit px-1 font-mono text-xs text-muted-foreground/70",variant:"ghost",size:"icon",onClick:_,children:e.jsx(gs,{strokeWidth:1.5,className:"size-4"})}),e.jsx(t.CopyButton,{text:JSON.stringify(h==null?void 0:h.records,null,2),className:"h-7 w-fit px-1 font-mono text-xs text-muted-foreground/70"})]}),e.jsx(Tn,{}),e.jsx(Mn,{})]}),r?D():e.jsxs(t.ResizablePanelGroup,{className:"px-6",direction:"horizontal",children:[i&&e.jsxs(e.Fragment,{children:[e.jsx(t.ResizablePanel,{id:"1",order:1,defaultSize:30,minSize:10,className:"relative flex h-full min-h-0 w-full flex-1 basis-0",children:i&&e.jsx(An,{})}),e.jsx(t.ResizableHandle,{})]}),e.jsxs(t.ResizablePanel,{id:"2",order:2,minSize:10,className:"relative flex h-full min-h-0 w-full flex-1 basis-0",children:[(h==null?void 0:h.records)&&(h==null?void 0:h.records.length)>0&&e.jsx(fn,{data:(h==null?void 0:h.records)||[]}),(O||(h==null?void 0:h.error))&&e.jsx("span",{className:"font-mono text-xs",children:(O==null?void 0:O.message)||((B=h==null?void 0:h.error)==null?void 0:B.message)})]})]})]})}function An(){const s=t.useEditorStore(n=>n.pythonStdOut);if(!s)return null;const a=s.replace(/\n/g,"<br>");return e.jsxs("div",{className:"relative flex w-full flex-col border-r",children:[e.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.jsxs(t.ScrollArea,{className:"overflow-y-auto px-2 pt-1 font-mono text-xs text-foreground/90",children:[e.jsx("div",{dangerouslySetInnerHTML:{__html:a}}),e.jsx(t.ScrollBar,{orientation:"horizontal"})]})]})}function Mn(){const s=t.useEditorStore(n=>n.isShowingVisual),a=t.useEditorStore(n=>n.actions.setIsShowingVisual);return e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(t.Label,{htmlFor:"visualize",children:"Chart"}),e.jsx(t.SmallSwitch,{checked:s,onCheckedChange:()=>a(!s),id:"visualize",className:"data-[state=checked]:bg-foreground/50"})]})}function Ln(){var h,j;const s=t.useEditorStore(b=>b.card.customCardPreferences),{data:a}=Bt(),n=(a==null?void 0:a.plugins)||[],r=t.useEditorStore(b=>b.card),o=t.useEditorStore(b=>b.frame),l=(s==null?void 0:s.visualType)||"single",{setCustomCardPreferences:i}=t.useEditorActions(),{components:d,manifest:m}=t.useCustomVisual((s==null?void 0:s.url)||""),p=(h=m==null?void 0:m.visuals)==null?void 0:h.find(b=>b.name===(s==null?void 0:s.componentName));function u(b,O){if(!s)return;const z={...(s==null?void 0:s.dataInputCardIds)||{},[b]:{cardId:O,hookRef:null}};i({...s,dataInputCardIds:z})}function x(b){var E,z;const O=(E=o==null?void 0:o.cards)==null?void 0:E.filter(w=>{var M;return((M=w==null?void 0:w.customCardPreferences)==null?void 0:M.visualType)!=="multiple"}).map(w=>({value:w.id,label:w.tabTitle||w.title}));return e.jsx("div",{className:"space-y-2",children:(z=b==null?void 0:b.dataInputs)==null?void 0:z.map((w,M)=>{var R,F;return e.jsxs("div",{className:"grid grid-cols-10 gap-2",children:[e.jsx("div",{className:"col-span-4 flex items-center",children:w}),e.jsx(X,{className:"col-span-6 h-8 w-full justify-between",label:"",options:O||[],value:((F=(R=s==null?void 0:s.dataInputCardIds)==null?void 0:R[M])==null?void 0:F.cardId)||"",onValueChange:H=>u(M,H)})]},M+Math.random())})})}function f(b,O,E=[],z=""){var w,M;return s?b==="input"?e.jsx(t.Input,{className:`h-8 w-full ${t.removeRing}`,value:((w=s==null?void 0:s.settings)==null?void 0:w[O])||z,onChange:R=>{i({...s,settings:{...s==null?void 0:s.settings,[O]:R.target.value}})}},O):b==="select"?e.jsx(X,{className:"h-8 w-full",label:"",options:E,value:((M=s==null?void 0:s.settings)==null?void 0:M[O])||z,onValueChange:R=>{i({...s,settings:{...s==null?void 0:s.settings,[O]:R}})}}):null:null}function c(b){const O=Object.entries((b==null?void 0:b.settings)||{});return e.jsx("div",{className:"space-y-3",children:O.map(([E,z])=>e.jsxs("div",{className:"space-y-1",children:[e.jsx(t.Label,{children:z.title}),f(z.ui,E,z.options,z.defaultValue)]},E))})}function g(b){s&&i({...s,visualType:b,componentName:""})}return e.jsxs(t.Accordion,{type:"multiple",defaultValue:["component-settings"],className:"px-6 py-2",children:[e.jsxs(t.AccordionItem,{value:"plugin-settings",children:[e.jsx(t.AccordionTrigger,{children:"Plugin"}),e.jsx(t.AccordionContent,{children:e.jsxs("div",{className:"space-y-4 text-sm",children:[e.jsx("div",{className:"space-y-2",children:e.jsxs("div",{className:"space-y-4",children:[e.jsx(X,{icon:e.jsx(ns,{className:"h-3.5 w-3.5"}),className:"h-9 w-full",label:"Select Plugin",options:n,value:(s==null?void 0:s.url)||"",onValueChange:b=>i({...s||{url:"",componentName:""},url:b})}),((s==null?void 0:s.type)==="component"||(s==null?void 0:s.type)===void 0)&&e.jsx(t.Tabs,{value:l,onValueChange:g,children:e.jsxs(t.TabsList,{className:"h-9 w-full",children:[e.jsx(t.TabsTrigger,{className:"h-7 w-full",value:"single",children:"Single Visual"}),e.jsx(t.TabsTrigger,{className:"h-7 w-full",value:"multiple",children:"Multi-Visual"})]})})]})}),((s==null?void 0:s.type)==="component"||(s==null?void 0:s.type)===void 0)&&s&&e.jsx(e.Fragment,{children:d&&e.jsx(X,{icon:e.jsx(ms,{className:"h-3.5 w-3.5"}),className:"h-9 w-full",label:"Select Component",options:(d==null?void 0:d.filter(b=>b.type===l).map(b=>({value:b.name,label:b.name})))||[],value:s.componentName,onValueChange:b=>{console.log("changing value",b),i({...s,componentName:b})}})})]})})]}),((j=r==null?void 0:r.customCardPreferences)==null?void 0:j.componentName)&&e.jsxs(t.AccordionItem,{className:"border-none",value:"component-settings",children:[e.jsx(t.AccordionTrigger,{children:"Settings"}),e.jsxs(t.AccordionContent,{children:[p&&p.dataInputs&&e.jsxs("div",{className:"space-y-3",children:[e.jsx(t.Label,{children:"Input Mapping"}),e.jsx("div",{className:"px-2",children:x(p)})]}),p&&p.settings&&e.jsx("div",{className:"space-y-3",children:e.jsx("div",{className:"px-2",children:c(p)})})]})]})]})}function oe(){const[s,a]=k.useState([]),n=t.useEditorStore(p=>p.card.preferences),{setFilterOnClickColumnIndex:r,setCardPreferences:o}=t.useEditorStore(p=>p.actions),l=t.useEditorStore(p=>p.queryResultColumns);t.useEditorStore(p=>{var u;return(u=p.card.preferences)==null?void 0:u.filterOnClickColumnIndex}),k.useEffect(()=>{l&&a(new Array(l.length).fill(!1))},[l]);function i(p,u){var x,f;u?n!=null&&n.onClickFilter&&((x=n==null?void 0:n.onClickFilter)==null?void 0:x.length)>0?o({...n,onClickFilter:[...n.onClickFilter,{columnIndex:p,expression:""}]}):o({...n,onClickFilter:[{columnIndex:p,expression:""}]}):(o({...n,onClickFilter:(f=n==null?void 0:n.onClickFilter)==null?void 0:f.filter(c=>c.columnIndex!==p)}),a(c=>{const g=[...c];return g[p]=!1,g}))}function d(p,u){var f;const x=(f=n==null?void 0:n.onClickFilter)==null?void 0:f.map(c=>c.columnIndex===p?{...c,expression:u.target.value}:c);o({...n,onClickFilter:x})}function m(p){var u,x,f,c;if(s!=null&&s[p]||(x=(u=n==null?void 0:n.onClickFilter)==null?void 0:u.find(g=>g.columnIndex===p))!=null&&x.expression)return e.jsx(t.Input,{value:(c=(f=n==null?void 0:n.onClickFilter)==null?void 0:f.find(g=>g.columnIndex===p))==null?void 0:c.expression,onChange:g=>d(p,g),type:"text",className:"h-9 w-full font-mono text-xs focus-visible:ring-0 focus-visible:ring-ring focus-visible:ring-offset-0",placeholder:"Expression"})}return e.jsxs("div",{className:"space-y-2",children:[e.jsx(t.Label,{children:"On Click"}),l==null?void 0:l.map((p,u)=>{var x,f;return e.jsx("div",{className:"xbg-red-100 group flex items-center justify-between space-y-2",children:e.jsxs("div",{className:"grow",children:[e.jsxs("div",{className:"flex items-center space-x-2 py-2",children:[e.jsx(t.Checkbox,{checked:!!((x=n==null?void 0:n.onClickFilter)!=null&&x.find(c=>c.columnIndex===u)),onCheckedChange:c=>i(u,c)}),e.jsx("label",{className:"text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70",children:p}),e.jsx("div",{className:"flex items-center gap-2",children:((f=n==null?void 0:n.onClickFilter)==null?void 0:f.find(c=>c.columnIndex===u))&&e.jsx(t.Pencil,{onClick:()=>{a(c=>{const g=[...c];return g[u]=!c[u],g})},className:"invisible size-3 cursor-pointer text-gray-400 group-hover:visible"})})]}),m(u)]})},p)})]})}function On({idx:s}){var d;const a=t.useEditorStore(m=>{var p;return(p=m.card)==null?void 0:p.preferences}),n=t.useEditorStore(m=>{var p;return(p=m.card.preferences)==null?void 0:p.datasetOptions}),r=t.useEditorStore(m=>m.actions.setCardPreferences),o=(d=a==null?void 0:a.chartOptions)==null?void 0:d.indexAxis,l=n==null?void 0:n.find(m=>m.idx===s);function i(m,p){(m==="end"||m==="start")&&t.getContrastColor(t.getCanvasBackgroundColor());const u={display:m!=="none",align:m,anchor:m,clamp:!0};if(!l)r({...a,datasetOptions:[...n||[],{idx:p,datalabels:u}]});else{const x={...l};x.datalabels=u;const f=n==null?void 0:n.map(c=>c.idx===p?x:c);r({...a,datasetOptions:f})}}return e.jsxs(t.Popover,{children:[e.jsx(t.PopoverTrigger,{children:e.jsx(Vs,{className:"invisible size-4 rotate-[135deg] cursor-pointer text-muted-foreground hover:text-foreground group-hover:visible"})}),e.jsx(t.PopoverContent,{className:"w-fit p-1",children:e.jsxs("div",{className:"flex gap-1",children:[e.jsx(t.Button,{onClick:()=>i("none",s),size:"sm",variant:"secondary",className:"h-7 p-1 text-xs font-normal",children:e.jsx(t.X,{className:"size-4"})}),e.jsx(t.Button,{onClick:()=>i("start",s),size:"sm",variant:"secondary",className:"h-7 p-1 text-xs font-normal",children:e.jsx(Ns,{className:t.cn("h-4 w-4",{"rotate-90":o==="y"})})}),e.jsx(t.Button,{onClick:()=>i("center",s),size:"sm",variant:"secondary",className:"h-7 p-1 text-xs font-normal",children:e.jsx(ks,{className:t.cn("h-4 w-4",{"rotate-90":o==="y"})})}),e.jsx(t.Button,{onClick:()=>i("end",s),size:"sm",variant:"secondary",className:"h-7 p-1 text-xs font-normal",children:e.jsx(ws,{className:t.cn("h-4 w-4",{"rotate-90":o==="y"})})})]})})]})}function Pt(){const s=t.useEditorStore(p=>p.card),a=t.useEditorStore(p=>{var u,x,f;return(f=(x=(u=p==null?void 0:p.card)==null?void 0:u.preferences)==null?void 0:x.chartOptions)==null?void 0:f.indexAxis}),{data:n}=t.useDashboardCardQuery(s),r=a==="y"?"Metric":"Dimension",o=a==="y"?"Dimension":"Metric",{keys:l,metricKeys:i,dimensionKeys:d}=t.getKeys((n==null?void 0:n.records)||[]);let m=i;if(["stackedBar","stackedLine"].includes(s.type)){const p=t.pivotData({dataArray:(n==null?void 0:n.records)||[],groupKey:d[0],pivotKey:d[1],valueKey:m[0]}),{metricKeys:u}=t.getKeys(p);m=u}return l.length===0?null:e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(t.Label,{children:r}),e.jsx("div",{className:"max-h-[125px] space-y-1 overflow-y-auto",children:d.map(p=>e.jsx("p",{className:"rounded-md bg-muted/70 px-3 py-2 hover:bg-muted",title:p,children:Ht(p)},p))})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(t.Label,{children:o}),e.jsx("div",{className:"my-1 max-h-[125px] space-y-1 overflow-y-auto",children:m.map((p,u)=>e.jsx(zn,{col:p,idx:u},p))})]})]})}function Ht(s,a=30){return s.length>a?s.slice(0,a)+"...":s}function zn({col:s,idx:a}){const n=t.useEditorStore(d=>{var m;return(m=d.card)==null?void 0:m.preferences}),r=t.useEditorStore(d=>{var m;return(m=d.card.preferences)==null?void 0:m.datasetOptions}),o=r==null?void 0:r.find(d=>d.idx===a),{setCardPreferences:l}=t.useEditorStore(d=>d.actions);function i(d){if(!o)l({...n,datasetOptions:[...r||[],{idx:a,type:d==="area"?"line":d,fill:d==="area"?"origin":""}]});else{const m={...o};m.type=d==="area"?"line":d,m.fill=d==="area"?"origin":"";const p=r==null?void 0:r.map(u=>u.idx===a?m:u);l({...n,datasetOptions:p})}}return e.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.jsx("p",{title:s,children:Ht(s)}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(Be,{onClick:()=>i("bar"),className:"invisible size-4 cursor-pointer text-muted-foreground hover:text-foreground group-hover:visible"}),e.jsx(Pe,{onClick:()=>i("line"),className:"invisible size-4 cursor-pointer text-muted-foreground hover:text-foreground group-hover:visible"}),e.jsx(ls,{onClick:()=>i("area"),className:"invisible size-4 cursor-pointer text-muted-foreground hover:text-foreground group-hover:visible"}),e.jsx(On,{idx:a})]})]})}function Gt(){const s=t.useEditorStore(c=>c.selectedConnectionId),a=t.useEditorStore(c=>c.selectedDatamodelId),n=t.useEditorStore(c=>c.selectedDatabaseName),r=t.useEditorStore(c=>c.selectedSchemaName),o=t.useEditorStore(c=>c.selectedTableName),l=t.useDashboardStore(c=>c.dashboard.filters)||[],i=t.useDashboardStore(c=>c.actions.addFilter),d=t.useDashboardStore(c=>c.actions.removeFilter),{removeFilterValues:m}=t.useDashboardActions(),{modelItems:p,tableName:u,connectionType:x}=se();function f(c,g="dashboard"){var R;const h=t.fmt(c.column_name),j=t.fmt(n||""),b=t.fmt(r||""),O=t.fmt(u);let E=t.getQualifiedTableName({schemaName:b,tableName:O,connectionType:x,databaseName:j}),z=`${E}.${h}`;const w=(R=p==null?void 0:p.find(F=>F.id===a))==null?void 0:R.name;a&&a!=="none"&&(z=`${t.DATAMODEL_NAMESPCACE}.${w}.${h}`,E=`${t.DATAMODEL_NAMESPCACE}.${w}`);const M=l==null?void 0:l.find(F=>F.column===z&&F.table===O&&(F.database===j||F.database===n));if(M)m(M.id),d(M.id);else{const F=t.v4();return u==="api"&&s?(i({location:g,id:F,column:z,title:c.column_name,dataType:c.data_type,table:"api",database:"",connectionId:s,operation:"in",sql:t.getDefaultFilterSql(c.data_type,E,h)}),F):(i({id:F,location:g,column:z,title:c.column_name,dataType:c.data_type,table:o||"",database:n||"",connectionId:s||"",operation:"in",sql:t.getDefaultFilterSql(c.data_type,E,h)}),F)}}return{assignFilter:f}}function me(){const s=t.useDashboardStore(d=>d.dashboard.filters),a=t.useEditorStore(d=>d.frame),{setFrame:n}=t.useEditorActions(),{columns:r}=se(),{assignFilter:o}=Gt();function l(d){const m=o(d,"frame");n({...a,filterId:m})}const i=s==null?void 0:s.find(d=>d.id===a.filterId);return e.jsxs("div",{className:"space-y-3",children:[e.jsx(t.Label,{children:"Card Filter"}),e.jsx(Fn,{onSelect:l,columns:r}),i&&e.jsx(t.FilterHeader,{filter:i})]})}function Fn({columns:s,onSelect:a}){var i;const[n,r]=de.useState(!1),[o,l]=de.useState("");return e.jsxs(t.Popover,{open:n,onOpenChange:r,children:[e.jsx(t.PopoverTrigger,{asChild:!0,children:e.jsxs(t.Button,{size:"sm",variant:"outline",role:"combobox","aria-expanded":n,className:"w-full justify-between font-normal",children:[o?(i=s.find(d=>d.column_name===o))==null?void 0:i.column_name:"Select Column...",e.jsx(t.CaretSortIcon,{className:"ml-2 h-4 w-4 shrink-0 opacity-50"})]})}),e.jsx(t.PopoverContent,{className:"w-[200px] p-0",children:e.jsxs(t.Command,{children:[e.jsx(t.CommandInput,{placeholder:"Search column",className:"h-9"}),e.jsxs(t.CommandList,{children:[e.jsx(t.CommandEmpty,{children:"No framework found."}),e.jsx(t.CommandGroup,{children:s==null?void 0:s.map(d=>e.jsxs(t.CommandItem,{value:d.column_name,onSelect:m=>{const p=m===o?"":m;l(p),r(!1),p&&a(d)},children:[d.column_name,e.jsx(t.CheckIcon,{className:t.cn("ml-auto h-4 w-4",o===d.column_name?"opacity-100":"opacity-0")})]},d.column_name))})]})]})})]})}function Rn({cardType:s}){return e.jsx("div",{className:"space-y-6 px-6 py-2",children:e.jsxs(t.Accordion,{defaultValue:["item-2"],type:"multiple",children:[e.jsxs(t.AccordionItem,{value:"item-1",children:[e.jsx(t.AccordionTrigger,{children:`${t.titleCase(s)} Chart`}),e.jsxs(t.AccordionContent,{className:"space-y-4 font-mono text-xs",children:[e.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.jsxs("ul",{className:"ml-6 list-disc text-xs [&>li]:mt-2",children:[e.jsx("li",{children:"x-axis - category"}),e.jsx("li",{children:"y-axis1 - number"}),e.jsx("li",{children:"y-axis2 - number"})]}),e.jsxs("div",{children:["See ",e.jsx("a",{target:"_blank",onClick:a=>a.stopPropagation(),className:"text-blue-700",href:"https://docs.semaphor.cloud/docs/charts/bar-line-area",children:"example"})," in the docs."]})]})]}),e.jsxs(t.AccordionItem,{value:"item-2",children:[e.jsx(t.AccordionTrigger,{children:"Settings"}),e.jsx(t.AccordionContent,{className:"space-y-4 px-2",children:e.jsx(Pt,{})})]}),e.jsxs(t.AccordionItem,{value:"item-3",children:[e.jsx(t.AccordionTrigger,{children:"Filters"}),e.jsxs(t.AccordionContent,{className:"space-y-4 px-2",children:[e.jsx(oe,{}),e.jsx(me,{})]})]})]})})}function $e(){var o,l,i;const s=t.useEditorStore(d=>d.card.type),a=t.useEditorStore(d=>d.card.preferences),{setCardPreferences:n}=t.useEditorStore(d=>d.actions);function r(d){var u;const m={datalabels:{display:d!=="none",align:d,anchor:d,clamp:!0}},p={...a,chartOptions:{...a==null?void 0:a.chartOptions,plugins:{...(u=a==null?void 0:a.chartOptions)==null?void 0:u.plugins,...m}}};n(p),console.log(d)}return e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"font-medium",children:"Data Labels"}),e.jsxs(t.Select,{value:((i=(l=(o=a==null?void 0:a.chartOptions)==null?void 0:o.plugins)==null?void 0:l.datalabels)==null?void 0:i.anchor)||"none",onValueChange:r,defaultValue:"none",children:[e.jsx(t.SelectTrigger,{className:"h-8 w-full focus:ring-1 focus:ring-offset-0",children:e.jsx(t.SelectValue,{placeholder:"Select position"})}),e.jsx(t.SelectContent,{children:e.jsxs(t.SelectGroup,{children:[e.jsx(t.SelectLabel,{children:"Data Labels"}),e.jsx(t.SelectItem,{value:"none",children:"None"}),s!=="pyramid"&&e.jsx(t.SelectItem,{value:"start",children:"Start"}),e.jsx(t.SelectItem,{value:"center",children:"Center"}),s!=="pyramid"&&e.jsx(t.SelectItem,{value:"end",children:"End"})]})})]})]})}function _n({cardType:s}){function a(n){return e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"rounded bg-muted px-2 py-1 text-xs",children:n==="bubble"?"SELECT label, [group], x-axis, y-axis, radius FROM table":"SELECT label, [group], x-axis, y-axis FROM table"}),e.jsxs("ul",{className:"ml-6 list-disc text-xs [&>li]:mt-2",children:[e.jsx("li",{children:"label - category"}),e.jsx("li",{children:"group (optional) - category"}),e.jsx("li",{children:"x-axis - number"}),e.jsx("li",{children:"y-axis - number"}),n==="bubble"&&e.jsx("li",{children:"radius - number"})]}),e.jsxs("div",{children:["See ",e.jsx("a",{target:"_blank",onClick:l=>l.stopPropagation(),className:"text-blue-700",href:"https://docs.semaphor.cloud/docs/charts/bubble",children:"example"})," in the docs."]})]})}return e.jsx("div",{className:"space-y-6 px-6 py-2",children:e.jsxs(t.Accordion,{defaultValue:["item-2"],type:"multiple",children:[e.jsxs(t.AccordionItem,{value:"item-1",children:[e.jsx(t.AccordionTrigger,{children:`${t.titleCase(s)} Chart`}),e.jsx(t.AccordionContent,{className:"space-y-4 font-mono text-xs",children:a(s)})]}),e.jsxs(t.AccordionItem,{value:"item-2",children:[e.jsx(t.AccordionTrigger,{children:"Settings"}),e.jsx(t.AccordionContent,{className:"px-2",children:e.jsx($e,{})})]}),e.jsxs(t.AccordionItem,{value:"item-3",children:[e.jsx(t.AccordionTrigger,{children:"Filters"}),e.jsxs(t.AccordionContent,{className:"space-y-4 px-2",children:[e.jsx(oe,{}),e.jsx(me,{})]})]})]})})}const Vn={datasets:[{type:"line",label:"Sum_sales",data:[]},{type:"bar",label:"Sum_profit",data:[]}]},qn={datasets:[{fill:"origin",type:"line",label:"Sum_sales",data:[]}]};function Bn(){const s=t.useEditorStore(a=>a.card.type);return e.jsxs("div",{className:"space-y-6 p-6",children:[e.jsx(t.Accordion,{className:" ",type:"single",collapsible:!0,children:Pn(s)}),!["kpi"].includes(s)&&e.jsxs("div",{className:"space-y-4",children:[e.jsx($e,{}),e.jsx(oe,{}),e.jsx(me,{})]})]})}function Pn(s){if(["line","bar"].includes(s))return e.jsxs(e.Fragment,{children:[e.jsxs(t.AccordionItem,{value:"item-1",children:[e.jsx(t.AccordionTrigger,{className:"font-normal",children:e.jsx("p",{children:"Chart Query"})}),e.jsxs(t.AccordionContent,{className:" ",children:[e.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.jsxs("ul",{className:"my-6 ml-6 list-disc text-xs font-normal [&>li]:mt-2",children:[e.jsx("li",{children:"X-axis - Category (ex. city)"}),e.jsx("li",{children:"Y-axis - Number (ex. population)"})]})]})]}),e.jsxs(t.AccordionItem,{value:"item-2",children:[e.jsx(t.AccordionTrigger,{className:"font-normal",children:"Mixed Chart"}),e.jsxs(t.AccordionContent,{className:"space-y-2 text-xs",children:[e.jsxs("p",{children:["Click ",e.jsx("b",{children:"Customize"})," and change the `type` property in the dataset."]}),e.jsx("pre",{children:JSON.stringify(Vn,null,2)})]})]}),e.jsxs(t.AccordionItem,{value:"item-3",children:[e.jsx(t.AccordionTrigger,{className:"font-normal",children:"Area Chart"}),e.jsxs(t.AccordionContent,{className:"space-y-2 text-xs",children:[e.jsxs("p",{children:["Click ",e.jsx("b",{children:"Customize"})," and add `fill` property to the dataset. See",e.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.jsx("pre",{children:JSON.stringify(qn,null,2)})]})]})]});if(s==="bubble")return e.jsx(e.Fragment,{children:e.jsxs(t.AccordionItem,{value:"item-1",children:[e.jsx(t.AccordionTrigger,{className:"font-normal",children:e.jsxs("p",{children:["How to create a ",e.jsx("span",{children:s})," chart query?"]})}),e.jsxs(t.AccordionContent,{className:" ",children:[e.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.jsxs("ul",{className:"my-6 ml-6 list-disc text-xs font-normal [&>li]:mt-2",children:[e.jsx("li",{children:"Label - Category (ex. city)"}),e.jsx("li",{children:"Bubble Group (opt) - Category (ex. state)"}),e.jsx("li",{children:"X-axis - Number (ex. avg. age)"}),e.jsx("li",{children:"Y-axis - Number (ex. avg. weight)"}),e.jsx("li",{children:"Radius - Number (ex. population)"})]})]})]})});if(s==="scatter")return e.jsx(e.Fragment,{children:e.jsxs(t.AccordionItem,{value:"item-1",children:[e.jsx(t.AccordionTrigger,{className:"font-normal",children:e.jsxs("p",{children:["How to create a ",e.jsx("span",{children:s})," chart query?"]})}),e.jsxs(t.AccordionContent,{className:" ",children:[e.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.jsxs("ul",{className:"my-6 ml-6 list-disc text-xs font-normal [&>li]:mt-2",children:[e.jsx("li",{children:"Label - Category (ex. city)"}),e.jsx("li",{children:"Group (opt) - Category (ex. state)"}),e.jsx("li",{children:"X-axis - Number (ex. avg. age)"}),e.jsx("li",{children:"Y-axis - Number (ex. avg. weight)"})]})]})]})});if(["pie","doughnut","polarArea"].includes(s))return e.jsx(e.Fragment,{children:e.jsxs(t.AccordionItem,{value:"item-1",children:[e.jsx(t.AccordionTrigger,{className:"font-normal",children:e.jsxs("p",{children:[e.jsx("span",{children:s==="polarArea"?"Polar":s.charAt(0).toUpperCase()+s.slice(1)})," ","chart query"]})}),e.jsxs(t.AccordionContent,{className:" ",children:[e.jsx("div",{className:"rounded bg-muted px-2 py-1 font-mono text-xs font-semibold",children:"SELECT label, measure FROM table"}),e.jsxs("ul",{className:"my-6 ml-6 list-disc text-xs font-normal [&>li]:mt-2",children:[e.jsx("li",{children:"Label - Category (ex. city)"}),e.jsx("li",{children:"Measure - Number (ex. population)"})]})]})]})})}function Hn(){var m,p,u,x,f;const s=t.useEditorStore(c=>c.card.preferences),a=t.useEditorStore(c=>c.actions.setCardPreferences),n=t.useEditorStore(c=>c.actions.setNumberFormat);t.useEditorStore(c=>{var g,h;return(h=(g=c.card.preferences)==null?void 0:g.formatNumber)==null?void 0:h.decimalPlaces});const r=t.useEditorStore(c=>{var g,h;return(h=(g=c.card.preferences)==null?void 0:g.formatNumber)==null?void 0:h.locale}),o=t.useEditorStore(c=>{var g,h;return(h=(g=c.card.preferences)==null?void 0:g.formatNumber)==null?void 0:h.currency});t.useEditorStore(c=>c.actions.setFilterOnClickField);const l=t.useEditorStore(c=>{var g,h;return(h=(g=c.card.preferences)==null?void 0:g.formatNumber)==null?void 0:h.colorRanges})||[],i=t.useEditorStore(c=>c.actions.setColorRanges),d=[...new Set(t.LOCALE_CURRENCY_PAIRS.map(c=>c.currency))];return e.jsxs("div",{children:[e.jsxs("div",{className:"mb-3 flex items-center gap-2",children:[e.jsx(t.Checkbox,{checked:!!((m=s==null?void 0:s.formatNumber)!=null&&m.enabled),onCheckedChange:c=>{a({...s,formatNumber:{...s==null?void 0:s.formatNumber,enabled:c}})}}),e.jsx(t.Label,{children:"Format Number"})]}),((p=s==null?void 0:s.formatNumber)==null?void 0:p.enabled)===!0&&e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsx("div",{children:e.jsxs("div",{className:"space-y-4 p-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("div",{className:"w-full space-y-1",children:[e.jsx(t.Label,{children:"Locale"}),e.jsxs(t.Select,{value:r||"none",onValueChange:c=>{var g,h,j;return n(((g=s==null?void 0:s.formatNumber)==null?void 0:g.decimalPlaces)||0,((h=s==null?void 0:s.formatNumber)==null?void 0:h.currency)||"",c,((j=s==null?void 0:s.formatNumber)==null?void 0:j.suffix)||"")},children:[e.jsx(t.SelectTrigger,{className:"col-span-6 h-8 w-full focus:ring-1 focus:ring-offset-0",children:e.jsx(t.SelectValue,{})}),e.jsx(t.SelectContent,{children:e.jsxs(t.SelectGroup,{children:[e.jsx(t.SelectLabel,{children:"Format"}),e.jsx(t.SelectItem,{value:"none",children:"None"},"none"),t.LOCALE_CURRENCY_PAIRS.map(c=>e.jsx(t.SelectItem,{value:c.locale,children:c.locale},c.locale))]})})]})]}),e.jsxs("div",{className:"w-full space-y-1",children:[e.jsx(t.Label,{children:"Currency"}),e.jsxs(t.Select,{value:o||"none",onValueChange:c=>{var g,h,j;console.log("currency",c),n(((g=s==null?void 0:s.formatNumber)==null?void 0:g.decimalPlaces)||0,c==="none"?"":c,((h=s==null?void 0:s.formatNumber)==null?void 0:h.locale)||"",((j=s==null?void 0:s.formatNumber)==null?void 0:j.suffix)||"")},children:[e.jsx(t.SelectTrigger,{className:"col-span-6 h-8 w-full focus:ring-1 focus:ring-offset-0",children:e.jsx(t.SelectValue,{})}),e.jsx(t.SelectContent,{children:e.jsxs(t.SelectGroup,{children:[e.jsx(t.SelectLabel,{children:"Currency"}),e.jsx(t.SelectItem,{value:"none",children:"None"},"none"),d.map(c=>e.jsx(t.SelectItem,{value:c,children:c},c))]})})]})]})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs("div",{className:"w-full space-y-1",children:[e.jsx(t.Label,{children:"Decimals"}),e.jsxs(t.Select,{value:((x=(u=s==null?void 0:s.formatNumber)==null?void 0:u.decimalPlaces)==null?void 0:x.toString())||"0",onValueChange:c=>{var g,h,j;return n(Number(c),((g=s==null?void 0:s.formatNumber)==null?void 0:g.currency)||"",((h=s==null?void 0:s.formatNumber)==null?void 0:h.locale)||"",((j=s==null?void 0:s.formatNumber)==null?void 0:j.suffix)||"")},children:[e.jsx(t.SelectTrigger,{className:"col-span-3 h-8 w-full focus:ring-1 focus:ring-offset-0",children:e.jsx(t.SelectValue,{})}),e.jsx(t.SelectContent,{children:["0","1","2","3","4"].map(c=>e.jsx(t.SelectItem,{value:c,children:c},c))})]})]}),e.jsxs("div",{className:"w-full space-y-1",children:[e.jsx(t.Label,{children:"Suffix"}),e.jsx(t.Input,{value:((f=s==null?void 0:s.formatNumber)==null?void 0:f.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 g,h,j;return n(((g=s==null?void 0:s.formatNumber)==null?void 0:g.decimalPlaces)||0,((h=s==null?void 0:s.formatNumber)==null?void 0:h.currency)||"",((j=s==null?void 0:s.formatNumber)==null?void 0:j.locale)||"",c.target.value)}})]})]})]})}),e.jsx(t.Separator,{className:"my-3"}),e.jsx(t.ColorFormat,{colorRanges:l,setColorRanges:i})]})]})}function Gn(){return e.jsxs("div",{className:"space-y-6 px-6 py-2",children:[e.jsx(t.Accordion,{type:"single",collapsible:!0,children:e.jsxs(t.AccordionItem,{value:"item-1",children:[e.jsx(t.AccordionTrigger,{className:"",children:"KPI Query"}),e.jsxs(t.AccordionContent,{className:"font-mono",children:[e.jsx("div",{className:"rounded bg-muted px-2 py-1 font-mono text-xs",children:"SELECT current, previous FROM table"}),e.jsxs("ul",{className:"my-6 ml-6 list-disc text-xs [&>li]:mt-2",children:[e.jsx("li",{children:"current - number"}),e.jsx("li",{children:"previous - number"})]}),e.jsxs("div",{children:["See ",e.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.jsx("section",{className:"",children:e.jsx(Hn,{})}),e.jsx("div",{}),e.jsx("div",{})]})}function De({children:s,summary:a,open:n,className:r}){return e.jsxs("details",{open:n,className:t.cn("space-y-4 [&_summary>svg]:open:-rotate-180",r),children:[e.jsxs("summary",{className:"flex cursor-pointer list-none items-center justify-between gap-4",children:[e.jsx(t.Label,{children:a}),e.jsx(t.ChevronUp,{className:"h-4 w-4"})]}),e.jsx("div",{className:"transition-all ease-in-out",children:s})]})}const Un=[{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"}],$n=["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"],Qn=$n.map(s=>({label:s,value:s}));function Jn(){var m,p,u,x,f,c,g,h,j,b,O,E,z,w,M,R,F,H;const s=t.useEditorStore(S=>S.card),a=(p=(m=s==null?void 0:s.preferences)==null?void 0:m.mapVisualOptions)==null?void 0:p.topoJsonUrl,[n,r]=k.useState(((x=(u=s==null?void 0:s.preferences)==null?void 0:u.mapVisualOptions)==null?void 0:x.customTopoJsonUrl)||""),{setCardPreferences:o}=t.useEditorActions(),{data:l}=t.useTopoJson(s),i=Object.keys((l==null?void 0:l.objects)||{}).map(S=>({label:S,value:S}))||[],d=[{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.jsxs("div",{className:"p-6",children:[e.jsx(De,{summary:"Map Chart",children:e.jsx("p",{className:"rounded-md bg-muted p-2 font-mono text-xs",children:"SELECT country, value FROM table"})}),e.jsx(t.Separator,{className:"my-4"}),e.jsx(De,{open:!0,summary:"Settings",children:e.jsxs("div",{className:"space-y-3 px-2",children:[e.jsx(X,{className:"h-9",options:d,onValueChange:S=>{console.log("value",S),o({...s.preferences,mapVisualOptions:{topoJsonUrl:S}})},value:a||"",label:"Select Map"}),a==="custom"&&e.jsx(t.Input,{onChange:S=>{r(S.target.value)},onBlur:()=>{var S;console.log("onBlur",n),o({...s.preferences,mapVisualOptions:{...(S=s.preferences)==null?void 0:S.mapVisualOptions,customTopoJsonUrl:n}})},value:n,className:`h-9 w-full ${t.removeRing}`,placeholder:"Custom URL"}),l&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(t.Label,{children:"Map Object"}),e.jsx(X,{className:"h-9",options:i,value:((c=(f=s.preferences)==null?void 0:f.mapVisualOptions)==null?void 0:c.objectKey)||"",label:"Map Object",onValueChange:S=>{var v;o({...s.preferences,mapVisualOptions:{...(v=s.preferences)==null?void 0:v.mapVisualOptions,objectKey:S}})}})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(t.Label,{children:"Projection"}),e.jsx(X,{className:"h-9",options:Un,value:((h=(g=s.preferences)==null?void 0:g.mapVisualOptions)==null?void 0:h.projection)||"",label:"Projection",onValueChange:S=>{var v;o({...s.preferences,mapVisualOptions:{...(v=s.preferences)==null?void 0:v.mapVisualOptions,projection:S}})}})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(t.Label,{children:"Colors"}),e.jsx(X,{className:"h-9",options:Qn,value:((b=(j=s.preferences)==null?void 0:j.mapVisualOptions)==null?void 0:b.colorScale)||"",label:"Select Color Scale",onValueChange:S=>{var v;o({...s.preferences,mapVisualOptions:{...(v=s.preferences)==null?void 0:v.mapVisualOptions,colorScale:S}})}})]})]})]})}),e.jsx(t.Separator,{className:"my-4"}),e.jsx(De,{className:"",summary:"Scale Options",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(t.Input,{className:`h-9 w-full ${t.removeRing}`,type:"number",step:.1,value:((E=(O=s.preferences)==null?void 0:O.mapVisualOptions)==null?void 0:E.projectionScale)||1,onChange:S=>{var v;o({...s.preferences,mapVisualOptions:{...(v=s.preferences)==null?void 0:v.mapVisualOptions,projectionScale:Number(S.target.value)}})}}),e.jsx(t.Label,{children:"X"}),e.jsx(t.Input,{className:`h-9 w-full ${t.removeRing}`,type:"number",step:10,value:((M=(w=(z=s.preferences)==null?void 0:z.mapVisualOptions)==null?void 0:w.projectionOffset)==null?void 0:M[0])||0,onChange:S=>{var v,A,D,y;o({...s.preferences,mapVisualOptions:{...(v=s.preferences)==null?void 0:v.mapVisualOptions,projectionOffset:[Number(S.target.value),((y=(D=(A=s.preferences)==null?void 0:A.mapVisualOptions)==null?void 0:D.projectionOffset)==null?void 0:y[1])||0]}})}}),e.jsx(t.Label,{children:"Y"}),e.jsx(t.Input,{className:`h-9 w-full ${t.removeRing}`,type:"number",step:10,value:((H=(F=(R=s.preferences)==null?void 0:R.mapVisualOptions)==null?void 0:F.projectionOffset)==null?void 0:H[1])||0,onChange:S=>{var v,A,D,y;o({...s.preferences,mapVisualOptions:{...(v=s.preferences)==null?void 0:v.mapVisualOptions,projectionOffset:[((y=(D=(A=s.preferences)==null?void 0:A.mapVisualOptions)==null?void 0:D.projectionOffset)==null?void 0:y[0])||0,Number(S.target.value)]}})}})]})}),e.jsx(t.Separator,{className:"my-4"}),e.jsx(oe,{})]})}function Kn(){var r;const s=t.useEditorStore(o=>o.card.preferences),{setCardPreferences:a}=t.useEditorStore(o=>o.actions);function n(o){a({...s,textVisualOptions:{...s==null?void 0:s.textVisualOptions,isDynamicText:o==="dynamic"}})}return e.jsxs(t.RadioGroup,{value:(r=s==null?void 0:s.textVisualOptions)!=null&&r.isDynamicText?"dynamic":"static",onValueChange:n,className:"flex gap-3",defaultValue:"x",children:[e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(t.RadioGroupItem,{value:"static",id:"r1"}),e.jsx("label",{className:"text-sm",htmlFor:"r1",children:"Static"})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(t.RadioGroupItem,{value:"dynamic",id:"r2"}),e.jsx("label",{className:"text-sm",htmlFor:"r2",children:"Dynamic"})]})]})}function fe({cardType:s,docContent:a,suffix:n="Chart"}){return e.jsx("div",{className:"space-y-6 px-6 py-2",children:e.jsxs(t.Accordion,{defaultValue:["item-2"],type:"multiple",children:[e.jsxs(t.AccordionItem,{value:"item-1",children:[e.jsx(t.AccordionTrigger,{children:`${t.titleCase(s)} ${n}`}),e.jsx(t.AccordionContent,{children:a||e.jsxs("div",{className:"space-y-4 font-mono text-xs",children:[e.jsx("div",{className:"rounded bg-muted px-2 py-1 text-xs",children:"SELECT label, measure FROM table"}),e.jsxs("ul",{className:"ml-6 list-disc text-xs [&>li]:mt-2",children:[e.jsx("li",{children:"label - category"}),e.jsx("li",{children:"measure - number"})]}),e.jsxs("div",{children:["See ",e.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.jsxs(t.AccordionItem,{value:"item-2",children:[e.jsx(t.AccordionTrigger,{children:"Settings"}),e.jsxs(t.AccordionContent,{className:"space-y-4 px-2",children:[s!=="text"&&e.jsx($e,{}),s==="text"&&e.jsx(Kn,{})]})]}),!["range","text"].includes(s)&&e.jsxs(t.AccordionItem,{value:"item-3",children:[e.jsx(t.AccordionTrigger,{children:"Filters"}),e.jsxs(t.AccordionContent,{className:"space-y-4 px-2",children:[e.jsx(oe,{}),e.jsx(me,{})]})]})]})})}function Wn(){const s=t.useEditorStore(r=>{var o,l;return(l=(o=r==null?void 0:r.card)==null?void 0:o.preferences)==null?void 0:l.sortChart}),{setSortChart:a}=t.useEditorActions();function n(){return e.jsxs("div",{className:"space-y-2",children:[e.jsx(t.Label,{children:"Sort"}),e.jsx(X,{className:"h-8",label:"Sort Chart",options:[{label:"None",value:"none"},{label:"ASC",value:"asc"},{label:"DESC",value:"desc"}],value:s||"none",onValueChange:r=>{a(r)}})]})}return e.jsx("div",{className:"space-y-6 px-6 py-2",children:e.jsxs(t.Accordion,{defaultValue:["item-2"],type:"multiple",children:[e.jsxs(t.AccordionItem,{value:"item-1",children:[e.jsx(t.AccordionTrigger,{children:"Stacked Chart"}),e.jsxs(t.AccordionContent,{className:"space-y-4 font-mono text-xs",children:[e.jsx("div",{className:"rounded bg-muted px-2 py-1 text-xs",children:"SELECT x-axis, stack-by, y-axis FROM table"}),e.jsxs("ul",{className:"ml-6 list-disc text-xs [&>li]:mt-2",children:[e.jsx("li",{children:"x-axis - category"}),e.jsx("li",{children:"stack by - category"}),e.jsx("li",{children:"y-axis - number"})]}),e.jsxs("div",{children:["See ",e.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.jsxs(t.AccordionItem,{value:"item-2",children:[e.jsx(t.AccordionTrigger,{children:"Settings"}),e.jsxs(t.AccordionContent,{className:"space-y-4 px-2",children:[n(),e.jsx(Pt,{})]})]}),e.jsxs(t.AccordionItem,{value:"item-3",children:[e.jsx(t.AccordionTrigger,{children:"Filters"}),e.jsxs(t.AccordionContent,{className:"space-y-4 px-2",children:[e.jsx(oe,{}),e.jsx(me,{})]})]})]})})}function Yn({cardType:s="table"}){console.log("cardType",s);const a=t.useEditorStore(o=>{var l;return(l=o.card)==null?void 0:l.preferences}),n=t.useEditorStore(o=>o.actions.setCardPreferences),r=o=>{n({...a,allowDownload:o})};return e.jsxs("div",{className:"space-y-6 px-6 py-2",children:[e.jsx(t.Accordion,{defaultValue:["item-3"],type:"multiple",children:e.jsxs(t.AccordionItem,{value:"item-3",children:[e.jsx(t.AccordionTrigger,{children:"Filters"}),e.jsxs(t.AccordionContent,{className:"space-y-4 px-2",children:[e.jsx(oe,{}),e.jsx(me,{})]})]})}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(t.Checkbox,{onCheckedChange:r,id:"allow-download"}),e.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 Xn=e.jsxs("div",{className:"space-y-4 font-mono text-xs",children:[e.jsx("div",{className:"rounded bg-muted px-2 py-1 text-xs",children:"SELECT dimension, cohort, metric FROM table"}),e.jsxs("div",{children:["See ",e.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."]})]}),Zn=e.jsxs("div",{className:"space-y-4 font-mono text-xs",children:[e.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.jsxs("div",{children:["See ",e.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."]})]}),ea=e.jsxs("div",{className:"space-y-4 font-mono text-xs",children:[e.jsx("div",{className:"rounded bg-muted px-2 py-1 text-xs",children:"SELECT text FROM table limit 1"}),e.jsxs("div",{children:["See ",e.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 ta(){const s=t.useEditorStore(n=>n.card.type);function a(n){switch(n){case"stackedBar":case"stackedLine":return e.jsx(Wn,{});case"pyramid":return e.jsx(fe,{docContent:Xn,cardType:n});case"kpi":return e.jsx(Gn,{});case"line":case"bar":return e.jsx(Rn,{cardType:n});case"range":return e.jsx(fe,{docContent:Zn,cardType:n});case"pie":case"doughnut":case"polarArea":case"radar":return e.jsx(fe,{cardType:n});case"bubble":case"scatter":return e.jsx(_n,{cardType:n});case"table":return e.jsx(Yn,{cardType:n});case"text":return e.jsx(fe,{docContent:ea,cardType:n,suffix:"Visual"});case"map":return e.jsx(Jn,{});case"custom":return e.jsx(Ln,{});default:return e.jsx(Bn,{})}}return e.jsxs(t.ScrollArea,{className:"h-full w-full text-sm",children:[a(s),e.jsx(t.ScrollBar,{orientation:"horizontal"})]})}const Ee={id:"__placeholder__",role:"groupby",type:"string"},Te={id:"__placeholder__",role:"metric",type:"number"},Ae={id:"__placeholder__",role:"trendby",type:"date"},Me={id:"__placeholder__",role:"filter",type:"string"},Ut={id:"__placeholder__"},ye="droppable-group-by",Se="droppable-metrics",ze="sortable-group-by",Fe="sortable-metrics",Re="droppable-trend-by",_e="sortable-trend-by",Ve="droppable-filters",qe="sortable-filters";function sa(){const s=t.useDndStore(v=>v.insertIndex),a=t.useEditorStore(v=>{var A;return((A=v.card.queryConfig)==null?void 0:A.groupByColumns)||[]}),n=t.useEditorStore(v=>{var A;return((A=v.card.queryConfig)==null?void 0:A.metricColumns)||[]}),r=t.useEditorStore(v=>{var A;return((A=v.card.queryConfig)==null?void 0:A.trendByColumns)||[]}),o=t.useEditorStore(v=>{var A;return((A=v.card.queryConfig)==null?void 0:A.filterColumns)||[]}),{setInsertIndex:l,setActiveId:i,setPreviewGroupByColumns:d,setPreviewMetricColumns:m,setPreviewTrendByColumns:p,setPreviewFilterColumns:u}=t.useDndActions(),{setGroupByColumns:x,setMetricColumns:f,setTrendByColumns:c,setFilterColumns:g}=t.useEditorActions(),{columns:h}=wt(),{formattedTableName:j}=se(),b=t.useSensors(t.useSensor(t.MouseSensor,{activationConstraint:{distance:1}})),O=v=>{var y;const{active:A,over:D}=v;if(((y=A.data.current)==null?void 0:y.type)==="column"&&D){const _=D.id,G=h.find(C=>C.column_name===A.id);if(!G)return;const $=t.isNumberDataType(G.data_type),B=t.isTextDataType(G.data_type),I=t.isDateDataType(G.data_type);if(B){if(a.some(N=>N.id===_)){const N=a.findIndex(L=>L.id===_);l(N);const T=a.filter(L=>L.id!==Ee.id);T.splice(N,0,Ee),d(T)}else if(D.id===ye){l(a.length);const N=[...a,Ee];d(N),m(n),p(r),u(o)}}if($||B){if(n.some(N=>N.id===_)){console.log("isOverMetricSortable",_);const N=n.findIndex(L=>L.id===_);l(N);const T=n.filter(L=>L.id!==Te.id);T.splice(N,0,Te),m(T)}else if(D.id===Se){l(n.length);const N=[...n,Te];m(N),p(r),u(o),d(a)}}if(I){if(r.some(N=>N.id===_)){const N=r.findIndex(L=>L.id===_);l(N);const T=r.filter(L=>L.id!==Ae.id);T.splice(N,0,Ae),p(T)}else if(D.id===Re){l(r.length);const N=[...r,Ae];p(N),m(n),u(o),d(a)}}if(z(G)){if(o.some(N=>N.id===_)){const N=o.findIndex(L=>L.id===_);l(N);const T=o.filter(L=>L.id!==Me.id);T.splice(N,0,Me),u(T)}else if(D.id===Ve){l(o.length);const N=[...o,Me];u(N),m(n),p(r),d(a)}}}else d(a),m(n),p(r),u(o)};function E(v){i(v.active.id),l(null),d(a),m(n),p(r),u(o)}function z(v){return!o.some(A=>A.name===v.column_name)}function w(v,A="SUM"){const{column_name:D,data_type:y}=v,_=[...n],G=s!==null?s:n.length,$={...v,id:ae(D),name:D,label:ge(A,D),type:y,role:"metric",aggregate:A};_.splice(G,0,$),f(_)}function M(v){const A=[...a],D=s!==null?s:a.length,y={...v,id:ae(v.column_name),name:v.column_name,type:v.data_type,role:"groupby"};A.splice(D,0,y),x(A)}function R(v){const A=[...r],D=s!==null?s:r.length,y={...v,id:ae(v.column_name),name:v.column_name,type:v.data_type,role:"trendby"};A.splice(D,0,y),c(A)}function F(v){const A=[...o],D=s!==null?s:o.length,y={...v,id:ae(v.column_name),name:v.column_name,type:v.data_type,sql:t.getDefaultFilterSql(v.data_type,j,t.fmt(v.column_name)),role:"filter"};A.splice(D,0,y),g(A)}function H(v){var _,G,$,B,I,C,N,T;const{active:A,over:D}=v,y=A.data.current;if((y==null?void 0:y.type)==="column"&&D){const L=h.find(W=>W.column_name===A.id);if(!L)return;const U=t.isNumberDataType(L.data_type),P=t.isTextDataType(L.data_type),K=t.isDateDataType(L.data_type);P&&(D.id===ye||((_=D.data.current)==null?void 0:_.type)===ze)?M(L):(U||P)&&(D.id===Se||((G=D.data.current)==null?void 0:G.type)===Fe)?(U&&w(L),P&&w(L,"COUNT")):K&&(D.id===Re||(($=D.data.current)==null?void 0:$.type)===_e)?R(L):z(L)&&(D.id===Ve||((B=D.data.current)==null?void 0:B.type)===qe)&&F(L)}if(D&&((I=D.data.current)==null?void 0:I.type)===ze&&a.some(L=>L.id===A.id)){const L=a.findIndex(P=>P.id===A.id),U=a.findIndex(P=>P.id===D.id);if(L!==-1&&U!==-1&&L!==U){const P=[...a],[K]=P.splice(L,1);P.splice(U,0,K),x(P)}}if(D&&((C=D.data.current)==null?void 0:C.type)===Fe&&n.some(L=>L.id===A.id)){const L=n.findIndex(P=>P.id===A.id),U=n.findIndex(P=>P.id===D.id);if(L!==-1&&U!==-1&&L!==U){const P=[...n],[K]=P.splice(L,1);P.splice(U,0,K),f(P)}}if(D&&((N=D.data.current)==null?void 0:N.type)===_e&&r.some(L=>L.id===A.id)){const L=r.findIndex(P=>P.id===A.id),U=r.findIndex(P=>P.id===D.id);if(L!==-1&&U!==-1&&L!==U){const P=[...r],[K]=P.splice(L,1);P.splice(U,0,K),c(P)}}if(D&&((T=D.data.current)==null?void 0:T.type)===qe&&o.some(L=>L.id===A.id)){const L=o.findIndex(P=>P.id===A.id),U=o.findIndex(P=>P.id===D.id);if(L!==-1&&U!==-1&&L!==U){const P=[...o],[K]=P.splice(L,1);P.splice(U,0,K),g(P)}}i(null),l(null),d(a),m(n),p(r),u(o)}function S(){i(null),l(null),d(a),m(n),p(r),u(o)}return{handleDragOver:O,handleDragEnd:H,handleDragStart:E,handleDragCancel:S,sensors:b}}const ce=[{label:"Sum",value:"SUM",logo:e.jsx(gt,{className:"size-3.5"})},{label:"Count",value:"COUNT",logo:e.jsx(mt,{className:"size-3.5"})},{label:"Unique",value:"DISTINCT",logo:e.jsx(js,{className:"size-3.5"})},{label:"Average",value:"AVG",logo:e.jsx(Zt,{className:"size-3.5"})},{label:"Min",value:"MIN",logo:e.jsx(Yt,{className:"size-3.5"})},{label:"Max",value:"MAX",logo:e.jsx(ss,{className:"size-3.5"})}];function na({column:s,type:a,onRemoveColumn:n,droppableId:r}){const[o,l]=k.useState(!1),[i,d]=k.useState(ce[0]),{attributes:m,listeners:p,setNodeRef:u,transform:x,transition:f,isDragging:c}=t.useSortable({id:s.id,data:{type:a}}),g=x?{opacity:c?.5:void 0,transform:t.CSS.Translate.toString(x),transition:f}:void 0;function h(){return e.jsx("div",{"data-setting-container":"",className:"h-32 rounded-b-md border-x border-b border-border p-3 text-sm",children:e.jsx(e.Fragment,{})})}return e.jsxs("div",{...p,...m,ref:u,style:g,children:[e.jsxs("div",{className:t.cn("group flex h-8 items-center rounded-t-md bg-muted px-2",!o&&"rounded-b-md",o&&"border border-border"),children:[e.jsx("div",{children:e.jsx(t.GripVertical,{className:"size-3.5 cursor-move items-center justify-center p-0 text-muted-foreground/60 hover:text-foreground"})}),r===Se&&e.jsx(ra,{column:s}),e.jsx("div",{className:t.cn("max-w-[250px] grow cursor-pointer overflow-hidden truncate text-ellipsis whitespace-nowrap",{"pl-2":r===ye}),children:e.jsx(aa,{col:s})}),e.jsxs("div",{"data-setting-actions":"",className:"hidden h-full items-center gap-2 group-hover:flex",children:[e.jsx("button",{onClick:()=>l(!o),children:e.jsx(t.ChevronDown,{className:t.cn("ml-1 size-4 cursor-pointer items-center justify-center rounded-r-sm bg-muted text-muted-foreground",o&&"rotate-180")})}),e.jsx("button",{onClick:()=>n(s.id),children:e.jsx(t.X,{className:"size-3.5 cursor-pointer items-center justify-center rounded-r-sm bg-muted text-muted-foreground"})})]})]}),o&&h()]})}function aa({col:s}){return e.jsx(t.Editable,{text:s.label||s.name,className:"h-6 rounded-none",onSave:a=>{console.log("saved",a)},children:e.jsx("span",{className:"w-[250px] truncate text-ellipsis whitespace-nowrap text-sm",children:s.label||s.name})})}function ra({column:s}){const[a,n]=k.useState(ce[0]),{updateMetricColumn:r}=t.useEditorActions();let o=ce;t.isTextDataType(s.type)&&(o=o.filter(i=>["COUNT","DISTINCT"].includes(i.value))),t.isNumberDataType(s.type)&&(o=o.filter(i=>!["DISTINCT","COUNT"].includes(i.value))),k.useEffect(()=>{n(ce.find(i=>i.value===s.aggregate)||ce[0])},[s]);function l(i){const d=ce.find(p=>p.value===i);if(!d)return;n(d);const m={...s,aggregate:i,label:ge(i,s.name)};r(s.id,m)}return e.jsx(X,{className:"size-7 overflow-clip rounded-none rounded-l-md border-none bg-muted px-2",icon:a.logo,options:o,value:a.value,onValueChange:i=>l(i),label:"Aggregation"})}function Le({id:s,label:a,columns:n,previewColumns:r,sortableType:o,onRemoveColumn:l}){const{setNodeRef:i}=t.useDroppable({id:s}),d=t.useDndStore(u=>u.activeId),m={},p=d?r:n;return e.jsx(t.SortableContext,{items:n==null?void 0:n.map(u=>u.id),children:e.jsxs("div",{className:"space-y-2 rounded-md border-2 border-dashed p-5",ref:i,style:m,children:[e.jsx(t.Label,{className:"text-sm",children:a}),e.jsx("div",{className:"space-y-2",children:p==null?void 0:p.map(u=>u.id===Ut.id?e.jsx(oa,{},u.id):e.jsx(na,{droppableId:s,type:o,column:u,onRemoveColumn:l},u.id))})]})})}function oa(){return e.jsx("div",{className:"flex h-7 grow items-center space-x-2 rounded-md border border-dashed border-muted-foreground bg-background px-2 py-1 text-sm"})}function nt(){const s=t.useEditorStore(c=>{var g;return((g=c.card.queryConfig)==null?void 0:g.groupByColumns)||[]}),a=t.useDndStore(c=>c.previewGroupByColumns),n=t.useEditorStore(c=>{var g;return((g=c.card.queryConfig)==null?void 0:g.metricColumns)||[]}),r=t.useDndStore(c=>c.previewMetricColumns),o=t.useEditorStore(c=>{var g;return((g=c.card.queryConfig)==null?void 0:g.trendByColumns)||[]}),l=t.useDndStore(c=>c.previewTrendByColumns),{setSelectedConnectionId:i,removeColumnFromGroupBy:d,removeColumnFromMetricColumns:m,removeColumnFromTrendByColumns:p}=t.useEditorActions();k.useEffect(()=>{i("c_2d3646f0-68a6-47e7-942d-d9cbc80fb7d4")},[i]);function u(c){d(c)}function x(c){p(c)}function f(c){m(c)}return e.jsxs("div",{className:"h-full w-full space-y-2 p-4",children:[e.jsx(Le,{onRemoveColumn:u,sortableType:ze,id:ye,label:"Group By",columns:s,previewColumns:a}),e.jsx(Le,{onRemoveColumn:x,sortableType:_e,id:Re,label:"Trend By",columns:o,previewColumns:l}),e.jsx(Le,{onRemoveColumn:f,sortableType:Fe,id:Se,label:"Metrics",columns:n,previewColumns:r})]})}function ia({children:s,id:a,type:n}){const{attributes:r,listeners:o,setNodeRef:l,transform:i,transition:d,isDragging:m}=t.useSortable({id:a,data:{type:n}}),p=i?{opacity:m?.5:void 0,transform:t.CSS.Translate.toString(i),transition:d}:void 0;return e.jsx("div",{...o,...r,ref:l,style:p,children:s})}function la({column:s,type:a}){const n=t.useDashboardStore(R=>R.themeStyle),[r,o]=k.useState(!1),l=t.useEditorStore(R=>{var F,H;return(H=(F=R.card)==null?void 0:F.queryConfig)==null?void 0:H.filters}),{selectedConnectionId:i,selectedDatabaseName:d,selectedTableName:m}=se(),p=t.isTextDataType(s.type);t.isNumberDataType(s.type),t.isDateDataType(s.type);const u=k.useMemo(()=>{var R;return(R=l==null?void 0:l.find(F=>F.filterColumnName===s.name))==null?void 0:R.filterValue},[l,s.name]),x=k.useMemo(()=>Array.isArray(u)?u.map(R=>({id:R,value:R})):[],[u]),{updateEditorCardFilterValue:f,removeEditorCardFilter:c}=t.useEditorActions(),g={column:s.name,sql:s.sql,id:s.name,connectionId:i,dataType:s.type},{data:h,isLoading:j,isFetching:b,isError:O}=t.useFilterQuery(g),E=k.useMemo(()=>{var F;return g.column?(F=h==null?void 0:h.records)==null?void 0:F.map(H=>{let S=g.column.split(".").slice(-1)[0].replace(/"/g,"");return H[S]===void 0&&(S=S.toLowerCase()),{id:H[S],value:H[S]}}):[]},[h,g.column]);function z(R){const F=R.map(H=>H.id);f(s.name,F)}function w(R){c(R)}function M(){return j||b?e.jsx(t.Skeleton,{style:{borderRadius:n==null?void 0:n.controlInputRadius},className:"h-8 w-60 bg-foreground/10"}):O?e.jsx("div",{className:"flex h-8 w-60 items-center bg-muted px-2 text-sm",children:"Error"}):p?e.jsx(t.ComboBoxMultiSelect,{options:E,onChange:z,selectedOptions:x,selectAllChecked:!1,onSelectAllCheckedChange:()=>{}}):e.jsx("div",{children:"Not implemented"})}return e.jsx(ia,{id:s.id,type:a,children:e.jsxs("div",{className:"group w-60 space-y-1 rounded-md border border-border px-3 py-2",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(t.Label,{className:"text-sm",children:s.name}),e.jsx("div",{"data-setting-actions":"",className:"invisible flex h-full items-center gap-2 group-hover:visible",children:e.jsx("button",{onClick:()=>w(s),children:e.jsx(t.X,{className:"size-3.5 cursor-pointer items-center justify-center rounded-r-sm text-muted-foreground"})})})]}),e.jsxs("div",{className:t.cn("group flex items-center rounded-t-md text-sm",!r&&"rounded-b-md",r&&"border border-border"),children:[e.jsx("div",{children:e.jsx(t.GripVertical,{className:"mr-2 size-3.5 cursor-move items-center justify-center p-0 text-muted-foreground/60 hover:text-foreground"})}),e.jsx("div",{className:"max-w-[250px] grow cursor-pointer overflow-hidden truncate text-ellipsis whitespace-nowrap",children:M()})]})]})})}function ca({id:s,label:a,columns:n,previewColumns:r,sortableType:o}){const{setNodeRef:l,isOver:i}=t.useDroppable({id:s}),d=t.useDndStore(x=>x.activeId),m={borderColor:i?"green":void 0};function p(x){return x.id===Ut.id?e.jsx(da,{}):e.jsx(la,{droppableId:s,type:o,column:x},x.id)}const u=d?r:n;return e.jsx(t.SortableContext,{items:n==null?void 0:n.map(x=>x.id),children:e.jsxs("div",{className:"space-y-2 rounded-md border-2 border-dashed p-5",ref:l,style:m,children:[e.jsx(t.Label,{className:"text-sm",children:a}),e.jsx("div",{className:"flex flex-wrap items-center gap-4",children:u==null?void 0:u.map(x=>p(x))})]})})}function da(){return e.jsx("div",{className:"flex h-7 w-60 items-center space-x-2 rounded-md border border-dashed border-muted-foreground bg-background px-2 py-1 text-sm"})}function ua(){const s=t.useEditorStore(o=>{var l;return((l=o.card.queryConfig)==null?void 0:l.filterColumns)||[]}),a=t.useDndStore(o=>o.previewFilterColumns),{removeColumnFromFilterColumns:n}=t.useEditorActions();function r(o){n(o)}return e.jsx("div",{className:"size-full p-4",children:e.jsx(ca,{onRemoveColumn:r,sortableType:qe,id:Ve,label:"Filters",columns:s,previewColumns:a})})}function ma(){const s=t.useEditorStore(r=>r.card),{data:a,errorMessage:n}=t.useDashboardCardQuery(s);return e.jsxs("section",{className:"flex justify-between gap-2 p-4",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(Ot,{}),e.jsx(It,{sql:a==null?void 0:a.sql,error:n})]}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"rounded-full bg-green-300 bg-muted px-3 py-1 text-xs font-medium",children:"Early Preview"}),e.jsx(Lt,{}),e.jsx(Mt,{variant:"default"})]})]})}function ha(){const s=k.useRef(null),a=t.useEditorStore(i=>i.isShowingVisual),n=t.useEditorStore(i=>i.showAIDialog),r=t.useEditorStore(i=>i.isDevMode);k.useEffect(()=>{var i,d;n?(i=s.current)==null||i.resize(0):(d=s.current)==null||d.resize(25)},[n]);function o(){return e.jsxs(e.Fragment,{children:[e.jsx(t.ResizablePanel,{role:"query-section",className:"flex",minSize:20,defaultSize:40,children:e.jsx(xn,{})}),e.jsx(t.ResizableHandle,{withHandle:!0,className:"border"}),e.jsx(t.ResizablePanel,{className:"pb-1",role:"visual-section",minSize:0,defaultSize:60,children:a&&!n?e.jsxs(t.ResizablePanelGroup,{direction:"horizontal",children:[e.jsx(e.Fragment,{children:e.jsx(t.ResizablePanel,{ref:s,className:"flex",defaultSize:25,maxSize:30,children:r?e.jsx(ta,{}):e.jsx(nt,{})})}),!n&&e.jsx(t.ResizableHandle,{className:"border"}),e.jsx(t.ResizablePanel,{minSize:40,defaultSize:75,maxSize:100,children:e.jsx(xe,{})})]}):e.jsx(xe,{})})]})}function l(){return e.jsx(e.Fragment,{children:e.jsx(t.ResizablePanel,{className:"pb-1","data-biz-mode-container":"",minSize:0,defaultSize:100,children:a&&!n?e.jsxs(t.ResizablePanelGroup,{direction:"horizontal",children:[e.jsx(e.Fragment,{children:e.jsx(t.ResizablePanel,{ref:s,className:"flex min-w-[320px]",defaultSize:25,maxSize:30,children:e.jsx(nt,{})})}),!n&&e.jsx(t.ResizableHandle,{className:"border"}),e.jsx(t.ResizablePanel,{minSize:40,defaultSize:75,maxSize:100,children:e.jsxs(t.ResizablePanelGroup,{direction:"vertical",children:[e.jsxs(t.ResizablePanel,{className:"flex min-h-fit flex-col",minSize:10,defaultSize:20,children:[e.jsx(ma,{}),e.jsx(ua,{})]}),e.jsx(t.ResizableHandle,{className:"border"}),e.jsx(t.ResizablePanel,{minSize:20,defaultSize:80,children:e.jsx(xe,{})})]})})]}):e.jsx(xe,{})})})}return e.jsx(t.ResizablePanelGroup,{direction:"vertical",className:"min-h-[250px] min-w-full max-w-lg",children:r?o():l()})}const pa=[{title:"Help me write a query for",subtitle:"orders by month"},{title:"Create a bar chart for",subtitle:"sales by category"}];function xa(){const s=k.useRef(null),a=k.useRef(null),[n,r]=k.useState(!1),[o,l]=k.useState(t.isDevEnv),[i,d]=k.useState(!1),m=t.useEditorStore(B=>B.actions.setCardSql),p=t.useEditorStore(B=>B.actions.setRunSql),u=t.useEditorStore(B=>B.showAIDialog),{setShowAIDialog:x}=t.useEditorActions(),{messages:f,setMessages:c,reload:g,append:h,input:j,setInput:b,isLoading:O,handleAddCurrentTableToScope:E,removeFromCurrentSelections:z,currentAssitantScope:w,handleInputChange:M,handleSubmit:R,stop:F,chatStatus:H,toolStatus:S,llmUsage:v,errorMessage:A}=At();t.useAssistantScroll({scrollContainerRef:s,inputRef:a,messages:f}),k.useEffect(()=>{var B;u&&((B=a.current)==null||B.focus())},[u]);function D(B){m(B),p(!0)}function y(B){const I={role:"user",content:B.title+" "+B.subtitle};h(I)}function _(){return e.jsxs(t.DropdownMenu,{children:[e.jsx(t.DropdownMenuTrigger,{asChild:!0,children:e.jsx(t.Button,{className:"h-7 p-2",size:"sm",variant:"ghost",children:e.jsx(dt,{className:"size-3.5 text-muted-foreground/70 hover:text-muted-foreground"})})}),e.jsxs(t.DropdownMenuContent,{align:"end",children:[e.jsx(t.DropdownMenuLabel,{children:"Options"}),e.jsx(t.DropdownMenuSeparator,{}),e.jsx(t.DropdownMenuCheckboxItem,{checked:n,onCheckedChange:r,children:"Token Usage"}),e.jsx(t.DropdownMenuCheckboxItem,{checked:o,onCheckedChange:l,children:"Tool Invocations"}),e.jsx(t.DropdownMenuCheckboxItem,{checked:i,onCheckedChange:d,children:"System Message"})]})]})}function G(){return e.jsxs("div",{"data-role":"header",children:[e.jsx("div",{className:"text-lg font-semibold",children:"Assistant"}),w&&w.length>0&&e.jsx("div",{className:"mt-2 flex flex-wrap items-center gap-2",children:w==null?void 0:w.map((B,I)=>e.jsxs("div",{className:"flex items-center gap-2 rounded-md border border-border bg-muted px-2 py-1 text-xs",children:[t.getFormattedTableNameForQuery({schemaName:B.schemaName||"",tableName:B.tableName||"",modelName:B.datamodelName||"",connectionType:B.connectionType||"",databaseName:B.databaseName||""}),e.jsx("button",{onClick:()=>{z(B)},children:e.jsx(t.X,{className:"size-3 text-muted-foreground hover:text-foreground"})})]},I))}),(w==null?void 0:w.length)===0&&e.jsxs("div",{className:"mt-2 flex items-center gap-2",children:[e.jsx("span",{className:"text-xs text-muted-foreground",children:"Context: None"}),e.jsxs(t.Button,{className:"h-6 text-xs",size:"sm",variant:"secondary",onClick:E,children:[e.jsx(t.Plus,{className:"mr-2 size-3"}),"Current Table"]})]})]})}const $=(j==null?void 0:j.length)===0&&(f==null?void 0:f.filter(B=>B.role==="user").length)===0;return e.jsxs("div",{"data-role":"editor-assistant",className:"flex h-full w-full flex-col justify-between gap-2 px-6 py-4",children:[e.jsxs("div",{"data-role":"header-section",className:"flex items-start justify-between gap-2",children:[G(),e.jsxs("div",{"data-role":"header-actions",className:"flex items-center",children:[_(),e.jsx(t.Button,{className:"h-7 p-2",size:"sm",variant:"ghost",onClick:()=>{c([]),g()},children:e.jsx(t.RefreshCcw,{className:"size-3.5 text-muted-foreground"})}),e.jsx(t.Button,{className:"h-7 p-2",size:"sm",variant:"ghost",onClick:()=>{x(!1)},children:e.jsx(t.X,{className:"size-4"})})]})]}),e.jsx(t.CustomScrollArea,{ref:s,className:"flex w-full grow basis-0",children:e.jsxs("div",{className:"space-y-4 py-2 pr-3","data-role":"messages",children:[e.jsx(t.PrintMessages,{messages:f,showTools:o,handleRun:D,showSystemMessage:i}),e.jsx(t.ChatStatus,{status:t.getStatus(H,S),isLoading:O})]})}),$&&e.jsx(t.Placeholders,{onClick:y,placeholders:pa}),e.jsx(t.ChatInput,{onFocus:()=>{E()},stop:F,ref:a,setInput:b,input:j,handleInputChange:M,handleSubmit:R,isLoading:O}),v&&n&&e.jsx("div",{className:"flex h-8 items-center justify-between",children:e.jsxs("div",{className:"text-xs text-muted-foreground",children:["Usage: ",v.promptTokens," prompt tokens,"," ",v.completionTokens," completion tokens,"," ",v.totalTokens," total tokens"]})}),A&&e.jsx("div",{className:"flex items-center justify-between text-xs text-muted-foreground",children:e.jsx("span",{children:A})})]})}function fa({authToken:s,onSave:a,onClose:n}){const r=k.useRef(null),o=t.useEditorStore(j=>j.showAIDialog),{setAuthToken:l}=t.useDashboardActions(),{setShowAIDialog:i,setOnSave:d,setOnClose:m}=t.useEditorActions(),{handleDragOver:p,handleDragEnd:u,handleDragStart:x,handleDragCancel:f,sensors:c}=sa();k.useEffect(()=>{a&&d(a),n&&m(n)},[a,d,n,m]),k.useEffect(()=>{s&&s.accessToken&&l(s)},[s,l]),k.useEffect(()=>{var j,b;o?((j=r.current)==null||j.resize(40),i(!0)):(i(!1),(b=r.current)==null||b.resize(0))},[o,i]);function g(j){j<1?i(!1):o||i(!0)}function h(){return e.jsxs(t.ResizablePanelGroup,{"data-content":"editor-main",className:"grow",direction:"horizontal",children:[e.jsx(t.ResizablePanel,{className:"min-w-[510px] rounded-none border-x-[1px]",children:e.jsx(ha,{})}),e.jsx(t.ResizableHandle,{}),e.jsx(t.ResizablePanel,{"data-role":"editor-assistant-panel",ref:r,onResize:g,defaultSize:0,children:e.jsx(xa,{})})]})}return e.jsx(t.ErrorBoundary,{FallbackComponent:t.Fallback,children:e.jsx(t.DndContext,{sensors:c,onDragStart:x,onDragEnd:u,onDragOver:p,onDragCancel:f,children:e.jsxs("section",{className:"isolate flex h-full grow","data-content":"editor-panel",children:[e.jsx(kt,{type:"main"}),h()]})})})}function ga(){t.useDashboardStore(i=>i.selectedCardId);const s=t.useDashboardStore(i=>i.selectedSheetId),{setIsVisualEditing:a}=t.useDashboardStore(i=>i.actions),n=t.useDashboardStore(i=>i.isVisualEditing),r=t.useDashboardStore(i=>i.actions.updateFrame);function o(i){s&&(r(s,i),a(!1))}function l(){a(!1)}return e.jsx("div",{role:"editor-container",className:t.cn("flex grow",{"max-h-0 overflow-hidden":!n}),children:e.jsx(fa,{onSave:o,onClose:l})})}function ja(){const s=t.useEditorStore(l=>l.selectedDatabaseName),a=t.useEditorStore(l=>l.selectedTableName),n=t.useDashboardStore(l=>l.dashboard.filters)||[],{columns:r}=se(),{assignFilter:o}=Gt();return e.jsx(t.ScrollArea,{className:"flex-1 basis-0 flex-col px-3",children:r==null?void 0:r.map(l=>{const i=n==null?void 0:n.find(d=>d.column===t.fmt(l.column_name)&&d.table===a&&d.database===s);return e.jsx("div",{onClick:()=>o(l),className:t.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":i}),children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Ue,{column:l}),e.jsx("span",{children:l.column_name})]})},l.column_name)})})}function ba(){t.useDashboardStore(a=>a.showFilters);const s=t.useDashboardStore(a=>a.actions.setShowFilters);return e.jsxs("section",{className:"relative flex min-w-[320px] grow flex-col border-l px-1",children:[e.jsxs("div",{className:"mt-4 flex items-center justify-between gap-2 px-3",children:[e.jsx(t.Label,{className:"px-2 text-lg",children:"Filters"}),e.jsx(t.Button,{onClick:()=>s(!1),className:"h-7 w-7 p-0",variant:"ghost",children:e.jsx(t.Cross2Icon,{})})]}),e.jsx("div",{className:"flex grow",children:e.jsx(kt,{type:"filter",ColumnsComponent:()=>e.jsx(ja,{})})})]})}function ya(){const s=t.useDashboardStore(r=>r.dashboard.filters),a=t.useDashboardStore(r=>r.theme),n=s==null?void 0:s.filter(r=>r.hide);return n!=null&&n.length?e.jsx("div",{className:t.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)]":a==="light","bg-[repeating-linear-gradient(45deg,_#18171d_0_3px,_#272729_3px_6px)]":a==="dark"}),children:n==null?void 0:n.map(r=>e.jsxs("div",{className:"flex min-w-[250px] max-w-fit flex-col gap-1 p-2",children:[e.jsx(t.FilterHeader,{filter:r}),e.jsx(t.FilterComponent,{filter:r})]},r.id))}):null}function Sa(){const s=t.useDashboardStore(r=>r.showFilters),a=t.useDashboardStore(r=>r.isVisualEditing),n=t.useDashboardStore(r=>r.isDashboardEditing);return e.jsxs("div",{role:"dashboard-plus-main",className:t.cn("",{"max-h-0 overflow-hidden":a,"flex grow overflow-auto":!a}),children:[e.jsxs("section",{className:"flex grow flex-col",children:[n&&e.jsx(ya,{}),e.jsx(t.DashboardTabs,{})]}),s&&e.jsx("div",{role:"filter-aside-container",className:"flex",children:e.jsx(ba,{})})]})}function Ca(){const s=t.useDashboardStore(o=>o.dashboard),a=t.useDashboardStore(o=>o.actions.setDashboard),n=t.useDashboardStore(o=>o.showDashboardJSON),r=t.useDashboardStore(o=>o.actions.setShowDashboardJSON);return e.jsxs("div",{className:t.cn("relative p-2",{hidden:!n}),children:[e.jsxs(t.Button,{variant:"secondary",size:"sm",className:"absolute right-2 top-2 z-10 h-8",onClick:()=>r(!1),children:[e.jsx(t.X,{className:"mr-2 h-4 w-4"}),"Close"]}),e.jsx(t.de,{onChange:o=>{if(o)try{JSON.parse(o),a(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 va({showControls:s=!1,showFooter:a=!0,...n}){return e.jsx(t.ErrorBoundary,{FallbackComponent:t.Fallback,children:e.jsxs(t.SemaphorContextProvider,{dashboardProps:n,children:[e.jsx(t.$e,{}),e.jsxs(t.UXProvider,{children:[e.jsx(Ca,{}),e.jsxs(t.DashboardPanel,{...n,children:[s&&e.jsx(Ks,{}),e.jsx(ga,{}),e.jsx(Sa,{})]})]})]})})}exports.Dashboard=t.Dashboard;exports.DashboardWC=t.DashboardWC;exports.SemaphorDataProvider=t.SemaphorQueryClient;exports.SemaphorQueryClient=t.SemaphorQueryClient;exports.createSqlGenConfig=t.createSqlGenConfig;exports.fmt=t.fmt;exports.getColumnDataType=t.getColumnDataType;exports.getFilterValueType=t.getFilterValueType;exports.getFormattedTableNameForQuery=t.getFormattedTableNameForQuery;exports.getQualifiedTableName=t.getQualifiedTableName;exports.getSql=t.getSql;exports.invalidateToken=t.invalidateToken;exports.isBooleanDataType=t.isBooleanDataType;exports.isColumnInSqlGen=t.isColumnInSqlGen;exports.isDateDataType=t.isDateDataType;exports.isNumberDataType=t.isNumberDataType;exports.isTextDataType=t.isTextDataType;exports.resolveDataType=t.resolveDataType;exports.resolveDatamodelName=t.resolveDatamodelName;exports.useCard=t.useCard;exports.useDashboardActions=t.useDashboardActions;exports.useDashboardStore=t.useDashboardStore;exports.useDateFilterHook=t.useDateFilterHook;exports.useEditorActions=t.useEditorActions;exports.useEditorStore=t.useEditorStore;exports.useTextFilterHook=t.useTextFilterHook;exports.ScheduleDashboard=vt;exports.SelectComponent=le;exports.Surfboard=va;exports.cleanCard=yt;exports.downloadPdf=Ct;exports.getDashbaordStateWithoutData=Ge;exports.useEditorAside=se;
|
|
352
|
+
`),N=new Blob([C],{type:"text/csv"}),T=URL.createObjectURL(N),L=document.createElement("a");L.href=T,L.download=`${a.title}.csv`,L.click()}function $(){const I=`Can you get the documentation for ${a.type} chart?`;c(I)}return e.jsxs("div",{className:"relative isolate flex h-full flex-col py-3",children:[(j||b)&&e.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.jsx(re,{className:"h-8 w-8 animate-spin text-muted-foreground"})}),e.jsxs("div",{className:"z-10 mb-0 flex min-h-10 items-center justify-end gap-2 px-6",children:[r&&e.jsxs("div",{className:"flex grow items-center",children:[e.jsx(wn,{}),o&&e.jsx(t.IconButton,{tooltip:"Visual Docs",onClick:$,children:e.jsx(as,{className:"size-4"})}),!["table","custom"].includes(a.type)&&o&&e.jsx(Sn,{})]}),!r&&e.jsxs("div",{className:"flex grow items-center gap-1",children:[e.jsx(t.Button,{className:"h-7 w-fit px-1 font-mono text-xs text-muted-foreground/70",variant:"ghost",size:"icon",onClick:G,children:e.jsx(Cn,{className:"size-4"})}),e.jsx(t.Button,{className:"h-7 w-fit px-1 font-mono text-xs text-muted-foreground/70",variant:"ghost",size:"icon",onClick:_,children:e.jsx(gs,{strokeWidth:1.5,className:"size-4"})}),e.jsx(t.CopyButton,{text:JSON.stringify(h==null?void 0:h.records,null,2),className:"h-7 w-fit px-1 font-mono text-xs text-muted-foreground/70"})]}),e.jsx(Tn,{}),e.jsx(Mn,{})]}),r?D():e.jsxs(t.ResizablePanelGroup,{className:"px-6",direction:"horizontal",children:[i&&e.jsxs(e.Fragment,{children:[e.jsx(t.ResizablePanel,{id:"1",order:1,defaultSize:30,minSize:10,className:"relative flex h-full min-h-0 w-full flex-1 basis-0",children:i&&e.jsx(An,{})}),e.jsx(t.ResizableHandle,{})]}),e.jsxs(t.ResizablePanel,{id:"2",order:2,minSize:10,className:"relative flex h-full min-h-0 w-full flex-1 basis-0",children:[(h==null?void 0:h.records)&&(h==null?void 0:h.records.length)>0&&e.jsx(fn,{data:(h==null?void 0:h.records)||[]}),(O||(h==null?void 0:h.error))&&e.jsx("span",{className:"font-mono text-xs",children:(O==null?void 0:O.message)||((B=h==null?void 0:h.error)==null?void 0:B.message)})]})]})]})}function An(){const s=t.useEditorStore(n=>n.pythonStdOut);if(!s)return null;const a=s.replace(/\n/g,"<br>");return e.jsxs("div",{className:"relative flex w-full flex-col border-r",children:[e.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.jsxs(t.ScrollArea,{className:"overflow-y-auto px-2 pt-1 font-mono text-xs text-foreground/90",children:[e.jsx("div",{dangerouslySetInnerHTML:{__html:a}}),e.jsx(t.ScrollBar,{orientation:"horizontal"})]})]})}function Mn(){const s=t.useEditorStore(n=>n.isShowingVisual),a=t.useEditorStore(n=>n.actions.setIsShowingVisual);return e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(t.Label,{htmlFor:"visualize",children:"Chart"}),e.jsx(t.SmallSwitch,{checked:s,onCheckedChange:()=>a(!s),id:"visualize",className:"data-[state=checked]:bg-foreground/50"})]})}function Ln(){var h,j;const s=t.useEditorStore(b=>b.card.customCardPreferences),{data:a}=Bt(),n=(a==null?void 0:a.plugins)||[],r=t.useEditorStore(b=>b.card),o=t.useEditorStore(b=>b.frame),l=(s==null?void 0:s.visualType)||"single",{setCustomCardPreferences:i}=t.useEditorActions(),{components:d,manifest:m}=t.useCustomVisual((s==null?void 0:s.url)||""),p=(h=m==null?void 0:m.visuals)==null?void 0:h.find(b=>b.name===(s==null?void 0:s.componentName));function u(b,O){if(!s)return;const z={...(s==null?void 0:s.dataInputCardIds)||{},[b]:{cardId:O,hookRef:null}};i({...s,dataInputCardIds:z})}function x(b){var E,z;const O=(E=o==null?void 0:o.cards)==null?void 0:E.filter(w=>{var M;return((M=w==null?void 0:w.customCardPreferences)==null?void 0:M.visualType)!=="multiple"}).map(w=>({value:w.id,label:w.tabTitle||w.title}));return e.jsx("div",{className:"space-y-2",children:(z=b==null?void 0:b.dataInputs)==null?void 0:z.map((w,M)=>{var R,F;return e.jsxs("div",{className:"grid grid-cols-10 gap-2",children:[e.jsx("div",{className:"col-span-4 flex items-center",children:w}),e.jsx(X,{className:"col-span-6 h-8 w-full justify-between",label:"",options:O||[],value:((F=(R=s==null?void 0:s.dataInputCardIds)==null?void 0:R[M])==null?void 0:F.cardId)||"",onValueChange:H=>u(M,H)})]},M+Math.random())})})}function f(b,O,E=[],z=""){var w,M;return s?b==="input"?e.jsx(t.Input,{className:`h-8 w-full ${t.removeRing}`,value:((w=s==null?void 0:s.settings)==null?void 0:w[O])||z,onChange:R=>{i({...s,settings:{...s==null?void 0:s.settings,[O]:R.target.value}})}},O):b==="select"?e.jsx(X,{className:"h-8 w-full",label:"",options:E,value:((M=s==null?void 0:s.settings)==null?void 0:M[O])||z,onValueChange:R=>{i({...s,settings:{...s==null?void 0:s.settings,[O]:R}})}}):null:null}function c(b){const O=Object.entries((b==null?void 0:b.settings)||{});return e.jsx("div",{className:"space-y-3",children:O.map(([E,z])=>e.jsxs("div",{className:"space-y-1",children:[e.jsx(t.Label,{children:z.title}),f(z.ui,E,z.options,z.defaultValue)]},E))})}function g(b){s&&i({...s,visualType:b,componentName:""})}return e.jsxs(t.Accordion,{type:"multiple",defaultValue:["component-settings"],className:"px-6 py-2",children:[e.jsxs(t.AccordionItem,{value:"plugin-settings",children:[e.jsx(t.AccordionTrigger,{children:"Plugin"}),e.jsx(t.AccordionContent,{children:e.jsxs("div",{className:"space-y-4 text-sm",children:[e.jsx("div",{className:"space-y-2",children:e.jsxs("div",{className:"space-y-4",children:[e.jsx(X,{icon:e.jsx(ns,{className:"h-3.5 w-3.5"}),className:"h-9 w-full",label:"Select Plugin",options:n,value:(s==null?void 0:s.url)||"",onValueChange:b=>i({...s||{url:"",componentName:""},url:b})}),((s==null?void 0:s.type)==="component"||(s==null?void 0:s.type)===void 0)&&e.jsx(t.Tabs,{value:l,onValueChange:g,children:e.jsxs(t.TabsList,{className:"h-9 w-full",children:[e.jsx(t.TabsTrigger,{className:"h-7 w-full",value:"single",children:"Single Visual"}),e.jsx(t.TabsTrigger,{className:"h-7 w-full",value:"multiple",children:"Multi-Visual"})]})})]})}),((s==null?void 0:s.type)==="component"||(s==null?void 0:s.type)===void 0)&&s&&e.jsx(e.Fragment,{children:d&&e.jsx(X,{icon:e.jsx(ms,{className:"h-3.5 w-3.5"}),className:"h-9 w-full",label:"Select Component",options:(d==null?void 0:d.filter(b=>b.type===l).map(b=>({value:b.name,label:b.name})))||[],value:s.componentName,onValueChange:b=>{console.log("changing value",b),i({...s,componentName:b})}})})]})})]}),((j=r==null?void 0:r.customCardPreferences)==null?void 0:j.componentName)&&e.jsxs(t.AccordionItem,{className:"border-none",value:"component-settings",children:[e.jsx(t.AccordionTrigger,{children:"Settings"}),e.jsxs(t.AccordionContent,{children:[p&&p.dataInputs&&e.jsxs("div",{className:"space-y-3",children:[e.jsx(t.Label,{children:"Input Mapping"}),e.jsx("div",{className:"px-2",children:x(p)})]}),p&&p.settings&&e.jsx("div",{className:"space-y-3",children:e.jsx("div",{className:"px-2",children:c(p)})})]})]})]})}function oe(){const[s,a]=k.useState([]),n=t.useEditorStore(p=>p.card.preferences),{setFilterOnClickColumnIndex:r,setCardPreferences:o}=t.useEditorStore(p=>p.actions),l=t.useEditorStore(p=>p.queryResultColumns);t.useEditorStore(p=>{var u;return(u=p.card.preferences)==null?void 0:u.filterOnClickColumnIndex}),k.useEffect(()=>{l&&a(new Array(l.length).fill(!1))},[l]);function i(p,u){var x,f;u?n!=null&&n.onClickFilter&&((x=n==null?void 0:n.onClickFilter)==null?void 0:x.length)>0?o({...n,onClickFilter:[...n.onClickFilter,{columnIndex:p,expression:""}]}):o({...n,onClickFilter:[{columnIndex:p,expression:""}]}):(o({...n,onClickFilter:(f=n==null?void 0:n.onClickFilter)==null?void 0:f.filter(c=>c.columnIndex!==p)}),a(c=>{const g=[...c];return g[p]=!1,g}))}function d(p,u){var f;const x=(f=n==null?void 0:n.onClickFilter)==null?void 0:f.map(c=>c.columnIndex===p?{...c,expression:u.target.value}:c);o({...n,onClickFilter:x})}function m(p){var u,x,f,c;if(s!=null&&s[p]||(x=(u=n==null?void 0:n.onClickFilter)==null?void 0:u.find(g=>g.columnIndex===p))!=null&&x.expression)return e.jsx(t.Input,{value:(c=(f=n==null?void 0:n.onClickFilter)==null?void 0:f.find(g=>g.columnIndex===p))==null?void 0:c.expression,onChange:g=>d(p,g),type:"text",className:"h-9 w-full font-mono text-xs focus-visible:ring-0 focus-visible:ring-ring focus-visible:ring-offset-0",placeholder:"Expression"})}return e.jsxs("div",{className:"space-y-2",children:[e.jsx(t.Label,{children:"On Click"}),l==null?void 0:l.map((p,u)=>{var x,f;return e.jsx("div",{className:"xbg-red-100 group flex items-center justify-between space-y-2",children:e.jsxs("div",{className:"grow",children:[e.jsxs("div",{className:"flex items-center space-x-2 py-2",children:[e.jsx(t.Checkbox,{checked:!!((x=n==null?void 0:n.onClickFilter)!=null&&x.find(c=>c.columnIndex===u)),onCheckedChange:c=>i(u,c)}),e.jsx("label",{className:"text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70",children:p}),e.jsx("div",{className:"flex items-center gap-2",children:((f=n==null?void 0:n.onClickFilter)==null?void 0:f.find(c=>c.columnIndex===u))&&e.jsx(t.Pencil,{onClick:()=>{a(c=>{const g=[...c];return g[u]=!c[u],g})},className:"invisible size-3 cursor-pointer text-gray-400 group-hover:visible"})})]}),m(u)]})},p)})]})}function On({idx:s}){var d;const a=t.useEditorStore(m=>{var p;return(p=m.card)==null?void 0:p.preferences}),n=t.useEditorStore(m=>{var p;return(p=m.card.preferences)==null?void 0:p.datasetOptions}),r=t.useEditorStore(m=>m.actions.setCardPreferences),o=(d=a==null?void 0:a.chartOptions)==null?void 0:d.indexAxis,l=n==null?void 0:n.find(m=>m.idx===s);function i(m,p){(m==="end"||m==="start")&&t.getContrastColor(t.getCanvasBackgroundColor());const u={display:m!=="none",align:m,anchor:m,clamp:!0};if(!l)r({...a,datasetOptions:[...n||[],{idx:p,datalabels:u}]});else{const x={...l};x.datalabels=u;const f=n==null?void 0:n.map(c=>c.idx===p?x:c);r({...a,datasetOptions:f})}}return e.jsxs(t.Popover,{children:[e.jsx(t.PopoverTrigger,{children:e.jsx(Vs,{className:"invisible size-4 rotate-[135deg] cursor-pointer text-muted-foreground hover:text-foreground group-hover:visible"})}),e.jsx(t.PopoverContent,{className:"w-fit p-1",children:e.jsxs("div",{className:"flex gap-1",children:[e.jsx(t.Button,{onClick:()=>i("none",s),size:"sm",variant:"secondary",className:"h-7 p-1 text-xs font-normal",children:e.jsx(t.X,{className:"size-4"})}),e.jsx(t.Button,{onClick:()=>i("start",s),size:"sm",variant:"secondary",className:"h-7 p-1 text-xs font-normal",children:e.jsx(Ns,{className:t.cn("h-4 w-4",{"rotate-90":o==="y"})})}),e.jsx(t.Button,{onClick:()=>i("center",s),size:"sm",variant:"secondary",className:"h-7 p-1 text-xs font-normal",children:e.jsx(ks,{className:t.cn("h-4 w-4",{"rotate-90":o==="y"})})}),e.jsx(t.Button,{onClick:()=>i("end",s),size:"sm",variant:"secondary",className:"h-7 p-1 text-xs font-normal",children:e.jsx(ws,{className:t.cn("h-4 w-4",{"rotate-90":o==="y"})})})]})})]})}function Pt(){const s=t.useEditorStore(p=>p.card),a=t.useEditorStore(p=>{var u,x,f;return(f=(x=(u=p==null?void 0:p.card)==null?void 0:u.preferences)==null?void 0:x.chartOptions)==null?void 0:f.indexAxis}),{data:n}=t.useDashboardCardQuery(s),r=a==="y"?"Metric":"Dimension",o=a==="y"?"Dimension":"Metric",{keys:l,metricKeys:i,dimensionKeys:d}=t.getKeys((n==null?void 0:n.records)||[]);let m=i;if(["stackedBar","stackedLine"].includes(s.type)){const p=t.pivotData({dataArray:(n==null?void 0:n.records)||[],groupKey:d[0],pivotKey:d[1],valueKey:m[0]}),{metricKeys:u}=t.getKeys(p);m=u}return l.length===0?null:e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(t.Label,{children:r}),e.jsx("div",{className:"max-h-[125px] space-y-1 overflow-y-auto",children:d.map(p=>e.jsx("p",{className:"rounded-md bg-muted/70 px-3 py-2 hover:bg-muted",title:p,children:Ht(p)},p))})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(t.Label,{children:o}),e.jsx("div",{className:"my-1 max-h-[125px] space-y-1 overflow-y-auto",children:m.map((p,u)=>e.jsx(zn,{col:p,idx:u},p))})]})]})}function Ht(s,a=30){return s.length>a?s.slice(0,a)+"...":s}function zn({col:s,idx:a}){const n=t.useEditorStore(d=>{var m;return(m=d.card)==null?void 0:m.preferences}),r=t.useEditorStore(d=>{var m;return(m=d.card.preferences)==null?void 0:m.datasetOptions}),o=r==null?void 0:r.find(d=>d.idx===a),{setCardPreferences:l}=t.useEditorStore(d=>d.actions);function i(d){if(!o)l({...n,datasetOptions:[...r||[],{idx:a,type:d==="area"?"line":d,fill:d==="area"?"origin":""}]});else{const m={...o};m.type=d==="area"?"line":d,m.fill=d==="area"?"origin":"";const p=r==null?void 0:r.map(u=>u.idx===a?m:u);l({...n,datasetOptions:p})}}return e.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.jsx("p",{title:s,children:Ht(s)}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(Be,{onClick:()=>i("bar"),className:"invisible size-4 cursor-pointer text-muted-foreground hover:text-foreground group-hover:visible"}),e.jsx(Pe,{onClick:()=>i("line"),className:"invisible size-4 cursor-pointer text-muted-foreground hover:text-foreground group-hover:visible"}),e.jsx(ls,{onClick:()=>i("area"),className:"invisible size-4 cursor-pointer text-muted-foreground hover:text-foreground group-hover:visible"}),e.jsx(On,{idx:a})]})]})}function Gt(){const s=t.useEditorStore(c=>c.selectedConnectionId),a=t.useEditorStore(c=>c.selectedDatamodelId),n=t.useEditorStore(c=>c.selectedDatabaseName),r=t.useEditorStore(c=>c.selectedSchemaName),o=t.useEditorStore(c=>c.selectedTableName),l=t.useDashboardStore(c=>c.dashboard.filters)||[],i=t.useDashboardStore(c=>c.actions.addFilter),d=t.useDashboardStore(c=>c.actions.removeFilter),{removeFilterValues:m}=t.useDashboardActions(),{modelItems:p,tableName:u,connectionType:x}=se();function f(c,g="dashboard"){var R;const h=t.fmt(c.column_name),j=t.fmt(n||""),b=t.fmt(r||""),O=t.fmt(u);let E=t.getQualifiedTableName({schemaName:b,tableName:O,connectionType:x,databaseName:j}),z=`${E}.${h}`;const w=(R=p==null?void 0:p.find(F=>F.id===a))==null?void 0:R.name;a&&a!=="none"&&(z=`${t.DATAMODEL_NAMESPCACE}.${w}.${h}`,E=`${t.DATAMODEL_NAMESPCACE}.${w}`);const M=l==null?void 0:l.find(F=>F.column===z&&F.table===O&&(F.database===j||F.database===n));if(M)m(M.id),d(M.id);else{const F=t.v4();return u==="api"&&s?(i({location:g,id:F,column:z,title:c.column_name,dataType:c.data_type,table:"api",database:"",connectionId:s,operation:"in",sql:t.getDefaultFilterSql(c.data_type,E,h)}),F):(i({id:F,location:g,column:z,title:c.column_name,dataType:c.data_type,table:o||"",database:n||"",connectionId:s||"",operation:"in",sql:t.getDefaultFilterSql(c.data_type,E,h)}),F)}}return{assignFilter:f}}function me(){const s=t.useDashboardStore(d=>d.dashboard.filters),a=t.useEditorStore(d=>d.frame),{setFrame:n}=t.useEditorActions(),{columns:r}=se(),{assignFilter:o}=Gt();function l(d){const m=o(d,"frame");n({...a,filterId:m})}const i=s==null?void 0:s.find(d=>d.id===a.filterId);return e.jsxs("div",{className:"space-y-3",children:[e.jsx(t.Label,{children:"Card Filter"}),e.jsx(Fn,{onSelect:l,columns:r}),i&&e.jsx(t.FilterHeader,{filter:i})]})}function Fn({columns:s,onSelect:a}){var i;const[n,r]=de.useState(!1),[o,l]=de.useState("");return e.jsxs(t.Popover,{open:n,onOpenChange:r,children:[e.jsx(t.PopoverTrigger,{asChild:!0,children:e.jsxs(t.Button,{size:"sm",variant:"outline",role:"combobox","aria-expanded":n,className:"w-full justify-between font-normal",children:[o?(i=s.find(d=>d.column_name===o))==null?void 0:i.column_name:"Select Column...",e.jsx(t.CaretSortIcon,{className:"ml-2 h-4 w-4 shrink-0 opacity-50"})]})}),e.jsx(t.PopoverContent,{className:"w-[200px] p-0",children:e.jsxs(t.Command,{children:[e.jsx(t.CommandInput,{placeholder:"Search column",className:"h-9"}),e.jsxs(t.CommandList,{children:[e.jsx(t.CommandEmpty,{children:"No framework found."}),e.jsx(t.CommandGroup,{children:s==null?void 0:s.map(d=>e.jsxs(t.CommandItem,{value:d.column_name,onSelect:m=>{const p=m===o?"":m;l(p),r(!1),p&&a(d)},children:[d.column_name,e.jsx(t.CheckIcon,{className:t.cn("ml-auto h-4 w-4",o===d.column_name?"opacity-100":"opacity-0")})]},d.column_name))})]})]})})]})}function Rn({cardType:s}){return e.jsx("div",{className:"space-y-6 px-6 py-2",children:e.jsxs(t.Accordion,{defaultValue:["item-2"],type:"multiple",children:[e.jsxs(t.AccordionItem,{value:"item-1",children:[e.jsx(t.AccordionTrigger,{children:`${t.titleCase(s)} Chart`}),e.jsxs(t.AccordionContent,{className:"space-y-4 font-mono text-xs",children:[e.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.jsxs("ul",{className:"ml-6 list-disc text-xs [&>li]:mt-2",children:[e.jsx("li",{children:"x-axis - category"}),e.jsx("li",{children:"y-axis1 - number"}),e.jsx("li",{children:"y-axis2 - number"})]}),e.jsxs("div",{children:["See ",e.jsx("a",{target:"_blank",onClick:a=>a.stopPropagation(),className:"text-blue-700",href:"https://docs.semaphor.cloud/docs/charts/bar-line-area",children:"example"})," in the docs."]})]})]}),e.jsxs(t.AccordionItem,{value:"item-2",children:[e.jsx(t.AccordionTrigger,{children:"Settings"}),e.jsx(t.AccordionContent,{className:"space-y-4 px-2",children:e.jsx(Pt,{})})]}),e.jsxs(t.AccordionItem,{value:"item-3",children:[e.jsx(t.AccordionTrigger,{children:"Filters"}),e.jsxs(t.AccordionContent,{className:"space-y-4 px-2",children:[e.jsx(oe,{}),e.jsx(me,{})]})]})]})})}function $e(){var o,l,i;const s=t.useEditorStore(d=>d.card.type),a=t.useEditorStore(d=>d.card.preferences),{setCardPreferences:n}=t.useEditorStore(d=>d.actions);function r(d){var u;const m={datalabels:{display:d!=="none",align:d,anchor:d,clamp:!0}},p={...a,chartOptions:{...a==null?void 0:a.chartOptions,plugins:{...(u=a==null?void 0:a.chartOptions)==null?void 0:u.plugins,...m}}};n(p),console.log(d)}return e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"font-medium",children:"Data Labels"}),e.jsxs(t.Select,{value:((i=(l=(o=a==null?void 0:a.chartOptions)==null?void 0:o.plugins)==null?void 0:l.datalabels)==null?void 0:i.anchor)||"none",onValueChange:r,defaultValue:"none",children:[e.jsx(t.SelectTrigger,{className:"h-8 w-full focus:ring-1 focus:ring-offset-0",children:e.jsx(t.SelectValue,{placeholder:"Select position"})}),e.jsx(t.SelectContent,{children:e.jsxs(t.SelectGroup,{children:[e.jsx(t.SelectLabel,{children:"Data Labels"}),e.jsx(t.SelectItem,{value:"none",children:"None"}),s!=="pyramid"&&e.jsx(t.SelectItem,{value:"start",children:"Start"}),e.jsx(t.SelectItem,{value:"center",children:"Center"}),s!=="pyramid"&&e.jsx(t.SelectItem,{value:"end",children:"End"})]})})]})]})}function _n({cardType:s}){function a(n){return e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"rounded bg-muted px-2 py-1 text-xs",children:n==="bubble"?"SELECT label, [group], x-axis, y-axis, radius FROM table":"SELECT label, [group], x-axis, y-axis FROM table"}),e.jsxs("ul",{className:"ml-6 list-disc text-xs [&>li]:mt-2",children:[e.jsx("li",{children:"label - category"}),e.jsx("li",{children:"group (optional) - category"}),e.jsx("li",{children:"x-axis - number"}),e.jsx("li",{children:"y-axis - number"}),n==="bubble"&&e.jsx("li",{children:"radius - number"})]}),e.jsxs("div",{children:["See ",e.jsx("a",{target:"_blank",onClick:l=>l.stopPropagation(),className:"text-blue-700",href:"https://docs.semaphor.cloud/docs/charts/bubble",children:"example"})," in the docs."]})]})}return e.jsx("div",{className:"space-y-6 px-6 py-2",children:e.jsxs(t.Accordion,{defaultValue:["item-2"],type:"multiple",children:[e.jsxs(t.AccordionItem,{value:"item-1",children:[e.jsx(t.AccordionTrigger,{children:`${t.titleCase(s)} Chart`}),e.jsx(t.AccordionContent,{className:"space-y-4 font-mono text-xs",children:a(s)})]}),e.jsxs(t.AccordionItem,{value:"item-2",children:[e.jsx(t.AccordionTrigger,{children:"Settings"}),e.jsx(t.AccordionContent,{className:"px-2",children:e.jsx($e,{})})]}),e.jsxs(t.AccordionItem,{value:"item-3",children:[e.jsx(t.AccordionTrigger,{children:"Filters"}),e.jsxs(t.AccordionContent,{className:"space-y-4 px-2",children:[e.jsx(oe,{}),e.jsx(me,{})]})]})]})})}const Vn={datasets:[{type:"line",label:"Sum_sales",data:[]},{type:"bar",label:"Sum_profit",data:[]}]},qn={datasets:[{fill:"origin",type:"line",label:"Sum_sales",data:[]}]};function Bn(){const s=t.useEditorStore(a=>a.card.type);return e.jsxs("div",{className:"space-y-6 p-6",children:[e.jsx(t.Accordion,{className:" ",type:"single",collapsible:!0,children:Pn(s)}),!["kpi"].includes(s)&&e.jsxs("div",{className:"space-y-4",children:[e.jsx($e,{}),e.jsx(oe,{}),e.jsx(me,{})]})]})}function Pn(s){if(["line","bar"].includes(s))return e.jsxs(e.Fragment,{children:[e.jsxs(t.AccordionItem,{value:"item-1",children:[e.jsx(t.AccordionTrigger,{className:"font-normal",children:e.jsx("p",{children:"Chart Query"})}),e.jsxs(t.AccordionContent,{className:" ",children:[e.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.jsxs("ul",{className:"my-6 ml-6 list-disc text-xs font-normal [&>li]:mt-2",children:[e.jsx("li",{children:"X-axis - Category (ex. city)"}),e.jsx("li",{children:"Y-axis - Number (ex. population)"})]})]})]}),e.jsxs(t.AccordionItem,{value:"item-2",children:[e.jsx(t.AccordionTrigger,{className:"font-normal",children:"Mixed Chart"}),e.jsxs(t.AccordionContent,{className:"space-y-2 text-xs",children:[e.jsxs("p",{children:["Click ",e.jsx("b",{children:"Customize"})," and change the `type` property in the dataset."]}),e.jsx("pre",{children:JSON.stringify(Vn,null,2)})]})]}),e.jsxs(t.AccordionItem,{value:"item-3",children:[e.jsx(t.AccordionTrigger,{className:"font-normal",children:"Area Chart"}),e.jsxs(t.AccordionContent,{className:"space-y-2 text-xs",children:[e.jsxs("p",{children:["Click ",e.jsx("b",{children:"Customize"})," and add `fill` property to the dataset. See",e.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.jsx("pre",{children:JSON.stringify(qn,null,2)})]})]})]});if(s==="bubble")return e.jsx(e.Fragment,{children:e.jsxs(t.AccordionItem,{value:"item-1",children:[e.jsx(t.AccordionTrigger,{className:"font-normal",children:e.jsxs("p",{children:["How to create a ",e.jsx("span",{children:s})," chart query?"]})}),e.jsxs(t.AccordionContent,{className:" ",children:[e.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.jsxs("ul",{className:"my-6 ml-6 list-disc text-xs font-normal [&>li]:mt-2",children:[e.jsx("li",{children:"Label - Category (ex. city)"}),e.jsx("li",{children:"Bubble Group (opt) - Category (ex. state)"}),e.jsx("li",{children:"X-axis - Number (ex. avg. age)"}),e.jsx("li",{children:"Y-axis - Number (ex. avg. weight)"}),e.jsx("li",{children:"Radius - Number (ex. population)"})]})]})]})});if(s==="scatter")return e.jsx(e.Fragment,{children:e.jsxs(t.AccordionItem,{value:"item-1",children:[e.jsx(t.AccordionTrigger,{className:"font-normal",children:e.jsxs("p",{children:["How to create a ",e.jsx("span",{children:s})," chart query?"]})}),e.jsxs(t.AccordionContent,{className:" ",children:[e.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.jsxs("ul",{className:"my-6 ml-6 list-disc text-xs font-normal [&>li]:mt-2",children:[e.jsx("li",{children:"Label - Category (ex. city)"}),e.jsx("li",{children:"Group (opt) - Category (ex. state)"}),e.jsx("li",{children:"X-axis - Number (ex. avg. age)"}),e.jsx("li",{children:"Y-axis - Number (ex. avg. weight)"})]})]})]})});if(["pie","doughnut","polarArea"].includes(s))return e.jsx(e.Fragment,{children:e.jsxs(t.AccordionItem,{value:"item-1",children:[e.jsx(t.AccordionTrigger,{className:"font-normal",children:e.jsxs("p",{children:[e.jsx("span",{children:s==="polarArea"?"Polar":s.charAt(0).toUpperCase()+s.slice(1)})," ","chart query"]})}),e.jsxs(t.AccordionContent,{className:" ",children:[e.jsx("div",{className:"rounded bg-muted px-2 py-1 font-mono text-xs font-semibold",children:"SELECT label, measure FROM table"}),e.jsxs("ul",{className:"my-6 ml-6 list-disc text-xs font-normal [&>li]:mt-2",children:[e.jsx("li",{children:"Label - Category (ex. city)"}),e.jsx("li",{children:"Measure - Number (ex. population)"})]})]})]})})}function Hn(){var m,p,u,x,f;const s=t.useEditorStore(c=>c.card.preferences),a=t.useEditorStore(c=>c.actions.setCardPreferences),n=t.useEditorStore(c=>c.actions.setNumberFormat);t.useEditorStore(c=>{var g,h;return(h=(g=c.card.preferences)==null?void 0:g.formatNumber)==null?void 0:h.decimalPlaces});const r=t.useEditorStore(c=>{var g,h;return(h=(g=c.card.preferences)==null?void 0:g.formatNumber)==null?void 0:h.locale}),o=t.useEditorStore(c=>{var g,h;return(h=(g=c.card.preferences)==null?void 0:g.formatNumber)==null?void 0:h.currency});t.useEditorStore(c=>c.actions.setFilterOnClickField);const l=t.useEditorStore(c=>{var g,h;return(h=(g=c.card.preferences)==null?void 0:g.formatNumber)==null?void 0:h.colorRanges})||[],i=t.useEditorStore(c=>c.actions.setColorRanges),d=[...new Set(t.LOCALE_CURRENCY_PAIRS.map(c=>c.currency))];return e.jsxs("div",{children:[e.jsxs("div",{className:"mb-3 flex items-center gap-2",children:[e.jsx(t.Checkbox,{checked:!!((m=s==null?void 0:s.formatNumber)!=null&&m.enabled),onCheckedChange:c=>{a({...s,formatNumber:{...s==null?void 0:s.formatNumber,enabled:c}})}}),e.jsx(t.Label,{children:"Format Number"})]}),((p=s==null?void 0:s.formatNumber)==null?void 0:p.enabled)===!0&&e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsx("div",{children:e.jsxs("div",{className:"space-y-4 p-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("div",{className:"w-full space-y-1",children:[e.jsx(t.Label,{children:"Locale"}),e.jsxs(t.Select,{value:r||"none",onValueChange:c=>{var g,h,j;return n(((g=s==null?void 0:s.formatNumber)==null?void 0:g.decimalPlaces)||0,((h=s==null?void 0:s.formatNumber)==null?void 0:h.currency)||"",c,((j=s==null?void 0:s.formatNumber)==null?void 0:j.suffix)||"")},children:[e.jsx(t.SelectTrigger,{className:"col-span-6 h-8 w-full focus:ring-1 focus:ring-offset-0",children:e.jsx(t.SelectValue,{})}),e.jsx(t.SelectContent,{children:e.jsxs(t.SelectGroup,{children:[e.jsx(t.SelectLabel,{children:"Format"}),e.jsx(t.SelectItem,{value:"none",children:"None"},"none"),t.LOCALE_CURRENCY_PAIRS.map(c=>e.jsx(t.SelectItem,{value:c.locale,children:c.locale},c.locale))]})})]})]}),e.jsxs("div",{className:"w-full space-y-1",children:[e.jsx(t.Label,{children:"Currency"}),e.jsxs(t.Select,{value:o||"none",onValueChange:c=>{var g,h,j;console.log("currency",c),n(((g=s==null?void 0:s.formatNumber)==null?void 0:g.decimalPlaces)||0,c==="none"?"":c,((h=s==null?void 0:s.formatNumber)==null?void 0:h.locale)||"",((j=s==null?void 0:s.formatNumber)==null?void 0:j.suffix)||"")},children:[e.jsx(t.SelectTrigger,{className:"col-span-6 h-8 w-full focus:ring-1 focus:ring-offset-0",children:e.jsx(t.SelectValue,{})}),e.jsx(t.SelectContent,{children:e.jsxs(t.SelectGroup,{children:[e.jsx(t.SelectLabel,{children:"Currency"}),e.jsx(t.SelectItem,{value:"none",children:"None"},"none"),d.map(c=>e.jsx(t.SelectItem,{value:c,children:c},c))]})})]})]})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs("div",{className:"w-full space-y-1",children:[e.jsx(t.Label,{children:"Decimals"}),e.jsxs(t.Select,{value:((x=(u=s==null?void 0:s.formatNumber)==null?void 0:u.decimalPlaces)==null?void 0:x.toString())||"0",onValueChange:c=>{var g,h,j;return n(Number(c),((g=s==null?void 0:s.formatNumber)==null?void 0:g.currency)||"",((h=s==null?void 0:s.formatNumber)==null?void 0:h.locale)||"",((j=s==null?void 0:s.formatNumber)==null?void 0:j.suffix)||"")},children:[e.jsx(t.SelectTrigger,{className:"col-span-3 h-8 w-full focus:ring-1 focus:ring-offset-0",children:e.jsx(t.SelectValue,{})}),e.jsx(t.SelectContent,{children:["0","1","2","3","4"].map(c=>e.jsx(t.SelectItem,{value:c,children:c},c))})]})]}),e.jsxs("div",{className:"w-full space-y-1",children:[e.jsx(t.Label,{children:"Suffix"}),e.jsx(t.Input,{value:((f=s==null?void 0:s.formatNumber)==null?void 0:f.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 g,h,j;return n(((g=s==null?void 0:s.formatNumber)==null?void 0:g.decimalPlaces)||0,((h=s==null?void 0:s.formatNumber)==null?void 0:h.currency)||"",((j=s==null?void 0:s.formatNumber)==null?void 0:j.locale)||"",c.target.value)}})]})]})]})}),e.jsx(t.Separator,{className:"my-3"}),e.jsx(t.ColorFormat,{colorRanges:l,setColorRanges:i})]})]})}function Gn(){return e.jsxs("div",{className:"space-y-6 px-6 py-2",children:[e.jsx(t.Accordion,{type:"single",collapsible:!0,children:e.jsxs(t.AccordionItem,{value:"item-1",children:[e.jsx(t.AccordionTrigger,{className:"",children:"KPI Query"}),e.jsxs(t.AccordionContent,{className:"font-mono",children:[e.jsx("div",{className:"rounded bg-muted px-2 py-1 font-mono text-xs",children:"SELECT current, previous FROM table"}),e.jsxs("ul",{className:"my-6 ml-6 list-disc text-xs [&>li]:mt-2",children:[e.jsx("li",{children:"current - number"}),e.jsx("li",{children:"previous - number"})]}),e.jsxs("div",{children:["See ",e.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.jsx("section",{className:"",children:e.jsx(Hn,{})}),e.jsx("div",{}),e.jsx("div",{})]})}function De({children:s,summary:a,open:n,className:r}){return e.jsxs("details",{open:n,className:t.cn("space-y-4 [&_summary>svg]:open:-rotate-180",r),children:[e.jsxs("summary",{className:"flex cursor-pointer list-none items-center justify-between gap-4",children:[e.jsx(t.Label,{children:a}),e.jsx(t.ChevronUp,{className:"h-4 w-4"})]}),e.jsx("div",{className:"transition-all ease-in-out",children:s})]})}const Un=[{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"}],$n=["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"],Qn=$n.map(s=>({label:s,value:s}));function Jn(){var m,p,u,x,f,c,g,h,j,b,O,E,z,w,M,R,F,H;const s=t.useEditorStore(S=>S.card),a=(p=(m=s==null?void 0:s.preferences)==null?void 0:m.mapVisualOptions)==null?void 0:p.topoJsonUrl,[n,r]=k.useState(((x=(u=s==null?void 0:s.preferences)==null?void 0:u.mapVisualOptions)==null?void 0:x.customTopoJsonUrl)||""),{setCardPreferences:o}=t.useEditorActions(),{data:l}=t.useTopoJson(s),i=Object.keys((l==null?void 0:l.objects)||{}).map(S=>({label:S,value:S}))||[],d=[{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.jsxs("div",{className:"p-6",children:[e.jsx(De,{summary:"Map Chart",children:e.jsx("p",{className:"rounded-md bg-muted p-2 font-mono text-xs",children:"SELECT country, value FROM table"})}),e.jsx(t.Separator,{className:"my-4"}),e.jsx(De,{open:!0,summary:"Settings",children:e.jsxs("div",{className:"space-y-3 px-2",children:[e.jsx(X,{className:"h-9",options:d,onValueChange:S=>{console.log("value",S),o({...s.preferences,mapVisualOptions:{topoJsonUrl:S}})},value:a||"",label:"Select Map"}),a==="custom"&&e.jsx(t.Input,{onChange:S=>{r(S.target.value)},onBlur:()=>{var S;console.log("onBlur",n),o({...s.preferences,mapVisualOptions:{...(S=s.preferences)==null?void 0:S.mapVisualOptions,customTopoJsonUrl:n}})},value:n,className:`h-9 w-full ${t.removeRing}`,placeholder:"Custom URL"}),l&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(t.Label,{children:"Map Object"}),e.jsx(X,{className:"h-9",options:i,value:((c=(f=s.preferences)==null?void 0:f.mapVisualOptions)==null?void 0:c.objectKey)||"",label:"Map Object",onValueChange:S=>{var v;o({...s.preferences,mapVisualOptions:{...(v=s.preferences)==null?void 0:v.mapVisualOptions,objectKey:S}})}})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(t.Label,{children:"Projection"}),e.jsx(X,{className:"h-9",options:Un,value:((h=(g=s.preferences)==null?void 0:g.mapVisualOptions)==null?void 0:h.projection)||"",label:"Projection",onValueChange:S=>{var v;o({...s.preferences,mapVisualOptions:{...(v=s.preferences)==null?void 0:v.mapVisualOptions,projection:S}})}})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(t.Label,{children:"Colors"}),e.jsx(X,{className:"h-9",options:Qn,value:((b=(j=s.preferences)==null?void 0:j.mapVisualOptions)==null?void 0:b.colorScale)||"",label:"Select Color Scale",onValueChange:S=>{var v;o({...s.preferences,mapVisualOptions:{...(v=s.preferences)==null?void 0:v.mapVisualOptions,colorScale:S}})}})]})]})]})}),e.jsx(t.Separator,{className:"my-4"}),e.jsx(De,{className:"",summary:"Scale Options",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(t.Input,{className:`h-9 w-full ${t.removeRing}`,type:"number",step:.1,value:((E=(O=s.preferences)==null?void 0:O.mapVisualOptions)==null?void 0:E.projectionScale)||1,onChange:S=>{var v;o({...s.preferences,mapVisualOptions:{...(v=s.preferences)==null?void 0:v.mapVisualOptions,projectionScale:Number(S.target.value)}})}}),e.jsx(t.Label,{children:"X"}),e.jsx(t.Input,{className:`h-9 w-full ${t.removeRing}`,type:"number",step:10,value:((M=(w=(z=s.preferences)==null?void 0:z.mapVisualOptions)==null?void 0:w.projectionOffset)==null?void 0:M[0])||0,onChange:S=>{var v,A,D,y;o({...s.preferences,mapVisualOptions:{...(v=s.preferences)==null?void 0:v.mapVisualOptions,projectionOffset:[Number(S.target.value),((y=(D=(A=s.preferences)==null?void 0:A.mapVisualOptions)==null?void 0:D.projectionOffset)==null?void 0:y[1])||0]}})}}),e.jsx(t.Label,{children:"Y"}),e.jsx(t.Input,{className:`h-9 w-full ${t.removeRing}`,type:"number",step:10,value:((H=(F=(R=s.preferences)==null?void 0:R.mapVisualOptions)==null?void 0:F.projectionOffset)==null?void 0:H[1])||0,onChange:S=>{var v,A,D,y;o({...s.preferences,mapVisualOptions:{...(v=s.preferences)==null?void 0:v.mapVisualOptions,projectionOffset:[((y=(D=(A=s.preferences)==null?void 0:A.mapVisualOptions)==null?void 0:D.projectionOffset)==null?void 0:y[0])||0,Number(S.target.value)]}})}})]})}),e.jsx(t.Separator,{className:"my-4"}),e.jsx(oe,{})]})}function Kn(){var r;const s=t.useEditorStore(o=>o.card.preferences),{setCardPreferences:a}=t.useEditorStore(o=>o.actions);function n(o){a({...s,textVisualOptions:{...s==null?void 0:s.textVisualOptions,isDynamicText:o==="dynamic"}})}return e.jsxs(t.RadioGroup,{value:(r=s==null?void 0:s.textVisualOptions)!=null&&r.isDynamicText?"dynamic":"static",onValueChange:n,className:"flex gap-3",defaultValue:"x",children:[e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(t.RadioGroupItem,{value:"static",id:"r1"}),e.jsx("label",{className:"text-sm",htmlFor:"r1",children:"Static"})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(t.RadioGroupItem,{value:"dynamic",id:"r2"}),e.jsx("label",{className:"text-sm",htmlFor:"r2",children:"Dynamic"})]})]})}function fe({cardType:s,docContent:a,suffix:n="Chart"}){return e.jsx("div",{className:"space-y-6 px-6 py-2",children:e.jsxs(t.Accordion,{defaultValue:["item-2"],type:"multiple",children:[e.jsxs(t.AccordionItem,{value:"item-1",children:[e.jsx(t.AccordionTrigger,{children:`${t.titleCase(s)} ${n}`}),e.jsx(t.AccordionContent,{children:a||e.jsxs("div",{className:"space-y-4 font-mono text-xs",children:[e.jsx("div",{className:"rounded bg-muted px-2 py-1 text-xs",children:"SELECT label, measure FROM table"}),e.jsxs("ul",{className:"ml-6 list-disc text-xs [&>li]:mt-2",children:[e.jsx("li",{children:"label - category"}),e.jsx("li",{children:"measure - number"})]}),e.jsxs("div",{children:["See ",e.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.jsxs(t.AccordionItem,{value:"item-2",children:[e.jsx(t.AccordionTrigger,{children:"Settings"}),e.jsxs(t.AccordionContent,{className:"space-y-4 px-2",children:[s!=="text"&&e.jsx($e,{}),s==="text"&&e.jsx(Kn,{})]})]}),!["range","text"].includes(s)&&e.jsxs(t.AccordionItem,{value:"item-3",children:[e.jsx(t.AccordionTrigger,{children:"Filters"}),e.jsxs(t.AccordionContent,{className:"space-y-4 px-2",children:[e.jsx(oe,{}),e.jsx(me,{})]})]})]})})}function Wn(){const s=t.useEditorStore(r=>{var o,l;return(l=(o=r==null?void 0:r.card)==null?void 0:o.preferences)==null?void 0:l.sortChart}),{setSortChart:a}=t.useEditorActions();function n(){return e.jsxs("div",{className:"space-y-2",children:[e.jsx(t.Label,{children:"Sort"}),e.jsx(X,{className:"h-8",label:"Sort Chart",options:[{label:"None",value:"none"},{label:"ASC",value:"asc"},{label:"DESC",value:"desc"}],value:s||"none",onValueChange:r=>{a(r)}})]})}return e.jsx("div",{className:"space-y-6 px-6 py-2",children:e.jsxs(t.Accordion,{defaultValue:["item-2"],type:"multiple",children:[e.jsxs(t.AccordionItem,{value:"item-1",children:[e.jsx(t.AccordionTrigger,{children:"Stacked Chart"}),e.jsxs(t.AccordionContent,{className:"space-y-4 font-mono text-xs",children:[e.jsx("div",{className:"rounded bg-muted px-2 py-1 text-xs",children:"SELECT x-axis, stack-by, y-axis FROM table"}),e.jsxs("ul",{className:"ml-6 list-disc text-xs [&>li]:mt-2",children:[e.jsx("li",{children:"x-axis - category"}),e.jsx("li",{children:"stack by - category"}),e.jsx("li",{children:"y-axis - number"})]}),e.jsxs("div",{children:["See ",e.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.jsxs(t.AccordionItem,{value:"item-2",children:[e.jsx(t.AccordionTrigger,{children:"Settings"}),e.jsxs(t.AccordionContent,{className:"space-y-4 px-2",children:[n(),e.jsx(Pt,{})]})]}),e.jsxs(t.AccordionItem,{value:"item-3",children:[e.jsx(t.AccordionTrigger,{children:"Filters"}),e.jsxs(t.AccordionContent,{className:"space-y-4 px-2",children:[e.jsx(oe,{}),e.jsx(me,{})]})]})]})})}function Yn({cardType:s="table"}){console.log("cardType",s);const a=t.useEditorStore(o=>{var l;return(l=o.card)==null?void 0:l.preferences}),n=t.useEditorStore(o=>o.actions.setCardPreferences),r=o=>{n({...a,allowDownload:o})};return e.jsxs("div",{className:"space-y-6 px-6 py-2",children:[e.jsx(t.Accordion,{defaultValue:["item-3"],type:"multiple",children:e.jsxs(t.AccordionItem,{value:"item-3",children:[e.jsx(t.AccordionTrigger,{children:"Filters"}),e.jsxs(t.AccordionContent,{className:"space-y-4 px-2",children:[e.jsx(oe,{}),e.jsx(me,{})]})]})}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(t.Checkbox,{onCheckedChange:r,id:"allow-download"}),e.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 Xn=e.jsxs("div",{className:"space-y-4 font-mono text-xs",children:[e.jsx("div",{className:"rounded bg-muted px-2 py-1 text-xs",children:"SELECT dimension, cohort, metric FROM table"}),e.jsxs("div",{children:["See ",e.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."]})]}),Zn=e.jsxs("div",{className:"space-y-4 font-mono text-xs",children:[e.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.jsxs("div",{children:["See ",e.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."]})]}),ea=e.jsxs("div",{className:"space-y-4 font-mono text-xs",children:[e.jsx("div",{className:"rounded bg-muted px-2 py-1 text-xs",children:"SELECT text FROM table limit 1"}),e.jsxs("div",{children:["See ",e.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 ta(){const s=t.useEditorStore(n=>n.card.type);function a(n){switch(n){case"stackedBar":case"stackedLine":return e.jsx(Wn,{});case"pyramid":return e.jsx(fe,{docContent:Xn,cardType:n});case"kpi":return e.jsx(Gn,{});case"line":case"bar":return e.jsx(Rn,{cardType:n});case"range":return e.jsx(fe,{docContent:Zn,cardType:n});case"pie":case"doughnut":case"polarArea":case"radar":return e.jsx(fe,{cardType:n});case"bubble":case"scatter":return e.jsx(_n,{cardType:n});case"table":return e.jsx(Yn,{cardType:n});case"text":return e.jsx(fe,{docContent:ea,cardType:n,suffix:"Visual"});case"map":return e.jsx(Jn,{});case"custom":return e.jsx(Ln,{});default:return e.jsx(Bn,{})}}return e.jsxs(t.ScrollArea,{className:"h-full w-full text-sm",children:[a(s),e.jsx(t.ScrollBar,{orientation:"horizontal"})]})}const Ee={id:"__placeholder__",role:"groupby",type:"string"},Te={id:"__placeholder__",role:"metric",type:"number"},Ae={id:"__placeholder__",role:"trendby",type:"date"},Me={id:"__placeholder__",role:"filter",type:"string"},Ut={id:"__placeholder__"},ye="droppable-group-by",Se="droppable-metrics",ze="sortable-group-by",Fe="sortable-metrics",Re="droppable-trend-by",_e="sortable-trend-by",Ve="droppable-filters",qe="sortable-filters";function sa(){const s=t.useDndStore(v=>v.insertIndex),a=t.useEditorStore(v=>{var A;return((A=v.card.queryConfig)==null?void 0:A.groupByColumns)||[]}),n=t.useEditorStore(v=>{var A;return((A=v.card.queryConfig)==null?void 0:A.metricColumns)||[]}),r=t.useEditorStore(v=>{var A;return((A=v.card.queryConfig)==null?void 0:A.trendByColumns)||[]}),o=t.useEditorStore(v=>{var A;return((A=v.card.queryConfig)==null?void 0:A.filterColumns)||[]}),{setInsertIndex:l,setActiveId:i,setPreviewGroupByColumns:d,setPreviewMetricColumns:m,setPreviewTrendByColumns:p,setPreviewFilterColumns:u}=t.useDndActions(),{setGroupByColumns:x,setMetricColumns:f,setTrendByColumns:c,setFilterColumns:g}=t.useEditorActions(),{columns:h}=wt(),{formattedTableName:j}=se(),b=t.useSensors(t.useSensor(t.MouseSensor,{activationConstraint:{distance:1}})),O=v=>{var y;const{active:A,over:D}=v;if(((y=A.data.current)==null?void 0:y.type)==="column"&&D){const _=D.id,G=h.find(C=>C.column_name===A.id);if(!G)return;const $=t.isNumberDataType(G.data_type),B=t.isTextDataType(G.data_type),I=t.isDateDataType(G.data_type);if(B){if(a.some(N=>N.id===_)){const N=a.findIndex(L=>L.id===_);l(N);const T=a.filter(L=>L.id!==Ee.id);T.splice(N,0,Ee),d(T)}else if(D.id===ye){l(a.length);const N=[...a,Ee];d(N),m(n),p(r),u(o)}}if($||B){if(n.some(N=>N.id===_)){console.log("isOverMetricSortable",_);const N=n.findIndex(L=>L.id===_);l(N);const T=n.filter(L=>L.id!==Te.id);T.splice(N,0,Te),m(T)}else if(D.id===Se){l(n.length);const N=[...n,Te];m(N),p(r),u(o),d(a)}}if(I){if(r.some(N=>N.id===_)){const N=r.findIndex(L=>L.id===_);l(N);const T=r.filter(L=>L.id!==Ae.id);T.splice(N,0,Ae),p(T)}else if(D.id===Re){l(r.length);const N=[...r,Ae];p(N),m(n),u(o),d(a)}}if(z(G)){if(o.some(N=>N.id===_)){const N=o.findIndex(L=>L.id===_);l(N);const T=o.filter(L=>L.id!==Me.id);T.splice(N,0,Me),u(T)}else if(D.id===Ve){l(o.length);const N=[...o,Me];u(N),m(n),p(r),d(a)}}}else d(a),m(n),p(r),u(o)};function E(v){i(v.active.id),l(null),d(a),m(n),p(r),u(o)}function z(v){return!o.some(A=>A.name===v.column_name)}function w(v,A="SUM"){const{column_name:D,data_type:y}=v,_=[...n],G=s!==null?s:n.length,$={...v,id:ae(D),name:D,label:ge(A,D),type:y,role:"metric",aggregate:A};_.splice(G,0,$),f(_)}function M(v){const A=[...a],D=s!==null?s:a.length,y={...v,id:ae(v.column_name),name:v.column_name,type:v.data_type,role:"groupby"};A.splice(D,0,y),x(A)}function R(v){const A=[...r],D=s!==null?s:r.length,y={...v,id:ae(v.column_name),name:v.column_name,type:v.data_type,role:"trendby"};A.splice(D,0,y),c(A)}function F(v){const A=[...o],D=s!==null?s:o.length,y={...v,id:ae(v.column_name),name:v.column_name,type:v.data_type,sql:t.getDefaultFilterSql(v.data_type,j,t.fmt(v.column_name)),role:"filter"};A.splice(D,0,y),g(A)}function H(v){var _,G,$,B,I,C,N,T;const{active:A,over:D}=v,y=A.data.current;if((y==null?void 0:y.type)==="column"&&D){const L=h.find(W=>W.column_name===A.id);if(!L)return;const U=t.isNumberDataType(L.data_type),P=t.isTextDataType(L.data_type),K=t.isDateDataType(L.data_type);P&&(D.id===ye||((_=D.data.current)==null?void 0:_.type)===ze)?M(L):(U||P)&&(D.id===Se||((G=D.data.current)==null?void 0:G.type)===Fe)?(U&&w(L),P&&w(L,"COUNT")):K&&(D.id===Re||(($=D.data.current)==null?void 0:$.type)===_e)?R(L):z(L)&&(D.id===Ve||((B=D.data.current)==null?void 0:B.type)===qe)&&F(L)}if(D&&((I=D.data.current)==null?void 0:I.type)===ze&&a.some(L=>L.id===A.id)){const L=a.findIndex(P=>P.id===A.id),U=a.findIndex(P=>P.id===D.id);if(L!==-1&&U!==-1&&L!==U){const P=[...a],[K]=P.splice(L,1);P.splice(U,0,K),x(P)}}if(D&&((C=D.data.current)==null?void 0:C.type)===Fe&&n.some(L=>L.id===A.id)){const L=n.findIndex(P=>P.id===A.id),U=n.findIndex(P=>P.id===D.id);if(L!==-1&&U!==-1&&L!==U){const P=[...n],[K]=P.splice(L,1);P.splice(U,0,K),f(P)}}if(D&&((N=D.data.current)==null?void 0:N.type)===_e&&r.some(L=>L.id===A.id)){const L=r.findIndex(P=>P.id===A.id),U=r.findIndex(P=>P.id===D.id);if(L!==-1&&U!==-1&&L!==U){const P=[...r],[K]=P.splice(L,1);P.splice(U,0,K),c(P)}}if(D&&((T=D.data.current)==null?void 0:T.type)===qe&&o.some(L=>L.id===A.id)){const L=o.findIndex(P=>P.id===A.id),U=o.findIndex(P=>P.id===D.id);if(L!==-1&&U!==-1&&L!==U){const P=[...o],[K]=P.splice(L,1);P.splice(U,0,K),g(P)}}i(null),l(null),d(a),m(n),p(r),u(o)}function S(){i(null),l(null),d(a),m(n),p(r),u(o)}return{handleDragOver:O,handleDragEnd:H,handleDragStart:E,handleDragCancel:S,sensors:b}}const ce=[{label:"Sum",value:"SUM",logo:e.jsx(gt,{className:"size-3.5"})},{label:"Count",value:"COUNT",logo:e.jsx(mt,{className:"size-3.5"})},{label:"Unique",value:"DISTINCT",logo:e.jsx(js,{className:"size-3.5"})},{label:"Average",value:"AVG",logo:e.jsx(Zt,{className:"size-3.5"})},{label:"Min",value:"MIN",logo:e.jsx(Yt,{className:"size-3.5"})},{label:"Max",value:"MAX",logo:e.jsx(ss,{className:"size-3.5"})}];function na({column:s,type:a,onRemoveColumn:n,droppableId:r}){const[o,l]=k.useState(!1),[i,d]=k.useState(ce[0]),{attributes:m,listeners:p,setNodeRef:u,transform:x,transition:f,isDragging:c}=t.useSortable({id:s.id,data:{type:a}}),g=x?{opacity:c?.5:void 0,transform:t.CSS.Translate.toString(x),transition:f}:void 0;function h(){return e.jsx("div",{"data-setting-container":"",className:"h-32 rounded-b-md border-x border-b border-border p-3 text-sm",children:e.jsx(e.Fragment,{})})}return e.jsxs("div",{...p,...m,ref:u,style:g,children:[e.jsxs("div",{className:t.cn("group flex h-8 items-center rounded-t-md bg-muted px-2",!o&&"rounded-b-md",o&&"border border-border"),children:[e.jsx("div",{children:e.jsx(t.GripVertical,{className:"size-3.5 cursor-move items-center justify-center p-0 text-muted-foreground/60 hover:text-foreground"})}),r===Se&&e.jsx(ra,{column:s}),e.jsx("div",{className:t.cn("max-w-[250px] grow cursor-pointer overflow-hidden truncate text-ellipsis whitespace-nowrap",{"pl-2":r===ye}),children:e.jsx(aa,{col:s})}),e.jsxs("div",{"data-setting-actions":"",className:"hidden h-full items-center gap-2 group-hover:flex",children:[e.jsx("button",{onClick:()=>l(!o),children:e.jsx(t.ChevronDown,{className:t.cn("ml-1 size-4 cursor-pointer items-center justify-center rounded-r-sm bg-muted text-muted-foreground",o&&"rotate-180")})}),e.jsx("button",{onClick:()=>n(s.id),children:e.jsx(t.X,{className:"size-3.5 cursor-pointer items-center justify-center rounded-r-sm bg-muted text-muted-foreground"})})]})]}),o&&h()]})}function aa({col:s}){return e.jsx(t.Editable,{text:s.label||s.name,className:"h-6 rounded-none",onSave:a=>{console.log("saved",a)},children:e.jsx("span",{className:"w-[250px] truncate text-ellipsis whitespace-nowrap text-sm",children:s.label||s.name})})}function ra({column:s}){const[a,n]=k.useState(ce[0]),{updateMetricColumn:r}=t.useEditorActions();let o=ce;t.isTextDataType(s.type)&&(o=o.filter(i=>["COUNT","DISTINCT"].includes(i.value))),t.isNumberDataType(s.type)&&(o=o.filter(i=>!["DISTINCT","COUNT"].includes(i.value))),k.useEffect(()=>{n(ce.find(i=>i.value===s.aggregate)||ce[0])},[s]);function l(i){const d=ce.find(p=>p.value===i);if(!d)return;n(d);const m={...s,aggregate:i,label:ge(i,s.name)};r(s.id,m)}return e.jsx(X,{className:"size-7 overflow-clip rounded-none rounded-l-md border-none bg-muted px-2",icon:a.logo,options:o,value:a.value,onValueChange:i=>l(i),label:"Aggregation"})}function Le({id:s,label:a,columns:n,previewColumns:r,sortableType:o,onRemoveColumn:l}){const{setNodeRef:i}=t.useDroppable({id:s}),d=t.useDndStore(u=>u.activeId),m={},p=d?r:n;return e.jsx(t.SortableContext,{items:n==null?void 0:n.map(u=>u.id),children:e.jsxs("div",{className:"space-y-2 rounded-md border-2 border-dashed p-5",ref:i,style:m,children:[e.jsx(t.Label,{className:"text-sm",children:a}),e.jsx("div",{className:"space-y-2",children:p==null?void 0:p.map(u=>u.id===Ut.id?e.jsx(oa,{},u.id):e.jsx(na,{droppableId:s,type:o,column:u,onRemoveColumn:l},u.id))})]})})}function oa(){return e.jsx("div",{className:"flex h-7 grow items-center space-x-2 rounded-md border border-dashed border-muted-foreground bg-background px-2 py-1 text-sm"})}function nt(){const s=t.useEditorStore(c=>{var g;return((g=c.card.queryConfig)==null?void 0:g.groupByColumns)||[]}),a=t.useDndStore(c=>c.previewGroupByColumns),n=t.useEditorStore(c=>{var g;return((g=c.card.queryConfig)==null?void 0:g.metricColumns)||[]}),r=t.useDndStore(c=>c.previewMetricColumns),o=t.useEditorStore(c=>{var g;return((g=c.card.queryConfig)==null?void 0:g.trendByColumns)||[]}),l=t.useDndStore(c=>c.previewTrendByColumns),{setSelectedConnectionId:i,removeColumnFromGroupBy:d,removeColumnFromMetricColumns:m,removeColumnFromTrendByColumns:p}=t.useEditorActions();k.useEffect(()=>{i("c_2d3646f0-68a6-47e7-942d-d9cbc80fb7d4")},[i]);function u(c){d(c)}function x(c){p(c)}function f(c){m(c)}return e.jsxs("div",{className:"h-full w-full space-y-2 p-4",children:[e.jsx(Le,{onRemoveColumn:u,sortableType:ze,id:ye,label:"Group By",columns:s,previewColumns:a}),e.jsx(Le,{onRemoveColumn:x,sortableType:_e,id:Re,label:"Trend By",columns:o,previewColumns:l}),e.jsx(Le,{onRemoveColumn:f,sortableType:Fe,id:Se,label:"Metrics",columns:n,previewColumns:r})]})}function ia({children:s,id:a,type:n}){const{attributes:r,listeners:o,setNodeRef:l,transform:i,transition:d,isDragging:m}=t.useSortable({id:a,data:{type:n}}),p=i?{opacity:m?.5:void 0,transform:t.CSS.Translate.toString(i),transition:d}:void 0;return e.jsx("div",{...o,...r,ref:l,style:p,children:s})}function la({column:s,type:a}){const n=t.useDashboardStore(R=>R.themeStyle),[r,o]=k.useState(!1),l=t.useEditorStore(R=>{var F,H;return(H=(F=R.card)==null?void 0:F.queryConfig)==null?void 0:H.filters}),{selectedConnectionId:i,selectedDatabaseName:d,selectedTableName:m}=se(),p=t.isTextDataType(s.type);t.isNumberDataType(s.type),t.isDateDataType(s.type);const u=k.useMemo(()=>{var R;return(R=l==null?void 0:l.find(F=>F.filterColumnName===s.name))==null?void 0:R.filterValue},[l,s.name]),x=k.useMemo(()=>Array.isArray(u)?u.map(R=>({id:R,value:R})):[],[u]),{updateEditorCardFilterValue:f,removeEditorCardFilter:c}=t.useEditorActions(),g={column:s.name,sql:s.sql,id:s.name,connectionId:i,dataType:s.type},{data:h,isLoading:j,isFetching:b,isError:O}=t.useFilterQuery(g),E=k.useMemo(()=>{var F;return g.column?(F=h==null?void 0:h.records)==null?void 0:F.map(H=>{let S=g.column.split(".").slice(-1)[0].replace(/"/g,"");return H[S]===void 0&&(S=S.toLowerCase()),{id:H[S],value:H[S]}}):[]},[h,g.column]);function z(R){const F=R.map(H=>H.id);f(s.name,F)}function w(R){c(R)}function M(){return j||b?e.jsx(t.Skeleton,{style:{borderRadius:n==null?void 0:n.controlInputRadius},className:"h-8 w-60 bg-foreground/10"}):O?e.jsx("div",{className:"flex h-8 w-60 items-center bg-muted px-2 text-sm",children:"Error"}):p?e.jsx(t.ComboBoxMultiSelect,{options:E,onChange:z,selectedOptions:x,selectAllChecked:!1,onSelectAllCheckedChange:()=>{}}):e.jsx("div",{children:"Not implemented"})}return e.jsx(ia,{id:s.id,type:a,children:e.jsxs("div",{className:"group w-60 space-y-1 rounded-md border border-border px-3 py-2",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(t.Label,{className:"text-sm",children:s.name}),e.jsx("div",{"data-setting-actions":"",className:"invisible flex h-full items-center gap-2 group-hover:visible",children:e.jsx("button",{onClick:()=>w(s),children:e.jsx(t.X,{className:"size-3.5 cursor-pointer items-center justify-center rounded-r-sm text-muted-foreground"})})})]}),e.jsxs("div",{className:t.cn("group flex items-center rounded-t-md text-sm",!r&&"rounded-b-md",r&&"border border-border"),children:[e.jsx("div",{children:e.jsx(t.GripVertical,{className:"mr-2 size-3.5 cursor-move items-center justify-center p-0 text-muted-foreground/60 hover:text-foreground"})}),e.jsx("div",{className:"max-w-[250px] grow cursor-pointer overflow-hidden truncate text-ellipsis whitespace-nowrap",children:M()})]})]})})}function ca({id:s,label:a,columns:n,previewColumns:r,sortableType:o}){const{setNodeRef:l,isOver:i}=t.useDroppable({id:s}),d=t.useDndStore(x=>x.activeId),m={borderColor:i?"green":void 0};function p(x){return x.id===Ut.id?e.jsx(da,{}):e.jsx(la,{droppableId:s,type:o,column:x},x.id)}const u=d?r:n;return e.jsx(t.SortableContext,{items:n==null?void 0:n.map(x=>x.id),children:e.jsxs("div",{className:"space-y-2 rounded-md border-2 border-dashed p-5",ref:l,style:m,children:[e.jsx(t.Label,{className:"text-sm",children:a}),e.jsx("div",{className:"flex flex-wrap items-center gap-4",children:u==null?void 0:u.map(x=>p(x))})]})})}function da(){return e.jsx("div",{className:"flex h-7 w-60 items-center space-x-2 rounded-md border border-dashed border-muted-foreground bg-background px-2 py-1 text-sm"})}function ua(){const s=t.useEditorStore(o=>{var l;return((l=o.card.queryConfig)==null?void 0:l.filterColumns)||[]}),a=t.useDndStore(o=>o.previewFilterColumns),{removeColumnFromFilterColumns:n}=t.useEditorActions();function r(o){n(o)}return e.jsx("div",{className:"size-full p-4",children:e.jsx(ca,{onRemoveColumn:r,sortableType:qe,id:Ve,label:"Filters",columns:s,previewColumns:a})})}function ma(){const s=t.useEditorStore(r=>r.card),{data:a,errorMessage:n}=t.useDashboardCardQuery(s);return e.jsxs("section",{className:"flex justify-between gap-2 p-4",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(Ot,{}),e.jsx(It,{sql:a==null?void 0:a.sql,error:n})]}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"rounded-full bg-green-300 px-3 py-1 text-xs font-medium",children:"Early Preview"}),e.jsx(Lt,{}),e.jsx(Mt,{variant:"default"})]})]})}function ha(){const s=k.useRef(null),a=t.useEditorStore(i=>i.isShowingVisual),n=t.useEditorStore(i=>i.showAIDialog),r=t.useEditorStore(i=>i.isDevMode);k.useEffect(()=>{var i,d;n?(i=s.current)==null||i.resize(0):(d=s.current)==null||d.resize(25)},[n]);function o(){return e.jsxs(e.Fragment,{children:[e.jsx(t.ResizablePanel,{role:"query-section",className:"flex",minSize:20,defaultSize:40,children:e.jsx(xn,{})}),e.jsx(t.ResizableHandle,{withHandle:!0,className:"border"}),e.jsx(t.ResizablePanel,{className:"pb-1",role:"visual-section",minSize:0,defaultSize:60,children:a&&!n?e.jsxs(t.ResizablePanelGroup,{direction:"horizontal",children:[e.jsx(e.Fragment,{children:e.jsx(t.ResizablePanel,{ref:s,className:"flex",defaultSize:25,maxSize:30,children:r?e.jsx(ta,{}):e.jsx(nt,{})})}),!n&&e.jsx(t.ResizableHandle,{className:"border"}),e.jsx(t.ResizablePanel,{minSize:40,defaultSize:75,maxSize:100,children:e.jsx(xe,{})})]}):e.jsx(xe,{})})]})}function l(){return e.jsx(e.Fragment,{children:e.jsx(t.ResizablePanel,{className:"pb-1","data-biz-mode-container":"",minSize:0,defaultSize:100,children:a&&!n?e.jsxs(t.ResizablePanelGroup,{direction:"horizontal",children:[e.jsx(e.Fragment,{children:e.jsx(t.ResizablePanel,{ref:s,className:"flex min-w-[320px]",defaultSize:25,maxSize:30,children:e.jsx(nt,{})})}),!n&&e.jsx(t.ResizableHandle,{className:"border"}),e.jsx(t.ResizablePanel,{minSize:40,defaultSize:75,maxSize:100,children:e.jsxs(t.ResizablePanelGroup,{direction:"vertical",children:[e.jsxs(t.ResizablePanel,{className:"flex min-h-fit flex-col",minSize:10,defaultSize:20,children:[e.jsx(ma,{}),e.jsx(ua,{})]}),e.jsx(t.ResizableHandle,{className:"border"}),e.jsx(t.ResizablePanel,{minSize:20,defaultSize:80,children:e.jsx(xe,{})})]})})]}):e.jsx(xe,{})})})}return e.jsx(t.ResizablePanelGroup,{direction:"vertical",className:"min-h-[250px] min-w-full max-w-lg",children:r?o():l()})}const pa=[{title:"Help me write a query for",subtitle:"orders by month"},{title:"Create a bar chart for",subtitle:"sales by category"}];function xa(){const s=k.useRef(null),a=k.useRef(null),[n,r]=k.useState(!1),[o,l]=k.useState(t.isDevEnv),[i,d]=k.useState(!1),m=t.useEditorStore(B=>B.actions.setCardSql),p=t.useEditorStore(B=>B.actions.setRunSql),u=t.useEditorStore(B=>B.showAIDialog),{setShowAIDialog:x}=t.useEditorActions(),{messages:f,setMessages:c,reload:g,append:h,input:j,setInput:b,isLoading:O,handleAddCurrentTableToScope:E,removeFromCurrentSelections:z,currentAssitantScope:w,handleInputChange:M,handleSubmit:R,stop:F,chatStatus:H,toolStatus:S,llmUsage:v,errorMessage:A}=At();t.useAssistantScroll({scrollContainerRef:s,inputRef:a,messages:f}),k.useEffect(()=>{var B;u&&((B=a.current)==null||B.focus())},[u]);function D(B){m(B),p(!0)}function y(B){const I={role:"user",content:B.title+" "+B.subtitle};h(I)}function _(){return e.jsxs(t.DropdownMenu,{children:[e.jsx(t.DropdownMenuTrigger,{asChild:!0,children:e.jsx(t.Button,{className:"h-7 p-2",size:"sm",variant:"ghost",children:e.jsx(dt,{className:"size-3.5 text-muted-foreground/70 hover:text-muted-foreground"})})}),e.jsxs(t.DropdownMenuContent,{align:"end",children:[e.jsx(t.DropdownMenuLabel,{children:"Options"}),e.jsx(t.DropdownMenuSeparator,{}),e.jsx(t.DropdownMenuCheckboxItem,{checked:n,onCheckedChange:r,children:"Token Usage"}),e.jsx(t.DropdownMenuCheckboxItem,{checked:o,onCheckedChange:l,children:"Tool Invocations"}),e.jsx(t.DropdownMenuCheckboxItem,{checked:i,onCheckedChange:d,children:"System Message"})]})]})}function G(){return e.jsxs("div",{"data-role":"header",children:[e.jsx("div",{className:"text-lg font-semibold",children:"Assistant"}),w&&w.length>0&&e.jsx("div",{className:"mt-2 flex flex-wrap items-center gap-2",children:w==null?void 0:w.map((B,I)=>e.jsxs("div",{className:"flex items-center gap-2 rounded-md border border-border bg-muted px-2 py-1 text-xs",children:[t.getFormattedTableNameForQuery({schemaName:B.schemaName||"",tableName:B.tableName||"",modelName:B.datamodelName||"",connectionType:B.connectionType||"",databaseName:B.databaseName||""}),e.jsx("button",{onClick:()=>{z(B)},children:e.jsx(t.X,{className:"size-3 text-muted-foreground hover:text-foreground"})})]},I))}),(w==null?void 0:w.length)===0&&e.jsxs("div",{className:"mt-2 flex items-center gap-2",children:[e.jsx("span",{className:"text-xs text-muted-foreground",children:"Context: None"}),e.jsxs(t.Button,{className:"h-6 text-xs",size:"sm",variant:"secondary",onClick:E,children:[e.jsx(t.Plus,{className:"mr-2 size-3"}),"Current Table"]})]})]})}const $=(j==null?void 0:j.length)===0&&(f==null?void 0:f.filter(B=>B.role==="user").length)===0;return e.jsxs("div",{"data-role":"editor-assistant",className:"flex h-full w-full flex-col justify-between gap-2 px-6 py-4",children:[e.jsxs("div",{"data-role":"header-section",className:"flex items-start justify-between gap-2",children:[G(),e.jsxs("div",{"data-role":"header-actions",className:"flex items-center",children:[_(),e.jsx(t.Button,{className:"h-7 p-2",size:"sm",variant:"ghost",onClick:()=>{c([]),g()},children:e.jsx(t.RefreshCcw,{className:"size-3.5 text-muted-foreground"})}),e.jsx(t.Button,{className:"h-7 p-2",size:"sm",variant:"ghost",onClick:()=>{x(!1)},children:e.jsx(t.X,{className:"size-4"})})]})]}),e.jsx(t.CustomScrollArea,{ref:s,className:"flex w-full grow basis-0",children:e.jsxs("div",{className:"space-y-4 py-2 pr-3","data-role":"messages",children:[e.jsx(t.PrintMessages,{messages:f,showTools:o,handleRun:D,showSystemMessage:i}),e.jsx(t.ChatStatus,{status:t.getStatus(H,S),isLoading:O})]})}),$&&e.jsx(t.Placeholders,{onClick:y,placeholders:pa}),e.jsx(t.ChatInput,{onFocus:()=>{E()},stop:F,ref:a,setInput:b,input:j,handleInputChange:M,handleSubmit:R,isLoading:O}),v&&n&&e.jsx("div",{className:"flex h-8 items-center justify-between",children:e.jsxs("div",{className:"text-xs text-muted-foreground",children:["Usage: ",v.promptTokens," prompt tokens,"," ",v.completionTokens," completion tokens,"," ",v.totalTokens," total tokens"]})}),A&&e.jsx("div",{className:"flex items-center justify-between text-xs text-muted-foreground",children:e.jsx("span",{children:A})})]})}function fa({authToken:s,onSave:a,onClose:n}){const r=k.useRef(null),o=t.useEditorStore(j=>j.showAIDialog),{setAuthToken:l}=t.useDashboardActions(),{setShowAIDialog:i,setOnSave:d,setOnClose:m}=t.useEditorActions(),{handleDragOver:p,handleDragEnd:u,handleDragStart:x,handleDragCancel:f,sensors:c}=sa();k.useEffect(()=>{a&&d(a),n&&m(n)},[a,d,n,m]),k.useEffect(()=>{s&&s.accessToken&&l(s)},[s,l]),k.useEffect(()=>{var j,b;o?((j=r.current)==null||j.resize(40),i(!0)):(i(!1),(b=r.current)==null||b.resize(0))},[o,i]);function g(j){j<1?i(!1):o||i(!0)}function h(){return e.jsxs(t.ResizablePanelGroup,{"data-content":"editor-main",className:"grow",direction:"horizontal",children:[e.jsx(t.ResizablePanel,{className:"min-w-[510px] rounded-none border-x-[1px]",children:e.jsx(ha,{})}),e.jsx(t.ResizableHandle,{}),e.jsx(t.ResizablePanel,{"data-role":"editor-assistant-panel",ref:r,onResize:g,defaultSize:0,children:e.jsx(xa,{})})]})}return e.jsx(t.ErrorBoundary,{FallbackComponent:t.Fallback,children:e.jsx(t.DndContext,{sensors:c,onDragStart:x,onDragEnd:u,onDragOver:p,onDragCancel:f,children:e.jsxs("section",{className:"isolate flex h-full grow","data-content":"editor-panel",children:[e.jsx(kt,{type:"main"}),h()]})})})}function ga(){t.useDashboardStore(i=>i.selectedCardId);const s=t.useDashboardStore(i=>i.selectedSheetId),{setIsVisualEditing:a}=t.useDashboardStore(i=>i.actions),n=t.useDashboardStore(i=>i.isVisualEditing),r=t.useDashboardStore(i=>i.actions.updateFrame);function o(i){s&&(r(s,i),a(!1))}function l(){a(!1)}return e.jsx("div",{role:"editor-container",className:t.cn("flex grow",{"max-h-0 overflow-hidden":!n}),children:e.jsx(fa,{onSave:o,onClose:l})})}function ja(){const s=t.useEditorStore(l=>l.selectedDatabaseName),a=t.useEditorStore(l=>l.selectedTableName),n=t.useDashboardStore(l=>l.dashboard.filters)||[],{columns:r}=se(),{assignFilter:o}=Gt();return e.jsx(t.ScrollArea,{className:"flex-1 basis-0 flex-col px-3",children:r==null?void 0:r.map(l=>{const i=n==null?void 0:n.find(d=>d.column===t.fmt(l.column_name)&&d.table===a&&d.database===s);return e.jsx("div",{onClick:()=>o(l),className:t.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":i}),children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Ue,{column:l}),e.jsx("span",{children:l.column_name})]})},l.column_name)})})}function ba(){t.useDashboardStore(a=>a.showFilters);const s=t.useDashboardStore(a=>a.actions.setShowFilters);return e.jsxs("section",{className:"relative flex min-w-[320px] grow flex-col border-l px-1",children:[e.jsxs("div",{className:"mt-4 flex items-center justify-between gap-2 px-3",children:[e.jsx(t.Label,{className:"px-2 text-lg",children:"Filters"}),e.jsx(t.Button,{onClick:()=>s(!1),className:"h-7 w-7 p-0",variant:"ghost",children:e.jsx(t.Cross2Icon,{})})]}),e.jsx("div",{className:"flex grow",children:e.jsx(kt,{type:"filter",ColumnsComponent:()=>e.jsx(ja,{})})})]})}function ya(){const s=t.useDashboardStore(r=>r.dashboard.filters),a=t.useDashboardStore(r=>r.theme),n=s==null?void 0:s.filter(r=>r.hide);return n!=null&&n.length?e.jsx("div",{className:t.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)]":a==="light","bg-[repeating-linear-gradient(45deg,_#18171d_0_3px,_#272729_3px_6px)]":a==="dark"}),children:n==null?void 0:n.map(r=>e.jsxs("div",{className:"flex min-w-[250px] max-w-fit flex-col gap-1 p-2",children:[e.jsx(t.FilterHeader,{filter:r}),e.jsx(t.FilterComponent,{filter:r})]},r.id))}):null}function Sa(){const s=t.useDashboardStore(r=>r.showFilters),a=t.useDashboardStore(r=>r.isVisualEditing),n=t.useDashboardStore(r=>r.isDashboardEditing);return e.jsxs("div",{role:"dashboard-plus-main",className:t.cn("",{"max-h-0 overflow-hidden":a,"flex grow overflow-auto":!a}),children:[e.jsxs("section",{className:"flex grow flex-col",children:[n&&e.jsx(ya,{}),e.jsx(t.DashboardTabs,{})]}),s&&e.jsx("div",{role:"filter-aside-container",className:"flex",children:e.jsx(ba,{})})]})}function Ca(){const s=t.useDashboardStore(o=>o.dashboard),a=t.useDashboardStore(o=>o.actions.setDashboard),n=t.useDashboardStore(o=>o.showDashboardJSON),r=t.useDashboardStore(o=>o.actions.setShowDashboardJSON);return e.jsxs("div",{className:t.cn("relative p-2",{hidden:!n}),children:[e.jsxs(t.Button,{variant:"secondary",size:"sm",className:"absolute right-2 top-2 z-10 h-8",onClick:()=>r(!1),children:[e.jsx(t.X,{className:"mr-2 h-4 w-4"}),"Close"]}),e.jsx(t.de,{onChange:o=>{if(o)try{JSON.parse(o),a(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 va({showControls:s=!1,showFooter:a=!0,...n}){return e.jsx(t.ErrorBoundary,{FallbackComponent:t.Fallback,children:e.jsxs(t.SemaphorContextProvider,{dashboardProps:n,children:[e.jsx(t.$e,{}),e.jsxs(t.UXProvider,{children:[e.jsx(Ca,{}),e.jsxs(t.DashboardPanel,{...n,children:[s&&e.jsx(Ks,{}),e.jsx(ga,{}),e.jsx(Sa,{})]})]})]})})}exports.Dashboard=t.Dashboard;exports.DashboardWC=t.DashboardWC;exports.SemaphorDataProvider=t.SemaphorQueryClient;exports.SemaphorQueryClient=t.SemaphorQueryClient;exports.createSqlGenConfig=t.createSqlGenConfig;exports.fmt=t.fmt;exports.getColumnDataType=t.getColumnDataType;exports.getFilterValueType=t.getFilterValueType;exports.getFormattedTableNameForQuery=t.getFormattedTableNameForQuery;exports.getQualifiedTableName=t.getQualifiedTableName;exports.getSql=t.getSql;exports.invalidateToken=t.invalidateToken;exports.isBooleanDataType=t.isBooleanDataType;exports.isColumnInSqlGen=t.isColumnInSqlGen;exports.isDateDataType=t.isDateDataType;exports.isNumberDataType=t.isNumberDataType;exports.isTextDataType=t.isTextDataType;exports.resolveDataType=t.resolveDataType;exports.resolveDatamodelName=t.resolveDatamodelName;exports.useCard=t.useCard;exports.useDashboardActions=t.useDashboardActions;exports.useDashboardStore=t.useDashboardStore;exports.useDateFilterHook=t.useDateFilterHook;exports.useEditorActions=t.useEditorActions;exports.useEditorStore=t.useEditorStore;exports.useTextFilterHook=t.useTextFilterHook;exports.ScheduleDashboard=vt;exports.SelectComponent=le;exports.Surfboard=va;exports.cleanCard=yt;exports.downloadPdf=Ct;exports.getDashbaordStateWithoutData=Ge;exports.useEditorAside=se;
|
package/dist/index.js
CHANGED
|
@@ -7486,7 +7486,7 @@ function so() {
|
|
|
7486
7486
|
/* @__PURE__ */ e(Gn, { sql: n == null ? void 0 : n.sql, error: a })
|
|
7487
7487
|
] }),
|
|
7488
7488
|
/* @__PURE__ */ r("div", { className: "flex items-center gap-3", children: [
|
|
7489
|
-
/* @__PURE__ */ e("div", { className: "rounded-full bg-green-300
|
|
7489
|
+
/* @__PURE__ */ e("div", { className: "rounded-full bg-green-300 px-3 py-1 text-xs font-medium", children: "Early Preview" }),
|
|
7490
7490
|
/* @__PURE__ */ e(Zn, {}),
|
|
7491
7491
|
/* @__PURE__ */ e(Wn, { variant: "default" })
|
|
7492
7492
|
] })
|