react-semaphor 0.0.433 → 0.0.434

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("../chunks/index-XcoCF3Dr.js");exports.Dashboard=e.Dashboard;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("../chunks/index-TEaQlZ9a.js");exports.Dashboard=e.Dashboard;
@@ -1,4 +1,4 @@
1
- import { D as r } from "../chunks/index-OlgLt7aM.js";
1
+ import { D as r } from "../chunks/index-DysmhXPG.js";
2
2
  export {
3
3
  r as Dashboard
4
4
  };
package/dist/index.cjs CHANGED
@@ -1,4 +1,4 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("./chunks/index-XcoCF3Dr.js"),e=require("react/jsx-runtime"),E=require("react");require("react-dom");function es(s){const a=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(s){for(const n in s)if(n!=="default"){const r=Object.getOwnPropertyDescriptor(s,n);Object.defineProperty(a,n,r.get?r:{enumerable:!0,get:()=>s[n]})}}return a.default=s,Object.freeze(a)}const ue=es(E);/**
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("./chunks/index-TEaQlZ9a.js"),e=require("react/jsx-runtime"),E=require("react");require("react-dom");function es(s){const a=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(s){for(const n in s)if(n!=="default"){const r=Object.getOwnPropertyDescriptor(s,n);Object.defineProperty(a,n,r.get?r:{enumerable:!0,get:()=>s[n]})}}return a.default=s,Object.freeze(a)}const ue=es(E);/**
2
2
  * @license lucide-react v0.453.0 - ISC
3
3
  *
4
4
  * This source code is licensed under the ISC license.
@@ -369,4 +369,4 @@
369
369
  ${c}
370
370
 
371
371
  `;f(j)}function H(){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(Cn,{jsonString:JSON.stringify(u,null,2)})})}),u&&u.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(ht,{className:"size-3.5 text-muted-foreground"})})]})}function q(){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(bn,{})}),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(Sn,{})}),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,onClick:()=>{O()},className:"shrink-0",size:"sm",children:[_||R?e.jsx(ie,{className:"mr-2 h-4 w-4 animate-spin"}):e.jsx(t.Play,{className:"mr-2 h-4 w-4"}),"Run"]}),e.jsx(Et,{sql:A==null?void 0:A.sql,error:C,onClick:B}),e.jsx(Ft,{}),e.jsx(t.Toggle,{pressed:a,onPressedChange:j=>n(j),className:"",size:"sm",children:e.jsx(yn,{className:"size-4 text-foreground/70"})}),e.jsx("button",{disabled:i,onClick:()=>{V(),S(!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(zt,{}),e.jsx(Ot,{})]})]})}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:[q(),H()]}),I()]})}function kn({data:s}){var i;const[a,n]=E.useState([]),o=Object.keys(s[0]).map(c=>({accessorKey:c,header:({column:u})=>{const h=u.getIsSorted();return e.jsx("div",{className:"flex gap-2",children:e.jsxs("div",{className:"flex cursor-pointer items-center",onClick:()=>u.toggleSorting(u.getIsSorted()==="asc"),children:[c,h==="asc"?e.jsx(t.TriangleUpIcon,{className:"ml-2 h-5 w-5"}):h==="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(c=>e.jsx(t.TableRow,{className:"",children:c.headers.map(u=>e.jsx(t.TableHead,{className:"h-11 font-semibold text-foreground",children:u.isPlaceholder?null:t.flexRender(u.column.columnDef.header,u.getContext())},u.id))},c.id))}),e.jsx(t.TableBody,{children:(i=l.getRowModel().rows)!=null&&i.length?l.getRowModel().rows.map(c=>e.jsx(t.TableRow,{className:"h-11 whitespace-nowrap py-2","data-state":c.getIsSelected()&&"selected",children:c.getVisibleCells().map(u=>e.jsx(t.TableCell,{className:"py-2",children:t.flexRender(u.column.columnDef.cell,u.getContext())},u.id))},c.id)):e.jsx(t.TableRow,{children:e.jsx(t.TableCell,{colSpan:o.length,className:"h-24 text-center",children:"No results."})})})]})})}function In({card:s}){var S,v,M,N,A,_,R,P,g,D,L;const[a,n]=E.useState(!1),[r,o]=E.useState([]),{authToken:l}=t.useSemaphorContext(),i=t.getTokenParams(l==null?void 0:l.accessToken),c=t.useDashboardStore(O=>O.themeStyle),u={colors:((v=(S=c==null?void 0:c.chart)==null?void 0:S.dataset)==null?void 0:v.backgroundColor)||[]};(M=s.customCardPreferences)!=null&&M.inputData;const{getCard:h}=t.useCustomVisual(((N=s.customCardPreferences)==null?void 0:N.url)||""),d=((A=s.customCardPreferences)==null?void 0:A.visualType)||"single",x=t.useEditorStore(O=>O.frame),{setCustomCardPreferences:y}=t.useEditorActions(),{data:m}=t.useDashboardCardQuery(s),b=E.useCallback((O,C)=>{o(V=>({...V,[O]:C}))},[]);if(!((_=s.customCardPreferences)!=null&&_.componentName))return null;const p=h((R=s.customCardPreferences)==null?void 0:R.componentName);function w(O){n(O)}const f=Object.keys(((P=s.customCardPreferences)==null?void 0:P.dataInputCardIds)||{}).map(O=>{var B,H,q;const C=(H=(B=s.customCardPreferences)==null?void 0:B.dataInputCardIds)==null?void 0:H[O].cardId,V=(q=x==null?void 0:x.cards)==null?void 0:q.find(I=>I.id===C);return V||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(E.Suspense,{fallback:e.jsx(e.Fragment,{}),children:[p&&d==="single"&&e.jsx(p,{params:i,theme:u,settings:(g=s.customCardPreferences)==null?void 0:g.settings,onDataChange:b,data:(m==null?void 0:m.records)||[]}),p&&d==="multiple"&&e.jsxs(e.Fragment,{children:[Object.keys(((D=s.customCardPreferences)==null?void 0:D.dataInputCardIds)||{}).map(O=>{var B,H,q;const C=(H=(B=s.customCardPreferences)==null?void 0:B.dataInputCardIds)==null?void 0:H[O].cardId,V=(q=x==null?void 0:x.cards)==null?void 0:q.find(I=>I.id===C);if(V)return e.jsx(t.MultiInputEmptyRenderer,{onLoadingStatus:w,onDataChange:b,dataInputIndex:O,card:V},V.id+O)}),e.jsx("div",{className:"flex flex-col gap-2",children:e.jsx(p,{theme:u,onDataChange:b,settings:f.map(O=>{var C;return(C=O==null?void 0:O.customCardPreferences)==null?void 0:C.settings}),data:f.map(O=>O!=null&&O.id?r==null?void 0:r[O.id]:[])})})]})]},(L=s.customCardPreferences)==null?void 0:L.componentName)})}function Rt({className:s,...a}){var w;const n=t.useEditorStore(f=>f.card),r=((w=n.customCardPreferences)==null?void 0:w.showCardHeader)??!0,o=t.useEditorStore(f=>f.frame),l=t.useDashboardStore(f=>f.dashboard.filters);t.useEditorStore(f=>f.actions.setRunSql);const{updateFilter:i}=t.useDashboardActions(),c=l==null?void 0:l.find(f=>f.id===o.filterId),{data:u,isLoading:h,isFetching:d}=t.useDashboardCardQuery(n),{setCard:x}=t.useEditorActions(),{data:y}=t.useTopoJson(n),m=E.useMemo(()=>!n.id||!(u!=null&&u.records)?null:t.createChartConfig({data:u==null?void 0:u.records,cardType:n.type,customCfg:n.customCfg,preferences:n.preferences,topoJson:y}),[n.id,u==null?void 0:u.records,n.type,n.customCfg,n.preferences,y]);function b(f){return e.jsx(In,{card:f})}function p(){if(u!=null&&u.records&&(u==null?void 0:u.records.length)===0&&!h&&!d)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 b(n);if(!["table","custom"].includes(n.type)&&m)return e.jsx(e.Fragment,{children:h||d?e.jsx(e.Fragment,{}):e.jsx(t.ChartJsVisual,{cfg:m})});if(n.type==="table"&&(u!=null&&u.records)&&(u==null?void 0:u.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:u==null?void 0:u.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:f=>x({...n,title:f}),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:f=>x({...n,description:f}),children:e.jsx(t.CardDescription,{children:n.description||"Edit description..."})},n.description)]}),c&&e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(t.Editable,{className:"my-1",text:c.title||c.column,onSave:f=>i({...c,title:f}),children:e.jsx(t.Label,{children:c.title})}),e.jsx(t.FilterComponent,{filter:c})]})]}),e.jsx(t.CardContent,{className:"flex grow flex-col",children:p()})]})}const Me=({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}),Dn=()=>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."})]})]}),En=({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(Me,{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(Me,{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(Me,{language:"javascript",value:s,onChange:o})})]}),Tn=({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 Mn(){const[s,a]=E.useState(!1),[n,r]=E.useState(""),[o,l]=E.useState(""),[i,c]=E.useState(""),[u,h]=E.useState(""),d=t.useEditorStore(N=>N.card),x=t.useEditorStore(N=>N.card.customCfg),y=x?JSON.stringify(x,null,2):"",{data:m}=t.useDashboardCardQuery(d),{data:b}=t.useTopoJson(d),{setCardCustomCfg:p,setCustomVisualCode:w}=t.useEditorActions(),f=N=>{var A,_;return JSON.stringify({...N,data:{...N.data,datasets:(_=(A=N.data)==null?void 0:A.datasets)==null?void 0:_.map(R=>({...R,data:[]}))}},null,2)},S=()=>{var A,_;if(!((A=m==null?void 0:m.records)!=null&&A.length))return;const N=t.createChartConfig({data:m.records,cardType:d.type,preferences:d.preferences,topoJson:b});if(N){r(f(N)),c(((_=d.preferences)==null?void 0:_.customVisualCode)||"");const R=t.merge(N,x);l(f(R))}},v=()=>{try{if(i&&w(i),o){const N=JSON.parse(o),A=t.getObjectDiff(JSON.parse(n),N);p(A),h("")}}catch{h("Invalid JSON configuration")}},M=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:S,className:M?"":"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(Dn,{}),e.jsxs("div",{className:"flex grow gap-2",children:[e.jsx(t.ErrorBoundary,{FallbackComponent:t.FallbackEditorCard,children:e.jsx(Rt,{className:"w-1/2 rounded shadow-none"})}),e.jsx(En,{customCode:i,cardCustomCfgString:y,mergedConfig:o,onConfigChange:N=>l(N??""),onCodeChange:N=>c(N??"")})]}),e.jsx(Tn,{error:u,hasCardCustomConfig:!!x,onReset:()=>{l(n),p(null)},onApply:v,onClose:()=>a(!1)})]})]})}function Vt(s){const[a,n]=E.useState(null);return a}function _t(){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 An({onChartTypeChange:s}){const[a,n]=E.useState([]),{setCardCustomCfg:r,setCardPreferences:o,setCardType:l,setCustomCardPreferences:i}=t.useEditorActions(),{data:c}=_t();function u(h,d){r(null),o({}),l(h),d&&i({type:"component",visualType:"single",url:d.url,componentName:d.name,icon:d.icon}),s==null||s()}return E.useEffect(()=>{(async()=>{var d;if(c){const y=(await Promise.all((d=c==null?void 0:c.plugins)==null?void 0:d.map(async m=>(await t.loadManifest(m.value)).visuals.map(w=>({name:w.name,icon:w.icon,url:m.value}))))).flat();n(y)}})()},[c]),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((h,d)=>e.jsx(Ln,{text:h.name,onClick:()=>u("custom",h),icon:h.icon},h.url+h.name+d))})]})}const Ln=({text:s,icon:a,onClick:n})=>{const r=Vt(),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 qt(s){return me({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 On(s){return me({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 Bt(s){return me({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 Pt(s){return me({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 Ht(s){return me({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 Gt({onChartTypeChange:s,iconClassName:a}){const{setCardType:n,setCardPreferences:r,setChartOrientation:o}=t.useEditorStore(h=>h.actions),{setCardCustomCfg:l,setCustomCardPreferences:i}=t.useEditorActions();function c(h,d){l(null),r({}),n(h),s==null||s()}const u=1e3;return e.jsxs("div",{className:"grid grid-cols-4 place-items-center",children:[e.jsx(t.IconButton,{openDelay:u,tooltip:"Table",onClick:()=>c("table"),className:"h-10 p-4",children:e.jsx(qe,{className:t.cn("size-5",a)})}),e.jsx(t.IconButton,{openDelay:u,tooltip:"Bar Chart",onClick:()=>c("bar"),className:"h-10 p-4",children:e.jsx(Ve,{className:t.cn("size-5",a)})}),e.jsx(t.IconButton,{openDelay:u,tooltip:"Line Chart",onClick:()=>c("line"),className:"h-10 p-4",children:e.jsx(_e,{className:t.cn("size-5",a)})}),e.jsx(t.IconButton,{openDelay:u,tooltip:"Stacked Bar Chart",onClick:()=>c("stackedBar"),className:"h-10 p-4",children:e.jsx(rt,{className:t.cn("size-5",a)})}),e.jsx(t.IconButton,{openDelay:u,tooltip:"Stacked Line Chart",onClick:()=>c("stackedLine"),className:"h-10 p-4",children:e.jsx(Pt,{className:t.cn("size-5",a),strokeWidth:0})}),e.jsx(t.IconButton,{openDelay:u,tooltip:"Scatter Chart",onClick:()=>c("scatter"),className:"h-10 p-4",children:e.jsx(lt,{className:t.cn("size-5",a)})}),e.jsx(t.IconButton,{openDelay:u,tooltip:"Bubble Chart",onClick:()=>c("bubble"),className:"h-10 p-4",children:e.jsx(Bt,{className:t.cn("size-5",a)})}),e.jsx(t.IconButton,{openDelay:u,tooltip:"Pie Chart",onClick:()=>c("pie"),className:"h-10 p-4",children:e.jsx(it,{className:t.cn("size-5",a)})}),e.jsx(t.IconButton,{openDelay:u,tooltip:"Doughnut Chart",onClick:()=>c("doughnut"),className:"h-10 p-4",children:e.jsx(dt,{className:t.cn("size-5",a)})}),e.jsx(t.IconButton,{openDelay:u,tooltip:"Radar Chart",onClick:()=>c("radar"),className:"h-10 p-4",children:e.jsx(ft,{className:t.cn("size-5",a)})}),e.jsx(t.IconButton,{openDelay:u,tooltip:"Polar Area Chart",onClick:()=>c("polarArea"),className:"h-10 p-4",children:e.jsx(qt,{className:t.cn("size-5",a)})}),e.jsx(t.IconButton,{openDelay:u,tooltip:"Pyramid Chart",onClick:()=>c("pyramid"),className:"h-10 p-4",children:e.jsx(bt,{className:t.cn("size-5",a)})}),e.jsx(t.IconButton,{tooltip:"Range Chart",onClick:()=>c("range"),className:"h-10 p-4",children:e.jsx(ot,{className:t.cn("size-5",a)})}),e.jsx(t.IconButton,{openDelay:u,tooltip:"KPI",onClick:()=>c("kpi"),className:"h-10 p-4",children:e.jsx(Ht,{className:t.cn("size-5",a)})}),e.jsx(t.IconButton,{openDelay:u,tooltip:"Text",onClick:()=>c("text"),className:"h-10 p-4",children:e.jsx(hs,{className:t.cn("size-5",a)})}),e.jsx(t.IconButton,{tooltip:"Map",onClick:()=>c("map"),className:"h-10 p-4",children:e.jsx(xt,{className:t.cn("size-5",a)})}),e.jsx(t.IconButton,{openDelay:u,tooltip:"Custom",onClick:()=>c("custom"),className:"h-10 p-4",children:e.jsx(jt,{className:t.cn("size-5",a)})})]})}function zn({chartType:s,className:a,customIcon:n,componentName:r}){const o=Vt();switch(s){case"bar":return e.jsx(Ve,{className:a});case"line":return e.jsx(_e,{className:a});case"pie":return e.jsx(it,{className:a});case"radar":return e.jsx(ft,{className:a});case"scatter":return e.jsx(lt,{className:a});case"bubble":return e.jsx(Bt,{className:a});case"doughnut":return e.jsx(dt,{className:a});case"stackedBar":return e.jsx(rt,{className:a});case"stackedLine":return e.jsx(Pt,{className:a});case"polarArea":return e.jsx(qt,{className:a});case"pyramid":return e.jsx(bt,{className:a});case"range":return e.jsx(ot,{className:a});case"kpi":return e.jsx(Ht,{className:a});case"text":return e.jsx(St,{className:a});case"map":return e.jsx(xt,{className:a});case"custom":return n&&o?e.jsx(o,{className:a}):r?r==null?void 0:r.charAt(0).toUpperCase():e.jsx(jt,{className:a});default:return e.jsx(qe,{className:a})}}function Fn(){var l,i;const[s,a]=E.useState(!1),n=t.useEditorStore(c=>c.card),r=n.type,o=t.useDashboardStore(c=>c.isVisualEditing);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(zn,{className:"size-4",chartType:r,customIcon:(l=n.customCardPreferences)==null?void 0:l.icon,componentName:(i=n.customCardPreferences)==null?void 0:i.componentName})})}),e.jsxs(t.PopoverContentCustom,{onOpenAutoFocus:c=>c.preventDefault(),className:"w-50",children:[e.jsx(Gt,{onChartTypeChange:()=>a(!1)}),e.jsx(An,{onChartTypeChange:()=>a(!1)})]})]})}const ge="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 Rn(){var V,B,H,q,I,j;const[s,a]=E.useState(!1),n=t.useEditorStore(T=>{var k;return(k=T.card)==null?void 0:k.preferences}),r=t.getNumberAxis(n,{}),[o,l]=E.useState(st(n)),[i,c]=E.useState(((H=(B=(V=n==null?void 0:n.chartOptions)==null?void 0:V.scales)==null?void 0:B[r])==null?void 0:H.min)||""),[u,h]=E.useState(((j=(I=(q=n==null?void 0:n.chartOptions)==null?void 0:q.scales)==null?void 0:I[r])==null?void 0:j.max)||""),[d,x]=E.useState(i||u?"custom":"auto"),[y,m]=E.useState(""),[b,p]=E.useState(0),[w,f]=E.useState(""),[S,v]=E.useState(""),[M,N]=E.useState(""),A=t.useEditorStore(T=>T.actions.setCardPreferences),{updateCardInFrame:_}=t.useEditorActions(),R=t.useEditorStore(T=>T.card),P=t.useEditorStore(T=>{var k;return(k=T.card)==null?void 0:k.type}),g=["pie","doughnut","polarArea"].includes(P);E.useEffect(()=>{var T,k,U,Q,Y,se,Z,X,ee,z,G,K,ne,ce;l(st(n)),c(((U=(k=(T=n==null?void 0:n.chartOptions)==null?void 0:T.scales)==null?void 0:k[r])==null?void 0:U.min)===0?0:""),h(((se=(Y=(Q=n==null?void 0:n.chartOptions)==null?void 0:Q.scales)==null?void 0:Y[r])==null?void 0:se.max)||""),m(((z=(ee=(X=(Z=n==null?void 0:n.chartOptions)==null?void 0:Z.scales)==null?void 0:X[r])==null?void 0:ee.ticks)==null?void 0:z.stepSize)||""),p(((G=n==null?void 0:n.numberAxisFormat)==null?void 0:G.decimalPlaces)||0),f(((K=n==null?void 0:n.numberAxisFormat)==null?void 0:K.suffix)||""),v(((ne=n==null?void 0:n.numberAxisFormat)==null?void 0:ne.currency)||""),N(((ce=n==null?void 0:n.numberAxisFormat)==null?void 0:ce.locale)||"")},[s,n,r]);function D(T,k){return k===""||/^[0-9\b]+$/.test(k)?Number(k):Number(T)}function L(){const T=[...new Set(t.LOCALE_CURRENCY_PAIRS.map(k=>k.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:S||"none",onValueChange:k=>v(k==="none"?"":k),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"}),T.map(k=>e.jsx(t.SelectItem,{value:k,children:k},k))]})})]}),e.jsxs(t.Select,{value:M,onValueChange:k=>N(k),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(k=>e.jsx(t.SelectItem,{value:k.locale,children:k.locale},k.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:b,onChange:k=>p(Number(k.target.value)),id:"format",className:`col-span-6 h-8 w-full tracking-wide ${ge}`})]})]})}function O(){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:T=>c(k=>D(k,T.target.value)),className:`col-span-1 h-8 w-full ${ge}`}),e.jsx(t.Input,{value:u,onChange:T=>h(k=>D(k,T.target.value)),id:"max",className:`col-span-1 h-8 w-full ${ge}`})]}),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:y,onChange:T=>m(k=>D(k,T.target.value)),id:"step-size",className:`col-span-1 h-8 w-full ${ge}`})]})]})}function C(){var Q;let T={};d==="custom"&&(T={min:i,max:u,ticks:{stepSize:y}});const k={...n||{},chartOptions:{...n==null?void 0:n.chartOptions,scales:{...(Q=n==null?void 0:n.chartOptions)==null?void 0:Q.scales,[r]:{type:o,...o==="linear"?T:{}}}},numberAxisFormat:{decimalPlaces:b,suffix:w,currency:S,locale:M}};console.log(k),A(k);const U={...R,preferences:k};_(U)}return e.jsxs(t.Popover,{onOpenChange:T=>a(T),children:[e.jsx(t.PopoverTrigger,{asChild:!0,children:e.jsx(t.IconButton,{tooltip:"Scale Options",children:e.jsx(Hs,{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:g,value:o,onValueChange:T=>l(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,{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:g,id:"scale-option",value:d,onValueChange:T=>x(T),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"})]})]})]}),d==="custom"&&o=="linear"&&O(),L(),e.jsx(t.SelectSeparator,{}),e.jsx("div",{className:"grid grid-cols-3",children:e.jsx(t.Button,{onClick:C,variant:"secondary",className:"col-span-1 col-start-3 h-8 w-full",children:"Apply"})})]})]})})]})}function Vn(){const s=t.useEditorStore(c=>{var u,h,d,x;return(x=(d=(h=(u=c.card.preferences)==null?void 0:u.chartOptions)==null?void 0:h.plugins)==null?void 0:d.legend)==null?void 0:x.position}),a=t.useEditorStore(c=>{var u,h,d,x;return(x=(d=(h=(u=c.card.preferences)==null?void 0:u.chartOptions)==null?void 0:h.plugins)==null?void 0:d.legend)==null?void 0:x.align}),n=t.useEditorStore(c=>{var u,h,d,x;return(x=(d=(h=(u=c.card.preferences)==null?void 0:u.chartOptions)==null?void 0:h.plugins)==null?void 0:d.legend)==null?void 0:x.display}),{setLegendOptions:r}=t.useEditorActions(),o=c=>{r({display:c,position:s,align:a})},l=c=>{r({display:n,position:c,align:a})},i=c=>{r({display:n,position:s,align:c})};return e.jsxs(t.Popover,{children:[e.jsx(t.PopoverTrigger,{asChild:!0,children:e.jsx(t.IconButton,{tooltip:"Legend Settings",children:e.jsx(Ms,{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(is,{className:"size-4"})}),e.jsx(t.IconButton,{tooltip:"Bottom",onClick:()=>l("bottom"),children:e.jsx(at,{className:"size-4"})}),e.jsx(t.IconButton,{tooltip:"Right",onClick:()=>l("right"),children:e.jsx(ls,{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(ss,{className:"size-4"})}),e.jsx(t.IconButton,{tooltip:"Center",onClick:()=>i("center"),children:e.jsx(ts,{className:"size-4"})}),e.jsx(t.IconButton,{tooltip:"End",onClick:()=>i("end"),children:e.jsx(ns,{className:"size-4"})})]})]})]})]})})]})}function _n(){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(_s,{className:"size-4"}):e.jsx(Vs,{className:"size-4"})})}function qn(){const s=t.useEditorStore(i=>i.card),a=t.useEditorStore(i=>i.isShowingVisual),n=t.useEditorStore(i=>{var c,u;return(u=(c=i.card)==null?void 0:c.preferences)==null?void 0:u.chartOptions}),r=t.getChartGridStyle(n),{setChartGrid:o}=t.useEditorActions();function l(){const i=["xy","none","x","y"],u=(i.indexOf(r)+1)%i.length;o(i[u])}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(_n,{}),!["kpi","text","custom","table"].includes(s.type)&&e.jsxs(e.Fragment,{children:[e.jsx(Rn,{}),e.jsx(Vn,{})]}),!["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(Ds,{className:"size-4"}),r==="x"&&e.jsx(ys,{className:"size-4"}),r==="y"&&e.jsx(Ps,{className:"size-4"}),r==="none"&&e.jsx(Qs,{className:"size-4"})]})]}):null}function je(){var q;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),c=t.useEditorStore(I=>{var j;return(j=I.card.preferences)==null?void 0:j.chartOptions}),u=t.useEditorStore(I=>I.actions.setRunSql);t.getChartGridStyle(c);const{setFrame:h,setCard:d,updateCardInFrame:x,setActiveTabCardId:y,runAssistant:m,setChartGrid:b}=t.useEditorActions(),{data:p,isLoading:w,isFetching:f,error:S}=t.useDashboardCardQuery(a);if(!a)return e.jsx(e.Fragment,{children:"No Active Card"});function v(){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:[]};M(I)}function M(I){const j={...s,cards:[...s.cards,I],activeCardId:I.id};h(j),d(I),y(I.id)}function N(){const I={...a,id:t.v4(),title:`${a.title} Copy`,tabTitle:`${a.tabTitle||a.title} Copy`};M(I)}function A(I){const j=s.cards.filter(U=>U.id!==I),T=j[0],k={...s,cards:j,activeCardId:T.id};h(k),y(T.id),d(T)}function _(I){n||R(I),y(I)}function R(I){const j={...s,cards:s.cards.map(k=>k.id===a.id?a:k),activeCardId:I};h(j);const T=j.cards.find(k=>k.id===I);T.sql&&u(!0),d(T)}const P=(I,j)=>{console.log("handleDragStart",j),I.dataTransfer.setData("tabIndex",j.toString())},g=I=>{I.preventDefault()},D=(I,j)=>{const T=I.dataTransfer.getData("tabIndex");if(T===j.toString())return;const k=Array.from(s.cards),[U]=k.splice(parseInt(T),1);k.splice(j,0,U),h({...s,cards:k})};function L(I,j){return I.cards.length===1&&(j.displayTab===!0||j.displayTab===void 0)||I.activeCardId!==j.id&&(j.displayTab===!0||j.displayTab===void 0)?null:e.jsx("div",{onClick:()=>{const T=j.displayTab===void 0?!1:!j.displayTab;d({...j,displayTab:T}),x({...j,displayTab:T})},children:j.displayTab===!0||j.displayTab===void 0?e.jsx(t.Eye,{className:"mr-2 size-3.5 text-muted-foreground hover:text-foreground"}):e.jsx(Ns,{className:"mr-2 size-3.5 text-muted-foreground hover:text-foreground"})})}function O(){return e.jsxs(t.Tabs,{onValueChange:_,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:C()},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,j)=>e.jsx(t.Editable,{text:I.tabTitle||I.title,onSave:T=>{d({...a,tabTitle:T}),x({...a,tabTitle:T})},children:e.jsxs(t.TabsTrigger,{draggable:!0,onDragStart:T=>P(T,j),onDragOver:g,onDrop:T=>D(T,j),className:"",value:I.id,children:[L(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:()=>A(I.id)})]})},I.id)),e.jsx(t.Button,{className:"ml-1 h-8 px-2 hover:bg-muted-foreground/50",variant:"outline",onClick:v,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:N,children:e.jsx(Ss,{className:"h-4 w-4"})})]})})]})}function C(){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:p==null?void 0:p.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:p==null?void 0:p.records})})})}):e.jsx(t.ErrorBoundary,{FallbackComponent:t.FallbackEditorCard,children:e.jsx(Rt,{className:"grow border-none shadow-none"})})}function V(){const I=JSON.stringify(p==null?void 0:p.records,null,2),j=new Blob([I],{type:"application/json"}),T=URL.createObjectURL(j),k=document.createElement("a");k.href=T,k.download=`${a.title}.json`,k.click()}function B(){const j=[Object.keys(p==null?void 0:p.records.reduce((Q,Y)=>({...Q,...Y}),{})).join(","),...((p==null?void 0:p.records)||[]).map(Q=>Object.values(Q).join(","))].join(`
372
- `),T=new Blob([j],{type:"text/csv"}),k=URL.createObjectURL(T),U=document.createElement("a");U.href=k,U.download=`${a.title}.csv`,U.click()}function H(){const I=`Can you get the documentation for ${a.type} chart?`;m(I)}return e.jsxs("div",{className:"relative isolate flex h-full flex-col py-3",children:[(w||f)&&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(ie,{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(Fn,{}),o&&e.jsx(t.IconButton,{tooltip:"Visual Docs",onClick:H,children:e.jsx(ms,{className:"size-4"})}),!["table","custom"].includes(a.type)&&o&&e.jsx(Mn,{})]}),!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:B,children:e.jsx(On,{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:V,children:e.jsx(ws,{strokeWidth:1.5,className:"size-4"})}),e.jsx(t.CopyButton,{text:JSON.stringify(p==null?void 0:p.records,null,2),className:"h-7 w-fit px-1 font-mono text-xs text-muted-foreground/70"})]}),e.jsx(qn,{}),n&&e.jsx(Pn,{})]}),r?O():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(Bn,{})}),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:[(p==null?void 0:p.records)&&(p==null?void 0:p.records.length)>0&&e.jsx(kn,{data:(p==null?void 0:p.records)||[]}),(S||(p==null?void 0:p.error))&&e.jsx("span",{className:"font-mono text-xs",children:(S==null?void 0:S.message)||((q=p==null?void 0:p.error)==null?void 0:q.message)})]})]})]})}function Bn(){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 Pn(){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 Hn(){var p,w;const s=t.useEditorStore(f=>f.card.customCardPreferences),{data:a}=_t(),n=(a==null?void 0:a.plugins)||[],r=t.useEditorStore(f=>f.card),o=t.useEditorStore(f=>f.frame),l=(s==null?void 0:s.visualType)||"single",{setCustomCardPreferences:i}=t.useEditorActions(),{components:c,manifest:u}=t.useCustomVisual((s==null?void 0:s.url)||""),h=(p=u==null?void 0:u.visuals)==null?void 0:p.find(f=>f.name===(s==null?void 0:s.componentName));function d(f,S){if(!s)return;const M={...(s==null?void 0:s.dataInputCardIds)||{},[f]:{cardId:S,hookRef:null}};i({...s,dataInputCardIds:M})}function x(f){var v,M;const S=(v=o==null?void 0:o.cards)==null?void 0:v.filter(N=>{var A;return((A=N==null?void 0:N.customCardPreferences)==null?void 0:A.visualType)!=="multiple"}).map(N=>({value:N.id,label:N.tabTitle||N.title}));return e.jsx("div",{className:"space-y-2",children:(M=f==null?void 0:f.dataInputs)==null?void 0:M.map((N,A)=>{var _,R;return e.jsxs("div",{className:"grid grid-cols-10 gap-2",children:[e.jsx("div",{className:"col-span-4 flex items-center",children:N}),e.jsx(J,{className:"col-span-6 h-8 w-full justify-between",label:"",options:S||[],value:((R=(_=s==null?void 0:s.dataInputCardIds)==null?void 0:_[A])==null?void 0:R.cardId)||"",onValueChange:P=>d(A,P)})]},A+Math.random())})})}function y(f,S,v=[],M=""){var N,A;return s?f==="input"?e.jsx(t.Input,{className:`h-8 w-full ${t.removeRing}`,value:((N=s==null?void 0:s.settings)==null?void 0:N[S])||M,onChange:_=>{i({...s,settings:{...s==null?void 0:s.settings,[S]:_.target.value}})}},S):f==="select"?e.jsx(J,{className:"h-8 w-full",label:"",options:v,value:((A=s==null?void 0:s.settings)==null?void 0:A[S])||M,onValueChange:_=>{i({...s,settings:{...s==null?void 0:s.settings,[S]:_}})}}):null:null}function m(f){const S=Object.entries((f==null?void 0:f.settings)||{});return e.jsx("div",{className:"space-y-3",children:S.map(([v,M])=>e.jsxs("div",{className:"space-y-1",children:[e.jsx(t.Label,{children:M.title}),y(M.ui,v,M.options,M.defaultValue)]},v))})}function b(f){s&&i({...s,visualType:f,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(J,{icon:e.jsx(us,{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:f=>i({...s||{url:"",componentName:""},url:f})}),((s==null?void 0:s.type)==="component"||(s==null?void 0:s.type)===void 0)&&e.jsx(t.Tabs,{value:l,onValueChange:b,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:c&&e.jsx(J,{icon:e.jsx(bs,{className:"h-3.5 w-3.5"}),className:"h-9 w-full",label:"Select Component",options:(c==null?void 0:c.filter(f=>f.type===l).map(f=>({value:f.name,label:f.name})))||[],value:s.componentName,onValueChange:f=>{console.log("changing value",f),i({...s,componentName:f})}})})]})})]}),((w=r==null?void 0:r.customCardPreferences)==null?void 0:w.componentName)&&e.jsxs(t.AccordionItem,{className:"border-none",value:"component-settings",children:[e.jsx(t.AccordionTrigger,{children:"Settings"}),e.jsxs(t.AccordionContent,{children:[h&&h.dataInputs&&e.jsxs("div",{className:"space-y-3",children:[e.jsx(t.Label,{children:"Input Mapping"}),e.jsx("div",{className:"px-2",children:x(h)})]}),h&&h.settings&&e.jsx("div",{className:"space-y-3",children:e.jsx("div",{className:"px-2",children:m(h)})})]})]})]})}function le(){const[s,a]=E.useState([]),n=t.useEditorStore(h=>h.card.preferences),{setFilterOnClickColumnIndex:r,setCardPreferences:o}=t.useEditorStore(h=>h.actions),l=t.useEditorStore(h=>h.queryResultColumns);t.useEditorStore(h=>{var d;return(d=h.card.preferences)==null?void 0:d.filterOnClickColumnIndex}),E.useEffect(()=>{l&&a(new Array(l.length).fill(!1))},[l]);function i(h,d){var x,y;d?n!=null&&n.onClickFilter&&((x=n==null?void 0:n.onClickFilter)==null?void 0:x.length)>0?o({...n,onClickFilter:[...n.onClickFilter,{columnIndex:h,expression:""}]}):o({...n,onClickFilter:[{columnIndex:h,expression:""}]}):(o({...n,onClickFilter:(y=n==null?void 0:n.onClickFilter)==null?void 0:y.filter(m=>m.columnIndex!==h)}),a(m=>{const b=[...m];return b[h]=!1,b}))}function c(h,d){var y;const x=(y=n==null?void 0:n.onClickFilter)==null?void 0:y.map(m=>m.columnIndex===h?{...m,expression:d.target.value}:m);o({...n,onClickFilter:x})}function u(h){var d,x,y,m;if(s!=null&&s[h]||(x=(d=n==null?void 0:n.onClickFilter)==null?void 0:d.find(b=>b.columnIndex===h))!=null&&x.expression)return e.jsx(t.Input,{value:(m=(y=n==null?void 0:n.onClickFilter)==null?void 0:y.find(b=>b.columnIndex===h))==null?void 0:m.expression,onChange:b=>c(h,b),type:"text",className:"h-9 w-full font-mono text-xs focus-visible:ring-0 focus-visible:ring-ring focus-visible:ring-offset-0",placeholder:"Expression"})}return e.jsxs("div",{className:"space-y-2",children:[e.jsx(t.Label,{children:"On Click"}),l==null?void 0:l.map((h,d)=>{var x,y;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(m=>m.columnIndex===d)),onCheckedChange:m=>i(d,m)}),e.jsx("label",{className:"text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70",children:h}),e.jsx("div",{className:"flex items-center gap-2",children:((y=n==null?void 0:n.onClickFilter)==null?void 0:y.find(m=>m.columnIndex===d))&&e.jsx(t.Pencil,{onClick:()=>{a(m=>{const b=[...m];return b[d]=!m[d],b})},className:"invisible size-3 cursor-pointer text-gray-400 group-hover:visible"})})]}),u(d)]})},h)})]})}function Gn({idx:s}){var c;const a=t.useEditorStore(u=>{var h;return(h=u.card)==null?void 0:h.preferences}),n=t.useEditorStore(u=>{var h;return(h=u.card.preferences)==null?void 0:h.datasetOptions}),r=t.useEditorStore(u=>u.actions.setCardPreferences),o=(c=a==null?void 0:a.chartOptions)==null?void 0:c.indexAxis,l=n==null?void 0:n.find(u=>u.idx===s);function i(u,h){(u==="end"||u==="start")&&t.getContrastColor(t.getCanvasBackgroundColor());const d={display:u!=="none",align:u,anchor:u,clamp:!0};if(!l)r({...a,datasetOptions:[...n||[],{idx:h,datalabels:d}]});else{const x={...l};x.datalabels=d;const y=n==null?void 0:n.map(m=>m.idx===h?x:m);r({...a,datasetOptions:y})}}return e.jsxs(t.Popover,{children:[e.jsx(t.PopoverTrigger,{children:e.jsx(Ks,{className:"size-4 rotate-[135deg] cursor-pointer text-muted-foreground hover:text-foreground"})}),e.jsx(t.PopoverContent,{className:"w-fit px-2 py-1",children:e.jsxs("div",{className:"flex gap-1",children:[e.jsx("button",{onClick:()=>i("none",s),className:"h-7 p-1 text-xs font-normal",children:e.jsx(t.X,{className:"size-3.5"})}),e.jsx("button",{onClick:()=>i("start",s),className:"h-7 p-1 text-xs font-normal",children:e.jsx(As,{className:t.cn("h-4 w-4",{"rotate-90":o==="y"})})}),e.jsx("button",{onClick:()=>i("center",s),className:"h-7 p-1 text-xs font-normal",children:e.jsx(Os,{className:t.cn("h-4 w-4",{"rotate-90":o==="y"})})}),e.jsx("button",{onClick:()=>i("end",s),className:"h-7 p-1 text-xs font-normal",children:e.jsx(Ls,{className:t.cn("h-4 w-4",{"rotate-90":o==="y"})})})]})})]})}function Ut(){const s=t.useEditorStore(i=>i.card),{data:a}=t.useDashboardCardQuery(s),{metricKeys:n,dimensionKeys:r,keys:o}=t.getKeys((a==null?void 0:a.records)||[]);let l=n;if(["stackedBar","stackedLine"].includes(s.type)){const i=t.pivotData({dataArray:(a==null?void 0:a.records)||[],groupKey:r[0],pivotKey:r[1],valueKey:l[0]}),{metricKeys:c}=t.getKeys(i);l=c}return{transformedMetricKeys:l,dimensionKeys:r,keys:o,defaultMetricKeys:n}}function $t(){const s=t.useEditorStore(u=>u.card),a=t.useEditorStore(u=>{var h,d,x;return(x=(d=(h=u==null?void 0:u.card)==null?void 0:h.preferences)==null?void 0:d.chartOptions)==null?void 0:x.indexAxis}),{data:n}=t.useDashboardCardQuery(s),r=a==="y"?"Metric":"Dimension",o=a==="y"?"Dimension":"Metric",{dimensionKeys:l,transformedMetricKeys:i,keys:c}=Ut();return c.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:l.map(u=>e.jsx("p",{className:"rounded-md bg-muted/70 px-3 py-2 hover:bg-muted",title:u,children:Qt(u)},u))})]}),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:i.map((u,h)=>e.jsx(Kt,{className:"bg-muted/70 px-3 py-2 hover:bg-muted",iconClassName:"invisible group-hover:visible",col:u,idx:h},u))})]})]})}function Qt(s,a=30){return s.length>a?s.slice(0,a)+"...":s}function Kt({col:s,idx:a,className:n,iconClassName:r,children:o}){const l=t.useEditorStore(d=>{var x;return(x=d.card)==null?void 0:x.preferences}),i=t.useEditorStore(d=>{var x,y;return(y=(x=d.card)==null?void 0:x.preferences)==null?void 0:y.datasetOptions}),c=i==null?void 0:i.find(d=>d.idx===a),{setCardPreferences:u}=t.useEditorStore(d=>d.actions);function h(d){if(!c)u({...l,datasetOptions:[...i||[],{idx:a,type:d==="area"?"line":d,fill:d==="area"?"origin":""}]});else{const x={...c};x.type=d==="area"?"line":d,x.fill=d==="area"?"origin":"";const y=i==null?void 0:i.map(m=>m.idx===a?x:m);u({...l,datasetOptions:y})}}return e.jsxs("div",{className:t.cn("group flex items-center justify-between gap-5 rounded-md",n),children:[o||e.jsx("p",{title:s,children:Qt(s)}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(Ve,{onClick:()=>h("bar"),className:t.cn("size-4 cursor-pointer text-muted-foreground hover:text-foreground",r)}),e.jsx(_e,{onClick:()=>h("line"),className:t.cn("size-4 cursor-pointer text-muted-foreground hover:text-foreground",r)}),e.jsx(fs,{onClick:()=>h("area"),className:t.cn("size-4 cursor-pointer text-muted-foreground hover:text-foreground",r)}),e.jsx(Gn,{idx:a})]})]})}function Jt(){const s=t.useEditorStore(m=>m.selectedConnectionId),a=t.useEditorStore(m=>m.selectedDatamodelId),n=t.useEditorStore(m=>m.selectedDatabaseName),r=t.useEditorStore(m=>m.selectedSchemaName),o=t.useEditorStore(m=>m.selectedTableName),l=t.useDashboardStore(m=>m.dashboard.filters)||[],i=t.useDashboardStore(m=>m.actions.addFilter),c=t.useDashboardStore(m=>m.actions.removeFilter),{removeFilterValues:u}=t.useDashboardActions(),{modelItems:h,tableName:d,connectionType:x}=W();function y(m,b="dashboard"){var _;const p=t.fmt(m.column_name),w=t.fmt(n||""),f=t.fmt(r||""),S=t.fmt(d);let v=t.getQualifiedTableName({schemaName:f,tableName:S,connectionType:x,databaseName:w}),M=`${v}.${p}`;const N=(_=h==null?void 0:h.find(R=>R.id===a))==null?void 0:_.name;a&&a!=="none"&&(M=`${t.DATAMODEL_NAMESPCACE}.${N}.${p}`,v=`${t.DATAMODEL_NAMESPCACE}.${N}`);const A=l==null?void 0:l.find(R=>R.column===M&&R.table===S&&(R.database===w||R.database===n));if(A)u(A.id),c(A.id);else{const R=t.v4();return d==="api"&&s?(i({location:b,id:R,column:M,title:m.column_name,dataType:m.data_type,table:"api",database:"",connectionId:s,operation:"in",sql:t.getDefaultFilterSql(m.data_type,v,p)}),R):(i({id:R,location:b,column:M,title:m.column_name,dataType:m.data_type,table:o||"",database:n||"",connectionId:s||"",operation:"in",sql:t.getDefaultFilterSql(m.data_type,v,p)}),R)}}return{assignFilter:y}}function he(){const s=t.useDashboardStore(c=>c.dashboard.filters),a=t.useEditorStore(c=>c.frame),{setFrame:n}=t.useEditorActions(),{columns:r}=W(),{assignFilter:o}=Jt();function l(c){const u=o(c,"frame");n({...a,filterId:u})}const i=s==null?void 0:s.find(c=>c.id===a.filterId);return e.jsxs("div",{className:"space-y-3",children:[e.jsx(t.Label,{children:"Card Filter"}),e.jsx(Un,{onSelect:l,columns:r}),i&&e.jsx(t.FilterHeader,{filter:i})]})}function Un({columns:s,onSelect:a}){var i;const[n,r]=ue.useState(!1),[o,l]=ue.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(c=>c.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(c=>e.jsxs(t.CommandItem,{value:c.column_name,onSelect:u=>{const h=u===o?"":u;l(h),r(!1),h&&a(c)},children:[c.column_name,e.jsx(t.CheckIcon,{className:t.cn("ml-auto h-4 w-4",o===c.column_name?"opacity-100":"opacity-0")})]},c.column_name))})]})]})})]})}function $n({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($t,{})})]}),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(le,{}),e.jsx(he,{})]})]})]})})}function Ue(){var o,l,i;const s=t.useEditorStore(c=>c.card.type),a=t.useEditorStore(c=>c.card.preferences),{setCardPreferences:n}=t.useEditorStore(c=>c.actions);function r(c){var d;const u={datalabels:{display:c!=="none",align:c,anchor:c,clamp:!0}},h={...a,chartOptions:{...a==null?void 0:a.chartOptions,plugins:{...(d=a==null?void 0:a.chartOptions)==null?void 0:d.plugins,...u}}};n(h),console.log(c)}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 Qn({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(Ue,{})})]}),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(le,{}),e.jsx(he,{})]})]})]})})}const Kn={datasets:[{type:"line",label:"Sum_sales",data:[]},{type:"bar",label:"Sum_profit",data:[]}]},Jn={datasets:[{fill:"origin",type:"line",label:"Sum_sales",data:[]}]};function Wn(){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:Yn(s)}),!["kpi"].includes(s)&&e.jsxs("div",{className:"space-y-4",children:[e.jsx(Ue,{}),e.jsx(le,{}),e.jsx(he,{})]})]})}function Yn(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(Kn,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(Jn,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 Zn(){var u,h,d,x,y;const s=t.useEditorStore(m=>m.card.preferences),a=t.useEditorStore(m=>m.actions.setCardPreferences),n=t.useEditorStore(m=>m.actions.setNumberFormat);t.useEditorStore(m=>{var b,p;return(p=(b=m.card.preferences)==null?void 0:b.formatNumber)==null?void 0:p.decimalPlaces});const r=t.useEditorStore(m=>{var b,p;return(p=(b=m.card.preferences)==null?void 0:b.formatNumber)==null?void 0:p.locale}),o=t.useEditorStore(m=>{var b,p;return(p=(b=m.card.preferences)==null?void 0:b.formatNumber)==null?void 0:p.currency});t.useEditorStore(m=>m.actions.setFilterOnClickField);const l=t.useEditorStore(m=>{var b,p;return(p=(b=m.card.preferences)==null?void 0:b.formatNumber)==null?void 0:p.colorRanges})||[],i=t.useEditorStore(m=>m.actions.setColorRanges),c=[...new Set(t.LOCALE_CURRENCY_PAIRS.map(m=>m.currency))];return e.jsxs("div",{children:[e.jsxs("div",{className:"mb-3 flex items-center gap-2",children:[e.jsx(t.Checkbox,{checked:!!((u=s==null?void 0:s.formatNumber)!=null&&u.enabled),onCheckedChange:m=>{a({...s,formatNumber:{...s==null?void 0:s.formatNumber,enabled:m}})}}),e.jsx(t.Label,{children:"Format Number"})]}),((h=s==null?void 0:s.formatNumber)==null?void 0:h.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:m=>{var b,p,w;return n(((b=s==null?void 0:s.formatNumber)==null?void 0:b.decimalPlaces)||0,((p=s==null?void 0:s.formatNumber)==null?void 0:p.currency)||"",m,((w=s==null?void 0:s.formatNumber)==null?void 0:w.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(m=>e.jsx(t.SelectItem,{value:m.locale,children:m.locale},m.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:m=>{var b,p,w;console.log("currency",m),n(((b=s==null?void 0:s.formatNumber)==null?void 0:b.decimalPlaces)||0,m==="none"?"":m,((p=s==null?void 0:s.formatNumber)==null?void 0:p.locale)||"",((w=s==null?void 0:s.formatNumber)==null?void 0:w.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"),c.map(m=>e.jsx(t.SelectItem,{value:m,children:m},m))]})})]})]})]}),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=(d=s==null?void 0:s.formatNumber)==null?void 0:d.decimalPlaces)==null?void 0:x.toString())||"0",onValueChange:m=>{var b,p,w;return n(Number(m),((b=s==null?void 0:s.formatNumber)==null?void 0:b.currency)||"",((p=s==null?void 0:s.formatNumber)==null?void 0:p.locale)||"",((w=s==null?void 0:s.formatNumber)==null?void 0:w.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(m=>e.jsx(t.SelectItem,{value:m,children:m},m))})]})]}),e.jsxs("div",{className:"w-full space-y-1",children:[e.jsx(t.Label,{children:"Suffix"}),e.jsx(t.Input,{value:((y=s==null?void 0:s.formatNumber)==null?void 0:y.suffix)||"",className:"h-8 font-mono text-xs focus-visible:ring-0 focus-visible:ring-ring focus-visible:ring-offset-0",placeholder:"K, M, B, %",onChange:m=>{var b,p,w;return n(((b=s==null?void 0:s.formatNumber)==null?void 0:b.decimalPlaces)||0,((p=s==null?void 0:s.formatNumber)==null?void 0:p.currency)||"",((w=s==null?void 0:s.formatNumber)==null?void 0:w.locale)||"",m.target.value)}})]})]})]})}),e.jsx(t.Separator,{className:"my-3"}),e.jsx(t.ColorFormat,{colorRanges:l,setColorRanges:i})]})]})}function Xn(){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(Zn,{})}),e.jsx("div",{}),e.jsx("div",{})]})}function Ae({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 ea=[{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"}],ta=["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"],sa=ta.map(s=>({label:s,value:s}));function na(){var u,h,d,x,y,m,b,p,w,f,S,v,M,N,A,_,R,P;const s=t.useEditorStore(g=>g.card),a=(h=(u=s==null?void 0:s.preferences)==null?void 0:u.mapVisualOptions)==null?void 0:h.topoJsonUrl,[n,r]=E.useState(((x=(d=s==null?void 0:s.preferences)==null?void 0:d.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(g=>({label:g,value:g}))||[],c=[{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(Ae,{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(Ae,{open:!0,summary:"Settings",children:e.jsxs("div",{className:"space-y-3 px-2",children:[e.jsx(J,{className:"h-9",options:c,onValueChange:g=>{console.log("value",g),o({...s.preferences,mapVisualOptions:{topoJsonUrl:g}})},value:a||"",label:"Select Map"}),a==="custom"&&e.jsx(t.Input,{onChange:g=>{r(g.target.value)},onBlur:()=>{var g;console.log("onBlur",n),o({...s.preferences,mapVisualOptions:{...(g=s.preferences)==null?void 0:g.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(J,{className:"h-9",options:i,value:((m=(y=s.preferences)==null?void 0:y.mapVisualOptions)==null?void 0:m.objectKey)||"",label:"Map Object",onValueChange:g=>{var D;o({...s.preferences,mapVisualOptions:{...(D=s.preferences)==null?void 0:D.mapVisualOptions,objectKey:g}})}})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(t.Label,{children:"Projection"}),e.jsx(J,{className:"h-9",options:ea,value:((p=(b=s.preferences)==null?void 0:b.mapVisualOptions)==null?void 0:p.projection)||"",label:"Projection",onValueChange:g=>{var D;o({...s.preferences,mapVisualOptions:{...(D=s.preferences)==null?void 0:D.mapVisualOptions,projection:g}})}})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(t.Label,{children:"Colors"}),e.jsx(J,{className:"h-9",options:sa,value:((f=(w=s.preferences)==null?void 0:w.mapVisualOptions)==null?void 0:f.colorScale)||"",label:"Select Color Scale",onValueChange:g=>{var D;o({...s.preferences,mapVisualOptions:{...(D=s.preferences)==null?void 0:D.mapVisualOptions,colorScale:g}})}})]})]})]})}),e.jsx(t.Separator,{className:"my-4"}),e.jsx(Ae,{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:((v=(S=s.preferences)==null?void 0:S.mapVisualOptions)==null?void 0:v.projectionScale)||1,onChange:g=>{var D;o({...s.preferences,mapVisualOptions:{...(D=s.preferences)==null?void 0:D.mapVisualOptions,projectionScale:Number(g.target.value)}})}}),e.jsx(t.Label,{children:"X"}),e.jsx(t.Input,{className:`h-9 w-full ${t.removeRing}`,type:"number",step:10,value:((A=(N=(M=s.preferences)==null?void 0:M.mapVisualOptions)==null?void 0:N.projectionOffset)==null?void 0:A[0])||0,onChange:g=>{var D,L,O,C;o({...s.preferences,mapVisualOptions:{...(D=s.preferences)==null?void 0:D.mapVisualOptions,projectionOffset:[Number(g.target.value),((C=(O=(L=s.preferences)==null?void 0:L.mapVisualOptions)==null?void 0:O.projectionOffset)==null?void 0:C[1])||0]}})}}),e.jsx(t.Label,{children:"Y"}),e.jsx(t.Input,{className:`h-9 w-full ${t.removeRing}`,type:"number",step:10,value:((P=(R=(_=s.preferences)==null?void 0:_.mapVisualOptions)==null?void 0:R.projectionOffset)==null?void 0:P[1])||0,onChange:g=>{var D,L,O,C;o({...s.preferences,mapVisualOptions:{...(D=s.preferences)==null?void 0:D.mapVisualOptions,projectionOffset:[((C=(O=(L=s.preferences)==null?void 0:L.mapVisualOptions)==null?void 0:O.projectionOffset)==null?void 0:C[0])||0,Number(g.target.value)]}})}})]})}),e.jsx(t.Separator,{className:"my-4"}),e.jsx(le,{})]})}function aa(){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 ye({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(Ue,{}),s==="text"&&e.jsx(aa,{})]})]}),!["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(le,{}),e.jsx(he,{})]})]})]})})}function ra(){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(J,{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($t,{})]})]}),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(le,{}),e.jsx(he,{})]})]})]})})}function oa({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(le,{}),e.jsx(he,{})]})]})}),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 ia=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."]})]}),la=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."]})]}),ca=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 da(){const s=t.useEditorStore(n=>n.card.type);function a(n){switch(n){case"stackedBar":case"stackedLine":return e.jsx(ra,{});case"pyramid":return e.jsx(ye,{docContent:ia,cardType:n});case"kpi":return e.jsx(Xn,{});case"line":case"bar":return e.jsx($n,{cardType:n});case"range":return e.jsx(ye,{docContent:la,cardType:n});case"pie":case"doughnut":case"polarArea":case"radar":return e.jsx(ye,{cardType:n});case"bubble":case"scatter":return e.jsx(Qn,{cardType:n});case"table":return e.jsx(oa,{cardType:n});case"text":return e.jsx(ye,{docContent:ca,cardType:n,suffix:"Visual"});case"map":return e.jsx(na,{});case"custom":return e.jsx(Hn,{});default:return e.jsx(Wn,{})}}return e.jsxs(t.ScrollArea,{className:"h-full w-full text-sm",children:[a(s),e.jsx(t.ScrollBar,{orientation:"horizontal"})]})}function Wt({label:s,column:a,functions:n,onFunctionChange:r}){let o=n[0];"aggregate"in a?o=n.find(i=>i.value===a.aggregate)||n[0]:"granularity"in a&&(o=n.find(i=>i.value===a.granularity)||n[0]);function l(i){r(i)}return e.jsx(J,{className:"flex h-8 w-8 justify-center overflow-clip rounded-none border-none bg-muted px-0 [&>svg]:hidden",icon:o.logo,options:n,value:o.value,onValueChange:i=>l(i),label:s,showPlaceholderLabel:!1})}const ua=[{label:"Sum",value:"SUM",logo:e.jsx(yt,{className:"size-3.5"})},{label:"Count",value:"COUNT",logo:e.jsx(pt,{className:"size-3.5"})},{label:"Unique",value:"DISTINCT",logo:e.jsx(ks,{className:"size-3.5"})},{label:"Average",value:"AVG",logo:e.jsx(os,{className:"size-3.5"})},{label:"Min",value:"MIN",logo:e.jsx(at,{className:"size-3.5"})},{label:"Max",value:"MAX",logo:e.jsx(t.ArrowUp,{className:"size-3.5"})}];function ma({column:s}){const{updateMetricColumn:a}=t.useEditorActions();let n=ua;t.isTextDataType(s.type)&&(n=n.filter(o=>["COUNT","DISTINCT"].includes(o.value))),t.isNumberDataType(s.type)&&(n=n.filter(o=>!["DISTINCT"].includes(o.value)));function r(o){const l={...s,aggregate:o,label:xe(s.name,o)};a(s.id,l)}return e.jsx(Wt,{column:s,functions:n,onFunctionChange:o=>r(o),label:"Aggregation"})}const ha=[{label:"Day (D)",value:"day",logo:e.jsx(t.Label,{className:"cursor-pointer text-xs",children:"D"})},{label:"Week (W)",value:"week",logo:e.jsx(t.Label,{className:"cursor-pointer text-xs",children:"W"})},{label:"Month (M)",value:"month",logo:e.jsx(t.Label,{className:"cursor-pointer text-xs",children:"M"})},{label:"Year (Y)",value:"year",logo:e.jsx(t.Label,{className:"cursor-pointer text-xs",children:"Y"})}];function pa({column:s}){const{updateGroupByColumn:a}=t.useEditorActions();function n(r){const o={...s,granularity:r,label:Ce(s.name,r)};a(s.id,o)}return e.jsx(Wt,{column:s,functions:ha,onFunctionChange:r=>n(r),label:"Granularity"})}function xa({col:s,onChange:a,droppableId:n}){const{columns:r}=He(),o=E.useMemo(()=>{let c=[];(n===ae||n===oe)&&(c=r);const u=c==null?void 0:c.filter(h=>h.column_name!==s.name);return u==null?void 0:u.map(h=>({id:h.column_name,value:h.column_name}))},[r,n,s.name]),l=[{id:s.name,value:s.name}];function i(c){const u=r==null?void 0:r.find(h=>{var d;return h.column_name===((d=c[0])==null?void 0:d.id)});u&&a(u)}return o!=null&&o.length?e.jsx(t.ComboBox2,{multiple:!1,options:o,selectedOptions:l,onChange:i,selectAllChecked:!1,onSelectAllCheckedChange:()=>{},inputClassName:"border-none bg-muted px-0"}):e.jsx("input",{disabled:!0,type:"text",className:"overflow-hidden truncate text-ellipsis whitespace-nowrap bg-muted text-sm",value:s.name})}function Yt({children:s,className:a,delayDuration:n}){return e.jsx(t.TooltipProvider$1,{children:e.jsxs(t.Tooltip,{delayDuration:n,children:[e.jsx(t.TooltipTrigger,{asChild:!0,children:e.jsx("span",{className:t.cn("overflow-hidden text-ellipsis whitespace-nowrap",a),children:s})}),e.jsx(t.TooltipContent,{children:s})]})})}function fa({column:s}){const{updateMetricColumn:a}=t.useEditorActions(),{transformedMetricKeys:n,dimensionKeys:r}=Ut();console.log(n,r);const o=n.find(i=>i===s.label||i===s.name),l=o?n.indexOf(o):-1;return e.jsx("div",{className:"space-y-2",children:o&&e.jsx(Kt,{idx:l,col:o,children:e.jsx(t.Editable,{className:"w-[130px]",text:s.label||"",placeholder:"Enter label",onSave:i=>{a(s.id,{...s,label:i||s.name})},children:e.jsx(Yt,{className:"w-[130px]",children:s.label||s.name})})})})}function ga({column:s,type:a,onRemoveColumn:n,droppableId:r}){const[o,l]=E.useState(!1),{updateGroupByColumn:i,updateMetricColumn:c}=t.useEditorActions(),{attributes:u,listeners:h,setNodeRef:d,transform:x,transition:y,isDragging:m}=t.useSortable({id:s.id,data:{type:a}}),b=x?{opacity:m?.5:void 0,transform:t.CSS.Translate.toString(x),transition:y}:void 0,p=t.isTextDataType(s.type);function w(N){const A=t.isNumberDataType(N.data_type),_=t.isTextDataType(N.data_type),R=t.isDateDataType(N.data_type),P=A?"number":_?"string":R?"date":"string";if(r===ae&&_){const g={id:s.id,name:N.column_name,type:P,role:"groupby"};i(s.id,g)}if(r===ae&&R){const g={id:s.id,name:N.column_name,type:P,role:"groupby",label:Ce(N.column_name,"month"),granularity:"month"};i(s.id,g)}if(r===oe){const g={id:s.id,name:N.column_name,type:P,role:"metric",label:xe(N.column_name,"SUM"),aggregate:A?"SUM":"COUNT"};c(s.id,g)}}function f(){if(r===oe)return e.jsx("div",{"data-setting-container":"",className:"mt-1.5 max-h-32 overflow-y-auto rounded-md border border-border p-3 text-sm",children:e.jsx(fa,{column:s})})}function S(){const N=t.isDateDataType(s.type);if(r===oe)return e.jsx(ma,{column:s});if(r===ae&&N)return e.jsx(pa,{column:s})}function v(){return e.jsx("div",{className:t.cn("grow",{"pl-3":r===ae&&p}),children:e.jsx(xa,{col:s,onChange:w,droppableId:r})})}function M(){return e.jsx("div",{"data-setting-actions":"",className:"flex h-full items-center gap-2",children:e.jsx("button",{onClick:()=>l(!o),children:o?e.jsx($s,{className:t.cn("size-3 cursor-pointer items-center justify-center rounded-r-sm text-muted-foreground")}):e.jsx(mt,{className:t.cn("size-3 cursor-pointer items-center justify-center rounded-r-sm text-muted-foreground")})})})}return e.jsx("div",{...h,...u,ref:d,style:b,children:e.jsxs("div",{className:"group flex items-center justify-between gap-2",children:[e.jsxs("div",{className:"grow",children:[e.jsxs("div",{className:"flex h-8 grow items-center justify-between rounded-md bg-muted pl-2",children:[M(),S(),v()]}),o&&f()]}),e.jsx("div",{className:t.cn("opacity-0 transition-opacity duration-200 group-hover:opacity-100",{hidden:o}),children:e.jsx("button",{onClick:()=>n(s.id),children:e.jsx(t.X,{className:"size-3 cursor-pointer text-muted-foreground"})})})]})})}function nt({id:s,label:a,columns:n,previewColumns:r,sortableType:o,onRemoveColumn:l}){const{setNodeRef:i}=t.useDroppable({id:s}),c=t.useDndStore(d=>d.activeId),u={},h=c?r:n;return e.jsx(t.SortableContext,{items:n==null?void 0:n.map(d=>d.id),children:e.jsxs("div",{className:"space-y-2 rounded-md border-2 border-dashed p-4",ref:i,style:u,children:[e.jsx(t.Label,{className:"text-sm",children:a}),e.jsx("div",{className:"space-y-2",children:h==null?void 0:h.map(d=>d.id===It.id?e.jsx(ja,{},d.id):e.jsx(ga,{droppableId:s,type:o,column:d,onRemoveColumn:l},d.id))})]})})}function ja(){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 Zt({children:s,id:a,type:n}){const{attributes:r,listeners:o,setNodeRef:l,transform:i,transition:c,isDragging:u}=t.useSortable({id:a,data:{type:n}}),h=i?{opacity:u?.5:void 0,transform:t.CSS.Translate.toString(i),transition:c}:void 0;return e.jsx("div",{...o,...r,ref:l,style:h,children:s})}function ya(){const s=t.useEditorStore(f=>{var S;return(S=f.card.queryConfig)==null?void 0:S.orderBy})||[],a=t.useEditorStore(f=>{var S;return(S=f.card.queryConfig)==null?void 0:S.groupByColumns})||[],n=t.useEditorStore(f=>{var S;return(S=f.card.queryConfig)==null?void 0:S.metricColumns})||[],{addOrderByColumn:r,removeOrderByColumn:o,updateOrderByColumn:l}=t.useEditorActions(),i=[...a,...n];if(i.length===0)return e.jsx(e.Fragment,{});const c=e.jsx(ds,{className:"size-3.5 text-muted-foreground hover:text-foreground"}),u=e.jsx(rs,{className:"size-3.5 text-muted-foreground hover:text-foreground"}),h=e.jsx(cs,{className:"size-3.5 text-muted-foreground hover:text-foreground"}),d=e.jsx(as,{className:"size-3.5 text-muted-foreground hover:text-foreground"}),x=i==null?void 0:i.filter(f=>!s.some(S=>S.columnId===f.id)).map(f=>({id:f.id,value:f.label||f.name}));function y(f,S){const v=m(f);return v?v.role==="metric"?S==="asc"?h:d:S==="asc"?c:u:null}function m(f){return i.find(S=>S.id===f)}function b(f){const S=s.find(v=>v.columnId===f);if(S){const v={...S,direction:S.direction==="asc"?"desc":"asc"};l(v)}}const p=f=>{r({columnId:f.id,direction:"asc"})};function w(f){const S=s.find(v=>v.columnId===f);S&&o(S)}return e.jsx(t.SortableContext,{items:s.map(f=>pe(f.columnId)),children:e.jsxs("div",{className:"space-y-2 rounded-md border border-border p-4 text-sm",children:[e.jsx(t.Label,{className:"text-sm",children:"Sort By"}),x.length>0&&e.jsx("div",{className:"mr-5",children:e.jsx(t.ComboBox2,{multiple:!1,options:x,selectedOptions:[],onChange:f=>p(f[0]),selectAllChecked:!1,onSelectAllCheckedChange:()=>{},inputClassName:"h-8"})}),s.map(f=>{var S,v;return e.jsx(Zt,{id:pe(f.columnId),type:Ge,children:e.jsx("div",{className:"group flex h-8 items-center gap-2 rounded-sm p-0",children:e.jsxs("div",{className:"flex h-full grow items-center justify-between gap-2",children:[e.jsxs("div",{className:"flex h-full grow items-center justify-between gap-2 rounded-sm bg-muted px-2",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(mt,{className:"size-3 cursor-move text-muted-foreground hover:text-foreground"}),e.jsx(Yt,{className:"w-[175px] text-sm",children:((S=m(f.columnId))==null?void 0:S.label)||((v=m(f.columnId))==null?void 0:v.name)})]}),e.jsx("button",{title:f.direction==="asc"?"Ascending":"Descending",onClick:()=>b(f.columnId),className:"rounded-sm p-0",children:y(f.columnId,f.direction)})]}),e.jsx("div",{children:e.jsx("button",{onClick:()=>w(f.columnId),className:"rounded-sm p-0",children:e.jsx(t.X,{className:"size-3 text-muted-foreground opacity-0 transition-opacity duration-200 hover:text-foreground group-hover:opacity-100"})})})]})},f.columnId)},pe(f.columnId))})]})})}function ba(){const s=t.useEditorStore(x=>{var y;return((y=x.card.queryConfig)==null?void 0:y.groupByColumns)||[]}),a=t.useEditorStore(x=>x.card.type),n=t.useDndStore(x=>x.previewGroupByColumns),r=t.useEditorStore(x=>{var y;return((y=x.card.queryConfig)==null?void 0:y.metricColumns)||[]}),o=t.useDndStore(x=>x.previewMetricColumns),{removeColumnFromGroupBy:l,removeColumnFromMetricColumns:i}=t.useEditorActions();function c(x){l(x)}function u(x){i(x)}let h="Group By",d="Metrics";return a==="table"&&(h="Rows",d="Columns"),e.jsxs("div",{className:"flex h-full w-full flex-col gap-4 py-4",children:[e.jsx(Gt,{iconClassName:"size-[19px]"}),e.jsxs(t.CustomScrollArea,{className:"flex min-h-0 grow basis-0 flex-col gap-4 overflow-y-auto",children:[e.jsxs("div",{className:"flex flex-col gap-4 p-4",children:[e.jsx(nt,{onRemoveColumn:c,sortableType:Oe,id:ae,label:h,columns:s,previewColumns:n}),e.jsx(nt,{onRemoveColumn:u,sortableType:ze,id:oe,label:d,columns:r,previewColumns:o}),e.jsx(ya,{})]}),e.jsx(t.ScrollBar,{orientation:"horizontal"})]})]})}function $e({children:s,column:a,id:n,sortableType:r,className:o}){const[l,i]=E.useState(!1),{removeEditorFilter:c}=t.useEditorActions();function u(h){c(h)}return e.jsx(Zt,{id:n,type:r,children:e.jsxs("div",{className:t.cn("group space-y-1 rounded-md bg-muted px-3 py-2",{"border-border":l}),children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(t.Label,{className:"text-sm",children:a.name}),e.jsx("div",{"data-setting-actions":"",className:"invisible flex h-full items-center gap-2 group-hover:visible",children:e.jsx("button",{onClick:()=>u(a),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",!l&&"rounded-b-md",l&&"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:t.cn("grow cursor-pointer overflow-hidden truncate text-ellipsis whitespace-nowrap",o),children:s})]})]})})}function Sa({column:s,sortableType:a}){const n=t.useDashboardStore(S=>S.themeStyle),r=t.useEditorStore(S=>{var v,M;return(M=(v=S.card)==null?void 0:v.queryConfig)==null?void 0:M.filters}),{selectedConnectionId:o,selectedDatabaseName:l,selectedTableName:i}=W(),c=E.useMemo(()=>{var S;return(S=r==null?void 0:r.find(v=>v.filterColumnName===s.name))==null?void 0:S.filterValue},[r,s.name]),u=E.useMemo(()=>Array.isArray(c)?c.map(S=>({id:S,value:S})):[],[c]),{updateEditorFilterValue:h}=t.useEditorActions(),d={column:s.name,sql:s.sql,id:s.name,connectionId:o,dataType:s.type},{data:x,isLoading:y,isFetching:m,isError:b}=t.useFilterQuery(d),p=E.useMemo(()=>{var v;return d.column?(v=x==null?void 0:x.records)==null?void 0:v.map(M=>{let N=d.column.split(".").slice(-1)[0].replace(/"/g,"");return M[N]===void 0&&(N=N.toLowerCase()),{id:M[N],value:M[N]}}):[]},[x,d.column]);function w(S){const v=S.map(M=>M.id);h(s.name,v)}function f(){return y||m?e.jsx(t.Skeleton,{style:{borderRadius:n==null?void 0:n.controlInputRadius},className:"h-8 min-w-60 bg-foreground/10"}):b?e.jsx("div",{className:"flex h-8 min-w-60 items-center bg-muted px-2 text-sm",children:"Error"}):e.jsx(t.ComboBox2,{options:p,onChange:w,selectedOptions:u,selectAllChecked:!1,onSelectAllCheckedChange:()=>{}})}return e.jsx($e,{className:"w-60",id:s.id,sortableType:a,column:s,children:f()})}function Ca({column:s,sortableType:a}){const[n,r]=E.useState(!1),{selectedConnectionId:o,selectedDatabaseName:l,selectedTableName:i}=W(),c={column:s.name,sql:s.sql,id:s.name,connectionId:o,title:"",dataType:s.type},{isLoading:u,isFetching:h,isError:d,data:x}=t.useFilterQuery(c),y=x==null?void 0:x.records,{dateRange:m,setDateRange:b,initialDateRange:p}=t.useDateRangeFromRecords(y),{updateEditorFilterValue:w}=t.useEditorActions();function f(M){var A,_;const N={gte:(A=M==null?void 0:M.from)==null?void 0:A.toISOString(),lte:(_=M==null?void 0:M.to)==null?void 0:_.toISOString()};w(s.name,N)}function S(){w(s.name,null,!0),b(p)}function v(){return u||h?e.jsx("div",{children:e.jsx(t.Skeleton,{className:"h-8 w-72 bg-foreground/10"})}):d?e.jsx("div",{className:"h-8 w-72 bg-muted px-2",children:"Error"}):y?e.jsx(t.DateRangePopover,{title:c.title,open:n,inputClassName:"h-8",setOpen:r,dateRange:m,setDateRange:b,onApply:f,onClear:S}):e.jsx(t.Label,{className:"flex h-8 w-72 items-center bg-muted px-2",children:"No Data"})}return e.jsx($e,{className:"w-72",id:s.id,sortableType:a,column:s,children:v()})}function va({id:s,label:a,columns:n,previewColumns:r,sortableType:o}){const{setNodeRef:l}=t.useDroppable({id:s}),i=t.useDndStore(d=>d.activeId),c={};function u(d){const x=t.isDateDataType(d.type);return d.id===It.id?e.jsx($e,{id:d.id,sortableType:o,column:d,children:e.jsx(Na,{})},d.id):x?e.jsx(Ca,{droppableId:s,sortableType:o,column:d},d.id):e.jsx(Sa,{droppableId:s,sortableType:o,column:d},d.id)}const h=i?r:n;return e.jsx(t.SortableContext,{items:n==null?void 0:n.map(d=>d.id),children:e.jsxs("div",{className:"space-y-2 rounded-md border-2 border-dashed p-5",ref:l,style:c,children:[e.jsx(t.Label,{className:"text-sm",children:a}),e.jsx("div",{className:"flex flex-wrap items-center gap-4",children:h==null?void 0:h.map(d=>u(d))})]})})}function Na(){return e.jsx("div",{className:"flex h-8 w-60 items-center space-x-2 rounded-md border border-dashed border-muted-foreground bg-background px-2 py-1 text-sm"})}function wa(){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("section",{className:"size-full px-4 pb-4",children:e.jsx(va,{onRemoveColumn:r,sortableType:Re,id:Fe,label:"Filters",columns:s,previewColumns:a})})}function ka(){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(Ft,{}),e.jsx(Et,{sql:a==null?void 0:a.sql,error:n})]}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(zt,{}),e.jsx(Ot,{variant:"default"})]})]})}function Ia(){const s=E.useRef(null),a=t.useEditorStore(i=>i.isShowingVisual),n=t.useEditorStore(i=>i.showAIDialog),r=t.useEditorStore(i=>i.isDevMode);E.useEffect(()=>{var i,c;n?(i=s.current)==null||i.resize(0):(c=s.current)==null||c.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(wn,{})}),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:e.jsx(da,{})})}),!n&&e.jsx(t.ResizableHandle,{className:"border"}),e.jsx(t.ResizablePanel,{minSize:40,defaultSize:75,maxSize:100,children:e.jsx(je,{})})]}):e.jsx(je,{})})]})}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(ba,{})})}),!n&&e.jsx(t.ResizableHandle,{}),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(ka,{}),e.jsx(wa,{})]}),e.jsx(t.ResizableHandle,{}),e.jsx(t.ResizablePanel,{minSize:20,defaultSize:80,children:e.jsx(je,{})})]})})]}):e.jsx(je,{})})})}return e.jsx(t.ResizablePanelGroup,{direction:"vertical",className:"min-h-[250px] min-w-full max-w-lg",children:r?o():l()})}const Da=[{title:"Help me write a query for",subtitle:"orders by month"},{title:"Create a bar chart for",subtitle:"sales by category"}];function Ea(){const s=E.useRef(null),a=E.useRef(null),[n,r]=E.useState(!1),[o,l]=E.useState(t.isDevEnv),[i,c]=E.useState(!1),u=t.useEditorStore(q=>q.actions.setCardSql),h=t.useEditorStore(q=>q.actions.setRunSql),d=t.useEditorStore(q=>q.showAIDialog),{setShowAIDialog:x}=t.useEditorActions(),{messages:y,setMessages:m,reload:b,append:p,input:w,setInput:f,isLoading:S,handleAddCurrentTableToScope:v,removeFromCurrentSelections:M,currentAssitantScope:N,handleInputChange:A,handleSubmit:_,stop:R,chatStatus:P,toolStatus:g,llmUsage:D,errorMessage:L}=Lt();t.useAssistantScroll({scrollContainerRef:s,inputRef:a,messages:y}),E.useEffect(()=>{var q;d&&((q=a.current)==null||q.focus())},[d]);function O(q){u(q),h(!0)}function C(q){const I={role:"user",content:q.title+" "+q.subtitle};p(I)}function V(){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(ut,{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:c,children:"System Message"})]})]})}function B(){return e.jsxs("div",{"data-role":"header",children:[e.jsx("div",{className:"text-lg font-semibold",children:"Assistant"}),N&&N.length>0&&e.jsx("div",{className:"mt-2 flex flex-wrap items-center gap-2",children:N==null?void 0:N.map((q,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:q.schemaName||"",tableName:q.tableName||"",modelName:q.datamodelName||"",connectionType:q.connectionType||"",databaseName:q.databaseName||""}),e.jsx("button",{onClick:()=>{M(q)},children:e.jsx(t.X,{className:"size-3 text-muted-foreground hover:text-foreground"})})]},I))}),(N==null?void 0:N.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:v,children:[e.jsx(t.Plus,{className:"mr-2 size-3"}),"Current Table"]})]})]})}const H=(w==null?void 0:w.length)===0&&(y==null?void 0:y.filter(q=>q.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:[B(),e.jsxs("div",{"data-role":"header-actions",className:"flex items-center",children:[V(),e.jsx(t.Button,{className:"h-7 p-2",size:"sm",variant:"ghost",onClick:()=>{m([]),b()},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:y,showTools:o,handleRun:O,showSystemMessage:i}),e.jsx(t.ChatStatus,{status:t.getStatus(P,g),isLoading:S})]})}),H&&e.jsx(t.Placeholders,{onClick:C,placeholders:Da}),e.jsx(t.ChatInput,{onFocus:()=>{v()},stop:R,ref:a,setInput:f,input:w,handleInputChange:A,handleSubmit:_,isLoading:S}),D&&n&&e.jsx("div",{className:"flex h-8 items-center justify-between",children:e.jsxs("div",{className:"text-xs text-muted-foreground",children:["Usage: ",D.promptTokens," prompt tokens,"," ",D.completionTokens," completion tokens,"," ",D.totalTokens," total tokens"]})}),L&&e.jsx("div",{className:"flex items-center justify-between text-xs text-muted-foreground",children:e.jsx("span",{children:L})})]})}function Ta({authToken:s,onSave:a,onClose:n}){const r=E.useRef(null),o=t.useEditorStore(w=>w.showAIDialog),{setAuthToken:l}=t.useDashboardActions(),{setShowAIDialog:i,setOnSave:c,setOnClose:u}=t.useEditorActions(),{handleDragOver:h,handleDragEnd:d,handleDragStart:x,handleDragCancel:y,sensors:m}=dn();E.useEffect(()=>{a&&c(a),n&&u(n)},[a,c,n,u]),E.useEffect(()=>{s&&s.accessToken&&l(s)},[s,l]),E.useEffect(()=>{var w,f;o?((w=r.current)==null||w.resize(40),i(!0)):(i(!1),(f=r.current)==null||f.resize(0))},[o,i]);function b(w){w<1?i(!1):o||i(!0)}function p(){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(Ia,{})}),e.jsx(t.ResizableHandle,{}),e.jsx(t.ResizablePanel,{"data-role":"editor-assistant-panel",ref:r,onResize:b,defaultSize:0,children:e.jsx(Ea,{})})]})}return e.jsx(t.ErrorBoundary,{FallbackComponent:t.Fallback,children:e.jsx(t.DndContext,{sensors:m,onDragStart:x,onDragEnd:d,onDragOver:h,onDragCancel:y,children:e.jsxs("section",{className:"isolate flex h-full grow","data-content":"editor-panel",children:[e.jsx(Dt,{type:"main"}),p()]})})})}function Ma(){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(Ta,{onSave:o,onClose:l})})}function Aa(){const s=t.useEditorStore(l=>l.selectedDatabaseName),a=t.useEditorStore(l=>l.selectedTableName),n=t.useDashboardStore(l=>l.dashboard.filters)||[],{columns:r}=W(),{assignFilter:o}=Jt();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(c=>c.column===t.fmt(l.column_name)&&c.table===a&&c.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(Pe,{column:l}),e.jsx("span",{children:l.column_name})]})},l.column_name)})})}function La(){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(Dt,{type:"filter",ColumnsComponent:()=>e.jsx(Aa,{})})})]})}function Oa(){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 za(){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(Oa,{}),e.jsx(t.DashboardTabs,{})]}),s&&e.jsx("div",{role:"filter-aside-container",className:"flex",children:e.jsx(La,{})})]})}function Fa(){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 Ra({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(Fa,{}),e.jsxs(t.DashboardPanel,{...n,children:[s&&e.jsx(an,{}),e.jsx(Ma,{}),e.jsx(za,{})]})]})]})})}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=wt;exports.SelectComponent=de;exports.Surfboard=Ra;exports.cleanCard=Ct;exports.downloadPdf=Nt;exports.getDashbaordStateWithoutData=Be;exports.useEditorAside=W;
372
+ `),T=new Blob([j],{type:"text/csv"}),k=URL.createObjectURL(T),U=document.createElement("a");U.href=k,U.download=`${a.title}.csv`,U.click()}function H(){const I=`Can you get the documentation for ${a.type} chart?`;m(I)}return e.jsxs("div",{className:"relative isolate flex h-full flex-col py-2 pb-3",children:[(w||f)&&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(ie,{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(Fn,{}),o&&e.jsx(t.IconButton,{tooltip:"Visual Docs",onClick:H,children:e.jsx(ms,{className:"size-4"})}),!["table","custom"].includes(a.type)&&o&&e.jsx(Mn,{})]}),!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:B,children:e.jsx(On,{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:V,children:e.jsx(ws,{strokeWidth:1.5,className:"size-4"})}),e.jsx(t.CopyButton,{text:JSON.stringify(p==null?void 0:p.records,null,2),className:"h-7 w-fit px-1 font-mono text-xs text-muted-foreground/70"})]}),e.jsx(qn,{}),n&&e.jsx(Pn,{})]}),r?O():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(Bn,{})}),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:[(p==null?void 0:p.records)&&(p==null?void 0:p.records.length)>0&&e.jsx(kn,{data:(p==null?void 0:p.records)||[]}),(S||(p==null?void 0:p.error))&&e.jsx("span",{className:"font-mono text-xs",children:(S==null?void 0:S.message)||((q=p==null?void 0:p.error)==null?void 0:q.message)})]})]})]})}function Bn(){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 Pn(){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 Hn(){var p,w;const s=t.useEditorStore(f=>f.card.customCardPreferences),{data:a}=_t(),n=(a==null?void 0:a.plugins)||[],r=t.useEditorStore(f=>f.card),o=t.useEditorStore(f=>f.frame),l=(s==null?void 0:s.visualType)||"single",{setCustomCardPreferences:i}=t.useEditorActions(),{components:c,manifest:u}=t.useCustomVisual((s==null?void 0:s.url)||""),h=(p=u==null?void 0:u.visuals)==null?void 0:p.find(f=>f.name===(s==null?void 0:s.componentName));function d(f,S){if(!s)return;const M={...(s==null?void 0:s.dataInputCardIds)||{},[f]:{cardId:S,hookRef:null}};i({...s,dataInputCardIds:M})}function x(f){var v,M;const S=(v=o==null?void 0:o.cards)==null?void 0:v.filter(N=>{var A;return((A=N==null?void 0:N.customCardPreferences)==null?void 0:A.visualType)!=="multiple"}).map(N=>({value:N.id,label:N.tabTitle||N.title}));return e.jsx("div",{className:"space-y-2",children:(M=f==null?void 0:f.dataInputs)==null?void 0:M.map((N,A)=>{var _,R;return e.jsxs("div",{className:"grid grid-cols-10 gap-2",children:[e.jsx("div",{className:"col-span-4 flex items-center",children:N}),e.jsx(J,{className:"col-span-6 h-8 w-full justify-between",label:"",options:S||[],value:((R=(_=s==null?void 0:s.dataInputCardIds)==null?void 0:_[A])==null?void 0:R.cardId)||"",onValueChange:P=>d(A,P)})]},A+Math.random())})})}function y(f,S,v=[],M=""){var N,A;return s?f==="input"?e.jsx(t.Input,{className:`h-8 w-full ${t.removeRing}`,value:((N=s==null?void 0:s.settings)==null?void 0:N[S])||M,onChange:_=>{i({...s,settings:{...s==null?void 0:s.settings,[S]:_.target.value}})}},S):f==="select"?e.jsx(J,{className:"h-8 w-full",label:"",options:v,value:((A=s==null?void 0:s.settings)==null?void 0:A[S])||M,onValueChange:_=>{i({...s,settings:{...s==null?void 0:s.settings,[S]:_}})}}):null:null}function m(f){const S=Object.entries((f==null?void 0:f.settings)||{});return e.jsx("div",{className:"space-y-3",children:S.map(([v,M])=>e.jsxs("div",{className:"space-y-1",children:[e.jsx(t.Label,{children:M.title}),y(M.ui,v,M.options,M.defaultValue)]},v))})}function b(f){s&&i({...s,visualType:f,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(J,{icon:e.jsx(us,{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:f=>i({...s||{url:"",componentName:""},url:f})}),((s==null?void 0:s.type)==="component"||(s==null?void 0:s.type)===void 0)&&e.jsx(t.Tabs,{value:l,onValueChange:b,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:c&&e.jsx(J,{icon:e.jsx(bs,{className:"h-3.5 w-3.5"}),className:"h-9 w-full",label:"Select Component",options:(c==null?void 0:c.filter(f=>f.type===l).map(f=>({value:f.name,label:f.name})))||[],value:s.componentName,onValueChange:f=>{console.log("changing value",f),i({...s,componentName:f})}})})]})})]}),((w=r==null?void 0:r.customCardPreferences)==null?void 0:w.componentName)&&e.jsxs(t.AccordionItem,{className:"border-none",value:"component-settings",children:[e.jsx(t.AccordionTrigger,{children:"Settings"}),e.jsxs(t.AccordionContent,{children:[h&&h.dataInputs&&e.jsxs("div",{className:"space-y-3",children:[e.jsx(t.Label,{children:"Input Mapping"}),e.jsx("div",{className:"px-2",children:x(h)})]}),h&&h.settings&&e.jsx("div",{className:"space-y-3",children:e.jsx("div",{className:"px-2",children:m(h)})})]})]})]})}function le(){const[s,a]=E.useState([]),n=t.useEditorStore(h=>h.card.preferences),{setFilterOnClickColumnIndex:r,setCardPreferences:o}=t.useEditorStore(h=>h.actions),l=t.useEditorStore(h=>h.queryResultColumns);t.useEditorStore(h=>{var d;return(d=h.card.preferences)==null?void 0:d.filterOnClickColumnIndex}),E.useEffect(()=>{l&&a(new Array(l.length).fill(!1))},[l]);function i(h,d){var x,y;d?n!=null&&n.onClickFilter&&((x=n==null?void 0:n.onClickFilter)==null?void 0:x.length)>0?o({...n,onClickFilter:[...n.onClickFilter,{columnIndex:h,expression:""}]}):o({...n,onClickFilter:[{columnIndex:h,expression:""}]}):(o({...n,onClickFilter:(y=n==null?void 0:n.onClickFilter)==null?void 0:y.filter(m=>m.columnIndex!==h)}),a(m=>{const b=[...m];return b[h]=!1,b}))}function c(h,d){var y;const x=(y=n==null?void 0:n.onClickFilter)==null?void 0:y.map(m=>m.columnIndex===h?{...m,expression:d.target.value}:m);o({...n,onClickFilter:x})}function u(h){var d,x,y,m;if(s!=null&&s[h]||(x=(d=n==null?void 0:n.onClickFilter)==null?void 0:d.find(b=>b.columnIndex===h))!=null&&x.expression)return e.jsx(t.Input,{value:(m=(y=n==null?void 0:n.onClickFilter)==null?void 0:y.find(b=>b.columnIndex===h))==null?void 0:m.expression,onChange:b=>c(h,b),type:"text",className:"h-9 w-full font-mono text-xs focus-visible:ring-0 focus-visible:ring-ring focus-visible:ring-offset-0",placeholder:"Expression"})}return e.jsxs("div",{className:"space-y-2",children:[e.jsx(t.Label,{children:"On Click"}),l==null?void 0:l.map((h,d)=>{var x,y;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(m=>m.columnIndex===d)),onCheckedChange:m=>i(d,m)}),e.jsx("label",{className:"text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70",children:h}),e.jsx("div",{className:"flex items-center gap-2",children:((y=n==null?void 0:n.onClickFilter)==null?void 0:y.find(m=>m.columnIndex===d))&&e.jsx(t.Pencil,{onClick:()=>{a(m=>{const b=[...m];return b[d]=!m[d],b})},className:"invisible size-3 cursor-pointer text-gray-400 group-hover:visible"})})]}),u(d)]})},h)})]})}function Gn({idx:s}){var c;const a=t.useEditorStore(u=>{var h;return(h=u.card)==null?void 0:h.preferences}),n=t.useEditorStore(u=>{var h;return(h=u.card.preferences)==null?void 0:h.datasetOptions}),r=t.useEditorStore(u=>u.actions.setCardPreferences),o=(c=a==null?void 0:a.chartOptions)==null?void 0:c.indexAxis,l=n==null?void 0:n.find(u=>u.idx===s);function i(u,h){(u==="end"||u==="start")&&t.getContrastColor(t.getCanvasBackgroundColor());const d={display:u!=="none",align:u,anchor:u,clamp:!0};if(!l)r({...a,datasetOptions:[...n||[],{idx:h,datalabels:d}]});else{const x={...l};x.datalabels=d;const y=n==null?void 0:n.map(m=>m.idx===h?x:m);r({...a,datasetOptions:y})}}return e.jsxs(t.Popover,{children:[e.jsx(t.PopoverTrigger,{children:e.jsx(Ks,{className:"size-4 rotate-[135deg] cursor-pointer text-muted-foreground hover:text-foreground"})}),e.jsx(t.PopoverContent,{className:"w-fit px-2 py-1",children:e.jsxs("div",{className:"flex gap-1",children:[e.jsx("button",{onClick:()=>i("none",s),className:"h-7 p-1 text-xs font-normal",children:e.jsx(t.X,{className:"size-3.5"})}),e.jsx("button",{onClick:()=>i("start",s),className:"h-7 p-1 text-xs font-normal",children:e.jsx(As,{className:t.cn("h-4 w-4",{"rotate-90":o==="y"})})}),e.jsx("button",{onClick:()=>i("center",s),className:"h-7 p-1 text-xs font-normal",children:e.jsx(Os,{className:t.cn("h-4 w-4",{"rotate-90":o==="y"})})}),e.jsx("button",{onClick:()=>i("end",s),className:"h-7 p-1 text-xs font-normal",children:e.jsx(Ls,{className:t.cn("h-4 w-4",{"rotate-90":o==="y"})})})]})})]})}function Ut(){const s=t.useEditorStore(i=>i.card),{data:a}=t.useDashboardCardQuery(s),{metricKeys:n,dimensionKeys:r,keys:o}=t.getKeys((a==null?void 0:a.records)||[]);let l=n;if(["stackedBar","stackedLine"].includes(s.type)){const i=t.pivotData({dataArray:(a==null?void 0:a.records)||[],groupKey:r[0],pivotKey:r[1],valueKey:l[0]}),{metricKeys:c}=t.getKeys(i);l=c}return{transformedMetricKeys:l,dimensionKeys:r,keys:o,defaultMetricKeys:n}}function $t(){const s=t.useEditorStore(u=>u.card),a=t.useEditorStore(u=>{var h,d,x;return(x=(d=(h=u==null?void 0:u.card)==null?void 0:h.preferences)==null?void 0:d.chartOptions)==null?void 0:x.indexAxis}),{data:n}=t.useDashboardCardQuery(s),r=a==="y"?"Metric":"Dimension",o=a==="y"?"Dimension":"Metric",{dimensionKeys:l,transformedMetricKeys:i,keys:c}=Ut();return c.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:l.map(u=>e.jsx("p",{className:"rounded-md bg-muted/70 px-3 py-2 hover:bg-muted",title:u,children:Qt(u)},u))})]}),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:i.map((u,h)=>e.jsx(Kt,{className:"bg-muted/70 px-3 py-2 hover:bg-muted",iconClassName:"invisible group-hover:visible",col:u,idx:h},u))})]})]})}function Qt(s,a=30){return s.length>a?s.slice(0,a)+"...":s}function Kt({col:s,idx:a,className:n,iconClassName:r,children:o}){const l=t.useEditorStore(d=>{var x;return(x=d.card)==null?void 0:x.preferences}),i=t.useEditorStore(d=>{var x,y;return(y=(x=d.card)==null?void 0:x.preferences)==null?void 0:y.datasetOptions}),c=i==null?void 0:i.find(d=>d.idx===a),{setCardPreferences:u}=t.useEditorStore(d=>d.actions);function h(d){if(!c)u({...l,datasetOptions:[...i||[],{idx:a,type:d==="area"?"line":d,fill:d==="area"?"origin":""}]});else{const x={...c};x.type=d==="area"?"line":d,x.fill=d==="area"?"origin":"";const y=i==null?void 0:i.map(m=>m.idx===a?x:m);u({...l,datasetOptions:y})}}return e.jsxs("div",{className:t.cn("group flex items-center justify-between gap-2 rounded-md",n),children:[o||e.jsx("p",{title:s,children:Qt(s)}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(Ve,{onClick:()=>h("bar"),className:t.cn("size-4 cursor-pointer text-muted-foreground hover:text-foreground",r)}),e.jsx(_e,{onClick:()=>h("line"),className:t.cn("size-4 cursor-pointer text-muted-foreground hover:text-foreground",r)}),e.jsx(fs,{onClick:()=>h("area"),className:t.cn("size-4 cursor-pointer text-muted-foreground hover:text-foreground",r)}),e.jsx(Gn,{idx:a})]})]})}function Jt(){const s=t.useEditorStore(m=>m.selectedConnectionId),a=t.useEditorStore(m=>m.selectedDatamodelId),n=t.useEditorStore(m=>m.selectedDatabaseName),r=t.useEditorStore(m=>m.selectedSchemaName),o=t.useEditorStore(m=>m.selectedTableName),l=t.useDashboardStore(m=>m.dashboard.filters)||[],i=t.useDashboardStore(m=>m.actions.addFilter),c=t.useDashboardStore(m=>m.actions.removeFilter),{removeFilterValues:u}=t.useDashboardActions(),{modelItems:h,tableName:d,connectionType:x}=W();function y(m,b="dashboard"){var _;const p=t.fmt(m.column_name),w=t.fmt(n||""),f=t.fmt(r||""),S=t.fmt(d);let v=t.getQualifiedTableName({schemaName:f,tableName:S,connectionType:x,databaseName:w}),M=`${v}.${p}`;const N=(_=h==null?void 0:h.find(R=>R.id===a))==null?void 0:_.name;a&&a!=="none"&&(M=`${t.DATAMODEL_NAMESPCACE}.${N}.${p}`,v=`${t.DATAMODEL_NAMESPCACE}.${N}`);const A=l==null?void 0:l.find(R=>R.column===M&&R.table===S&&(R.database===w||R.database===n));if(A)u(A.id),c(A.id);else{const R=t.v4();return d==="api"&&s?(i({location:b,id:R,column:M,title:m.column_name,dataType:m.data_type,table:"api",database:"",connectionId:s,operation:"in",sql:t.getDefaultFilterSql(m.data_type,v,p)}),R):(i({id:R,location:b,column:M,title:m.column_name,dataType:m.data_type,table:o||"",database:n||"",connectionId:s||"",operation:"in",sql:t.getDefaultFilterSql(m.data_type,v,p)}),R)}}return{assignFilter:y}}function he(){const s=t.useDashboardStore(c=>c.dashboard.filters),a=t.useEditorStore(c=>c.frame),{setFrame:n}=t.useEditorActions(),{columns:r}=W(),{assignFilter:o}=Jt();function l(c){const u=o(c,"frame");n({...a,filterId:u})}const i=s==null?void 0:s.find(c=>c.id===a.filterId);return e.jsxs("div",{className:"space-y-3",children:[e.jsx(t.Label,{children:"Card Filter"}),e.jsx(Un,{onSelect:l,columns:r}),i&&e.jsx(t.FilterHeader,{filter:i})]})}function Un({columns:s,onSelect:a}){var i;const[n,r]=ue.useState(!1),[o,l]=ue.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(c=>c.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(c=>e.jsxs(t.CommandItem,{value:c.column_name,onSelect:u=>{const h=u===o?"":u;l(h),r(!1),h&&a(c)},children:[c.column_name,e.jsx(t.CheckIcon,{className:t.cn("ml-auto h-4 w-4",o===c.column_name?"opacity-100":"opacity-0")})]},c.column_name))})]})]})})]})}function $n({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($t,{})})]}),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(le,{}),e.jsx(he,{})]})]})]})})}function Ue(){var o,l,i;const s=t.useEditorStore(c=>c.card.type),a=t.useEditorStore(c=>c.card.preferences),{setCardPreferences:n}=t.useEditorStore(c=>c.actions);function r(c){var d;const u={datalabels:{display:c!=="none",align:c,anchor:c,clamp:!0}},h={...a,chartOptions:{...a==null?void 0:a.chartOptions,plugins:{...(d=a==null?void 0:a.chartOptions)==null?void 0:d.plugins,...u}}};n(h),console.log(c)}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 Qn({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(Ue,{})})]}),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(le,{}),e.jsx(he,{})]})]})]})})}const Kn={datasets:[{type:"line",label:"Sum_sales",data:[]},{type:"bar",label:"Sum_profit",data:[]}]},Jn={datasets:[{fill:"origin",type:"line",label:"Sum_sales",data:[]}]};function Wn(){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:Yn(s)}),!["kpi"].includes(s)&&e.jsxs("div",{className:"space-y-4",children:[e.jsx(Ue,{}),e.jsx(le,{}),e.jsx(he,{})]})]})}function Yn(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(Kn,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(Jn,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 Zn(){var u,h,d,x,y;const s=t.useEditorStore(m=>m.card.preferences),a=t.useEditorStore(m=>m.actions.setCardPreferences),n=t.useEditorStore(m=>m.actions.setNumberFormat);t.useEditorStore(m=>{var b,p;return(p=(b=m.card.preferences)==null?void 0:b.formatNumber)==null?void 0:p.decimalPlaces});const r=t.useEditorStore(m=>{var b,p;return(p=(b=m.card.preferences)==null?void 0:b.formatNumber)==null?void 0:p.locale}),o=t.useEditorStore(m=>{var b,p;return(p=(b=m.card.preferences)==null?void 0:b.formatNumber)==null?void 0:p.currency});t.useEditorStore(m=>m.actions.setFilterOnClickField);const l=t.useEditorStore(m=>{var b,p;return(p=(b=m.card.preferences)==null?void 0:b.formatNumber)==null?void 0:p.colorRanges})||[],i=t.useEditorStore(m=>m.actions.setColorRanges),c=[...new Set(t.LOCALE_CURRENCY_PAIRS.map(m=>m.currency))];return e.jsxs("div",{children:[e.jsxs("div",{className:"mb-3 flex items-center gap-2",children:[e.jsx(t.Checkbox,{checked:!!((u=s==null?void 0:s.formatNumber)!=null&&u.enabled),onCheckedChange:m=>{a({...s,formatNumber:{...s==null?void 0:s.formatNumber,enabled:m}})}}),e.jsx(t.Label,{children:"Format Number"})]}),((h=s==null?void 0:s.formatNumber)==null?void 0:h.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:m=>{var b,p,w;return n(((b=s==null?void 0:s.formatNumber)==null?void 0:b.decimalPlaces)||0,((p=s==null?void 0:s.formatNumber)==null?void 0:p.currency)||"",m,((w=s==null?void 0:s.formatNumber)==null?void 0:w.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(m=>e.jsx(t.SelectItem,{value:m.locale,children:m.locale},m.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:m=>{var b,p,w;console.log("currency",m),n(((b=s==null?void 0:s.formatNumber)==null?void 0:b.decimalPlaces)||0,m==="none"?"":m,((p=s==null?void 0:s.formatNumber)==null?void 0:p.locale)||"",((w=s==null?void 0:s.formatNumber)==null?void 0:w.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"),c.map(m=>e.jsx(t.SelectItem,{value:m,children:m},m))]})})]})]})]}),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=(d=s==null?void 0:s.formatNumber)==null?void 0:d.decimalPlaces)==null?void 0:x.toString())||"0",onValueChange:m=>{var b,p,w;return n(Number(m),((b=s==null?void 0:s.formatNumber)==null?void 0:b.currency)||"",((p=s==null?void 0:s.formatNumber)==null?void 0:p.locale)||"",((w=s==null?void 0:s.formatNumber)==null?void 0:w.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(m=>e.jsx(t.SelectItem,{value:m,children:m},m))})]})]}),e.jsxs("div",{className:"w-full space-y-1",children:[e.jsx(t.Label,{children:"Suffix"}),e.jsx(t.Input,{value:((y=s==null?void 0:s.formatNumber)==null?void 0:y.suffix)||"",className:"h-8 font-mono text-xs focus-visible:ring-0 focus-visible:ring-ring focus-visible:ring-offset-0",placeholder:"K, M, B, %",onChange:m=>{var b,p,w;return n(((b=s==null?void 0:s.formatNumber)==null?void 0:b.decimalPlaces)||0,((p=s==null?void 0:s.formatNumber)==null?void 0:p.currency)||"",((w=s==null?void 0:s.formatNumber)==null?void 0:w.locale)||"",m.target.value)}})]})]})]})}),e.jsx(t.Separator,{className:"my-3"}),e.jsx(t.ColorFormat,{colorRanges:l,setColorRanges:i})]})]})}function Xn(){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(Zn,{})}),e.jsx("div",{}),e.jsx("div",{})]})}function Ae({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 ea=[{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"}],ta=["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"],sa=ta.map(s=>({label:s,value:s}));function na(){var u,h,d,x,y,m,b,p,w,f,S,v,M,N,A,_,R,P;const s=t.useEditorStore(g=>g.card),a=(h=(u=s==null?void 0:s.preferences)==null?void 0:u.mapVisualOptions)==null?void 0:h.topoJsonUrl,[n,r]=E.useState(((x=(d=s==null?void 0:s.preferences)==null?void 0:d.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(g=>({label:g,value:g}))||[],c=[{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(Ae,{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(Ae,{open:!0,summary:"Settings",children:e.jsxs("div",{className:"space-y-3 px-2",children:[e.jsx(J,{className:"h-9",options:c,onValueChange:g=>{console.log("value",g),o({...s.preferences,mapVisualOptions:{topoJsonUrl:g}})},value:a||"",label:"Select Map"}),a==="custom"&&e.jsx(t.Input,{onChange:g=>{r(g.target.value)},onBlur:()=>{var g;console.log("onBlur",n),o({...s.preferences,mapVisualOptions:{...(g=s.preferences)==null?void 0:g.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(J,{className:"h-9",options:i,value:((m=(y=s.preferences)==null?void 0:y.mapVisualOptions)==null?void 0:m.objectKey)||"",label:"Map Object",onValueChange:g=>{var D;o({...s.preferences,mapVisualOptions:{...(D=s.preferences)==null?void 0:D.mapVisualOptions,objectKey:g}})}})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(t.Label,{children:"Projection"}),e.jsx(J,{className:"h-9",options:ea,value:((p=(b=s.preferences)==null?void 0:b.mapVisualOptions)==null?void 0:p.projection)||"",label:"Projection",onValueChange:g=>{var D;o({...s.preferences,mapVisualOptions:{...(D=s.preferences)==null?void 0:D.mapVisualOptions,projection:g}})}})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(t.Label,{children:"Colors"}),e.jsx(J,{className:"h-9",options:sa,value:((f=(w=s.preferences)==null?void 0:w.mapVisualOptions)==null?void 0:f.colorScale)||"",label:"Select Color Scale",onValueChange:g=>{var D;o({...s.preferences,mapVisualOptions:{...(D=s.preferences)==null?void 0:D.mapVisualOptions,colorScale:g}})}})]})]})]})}),e.jsx(t.Separator,{className:"my-4"}),e.jsx(Ae,{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:((v=(S=s.preferences)==null?void 0:S.mapVisualOptions)==null?void 0:v.projectionScale)||1,onChange:g=>{var D;o({...s.preferences,mapVisualOptions:{...(D=s.preferences)==null?void 0:D.mapVisualOptions,projectionScale:Number(g.target.value)}})}}),e.jsx(t.Label,{children:"X"}),e.jsx(t.Input,{className:`h-9 w-full ${t.removeRing}`,type:"number",step:10,value:((A=(N=(M=s.preferences)==null?void 0:M.mapVisualOptions)==null?void 0:N.projectionOffset)==null?void 0:A[0])||0,onChange:g=>{var D,L,O,C;o({...s.preferences,mapVisualOptions:{...(D=s.preferences)==null?void 0:D.mapVisualOptions,projectionOffset:[Number(g.target.value),((C=(O=(L=s.preferences)==null?void 0:L.mapVisualOptions)==null?void 0:O.projectionOffset)==null?void 0:C[1])||0]}})}}),e.jsx(t.Label,{children:"Y"}),e.jsx(t.Input,{className:`h-9 w-full ${t.removeRing}`,type:"number",step:10,value:((P=(R=(_=s.preferences)==null?void 0:_.mapVisualOptions)==null?void 0:R.projectionOffset)==null?void 0:P[1])||0,onChange:g=>{var D,L,O,C;o({...s.preferences,mapVisualOptions:{...(D=s.preferences)==null?void 0:D.mapVisualOptions,projectionOffset:[((C=(O=(L=s.preferences)==null?void 0:L.mapVisualOptions)==null?void 0:O.projectionOffset)==null?void 0:C[0])||0,Number(g.target.value)]}})}})]})}),e.jsx(t.Separator,{className:"my-4"}),e.jsx(le,{})]})}function aa(){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 ye({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(Ue,{}),s==="text"&&e.jsx(aa,{})]})]}),!["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(le,{}),e.jsx(he,{})]})]})]})})}function ra(){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(J,{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($t,{})]})]}),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(le,{}),e.jsx(he,{})]})]})]})})}function oa({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(le,{}),e.jsx(he,{})]})]})}),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 ia=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."]})]}),la=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."]})]}),ca=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 da(){const s=t.useEditorStore(n=>n.card.type);function a(n){switch(n){case"stackedBar":case"stackedLine":return e.jsx(ra,{});case"pyramid":return e.jsx(ye,{docContent:ia,cardType:n});case"kpi":return e.jsx(Xn,{});case"line":case"bar":return e.jsx($n,{cardType:n});case"range":return e.jsx(ye,{docContent:la,cardType:n});case"pie":case"doughnut":case"polarArea":case"radar":return e.jsx(ye,{cardType:n});case"bubble":case"scatter":return e.jsx(Qn,{cardType:n});case"table":return e.jsx(oa,{cardType:n});case"text":return e.jsx(ye,{docContent:ca,cardType:n,suffix:"Visual"});case"map":return e.jsx(na,{});case"custom":return e.jsx(Hn,{});default:return e.jsx(Wn,{})}}return e.jsxs(t.ScrollArea,{className:"h-full w-full text-sm",children:[a(s),e.jsx(t.ScrollBar,{orientation:"horizontal"})]})}function Wt({label:s,column:a,functions:n,onFunctionChange:r}){let o=n[0];"aggregate"in a?o=n.find(i=>i.value===a.aggregate)||n[0]:"granularity"in a&&(o=n.find(i=>i.value===a.granularity)||n[0]);function l(i){r(i)}return e.jsx(J,{className:"flex h-8 w-8 justify-center overflow-clip rounded-none border-none bg-muted px-0 [&>svg]:hidden",icon:o.logo,options:n,value:o.value,onValueChange:i=>l(i),label:s,showPlaceholderLabel:!1})}const ua=[{label:"Sum",value:"SUM",logo:e.jsx(yt,{className:"size-3.5"})},{label:"Count",value:"COUNT",logo:e.jsx(pt,{className:"size-3.5"})},{label:"Unique",value:"DISTINCT",logo:e.jsx(ks,{className:"size-3.5"})},{label:"Average",value:"AVG",logo:e.jsx(os,{className:"size-3.5"})},{label:"Min",value:"MIN",logo:e.jsx(at,{className:"size-3.5"})},{label:"Max",value:"MAX",logo:e.jsx(t.ArrowUp,{className:"size-3.5"})}];function ma({column:s}){const{updateMetricColumn:a}=t.useEditorActions();let n=ua;t.isTextDataType(s.type)&&(n=n.filter(o=>["COUNT","DISTINCT"].includes(o.value))),t.isNumberDataType(s.type)&&(n=n.filter(o=>!["DISTINCT"].includes(o.value)));function r(o){const l={...s,aggregate:o,label:xe(s.name,o)};a(s.id,l)}return e.jsx(Wt,{column:s,functions:n,onFunctionChange:o=>r(o),label:"Aggregation"})}const ha=[{label:"Day (D)",value:"day",logo:e.jsx(t.Label,{className:"cursor-pointer text-xs",children:"D"})},{label:"Week (W)",value:"week",logo:e.jsx(t.Label,{className:"cursor-pointer text-xs",children:"W"})},{label:"Month (M)",value:"month",logo:e.jsx(t.Label,{className:"cursor-pointer text-xs",children:"M"})},{label:"Year (Y)",value:"year",logo:e.jsx(t.Label,{className:"cursor-pointer text-xs",children:"Y"})}];function pa({column:s}){const{updateGroupByColumn:a}=t.useEditorActions();function n(r){const o={...s,granularity:r,label:Ce(s.name,r)};a(s.id,o)}return e.jsx(Wt,{column:s,functions:ha,onFunctionChange:r=>n(r),label:"Granularity"})}function xa({col:s,onChange:a,droppableId:n}){const{columns:r}=He(),o=E.useMemo(()=>{let c=[];(n===ae||n===oe)&&(c=r);const u=c==null?void 0:c.filter(h=>h.column_name!==s.name);return u==null?void 0:u.map(h=>({id:h.column_name,value:h.column_name}))},[r,n,s.name]),l=[{id:s.name,value:s.name}];function i(c){const u=r==null?void 0:r.find(h=>{var d;return h.column_name===((d=c[0])==null?void 0:d.id)});u&&a(u)}return o!=null&&o.length?e.jsx(t.ComboBox2,{multiple:!1,options:o,selectedOptions:l,onChange:i,selectAllChecked:!1,onSelectAllCheckedChange:()=>{},inputClassName:"border-none bg-muted px-0"}):e.jsx("input",{disabled:!0,type:"text",className:"overflow-hidden truncate text-ellipsis whitespace-nowrap bg-muted text-sm",value:s.name})}function Yt({children:s,className:a,delayDuration:n}){return e.jsx(t.TooltipProvider$1,{children:e.jsxs(t.Tooltip,{delayDuration:n,children:[e.jsx(t.TooltipTrigger,{asChild:!0,children:e.jsx("span",{className:t.cn("overflow-hidden text-ellipsis whitespace-nowrap",a),children:s})}),e.jsx(t.TooltipContent,{children:s})]})})}function fa({column:s}){const{updateMetricColumn:a}=t.useEditorActions(),{transformedMetricKeys:n,dimensionKeys:r}=Ut();console.log(n,r);const o=n.find(i=>i===s.label||i===s.name),l=o?n.indexOf(o):-1;return e.jsx("div",{className:"space-y-2",children:o&&e.jsx(Kt,{idx:l,col:o,children:e.jsx(t.Editable,{className:"w-[130px]",text:s.label||"",placeholder:"Enter label",onSave:i=>{a(s.id,{...s,label:i||s.name})},children:e.jsx(Yt,{className:"w-[130px]",children:s.label||s.name})})})})}function ga({column:s,type:a,onRemoveColumn:n,droppableId:r}){const[o,l]=E.useState(!1),{updateGroupByColumn:i,updateMetricColumn:c}=t.useEditorActions(),{attributes:u,listeners:h,setNodeRef:d,transform:x,transition:y,isDragging:m}=t.useSortable({id:s.id,data:{type:a}}),b=x?{opacity:m?.5:void 0,transform:t.CSS.Translate.toString(x),transition:y}:void 0,p=t.isTextDataType(s.type);function w(N){const A=t.isNumberDataType(N.data_type),_=t.isTextDataType(N.data_type),R=t.isDateDataType(N.data_type),P=A?"number":_?"string":R?"date":"string";if(r===ae&&_){const g={id:s.id,name:N.column_name,type:P,role:"groupby"};i(s.id,g)}if(r===ae&&R){const g={id:s.id,name:N.column_name,type:P,role:"groupby",label:Ce(N.column_name,"month"),granularity:"month"};i(s.id,g)}if(r===oe){const g={id:s.id,name:N.column_name,type:P,role:"metric",label:xe(N.column_name,"SUM"),aggregate:A?"SUM":"COUNT"};c(s.id,g)}}function f(){if(r===oe)return e.jsx("div",{"data-setting-container":"",className:"mt-1.5 max-h-32 overflow-y-auto rounded-md border border-border p-3 text-sm",children:e.jsx(fa,{column:s})})}function S(){const N=t.isDateDataType(s.type);if(r===oe)return e.jsx(ma,{column:s});if(r===ae&&N)return e.jsx(pa,{column:s})}function v(){return e.jsx("div",{className:t.cn("grow",{"pl-3":r===ae&&p}),children:e.jsx(xa,{col:s,onChange:w,droppableId:r})})}function M(){return e.jsx("div",{"data-setting-actions":"",className:"flex h-full items-center gap-2",children:e.jsx("button",{onClick:()=>l(!o),children:o?e.jsx($s,{className:t.cn("size-3 cursor-pointer items-center justify-center rounded-r-sm text-muted-foreground")}):e.jsx(mt,{className:t.cn("size-3 cursor-pointer items-center justify-center rounded-r-sm text-muted-foreground")})})})}return e.jsx("div",{...h,...u,ref:d,style:b,children:e.jsxs("div",{className:"group flex items-center justify-between gap-2",children:[e.jsxs("div",{className:"grow",children:[e.jsxs("div",{className:"flex h-8 grow items-center justify-between rounded-md bg-muted pl-2",children:[M(),S(),v()]}),o&&f()]}),e.jsx("div",{className:t.cn("opacity-0 transition-opacity duration-200 group-hover:opacity-100",{hidden:o}),children:e.jsx("button",{onClick:()=>n(s.id),children:e.jsx(t.X,{className:"size-3 cursor-pointer text-muted-foreground"})})})]})})}function nt({id:s,label:a,columns:n,previewColumns:r,sortableType:o,onRemoveColumn:l}){const{setNodeRef:i}=t.useDroppable({id:s}),c=t.useDndStore(d=>d.activeId),u={},h=c?r:n;return e.jsx(t.SortableContext,{items:n==null?void 0:n.map(d=>d.id),children:e.jsxs("div",{className:"space-y-2 rounded-md border-2 border-dashed p-4",ref:i,style:u,children:[e.jsx(t.Label,{className:"text-sm",children:a}),e.jsx("div",{className:"space-y-2",children:h==null?void 0:h.map(d=>d.id===It.id?e.jsx(ja,{},d.id):e.jsx(ga,{droppableId:s,type:o,column:d,onRemoveColumn:l},d.id))})]})})}function ja(){return e.jsx("div",{className:"flex h-8 grow items-center space-x-2 rounded-md border border-dashed border-muted-foreground bg-background px-2 py-1 text-sm"})}function Zt({children:s,id:a,type:n}){const{attributes:r,listeners:o,setNodeRef:l,transform:i,transition:c,isDragging:u}=t.useSortable({id:a,data:{type:n}}),h=i?{opacity:u?.5:void 0,transform:t.CSS.Translate.toString(i),transition:c}:void 0;return e.jsx("div",{...o,...r,ref:l,style:h,children:s})}function ya(){const s=t.useEditorStore(f=>{var S;return(S=f.card.queryConfig)==null?void 0:S.orderBy})||[],a=t.useEditorStore(f=>{var S;return(S=f.card.queryConfig)==null?void 0:S.groupByColumns})||[],n=t.useEditorStore(f=>{var S;return(S=f.card.queryConfig)==null?void 0:S.metricColumns})||[],{addOrderByColumn:r,removeOrderByColumn:o,updateOrderByColumn:l}=t.useEditorActions(),i=[...a,...n];if(i.length===0)return e.jsx(e.Fragment,{});const c=e.jsx(ds,{className:"size-3.5 text-muted-foreground hover:text-foreground"}),u=e.jsx(rs,{className:"size-3.5 text-muted-foreground hover:text-foreground"}),h=e.jsx(cs,{className:"size-3.5 text-muted-foreground hover:text-foreground"}),d=e.jsx(as,{className:"size-3.5 text-muted-foreground hover:text-foreground"}),x=i==null?void 0:i.filter(f=>!s.some(S=>S.columnId===f.id)).map(f=>({id:f.id,value:f.label||f.name}));function y(f,S){const v=m(f);return v?v.role==="metric"?S==="asc"?h:d:S==="asc"?c:u:null}function m(f){return i.find(S=>S.id===f)}function b(f){const S=s.find(v=>v.columnId===f);if(S){const v={...S,direction:S.direction==="asc"?"desc":"asc"};l(v)}}const p=f=>{r({columnId:f.id,direction:"asc"})};function w(f){const S=s.find(v=>v.columnId===f);S&&o(S)}return e.jsx(t.SortableContext,{items:s.map(f=>pe(f.columnId)),children:e.jsxs("div",{className:"space-y-2 rounded-md border border-border p-4 text-sm",children:[e.jsx(t.Label,{className:"text-sm",children:"Sort By"}),x.length>0&&e.jsx("div",{className:"mr-5",children:e.jsx(t.ComboBox2,{multiple:!1,options:x,selectedOptions:[],onChange:f=>p(f[0]),selectAllChecked:!1,onSelectAllCheckedChange:()=>{},inputClassName:"h-8"})}),s.map(f=>{var S,v;return e.jsx(Zt,{id:pe(f.columnId),type:Ge,children:e.jsx("div",{className:"group flex h-8 items-center gap-2 rounded-sm p-0",children:e.jsxs("div",{className:"flex h-full grow items-center justify-between gap-2",children:[e.jsxs("div",{className:"flex h-full grow items-center justify-between gap-2 rounded-sm bg-muted px-2",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(mt,{className:"size-3 cursor-move text-muted-foreground hover:text-foreground"}),e.jsx(Yt,{className:"w-[175px] text-sm",children:((S=m(f.columnId))==null?void 0:S.label)||((v=m(f.columnId))==null?void 0:v.name)})]}),e.jsx("button",{title:f.direction==="asc"?"Ascending":"Descending",onClick:()=>b(f.columnId),className:"rounded-sm p-0",children:y(f.columnId,f.direction)})]}),e.jsx("div",{children:e.jsx("button",{onClick:()=>w(f.columnId),className:"rounded-sm p-0",children:e.jsx(t.X,{className:"size-3 text-muted-foreground opacity-0 transition-opacity duration-200 hover:text-foreground group-hover:opacity-100"})})})]})},f.columnId)},pe(f.columnId))})]})})}function ba(){const s=t.useEditorStore(x=>{var y;return((y=x.card.queryConfig)==null?void 0:y.groupByColumns)||[]}),a=t.useEditorStore(x=>x.card.type),n=t.useDndStore(x=>x.previewGroupByColumns),r=t.useEditorStore(x=>{var y;return((y=x.card.queryConfig)==null?void 0:y.metricColumns)||[]}),o=t.useDndStore(x=>x.previewMetricColumns),{removeColumnFromGroupBy:l,removeColumnFromMetricColumns:i}=t.useEditorActions();function c(x){l(x)}function u(x){i(x)}let h="Group By",d="Metrics";return a==="table"&&(h="Rows",d="Columns"),e.jsxs("div",{className:"flex h-full w-full flex-col gap-4 py-4",children:[e.jsx(Gt,{iconClassName:"size-[19px]"}),e.jsxs(t.CustomScrollArea,{className:"flex min-h-0 grow basis-0 flex-col gap-4 overflow-y-auto",children:[e.jsxs("div",{className:"flex flex-col gap-4 p-4",children:[e.jsx(nt,{onRemoveColumn:c,sortableType:Oe,id:ae,label:h,columns:s,previewColumns:n}),e.jsx(nt,{onRemoveColumn:u,sortableType:ze,id:oe,label:d,columns:r,previewColumns:o}),e.jsx(ya,{})]}),e.jsx(t.ScrollBar,{orientation:"horizontal"})]})]})}function $e({children:s,column:a,id:n,sortableType:r,className:o}){const[l,i]=E.useState(!1),{removeEditorFilter:c}=t.useEditorActions();function u(h){c(h)}return e.jsx(Zt,{id:n,type:r,children:e.jsxs("div",{className:t.cn("group space-y-1 rounded-md bg-muted px-3 py-2",{"border-border":l}),children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(t.Label,{className:"text-sm",children:a.name}),e.jsx("div",{"data-setting-actions":"",className:"invisible flex h-full items-center gap-2 group-hover:visible",children:e.jsx("button",{onClick:()=>u(a),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",!l&&"rounded-b-md",l&&"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:t.cn("grow cursor-pointer overflow-hidden truncate text-ellipsis whitespace-nowrap",o),children:s})]})]})})}function Sa({column:s,sortableType:a}){const n=t.useDashboardStore(S=>S.themeStyle),r=t.useEditorStore(S=>{var v,M;return(M=(v=S.card)==null?void 0:v.queryConfig)==null?void 0:M.filters}),{selectedConnectionId:o,selectedDatabaseName:l,selectedTableName:i}=W(),c=E.useMemo(()=>{var S;return(S=r==null?void 0:r.find(v=>v.filterColumnName===s.name))==null?void 0:S.filterValue},[r,s.name]),u=E.useMemo(()=>Array.isArray(c)?c.map(S=>({id:S,value:S})):[],[c]),{updateEditorFilterValue:h}=t.useEditorActions(),d={column:s.name,sql:s.sql,id:s.name,connectionId:o,dataType:s.type},{data:x,isLoading:y,isFetching:m,isError:b}=t.useFilterQuery(d),p=E.useMemo(()=>{var v;return d.column?(v=x==null?void 0:x.records)==null?void 0:v.map(M=>{let N=d.column.split(".").slice(-1)[0].replace(/"/g,"");return M[N]===void 0&&(N=N.toLowerCase()),{id:M[N],value:M[N]}}):[]},[x,d.column]);function w(S){const v=S.map(M=>M.id);h(s.name,v)}function f(){return y||m?e.jsx(t.Skeleton,{style:{borderRadius:n==null?void 0:n.controlInputRadius},className:"h-8 min-w-60 bg-foreground/10"}):b?e.jsx("div",{className:"flex h-8 min-w-60 items-center bg-muted px-2 text-sm",children:"Error"}):e.jsx(t.ComboBox2,{options:p,onChange:w,selectedOptions:u,selectAllChecked:!1,onSelectAllCheckedChange:()=>{}})}return e.jsx($e,{className:"w-60",id:s.id,sortableType:a,column:s,children:f()})}function Ca({column:s,sortableType:a}){const[n,r]=E.useState(!1),{selectedConnectionId:o,selectedDatabaseName:l,selectedTableName:i}=W(),c={column:s.name,sql:s.sql,id:s.name,connectionId:o,title:"",dataType:s.type},{isLoading:u,isFetching:h,isError:d,data:x}=t.useFilterQuery(c),y=x==null?void 0:x.records,{dateRange:m,setDateRange:b,initialDateRange:p}=t.useDateRangeFromRecords(y),{updateEditorFilterValue:w}=t.useEditorActions();function f(M){var A,_;const N={gte:(A=M==null?void 0:M.from)==null?void 0:A.toISOString(),lte:(_=M==null?void 0:M.to)==null?void 0:_.toISOString()};w(s.name,N)}function S(){w(s.name,null,!0),b(p)}function v(){return u||h?e.jsx("div",{children:e.jsx(t.Skeleton,{className:"h-8 w-72 bg-foreground/10"})}):d?e.jsx("div",{className:"h-8 w-72 bg-muted px-2",children:"Error"}):y?e.jsx(t.DateRangePopover,{title:c.title,open:n,inputClassName:"h-8",setOpen:r,dateRange:m,setDateRange:b,onApply:f,onClear:S}):e.jsx(t.Label,{className:"flex h-8 w-72 items-center bg-muted px-2",children:"No Data"})}return e.jsx($e,{className:"w-72",id:s.id,sortableType:a,column:s,children:v()})}function va({id:s,label:a,columns:n,previewColumns:r,sortableType:o}){const{setNodeRef:l}=t.useDroppable({id:s}),i=t.useDndStore(d=>d.activeId),c={};function u(d){const x=t.isDateDataType(d.type);return d.id===It.id?e.jsx($e,{id:d.id,sortableType:o,column:d,children:e.jsx(Na,{})},d.id):x?e.jsx(Ca,{droppableId:s,sortableType:o,column:d},d.id):e.jsx(Sa,{droppableId:s,sortableType:o,column:d},d.id)}const h=i?r:n;return e.jsx(t.SortableContext,{items:n==null?void 0:n.map(d=>d.id),children:e.jsxs("div",{className:"space-y-2 rounded-md border-2 border-dashed p-5",ref:l,style:c,children:[e.jsx(t.Label,{className:"text-sm",children:a}),e.jsx("div",{className:"flex flex-wrap items-center gap-4",children:h==null?void 0:h.map(d=>u(d))})]})})}function Na(){return e.jsx("div",{className:"flex h-8 w-60 items-center space-x-2 rounded-md border border-dashed border-muted-foreground bg-background px-2 py-1 text-sm"})}function wa(){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("section",{className:"size-full px-4 pb-4",children:e.jsx(va,{onRemoveColumn:r,sortableType:Re,id:Fe,label:"Filters",columns:s,previewColumns:a})})}function ka(){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(Ft,{}),e.jsx(Et,{sql:a==null?void 0:a.sql,error:n})]}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(zt,{}),e.jsx(Ot,{variant:"default"})]})]})}function Ia(){const s=E.useRef(null),a=t.useEditorStore(i=>i.isShowingVisual),n=t.useEditorStore(i=>i.showAIDialog),r=t.useEditorStore(i=>i.isDevMode);E.useEffect(()=>{var i,c;n?(i=s.current)==null||i.resize(0):(c=s.current)==null||c.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(wn,{})}),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:e.jsx(da,{})})}),!n&&e.jsx(t.ResizableHandle,{className:"border"}),e.jsx(t.ResizablePanel,{minSize:40,defaultSize:75,maxSize:100,children:e.jsx(je,{})})]}):e.jsx(je,{})})]})}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-[325px]",defaultSize:25,maxSize:30,children:e.jsx(ba,{})})}),!n&&e.jsx(t.ResizableHandle,{}),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:10,children:[e.jsx(ka,{}),e.jsx(wa,{})]}),e.jsx(t.ResizableHandle,{}),e.jsx(t.ResizablePanel,{minSize:20,defaultSize:80,children:e.jsx(je,{})})]})})]}):e.jsx(je,{})})})}return e.jsx(t.ResizablePanelGroup,{direction:"vertical",className:"min-h-[250px] min-w-full max-w-lg",children:r?o():l()})}const Da=[{title:"Help me write a query for",subtitle:"orders by month"},{title:"Create a bar chart for",subtitle:"sales by category"}];function Ea(){const s=E.useRef(null),a=E.useRef(null),[n,r]=E.useState(!1),[o,l]=E.useState(t.isDevEnv),[i,c]=E.useState(!1),u=t.useEditorStore(q=>q.actions.setCardSql),h=t.useEditorStore(q=>q.actions.setRunSql),d=t.useEditorStore(q=>q.showAIDialog),{setShowAIDialog:x}=t.useEditorActions(),{messages:y,setMessages:m,reload:b,append:p,input:w,setInput:f,isLoading:S,handleAddCurrentTableToScope:v,removeFromCurrentSelections:M,currentAssitantScope:N,handleInputChange:A,handleSubmit:_,stop:R,chatStatus:P,toolStatus:g,llmUsage:D,errorMessage:L}=Lt();t.useAssistantScroll({scrollContainerRef:s,inputRef:a,messages:y}),E.useEffect(()=>{var q;d&&((q=a.current)==null||q.focus())},[d]);function O(q){u(q),h(!0)}function C(q){const I={role:"user",content:q.title+" "+q.subtitle};p(I)}function V(){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(ut,{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:c,children:"System Message"})]})]})}function B(){return e.jsxs("div",{"data-role":"header",children:[e.jsx("div",{className:"text-lg font-semibold",children:"Assistant"}),N&&N.length>0&&e.jsx("div",{className:"mt-2 flex flex-wrap items-center gap-2",children:N==null?void 0:N.map((q,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:q.schemaName||"",tableName:q.tableName||"",modelName:q.datamodelName||"",connectionType:q.connectionType||"",databaseName:q.databaseName||""}),e.jsx("button",{onClick:()=>{M(q)},children:e.jsx(t.X,{className:"size-3 text-muted-foreground hover:text-foreground"})})]},I))}),(N==null?void 0:N.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:v,children:[e.jsx(t.Plus,{className:"mr-2 size-3"}),"Current Table"]})]})]})}const H=(w==null?void 0:w.length)===0&&(y==null?void 0:y.filter(q=>q.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:[B(),e.jsxs("div",{"data-role":"header-actions",className:"flex items-center",children:[V(),e.jsx(t.Button,{className:"h-7 p-2",size:"sm",variant:"ghost",onClick:()=>{m([]),b()},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:y,showTools:o,handleRun:O,showSystemMessage:i}),e.jsx(t.ChatStatus,{status:t.getStatus(P,g),isLoading:S})]})}),H&&e.jsx(t.Placeholders,{onClick:C,placeholders:Da}),e.jsx(t.ChatInput,{onFocus:()=>{v()},stop:R,ref:a,setInput:f,input:w,handleInputChange:A,handleSubmit:_,isLoading:S}),D&&n&&e.jsx("div",{className:"flex h-8 items-center justify-between",children:e.jsxs("div",{className:"text-xs text-muted-foreground",children:["Usage: ",D.promptTokens," prompt tokens,"," ",D.completionTokens," completion tokens,"," ",D.totalTokens," total tokens"]})}),L&&e.jsx("div",{className:"flex items-center justify-between text-xs text-muted-foreground",children:e.jsx("span",{children:L})})]})}function Ta({authToken:s,onSave:a,onClose:n}){const r=E.useRef(null),o=t.useEditorStore(w=>w.showAIDialog),{setAuthToken:l}=t.useDashboardActions(),{setShowAIDialog:i,setOnSave:c,setOnClose:u}=t.useEditorActions(),{handleDragOver:h,handleDragEnd:d,handleDragStart:x,handleDragCancel:y,sensors:m}=dn();E.useEffect(()=>{a&&c(a),n&&u(n)},[a,c,n,u]),E.useEffect(()=>{s&&s.accessToken&&l(s)},[s,l]),E.useEffect(()=>{var w,f;o?((w=r.current)==null||w.resize(40),i(!0)):(i(!1),(f=r.current)==null||f.resize(0))},[o,i]);function b(w){w<1?i(!1):o||i(!0)}function p(){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(Ia,{})}),e.jsx(t.ResizableHandle,{}),e.jsx(t.ResizablePanel,{"data-role":"editor-assistant-panel",ref:r,onResize:b,defaultSize:0,children:e.jsx(Ea,{})})]})}return e.jsx(t.ErrorBoundary,{FallbackComponent:t.Fallback,children:e.jsx(t.DndContext,{sensors:m,onDragStart:x,onDragEnd:d,onDragOver:h,onDragCancel:y,children:e.jsxs("section",{className:"isolate flex h-full grow","data-content":"editor-panel",children:[e.jsx(Dt,{type:"main"}),p()]})})})}function Ma(){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(Ta,{onSave:o,onClose:l})})}function Aa(){const s=t.useEditorStore(l=>l.selectedDatabaseName),a=t.useEditorStore(l=>l.selectedTableName),n=t.useDashboardStore(l=>l.dashboard.filters)||[],{columns:r}=W(),{assignFilter:o}=Jt();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(c=>c.column===t.fmt(l.column_name)&&c.table===a&&c.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(Pe,{column:l}),e.jsx("span",{children:l.column_name})]})},l.column_name)})})}function La(){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(Dt,{type:"filter",ColumnsComponent:()=>e.jsx(Aa,{})})})]})}function Oa(){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 za(){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(Oa,{}),e.jsx(t.DashboardTabs,{})]}),s&&e.jsx("div",{role:"filter-aside-container",className:"flex",children:e.jsx(La,{})})]})}function Fa(){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 Ra({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(Fa,{}),e.jsxs(t.DashboardPanel,{...n,children:[s&&e.jsx(an,{}),e.jsx(Ma,{}),e.jsx(za,{})]})]})]})})}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=wt;exports.SelectComponent=de;exports.Surfboard=Ra;exports.cleanCard=Ct;exports.downloadPdf=Nt;exports.getDashbaordStateWithoutData=Be;exports.useEditorAside=W;
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
- import { c as F, p as Zt, u as E, a as at, b as Ve, d as La, e as Ea, B as W, P as dt, f as Va, g as _a, h as qa, i as Ra, L as G, I as ce, j as ja, k as Ba, l as Pa, m as J, n as Ha, o as Ga, q as Ua, r as Ns, s as Na, t as P, C as Yt, v as Ss, S as Ce, w as Ne, x as Se, y as we, z as ze, A as ke, E as le, T as $a, F as Ke, G as Qe, H as wt, J as Ie, K as Xt, M as kt, N as ea, O as Mt, Q as Ae, R as Ka, U as Dt, V as Qa, W as Oe, X as Sa, Y as qe, Z as f, _ as Ja, $ as Xe, a0 as gt, a1 as ws, a2 as Wa, a3 as Za, a4 as Ya, a5 as Xa, a6 as en, a7 as tn, a8 as an, a9 as nn, aa as sn, ab as rn, ac as ln, ad as on, ae as be, af as ks, ag as Fe, ah as Ge, ai as Le, aj as Ms, ak as Ds, al as Is, am as yt, an as Ue, ao as Os, ap as bt, aq as Ts, ar as Q, as as zs, at as As, au as Fs, av as Gt, aw as cn, ax as It, ay as et, az as dn, aA as vt, aB as ue, aC as Ls, aD as Es, aE as nt, aF as Vs, aG as _s, aH as qs, aI as un, aJ as Rs, aK as Ot, aL as js, aM as Bs, aN as Ps, aO as wa, aP as Hs, aQ as Gs, aR as ta, aS as ve, aT as Us, aU as Ut, aV as Re, aW as oe, aX as je, aY as $s, aZ as Ks, a_ as Qs, a$ as Js, b0 as Ws, b1 as Vt, b2 as Zs, b3 as ka, b4 as Ys, b5 as Ma, b6 as Xs, b7 as er, b8 as tr, b9 as ar, ba as mn, bb as nr, bc as aa, bd as hn, be as sr, bf as rr, bg as it, bh as lr, bi as ir, bj as pn, bk as or, bl as cr, bm as dr, bn as ur, bo as mr, bp as Tt, bq as fn, br as hr, bs as na, bt as sa, bu as Ye, bv as ft, bw as pr, bx as fr, by as gr, bz as ra, bA as gn, bB as yn, bC as xt, bD as yr, bE as Ct, bF as bn, bG as vn, bH as xn, bI as br, bJ as vr, bK as xr, bL as Cr, bM as _e, bN as ae, bO as ne, bP as se, bQ as la, bR as Nr, bS as Sr, bT as wr, bU as kr, bV as Da, bW as Cn, bX as Mr, bY as Dr, bZ as Ir, b_ as Or, b$ as ia, c0 as Nn, c1 as Sn, c2 as oa, c3 as Tr, c4 as wn, c5 as kn, c6 as zr, c7 as Ar, c8 as Fr, c9 as Lr, ca as Er, cb as Vr, cc as _r, cd as qr, ce as Rr, cf as _t, cg as Mn, ch as jr, ci as Br, cj as Pr, ck as Hr, cl as Gr, cm as Ur, cn as $r } from "./chunks/index-OlgLt7aM.js";
2
- import { D as jo, cs as Bo, cq as Po, cq as Ho, cv as Go, cu as Uo, ct as $o, cw as Ko, cx as Qo, cr as Jo, co as Wo, cp as Zo } from "./chunks/index-OlgLt7aM.js";
1
+ import { c as F, p as Zt, u as E, a as at, b as Ve, d as La, e as Ea, B as W, P as dt, f as Va, g as _a, h as qa, i as Ra, L as G, I as ce, j as ja, k as Ba, l as Pa, m as J, n as Ha, o as Ga, q as Ua, r as Ns, s as Na, t as P, C as Yt, v as Ss, S as Ce, w as Ne, x as Se, y as we, z as ze, A as ke, E as le, T as $a, F as Ke, G as Qe, H as wt, J as Ie, K as Xt, M as kt, N as ea, O as Mt, Q as Ae, R as Ka, U as Dt, V as Qa, W as Oe, X as Sa, Y as qe, Z as f, _ as Ja, $ as Xe, a0 as gt, a1 as ws, a2 as Wa, a3 as Za, a4 as Ya, a5 as Xa, a6 as en, a7 as tn, a8 as an, a9 as nn, aa as sn, ab as rn, ac as ln, ad as on, ae as be, af as ks, ag as Fe, ah as Ge, ai as Le, aj as Ms, ak as Ds, al as Is, am as yt, an as Ue, ao as Os, ap as bt, aq as Ts, ar as Q, as as zs, at as As, au as Fs, av as Gt, aw as cn, ax as It, ay as et, az as dn, aA as vt, aB as ue, aC as Ls, aD as Es, aE as nt, aF as Vs, aG as _s, aH as qs, aI as un, aJ as Rs, aK as Ot, aL as js, aM as Bs, aN as Ps, aO as wa, aP as Hs, aQ as Gs, aR as ta, aS as ve, aT as Us, aU as Ut, aV as Re, aW as oe, aX as je, aY as $s, aZ as Ks, a_ as Qs, a$ as Js, b0 as Ws, b1 as Vt, b2 as Zs, b3 as ka, b4 as Ys, b5 as Ma, b6 as Xs, b7 as er, b8 as tr, b9 as ar, ba as mn, bb as nr, bc as aa, bd as hn, be as sr, bf as rr, bg as it, bh as lr, bi as ir, bj as pn, bk as or, bl as cr, bm as dr, bn as ur, bo as mr, bp as Tt, bq as fn, br as hr, bs as na, bt as sa, bu as Ye, bv as ft, bw as pr, bx as fr, by as gr, bz as ra, bA as gn, bB as yn, bC as xt, bD as yr, bE as Ct, bF as bn, bG as vn, bH as xn, bI as br, bJ as vr, bK as xr, bL as Cr, bM as _e, bN as ae, bO as ne, bP as se, bQ as la, bR as Nr, bS as Sr, bT as wr, bU as kr, bV as Da, bW as Cn, bX as Mr, bY as Dr, bZ as Ir, b_ as Or, b$ as ia, c0 as Nn, c1 as Sn, c2 as oa, c3 as Tr, c4 as wn, c5 as kn, c6 as zr, c7 as Ar, c8 as Fr, c9 as Lr, ca as Er, cb as Vr, cc as _r, cd as qr, ce as Rr, cf as _t, cg as Mn, ch as jr, ci as Br, cj as Pr, ck as Hr, cl as Gr, cm as Ur, cn as $r } from "./chunks/index-DysmhXPG.js";
2
+ import { D as jo, cs as Bo, cq as Po, cq as Ho, cv as Go, cu as Uo, ct as $o, cw as Ko, cx as Qo, cr as Jo, co as Wo, cp as Zo } from "./chunks/index-DysmhXPG.js";
3
3
  import { jsxs as r, jsx as e, Fragment as X } from "react/jsx-runtime";
4
4
  import * as Ze from "react";
5
5
  import Ee, { useState as $, useMemo as Pe, useEffect as ie, useRef as tt, useCallback as Dn, Suspense as Kr } from "react";
@@ -5276,7 +5276,7 @@ function ht() {
5276
5276
  return /* @__PURE__ */ r(
5277
5277
  "div",
5278
5278
  {
5279
- className: "relative isolate flex h-full flex-col py-3",
5279
+ className: "relative isolate flex h-full flex-col py-2 pb-3",
5280
5280
  children: [
5281
5281
  (M || y) && /* @__PURE__ */ e("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: /* @__PURE__ */ e($e, { className: "h-8 w-8 animate-spin text-muted-foreground" }) }),
5282
5282
  /* @__PURE__ */ r(
@@ -5902,7 +5902,7 @@ function gs({
5902
5902
  "div",
5903
5903
  {
5904
5904
  className: P(
5905
- "group flex items-center justify-between gap-5 rounded-md",
5905
+ "group flex items-center justify-between gap-2 rounded-md",
5906
5906
  a
5907
5907
  ),
5908
5908
  children: [
@@ -7544,7 +7544,7 @@ function Fa({
7544
7544
  ) });
7545
7545
  }
7546
7546
  function po() {
7547
- return /* @__PURE__ */ e("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" });
7547
+ return /* @__PURE__ */ e("div", { className: "flex h-8 grow items-center space-x-2 rounded-md border border-dashed border-muted-foreground bg-background px-2 py-1 text-sm" });
7548
7548
  }
7549
7549
  function xs({ children: t, id: n, type: a }) {
7550
7550
  const {
@@ -8073,7 +8073,7 @@ function So() {
8073
8073
  oe,
8074
8074
  {
8075
8075
  ref: t,
8076
- className: "flex min-w-[320px]",
8076
+ className: "flex min-w-[325px]",
8077
8077
  defaultSize: 25,
8078
8078
  maxSize: 30,
8079
8079
  children: /* @__PURE__ */ e(go, {})
@@ -8086,7 +8086,7 @@ function So() {
8086
8086
  {
8087
8087
  className: "flex min-h-fit flex-col",
8088
8088
  minSize: 10,
8089
- defaultSize: 20,
8089
+ defaultSize: 10,
8090
8090
  children: [
8091
8091
  /* @__PURE__ */ e(No, {}),
8092
8092
  /* @__PURE__ */ e(Co, {})