react-semaphor 0.0.164 → 0.0.166

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,4 +1,4 @@
1
- "use strict";const t=require("./index-wfFQDxUt.js"),A=require("react");/**
1
+ "use strict";const t=require("./index-qttr0XCK.js"),A=require("react");/**
2
2
  * @license lucide-react v0.379.0 - ISC
3
3
  *
4
4
  * This source code is licensed under the ISC license.
@@ -225,4 +225,4 @@ SELECT label, measure FROM table
225
225
  Table Columns: ${E==null?void 0:E.map(v=>`${v.column_name} | ${v.data_type}`).join(", ")}
226
226
  User SQL: ${R}
227
227
  ${m&&`Base Queries: ${JSON.stringify(m)} `}`,T=` When the user asks for a specific chart please use the following query structure to generate the chart query. Do not make up the column names. Use only the table columns provided above for the query. Replace x-axis, y-axis, and lables with the appropriate column names.
228
- Visual Query Syntax: ${gu}`,{data:S,isLoading:M,isFetching:K,isError:U,refetch:_}=t.useQuery({queryKey:["ai-query"],queryFn:()=>t.getRequest("https://semaphor.cloud/api/v1/ai",(u==null?void 0:u.accessToken)||"",{user_content:`userContent: ${z} ${c?T:""}`}),enabled:!1});function I(v){if(v.toLowerCase().includes("bar"))g("bar");else if(v.toLowerCase().includes("line"))g("line");else if(v.toLowerCase().includes("bubble"))g("bubble");else if(v.toLowerCase().includes("scatter"))g("scatter");else if(v.toLowerCase().includes("stacked"))g("stackedBar");else if(v.toLowerCase().includes("pie"))g("pie");else if(v.toLowerCase().includes("donut")||v.toLowerCase().includes("doughnut"))g("doughnut");else if(v.toLowerCase().includes("radar"))g("radar");else return g("bar"),!1;return!0}A.useEffect(()=>{S&&k(v=>[...v,{role:"ai",content:S.response}])},[S]),A.useEffect(()=>{const v=setTimeout(()=>{var h;a.current&&(a.current.scroll({top:a.current.scrollHeight,behavior:"smooth"}),(h=o.current)==null||h.focus())},100);return()=>clearTimeout(v)},[y]);function N(){r&&(k(v=>[...v,{role:"user",content:r}]),I(r)&&x(!0),i(""),_())}A.useEffect(()=>{s&&(N(),l(!1))},[s,l]);const $={fontFamily:"Arial, sans-serif",lineHeight:1.6,fontSize:15,width:"100%"},W={fontFamily:"monospace",fontSize:14,lineHeight:1.6},B={fontFamily:"Arial, sans-serif",lineHeight:1.6,fontSize:15,padding:"2px 0",marginLeft:20,listStyleType:"disc"},G={p:({node:v,...h})=>t.jsxRuntimeExports.jsx("p",{style:$,...h}),code:({node:v,...h})=>t.jsxRuntimeExports.jsx("code",{className:"rounded-sm bg-muted px-2 py-1 text-sm",...h}),pre:({node:v,...h})=>t.jsxRuntimeExports.jsxs("pre",{className:"space-y-2 rounded-sm bg-muted/50 p-3",style:W,children:[t.jsxRuntimeExports.jsx("code",{className:"whitespace-normal text-sm",children:h.children}),t.jsxRuntimeExports.jsxs("div",{className:"flex justify-start gap-2",children:[t.jsxRuntimeExports.jsx(t.Button,{onClick:L,size:"sm",variant:"outline",children:t.jsxRuntimeExports.jsx(t.ClipboardCopyIcon,{})}),t.jsxRuntimeExports.jsx(t.Button,{onClick:J=>{const re=L(J);re&&(n(!1),p(re),d(!0))},size:"sm",variant:"outline",children:t.jsxRuntimeExports.jsx(t.PlayIcon,{})})]})]}),li:({node:v,...h})=>t.jsxRuntimeExports.jsx("li",{style:B,...h})};function L(v){const h=v.currentTarget.closest("pre");if(!h)return;const J=h.textContent||h.innerText;return navigator.clipboard.writeText(J).then(()=>console.log("Text copied to clipboard")).catch(re=>console.error("Error in copying text: ",re)),J}function F(){return y==null?void 0:y.map((v,h)=>v.role==="user"?t.jsxRuntimeExports.jsxs("div",{className:"flex items-start rounded-md bg-muted p-3 text-sm",children:[t.jsxRuntimeExports.jsx(Li,{className:"mr-2 h-5 w-5"}),t.jsxRuntimeExports.jsx("div",{children:v.content})]},h):v.role==="ai"?t.jsxRuntimeExports.jsx(t.jsxRuntimeExports.Fragment,{children:t.jsxRuntimeExports.jsx(hu,{className:"w-full overflow-auto py-1",components:G,children:S==null?void 0:S.response},h)}):t.jsxRuntimeExports.jsx("div",{},h))}return t.jsxRuntimeExports.jsxs(t.Dialog,{open:e,onOpenChange:n,children:[t.jsxRuntimeExports.jsx(t.DialogTrigger,{asChild:!0,children:t.jsxRuntimeExports.jsx(t.Button,{size:"sm",className:"w-full justify-start border font-normal text-muted-foreground focus-visible:ring-0 focus-visible:ring-offset-0",variant:"secondary",children:"Type your question here..."})}),t.jsxRuntimeExports.jsxs(t.DialogContent,{className:"flex flex-col justify-between overflow-auto sm:max-w-[425px] md:max-h-[625px] md:min-w-[625px]",children:[t.jsxRuntimeExports.jsxs(t.DialogHeader,{children:[t.jsxRuntimeExports.jsx(t.DialogTitle,{children:"Assistant"}),t.jsxRuntimeExports.jsx(t.DialogDescription,{children:"What can I help you with?"})]}),t.jsxRuntimeExports.jsx("div",{ref:a,className:"h-[625px] w-full overflow-auto border-t border-t-muted",children:t.jsxRuntimeExports.jsx("div",{className:"space-y-4 py-2 pr-3",role:"messages",children:F()})}),t.jsxRuntimeExports.jsx("div",{children:t.jsxRuntimeExports.jsxs("div",{className:"flex w-full items-center rounded-md border",children:[t.jsxRuntimeExports.jsx(t.Textarea,{autoFocus:!0,ref:o,onKeyDown:v=>{v.key==="Enter"&&!v.shiftKey&&(v.preventDefault(),i(""),N())},placeholder:"Type your question here...",onFocus:v=>{const h=v.target,J=h.value.length;h.setSelectionRange(J,J)},className:t.cn("max-h-10 min-h-7 resize-none border-none focus-visible:ring-0 focus-visible:ring-ring focus-visible:ring-offset-0"),disabled:M||K,value:r,onChange:v=>i(v.target.value)})," ",t.jsxRuntimeExports.jsx(t.Button,{className:"h-8",size:"sm",variant:"ghost",onClick:N,children:!M&&!K?t.jsxRuntimeExports.jsx(t.PaperPlaneIcon,{}):t.jsxRuntimeExports.jsx(t.LoaderCircle,{className:"mr-2 h-4 w-4 animate-spin text-foreground/50"})})]})})]})]})}var Yr={color:void 0,size:void 0,className:void 0,style:void 0,attr:void 0},tr=A.createContext&&A.createContext(Yr),yu=["attr","size","title"];function Eu(e,n){if(e==null)return{};var r=bu(e,n),i,s;if(Object.getOwnPropertySymbols){var l=Object.getOwnPropertySymbols(e);for(s=0;s<l.length;s++)i=l[s],!(n.indexOf(i)>=0)&&Object.prototype.propertyIsEnumerable.call(e,i)&&(r[i]=e[i])}return r}function bu(e,n){if(e==null)return{};var r={},i=Object.keys(e),s,l;for(l=0;l<i.length;l++)s=i[l],!(n.indexOf(s)>=0)&&(r[s]=e[s]);return r}function xt(){return xt=Object.assign?Object.assign.bind():function(e){for(var n=1;n<arguments.length;n++){var r=arguments[n];for(var i in r)Object.prototype.hasOwnProperty.call(r,i)&&(e[i]=r[i])}return e},xt.apply(this,arguments)}function nr(e,n){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(e);n&&(i=i.filter(function(s){return Object.getOwnPropertyDescriptor(e,s).enumerable})),r.push.apply(r,i)}return r}function dt(e){for(var n=1;n<arguments.length;n++){var r=arguments[n]!=null?arguments[n]:{};n%2?nr(Object(r),!0).forEach(function(i){Su(e,i,r[i])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):nr(Object(r)).forEach(function(i){Object.defineProperty(e,i,Object.getOwnPropertyDescriptor(r,i))})}return e}function Su(e,n,r){return n=ku(n),n in e?Object.defineProperty(e,n,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[n]=r,e}function ku(e){var n=Ru(e,"string");return typeof n=="symbol"?n:String(n)}function Ru(e,n){if(typeof e!="object"||e===null)return e;var r=e[Symbol.toPrimitive];if(r!==void 0){var i=r.call(e,n||"default");if(typeof i!="object")return i;throw new TypeError("@@toPrimitive must return a primitive value.")}return(n==="string"?String:Number)(e)}function Zr(e){return e&&e.map((n,r)=>A.createElement(n.tag,dt({key:r},n.attr),Zr(n.child)))}function Pe(e){return n=>A.createElement(Cu,xt({attr:dt({},e.attr)},n),Zr(e.child))}function Cu(e){var n=r=>{var{attr:i,size:s,title:l}=e,o=Eu(e,yu),a=s||r.size||"1em",u;return r.className&&(u=r.className),e.className&&(u=(u?u+" ":"")+e.className),A.createElement("svg",xt({stroke:"currentColor",fill:"currentColor",strokeWidth:"0"},r.attr,i,o,{className:u,style:dt(dt({color:e.color||r.color},r.style),e.style),height:a,width:a,xmlns:"http://www.w3.org/2000/svg"}),l&&A.createElement("title",null,l),e.children)};return tr!==void 0?A.createElement(tr.Consumer,null,r=>n(r)):n(Yr)}function wu(e){return Pe({tag:"svg",attr:{viewBox:"0 0 448 512"},child:[{tag:"path",attr:{d:"M439.8 200.5c-7.7-30.9-22.3-54.2-53.4-54.2h-40.1v47.4c0 36.8-31.2 67.8-66.8 67.8H172.7c-29.2 0-53.4 25-53.4 54.3v101.8c0 29 25.2 46 53.4 54.3 33.8 9.9 66.3 11.7 106.8 0 26.9-7.8 53.4-23.5 53.4-54.3v-40.7H226.2v-13.6h160.2c31.1 0 42.6-21.7 53.4-54.2 11.2-33.5 10.7-65.7 0-108.6zM286.2 404c11.1 0 20.1 9.1 20.1 20.3 0 11.3-9 20.4-20.1 20.4-11 0-20.1-9.2-20.1-20.4.1-11.3 9.1-20.3 20.1-20.3zM167.8 248.1h106.8c29.7 0 53.4-24.5 53.4-54.3V91.9c0-29-24.4-50.7-53.4-55.6-35.8-5.9-74.7-5.6-106.8.1-45.2 8-53.4 24.7-53.4 55.6v40.7h106.9v13.6h-147c-31.1 0-58.3 18.7-66.8 54.2-9.8 40.7-10.2 66.1 0 108.6 7.6 31.6 25.7 54.2 56.8 54.2H101v-48.8c0-35.3 30.5-66.4 66.8-66.4zm-6.7-142.6c-11.1 0-20.1-9.1-20.1-20.3.1-11.3 9-20.4 20.1-20.4 11 0 20.1 9.2 20.1 20.4s-9 20.3-20.1 20.3z"},child:[]}]})(e)}function vu(){const{theme:e}=t.useTheme(),n=A.useRef(),r=A.useRef(),[i,s]=A.useState(!1),[l,o]=A.useState(!1),[a,u]=A.useState(!1),[c,x]=A.useState(""),[p,m]=A.useState(!1),{authToken:d}=t.useSemaphorContext();t.useDashboardStore(j=>j.selectedSheetId);const g=t.useDashboardStore(j=>j.dashboard.baseQueries),y=t.useEditorStore(j=>j.card),k=t.useDashboardStore(j=>j.theme),E=t.useEditorStore(j=>j.isShowingVisual),R=t.useEditorStore(j=>j.selectedConnectionId),C=t.useEditorStore(j=>j.selectedDatabaseName),z=t.useEditorStore(j=>j.selectedSchemaName);t.useDashboardStore(j=>j.actions.updateFrameCard);const T=t.useEditorStore(j=>j.selectedTableName),S=t.useEditorStore(j=>j.card.sql),M=t.useEditorStore(j=>j.card.python),K=t.resolveBaseQuery(S,g),U=t.useEditorStore(j=>j.selectedConnectionId),_=t.useEditorStore(j=>j.frame),I=t.useEditorStore(j=>j.filterValues),N=t.useEditorStore(j=>j.applyFilters),{setCardCustomCfg:$,setQueryResultColumns:W,setFilterValues:B,setCardSql:G,setCardPython:L,setQueryError:F,setPythonStdOut:v,setCardPreferences:h}=t.useEditorStore(j=>j.actions),J=t.useEditorStore(j=>j.onSave),re=t.useEditorStore(j=>j.actions.setApplyFilters),f=t.useEditorStore(j=>j.onClose),te=t.useEditorStore(j=>j.actions.setCardData),ue=t.useEditorStore(j=>j.actions.setSqlGen),Z=t.useEditorStore(j=>j.runSql),xe=t.useEditorStore(j=>j.actions.setRunSql),oe=t.useEditorStore(j=>j.actions.setIsSqlRunning),{data:ie,isLoading:le,isFetching:Ee,isSuccess:Be,isError:Ce,error:we,status:_e,refetch:be}=t.useQuery({queryKey:[K,M],queryFn:()=>t.postRequest("https://semaphor.cloud/api/v1/query",(d==null?void 0:d.accessToken)||"",{connection_id:U,sql:K,python:M===t.PYTHON_DEFAULT_CODE?"":M,active_filters:N?I:[]}),enabled:!1,retry:!1});A.useEffect(()=>{if(ie&&(te(ie.records),v((ie==null?void 0:ie.output)||""),ie.records.length>0)){const{dimensionKeys:j}=t.getKeys(ie.records);W(j)}},[ie,te,W,v]),A.useEffect(()=>{Z&&(be(),xe(!1))},[Z,be,xe]),A.useEffect(()=>{(le||Ee)&&oe(!0),(Ce||Be)&&oe(!1),Ce?(F(we.message),te([]),W([]),v("")):F("")},[le,Ee,ie,v,Ce,Be,oe,te,W,F,we]);function D(){G(""),te([]),ue({}),$(""),h({})}const Qe=j=>{r.current=j};function nt(){let j=S;S&&!S.includes("{{")&&(j=Bi(S),G(j));const O={...y,lastSelectedSchema:z,lastSelectedDatabase:C,lastSelectedTable:T,connectionId:R,type:E?y.type:"table",sql:j,customCfg:E?y.customCfg:null},q=_.cards.map(H=>H.id===y.id?O:H);J==null||J({..._,cards:q})}function gt(){f==null||f()}function jt(j){const O=getComputedStyle(document.documentElement).getPropertyValue(j);return yt(O)}function yt(j){const[O,q,H]=j.split(" "),ee=parseFloat(O),ve=parseFloat(q),ye=parseFloat(H),Oe=ve/100,Te=ye/100,ne=(1-Math.abs(2*Te-1))*Oe,de=ne*(1-Math.abs(ee/60%2-1)),me=Te-ne/2;let Ne=0,Ie=0,Ae=0;0<=ee&&ee<60?(Ne=ne,Ie=de,Ae=0):60<=ee&&ee<120?(Ne=de,Ie=ne,Ae=0):120<=ee&&ee<180?(Ne=0,Ie=ne,Ae=de):180<=ee&&ee<240?(Ne=0,Ie=de,Ae=ne):240<=ee&&ee<300?(Ne=de,Ie=0,Ae=ne):300<=ee&&ee<360&&(Ne=ne,Ie=0,Ae=de),Ne=Math.round((Ne+me)*255),Ie=Math.round((Ie+me)*255),Ae=Math.round((Ae+me)*255);const bt=ai=>{const St=ai.toString(16);return St.length==1?"0"+St:St};return`#${bt(Ne)}${bt(Ie)}${bt(Ae)}`}A.useEffect(()=>{const j=n.current,O=r.current;if(j){const q=window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light",H=k==="system"?q:k;j.editor.defineTheme("default",{base:H==="light"?"vs":"vs-dark",inherit:!0,rules:[],colors:{"editor.background":H==="light"?"#ffffff":jt("--background")}}),j.editor.setTheme("default")}return O&&j&&O.addCommand(j.KeyMod.Shift|j.KeyCode.Enter,function(){return console.log("Executing query..."),be(),!1}),()=>{}},[e,k,n.current]);function rt(j){n.current=j}function Et(){return t.jsxRuntimeExports.jsxs(t.jsxRuntimeExports.Fragment,{children:[l&&t.jsxRuntimeExports.jsx("div",{className:"xbg-yellow-100 relative flex w-1/3 min-w-0 grow overflow-hidden border-l p-1 text-xs",role:"editor-filter-container",children:t.jsxRuntimeExports.jsxs("div",{className:"w-[99%]",children:[t.jsxRuntimeExports.jsxs("div",{className:"flex items-center gap-2 pt-3",children:[t.jsxRuntimeExports.jsx(qi,{checked:N,onCheckedChange:()=>re(!N),text:"Apply Filters"}),t.jsxRuntimeExports.jsx(Vi,{}),I&&l&&t.jsxRuntimeExports.jsx(t.Cross2Icon,{onClick:()=>o(!1),className:"bg-background/50 text-foreground/50 hover:cursor-pointer hover:text-foreground"})]}),t.jsxRuntimeExports.jsx(t.Ft,{theme:"default",onChange:j=>{if(j)try{JSON.parse(j),B(JSON.parse(j))}catch{}},defaultLanguage:"json",className:"mt-1 min-h-[220px]",value:JSON.stringify(I,null,2),options:{readOnly:!0,minimap:{enabled:!1},lineNumbers:"off",glyphMargin:!1,wordWrap:"on",scrollbar:{verticalScrollbarSize:0,horizontalScrollbarSize:0},fontSize:12,renderLineHighlight:"none"}})]})}),I&&!l&&t.jsxRuntimeExports.jsx(sr,{onClick:()=>o(!0),className:t.cn("absolute bottom-4 right-6 h-3 w-3 text-foreground/50 hover:cursor-pointer hover:text-foreground",{"font-bold text-red-800":N})})]})}function b(){return t.jsxRuntimeExports.jsxs(Ot,{className:"flex grow pb-1",direction:"vertical",role:"editor-resizable-group",children:[t.jsxRuntimeExports.jsxs(Ve,{id:"1",order:1,defaultSize:i?20:100,className:"relative flex grow",children:[t.jsxRuntimeExports.jsx("div",{role:"sql-container",className:"relative flex w-[99%]",children:t.jsxRuntimeExports.jsx(t.Ft,{theme:"default",className:"pt-3",onChange:j=>{G(j)},value:S,options:{minimap:{enabled:!1},wordWrap:"on",scrollbar:{verticalScrollbarSize:0,horizontalScrollbarSize:0},fontSize:14,renderLineHighlight:"none"},defaultLanguage:"sql",defaultValue:"SELECT * FROM table",beforeMount:rt,onMount:Qe})}),i&&t.jsxRuntimeExports.jsx("code",{className:"absolute right-6 top-3 text-sm text-muted-foreground/70",children:"sql"})]}),i&&t.jsxRuntimeExports.jsxs(t.jsxRuntimeExports.Fragment,{children:[t.jsxRuntimeExports.jsx(Dt,{withHandle:!0,className:"border"}),t.jsxRuntimeExports.jsxs(Ve,{id:"2",order:2,defaultSize:80,className:"relative flex grow",children:[t.jsxRuntimeExports.jsx("div",{role:"python-container",className:"relative flex w-[99%] pt-0",children:t.jsxRuntimeExports.jsx(t.Ft,{className:"pt-3",theme:"default",onChange:j=>{L(j&&j.trim()||"")},value:M||t.PYTHON_DEFAULT_CODE,options:{minimap:{enabled:!1},wordWrap:"on",scrollbar:{verticalScrollbarSize:0,horizontalScrollbarSize:0},fontSize:14,renderLineHighlight:"none"},defaultLanguage:"python",beforeMount:rt,onMount:Qe})}),t.jsxRuntimeExports.jsx("code",{className:"absolute right-6 top-3 text-sm text-muted-foreground/70",children:"python"})]})]})]})}return t.jsxRuntimeExports.jsxs("section",{role:"editor-section",className:"flex grow flex-col justify-end",children:[t.jsxRuntimeExports.jsxs("div",{role:"sql-editor",className:"relative flex grow justify-between overflow-y-scroll",children:[b(),Et()]}),t.jsxRuntimeExports.jsxs("div",{role:"editor-controls",className:"item-center flex flex-wrap justify-between gap-2 px-6 py-4",children:[t.jsxRuntimeExports.jsxs("div",{className:"flex grow items-center gap-2",children:[t.jsxRuntimeExports.jsxs(t.Button,{disabled:le||Ee,onClick:()=>{be()},className:"shrink-0",size:"sm",variant:"outline",children:[le||Ee?t.jsxRuntimeExports.jsx(t.LoaderCircle,{className:"mr-2 h-4 w-4 animate-spin text-foreground/50"}):t.jsxRuntimeExports.jsx(Ri,{className:"mr-2 h-4 w-4"}),"Run"]}),Ce&&t.jsxRuntimeExports.jsx(_i,{error:we.message,setShowAIDialog:u,setTriggerAIRun:m,setUserInputforAI:x}),t.jsxRuntimeExports.jsxs(t.Button,{onClick:D,className:"",size:"sm",variant:"outline",children:[t.jsxRuntimeExports.jsx(di,{className:"mr-2 size-4"}),"Clear"]}),t.jsxRuntimeExports.jsx(t.Toggle,{pressed:i,onPressedChange:j=>s(j),className:"",size:"sm",variant:"outline",children:t.jsxRuntimeExports.jsx(wu,{className:"size-4 text-foreground/70"})}),t.jsxRuntimeExports.jsx(ju,{open:a,setOpen:u,userInput:c,triggerAIRun:p,setTriggerAIRun:m,setUserInput:j=>x(j)})]}),t.jsxRuntimeExports.jsxs("div",{className:"flex items-end gap-2",children:[t.jsxRuntimeExports.jsxs(t.Button,{onClick:nt,size:"sm",variant:"outline",children:[t.jsxRuntimeExports.jsx(t.Check,{className:"mr-2 size-4 font-bold text-green-600"}),"Accept"]}),t.jsxRuntimeExports.jsxs(t.Button,{onClick:gt,className:"w-full",size:"sm",variant:"outline",children:[t.jsxRuntimeExports.jsx(t.Cross2Icon,{className:"mr-2 size-4"}),"Close"]})]})]})]})}function Nu({data:e}){var o;const[n,r]=A.useState([]),s=Object.keys(e[0]).map(a=>({accessorKey:a,header:({column:u})=>{const c=u.getIsSorted();return t.jsxRuntimeExports.jsx("div",{className:"flex gap-2",children:t.jsxRuntimeExports.jsxs("div",{className:"flex cursor-pointer items-center",onClick:()=>u.toggleSorting(u.getIsSorted()==="asc"),children:[a,c==="asc"?t.jsxRuntimeExports.jsx(t.TriangleUpIcon,{className:"ml-2 h-5 w-5"}):c==="desc"?t.jsxRuntimeExports.jsx(t.TriangleDownIcon,{className:"ml-2 h-5 w-5"}):null]})})}})),l=t.useReactTable({data:e,columns:s,getCoreRowModel:t.getCoreRowModel(),getPaginationRowModel:t.getPaginationRowModel(),onSortingChange:r,getSortedRowModel:t.getSortedRowModel(),manualPagination:!0,state:{sorting:n}});return t.jsxRuntimeExports.jsxs(t.Table,{children:[t.jsxRuntimeExports.jsx(t.TableHeader,{children:l.getHeaderGroups().map(a=>t.jsxRuntimeExports.jsx(t.TableRow,{children:a.headers.map(u=>t.jsxRuntimeExports.jsx(t.TableHead,{className:"sticky top-0 bg-muted",children:u.isPlaceholder?null:t.flexRender(u.column.columnDef.header,u.getContext())},u.id))},a.id))}),t.jsxRuntimeExports.jsx(t.TableBody,{children:(o=l.getRowModel().rows)!=null&&o.length?l.getRowModel().rows.map(a=>t.jsxRuntimeExports.jsx(t.TableRow,{className:"whitespace-nowrap py-2","data-state":a.getIsSelected()&&"selected",children:a.getVisibleCells().map(u=>t.jsxRuntimeExports.jsx(t.TableCell,{children:t.flexRender(u.column.columnDef.cell,u.getContext())},u.id))},a.id)):t.jsxRuntimeExports.jsx(t.TableRow,{children:t.jsxRuntimeExports.jsx(t.TableCell,{colSpan:s.length,className:"h-24 text-center",children:"No results."})})})]})}function ei({className:e,...n}){A.useState(0);const r=t.useDashboardStore(o=>o.themeStyle),i=t.useEditorStore(o=>o.card),s=t.useEditorStore(o=>o.actions.setCard);if(A.useEffect(()=>{},[i.data,i.type,i.cfg,i.customCfg,r,i.preferences]),!i.id)return null;let l;return i.data&&i.data.length>0&&(l=t.createChartConfig({data:i.data,cardType:i.type,cfg:i.cfg,customCfg:i.customCfg,preferences:i.preferences})),t.jsxRuntimeExports.jsxs(t.Card,{role:"editor-visual-card",className:t.cn("relative flex h-full flex-col rounded-none",e),...n,children:[t.jsxRuntimeExports.jsxs(t.CardHeader,{className:"py-4",children:[t.jsxRuntimeExports.jsx(t.Editable,{text:i.title,onSave:o=>s({...i,title:o}),children:t.jsxRuntimeExports.jsx("div",{className:"flex items-center gap-2",children:t.jsxRuntimeExports.jsx(t.CardTitle,{className:"text-base",children:i.title})})},i.title),t.jsxRuntimeExports.jsx(t.Editable,{text:i.description||"",onSave:o=>s({...i,description:o}),children:t.jsxRuntimeExports.jsxs(t.CardDescription,{children:[" ",i.description]})},i.description)]}),t.jsxRuntimeExports.jsxs(t.CardContent,{className:"flex grow flex-col pb-3",children:[i.type!=="table"&&l&&t.jsxRuntimeExports.jsx(t.ChartJsVisual,{cfg:l},JSON.stringify(l)+JSON.stringify(i.preferences)),i.type==="table"&&i.data&&i.data.length>0&&t.jsxRuntimeExports.jsx(t.$57acba87d6e25586$export$ccf8d8d7bbf3c2cc,{className:"flex min-h-0 flex-1 grow basis-0",children:t.jsxRuntimeExports.jsx(t.TableVisual,{card:i,data:i==null?void 0:i.data})})]})]})}function Iu(){const[e,n]=A.useState(!1),[r,i]=A.useState(""),[s,l]=A.useState(""),[o,a]=A.useState(""),u=t.useEditorStore(k=>k.card),c=t.useEditorStore(k=>k.card.customCfg),x=t.useEditorStore(k=>k.actions.setCardCustomCfg);function p(k){var C,z;const E={...k,data:{...k==null?void 0:k.data,datasets:(z=(C=k==null?void 0:k.data)==null?void 0:C.datasets)==null?void 0:z.map(T=>({...T,data:[]}))}};return JSON.stringify(E,null,1)}function m(){if(!u.data||u.data.length===0)return;const k=t.createChartConfig({data:u.data,cardType:u.type,cfg:u.cfg,preferences:u.preferences});k&&(i(JSON.stringify(k,null,1)),c&&l(JSON.stringify(c,null,1)))}function d(){if(s)try{const k=JSON.parse(s);return k?(x(k),a(""),l(""),k):void 0}catch(k){console.log(k),a("Invalid JSON")}}function g(){l(""),x(null)}function y(){let k;if(c){const E=t._.cloneDeep(u.cfg),R=t._.merge(E,c);return k=p(R),k}return r?(k=p(JSON.parse(r)),k):""}return t.jsxRuntimeExports.jsxs(t.Dialog,{open:e,onOpenChange:n,children:[t.jsxRuntimeExports.jsx(t.DialogTrigger,{asChild:!0,children:t.jsxRuntimeExports.jsx(t.Button,{onClick:m,className:` ${c&&"border-foreground/50 dark:border-foreground/70"}`,size:"sm",variant:"outline",children:t.jsxRuntimeExports.jsx(t.Settings,{className:"h-4 w-4"})})}),t.jsxRuntimeExports.jsxs(t.DialogContent,{className:"max-h-[70vh] min-h-[70vh] min-w-[900px] overflow-auto",children:[t.jsxRuntimeExports.jsxs(t.DialogHeader,{className:"",children:[t.jsxRuntimeExports.jsxs("div",{className:"flex items-center gap-2",children:[t.jsxRuntimeExports.jsx(t.DialogTitle,{children:"Customize Card"}),t.jsxRuntimeExports.jsxs(t.Tooltip,{children:[t.jsxRuntimeExports.jsx(t.TooltipTrigger,{children:t.jsxRuntimeExports.jsx(ji,{onClick:()=>{navigator.clipboard.writeText(u.id)},className:"size-3 cursor-pointer text-muted-foreground/70 transition-colors hover:text-muted-foreground"})}),t.jsxRuntimeExports.jsx(t.TooltipContent,{side:"right",align:"center",children:t.jsxRuntimeExports.jsx("p",{className:"text-xs",children:"Copy Card ID"})})]})]}),t.jsxRuntimeExports.jsxs(t.DialogDescription,{children:["See the configuration options and documentation",t.jsxRuntimeExports.jsx("a",{target:"_blank",className:"ml-1 text-blue-500 underline",href:"https://www.chartjs.org/docs/latest/samples/bar/vertical.html",children:"here."})]})]}),t.jsxRuntimeExports.jsxs("div",{className:"flex grow gap-2",children:[t.jsxRuntimeExports.jsx(ei,{className:"w-1/2 rounded shadow-none"}),t.jsxRuntimeExports.jsxs(t.Tabs,{defaultValue:"custom-config",className:"flex w-1/2 flex-col",children:[t.jsxRuntimeExports.jsxs(t.TabsList,{className:"justify-start rounded-sm rounded-b-none border border-b-0",children:[t.jsxRuntimeExports.jsxs(t.TabsTrigger,{value:"custom-config",children:[c&&t.jsxRuntimeExports.jsx(t.CheckIcon,{className:"mr-1 h-5 w-5 text-green-600"}),c?"Custom Config":"Default Config"]}),t.jsxRuntimeExports.jsx(t.TabsTrigger,{className:"",value:"output",children:"Output"})]}),t.jsxRuntimeExports.jsx(t.TabsContent,{className:"bg-red-x mt-0 grow rounded-b border border-t-0 p-2",value:"output",children:t.jsxRuntimeExports.jsx(t.Textarea,{disabled:!0,value:r,className:"h-full resize-none border-none font-mono focus-visible:ring-0 focus-visible:ring-offset-0"})}),t.jsxRuntimeExports.jsx(t.TabsContent,{className:"mt-0 grow rounded-b border border-t-0",value:"custom-config",children:t.jsxRuntimeExports.jsx(t.Ft,{className:"h-full w-full overflow-hidden",theme:"default",options:{minimap:{enabled:!1},wordWrap:"on",scrollbar:{verticalScrollbarSize:0,horizontalScrollbarSize:0},fontSize:14,renderLineHighlight:"none"},defaultLanguage:"json",value:y(),onChange:k=>l(k)})})]})]}),t.jsxRuntimeExports.jsxs(t.DialogFooter,{className:"flex items-center",children:[t.jsxRuntimeExports.jsx(t.Label,{className:"mr-2 text-red-500",children:o}),t.jsxRuntimeExports.jsx(t.Button,{disabled:!c,onClick:g,variant:"outline",children:"Reset"}),t.jsxRuntimeExports.jsx(t.Button,{onClick:d,variant:"outline",children:"Apply"}),t.jsxRuntimeExports.jsx(t.Button,{onClick:()=>n(!1),variant:"outline",children:"Close"})]})]})]})}function ti(e){return Pe({tag:"svg",attr:{viewBox:"0 0 1024 1024"},child:[{tag:"path",attr:{d:"M926.8 397.1l-396-288a31.81 31.81 0 0 0-37.6 0l-396 288a31.99 31.99 0 0 0-11.6 35.8l151.3 466a32 32 0 0 0 30.4 22.1h489.5c13.9 0 26.1-8.9 30.4-22.1l151.3-466c4.2-13.2-.5-27.6-11.7-35.8zM838.6 417l-98.5 32-200-144.7V199.9L838.6 417zM466 567.2l-89.1 122.3-55.2-169.2L466 567.2zm-116.3-96.8L484 373.3v140.8l-134.3-43.7zM512 599.2l93.9 128.9H418.1L512 599.2zm28.1-225.9l134.2 97.1L540.1 514V373.3zM558 567.2l144.3-46.9-55.2 169.2L558 567.2zm-74-367.3v104.4L283.9 449l-98.5-32L484 199.9zM169.3 470.8l86.5 28.1 80.4 246.4-53.8 73.9-113.1-348.4zM327.1 853l50.3-69h269.3l50.3 69H327.1zm414.5-33.8l-53.8-73.9 80.4-246.4 86.5-28.1-113.1 348.4z"},child:[]}]})(e)}function ni(e){return Pe({tag:"svg",attr:{viewBox:"0 0 256 256",fill:"currentColor"},child:[{tag:"path",attr:{d:"M137.39,24.06A16,16,0,0,0,120,40V80.67a15.86,15.86,0,0,0,13.25,15.76A32,32,0,1,1,96,129.68c-.41-8.22,1.27-15,5-20.26h0a15.86,15.86,0,0,0-1.69-20.47L71.69,60.68a16,16,0,0,0-23.63,1.1A103.6,103.6,0,0,0,55,202.05,103.24,103.24,0,0,0,128,232h1.49A104.3,104.3,0,0,0,232,129.48C232.75,75.18,191.19,28.88,137.39,24.06ZM60.32,71.94l27.61,28.19,0,.06A43.29,43.29,0,0,0,80.44,120H40.36A87.13,87.13,0,0,1,60.32,71.94ZM40.37,136h40.3A48,48,0,0,0,120,175.34v40.3A88,88,0,0,1,40.37,136Zm149.77,54.14A87.45,87.45,0,0,1,136,215.61V175.34a47.55,47.55,0,0,0,24.73-12.23A48,48,0,0,0,136,80.66L136,40c45.52,4.08,80.67,43.28,80,89.25A87.45,87.45,0,0,1,190.14,190.14Z"},child:[]}]})(e)}function ri(e){return Pe({tag:"svg",attr:{viewBox:"0 0 256 256",fill:"currentColor"},child:[{tag:"path",attr:{d:"M128,24A104,104,0,1,0,232,128,104.11,104.11,0,0,0,128,24Zm87.63,96H191.48A64.1,64.1,0,0,0,136,64.52V40.37A88.13,88.13,0,0,1,215.63,120ZM120,120H80.68A48.09,48.09,0,0,1,120,80.68Zm0,16v39.32A48.09,48.09,0,0,1,80.68,136Zm16,0h39.32A48.09,48.09,0,0,1,136,175.32Zm0-16V80.68A48.09,48.09,0,0,1,175.32,120ZM120,40.37V64.52A64.1,64.1,0,0,0,64.52,120H40.37A88.13,88.13,0,0,1,120,40.37ZM40.37,136H64.52A64.1,64.1,0,0,0,120,191.48v24.15A88.13,88.13,0,0,1,40.37,136ZM136,215.63V191.48A64.1,64.1,0,0,0,191.48,136h24.15A88.13,88.13,0,0,1,136,215.63Z"},child:[]}]})(e)}function ii(e){return Pe({tag:"svg",attr:{viewBox:"0 0 24 24",strokeWidth:"2",stroke:"currentColor",fill:"none",strokeLinecap:"round",strokeLinejoin:"round"},child:[{tag:"path",attr:{stroke:"none",d:"M0 0h24v24H0z",fill:"none"},child:[]},{tag:"path",attr:{d:"M6 16m-3 0a3 3 0 1 0 6 0a3 3 0 1 0 -6 0"},child:[]},{tag:"path",attr:{d:"M16 19m-2 0a2 2 0 1 0 4 0a2 2 0 1 0 -4 0"},child:[]},{tag:"path",attr:{d:"M14.5 7.5m-4.5 0a4.5 4.5 0 1 0 9 0a4.5 4.5 0 1 0 -9 0"},child:[]}]})(e)}function si(e){return Pe({tag:"svg",attr:{viewBox:"0 0 24 24"},child:[{tag:"path",attr:{fill:"none",d:"M0 0h24v24H0z"},child:[]},{tag:"path",attr:{d:"M4 9h4v11H4zM4 4h4v4H4zM10 7h4v4h-4zM16 10h4v4h-4zM16 15h4v5h-4zM10 12h4v8h-4z"},child:[]}]})(e)}function oi(e){return Pe({tag:"svg",attr:{version:"1.2",baseProfile:"tiny",viewBox:"0 0 24 24"},child:[{tag:"path",attr:{d:"M4 18c-.552 0-1-.448-1-1v-6.382l-.553.276c-.495.248-1.095.046-1.342-.447-.247-.494-.046-1.094.448-1.342l2-1c.31-.155.678-.139.973.044.294.183.474.504.474.851v8c0 .552-.448 1-1 1zM13 18h-5c-.404 0-.769-.244-.924-.617-.155-.374-.069-.804.217-1.09l4-4c.254-.254.394-.591.394-.95 0-.358-.14-.695-.394-.949-.508-.508-1.39-.508-1.9.001-.253.252-.393.589-.393.948 0 .552-.448 1-1 1s-1-.448-1-1c0-.894.348-1.733.98-2.364 1.265-1.263 3.464-1.263 4.727.001.632.631.979 1.471.979 2.363 0 .893-.348 1.733-.979 2.364l-2.293 2.293h2.586c.552 0 1 .448 1 1s-.448 1-1 1zM20.955 12.377c.338-.457.545-1.016.545-1.627 0-1.517-1.234-2.75-2.75-2.75-1.031 0-1.966.569-2.44 1.484-.254.49-.063 1.094.428 1.348.49.254 1.094.062 1.348-.428.128-.249.383-.404.664-.404.414 0 .75.336.75.75s-.336.75-.75.75c-.552 0-1 .448-1 1s.448 1 1 1c.689 0 1.25.561 1.25 1.25s-.561 1.25-1.25 1.25-1.25-.561-1.25-1.25c0-.552-.448-1-1-1s-1 .448-1 1c0 1.792 1.458 3.25 3.25 3.25s3.25-1.458 3.25-3.25c0-.939-.406-1.779-1.045-2.373z"},child:[]}]})(e)}function Au(){const[e,n]=A.useState(!1),r=t.useEditorStore(a=>a.card.type),{setCardType:i,setCardPreferences:s}=t.useEditorStore(a=>a.actions),l=t.useEditorStore(a=>a.actions.setCardCustomCfg);function o(a){i(a),l(null),s({}),n(!1)}return t.jsxRuntimeExports.jsxs(t.Popover,{open:e,onOpenChange:n,children:[t.jsxRuntimeExports.jsx(t.PopoverTrigger,{asChild:!0,children:t.jsxRuntimeExports.jsx(t.Button,{size:"sm",variant:"outline",children:t.jsxRuntimeExports.jsx(Tu,{className:"h-4 w-4",chartType:r})})}),t.jsxRuntimeExports.jsx(t.PopoverContent,{className:"w-50",children:t.jsxRuntimeExports.jsxs("div",{className:"grid grid-cols-3 place-items-center",children:[t.jsxRuntimeExports.jsx(t.Button,{onClick:()=>o("bar"),className:"font-normal",variant:"ghost",children:t.jsxRuntimeExports.jsx($t,{className:"size-5"})}),t.jsxRuntimeExports.jsx(t.Button,{onClick:()=>o("line"),variant:"ghost",children:t.jsxRuntimeExports.jsx(Kt,{className:"size-5"})}),t.jsxRuntimeExports.jsx(t.Button,{onClick:()=>o("stackedBar"),variant:"ghost",children:t.jsxRuntimeExports.jsx(si,{className:"size-5",strokeWidth:0})}),t.jsxRuntimeExports.jsx(t.Button,{onClick:()=>o("scatter"),variant:"ghost",children:t.jsxRuntimeExports.jsx(ur,{className:"size-5"})}),t.jsxRuntimeExports.jsx(t.Button,{onClick:()=>o("bubble"),variant:"ghost",children:t.jsxRuntimeExports.jsx(ii,{className:"size-4"})}),t.jsxRuntimeExports.jsx(t.Button,{onClick:()=>o("pie"),variant:"ghost",children:t.jsxRuntimeExports.jsx(lr,{className:"size-5"})}),t.jsxRuntimeExports.jsx(t.Button,{onClick:()=>o("doughnut"),variant:"ghost",children:t.jsxRuntimeExports.jsx(ni,{className:"size-5",strokeWidth:1})}),t.jsxRuntimeExports.jsx(t.Button,{onClick:()=>o("radar"),variant:"ghost",children:t.jsxRuntimeExports.jsx(ti,{className:"size-5 font-extralight",strokeWidth:.5})}),t.jsxRuntimeExports.jsx(t.Button,{onClick:()=>o("polarArea"),variant:"ghost",children:t.jsxRuntimeExports.jsx(ri,{className:"size-5"})}),t.jsxRuntimeExports.jsx(t.Button,{onClick:()=>o("table"),variant:"ghost",children:t.jsxRuntimeExports.jsx(Wt,{className:"size-5"})}),t.jsxRuntimeExports.jsx(t.Button,{onClick:()=>o("kpi"),variant:"ghost",children:t.jsxRuntimeExports.jsx(oi,{className:"size-6"})})]})})]})}function Tu({chartType:e,className:n}){switch(e){case"bar":return t.jsxRuntimeExports.jsx($t,{className:n});case"line":return t.jsxRuntimeExports.jsx(Kt,{className:n});case"pie":return t.jsxRuntimeExports.jsx(lr,{className:n});case"radar":return t.jsxRuntimeExports.jsx(ti,{className:n});case"scatter":return t.jsxRuntimeExports.jsx(ur,{className:n});case"bubble":return t.jsxRuntimeExports.jsx(ii,{className:n});case"doughnut":return t.jsxRuntimeExports.jsx(ni,{className:n});case"stackedBar":return t.jsxRuntimeExports.jsx(si,{className:"size-4 text-foreground/70"});case"polarArea":return t.jsxRuntimeExports.jsx(ri,{className:n});case"kpi":return t.jsxRuntimeExports.jsx(oi,{className:n});default:return t.jsxRuntimeExports.jsx(Wt,{className:n})}}function Lu(){const e=t.useEditorStore(r=>r.card.refreshInterval),n=t.useEditorStore(r=>r.actions.setCardRefreshInterval);return t.jsxRuntimeExports.jsxs(t.Popover,{children:[t.jsxRuntimeExports.jsx(t.PopoverTrigger,{asChild:!0,children:t.jsxRuntimeExports.jsx(t.Button,{size:"sm",variant:"outline",children:t.jsxRuntimeExports.jsx(ui,{className:"w-4 h-4"})})}),t.jsxRuntimeExports.jsx(t.PopoverContent,{className:"w-[200px]",children:t.jsxRuntimeExports.jsx("div",{className:"grid gap-4",children:t.jsxRuntimeExports.jsx("div",{className:"grid gap-2",children:t.jsxRuntimeExports.jsxs("div",{className:"grid grid-cols-5 items-center gap-1",children:[t.jsxRuntimeExports.jsx(t.Label,{className:"col-span-3",htmlFor:"width",children:"Refresh Every"}),t.jsxRuntimeExports.jsx(t.Input,{value:e||"",onChange:r=>n(r.target.value),id:"width",placeholder:"30s",className:"col-span-2 h-7 focus-visible:ring-1 focus-visible:ring-ring focus-visible:ring-offset-0"})]})})})})]})}function rr(){t.useEditorStore(o=>o.frame);const e=t.useEditorStore(o=>o.card),n=t.useEditorStore(o=>o.card.data),r=t.useEditorStore(o=>o.isShowingVisual),i=t.useEditorStore(o=>o.isSqlRunning),s=t.useEditorStore(o=>o.queryError),l=t.useEditorStore(o=>o.pythonStdOut);return t.useEditorStore(o=>o.onSave),t.useEditorStore(o=>o.onClose),t.useEditorStore(o=>o.actions.setCardSql),t.useEditorStore(o=>o.actions.setCardType),t.useEditorStore(o=>o.actions.setSqlGen),e?t.jsxRuntimeExports.jsxs("div",{className:"relative flex h-full flex-col pt-3",children:[i&&t.jsxRuntimeExports.jsx(t.LoaderCircle,{className:"absolute bottom-0 left-0 right-0 top-0 z-10 m-auto h-10 w-10 animate-spin text-foreground/10"}),t.jsxRuntimeExports.jsxs("div",{className:"mb-0 flex min-h-10 items-center justify-end gap-2 px-6",children:[r&&t.jsxRuntimeExports.jsxs("div",{className:"flex grow items-center gap-2",children:[t.jsxRuntimeExports.jsx(Au,{}),t.jsxRuntimeExports.jsx(Iu,{}),t.jsxRuntimeExports.jsx(Lu,{})]}),t.jsxRuntimeExports.jsx(Ou,{})]}),r?e.type==="kpi"?t.jsxRuntimeExports.jsx("div",{className:"flex grow items-center justify-center",children:t.jsxRuntimeExports.jsx("div",{className:"w-1/2 rounded-md border",children:t.jsxRuntimeExports.jsx(t.KPICard,{isLoading:i,card:e})})}):t.jsxRuntimeExports.jsx(ei,{className:"grow border-none shadow-none"}):t.jsxRuntimeExports.jsxs("div",{className:"flex min-h-0 w-full flex-1 grow basis-0 px-6",children:[l&&t.jsxRuntimeExports.jsx(zu,{}),e.data&&e.data.length>0&&t.jsxRuntimeExports.jsx(Nu,{data:n||[]}),s&&t.jsxRuntimeExports.jsx("span",{className:"font-mono text-sm",children:s})]})]}):t.jsxRuntimeExports.jsx(t.jsxRuntimeExports.Fragment,{children:"No Active Card"})}function zu(){const e=t.useEditorStore(r=>r.pythonStdOut);if(!e)return null;const n=e.replace(/\n/g,"<br>");return t.jsxRuntimeExports.jsxs(t.jsxRuntimeExports.Fragment,{children:[t.jsxRuntimeExports.jsx("p",{className:"font-mono text-sm",children:"Output:"}),t.jsxRuntimeExports.jsx("div",{dangerouslySetInnerHTML:{__html:n},className:"bg-muted p-2 font-mono text-sm"}),t.jsxRuntimeExports.jsx(t.Separator,{className:"mb-2"})]})}function Ou(){const e=t.useEditorStore(r=>r.isShowingVisual),n=t.useEditorStore(r=>r.actions.setIsShowingVisual);return t.jsxRuntimeExports.jsxs("div",{className:"flex items-center space-x-2",children:[t.jsxRuntimeExports.jsx(t.Label,{htmlFor:"visualize",children:"Chart"}),t.jsxRuntimeExports.jsx(t.Switch,{checked:e,onCheckedChange:()=>n(!e),id:"visualize",className:"data-[state=checked]:bg-foreground/50"})]})}function We(){const[e,n]=A.useState([]);t.useEditorStore(x=>x.card.cfg);const r=t.useEditorStore(x=>x.card.preferences),{setCardCfg:i,setFilterOnClickColumnIndex:s,setCardPreferences:l}=t.useEditorStore(x=>x.actions),o=t.useEditorStore(x=>x.queryResultColumns);t.useEditorStore(x=>{var p;return(p=x.card.preferences)==null?void 0:p.filterOnClickColumnIndex}),A.useEffect(()=>{o&&n(new Array(o.length).fill(!1))},[o]);function a(x,p){var m,d;p?r!=null&&r.onClickFilter&&((m=r==null?void 0:r.onClickFilter)==null?void 0:m.length)>0?l({...r,onClickFilter:[...r.onClickFilter,{columnIndex:x,expression:""}]}):l({...r,onClickFilter:[{columnIndex:x,expression:""}]}):(l({...r,onClickFilter:(d=r==null?void 0:r.onClickFilter)==null?void 0:d.filter(g=>g.columnIndex!==x)}),n(g=>{const y=[...g];return y[x]=!1,y}))}function u(x,p){var d;const m=(d=r==null?void 0:r.onClickFilter)==null?void 0:d.map(g=>g.columnIndex===x?{...g,expression:p.target.value}:g);l({...r,onClickFilter:m})}function c(x){var p,m,d,g;if(e!=null&&e[x]||(m=(p=r==null?void 0:r.onClickFilter)==null?void 0:p.find(y=>y.columnIndex===x))!=null&&m.expression)return t.jsxRuntimeExports.jsx(t.Input,{value:(g=(d=r==null?void 0:r.onClickFilter)==null?void 0:d.find(y=>y.columnIndex===x))==null?void 0:g.expression,onChange:y=>u(x,y),type:"text",className:" h-9 w-full focus-visible:ring-0 focus-visible:ring-ring focus-visible:ring-offset-0 font-mono text-xs",placeholder:"Expression"})}return t.jsxRuntimeExports.jsx(t.jsxRuntimeExports.Fragment,{children:o==null?void 0:o.map((x,p)=>{var m,d;return t.jsxRuntimeExports.jsx("div",{className:"flex items-center justify-between space-y-2 xbg-red-100 group",children:t.jsxRuntimeExports.jsxs("div",{className:" grow",children:[t.jsxRuntimeExports.jsxs("div",{className:"flex items-center py-2 space-x-2",children:[t.jsxRuntimeExports.jsx(t.Checkbox,{checked:!!((m=r==null?void 0:r.onClickFilter)!=null&&m.find(g=>g.columnIndex===p)),onCheckedChange:g=>a(p,g)}),t.jsxRuntimeExports.jsx("label",{className:"text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70",children:x}),t.jsxRuntimeExports.jsx("div",{className:"flex gap-2 items-center ",children:((d=r==null?void 0:r.onClickFilter)==null?void 0:d.find(g=>g.columnIndex===p))&&t.jsxRuntimeExports.jsx(or,{onClick:()=>{n(g=>{const y=[...g];return y[p]=!g[p],y})},className:" invisible group-hover:visible size-3 text-gray-400 cursor-pointer"})})]}),c(p)]})},x)})})}function un(){var l,o;const e=t.useEditorStore(a=>a.card.preferences),n=t.useEditorStore(a=>a.card.cfg),{setCardCfg:r,setCardPreferences:i}=t.useEditorStore(a=>a.actions);(l=n==null?void 0:n.options)!=null&&l.indexAxis;function s(a){var x,p,m,d,g,y;let u={};(x=e==null?void 0:e.chartOptions)!=null&&x.scales&&(u={x:(m=(p=e==null?void 0:e.chartOptions)==null?void 0:p.scales)==null?void 0:m.y,y:(g=(d=e==null?void 0:e.chartOptions)==null?void 0:d.scales)==null?void 0:g.x});const c={...e,chartOptions:{...e==null?void 0:e.chartOptions,scales:{...(y=e==null?void 0:e.chartOptions)==null?void 0:y.scales,...u},indexAxis:a}};i(c)}return t.jsxRuntimeExports.jsxs(t.RadioGroup,{value:((o=e==null?void 0:e.chartOptions)==null?void 0:o.indexAxis)||"x",onValueChange:s,className:"flex gap-3",defaultValue:"x",children:[t.jsxRuntimeExports.jsxs("div",{className:"flex items-center space-x-2",children:[t.jsxRuntimeExports.jsx(t.RadioGroupItem,{value:"x",id:"r1"}),t.jsxRuntimeExports.jsx("label",{className:"text-sm",htmlFor:"r1",children:"Vertical"})]}),t.jsxRuntimeExports.jsxs("div",{className:"flex items-center space-x-2",children:[t.jsxRuntimeExports.jsx(t.RadioGroupItem,{value:"y",id:"r2"}),t.jsxRuntimeExports.jsx("label",{className:"text-sm",htmlFor:"r2",children:"Horizontal"})]})]})}const De="focus-visible:ring-0 focus-visible:ring-ring focus-visible:ring-offset-0";function ir(e){var r,i,s;const n=t.getNumberAxis(e);return((s=(i=(r=e==null?void 0:e.chartOptions)==null?void 0:r.scales)==null?void 0:i[n])==null?void 0:s.type)||"linear"}function Du(){var I,N,$,W,B,G;const[e,n]=A.useState(!1),r=t.useEditorStore(L=>{var F;return(F=L.card)==null?void 0:F.preferences}),i=t.getNumberAxis(r),[s,l]=A.useState(ir(r)),[o,a]=A.useState((($=(N=(I=r==null?void 0:r.chartOptions)==null?void 0:I.scales)==null?void 0:N[i])==null?void 0:$.min)||""),[u,c]=A.useState(((G=(B=(W=r==null?void 0:r.chartOptions)==null?void 0:W.scales)==null?void 0:B[i])==null?void 0:G.max)||""),[x,p]=A.useState(o||u?"custom":"auto"),[m,d]=A.useState(""),[g,y]=A.useState(""),[k,E]=A.useState(""),[R,C]=A.useState(""),[z,T]=A.useState(""),S=t.useEditorStore(L=>L.actions.setCardPreferences);A.useEffect(()=>{var L,F,v,h,J,re,f,te,ue,Z,xe,oe,ie,le;l(ir(r)),a(((v=(F=(L=r==null?void 0:r.chartOptions)==null?void 0:L.scales)==null?void 0:F[i])==null?void 0:v.min)===0?0:""),c(((re=(J=(h=r==null?void 0:r.chartOptions)==null?void 0:h.scales)==null?void 0:J[i])==null?void 0:re.max)||""),d(((Z=(ue=(te=(f=r==null?void 0:r.chartOptions)==null?void 0:f.scales)==null?void 0:te[i])==null?void 0:ue.ticks)==null?void 0:Z.stepSize)||""),y(((xe=r==null?void 0:r.numberAxisFormat)==null?void 0:xe.format)||""),E(((oe=r==null?void 0:r.numberAxisFormat)==null?void 0:oe.suffix)||""),C(((ie=r==null?void 0:r.numberAxisFormat)==null?void 0:ie.currency)||""),T(((le=r==null?void 0:r.numberAxisFormat)==null?void 0:le.locale)||"")},[e,r,i]);function M(L,F){return F===""||/^[0-9\b]+$/.test(F)?Number(F):Number(L)}function K(){return t.jsxRuntimeExports.jsxs(t.jsxRuntimeExports.Fragment,{children:[t.jsxRuntimeExports.jsxs("div",{className:"grid grid-cols-9 items-center gap-2",children:[t.jsxRuntimeExports.jsx(t.Label,{className:"col-span-3",htmlFor:"format",children:"Format"}),t.jsxRuntimeExports.jsx(t.Input,{value:g,placeholder:"000,0.00",onChange:L=>y(L.target.value),id:"format",className:`col-span-4 h-8 w-full tracking-wide ${De}`}),t.jsxRuntimeExports.jsx(t.Input,{value:k,placeholder:"M",onChange:L=>E(L.target.value),id:"unit",className:`col-span-2 h-8 w-full ${De}`})]}),t.jsxRuntimeExports.jsxs("div",{className:"grid grid-cols-6 items-center gap-2",children:[t.jsxRuntimeExports.jsx(t.Label,{className:"col-span-2 hover:cursor-pointer hover:underline",htmlFor:"currency",children:t.jsxRuntimeExports.jsx("a",{target:"_blank",href:"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat",children:"Currency"})}),t.jsxRuntimeExports.jsx(t.Input,{value:R,placeholder:"USD",onChange:L=>C(L.target.value),id:"currency",className:`col-span-2 h-8 w-full ${De}`}),t.jsxRuntimeExports.jsx(t.Input,{value:z,placeholder:"en-US",onChange:L=>T(L.target.value),id:"locale",className:`col-span-2 h-8 w-full ${De}`})]})]})}function U(){return t.jsxRuntimeExports.jsxs(t.jsxRuntimeExports.Fragment,{children:[t.jsxRuntimeExports.jsxs("div",{className:"grid grid-cols-3 items-center gap-2",children:[t.jsxRuntimeExports.jsx(t.Label,{htmlFor:"range",children:"Range"}),t.jsxRuntimeExports.jsx(t.Input,{id:"min",value:o,onChange:L=>a(F=>M(F,L.target.value)),className:`col-span-1 h-8 w-full ${De}`}),t.jsxRuntimeExports.jsx(t.Input,{value:u,onChange:L=>c(F=>M(F,L.target.value)),id:"max",className:`col-span-1 h-8 w-full ${De}`})]}),t.jsxRuntimeExports.jsxs("div",{className:"grid grid-cols-3 items-center gap-2",children:[t.jsxRuntimeExports.jsx(t.Label,{htmlFor:"step-size",children:"Step Size"}),t.jsxRuntimeExports.jsx(t.Input,{value:m,onChange:L=>d(F=>M(F,L.target.value)),id:"step-size",className:`col-span-1 h-8 w-full ${De}`})]})]})}function _(){var v;let L={};x==="custom"&&(L={min:o,max:u,ticks:{stepSize:m}});const F={...r||{},chartOptions:{...r==null?void 0:r.chartOptions,scales:{...(v=r==null?void 0:r.chartOptions)==null?void 0:v.scales,[i]:{type:s,...s==="linear"?L:{}}}},numberAxisFormat:{format:g,suffix:k,currency:R,locale:z}};S(F)}return t.jsxRuntimeExports.jsxs(t.Popover,{onOpenChange:L=>n(L),children:[t.jsxRuntimeExports.jsx(t.PopoverTrigger,{asChild:!0,children:t.jsxRuntimeExports.jsx(t.SliderIcon,{className:"size-4 cursor-pointer text-muted-foreground hover:text-foreground"})}),t.jsxRuntimeExports.jsx(t.PopoverContent,{align:"center",className:"max-w-65",children:t.jsxRuntimeExports.jsxs("div",{className:"grid gap-4",children:[t.jsxRuntimeExports.jsxs("div",{className:"space-y-2",children:[t.jsxRuntimeExports.jsx("h4",{className:"font-medium leading-none",children:"Scale Options"}),t.jsxRuntimeExports.jsx("p",{className:"text-sm text-muted-foreground",children:"Set the scale for the number axis"})]}),t.jsxRuntimeExports.jsxs("div",{className:"grid gap-2",children:[t.jsxRuntimeExports.jsxs("div",{className:"grid grid-cols-3 items-center gap-2",children:[t.jsxRuntimeExports.jsx(t.Label,{htmlFor:"scale",children:"Type"}),t.jsxRuntimeExports.jsxs(t.Select,{value:s,onValueChange:L=>l(L),children:[t.jsxRuntimeExports.jsx(t.SelectTrigger,{className:"col-span-2 h-8 w-full focus:ring-1 focus:ring-offset-0",children:t.jsxRuntimeExports.jsx(t.SelectValue,{})}),t.jsxRuntimeExports.jsx(t.SelectContent,{id:"type",children:t.jsxRuntimeExports.jsxs(t.SelectGroup,{children:[t.jsxRuntimeExports.jsx(t.SelectLabel,{children:"Option"}),t.jsxRuntimeExports.jsx(t.SelectItem,{value:"linear",children:"Linear"}),t.jsxRuntimeExports.jsx(t.SelectItem,{value:"logarithmic",children:"Logarithmic"})]})})]})]}),s=="linear"&&t.jsxRuntimeExports.jsxs("div",{className:"grid grid-cols-3 items-center gap-2 py-1",children:[t.jsxRuntimeExports.jsx(t.Label,{htmlFor:"scale-option",children:"Setup"}),t.jsxRuntimeExports.jsxs(t.RadioGroup,{id:"scale-option",value:x,onValueChange:L=>p(L),className:"col-span-2 flex gap-3",defaultValue:"x",children:[t.jsxRuntimeExports.jsxs("div",{className:"flex items-center space-x-2",children:[t.jsxRuntimeExports.jsx(t.RadioGroupItem,{value:"auto",id:"r1"}),t.jsxRuntimeExports.jsx("label",{className:"text-sm",htmlFor:"r1",children:"Auto"})]}),t.jsxRuntimeExports.jsxs("div",{className:"flex items-center space-x-2",children:[t.jsxRuntimeExports.jsx(t.RadioGroupItem,{value:"custom",id:"r2"}),t.jsxRuntimeExports.jsx("label",{className:"text-sm",htmlFor:"r2",children:"Custom"})]})]})]}),x==="custom"&&s=="linear"&&U(),K(),t.jsxRuntimeExports.jsx(t.SelectSeparator,{}),t.jsxRuntimeExports.jsx("div",{className:"grid grid-cols-3",children:t.jsxRuntimeExports.jsx(t.Button,{onClick:_,variant:"secondary",className:"col-span-1 col-start-3 h-8 w-full",children:"Apply"})})]})]})})]})}function Fu({idx:e}){var a;const n=t.useEditorStore(u=>{var c;return(c=u.card)==null?void 0:c.preferences}),r=t.useEditorStore(u=>{var c;return(c=u.card.preferences)==null?void 0:c.datasetOptions}),i=t.useEditorStore(u=>u.actions.setCardPreferences),s=(a=n==null?void 0:n.chartOptions)==null?void 0:a.indexAxis,l=r==null?void 0:r.find(u=>u.idx===e);function o(u,c){(u==="end"||u==="start")&&t.getContrastColor(t.getCanvasBackgroundColor());const x={display:u!=="none",align:u,anchor:u,clamp:!0};if(!l)i({...n,datasetOptions:[...r||[],{idx:c,datalabels:x}]});else{const p={...l};p.datalabels=x;const m=r==null?void 0:r.map(d=>d.idx===c?p:d);i({...n,datasetOptions:m})}}return t.jsxRuntimeExports.jsxs(t.Popover,{children:[t.jsxRuntimeExports.jsx(t.PopoverTrigger,{children:t.jsxRuntimeExports.jsx(Ii,{className:"invisible size-4 rotate-[135deg] cursor-pointer text-muted-foreground hover:text-foreground group-hover:visible"})}),t.jsxRuntimeExports.jsx(t.PopoverContent,{className:"w-fit p-1",children:t.jsxRuntimeExports.jsxs("div",{className:"flex gap-1",children:[t.jsxRuntimeExports.jsx(t.Button,{onClick:()=>o("none",e),size:"sm",variant:"secondary",className:"h-7 p-1 text-xs font-normal",children:t.jsxRuntimeExports.jsx(t.X,{className:"size-4"})}),t.jsxRuntimeExports.jsx(t.Button,{onClick:()=>o("start",e),size:"sm",variant:"secondary",className:"h-7 p-1 text-xs font-normal",children:t.jsxRuntimeExports.jsx(yi,{className:t.cn("h-4 w-4",{"rotate-90":s==="y"})})}),t.jsxRuntimeExports.jsx(t.Button,{onClick:()=>o("center",e),size:"sm",variant:"secondary",className:"h-7 p-1 text-xs font-normal",children:t.jsxRuntimeExports.jsx(bi,{className:t.cn("h-4 w-4",{"rotate-90":s==="y"})})}),t.jsxRuntimeExports.jsx(t.Button,{onClick:()=>o("end",e),size:"sm",variant:"secondary",className:"h-7 p-1 text-xs font-normal",children:t.jsxRuntimeExports.jsx(Ei,{className:t.cn("h-4 w-4",{"rotate-90":s==="y"})})})]})})]})}function li(){const e=t.useEditorStore(u=>u.card),n=t.useEditorStore(u=>{var c,x,p;return(p=(x=(c=u==null?void 0:u.card)==null?void 0:c.preferences)==null?void 0:x.chartOptions)==null?void 0:p.indexAxis}),r=n==="y"?"Y axis":"X axis",i=n==="y"?"X axis":"Y axis",{keys:s,metricKeys:l,dimensionKeys:o}=t.getKeys(e.data||[]);let a=l;if(e.type==="stackedBar"){const u=t.pivotData({dataArray:e.data||[],groupKey:o[0],pivotKey:o[1],valueKey:a[0]}),{metricKeys:c}=t.getKeys(u);a=c}return s.length===0?null:t.jsxRuntimeExports.jsxs("div",{className:"space-y-4",children:[t.jsxRuntimeExports.jsxs("div",{className:"space-y-2",children:[t.jsxRuntimeExports.jsx(t.Label,{children:r}),t.jsxRuntimeExports.jsx("div",{className:"my-1 space-y-1",children:t.jsxRuntimeExports.jsx("div",{className:"rounded-md bg-muted/70 px-2 py-1 hover:bg-muted",children:t.jsxRuntimeExports.jsx("p",{children:o[0]})})})]}),t.jsxRuntimeExports.jsxs("div",{className:"space-y-2",children:[t.jsxRuntimeExports.jsxs("div",{className:"flex items-center justify-between gap-5",children:[t.jsxRuntimeExports.jsx(t.Label,{children:i}),t.jsxRuntimeExports.jsx(Du,{})]}),t.jsxRuntimeExports.jsx("div",{className:"my-1 space-y-1",children:a.map((u,c)=>t.jsxRuntimeExports.jsx(Mu,{col:u,idx:c},u))})]})]})}function Mu({col:e,idx:n}){const r=t.useEditorStore(a=>{var u;return(u=a.card)==null?void 0:u.preferences}),i=t.useEditorStore(a=>{var u;return(u=a.card.preferences)==null?void 0:u.datasetOptions}),s=i==null?void 0:i.find(a=>a.idx===n),{setCardPreferences:l}=t.useEditorStore(a=>a.actions);function o(a){if(!s)l({...r,datasetOptions:[...i||[],{idx:n,type:a==="area"?"line":a,fill:a==="area"?"origin":""}]});else{const u={...s};u.type=a==="area"?"line":a,u.fill=a==="area"?"origin":"";const c=i==null?void 0:i.map(x=>x.idx===n?u:x);l({...r,datasetOptions:c})}}return t.jsxRuntimeExports.jsxs("div",{className:"group flex items-center justify-between gap-5 rounded-md bg-muted/70 px-2 py-1 hover:bg-muted",children:[t.jsxRuntimeExports.jsx("p",{children:e}),t.jsxRuntimeExports.jsxs("div",{className:"flex gap-2",children:[t.jsxRuntimeExports.jsx($t,{onClick:()=>o("bar"),className:"invisible size-4 cursor-pointer text-muted-foreground hover:text-foreground group-hover:visible"}),t.jsxRuntimeExports.jsx(Kt,{onClick:()=>o("line"),className:"invisible size-4 cursor-pointer text-muted-foreground hover:text-foreground group-hover:visible"}),t.jsxRuntimeExports.jsx(ci,{onClick:()=>o("area"),className:"invisible size-4 cursor-pointer text-muted-foreground hover:text-foreground group-hover:visible"}),t.jsxRuntimeExports.jsx(t.Separator,{orientation:"vertical",className:"invisible size-4 cursor-pointer py-2 text-muted-foreground hover:text-foreground group-hover:visible"}),t.jsxRuntimeExports.jsx(Fu,{idx:n})]})]})}function Pu({cardType:e}){return t.jsxRuntimeExports.jsx("div",{className:"space-y-6 px-6 py-2",children:t.jsxRuntimeExports.jsxs(t.Accordion,{defaultValue:["item-2"],type:"multiple",children:[t.jsxRuntimeExports.jsxs(t.AccordionItem,{value:"item-1",children:[t.jsxRuntimeExports.jsx(t.AccordionTrigger,{children:`${t.titleCase(e)} Chart`}),t.jsxRuntimeExports.jsxs(t.AccordionContent,{className:"space-y-4 font-mono text-xs",children:[t.jsxRuntimeExports.jsx("div",{className:"rounded bg-muted px-2 py-1 text-xs",children:"SELECT x-axis, y-axis-1, y-axis-2,... FROM table"}),t.jsxRuntimeExports.jsxs("ul",{className:"ml-6 list-disc text-xs [&>li]:mt-2",children:[t.jsxRuntimeExports.jsx("li",{children:"x-axis - category"}),t.jsxRuntimeExports.jsx("li",{children:"y-axis1 - number"}),t.jsxRuntimeExports.jsx("li",{children:"y-axis2 - number"})]}),t.jsxRuntimeExports.jsxs("div",{children:["See ",t.jsxRuntimeExports.jsx("a",{target:"_blank",onClick:n=>n.stopPropagation(),className:"text-blue-700",href:"https://docs.semaphor.cloud/concepts/visuals#line-chart",children:"example"})," in the docs."]})]})]}),t.jsxRuntimeExports.jsxs(t.AccordionItem,{value:"item-2",children:[t.jsxRuntimeExports.jsx(t.AccordionTrigger,{children:"Settings"}),t.jsxRuntimeExports.jsxs(t.AccordionContent,{className:"space-y-4 px-2",children:[t.jsxRuntimeExports.jsx(un,{}),t.jsxRuntimeExports.jsx(li,{})]})]}),t.jsxRuntimeExports.jsxs(t.AccordionItem,{value:"item-3",children:[t.jsxRuntimeExports.jsx(t.AccordionTrigger,{children:"Filter on click"}),t.jsxRuntimeExports.jsx(t.AccordionContent,{className:"px-2",children:t.jsxRuntimeExports.jsx(We,{})})]})]})})}function cn(){var i,s,l;const e=t.useEditorStore(o=>o.card.cfg),n=t.useEditorStore(o=>o.actions.setCardCfg);function r(o){var c;const a={datalabels:{display:o!=="none",align:o,anchor:o,clamp:!0}},u={...e,options:{...e==null?void 0:e.options,plugins:{...(c=e==null?void 0:e.options)==null?void 0:c.plugins,...a}}};n(u),console.log(o)}return t.jsxRuntimeExports.jsxs("div",{className:"space-y-2",children:[t.jsxRuntimeExports.jsx("label",{className:"font-medium",children:"Data Labels"}),t.jsxRuntimeExports.jsxs(t.Select,{value:(l=(s=(i=e==null?void 0:e.options)==null?void 0:i.plugins)==null?void 0:s.datalabels)==null?void 0:l.anchor,onValueChange:r,defaultValue:"none",children:[t.jsxRuntimeExports.jsx(t.SelectTrigger,{className:"h-8 w-[180px] focus:ring-1 focus:ring-offset-0",children:t.jsxRuntimeExports.jsx(t.SelectValue,{placeholder:"Select position"})}),t.jsxRuntimeExports.jsx(t.SelectContent,{children:t.jsxRuntimeExports.jsxs(t.SelectGroup,{children:[t.jsxRuntimeExports.jsx(t.SelectLabel,{children:"Data Labels"}),t.jsxRuntimeExports.jsx(t.SelectItem,{value:"none",children:"None"}),t.jsxRuntimeExports.jsx(t.SelectItem,{value:"start",children:"Start"}),t.jsxRuntimeExports.jsx(t.SelectItem,{value:"center",children:"Center"}),t.jsxRuntimeExports.jsx(t.SelectItem,{value:"end",children:"End"})]})})]})]})}function Bu({cardType:e}){function n(r){const i="SELECT label, [group], x-axis, y-axis, radius FROM table",s="SELECT label, [group], x-axis, y-axis FROM table";return t.jsxRuntimeExports.jsxs(t.jsxRuntimeExports.Fragment,{children:[t.jsxRuntimeExports.jsx("div",{className:"bg-muted px-2 py-1 rounded text-xs",children:r==="bubble"?i:s}),t.jsxRuntimeExports.jsxs("ul",{className:" ml-6 list-disc [&>li]:mt-2 text-xs",children:[t.jsxRuntimeExports.jsx("li",{children:"label - category"}),t.jsxRuntimeExports.jsx("li",{children:"group - category"}),t.jsxRuntimeExports.jsx("li",{children:"x-axis - category"}),t.jsxRuntimeExports.jsx("li",{children:"y-axis - category"}),r==="bubble"&&t.jsxRuntimeExports.jsx("li",{children:"radius - number"})]}),t.jsxRuntimeExports.jsxs("div",{children:["See ",t.jsxRuntimeExports.jsx("a",{target:"_blank",onClick:l=>l.stopPropagation(),className:"text-blue-700",href:"https://docs.semaphor.cloud/concepts/visuals#pie-chart",children:"example"})," in the docs."]})]})}return t.jsxRuntimeExports.jsx("div",{className:"px-6 py-2 space-y-6",children:t.jsxRuntimeExports.jsxs(t.Accordion,{defaultValue:["item-2"],type:"multiple",children:[t.jsxRuntimeExports.jsxs(t.AccordionItem,{value:"item-1",children:[t.jsxRuntimeExports.jsx(t.AccordionTrigger,{children:`${t.titleCase(e)} Chart`}),t.jsxRuntimeExports.jsx(t.AccordionContent,{className:" space-y-4 font-mono text-xs ",children:n(e)})]}),t.jsxRuntimeExports.jsxs(t.AccordionItem,{value:"item-2",children:[t.jsxRuntimeExports.jsx(t.AccordionTrigger,{children:"Settings"}),t.jsxRuntimeExports.jsx(t.AccordionContent,{className:"px-2",children:t.jsxRuntimeExports.jsx(cn,{})})]}),t.jsxRuntimeExports.jsxs(t.AccordionItem,{value:"item-3",children:[t.jsxRuntimeExports.jsx(t.AccordionTrigger,{children:"Filter on click"}),t.jsxRuntimeExports.jsx(t.AccordionContent,{className:"px-2",children:t.jsxRuntimeExports.jsx(We,{})})]})]})})}const _u={datasets:[{type:"line",label:"Sum_sales",data:[]},{type:"bar",label:"Sum_profit",data:[]}]},qu={datasets:[{fill:"origin",type:"line",label:"Sum_sales",data:[]}]};function Vu(){const e=t.useEditorStore(n=>n.card.type);return t.jsxRuntimeExports.jsxs("div",{className:"p-6 space-y-6",children:[t.jsxRuntimeExports.jsx(t.Accordion,{className:" ",type:"single",collapsible:!0,children:Hu(e)}),t.jsxRuntimeExports.jsx("section",{className:"",children:["line","bar"].includes(e)&&t.jsxRuntimeExports.jsx(un,{})}),t.jsxRuntimeExports.jsx("div",{children:!["kpi"].includes(e)&&t.jsxRuntimeExports.jsx(cn,{})}),t.jsxRuntimeExports.jsx("div",{children:!["kpi"].includes(e)&&t.jsxRuntimeExports.jsx(We,{})})]})}function Hu(e){if(["line","bar"].includes(e))return t.jsxRuntimeExports.jsxs(t.jsxRuntimeExports.Fragment,{children:[t.jsxRuntimeExports.jsxs(t.AccordionItem,{value:"item-1",children:[t.jsxRuntimeExports.jsx(t.AccordionTrigger,{className:" font-normal",children:t.jsxRuntimeExports.jsx("p",{children:"Chart Query"})}),t.jsxRuntimeExports.jsxs(t.AccordionContent,{className:" ",children:[t.jsxRuntimeExports.jsx("div",{className:"bg-muted px-2 py-1 rounded font-mono font-semibold text-xs",children:"SELECT x-axis, y-axis-1, y-axis-2, y-axis-3,... FROM table"}),t.jsxRuntimeExports.jsxs("ul",{className:"my-6 ml-6 list-disc [&>li]:mt-2 font-normal text-xs",children:[t.jsxRuntimeExports.jsx("li",{children:"X-axis - Category (ex. city)"}),t.jsxRuntimeExports.jsx("li",{children:"Y-axis - Number (ex. population)"})]})]})]}),t.jsxRuntimeExports.jsxs(t.AccordionItem,{value:"item-2",children:[t.jsxRuntimeExports.jsx(t.AccordionTrigger,{className:" font-normal",children:"Mixed Chart"}),t.jsxRuntimeExports.jsxs(t.AccordionContent,{className:" text-xs space-y-2",children:[t.jsxRuntimeExports.jsxs("p",{children:["Click ",t.jsxRuntimeExports.jsx("b",{children:"Customize"})," and change the `type` property in the dataset."]}),t.jsxRuntimeExports.jsx("pre",{children:JSON.stringify(_u,null,2)})]})]}),t.jsxRuntimeExports.jsxs(t.AccordionItem,{value:"item-3",children:[t.jsxRuntimeExports.jsx(t.AccordionTrigger,{className:" font-normal",children:"Area Chart"}),t.jsxRuntimeExports.jsxs(t.AccordionContent,{className:" text-xs space-y-2",children:[t.jsxRuntimeExports.jsxs("p",{children:["Click ",t.jsxRuntimeExports.jsx("b",{children:"Customize"})," and add `fill` property to the dataset. See",t.jsxRuntimeExports.jsx("a",{className:"text-blue-500 hover:underline mx-1",href:"https://www.chartjs.org/docs/latest/samples/area/line-boundaries.html",target:"_blank",children:"docs"}),"for more options."]}),t.jsxRuntimeExports.jsx("pre",{children:JSON.stringify(qu,null,2)})]})]})]});if(e==="bubble")return t.jsxRuntimeExports.jsx(t.jsxRuntimeExports.Fragment,{children:t.jsxRuntimeExports.jsxs(t.AccordionItem,{value:"item-1",children:[t.jsxRuntimeExports.jsx(t.AccordionTrigger,{className:" font-normal",children:t.jsxRuntimeExports.jsxs("p",{children:["How to create a ",t.jsxRuntimeExports.jsx("span",{children:e})," chart query?"]})}),t.jsxRuntimeExports.jsxs(t.AccordionContent,{className:" ",children:[t.jsxRuntimeExports.jsx("div",{className:"bg-muted px-2 py-1 rounded font-mono font-semibold text-xs",children:"SELECT label, x-axis, y-axis, radius FROM table"}),t.jsxRuntimeExports.jsxs("ul",{className:"my-6 ml-6 list-disc [&>li]:mt-2 font-normal text-xs",children:[t.jsxRuntimeExports.jsx("li",{children:"Label - Category (ex. city)"}),t.jsxRuntimeExports.jsx("li",{children:"Bubble Group (opt) - Category (ex. state)"}),t.jsxRuntimeExports.jsx("li",{children:"X-axis - Number (ex. avg. age)"}),t.jsxRuntimeExports.jsx("li",{children:"Y-axis - Number (ex. avg. weight)"}),t.jsxRuntimeExports.jsx("li",{children:"Radius - Number (ex. population)"})]})]})]})});if(e==="scatter")return t.jsxRuntimeExports.jsx(t.jsxRuntimeExports.Fragment,{children:t.jsxRuntimeExports.jsxs(t.AccordionItem,{value:"item-1",children:[t.jsxRuntimeExports.jsx(t.AccordionTrigger,{className:" font-normal",children:t.jsxRuntimeExports.jsxs("p",{children:["How to create a ",t.jsxRuntimeExports.jsx("span",{children:e})," chart query?"]})}),t.jsxRuntimeExports.jsxs(t.AccordionContent,{className:" ",children:[t.jsxRuntimeExports.jsx("div",{className:"bg-muted px-2 py-1 rounded font-mono font-semibold text-xs",children:"SELECT label, x-axis, y-axis FROM table"}),t.jsxRuntimeExports.jsxs("ul",{className:"my-6 ml-6 list-disc [&>li]:mt-2 font-normal text-xs",children:[t.jsxRuntimeExports.jsx("li",{children:"Label - Category (ex. city)"}),t.jsxRuntimeExports.jsx("li",{children:"Group (opt) - Category (ex. state)"}),t.jsxRuntimeExports.jsx("li",{children:"X-axis - Number (ex. avg. age)"}),t.jsxRuntimeExports.jsx("li",{children:"Y-axis - Number (ex. avg. weight)"})]})]})]})});if(["pie","doughnut","polarArea"].includes(e))return t.jsxRuntimeExports.jsx(t.jsxRuntimeExports.Fragment,{children:t.jsxRuntimeExports.jsxs(t.AccordionItem,{value:"item-1",children:[t.jsxRuntimeExports.jsx(t.AccordionTrigger,{className:" font-normal",children:t.jsxRuntimeExports.jsxs("p",{children:[t.jsxRuntimeExports.jsx("span",{children:e==="polarArea"?"Polar":e.charAt(0).toUpperCase()+e.slice(1)})," ","chart query"]})}),t.jsxRuntimeExports.jsxs(t.AccordionContent,{className:" ",children:[t.jsxRuntimeExports.jsx("div",{className:"bg-muted px-2 py-1 rounded font-mono font-semibold text-xs",children:"SELECT label, measure FROM table"}),t.jsxRuntimeExports.jsxs("ul",{className:"my-6 ml-6 list-disc [&>li]:mt-2 font-normal text-xs",children:[t.jsxRuntimeExports.jsx("li",{children:"Label - Category (ex. city)"}),t.jsxRuntimeExports.jsx("li",{children:"Measure - Number (ex. population)"})]})]})]})})}function Uu(){var o,a,u;const e=t.useEditorStore(c=>c.card.preferences),n=t.useEditorStore(c=>c.actions.setCardPreferences),r=t.useEditorStore(c=>c.actions.setNumberFormat),i=t.useEditorStore(c=>{var x,p;return(p=(x=c.card.preferences)==null?void 0:x.formatNumber)==null?void 0:p.format}),s=t.useEditorStore(c=>{var x,p;return(p=(x=c.card.preferences)==null?void 0:x.formatNumber)==null?void 0:p.locale}),l=t.useEditorStore(c=>{var x,p;return(p=(x=c.card.preferences)==null?void 0:x.formatNumber)==null?void 0:p.currency});return t.useEditorStore(c=>c.actions.setFilterOnClickField),t.jsxRuntimeExports.jsxs("div",{children:[t.jsxRuntimeExports.jsxs("div",{className:"mb-3 flex items-center gap-2",children:[t.jsxRuntimeExports.jsx(t.Checkbox,{checked:!!((o=e==null?void 0:e.formatNumber)!=null&&o.enabled),onCheckedChange:c=>{n({...e,formatNumber:{...e==null?void 0:e.formatNumber,enabled:c}})}}),t.jsxRuntimeExports.jsx(t.Label,{children:"Format Number"})]}),((a=e==null?void 0:e.formatNumber)==null?void 0:a.enabled)===!0&&t.jsxRuntimeExports.jsxs("div",{className:"flex flex-col gap-2",children:[t.jsxRuntimeExports.jsxs("div",{children:[t.jsxRuntimeExports.jsx(t.Label,{className:"text-xs",children:"Currency"}),t.jsxRuntimeExports.jsxs("div",{className:"flex gap-1",children:[t.jsxRuntimeExports.jsx(t.Input,{value:l||"",className:"h-7 font-mono text-xs focus-visible:ring-0 focus-visible:ring-ring focus-visible:ring-offset-0",placeholder:"USD",onChange:c=>{var x,p,m;return r(((x=e==null?void 0:e.formatNumber)==null?void 0:x.format)||"",c.target.value,((p=e==null?void 0:e.formatNumber)==null?void 0:p.locale)||"",((m=e==null?void 0:e.formatNumber)==null?void 0:m.suffix)||"")}}),t.jsxRuntimeExports.jsx(t.Input,{value:s||"",className:"h-7 font-mono text-xs focus-visible:ring-0 focus-visible:ring-ring focus-visible:ring-offset-0",placeholder:"en-US",onChange:c=>{var x,p,m;return r(((x=e==null?void 0:e.formatNumber)==null?void 0:x.format)||"",((p=e==null?void 0:e.formatNumber)==null?void 0:p.currency)||"",c.target.value,((m=e==null?void 0:e.formatNumber)==null?void 0:m.suffix)||"")}})]})]}),t.jsxRuntimeExports.jsxs("div",{children:[t.jsxRuntimeExports.jsxs("div",{className:"flex gap-1",children:[t.jsxRuntimeExports.jsx(t.Label,{className:"text-xs",children:"Format"}),t.jsxRuntimeExports.jsxs(t.Tooltip,{children:[t.jsxRuntimeExports.jsx(t.TooltipTrigger,{children:t.jsxRuntimeExports.jsx(t.InfoCircledIcon,{strokeWidth:1,className:"h-3 w-3 opacity-70"})}),t.jsxRuntimeExports.jsx(t.TooltipContent,{children:t.jsxRuntimeExports.jsxs("div",{className:"max-w-[200px]",children:["Format number",t.jsxRuntimeExports.jsx("div",{className:"mt-1 font-mono text-xs",children:"#.## for 123.43"})]})})]})]}),t.jsxRuntimeExports.jsx("div",{children:t.jsxRuntimeExports.jsx(t.Input,{value:i||"",className:"h-7 font-mono text-xs focus-visible:ring-0 focus-visible:ring-ring focus-visible:ring-offset-0",placeholder:"###,###.##",onChange:c=>{var x,p,m;return r(c.target.value,((x=e==null?void 0:e.formatNumber)==null?void 0:x.currency)||"",((p=e==null?void 0:e.formatNumber)==null?void 0:p.locale)||"",((m=e==null?void 0:e.formatNumber)==null?void 0:m.suffix)||"")}})})]}),t.jsxRuntimeExports.jsxs("div",{children:[t.jsxRuntimeExports.jsx(t.Label,{className:"text-xs",children:"Suffix"}),t.jsxRuntimeExports.jsx(t.Input,{value:((u=e==null?void 0:e.formatNumber)==null?void 0:u.suffix)||"",className:"h-7 font-mono text-xs focus-visible:ring-0 focus-visible:ring-ring focus-visible:ring-offset-0",placeholder:"K, M, B",onChange:c=>{var x,p,m;return r(((x=e==null?void 0:e.formatNumber)==null?void 0:x.format)||"",((p=e==null?void 0:e.formatNumber)==null?void 0:p.currency)||"",((m=e==null?void 0:e.formatNumber)==null?void 0:m.locale)||"",c.target.value)}})]})]})]})}function $u(){return t.jsxRuntimeExports.jsxs("div",{className:"space-y-6 px-6 py-2",children:[t.jsxRuntimeExports.jsx(t.Accordion,{type:"single",collapsible:!0,children:t.jsxRuntimeExports.jsxs(t.AccordionItem,{value:"item-1",children:[t.jsxRuntimeExports.jsx(t.AccordionTrigger,{className:"",children:"KPI Query"}),t.jsxRuntimeExports.jsxs(t.AccordionContent,{className:"font-mono",children:[t.jsxRuntimeExports.jsx("div",{className:"rounded bg-muted px-2 py-1 font-mono text-xs",children:"SELECT current, previous FROM table"}),t.jsxRuntimeExports.jsxs("ul",{className:"my-6 ml-6 list-disc text-xs [&>li]:mt-2",children:[t.jsxRuntimeExports.jsx("li",{children:"current - number"}),t.jsxRuntimeExports.jsx("li",{children:"previous - number"})]}),t.jsxRuntimeExports.jsxs("div",{children:["See ",t.jsxRuntimeExports.jsx("a",{target:"_blank",onClick:e=>e.stopPropagation(),className:"text-blue-700",href:"https://docs.semaphor.cloud/concepts/visuals#kpi",children:"example"})," in the docs."]})]})]})}),t.jsxRuntimeExports.jsx("section",{className:"",children:t.jsxRuntimeExports.jsx(Uu,{})}),t.jsxRuntimeExports.jsx("div",{}),t.jsxRuntimeExports.jsx("div",{})]})}function Ku({cardType:e}){return t.jsxRuntimeExports.jsx("div",{className:"px-6 py-2 space-y-6",children:t.jsxRuntimeExports.jsxs(t.Accordion,{defaultValue:["item-2"],type:"multiple",children:[t.jsxRuntimeExports.jsxs(t.AccordionItem,{value:"item-1",children:[t.jsxRuntimeExports.jsx(t.AccordionTrigger,{children:`${t.titleCase(e)} Chart`}),t.jsxRuntimeExports.jsxs(t.AccordionContent,{className:" space-y-4 font-mono text-xs ",children:[t.jsxRuntimeExports.jsx("div",{className:"bg-muted px-2 py-1 rounded text-xs",children:"SELECT label, measure FROM table"}),t.jsxRuntimeExports.jsxs("ul",{className:" ml-6 list-disc [&>li]:mt-2 text-xs",children:[t.jsxRuntimeExports.jsx("li",{children:"label - category"}),t.jsxRuntimeExports.jsx("li",{children:"measure - number"})]}),t.jsxRuntimeExports.jsxs("div",{children:["See ",t.jsxRuntimeExports.jsx("a",{target:"_blank",onClick:n=>n.stopPropagation(),className:"text-blue-700",href:"https://docs.semaphor.cloud/concepts/visuals#pie-chart",children:"example"})," in the docs."]})]})]}),t.jsxRuntimeExports.jsxs(t.AccordionItem,{value:"item-2",children:[t.jsxRuntimeExports.jsx(t.AccordionTrigger,{children:"Settings"}),t.jsxRuntimeExports.jsx(t.AccordionContent,{className:"px-2",children:t.jsxRuntimeExports.jsx(cn,{})})]}),t.jsxRuntimeExports.jsxs(t.AccordionItem,{value:"item-3",children:[t.jsxRuntimeExports.jsx(t.AccordionTrigger,{children:"Filter on click"}),t.jsxRuntimeExports.jsx(t.AccordionContent,{className:"px-2",children:t.jsxRuntimeExports.jsx(We,{})})]})]})})}function Wu(){return t.jsxRuntimeExports.jsx("div",{className:"space-y-6 px-6 py-2",children:t.jsxRuntimeExports.jsxs(t.Accordion,{defaultValue:["item-2"],type:"multiple",children:[t.jsxRuntimeExports.jsxs(t.AccordionItem,{value:"item-1",children:[t.jsxRuntimeExports.jsx(t.AccordionTrigger,{children:"Stacked Chart"}),t.jsxRuntimeExports.jsxs(t.AccordionContent,{className:"space-y-4 font-mono text-xs",children:[t.jsxRuntimeExports.jsx("div",{className:"rounded bg-muted px-2 py-1 text-xs",children:"SELECT x-axis, stack-by, y-axis FROM table"}),t.jsxRuntimeExports.jsxs("ul",{className:"ml-6 list-disc text-xs [&>li]:mt-2",children:[t.jsxRuntimeExports.jsx("li",{children:"x-axis - category"}),t.jsxRuntimeExports.jsx("li",{children:"stack by - category"}),t.jsxRuntimeExports.jsx("li",{children:"y-axis - number"})]}),t.jsxRuntimeExports.jsxs("div",{children:["See ",t.jsxRuntimeExports.jsx("a",{target:"_blank",onClick:e=>e.stopPropagation(),className:"text-blue-700",href:"https://docs.semaphor.cloud/concepts/visuals#stacked-chart",children:"example"})," in the docs."]})]})]}),t.jsxRuntimeExports.jsxs(t.AccordionItem,{value:"item-2",children:[t.jsxRuntimeExports.jsx(t.AccordionTrigger,{children:"Settings"}),t.jsxRuntimeExports.jsxs(t.AccordionContent,{className:"space-y-4 px-2",children:[t.jsxRuntimeExports.jsx(un,{}),t.jsxRuntimeExports.jsx(li,{})]})]}),t.jsxRuntimeExports.jsxs(t.AccordionItem,{value:"item-3",children:[t.jsxRuntimeExports.jsx(t.AccordionTrigger,{children:"Filter on click"}),t.jsxRuntimeExports.jsx(t.AccordionContent,{className:"px-2",children:t.jsxRuntimeExports.jsx(We,{})})]})]})})}function Qu({cardType:e}){return console.log("TableVisualSettings",e),t.jsxRuntimeExports.jsx("div",{className:"space-y-6 px-6 py-2",children:t.jsxRuntimeExports.jsx(t.Accordion,{defaultValue:["item-3"],type:"multiple",children:t.jsxRuntimeExports.jsxs(t.AccordionItem,{value:"item-3",children:[t.jsxRuntimeExports.jsx(t.AccordionTrigger,{children:"Filter on click"}),t.jsxRuntimeExports.jsx(t.AccordionContent,{className:"px-2",children:t.jsxRuntimeExports.jsx(We,{})})]})})})}function Gu(){const e=t.useEditorStore(r=>r.card.type);function n(r){switch(r){case"stackedBar":return t.jsxRuntimeExports.jsx(Wu,{});case"kpi":return t.jsxRuntimeExports.jsx($u,{});case"line":case"bar":return t.jsxRuntimeExports.jsx(Pu,{cardType:r});case"pie":case"doughnut":case"polarArea":case"radar":return t.jsxRuntimeExports.jsx(Ku,{cardType:r});case"bubble":case"scatter":return t.jsxRuntimeExports.jsx(Bu,{cardType:r});case"table":return t.jsxRuntimeExports.jsx(Qu,{cardType:r});default:return t.jsxRuntimeExports.jsx(Vu,{})}}return t.jsxRuntimeExports.jsx(t.ScrollArea,{className:"h-full w-full text-sm",children:n(e)})}function Ju(){const e=t.useEditorStore(n=>n.isShowingVisual);return t.jsxRuntimeExports.jsxs(Ot,{direction:"vertical",className:"min-w-full max-w-lg min-h-[250px]",children:[t.jsxRuntimeExports.jsx(Ve,{role:"query-section",className:"flex",minSize:20,defaultSize:40,children:t.jsxRuntimeExports.jsx(vu,{})}),t.jsxRuntimeExports.jsx(Dt,{withHandle:!0,className:"border "}),t.jsxRuntimeExports.jsx(Ve,{className:"pb-1",role:"visual-section",minSize:0,defaultSize:60,children:e?t.jsxRuntimeExports.jsxs(Ot,{direction:"horizontal",children:[t.jsxRuntimeExports.jsx(t.jsxRuntimeExports.Fragment,{children:t.jsxRuntimeExports.jsx(Ve,{className:"flex min-w-[275px]",minSize:20,defaultSize:25,maxSize:30,children:t.jsxRuntimeExports.jsx(Gu,{})})}),t.jsxRuntimeExports.jsx(Dt,{className:"border "}),t.jsxRuntimeExports.jsx(Ve,{minSize:40,defaultSize:75,maxSize:100,children:t.jsxRuntimeExports.jsx(rr,{})})]}):t.jsxRuntimeExports.jsx(rr,{})})]})}function Xu({authToken:e,onSave:n,onClose:r}){const i=t.useEditorStore(o=>o.actions.setOnSave),s=t.useEditorStore(o=>o.actions.setOnClose),l=t.useDashboardStore(o=>o.actions.setAuthToken);return A.useEffect(()=>{n&&i(n),r&&s(r)},[n,i,r,s]),A.useEffect(()=>{e&&e.accessToken&&l(e)},[e,l]),t.jsxRuntimeExports.jsxs(t.EditorPanel,{className:"rounded-none",role:"editor-panel",children:[t.jsxRuntimeExports.jsx(t.EditorAside,{className:"rounded-none border-r-[1.5px]",children:t.jsxRuntimeExports.jsx(xr,{})}),t.jsxRuntimeExports.jsx(t.EditorMain,{children:t.jsxRuntimeExports.jsx(Ju,{})})]})}function Yu(){t.useDashboardStore(o=>o.selectedCardId);const e=t.useDashboardStore(o=>o.selectedSheetId),{setIsVisualEditing:n}=t.useDashboardStore(o=>o.actions),r=t.useDashboardStore(o=>o.isVisualEditing),i=t.useDashboardStore(o=>o.actions.updateFrame);function s(o){e&&(i(e,o),n(!1))}function l(){n(!1)}return t.jsxRuntimeExports.jsx("div",{role:"editor-container",className:t.cn("flex grow",{block:r,hidden:!r}),children:t.jsxRuntimeExports.jsx(Xu,{onSave:s,onClose:l})})}function Zu({columns:e,tableName:n}){const r=t.useEditorStore(p=>p.selectedConnectionId),i=t.useEditorStore(p=>p.selectedDatabaseName),s=t.useEditorStore(p=>p.selectedSchemaName),l=t.useEditorStore(p=>p.selectedTableName),o=t.useDashboardStore(p=>p.dashboard.filters)||[],a=t.useDashboardStore(p=>p.actions.addFilter),u=t.useDashboardStore(p=>p.actions.removeFilter),c=t.useDashboardStore(p=>p.actions.removeFilterValue);function x(p){const m=t.fmt(p.column_name),d=t.fmt(i||""),g=t.fmt(s||""),y=t.fmt(n),k=t.getQualifiedTableName(g,y),E=`${k}.${m}`;console.log("find",E,y,d);const R=o==null?void 0:o.find(C=>C.column===E&&C.table===y&&(C.database===d||C.database===i));if(R)c(R.id),u(R.id);else{if(n==="api"&&r){a({id:t.v4(),column:E,title:p.column_name,dataType:p.data_type,table:"api",database:"NA",connectionId:r,operation:"in",sql:t.getDefaultFilterSql(p.data_type,k,m)});return}if(!r||!i||!l)throw new Error("missing connectionId, database, or table");a({id:t.v4(),column:`${k}.${m}`,title:p.column_name,dataType:p.data_type,table:l,database:i,connectionId:r,operation:"in",sql:t.getDefaultFilterSql(p.data_type,k,m)})}}return t.jsxRuntimeExports.jsx("div",{className:"xbg-red-100 flex-1 basis-0 flex-col overflow-scroll px-3",children:e==null?void 0:e.map(p=>{const m=o==null?void 0:o.find(d=>d.column===t.fmt(p.column_name)&&d.table===l&&d.database===i);return t.jsxRuntimeExports.jsx("div",{onClick:()=>x(p),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":m}),children:t.jsxRuntimeExports.jsxs("div",{className:"flex items-center gap-2",children:[t.jsxRuntimeExports.jsx(cr,{column:p}),t.jsxRuntimeExports.jsx("span",{children:p.column_name})]})},p.column_name)})})}function ec(){t.useDashboardStore(n=>n.showFilters);const e=t.useDashboardStore(n=>n.actions.setShowFilters);return t.jsxRuntimeExports.jsxs("section",{className:"relative flex grow flex-col border-l px-4",children:[t.jsxRuntimeExports.jsxs("div",{className:"mt-4 flex items-center justify-between gap-2 px-3",children:[t.jsxRuntimeExports.jsx(t.Label,{className:"text-lg",children:"Filters"}),t.jsxRuntimeExports.jsx(t.Button,{onClick:()=>e(!1),className:"h-7 w-7 p-0",variant:"ghost",children:t.jsxRuntimeExports.jsx(t.Cross2Icon,{})})]}),t.jsxRuntimeExports.jsx("div",{className:"flex grow",children:t.jsxRuntimeExports.jsx(xr,{ColumnsComponent:(n,r,i)=>t.jsxRuntimeExports.jsx(Zu,{schemaName:n,tableName:r,columns:i})})})]})}function tc(){t.useDashboardStore(r=>r.dashboard);const e=t.useDashboardStore(r=>r.showFilters),n=t.useDashboardStore(r=>r.isVisualEditing);return t.useDashboardStore(r=>r.bookmarkKey),t.jsxRuntimeExports.jsxs("div",{role:"dashboard-plus-main",className:t.cn("grow",{hidden:n,flex:!n}),children:[t.jsxRuntimeExports.jsx(t.DashboardTabs,{}),e&&t.jsxRuntimeExports.jsx("div",{role:"filter-aside-container",className:"flex",children:t.jsxRuntimeExports.jsx(ec,{})})]})}function nc(){const e=t.useDashboardStore(i=>i.dashboard),n=t.useDashboardStore(i=>i.actions.setDashboard),r=t.useDashboardStore(i=>i.showDashboardJSON);return t.useDashboardStore(i=>i.actions.setShowDashboardJSON),t.jsxRuntimeExports.jsx("div",{className:t.cn(" p-2",{hidden:!r}),children:t.jsxRuntimeExports.jsx(t.de,{onChange:i=>{if(i)try{JSON.parse(i),n(JSON.parse(i))}catch{}},defaultLanguage:"json",className:"h-[550px] overflow-y-auto ",value:JSON.stringify(e,null,2),options:{minimap:{enabled:!1},glyphMargin:!1,wordWrap:"on",scrollbar:{verticalScrollbarSize:0,horizontalScrollbarSize:0},fontSize:12,renderLineHighlight:"none"}})})}function rc({showControls:e=!1,showFooter:n=!0,...r}){return t.jsxRuntimeExports.jsx(t.SemaphorContextProvider,{dashboardProps:r,children:t.jsxRuntimeExports.jsxs(t.UXProvider,{children:[t.jsxRuntimeExports.jsx(nc,{}),t.jsxRuntimeExports.jsxs(t.DashboardPanel,{...r,children:[e&&t.jsxRuntimeExports.jsx(Fi,{}),t.jsxRuntimeExports.jsx(Yu,{}),t.jsxRuntimeExports.jsx(tc,{})]})]})})}exports.DashboardPlus=rc;exports.SelectComponent=Je;exports.useEditorAside=pr;
228
+ Visual Query Syntax: ${gu}`,{data:S,isLoading:M,isFetching:K,isError:U,refetch:_}=t.useQuery({queryKey:["ai-query"],queryFn:()=>t.getRequest("https://semaphor.cloud/api/v1/ai",(u==null?void 0:u.accessToken)||"",{user_content:`userContent: ${z} ${c?T:""}`}),enabled:!1});function I(v){if(v.toLowerCase().includes("bar"))g("bar");else if(v.toLowerCase().includes("line"))g("line");else if(v.toLowerCase().includes("bubble"))g("bubble");else if(v.toLowerCase().includes("scatter"))g("scatter");else if(v.toLowerCase().includes("stacked"))g("stackedBar");else if(v.toLowerCase().includes("pie"))g("pie");else if(v.toLowerCase().includes("donut")||v.toLowerCase().includes("doughnut"))g("doughnut");else if(v.toLowerCase().includes("radar"))g("radar");else return g("bar"),!1;return!0}A.useEffect(()=>{S&&k(v=>[...v,{role:"ai",content:S.response}])},[S]),A.useEffect(()=>{const v=setTimeout(()=>{var h;a.current&&(a.current.scroll({top:a.current.scrollHeight,behavior:"smooth"}),(h=o.current)==null||h.focus())},100);return()=>clearTimeout(v)},[y]);function N(){r&&(k(v=>[...v,{role:"user",content:r}]),I(r)&&x(!0),i(""),_())}A.useEffect(()=>{s&&(N(),l(!1))},[s,l]);const $={fontFamily:"Arial, sans-serif",lineHeight:1.6,fontSize:15,width:"100%"},W={fontFamily:"monospace",fontSize:14,lineHeight:1.6},B={fontFamily:"Arial, sans-serif",lineHeight:1.6,fontSize:15,padding:"2px 0",marginLeft:20,listStyleType:"disc"},G={p:({node:v,...h})=>t.jsxRuntimeExports.jsx("p",{style:$,...h}),code:({node:v,...h})=>t.jsxRuntimeExports.jsx("code",{className:"rounded-sm bg-muted px-2 py-1 text-sm",...h}),pre:({node:v,...h})=>t.jsxRuntimeExports.jsxs("pre",{className:"space-y-2 rounded-sm bg-muted/50 p-3",style:W,children:[t.jsxRuntimeExports.jsx("code",{className:"whitespace-normal text-sm",children:h.children}),t.jsxRuntimeExports.jsxs("div",{className:"flex justify-start gap-2",children:[t.jsxRuntimeExports.jsx(t.Button,{onClick:L,size:"sm",variant:"outline",children:t.jsxRuntimeExports.jsx(t.ClipboardCopyIcon,{})}),t.jsxRuntimeExports.jsx(t.Button,{onClick:J=>{const re=L(J);re&&(n(!1),p(re),d(!0))},size:"sm",variant:"outline",children:t.jsxRuntimeExports.jsx(t.PlayIcon,{})})]})]}),li:({node:v,...h})=>t.jsxRuntimeExports.jsx("li",{style:B,...h})};function L(v){const h=v.currentTarget.closest("pre");if(!h)return;const J=h.textContent||h.innerText;return navigator.clipboard.writeText(J).then(()=>console.log("Text copied to clipboard")).catch(re=>console.error("Error in copying text: ",re)),J}function F(){return y==null?void 0:y.map((v,h)=>v.role==="user"?t.jsxRuntimeExports.jsxs("div",{className:"flex items-start rounded-md bg-muted p-3 text-sm",children:[t.jsxRuntimeExports.jsx(Li,{className:"mr-2 h-5 w-5"}),t.jsxRuntimeExports.jsx("div",{children:v.content})]},h):v.role==="ai"?t.jsxRuntimeExports.jsx(t.jsxRuntimeExports.Fragment,{children:t.jsxRuntimeExports.jsx(hu,{className:"w-full overflow-auto py-1",components:G,children:S==null?void 0:S.response},h)}):t.jsxRuntimeExports.jsx("div",{},h))}return t.jsxRuntimeExports.jsxs(t.Dialog,{open:e,onOpenChange:n,children:[t.jsxRuntimeExports.jsx(t.DialogTrigger,{asChild:!0,children:t.jsxRuntimeExports.jsx(t.Button,{size:"sm",className:"w-full justify-start border font-normal text-muted-foreground focus-visible:ring-0 focus-visible:ring-offset-0",variant:"secondary",children:"Type your question here..."})}),t.jsxRuntimeExports.jsxs(t.DialogContent,{className:"flex flex-col justify-between overflow-auto sm:max-w-[425px] md:max-h-[625px] md:min-w-[625px]",children:[t.jsxRuntimeExports.jsxs(t.DialogHeader,{children:[t.jsxRuntimeExports.jsx(t.DialogTitle,{children:"Assistant"}),t.jsxRuntimeExports.jsx(t.DialogDescription,{children:"What can I help you with?"})]}),t.jsxRuntimeExports.jsx("div",{ref:a,className:"h-[625px] w-full overflow-auto border-t border-t-muted",children:t.jsxRuntimeExports.jsx("div",{className:"space-y-4 py-2 pr-3",role:"messages",children:F()})}),t.jsxRuntimeExports.jsx("div",{children:t.jsxRuntimeExports.jsxs("div",{className:"flex w-full items-center rounded-md border",children:[t.jsxRuntimeExports.jsx(t.Textarea,{autoFocus:!0,ref:o,onKeyDown:v=>{v.key==="Enter"&&!v.shiftKey&&(v.preventDefault(),i(""),N())},placeholder:"Type your question here...",onFocus:v=>{const h=v.target,J=h.value.length;h.setSelectionRange(J,J)},className:t.cn("max-h-10 min-h-7 resize-none border-none focus-visible:ring-0 focus-visible:ring-ring focus-visible:ring-offset-0"),disabled:M||K,value:r,onChange:v=>i(v.target.value)})," ",t.jsxRuntimeExports.jsx(t.Button,{className:"h-8",size:"sm",variant:"ghost",onClick:N,children:!M&&!K?t.jsxRuntimeExports.jsx(t.PaperPlaneIcon,{}):t.jsxRuntimeExports.jsx(t.LoaderCircle,{className:"mr-2 h-4 w-4 animate-spin text-foreground/50"})})]})})]})]})}var Yr={color:void 0,size:void 0,className:void 0,style:void 0,attr:void 0},tr=A.createContext&&A.createContext(Yr),yu=["attr","size","title"];function Eu(e,n){if(e==null)return{};var r=bu(e,n),i,s;if(Object.getOwnPropertySymbols){var l=Object.getOwnPropertySymbols(e);for(s=0;s<l.length;s++)i=l[s],!(n.indexOf(i)>=0)&&Object.prototype.propertyIsEnumerable.call(e,i)&&(r[i]=e[i])}return r}function bu(e,n){if(e==null)return{};var r={},i=Object.keys(e),s,l;for(l=0;l<i.length;l++)s=i[l],!(n.indexOf(s)>=0)&&(r[s]=e[s]);return r}function xt(){return xt=Object.assign?Object.assign.bind():function(e){for(var n=1;n<arguments.length;n++){var r=arguments[n];for(var i in r)Object.prototype.hasOwnProperty.call(r,i)&&(e[i]=r[i])}return e},xt.apply(this,arguments)}function nr(e,n){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(e);n&&(i=i.filter(function(s){return Object.getOwnPropertyDescriptor(e,s).enumerable})),r.push.apply(r,i)}return r}function dt(e){for(var n=1;n<arguments.length;n++){var r=arguments[n]!=null?arguments[n]:{};n%2?nr(Object(r),!0).forEach(function(i){Su(e,i,r[i])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):nr(Object(r)).forEach(function(i){Object.defineProperty(e,i,Object.getOwnPropertyDescriptor(r,i))})}return e}function Su(e,n,r){return n=ku(n),n in e?Object.defineProperty(e,n,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[n]=r,e}function ku(e){var n=Ru(e,"string");return typeof n=="symbol"?n:String(n)}function Ru(e,n){if(typeof e!="object"||e===null)return e;var r=e[Symbol.toPrimitive];if(r!==void 0){var i=r.call(e,n||"default");if(typeof i!="object")return i;throw new TypeError("@@toPrimitive must return a primitive value.")}return(n==="string"?String:Number)(e)}function Zr(e){return e&&e.map((n,r)=>A.createElement(n.tag,dt({key:r},n.attr),Zr(n.child)))}function Pe(e){return n=>A.createElement(Cu,xt({attr:dt({},e.attr)},n),Zr(e.child))}function Cu(e){var n=r=>{var{attr:i,size:s,title:l}=e,o=Eu(e,yu),a=s||r.size||"1em",u;return r.className&&(u=r.className),e.className&&(u=(u?u+" ":"")+e.className),A.createElement("svg",xt({stroke:"currentColor",fill:"currentColor",strokeWidth:"0"},r.attr,i,o,{className:u,style:dt(dt({color:e.color||r.color},r.style),e.style),height:a,width:a,xmlns:"http://www.w3.org/2000/svg"}),l&&A.createElement("title",null,l),e.children)};return tr!==void 0?A.createElement(tr.Consumer,null,r=>n(r)):n(Yr)}function wu(e){return Pe({tag:"svg",attr:{viewBox:"0 0 448 512"},child:[{tag:"path",attr:{d:"M439.8 200.5c-7.7-30.9-22.3-54.2-53.4-54.2h-40.1v47.4c0 36.8-31.2 67.8-66.8 67.8H172.7c-29.2 0-53.4 25-53.4 54.3v101.8c0 29 25.2 46 53.4 54.3 33.8 9.9 66.3 11.7 106.8 0 26.9-7.8 53.4-23.5 53.4-54.3v-40.7H226.2v-13.6h160.2c31.1 0 42.6-21.7 53.4-54.2 11.2-33.5 10.7-65.7 0-108.6zM286.2 404c11.1 0 20.1 9.1 20.1 20.3 0 11.3-9 20.4-20.1 20.4-11 0-20.1-9.2-20.1-20.4.1-11.3 9.1-20.3 20.1-20.3zM167.8 248.1h106.8c29.7 0 53.4-24.5 53.4-54.3V91.9c0-29-24.4-50.7-53.4-55.6-35.8-5.9-74.7-5.6-106.8.1-45.2 8-53.4 24.7-53.4 55.6v40.7h106.9v13.6h-147c-31.1 0-58.3 18.7-66.8 54.2-9.8 40.7-10.2 66.1 0 108.6 7.6 31.6 25.7 54.2 56.8 54.2H101v-48.8c0-35.3 30.5-66.4 66.8-66.4zm-6.7-142.6c-11.1 0-20.1-9.1-20.1-20.3.1-11.3 9-20.4 20.1-20.4 11 0 20.1 9.2 20.1 20.4s-9 20.3-20.1 20.3z"},child:[]}]})(e)}function vu(){const{theme:e}=t.useTheme(),n=A.useRef(),r=A.useRef(),[i,s]=A.useState(!1),[l,o]=A.useState(!1),[a,u]=A.useState(!1),[c,x]=A.useState(""),[p,m]=A.useState(!1),{authToken:d}=t.useSemaphorContext();t.useDashboardStore(j=>j.selectedSheetId);const g=t.useDashboardStore(j=>j.dashboard.baseQueries),y=t.useEditorStore(j=>j.card),k=t.useDashboardStore(j=>j.theme),E=t.useEditorStore(j=>j.isShowingVisual),R=t.useEditorStore(j=>j.selectedConnectionId),C=t.useEditorStore(j=>j.selectedDatabaseName),z=t.useEditorStore(j=>j.selectedSchemaName);t.useDashboardStore(j=>j.actions.updateFrameCard);const T=t.useEditorStore(j=>j.selectedTableName),S=t.useEditorStore(j=>j.card.sql),M=t.useEditorStore(j=>j.card.python),K=t.resolveBaseQuery(S,g),U=t.useEditorStore(j=>j.selectedConnectionId),_=t.useEditorStore(j=>j.frame),I=t.useEditorStore(j=>j.filterValues),N=t.useEditorStore(j=>j.applyFilters),{setCardCustomCfg:$,setQueryResultColumns:W,setFilterValues:B,setCardSql:G,setCardPython:L,setQueryError:F,setPythonStdOut:v,setCardPreferences:h}=t.useEditorStore(j=>j.actions),J=t.useEditorStore(j=>j.onSave),re=t.useEditorStore(j=>j.actions.setApplyFilters),f=t.useEditorStore(j=>j.onClose),te=t.useEditorStore(j=>j.actions.setCardData),ue=t.useEditorStore(j=>j.actions.setSqlGen),Z=t.useEditorStore(j=>j.runSql),xe=t.useEditorStore(j=>j.actions.setRunSql),oe=t.useEditorStore(j=>j.actions.setIsSqlRunning),{data:ie,isLoading:le,isFetching:Ee,isSuccess:Be,isError:Ce,error:we,status:_e,refetch:be}=t.useQuery({queryKey:[K,M],queryFn:()=>t.postRequest("https://semaphor.cloud/api/v1/query",(d==null?void 0:d.accessToken)||"",{connection_id:U,sql:K,python:M===t.PYTHON_DEFAULT_CODE?"":M,active_filters:N?I:[]}),enabled:!1,retry:!1});A.useEffect(()=>{if(ie&&(te(ie.records),v((ie==null?void 0:ie.output)||""),ie.records.length>0)){const{dimensionKeys:j}=t.getKeys(ie.records);W(j)}},[ie,te,W,v]),A.useEffect(()=>{Z&&(be(),xe(!1))},[Z,be,xe]),A.useEffect(()=>{(le||Ee)&&oe(!0),(Ce||Be)&&oe(!1),Ce?(F(we.message),te([]),W([]),v("")):F("")},[le,Ee,ie,v,Ce,Be,oe,te,W,F,we]);function D(){G(""),te([]),ue({}),$(""),h({})}const Qe=j=>{r.current=j};function nt(){let j=S;S&&!S.includes("{{")&&(j=Bi(S),G(j));const O={...y,lastSelectedSchema:z,lastSelectedDatabase:C,lastSelectedTable:T,connectionId:R,type:E?y.type:"table",sql:j,customCfg:E?y.customCfg:null},q=_.cards.map(H=>H.id===y.id?O:H);J==null||J({..._,cards:q})}function gt(){f==null||f()}function jt(j){const O=getComputedStyle(document.documentElement).getPropertyValue(j);return yt(O)}function yt(j){const[O,q,H]=j.split(" "),ee=parseFloat(O),ve=parseFloat(q),ye=parseFloat(H),Oe=ve/100,Te=ye/100,ne=(1-Math.abs(2*Te-1))*Oe,de=ne*(1-Math.abs(ee/60%2-1)),me=Te-ne/2;let Ne=0,Ie=0,Ae=0;0<=ee&&ee<60?(Ne=ne,Ie=de,Ae=0):60<=ee&&ee<120?(Ne=de,Ie=ne,Ae=0):120<=ee&&ee<180?(Ne=0,Ie=ne,Ae=de):180<=ee&&ee<240?(Ne=0,Ie=de,Ae=ne):240<=ee&&ee<300?(Ne=de,Ie=0,Ae=ne):300<=ee&&ee<360&&(Ne=ne,Ie=0,Ae=de),Ne=Math.round((Ne+me)*255),Ie=Math.round((Ie+me)*255),Ae=Math.round((Ae+me)*255);const bt=ai=>{const St=ai.toString(16);return St.length==1?"0"+St:St};return`#${bt(Ne)}${bt(Ie)}${bt(Ae)}`}A.useEffect(()=>{const j=n.current,O=r.current;if(j){const q=window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light",H=k==="system"?q:k;j.editor.defineTheme("default",{base:H==="light"?"vs":"vs-dark",inherit:!0,rules:[],colors:{"editor.background":H==="light"?"#ffffff":jt("--background")}}),j.editor.setTheme("default")}return O&&j&&O.addCommand(j.KeyMod.Shift|j.KeyCode.Enter,function(){return console.log("Executing query..."),be(),!1}),()=>{}},[e,k,n.current]);function rt(j){n.current=j}function Et(){return t.jsxRuntimeExports.jsxs(t.jsxRuntimeExports.Fragment,{children:[l&&t.jsxRuntimeExports.jsx("div",{className:"xbg-yellow-100 relative flex w-1/3 min-w-0 grow overflow-hidden border-l p-1 text-xs",role:"editor-filter-container",children:t.jsxRuntimeExports.jsxs("div",{className:"w-[99%]",children:[t.jsxRuntimeExports.jsxs("div",{className:"flex items-center gap-2 pt-3",children:[t.jsxRuntimeExports.jsx(qi,{checked:N,onCheckedChange:()=>re(!N),text:"Apply Filters"}),t.jsxRuntimeExports.jsx(Vi,{}),I&&l&&t.jsxRuntimeExports.jsx(t.Cross2Icon,{onClick:()=>o(!1),className:"bg-background/50 text-foreground/50 hover:cursor-pointer hover:text-foreground"})]}),t.jsxRuntimeExports.jsx(t.Ft,{theme:"default",onChange:j=>{if(j)try{JSON.parse(j),B(JSON.parse(j))}catch{}},defaultLanguage:"json",className:"mt-1 min-h-[220px]",value:JSON.stringify(I,null,2),options:{readOnly:!0,minimap:{enabled:!1},lineNumbers:"off",glyphMargin:!1,wordWrap:"on",scrollbar:{verticalScrollbarSize:0,horizontalScrollbarSize:0},fontSize:12,renderLineHighlight:"none"}})]})}),I&&!l&&t.jsxRuntimeExports.jsx(sr,{onClick:()=>o(!0),className:t.cn("absolute bottom-4 right-6 h-3 w-3 text-foreground/50 hover:cursor-pointer hover:text-foreground",{"font-bold text-red-800":N})})]})}function b(){return t.jsxRuntimeExports.jsxs(Ot,{className:"flex grow pb-1",direction:"vertical",role:"editor-resizable-group",children:[t.jsxRuntimeExports.jsxs(Ve,{id:"1",order:1,defaultSize:i?20:100,className:"relative flex grow",children:[t.jsxRuntimeExports.jsx("div",{role:"sql-container",className:"relative flex w-[99%]",children:t.jsxRuntimeExports.jsx(t.Ft,{theme:"default",className:"pt-3",onChange:j=>{G(j)},value:S,options:{minimap:{enabled:!1},wordWrap:"on",scrollbar:{verticalScrollbarSize:0,horizontalScrollbarSize:0},fontSize:14,renderLineHighlight:"none"},defaultLanguage:"sql",defaultValue:"SELECT * FROM table",beforeMount:rt,onMount:Qe})}),i&&t.jsxRuntimeExports.jsx("code",{className:"absolute right-6 top-3 text-sm text-muted-foreground/70",children:"sql"})]}),i&&t.jsxRuntimeExports.jsxs(t.jsxRuntimeExports.Fragment,{children:[t.jsxRuntimeExports.jsx(Dt,{withHandle:!0,className:"border"}),t.jsxRuntimeExports.jsxs(Ve,{id:"2",order:2,defaultSize:80,className:"relative flex grow",children:[t.jsxRuntimeExports.jsx("div",{role:"python-container",className:"relative flex w-[99%] pt-0",children:t.jsxRuntimeExports.jsx(t.Ft,{className:"pt-3",theme:"default",onChange:j=>{L(j&&j.trim()||"")},value:M||t.PYTHON_DEFAULT_CODE,options:{minimap:{enabled:!1},wordWrap:"on",scrollbar:{verticalScrollbarSize:0,horizontalScrollbarSize:0},fontSize:14,renderLineHighlight:"none"},defaultLanguage:"python",beforeMount:rt,onMount:Qe})}),t.jsxRuntimeExports.jsx("code",{className:"absolute right-6 top-3 text-sm text-muted-foreground/70",children:"python"})]})]})]})}return t.jsxRuntimeExports.jsxs("section",{role:"editor-section",className:"flex grow flex-col justify-end",children:[t.jsxRuntimeExports.jsxs("div",{role:"sql-editor",className:"relative flex grow justify-between overflow-y-scroll",children:[b(),Et()]}),t.jsxRuntimeExports.jsxs("div",{role:"editor-controls",className:"item-center flex flex-wrap justify-between gap-2 px-6 py-4",children:[t.jsxRuntimeExports.jsxs("div",{className:"flex grow items-center gap-2",children:[t.jsxRuntimeExports.jsxs(t.Button,{disabled:le||Ee,onClick:()=>{be()},className:"shrink-0",size:"sm",variant:"outline",children:[le||Ee?t.jsxRuntimeExports.jsx(t.LoaderCircle,{className:"mr-2 h-4 w-4 animate-spin text-foreground/50"}):t.jsxRuntimeExports.jsx(Ri,{className:"mr-2 h-4 w-4"}),"Run"]}),Ce&&t.jsxRuntimeExports.jsx(_i,{error:we.message,setShowAIDialog:u,setTriggerAIRun:m,setUserInputforAI:x}),t.jsxRuntimeExports.jsxs(t.Button,{onClick:D,className:"",size:"sm",variant:"outline",children:[t.jsxRuntimeExports.jsx(di,{className:"mr-2 size-4"}),"Clear"]}),t.jsxRuntimeExports.jsx(t.Toggle,{pressed:i,onPressedChange:j=>s(j),className:"",size:"sm",variant:"outline",children:t.jsxRuntimeExports.jsx(wu,{className:"size-4 text-foreground/70"})}),t.jsxRuntimeExports.jsx(ju,{open:a,setOpen:u,userInput:c,triggerAIRun:p,setTriggerAIRun:m,setUserInput:j=>x(j)})]}),t.jsxRuntimeExports.jsxs("div",{className:"flex items-end gap-2",children:[t.jsxRuntimeExports.jsxs(t.Button,{onClick:nt,size:"sm",variant:"outline",children:[t.jsxRuntimeExports.jsx(t.Check,{className:"mr-2 size-4 font-bold text-green-600"}),"Accept"]}),t.jsxRuntimeExports.jsxs(t.Button,{onClick:gt,className:"w-full",size:"sm",variant:"outline",children:[t.jsxRuntimeExports.jsx(t.Cross2Icon,{className:"mr-2 size-4"}),"Close"]})]})]})]})}function Nu({data:e}){var o;const[n,r]=A.useState([]),s=Object.keys(e[0]).map(a=>({accessorKey:a,header:({column:u})=>{const c=u.getIsSorted();return t.jsxRuntimeExports.jsx("div",{className:"flex gap-2",children:t.jsxRuntimeExports.jsxs("div",{className:"flex cursor-pointer items-center",onClick:()=>u.toggleSorting(u.getIsSorted()==="asc"),children:[a,c==="asc"?t.jsxRuntimeExports.jsx(t.TriangleUpIcon,{className:"ml-2 h-5 w-5"}):c==="desc"?t.jsxRuntimeExports.jsx(t.TriangleDownIcon,{className:"ml-2 h-5 w-5"}):null]})})}})),l=t.useReactTable({data:e,columns:s,getCoreRowModel:t.getCoreRowModel(),getPaginationRowModel:t.getPaginationRowModel(),onSortingChange:r,getSortedRowModel:t.getSortedRowModel(),manualPagination:!0,state:{sorting:n}});return t.jsxRuntimeExports.jsxs(t.Table,{children:[t.jsxRuntimeExports.jsx(t.TableHeader,{children:l.getHeaderGroups().map(a=>t.jsxRuntimeExports.jsx(t.TableRow,{children:a.headers.map(u=>t.jsxRuntimeExports.jsx(t.TableHead,{className:"sticky top-0 bg-muted",children:u.isPlaceholder?null:t.flexRender(u.column.columnDef.header,u.getContext())},u.id))},a.id))}),t.jsxRuntimeExports.jsx(t.TableBody,{children:(o=l.getRowModel().rows)!=null&&o.length?l.getRowModel().rows.map(a=>t.jsxRuntimeExports.jsx(t.TableRow,{className:"whitespace-nowrap py-2","data-state":a.getIsSelected()&&"selected",children:a.getVisibleCells().map(u=>t.jsxRuntimeExports.jsx(t.TableCell,{children:t.flexRender(u.column.columnDef.cell,u.getContext())},u.id))},a.id)):t.jsxRuntimeExports.jsx(t.TableRow,{children:t.jsxRuntimeExports.jsx(t.TableCell,{colSpan:s.length,className:"h-24 text-center",children:"No results."})})})]})}function ei({className:e,...n}){A.useState(0);const r=t.useDashboardStore(o=>o.themeStyle),i=t.useEditorStore(o=>o.card),s=t.useEditorStore(o=>o.actions.setCard);if(A.useEffect(()=>{},[i.data,i.type,i.cfg,i.customCfg,r,i.preferences]),!i.id)return null;let l;return i.data&&i.data.length>0&&(l=t.createChartConfig({data:i.data,cardType:i.type,cfg:i.cfg,customCfg:i.customCfg,preferences:i.preferences})),t.jsxRuntimeExports.jsxs(t.Card,{role:"editor-visual-card",className:t.cn("relative flex h-full flex-col rounded-none",e),...n,children:[t.jsxRuntimeExports.jsxs(t.CardHeader,{className:"py-4",children:[t.jsxRuntimeExports.jsx(t.Editable,{text:i.title,onSave:o=>s({...i,title:o}),children:t.jsxRuntimeExports.jsx("div",{className:"flex items-center gap-2",children:t.jsxRuntimeExports.jsx(t.CardTitle,{className:"text-base",children:i.title})})},i.title),t.jsxRuntimeExports.jsx(t.Editable,{text:i.description||"",onSave:o=>s({...i,description:o}),children:t.jsxRuntimeExports.jsxs(t.CardDescription,{children:[" ",i.description]})},i.description)]}),t.jsxRuntimeExports.jsxs(t.CardContent,{className:"flex grow flex-col pb-3",children:[i.type!=="table"&&l&&t.jsxRuntimeExports.jsx(t.ChartJsVisual,{cfg:l},JSON.stringify(l)+JSON.stringify(i.preferences)),i.type==="table"&&i.data&&i.data.length>0&&t.jsxRuntimeExports.jsx(t.$57acba87d6e25586$export$ccf8d8d7bbf3c2cc,{className:"flex min-h-0 flex-1 grow basis-0",children:t.jsxRuntimeExports.jsx(t.TableVisual,{card:i,data:i==null?void 0:i.data})})]})]})}function Iu(){const[e,n]=A.useState(!1),[r,i]=A.useState(""),[s,l]=A.useState(""),[o,a]=A.useState(""),u=t.useEditorStore(k=>k.card),c=t.useEditorStore(k=>k.card.customCfg),x=t.useEditorStore(k=>k.actions.setCardCustomCfg);function p(k){var C,z;const E={...k,data:{...k==null?void 0:k.data,datasets:(z=(C=k==null?void 0:k.data)==null?void 0:C.datasets)==null?void 0:z.map(T=>({...T,data:[]}))}};return JSON.stringify(E,null,1)}function m(){if(!u.data||u.data.length===0)return;const k=t.createChartConfig({data:u.data,cardType:u.type,cfg:u.cfg,preferences:u.preferences});k&&(i(JSON.stringify(k,null,1)),c&&l(JSON.stringify(c,null,1)))}function d(){if(s)try{const k=JSON.parse(s);return k?(x(k),a(""),l(""),k):void 0}catch(k){console.log(k),a("Invalid JSON")}}function g(){l(""),x(null)}function y(){let k;if(c){const E=t._.cloneDeep(u.cfg),R=t._.merge(E,c);return k=p(R),k}return r?(k=p(JSON.parse(r)),k):""}return t.jsxRuntimeExports.jsxs(t.Dialog,{open:e,onOpenChange:n,children:[t.jsxRuntimeExports.jsx(t.DialogTrigger,{asChild:!0,children:t.jsxRuntimeExports.jsx(t.Button,{onClick:m,className:` ${c&&"border-foreground/50 dark:border-foreground/70"}`,size:"sm",variant:"outline",children:t.jsxRuntimeExports.jsx(t.Settings,{className:"h-4 w-4"})})}),t.jsxRuntimeExports.jsxs(t.DialogContent,{className:"max-h-[70vh] min-h-[70vh] min-w-[900px] overflow-auto",children:[t.jsxRuntimeExports.jsxs(t.DialogHeader,{className:"",children:[t.jsxRuntimeExports.jsxs("div",{className:"flex items-center gap-2",children:[t.jsxRuntimeExports.jsx(t.DialogTitle,{children:"Customize Card"}),t.jsxRuntimeExports.jsxs(t.Tooltip,{children:[t.jsxRuntimeExports.jsx(t.TooltipTrigger,{children:t.jsxRuntimeExports.jsx(ji,{onClick:()=>{navigator.clipboard.writeText(u.id)},className:"size-3 cursor-pointer text-muted-foreground/70 transition-colors hover:text-muted-foreground"})}),t.jsxRuntimeExports.jsx(t.TooltipContent,{side:"right",align:"center",children:t.jsxRuntimeExports.jsx("p",{className:"text-xs",children:"Copy Card ID"})})]})]}),t.jsxRuntimeExports.jsxs(t.DialogDescription,{children:["See the configuration options and documentation",t.jsxRuntimeExports.jsx("a",{target:"_blank",className:"ml-1 text-blue-500 underline",href:"https://www.chartjs.org/docs/latest/samples/bar/vertical.html",children:"here."})]})]}),t.jsxRuntimeExports.jsxs("div",{className:"flex grow gap-2",children:[t.jsxRuntimeExports.jsx(ei,{className:"w-1/2 rounded shadow-none"}),t.jsxRuntimeExports.jsxs(t.Tabs,{defaultValue:"custom-config",className:"flex w-1/2 flex-col",children:[t.jsxRuntimeExports.jsxs(t.TabsList,{className:"justify-start rounded-sm rounded-b-none border border-b-0",children:[t.jsxRuntimeExports.jsxs(t.TabsTrigger,{value:"custom-config",children:[c&&t.jsxRuntimeExports.jsx(t.CheckIcon,{className:"mr-1 h-5 w-5 text-green-600"}),c?"Custom Config":"Default Config"]}),t.jsxRuntimeExports.jsx(t.TabsTrigger,{className:"",value:"output",children:"Output"})]}),t.jsxRuntimeExports.jsx(t.TabsContent,{className:"bg-red-x mt-0 grow rounded-b border border-t-0 p-2",value:"output",children:t.jsxRuntimeExports.jsx(t.Textarea,{disabled:!0,value:r,className:"h-full resize-none border-none font-mono focus-visible:ring-0 focus-visible:ring-offset-0"})}),t.jsxRuntimeExports.jsx(t.TabsContent,{className:"mt-0 grow rounded-b border border-t-0",value:"custom-config",children:t.jsxRuntimeExports.jsx(t.Ft,{className:"h-full w-full overflow-hidden",theme:"default",options:{minimap:{enabled:!1},wordWrap:"on",scrollbar:{verticalScrollbarSize:0,horizontalScrollbarSize:0},fontSize:14,renderLineHighlight:"none"},defaultLanguage:"json",value:y(),onChange:k=>l(k)})})]})]}),t.jsxRuntimeExports.jsxs(t.DialogFooter,{className:"flex items-center",children:[t.jsxRuntimeExports.jsx(t.Label,{className:"mr-2 text-red-500",children:o}),t.jsxRuntimeExports.jsx(t.Button,{disabled:!c,onClick:g,variant:"outline",children:"Reset"}),t.jsxRuntimeExports.jsx(t.Button,{onClick:d,variant:"outline",children:"Apply"}),t.jsxRuntimeExports.jsx(t.Button,{onClick:()=>n(!1),variant:"outline",children:"Close"})]})]})]})}function ti(e){return Pe({tag:"svg",attr:{viewBox:"0 0 1024 1024"},child:[{tag:"path",attr:{d:"M926.8 397.1l-396-288a31.81 31.81 0 0 0-37.6 0l-396 288a31.99 31.99 0 0 0-11.6 35.8l151.3 466a32 32 0 0 0 30.4 22.1h489.5c13.9 0 26.1-8.9 30.4-22.1l151.3-466c4.2-13.2-.5-27.6-11.7-35.8zM838.6 417l-98.5 32-200-144.7V199.9L838.6 417zM466 567.2l-89.1 122.3-55.2-169.2L466 567.2zm-116.3-96.8L484 373.3v140.8l-134.3-43.7zM512 599.2l93.9 128.9H418.1L512 599.2zm28.1-225.9l134.2 97.1L540.1 514V373.3zM558 567.2l144.3-46.9-55.2 169.2L558 567.2zm-74-367.3v104.4L283.9 449l-98.5-32L484 199.9zM169.3 470.8l86.5 28.1 80.4 246.4-53.8 73.9-113.1-348.4zM327.1 853l50.3-69h269.3l50.3 69H327.1zm414.5-33.8l-53.8-73.9 80.4-246.4 86.5-28.1-113.1 348.4z"},child:[]}]})(e)}function ni(e){return Pe({tag:"svg",attr:{viewBox:"0 0 256 256",fill:"currentColor"},child:[{tag:"path",attr:{d:"M137.39,24.06A16,16,0,0,0,120,40V80.67a15.86,15.86,0,0,0,13.25,15.76A32,32,0,1,1,96,129.68c-.41-8.22,1.27-15,5-20.26h0a15.86,15.86,0,0,0-1.69-20.47L71.69,60.68a16,16,0,0,0-23.63,1.1A103.6,103.6,0,0,0,55,202.05,103.24,103.24,0,0,0,128,232h1.49A104.3,104.3,0,0,0,232,129.48C232.75,75.18,191.19,28.88,137.39,24.06ZM60.32,71.94l27.61,28.19,0,.06A43.29,43.29,0,0,0,80.44,120H40.36A87.13,87.13,0,0,1,60.32,71.94ZM40.37,136h40.3A48,48,0,0,0,120,175.34v40.3A88,88,0,0,1,40.37,136Zm149.77,54.14A87.45,87.45,0,0,1,136,215.61V175.34a47.55,47.55,0,0,0,24.73-12.23A48,48,0,0,0,136,80.66L136,40c45.52,4.08,80.67,43.28,80,89.25A87.45,87.45,0,0,1,190.14,190.14Z"},child:[]}]})(e)}function ri(e){return Pe({tag:"svg",attr:{viewBox:"0 0 256 256",fill:"currentColor"},child:[{tag:"path",attr:{d:"M128,24A104,104,0,1,0,232,128,104.11,104.11,0,0,0,128,24Zm87.63,96H191.48A64.1,64.1,0,0,0,136,64.52V40.37A88.13,88.13,0,0,1,215.63,120ZM120,120H80.68A48.09,48.09,0,0,1,120,80.68Zm0,16v39.32A48.09,48.09,0,0,1,80.68,136Zm16,0h39.32A48.09,48.09,0,0,1,136,175.32Zm0-16V80.68A48.09,48.09,0,0,1,175.32,120ZM120,40.37V64.52A64.1,64.1,0,0,0,64.52,120H40.37A88.13,88.13,0,0,1,120,40.37ZM40.37,136H64.52A64.1,64.1,0,0,0,120,191.48v24.15A88.13,88.13,0,0,1,40.37,136ZM136,215.63V191.48A64.1,64.1,0,0,0,191.48,136h24.15A88.13,88.13,0,0,1,136,215.63Z"},child:[]}]})(e)}function ii(e){return Pe({tag:"svg",attr:{viewBox:"0 0 24 24",strokeWidth:"2",stroke:"currentColor",fill:"none",strokeLinecap:"round",strokeLinejoin:"round"},child:[{tag:"path",attr:{stroke:"none",d:"M0 0h24v24H0z",fill:"none"},child:[]},{tag:"path",attr:{d:"M6 16m-3 0a3 3 0 1 0 6 0a3 3 0 1 0 -6 0"},child:[]},{tag:"path",attr:{d:"M16 19m-2 0a2 2 0 1 0 4 0a2 2 0 1 0 -4 0"},child:[]},{tag:"path",attr:{d:"M14.5 7.5m-4.5 0a4.5 4.5 0 1 0 9 0a4.5 4.5 0 1 0 -9 0"},child:[]}]})(e)}function si(e){return Pe({tag:"svg",attr:{viewBox:"0 0 24 24"},child:[{tag:"path",attr:{fill:"none",d:"M0 0h24v24H0z"},child:[]},{tag:"path",attr:{d:"M4 9h4v11H4zM4 4h4v4H4zM10 7h4v4h-4zM16 10h4v4h-4zM16 15h4v5h-4zM10 12h4v8h-4z"},child:[]}]})(e)}function oi(e){return Pe({tag:"svg",attr:{version:"1.2",baseProfile:"tiny",viewBox:"0 0 24 24"},child:[{tag:"path",attr:{d:"M4 18c-.552 0-1-.448-1-1v-6.382l-.553.276c-.495.248-1.095.046-1.342-.447-.247-.494-.046-1.094.448-1.342l2-1c.31-.155.678-.139.973.044.294.183.474.504.474.851v8c0 .552-.448 1-1 1zM13 18h-5c-.404 0-.769-.244-.924-.617-.155-.374-.069-.804.217-1.09l4-4c.254-.254.394-.591.394-.95 0-.358-.14-.695-.394-.949-.508-.508-1.39-.508-1.9.001-.253.252-.393.589-.393.948 0 .552-.448 1-1 1s-1-.448-1-1c0-.894.348-1.733.98-2.364 1.265-1.263 3.464-1.263 4.727.001.632.631.979 1.471.979 2.363 0 .893-.348 1.733-.979 2.364l-2.293 2.293h2.586c.552 0 1 .448 1 1s-.448 1-1 1zM20.955 12.377c.338-.457.545-1.016.545-1.627 0-1.517-1.234-2.75-2.75-2.75-1.031 0-1.966.569-2.44 1.484-.254.49-.063 1.094.428 1.348.49.254 1.094.062 1.348-.428.128-.249.383-.404.664-.404.414 0 .75.336.75.75s-.336.75-.75.75c-.552 0-1 .448-1 1s.448 1 1 1c.689 0 1.25.561 1.25 1.25s-.561 1.25-1.25 1.25-1.25-.561-1.25-1.25c0-.552-.448-1-1-1s-1 .448-1 1c0 1.792 1.458 3.25 3.25 3.25s3.25-1.458 3.25-3.25c0-.939-.406-1.779-1.045-2.373z"},child:[]}]})(e)}function Au(){const[e,n]=A.useState(!1),r=t.useEditorStore(a=>a.card.type),{setCardType:i,setCardPreferences:s}=t.useEditorStore(a=>a.actions),l=t.useEditorStore(a=>a.actions.setCardCustomCfg);function o(a){i(a),l(null),s({}),n(!1)}return t.jsxRuntimeExports.jsxs(t.Popover,{open:e,onOpenChange:n,children:[t.jsxRuntimeExports.jsx(t.PopoverTrigger,{asChild:!0,children:t.jsxRuntimeExports.jsx(t.Button,{size:"sm",variant:"outline",children:t.jsxRuntimeExports.jsx(Tu,{className:"h-4 w-4",chartType:r})})}),t.jsxRuntimeExports.jsx(t.PopoverContent,{className:"w-50",children:t.jsxRuntimeExports.jsxs("div",{className:"grid grid-cols-3 place-items-center",children:[t.jsxRuntimeExports.jsx(t.Button,{onClick:()=>o("bar"),className:"font-normal",variant:"ghost",children:t.jsxRuntimeExports.jsx($t,{className:"size-5"})}),t.jsxRuntimeExports.jsx(t.Button,{onClick:()=>o("line"),variant:"ghost",children:t.jsxRuntimeExports.jsx(Kt,{className:"size-5"})}),t.jsxRuntimeExports.jsx(t.Button,{onClick:()=>o("stackedBar"),variant:"ghost",children:t.jsxRuntimeExports.jsx(si,{className:"size-5",strokeWidth:0})}),t.jsxRuntimeExports.jsx(t.Button,{onClick:()=>o("scatter"),variant:"ghost",children:t.jsxRuntimeExports.jsx(ur,{className:"size-5"})}),t.jsxRuntimeExports.jsx(t.Button,{onClick:()=>o("bubble"),variant:"ghost",children:t.jsxRuntimeExports.jsx(ii,{className:"size-4"})}),t.jsxRuntimeExports.jsx(t.Button,{onClick:()=>o("pie"),variant:"ghost",children:t.jsxRuntimeExports.jsx(lr,{className:"size-5"})}),t.jsxRuntimeExports.jsx(t.Button,{onClick:()=>o("doughnut"),variant:"ghost",children:t.jsxRuntimeExports.jsx(ni,{className:"size-5",strokeWidth:1})}),t.jsxRuntimeExports.jsx(t.Button,{onClick:()=>o("radar"),variant:"ghost",children:t.jsxRuntimeExports.jsx(ti,{className:"size-5 font-extralight",strokeWidth:.5})}),t.jsxRuntimeExports.jsx(t.Button,{onClick:()=>o("polarArea"),variant:"ghost",children:t.jsxRuntimeExports.jsx(ri,{className:"size-5"})}),t.jsxRuntimeExports.jsx(t.Button,{onClick:()=>o("table"),variant:"ghost",children:t.jsxRuntimeExports.jsx(Wt,{className:"size-5"})}),t.jsxRuntimeExports.jsx(t.Button,{onClick:()=>o("kpi"),variant:"ghost",children:t.jsxRuntimeExports.jsx(oi,{className:"size-6"})})]})})]})}function Tu({chartType:e,className:n}){switch(e){case"bar":return t.jsxRuntimeExports.jsx($t,{className:n});case"line":return t.jsxRuntimeExports.jsx(Kt,{className:n});case"pie":return t.jsxRuntimeExports.jsx(lr,{className:n});case"radar":return t.jsxRuntimeExports.jsx(ti,{className:n});case"scatter":return t.jsxRuntimeExports.jsx(ur,{className:n});case"bubble":return t.jsxRuntimeExports.jsx(ii,{className:n});case"doughnut":return t.jsxRuntimeExports.jsx(ni,{className:n});case"stackedBar":return t.jsxRuntimeExports.jsx(si,{className:"size-4 text-foreground/70"});case"polarArea":return t.jsxRuntimeExports.jsx(ri,{className:n});case"kpi":return t.jsxRuntimeExports.jsx(oi,{className:n});default:return t.jsxRuntimeExports.jsx(Wt,{className:n})}}function Lu(){const e=t.useEditorStore(r=>r.card.refreshInterval),n=t.useEditorStore(r=>r.actions.setCardRefreshInterval);return t.jsxRuntimeExports.jsxs(t.Popover,{children:[t.jsxRuntimeExports.jsx(t.PopoverTrigger,{asChild:!0,children:t.jsxRuntimeExports.jsx(t.Button,{size:"sm",variant:"outline",children:t.jsxRuntimeExports.jsx(ui,{className:"w-4 h-4"})})}),t.jsxRuntimeExports.jsx(t.PopoverContent,{className:"w-[200px]",children:t.jsxRuntimeExports.jsx("div",{className:"grid gap-4",children:t.jsxRuntimeExports.jsx("div",{className:"grid gap-2",children:t.jsxRuntimeExports.jsxs("div",{className:"grid grid-cols-5 items-center gap-1",children:[t.jsxRuntimeExports.jsx(t.Label,{className:"col-span-3",htmlFor:"width",children:"Refresh Every"}),t.jsxRuntimeExports.jsx(t.Input,{value:e||"",onChange:r=>n(r.target.value),id:"width",placeholder:"30s",className:"col-span-2 h-7 focus-visible:ring-1 focus-visible:ring-ring focus-visible:ring-offset-0"})]})})})})]})}function rr(){t.useEditorStore(o=>o.frame);const e=t.useEditorStore(o=>o.card),n=t.useEditorStore(o=>o.card.data),r=t.useEditorStore(o=>o.isShowingVisual),i=t.useEditorStore(o=>o.isSqlRunning),s=t.useEditorStore(o=>o.queryError),l=t.useEditorStore(o=>o.pythonStdOut);return t.useEditorStore(o=>o.onSave),t.useEditorStore(o=>o.onClose),t.useEditorStore(o=>o.actions.setCardSql),t.useEditorStore(o=>o.actions.setCardType),t.useEditorStore(o=>o.actions.setSqlGen),e?t.jsxRuntimeExports.jsxs("div",{className:"relative flex h-full flex-col pt-3",children:[i&&t.jsxRuntimeExports.jsx(t.LoaderCircle,{className:"absolute bottom-0 left-0 right-0 top-0 z-10 m-auto h-10 w-10 animate-spin text-foreground/10"}),t.jsxRuntimeExports.jsxs("div",{className:"mb-0 flex min-h-10 items-center justify-end gap-2 px-6",children:[r&&t.jsxRuntimeExports.jsxs("div",{className:"flex grow items-center gap-2",children:[t.jsxRuntimeExports.jsx(Au,{}),t.jsxRuntimeExports.jsx(Iu,{}),t.jsxRuntimeExports.jsx(Lu,{})]}),t.jsxRuntimeExports.jsx(Ou,{})]}),r?e.type==="kpi"?t.jsxRuntimeExports.jsx("div",{className:"flex grow items-center justify-center",children:t.jsxRuntimeExports.jsx("div",{className:"w-1/2 rounded-md border",children:t.jsxRuntimeExports.jsx(t.KPICard,{isLoading:i,card:e})})}):t.jsxRuntimeExports.jsx(ei,{className:"grow border-none shadow-none"}):t.jsxRuntimeExports.jsxs("div",{className:"flex min-h-0 w-full flex-1 grow basis-0 px-6",children:[l&&t.jsxRuntimeExports.jsx(zu,{}),e.data&&e.data.length>0&&t.jsxRuntimeExports.jsx(Nu,{data:n||[]}),s&&t.jsxRuntimeExports.jsx("span",{className:"font-mono text-sm",children:s})]})]}):t.jsxRuntimeExports.jsx(t.jsxRuntimeExports.Fragment,{children:"No Active Card"})}function zu(){const e=t.useEditorStore(r=>r.pythonStdOut);if(!e)return null;const n=e.replace(/\n/g,"<br>");return t.jsxRuntimeExports.jsxs(t.jsxRuntimeExports.Fragment,{children:[t.jsxRuntimeExports.jsx("p",{className:"font-mono text-sm",children:"Output:"}),t.jsxRuntimeExports.jsx("div",{dangerouslySetInnerHTML:{__html:n},className:"bg-muted p-2 font-mono text-sm"}),t.jsxRuntimeExports.jsx(t.Separator,{className:"mb-2"})]})}function Ou(){const e=t.useEditorStore(r=>r.isShowingVisual),n=t.useEditorStore(r=>r.actions.setIsShowingVisual);return t.jsxRuntimeExports.jsxs("div",{className:"flex items-center space-x-2",children:[t.jsxRuntimeExports.jsx(t.Label,{htmlFor:"visualize",children:"Chart"}),t.jsxRuntimeExports.jsx(t.Switch,{checked:e,onCheckedChange:()=>n(!e),id:"visualize",className:"data-[state=checked]:bg-foreground/50"})]})}function We(){const[e,n]=A.useState([]);t.useEditorStore(x=>x.card.cfg);const r=t.useEditorStore(x=>x.card.preferences),{setCardCfg:i,setFilterOnClickColumnIndex:s,setCardPreferences:l}=t.useEditorStore(x=>x.actions),o=t.useEditorStore(x=>x.queryResultColumns);t.useEditorStore(x=>{var p;return(p=x.card.preferences)==null?void 0:p.filterOnClickColumnIndex}),A.useEffect(()=>{o&&n(new Array(o.length).fill(!1))},[o]);function a(x,p){var m,d;p?r!=null&&r.onClickFilter&&((m=r==null?void 0:r.onClickFilter)==null?void 0:m.length)>0?l({...r,onClickFilter:[...r.onClickFilter,{columnIndex:x,expression:""}]}):l({...r,onClickFilter:[{columnIndex:x,expression:""}]}):(l({...r,onClickFilter:(d=r==null?void 0:r.onClickFilter)==null?void 0:d.filter(g=>g.columnIndex!==x)}),n(g=>{const y=[...g];return y[x]=!1,y}))}function u(x,p){var d;const m=(d=r==null?void 0:r.onClickFilter)==null?void 0:d.map(g=>g.columnIndex===x?{...g,expression:p.target.value}:g);l({...r,onClickFilter:m})}function c(x){var p,m,d,g;if(e!=null&&e[x]||(m=(p=r==null?void 0:r.onClickFilter)==null?void 0:p.find(y=>y.columnIndex===x))!=null&&m.expression)return t.jsxRuntimeExports.jsx(t.Input,{value:(g=(d=r==null?void 0:r.onClickFilter)==null?void 0:d.find(y=>y.columnIndex===x))==null?void 0:g.expression,onChange:y=>u(x,y),type:"text",className:" h-9 w-full focus-visible:ring-0 focus-visible:ring-ring focus-visible:ring-offset-0 font-mono text-xs",placeholder:"Expression"})}return t.jsxRuntimeExports.jsx(t.jsxRuntimeExports.Fragment,{children:o==null?void 0:o.map((x,p)=>{var m,d;return t.jsxRuntimeExports.jsx("div",{className:"flex items-center justify-between space-y-2 xbg-red-100 group",children:t.jsxRuntimeExports.jsxs("div",{className:" grow",children:[t.jsxRuntimeExports.jsxs("div",{className:"flex items-center py-2 space-x-2",children:[t.jsxRuntimeExports.jsx(t.Checkbox,{checked:!!((m=r==null?void 0:r.onClickFilter)!=null&&m.find(g=>g.columnIndex===p)),onCheckedChange:g=>a(p,g)}),t.jsxRuntimeExports.jsx("label",{className:"text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70",children:x}),t.jsxRuntimeExports.jsx("div",{className:"flex gap-2 items-center ",children:((d=r==null?void 0:r.onClickFilter)==null?void 0:d.find(g=>g.columnIndex===p))&&t.jsxRuntimeExports.jsx(or,{onClick:()=>{n(g=>{const y=[...g];return y[p]=!g[p],y})},className:" invisible group-hover:visible size-3 text-gray-400 cursor-pointer"})})]}),c(p)]})},x)})})}function un(){var l,o;const e=t.useEditorStore(a=>a.card.preferences),n=t.useEditorStore(a=>a.card.cfg),{setCardCfg:r,setCardPreferences:i}=t.useEditorStore(a=>a.actions);(l=n==null?void 0:n.options)!=null&&l.indexAxis;function s(a){var x,p,m,d,g,y;let u={};(x=e==null?void 0:e.chartOptions)!=null&&x.scales&&(u={x:(m=(p=e==null?void 0:e.chartOptions)==null?void 0:p.scales)==null?void 0:m.y,y:(g=(d=e==null?void 0:e.chartOptions)==null?void 0:d.scales)==null?void 0:g.x});const c={...e,chartOptions:{...e==null?void 0:e.chartOptions,scales:{...(y=e==null?void 0:e.chartOptions)==null?void 0:y.scales,...u},indexAxis:a}};i(c)}return t.jsxRuntimeExports.jsxs(t.RadioGroup,{value:((o=e==null?void 0:e.chartOptions)==null?void 0:o.indexAxis)||"x",onValueChange:s,className:"flex gap-3",defaultValue:"x",children:[t.jsxRuntimeExports.jsxs("div",{className:"flex items-center space-x-2",children:[t.jsxRuntimeExports.jsx(t.RadioGroupItem,{value:"x",id:"r1"}),t.jsxRuntimeExports.jsx("label",{className:"text-sm",htmlFor:"r1",children:"Vertical"})]}),t.jsxRuntimeExports.jsxs("div",{className:"flex items-center space-x-2",children:[t.jsxRuntimeExports.jsx(t.RadioGroupItem,{value:"y",id:"r2"}),t.jsxRuntimeExports.jsx("label",{className:"text-sm",htmlFor:"r2",children:"Horizontal"})]})]})}const De="focus-visible:ring-0 focus-visible:ring-ring focus-visible:ring-offset-0";function ir(e){var r,i,s;const n=t.getNumberAxis(e);return((s=(i=(r=e==null?void 0:e.chartOptions)==null?void 0:r.scales)==null?void 0:i[n])==null?void 0:s.type)||"linear"}function Du(){var I,N,$,W,B,G;const[e,n]=A.useState(!1),r=t.useEditorStore(L=>{var F;return(F=L.card)==null?void 0:F.preferences}),i=t.getNumberAxis(r),[s,l]=A.useState(ir(r)),[o,a]=A.useState((($=(N=(I=r==null?void 0:r.chartOptions)==null?void 0:I.scales)==null?void 0:N[i])==null?void 0:$.min)||""),[u,c]=A.useState(((G=(B=(W=r==null?void 0:r.chartOptions)==null?void 0:W.scales)==null?void 0:B[i])==null?void 0:G.max)||""),[x,p]=A.useState(o||u?"custom":"auto"),[m,d]=A.useState(""),[g,y]=A.useState(""),[k,E]=A.useState(""),[R,C]=A.useState(""),[z,T]=A.useState(""),S=t.useEditorStore(L=>L.actions.setCardPreferences);A.useEffect(()=>{var L,F,v,h,J,re,f,te,ue,Z,xe,oe,ie,le;l(ir(r)),a(((v=(F=(L=r==null?void 0:r.chartOptions)==null?void 0:L.scales)==null?void 0:F[i])==null?void 0:v.min)===0?0:""),c(((re=(J=(h=r==null?void 0:r.chartOptions)==null?void 0:h.scales)==null?void 0:J[i])==null?void 0:re.max)||""),d(((Z=(ue=(te=(f=r==null?void 0:r.chartOptions)==null?void 0:f.scales)==null?void 0:te[i])==null?void 0:ue.ticks)==null?void 0:Z.stepSize)||""),y(((xe=r==null?void 0:r.numberAxisFormat)==null?void 0:xe.format)||""),E(((oe=r==null?void 0:r.numberAxisFormat)==null?void 0:oe.suffix)||""),C(((ie=r==null?void 0:r.numberAxisFormat)==null?void 0:ie.currency)||""),T(((le=r==null?void 0:r.numberAxisFormat)==null?void 0:le.locale)||"")},[e,r,i]);function M(L,F){return F===""||/^[0-9\b]+$/.test(F)?Number(F):Number(L)}function K(){return t.jsxRuntimeExports.jsxs(t.jsxRuntimeExports.Fragment,{children:[t.jsxRuntimeExports.jsxs("div",{className:"grid grid-cols-9 items-center gap-2",children:[t.jsxRuntimeExports.jsx(t.Label,{className:"col-span-3",htmlFor:"format",children:"Format"}),t.jsxRuntimeExports.jsx(t.Input,{value:g,placeholder:"000,0.00",onChange:L=>y(L.target.value),id:"format",className:`col-span-4 h-8 w-full tracking-wide ${De}`}),t.jsxRuntimeExports.jsx(t.Input,{value:k,placeholder:"M",onChange:L=>E(L.target.value),id:"unit",className:`col-span-2 h-8 w-full ${De}`})]}),t.jsxRuntimeExports.jsxs("div",{className:"grid grid-cols-6 items-center gap-2",children:[t.jsxRuntimeExports.jsx(t.Label,{className:"col-span-2 hover:cursor-pointer hover:underline",htmlFor:"currency",children:t.jsxRuntimeExports.jsx("a",{target:"_blank",href:"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat",children:"Currency"})}),t.jsxRuntimeExports.jsx(t.Input,{value:R,placeholder:"USD",onChange:L=>C(L.target.value),id:"currency",className:`col-span-2 h-8 w-full ${De}`}),t.jsxRuntimeExports.jsx(t.Input,{value:z,placeholder:"en-US",onChange:L=>T(L.target.value),id:"locale",className:`col-span-2 h-8 w-full ${De}`})]})]})}function U(){return t.jsxRuntimeExports.jsxs(t.jsxRuntimeExports.Fragment,{children:[t.jsxRuntimeExports.jsxs("div",{className:"grid grid-cols-3 items-center gap-2",children:[t.jsxRuntimeExports.jsx(t.Label,{htmlFor:"range",children:"Range"}),t.jsxRuntimeExports.jsx(t.Input,{id:"min",value:o,onChange:L=>a(F=>M(F,L.target.value)),className:`col-span-1 h-8 w-full ${De}`}),t.jsxRuntimeExports.jsx(t.Input,{value:u,onChange:L=>c(F=>M(F,L.target.value)),id:"max",className:`col-span-1 h-8 w-full ${De}`})]}),t.jsxRuntimeExports.jsxs("div",{className:"grid grid-cols-3 items-center gap-2",children:[t.jsxRuntimeExports.jsx(t.Label,{htmlFor:"step-size",children:"Step Size"}),t.jsxRuntimeExports.jsx(t.Input,{value:m,onChange:L=>d(F=>M(F,L.target.value)),id:"step-size",className:`col-span-1 h-8 w-full ${De}`})]})]})}function _(){var v;let L={};x==="custom"&&(L={min:o,max:u,ticks:{stepSize:m}});const F={...r||{},chartOptions:{...r==null?void 0:r.chartOptions,scales:{...(v=r==null?void 0:r.chartOptions)==null?void 0:v.scales,[i]:{type:s,...s==="linear"?L:{}}}},numberAxisFormat:{format:g,suffix:k,currency:R,locale:z}};S(F)}return t.jsxRuntimeExports.jsxs(t.Popover,{onOpenChange:L=>n(L),children:[t.jsxRuntimeExports.jsx(t.PopoverTrigger,{asChild:!0,children:t.jsxRuntimeExports.jsx(t.SliderIcon,{className:"size-4 cursor-pointer text-muted-foreground hover:text-foreground"})}),t.jsxRuntimeExports.jsx(t.PopoverContent,{align:"center",className:"max-w-65",children:t.jsxRuntimeExports.jsxs("div",{className:"grid gap-4",children:[t.jsxRuntimeExports.jsxs("div",{className:"space-y-2",children:[t.jsxRuntimeExports.jsx("h4",{className:"font-medium leading-none",children:"Scale Options"}),t.jsxRuntimeExports.jsx("p",{className:"text-sm text-muted-foreground",children:"Set the scale for the number axis"})]}),t.jsxRuntimeExports.jsxs("div",{className:"grid gap-2",children:[t.jsxRuntimeExports.jsxs("div",{className:"grid grid-cols-3 items-center gap-2",children:[t.jsxRuntimeExports.jsx(t.Label,{htmlFor:"scale",children:"Type"}),t.jsxRuntimeExports.jsxs(t.Select,{value:s,onValueChange:L=>l(L),children:[t.jsxRuntimeExports.jsx(t.SelectTrigger,{className:"col-span-2 h-8 w-full focus:ring-1 focus:ring-offset-0",children:t.jsxRuntimeExports.jsx(t.SelectValue,{})}),t.jsxRuntimeExports.jsx(t.SelectContent,{id:"type",children:t.jsxRuntimeExports.jsxs(t.SelectGroup,{children:[t.jsxRuntimeExports.jsx(t.SelectLabel,{children:"Option"}),t.jsxRuntimeExports.jsx(t.SelectItem,{value:"linear",children:"Linear"}),t.jsxRuntimeExports.jsx(t.SelectItem,{value:"logarithmic",children:"Logarithmic"})]})})]})]}),s=="linear"&&t.jsxRuntimeExports.jsxs("div",{className:"grid grid-cols-3 items-center gap-2 py-1",children:[t.jsxRuntimeExports.jsx(t.Label,{htmlFor:"scale-option",children:"Setup"}),t.jsxRuntimeExports.jsxs(t.RadioGroup,{id:"scale-option",value:x,onValueChange:L=>p(L),className:"col-span-2 flex gap-3",defaultValue:"x",children:[t.jsxRuntimeExports.jsxs("div",{className:"flex items-center space-x-2",children:[t.jsxRuntimeExports.jsx(t.RadioGroupItem,{value:"auto",id:"r1"}),t.jsxRuntimeExports.jsx("label",{className:"text-sm",htmlFor:"r1",children:"Auto"})]}),t.jsxRuntimeExports.jsxs("div",{className:"flex items-center space-x-2",children:[t.jsxRuntimeExports.jsx(t.RadioGroupItem,{value:"custom",id:"r2"}),t.jsxRuntimeExports.jsx("label",{className:"text-sm",htmlFor:"r2",children:"Custom"})]})]})]}),x==="custom"&&s=="linear"&&U(),K(),t.jsxRuntimeExports.jsx(t.SelectSeparator,{}),t.jsxRuntimeExports.jsx("div",{className:"grid grid-cols-3",children:t.jsxRuntimeExports.jsx(t.Button,{onClick:_,variant:"secondary",className:"col-span-1 col-start-3 h-8 w-full",children:"Apply"})})]})]})})]})}function Fu({idx:e}){var a;const n=t.useEditorStore(u=>{var c;return(c=u.card)==null?void 0:c.preferences}),r=t.useEditorStore(u=>{var c;return(c=u.card.preferences)==null?void 0:c.datasetOptions}),i=t.useEditorStore(u=>u.actions.setCardPreferences),s=(a=n==null?void 0:n.chartOptions)==null?void 0:a.indexAxis,l=r==null?void 0:r.find(u=>u.idx===e);function o(u,c){(u==="end"||u==="start")&&t.getContrastColor(t.getCanvasBackgroundColor());const x={display:u!=="none",align:u,anchor:u,clamp:!0};if(!l)i({...n,datasetOptions:[...r||[],{idx:c,datalabels:x}]});else{const p={...l};p.datalabels=x;const m=r==null?void 0:r.map(d=>d.idx===c?p:d);i({...n,datasetOptions:m})}}return t.jsxRuntimeExports.jsxs(t.Popover,{children:[t.jsxRuntimeExports.jsx(t.PopoverTrigger,{children:t.jsxRuntimeExports.jsx(Ii,{className:"invisible size-4 rotate-[135deg] cursor-pointer text-muted-foreground hover:text-foreground group-hover:visible"})}),t.jsxRuntimeExports.jsx(t.PopoverContent,{className:"w-fit p-1",children:t.jsxRuntimeExports.jsxs("div",{className:"flex gap-1",children:[t.jsxRuntimeExports.jsx(t.Button,{onClick:()=>o("none",e),size:"sm",variant:"secondary",className:"h-7 p-1 text-xs font-normal",children:t.jsxRuntimeExports.jsx(t.X,{className:"size-4"})}),t.jsxRuntimeExports.jsx(t.Button,{onClick:()=>o("start",e),size:"sm",variant:"secondary",className:"h-7 p-1 text-xs font-normal",children:t.jsxRuntimeExports.jsx(yi,{className:t.cn("h-4 w-4",{"rotate-90":s==="y"})})}),t.jsxRuntimeExports.jsx(t.Button,{onClick:()=>o("center",e),size:"sm",variant:"secondary",className:"h-7 p-1 text-xs font-normal",children:t.jsxRuntimeExports.jsx(bi,{className:t.cn("h-4 w-4",{"rotate-90":s==="y"})})}),t.jsxRuntimeExports.jsx(t.Button,{onClick:()=>o("end",e),size:"sm",variant:"secondary",className:"h-7 p-1 text-xs font-normal",children:t.jsxRuntimeExports.jsx(Ei,{className:t.cn("h-4 w-4",{"rotate-90":s==="y"})})})]})})]})}function li(){const e=t.useEditorStore(u=>u.card),n=t.useEditorStore(u=>{var c,x,p;return(p=(x=(c=u==null?void 0:u.card)==null?void 0:c.preferences)==null?void 0:x.chartOptions)==null?void 0:p.indexAxis}),r=n==="y"?"Y axis":"X axis",i=n==="y"?"X axis":"Y axis",{keys:s,metricKeys:l,dimensionKeys:o}=t.getKeys(e.data||[]);let a=l;if(e.type==="stackedBar"){const u=t.pivotData({dataArray:e.data||[],groupKey:o[0],pivotKey:o[1],valueKey:a[0]}),{metricKeys:c}=t.getKeys(u);a=c}return s.length===0?null:t.jsxRuntimeExports.jsxs("div",{className:"space-y-4",children:[t.jsxRuntimeExports.jsxs("div",{className:"space-y-2",children:[t.jsxRuntimeExports.jsx(t.Label,{children:r}),t.jsxRuntimeExports.jsx("div",{className:"my-1 space-y-1",children:t.jsxRuntimeExports.jsx("div",{className:"rounded-md bg-muted/70 px-2 py-1 hover:bg-muted",children:t.jsxRuntimeExports.jsx("p",{children:o[0]})})})]}),t.jsxRuntimeExports.jsxs("div",{className:"space-y-2",children:[t.jsxRuntimeExports.jsxs("div",{className:"flex items-center justify-between gap-5",children:[t.jsxRuntimeExports.jsx(t.Label,{children:i}),t.jsxRuntimeExports.jsx(Du,{})]}),t.jsxRuntimeExports.jsx("div",{className:"my-1 space-y-1",children:a.map((u,c)=>t.jsxRuntimeExports.jsx(Mu,{col:u,idx:c},u))})]})]})}function Mu({col:e,idx:n}){const r=t.useEditorStore(a=>{var u;return(u=a.card)==null?void 0:u.preferences}),i=t.useEditorStore(a=>{var u;return(u=a.card.preferences)==null?void 0:u.datasetOptions}),s=i==null?void 0:i.find(a=>a.idx===n),{setCardPreferences:l}=t.useEditorStore(a=>a.actions);function o(a){if(!s)l({...r,datasetOptions:[...i||[],{idx:n,type:a==="area"?"line":a,fill:a==="area"?"origin":""}]});else{const u={...s};u.type=a==="area"?"line":a,u.fill=a==="area"?"origin":"";const c=i==null?void 0:i.map(x=>x.idx===n?u:x);l({...r,datasetOptions:c})}}return t.jsxRuntimeExports.jsxs("div",{className:"group flex items-center justify-between gap-5 rounded-md bg-muted/70 px-2 py-1 hover:bg-muted",children:[t.jsxRuntimeExports.jsx("p",{children:e}),t.jsxRuntimeExports.jsxs("div",{className:"flex gap-2",children:[t.jsxRuntimeExports.jsx($t,{onClick:()=>o("bar"),className:"invisible size-4 cursor-pointer text-muted-foreground hover:text-foreground group-hover:visible"}),t.jsxRuntimeExports.jsx(Kt,{onClick:()=>o("line"),className:"invisible size-4 cursor-pointer text-muted-foreground hover:text-foreground group-hover:visible"}),t.jsxRuntimeExports.jsx(ci,{onClick:()=>o("area"),className:"invisible size-4 cursor-pointer text-muted-foreground hover:text-foreground group-hover:visible"}),t.jsxRuntimeExports.jsx(t.Separator,{orientation:"vertical",className:"invisible size-4 cursor-pointer py-2 text-muted-foreground hover:text-foreground group-hover:visible"}),t.jsxRuntimeExports.jsx(Fu,{idx:n})]})]})}function Pu({cardType:e}){return t.jsxRuntimeExports.jsx("div",{className:"space-y-6 px-6 py-2",children:t.jsxRuntimeExports.jsxs(t.Accordion,{defaultValue:["item-2"],type:"multiple",children:[t.jsxRuntimeExports.jsxs(t.AccordionItem,{value:"item-1",children:[t.jsxRuntimeExports.jsx(t.AccordionTrigger,{children:`${t.titleCase(e)} Chart`}),t.jsxRuntimeExports.jsxs(t.AccordionContent,{className:"space-y-4 font-mono text-xs",children:[t.jsxRuntimeExports.jsx("div",{className:"rounded bg-muted px-2 py-1 text-xs",children:"SELECT x-axis, y-axis-1, y-axis-2,... FROM table"}),t.jsxRuntimeExports.jsxs("ul",{className:"ml-6 list-disc text-xs [&>li]:mt-2",children:[t.jsxRuntimeExports.jsx("li",{children:"x-axis - category"}),t.jsxRuntimeExports.jsx("li",{children:"y-axis1 - number"}),t.jsxRuntimeExports.jsx("li",{children:"y-axis2 - number"})]}),t.jsxRuntimeExports.jsxs("div",{children:["See ",t.jsxRuntimeExports.jsx("a",{target:"_blank",onClick:n=>n.stopPropagation(),className:"text-blue-700",href:"https://docs.semaphor.cloud/concepts/visuals#line-chart",children:"example"})," in the docs."]})]})]}),t.jsxRuntimeExports.jsxs(t.AccordionItem,{value:"item-2",children:[t.jsxRuntimeExports.jsx(t.AccordionTrigger,{children:"Settings"}),t.jsxRuntimeExports.jsxs(t.AccordionContent,{className:"space-y-4 px-2",children:[t.jsxRuntimeExports.jsx(un,{}),t.jsxRuntimeExports.jsx(li,{})]})]}),t.jsxRuntimeExports.jsxs(t.AccordionItem,{value:"item-3",children:[t.jsxRuntimeExports.jsx(t.AccordionTrigger,{children:"Filter on click"}),t.jsxRuntimeExports.jsx(t.AccordionContent,{className:"px-2",children:t.jsxRuntimeExports.jsx(We,{})})]})]})})}function cn(){var i,s,l;const e=t.useEditorStore(o=>o.card.cfg),n=t.useEditorStore(o=>o.actions.setCardCfg);function r(o){var c;const a={datalabels:{display:o!=="none",align:o,anchor:o,clamp:!0}},u={...e,options:{...e==null?void 0:e.options,plugins:{...(c=e==null?void 0:e.options)==null?void 0:c.plugins,...a}}};n(u),console.log(o)}return t.jsxRuntimeExports.jsxs("div",{className:"space-y-2",children:[t.jsxRuntimeExports.jsx("label",{className:"font-medium",children:"Data Labels"}),t.jsxRuntimeExports.jsxs(t.Select,{value:(l=(s=(i=e==null?void 0:e.options)==null?void 0:i.plugins)==null?void 0:s.datalabels)==null?void 0:l.anchor,onValueChange:r,defaultValue:"none",children:[t.jsxRuntimeExports.jsx(t.SelectTrigger,{className:"h-8 w-[180px] focus:ring-1 focus:ring-offset-0",children:t.jsxRuntimeExports.jsx(t.SelectValue,{placeholder:"Select position"})}),t.jsxRuntimeExports.jsx(t.SelectContent,{children:t.jsxRuntimeExports.jsxs(t.SelectGroup,{children:[t.jsxRuntimeExports.jsx(t.SelectLabel,{children:"Data Labels"}),t.jsxRuntimeExports.jsx(t.SelectItem,{value:"none",children:"None"}),t.jsxRuntimeExports.jsx(t.SelectItem,{value:"start",children:"Start"}),t.jsxRuntimeExports.jsx(t.SelectItem,{value:"center",children:"Center"}),t.jsxRuntimeExports.jsx(t.SelectItem,{value:"end",children:"End"})]})})]})]})}function Bu({cardType:e}){function n(r){const i="SELECT label, [group], x-axis, y-axis, radius FROM table",s="SELECT label, [group], x-axis, y-axis FROM table";return t.jsxRuntimeExports.jsxs(t.jsxRuntimeExports.Fragment,{children:[t.jsxRuntimeExports.jsx("div",{className:"bg-muted px-2 py-1 rounded text-xs",children:r==="bubble"?i:s}),t.jsxRuntimeExports.jsxs("ul",{className:" ml-6 list-disc [&>li]:mt-2 text-xs",children:[t.jsxRuntimeExports.jsx("li",{children:"label - category"}),t.jsxRuntimeExports.jsx("li",{children:"group - category"}),t.jsxRuntimeExports.jsx("li",{children:"x-axis - category"}),t.jsxRuntimeExports.jsx("li",{children:"y-axis - category"}),r==="bubble"&&t.jsxRuntimeExports.jsx("li",{children:"radius - number"})]}),t.jsxRuntimeExports.jsxs("div",{children:["See ",t.jsxRuntimeExports.jsx("a",{target:"_blank",onClick:l=>l.stopPropagation(),className:"text-blue-700",href:"https://docs.semaphor.cloud/concepts/visuals#pie-chart",children:"example"})," in the docs."]})]})}return t.jsxRuntimeExports.jsx("div",{className:"px-6 py-2 space-y-6",children:t.jsxRuntimeExports.jsxs(t.Accordion,{defaultValue:["item-2"],type:"multiple",children:[t.jsxRuntimeExports.jsxs(t.AccordionItem,{value:"item-1",children:[t.jsxRuntimeExports.jsx(t.AccordionTrigger,{children:`${t.titleCase(e)} Chart`}),t.jsxRuntimeExports.jsx(t.AccordionContent,{className:" space-y-4 font-mono text-xs ",children:n(e)})]}),t.jsxRuntimeExports.jsxs(t.AccordionItem,{value:"item-2",children:[t.jsxRuntimeExports.jsx(t.AccordionTrigger,{children:"Settings"}),t.jsxRuntimeExports.jsx(t.AccordionContent,{className:"px-2",children:t.jsxRuntimeExports.jsx(cn,{})})]}),t.jsxRuntimeExports.jsxs(t.AccordionItem,{value:"item-3",children:[t.jsxRuntimeExports.jsx(t.AccordionTrigger,{children:"Filter on click"}),t.jsxRuntimeExports.jsx(t.AccordionContent,{className:"px-2",children:t.jsxRuntimeExports.jsx(We,{})})]})]})})}const _u={datasets:[{type:"line",label:"Sum_sales",data:[]},{type:"bar",label:"Sum_profit",data:[]}]},qu={datasets:[{fill:"origin",type:"line",label:"Sum_sales",data:[]}]};function Vu(){const e=t.useEditorStore(n=>n.card.type);return t.jsxRuntimeExports.jsxs("div",{className:"p-6 space-y-6",children:[t.jsxRuntimeExports.jsx(t.Accordion,{className:" ",type:"single",collapsible:!0,children:Hu(e)}),t.jsxRuntimeExports.jsx("section",{className:"",children:["line","bar"].includes(e)&&t.jsxRuntimeExports.jsx(un,{})}),t.jsxRuntimeExports.jsx("div",{children:!["kpi"].includes(e)&&t.jsxRuntimeExports.jsx(cn,{})}),t.jsxRuntimeExports.jsx("div",{children:!["kpi"].includes(e)&&t.jsxRuntimeExports.jsx(We,{})})]})}function Hu(e){if(["line","bar"].includes(e))return t.jsxRuntimeExports.jsxs(t.jsxRuntimeExports.Fragment,{children:[t.jsxRuntimeExports.jsxs(t.AccordionItem,{value:"item-1",children:[t.jsxRuntimeExports.jsx(t.AccordionTrigger,{className:" font-normal",children:t.jsxRuntimeExports.jsx("p",{children:"Chart Query"})}),t.jsxRuntimeExports.jsxs(t.AccordionContent,{className:" ",children:[t.jsxRuntimeExports.jsx("div",{className:"bg-muted px-2 py-1 rounded font-mono font-semibold text-xs",children:"SELECT x-axis, y-axis-1, y-axis-2, y-axis-3,... FROM table"}),t.jsxRuntimeExports.jsxs("ul",{className:"my-6 ml-6 list-disc [&>li]:mt-2 font-normal text-xs",children:[t.jsxRuntimeExports.jsx("li",{children:"X-axis - Category (ex. city)"}),t.jsxRuntimeExports.jsx("li",{children:"Y-axis - Number (ex. population)"})]})]})]}),t.jsxRuntimeExports.jsxs(t.AccordionItem,{value:"item-2",children:[t.jsxRuntimeExports.jsx(t.AccordionTrigger,{className:" font-normal",children:"Mixed Chart"}),t.jsxRuntimeExports.jsxs(t.AccordionContent,{className:" text-xs space-y-2",children:[t.jsxRuntimeExports.jsxs("p",{children:["Click ",t.jsxRuntimeExports.jsx("b",{children:"Customize"})," and change the `type` property in the dataset."]}),t.jsxRuntimeExports.jsx("pre",{children:JSON.stringify(_u,null,2)})]})]}),t.jsxRuntimeExports.jsxs(t.AccordionItem,{value:"item-3",children:[t.jsxRuntimeExports.jsx(t.AccordionTrigger,{className:" font-normal",children:"Area Chart"}),t.jsxRuntimeExports.jsxs(t.AccordionContent,{className:" text-xs space-y-2",children:[t.jsxRuntimeExports.jsxs("p",{children:["Click ",t.jsxRuntimeExports.jsx("b",{children:"Customize"})," and add `fill` property to the dataset. See",t.jsxRuntimeExports.jsx("a",{className:"text-blue-500 hover:underline mx-1",href:"https://www.chartjs.org/docs/latest/samples/area/line-boundaries.html",target:"_blank",children:"docs"}),"for more options."]}),t.jsxRuntimeExports.jsx("pre",{children:JSON.stringify(qu,null,2)})]})]})]});if(e==="bubble")return t.jsxRuntimeExports.jsx(t.jsxRuntimeExports.Fragment,{children:t.jsxRuntimeExports.jsxs(t.AccordionItem,{value:"item-1",children:[t.jsxRuntimeExports.jsx(t.AccordionTrigger,{className:" font-normal",children:t.jsxRuntimeExports.jsxs("p",{children:["How to create a ",t.jsxRuntimeExports.jsx("span",{children:e})," chart query?"]})}),t.jsxRuntimeExports.jsxs(t.AccordionContent,{className:" ",children:[t.jsxRuntimeExports.jsx("div",{className:"bg-muted px-2 py-1 rounded font-mono font-semibold text-xs",children:"SELECT label, x-axis, y-axis, radius FROM table"}),t.jsxRuntimeExports.jsxs("ul",{className:"my-6 ml-6 list-disc [&>li]:mt-2 font-normal text-xs",children:[t.jsxRuntimeExports.jsx("li",{children:"Label - Category (ex. city)"}),t.jsxRuntimeExports.jsx("li",{children:"Bubble Group (opt) - Category (ex. state)"}),t.jsxRuntimeExports.jsx("li",{children:"X-axis - Number (ex. avg. age)"}),t.jsxRuntimeExports.jsx("li",{children:"Y-axis - Number (ex. avg. weight)"}),t.jsxRuntimeExports.jsx("li",{children:"Radius - Number (ex. population)"})]})]})]})});if(e==="scatter")return t.jsxRuntimeExports.jsx(t.jsxRuntimeExports.Fragment,{children:t.jsxRuntimeExports.jsxs(t.AccordionItem,{value:"item-1",children:[t.jsxRuntimeExports.jsx(t.AccordionTrigger,{className:" font-normal",children:t.jsxRuntimeExports.jsxs("p",{children:["How to create a ",t.jsxRuntimeExports.jsx("span",{children:e})," chart query?"]})}),t.jsxRuntimeExports.jsxs(t.AccordionContent,{className:" ",children:[t.jsxRuntimeExports.jsx("div",{className:"bg-muted px-2 py-1 rounded font-mono font-semibold text-xs",children:"SELECT label, x-axis, y-axis FROM table"}),t.jsxRuntimeExports.jsxs("ul",{className:"my-6 ml-6 list-disc [&>li]:mt-2 font-normal text-xs",children:[t.jsxRuntimeExports.jsx("li",{children:"Label - Category (ex. city)"}),t.jsxRuntimeExports.jsx("li",{children:"Group (opt) - Category (ex. state)"}),t.jsxRuntimeExports.jsx("li",{children:"X-axis - Number (ex. avg. age)"}),t.jsxRuntimeExports.jsx("li",{children:"Y-axis - Number (ex. avg. weight)"})]})]})]})});if(["pie","doughnut","polarArea"].includes(e))return t.jsxRuntimeExports.jsx(t.jsxRuntimeExports.Fragment,{children:t.jsxRuntimeExports.jsxs(t.AccordionItem,{value:"item-1",children:[t.jsxRuntimeExports.jsx(t.AccordionTrigger,{className:" font-normal",children:t.jsxRuntimeExports.jsxs("p",{children:[t.jsxRuntimeExports.jsx("span",{children:e==="polarArea"?"Polar":e.charAt(0).toUpperCase()+e.slice(1)})," ","chart query"]})}),t.jsxRuntimeExports.jsxs(t.AccordionContent,{className:" ",children:[t.jsxRuntimeExports.jsx("div",{className:"bg-muted px-2 py-1 rounded font-mono font-semibold text-xs",children:"SELECT label, measure FROM table"}),t.jsxRuntimeExports.jsxs("ul",{className:"my-6 ml-6 list-disc [&>li]:mt-2 font-normal text-xs",children:[t.jsxRuntimeExports.jsx("li",{children:"Label - Category (ex. city)"}),t.jsxRuntimeExports.jsx("li",{children:"Measure - Number (ex. population)"})]})]})]})})}function Uu(){var o,a,u;const e=t.useEditorStore(c=>c.card.preferences),n=t.useEditorStore(c=>c.actions.setCardPreferences),r=t.useEditorStore(c=>c.actions.setNumberFormat),i=t.useEditorStore(c=>{var x,p;return(p=(x=c.card.preferences)==null?void 0:x.formatNumber)==null?void 0:p.format}),s=t.useEditorStore(c=>{var x,p;return(p=(x=c.card.preferences)==null?void 0:x.formatNumber)==null?void 0:p.locale}),l=t.useEditorStore(c=>{var x,p;return(p=(x=c.card.preferences)==null?void 0:x.formatNumber)==null?void 0:p.currency});return t.useEditorStore(c=>c.actions.setFilterOnClickField),t.jsxRuntimeExports.jsxs("div",{children:[t.jsxRuntimeExports.jsxs("div",{className:"mb-3 flex items-center gap-2",children:[t.jsxRuntimeExports.jsx(t.Checkbox,{checked:!!((o=e==null?void 0:e.formatNumber)!=null&&o.enabled),onCheckedChange:c=>{n({...e,formatNumber:{...e==null?void 0:e.formatNumber,enabled:c}})}}),t.jsxRuntimeExports.jsx(t.Label,{children:"Format Number"})]}),((a=e==null?void 0:e.formatNumber)==null?void 0:a.enabled)===!0&&t.jsxRuntimeExports.jsxs("div",{className:"flex flex-col gap-2",children:[t.jsxRuntimeExports.jsxs("div",{children:[t.jsxRuntimeExports.jsx(t.Label,{className:"text-xs",children:"Currency"}),t.jsxRuntimeExports.jsxs("div",{className:"flex gap-1",children:[t.jsxRuntimeExports.jsx(t.Input,{value:l||"",className:"h-7 font-mono text-xs focus-visible:ring-0 focus-visible:ring-ring focus-visible:ring-offset-0",placeholder:"USD",onChange:c=>{var x,p,m;return r(((x=e==null?void 0:e.formatNumber)==null?void 0:x.format)||"",c.target.value,((p=e==null?void 0:e.formatNumber)==null?void 0:p.locale)||"",((m=e==null?void 0:e.formatNumber)==null?void 0:m.suffix)||"")}}),t.jsxRuntimeExports.jsx(t.Input,{value:s||"",className:"h-7 font-mono text-xs focus-visible:ring-0 focus-visible:ring-ring focus-visible:ring-offset-0",placeholder:"en-US",onChange:c=>{var x,p,m;return r(((x=e==null?void 0:e.formatNumber)==null?void 0:x.format)||"",((p=e==null?void 0:e.formatNumber)==null?void 0:p.currency)||"",c.target.value,((m=e==null?void 0:e.formatNumber)==null?void 0:m.suffix)||"")}})]})]}),t.jsxRuntimeExports.jsxs("div",{children:[t.jsxRuntimeExports.jsxs("div",{className:"flex gap-1",children:[t.jsxRuntimeExports.jsx(t.Label,{className:"text-xs",children:"Format"}),t.jsxRuntimeExports.jsxs(t.Tooltip,{children:[t.jsxRuntimeExports.jsx(t.TooltipTrigger,{children:t.jsxRuntimeExports.jsx(t.InfoCircledIcon,{strokeWidth:1,className:"h-3 w-3 opacity-70"})}),t.jsxRuntimeExports.jsx(t.TooltipContent,{children:t.jsxRuntimeExports.jsxs("div",{className:"max-w-[200px]",children:["Format number",t.jsxRuntimeExports.jsx("div",{className:"mt-1 font-mono text-xs",children:"#.## for 123.43"})]})})]})]}),t.jsxRuntimeExports.jsx("div",{children:t.jsxRuntimeExports.jsx(t.Input,{value:i||"",className:"h-7 font-mono text-xs focus-visible:ring-0 focus-visible:ring-ring focus-visible:ring-offset-0",placeholder:"###,###.##",onChange:c=>{var x,p,m;return r(c.target.value,((x=e==null?void 0:e.formatNumber)==null?void 0:x.currency)||"",((p=e==null?void 0:e.formatNumber)==null?void 0:p.locale)||"",((m=e==null?void 0:e.formatNumber)==null?void 0:m.suffix)||"")}})})]}),t.jsxRuntimeExports.jsxs("div",{children:[t.jsxRuntimeExports.jsx(t.Label,{className:"text-xs",children:"Suffix"}),t.jsxRuntimeExports.jsx(t.Input,{value:((u=e==null?void 0:e.formatNumber)==null?void 0:u.suffix)||"",className:"h-7 font-mono text-xs focus-visible:ring-0 focus-visible:ring-ring focus-visible:ring-offset-0",placeholder:"K, M, B",onChange:c=>{var x,p,m;return r(((x=e==null?void 0:e.formatNumber)==null?void 0:x.format)||"",((p=e==null?void 0:e.formatNumber)==null?void 0:p.currency)||"",((m=e==null?void 0:e.formatNumber)==null?void 0:m.locale)||"",c.target.value)}})]})]})]})}function $u(){return t.jsxRuntimeExports.jsxs("div",{className:"space-y-6 px-6 py-2",children:[t.jsxRuntimeExports.jsx(t.Accordion,{type:"single",collapsible:!0,children:t.jsxRuntimeExports.jsxs(t.AccordionItem,{value:"item-1",children:[t.jsxRuntimeExports.jsx(t.AccordionTrigger,{className:"",children:"KPI Query"}),t.jsxRuntimeExports.jsxs(t.AccordionContent,{className:"font-mono",children:[t.jsxRuntimeExports.jsx("div",{className:"rounded bg-muted px-2 py-1 font-mono text-xs",children:"SELECT current, previous FROM table"}),t.jsxRuntimeExports.jsxs("ul",{className:"my-6 ml-6 list-disc text-xs [&>li]:mt-2",children:[t.jsxRuntimeExports.jsx("li",{children:"current - number"}),t.jsxRuntimeExports.jsx("li",{children:"previous - number"})]}),t.jsxRuntimeExports.jsxs("div",{children:["See ",t.jsxRuntimeExports.jsx("a",{target:"_blank",onClick:e=>e.stopPropagation(),className:"text-blue-700",href:"https://docs.semaphor.cloud/concepts/visuals#kpi",children:"example"})," in the docs."]})]})]})}),t.jsxRuntimeExports.jsx("section",{className:"",children:t.jsxRuntimeExports.jsx(Uu,{})}),t.jsxRuntimeExports.jsx("div",{}),t.jsxRuntimeExports.jsx("div",{})]})}function Ku({cardType:e}){return t.jsxRuntimeExports.jsx("div",{className:"px-6 py-2 space-y-6",children:t.jsxRuntimeExports.jsxs(t.Accordion,{defaultValue:["item-2"],type:"multiple",children:[t.jsxRuntimeExports.jsxs(t.AccordionItem,{value:"item-1",children:[t.jsxRuntimeExports.jsx(t.AccordionTrigger,{children:`${t.titleCase(e)} Chart`}),t.jsxRuntimeExports.jsxs(t.AccordionContent,{className:" space-y-4 font-mono text-xs ",children:[t.jsxRuntimeExports.jsx("div",{className:"bg-muted px-2 py-1 rounded text-xs",children:"SELECT label, measure FROM table"}),t.jsxRuntimeExports.jsxs("ul",{className:" ml-6 list-disc [&>li]:mt-2 text-xs",children:[t.jsxRuntimeExports.jsx("li",{children:"label - category"}),t.jsxRuntimeExports.jsx("li",{children:"measure - number"})]}),t.jsxRuntimeExports.jsxs("div",{children:["See ",t.jsxRuntimeExports.jsx("a",{target:"_blank",onClick:n=>n.stopPropagation(),className:"text-blue-700",href:"https://docs.semaphor.cloud/concepts/visuals#pie-chart",children:"example"})," in the docs."]})]})]}),t.jsxRuntimeExports.jsxs(t.AccordionItem,{value:"item-2",children:[t.jsxRuntimeExports.jsx(t.AccordionTrigger,{children:"Settings"}),t.jsxRuntimeExports.jsx(t.AccordionContent,{className:"px-2",children:t.jsxRuntimeExports.jsx(cn,{})})]}),t.jsxRuntimeExports.jsxs(t.AccordionItem,{value:"item-3",children:[t.jsxRuntimeExports.jsx(t.AccordionTrigger,{children:"Filter on click"}),t.jsxRuntimeExports.jsx(t.AccordionContent,{className:"px-2",children:t.jsxRuntimeExports.jsx(We,{})})]})]})})}function Wu(){return t.jsxRuntimeExports.jsx("div",{className:"space-y-6 px-6 py-2",children:t.jsxRuntimeExports.jsxs(t.Accordion,{defaultValue:["item-2"],type:"multiple",children:[t.jsxRuntimeExports.jsxs(t.AccordionItem,{value:"item-1",children:[t.jsxRuntimeExports.jsx(t.AccordionTrigger,{children:"Stacked Chart"}),t.jsxRuntimeExports.jsxs(t.AccordionContent,{className:"space-y-4 font-mono text-xs",children:[t.jsxRuntimeExports.jsx("div",{className:"rounded bg-muted px-2 py-1 text-xs",children:"SELECT x-axis, stack-by, y-axis FROM table"}),t.jsxRuntimeExports.jsxs("ul",{className:"ml-6 list-disc text-xs [&>li]:mt-2",children:[t.jsxRuntimeExports.jsx("li",{children:"x-axis - category"}),t.jsxRuntimeExports.jsx("li",{children:"stack by - category"}),t.jsxRuntimeExports.jsx("li",{children:"y-axis - number"})]}),t.jsxRuntimeExports.jsxs("div",{children:["See ",t.jsxRuntimeExports.jsx("a",{target:"_blank",onClick:e=>e.stopPropagation(),className:"text-blue-700",href:"https://docs.semaphor.cloud/concepts/visuals#stacked-chart",children:"example"})," in the docs."]})]})]}),t.jsxRuntimeExports.jsxs(t.AccordionItem,{value:"item-2",children:[t.jsxRuntimeExports.jsx(t.AccordionTrigger,{children:"Settings"}),t.jsxRuntimeExports.jsxs(t.AccordionContent,{className:"space-y-4 px-2",children:[t.jsxRuntimeExports.jsx(un,{}),t.jsxRuntimeExports.jsx(li,{})]})]}),t.jsxRuntimeExports.jsxs(t.AccordionItem,{value:"item-3",children:[t.jsxRuntimeExports.jsx(t.AccordionTrigger,{children:"Filter on click"}),t.jsxRuntimeExports.jsx(t.AccordionContent,{className:"px-2",children:t.jsxRuntimeExports.jsx(We,{})})]})]})})}function Qu({cardType:e}){return console.log("TableVisualSettings",e),t.jsxRuntimeExports.jsx("div",{className:"space-y-6 px-6 py-2",children:t.jsxRuntimeExports.jsx(t.Accordion,{defaultValue:["item-3"],type:"multiple",children:t.jsxRuntimeExports.jsxs(t.AccordionItem,{value:"item-3",children:[t.jsxRuntimeExports.jsx(t.AccordionTrigger,{children:"Filter on click"}),t.jsxRuntimeExports.jsx(t.AccordionContent,{className:"px-2",children:t.jsxRuntimeExports.jsx(We,{})})]})})})}function Gu(){const e=t.useEditorStore(r=>r.card.type);function n(r){switch(r){case"stackedBar":return t.jsxRuntimeExports.jsx(Wu,{});case"kpi":return t.jsxRuntimeExports.jsx($u,{});case"line":case"bar":return t.jsxRuntimeExports.jsx(Pu,{cardType:r});case"pie":case"doughnut":case"polarArea":case"radar":return t.jsxRuntimeExports.jsx(Ku,{cardType:r});case"bubble":case"scatter":return t.jsxRuntimeExports.jsx(Bu,{cardType:r});case"table":return t.jsxRuntimeExports.jsx(Qu,{cardType:r});default:return t.jsxRuntimeExports.jsx(Vu,{})}}return t.jsxRuntimeExports.jsx(t.ScrollArea,{className:"h-full w-full text-sm",children:n(e)})}function Ju(){const e=t.useEditorStore(n=>n.isShowingVisual);return t.jsxRuntimeExports.jsxs(Ot,{direction:"vertical",className:"min-w-full max-w-lg min-h-[250px]",children:[t.jsxRuntimeExports.jsx(Ve,{role:"query-section",className:"flex",minSize:20,defaultSize:40,children:t.jsxRuntimeExports.jsx(vu,{})}),t.jsxRuntimeExports.jsx(Dt,{withHandle:!0,className:"border "}),t.jsxRuntimeExports.jsx(Ve,{className:"pb-1",role:"visual-section",minSize:0,defaultSize:60,children:e?t.jsxRuntimeExports.jsxs(Ot,{direction:"horizontal",children:[t.jsxRuntimeExports.jsx(t.jsxRuntimeExports.Fragment,{children:t.jsxRuntimeExports.jsx(Ve,{className:"flex min-w-[275px]",minSize:20,defaultSize:25,maxSize:30,children:t.jsxRuntimeExports.jsx(Gu,{})})}),t.jsxRuntimeExports.jsx(Dt,{className:"border "}),t.jsxRuntimeExports.jsx(Ve,{minSize:40,defaultSize:75,maxSize:100,children:t.jsxRuntimeExports.jsx(rr,{})})]}):t.jsxRuntimeExports.jsx(rr,{})})]})}function Xu({authToken:e,onSave:n,onClose:r}){const i=t.useEditorStore(o=>o.actions.setOnSave),s=t.useEditorStore(o=>o.actions.setOnClose),l=t.useDashboardStore(o=>o.actions.setAuthToken);return A.useEffect(()=>{n&&i(n),r&&s(r)},[n,i,r,s]),A.useEffect(()=>{e&&e.accessToken&&l(e)},[e,l]),t.jsxRuntimeExports.jsxs(t.EditorPanel,{className:"rounded-none",role:"editor-panel",children:[t.jsxRuntimeExports.jsx(t.EditorAside,{className:"rounded-none border-r-[1.5px]",children:t.jsxRuntimeExports.jsx(xr,{})}),t.jsxRuntimeExports.jsx(t.EditorMain,{children:t.jsxRuntimeExports.jsx(Ju,{})})]})}function Yu(){t.useDashboardStore(o=>o.selectedCardId);const e=t.useDashboardStore(o=>o.selectedSheetId),{setIsVisualEditing:n}=t.useDashboardStore(o=>o.actions),r=t.useDashboardStore(o=>o.isVisualEditing),i=t.useDashboardStore(o=>o.actions.updateFrame);function s(o){e&&(i(e,o),n(!1))}function l(){n(!1)}return t.jsxRuntimeExports.jsx("div",{role:"editor-container",className:t.cn("flex grow",{block:r,hidden:!r}),children:t.jsxRuntimeExports.jsx(Xu,{onSave:s,onClose:l})})}function Zu({columns:e,tableName:n}){const r=t.useEditorStore(p=>p.selectedConnectionId),i=t.useEditorStore(p=>p.selectedDatabaseName),s=t.useEditorStore(p=>p.selectedSchemaName),l=t.useEditorStore(p=>p.selectedTableName),o=t.useDashboardStore(p=>p.dashboard.filters)||[],a=t.useDashboardStore(p=>p.actions.addFilter),u=t.useDashboardStore(p=>p.actions.removeFilter),c=t.useDashboardStore(p=>p.actions.removeFilterValue);function x(p){const m=t.fmt(p.column_name),d=t.fmt(i||""),g=t.fmt(s||""),y=t.fmt(n),k=t.getQualifiedTableName(g,y),E=`${k}.${m}`;console.log("find",E,y,d);const R=o==null?void 0:o.find(C=>C.column===E&&C.table===y&&(C.database===d||C.database===i));if(R)c(R.id),u(R.id);else{if(n==="api"&&r){a({id:t.v4(),column:E,title:p.column_name,dataType:p.data_type,table:"api",database:"NA",connectionId:r,operation:"in",sql:t.getDefaultFilterSql(p.data_type,k,m)});return}a({id:t.v4(),column:`${k}.${m}`,title:p.column_name,dataType:p.data_type,table:l||"",database:i||"NA",connectionId:r||"",operation:"in",sql:t.getDefaultFilterSql(p.data_type,k,m)})}}return t.jsxRuntimeExports.jsx("div",{className:"xbg-red-100 flex-1 basis-0 flex-col overflow-scroll px-3",children:e==null?void 0:e.map(p=>{const m=o==null?void 0:o.find(d=>d.column===t.fmt(p.column_name)&&d.table===l&&d.database===i);return t.jsxRuntimeExports.jsx("div",{onClick:()=>x(p),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":m}),children:t.jsxRuntimeExports.jsxs("div",{className:"flex items-center gap-2",children:[t.jsxRuntimeExports.jsx(cr,{column:p}),t.jsxRuntimeExports.jsx("span",{children:p.column_name})]})},p.column_name)})})}function ec(){t.useDashboardStore(n=>n.showFilters);const e=t.useDashboardStore(n=>n.actions.setShowFilters);return t.jsxRuntimeExports.jsxs("section",{className:"relative flex grow flex-col border-l px-4",children:[t.jsxRuntimeExports.jsxs("div",{className:"mt-4 flex items-center justify-between gap-2 px-3",children:[t.jsxRuntimeExports.jsx(t.Label,{className:"text-lg",children:"Filters"}),t.jsxRuntimeExports.jsx(t.Button,{onClick:()=>e(!1),className:"h-7 w-7 p-0",variant:"ghost",children:t.jsxRuntimeExports.jsx(t.Cross2Icon,{})})]}),t.jsxRuntimeExports.jsx("div",{className:"flex grow",children:t.jsxRuntimeExports.jsx(xr,{ColumnsComponent:(n,r,i)=>t.jsxRuntimeExports.jsx(Zu,{schemaName:n,tableName:r,columns:i})})})]})}function tc(){t.useDashboardStore(r=>r.dashboard);const e=t.useDashboardStore(r=>r.showFilters),n=t.useDashboardStore(r=>r.isVisualEditing);return t.useDashboardStore(r=>r.bookmarkKey),t.jsxRuntimeExports.jsxs("div",{role:"dashboard-plus-main",className:t.cn("grow",{hidden:n,flex:!n}),children:[t.jsxRuntimeExports.jsx(t.DashboardTabs,{}),e&&t.jsxRuntimeExports.jsx("div",{role:"filter-aside-container",className:"flex",children:t.jsxRuntimeExports.jsx(ec,{})})]})}function nc(){const e=t.useDashboardStore(i=>i.dashboard),n=t.useDashboardStore(i=>i.actions.setDashboard),r=t.useDashboardStore(i=>i.showDashboardJSON);return t.useDashboardStore(i=>i.actions.setShowDashboardJSON),t.jsxRuntimeExports.jsx("div",{className:t.cn(" p-2",{hidden:!r}),children:t.jsxRuntimeExports.jsx(t.de,{onChange:i=>{if(i)try{JSON.parse(i),n(JSON.parse(i))}catch{}},defaultLanguage:"json",className:"h-[550px] overflow-y-auto ",value:JSON.stringify(e,null,2),options:{minimap:{enabled:!1},glyphMargin:!1,wordWrap:"on",scrollbar:{verticalScrollbarSize:0,horizontalScrollbarSize:0},fontSize:12,renderLineHighlight:"none"}})})}function rc({showControls:e=!1,showFooter:n=!0,...r}){return t.jsxRuntimeExports.jsx(t.SemaphorContextProvider,{dashboardProps:r,children:t.jsxRuntimeExports.jsxs(t.UXProvider,{children:[t.jsxRuntimeExports.jsx(nc,{}),t.jsxRuntimeExports.jsxs(t.DashboardPanel,{...r,children:[e&&t.jsxRuntimeExports.jsx(Fi,{}),t.jsxRuntimeExports.jsx(Yu,{}),t.jsxRuntimeExports.jsx(tc,{})]})]})})}exports.DashboardPlus=rc;exports.SelectComponent=Je;exports.useEditorAside=pr;