semaphor 0.0.81 → 0.0.82

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 e=require("./index-D5fUelI7.js"),S=require("react");require("react-dom");function Gs(s){const n=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(s){for(const t in s)if(t!=="default"){const r=Object.getOwnPropertyDescriptor(s,t);Object.defineProperty(n,t,r.get?r:{enumerable:!0,get:()=>s[t]})}}return n.default=s,Object.freeze(n)}const $e=Gs(S);/**
1
+ "use strict";const e=require("./index-BTonSpSL.js"),S=require("react");require("react-dom");function Gs(s){const n=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(s){for(const t in s)if(t!=="default"){const r=Object.getOwnPropertyDescriptor(s,t);Object.defineProperty(n,t,r.get?r:{enumerable:!0,get:()=>s[t]})}}return n.default=s,Object.freeze(n)}const $e=Gs(S);/**
2
2
  * @license lucide-react v0.453.0 - ISC
3
3
  *
4
4
  * This source code is licensed under the ISC license.
@@ -242,4 +242,4 @@ SELECT label, measure FROM table
242
242
  Table Columns: ${b==null?void 0:b.map(N=>`${N.column_name} | ${N.data_type}`).join(", ")}
243
243
  User SQL: ${L}
244
244
  ${j&&`Base Queries: ${JSON.stringify(j)} `}`,y=` When the user asks for a specific chart please use the following query structure to generate the chart query. Do not make up the column names. Use only the table columns provided above for the query. Replace x-axis, y-axis, and lables with the appropriate column names.
245
- Visual Query Syntax: ${rt}`,{data:C,isLoading:T,isFetching:u,isError:R,refetch:p}=e.useQuery({queryKey:["ai-query"],queryFn:()=>e.getRequest("https://semaphor.cloud/api/v1/ai",(a==null?void 0:a.accessToken)||"",{user_content:`userContent: ${z} ${m?y:""}`}),enabled:!1});function w(N){if(N.toLowerCase().includes("bar"))h("bar");else if(N.toLowerCase().includes("line"))h("line");else if(N.toLowerCase().includes("bubble"))h("bubble");else if(N.toLowerCase().includes("scatter"))h("scatter");else if(N.toLowerCase().includes("stacked"))h("stackedBar");else if(N.toLowerCase().includes("pie"))h("pie");else if(N.toLowerCase().includes("donut")||N.toLowerCase().includes("doughnut"))h("doughnut");else if(N.toLowerCase().includes("radar"))h("radar");else return h("bar"),!1;return!0}S.useEffect(()=>{C&&I(N=>[...N,{role:"ai",content:C.response}])},[C]),S.useEffect(()=>{const N=setTimeout(()=>{var F;c.current&&(c.current.scroll({top:c.current.scrollHeight,behavior:"smooth"}),(F=i.current)==null||F.focus())},100);return()=>clearTimeout(N)},[E]);function A(){t&&(I(N=>[...N,{role:"user",content:t}]),w(t)&&x(!0),r(""),p())}S.useEffect(()=>{o&&(A(),l(!1))},[o,l]);const M={fontFamily:"Arial, sans-serif",lineHeight:1.6,fontSize:15,width:"100%"},q={fontFamily:"monospace",fontSize:14,lineHeight:1.6},B={fontFamily:"Arial, sans-serif",lineHeight:1.6,fontSize:15,padding:"2px 0",marginLeft:20,listStyleType:"disc"},K={p:({node:N,...F})=>e.jsxRuntimeExports.jsx("p",{style:M,...F}),code:({node:N,...F})=>e.jsxRuntimeExports.jsx("code",{className:"rounded-sm bg-muted px-2 py-1 text-sm",...F}),pre:({node:N,...F})=>e.jsxRuntimeExports.jsxs("pre",{className:"space-y-2 rounded-sm bg-muted/50 p-3",style:q,children:[e.jsxRuntimeExports.jsx("code",{className:"whitespace-normal text-sm",children:F.children}),e.jsxRuntimeExports.jsxs("div",{className:"flex justify-start gap-2",children:[e.jsxRuntimeExports.jsx(e.Button,{onClick:_,size:"sm",variant:"outline",children:e.jsxRuntimeExports.jsx(e.ClipboardCopyIcon,{})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:P=>{const O=_(P);O&&(n(!1),g(O),d(!0))},size:"sm",variant:"outline",children:e.jsxRuntimeExports.jsx(e.PlayIcon,{})})]})]}),li:({node:N,...F})=>e.jsxRuntimeExports.jsx("li",{style:B,...F})};function _(N){const F=N.currentTarget.closest("pre");if(!F)return;const P=F.textContent||F.innerText;return navigator.clipboard.writeText(P).then(()=>console.log("Text copied to clipboard")).catch(O=>console.error("Error in copying text: ",O)),P}function U(){return E==null?void 0:E.map((N,F)=>N.role==="user"?e.jsxRuntimeExports.jsxs("div",{className:"flex items-start rounded-md bg-muted p-3 text-sm",children:[e.jsxRuntimeExports.jsx(bs,{className:"mr-2 h-5 w-5"}),e.jsxRuntimeExports.jsx("div",{children:N.content})]},F):N.role==="ai"?e.jsxRuntimeExports.jsx(e.Markdown,{className:"w-full overflow-auto py-1",components:K,children:C==null?void 0:C.response.replace(/DuckDB/gi,"Semaphor")},F):e.jsxRuntimeExports.jsx("div",{},F))}return e.jsxRuntimeExports.jsxs(e.Dialog,{open:s,onOpenChange:n,children:[e.jsxRuntimeExports.jsx(e.DialogTrigger,{asChild:!0,children:e.jsxRuntimeExports.jsx(e.Button,{size:"sm",className:"w-full justify-start border font-normal text-muted-foreground focus-visible:ring-0 focus-visible:ring-offset-0",variant:"secondary",children:"Type your question here..."})}),e.jsxRuntimeExports.jsxs(e.DialogContent,{className:"flex flex-col justify-between overflow-auto sm:max-w-[425px] md:max-h-[625px] md:min-w-[625px]",children:[e.jsxRuntimeExports.jsxs(e.DialogHeader,{children:[e.jsxRuntimeExports.jsx(e.DialogTitle,{children:"Assistant"}),e.jsxRuntimeExports.jsx(e.DialogDescription,{children:"What can I help you with?"})]}),e.jsxRuntimeExports.jsx("div",{ref:c,className:"h-[625px] w-full overflow-auto border-t border-t-muted",children:e.jsxRuntimeExports.jsx("div",{className:"space-y-4 py-2 pr-3",role:"messages",children:U()})}),e.jsxRuntimeExports.jsx("div",{children:e.jsxRuntimeExports.jsxs("div",{className:"flex w-full items-center rounded-md border",children:[e.jsxRuntimeExports.jsx(e.Textarea,{autoFocus:!0,ref:i,onKeyDown:N=>{N.key==="Enter"&&!N.shiftKey&&(N.preventDefault(),r(""),A())},placeholder:"Type your question here...",onFocus:N=>{const F=N.target,P=F.value.length;F.setSelectionRange(P,P)},className:e.cn("max-h-10 min-h-7 resize-none border-none focus-visible:ring-0 focus-visible:ring-ring focus-visible:ring-offset-0"),disabled:T||u,value:t,onChange:N=>r(N.target.value)})," ",e.jsxRuntimeExports.jsx(e.Button,{className:"h-8",size:"sm",variant:"ghost",onClick:A,children:!T&&!u?e.jsxRuntimeExports.jsx(e.PaperPlaneIcon,{}):e.jsxRuntimeExports.jsx(de,{className:"mr-2 h-4 w-4 animate-spin text-foreground/50"})})]})})]})]})}var Cs={color:void 0,size:void 0,className:void 0,style:void 0,attr:void 0},Qe=S.createContext&&S.createContext(Cs),it=["attr","size","title"];function at(s,n){if(s==null)return{};var t=lt(s,n),r,o;if(Object.getOwnPropertySymbols){var l=Object.getOwnPropertySymbols(s);for(o=0;o<l.length;o++)r=l[o],!(n.indexOf(r)>=0)&&Object.prototype.propertyIsEnumerable.call(s,r)&&(t[r]=s[r])}return t}function lt(s,n){if(s==null)return{};var t={};for(var r in s)if(Object.prototype.hasOwnProperty.call(s,r)){if(n.indexOf(r)>=0)continue;t[r]=s[r]}return t}function Ce(){return Ce=Object.assign?Object.assign.bind():function(s){for(var n=1;n<arguments.length;n++){var t=arguments[n];for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&(s[r]=t[r])}return s},Ce.apply(this,arguments)}function Ue(s,n){var t=Object.keys(s);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(s);n&&(r=r.filter(function(o){return Object.getOwnPropertyDescriptor(s,o).enumerable})),t.push.apply(t,r)}return t}function Ne(s){for(var n=1;n<arguments.length;n++){var t=arguments[n]!=null?arguments[n]:{};n%2?Ue(Object(t),!0).forEach(function(r){ct(s,r,t[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(s,Object.getOwnPropertyDescriptors(t)):Ue(Object(t)).forEach(function(r){Object.defineProperty(s,r,Object.getOwnPropertyDescriptor(t,r))})}return s}function ct(s,n,t){return n=xt(n),n in s?Object.defineProperty(s,n,{value:t,enumerable:!0,configurable:!0,writable:!0}):s[n]=t,s}function xt(s){var n=ut(s,"string");return typeof n=="symbol"?n:n+""}function ut(s,n){if(typeof s!="object"||!s)return s;var t=s[Symbol.toPrimitive];if(t!==void 0){var r=t.call(s,n||"default");if(typeof r!="object")return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return(n==="string"?String:Number)(s)}function Ns(s){return s&&s.map((n,t)=>S.createElement(n.tag,Ne({key:t},n.attr),Ns(n.child)))}function ee(s){return n=>S.createElement(dt,Ce({attr:Ne({},s.attr)},n),Ns(s.child))}function dt(s){var n=t=>{var{attr:r,size:o,title:l}=s,i=at(s,it),c=o||t.size||"1em",a;return t.className&&(a=t.className),s.className&&(a=(a?a+" ":"")+s.className),S.createElement("svg",Ce({stroke:"currentColor",fill:"currentColor",strokeWidth:"0"},t.attr,r,i,{className:a,style:Ne(Ne({color:s.color||t.color},t.style),s.style),height:c,width:c,xmlns:"http://www.w3.org/2000/svg"}),l&&S.createElement("title",null,l),s.children)};return Qe!==void 0?S.createElement(Qe.Consumer,null,t=>n(t)):n(Cs)}function mt(s){return ee({tag:"svg",attr:{viewBox:"0 0 448 512"},child:[{tag:"path",attr:{d:"M439.8 200.5c-7.7-30.9-22.3-54.2-53.4-54.2h-40.1v47.4c0 36.8-31.2 67.8-66.8 67.8H172.7c-29.2 0-53.4 25-53.4 54.3v101.8c0 29 25.2 46 53.4 54.3 33.8 9.9 66.3 11.7 106.8 0 26.9-7.8 53.4-23.5 53.4-54.3v-40.7H226.2v-13.6h160.2c31.1 0 42.6-21.7 53.4-54.2 11.2-33.5 10.7-65.7 0-108.6zM286.2 404c11.1 0 20.1 9.1 20.1 20.3 0 11.3-9 20.4-20.1 20.4-11 0-20.1-9.2-20.1-20.4.1-11.3 9.1-20.3 20.1-20.3zM167.8 248.1h106.8c29.7 0 53.4-24.5 53.4-54.3V91.9c0-29-24.4-50.7-53.4-55.6-35.8-5.9-74.7-5.6-106.8.1-45.2 8-53.4 24.7-53.4 55.6v40.7h106.9v13.6h-147c-31.1 0-58.3 18.7-66.8 54.2-9.8 40.7-10.2 66.1 0 108.6 7.6 31.6 25.7 54.2 56.8 54.2H101v-48.8c0-35.3 30.5-66.4 66.8-66.4zm-6.7-142.6c-11.1 0-20.1-9.1-20.1-20.3.1-11.3 9-20.4 20.1-20.4 11 0 20.1 9.2 20.1 20.4s-9 20.3-20.1 20.3z"},child:[]}]})(s)}function pt(){const[s,n]=S.useState({queryKey:[],queryData:null}),{theme:t}=e.useTheme(),r=e.useQueryClient(),o=S.useRef(),l=S.useRef(),[i,c]=S.useState(!1),[a,m]=S.useState(!1),[x,g]=S.useState(!1),[j,d]=S.useState(""),[h,E]=S.useState(!1),I=e.useDashboardStore(f=>f.selectedSheetId);e.useDashboardStore(f=>f.dashboard.baseQueries);const b=e.useEditorStore(f=>f.card),L=e.useDashboardStore(f=>f.theme),k=e.useEditorStore(f=>f.isShowingVisual);e.useDashboardStore(f=>f.onAcceptChanges);const z=e.useEditorStore(f=>f.selectedConnectionId),y=e.useEditorStore(f=>f.selectedDatabaseName),C=e.useEditorStore(f=>f.selectedDatamodelId),T=e.useEditorStore(f=>f.selectedSchemaName);e.useDashboardStore(f=>f.actions.updateFrameCard);const u=e.useEditorStore(f=>f.selectedTableName),R=e.useEditorStore(f=>f.card.sql),p=e.useEditorStore(f=>f.card.python),w=e.useEditorStore(f=>f.frame),A=e.useDashboardStore(f=>f.dashboard.filters),M=e.useDashboardStore(f=>f.filterValues),q=A==null?void 0:A.filter(f=>f.sheetId===I||!f.sheetId),B=M==null?void 0:M.filter(f=>(q==null?void 0:q.some(Q=>Q.id===f.filterId))||f.filterId.endsWith(I)),K=e.useEditorStore(f=>f.applyFilters),{setCardCustomCfg:_,setQueryResultColumns:U,setFilterValues:N,setCardSql:F,setCard:P,setCardPython:O,setQueryError:D,setPythonStdOut:G,setCardPreferences:V}=e.useEditorStore(f=>f.actions),H=e.useEditorStore(f=>f.onSave),J=e.useEditorStore(f=>f.actions.setApplyFilters),se=e.useEditorStore(f=>f.onClose),le=e.useEditorStore(f=>f.actions.setSqlGen),te=e.useEditorStore(f=>f.runSql),re=e.useEditorStore(f=>f.actions.setRunSql);e.useEditorStore(f=>f.actions.setCardCfg);const ne=e.useEditorStore(f=>f.actions.setIsSqlRunning),{data:$,isLoading:Y,isFetching:X,isSuccess:ge,isError:ce,error:pe,queryKey:je,refetch:xe}=e.useDashboardCardQuery(b);S.useEffect(()=>{if($&&($.rowLimitExceeded&&e.ce.error("Row limit (10,000) exceeded. Refine your query.",{position:"top-center",richColors:!0}),G(($==null?void 0:$.output)||""),$.records.length>0)){const{dimensionKeys:f}=e.getKeys($.records);U(f)}},[$,U,G]),S.useEffect(()=>{(Y||X)&&ne(!0),(ce||ge)&&ne(!1),ce?(D(pe.message),U([]),G("")):D("")},[Y,X,$,G,ce,ge,ne,U,D,pe]),S.useEffect(()=>{te&&(xe(),re(!1))},[te,xe,re]);function Le(){const f=r.getQueryData(je);s.queryData||n({queryKey:je,queryData:f}),r.setQueryData(je,null),F(""),le({}),_(""),V({})}const he=f=>{l.current=f};function Re(f,Q){if(f.length===0)return"";if(Q){const oe=f.find(W=>W.id===Q);if(oe){const W=oe.tabTitle;if(W=="All__Header")return f[0].id;if(W&&W.endsWith("__Header")){const Hs=W.split("__")[0],Ge=f.find(Ps=>Ps.tabTitle===Hs);return Ge?Ge.id:f[0].id}return Q}}return f[0].id}function be(){let f=R;R&&!R.includes("{{")&&(f=Zs(R),F(f));const Q={...b,lastSelectedSchema:T,lastSelectedDatamodelId:C,lastSelectedDatabase:y,lastSelectedTable:u,connectionId:z,type:k?b.type:"table",sql:f,customCfg:k?b.customCfg:null},oe=w.cards.map(Te=>Te.id===b.id?Q:Te),W={...w,cards:oe,activeCardId:Re(oe,w.activeCardId)};H==null||H(W)}function ye(){const{queryKey:f,queryData:Q}=s;f&&Q&&r.setQueryData(f,Q),se==null||se()}S.useEffect(()=>{const f=o.current,Q=l.current;if(f){const oe=window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light",W=L==="system"?oe:L;f.editor.defineTheme("default",{base:W==="light"?"vs":"vs-dark",inherit:!0,rules:[],colors:{"editor.background":W==="light"?"#ffffff":e.getCssVariableValue("--semaphor-background")}}),f.editor.setTheme("default")}return Q&&f&&Q.addCommand(f.KeyMod.Shift|f.KeyCode.Enter,function(){return console.log("Executing query..."),xe(),!1}),()=>{}},[t,L,o.current]);function Ee(f){o.current=f}function v(){return e.jsxRuntimeExports.jsxs(e.jsxRuntimeExports.Fragment,{children:[a&&e.jsxRuntimeExports.jsx("div",{className:"xbg-yellow-100 relative flex w-1/3 min-w-0 grow overflow-hidden border-l p-1 text-xs",role:"editor-filter-container",children:e.jsxRuntimeExports.jsxs("div",{className:"w-[99%]",children:[e.jsxRuntimeExports.jsxs("div",{className:"flex items-center gap-2 pt-3",children:[e.jsxRuntimeExports.jsx(st,{checked:K,onCheckedChange:()=>J(!K),text:"Apply Filters"}),e.jsxRuntimeExports.jsx(nt,{}),B&&a&&e.jsxRuntimeExports.jsx(e.Cross2Icon,{onClick:()=>m(!1),className:"bg-background/50 text-foreground/50 hover:cursor-pointer hover:text-foreground"})]}),e.jsxRuntimeExports.jsx(e.Ft,{theme:"default",onChange:f=>{if(f)try{JSON.parse(f),N(JSON.parse(f))}catch{}},defaultLanguage:"json",className:"mt-1 min-h-[220px]",value:JSON.stringify(B,null,2),options:{readOnly:!0,minimap:{enabled:!1},lineNumbers:"off",glyphMargin:!1,wordWrap:"on",scrollbar:{verticalScrollbarSize:0,horizontalScrollbarSize:0},fontSize:12,renderLineHighlight:"none"}})]})}),B&&!a&&e.jsxRuntimeExports.jsx(e.Filter,{onClick:()=>m(!0),className:e.cn("absolute bottom-4 right-6 h-3 w-3 text-foreground/50 hover:cursor-pointer hover:text-foreground",{"font-bold text-red-800":K})})]})}function Bs(){return e.jsxRuntimeExports.jsxs(e.ResizablePanelGroup,{className:"flex grow pb-1",direction:"vertical",role:"editor-resizable-group",children:[e.jsxRuntimeExports.jsxs(e.ResizablePanel,{id:"1",order:1,defaultSize:i?20:100,className:"relative flex grow",children:[e.jsxRuntimeExports.jsx("div",{role:"sql-container",className:"relative flex w-[99%]",children:e.jsxRuntimeExports.jsx(e.Ft,{theme:"default",className:"pt-3",onChange:f=>{F(f)},value:R,options:{minimap:{enabled:!1},wordWrap:"on",scrollbar:{verticalScrollbarSize:0,horizontalScrollbarSize:0},fontSize:14,renderLineHighlight:"none"},defaultLanguage:"sql",beforeMount:Ee,onMount:he})}),i&&e.jsxRuntimeExports.jsx("code",{className:"absolute right-6 top-3 text-sm text-muted-foreground/70",children:"sql"})]}),i&&e.jsxRuntimeExports.jsxs(e.jsxRuntimeExports.Fragment,{children:[e.jsxRuntimeExports.jsx(e.ResizableHandle,{withHandle:!0,className:"border"}),e.jsxRuntimeExports.jsxs(e.ResizablePanel,{id:"2",order:2,defaultSize:80,className:"relative flex grow",children:[e.jsxRuntimeExports.jsx("div",{role:"python-container",className:"relative flex w-[99%] pt-0",children:e.jsxRuntimeExports.jsx(e.Ft,{className:"pt-3",theme:"default",onChange:f=>{O(f&&f.trim()||"")},value:p||e.PYTHON_DEFAULT_CODE,options:{minimap:{enabled:!1},wordWrap:"on",scrollbar:{verticalScrollbarSize:0,horizontalScrollbarSize:0},fontSize:14,renderLineHighlight:"none"},defaultLanguage:"python",beforeMount:Ee,onMount:he})}),e.jsxRuntimeExports.jsx("code",{className:"absolute right-6 top-3 text-sm text-muted-foreground/70",children:"python"})]})]})]})}return e.jsxRuntimeExports.jsxs("section",{role:"editor-section",className:"flex grow flex-col justify-end",children:[e.jsxRuntimeExports.jsxs("div",{role:"sql-editor",className:"relative flex grow justify-between overflow-y-scroll",children:[Bs(),v()]}),e.jsxRuntimeExports.jsxs("div",{role:"editor-controls",className:"item-center flex flex-wrap justify-between gap-2 px-6 py-4",children:[e.jsxRuntimeExports.jsxs("div",{className:"flex grow items-center gap-2",children:[e.jsxRuntimeExports.jsxs(e.Button,{title:"Shift + Enter",disabled:Y||X,onClick:()=>{xe()},className:"shrink-0",size:"sm",variant:"outline",children:[Y||X?e.jsxRuntimeExports.jsx(de,{className:"mr-2 h-4 w-4 animate-spin text-foreground/50"}):e.jsxRuntimeExports.jsx(ms,{className:"mr-2 h-4 w-4"}),"Run"]}),ce&&e.jsxRuntimeExports.jsx(et,{error:pe.message,setShowAIDialog:g,setTriggerAIRun:E,setUserInputforAI:d}),e.jsxRuntimeExports.jsxs(e.Button,{onClick:Le,className:"",size:"sm",variant:"outline",children:[e.jsxRuntimeExports.jsx(ss,{className:"mr-2 size-4"}),"Clear"]}),e.jsxRuntimeExports.jsx(e.Toggle,{pressed:i,onPressedChange:f=>c(f),className:"",size:"sm",variant:"outline",children:e.jsxRuntimeExports.jsx(mt,{className:"size-4 text-foreground/70"})}),e.jsxRuntimeExports.jsx(ot,{open:x,setOpen:g,userInput:j,triggerAIRun:h,setTriggerAIRun:E,setUserInput:f=>d(f)})]}),e.jsxRuntimeExports.jsxs("div",{className:"flex items-end gap-2",children:[e.jsxRuntimeExports.jsxs(e.Button,{onClick:be,size:"sm",variant:"outline",children:[e.jsxRuntimeExports.jsx(e.Check,{className:"mr-2 size-4 font-bold text-green-600"}),"Accept"]}),e.jsxRuntimeExports.jsxs(e.Button,{onClick:ye,className:"w-full",size:"sm",variant:"outline",children:[e.jsxRuntimeExports.jsx(e.Cross2Icon,{className:"mr-2 size-4"}),"Close"]})]})]})]})}function jt({data:s}){var i;const[n,t]=S.useState([]),o=Object.keys(s[0]).map(c=>({accessorKey:c,header:({column:a})=>{const m=a.getIsSorted();return e.jsxRuntimeExports.jsx("div",{className:"flex gap-2",children:e.jsxRuntimeExports.jsxs("div",{className:"flex cursor-pointer items-center",onClick:()=>a.toggleSorting(a.getIsSorted()==="asc"),children:[c,m==="asc"?e.jsxRuntimeExports.jsx(e.TriangleUpIcon,{className:"ml-2 h-5 w-5"}):m==="desc"?e.jsxRuntimeExports.jsx(e.TriangleDownIcon,{className:"ml-2 h-5 w-5"}):null]})})}})),l=e.useReactTable({data:s,columns:o,getCoreRowModel:e.getCoreRowModel(),getPaginationRowModel:e.getPaginationRowModel(),onSortingChange:t,getSortedRowModel:e.getSortedRowModel(),manualPagination:!0,state:{sorting:n}});return e.jsxRuntimeExports.jsxs(e.Table$1,{children:[e.jsxRuntimeExports.jsx(e.TableHeader,{children:l.getHeaderGroups().map(c=>e.jsxRuntimeExports.jsx(e.TableRow,{children:c.headers.map(a=>e.jsxRuntimeExports.jsx(e.TableHead,{className:"sticky top-0 bg-muted",children:a.isPlaceholder?null:e.flexRender(a.column.columnDef.header,a.getContext())},a.id))},c.id))}),e.jsxRuntimeExports.jsx(e.TableBody,{children:(i=l.getRowModel().rows)!=null&&i.length?l.getRowModel().rows.map(c=>e.jsxRuntimeExports.jsx(e.TableRow,{className:"whitespace-nowrap py-2","data-state":c.getIsSelected()&&"selected",children:c.getVisibleCells().map(a=>e.jsxRuntimeExports.jsx(e.TableCell,{children:e.flexRender(a.column.columnDef.cell,a.getContext())},a.id))},c.id)):e.jsxRuntimeExports.jsx(e.TableRow,{children:e.jsxRuntimeExports.jsx(e.TableCell,{colSpan:o.length,className:"h-24 text-center",children:"No results."})})})]})}function ht({card:s}){var j,d,h,E,I,b,L,k,z,y;const{authToken:n}=e.useSemaphorContext(),t=e.getTokenParams(n==null?void 0:n.accessToken),r=e.useDashboardStore(C=>C.themeStyle),o={colors:((d=(j=r==null?void 0:r.chart)==null?void 0:j.dataset)==null?void 0:d.backgroundColor)||[]};(h=s.customCardPreferences)!=null&&h.inputData;const{getCard:l}=e.useCustomVisual(((E=s.customCardPreferences)==null?void 0:E.url)||""),i=((I=s.customCardPreferences)==null?void 0:I.visualType)||"single",c=e.useEditorStore(C=>C.frame);e.useEditorActions();const{data:a}=e.useDashboardCardQuery(s);if(!((b=s.customCardPreferences)!=null&&b.componentName))return null;const m=l((L=s.customCardPreferences)==null?void 0:L.componentName),x=C=>{console.log("data",C),s.customCardPreferences},g=Object.keys(((k=s.customCardPreferences)==null?void 0:k.dataInputCardIds)||{}).map(C=>{var R,p,w;const T=(p=(R=s.customCardPreferences)==null?void 0:R.dataInputCardIds)==null?void 0:p[C].cardId,u=(w=c==null?void 0:c.cards)==null?void 0:w.find(A=>A.id===T);return u||null});return e.jsxRuntimeExports.jsx("div",{className:"semaphor-custom mb-3 flex grow basis-0 flex-col space-y-2 overflow-y-auto",children:e.jsxRuntimeExports.jsxs(S.Suspense,{fallback:e.jsxRuntimeExports.jsx(e.jsxRuntimeExports.Fragment,{}),children:[m&&i==="single"&&e.jsxRuntimeExports.jsx(m,{params:t,theme:o,settings:(z=s.customCardPreferences)==null?void 0:z.settings,onDataChange:x,data:(a==null?void 0:a.records)||[]}),m&&i==="multiple"&&e.jsxRuntimeExports.jsx("div",{className:"flex flex-col gap-2",children:e.jsxRuntimeExports.jsx(m,{theme:o,onDataChange:x,settings:g.map(C=>{var T;return(T=C==null?void 0:C.customCardPreferences)==null?void 0:T.settings}),data:g.map(C=>(C==null?void 0:C.data)||[])})})]},(y=s.customCardPreferences)==null?void 0:y.componentName)})}function ws({className:s,...n}){var d,h;const t=e.useEditorStore(E=>E.card),r=((d=t.customCardPreferences)==null?void 0:d.showCardHeader)??!0,o=e.useEditorStore(E=>E.frame),l=e.useDashboardStore(E=>E.dashboard.filters);e.useEditorStore(E=>E.actions.setRunSql);const{updateFilter:i}=e.useDashboardActions(),c=l==null?void 0:l.find(E=>E.id===o.filterId),{data:a}=e.useDashboardCardQuery(t),{setCard:m}=e.useEditorActions(),{data:x}=e.useTopoJson(t);if(!t.id)return null;let g;a!=null&&a.records&&(a==null?void 0:a.records.length)>0&&(g=e.createChartConfig({data:a==null?void 0:a.records,cardType:t.type,cfg:t.cfg,customCfg:t.customCfg,preferences:t.preferences,topoJson:x}));function j(E){return e.jsxRuntimeExports.jsx(ht,{card:E})}return e.jsxRuntimeExports.jsxs(e.Card,{role:"editor-visual-card",className:e.cn("relative flex h-full flex-col rounded-none",s),...n,children:[r&&e.jsxRuntimeExports.jsxs(e.CardHeader,{className:"flex flex-row items-start justify-between py-4",children:[e.jsxRuntimeExports.jsxs("div",{children:[e.jsxRuntimeExports.jsx(e.Editable,{text:t.title,onSave:E=>m({...t,title:E}),children:e.jsxRuntimeExports.jsx("div",{className:"flex items-center gap-5",children:e.jsxRuntimeExports.jsx(e.CardTitle,{className:"text-base",children:t.title||"Edit title..."})})},t.title),e.jsxRuntimeExports.jsx(e.Editable,{text:t.description||"",onSave:E=>m({...t,description:E}),children:e.jsxRuntimeExports.jsx(e.CardDescription,{children:t.description||"Edit description..."})},t.description)]}),c&&e.jsxRuntimeExports.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxRuntimeExports.jsx(e.Editable,{className:"my-1",text:c.title||c.column,onSave:E=>i({...c,title:E}),children:e.jsxRuntimeExports.jsx(e.Label,{children:c.title})}),e.getFilterComponent(c)]})]}),e.jsxRuntimeExports.jsxs(e.CardContent,{className:"flex grow flex-col",children:[t.type==="custom"&&j(t),!["table","custom"].includes(t.type)&&g&&e.jsxRuntimeExports.jsx(e.ChartJsVisual,{cfg:g},JSON.stringify(g)+JSON.stringify(t.preferences)+((h=t==null?void 0:t.preferences)==null?void 0:h.customVisualCode)),t.type==="table"&&(a==null?void 0:a.records)&&(a==null?void 0:a.records.length)>0&&e.jsxRuntimeExports.jsx(e.ScrollArea$1,{className:"flex min-h-0 flex-1 grow basis-0",children:e.jsxRuntimeExports.jsx(e.TableVisual,{card:t,data:a==null?void 0:a.records})})]})]})}function Et(){const[s,n]=S.useState(!1),[t,r]=S.useState(""),[o,l]=S.useState(""),[i,c]=S.useState(""),[a,m]=S.useState(""),x=e.useEditorStore(y=>y.card),g=e.useEditorStore(y=>y.card.customCfg),{data:j}=e.useDashboardCardQuery(x),{data:d}=e.useTopoJson(x),{setCardCustomCfg:h,setCustomVisualCode:E}=e.useEditorActions();function I(y){var u,R;const C={...y,data:{...y==null?void 0:y.data,datasets:(R=(u=y==null?void 0:y.data)==null?void 0:u.datasets)==null?void 0:R.map(p=>({...p,data:[]}))}};return JSON.stringify(C,null,1)}function b(){var C,T;if(!(j!=null&&j.records)||(j==null?void 0:j.records.length)===0)return;const y=e.createChartConfig({data:j==null?void 0:j.records,cardType:x.type,cfg:x.cfg,preferences:x.preferences,topoJson:d});y&&(r(JSON.stringify(y,null,1)),(C=x==null?void 0:x.preferences)!=null&&C.customVisualCode&&c((T=x==null?void 0:x.preferences)==null?void 0:T.customVisualCode),g&&l(JSON.stringify(g,null,1)))}function L(){if(i&&E(i),!!o)try{const y=JSON.parse(o);return y?(h(y),m(""),l(""),y):void 0}catch(y){console.log(y),m("Invalid JSON")}}function k(){l(""),h(null)}function z(){let y;if(g){const C=e._.cloneDeep(x.cfg),T=e._.merge(C,g);return y=I(T),y}return t?(y=I(JSON.parse(t)),y):""}return e.jsxRuntimeExports.jsxs(e.Dialog,{open:s,onOpenChange:n,children:[e.jsxRuntimeExports.jsx(e.DialogTrigger,{asChild:!0,children:e.jsxRuntimeExports.jsx(e.Button,{onClick:b,className:` ${g&&"border-foreground/50 dark:border-foreground/70"}`,size:"sm",variant:"outline",children:e.jsxRuntimeExports.jsx(e.Settings,{className:"h-4 w-4"})})}),e.jsxRuntimeExports.jsxs(e.DialogContent,{className:"max-h-[70vh] min-h-[70vh] overflow-auto sm:min-w-[900px] lg:min-w-[1200px]",children:[e.jsxRuntimeExports.jsxs(e.DialogHeader,{className:"",children:[e.jsxRuntimeExports.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxRuntimeExports.jsx(e.DialogTitle,{children:"Customize Card"}),e.jsxRuntimeExports.jsxs(e.Tooltip,{children:[e.jsxRuntimeExports.jsx(e.TooltipTrigger,{children:e.jsxRuntimeExports.jsx(Ve,{onClick:()=>{navigator.clipboard.writeText(x.id)},className:"size-3 cursor-pointer text-muted-foreground/70 transition-colors hover:text-muted-foreground"})}),e.jsxRuntimeExports.jsx(e.TooltipContent,{side:"right",align:"center",children:e.jsxRuntimeExports.jsx("p",{className:"text-xs",children:"Copy Card ID"})})]})]}),e.jsxRuntimeExports.jsxs(e.DialogDescription,{children:["See the configuration options and documentation",e.jsxRuntimeExports.jsx("a",{target:"_blank",className:"ml-1 text-blue-500 underline",href:"https://www.chartjs.org/docs/latest/samples/bar/vertical.html",children:"here."})]})]}),e.jsxRuntimeExports.jsxs("div",{className:"flex grow gap-2",children:[e.jsxRuntimeExports.jsx(e.ErrorBoundary,{FallbackComponent:e.FallbackEditorCard,children:e.jsxRuntimeExports.jsx(ws,{className:"w-1/2 rounded shadow-none"})}),e.jsxRuntimeExports.jsxs(e.Tabs,{defaultValue:"custom-config",className:"flex w-1/2 flex-col",children:[e.jsxRuntimeExports.jsxs(e.TabsList,{className:"justify-start rounded-sm rounded-b-none border border-b-0",children:[e.jsxRuntimeExports.jsxs(e.TabsTrigger,{value:"custom-config",children:[g&&e.jsxRuntimeExports.jsx(e.CheckIcon,{className:"mr-1 h-5 w-5 text-green-600"}),g?"Custom Config":"Default Config"]}),e.jsxRuntimeExports.jsx(e.TabsTrigger,{className:"",value:"output",children:"Output"}),e.jsxRuntimeExports.jsx(e.TabsTrigger,{className:"",value:"custom-code",children:"Custom Code"})]}),e.jsxRuntimeExports.jsx(e.TabsContent,{className:"bg-red-x mt-0 grow rounded-b border border-t-0 p-2",value:"output",children:e.jsxRuntimeExports.jsx(e.Textarea,{disabled:!0,value:t,className:"h-full resize-none border-none font-mono focus-visible:ring-0 focus-visible:ring-offset-0"})}),e.jsxRuntimeExports.jsx(e.TabsContent,{className:"mt-0 grow rounded-b border border-t-0",value:"custom-config",children:e.jsxRuntimeExports.jsx(e.Ft,{className:"h-full w-full overflow-hidden",theme:"default",options:{minimap:{enabled:!1},wordWrap:"on",scrollbar:{verticalScrollbarSize:0,horizontalScrollbarSize:0},fontSize:14,renderLineHighlight:"none"},defaultLanguage:"json",value:z(),onChange:y=>l(y)})}),e.jsxRuntimeExports.jsx(e.TabsContent,{className:"mt-0 grow rounded-b border border-t-0",value:"custom-code",children:e.jsxRuntimeExports.jsx(e.Ft,{className:"h-full w-full overflow-hidden",theme:"default",options:{minimap:{enabled:!1},wordWrap:"on",scrollbar:{verticalScrollbarSize:0,horizontalScrollbarSize:0},fontSize:14,renderLineHighlight:"none"},defaultLanguage:"javascript",value:i,onChange:y=>c(y||"")})})]})]}),e.jsxRuntimeExports.jsxs(e.DialogFooter,{className:"flex items-center",children:[e.jsxRuntimeExports.jsx(e.Label,{className:"mr-2 text-red-500",children:a}),e.jsxRuntimeExports.jsx(e.Button,{disabled:!g,onClick:k,variant:"outline",children:"Reset"}),e.jsxRuntimeExports.jsx(e.Button,{onClick:L,variant:"outline",children:"Apply"}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>n(!1),variant:"outline",children:"Close"})]})]})]})}function ks(s){return ee({tag:"svg",attr:{viewBox:"0 0 1024 1024"},child:[{tag:"path",attr:{d:"M926.8 397.1l-396-288a31.81 31.81 0 0 0-37.6 0l-396 288a31.99 31.99 0 0 0-11.6 35.8l151.3 466a32 32 0 0 0 30.4 22.1h489.5c13.9 0 26.1-8.9 30.4-22.1l151.3-466c4.2-13.2-.5-27.6-11.7-35.8zM838.6 417l-98.5 32-200-144.7V199.9L838.6 417zM466 567.2l-89.1 122.3-55.2-169.2L466 567.2zm-116.3-96.8L484 373.3v140.8l-134.3-43.7zM512 599.2l93.9 128.9H418.1L512 599.2zm28.1-225.9l134.2 97.1L540.1 514V373.3zM558 567.2l144.3-46.9-55.2 169.2L558 567.2zm-74-367.3v104.4L283.9 449l-98.5-32L484 199.9zM169.3 470.8l86.5 28.1 80.4 246.4-53.8 73.9-113.1-348.4zM327.1 853l50.3-69h269.3l50.3 69H327.1zm414.5-33.8l-53.8-73.9 80.4-246.4 86.5-28.1-113.1 348.4z"},child:[]}]})(s)}function Is(s){return ee({tag:"svg",attr:{viewBox:"0 0 256 256",fill:"currentColor"},child:[{tag:"path",attr:{d:"M128,24a8,8,0,0,0-8,8V88a8,8,0,0,0,8,8,32,32,0,1,1-27.72,16,8,8,0,0,0-2.93-10.93l-48.5-28A8,8,0,0,0,37.92,76,104,104,0,1,0,128,24ZM48.09,91.1,83,111.26A48.09,48.09,0,0,0,80,128c0,1.53.08,3,.22,4.52L41.28,143A88.16,88.16,0,0,1,48.09,91.1Zm-2.67,67.31,39-10.44A48.1,48.1,0,0,0,120,175.32v40.31A88.2,88.2,0,0,1,45.42,158.41ZM136,215.63V175.32a48,48,0,0,0,0-94.65V40.36a88,88,0,0,1,0,175.27Z"},child:[]}]})(s)}function Ds(s){return ee({tag:"svg",attr:{viewBox:"0 0 256 256",fill:"currentColor"},child:[{tag:"path",attr:{d:"M128,24A104,104,0,1,0,232,128,104.11,104.11,0,0,0,128,24Zm87.63,96H191.48A64.1,64.1,0,0,0,136,64.52V40.37A88.13,88.13,0,0,1,215.63,120ZM120,120H80.68A48.09,48.09,0,0,1,120,80.68Zm0,16v39.32A48.09,48.09,0,0,1,80.68,136Zm16,0h39.32A48.09,48.09,0,0,1,136,175.32Zm0-16V80.68A48.09,48.09,0,0,1,175.32,120ZM120,40.37V64.52A64.1,64.1,0,0,0,64.52,120H40.37A88.13,88.13,0,0,1,120,40.37ZM40.37,136H64.52A64.1,64.1,0,0,0,120,191.48v24.15A88.13,88.13,0,0,1,40.37,136ZM136,215.63V191.48A64.1,64.1,0,0,0,191.48,136h24.15A88.13,88.13,0,0,1,136,215.63Z"},child:[]}]})(s)}function Ls(s){return ee({tag:"svg",attr:{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"},child:[{tag:"path",attr:{d:"M6 16m-3 0a3 3 0 1 0 6 0a3 3 0 1 0 -6 0"},child:[]},{tag:"path",attr:{d:"M16 19m-2 0a2 2 0 1 0 4 0a2 2 0 1 0 -4 0"},child:[]},{tag:"path",attr:{d:"M14.5 7.5m-4.5 0a4.5 4.5 0 1 0 9 0a4.5 4.5 0 1 0 -9 0"},child:[]}]})(s)}function Ts(s){return ee({tag:"svg",attr:{viewBox:"0 0 24 24"},child:[{tag:"path",attr:{fill:"none",d:"M0 0h24v24H0z"},child:[]},{tag:"path",attr:{d:"m2 19.99 7.5-7.51 4 4 7.09-7.97L22 9.92l-8.5 9.56-4-4-6 6.01-1.5-1.5zm1.5-4.5 6-6.01 4 4L22 3.92l-1.41-1.41-7.09 7.97-4-4L2 13.99l1.5 1.5z"},child:[]}]})(s)}function As(s){return ee({tag:"svg",attr:{viewBox:"0 0 24 24"},child:[{tag:"path",attr:{fill:"none",d:"M0 0h24v24H0z"},child:[]},{tag:"path",attr:{d:"M4 9h4v11H4zM4 4h4v4H4zM10 7h4v4h-4zM16 10h4v4h-4zM16 15h4v5h-4zM10 12h4v8h-4z"},child:[]}]})(s)}function Os(s){return ee({tag:"svg",attr:{version:"1.2",baseProfile:"tiny",viewBox:"0 0 24 24"},child:[{tag:"path",attr:{d:"M4 18c-.552 0-1-.448-1-1v-6.382l-.553.276c-.495.248-1.095.046-1.342-.447-.247-.494-.046-1.094.448-1.342l2-1c.31-.155.678-.139.973.044.294.183.474.504.474.851v8c0 .552-.448 1-1 1zM13 18h-5c-.404 0-.769-.244-.924-.617-.155-.374-.069-.804.217-1.09l4-4c.254-.254.394-.591.394-.95 0-.358-.14-.695-.394-.949-.508-.508-1.39-.508-1.9.001-.253.252-.393.589-.393.948 0 .552-.448 1-1 1s-1-.448-1-1c0-.894.348-1.733.98-2.364 1.265-1.263 3.464-1.263 4.727.001.632.631.979 1.471.979 2.363 0 .893-.348 1.733-.979 2.364l-2.293 2.293h2.586c.552 0 1 .448 1 1s-.448 1-1 1zM20.955 12.377c.338-.457.545-1.016.545-1.627 0-1.517-1.234-2.75-2.75-2.75-1.031 0-1.966.569-2.44 1.484-.254.49-.063 1.094.428 1.348.49.254 1.094.062 1.348-.428.128-.249.383-.404.664-.404.414 0 .75.336.75.75s-.336.75-.75.75c-.552 0-1 .448-1 1s.448 1 1 1c.689 0 1.25.561 1.25 1.25s-.561 1.25-1.25 1.25-1.25-.561-1.25-1.25c0-.552-.448-1-1-1s-1 .448-1 1c0 1.792 1.458 3.25 3.25 3.25s3.25-1.458 3.25-3.25c0-.939-.406-1.779-1.045-2.373z"},child:[]}]})(s)}function zs(s){return ee({tag:"svg",attr:{viewBox:"0 0 512 512"},child:[{tag:"path",attr:{d:"M217 25v14h78V25h-78zm0 32v46h14V71h50v32h14V57h-78zm32 32v14h14V89h-14zm-64 32v46h30v-46h-30zm48 0v14h46v-14h-46zm64 0v46h30v-46h-30zm-64 32v14h46v-14h-46zm-80 32v46h62v-46h-62zm80 0v14h46v-14h-46zm64 0v46h62v-46h-62zm-64 32v14h46v-14h-46zm-112 32v46h94v-46h-94zm112 0v14h46v-14h-46zm64 0v46h94v-46h-94zm-64 32v14h46v-14h-46zM89 313v46h126v-46H89zm144 0v14h46v-14h-46zm64 0v46h126v-46H297zm-64 32v14h46v-14h-46zM57 377v46h158v-46H57zm176 0v14h46v-14h-46zm64 0v46h158v-46H297zm-64 32v14h46v-14h-46zM25 441v46h190v-46H25zm208 0v14h46v-14h-46zm64 0v46h190v-46H297zm-64 32v14h46v-14h-46z"},child:[]}]})(s)}function Fs(s){const[n,t]=S.useState(null);return S.useEffect(()=>{s&&(async()=>{const l=(await Promise.resolve().then(()=>require("./lucide-react-CDOQx4us.js")))[s];t(l)})()},[s]),n}function Ms(){const{authToken:s}=e.useSemaphorContext(),{data:n,isLoading:t,isFetching:r,isError:o}=e.useQuery({queryKey:["plugins",s==null?void 0:s.accessToken],queryFn:()=>e.getPlugins(s==null?void 0:s.accessToken)});return{data:n,isLoading:t,isFetching:r,isError:o}}function ft({onChartTypeChange:s}){const[n,t]=S.useState([]),{data:r}=Ms();return S.useEffect(()=>{(async()=>{var l;if(r){const c=(await Promise.all((l=r==null?void 0:r.plugins)==null?void 0:l.map(async a=>(await e.loadManifest(a.value)).visuals.map(g=>({name:g.name,icon:g.icon,url:a.value}))))).flat();t(c)}})()},[r]),n.length===0?null:e.jsxRuntimeExports.jsxs(e.jsxRuntimeExports.Fragment,{children:[e.jsxRuntimeExports.jsx(e.Separator,{className:"my-2"}),e.jsxRuntimeExports.jsx("div",{className:"grid grid-cols-4 place-items-center",children:n.map((o,l)=>e.jsxRuntimeExports.jsx(gt,{text:o.name,onClick:()=>s("custom",o),icon:o.icon},o.url+o.name+l))})]})}const gt=({text:s,icon:n,onClick:t})=>{const r=Fs(n||""),o=s.charAt(0).toUpperCase();return e.jsxRuntimeExports.jsx(e.Button,{onClick:t,title:s,variant:"ghost",children:r?e.jsxRuntimeExports.jsx(r,{className:"h-4 w-4"}):o})};function Rt(){var x,g;const[s,n]=S.useState(!1),t=e.useEditorStore(j=>j.card),r=t.type,{setCardType:o,setCardPreferences:l,setChartOrientation:i}=e.useEditorStore(j=>j.actions),{setCardCustomCfg:c,setCustomCardPreferences:a}=e.useEditorActions();function m(j,d){c(null),l({}),o(j),d&&a({type:"component",visualType:"single",url:d.url,componentName:d.name,icon:d.icon}),n(!1)}return e.jsxRuntimeExports.jsxs(e.Popover,{open:s,onOpenChange:n,children:[e.jsxRuntimeExports.jsx(e.PopoverTrigger,{asChild:!0,children:e.jsxRuntimeExports.jsx(e.Button,{size:"sm",variant:"outline",children:e.jsxRuntimeExports.jsx(bt,{className:"h-4 w-4",chartType:r,customIcon:(x=t.customCardPreferences)==null?void 0:x.icon,componentName:(g=t.customCardPreferences)==null?void 0:g.componentName})})}),e.jsxRuntimeExports.jsxs(e.PopoverContent,{className:"w-50",children:[e.jsxRuntimeExports.jsxs("div",{className:"grid grid-cols-4 place-items-center",children:[e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>m("bar"),className:"font-normal",variant:"ghost",children:e.jsxRuntimeExports.jsx(we,{className:"size-5"})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>m("line"),variant:"ghost",children:e.jsxRuntimeExports.jsx(ke,{className:"size-5"})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>m("stackedBar"),variant:"ghost",children:e.jsxRuntimeExports.jsx(As,{className:"size-5",strokeWidth:0})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>m("stackedLine"),variant:"ghost",children:e.jsxRuntimeExports.jsx(Ts,{className:"size-5",strokeWidth:0})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>m("scatter"),variant:"ghost",children:e.jsxRuntimeExports.jsx(Fe,{className:"size-5"})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>m("bubble"),variant:"ghost",children:e.jsxRuntimeExports.jsx(Ls,{className:"size-4"})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>m("pie"),variant:"ghost",children:e.jsxRuntimeExports.jsx(ze,{className:"size-5"})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>m("doughnut"),variant:"ghost",children:e.jsxRuntimeExports.jsx(Is,{className:"size-5",strokeWidth:1})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>m("radar"),variant:"ghost",children:e.jsxRuntimeExports.jsx(ks,{className:"size-5 font-extralight",strokeWidth:.5})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>m("polarArea"),variant:"ghost",children:e.jsxRuntimeExports.jsx(Ds,{className:"size-5"})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>m("pyramid"),variant:"ghost",children:e.jsxRuntimeExports.jsx(zs,{className:"size-5"})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>m("range"),variant:"ghost",children:e.jsxRuntimeExports.jsx(Oe,{className:"size-5"})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>m("table"),variant:"ghost",children:e.jsxRuntimeExports.jsx(e.Table,{className:"size-5"})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>m("kpi"),variant:"ghost",children:e.jsxRuntimeExports.jsx(Os,{className:"size-6"})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>m("text"),variant:"ghost",children:e.jsxRuntimeExports.jsx(Ie,{className:"size-4"})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>m("map"),variant:"ghost",children:e.jsxRuntimeExports.jsx(qe,{className:"size-4"})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>m("custom"),variant:"ghost",children:e.jsxRuntimeExports.jsx(Be,{className:"size-4"})})]}),e.jsxRuntimeExports.jsx(ft,{onChartTypeChange:m})]})]})}function bt({chartType:s,className:n,customIcon:t,componentName:r}){const o=Fs(t||"");switch(s){case"bar":return e.jsxRuntimeExports.jsx(we,{className:n});case"line":return e.jsxRuntimeExports.jsx(ke,{className:n});case"pie":return e.jsxRuntimeExports.jsx(ze,{className:n});case"radar":return e.jsxRuntimeExports.jsx(ks,{className:n});case"scatter":return e.jsxRuntimeExports.jsx(Fe,{className:n});case"bubble":return e.jsxRuntimeExports.jsx(Ls,{className:n});case"doughnut":return e.jsxRuntimeExports.jsx(Is,{className:n});case"stackedBar":return e.jsxRuntimeExports.jsx(As,{className:"size-4 text-foreground/70"});case"stackedLine":return e.jsxRuntimeExports.jsx(Ts,{className:"size-4 text-foreground/70"});case"polarArea":return e.jsxRuntimeExports.jsx(Ds,{className:n});case"pyramid":return e.jsxRuntimeExports.jsx(zs,{className:n});case"range":return e.jsxRuntimeExports.jsx(Oe,{className:n});case"kpi":return e.jsxRuntimeExports.jsx(Os,{className:n});case"text":return e.jsxRuntimeExports.jsx(Ie,{className:n});case"map":return e.jsxRuntimeExports.jsx(qe,{className:n});case"custom":return t&&o?e.jsxRuntimeExports.jsx(o,{className:n}):r?r==null?void 0:r.charAt(0).toUpperCase():e.jsxRuntimeExports.jsx(Be,{className:n});default:return e.jsxRuntimeExports.jsx(e.Table,{className:n})}}function yt(){var o;const s=e.useEditorStore(l=>l.card),n=((o=s.customCardPreferences)==null?void 0:o.showCardHeader)??!0,{setCustomCardPreferences:t}=e.useEditorActions(),r=l=>{s.customCardPreferences&&t({...s.customCardPreferences,showCardHeader:l===!0})};return e.jsxRuntimeExports.jsxs(e.DropdownMenu,{children:[e.jsxRuntimeExports.jsx(e.DropdownMenuTrigger,{asChild:!0,children:e.jsxRuntimeExports.jsx(Me,{className:"size-4 cursor-pointer text-muted-foreground/70 transition-colors hover:text-muted-foreground"})}),e.jsxRuntimeExports.jsxs(e.DropdownMenuContent,{align:"start",className:"w-40 text-muted-foreground",children:[e.jsxRuntimeExports.jsx(e.DropdownMenuCheckboxItem,{checked:n,onCheckedChange:r,children:"Card Header"}),e.jsxRuntimeExports.jsxs(e.DropdownMenuItem,{onClick:()=>{navigator.clipboard.writeText(s.id),e.ce.success("Card ID copied to clipboard")},className:"cursor-pointer space-x-2",children:[e.jsxRuntimeExports.jsx(Ve,{className:"size-4"}),e.jsxRuntimeExports.jsx("span",{children:"Copy Card ID"})]})]})]})}function Ke(){const s=e.useEditorStore(u=>u.frame),n=e.useEditorStore(u=>u.card),t=e.useEditorStore(u=>u.isShowingVisual),r=e.useEditorStore(u=>u.isSqlRunning),o=e.useEditorStore(u=>u.queryError),l=e.useEditorStore(u=>u.pythonStdOut),i=e.useEditorStore(u=>u.actions.setRunSql);e.useEditorStore(u=>u.onSave),e.useEditorStore(u=>u.onClose),e.useEditorStore(u=>u.actions.setCardSql),e.useEditorStore(u=>u.actions.setCardType),e.useEditorStore(u=>u.actions.setSqlGen);const{setFrame:c,setCard:a,updateCardInFrame:m}=e.useEditorActions(),{data:x,isLoading:g,isFetching:j}=e.useDashboardCardQuery(n);if(!n)return e.jsxRuntimeExports.jsx(e.jsxRuntimeExports.Fragment,{children:"No Active Card"});function d(){const u={connectionId:n.connectionId,id:e.v4(),title:"Title",description:"Description",preferences:{onClickFilter:[{columnIndex:0,expression:""}]},type:"bar",sql:"",data:[]};h(u)}function h(u){const R={...s,cards:[...s.cards,u],activeCardId:u.id};c(R),a(u)}function E(){const u={...n,id:e.v4(),title:`${n.title} Copy`,tabTitle:`${n.tabTitle} Copy`};h(u)}function I(u){const R=s.cards.filter(A=>A.id!==u),p=R[0],w={...s,cards:R,activeCardId:p.id};c(w),a(p)}function b(u){const R={...s,cards:s.cards.map(w=>w.id===n.id?n:w),activeCardId:u};c(R);const p=R.cards.find(w=>w.id===u);p.sql&&i(!0),a(p)}const L=(u,R)=>{console.log("handleDragStart",R),u.dataTransfer.setData("tabIndex",R.toString())},k=u=>{u.preventDefault()},z=(u,R)=>{const p=u.dataTransfer.getData("tabIndex");if(p===R.toString())return;const w=Array.from(s.cards),[A]=w.splice(parseInt(p),1);w.splice(R,0,A),c({...s,cards:w})};function y(u,R){return u.cards.length===1&&(R.displayTab===!0||R.displayTab===void 0)||u.activeCardId!==R.id&&(R.displayTab===!0||R.displayTab===void 0)?null:e.jsxRuntimeExports.jsx("div",{onClick:()=>{const p=R.displayTab===void 0?!1:!R.displayTab;a({...R,displayTab:p}),m({...R,displayTab:p})},children:R.displayTab===!0||R.displayTab===void 0?e.jsxRuntimeExports.jsx(ns,{className:"mr-2 size-3.5 text-muted-foreground hover:text-foreground"}):e.jsxRuntimeExports.jsx(ts,{className:"mr-2 size-3.5 text-muted-foreground hover:text-foreground"})})}function C(){return e.jsxRuntimeExports.jsxs(e.Tabs,{onValueChange:b,value:s.activeCardId,className:"flex grow flex-col",children:[s.cards.map(u=>e.jsxRuntimeExports.jsx(e.TabsContent,{className:"mt-0 grow",value:u.id,children:T()},u.id)),e.jsxRuntimeExports.jsx(e.TabsList,{className:"group mx-6 justify-between",children:e.jsxRuntimeExports.jsxs("div",{className:"flex items-center",children:[s.cards.map((u,R)=>e.jsxRuntimeExports.jsx(e.Editable,{text:u.tabTitle||u.title,onSave:p=>{a({...n,tabTitle:p}),m({...n,tabTitle:p})},children:e.jsxRuntimeExports.jsxs(e.TabsTrigger,{draggable:!0,onDragStart:p=>L(p,R),onDragOver:k,onDrop:p=>z(p,R),className:"",value:u.id,children:[y(s,u),u.tabTitle||u.title,s.activeCardId===u.id&&s.cards.length>1&&e.jsxRuntimeExports.jsx(e.X,{className:"ml-2 size-3.5 text-muted-foreground hover:text-foreground",onClick:()=>I(u.id)})]})},u.id)),e.jsxRuntimeExports.jsx(e.Button,{className:"ml-1 h-8 px-2 hover:bg-muted-foreground/50",variant:"outline",onClick:d,children:e.jsxRuntimeExports.jsx(e.Plus,{className:"h-4 w-4"})}),e.jsxRuntimeExports.jsx(e.Button,{className:"invisible ml-1 h-8 px-2 hover:bg-muted-foreground/50 group-hover:visible",variant:"outline",onClick:E,children:e.jsxRuntimeExports.jsx(Ze,{className:"h-4 w-4"})})]})})]})}function T(){return n.type==="kpi"?e.jsxRuntimeExports.jsx("div",{className:"flex h-full items-center justify-center",children:e.jsxRuntimeExports.jsx("div",{className:"w-1/2 rounded-md border",children:e.jsxRuntimeExports.jsx(e.KPICard,{card:n,data:x==null?void 0:x.records})})}):n.type==="text"?e.jsxRuntimeExports.jsx("div",{className:"flex h-full items-center justify-center",children:e.jsxRuntimeExports.jsx("div",{className:"w-1/2 rounded-md border",children:e.jsxRuntimeExports.jsx(e.ScrollArea,{className:"mx-3 my-6 h-[300px] overflow-y-auto break-words px-3",children:e.jsxRuntimeExports.jsx(e.TextCard,{isLoading:r,card:n,data:x==null?void 0:x.records})})})}):e.jsxRuntimeExports.jsx(e.ErrorBoundary,{FallbackComponent:e.FallbackEditorCard,children:e.jsxRuntimeExports.jsx(ws,{className:"grow border-none shadow-none"})})}return e.jsxRuntimeExports.jsxs("div",{className:"relative flex h-full flex-col py-3",children:[(g||j)&&e.jsxRuntimeExports.jsx(de,{className:"absolute bottom-0 left-0 right-0 top-0 z-50 m-auto h-10 w-10 animate-spin text-foreground/10"}),e.jsxRuntimeExports.jsxs("div",{className:"mb-0 flex min-h-10 items-center justify-end gap-2 px-6",children:[t&&e.jsxRuntimeExports.jsxs("div",{className:"flex grow items-center gap-2",children:[e.jsxRuntimeExports.jsx(Rt,{}),!["table","custom"].includes(n.type)&&e.jsxRuntimeExports.jsx(Et,{}),e.jsxRuntimeExports.jsx(yt,{})]}),e.jsxRuntimeExports.jsx(St,{})]}),t?C():e.jsxRuntimeExports.jsxs("div",{className:"flex min-h-0 w-full flex-1 grow basis-0 px-6",children:[l&&e.jsxRuntimeExports.jsx(vt,{}),(x==null?void 0:x.records)&&(x==null?void 0:x.records.length)>0&&e.jsxRuntimeExports.jsx(jt,{data:(x==null?void 0:x.records)||[]}),o&&e.jsxRuntimeExports.jsx("span",{className:"font-mono text-sm",children:o})]})]})}function vt(){const s=e.useEditorStore(t=>t.pythonStdOut);if(!s)return null;const n=s.replace(/\n/g,"<br>");return e.jsxRuntimeExports.jsxs(e.jsxRuntimeExports.Fragment,{children:[e.jsxRuntimeExports.jsx("p",{className:"font-mono text-sm",children:"Output:"}),e.jsxRuntimeExports.jsx("div",{dangerouslySetInnerHTML:{__html:n},className:"bg-muted p-2 font-mono text-sm"}),e.jsxRuntimeExports.jsx(e.Separator,{className:"mb-2"})]})}function St(){const s=e.useEditorStore(t=>t.isShowingVisual),n=e.useEditorStore(t=>t.actions.setIsShowingVisual);return e.jsxRuntimeExports.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsxRuntimeExports.jsx(e.Label,{htmlFor:"visualize",children:"Chart"}),e.jsxRuntimeExports.jsx(e.Switch,{checked:s,onCheckedChange:()=>n(!s),id:"visualize",className:"data-[state=checked]:bg-foreground/50"})]})}function Ct({options:s,value:n,onValueChange:t}){return e.jsxRuntimeExports.jsx(e.RadioGroup,{value:n,onValueChange:t,className:"flex gap-4",defaultValue:s[0].value,children:s.map(r=>e.jsxRuntimeExports.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsxRuntimeExports.jsx(e.RadioGroupItem,{value:r.value,id:r.value}),e.jsxRuntimeExports.jsx("label",{className:"text-sm",htmlFor:r.value,children:r.label})]},r.value))})}function Z({label:s,options:n,value:t,onValueChange:r,className:o}){return e.jsxRuntimeExports.jsxs(e.Select,{value:t,onValueChange:r,children:[e.jsxRuntimeExports.jsx(e.SelectTrigger,{className:e.cn("w-full focus:ring-0 focus:ring-offset-0",o),children:e.jsxRuntimeExports.jsx(e.SelectValue,{placeholder:s})}),e.jsxRuntimeExports.jsx(e.SelectContent,{children:e.jsxRuntimeExports.jsxs(e.SelectGroup,{children:[e.jsxRuntimeExports.jsx(e.SelectLabel,{children:s}),n.map(l=>e.jsxRuntimeExports.jsx(e.SelectItem,{value:l.value,children:l.label},l.value))]})})]})}function fe({children:s,summary:n,open:t,className:r}){return e.jsxRuntimeExports.jsxs("details",{open:t,className:e.cn("space-y-4 [&_summary>svg]:open:-rotate-180",r),children:[e.jsxRuntimeExports.jsxs("summary",{className:"flex cursor-pointer list-none items-center justify-between gap-4",children:[e.jsxRuntimeExports.jsx(e.Label,{children:n}),e.jsxRuntimeExports.jsx(e.ChevronUp,{className:"h-4 w-4"})]}),e.jsxRuntimeExports.jsx("div",{className:"transition-all ease-in-out",children:s})]})}function Nt(){var E,I;const s=e.useEditorStore(b=>b.card.customCardPreferences),{data:n}=Ms(),t=(n==null?void 0:n.plugins)||[],r=e.useEditorStore(b=>b.card),o=e.useEditorStore(b=>b.frame),l=(s==null?void 0:s.visualType)||"single",{setCustomCardPreferences:i}=e.useEditorActions(),{components:c,manifest:a}=e.useCustomVisual((s==null?void 0:s.url)||""),m=(E=a==null?void 0:a.visuals)==null?void 0:E.find(b=>b.name===(s==null?void 0:s.componentName));function x(b,L){if(!s)return;const z={...(s==null?void 0:s.dataInputCardIds)||{},[b]:{cardId:L,hookRef:null}};i({...s,dataInputCardIds:z})}function g(b){var k,z;const L=(k=o==null?void 0:o.cards)==null?void 0:k.filter(y=>{var C;return((C=y==null?void 0:y.customCardPreferences)==null?void 0:C.visualType)!=="multiple"}).map(y=>({value:y.id,label:y.tabTitle||y.title}));return e.jsxRuntimeExports.jsx("div",{className:"space-y-2",children:(z=b==null?void 0:b.dataInputs)==null?void 0:z.map((y,C)=>{var T,u;return e.jsxRuntimeExports.jsxs("div",{className:"grid grid-cols-10 gap-2",children:[e.jsxRuntimeExports.jsx("div",{className:"col-span-4 flex items-center",children:y}),e.jsxRuntimeExports.jsx(Z,{className:"col-span-6 h-8 w-full justify-between",label:"",options:L||[],value:((u=(T=s==null?void 0:s.dataInputCardIds)==null?void 0:T[C])==null?void 0:u.cardId)||"",onValueChange:R=>x(C,R)})]},C+Math.random())})})}function j(b,L,k=[]){var z,y;return s?b==="input"?e.jsxRuntimeExports.jsx(e.Input,{className:`h-8 w-full ${e.removeRing}`,value:((z=s==null?void 0:s.settings)==null?void 0:z[L])||"",onChange:C=>{i({...s,settings:{...s==null?void 0:s.settings,[L]:C.target.value}})}},L):b==="select"?e.jsxRuntimeExports.jsx(Z,{className:"h-8 w-full",label:"",options:k,value:((y=s==null?void 0:s.settings)==null?void 0:y[L])||"",onValueChange:C=>{i({...s,settings:{...s==null?void 0:s.settings,[L]:C}})}}):null:null}function d(b){const L=Object.entries((b==null?void 0:b.settings)||{});return e.jsxRuntimeExports.jsx("div",{className:"space-y-3",children:L.map(([k,z])=>e.jsxRuntimeExports.jsxs("div",{className:"space-y-2",children:[e.jsxRuntimeExports.jsx(e.Label,{children:z.title}),j(z.ui,k,z.options)]},k))})}function h(b){s&&i({...s,visualType:b,componentName:""})}return e.jsxRuntimeExports.jsxs("div",{className:"p-6",children:[e.jsxRuntimeExports.jsx(fe,{summary:"Plugin Settings",children:e.jsxRuntimeExports.jsx("div",{className:"space-y-4 text-sm",children:e.jsxRuntimeExports.jsxs("div",{className:"space-y-4 text-sm",children:[e.jsxRuntimeExports.jsx("div",{className:"space-y-2",children:e.jsxRuntimeExports.jsx("div",{className:"px-2",children:e.jsxRuntimeExports.jsx(Z,{className:"h-8 w-full",label:"",options:t,value:(s==null?void 0:s.url)||"",onValueChange:b=>i({...s||{url:"",componentName:""},url:b})})})}),((s==null?void 0:s.type)==="component"||(s==null?void 0:s.type)===void 0)&&e.jsxRuntimeExports.jsx(Ct,{options:[{value:"single",label:"Single Visual"},{value:"multiple",label:"Multi-Visual"}],value:l,onValueChange:h}),((s==null?void 0:s.type)==="component"||(s==null?void 0:s.type)===void 0)&&s&&e.jsxRuntimeExports.jsx(e.jsxRuntimeExports.Fragment,{children:e.jsxRuntimeExports.jsxs("div",{className:"space-y-2",children:[e.jsxRuntimeExports.jsx(e.Label,{children:"Component"}),e.jsxRuntimeExports.jsx("div",{className:"space-y-2 px-2",children:c&&e.jsxRuntimeExports.jsx(Z,{className:"h-8 w-full",label:"",options:(c==null?void 0:c.filter(b=>b.type===l).map(b=>({value:b.name,label:b.name})))||[],value:s.componentName,onValueChange:b=>{console.log("changing value",b),i({...s,componentName:b})}})})]})})]})})}),e.jsxRuntimeExports.jsx(e.Separator,{className:"my-4"}),((I=r==null?void 0:r.customCardPreferences)==null?void 0:I.componentName)&&e.jsxRuntimeExports.jsxs(fe,{summary:"Component Settings",children:[m&&m.dataInputs&&e.jsxRuntimeExports.jsxs("div",{className:"space-y-3",children:[e.jsxRuntimeExports.jsx(e.Label,{children:"Input Mapping"}),e.jsxRuntimeExports.jsx("div",{className:"px-2",children:g(m)})]}),m&&m.settings&&e.jsxRuntimeExports.jsx("div",{className:"space-y-3",children:e.jsxRuntimeExports.jsx("div",{className:"px-2",children:d(m)})})]})]})}function ae(){const[s,n]=S.useState([]);e.useEditorStore(x=>x.card.cfg);const t=e.useEditorStore(x=>x.card.preferences),{setCardCfg:r,setFilterOnClickColumnIndex:o,setCardPreferences:l}=e.useEditorStore(x=>x.actions),i=e.useEditorStore(x=>x.queryResultColumns);e.useEditorStore(x=>{var g;return(g=x.card.preferences)==null?void 0:g.filterOnClickColumnIndex}),S.useEffect(()=>{i&&n(new Array(i.length).fill(!1))},[i]);function c(x,g){var j,d;g?t!=null&&t.onClickFilter&&((j=t==null?void 0:t.onClickFilter)==null?void 0:j.length)>0?l({...t,onClickFilter:[...t.onClickFilter,{columnIndex:x,expression:""}]}):l({...t,onClickFilter:[{columnIndex:x,expression:""}]}):(l({...t,onClickFilter:(d=t==null?void 0:t.onClickFilter)==null?void 0:d.filter(h=>h.columnIndex!==x)}),n(h=>{const E=[...h];return E[x]=!1,E}))}function a(x,g){var d;const j=(d=t==null?void 0:t.onClickFilter)==null?void 0:d.map(h=>h.columnIndex===x?{...h,expression:g.target.value}:h);l({...t,onClickFilter:j})}function m(x){var g,j,d,h;if(s!=null&&s[x]||(j=(g=t==null?void 0:t.onClickFilter)==null?void 0:g.find(E=>E.columnIndex===x))!=null&&j.expression)return e.jsxRuntimeExports.jsx(e.Input,{value:(h=(d=t==null?void 0:t.onClickFilter)==null?void 0:d.find(E=>E.columnIndex===x))==null?void 0:h.expression,onChange:E=>a(x,E),type:"text",className:"h-9 w-full font-mono text-xs focus-visible:ring-0 focus-visible:ring-ring focus-visible:ring-offset-0",placeholder:"Expression"})}return e.jsxRuntimeExports.jsxs("div",{className:"space-y-2",children:[e.jsxRuntimeExports.jsx(e.Label,{children:"On Click"}),i==null?void 0:i.map((x,g)=>{var j,d;return e.jsxRuntimeExports.jsx("div",{className:"xbg-red-100 group flex items-center justify-between space-y-2",children:e.jsxRuntimeExports.jsxs("div",{className:"grow",children:[e.jsxRuntimeExports.jsxs("div",{className:"flex items-center space-x-2 py-2",children:[e.jsxRuntimeExports.jsx(e.Checkbox,{checked:!!((j=t==null?void 0:t.onClickFilter)!=null&&j.find(h=>h.columnIndex===g)),onCheckedChange:h=>c(g,h)}),e.jsxRuntimeExports.jsx("label",{className:"text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70",children:x}),e.jsxRuntimeExports.jsx("div",{className:"flex items-center gap-2",children:((d=t==null?void 0:t.onClickFilter)==null?void 0:d.find(h=>h.columnIndex===g))&&e.jsxRuntimeExports.jsx(_e,{onClick:()=>{n(h=>{const E=[...h];return E[g]=!h[g],E})},className:"invisible size-3 cursor-pointer text-gray-400 group-hover:visible"})})]}),m(g)]})},x)})]})}function De(){var i,c,a;const s=e.useEditorStore(m=>m.card.preferences),n=e.useEditorStore(m=>m.card.cfg),{setCardCfg:t,setCardPreferences:r,setChartOrientation:o}=e.useEditorStore(m=>m.actions);(i=n==null?void 0:n.options)!=null&&i.indexAxis;function l(m){o(m)}return e.jsxRuntimeExports.jsxs(e.RadioGroup,{value:((c=s==null?void 0:s.chartOptions)==null?void 0:c.indexAxis)||((a=n==null?void 0:n.options)==null?void 0:a.indexAxis)||"x",onValueChange:l,className:"flex gap-3",defaultValue:"x",children:[e.jsxRuntimeExports.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsxRuntimeExports.jsx(e.RadioGroupItem,{value:"x",id:"r1"}),e.jsxRuntimeExports.jsx("label",{className:"text-sm",htmlFor:"r1",children:"Vertical"})]}),e.jsxRuntimeExports.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsxRuntimeExports.jsx(e.RadioGroupItem,{value:"y",id:"r2"}),e.jsxRuntimeExports.jsx("label",{className:"text-sm",htmlFor:"r2",children:"Horizontal"})]})]})}const ve="focus-visible:ring-0 focus-visible:ring-ring focus-visible:ring-offset-0";function Je(s,n){var r,o,l;const t=e.getNumberAxis(s,n);return((l=(o=(r=s==null?void 0:s.chartOptions)==null?void 0:r.scales)==null?void 0:o[t])==null?void 0:l.type)||"linear"}function Vs(){var K,_,U,N,F,P;const[s,n]=S.useState(!1),t=e.useEditorStore(O=>{var D;return(D=O.card)==null?void 0:D.preferences}),r=e.useEditorStore(O=>{var D;return(D=O.card)==null?void 0:D.cfg}),o=e.getNumberAxis(t,r),[l,i]=S.useState(Je(t)),[c,a]=S.useState(((U=(_=(K=t==null?void 0:t.chartOptions)==null?void 0:K.scales)==null?void 0:_[o])==null?void 0:U.min)||""),[m,x]=S.useState(((P=(F=(N=t==null?void 0:t.chartOptions)==null?void 0:N.scales)==null?void 0:F[o])==null?void 0:P.max)||""),[g,j]=S.useState(c||m?"custom":"auto"),[d,h]=S.useState(""),[E,I]=S.useState(0),[b,L]=S.useState(""),[k,z]=S.useState(""),[y,C]=S.useState(""),T=e.useEditorStore(O=>O.actions.setCardPreferences),{updateCardInFrame:u}=e.useEditorActions(),R=e.useEditorStore(O=>O.card),p=e.useEditorStore(O=>{var D;return(D=O.card)==null?void 0:D.type}),w=["pie","doughnut","polarArea"].includes(p);S.useEffect(()=>{var O,D,G,V,H,J,se,le,te,re,ne,$,Y,X;i(Je(t)),a(((G=(D=(O=t==null?void 0:t.chartOptions)==null?void 0:O.scales)==null?void 0:D[o])==null?void 0:G.min)===0?0:""),x(((J=(H=(V=t==null?void 0:t.chartOptions)==null?void 0:V.scales)==null?void 0:H[o])==null?void 0:J.max)||""),h(((re=(te=(le=(se=t==null?void 0:t.chartOptions)==null?void 0:se.scales)==null?void 0:le[o])==null?void 0:te.ticks)==null?void 0:re.stepSize)||""),I(((ne=t==null?void 0:t.numberAxisFormat)==null?void 0:ne.decimalPlaces)||0),L((($=t==null?void 0:t.numberAxisFormat)==null?void 0:$.suffix)||""),z(((Y=t==null?void 0:t.numberAxisFormat)==null?void 0:Y.currency)||""),C(((X=t==null?void 0:t.numberAxisFormat)==null?void 0:X.locale)||"")},[s,t,o]);function A(O,D){return D===""||/^[0-9\b]+$/.test(D)?Number(D):Number(O)}function M(){const O=[...new Set(e.LOCALE_CURRENCY_PAIRS.map(D=>D.currency))];return e.jsxRuntimeExports.jsxs(e.jsxRuntimeExports.Fragment,{children:[e.jsxRuntimeExports.jsxs("div",{className:"grid grid-cols-6 items-center gap-2",children:[e.jsxRuntimeExports.jsx(e.Label,{className:"col-span-2 hover:cursor-pointer hover:underline",htmlFor:"currency",children:e.jsxRuntimeExports.jsx("a",{target:"_blank",href:"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat",children:"Currency"})}),e.jsxRuntimeExports.jsxs(e.Select,{value:k||"none",onValueChange:D=>z(D==="none"?"":D),children:[e.jsxRuntimeExports.jsx(e.SelectTrigger,{className:"col-span-2 h-8 w-full focus:ring-1 focus:ring-offset-0",children:e.jsxRuntimeExports.jsx(e.SelectValue,{})}),e.jsxRuntimeExports.jsx(e.SelectContent,{children:e.jsxRuntimeExports.jsxs(e.SelectGroup,{children:[e.jsxRuntimeExports.jsx(e.SelectLabel,{children:"Currency"}),e.jsxRuntimeExports.jsx(e.SelectItem,{value:"none",children:"None"}),O.map(D=>e.jsxRuntimeExports.jsx(e.SelectItem,{value:D,children:D},D))]})})]}),e.jsxRuntimeExports.jsxs(e.Select,{value:y,onValueChange:D=>C(D),children:[e.jsxRuntimeExports.jsx(e.SelectTrigger,{className:"col-span-2 h-8 w-full focus:ring-1 focus:ring-offset-0",children:e.jsxRuntimeExports.jsx(e.SelectValue,{})}),e.jsxRuntimeExports.jsx(e.SelectContent,{children:e.jsxRuntimeExports.jsxs(e.SelectGroup,{children:[e.jsxRuntimeExports.jsx(e.SelectLabel,{children:"Locale"}),e.LOCALE_CURRENCY_PAIRS.map(D=>e.jsxRuntimeExports.jsx(e.SelectItem,{value:D.locale,children:D.locale},D.locale))]})})]})]}),e.jsxRuntimeExports.jsxs("div",{className:"grid grid-cols-9 items-center gap-2",children:[e.jsxRuntimeExports.jsx(e.Label,{className:"col-span-3",htmlFor:"format",children:"Decimals"}),e.jsxRuntimeExports.jsx(e.Input,{value:E,onChange:D=>I(Number(D.target.value)),id:"format",className:`col-span-6 h-8 w-full tracking-wide ${ve}`})]})]})}function q(){return e.jsxRuntimeExports.jsxs(e.jsxRuntimeExports.Fragment,{children:[e.jsxRuntimeExports.jsxs("div",{className:"grid grid-cols-3 items-center gap-2",children:[e.jsxRuntimeExports.jsx(e.Label,{htmlFor:"range",children:"Range"}),e.jsxRuntimeExports.jsx(e.Input,{id:"min",value:c,onChange:O=>a(D=>A(D,O.target.value)),className:`col-span-1 h-8 w-full ${ve}`}),e.jsxRuntimeExports.jsx(e.Input,{value:m,onChange:O=>x(D=>A(D,O.target.value)),id:"max",className:`col-span-1 h-8 w-full ${ve}`})]}),e.jsxRuntimeExports.jsxs("div",{className:"grid grid-cols-3 items-center gap-2",children:[e.jsxRuntimeExports.jsx(e.Label,{htmlFor:"step-size",children:"Step Size"}),e.jsxRuntimeExports.jsx(e.Input,{value:d,onChange:O=>h(D=>A(D,O.target.value)),id:"step-size",className:`col-span-1 h-8 w-full ${ve}`})]})]})}function B(){var V;let O={};g==="custom"&&(O={min:c,max:m,ticks:{stepSize:d}});const D={...t||{},chartOptions:{...t==null?void 0:t.chartOptions,scales:{...(V=t==null?void 0:t.chartOptions)==null?void 0:V.scales,[o]:{type:l,...l==="linear"?O:{}}}},numberAxisFormat:{decimalPlaces:E,suffix:b,currency:k,locale:y}};console.log(D),T(D);const G={...R,preferences:D};u(G)}return e.jsxRuntimeExports.jsxs(e.Popover,{onOpenChange:O=>n(O),children:[e.jsxRuntimeExports.jsx(e.PopoverTrigger,{asChild:!0,children:e.jsxRuntimeExports.jsx(e.SliderIcon,{className:"size-4 cursor-pointer text-muted-foreground hover:text-foreground"})}),e.jsxRuntimeExports.jsx(e.PopoverContent,{align:"center",className:"max-w-65",children:e.jsxRuntimeExports.jsxs("div",{className:"grid gap-4",children:[e.jsxRuntimeExports.jsxs("div",{className:"space-y-2",children:[e.jsxRuntimeExports.jsx("h4",{className:"font-medium leading-none",children:"Scale Options"}),e.jsxRuntimeExports.jsx("p",{className:"text-sm text-muted-foreground",children:"Set the scale for the number axis"})]}),e.jsxRuntimeExports.jsxs("div",{className:"grid gap-2",children:[e.jsxRuntimeExports.jsxs("div",{className:"grid grid-cols-3 items-center gap-2",children:[e.jsxRuntimeExports.jsx(e.Label,{htmlFor:"scale",children:"Type"}),e.jsxRuntimeExports.jsxs(e.Select,{disabled:w,value:l,onValueChange:O=>i(O),children:[e.jsxRuntimeExports.jsx(e.SelectTrigger,{className:"col-span-2 h-8 w-full focus:ring-1 focus:ring-offset-0",children:e.jsxRuntimeExports.jsx(e.SelectValue,{})}),e.jsxRuntimeExports.jsx(e.SelectContent,{id:"type",children:e.jsxRuntimeExports.jsxs(e.SelectGroup,{children:[e.jsxRuntimeExports.jsx(e.SelectLabel,{children:"Option"}),e.jsxRuntimeExports.jsx(e.SelectItem,{value:"linear",children:"Linear"}),e.jsxRuntimeExports.jsx(e.SelectItem,{value:"logarithmic",children:"Logarithmic"})]})})]})]}),l=="linear"&&e.jsxRuntimeExports.jsxs("div",{className:"grid grid-cols-3 items-center gap-2 py-1",children:[e.jsxRuntimeExports.jsx(e.Label,{htmlFor:"scale-option",children:"Setup"}),e.jsxRuntimeExports.jsxs(e.RadioGroup,{disabled:w,id:"scale-option",value:g,onValueChange:O=>j(O),className:"col-span-2 flex gap-3",defaultValue:"x",children:[e.jsxRuntimeExports.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsxRuntimeExports.jsx(e.RadioGroupItem,{value:"auto",id:"r1"}),e.jsxRuntimeExports.jsx("label",{className:"text-sm",htmlFor:"r1",children:"Auto"})]}),e.jsxRuntimeExports.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsxRuntimeExports.jsx(e.RadioGroupItem,{value:"custom",id:"r2"}),e.jsxRuntimeExports.jsx("label",{className:"text-sm",htmlFor:"r2",children:"Custom"})]})]})]}),g==="custom"&&l=="linear"&&q(),M(),e.jsxRuntimeExports.jsx(e.SelectSeparator,{}),e.jsxRuntimeExports.jsx("div",{className:"grid grid-cols-3",children:e.jsxRuntimeExports.jsx(e.Button,{onClick:B,variant:"secondary",className:"col-span-1 col-start-3 h-8 w-full",children:"Apply"})})]})]})})]})}function wt({idx:s}){var c;const n=e.useEditorStore(a=>{var m;return(m=a.card)==null?void 0:m.preferences}),t=e.useEditorStore(a=>{var m;return(m=a.card.preferences)==null?void 0:m.datasetOptions}),r=e.useEditorStore(a=>a.actions.setCardPreferences),o=(c=n==null?void 0:n.chartOptions)==null?void 0:c.indexAxis,l=t==null?void 0:t.find(a=>a.idx===s);function i(a,m){(a==="end"||a==="start")&&e.getContrastColor(e.getCanvasBackgroundColor());const x={display:a!=="none",align:a,anchor:a,clamp:!0};if(!l)r({...n,datasetOptions:[...t||[],{idx:m,datalabels:x}]});else{const g={...l};g.datalabels=x;const j=t==null?void 0:t.map(d=>d.idx===m?g:d);r({...n,datasetOptions:j})}}return e.jsxRuntimeExports.jsxs(e.Popover,{children:[e.jsxRuntimeExports.jsx(e.PopoverTrigger,{children:e.jsxRuntimeExports.jsx(gs,{className:"invisible size-4 rotate-[135deg] cursor-pointer text-muted-foreground hover:text-foreground group-hover:visible"})}),e.jsxRuntimeExports.jsx(e.PopoverContent,{className:"w-fit p-1",children:e.jsxRuntimeExports.jsxs("div",{className:"flex gap-1",children:[e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>i("none",s),size:"sm",variant:"secondary",className:"h-7 p-1 text-xs font-normal",children:e.jsxRuntimeExports.jsx(e.X,{className:"size-4"})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>i("start",s),size:"sm",variant:"secondary",className:"h-7 p-1 text-xs font-normal",children:e.jsxRuntimeExports.jsx(ls,{className:e.cn("h-4 w-4",{"rotate-90":o==="y"})})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>i("center",s),size:"sm",variant:"secondary",className:"h-7 p-1 text-xs font-normal",children:e.jsxRuntimeExports.jsx(xs,{className:e.cn("h-4 w-4",{"rotate-90":o==="y"})})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>i("end",s),size:"sm",variant:"secondary",className:"h-7 p-1 text-xs font-normal",children:e.jsxRuntimeExports.jsx(cs,{className:e.cn("h-4 w-4",{"rotate-90":o==="y"})})})]})})]})}function qs(){const s=e.useEditorStore(m=>m.card),n=e.useEditorStore(m=>{var x,g,j;return(j=(g=(x=m==null?void 0:m.card)==null?void 0:x.preferences)==null?void 0:g.chartOptions)==null?void 0:j.indexAxis}),{data:t}=e.useDashboardCardQuery(s),r=n==="y"?"Y axis":"X axis",o=n==="y"?"X axis":"Y axis",{keys:l,metricKeys:i,dimensionKeys:c}=e.getKeys((t==null?void 0:t.records)||[]);let a=i;if(["stackedBar","stackedLine"].includes(s.type)){const m=e.pivotData({dataArray:(t==null?void 0:t.records)||[],groupKey:c[0],pivotKey:c[1],valueKey:a[0]}),{metricKeys:x}=e.getKeys(m);a=x}return l.length===0?null:e.jsxRuntimeExports.jsxs("div",{className:"space-y-4",children:[e.jsxRuntimeExports.jsxs("div",{className:"space-y-2",children:[e.jsxRuntimeExports.jsx(e.Label,{children:r}),e.jsxRuntimeExports.jsx("div",{className:"my-1 space-y-1",children:e.jsxRuntimeExports.jsx("div",{className:"rounded-md bg-muted/70 px-2 py-1 hover:bg-muted",children:e.jsxRuntimeExports.jsx("p",{children:c[0]})})})]}),e.jsxRuntimeExports.jsxs("div",{className:"space-y-2",children:[e.jsxRuntimeExports.jsxs("div",{className:"flex items-center justify-between gap-5",children:[e.jsxRuntimeExports.jsx(e.Label,{children:o}),e.jsxRuntimeExports.jsx(Vs,{})]}),e.jsxRuntimeExports.jsx("div",{className:"my-1 space-y-1",children:a.map((m,x)=>e.jsxRuntimeExports.jsx(kt,{col:m,idx:x},m))})]})]})}function kt({col:s,idx:n}){const t=e.useEditorStore(c=>{var a;return(a=c.card)==null?void 0:a.preferences}),r=e.useEditorStore(c=>{var a;return(a=c.card.preferences)==null?void 0:a.datasetOptions}),o=r==null?void 0:r.find(c=>c.idx===n),{setCardPreferences:l}=e.useEditorStore(c=>c.actions);function i(c){if(!o)l({...t,datasetOptions:[...r||[],{idx:n,type:c==="area"?"line":c,fill:c==="area"?"origin":""}]});else{const a={...o};a.type=c==="area"?"line":c,a.fill=c==="area"?"origin":"";const m=r==null?void 0:r.map(x=>x.idx===n?a:x);l({...t,datasetOptions:m})}}return e.jsxRuntimeExports.jsxs("div",{className:"group flex items-center justify-between gap-5 rounded-md bg-muted/70 px-2 py-1 hover:bg-muted",children:[e.jsxRuntimeExports.jsx("p",{children:s}),e.jsxRuntimeExports.jsxs("div",{className:"flex gap-2",children:[e.jsxRuntimeExports.jsx(we,{onClick:()=>i("bar"),className:"invisible size-4 cursor-pointer text-muted-foreground hover:text-foreground group-hover:visible"}),e.jsxRuntimeExports.jsx(ke,{onClick:()=>i("line"),className:"invisible size-4 cursor-pointer text-muted-foreground hover:text-foreground group-hover:visible"}),e.jsxRuntimeExports.jsx(Ye,{onClick:()=>i("area"),className:"invisible size-4 cursor-pointer text-muted-foreground hover:text-foreground group-hover:visible"}),e.jsxRuntimeExports.jsx(e.Separator,{orientation:"vertical",className:"invisible size-4 cursor-pointer py-2 text-muted-foreground hover:text-foreground group-hover:visible"}),e.jsxRuntimeExports.jsx(wt,{idx:n})]})]})}function _s(){const s=e.useEditorStore(j=>j.selectedConnectionId),n=e.useEditorStore(j=>j.selectedDatamodelId),t=e.useEditorStore(j=>j.selectedDatabaseName),r=e.useEditorStore(j=>j.selectedSchemaName),o=e.useEditorStore(j=>j.selectedTableName),l=e.useDashboardStore(j=>j.dashboard.filters)||[],i=e.useDashboardStore(j=>j.actions.addFilter),c=e.useDashboardStore(j=>j.actions.removeFilter),a=e.useDashboardStore(j=>j.actions.removeFilterValue),{modelItems:m,tableName:x}=ie();function g(j,d="dashboard"){var C;const h=e.fmt(j.column_name),E=e.fmt(t||""),I=e.fmt(r||""),b=e.fmt(x);let L=e.getQualifiedTableName(I,b),k=`${L}.${h}`;const z=(C=m==null?void 0:m.find(T=>T.id===n))==null?void 0:C.name;n&&n!=="none"&&(k=`${e.DATAMODEL_NAMESPCACE}.${z}.${h}`,L=`${e.DATAMODEL_NAMESPCACE}.${z}`);const y=l==null?void 0:l.find(T=>T.column===k&&T.table===b&&(T.database===E||T.database===t));if(y)a(y.id),c(y.id);else{const T=e.v4();return x==="api"&&s?(i({location:d,id:T,column:k,title:j.column_name,dataType:j.data_type,table:"api",database:"",connectionId:s,operation:"in",sql:e.getDefaultFilterSql(j.data_type,L,h)}),T):(i({id:T,location:d,column:k,title:j.column_name,dataType:j.data_type,table:o||"",database:t||"",connectionId:s||"",operation:"in",sql:e.getDefaultFilterSql(j.data_type,L,h)}),T)}}return{assignFilter:g}}function me(){const s=e.useDashboardStore(c=>c.dashboard.filters),n=e.useEditorStore(c=>c.frame),{setFrame:t}=e.useEditorActions(),{columns:r}=ie(),{assignFilter:o}=_s();function l(c){const a=o(c,"frame");t({...n,filterId:a})}const i=s==null?void 0:s.find(c=>c.id===n.filterId);return e.jsxRuntimeExports.jsxs("div",{className:"space-y-3",children:[e.jsxRuntimeExports.jsx(e.Label,{children:"Card Filter"}),e.jsxRuntimeExports.jsx(It,{onSelect:l,columns:r}),i&&e.jsxRuntimeExports.jsx(e.FilterHeader,{filter:i})]})}function It({columns:s,onSelect:n}){var i;const[t,r]=$e.useState(!1),[o,l]=$e.useState("");return e.jsxRuntimeExports.jsxs(e.Popover,{open:t,onOpenChange:r,children:[e.jsxRuntimeExports.jsx(e.PopoverTrigger,{asChild:!0,children:e.jsxRuntimeExports.jsxs(e.Button,{size:"sm",variant:"outline",role:"combobox","aria-expanded":t,className:"w-full justify-between font-normal",children:[o?(i=s.find(c=>c.column_name===o))==null?void 0:i.column_name:"Select Column...",e.jsxRuntimeExports.jsx(e.CaretSortIcon,{className:"ml-2 h-4 w-4 shrink-0 opacity-50"})]})}),e.jsxRuntimeExports.jsx(e.PopoverContent,{className:"w-[200px] p-0",children:e.jsxRuntimeExports.jsxs(e.Command,{children:[e.jsxRuntimeExports.jsx(e.CommandInput,{placeholder:"Search column",className:"h-9"}),e.jsxRuntimeExports.jsxs(e.CommandList,{children:[e.jsxRuntimeExports.jsx(e.CommandEmpty,{children:"No framework found."}),e.jsxRuntimeExports.jsx(e.CommandGroup,{children:s.map(c=>e.jsxRuntimeExports.jsxs(e.CommandItem,{value:c.column_name,onSelect:a=>{const m=a===o?"":a;l(m),r(!1),m&&n(c)},children:[c.column_name,e.jsxRuntimeExports.jsx(e.CheckIcon,{className:e.cn("ml-auto h-4 w-4",o===c.column_name?"opacity-100":"opacity-0")})]},c.column_name))})]})]})})]})}function Dt({cardType:s}){return e.jsxRuntimeExports.jsx("div",{className:"space-y-6 px-6 py-2",children:e.jsxRuntimeExports.jsxs(e.Accordion,{defaultValue:["item-2"],type:"multiple",children:[e.jsxRuntimeExports.jsxs(e.AccordionItem,{value:"item-1",children:[e.jsxRuntimeExports.jsx(e.AccordionTrigger,{children:`${e.titleCase(s)} Chart`}),e.jsxRuntimeExports.jsxs(e.AccordionContent,{className:"space-y-4 font-mono text-xs",children:[e.jsxRuntimeExports.jsx("div",{className:"rounded bg-muted px-2 py-1 text-xs",children:"SELECT x-axis, y-axis-1, y-axis-2,... FROM table"}),e.jsxRuntimeExports.jsxs("ul",{className:"ml-6 list-disc text-xs [&>li]:mt-2",children:[e.jsxRuntimeExports.jsx("li",{children:"x-axis - category"}),e.jsxRuntimeExports.jsx("li",{children:"y-axis1 - number"}),e.jsxRuntimeExports.jsx("li",{children:"y-axis2 - number"})]}),e.jsxRuntimeExports.jsxs("div",{children:["See ",e.jsxRuntimeExports.jsx("a",{target:"_blank",onClick:n=>n.stopPropagation(),className:"text-blue-700",href:"https://docs.semaphor.cloud/concepts/visuals#line-chart",children:"example"})," in the docs."]})]})]}),e.jsxRuntimeExports.jsxs(e.AccordionItem,{value:"item-2",children:[e.jsxRuntimeExports.jsx(e.AccordionTrigger,{children:"Settings"}),e.jsxRuntimeExports.jsxs(e.AccordionContent,{className:"space-y-4 px-2",children:[e.jsxRuntimeExports.jsx(De,{}),e.jsxRuntimeExports.jsx(qs,{})]})]}),e.jsxRuntimeExports.jsxs(e.AccordionItem,{value:"item-3",children:[e.jsxRuntimeExports.jsx(e.AccordionTrigger,{children:"Filters"}),e.jsxRuntimeExports.jsxs(e.AccordionContent,{className:"space-y-4 px-2",children:[e.jsxRuntimeExports.jsx(ae,{}),e.jsxRuntimeExports.jsx(me,{})]})]})]})})}function Pe(){var o,l,i;const s=e.useEditorStore(c=>c.card.cfg),n=e.useEditorStore(c=>c.actions.setCardCfg),t=e.useEditorStore(c=>c.card.type);function r(c){var x;const a={datalabels:{display:c!=="none",align:c,anchor:c,clamp:!0}},m={...s,options:{...s==null?void 0:s.options,plugins:{...(x=s==null?void 0:s.options)==null?void 0:x.plugins,...a}}};n(m),console.log(c)}return e.jsxRuntimeExports.jsxs("div",{className:"space-y-2",children:[e.jsxRuntimeExports.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxRuntimeExports.jsx("label",{className:"font-medium",children:"Data Labels"}),!["pyramid"].includes(t)&&e.jsxRuntimeExports.jsx(Vs,{})]}),e.jsxRuntimeExports.jsxs(e.Select,{value:(i=(l=(o=s==null?void 0:s.options)==null?void 0:o.plugins)==null?void 0:l.datalabels)==null?void 0:i.anchor,onValueChange:r,defaultValue:"none",children:[e.jsxRuntimeExports.jsx(e.SelectTrigger,{className:"h-8 w-full focus:ring-1 focus:ring-offset-0",children:e.jsxRuntimeExports.jsx(e.SelectValue,{placeholder:"Select position"})}),e.jsxRuntimeExports.jsx(e.SelectContent,{children:e.jsxRuntimeExports.jsxs(e.SelectGroup,{children:[e.jsxRuntimeExports.jsx(e.SelectLabel,{children:"Data Labels"}),e.jsxRuntimeExports.jsx(e.SelectItem,{value:"none",children:"None"}),t!=="pyramid"&&e.jsxRuntimeExports.jsx(e.SelectItem,{value:"start",children:"Start"}),e.jsxRuntimeExports.jsx(e.SelectItem,{value:"center",children:"Center"}),t!=="pyramid"&&e.jsxRuntimeExports.jsx(e.SelectItem,{value:"end",children:"End"})]})})]})]})}function Lt({cardType:s}){function n(t){return e.jsxRuntimeExports.jsxs(e.jsxRuntimeExports.Fragment,{children:[e.jsxRuntimeExports.jsx("div",{className:"rounded bg-muted px-2 py-1 text-xs",children:t==="bubble"?"SELECT label, [group], x-axis, y-axis, radius FROM table":"SELECT label, [group], x-axis, y-axis FROM table"}),e.jsxRuntimeExports.jsxs("ul",{className:"ml-6 list-disc text-xs [&>li]:mt-2",children:[e.jsxRuntimeExports.jsx("li",{children:"label - category"}),e.jsxRuntimeExports.jsx("li",{children:"group - category"}),e.jsxRuntimeExports.jsx("li",{children:"x-axis - category"}),e.jsxRuntimeExports.jsx("li",{children:"y-axis - category"}),t==="bubble"&&e.jsxRuntimeExports.jsx("li",{children:"radius - number"})]}),e.jsxRuntimeExports.jsxs("div",{children:["See ",e.jsxRuntimeExports.jsx("a",{target:"_blank",onClick:l=>l.stopPropagation(),className:"text-blue-700",href:"https://docs.semaphor.cloud/concepts/visuals#pie-chart",children:"example"})," in the docs."]})]})}return e.jsxRuntimeExports.jsx("div",{className:"space-y-6 px-6 py-2",children:e.jsxRuntimeExports.jsxs(e.Accordion,{defaultValue:["item-2"],type:"multiple",children:[e.jsxRuntimeExports.jsxs(e.AccordionItem,{value:"item-1",children:[e.jsxRuntimeExports.jsx(e.AccordionTrigger,{children:`${e.titleCase(s)} Chart`}),e.jsxRuntimeExports.jsx(e.AccordionContent,{className:"space-y-4 font-mono text-xs",children:n(s)})]}),e.jsxRuntimeExports.jsxs(e.AccordionItem,{value:"item-2",children:[e.jsxRuntimeExports.jsx(e.AccordionTrigger,{children:"Settings"}),e.jsxRuntimeExports.jsx(e.AccordionContent,{className:"px-2",children:e.jsxRuntimeExports.jsx(Pe,{})})]}),e.jsxRuntimeExports.jsxs(e.AccordionItem,{value:"item-3",children:[e.jsxRuntimeExports.jsx(e.AccordionTrigger,{children:"Filters"}),e.jsxRuntimeExports.jsxs(e.AccordionContent,{className:"space-y-4 px-2",children:[e.jsxRuntimeExports.jsx(ae,{}),e.jsxRuntimeExports.jsx(me,{})]})]})]})})}const Tt={datasets:[{type:"line",label:"Sum_sales",data:[]},{type:"bar",label:"Sum_profit",data:[]}]},At={datasets:[{fill:"origin",type:"line",label:"Sum_sales",data:[]}]};function Ot(){const s=e.useEditorStore(n=>n.card.type);return e.jsxRuntimeExports.jsxs("div",{className:"space-y-6 p-6",children:[e.jsxRuntimeExports.jsx(e.Accordion,{className:" ",type:"single",collapsible:!0,children:zt(s)}),e.jsxRuntimeExports.jsx("section",{className:"",children:["line","bar"].includes(s)&&e.jsxRuntimeExports.jsx(De,{})}),!["kpi"].includes(s)&&e.jsxRuntimeExports.jsxs("div",{className:"space-y-4",children:[e.jsxRuntimeExports.jsx(Pe,{}),e.jsxRuntimeExports.jsx(ae,{}),e.jsxRuntimeExports.jsx(me,{})]})]})}function zt(s){if(["line","bar"].includes(s))return e.jsxRuntimeExports.jsxs(e.jsxRuntimeExports.Fragment,{children:[e.jsxRuntimeExports.jsxs(e.AccordionItem,{value:"item-1",children:[e.jsxRuntimeExports.jsx(e.AccordionTrigger,{className:"font-normal",children:e.jsxRuntimeExports.jsx("p",{children:"Chart Query"})}),e.jsxRuntimeExports.jsxs(e.AccordionContent,{className:" ",children:[e.jsxRuntimeExports.jsx("div",{className:"rounded bg-muted px-2 py-1 font-mono text-xs font-semibold",children:"SELECT x-axis, y-axis-1, y-axis-2, y-axis-3,... FROM table"}),e.jsxRuntimeExports.jsxs("ul",{className:"my-6 ml-6 list-disc text-xs font-normal [&>li]:mt-2",children:[e.jsxRuntimeExports.jsx("li",{children:"X-axis - Category (ex. city)"}),e.jsxRuntimeExports.jsx("li",{children:"Y-axis - Number (ex. population)"})]})]})]}),e.jsxRuntimeExports.jsxs(e.AccordionItem,{value:"item-2",children:[e.jsxRuntimeExports.jsx(e.AccordionTrigger,{className:"font-normal",children:"Mixed Chart"}),e.jsxRuntimeExports.jsxs(e.AccordionContent,{className:"space-y-2 text-xs",children:[e.jsxRuntimeExports.jsxs("p",{children:["Click ",e.jsxRuntimeExports.jsx("b",{children:"Customize"})," and change the `type` property in the dataset."]}),e.jsxRuntimeExports.jsx("pre",{children:JSON.stringify(Tt,null,2)})]})]}),e.jsxRuntimeExports.jsxs(e.AccordionItem,{value:"item-3",children:[e.jsxRuntimeExports.jsx(e.AccordionTrigger,{className:"font-normal",children:"Area Chart"}),e.jsxRuntimeExports.jsxs(e.AccordionContent,{className:"space-y-2 text-xs",children:[e.jsxRuntimeExports.jsxs("p",{children:["Click ",e.jsxRuntimeExports.jsx("b",{children:"Customize"})," and add `fill` property to the dataset. See",e.jsxRuntimeExports.jsx("a",{className:"mx-1 text-blue-500 hover:underline",href:"https://www.chartjs.org/docs/latest/samples/area/line-boundaries.html",target:"_blank",children:"docs"}),"for more options."]}),e.jsxRuntimeExports.jsx("pre",{children:JSON.stringify(At,null,2)})]})]})]});if(s==="bubble")return e.jsxRuntimeExports.jsx(e.jsxRuntimeExports.Fragment,{children:e.jsxRuntimeExports.jsxs(e.AccordionItem,{value:"item-1",children:[e.jsxRuntimeExports.jsx(e.AccordionTrigger,{className:"font-normal",children:e.jsxRuntimeExports.jsxs("p",{children:["How to create a ",e.jsxRuntimeExports.jsx("span",{children:s})," chart query?"]})}),e.jsxRuntimeExports.jsxs(e.AccordionContent,{className:" ",children:[e.jsxRuntimeExports.jsx("div",{className:"rounded bg-muted px-2 py-1 font-mono text-xs font-semibold",children:"SELECT label, x-axis, y-axis, radius FROM table"}),e.jsxRuntimeExports.jsxs("ul",{className:"my-6 ml-6 list-disc text-xs font-normal [&>li]:mt-2",children:[e.jsxRuntimeExports.jsx("li",{children:"Label - Category (ex. city)"}),e.jsxRuntimeExports.jsx("li",{children:"Bubble Group (opt) - Category (ex. state)"}),e.jsxRuntimeExports.jsx("li",{children:"X-axis - Number (ex. avg. age)"}),e.jsxRuntimeExports.jsx("li",{children:"Y-axis - Number (ex. avg. weight)"}),e.jsxRuntimeExports.jsx("li",{children:"Radius - Number (ex. population)"})]})]})]})});if(s==="scatter")return e.jsxRuntimeExports.jsx(e.jsxRuntimeExports.Fragment,{children:e.jsxRuntimeExports.jsxs(e.AccordionItem,{value:"item-1",children:[e.jsxRuntimeExports.jsx(e.AccordionTrigger,{className:"font-normal",children:e.jsxRuntimeExports.jsxs("p",{children:["How to create a ",e.jsxRuntimeExports.jsx("span",{children:s})," chart query?"]})}),e.jsxRuntimeExports.jsxs(e.AccordionContent,{className:" ",children:[e.jsxRuntimeExports.jsx("div",{className:"rounded bg-muted px-2 py-1 font-mono text-xs font-semibold",children:"SELECT label, x-axis, y-axis FROM table"}),e.jsxRuntimeExports.jsxs("ul",{className:"my-6 ml-6 list-disc text-xs font-normal [&>li]:mt-2",children:[e.jsxRuntimeExports.jsx("li",{children:"Label - Category (ex. city)"}),e.jsxRuntimeExports.jsx("li",{children:"Group (opt) - Category (ex. state)"}),e.jsxRuntimeExports.jsx("li",{children:"X-axis - Number (ex. avg. age)"}),e.jsxRuntimeExports.jsx("li",{children:"Y-axis - Number (ex. avg. weight)"})]})]})]})});if(["pie","doughnut","polarArea"].includes(s))return e.jsxRuntimeExports.jsx(e.jsxRuntimeExports.Fragment,{children:e.jsxRuntimeExports.jsxs(e.AccordionItem,{value:"item-1",children:[e.jsxRuntimeExports.jsx(e.AccordionTrigger,{className:"font-normal",children:e.jsxRuntimeExports.jsxs("p",{children:[e.jsxRuntimeExports.jsx("span",{children:s==="polarArea"?"Polar":s.charAt(0).toUpperCase()+s.slice(1)})," ","chart query"]})}),e.jsxRuntimeExports.jsxs(e.AccordionContent,{className:" ",children:[e.jsxRuntimeExports.jsx("div",{className:"rounded bg-muted px-2 py-1 font-mono text-xs font-semibold",children:"SELECT label, measure FROM table"}),e.jsxRuntimeExports.jsxs("ul",{className:"my-6 ml-6 list-disc text-xs font-normal [&>li]:mt-2",children:[e.jsxRuntimeExports.jsx("li",{children:"Label - Category (ex. city)"}),e.jsxRuntimeExports.jsx("li",{children:"Measure - Number (ex. population)"})]})]})]})})}function Ft(){var a,m,x,g,j;const s=e.useEditorStore(d=>d.card.preferences),n=e.useEditorStore(d=>d.actions.setCardPreferences),t=e.useEditorStore(d=>d.actions.setNumberFormat);e.useEditorStore(d=>{var h,E;return(E=(h=d.card.preferences)==null?void 0:h.formatNumber)==null?void 0:E.decimalPlaces});const r=e.useEditorStore(d=>{var h,E;return(E=(h=d.card.preferences)==null?void 0:h.formatNumber)==null?void 0:E.locale}),o=e.useEditorStore(d=>{var h,E;return(E=(h=d.card.preferences)==null?void 0:h.formatNumber)==null?void 0:E.currency});e.useEditorStore(d=>d.actions.setFilterOnClickField);const l=e.useEditorStore(d=>{var h,E;return(E=(h=d.card.preferences)==null?void 0:h.formatNumber)==null?void 0:E.colorRanges})||[],i=e.useEditorStore(d=>d.actions.setColorRanges),c=[...new Set(e.LOCALE_CURRENCY_PAIRS.map(d=>d.currency))];return e.jsxRuntimeExports.jsxs("div",{children:[e.jsxRuntimeExports.jsxs("div",{className:"mb-3 flex items-center gap-2",children:[e.jsxRuntimeExports.jsx(e.Checkbox,{checked:!!((a=s==null?void 0:s.formatNumber)!=null&&a.enabled),onCheckedChange:d=>{n({...s,formatNumber:{...s==null?void 0:s.formatNumber,enabled:d}})}}),e.jsxRuntimeExports.jsx(e.Label,{children:"Format Number"})]}),((m=s==null?void 0:s.formatNumber)==null?void 0:m.enabled)===!0&&e.jsxRuntimeExports.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsxRuntimeExports.jsx("div",{children:e.jsxRuntimeExports.jsxs("div",{className:"space-y-4 p-2",children:[e.jsxRuntimeExports.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxRuntimeExports.jsxs("div",{className:"w-full space-y-1",children:[e.jsxRuntimeExports.jsx(e.Label,{children:"Locale"}),e.jsxRuntimeExports.jsxs(e.Select,{value:r||"none",onValueChange:d=>{var h,E,I;return t(((h=s==null?void 0:s.formatNumber)==null?void 0:h.decimalPlaces)||0,((E=s==null?void 0:s.formatNumber)==null?void 0:E.currency)||"",d,((I=s==null?void 0:s.formatNumber)==null?void 0:I.suffix)||"")},children:[e.jsxRuntimeExports.jsx(e.SelectTrigger,{className:"col-span-6 h-8 w-full focus:ring-1 focus:ring-offset-0",children:e.jsxRuntimeExports.jsx(e.SelectValue,{})}),e.jsxRuntimeExports.jsx(e.SelectContent,{children:e.jsxRuntimeExports.jsxs(e.SelectGroup,{children:[e.jsxRuntimeExports.jsx(e.SelectLabel,{children:"Format"}),e.jsxRuntimeExports.jsx(e.SelectItem,{value:"none",children:"None"},"none"),e.LOCALE_CURRENCY_PAIRS.map(d=>e.jsxRuntimeExports.jsx(e.SelectItem,{value:d.locale,children:d.locale},d.locale))]})})]})]}),e.jsxRuntimeExports.jsxs("div",{className:"w-full space-y-1",children:[e.jsxRuntimeExports.jsx(e.Label,{children:"Currency"}),e.jsxRuntimeExports.jsxs(e.Select,{value:o||"none",onValueChange:d=>{var h,E,I;console.log("currency",d),t(((h=s==null?void 0:s.formatNumber)==null?void 0:h.decimalPlaces)||0,d==="none"?"":d,((E=s==null?void 0:s.formatNumber)==null?void 0:E.locale)||"",((I=s==null?void 0:s.formatNumber)==null?void 0:I.suffix)||"")},children:[e.jsxRuntimeExports.jsx(e.SelectTrigger,{className:"col-span-6 h-8 w-full focus:ring-1 focus:ring-offset-0",children:e.jsxRuntimeExports.jsx(e.SelectValue,{})}),e.jsxRuntimeExports.jsx(e.SelectContent,{children:e.jsxRuntimeExports.jsxs(e.SelectGroup,{children:[e.jsxRuntimeExports.jsx(e.SelectLabel,{children:"Currency"}),e.jsxRuntimeExports.jsx(e.SelectItem,{value:"none",children:"None"},"none"),c.map(d=>e.jsxRuntimeExports.jsx(e.SelectItem,{value:d,children:d},d))]})})]})]})]}),e.jsxRuntimeExports.jsxs("div",{className:"flex gap-2",children:[e.jsxRuntimeExports.jsxs("div",{className:"w-full space-y-1",children:[e.jsxRuntimeExports.jsx(e.Label,{children:"Decimals"}),e.jsxRuntimeExports.jsxs(e.Select,{value:((g=(x=s==null?void 0:s.formatNumber)==null?void 0:x.decimalPlaces)==null?void 0:g.toString())||"0",onValueChange:d=>{var h,E,I;return t(Number(d),((h=s==null?void 0:s.formatNumber)==null?void 0:h.currency)||"",((E=s==null?void 0:s.formatNumber)==null?void 0:E.locale)||"",((I=s==null?void 0:s.formatNumber)==null?void 0:I.suffix)||"")},children:[e.jsxRuntimeExports.jsx(e.SelectTrigger,{className:"col-span-3 h-8 w-full focus:ring-1 focus:ring-offset-0",children:e.jsxRuntimeExports.jsx(e.SelectValue,{})}),e.jsxRuntimeExports.jsx(e.SelectContent,{children:["0","1","2","3","4"].map(d=>e.jsxRuntimeExports.jsx(e.SelectItem,{value:d,children:d},d))})]})]}),e.jsxRuntimeExports.jsxs("div",{className:"w-full space-y-1",children:[e.jsxRuntimeExports.jsx(e.Label,{children:"Suffix"}),e.jsxRuntimeExports.jsx(e.Input,{value:((j=s==null?void 0:s.formatNumber)==null?void 0:j.suffix)||"",className:"h-8 font-mono text-xs focus-visible:ring-0 focus-visible:ring-ring focus-visible:ring-offset-0",placeholder:"K, M, B, %",onChange:d=>{var h,E,I;return t(((h=s==null?void 0:s.formatNumber)==null?void 0:h.decimalPlaces)||0,((E=s==null?void 0:s.formatNumber)==null?void 0:E.currency)||"",((I=s==null?void 0:s.formatNumber)==null?void 0:I.locale)||"",d.target.value)}})]})]})]})}),e.jsxRuntimeExports.jsx(e.Separator,{className:"my-3"}),e.jsxRuntimeExports.jsx(e.ColorFormat,{colorRanges:l,setColorRanges:i})]})]})}function Mt(){return e.jsxRuntimeExports.jsxs("div",{className:"space-y-6 px-6 py-2",children:[e.jsxRuntimeExports.jsx(e.Accordion,{type:"single",collapsible:!0,children:e.jsxRuntimeExports.jsxs(e.AccordionItem,{value:"item-1",children:[e.jsxRuntimeExports.jsx(e.AccordionTrigger,{className:"",children:"KPI Query"}),e.jsxRuntimeExports.jsxs(e.AccordionContent,{className:"font-mono",children:[e.jsxRuntimeExports.jsx("div",{className:"rounded bg-muted px-2 py-1 font-mono text-xs",children:"SELECT current, previous FROM table"}),e.jsxRuntimeExports.jsxs("ul",{className:"my-6 ml-6 list-disc text-xs [&>li]:mt-2",children:[e.jsxRuntimeExports.jsx("li",{children:"current - number"}),e.jsxRuntimeExports.jsx("li",{children:"previous - number"})]}),e.jsxRuntimeExports.jsxs("div",{children:["See ",e.jsxRuntimeExports.jsx("a",{target:"_blank",onClick:s=>s.stopPropagation(),className:"text-blue-700",href:"https://docs.semaphor.cloud/concepts/visuals#kpi",children:"example"})," in the docs."]})]})]})}),e.jsxRuntimeExports.jsx("section",{className:"",children:e.jsxRuntimeExports.jsx(Ft,{})}),e.jsxRuntimeExports.jsx("div",{}),e.jsxRuntimeExports.jsx("div",{})]})}const Vt=[{label:"Mercator",value:"mercator"},{label:"Azimuthal Equidistant",value:"azimuthalEquidistant"},{label:"Gnomonic",value:"gnomonic"},{label:"Orthographic",value:"orthographic"},{label:"Stereographic",value:"stereographic"},{label:"Equal Earth",value:"equalEarth"},{label:"Albers",value:"albers"},{label:"Albers USA",value:"albersUsa"},{label:"Conic Conformal",value:"conicConformal"},{label:"Conic Equal Area",value:"conicEqualArea"},{label:"Conic Equidistant",value:"conicEquidistant"},{label:"Equirectangular",value:"equirectangular"},{label:"Transverse Mercator",value:"transverseMercator"},{label:"Natural Earth 1",value:"naturalEarth1"}],qt=["blues","brBG","buGn","buPu","cividis","cool","cubehelixDefault","gnBu","greens","greys","inferno","magma","orRd","oranges","pRGn","piYG","plasma","puBu","puBuGn","puOr","puRd","purples","rainbow","rdBu","rdGy","rdPu","rdYlBu","rdYlGn","reds","sinebow","spectral","turbo","viridis","warm","ylGn","ylGnBu","ylOrBr","ylOrRd"],_t=qt.map(s=>({label:s,value:s}));function Bt(){var a,m,x,g,j,d,h,E,I,b,L,k,z,y,C,T,u,R;const s=e.useEditorStore(p=>p.card),n=(m=(a=s==null?void 0:s.preferences)==null?void 0:a.mapVisualOptions)==null?void 0:m.topoJsonUrl,[t,r]=S.useState(((g=(x=s==null?void 0:s.preferences)==null?void 0:x.mapVisualOptions)==null?void 0:g.customTopoJsonUrl)||""),{setCardPreferences:o}=e.useEditorActions(),{data:l}=e.useTopoJson(s),i=Object.keys((l==null?void 0:l.objects)||{}).map(p=>({label:p,value:p}))||[],c=[{label:"US States 10m",value:"https://unpkg.com/us-atlas/states-10m.json"},{label:"Countries 50m",value:"https://unpkg.com/world-atlas/countries-50m.json"},{label:"Custom",value:"custom"}];return e.jsxRuntimeExports.jsxs("div",{className:"p-6",children:[e.jsxRuntimeExports.jsx(fe,{summary:"Map Query",children:e.jsxRuntimeExports.jsx("p",{className:"rounded-md bg-muted p-2 font-mono text-xs",children:"SELECT country, value FROM table"})}),e.jsxRuntimeExports.jsx(e.Separator,{className:"my-4"}),e.jsxRuntimeExports.jsx(fe,{open:!0,summary:"Settings",children:e.jsxRuntimeExports.jsxs("div",{className:"space-y-3 px-2",children:[e.jsxRuntimeExports.jsx(Z,{className:"h-9",options:c,onValueChange:p=>{console.log("value",p),o({...s.preferences,mapVisualOptions:{topoJsonUrl:p}})},value:n||"",label:"Select Map"}),n==="custom"&&e.jsxRuntimeExports.jsx(e.Input,{onChange:p=>{r(p.target.value)},onBlur:()=>{var p;console.log("onBlur",t),o({...s.preferences,mapVisualOptions:{...(p=s.preferences)==null?void 0:p.mapVisualOptions,customTopoJsonUrl:t}})},value:t,className:`h-9 w-full ${e.removeRing}`,placeholder:"Custom URL"}),l&&e.jsxRuntimeExports.jsxs(e.jsxRuntimeExports.Fragment,{children:[e.jsxRuntimeExports.jsxs("div",{className:"space-y-1",children:[e.jsxRuntimeExports.jsx(e.Label,{children:"Map Object"}),e.jsxRuntimeExports.jsx(Z,{className:"h-9",options:i,value:((d=(j=s.preferences)==null?void 0:j.mapVisualOptions)==null?void 0:d.objectKey)||"",label:"Map Object",onValueChange:p=>{var w;o({...s.preferences,mapVisualOptions:{...(w=s.preferences)==null?void 0:w.mapVisualOptions,objectKey:p}})}})]}),e.jsxRuntimeExports.jsxs("div",{className:"space-y-1",children:[e.jsxRuntimeExports.jsx(e.Label,{children:"Projection"}),e.jsxRuntimeExports.jsx(Z,{className:"h-9",options:Vt,value:((E=(h=s.preferences)==null?void 0:h.mapVisualOptions)==null?void 0:E.projection)||"",label:"Projection",onValueChange:p=>{var w;o({...s.preferences,mapVisualOptions:{...(w=s.preferences)==null?void 0:w.mapVisualOptions,projection:p}})}})]}),e.jsxRuntimeExports.jsxs("div",{className:"space-y-1",children:[e.jsxRuntimeExports.jsx(e.Label,{children:"Colors"}),e.jsxRuntimeExports.jsx(Z,{className:"h-9",options:_t,value:((b=(I=s.preferences)==null?void 0:I.mapVisualOptions)==null?void 0:b.colorScale)||"",label:"Select Color Scale",onValueChange:p=>{var w;o({...s.preferences,mapVisualOptions:{...(w=s.preferences)==null?void 0:w.mapVisualOptions,colorScale:p}})}})]})]})]})}),e.jsxRuntimeExports.jsx(e.Separator,{className:"my-4"}),e.jsxRuntimeExports.jsx(fe,{className:"",summary:"Scale Options",children:e.jsxRuntimeExports.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxRuntimeExports.jsx(e.Input,{className:`h-9 w-full ${e.removeRing}`,type:"number",step:.1,value:((k=(L=s.preferences)==null?void 0:L.mapVisualOptions)==null?void 0:k.projectionScale)||1,onChange:p=>{var w;o({...s.preferences,mapVisualOptions:{...(w=s.preferences)==null?void 0:w.mapVisualOptions,projectionScale:Number(p.target.value)}})}}),e.jsxRuntimeExports.jsx(e.Label,{children:"X"}),e.jsxRuntimeExports.jsx(e.Input,{className:`h-9 w-full ${e.removeRing}`,type:"number",step:10,value:((C=(y=(z=s.preferences)==null?void 0:z.mapVisualOptions)==null?void 0:y.projectionOffset)==null?void 0:C[0])||0,onChange:p=>{var w,A,M,q;o({...s.preferences,mapVisualOptions:{...(w=s.preferences)==null?void 0:w.mapVisualOptions,projectionOffset:[Number(p.target.value),((q=(M=(A=s.preferences)==null?void 0:A.mapVisualOptions)==null?void 0:M.projectionOffset)==null?void 0:q[1])||0]}})}}),e.jsxRuntimeExports.jsx(e.Label,{children:"Y"}),e.jsxRuntimeExports.jsx(e.Input,{className:`h-9 w-full ${e.removeRing}`,type:"number",step:10,value:((R=(u=(T=s.preferences)==null?void 0:T.mapVisualOptions)==null?void 0:u.projectionOffset)==null?void 0:R[1])||0,onChange:p=>{var w,A,M,q;o({...s.preferences,mapVisualOptions:{...(w=s.preferences)==null?void 0:w.mapVisualOptions,projectionOffset:[((q=(M=(A=s.preferences)==null?void 0:A.mapVisualOptions)==null?void 0:M.projectionOffset)==null?void 0:q[0])||0,Number(p.target.value)]}})}})]})}),e.jsxRuntimeExports.jsx(e.Separator,{className:"my-4"}),e.jsxRuntimeExports.jsx(ae,{})]})}function Ht(){var r;const s=e.useEditorStore(o=>o.card.preferences),{setCardPreferences:n}=e.useEditorStore(o=>o.actions);function t(o){n({...s,textVisualOptions:{...s==null?void 0:s.textVisualOptions,isDynamicText:o==="dynamic"}})}return e.jsxRuntimeExports.jsxs(e.RadioGroup,{value:(r=s==null?void 0:s.textVisualOptions)!=null&&r.isDynamicText?"dynamic":"static",onValueChange:t,className:"flex gap-3",defaultValue:"x",children:[e.jsxRuntimeExports.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsxRuntimeExports.jsx(e.RadioGroupItem,{value:"static",id:"r1"}),e.jsxRuntimeExports.jsx("label",{className:"text-sm",htmlFor:"r1",children:"Static"})]}),e.jsxRuntimeExports.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsxRuntimeExports.jsx(e.RadioGroupItem,{value:"dynamic",id:"r2"}),e.jsxRuntimeExports.jsx("label",{className:"text-sm",htmlFor:"r2",children:"Dynamic"})]})]})}function Se({cardType:s,docContent:n,suffix:t="Chart"}){return e.jsxRuntimeExports.jsx("div",{className:"space-y-6 px-6 py-2",children:e.jsxRuntimeExports.jsxs(e.Accordion,{defaultValue:["item-2"],type:"multiple",children:[e.jsxRuntimeExports.jsxs(e.AccordionItem,{value:"item-1",children:[e.jsxRuntimeExports.jsx(e.AccordionTrigger,{children:`${e.titleCase(s)} ${t}`}),e.jsxRuntimeExports.jsx(e.AccordionContent,{children:n||e.jsxRuntimeExports.jsxs("div",{className:"space-y-4 font-mono text-xs",children:[e.jsxRuntimeExports.jsx("div",{className:"rounded bg-muted px-2 py-1 text-xs",children:"SELECT label, measure FROM table"}),e.jsxRuntimeExports.jsxs("ul",{className:"ml-6 list-disc text-xs [&>li]:mt-2",children:[e.jsxRuntimeExports.jsx("li",{children:"label - category"}),e.jsxRuntimeExports.jsx("li",{children:"measure - number"})]}),e.jsxRuntimeExports.jsxs("div",{children:["See ",e.jsxRuntimeExports.jsx("a",{target:"_blank",onClick:r=>r.stopPropagation(),className:"text-blue-700",href:"https://docs.semaphor.cloud/concepts/visuals#pie-chart",children:"example"})," in the docs."]})]})})]}),e.jsxRuntimeExports.jsxs(e.AccordionItem,{value:"item-2",children:[e.jsxRuntimeExports.jsx(e.AccordionTrigger,{children:"Settings"}),e.jsxRuntimeExports.jsxs(e.AccordionContent,{className:"space-y-4 px-2",children:[s==="range"&&e.jsxRuntimeExports.jsx(De,{}),s!=="text"&&e.jsxRuntimeExports.jsx(Pe,{}),s==="text"&&e.jsxRuntimeExports.jsx(Ht,{})]})]}),!["range","text"].includes(s)&&e.jsxRuntimeExports.jsxs(e.AccordionItem,{value:"item-3",children:[e.jsxRuntimeExports.jsx(e.AccordionTrigger,{children:"Filters"}),e.jsxRuntimeExports.jsxs(e.AccordionContent,{className:"space-y-4 px-2",children:[e.jsxRuntimeExports.jsx(ae,{}),e.jsxRuntimeExports.jsx(me,{})]})]})]})})}function Pt(){const s=e.useEditorStore(r=>{var o,l;return(l=(o=r==null?void 0:r.card)==null?void 0:o.preferences)==null?void 0:l.sortChart}),{setSortChart:n}=e.useEditorActions();function t(){return e.jsxRuntimeExports.jsxs("div",{className:"space-y-2",children:[e.jsxRuntimeExports.jsx(e.Label,{children:"Sort"}),e.jsxRuntimeExports.jsx(Z,{className:"h-8",label:"Sort Chart",options:[{label:"None",value:"none"},{label:"ASC",value:"asc"},{label:"DESC",value:"desc"}],value:s||"none",onValueChange:r=>{n(r)}})]})}return e.jsxRuntimeExports.jsx("div",{className:"space-y-6 px-6 py-2",children:e.jsxRuntimeExports.jsxs(e.Accordion,{defaultValue:["item-2"],type:"multiple",children:[e.jsxRuntimeExports.jsxs(e.AccordionItem,{value:"item-1",children:[e.jsxRuntimeExports.jsx(e.AccordionTrigger,{children:"Stacked Chart"}),e.jsxRuntimeExports.jsxs(e.AccordionContent,{className:"space-y-4 font-mono text-xs",children:[e.jsxRuntimeExports.jsx("div",{className:"rounded bg-muted px-2 py-1 text-xs",children:"SELECT x-axis, stack-by, y-axis FROM table"}),e.jsxRuntimeExports.jsxs("ul",{className:"ml-6 list-disc text-xs [&>li]:mt-2",children:[e.jsxRuntimeExports.jsx("li",{children:"x-axis - category"}),e.jsxRuntimeExports.jsx("li",{children:"stack by - category"}),e.jsxRuntimeExports.jsx("li",{children:"y-axis - number"})]}),e.jsxRuntimeExports.jsxs("div",{children:["See ",e.jsxRuntimeExports.jsx("a",{target:"_blank",onClick:r=>r.stopPropagation(),className:"text-blue-700",href:"https://docs.semaphor.cloud/concepts/visuals#stacked-chart",children:"example"})," in the docs."]})]})]}),e.jsxRuntimeExports.jsxs(e.AccordionItem,{value:"item-2",children:[e.jsxRuntimeExports.jsx(e.AccordionTrigger,{children:"Settings"}),e.jsxRuntimeExports.jsxs(e.AccordionContent,{className:"space-y-4 px-2",children:[e.jsxRuntimeExports.jsx(De,{}),t(),e.jsxRuntimeExports.jsx(qs,{})]})]}),e.jsxRuntimeExports.jsxs(e.AccordionItem,{value:"item-3",children:[e.jsxRuntimeExports.jsx(e.AccordionTrigger,{children:"Filters"}),e.jsxRuntimeExports.jsxs(e.AccordionContent,{className:"space-y-4 px-2",children:[e.jsxRuntimeExports.jsx(ae,{}),e.jsxRuntimeExports.jsx(me,{})]})]})]})})}function Gt({}){const s=e.useEditorStore(r=>{var o;return(o=r.card)==null?void 0:o.preferences}),n=e.useEditorStore(r=>r.actions.setCardPreferences),t=r=>{n({...s,allowDownload:r})};return e.jsxRuntimeExports.jsxs("div",{className:"space-y-6 px-6 py-2",children:[e.jsxRuntimeExports.jsx(e.Accordion,{defaultValue:["item-3"],type:"multiple",children:e.jsxRuntimeExports.jsxs(e.AccordionItem,{value:"item-3",children:[e.jsxRuntimeExports.jsx(e.AccordionTrigger,{children:"Filters"}),e.jsxRuntimeExports.jsxs(e.AccordionContent,{className:"space-y-4 px-2",children:[e.jsxRuntimeExports.jsx(ae,{}),e.jsxRuntimeExports.jsx(me,{})]})]})}),e.jsxRuntimeExports.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsxRuntimeExports.jsx(e.Checkbox,{onCheckedChange:t,id:"allow-download"}),e.jsxRuntimeExports.jsx("label",{htmlFor:"allow-download",className:"text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70",children:"Allow Download"})]})]})}const $t=e.jsxRuntimeExports.jsxs("div",{className:"space-y-4 font-mono text-xs",children:[e.jsxRuntimeExports.jsx("div",{className:"rounded bg-muted px-2 py-1 text-xs",children:"SELECT dimension, cohort, metric FROM table"}),e.jsxRuntimeExports.jsxs("div",{children:["See ",e.jsxRuntimeExports.jsx("a",{target:"_blank",onClick:s=>s.stopPropagation(),className:"text-blue-700",href:"https://docs.semaphor.cloud/concepts/visuals#pyramid-chart",children:"example"})," in the docs."]})]}),Qt=e.jsxRuntimeExports.jsxs("div",{className:"space-y-4 font-mono text-xs",children:[e.jsxRuntimeExports.jsx("div",{className:"rounded bg-muted px-2 py-1 text-xs",children:"SELECT y-axis, label, range-from, range-to, range-value FROM table"}),e.jsxRuntimeExports.jsxs("div",{children:["See ",e.jsxRuntimeExports.jsx("a",{target:"_blank",onClick:s=>s.stopPropagation(),className:"text-blue-700",href:"https://docs.semaphor.cloud/concepts/visuals#range-charts",children:"example"})," in the docs."]})]}),Ut=e.jsxRuntimeExports.jsxs("div",{className:"space-y-4 font-mono text-xs",children:[e.jsxRuntimeExports.jsx("div",{className:"rounded bg-muted px-2 py-1 text-xs",children:"SELECT text FROM table limit 1"}),e.jsxRuntimeExports.jsxs("div",{children:["See ",e.jsxRuntimeExports.jsx("a",{target:"_blank",onClick:s=>s.stopPropagation(),className:"text-blue-700",href:"https://docs.semaphor.cloud/concepts/visuals#text-visual",children:"example"})," in the docs."]})]});function Kt(){const s=e.useEditorStore(t=>t.card.type);function n(t){switch(t){case"stackedBar":case"stackedLine":return e.jsxRuntimeExports.jsx(Pt,{});case"pyramid":return e.jsxRuntimeExports.jsx(Se,{docContent:$t,cardType:t});case"kpi":return e.jsxRuntimeExports.jsx(Mt,{});case"line":case"bar":return e.jsxRuntimeExports.jsx(Dt,{cardType:t});case"range":return e.jsxRuntimeExports.jsx(Se,{docContent:Qt,cardType:t});case"pie":case"doughnut":case"polarArea":case"radar":return e.jsxRuntimeExports.jsx(Se,{cardType:t});case"bubble":case"scatter":return e.jsxRuntimeExports.jsx(Lt,{cardType:t});case"table":return e.jsxRuntimeExports.jsx(Gt,{cardType:t});case"text":return e.jsxRuntimeExports.jsx(Se,{docContent:Ut,cardType:t,suffix:"Visual"});case"map":return e.jsxRuntimeExports.jsx(Bt,{});case"custom":return e.jsxRuntimeExports.jsx(Nt,{});default:return e.jsxRuntimeExports.jsx(Ot,{})}}return e.jsxRuntimeExports.jsx(e.ScrollArea,{className:"h-full w-full text-sm",children:n(s)})}function Jt(){const s=e.useEditorStore(n=>n.isShowingVisual);return e.jsxRuntimeExports.jsxs(e.ResizablePanelGroup,{direction:"vertical",className:"min-h-[250px] min-w-full max-w-lg",children:[e.jsxRuntimeExports.jsx(e.ResizablePanel,{role:"query-section",className:"flex",minSize:20,defaultSize:40,children:e.jsxRuntimeExports.jsx(pt,{})}),e.jsxRuntimeExports.jsx(e.ResizableHandle,{withHandle:!0,className:"border"}),e.jsxRuntimeExports.jsx(e.ResizablePanel,{className:"pb-1",role:"visual-section",minSize:0,defaultSize:60,children:s?e.jsxRuntimeExports.jsxs(e.ResizablePanelGroup,{direction:"horizontal",children:[e.jsxRuntimeExports.jsx(e.jsxRuntimeExports.Fragment,{children:e.jsxRuntimeExports.jsx(e.ResizablePanel,{className:"flex min-w-[275px]",minSize:20,defaultSize:25,maxSize:30,children:e.jsxRuntimeExports.jsx(Kt,{})})}),e.jsxRuntimeExports.jsx(e.ResizableHandle,{className:"border"}),e.jsxRuntimeExports.jsx(e.ResizablePanel,{minSize:40,defaultSize:75,maxSize:100,children:e.jsxRuntimeExports.jsx(Ke,{})})]}):e.jsxRuntimeExports.jsx(Ke,{})})]})}function Wt({authToken:s,onSave:n,onClose:t}){e.useDashboardStore(i=>i.themeStyle);const r=e.useEditorStore(i=>i.actions.setOnSave),o=e.useEditorStore(i=>i.actions.setOnClose),l=e.useDashboardStore(i=>i.actions.setAuthToken);return S.useEffect(()=>{n&&r(n),t&&o(t)},[n,r,t,o]),S.useEffect(()=>{s&&s.accessToken&&l(s)},[s,l]),e.jsxRuntimeExports.jsx(e.ErrorBoundary,{FallbackComponent:e.Fallback,children:e.jsxRuntimeExports.jsxs(e.EditorPanel,{style:{},className:"rounded-none",role:"editor-panel",children:[e.jsxRuntimeExports.jsx(e.EditorAside,{className:"rounded-none border-r-[1.5px]",children:e.jsxRuntimeExports.jsx(Ss,{})}),e.jsxRuntimeExports.jsx(e.EditorMain,{children:e.jsxRuntimeExports.jsx(Jt,{})})]})})}function Yt(){e.useDashboardStore(i=>i.selectedCardId);const s=e.useDashboardStore(i=>i.selectedSheetId),{setIsVisualEditing:n}=e.useDashboardStore(i=>i.actions),t=e.useDashboardStore(i=>i.isVisualEditing),r=e.useDashboardStore(i=>i.actions.updateFrame);function o(i){s&&(r(s,i),n(!1))}function l(){n(!1)}return e.jsxRuntimeExports.jsx("div",{role:"editor-container",className:e.cn("flex grow",{"max-h-0 overflow-hidden":!t}),children:e.jsxRuntimeExports.jsx(Wt,{onSave:o,onClose:l})})}function Xt(){e.useEditorStore(i=>i.selectedConnectionId),e.useEditorStore(i=>i.selectedDatamodelId);const s=e.useEditorStore(i=>i.selectedDatabaseName);e.useEditorStore(i=>i.selectedSchemaName);const n=e.useEditorStore(i=>i.selectedTableName),t=e.useDashboardStore(i=>i.dashboard.filters)||[];e.useDashboardStore(i=>i.actions.addFilter),e.useDashboardStore(i=>i.actions.removeFilter),e.useDashboardStore(i=>i.actions.removeFilterValue);const{modelItems:r,columns:o}=ie(),{assignFilter:l}=_s();return e.jsxRuntimeExports.jsx("div",{className:"xbg-red-100 flex-1 basis-0 flex-col overflow-scroll px-3",children:o==null?void 0:o.map(i=>{const c=t==null?void 0:t.find(a=>a.column===e.fmt(i.column_name)&&a.table===n&&a.database===s);return e.jsxRuntimeExports.jsx("div",{onClick:()=>l(i),className:e.cn("group flex cursor-pointer items-center justify-between border border-dashed border-background px-3 py-[6px] text-sm transition-colors hover:bg-muted/50",{"bg-muted":c}),children:e.jsxRuntimeExports.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxRuntimeExports.jsx(vs,{column:i}),e.jsxRuntimeExports.jsx("span",{children:i.column_name})]})},i.column_name)})})}function Zt(){e.useDashboardStore(n=>n.showFilters);const s=e.useDashboardStore(n=>n.actions.setShowFilters);return e.jsxRuntimeExports.jsxs("section",{className:"relative flex grow flex-col border-l px-4",children:[e.jsxRuntimeExports.jsxs("div",{className:"mt-4 flex items-center justify-between gap-2 px-3",children:[e.jsxRuntimeExports.jsx(e.Label,{className:"text-lg",children:"Filters"}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>s(!1),className:"h-7 w-7 p-0",variant:"ghost",children:e.jsxRuntimeExports.jsx(e.Cross2Icon,{})})]}),e.jsxRuntimeExports.jsx("div",{className:"flex grow",children:e.jsxRuntimeExports.jsx(Ss,{ColumnsComponent:()=>e.jsxRuntimeExports.jsx(Xt,{})})})]})}function en(){const s=e.useDashboardStore(t=>t.showFilters),n=e.useDashboardStore(t=>t.isVisualEditing);return e.jsxRuntimeExports.jsxs("div",{role:"dashboard-plus-main",className:e.cn("",{"max-h-0 overflow-hidden":n,"flex grow":!n}),children:[e.jsxRuntimeExports.jsx(e.DashboardTabs,{}),s&&e.jsxRuntimeExports.jsx("div",{role:"filter-aside-container",className:"flex",children:e.jsxRuntimeExports.jsx(Zt,{})})]})}function sn(){const s=e.useDashboardStore(r=>r.dashboard),n=e.useDashboardStore(r=>r.actions.setDashboard),t=e.useDashboardStore(r=>r.showDashboardJSON);return e.useDashboardStore(r=>r.actions.setShowDashboardJSON),e.jsxRuntimeExports.jsx("div",{className:e.cn(" p-2",{hidden:!t}),children:e.jsxRuntimeExports.jsx(e.de,{onChange:r=>{if(r)try{JSON.parse(r),n(JSON.parse(r))}catch{}},defaultLanguage:"json",className:"h-[550px] overflow-y-auto ",value:JSON.stringify(s,null,2),options:{minimap:{enabled:!1},glyphMargin:!1,wordWrap:"on",scrollbar:{verticalScrollbarSize:0,horizontalScrollbarSize:0},fontSize:12,renderLineHighlight:"none"}})})}function tn({showControls:s=!1,showFooter:n=!0,...t}){return e.jsxRuntimeExports.jsx(e.ErrorBoundary,{FallbackComponent:e.Fallback,children:e.jsxRuntimeExports.jsxs(e.SemaphorContextProvider,{dashboardProps:t,children:[e.jsxRuntimeExports.jsx(e.Oe,{}),e.jsxRuntimeExports.jsxs(e.UXProvider,{children:[e.jsxRuntimeExports.jsx(sn,{}),e.jsxRuntimeExports.jsxs(e.DashboardPanel,{...t,children:[s&&e.jsxRuntimeExports.jsx(Ws,{}),e.jsxRuntimeExports.jsx(Yt,{}),e.jsxRuntimeExports.jsx(en,{})]})]})]})})}exports.Box=We;exports.ChartArea=Ye;exports.ChartColumnIncreasing=we;exports.ChartLine=ke;exports.ChartNoAxesGantt=Oe;exports.ChartPie=ze;exports.ChartScatter=Fe;exports.CircleX=Xe;exports.CopyPlus=Ze;exports.DashboardPlus=tn;exports.Database=es;exports.EllipsisVertical=Me;exports.Eraser=ss;exports.Eye=ns;exports.EyeClosed=ts;exports.Glasses=rs;exports.Hammer=os;exports.Hash=is;exports.House=as;exports.Key=Ve;exports.ListEnd=ls;exports.ListStart=cs;exports.ListX=xs;exports.LoaderCircle=de;exports.Map=qe;exports.MessageSquareMore=us;exports.Network=ds;exports.Pencil=_e;exports.Play=ms;exports.Plug2=ps;exports.Save=js;exports.SelectComponent=ue;exports.Shapes=Be;exports.ShieldQuestion=hs;exports.Sigma=Es;exports.SwatchBook=fs;exports.Tag=gs;exports.ToggleLeft=Rs;exports.Type=Ie;exports.User=bs;exports.cleanCard=ys;exports.getDashbaordStateWithoutData=He;exports.useEditorAside=ie;
245
+ Visual Query Syntax: ${rt}`,{data:C,isLoading:T,isFetching:u,isError:R,refetch:p}=e.useQuery({queryKey:["ai-query"],queryFn:()=>e.getRequest("https://semaphor.cloud/api/v1/ai",(a==null?void 0:a.accessToken)||"",{user_content:`userContent: ${z} ${m?y:""}`}),enabled:!1});function w(N){if(N.toLowerCase().includes("bar"))h("bar");else if(N.toLowerCase().includes("line"))h("line");else if(N.toLowerCase().includes("bubble"))h("bubble");else if(N.toLowerCase().includes("scatter"))h("scatter");else if(N.toLowerCase().includes("stacked"))h("stackedBar");else if(N.toLowerCase().includes("pie"))h("pie");else if(N.toLowerCase().includes("donut")||N.toLowerCase().includes("doughnut"))h("doughnut");else if(N.toLowerCase().includes("radar"))h("radar");else return h("bar"),!1;return!0}S.useEffect(()=>{C&&I(N=>[...N,{role:"ai",content:C.response}])},[C]),S.useEffect(()=>{const N=setTimeout(()=>{var F;c.current&&(c.current.scroll({top:c.current.scrollHeight,behavior:"smooth"}),(F=i.current)==null||F.focus())},100);return()=>clearTimeout(N)},[E]);function A(){t&&(I(N=>[...N,{role:"user",content:t}]),w(t)&&x(!0),r(""),p())}S.useEffect(()=>{o&&(A(),l(!1))},[o,l]);const M={fontFamily:"Arial, sans-serif",lineHeight:1.6,fontSize:15,width:"100%"},q={fontFamily:"monospace",fontSize:14,lineHeight:1.6},B={fontFamily:"Arial, sans-serif",lineHeight:1.6,fontSize:15,padding:"2px 0",marginLeft:20,listStyleType:"disc"},K={p:({node:N,...F})=>e.jsxRuntimeExports.jsx("p",{style:M,...F}),code:({node:N,...F})=>e.jsxRuntimeExports.jsx("code",{className:"rounded-sm bg-muted px-2 py-1 text-sm",...F}),pre:({node:N,...F})=>e.jsxRuntimeExports.jsxs("pre",{className:"space-y-2 rounded-sm bg-muted/50 p-3",style:q,children:[e.jsxRuntimeExports.jsx("code",{className:"whitespace-normal text-sm",children:F.children}),e.jsxRuntimeExports.jsxs("div",{className:"flex justify-start gap-2",children:[e.jsxRuntimeExports.jsx(e.Button,{onClick:_,size:"sm",variant:"outline",children:e.jsxRuntimeExports.jsx(e.ClipboardCopyIcon,{})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:P=>{const O=_(P);O&&(n(!1),g(O),d(!0))},size:"sm",variant:"outline",children:e.jsxRuntimeExports.jsx(e.PlayIcon,{})})]})]}),li:({node:N,...F})=>e.jsxRuntimeExports.jsx("li",{style:B,...F})};function _(N){const F=N.currentTarget.closest("pre");if(!F)return;const P=F.textContent||F.innerText;return navigator.clipboard.writeText(P).then(()=>console.log("Text copied to clipboard")).catch(O=>console.error("Error in copying text: ",O)),P}function U(){return E==null?void 0:E.map((N,F)=>N.role==="user"?e.jsxRuntimeExports.jsxs("div",{className:"flex items-start rounded-md bg-muted p-3 text-sm",children:[e.jsxRuntimeExports.jsx(bs,{className:"mr-2 h-5 w-5"}),e.jsxRuntimeExports.jsx("div",{children:N.content})]},F):N.role==="ai"?e.jsxRuntimeExports.jsx(e.Markdown,{className:"w-full overflow-auto py-1",components:K,children:C==null?void 0:C.response.replace(/DuckDB/gi,"Semaphor")},F):e.jsxRuntimeExports.jsx("div",{},F))}return e.jsxRuntimeExports.jsxs(e.Dialog,{open:s,onOpenChange:n,children:[e.jsxRuntimeExports.jsx(e.DialogTrigger,{asChild:!0,children:e.jsxRuntimeExports.jsx(e.Button,{size:"sm",className:"w-full justify-start border font-normal text-muted-foreground focus-visible:ring-0 focus-visible:ring-offset-0",variant:"secondary",children:"Type your question here..."})}),e.jsxRuntimeExports.jsxs(e.DialogContent,{className:"flex flex-col justify-between overflow-auto sm:max-w-[425px] md:max-h-[625px] md:min-w-[625px]",children:[e.jsxRuntimeExports.jsxs(e.DialogHeader,{children:[e.jsxRuntimeExports.jsx(e.DialogTitle,{children:"Assistant"}),e.jsxRuntimeExports.jsx(e.DialogDescription,{children:"What can I help you with?"})]}),e.jsxRuntimeExports.jsx("div",{ref:c,className:"h-[625px] w-full overflow-auto border-t border-t-muted",children:e.jsxRuntimeExports.jsx("div",{className:"space-y-4 py-2 pr-3",role:"messages",children:U()})}),e.jsxRuntimeExports.jsx("div",{children:e.jsxRuntimeExports.jsxs("div",{className:"flex w-full items-center rounded-md border",children:[e.jsxRuntimeExports.jsx(e.Textarea,{autoFocus:!0,ref:i,onKeyDown:N=>{N.key==="Enter"&&!N.shiftKey&&(N.preventDefault(),r(""),A())},placeholder:"Type your question here...",onFocus:N=>{const F=N.target,P=F.value.length;F.setSelectionRange(P,P)},className:e.cn("max-h-10 min-h-7 resize-none border-none focus-visible:ring-0 focus-visible:ring-ring focus-visible:ring-offset-0"),disabled:T||u,value:t,onChange:N=>r(N.target.value)})," ",e.jsxRuntimeExports.jsx(e.Button,{className:"h-8",size:"sm",variant:"ghost",onClick:A,children:!T&&!u?e.jsxRuntimeExports.jsx(e.PaperPlaneIcon,{}):e.jsxRuntimeExports.jsx(de,{className:"mr-2 h-4 w-4 animate-spin text-foreground/50"})})]})})]})]})}var Cs={color:void 0,size:void 0,className:void 0,style:void 0,attr:void 0},Qe=S.createContext&&S.createContext(Cs),it=["attr","size","title"];function at(s,n){if(s==null)return{};var t=lt(s,n),r,o;if(Object.getOwnPropertySymbols){var l=Object.getOwnPropertySymbols(s);for(o=0;o<l.length;o++)r=l[o],!(n.indexOf(r)>=0)&&Object.prototype.propertyIsEnumerable.call(s,r)&&(t[r]=s[r])}return t}function lt(s,n){if(s==null)return{};var t={};for(var r in s)if(Object.prototype.hasOwnProperty.call(s,r)){if(n.indexOf(r)>=0)continue;t[r]=s[r]}return t}function Ce(){return Ce=Object.assign?Object.assign.bind():function(s){for(var n=1;n<arguments.length;n++){var t=arguments[n];for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&(s[r]=t[r])}return s},Ce.apply(this,arguments)}function Ue(s,n){var t=Object.keys(s);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(s);n&&(r=r.filter(function(o){return Object.getOwnPropertyDescriptor(s,o).enumerable})),t.push.apply(t,r)}return t}function Ne(s){for(var n=1;n<arguments.length;n++){var t=arguments[n]!=null?arguments[n]:{};n%2?Ue(Object(t),!0).forEach(function(r){ct(s,r,t[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(s,Object.getOwnPropertyDescriptors(t)):Ue(Object(t)).forEach(function(r){Object.defineProperty(s,r,Object.getOwnPropertyDescriptor(t,r))})}return s}function ct(s,n,t){return n=xt(n),n in s?Object.defineProperty(s,n,{value:t,enumerable:!0,configurable:!0,writable:!0}):s[n]=t,s}function xt(s){var n=ut(s,"string");return typeof n=="symbol"?n:n+""}function ut(s,n){if(typeof s!="object"||!s)return s;var t=s[Symbol.toPrimitive];if(t!==void 0){var r=t.call(s,n||"default");if(typeof r!="object")return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return(n==="string"?String:Number)(s)}function Ns(s){return s&&s.map((n,t)=>S.createElement(n.tag,Ne({key:t},n.attr),Ns(n.child)))}function ee(s){return n=>S.createElement(dt,Ce({attr:Ne({},s.attr)},n),Ns(s.child))}function dt(s){var n=t=>{var{attr:r,size:o,title:l}=s,i=at(s,it),c=o||t.size||"1em",a;return t.className&&(a=t.className),s.className&&(a=(a?a+" ":"")+s.className),S.createElement("svg",Ce({stroke:"currentColor",fill:"currentColor",strokeWidth:"0"},t.attr,r,i,{className:a,style:Ne(Ne({color:s.color||t.color},t.style),s.style),height:c,width:c,xmlns:"http://www.w3.org/2000/svg"}),l&&S.createElement("title",null,l),s.children)};return Qe!==void 0?S.createElement(Qe.Consumer,null,t=>n(t)):n(Cs)}function mt(s){return ee({tag:"svg",attr:{viewBox:"0 0 448 512"},child:[{tag:"path",attr:{d:"M439.8 200.5c-7.7-30.9-22.3-54.2-53.4-54.2h-40.1v47.4c0 36.8-31.2 67.8-66.8 67.8H172.7c-29.2 0-53.4 25-53.4 54.3v101.8c0 29 25.2 46 53.4 54.3 33.8 9.9 66.3 11.7 106.8 0 26.9-7.8 53.4-23.5 53.4-54.3v-40.7H226.2v-13.6h160.2c31.1 0 42.6-21.7 53.4-54.2 11.2-33.5 10.7-65.7 0-108.6zM286.2 404c11.1 0 20.1 9.1 20.1 20.3 0 11.3-9 20.4-20.1 20.4-11 0-20.1-9.2-20.1-20.4.1-11.3 9.1-20.3 20.1-20.3zM167.8 248.1h106.8c29.7 0 53.4-24.5 53.4-54.3V91.9c0-29-24.4-50.7-53.4-55.6-35.8-5.9-74.7-5.6-106.8.1-45.2 8-53.4 24.7-53.4 55.6v40.7h106.9v13.6h-147c-31.1 0-58.3 18.7-66.8 54.2-9.8 40.7-10.2 66.1 0 108.6 7.6 31.6 25.7 54.2 56.8 54.2H101v-48.8c0-35.3 30.5-66.4 66.8-66.4zm-6.7-142.6c-11.1 0-20.1-9.1-20.1-20.3.1-11.3 9-20.4 20.1-20.4 11 0 20.1 9.2 20.1 20.4s-9 20.3-20.1 20.3z"},child:[]}]})(s)}function pt(){const[s,n]=S.useState({queryKey:[],queryData:null}),{theme:t}=e.useTheme(),r=e.useQueryClient(),o=S.useRef(),l=S.useRef(),[i,c]=S.useState(!1),[a,m]=S.useState(!1),[x,g]=S.useState(!1),[j,d]=S.useState(""),[h,E]=S.useState(!1),I=e.useDashboardStore(f=>f.selectedSheetId);e.useDashboardStore(f=>f.dashboard.baseQueries);const b=e.useEditorStore(f=>f.card),L=e.useDashboardStore(f=>f.theme),k=e.useEditorStore(f=>f.isShowingVisual);e.useDashboardStore(f=>f.onAcceptChanges);const z=e.useEditorStore(f=>f.selectedConnectionId),y=e.useEditorStore(f=>f.selectedDatabaseName),C=e.useEditorStore(f=>f.selectedDatamodelId),T=e.useEditorStore(f=>f.selectedSchemaName);e.useDashboardStore(f=>f.actions.updateFrameCard);const u=e.useEditorStore(f=>f.selectedTableName),R=e.useEditorStore(f=>f.card.sql),p=e.useEditorStore(f=>f.card.python),w=e.useEditorStore(f=>f.frame),A=e.useDashboardStore(f=>f.dashboard.filters),M=e.useDashboardStore(f=>f.filterValues),q=A==null?void 0:A.filter(f=>f.sheetId===I||!f.sheetId),B=M==null?void 0:M.filter(f=>(q==null?void 0:q.some(Q=>Q.id===f.filterId))||f.filterId.endsWith(I)),K=e.useEditorStore(f=>f.applyFilters),{setCardCustomCfg:_,setQueryResultColumns:U,setFilterValues:N,setCardSql:F,setCard:P,setCardPython:O,setQueryError:D,setPythonStdOut:G,setCardPreferences:V}=e.useEditorStore(f=>f.actions),H=e.useEditorStore(f=>f.onSave),J=e.useEditorStore(f=>f.actions.setApplyFilters),se=e.useEditorStore(f=>f.onClose),le=e.useEditorStore(f=>f.actions.setSqlGen),te=e.useEditorStore(f=>f.runSql),re=e.useEditorStore(f=>f.actions.setRunSql);e.useEditorStore(f=>f.actions.setCardCfg);const ne=e.useEditorStore(f=>f.actions.setIsSqlRunning),{data:$,isLoading:Y,isFetching:X,isSuccess:ge,isError:ce,error:pe,queryKey:je,refetch:xe}=e.useDashboardCardQuery(b);S.useEffect(()=>{if($&&($.rowLimitExceeded&&e.ce.error("Row limit (10,000) exceeded. Refine your query.",{position:"top-center",richColors:!0}),G(($==null?void 0:$.output)||""),$.records.length>0)){const{dimensionKeys:f}=e.getKeys($.records);U(f)}},[$,U,G]),S.useEffect(()=>{(Y||X)&&ne(!0),(ce||ge)&&ne(!1),ce?(D(pe.message),U([]),G("")):D("")},[Y,X,$,G,ce,ge,ne,U,D,pe]),S.useEffect(()=>{te&&(xe(),re(!1))},[te,xe,re]);function Le(){const f=r.getQueryData(je);s.queryData||n({queryKey:je,queryData:f}),r.setQueryData(je,null),F(""),le({}),_(""),V({})}const he=f=>{l.current=f};function Re(f,Q){if(f.length===0)return"";if(Q){const oe=f.find(W=>W.id===Q);if(oe){const W=oe.tabTitle;if(W=="All__Header")return f[0].id;if(W&&W.endsWith("__Header")){const Hs=W.split("__")[0],Ge=f.find(Ps=>Ps.tabTitle===Hs);return Ge?Ge.id:f[0].id}return Q}}return f[0].id}function be(){let f=R;R&&!R.includes("{{")&&(f=Zs(R),F(f));const Q={...b,lastSelectedSchema:T,lastSelectedDatamodelId:C,lastSelectedDatabase:y,lastSelectedTable:u,connectionId:z,type:k?b.type:"table",sql:f,customCfg:k?b.customCfg:null},oe=w.cards.map(Te=>Te.id===b.id?Q:Te),W={...w,cards:oe,activeCardId:Re(oe,w.activeCardId)};H==null||H(W)}function ye(){const{queryKey:f,queryData:Q}=s;f&&Q&&r.setQueryData(f,Q),se==null||se()}S.useEffect(()=>{const f=o.current,Q=l.current;if(f){const oe=window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light",W=L==="system"?oe:L;f.editor.defineTheme("default",{base:W==="light"?"vs":"vs-dark",inherit:!0,rules:[],colors:{"editor.background":W==="light"?"#ffffff":e.getCssVariableValue("--semaphor-background")}}),f.editor.setTheme("default")}return Q&&f&&Q.addCommand(f.KeyMod.Shift|f.KeyCode.Enter,function(){return console.log("Executing query..."),xe(),!1}),()=>{}},[t,L,o.current]);function Ee(f){o.current=f}function v(){return e.jsxRuntimeExports.jsxs(e.jsxRuntimeExports.Fragment,{children:[a&&e.jsxRuntimeExports.jsx("div",{className:"xbg-yellow-100 relative flex w-1/3 min-w-0 grow overflow-hidden border-l p-1 text-xs",role:"editor-filter-container",children:e.jsxRuntimeExports.jsxs("div",{className:"w-[99%]",children:[e.jsxRuntimeExports.jsxs("div",{className:"flex items-center gap-2 pt-3",children:[e.jsxRuntimeExports.jsx(st,{checked:K,onCheckedChange:()=>J(!K),text:"Apply Filters"}),e.jsxRuntimeExports.jsx(nt,{}),B&&a&&e.jsxRuntimeExports.jsx(e.Cross2Icon,{onClick:()=>m(!1),className:"bg-background/50 text-foreground/50 hover:cursor-pointer hover:text-foreground"})]}),e.jsxRuntimeExports.jsx(e.Ft,{theme:"default",onChange:f=>{if(f)try{JSON.parse(f),N(JSON.parse(f))}catch{}},defaultLanguage:"json",className:"mt-1 min-h-[220px]",value:JSON.stringify(B,null,2),options:{readOnly:!0,minimap:{enabled:!1},lineNumbers:"off",glyphMargin:!1,wordWrap:"on",scrollbar:{verticalScrollbarSize:0,horizontalScrollbarSize:0},fontSize:12,renderLineHighlight:"none"}})]})}),B&&!a&&e.jsxRuntimeExports.jsx(e.Filter,{onClick:()=>m(!0),className:e.cn("absolute bottom-4 right-6 h-3 w-3 text-foreground/50 hover:cursor-pointer hover:text-foreground",{"font-bold text-red-800":K})})]})}function Bs(){return e.jsxRuntimeExports.jsxs(e.ResizablePanelGroup,{className:"flex grow pb-1",direction:"vertical",role:"editor-resizable-group",children:[e.jsxRuntimeExports.jsxs(e.ResizablePanel,{id:"1",order:1,defaultSize:i?20:100,className:"relative flex grow",children:[e.jsxRuntimeExports.jsx("div",{role:"sql-container",className:"relative flex w-[99%]",children:e.jsxRuntimeExports.jsx(e.Ft,{theme:"default",className:"pt-3",onChange:f=>{F(f)},value:R,options:{minimap:{enabled:!1},wordWrap:"on",scrollbar:{verticalScrollbarSize:0,horizontalScrollbarSize:0},fontSize:14,renderLineHighlight:"none"},defaultLanguage:"sql",beforeMount:Ee,onMount:he})}),i&&e.jsxRuntimeExports.jsx("code",{className:"absolute right-6 top-3 text-sm text-muted-foreground/70",children:"sql"})]}),i&&e.jsxRuntimeExports.jsxs(e.jsxRuntimeExports.Fragment,{children:[e.jsxRuntimeExports.jsx(e.ResizableHandle,{withHandle:!0,className:"border"}),e.jsxRuntimeExports.jsxs(e.ResizablePanel,{id:"2",order:2,defaultSize:80,className:"relative flex grow",children:[e.jsxRuntimeExports.jsx("div",{role:"python-container",className:"relative flex w-[99%] pt-0",children:e.jsxRuntimeExports.jsx(e.Ft,{className:"pt-3",theme:"default",onChange:f=>{O(f&&f.trim()||"")},value:p||e.PYTHON_DEFAULT_CODE,options:{minimap:{enabled:!1},wordWrap:"on",scrollbar:{verticalScrollbarSize:0,horizontalScrollbarSize:0},fontSize:14,renderLineHighlight:"none"},defaultLanguage:"python",beforeMount:Ee,onMount:he})}),e.jsxRuntimeExports.jsx("code",{className:"absolute right-6 top-3 text-sm text-muted-foreground/70",children:"python"})]})]})]})}return e.jsxRuntimeExports.jsxs("section",{role:"editor-section",className:"flex grow flex-col justify-end",children:[e.jsxRuntimeExports.jsxs("div",{role:"sql-editor",className:"relative flex grow justify-between overflow-y-scroll",children:[Bs(),v()]}),e.jsxRuntimeExports.jsxs("div",{role:"editor-controls",className:"item-center flex flex-wrap justify-between gap-2 px-6 py-4",children:[e.jsxRuntimeExports.jsxs("div",{className:"flex grow items-center gap-2",children:[e.jsxRuntimeExports.jsxs(e.Button,{title:"Shift + Enter",disabled:Y||X,onClick:()=>{xe()},className:"shrink-0",size:"sm",variant:"outline",children:[Y||X?e.jsxRuntimeExports.jsx(de,{className:"mr-2 h-4 w-4 animate-spin text-foreground/50"}):e.jsxRuntimeExports.jsx(ms,{className:"mr-2 h-4 w-4"}),"Run"]}),ce&&e.jsxRuntimeExports.jsx(et,{error:pe.message,setShowAIDialog:g,setTriggerAIRun:E,setUserInputforAI:d}),e.jsxRuntimeExports.jsxs(e.Button,{onClick:Le,className:"",size:"sm",variant:"outline",children:[e.jsxRuntimeExports.jsx(ss,{className:"mr-2 size-4"}),"Clear"]}),e.jsxRuntimeExports.jsx(e.Toggle,{pressed:i,onPressedChange:f=>c(f),className:"",size:"sm",variant:"outline",children:e.jsxRuntimeExports.jsx(mt,{className:"size-4 text-foreground/70"})}),e.jsxRuntimeExports.jsx(ot,{open:x,setOpen:g,userInput:j,triggerAIRun:h,setTriggerAIRun:E,setUserInput:f=>d(f)})]}),e.jsxRuntimeExports.jsxs("div",{className:"flex items-end gap-2",children:[e.jsxRuntimeExports.jsxs(e.Button,{onClick:be,size:"sm",variant:"outline",children:[e.jsxRuntimeExports.jsx(e.Check,{className:"mr-2 size-4 font-bold text-green-600"}),"Accept"]}),e.jsxRuntimeExports.jsxs(e.Button,{onClick:ye,className:"w-full",size:"sm",variant:"outline",children:[e.jsxRuntimeExports.jsx(e.Cross2Icon,{className:"mr-2 size-4"}),"Close"]})]})]})]})}function jt({data:s}){var i;const[n,t]=S.useState([]),o=Object.keys(s[0]).map(c=>({accessorKey:c,header:({column:a})=>{const m=a.getIsSorted();return e.jsxRuntimeExports.jsx("div",{className:"flex gap-2",children:e.jsxRuntimeExports.jsxs("div",{className:"flex cursor-pointer items-center",onClick:()=>a.toggleSorting(a.getIsSorted()==="asc"),children:[c,m==="asc"?e.jsxRuntimeExports.jsx(e.TriangleUpIcon,{className:"ml-2 h-5 w-5"}):m==="desc"?e.jsxRuntimeExports.jsx(e.TriangleDownIcon,{className:"ml-2 h-5 w-5"}):null]})})}})),l=e.useReactTable({data:s,columns:o,getCoreRowModel:e.getCoreRowModel(),getPaginationRowModel:e.getPaginationRowModel(),onSortingChange:t,getSortedRowModel:e.getSortedRowModel(),manualPagination:!0,state:{sorting:n}});return e.jsxRuntimeExports.jsxs(e.Table$1,{children:[e.jsxRuntimeExports.jsx(e.TableHeader,{children:l.getHeaderGroups().map(c=>e.jsxRuntimeExports.jsx(e.TableRow,{children:c.headers.map(a=>e.jsxRuntimeExports.jsx(e.TableHead,{className:"sticky top-0 bg-muted",children:a.isPlaceholder?null:e.flexRender(a.column.columnDef.header,a.getContext())},a.id))},c.id))}),e.jsxRuntimeExports.jsx(e.TableBody,{children:(i=l.getRowModel().rows)!=null&&i.length?l.getRowModel().rows.map(c=>e.jsxRuntimeExports.jsx(e.TableRow,{className:"whitespace-nowrap py-2","data-state":c.getIsSelected()&&"selected",children:c.getVisibleCells().map(a=>e.jsxRuntimeExports.jsx(e.TableCell,{children:e.flexRender(a.column.columnDef.cell,a.getContext())},a.id))},c.id)):e.jsxRuntimeExports.jsx(e.TableRow,{children:e.jsxRuntimeExports.jsx(e.TableCell,{colSpan:o.length,className:"h-24 text-center",children:"No results."})})})]})}function ht({card:s}){var j,d,h,E,I,b,L,k,z,y;const{authToken:n}=e.useSemaphorContext(),t=e.getTokenParams(n==null?void 0:n.accessToken),r=e.useDashboardStore(C=>C.themeStyle),o={colors:((d=(j=r==null?void 0:r.chart)==null?void 0:j.dataset)==null?void 0:d.backgroundColor)||[]};(h=s.customCardPreferences)!=null&&h.inputData;const{getCard:l}=e.useCustomVisual(((E=s.customCardPreferences)==null?void 0:E.url)||""),i=((I=s.customCardPreferences)==null?void 0:I.visualType)||"single",c=e.useEditorStore(C=>C.frame);e.useEditorActions();const{data:a}=e.useDashboardCardQuery(s);if(!((b=s.customCardPreferences)!=null&&b.componentName))return null;const m=l((L=s.customCardPreferences)==null?void 0:L.componentName),x=C=>{console.log("data",C),s.customCardPreferences},g=Object.keys(((k=s.customCardPreferences)==null?void 0:k.dataInputCardIds)||{}).map(C=>{var R,p,w;const T=(p=(R=s.customCardPreferences)==null?void 0:R.dataInputCardIds)==null?void 0:p[C].cardId,u=(w=c==null?void 0:c.cards)==null?void 0:w.find(A=>A.id===T);return u||null});return e.jsxRuntimeExports.jsx("div",{className:"semaphor-custom mb-3 flex grow basis-0 flex-col space-y-2 overflow-y-auto",children:e.jsxRuntimeExports.jsxs(S.Suspense,{fallback:e.jsxRuntimeExports.jsx(e.jsxRuntimeExports.Fragment,{}),children:[m&&i==="single"&&e.jsxRuntimeExports.jsx(m,{params:t,theme:o,settings:(z=s.customCardPreferences)==null?void 0:z.settings,onDataChange:x,data:(a==null?void 0:a.records)||[]}),m&&i==="multiple"&&e.jsxRuntimeExports.jsx("div",{className:"flex flex-col gap-2",children:e.jsxRuntimeExports.jsx(m,{theme:o,onDataChange:x,settings:g.map(C=>{var T;return(T=C==null?void 0:C.customCardPreferences)==null?void 0:T.settings}),data:g.map(C=>(C==null?void 0:C.data)||[])})})]},(y=s.customCardPreferences)==null?void 0:y.componentName)})}function ws({className:s,...n}){var d,h;const t=e.useEditorStore(E=>E.card),r=((d=t.customCardPreferences)==null?void 0:d.showCardHeader)??!0,o=e.useEditorStore(E=>E.frame),l=e.useDashboardStore(E=>E.dashboard.filters);e.useEditorStore(E=>E.actions.setRunSql);const{updateFilter:i}=e.useDashboardActions(),c=l==null?void 0:l.find(E=>E.id===o.filterId),{data:a}=e.useDashboardCardQuery(t),{setCard:m}=e.useEditorActions(),{data:x}=e.useTopoJson(t);if(!t.id)return null;let g;a!=null&&a.records&&(a==null?void 0:a.records.length)>0&&(g=e.createChartConfig({data:a==null?void 0:a.records,cardType:t.type,cfg:t.cfg,customCfg:t.customCfg,preferences:t.preferences,topoJson:x}));function j(E){return e.jsxRuntimeExports.jsx(ht,{card:E})}return e.jsxRuntimeExports.jsxs(e.Card,{role:"editor-visual-card",className:e.cn("relative flex h-full flex-col rounded-none",s),...n,children:[r&&e.jsxRuntimeExports.jsxs(e.CardHeader,{className:"flex flex-row items-start justify-between py-4",children:[e.jsxRuntimeExports.jsxs("div",{children:[e.jsxRuntimeExports.jsx(e.Editable,{text:t.title,onSave:E=>m({...t,title:E}),children:e.jsxRuntimeExports.jsx("div",{className:"flex items-center gap-5",children:e.jsxRuntimeExports.jsx(e.CardTitle,{className:"text-base",children:t.title||"Edit title..."})})},t.title),e.jsxRuntimeExports.jsx(e.Editable,{text:t.description||"",onSave:E=>m({...t,description:E}),children:e.jsxRuntimeExports.jsx(e.CardDescription,{children:t.description||"Edit description..."})},t.description)]}),c&&e.jsxRuntimeExports.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxRuntimeExports.jsx(e.Editable,{className:"my-1",text:c.title||c.column,onSave:E=>i({...c,title:E}),children:e.jsxRuntimeExports.jsx(e.Label,{children:c.title})}),e.getFilterComponent(c)]})]}),e.jsxRuntimeExports.jsxs(e.CardContent,{className:"flex grow flex-col",children:[t.type==="custom"&&j(t),!["table","custom"].includes(t.type)&&g&&e.jsxRuntimeExports.jsx(e.ChartJsVisual,{cfg:g},JSON.stringify(g)+JSON.stringify(t.preferences)+((h=t==null?void 0:t.preferences)==null?void 0:h.customVisualCode)),t.type==="table"&&(a==null?void 0:a.records)&&(a==null?void 0:a.records.length)>0&&e.jsxRuntimeExports.jsx(e.ScrollArea$1,{className:"flex min-h-0 flex-1 grow basis-0",children:e.jsxRuntimeExports.jsx(e.TableVisual,{card:t,data:a==null?void 0:a.records})})]})]})}function Et(){const[s,n]=S.useState(!1),[t,r]=S.useState(""),[o,l]=S.useState(""),[i,c]=S.useState(""),[a,m]=S.useState(""),x=e.useEditorStore(y=>y.card),g=e.useEditorStore(y=>y.card.customCfg),{data:j}=e.useDashboardCardQuery(x),{data:d}=e.useTopoJson(x),{setCardCustomCfg:h,setCustomVisualCode:E}=e.useEditorActions();function I(y){var u,R;const C={...y,data:{...y==null?void 0:y.data,datasets:(R=(u=y==null?void 0:y.data)==null?void 0:u.datasets)==null?void 0:R.map(p=>({...p,data:[]}))}};return JSON.stringify(C,null,1)}function b(){var C,T;if(!(j!=null&&j.records)||(j==null?void 0:j.records.length)===0)return;const y=e.createChartConfig({data:j==null?void 0:j.records,cardType:x.type,cfg:x.cfg,preferences:x.preferences,topoJson:d});y&&(r(JSON.stringify(y,null,1)),(C=x==null?void 0:x.preferences)!=null&&C.customVisualCode&&c((T=x==null?void 0:x.preferences)==null?void 0:T.customVisualCode),g&&l(JSON.stringify(g,null,1)))}function L(){if(i&&E(i),!!o)try{const y=JSON.parse(o);return y?(h(y),m(""),l(""),y):void 0}catch(y){console.log(y),m("Invalid JSON")}}function k(){l(""),h(null)}function z(){let y;if(g){const C=e._.cloneDeep(x.cfg),T=e._.merge(C,g);return y=I(T),y}return t?(y=I(JSON.parse(t)),y):""}return e.jsxRuntimeExports.jsxs(e.Dialog,{open:s,onOpenChange:n,children:[e.jsxRuntimeExports.jsx(e.DialogTrigger,{asChild:!0,children:e.jsxRuntimeExports.jsx(e.Button,{onClick:b,className:` ${g&&"border-foreground/50 dark:border-foreground/70"}`,size:"sm",variant:"outline",children:e.jsxRuntimeExports.jsx(e.Settings,{className:"h-4 w-4"})})}),e.jsxRuntimeExports.jsxs(e.DialogContent,{className:"max-h-[70vh] min-h-[70vh] overflow-auto sm:min-w-[900px] lg:min-w-[1200px]",children:[e.jsxRuntimeExports.jsxs(e.DialogHeader,{className:"",children:[e.jsxRuntimeExports.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxRuntimeExports.jsx(e.DialogTitle,{children:"Customize Card"}),e.jsxRuntimeExports.jsxs(e.Tooltip,{children:[e.jsxRuntimeExports.jsx(e.TooltipTrigger,{children:e.jsxRuntimeExports.jsx(Ve,{onClick:()=>{navigator.clipboard.writeText(x.id)},className:"size-3 cursor-pointer text-muted-foreground/70 transition-colors hover:text-muted-foreground"})}),e.jsxRuntimeExports.jsx(e.TooltipContent,{side:"right",align:"center",children:e.jsxRuntimeExports.jsx("p",{className:"text-xs",children:"Copy Card ID"})})]})]}),e.jsxRuntimeExports.jsxs(e.DialogDescription,{children:["See the configuration options and documentation",e.jsxRuntimeExports.jsx("a",{target:"_blank",className:"ml-1 text-blue-500 underline",href:"https://www.chartjs.org/docs/latest/samples/bar/vertical.html",children:"here."})]})]}),e.jsxRuntimeExports.jsxs("div",{className:"flex grow gap-2",children:[e.jsxRuntimeExports.jsx(e.ErrorBoundary,{FallbackComponent:e.FallbackEditorCard,children:e.jsxRuntimeExports.jsx(ws,{className:"w-1/2 rounded shadow-none"})}),e.jsxRuntimeExports.jsxs(e.Tabs,{defaultValue:"custom-config",className:"flex w-1/2 flex-col",children:[e.jsxRuntimeExports.jsxs(e.TabsList,{className:"justify-start rounded-sm rounded-b-none border border-b-0",children:[e.jsxRuntimeExports.jsxs(e.TabsTrigger,{value:"custom-config",children:[g&&e.jsxRuntimeExports.jsx(e.CheckIcon,{className:"mr-1 h-5 w-5 text-green-600"}),g?"Custom Config":"Default Config"]}),e.jsxRuntimeExports.jsx(e.TabsTrigger,{className:"",value:"output",children:"Output"}),e.jsxRuntimeExports.jsx(e.TabsTrigger,{className:"",value:"custom-code",children:"Custom Code"})]}),e.jsxRuntimeExports.jsx(e.TabsContent,{className:"bg-red-x mt-0 grow rounded-b border border-t-0 p-2",value:"output",children:e.jsxRuntimeExports.jsx(e.Textarea,{disabled:!0,value:t,className:"h-full resize-none border-none font-mono focus-visible:ring-0 focus-visible:ring-offset-0"})}),e.jsxRuntimeExports.jsx(e.TabsContent,{className:"mt-0 grow rounded-b border border-t-0",value:"custom-config",children:e.jsxRuntimeExports.jsx(e.Ft,{className:"h-full w-full overflow-hidden",theme:"default",options:{minimap:{enabled:!1},wordWrap:"on",scrollbar:{verticalScrollbarSize:0,horizontalScrollbarSize:0},fontSize:14,renderLineHighlight:"none"},defaultLanguage:"json",value:z(),onChange:y=>l(y)})}),e.jsxRuntimeExports.jsx(e.TabsContent,{className:"mt-0 grow rounded-b border border-t-0",value:"custom-code",children:e.jsxRuntimeExports.jsx(e.Ft,{className:"h-full w-full overflow-hidden",theme:"default",options:{minimap:{enabled:!1},wordWrap:"on",scrollbar:{verticalScrollbarSize:0,horizontalScrollbarSize:0},fontSize:14,renderLineHighlight:"none"},defaultLanguage:"javascript",value:i,onChange:y=>c(y||"")})})]})]}),e.jsxRuntimeExports.jsxs(e.DialogFooter,{className:"flex items-center",children:[e.jsxRuntimeExports.jsx(e.Label,{className:"mr-2 text-red-500",children:a}),e.jsxRuntimeExports.jsx(e.Button,{disabled:!g,onClick:k,variant:"outline",children:"Reset"}),e.jsxRuntimeExports.jsx(e.Button,{onClick:L,variant:"outline",children:"Apply"}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>n(!1),variant:"outline",children:"Close"})]})]})]})}function ks(s){return ee({tag:"svg",attr:{viewBox:"0 0 1024 1024"},child:[{tag:"path",attr:{d:"M926.8 397.1l-396-288a31.81 31.81 0 0 0-37.6 0l-396 288a31.99 31.99 0 0 0-11.6 35.8l151.3 466a32 32 0 0 0 30.4 22.1h489.5c13.9 0 26.1-8.9 30.4-22.1l151.3-466c4.2-13.2-.5-27.6-11.7-35.8zM838.6 417l-98.5 32-200-144.7V199.9L838.6 417zM466 567.2l-89.1 122.3-55.2-169.2L466 567.2zm-116.3-96.8L484 373.3v140.8l-134.3-43.7zM512 599.2l93.9 128.9H418.1L512 599.2zm28.1-225.9l134.2 97.1L540.1 514V373.3zM558 567.2l144.3-46.9-55.2 169.2L558 567.2zm-74-367.3v104.4L283.9 449l-98.5-32L484 199.9zM169.3 470.8l86.5 28.1 80.4 246.4-53.8 73.9-113.1-348.4zM327.1 853l50.3-69h269.3l50.3 69H327.1zm414.5-33.8l-53.8-73.9 80.4-246.4 86.5-28.1-113.1 348.4z"},child:[]}]})(s)}function Is(s){return ee({tag:"svg",attr:{viewBox:"0 0 256 256",fill:"currentColor"},child:[{tag:"path",attr:{d:"M128,24a8,8,0,0,0-8,8V88a8,8,0,0,0,8,8,32,32,0,1,1-27.72,16,8,8,0,0,0-2.93-10.93l-48.5-28A8,8,0,0,0,37.92,76,104,104,0,1,0,128,24ZM48.09,91.1,83,111.26A48.09,48.09,0,0,0,80,128c0,1.53.08,3,.22,4.52L41.28,143A88.16,88.16,0,0,1,48.09,91.1Zm-2.67,67.31,39-10.44A48.1,48.1,0,0,0,120,175.32v40.31A88.2,88.2,0,0,1,45.42,158.41ZM136,215.63V175.32a48,48,0,0,0,0-94.65V40.36a88,88,0,0,1,0,175.27Z"},child:[]}]})(s)}function Ds(s){return ee({tag:"svg",attr:{viewBox:"0 0 256 256",fill:"currentColor"},child:[{tag:"path",attr:{d:"M128,24A104,104,0,1,0,232,128,104.11,104.11,0,0,0,128,24Zm87.63,96H191.48A64.1,64.1,0,0,0,136,64.52V40.37A88.13,88.13,0,0,1,215.63,120ZM120,120H80.68A48.09,48.09,0,0,1,120,80.68Zm0,16v39.32A48.09,48.09,0,0,1,80.68,136Zm16,0h39.32A48.09,48.09,0,0,1,136,175.32Zm0-16V80.68A48.09,48.09,0,0,1,175.32,120ZM120,40.37V64.52A64.1,64.1,0,0,0,64.52,120H40.37A88.13,88.13,0,0,1,120,40.37ZM40.37,136H64.52A64.1,64.1,0,0,0,120,191.48v24.15A88.13,88.13,0,0,1,40.37,136ZM136,215.63V191.48A64.1,64.1,0,0,0,191.48,136h24.15A88.13,88.13,0,0,1,136,215.63Z"},child:[]}]})(s)}function Ls(s){return ee({tag:"svg",attr:{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"},child:[{tag:"path",attr:{d:"M6 16m-3 0a3 3 0 1 0 6 0a3 3 0 1 0 -6 0"},child:[]},{tag:"path",attr:{d:"M16 19m-2 0a2 2 0 1 0 4 0a2 2 0 1 0 -4 0"},child:[]},{tag:"path",attr:{d:"M14.5 7.5m-4.5 0a4.5 4.5 0 1 0 9 0a4.5 4.5 0 1 0 -9 0"},child:[]}]})(s)}function Ts(s){return ee({tag:"svg",attr:{viewBox:"0 0 24 24"},child:[{tag:"path",attr:{fill:"none",d:"M0 0h24v24H0z"},child:[]},{tag:"path",attr:{d:"m2 19.99 7.5-7.51 4 4 7.09-7.97L22 9.92l-8.5 9.56-4-4-6 6.01-1.5-1.5zm1.5-4.5 6-6.01 4 4L22 3.92l-1.41-1.41-7.09 7.97-4-4L2 13.99l1.5 1.5z"},child:[]}]})(s)}function As(s){return ee({tag:"svg",attr:{viewBox:"0 0 24 24"},child:[{tag:"path",attr:{fill:"none",d:"M0 0h24v24H0z"},child:[]},{tag:"path",attr:{d:"M4 9h4v11H4zM4 4h4v4H4zM10 7h4v4h-4zM16 10h4v4h-4zM16 15h4v5h-4zM10 12h4v8h-4z"},child:[]}]})(s)}function Os(s){return ee({tag:"svg",attr:{version:"1.2",baseProfile:"tiny",viewBox:"0 0 24 24"},child:[{tag:"path",attr:{d:"M4 18c-.552 0-1-.448-1-1v-6.382l-.553.276c-.495.248-1.095.046-1.342-.447-.247-.494-.046-1.094.448-1.342l2-1c.31-.155.678-.139.973.044.294.183.474.504.474.851v8c0 .552-.448 1-1 1zM13 18h-5c-.404 0-.769-.244-.924-.617-.155-.374-.069-.804.217-1.09l4-4c.254-.254.394-.591.394-.95 0-.358-.14-.695-.394-.949-.508-.508-1.39-.508-1.9.001-.253.252-.393.589-.393.948 0 .552-.448 1-1 1s-1-.448-1-1c0-.894.348-1.733.98-2.364 1.265-1.263 3.464-1.263 4.727.001.632.631.979 1.471.979 2.363 0 .893-.348 1.733-.979 2.364l-2.293 2.293h2.586c.552 0 1 .448 1 1s-.448 1-1 1zM20.955 12.377c.338-.457.545-1.016.545-1.627 0-1.517-1.234-2.75-2.75-2.75-1.031 0-1.966.569-2.44 1.484-.254.49-.063 1.094.428 1.348.49.254 1.094.062 1.348-.428.128-.249.383-.404.664-.404.414 0 .75.336.75.75s-.336.75-.75.75c-.552 0-1 .448-1 1s.448 1 1 1c.689 0 1.25.561 1.25 1.25s-.561 1.25-1.25 1.25-1.25-.561-1.25-1.25c0-.552-.448-1-1-1s-1 .448-1 1c0 1.792 1.458 3.25 3.25 3.25s3.25-1.458 3.25-3.25c0-.939-.406-1.779-1.045-2.373z"},child:[]}]})(s)}function zs(s){return ee({tag:"svg",attr:{viewBox:"0 0 512 512"},child:[{tag:"path",attr:{d:"M217 25v14h78V25h-78zm0 32v46h14V71h50v32h14V57h-78zm32 32v14h14V89h-14zm-64 32v46h30v-46h-30zm48 0v14h46v-14h-46zm64 0v46h30v-46h-30zm-64 32v14h46v-14h-46zm-80 32v46h62v-46h-62zm80 0v14h46v-14h-46zm64 0v46h62v-46h-62zm-64 32v14h46v-14h-46zm-112 32v46h94v-46h-94zm112 0v14h46v-14h-46zm64 0v46h94v-46h-94zm-64 32v14h46v-14h-46zM89 313v46h126v-46H89zm144 0v14h46v-14h-46zm64 0v46h126v-46H297zm-64 32v14h46v-14h-46zM57 377v46h158v-46H57zm176 0v14h46v-14h-46zm64 0v46h158v-46H297zm-64 32v14h46v-14h-46zM25 441v46h190v-46H25zm208 0v14h46v-14h-46zm64 0v46h190v-46H297zm-64 32v14h46v-14h-46z"},child:[]}]})(s)}function Fs(s){const[n,t]=S.useState(null);return S.useEffect(()=>{s&&(async()=>{const l=(await Promise.resolve().then(()=>require("./lucide-react-C5W0mSbU.js")))[s];t(l)})()},[s]),n}function Ms(){const{authToken:s}=e.useSemaphorContext(),{data:n,isLoading:t,isFetching:r,isError:o}=e.useQuery({queryKey:["plugins",s==null?void 0:s.accessToken],queryFn:()=>e.getPlugins(s==null?void 0:s.accessToken)});return{data:n,isLoading:t,isFetching:r,isError:o}}function ft({onChartTypeChange:s}){const[n,t]=S.useState([]),{data:r}=Ms();return S.useEffect(()=>{(async()=>{var l;if(r){const c=(await Promise.all((l=r==null?void 0:r.plugins)==null?void 0:l.map(async a=>(await e.loadManifest(a.value)).visuals.map(g=>({name:g.name,icon:g.icon,url:a.value}))))).flat();t(c)}})()},[r]),n.length===0?null:e.jsxRuntimeExports.jsxs(e.jsxRuntimeExports.Fragment,{children:[e.jsxRuntimeExports.jsx(e.Separator,{className:"my-2"}),e.jsxRuntimeExports.jsx("div",{className:"grid grid-cols-4 place-items-center",children:n.map((o,l)=>e.jsxRuntimeExports.jsx(gt,{text:o.name,onClick:()=>s("custom",o),icon:o.icon},o.url+o.name+l))})]})}const gt=({text:s,icon:n,onClick:t})=>{const r=Fs(n||""),o=s.charAt(0).toUpperCase();return e.jsxRuntimeExports.jsx(e.Button,{onClick:t,title:s,variant:"ghost",children:r?e.jsxRuntimeExports.jsx(r,{className:"h-4 w-4"}):o})};function Rt(){var x,g;const[s,n]=S.useState(!1),t=e.useEditorStore(j=>j.card),r=t.type,{setCardType:o,setCardPreferences:l,setChartOrientation:i}=e.useEditorStore(j=>j.actions),{setCardCustomCfg:c,setCustomCardPreferences:a}=e.useEditorActions();function m(j,d){c(null),l({}),o(j),d&&a({type:"component",visualType:"single",url:d.url,componentName:d.name,icon:d.icon}),n(!1)}return e.jsxRuntimeExports.jsxs(e.Popover,{open:s,onOpenChange:n,children:[e.jsxRuntimeExports.jsx(e.PopoverTrigger,{asChild:!0,children:e.jsxRuntimeExports.jsx(e.Button,{size:"sm",variant:"outline",children:e.jsxRuntimeExports.jsx(bt,{className:"h-4 w-4",chartType:r,customIcon:(x=t.customCardPreferences)==null?void 0:x.icon,componentName:(g=t.customCardPreferences)==null?void 0:g.componentName})})}),e.jsxRuntimeExports.jsxs(e.PopoverContent,{className:"w-50",children:[e.jsxRuntimeExports.jsxs("div",{className:"grid grid-cols-4 place-items-center",children:[e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>m("bar"),className:"font-normal",variant:"ghost",children:e.jsxRuntimeExports.jsx(we,{className:"size-5"})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>m("line"),variant:"ghost",children:e.jsxRuntimeExports.jsx(ke,{className:"size-5"})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>m("stackedBar"),variant:"ghost",children:e.jsxRuntimeExports.jsx(As,{className:"size-5",strokeWidth:0})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>m("stackedLine"),variant:"ghost",children:e.jsxRuntimeExports.jsx(Ts,{className:"size-5",strokeWidth:0})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>m("scatter"),variant:"ghost",children:e.jsxRuntimeExports.jsx(Fe,{className:"size-5"})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>m("bubble"),variant:"ghost",children:e.jsxRuntimeExports.jsx(Ls,{className:"size-4"})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>m("pie"),variant:"ghost",children:e.jsxRuntimeExports.jsx(ze,{className:"size-5"})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>m("doughnut"),variant:"ghost",children:e.jsxRuntimeExports.jsx(Is,{className:"size-5",strokeWidth:1})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>m("radar"),variant:"ghost",children:e.jsxRuntimeExports.jsx(ks,{className:"size-5 font-extralight",strokeWidth:.5})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>m("polarArea"),variant:"ghost",children:e.jsxRuntimeExports.jsx(Ds,{className:"size-5"})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>m("pyramid"),variant:"ghost",children:e.jsxRuntimeExports.jsx(zs,{className:"size-5"})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>m("range"),variant:"ghost",children:e.jsxRuntimeExports.jsx(Oe,{className:"size-5"})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>m("table"),variant:"ghost",children:e.jsxRuntimeExports.jsx(e.Table,{className:"size-5"})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>m("kpi"),variant:"ghost",children:e.jsxRuntimeExports.jsx(Os,{className:"size-6"})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>m("text"),variant:"ghost",children:e.jsxRuntimeExports.jsx(Ie,{className:"size-4"})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>m("map"),variant:"ghost",children:e.jsxRuntimeExports.jsx(qe,{className:"size-4"})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>m("custom"),variant:"ghost",children:e.jsxRuntimeExports.jsx(Be,{className:"size-4"})})]}),e.jsxRuntimeExports.jsx(ft,{onChartTypeChange:m})]})]})}function bt({chartType:s,className:n,customIcon:t,componentName:r}){const o=Fs(t||"");switch(s){case"bar":return e.jsxRuntimeExports.jsx(we,{className:n});case"line":return e.jsxRuntimeExports.jsx(ke,{className:n});case"pie":return e.jsxRuntimeExports.jsx(ze,{className:n});case"radar":return e.jsxRuntimeExports.jsx(ks,{className:n});case"scatter":return e.jsxRuntimeExports.jsx(Fe,{className:n});case"bubble":return e.jsxRuntimeExports.jsx(Ls,{className:n});case"doughnut":return e.jsxRuntimeExports.jsx(Is,{className:n});case"stackedBar":return e.jsxRuntimeExports.jsx(As,{className:"size-4 text-foreground/70"});case"stackedLine":return e.jsxRuntimeExports.jsx(Ts,{className:"size-4 text-foreground/70"});case"polarArea":return e.jsxRuntimeExports.jsx(Ds,{className:n});case"pyramid":return e.jsxRuntimeExports.jsx(zs,{className:n});case"range":return e.jsxRuntimeExports.jsx(Oe,{className:n});case"kpi":return e.jsxRuntimeExports.jsx(Os,{className:n});case"text":return e.jsxRuntimeExports.jsx(Ie,{className:n});case"map":return e.jsxRuntimeExports.jsx(qe,{className:n});case"custom":return t&&o?e.jsxRuntimeExports.jsx(o,{className:n}):r?r==null?void 0:r.charAt(0).toUpperCase():e.jsxRuntimeExports.jsx(Be,{className:n});default:return e.jsxRuntimeExports.jsx(e.Table,{className:n})}}function yt(){var o;const s=e.useEditorStore(l=>l.card),n=((o=s.customCardPreferences)==null?void 0:o.showCardHeader)??!0,{setCustomCardPreferences:t}=e.useEditorActions(),r=l=>{s.customCardPreferences&&t({...s.customCardPreferences,showCardHeader:l===!0})};return e.jsxRuntimeExports.jsxs(e.DropdownMenu,{children:[e.jsxRuntimeExports.jsx(e.DropdownMenuTrigger,{asChild:!0,children:e.jsxRuntimeExports.jsx(Me,{className:"size-4 cursor-pointer text-muted-foreground/70 transition-colors hover:text-muted-foreground"})}),e.jsxRuntimeExports.jsxs(e.DropdownMenuContent,{align:"start",className:"w-40 text-muted-foreground",children:[e.jsxRuntimeExports.jsx(e.DropdownMenuCheckboxItem,{checked:n,onCheckedChange:r,children:"Card Header"}),e.jsxRuntimeExports.jsxs(e.DropdownMenuItem,{onClick:()=>{navigator.clipboard.writeText(s.id),e.ce.success("Card ID copied to clipboard")},className:"cursor-pointer space-x-2",children:[e.jsxRuntimeExports.jsx(Ve,{className:"size-4"}),e.jsxRuntimeExports.jsx("span",{children:"Copy Card ID"})]})]})]})}function Ke(){const s=e.useEditorStore(u=>u.frame),n=e.useEditorStore(u=>u.card),t=e.useEditorStore(u=>u.isShowingVisual),r=e.useEditorStore(u=>u.isSqlRunning),o=e.useEditorStore(u=>u.queryError),l=e.useEditorStore(u=>u.pythonStdOut),i=e.useEditorStore(u=>u.actions.setRunSql);e.useEditorStore(u=>u.onSave),e.useEditorStore(u=>u.onClose),e.useEditorStore(u=>u.actions.setCardSql),e.useEditorStore(u=>u.actions.setCardType),e.useEditorStore(u=>u.actions.setSqlGen);const{setFrame:c,setCard:a,updateCardInFrame:m}=e.useEditorActions(),{data:x,isLoading:g,isFetching:j}=e.useDashboardCardQuery(n);if(!n)return e.jsxRuntimeExports.jsx(e.jsxRuntimeExports.Fragment,{children:"No Active Card"});function d(){const u={connectionId:n.connectionId,id:e.v4(),title:"Title",description:"Description",preferences:{onClickFilter:[{columnIndex:0,expression:""}]},type:"bar",sql:"",data:[]};h(u)}function h(u){const R={...s,cards:[...s.cards,u],activeCardId:u.id};c(R),a(u)}function E(){const u={...n,id:e.v4(),title:`${n.title} Copy`,tabTitle:`${n.tabTitle} Copy`};h(u)}function I(u){const R=s.cards.filter(A=>A.id!==u),p=R[0],w={...s,cards:R,activeCardId:p.id};c(w),a(p)}function b(u){const R={...s,cards:s.cards.map(w=>w.id===n.id?n:w),activeCardId:u};c(R);const p=R.cards.find(w=>w.id===u);p.sql&&i(!0),a(p)}const L=(u,R)=>{console.log("handleDragStart",R),u.dataTransfer.setData("tabIndex",R.toString())},k=u=>{u.preventDefault()},z=(u,R)=>{const p=u.dataTransfer.getData("tabIndex");if(p===R.toString())return;const w=Array.from(s.cards),[A]=w.splice(parseInt(p),1);w.splice(R,0,A),c({...s,cards:w})};function y(u,R){return u.cards.length===1&&(R.displayTab===!0||R.displayTab===void 0)||u.activeCardId!==R.id&&(R.displayTab===!0||R.displayTab===void 0)?null:e.jsxRuntimeExports.jsx("div",{onClick:()=>{const p=R.displayTab===void 0?!1:!R.displayTab;a({...R,displayTab:p}),m({...R,displayTab:p})},children:R.displayTab===!0||R.displayTab===void 0?e.jsxRuntimeExports.jsx(ns,{className:"mr-2 size-3.5 text-muted-foreground hover:text-foreground"}):e.jsxRuntimeExports.jsx(ts,{className:"mr-2 size-3.5 text-muted-foreground hover:text-foreground"})})}function C(){return e.jsxRuntimeExports.jsxs(e.Tabs,{onValueChange:b,value:s.activeCardId,className:"flex grow flex-col",children:[s.cards.map(u=>e.jsxRuntimeExports.jsx(e.TabsContent,{className:"mt-0 grow",value:u.id,children:T()},u.id)),e.jsxRuntimeExports.jsx(e.TabsList,{className:"group mx-6 justify-between",children:e.jsxRuntimeExports.jsxs("div",{className:"flex items-center",children:[s.cards.map((u,R)=>e.jsxRuntimeExports.jsx(e.Editable,{text:u.tabTitle||u.title,onSave:p=>{a({...n,tabTitle:p}),m({...n,tabTitle:p})},children:e.jsxRuntimeExports.jsxs(e.TabsTrigger,{draggable:!0,onDragStart:p=>L(p,R),onDragOver:k,onDrop:p=>z(p,R),className:"",value:u.id,children:[y(s,u),u.tabTitle||u.title,s.activeCardId===u.id&&s.cards.length>1&&e.jsxRuntimeExports.jsx(e.X,{className:"ml-2 size-3.5 text-muted-foreground hover:text-foreground",onClick:()=>I(u.id)})]})},u.id)),e.jsxRuntimeExports.jsx(e.Button,{className:"ml-1 h-8 px-2 hover:bg-muted-foreground/50",variant:"outline",onClick:d,children:e.jsxRuntimeExports.jsx(e.Plus,{className:"h-4 w-4"})}),e.jsxRuntimeExports.jsx(e.Button,{className:"invisible ml-1 h-8 px-2 hover:bg-muted-foreground/50 group-hover:visible",variant:"outline",onClick:E,children:e.jsxRuntimeExports.jsx(Ze,{className:"h-4 w-4"})})]})})]})}function T(){return n.type==="kpi"?e.jsxRuntimeExports.jsx("div",{className:"flex h-full items-center justify-center",children:e.jsxRuntimeExports.jsx("div",{className:"w-1/2 rounded-md border",children:e.jsxRuntimeExports.jsx(e.KPICard,{card:n,data:x==null?void 0:x.records})})}):n.type==="text"?e.jsxRuntimeExports.jsx("div",{className:"flex h-full items-center justify-center",children:e.jsxRuntimeExports.jsx("div",{className:"w-1/2 rounded-md border",children:e.jsxRuntimeExports.jsx(e.ScrollArea,{className:"mx-3 my-6 h-[300px] overflow-y-auto break-words px-3",children:e.jsxRuntimeExports.jsx(e.TextCard,{isLoading:r,card:n,data:x==null?void 0:x.records})})})}):e.jsxRuntimeExports.jsx(e.ErrorBoundary,{FallbackComponent:e.FallbackEditorCard,children:e.jsxRuntimeExports.jsx(ws,{className:"grow border-none shadow-none"})})}return e.jsxRuntimeExports.jsxs("div",{className:"relative flex h-full flex-col py-3",children:[(g||j)&&e.jsxRuntimeExports.jsx(de,{className:"absolute bottom-0 left-0 right-0 top-0 z-50 m-auto h-10 w-10 animate-spin text-foreground/10"}),e.jsxRuntimeExports.jsxs("div",{className:"mb-0 flex min-h-10 items-center justify-end gap-2 px-6",children:[t&&e.jsxRuntimeExports.jsxs("div",{className:"flex grow items-center gap-2",children:[e.jsxRuntimeExports.jsx(Rt,{}),!["table","custom"].includes(n.type)&&e.jsxRuntimeExports.jsx(Et,{}),e.jsxRuntimeExports.jsx(yt,{})]}),e.jsxRuntimeExports.jsx(St,{})]}),t?C():e.jsxRuntimeExports.jsxs("div",{className:"flex min-h-0 w-full flex-1 grow basis-0 px-6",children:[l&&e.jsxRuntimeExports.jsx(vt,{}),(x==null?void 0:x.records)&&(x==null?void 0:x.records.length)>0&&e.jsxRuntimeExports.jsx(jt,{data:(x==null?void 0:x.records)||[]}),o&&e.jsxRuntimeExports.jsx("span",{className:"font-mono text-sm",children:o})]})]})}function vt(){const s=e.useEditorStore(t=>t.pythonStdOut);if(!s)return null;const n=s.replace(/\n/g,"<br>");return e.jsxRuntimeExports.jsxs(e.jsxRuntimeExports.Fragment,{children:[e.jsxRuntimeExports.jsx("p",{className:"font-mono text-sm",children:"Output:"}),e.jsxRuntimeExports.jsx("div",{dangerouslySetInnerHTML:{__html:n},className:"bg-muted p-2 font-mono text-sm"}),e.jsxRuntimeExports.jsx(e.Separator,{className:"mb-2"})]})}function St(){const s=e.useEditorStore(t=>t.isShowingVisual),n=e.useEditorStore(t=>t.actions.setIsShowingVisual);return e.jsxRuntimeExports.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsxRuntimeExports.jsx(e.Label,{htmlFor:"visualize",children:"Chart"}),e.jsxRuntimeExports.jsx(e.Switch,{checked:s,onCheckedChange:()=>n(!s),id:"visualize",className:"data-[state=checked]:bg-foreground/50"})]})}function Ct({options:s,value:n,onValueChange:t}){return e.jsxRuntimeExports.jsx(e.RadioGroup,{value:n,onValueChange:t,className:"flex gap-4",defaultValue:s[0].value,children:s.map(r=>e.jsxRuntimeExports.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsxRuntimeExports.jsx(e.RadioGroupItem,{value:r.value,id:r.value}),e.jsxRuntimeExports.jsx("label",{className:"text-sm",htmlFor:r.value,children:r.label})]},r.value))})}function Z({label:s,options:n,value:t,onValueChange:r,className:o}){return e.jsxRuntimeExports.jsxs(e.Select,{value:t,onValueChange:r,children:[e.jsxRuntimeExports.jsx(e.SelectTrigger,{className:e.cn("w-full focus:ring-0 focus:ring-offset-0",o),children:e.jsxRuntimeExports.jsx(e.SelectValue,{placeholder:s})}),e.jsxRuntimeExports.jsx(e.SelectContent,{children:e.jsxRuntimeExports.jsxs(e.SelectGroup,{children:[e.jsxRuntimeExports.jsx(e.SelectLabel,{children:s}),n.map(l=>e.jsxRuntimeExports.jsx(e.SelectItem,{value:l.value,children:l.label},l.value))]})})]})}function fe({children:s,summary:n,open:t,className:r}){return e.jsxRuntimeExports.jsxs("details",{open:t,className:e.cn("space-y-4 [&_summary>svg]:open:-rotate-180",r),children:[e.jsxRuntimeExports.jsxs("summary",{className:"flex cursor-pointer list-none items-center justify-between gap-4",children:[e.jsxRuntimeExports.jsx(e.Label,{children:n}),e.jsxRuntimeExports.jsx(e.ChevronUp,{className:"h-4 w-4"})]}),e.jsxRuntimeExports.jsx("div",{className:"transition-all ease-in-out",children:s})]})}function Nt(){var E,I;const s=e.useEditorStore(b=>b.card.customCardPreferences),{data:n}=Ms(),t=(n==null?void 0:n.plugins)||[],r=e.useEditorStore(b=>b.card),o=e.useEditorStore(b=>b.frame),l=(s==null?void 0:s.visualType)||"single",{setCustomCardPreferences:i}=e.useEditorActions(),{components:c,manifest:a}=e.useCustomVisual((s==null?void 0:s.url)||""),m=(E=a==null?void 0:a.visuals)==null?void 0:E.find(b=>b.name===(s==null?void 0:s.componentName));function x(b,L){if(!s)return;const z={...(s==null?void 0:s.dataInputCardIds)||{},[b]:{cardId:L,hookRef:null}};i({...s,dataInputCardIds:z})}function g(b){var k,z;const L=(k=o==null?void 0:o.cards)==null?void 0:k.filter(y=>{var C;return((C=y==null?void 0:y.customCardPreferences)==null?void 0:C.visualType)!=="multiple"}).map(y=>({value:y.id,label:y.tabTitle||y.title}));return e.jsxRuntimeExports.jsx("div",{className:"space-y-2",children:(z=b==null?void 0:b.dataInputs)==null?void 0:z.map((y,C)=>{var T,u;return e.jsxRuntimeExports.jsxs("div",{className:"grid grid-cols-10 gap-2",children:[e.jsxRuntimeExports.jsx("div",{className:"col-span-4 flex items-center",children:y}),e.jsxRuntimeExports.jsx(Z,{className:"col-span-6 h-8 w-full justify-between",label:"",options:L||[],value:((u=(T=s==null?void 0:s.dataInputCardIds)==null?void 0:T[C])==null?void 0:u.cardId)||"",onValueChange:R=>x(C,R)})]},C+Math.random())})})}function j(b,L,k=[]){var z,y;return s?b==="input"?e.jsxRuntimeExports.jsx(e.Input,{className:`h-8 w-full ${e.removeRing}`,value:((z=s==null?void 0:s.settings)==null?void 0:z[L])||"",onChange:C=>{i({...s,settings:{...s==null?void 0:s.settings,[L]:C.target.value}})}},L):b==="select"?e.jsxRuntimeExports.jsx(Z,{className:"h-8 w-full",label:"",options:k,value:((y=s==null?void 0:s.settings)==null?void 0:y[L])||"",onValueChange:C=>{i({...s,settings:{...s==null?void 0:s.settings,[L]:C}})}}):null:null}function d(b){const L=Object.entries((b==null?void 0:b.settings)||{});return e.jsxRuntimeExports.jsx("div",{className:"space-y-3",children:L.map(([k,z])=>e.jsxRuntimeExports.jsxs("div",{className:"space-y-2",children:[e.jsxRuntimeExports.jsx(e.Label,{children:z.title}),j(z.ui,k,z.options)]},k))})}function h(b){s&&i({...s,visualType:b,componentName:""})}return e.jsxRuntimeExports.jsxs("div",{className:"p-6",children:[e.jsxRuntimeExports.jsx(fe,{summary:"Plugin Settings",children:e.jsxRuntimeExports.jsx("div",{className:"space-y-4 text-sm",children:e.jsxRuntimeExports.jsxs("div",{className:"space-y-4 text-sm",children:[e.jsxRuntimeExports.jsx("div",{className:"space-y-2",children:e.jsxRuntimeExports.jsx("div",{className:"px-2",children:e.jsxRuntimeExports.jsx(Z,{className:"h-8 w-full",label:"",options:t,value:(s==null?void 0:s.url)||"",onValueChange:b=>i({...s||{url:"",componentName:""},url:b})})})}),((s==null?void 0:s.type)==="component"||(s==null?void 0:s.type)===void 0)&&e.jsxRuntimeExports.jsx(Ct,{options:[{value:"single",label:"Single Visual"},{value:"multiple",label:"Multi-Visual"}],value:l,onValueChange:h}),((s==null?void 0:s.type)==="component"||(s==null?void 0:s.type)===void 0)&&s&&e.jsxRuntimeExports.jsx(e.jsxRuntimeExports.Fragment,{children:e.jsxRuntimeExports.jsxs("div",{className:"space-y-2",children:[e.jsxRuntimeExports.jsx(e.Label,{children:"Component"}),e.jsxRuntimeExports.jsx("div",{className:"space-y-2 px-2",children:c&&e.jsxRuntimeExports.jsx(Z,{className:"h-8 w-full",label:"",options:(c==null?void 0:c.filter(b=>b.type===l).map(b=>({value:b.name,label:b.name})))||[],value:s.componentName,onValueChange:b=>{console.log("changing value",b),i({...s,componentName:b})}})})]})})]})})}),e.jsxRuntimeExports.jsx(e.Separator,{className:"my-4"}),((I=r==null?void 0:r.customCardPreferences)==null?void 0:I.componentName)&&e.jsxRuntimeExports.jsxs(fe,{summary:"Component Settings",children:[m&&m.dataInputs&&e.jsxRuntimeExports.jsxs("div",{className:"space-y-3",children:[e.jsxRuntimeExports.jsx(e.Label,{children:"Input Mapping"}),e.jsxRuntimeExports.jsx("div",{className:"px-2",children:g(m)})]}),m&&m.settings&&e.jsxRuntimeExports.jsx("div",{className:"space-y-3",children:e.jsxRuntimeExports.jsx("div",{className:"px-2",children:d(m)})})]})]})}function ae(){const[s,n]=S.useState([]);e.useEditorStore(x=>x.card.cfg);const t=e.useEditorStore(x=>x.card.preferences),{setCardCfg:r,setFilterOnClickColumnIndex:o,setCardPreferences:l}=e.useEditorStore(x=>x.actions),i=e.useEditorStore(x=>x.queryResultColumns);e.useEditorStore(x=>{var g;return(g=x.card.preferences)==null?void 0:g.filterOnClickColumnIndex}),S.useEffect(()=>{i&&n(new Array(i.length).fill(!1))},[i]);function c(x,g){var j,d;g?t!=null&&t.onClickFilter&&((j=t==null?void 0:t.onClickFilter)==null?void 0:j.length)>0?l({...t,onClickFilter:[...t.onClickFilter,{columnIndex:x,expression:""}]}):l({...t,onClickFilter:[{columnIndex:x,expression:""}]}):(l({...t,onClickFilter:(d=t==null?void 0:t.onClickFilter)==null?void 0:d.filter(h=>h.columnIndex!==x)}),n(h=>{const E=[...h];return E[x]=!1,E}))}function a(x,g){var d;const j=(d=t==null?void 0:t.onClickFilter)==null?void 0:d.map(h=>h.columnIndex===x?{...h,expression:g.target.value}:h);l({...t,onClickFilter:j})}function m(x){var g,j,d,h;if(s!=null&&s[x]||(j=(g=t==null?void 0:t.onClickFilter)==null?void 0:g.find(E=>E.columnIndex===x))!=null&&j.expression)return e.jsxRuntimeExports.jsx(e.Input,{value:(h=(d=t==null?void 0:t.onClickFilter)==null?void 0:d.find(E=>E.columnIndex===x))==null?void 0:h.expression,onChange:E=>a(x,E),type:"text",className:"h-9 w-full font-mono text-xs focus-visible:ring-0 focus-visible:ring-ring focus-visible:ring-offset-0",placeholder:"Expression"})}return e.jsxRuntimeExports.jsxs("div",{className:"space-y-2",children:[e.jsxRuntimeExports.jsx(e.Label,{children:"On Click"}),i==null?void 0:i.map((x,g)=>{var j,d;return e.jsxRuntimeExports.jsx("div",{className:"xbg-red-100 group flex items-center justify-between space-y-2",children:e.jsxRuntimeExports.jsxs("div",{className:"grow",children:[e.jsxRuntimeExports.jsxs("div",{className:"flex items-center space-x-2 py-2",children:[e.jsxRuntimeExports.jsx(e.Checkbox,{checked:!!((j=t==null?void 0:t.onClickFilter)!=null&&j.find(h=>h.columnIndex===g)),onCheckedChange:h=>c(g,h)}),e.jsxRuntimeExports.jsx("label",{className:"text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70",children:x}),e.jsxRuntimeExports.jsx("div",{className:"flex items-center gap-2",children:((d=t==null?void 0:t.onClickFilter)==null?void 0:d.find(h=>h.columnIndex===g))&&e.jsxRuntimeExports.jsx(_e,{onClick:()=>{n(h=>{const E=[...h];return E[g]=!h[g],E})},className:"invisible size-3 cursor-pointer text-gray-400 group-hover:visible"})})]}),m(g)]})},x)})]})}function De(){var i,c,a;const s=e.useEditorStore(m=>m.card.preferences),n=e.useEditorStore(m=>m.card.cfg),{setCardCfg:t,setCardPreferences:r,setChartOrientation:o}=e.useEditorStore(m=>m.actions);(i=n==null?void 0:n.options)!=null&&i.indexAxis;function l(m){o(m)}return e.jsxRuntimeExports.jsxs(e.RadioGroup,{value:((c=s==null?void 0:s.chartOptions)==null?void 0:c.indexAxis)||((a=n==null?void 0:n.options)==null?void 0:a.indexAxis)||"x",onValueChange:l,className:"flex gap-3",defaultValue:"x",children:[e.jsxRuntimeExports.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsxRuntimeExports.jsx(e.RadioGroupItem,{value:"x",id:"r1"}),e.jsxRuntimeExports.jsx("label",{className:"text-sm",htmlFor:"r1",children:"Vertical"})]}),e.jsxRuntimeExports.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsxRuntimeExports.jsx(e.RadioGroupItem,{value:"y",id:"r2"}),e.jsxRuntimeExports.jsx("label",{className:"text-sm",htmlFor:"r2",children:"Horizontal"})]})]})}const ve="focus-visible:ring-0 focus-visible:ring-ring focus-visible:ring-offset-0";function Je(s,n){var r,o,l;const t=e.getNumberAxis(s,n);return((l=(o=(r=s==null?void 0:s.chartOptions)==null?void 0:r.scales)==null?void 0:o[t])==null?void 0:l.type)||"linear"}function Vs(){var K,_,U,N,F,P;const[s,n]=S.useState(!1),t=e.useEditorStore(O=>{var D;return(D=O.card)==null?void 0:D.preferences}),r=e.useEditorStore(O=>{var D;return(D=O.card)==null?void 0:D.cfg}),o=e.getNumberAxis(t,r),[l,i]=S.useState(Je(t)),[c,a]=S.useState(((U=(_=(K=t==null?void 0:t.chartOptions)==null?void 0:K.scales)==null?void 0:_[o])==null?void 0:U.min)||""),[m,x]=S.useState(((P=(F=(N=t==null?void 0:t.chartOptions)==null?void 0:N.scales)==null?void 0:F[o])==null?void 0:P.max)||""),[g,j]=S.useState(c||m?"custom":"auto"),[d,h]=S.useState(""),[E,I]=S.useState(0),[b,L]=S.useState(""),[k,z]=S.useState(""),[y,C]=S.useState(""),T=e.useEditorStore(O=>O.actions.setCardPreferences),{updateCardInFrame:u}=e.useEditorActions(),R=e.useEditorStore(O=>O.card),p=e.useEditorStore(O=>{var D;return(D=O.card)==null?void 0:D.type}),w=["pie","doughnut","polarArea"].includes(p);S.useEffect(()=>{var O,D,G,V,H,J,se,le,te,re,ne,$,Y,X;i(Je(t)),a(((G=(D=(O=t==null?void 0:t.chartOptions)==null?void 0:O.scales)==null?void 0:D[o])==null?void 0:G.min)===0?0:""),x(((J=(H=(V=t==null?void 0:t.chartOptions)==null?void 0:V.scales)==null?void 0:H[o])==null?void 0:J.max)||""),h(((re=(te=(le=(se=t==null?void 0:t.chartOptions)==null?void 0:se.scales)==null?void 0:le[o])==null?void 0:te.ticks)==null?void 0:re.stepSize)||""),I(((ne=t==null?void 0:t.numberAxisFormat)==null?void 0:ne.decimalPlaces)||0),L((($=t==null?void 0:t.numberAxisFormat)==null?void 0:$.suffix)||""),z(((Y=t==null?void 0:t.numberAxisFormat)==null?void 0:Y.currency)||""),C(((X=t==null?void 0:t.numberAxisFormat)==null?void 0:X.locale)||"")},[s,t,o]);function A(O,D){return D===""||/^[0-9\b]+$/.test(D)?Number(D):Number(O)}function M(){const O=[...new Set(e.LOCALE_CURRENCY_PAIRS.map(D=>D.currency))];return e.jsxRuntimeExports.jsxs(e.jsxRuntimeExports.Fragment,{children:[e.jsxRuntimeExports.jsxs("div",{className:"grid grid-cols-6 items-center gap-2",children:[e.jsxRuntimeExports.jsx(e.Label,{className:"col-span-2 hover:cursor-pointer hover:underline",htmlFor:"currency",children:e.jsxRuntimeExports.jsx("a",{target:"_blank",href:"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat",children:"Currency"})}),e.jsxRuntimeExports.jsxs(e.Select,{value:k||"none",onValueChange:D=>z(D==="none"?"":D),children:[e.jsxRuntimeExports.jsx(e.SelectTrigger,{className:"col-span-2 h-8 w-full focus:ring-1 focus:ring-offset-0",children:e.jsxRuntimeExports.jsx(e.SelectValue,{})}),e.jsxRuntimeExports.jsx(e.SelectContent,{children:e.jsxRuntimeExports.jsxs(e.SelectGroup,{children:[e.jsxRuntimeExports.jsx(e.SelectLabel,{children:"Currency"}),e.jsxRuntimeExports.jsx(e.SelectItem,{value:"none",children:"None"}),O.map(D=>e.jsxRuntimeExports.jsx(e.SelectItem,{value:D,children:D},D))]})})]}),e.jsxRuntimeExports.jsxs(e.Select,{value:y,onValueChange:D=>C(D),children:[e.jsxRuntimeExports.jsx(e.SelectTrigger,{className:"col-span-2 h-8 w-full focus:ring-1 focus:ring-offset-0",children:e.jsxRuntimeExports.jsx(e.SelectValue,{})}),e.jsxRuntimeExports.jsx(e.SelectContent,{children:e.jsxRuntimeExports.jsxs(e.SelectGroup,{children:[e.jsxRuntimeExports.jsx(e.SelectLabel,{children:"Locale"}),e.LOCALE_CURRENCY_PAIRS.map(D=>e.jsxRuntimeExports.jsx(e.SelectItem,{value:D.locale,children:D.locale},D.locale))]})})]})]}),e.jsxRuntimeExports.jsxs("div",{className:"grid grid-cols-9 items-center gap-2",children:[e.jsxRuntimeExports.jsx(e.Label,{className:"col-span-3",htmlFor:"format",children:"Decimals"}),e.jsxRuntimeExports.jsx(e.Input,{value:E,onChange:D=>I(Number(D.target.value)),id:"format",className:`col-span-6 h-8 w-full tracking-wide ${ve}`})]})]})}function q(){return e.jsxRuntimeExports.jsxs(e.jsxRuntimeExports.Fragment,{children:[e.jsxRuntimeExports.jsxs("div",{className:"grid grid-cols-3 items-center gap-2",children:[e.jsxRuntimeExports.jsx(e.Label,{htmlFor:"range",children:"Range"}),e.jsxRuntimeExports.jsx(e.Input,{id:"min",value:c,onChange:O=>a(D=>A(D,O.target.value)),className:`col-span-1 h-8 w-full ${ve}`}),e.jsxRuntimeExports.jsx(e.Input,{value:m,onChange:O=>x(D=>A(D,O.target.value)),id:"max",className:`col-span-1 h-8 w-full ${ve}`})]}),e.jsxRuntimeExports.jsxs("div",{className:"grid grid-cols-3 items-center gap-2",children:[e.jsxRuntimeExports.jsx(e.Label,{htmlFor:"step-size",children:"Step Size"}),e.jsxRuntimeExports.jsx(e.Input,{value:d,onChange:O=>h(D=>A(D,O.target.value)),id:"step-size",className:`col-span-1 h-8 w-full ${ve}`})]})]})}function B(){var V;let O={};g==="custom"&&(O={min:c,max:m,ticks:{stepSize:d}});const D={...t||{},chartOptions:{...t==null?void 0:t.chartOptions,scales:{...(V=t==null?void 0:t.chartOptions)==null?void 0:V.scales,[o]:{type:l,...l==="linear"?O:{}}}},numberAxisFormat:{decimalPlaces:E,suffix:b,currency:k,locale:y}};console.log(D),T(D);const G={...R,preferences:D};u(G)}return e.jsxRuntimeExports.jsxs(e.Popover,{onOpenChange:O=>n(O),children:[e.jsxRuntimeExports.jsx(e.PopoverTrigger,{asChild:!0,children:e.jsxRuntimeExports.jsx(e.SliderIcon,{className:"size-4 cursor-pointer text-muted-foreground hover:text-foreground"})}),e.jsxRuntimeExports.jsx(e.PopoverContent,{align:"center",className:"max-w-65",children:e.jsxRuntimeExports.jsxs("div",{className:"grid gap-4",children:[e.jsxRuntimeExports.jsxs("div",{className:"space-y-2",children:[e.jsxRuntimeExports.jsx("h4",{className:"font-medium leading-none",children:"Scale Options"}),e.jsxRuntimeExports.jsx("p",{className:"text-sm text-muted-foreground",children:"Set the scale for the number axis"})]}),e.jsxRuntimeExports.jsxs("div",{className:"grid gap-2",children:[e.jsxRuntimeExports.jsxs("div",{className:"grid grid-cols-3 items-center gap-2",children:[e.jsxRuntimeExports.jsx(e.Label,{htmlFor:"scale",children:"Type"}),e.jsxRuntimeExports.jsxs(e.Select,{disabled:w,value:l,onValueChange:O=>i(O),children:[e.jsxRuntimeExports.jsx(e.SelectTrigger,{className:"col-span-2 h-8 w-full focus:ring-1 focus:ring-offset-0",children:e.jsxRuntimeExports.jsx(e.SelectValue,{})}),e.jsxRuntimeExports.jsx(e.SelectContent,{id:"type",children:e.jsxRuntimeExports.jsxs(e.SelectGroup,{children:[e.jsxRuntimeExports.jsx(e.SelectLabel,{children:"Option"}),e.jsxRuntimeExports.jsx(e.SelectItem,{value:"linear",children:"Linear"}),e.jsxRuntimeExports.jsx(e.SelectItem,{value:"logarithmic",children:"Logarithmic"})]})})]})]}),l=="linear"&&e.jsxRuntimeExports.jsxs("div",{className:"grid grid-cols-3 items-center gap-2 py-1",children:[e.jsxRuntimeExports.jsx(e.Label,{htmlFor:"scale-option",children:"Setup"}),e.jsxRuntimeExports.jsxs(e.RadioGroup,{disabled:w,id:"scale-option",value:g,onValueChange:O=>j(O),className:"col-span-2 flex gap-3",defaultValue:"x",children:[e.jsxRuntimeExports.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsxRuntimeExports.jsx(e.RadioGroupItem,{value:"auto",id:"r1"}),e.jsxRuntimeExports.jsx("label",{className:"text-sm",htmlFor:"r1",children:"Auto"})]}),e.jsxRuntimeExports.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsxRuntimeExports.jsx(e.RadioGroupItem,{value:"custom",id:"r2"}),e.jsxRuntimeExports.jsx("label",{className:"text-sm",htmlFor:"r2",children:"Custom"})]})]})]}),g==="custom"&&l=="linear"&&q(),M(),e.jsxRuntimeExports.jsx(e.SelectSeparator,{}),e.jsxRuntimeExports.jsx("div",{className:"grid grid-cols-3",children:e.jsxRuntimeExports.jsx(e.Button,{onClick:B,variant:"secondary",className:"col-span-1 col-start-3 h-8 w-full",children:"Apply"})})]})]})})]})}function wt({idx:s}){var c;const n=e.useEditorStore(a=>{var m;return(m=a.card)==null?void 0:m.preferences}),t=e.useEditorStore(a=>{var m;return(m=a.card.preferences)==null?void 0:m.datasetOptions}),r=e.useEditorStore(a=>a.actions.setCardPreferences),o=(c=n==null?void 0:n.chartOptions)==null?void 0:c.indexAxis,l=t==null?void 0:t.find(a=>a.idx===s);function i(a,m){(a==="end"||a==="start")&&e.getContrastColor(e.getCanvasBackgroundColor());const x={display:a!=="none",align:a,anchor:a,clamp:!0};if(!l)r({...n,datasetOptions:[...t||[],{idx:m,datalabels:x}]});else{const g={...l};g.datalabels=x;const j=t==null?void 0:t.map(d=>d.idx===m?g:d);r({...n,datasetOptions:j})}}return e.jsxRuntimeExports.jsxs(e.Popover,{children:[e.jsxRuntimeExports.jsx(e.PopoverTrigger,{children:e.jsxRuntimeExports.jsx(gs,{className:"invisible size-4 rotate-[135deg] cursor-pointer text-muted-foreground hover:text-foreground group-hover:visible"})}),e.jsxRuntimeExports.jsx(e.PopoverContent,{className:"w-fit p-1",children:e.jsxRuntimeExports.jsxs("div",{className:"flex gap-1",children:[e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>i("none",s),size:"sm",variant:"secondary",className:"h-7 p-1 text-xs font-normal",children:e.jsxRuntimeExports.jsx(e.X,{className:"size-4"})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>i("start",s),size:"sm",variant:"secondary",className:"h-7 p-1 text-xs font-normal",children:e.jsxRuntimeExports.jsx(ls,{className:e.cn("h-4 w-4",{"rotate-90":o==="y"})})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>i("center",s),size:"sm",variant:"secondary",className:"h-7 p-1 text-xs font-normal",children:e.jsxRuntimeExports.jsx(xs,{className:e.cn("h-4 w-4",{"rotate-90":o==="y"})})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>i("end",s),size:"sm",variant:"secondary",className:"h-7 p-1 text-xs font-normal",children:e.jsxRuntimeExports.jsx(cs,{className:e.cn("h-4 w-4",{"rotate-90":o==="y"})})})]})})]})}function qs(){const s=e.useEditorStore(m=>m.card),n=e.useEditorStore(m=>{var x,g,j;return(j=(g=(x=m==null?void 0:m.card)==null?void 0:x.preferences)==null?void 0:g.chartOptions)==null?void 0:j.indexAxis}),{data:t}=e.useDashboardCardQuery(s),r=n==="y"?"Y axis":"X axis",o=n==="y"?"X axis":"Y axis",{keys:l,metricKeys:i,dimensionKeys:c}=e.getKeys((t==null?void 0:t.records)||[]);let a=i;if(["stackedBar","stackedLine"].includes(s.type)){const m=e.pivotData({dataArray:(t==null?void 0:t.records)||[],groupKey:c[0],pivotKey:c[1],valueKey:a[0]}),{metricKeys:x}=e.getKeys(m);a=x}return l.length===0?null:e.jsxRuntimeExports.jsxs("div",{className:"space-y-4",children:[e.jsxRuntimeExports.jsxs("div",{className:"space-y-2",children:[e.jsxRuntimeExports.jsx(e.Label,{children:r}),e.jsxRuntimeExports.jsx("div",{className:"my-1 space-y-1",children:e.jsxRuntimeExports.jsx("div",{className:"rounded-md bg-muted/70 px-2 py-1 hover:bg-muted",children:e.jsxRuntimeExports.jsx("p",{children:c[0]})})})]}),e.jsxRuntimeExports.jsxs("div",{className:"space-y-2",children:[e.jsxRuntimeExports.jsxs("div",{className:"flex items-center justify-between gap-5",children:[e.jsxRuntimeExports.jsx(e.Label,{children:o}),e.jsxRuntimeExports.jsx(Vs,{})]}),e.jsxRuntimeExports.jsx("div",{className:"my-1 space-y-1",children:a.map((m,x)=>e.jsxRuntimeExports.jsx(kt,{col:m,idx:x},m))})]})]})}function kt({col:s,idx:n}){const t=e.useEditorStore(c=>{var a;return(a=c.card)==null?void 0:a.preferences}),r=e.useEditorStore(c=>{var a;return(a=c.card.preferences)==null?void 0:a.datasetOptions}),o=r==null?void 0:r.find(c=>c.idx===n),{setCardPreferences:l}=e.useEditorStore(c=>c.actions);function i(c){if(!o)l({...t,datasetOptions:[...r||[],{idx:n,type:c==="area"?"line":c,fill:c==="area"?"origin":""}]});else{const a={...o};a.type=c==="area"?"line":c,a.fill=c==="area"?"origin":"";const m=r==null?void 0:r.map(x=>x.idx===n?a:x);l({...t,datasetOptions:m})}}return e.jsxRuntimeExports.jsxs("div",{className:"group flex items-center justify-between gap-5 rounded-md bg-muted/70 px-2 py-1 hover:bg-muted",children:[e.jsxRuntimeExports.jsx("p",{children:s}),e.jsxRuntimeExports.jsxs("div",{className:"flex gap-2",children:[e.jsxRuntimeExports.jsx(we,{onClick:()=>i("bar"),className:"invisible size-4 cursor-pointer text-muted-foreground hover:text-foreground group-hover:visible"}),e.jsxRuntimeExports.jsx(ke,{onClick:()=>i("line"),className:"invisible size-4 cursor-pointer text-muted-foreground hover:text-foreground group-hover:visible"}),e.jsxRuntimeExports.jsx(Ye,{onClick:()=>i("area"),className:"invisible size-4 cursor-pointer text-muted-foreground hover:text-foreground group-hover:visible"}),e.jsxRuntimeExports.jsx(e.Separator,{orientation:"vertical",className:"invisible size-4 cursor-pointer py-2 text-muted-foreground hover:text-foreground group-hover:visible"}),e.jsxRuntimeExports.jsx(wt,{idx:n})]})]})}function _s(){const s=e.useEditorStore(j=>j.selectedConnectionId),n=e.useEditorStore(j=>j.selectedDatamodelId),t=e.useEditorStore(j=>j.selectedDatabaseName),r=e.useEditorStore(j=>j.selectedSchemaName),o=e.useEditorStore(j=>j.selectedTableName),l=e.useDashboardStore(j=>j.dashboard.filters)||[],i=e.useDashboardStore(j=>j.actions.addFilter),c=e.useDashboardStore(j=>j.actions.removeFilter),a=e.useDashboardStore(j=>j.actions.removeFilterValue),{modelItems:m,tableName:x}=ie();function g(j,d="dashboard"){var C;const h=e.fmt(j.column_name),E=e.fmt(t||""),I=e.fmt(r||""),b=e.fmt(x);let L=e.getQualifiedTableName(I,b),k=`${L}.${h}`;const z=(C=m==null?void 0:m.find(T=>T.id===n))==null?void 0:C.name;n&&n!=="none"&&(k=`${e.DATAMODEL_NAMESPCACE}.${z}.${h}`,L=`${e.DATAMODEL_NAMESPCACE}.${z}`);const y=l==null?void 0:l.find(T=>T.column===k&&T.table===b&&(T.database===E||T.database===t));if(y)a(y.id),c(y.id);else{const T=e.v4();return x==="api"&&s?(i({location:d,id:T,column:k,title:j.column_name,dataType:j.data_type,table:"api",database:"",connectionId:s,operation:"in",sql:e.getDefaultFilterSql(j.data_type,L,h)}),T):(i({id:T,location:d,column:k,title:j.column_name,dataType:j.data_type,table:o||"",database:t||"",connectionId:s||"",operation:"in",sql:e.getDefaultFilterSql(j.data_type,L,h)}),T)}}return{assignFilter:g}}function me(){const s=e.useDashboardStore(c=>c.dashboard.filters),n=e.useEditorStore(c=>c.frame),{setFrame:t}=e.useEditorActions(),{columns:r}=ie(),{assignFilter:o}=_s();function l(c){const a=o(c,"frame");t({...n,filterId:a})}const i=s==null?void 0:s.find(c=>c.id===n.filterId);return e.jsxRuntimeExports.jsxs("div",{className:"space-y-3",children:[e.jsxRuntimeExports.jsx(e.Label,{children:"Card Filter"}),e.jsxRuntimeExports.jsx(It,{onSelect:l,columns:r}),i&&e.jsxRuntimeExports.jsx(e.FilterHeader,{filter:i})]})}function It({columns:s,onSelect:n}){var i;const[t,r]=$e.useState(!1),[o,l]=$e.useState("");return e.jsxRuntimeExports.jsxs(e.Popover,{open:t,onOpenChange:r,children:[e.jsxRuntimeExports.jsx(e.PopoverTrigger,{asChild:!0,children:e.jsxRuntimeExports.jsxs(e.Button,{size:"sm",variant:"outline",role:"combobox","aria-expanded":t,className:"w-full justify-between font-normal",children:[o?(i=s.find(c=>c.column_name===o))==null?void 0:i.column_name:"Select Column...",e.jsxRuntimeExports.jsx(e.CaretSortIcon,{className:"ml-2 h-4 w-4 shrink-0 opacity-50"})]})}),e.jsxRuntimeExports.jsx(e.PopoverContent,{className:"w-[200px] p-0",children:e.jsxRuntimeExports.jsxs(e.Command,{children:[e.jsxRuntimeExports.jsx(e.CommandInput,{placeholder:"Search column",className:"h-9"}),e.jsxRuntimeExports.jsxs(e.CommandList,{children:[e.jsxRuntimeExports.jsx(e.CommandEmpty,{children:"No framework found."}),e.jsxRuntimeExports.jsx(e.CommandGroup,{children:s.map(c=>e.jsxRuntimeExports.jsxs(e.CommandItem,{value:c.column_name,onSelect:a=>{const m=a===o?"":a;l(m),r(!1),m&&n(c)},children:[c.column_name,e.jsxRuntimeExports.jsx(e.CheckIcon,{className:e.cn("ml-auto h-4 w-4",o===c.column_name?"opacity-100":"opacity-0")})]},c.column_name))})]})]})})]})}function Dt({cardType:s}){return e.jsxRuntimeExports.jsx("div",{className:"space-y-6 px-6 py-2",children:e.jsxRuntimeExports.jsxs(e.Accordion,{defaultValue:["item-2"],type:"multiple",children:[e.jsxRuntimeExports.jsxs(e.AccordionItem,{value:"item-1",children:[e.jsxRuntimeExports.jsx(e.AccordionTrigger,{children:`${e.titleCase(s)} Chart`}),e.jsxRuntimeExports.jsxs(e.AccordionContent,{className:"space-y-4 font-mono text-xs",children:[e.jsxRuntimeExports.jsx("div",{className:"rounded bg-muted px-2 py-1 text-xs",children:"SELECT x-axis, y-axis-1, y-axis-2,... FROM table"}),e.jsxRuntimeExports.jsxs("ul",{className:"ml-6 list-disc text-xs [&>li]:mt-2",children:[e.jsxRuntimeExports.jsx("li",{children:"x-axis - category"}),e.jsxRuntimeExports.jsx("li",{children:"y-axis1 - number"}),e.jsxRuntimeExports.jsx("li",{children:"y-axis2 - number"})]}),e.jsxRuntimeExports.jsxs("div",{children:["See ",e.jsxRuntimeExports.jsx("a",{target:"_blank",onClick:n=>n.stopPropagation(),className:"text-blue-700",href:"https://docs.semaphor.cloud/concepts/visuals#line-chart",children:"example"})," in the docs."]})]})]}),e.jsxRuntimeExports.jsxs(e.AccordionItem,{value:"item-2",children:[e.jsxRuntimeExports.jsx(e.AccordionTrigger,{children:"Settings"}),e.jsxRuntimeExports.jsxs(e.AccordionContent,{className:"space-y-4 px-2",children:[e.jsxRuntimeExports.jsx(De,{}),e.jsxRuntimeExports.jsx(qs,{})]})]}),e.jsxRuntimeExports.jsxs(e.AccordionItem,{value:"item-3",children:[e.jsxRuntimeExports.jsx(e.AccordionTrigger,{children:"Filters"}),e.jsxRuntimeExports.jsxs(e.AccordionContent,{className:"space-y-4 px-2",children:[e.jsxRuntimeExports.jsx(ae,{}),e.jsxRuntimeExports.jsx(me,{})]})]})]})})}function Pe(){var o,l,i;const s=e.useEditorStore(c=>c.card.cfg),n=e.useEditorStore(c=>c.actions.setCardCfg),t=e.useEditorStore(c=>c.card.type);function r(c){var x;const a={datalabels:{display:c!=="none",align:c,anchor:c,clamp:!0}},m={...s,options:{...s==null?void 0:s.options,plugins:{...(x=s==null?void 0:s.options)==null?void 0:x.plugins,...a}}};n(m),console.log(c)}return e.jsxRuntimeExports.jsxs("div",{className:"space-y-2",children:[e.jsxRuntimeExports.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxRuntimeExports.jsx("label",{className:"font-medium",children:"Data Labels"}),!["pyramid"].includes(t)&&e.jsxRuntimeExports.jsx(Vs,{})]}),e.jsxRuntimeExports.jsxs(e.Select,{value:(i=(l=(o=s==null?void 0:s.options)==null?void 0:o.plugins)==null?void 0:l.datalabels)==null?void 0:i.anchor,onValueChange:r,defaultValue:"none",children:[e.jsxRuntimeExports.jsx(e.SelectTrigger,{className:"h-8 w-full focus:ring-1 focus:ring-offset-0",children:e.jsxRuntimeExports.jsx(e.SelectValue,{placeholder:"Select position"})}),e.jsxRuntimeExports.jsx(e.SelectContent,{children:e.jsxRuntimeExports.jsxs(e.SelectGroup,{children:[e.jsxRuntimeExports.jsx(e.SelectLabel,{children:"Data Labels"}),e.jsxRuntimeExports.jsx(e.SelectItem,{value:"none",children:"None"}),t!=="pyramid"&&e.jsxRuntimeExports.jsx(e.SelectItem,{value:"start",children:"Start"}),e.jsxRuntimeExports.jsx(e.SelectItem,{value:"center",children:"Center"}),t!=="pyramid"&&e.jsxRuntimeExports.jsx(e.SelectItem,{value:"end",children:"End"})]})})]})]})}function Lt({cardType:s}){function n(t){return e.jsxRuntimeExports.jsxs(e.jsxRuntimeExports.Fragment,{children:[e.jsxRuntimeExports.jsx("div",{className:"rounded bg-muted px-2 py-1 text-xs",children:t==="bubble"?"SELECT label, [group], x-axis, y-axis, radius FROM table":"SELECT label, [group], x-axis, y-axis FROM table"}),e.jsxRuntimeExports.jsxs("ul",{className:"ml-6 list-disc text-xs [&>li]:mt-2",children:[e.jsxRuntimeExports.jsx("li",{children:"label - category"}),e.jsxRuntimeExports.jsx("li",{children:"group - category"}),e.jsxRuntimeExports.jsx("li",{children:"x-axis - category"}),e.jsxRuntimeExports.jsx("li",{children:"y-axis - category"}),t==="bubble"&&e.jsxRuntimeExports.jsx("li",{children:"radius - number"})]}),e.jsxRuntimeExports.jsxs("div",{children:["See ",e.jsxRuntimeExports.jsx("a",{target:"_blank",onClick:l=>l.stopPropagation(),className:"text-blue-700",href:"https://docs.semaphor.cloud/concepts/visuals#pie-chart",children:"example"})," in the docs."]})]})}return e.jsxRuntimeExports.jsx("div",{className:"space-y-6 px-6 py-2",children:e.jsxRuntimeExports.jsxs(e.Accordion,{defaultValue:["item-2"],type:"multiple",children:[e.jsxRuntimeExports.jsxs(e.AccordionItem,{value:"item-1",children:[e.jsxRuntimeExports.jsx(e.AccordionTrigger,{children:`${e.titleCase(s)} Chart`}),e.jsxRuntimeExports.jsx(e.AccordionContent,{className:"space-y-4 font-mono text-xs",children:n(s)})]}),e.jsxRuntimeExports.jsxs(e.AccordionItem,{value:"item-2",children:[e.jsxRuntimeExports.jsx(e.AccordionTrigger,{children:"Settings"}),e.jsxRuntimeExports.jsx(e.AccordionContent,{className:"px-2",children:e.jsxRuntimeExports.jsx(Pe,{})})]}),e.jsxRuntimeExports.jsxs(e.AccordionItem,{value:"item-3",children:[e.jsxRuntimeExports.jsx(e.AccordionTrigger,{children:"Filters"}),e.jsxRuntimeExports.jsxs(e.AccordionContent,{className:"space-y-4 px-2",children:[e.jsxRuntimeExports.jsx(ae,{}),e.jsxRuntimeExports.jsx(me,{})]})]})]})})}const Tt={datasets:[{type:"line",label:"Sum_sales",data:[]},{type:"bar",label:"Sum_profit",data:[]}]},At={datasets:[{fill:"origin",type:"line",label:"Sum_sales",data:[]}]};function Ot(){const s=e.useEditorStore(n=>n.card.type);return e.jsxRuntimeExports.jsxs("div",{className:"space-y-6 p-6",children:[e.jsxRuntimeExports.jsx(e.Accordion,{className:" ",type:"single",collapsible:!0,children:zt(s)}),e.jsxRuntimeExports.jsx("section",{className:"",children:["line","bar"].includes(s)&&e.jsxRuntimeExports.jsx(De,{})}),!["kpi"].includes(s)&&e.jsxRuntimeExports.jsxs("div",{className:"space-y-4",children:[e.jsxRuntimeExports.jsx(Pe,{}),e.jsxRuntimeExports.jsx(ae,{}),e.jsxRuntimeExports.jsx(me,{})]})]})}function zt(s){if(["line","bar"].includes(s))return e.jsxRuntimeExports.jsxs(e.jsxRuntimeExports.Fragment,{children:[e.jsxRuntimeExports.jsxs(e.AccordionItem,{value:"item-1",children:[e.jsxRuntimeExports.jsx(e.AccordionTrigger,{className:"font-normal",children:e.jsxRuntimeExports.jsx("p",{children:"Chart Query"})}),e.jsxRuntimeExports.jsxs(e.AccordionContent,{className:" ",children:[e.jsxRuntimeExports.jsx("div",{className:"rounded bg-muted px-2 py-1 font-mono text-xs font-semibold",children:"SELECT x-axis, y-axis-1, y-axis-2, y-axis-3,... FROM table"}),e.jsxRuntimeExports.jsxs("ul",{className:"my-6 ml-6 list-disc text-xs font-normal [&>li]:mt-2",children:[e.jsxRuntimeExports.jsx("li",{children:"X-axis - Category (ex. city)"}),e.jsxRuntimeExports.jsx("li",{children:"Y-axis - Number (ex. population)"})]})]})]}),e.jsxRuntimeExports.jsxs(e.AccordionItem,{value:"item-2",children:[e.jsxRuntimeExports.jsx(e.AccordionTrigger,{className:"font-normal",children:"Mixed Chart"}),e.jsxRuntimeExports.jsxs(e.AccordionContent,{className:"space-y-2 text-xs",children:[e.jsxRuntimeExports.jsxs("p",{children:["Click ",e.jsxRuntimeExports.jsx("b",{children:"Customize"})," and change the `type` property in the dataset."]}),e.jsxRuntimeExports.jsx("pre",{children:JSON.stringify(Tt,null,2)})]})]}),e.jsxRuntimeExports.jsxs(e.AccordionItem,{value:"item-3",children:[e.jsxRuntimeExports.jsx(e.AccordionTrigger,{className:"font-normal",children:"Area Chart"}),e.jsxRuntimeExports.jsxs(e.AccordionContent,{className:"space-y-2 text-xs",children:[e.jsxRuntimeExports.jsxs("p",{children:["Click ",e.jsxRuntimeExports.jsx("b",{children:"Customize"})," and add `fill` property to the dataset. See",e.jsxRuntimeExports.jsx("a",{className:"mx-1 text-blue-500 hover:underline",href:"https://www.chartjs.org/docs/latest/samples/area/line-boundaries.html",target:"_blank",children:"docs"}),"for more options."]}),e.jsxRuntimeExports.jsx("pre",{children:JSON.stringify(At,null,2)})]})]})]});if(s==="bubble")return e.jsxRuntimeExports.jsx(e.jsxRuntimeExports.Fragment,{children:e.jsxRuntimeExports.jsxs(e.AccordionItem,{value:"item-1",children:[e.jsxRuntimeExports.jsx(e.AccordionTrigger,{className:"font-normal",children:e.jsxRuntimeExports.jsxs("p",{children:["How to create a ",e.jsxRuntimeExports.jsx("span",{children:s})," chart query?"]})}),e.jsxRuntimeExports.jsxs(e.AccordionContent,{className:" ",children:[e.jsxRuntimeExports.jsx("div",{className:"rounded bg-muted px-2 py-1 font-mono text-xs font-semibold",children:"SELECT label, x-axis, y-axis, radius FROM table"}),e.jsxRuntimeExports.jsxs("ul",{className:"my-6 ml-6 list-disc text-xs font-normal [&>li]:mt-2",children:[e.jsxRuntimeExports.jsx("li",{children:"Label - Category (ex. city)"}),e.jsxRuntimeExports.jsx("li",{children:"Bubble Group (opt) - Category (ex. state)"}),e.jsxRuntimeExports.jsx("li",{children:"X-axis - Number (ex. avg. age)"}),e.jsxRuntimeExports.jsx("li",{children:"Y-axis - Number (ex. avg. weight)"}),e.jsxRuntimeExports.jsx("li",{children:"Radius - Number (ex. population)"})]})]})]})});if(s==="scatter")return e.jsxRuntimeExports.jsx(e.jsxRuntimeExports.Fragment,{children:e.jsxRuntimeExports.jsxs(e.AccordionItem,{value:"item-1",children:[e.jsxRuntimeExports.jsx(e.AccordionTrigger,{className:"font-normal",children:e.jsxRuntimeExports.jsxs("p",{children:["How to create a ",e.jsxRuntimeExports.jsx("span",{children:s})," chart query?"]})}),e.jsxRuntimeExports.jsxs(e.AccordionContent,{className:" ",children:[e.jsxRuntimeExports.jsx("div",{className:"rounded bg-muted px-2 py-1 font-mono text-xs font-semibold",children:"SELECT label, x-axis, y-axis FROM table"}),e.jsxRuntimeExports.jsxs("ul",{className:"my-6 ml-6 list-disc text-xs font-normal [&>li]:mt-2",children:[e.jsxRuntimeExports.jsx("li",{children:"Label - Category (ex. city)"}),e.jsxRuntimeExports.jsx("li",{children:"Group (opt) - Category (ex. state)"}),e.jsxRuntimeExports.jsx("li",{children:"X-axis - Number (ex. avg. age)"}),e.jsxRuntimeExports.jsx("li",{children:"Y-axis - Number (ex. avg. weight)"})]})]})]})});if(["pie","doughnut","polarArea"].includes(s))return e.jsxRuntimeExports.jsx(e.jsxRuntimeExports.Fragment,{children:e.jsxRuntimeExports.jsxs(e.AccordionItem,{value:"item-1",children:[e.jsxRuntimeExports.jsx(e.AccordionTrigger,{className:"font-normal",children:e.jsxRuntimeExports.jsxs("p",{children:[e.jsxRuntimeExports.jsx("span",{children:s==="polarArea"?"Polar":s.charAt(0).toUpperCase()+s.slice(1)})," ","chart query"]})}),e.jsxRuntimeExports.jsxs(e.AccordionContent,{className:" ",children:[e.jsxRuntimeExports.jsx("div",{className:"rounded bg-muted px-2 py-1 font-mono text-xs font-semibold",children:"SELECT label, measure FROM table"}),e.jsxRuntimeExports.jsxs("ul",{className:"my-6 ml-6 list-disc text-xs font-normal [&>li]:mt-2",children:[e.jsxRuntimeExports.jsx("li",{children:"Label - Category (ex. city)"}),e.jsxRuntimeExports.jsx("li",{children:"Measure - Number (ex. population)"})]})]})]})})}function Ft(){var a,m,x,g,j;const s=e.useEditorStore(d=>d.card.preferences),n=e.useEditorStore(d=>d.actions.setCardPreferences),t=e.useEditorStore(d=>d.actions.setNumberFormat);e.useEditorStore(d=>{var h,E;return(E=(h=d.card.preferences)==null?void 0:h.formatNumber)==null?void 0:E.decimalPlaces});const r=e.useEditorStore(d=>{var h,E;return(E=(h=d.card.preferences)==null?void 0:h.formatNumber)==null?void 0:E.locale}),o=e.useEditorStore(d=>{var h,E;return(E=(h=d.card.preferences)==null?void 0:h.formatNumber)==null?void 0:E.currency});e.useEditorStore(d=>d.actions.setFilterOnClickField);const l=e.useEditorStore(d=>{var h,E;return(E=(h=d.card.preferences)==null?void 0:h.formatNumber)==null?void 0:E.colorRanges})||[],i=e.useEditorStore(d=>d.actions.setColorRanges),c=[...new Set(e.LOCALE_CURRENCY_PAIRS.map(d=>d.currency))];return e.jsxRuntimeExports.jsxs("div",{children:[e.jsxRuntimeExports.jsxs("div",{className:"mb-3 flex items-center gap-2",children:[e.jsxRuntimeExports.jsx(e.Checkbox,{checked:!!((a=s==null?void 0:s.formatNumber)!=null&&a.enabled),onCheckedChange:d=>{n({...s,formatNumber:{...s==null?void 0:s.formatNumber,enabled:d}})}}),e.jsxRuntimeExports.jsx(e.Label,{children:"Format Number"})]}),((m=s==null?void 0:s.formatNumber)==null?void 0:m.enabled)===!0&&e.jsxRuntimeExports.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsxRuntimeExports.jsx("div",{children:e.jsxRuntimeExports.jsxs("div",{className:"space-y-4 p-2",children:[e.jsxRuntimeExports.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxRuntimeExports.jsxs("div",{className:"w-full space-y-1",children:[e.jsxRuntimeExports.jsx(e.Label,{children:"Locale"}),e.jsxRuntimeExports.jsxs(e.Select,{value:r||"none",onValueChange:d=>{var h,E,I;return t(((h=s==null?void 0:s.formatNumber)==null?void 0:h.decimalPlaces)||0,((E=s==null?void 0:s.formatNumber)==null?void 0:E.currency)||"",d,((I=s==null?void 0:s.formatNumber)==null?void 0:I.suffix)||"")},children:[e.jsxRuntimeExports.jsx(e.SelectTrigger,{className:"col-span-6 h-8 w-full focus:ring-1 focus:ring-offset-0",children:e.jsxRuntimeExports.jsx(e.SelectValue,{})}),e.jsxRuntimeExports.jsx(e.SelectContent,{children:e.jsxRuntimeExports.jsxs(e.SelectGroup,{children:[e.jsxRuntimeExports.jsx(e.SelectLabel,{children:"Format"}),e.jsxRuntimeExports.jsx(e.SelectItem,{value:"none",children:"None"},"none"),e.LOCALE_CURRENCY_PAIRS.map(d=>e.jsxRuntimeExports.jsx(e.SelectItem,{value:d.locale,children:d.locale},d.locale))]})})]})]}),e.jsxRuntimeExports.jsxs("div",{className:"w-full space-y-1",children:[e.jsxRuntimeExports.jsx(e.Label,{children:"Currency"}),e.jsxRuntimeExports.jsxs(e.Select,{value:o||"none",onValueChange:d=>{var h,E,I;console.log("currency",d),t(((h=s==null?void 0:s.formatNumber)==null?void 0:h.decimalPlaces)||0,d==="none"?"":d,((E=s==null?void 0:s.formatNumber)==null?void 0:E.locale)||"",((I=s==null?void 0:s.formatNumber)==null?void 0:I.suffix)||"")},children:[e.jsxRuntimeExports.jsx(e.SelectTrigger,{className:"col-span-6 h-8 w-full focus:ring-1 focus:ring-offset-0",children:e.jsxRuntimeExports.jsx(e.SelectValue,{})}),e.jsxRuntimeExports.jsx(e.SelectContent,{children:e.jsxRuntimeExports.jsxs(e.SelectGroup,{children:[e.jsxRuntimeExports.jsx(e.SelectLabel,{children:"Currency"}),e.jsxRuntimeExports.jsx(e.SelectItem,{value:"none",children:"None"},"none"),c.map(d=>e.jsxRuntimeExports.jsx(e.SelectItem,{value:d,children:d},d))]})})]})]})]}),e.jsxRuntimeExports.jsxs("div",{className:"flex gap-2",children:[e.jsxRuntimeExports.jsxs("div",{className:"w-full space-y-1",children:[e.jsxRuntimeExports.jsx(e.Label,{children:"Decimals"}),e.jsxRuntimeExports.jsxs(e.Select,{value:((g=(x=s==null?void 0:s.formatNumber)==null?void 0:x.decimalPlaces)==null?void 0:g.toString())||"0",onValueChange:d=>{var h,E,I;return t(Number(d),((h=s==null?void 0:s.formatNumber)==null?void 0:h.currency)||"",((E=s==null?void 0:s.formatNumber)==null?void 0:E.locale)||"",((I=s==null?void 0:s.formatNumber)==null?void 0:I.suffix)||"")},children:[e.jsxRuntimeExports.jsx(e.SelectTrigger,{className:"col-span-3 h-8 w-full focus:ring-1 focus:ring-offset-0",children:e.jsxRuntimeExports.jsx(e.SelectValue,{})}),e.jsxRuntimeExports.jsx(e.SelectContent,{children:["0","1","2","3","4"].map(d=>e.jsxRuntimeExports.jsx(e.SelectItem,{value:d,children:d},d))})]})]}),e.jsxRuntimeExports.jsxs("div",{className:"w-full space-y-1",children:[e.jsxRuntimeExports.jsx(e.Label,{children:"Suffix"}),e.jsxRuntimeExports.jsx(e.Input,{value:((j=s==null?void 0:s.formatNumber)==null?void 0:j.suffix)||"",className:"h-8 font-mono text-xs focus-visible:ring-0 focus-visible:ring-ring focus-visible:ring-offset-0",placeholder:"K, M, B, %",onChange:d=>{var h,E,I;return t(((h=s==null?void 0:s.formatNumber)==null?void 0:h.decimalPlaces)||0,((E=s==null?void 0:s.formatNumber)==null?void 0:E.currency)||"",((I=s==null?void 0:s.formatNumber)==null?void 0:I.locale)||"",d.target.value)}})]})]})]})}),e.jsxRuntimeExports.jsx(e.Separator,{className:"my-3"}),e.jsxRuntimeExports.jsx(e.ColorFormat,{colorRanges:l,setColorRanges:i})]})]})}function Mt(){return e.jsxRuntimeExports.jsxs("div",{className:"space-y-6 px-6 py-2",children:[e.jsxRuntimeExports.jsx(e.Accordion,{type:"single",collapsible:!0,children:e.jsxRuntimeExports.jsxs(e.AccordionItem,{value:"item-1",children:[e.jsxRuntimeExports.jsx(e.AccordionTrigger,{className:"",children:"KPI Query"}),e.jsxRuntimeExports.jsxs(e.AccordionContent,{className:"font-mono",children:[e.jsxRuntimeExports.jsx("div",{className:"rounded bg-muted px-2 py-1 font-mono text-xs",children:"SELECT current, previous FROM table"}),e.jsxRuntimeExports.jsxs("ul",{className:"my-6 ml-6 list-disc text-xs [&>li]:mt-2",children:[e.jsxRuntimeExports.jsx("li",{children:"current - number"}),e.jsxRuntimeExports.jsx("li",{children:"previous - number"})]}),e.jsxRuntimeExports.jsxs("div",{children:["See ",e.jsxRuntimeExports.jsx("a",{target:"_blank",onClick:s=>s.stopPropagation(),className:"text-blue-700",href:"https://docs.semaphor.cloud/concepts/visuals#kpi",children:"example"})," in the docs."]})]})]})}),e.jsxRuntimeExports.jsx("section",{className:"",children:e.jsxRuntimeExports.jsx(Ft,{})}),e.jsxRuntimeExports.jsx("div",{}),e.jsxRuntimeExports.jsx("div",{})]})}const Vt=[{label:"Mercator",value:"mercator"},{label:"Azimuthal Equidistant",value:"azimuthalEquidistant"},{label:"Gnomonic",value:"gnomonic"},{label:"Orthographic",value:"orthographic"},{label:"Stereographic",value:"stereographic"},{label:"Equal Earth",value:"equalEarth"},{label:"Albers",value:"albers"},{label:"Albers USA",value:"albersUsa"},{label:"Conic Conformal",value:"conicConformal"},{label:"Conic Equal Area",value:"conicEqualArea"},{label:"Conic Equidistant",value:"conicEquidistant"},{label:"Equirectangular",value:"equirectangular"},{label:"Transverse Mercator",value:"transverseMercator"},{label:"Natural Earth 1",value:"naturalEarth1"}],qt=["blues","brBG","buGn","buPu","cividis","cool","cubehelixDefault","gnBu","greens","greys","inferno","magma","orRd","oranges","pRGn","piYG","plasma","puBu","puBuGn","puOr","puRd","purples","rainbow","rdBu","rdGy","rdPu","rdYlBu","rdYlGn","reds","sinebow","spectral","turbo","viridis","warm","ylGn","ylGnBu","ylOrBr","ylOrRd"],_t=qt.map(s=>({label:s,value:s}));function Bt(){var a,m,x,g,j,d,h,E,I,b,L,k,z,y,C,T,u,R;const s=e.useEditorStore(p=>p.card),n=(m=(a=s==null?void 0:s.preferences)==null?void 0:a.mapVisualOptions)==null?void 0:m.topoJsonUrl,[t,r]=S.useState(((g=(x=s==null?void 0:s.preferences)==null?void 0:x.mapVisualOptions)==null?void 0:g.customTopoJsonUrl)||""),{setCardPreferences:o}=e.useEditorActions(),{data:l}=e.useTopoJson(s),i=Object.keys((l==null?void 0:l.objects)||{}).map(p=>({label:p,value:p}))||[],c=[{label:"US States 10m",value:"https://unpkg.com/us-atlas/states-10m.json"},{label:"Countries 50m",value:"https://unpkg.com/world-atlas/countries-50m.json"},{label:"Custom",value:"custom"}];return e.jsxRuntimeExports.jsxs("div",{className:"p-6",children:[e.jsxRuntimeExports.jsx(fe,{summary:"Map Query",children:e.jsxRuntimeExports.jsx("p",{className:"rounded-md bg-muted p-2 font-mono text-xs",children:"SELECT country, value FROM table"})}),e.jsxRuntimeExports.jsx(e.Separator,{className:"my-4"}),e.jsxRuntimeExports.jsx(fe,{open:!0,summary:"Settings",children:e.jsxRuntimeExports.jsxs("div",{className:"space-y-3 px-2",children:[e.jsxRuntimeExports.jsx(Z,{className:"h-9",options:c,onValueChange:p=>{console.log("value",p),o({...s.preferences,mapVisualOptions:{topoJsonUrl:p}})},value:n||"",label:"Select Map"}),n==="custom"&&e.jsxRuntimeExports.jsx(e.Input,{onChange:p=>{r(p.target.value)},onBlur:()=>{var p;console.log("onBlur",t),o({...s.preferences,mapVisualOptions:{...(p=s.preferences)==null?void 0:p.mapVisualOptions,customTopoJsonUrl:t}})},value:t,className:`h-9 w-full ${e.removeRing}`,placeholder:"Custom URL"}),l&&e.jsxRuntimeExports.jsxs(e.jsxRuntimeExports.Fragment,{children:[e.jsxRuntimeExports.jsxs("div",{className:"space-y-1",children:[e.jsxRuntimeExports.jsx(e.Label,{children:"Map Object"}),e.jsxRuntimeExports.jsx(Z,{className:"h-9",options:i,value:((d=(j=s.preferences)==null?void 0:j.mapVisualOptions)==null?void 0:d.objectKey)||"",label:"Map Object",onValueChange:p=>{var w;o({...s.preferences,mapVisualOptions:{...(w=s.preferences)==null?void 0:w.mapVisualOptions,objectKey:p}})}})]}),e.jsxRuntimeExports.jsxs("div",{className:"space-y-1",children:[e.jsxRuntimeExports.jsx(e.Label,{children:"Projection"}),e.jsxRuntimeExports.jsx(Z,{className:"h-9",options:Vt,value:((E=(h=s.preferences)==null?void 0:h.mapVisualOptions)==null?void 0:E.projection)||"",label:"Projection",onValueChange:p=>{var w;o({...s.preferences,mapVisualOptions:{...(w=s.preferences)==null?void 0:w.mapVisualOptions,projection:p}})}})]}),e.jsxRuntimeExports.jsxs("div",{className:"space-y-1",children:[e.jsxRuntimeExports.jsx(e.Label,{children:"Colors"}),e.jsxRuntimeExports.jsx(Z,{className:"h-9",options:_t,value:((b=(I=s.preferences)==null?void 0:I.mapVisualOptions)==null?void 0:b.colorScale)||"",label:"Select Color Scale",onValueChange:p=>{var w;o({...s.preferences,mapVisualOptions:{...(w=s.preferences)==null?void 0:w.mapVisualOptions,colorScale:p}})}})]})]})]})}),e.jsxRuntimeExports.jsx(e.Separator,{className:"my-4"}),e.jsxRuntimeExports.jsx(fe,{className:"",summary:"Scale Options",children:e.jsxRuntimeExports.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxRuntimeExports.jsx(e.Input,{className:`h-9 w-full ${e.removeRing}`,type:"number",step:.1,value:((k=(L=s.preferences)==null?void 0:L.mapVisualOptions)==null?void 0:k.projectionScale)||1,onChange:p=>{var w;o({...s.preferences,mapVisualOptions:{...(w=s.preferences)==null?void 0:w.mapVisualOptions,projectionScale:Number(p.target.value)}})}}),e.jsxRuntimeExports.jsx(e.Label,{children:"X"}),e.jsxRuntimeExports.jsx(e.Input,{className:`h-9 w-full ${e.removeRing}`,type:"number",step:10,value:((C=(y=(z=s.preferences)==null?void 0:z.mapVisualOptions)==null?void 0:y.projectionOffset)==null?void 0:C[0])||0,onChange:p=>{var w,A,M,q;o({...s.preferences,mapVisualOptions:{...(w=s.preferences)==null?void 0:w.mapVisualOptions,projectionOffset:[Number(p.target.value),((q=(M=(A=s.preferences)==null?void 0:A.mapVisualOptions)==null?void 0:M.projectionOffset)==null?void 0:q[1])||0]}})}}),e.jsxRuntimeExports.jsx(e.Label,{children:"Y"}),e.jsxRuntimeExports.jsx(e.Input,{className:`h-9 w-full ${e.removeRing}`,type:"number",step:10,value:((R=(u=(T=s.preferences)==null?void 0:T.mapVisualOptions)==null?void 0:u.projectionOffset)==null?void 0:R[1])||0,onChange:p=>{var w,A,M,q;o({...s.preferences,mapVisualOptions:{...(w=s.preferences)==null?void 0:w.mapVisualOptions,projectionOffset:[((q=(M=(A=s.preferences)==null?void 0:A.mapVisualOptions)==null?void 0:M.projectionOffset)==null?void 0:q[0])||0,Number(p.target.value)]}})}})]})}),e.jsxRuntimeExports.jsx(e.Separator,{className:"my-4"}),e.jsxRuntimeExports.jsx(ae,{})]})}function Ht(){var r;const s=e.useEditorStore(o=>o.card.preferences),{setCardPreferences:n}=e.useEditorStore(o=>o.actions);function t(o){n({...s,textVisualOptions:{...s==null?void 0:s.textVisualOptions,isDynamicText:o==="dynamic"}})}return e.jsxRuntimeExports.jsxs(e.RadioGroup,{value:(r=s==null?void 0:s.textVisualOptions)!=null&&r.isDynamicText?"dynamic":"static",onValueChange:t,className:"flex gap-3",defaultValue:"x",children:[e.jsxRuntimeExports.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsxRuntimeExports.jsx(e.RadioGroupItem,{value:"static",id:"r1"}),e.jsxRuntimeExports.jsx("label",{className:"text-sm",htmlFor:"r1",children:"Static"})]}),e.jsxRuntimeExports.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsxRuntimeExports.jsx(e.RadioGroupItem,{value:"dynamic",id:"r2"}),e.jsxRuntimeExports.jsx("label",{className:"text-sm",htmlFor:"r2",children:"Dynamic"})]})]})}function Se({cardType:s,docContent:n,suffix:t="Chart"}){return e.jsxRuntimeExports.jsx("div",{className:"space-y-6 px-6 py-2",children:e.jsxRuntimeExports.jsxs(e.Accordion,{defaultValue:["item-2"],type:"multiple",children:[e.jsxRuntimeExports.jsxs(e.AccordionItem,{value:"item-1",children:[e.jsxRuntimeExports.jsx(e.AccordionTrigger,{children:`${e.titleCase(s)} ${t}`}),e.jsxRuntimeExports.jsx(e.AccordionContent,{children:n||e.jsxRuntimeExports.jsxs("div",{className:"space-y-4 font-mono text-xs",children:[e.jsxRuntimeExports.jsx("div",{className:"rounded bg-muted px-2 py-1 text-xs",children:"SELECT label, measure FROM table"}),e.jsxRuntimeExports.jsxs("ul",{className:"ml-6 list-disc text-xs [&>li]:mt-2",children:[e.jsxRuntimeExports.jsx("li",{children:"label - category"}),e.jsxRuntimeExports.jsx("li",{children:"measure - number"})]}),e.jsxRuntimeExports.jsxs("div",{children:["See ",e.jsxRuntimeExports.jsx("a",{target:"_blank",onClick:r=>r.stopPropagation(),className:"text-blue-700",href:"https://docs.semaphor.cloud/concepts/visuals#pie-chart",children:"example"})," in the docs."]})]})})]}),e.jsxRuntimeExports.jsxs(e.AccordionItem,{value:"item-2",children:[e.jsxRuntimeExports.jsx(e.AccordionTrigger,{children:"Settings"}),e.jsxRuntimeExports.jsxs(e.AccordionContent,{className:"space-y-4 px-2",children:[s==="range"&&e.jsxRuntimeExports.jsx(De,{}),s!=="text"&&e.jsxRuntimeExports.jsx(Pe,{}),s==="text"&&e.jsxRuntimeExports.jsx(Ht,{})]})]}),!["range","text"].includes(s)&&e.jsxRuntimeExports.jsxs(e.AccordionItem,{value:"item-3",children:[e.jsxRuntimeExports.jsx(e.AccordionTrigger,{children:"Filters"}),e.jsxRuntimeExports.jsxs(e.AccordionContent,{className:"space-y-4 px-2",children:[e.jsxRuntimeExports.jsx(ae,{}),e.jsxRuntimeExports.jsx(me,{})]})]})]})})}function Pt(){const s=e.useEditorStore(r=>{var o,l;return(l=(o=r==null?void 0:r.card)==null?void 0:o.preferences)==null?void 0:l.sortChart}),{setSortChart:n}=e.useEditorActions();function t(){return e.jsxRuntimeExports.jsxs("div",{className:"space-y-2",children:[e.jsxRuntimeExports.jsx(e.Label,{children:"Sort"}),e.jsxRuntimeExports.jsx(Z,{className:"h-8",label:"Sort Chart",options:[{label:"None",value:"none"},{label:"ASC",value:"asc"},{label:"DESC",value:"desc"}],value:s||"none",onValueChange:r=>{n(r)}})]})}return e.jsxRuntimeExports.jsx("div",{className:"space-y-6 px-6 py-2",children:e.jsxRuntimeExports.jsxs(e.Accordion,{defaultValue:["item-2"],type:"multiple",children:[e.jsxRuntimeExports.jsxs(e.AccordionItem,{value:"item-1",children:[e.jsxRuntimeExports.jsx(e.AccordionTrigger,{children:"Stacked Chart"}),e.jsxRuntimeExports.jsxs(e.AccordionContent,{className:"space-y-4 font-mono text-xs",children:[e.jsxRuntimeExports.jsx("div",{className:"rounded bg-muted px-2 py-1 text-xs",children:"SELECT x-axis, stack-by, y-axis FROM table"}),e.jsxRuntimeExports.jsxs("ul",{className:"ml-6 list-disc text-xs [&>li]:mt-2",children:[e.jsxRuntimeExports.jsx("li",{children:"x-axis - category"}),e.jsxRuntimeExports.jsx("li",{children:"stack by - category"}),e.jsxRuntimeExports.jsx("li",{children:"y-axis - number"})]}),e.jsxRuntimeExports.jsxs("div",{children:["See ",e.jsxRuntimeExports.jsx("a",{target:"_blank",onClick:r=>r.stopPropagation(),className:"text-blue-700",href:"https://docs.semaphor.cloud/concepts/visuals#stacked-chart",children:"example"})," in the docs."]})]})]}),e.jsxRuntimeExports.jsxs(e.AccordionItem,{value:"item-2",children:[e.jsxRuntimeExports.jsx(e.AccordionTrigger,{children:"Settings"}),e.jsxRuntimeExports.jsxs(e.AccordionContent,{className:"space-y-4 px-2",children:[e.jsxRuntimeExports.jsx(De,{}),t(),e.jsxRuntimeExports.jsx(qs,{})]})]}),e.jsxRuntimeExports.jsxs(e.AccordionItem,{value:"item-3",children:[e.jsxRuntimeExports.jsx(e.AccordionTrigger,{children:"Filters"}),e.jsxRuntimeExports.jsxs(e.AccordionContent,{className:"space-y-4 px-2",children:[e.jsxRuntimeExports.jsx(ae,{}),e.jsxRuntimeExports.jsx(me,{})]})]})]})})}function Gt({}){const s=e.useEditorStore(r=>{var o;return(o=r.card)==null?void 0:o.preferences}),n=e.useEditorStore(r=>r.actions.setCardPreferences),t=r=>{n({...s,allowDownload:r})};return e.jsxRuntimeExports.jsxs("div",{className:"space-y-6 px-6 py-2",children:[e.jsxRuntimeExports.jsx(e.Accordion,{defaultValue:["item-3"],type:"multiple",children:e.jsxRuntimeExports.jsxs(e.AccordionItem,{value:"item-3",children:[e.jsxRuntimeExports.jsx(e.AccordionTrigger,{children:"Filters"}),e.jsxRuntimeExports.jsxs(e.AccordionContent,{className:"space-y-4 px-2",children:[e.jsxRuntimeExports.jsx(ae,{}),e.jsxRuntimeExports.jsx(me,{})]})]})}),e.jsxRuntimeExports.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsxRuntimeExports.jsx(e.Checkbox,{onCheckedChange:t,id:"allow-download"}),e.jsxRuntimeExports.jsx("label",{htmlFor:"allow-download",className:"text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70",children:"Allow Download"})]})]})}const $t=e.jsxRuntimeExports.jsxs("div",{className:"space-y-4 font-mono text-xs",children:[e.jsxRuntimeExports.jsx("div",{className:"rounded bg-muted px-2 py-1 text-xs",children:"SELECT dimension, cohort, metric FROM table"}),e.jsxRuntimeExports.jsxs("div",{children:["See ",e.jsxRuntimeExports.jsx("a",{target:"_blank",onClick:s=>s.stopPropagation(),className:"text-blue-700",href:"https://docs.semaphor.cloud/concepts/visuals#pyramid-chart",children:"example"})," in the docs."]})]}),Qt=e.jsxRuntimeExports.jsxs("div",{className:"space-y-4 font-mono text-xs",children:[e.jsxRuntimeExports.jsx("div",{className:"rounded bg-muted px-2 py-1 text-xs",children:"SELECT y-axis, label, range-from, range-to, range-value FROM table"}),e.jsxRuntimeExports.jsxs("div",{children:["See ",e.jsxRuntimeExports.jsx("a",{target:"_blank",onClick:s=>s.stopPropagation(),className:"text-blue-700",href:"https://docs.semaphor.cloud/concepts/visuals#range-charts",children:"example"})," in the docs."]})]}),Ut=e.jsxRuntimeExports.jsxs("div",{className:"space-y-4 font-mono text-xs",children:[e.jsxRuntimeExports.jsx("div",{className:"rounded bg-muted px-2 py-1 text-xs",children:"SELECT text FROM table limit 1"}),e.jsxRuntimeExports.jsxs("div",{children:["See ",e.jsxRuntimeExports.jsx("a",{target:"_blank",onClick:s=>s.stopPropagation(),className:"text-blue-700",href:"https://docs.semaphor.cloud/concepts/visuals#text-visual",children:"example"})," in the docs."]})]});function Kt(){const s=e.useEditorStore(t=>t.card.type);function n(t){switch(t){case"stackedBar":case"stackedLine":return e.jsxRuntimeExports.jsx(Pt,{});case"pyramid":return e.jsxRuntimeExports.jsx(Se,{docContent:$t,cardType:t});case"kpi":return e.jsxRuntimeExports.jsx(Mt,{});case"line":case"bar":return e.jsxRuntimeExports.jsx(Dt,{cardType:t});case"range":return e.jsxRuntimeExports.jsx(Se,{docContent:Qt,cardType:t});case"pie":case"doughnut":case"polarArea":case"radar":return e.jsxRuntimeExports.jsx(Se,{cardType:t});case"bubble":case"scatter":return e.jsxRuntimeExports.jsx(Lt,{cardType:t});case"table":return e.jsxRuntimeExports.jsx(Gt,{cardType:t});case"text":return e.jsxRuntimeExports.jsx(Se,{docContent:Ut,cardType:t,suffix:"Visual"});case"map":return e.jsxRuntimeExports.jsx(Bt,{});case"custom":return e.jsxRuntimeExports.jsx(Nt,{});default:return e.jsxRuntimeExports.jsx(Ot,{})}}return e.jsxRuntimeExports.jsx(e.ScrollArea,{className:"h-full w-full text-sm",children:n(s)})}function Jt(){const s=e.useEditorStore(n=>n.isShowingVisual);return e.jsxRuntimeExports.jsxs(e.ResizablePanelGroup,{direction:"vertical",className:"min-h-[250px] min-w-full max-w-lg",children:[e.jsxRuntimeExports.jsx(e.ResizablePanel,{role:"query-section",className:"flex",minSize:20,defaultSize:40,children:e.jsxRuntimeExports.jsx(pt,{})}),e.jsxRuntimeExports.jsx(e.ResizableHandle,{withHandle:!0,className:"border"}),e.jsxRuntimeExports.jsx(e.ResizablePanel,{className:"pb-1",role:"visual-section",minSize:0,defaultSize:60,children:s?e.jsxRuntimeExports.jsxs(e.ResizablePanelGroup,{direction:"horizontal",children:[e.jsxRuntimeExports.jsx(e.jsxRuntimeExports.Fragment,{children:e.jsxRuntimeExports.jsx(e.ResizablePanel,{className:"flex min-w-[275px]",minSize:20,defaultSize:25,maxSize:30,children:e.jsxRuntimeExports.jsx(Kt,{})})}),e.jsxRuntimeExports.jsx(e.ResizableHandle,{className:"border"}),e.jsxRuntimeExports.jsx(e.ResizablePanel,{minSize:40,defaultSize:75,maxSize:100,children:e.jsxRuntimeExports.jsx(Ke,{})})]}):e.jsxRuntimeExports.jsx(Ke,{})})]})}function Wt({authToken:s,onSave:n,onClose:t}){e.useDashboardStore(i=>i.themeStyle);const r=e.useEditorStore(i=>i.actions.setOnSave),o=e.useEditorStore(i=>i.actions.setOnClose),l=e.useDashboardStore(i=>i.actions.setAuthToken);return S.useEffect(()=>{n&&r(n),t&&o(t)},[n,r,t,o]),S.useEffect(()=>{s&&s.accessToken&&l(s)},[s,l]),e.jsxRuntimeExports.jsx(e.ErrorBoundary,{FallbackComponent:e.Fallback,children:e.jsxRuntimeExports.jsxs(e.EditorPanel,{style:{},className:"rounded-none",role:"editor-panel",children:[e.jsxRuntimeExports.jsx(e.EditorAside,{className:"rounded-none border-r-[1.5px]",children:e.jsxRuntimeExports.jsx(Ss,{})}),e.jsxRuntimeExports.jsx(e.EditorMain,{children:e.jsxRuntimeExports.jsx(Jt,{})})]})})}function Yt(){e.useDashboardStore(i=>i.selectedCardId);const s=e.useDashboardStore(i=>i.selectedSheetId),{setIsVisualEditing:n}=e.useDashboardStore(i=>i.actions),t=e.useDashboardStore(i=>i.isVisualEditing),r=e.useDashboardStore(i=>i.actions.updateFrame);function o(i){s&&(r(s,i),n(!1))}function l(){n(!1)}return e.jsxRuntimeExports.jsx("div",{role:"editor-container",className:e.cn("flex grow",{"max-h-0 overflow-hidden":!t}),children:e.jsxRuntimeExports.jsx(Wt,{onSave:o,onClose:l})})}function Xt(){e.useEditorStore(i=>i.selectedConnectionId),e.useEditorStore(i=>i.selectedDatamodelId);const s=e.useEditorStore(i=>i.selectedDatabaseName);e.useEditorStore(i=>i.selectedSchemaName);const n=e.useEditorStore(i=>i.selectedTableName),t=e.useDashboardStore(i=>i.dashboard.filters)||[];e.useDashboardStore(i=>i.actions.addFilter),e.useDashboardStore(i=>i.actions.removeFilter),e.useDashboardStore(i=>i.actions.removeFilterValue);const{modelItems:r,columns:o}=ie(),{assignFilter:l}=_s();return e.jsxRuntimeExports.jsx("div",{className:"xbg-red-100 flex-1 basis-0 flex-col overflow-scroll px-3",children:o==null?void 0:o.map(i=>{const c=t==null?void 0:t.find(a=>a.column===e.fmt(i.column_name)&&a.table===n&&a.database===s);return e.jsxRuntimeExports.jsx("div",{onClick:()=>l(i),className:e.cn("group flex cursor-pointer items-center justify-between border border-dashed border-background px-3 py-[6px] text-sm transition-colors hover:bg-muted/50",{"bg-muted":c}),children:e.jsxRuntimeExports.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxRuntimeExports.jsx(vs,{column:i}),e.jsxRuntimeExports.jsx("span",{children:i.column_name})]})},i.column_name)})})}function Zt(){e.useDashboardStore(n=>n.showFilters);const s=e.useDashboardStore(n=>n.actions.setShowFilters);return e.jsxRuntimeExports.jsxs("section",{className:"relative flex grow flex-col border-l px-4",children:[e.jsxRuntimeExports.jsxs("div",{className:"mt-4 flex items-center justify-between gap-2 px-3",children:[e.jsxRuntimeExports.jsx(e.Label,{className:"text-lg",children:"Filters"}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>s(!1),className:"h-7 w-7 p-0",variant:"ghost",children:e.jsxRuntimeExports.jsx(e.Cross2Icon,{})})]}),e.jsxRuntimeExports.jsx("div",{className:"flex grow",children:e.jsxRuntimeExports.jsx(Ss,{ColumnsComponent:()=>e.jsxRuntimeExports.jsx(Xt,{})})})]})}function en(){const s=e.useDashboardStore(t=>t.showFilters),n=e.useDashboardStore(t=>t.isVisualEditing);return e.jsxRuntimeExports.jsxs("div",{role:"dashboard-plus-main",className:e.cn("",{"max-h-0 overflow-hidden":n,"flex grow":!n}),children:[e.jsxRuntimeExports.jsx(e.DashboardTabs,{}),s&&e.jsxRuntimeExports.jsx("div",{role:"filter-aside-container",className:"flex",children:e.jsxRuntimeExports.jsx(Zt,{})})]})}function sn(){const s=e.useDashboardStore(r=>r.dashboard),n=e.useDashboardStore(r=>r.actions.setDashboard),t=e.useDashboardStore(r=>r.showDashboardJSON);return e.useDashboardStore(r=>r.actions.setShowDashboardJSON),e.jsxRuntimeExports.jsx("div",{className:e.cn(" p-2",{hidden:!t}),children:e.jsxRuntimeExports.jsx(e.de,{onChange:r=>{if(r)try{JSON.parse(r),n(JSON.parse(r))}catch{}},defaultLanguage:"json",className:"h-[550px] overflow-y-auto ",value:JSON.stringify(s,null,2),options:{minimap:{enabled:!1},glyphMargin:!1,wordWrap:"on",scrollbar:{verticalScrollbarSize:0,horizontalScrollbarSize:0},fontSize:12,renderLineHighlight:"none"}})})}function tn({showControls:s=!1,showFooter:n=!0,...t}){return e.jsxRuntimeExports.jsx(e.ErrorBoundary,{FallbackComponent:e.Fallback,children:e.jsxRuntimeExports.jsxs(e.SemaphorContextProvider,{dashboardProps:t,children:[e.jsxRuntimeExports.jsx(e.Oe,{}),e.jsxRuntimeExports.jsxs(e.UXProvider,{children:[e.jsxRuntimeExports.jsx(sn,{}),e.jsxRuntimeExports.jsxs(e.DashboardPanel,{...t,children:[s&&e.jsxRuntimeExports.jsx(Ws,{}),e.jsxRuntimeExports.jsx(Yt,{}),e.jsxRuntimeExports.jsx(en,{})]})]})]})})}exports.Box=We;exports.ChartArea=Ye;exports.ChartColumnIncreasing=we;exports.ChartLine=ke;exports.ChartNoAxesGantt=Oe;exports.ChartPie=ze;exports.ChartScatter=Fe;exports.CircleX=Xe;exports.CopyPlus=Ze;exports.DashboardPlus=tn;exports.Database=es;exports.EllipsisVertical=Me;exports.Eraser=ss;exports.Eye=ns;exports.EyeClosed=ts;exports.Glasses=rs;exports.Hammer=os;exports.Hash=is;exports.House=as;exports.Key=Ve;exports.ListEnd=ls;exports.ListStart=cs;exports.ListX=xs;exports.LoaderCircle=de;exports.Map=qe;exports.MessageSquareMore=us;exports.Network=ds;exports.Pencil=_e;exports.Play=ms;exports.Plug2=ps;exports.Save=js;exports.SelectComponent=ue;exports.Shapes=Be;exports.ShieldQuestion=hs;exports.Sigma=Es;exports.SwatchBook=fs;exports.Tag=gs;exports.ToggleLeft=Rs;exports.Type=Ie;exports.User=bs;exports.cleanCard=ys;exports.getDashbaordStateWithoutData=He;exports.useEditorAside=ie;