react-semaphor 0.0.290 → 0.0.291

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-CGIUYFBx.js"),S=require("react");require("react-dom");function Gs(s){const r=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(s){for(const t in s)if(t!=="default"){const n=Object.getOwnPropertyDescriptor(s,t);Object.defineProperty(r,t,n.get?n:{enumerable:!0,get:()=>s[t]})}}return r.default=s,Object.freeze(r)}const Ge=Gs(S);/**
1
+ "use strict";const e=require("./index-j6u8TMrb.js"),S=require("react");require("react-dom");function Gs(s){const r=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(s){for(const t in s)if(t!=="default"){const n=Object.getOwnPropertyDescriptor(s,t);Object.defineProperty(r,t,n.get?n:{enumerable:!0,get:()=>s[t]})}}return r.default=s,Object.freeze(r)}const Ge=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(k=>`${k.column_name} | ${k.data_type}`).join(", ")}
243
243
  User SQL: ${C}
244
244
  ${f&&`Base Queries: ${JSON.stringify(f)} `}`,D=` 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: ${ot}`,{data:m,isLoading:N,isFetching:E,isError:j,refetch:I}=e.useQuery({queryKey:["ai-query"],queryFn:()=>e.getRequest("https://semaphor.cloud/api/v1/ai",(l==null?void 0:l.accessToken)||"",{user_content:`userContent: ${v} ${x?D:""}`}),enabled:!1});function O(k){if(k.toLowerCase().includes("bar"))p("bar");else if(k.toLowerCase().includes("line"))p("line");else if(k.toLowerCase().includes("bubble"))p("bubble");else if(k.toLowerCase().includes("scatter"))p("scatter");else if(k.toLowerCase().includes("stacked"))p("stackedBar");else if(k.toLowerCase().includes("pie"))p("pie");else if(k.toLowerCase().includes("donut")||k.toLowerCase().includes("doughnut"))p("doughnut");else if(k.toLowerCase().includes("radar"))p("radar");else return p("bar"),!1;return!0}S.useEffect(()=>{m&&L(k=>[...k,{role:"ai",content:m.response}])},[m]),S.useEffect(()=>{const k=setTimeout(()=>{var F;c.current&&(c.current.scroll({top:c.current.scrollHeight,behavior:"smooth"}),(F=i.current)==null||F.focus())},100);return()=>clearTimeout(k)},[R]);function z(){t&&(L(k=>[...k,{role:"user",content:t}]),O(t)&&d(!0),n(""),I())}S.useEffect(()=>{o&&(z(),a(!1))},[o,a]);const M={fontFamily:"Arial, sans-serif",lineHeight:1.6,fontSize:15,width:"100%"},q={fontFamily:"monospace",fontSize:14,lineHeight:1.6},H={fontFamily:"Arial, sans-serif",lineHeight:1.6,fontSize:15,padding:"2px 0",marginLeft:20,listStyleType:"disc"},U={p:({node:k,...F})=>e.jsxRuntimeExports.jsx("p",{style:M,...F}),code:({node:k,...F})=>e.jsxRuntimeExports.jsx("code",{className:"rounded-sm bg-muted px-2 py-1 text-sm",...F}),pre:({node:k,...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:B=>{const A=_(B);A&&(r(!1),g(A),u(!0))},size:"sm",variant:"outline",children:e.jsxRuntimeExports.jsx(e.PlayIcon,{})})]})]}),li:({node:k,...F})=>e.jsxRuntimeExports.jsx("li",{style:H,...F})};function _(k){const F=k.currentTarget.closest("pre");if(!F)return;const B=F.textContent||F.innerText;return navigator.clipboard.writeText(B).then(()=>console.log("Text copied to clipboard")).catch(A=>console.error("Error in copying text: ",A)),B}function W(){return R==null?void 0:R.map((k,F)=>k.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:k.content})]},F):k.role==="ai"?e.jsxRuntimeExports.jsx(e.Markdown,{className:"w-full overflow-auto py-1",components:U,children:m==null?void 0:m.response.replace(/DuckDB/gi,"Semaphor")},F):e.jsxRuntimeExports.jsx("div",{},F))}return e.jsxRuntimeExports.jsxs(e.Dialog,{open:s,onOpenChange:r,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:W()})}),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:k=>{k.key==="Enter"&&!k.shiftKey&&(k.preventDefault(),n(""),z())},placeholder:"Type your question here...",onFocus:k=>{const F=k.target,B=F.value.length;F.setSelectionRange(B,B)},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:N||E,value:t,onChange:k=>n(k.target.value)})," ",e.jsxRuntimeExports.jsx(e.Button,{className:"h-8",size:"sm",variant:"ghost",onClick:z,children:!N&&!E?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},Ue=S.createContext&&S.createContext(Cs),at=["attr","size","title"];function lt(s,r){if(s==null)return{};var t=ct(s,r),n,o;if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(s);for(o=0;o<a.length;o++)n=a[o],!(r.indexOf(n)>=0)&&Object.prototype.propertyIsEnumerable.call(s,n)&&(t[n]=s[n])}return t}function ct(s,r){if(s==null)return{};var t={},n=Object.keys(s),o,a;for(a=0;a<n.length;a++)o=n[a],!(r.indexOf(o)>=0)&&(t[o]=s[o]);return t}function Ce(){return Ce=Object.assign?Object.assign.bind():function(s){for(var r=1;r<arguments.length;r++){var t=arguments[r];for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(s[n]=t[n])}return s},Ce.apply(this,arguments)}function Qe(s,r){var t=Object.keys(s);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(s);r&&(n=n.filter(function(o){return Object.getOwnPropertyDescriptor(s,o).enumerable})),t.push.apply(t,n)}return t}function Ne(s){for(var r=1;r<arguments.length;r++){var t=arguments[r]!=null?arguments[r]:{};r%2?Qe(Object(t),!0).forEach(function(n){xt(s,n,t[n])}):Object.getOwnPropertyDescriptors?Object.defineProperties(s,Object.getOwnPropertyDescriptors(t)):Qe(Object(t)).forEach(function(n){Object.defineProperty(s,n,Object.getOwnPropertyDescriptor(t,n))})}return s}function xt(s,r,t){return r=ut(r),r in s?Object.defineProperty(s,r,{value:t,enumerable:!0,configurable:!0,writable:!0}):s[r]=t,s}function ut(s){var r=dt(s,"string");return typeof r=="symbol"?r:String(r)}function dt(s,r){if(typeof s!="object"||s===null)return s;var t=s[Symbol.toPrimitive];if(t!==void 0){var n=t.call(s,r||"default");if(typeof n!="object")return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return(r==="string"?String:Number)(s)}function Ns(s){return s&&s.map((r,t)=>S.createElement(r.tag,Ne({key:t},r.attr),Ns(r.child)))}function ee(s){return r=>S.createElement(mt,Ce({attr:Ne({},s.attr)},r),Ns(s.child))}function mt(s){var r=t=>{var{attr:n,size:o,title:a}=s,i=lt(s,at),c=o||t.size||"1em",l;return t.className&&(l=t.className),s.className&&(l=(l?l+" ":"")+s.className),S.createElement("svg",Ce({stroke:"currentColor",fill:"currentColor",strokeWidth:"0"},t.attr,n,i,{className:l,style:Ne(Ne({color:s.color||t.color},t.style),s.style),height:c,width:c,xmlns:"http://www.w3.org/2000/svg"}),a&&S.createElement("title",null,a),s.children)};return Ue!==void 0?S.createElement(Ue.Consumer,null,t=>r(t)):r(Cs)}function pt(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 jt(){const{theme:s}=e.useTheme(),r=S.useRef(),t=S.useRef(),[n,o]=S.useState(!1),[a,i]=S.useState(!1),[c,l]=S.useState(!1),[x,d]=S.useState(""),[g,f]=S.useState(!1),{authToken:u}=e.useSemaphorContext(),p=e.useDashboardStore(h=>h.selectedSheetId),R=e.useDashboardStore(h=>h.dashboard.baseQueries),L=e.useEditorStore(h=>h.card),b=e.useDashboardStore(h=>h.theme),C=e.useEditorStore(h=>h.isShowingVisual);e.useDashboardStore(h=>h.onAcceptChanges);const w=e.useEditorStore(h=>h.selectedConnectionId),v=e.useEditorStore(h=>h.selectedDatabaseName),D=e.useEditorStore(h=>h.selectedDatamodelId),m=e.useEditorStore(h=>h.selectedSchemaName);e.useDashboardStore(h=>h.actions.updateFrameCard);const N=e.useEditorStore(h=>h.selectedTableName),E=e.useEditorStore(h=>h.card.sql),j=e.useEditorStore(h=>h.card.python),I=e.resolveBaseQuery(E,R),O=e.useEditorStore(h=>h.selectedConnectionId),z=e.useEditorStore(h=>h.frame),M=e.useDashboardStore(h=>h.dashboard.filters),q=e.useDashboardStore(h=>h.filterValues),H=M==null?void 0:M.filter(h=>h.sheetId===p||!h.sheetId),U=q==null?void 0:q.filter(h=>(H==null?void 0:H.some(J=>J.id===h.filterId))||h.filterId.endsWith(p)),_=e.useEditorStore(h=>h.applyFilters),{setCardCustomCfg:W,setQueryResultColumns:k,setFilterValues:F,setCardSql:B,setCardPython:A,setQueryError:T,setPythonStdOut:G,setCardPreferences:V}=e.useEditorStore(h=>h.actions),P=e.useEditorStore(h=>h.onSave),Q=e.useEditorStore(h=>h.actions.setApplyFilters),se=e.useEditorStore(h=>h.onClose),Y=e.useEditorStore(h=>h.actions.setCardData),ne=e.useEditorStore(h=>h.actions.setSqlGen),re=e.useEditorStore(h=>h.runSql),oe=e.useEditorStore(h=>h.actions.setRunSql),te=e.useEditorStore(h=>h.actions.setIsSqlRunning),{data:$,isLoading:X,isFetching:le,isSuccess:fe,isError:ce,error:je,status:Pe,refetch:xe}=e.useQuery({queryKey:[I,j],queryFn:()=>e.postRequest("https://semaphor.cloud/api/v1/query",(u==null?void 0:u.accessToken)||"",{connection_id:O,sql:I,python:j===e.PYTHON_DEFAULT_CODE?"":j,active_filters:_?U:[],cache_config:e.getCacheConfig()}),enabled:!1,retry:!1});S.useEffect(()=>{if($&&(Y($.records),$.rowLimitExceeded&&e.Jt.error("Row limit (10,000) exceeded. Refine your query.",{position:"top-center",richColors:!0}),G(($==null?void 0:$.output)||""),$.records.length>0)){const{dimensionKeys:h}=e.getKeys($.records);k(h)}},[$,Y,k,G]),S.useEffect(()=>{re&&(xe(),oe(!1))},[re,xe,oe]),S.useEffect(()=>{(X||le)&&te(!0),(ce||fe)&&te(!1),ce?(T(je.message),Y([]),k([]),G("")):T("")},[X,le,$,G,ce,fe,te,Y,k,T,je]);function ge(){B(""),Y([]),ne({}),W(""),V({})}const he=h=>{t.current=h};function Re(h,J){if(h.length===0)return"";if(J){const ie=h.find(K=>K.id===J);if(ie){const K=ie.tabTitle;if(K=="All__Header")return h[0].id;if(K&&K.endsWith("__Header")){const Ps=K.split("__")[0],$e=h.find($s=>$s.tabTitle===Ps);return $e?$e.id:h[0].id}return J}}return h[0].id}function be(){let h=E;E&&!E.includes("{{")&&(h=et(E),B(h));const J={...L,lastSelectedSchema:m,lastSelectedDatamodelId:D,lastSelectedDatabase:v,lastSelectedTable:N,connectionId:w,type:C?L.type:"table",sql:h,customCfg:C?L.customCfg:null},ie=z.cards.map(De=>De.id===L.id?J:De),K={...z,cards:ie,activeCardId:Re(ie,z.activeCardId)};P==null||P(K)}function ye(){se==null||se()}S.useEffect(()=>{const h=r.current,J=t.current;if(h){const ie=window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light",K=b==="system"?ie:b;h.editor.defineTheme("default",{base:K==="light"?"vs":"vs-dark",inherit:!0,rules:[],colors:{"editor.background":K==="light"?"#ffffff":e.getCssVariableValue("--semaphor-background")}}),h.editor.setTheme("default")}return J&&h&&J.addCommand(h.KeyMod.Shift|h.KeyCode.Enter,function(){return console.log("Executing query..."),xe(),!1}),()=>{}},[s,b,r.current]);function y(h){r.current=h}function Bs(){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(tt,{checked:_,onCheckedChange:()=>Q(!_),text:"Apply Filters"}),e.jsxRuntimeExports.jsx(rt,{}),U&&a&&e.jsxRuntimeExports.jsx(e.Cross2Icon,{onClick:()=>i(!1),className:"bg-background/50 text-foreground/50 hover:cursor-pointer hover:text-foreground"})]}),e.jsxRuntimeExports.jsx(e.Ft,{theme:"default",onChange:h=>{if(h)try{JSON.parse(h),F(JSON.parse(h))}catch{}},defaultLanguage:"json",className:"mt-1 min-h-[220px]",value:JSON.stringify(U,null,2),options:{readOnly:!0,minimap:{enabled:!1},lineNumbers:"off",glyphMargin:!1,wordWrap:"on",scrollbar:{verticalScrollbarSize:0,horizontalScrollbarSize:0},fontSize:12,renderLineHighlight:"none"}})]})}),U&&!a&&e.jsxRuntimeExports.jsx(e.Filter,{onClick:()=>i(!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":_})})]})}function Hs(){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:n?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:h=>{B(h)},value:E,options:{minimap:{enabled:!1},wordWrap:"on",scrollbar:{verticalScrollbarSize:0,horizontalScrollbarSize:0},fontSize:14,renderLineHighlight:"none"},defaultLanguage:"sql",beforeMount:y,onMount:he})}),n&&e.jsxRuntimeExports.jsx("code",{className:"absolute right-6 top-3 text-sm text-muted-foreground/70",children:"sql"})]}),n&&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:h=>{A(h&&h.trim()||"")},value:j||e.PYTHON_DEFAULT_CODE,options:{minimap:{enabled:!1},wordWrap:"on",scrollbar:{verticalScrollbarSize:0,horizontalScrollbarSize:0},fontSize:14,renderLineHighlight:"none"},defaultLanguage:"python",beforeMount:y,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:[Hs(),Bs()]}),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:X||le,onClick:()=>{xe()},className:"shrink-0",size:"sm",variant:"outline",children:[X||le?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(st,{error:je.message,setShowAIDialog:l,setTriggerAIRun:f,setUserInputforAI:d}),e.jsxRuntimeExports.jsxs(e.Button,{onClick:ge,className:"",size:"sm",variant:"outline",children:[e.jsxRuntimeExports.jsx(ss,{className:"mr-2 size-4"}),"Clear"]}),e.jsxRuntimeExports.jsx(e.Toggle,{pressed:n,onPressedChange:h=>o(h),className:"",size:"sm",variant:"outline",children:e.jsxRuntimeExports.jsx(pt,{className:"size-4 text-foreground/70"})}),e.jsxRuntimeExports.jsx(it,{open:c,setOpen:l,userInput:x,triggerAIRun:g,setTriggerAIRun:f,setUserInput:h=>d(h)})]}),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 ht({data:s}){var i;const[r,t]=S.useState([]),o=Object.keys(s[0]).map(c=>({accessorKey:c,header:({column:l})=>{const x=l.getIsSorted();return e.jsxRuntimeExports.jsx("div",{className:"flex gap-2",children:e.jsxRuntimeExports.jsxs("div",{className:"flex cursor-pointer items-center",onClick:()=>l.toggleSorting(l.getIsSorted()==="asc"),children:[c,x==="asc"?e.jsxRuntimeExports.jsx(e.TriangleUpIcon,{className:"ml-2 h-5 w-5"}):x==="desc"?e.jsxRuntimeExports.jsx(e.TriangleDownIcon,{className:"ml-2 h-5 w-5"}):null]})})}})),a=e.useReactTable({data:s,columns:o,getCoreRowModel:e.getCoreRowModel(),getPaginationRowModel:e.getPaginationRowModel(),onSortingChange:t,getSortedRowModel:e.getSortedRowModel(),manualPagination:!0,state:{sorting:r}});return e.jsxRuntimeExports.jsxs(e.Table$1,{children:[e.jsxRuntimeExports.jsx(e.TableHeader,{children:a.getHeaderGroups().map(c=>e.jsxRuntimeExports.jsx(e.TableRow,{children:c.headers.map(l=>e.jsxRuntimeExports.jsx(e.TableHead,{className:"sticky top-0 bg-muted",children:l.isPlaceholder?null:e.flexRender(l.column.columnDef.header,l.getContext())},l.id))},c.id))}),e.jsxRuntimeExports.jsx(e.TableBody,{children:(i=a.getRowModel().rows)!=null&&i.length?a.getRowModel().rows.map(c=>e.jsxRuntimeExports.jsx(e.TableRow,{className:"whitespace-nowrap py-2","data-state":c.getIsSelected()&&"selected",children:c.getVisibleCells().map(l=>e.jsxRuntimeExports.jsx(e.TableCell,{children:e.flexRender(l.column.columnDef.cell,l.getContext())},l.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 Et({card:s}){var x,d,g,f,u,p,R,L,b,C;const r=e.useDashboardStore(w=>w.themeStyle),t={colors:((d=(x=r==null?void 0:r.chart)==null?void 0:x.dataset)==null?void 0:d.backgroundColor)||[]};(g=s.customCardPreferences)!=null&&g.inputData;const{getCard:n}=e.useCustomVisual(((f=s.customCardPreferences)==null?void 0:f.url)||""),o=((u=s.customCardPreferences)==null?void 0:u.visualType)||"single",a=e.useEditorStore(w=>w.frame);if(e.useEditorActions(),!((p=s.customCardPreferences)!=null&&p.componentName))return null;const i=n((R=s.customCardPreferences)==null?void 0:R.componentName),c=w=>{console.log("data",w),s.customCardPreferences},l=Object.keys(((L=s.customCardPreferences)==null?void 0:L.dataInputCardIds)||{}).map(w=>{var m,N,E;const v=(N=(m=s.customCardPreferences)==null?void 0:m.dataInputCardIds)==null?void 0:N[w].cardId,D=(E=a==null?void 0:a.cards)==null?void 0:E.find(j=>j.id===v);return D||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:[i&&o==="single"&&e.jsxRuntimeExports.jsx(i,{theme:t,settings:(b=s.customCardPreferences)==null?void 0:b.settings,onDataChange:c,data:s.data}),i&&o==="multiple"&&e.jsxRuntimeExports.jsx("div",{className:"flex flex-col gap-2",children:e.jsxRuntimeExports.jsx(i,{theme:t,onDataChange:c,settings:l.map(w=>{var v;return(v=w==null?void 0:w.customCardPreferences)==null?void 0:v.settings}),data:l.map(w=>(w==null?void 0:w.data)||[])})})]},(C=s.customCardPreferences)==null?void 0:C.componentName)})}function ws({className:s,...r}){var L,b;S.useState(0);const t=e.useDashboardStore(C=>C.themeStyle),n=e.useEditorStore(C=>C.card),o=((L=n.customCardPreferences)==null?void 0:L.showCardHeader)??!0,a=e.useEditorStore(C=>C.frame),i=e.useDashboardStore(C=>C.dashboard.filters);e.useDashboardStore(C=>C.filterValues),e.useEditorStore(C=>C.actions.setRunSql);const{updateFilter:c}=e.useDashboardActions(),l=i==null?void 0:i.find(C=>C.id===a.filterId),x=e.useEditorStore(C=>C.actions.setCard),{data:d,isLoading:g,isFetching:f,isError:u}=e.useTopoJson(n);if(S.useEffect(()=>{},[n.data,n.type,n.cfg,n.customCfg,t,n.preferences]),!n.id)return null;let p;n.data&&n.data.length>0&&(p=e.createChartConfig({data:n.data,cardType:n.type,cfg:n.cfg,customCfg:n.customCfg,preferences:n.preferences,topoJson:d}));function R(C){return e.jsxRuntimeExports.jsx(Et,{card:C})}return e.jsxRuntimeExports.jsxs(e.Card,{role:"editor-visual-card",className:e.cn("relative flex h-full flex-col rounded-none",s),...r,children:[o&&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:n.title,onSave:C=>x({...n,title:C}),children:e.jsxRuntimeExports.jsx("div",{className:"flex items-center gap-5",children:e.jsxRuntimeExports.jsx(e.CardTitle,{className:"text-base",children:n.title||"Edit title..."})})},n.title),e.jsxRuntimeExports.jsx(e.Editable,{text:n.description||"",onSave:C=>x({...n,description:C}),children:e.jsxRuntimeExports.jsx(e.CardDescription,{children:n.description||"Edit description..."})},n.description)]}),l&&e.jsxRuntimeExports.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxRuntimeExports.jsx(e.Editable,{className:"my-1",text:l.title||l.column,onSave:C=>c({...l,title:C}),children:e.jsxRuntimeExports.jsx(e.Label,{children:l.title})}),e.getFilterComponent(l)]})]}),e.jsxRuntimeExports.jsxs(e.CardContent,{className:"flex grow flex-col",children:[n.type==="custom"&&R(n),!["table","custom"].includes(n.type)&&p&&e.jsxRuntimeExports.jsx(e.ChartJsVisual,{cfg:p},JSON.stringify(p)+JSON.stringify(n.preferences)+((b=n==null?void 0:n.preferences)==null?void 0:b.customVisualCode)),n.type==="table"&&n.data&&n.data.length>0&&e.jsxRuntimeExports.jsx(e.$57acba87d6e25586$export$ccf8d8d7bbf3c2cc,{className:"flex min-h-0 flex-1 grow basis-0",children:e.jsxRuntimeExports.jsx(e.TableVisual,{card:n,data:n==null?void 0:n.data})})]})]})}function ft(){const[s,r]=S.useState(!1),[t,n]=S.useState(""),[o,a]=S.useState(""),[i,c]=S.useState(""),[l,x]=S.useState(""),d=e.useEditorStore(v=>v.card),g=e.useEditorStore(v=>v.card.customCfg),{data:f}=e.useTopoJson(d),{setCardCustomCfg:u,setCustomVisualCode:p}=e.useEditorActions();function R(v){var N,E;const D={...v,data:{...v==null?void 0:v.data,datasets:(E=(N=v==null?void 0:v.data)==null?void 0:N.datasets)==null?void 0:E.map(j=>({...j,data:[]}))}};return JSON.stringify(D,null,1)}function L(){var D,m;if(!d.data||d.data.length===0)return;const v=e.createChartConfig({data:d.data,cardType:d.type,cfg:d.cfg,preferences:d.preferences,topoJson:f});v&&(n(JSON.stringify(v,null,1)),(D=d==null?void 0:d.preferences)!=null&&D.customVisualCode&&c((m=d==null?void 0:d.preferences)==null?void 0:m.customVisualCode),g&&a(JSON.stringify(g,null,1)))}function b(){if(i&&p(i),!!o)try{const v=JSON.parse(o);return v?(u(v),x(""),a(""),v):void 0}catch(v){console.log(v),x("Invalid JSON")}}function C(){a(""),u(null)}function w(){let v;if(g){const D=e._.cloneDeep(d.cfg),m=e._.merge(D,g);return v=R(m),v}return t?(v=R(JSON.parse(t)),v):""}return e.jsxRuntimeExports.jsxs(e.Dialog,{open:s,onOpenChange:r,children:[e.jsxRuntimeExports.jsx(e.DialogTrigger,{asChild:!0,children:e.jsxRuntimeExports.jsx(e.Button,{onClick:L,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(Me,{onClick:()=>{navigator.clipboard.writeText(d.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(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:w(),onChange:v=>a(v)})}),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:v=>c(v||"")})})]})]}),e.jsxRuntimeExports.jsxs(e.DialogFooter,{className:"flex items-center",children:[e.jsxRuntimeExports.jsx(e.Label,{className:"mr-2 text-red-500",children:l}),e.jsxRuntimeExports.jsx(e.Button,{disabled:!g,onClick:C,variant:"outline",children:"Reset"}),e.jsxRuntimeExports.jsx(e.Button,{onClick:b,variant:"outline",children:"Apply"}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>r(!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:"M137.39,24.06A16,16,0,0,0,120,40V80.67a15.86,15.86,0,0,0,13.25,15.76A32,32,0,1,1,96,129.68c-.41-8.22,1.27-15,5-20.26h0a15.86,15.86,0,0,0-1.69-20.47L71.69,60.68a16,16,0,0,0-23.63,1.1A103.6,103.6,0,0,0,55,202.05,103.24,103.24,0,0,0,128,232h1.49A104.3,104.3,0,0,0,232,129.48C232.75,75.18,191.19,28.88,137.39,24.06ZM60.32,71.94l27.61,28.19,0,.06A43.29,43.29,0,0,0,80.44,120H40.36A87.13,87.13,0,0,1,60.32,71.94ZM40.37,136h40.3A48,48,0,0,0,120,175.34v40.3A88,88,0,0,1,40.37,136Zm149.77,54.14A87.45,87.45,0,0,1,136,215.61V175.34a47.55,47.55,0,0,0,24.73-12.23A48,48,0,0,0,136,80.66L136,40c45.52,4.08,80.67,43.28,80,89.25A87.45,87.45,0,0,1,190.14,190.14Z"},child:[]}]})(s)}function Ls(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 Ds(s){return ee({tag:"svg",attr:{viewBox:"0 0 24 24",strokeWidth:"2",stroke:"currentColor",fill:"none",strokeLinecap:"round",strokeLinejoin:"round"},child:[{tag:"path",attr:{stroke:"none",d:"M0 0h24v24H0z",fill:"none"},child:[]},{tag:"path",attr:{d:"M6 16m-3 0a3 3 0 1 0 6 0a3 3 0 1 0 -6 0"},child:[]},{tag:"path",attr:{d:"M16 19m-2 0a2 2 0 1 0 4 0a2 2 0 1 0 -4 0"},child:[]},{tag:"path",attr:{d:"M14.5 7.5m-4.5 0a4.5 4.5 0 1 0 9 0a4.5 4.5 0 1 0 -9 0"},child:[]}]})(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[r,t]=S.useState(null);return S.useEffect(()=>{s&&(async()=>{const a=(await Promise.resolve().then(()=>require("./lucide-react-Tu85lAAG.js")))[s];t(a)})()},[s]),r}function Ms(){const{authToken:s}=e.useSemaphorContext(),{data:r,isLoading:t,isFetching:n,isError:o}=e.useQuery({queryKey:["plugins",s==null?void 0:s.accessToken],queryFn:()=>e.getPlugins(s==null?void 0:s.accessToken)});return{data:r,isLoading:t,isFetching:n,isError:o}}function gt({onChartTypeChange:s}){const[r,t]=S.useState([]),{data:n}=Ms();return S.useEffect(()=>{(async()=>{var a;if(n){const c=(await Promise.all((a=n==null?void 0:n.plugins)==null?void 0:a.map(async l=>(await e.loadManifest(l.value)).visuals.map(g=>({name:g.name,icon:g.icon,url:l.value}))))).flat();t(c)}})()},[n]),r.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:r.map((o,a)=>e.jsxRuntimeExports.jsx(Rt,{text:o.name,onClick:()=>s("custom",o),icon:o.icon},o.url+o.name+a))})]})}const Rt=({text:s,icon:r,onClick:t})=>{const n=Fs(r||""),o=s.charAt(0).toUpperCase();return e.jsxRuntimeExports.jsx(e.Button,{onClick:t,title:s,variant:"ghost",children:n?e.jsxRuntimeExports.jsx(n,{className:"h-4 w-4"}):o})};function bt(){var d,g;const[s,r]=S.useState(!1),t=e.useEditorStore(f=>f.card),n=t.type,{setCardType:o,setCardPreferences:a,setChartOrientation:i}=e.useEditorStore(f=>f.actions),{setCardCustomCfg:c,setCustomCardPreferences:l}=e.useEditorActions();function x(f,u){c(null),a({}),o(f),u&&l({type:"component",visualType:"single",url:u.url,componentName:u.name,icon:u.icon}),r(!1)}return e.jsxRuntimeExports.jsxs(e.Popover,{open:s,onOpenChange:r,children:[e.jsxRuntimeExports.jsx(e.PopoverTrigger,{asChild:!0,children:e.jsxRuntimeExports.jsx(e.Button,{size:"sm",variant:"outline",children:e.jsxRuntimeExports.jsx(yt,{className:"h-4 w-4",chartType:n,customIcon:(d=t.customCardPreferences)==null?void 0:d.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:()=>x("bar"),className:"font-normal",variant:"ghost",children:e.jsxRuntimeExports.jsx(we,{className:"size-5"})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>x("line"),variant:"ghost",children:e.jsxRuntimeExports.jsx(ke,{className:"size-5"})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>x("stackedBar"),variant:"ghost",children:e.jsxRuntimeExports.jsx(As,{className:"size-5",strokeWidth:0})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>x("stackedLine"),variant:"ghost",children:e.jsxRuntimeExports.jsx(Ts,{className:"size-5",strokeWidth:0})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>x("scatter"),variant:"ghost",children:e.jsxRuntimeExports.jsx(ze,{className:"size-5"})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>x("bubble"),variant:"ghost",children:e.jsxRuntimeExports.jsx(Ds,{className:"size-4"})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>x("pie"),variant:"ghost",children:e.jsxRuntimeExports.jsx(Oe,{className:"size-5"})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>x("doughnut"),variant:"ghost",children:e.jsxRuntimeExports.jsx(Is,{className:"size-5",strokeWidth:1})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>x("radar"),variant:"ghost",children:e.jsxRuntimeExports.jsx(ks,{className:"size-5 font-extralight",strokeWidth:.5})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>x("polarArea"),variant:"ghost",children:e.jsxRuntimeExports.jsx(Ls,{className:"size-5"})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>x("pyramid"),variant:"ghost",children:e.jsxRuntimeExports.jsx(zs,{className:"size-5"})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>x("range"),variant:"ghost",children:e.jsxRuntimeExports.jsx(Ae,{className:"size-5"})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>x("table"),variant:"ghost",children:e.jsxRuntimeExports.jsx(e.Table,{className:"size-5"})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>x("kpi"),variant:"ghost",children:e.jsxRuntimeExports.jsx(Os,{className:"size-6"})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>x("text"),variant:"ghost",children:e.jsxRuntimeExports.jsx(Ie,{className:"size-4"})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>x("map"),variant:"ghost",children:e.jsxRuntimeExports.jsx(Ve,{className:"size-4"})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>x("custom"),variant:"ghost",children:e.jsxRuntimeExports.jsx(_e,{className:"size-4"})})]}),e.jsxRuntimeExports.jsx(gt,{onChartTypeChange:x})]})]})}function yt({chartType:s,className:r,customIcon:t,componentName:n}){const o=Fs(t||"");switch(s){case"bar":return e.jsxRuntimeExports.jsx(we,{className:r});case"line":return e.jsxRuntimeExports.jsx(ke,{className:r});case"pie":return e.jsxRuntimeExports.jsx(Oe,{className:r});case"radar":return e.jsxRuntimeExports.jsx(ks,{className:r});case"scatter":return e.jsxRuntimeExports.jsx(ze,{className:r});case"bubble":return e.jsxRuntimeExports.jsx(Ds,{className:r});case"doughnut":return e.jsxRuntimeExports.jsx(Is,{className:r});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(Ls,{className:r});case"pyramid":return e.jsxRuntimeExports.jsx(zs,{className:r});case"range":return e.jsxRuntimeExports.jsx(Ae,{className:r});case"kpi":return e.jsxRuntimeExports.jsx(Os,{className:r});case"text":return e.jsxRuntimeExports.jsx(Ie,{className:r});case"map":return e.jsxRuntimeExports.jsx(Ve,{className:r});case"custom":return t&&o?e.jsxRuntimeExports.jsx(o,{className:r}):n?n==null?void 0:n.charAt(0).toUpperCase():e.jsxRuntimeExports.jsx(_e,{className:r});default:return e.jsxRuntimeExports.jsx(e.Table,{className:r})}}function vt(){var o;const s=e.useEditorStore(a=>a.card),r=((o=s.customCardPreferences)==null?void 0:o.showCardHeader)??!0,{setCustomCardPreferences:t}=e.useEditorActions(),n=a=>{s.customCardPreferences&&t({...s.customCardPreferences,showCardHeader:a===!0})};return e.jsxRuntimeExports.jsxs(e.DropdownMenu,{children:[e.jsxRuntimeExports.jsx(e.DropdownMenuTrigger,{asChild:!0,children:e.jsxRuntimeExports.jsx(Fe,{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:r,onCheckedChange:n,children:"Card Header"}),e.jsxRuntimeExports.jsxs(e.DropdownMenuItem,{onClick:()=>{navigator.clipboard.writeText(s.id),e.Jt.success("Card ID copied to clipboard")},className:"cursor-pointer space-x-2",children:[e.jsxRuntimeExports.jsx(Me,{className:"size-4"}),e.jsxRuntimeExports.jsx("span",{children:"Copy Card ID"})]})]})]})}function Je(){const s=e.useEditorStore(m=>m.frame),r=e.useEditorStore(m=>m.card),t=e.useEditorStore(m=>m.card.data),n=e.useEditorStore(m=>m.isShowingVisual),o=e.useEditorStore(m=>m.isSqlRunning),a=e.useEditorStore(m=>m.queryError),i=e.useEditorStore(m=>m.pythonStdOut),c=e.useEditorStore(m=>m.actions.setRunSql);e.useEditorStore(m=>m.onSave),e.useEditorStore(m=>m.onClose),e.useEditorStore(m=>m.actions.setCardSql),e.useEditorStore(m=>m.actions.setCardType),e.useEditorStore(m=>m.actions.setSqlGen);const{setFrame:l,setCard:x,updateCardInFrame:d}=e.useEditorActions();if(!r)return e.jsxRuntimeExports.jsx(e.jsxRuntimeExports.Fragment,{children:"No Active Card"});function g(){const m={id:e.v4(),title:"Title",description:"Description",preferences:{onClickFilter:[{columnIndex:0,expression:""}]},type:"bar",sql:"",data:[]};f(m)}function f(m){const N={...s,cards:[...s.cards,m],activeCardId:m.id};l(N),x(m)}function u(){const m={...r,id:e.v4(),title:`${r.title} Copy`,tabTitle:`${r.tabTitle} Copy`};f(m)}function p(m){const N=s.cards.filter(I=>I.id!==m),E=N[0],j={...s,cards:N,activeCardId:E.id};l(j),x(E)}function R(m){const N={...s,cards:s.cards.map(j=>j.id===r.id?r:j),activeCardId:m};l(N);const E=N.cards.find(j=>j.id===m);x(E),E.sql&&E.data&&E.data.length===0&&c(!0)}const L=(m,N)=>{console.log("handleDragStart",N),m.dataTransfer.setData("tabIndex",N.toString())},b=m=>{m.preventDefault()},C=(m,N)=>{const E=m.dataTransfer.getData("tabIndex");if(E===N.toString())return;const j=Array.from(s.cards),[I]=j.splice(parseInt(E),1);j.splice(N,0,I),l({...s,cards:j})};function w(m,N){return m.cards.length===1&&(N.displayTab===!0||N.displayTab===void 0)||m.activeCardId!==N.id&&(N.displayTab===!0||N.displayTab===void 0)?null:e.jsxRuntimeExports.jsx("div",{onClick:()=>{const E=N.displayTab===void 0?!1:!N.displayTab;x({...N,displayTab:E}),d({...N,displayTab:E})},children:N.displayTab===!0||N.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 v(){return e.jsxRuntimeExports.jsxs(e.Tabs,{onValueChange:R,value:s.activeCardId,className:"flex grow flex-col",children:[s.cards.map(m=>e.jsxRuntimeExports.jsx(e.TabsContent,{className:"mt-0 grow",value:m.id,children:D()},m.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((m,N)=>e.jsxRuntimeExports.jsx(e.Editable,{text:m.tabTitle||m.title,onSave:E=>{x({...r,tabTitle:E}),d({...r,tabTitle:E})},children:e.jsxRuntimeExports.jsxs(e.TabsTrigger,{draggable:!0,onDragStart:E=>L(E,N),onDragOver:b,onDrop:E=>C(E,N),className:"",value:m.id,children:[w(s,m),m.tabTitle||m.title,s.activeCardId===m.id&&s.cards.length>1&&e.jsxRuntimeExports.jsx(e.X,{className:"ml-2 size-3.5 text-muted-foreground hover:text-foreground",onClick:()=>p(m.id)})]})},m.id)),e.jsxRuntimeExports.jsx(e.Button,{className:"ml-1 h-8 px-2 hover:bg-muted-foreground/50",variant:"outline",onClick:g,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:u,children:e.jsxRuntimeExports.jsx(Ze,{className:"h-4 w-4"})})]})})]})}function D(){return r.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,{isLoading:o,card:r})})}):r.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.TextCard,{isLoading:o,card:r})})}):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:[o&&e.jsxRuntimeExports.jsx(de,{className:"absolute bottom-0 left-0 right-0 top-0 z-10 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:[n&&e.jsxRuntimeExports.jsxs("div",{className:"flex grow items-center gap-2",children:[e.jsxRuntimeExports.jsx(bt,{}),!["table","custom"].includes(r.type)&&e.jsxRuntimeExports.jsx(ft,{}),e.jsxRuntimeExports.jsx(vt,{})]}),e.jsxRuntimeExports.jsx(Ct,{})]}),n?v():e.jsxRuntimeExports.jsxs("div",{className:"flex min-h-0 w-full flex-1 grow basis-0 px-6",children:[i&&e.jsxRuntimeExports.jsx(St,{}),r.data&&r.data.length>0&&e.jsxRuntimeExports.jsx(ht,{data:t||[]}),a&&e.jsxRuntimeExports.jsx("span",{className:"font-mono text-sm",children:a})]})]})}function St(){const s=e.useEditorStore(t=>t.pythonStdOut);if(!s)return null;const r=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:r},className:"bg-muted p-2 font-mono text-sm"}),e.jsxRuntimeExports.jsx(e.Separator,{className:"mb-2"})]})}function Ct(){const s=e.useEditorStore(t=>t.isShowingVisual),r=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:()=>r(!s),id:"visualize",className:"data-[state=checked]:bg-foreground/50"})]})}function Nt({options:s,value:r,onValueChange:t}){return e.jsxRuntimeExports.jsx(e.RadioGroup,{value:r,onValueChange:t,className:"flex gap-4",defaultValue:s[0].value,children:s.map(n=>e.jsxRuntimeExports.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsxRuntimeExports.jsx(e.RadioGroupItem,{value:n.value,id:n.value}),e.jsxRuntimeExports.jsx("label",{className:"text-sm",htmlFor:n.value,children:n.label})]},n.value))})}function Z({label:s,options:r,value:t,onValueChange:n,className:o}){return e.jsxRuntimeExports.jsxs(e.Select,{value:t,onValueChange:n,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}),r.map(a=>e.jsxRuntimeExports.jsx(e.SelectItem,{value:a.value,children:a.label},a.value))]})})]})}function Ee({children:s,summary:r,open:t,className:n}){return e.jsxRuntimeExports.jsxs("details",{open:t,className:e.cn("space-y-4 [&_summary>svg]:open:-rotate-180",n),children:[e.jsxRuntimeExports.jsxs("summary",{className:"flex cursor-pointer list-none items-center justify-between gap-4",children:[e.jsxRuntimeExports.jsx(e.Label,{children:r}),e.jsxRuntimeExports.jsx(e.ChevronUp,{className:"h-4 w-4"})]}),e.jsxRuntimeExports.jsx("div",{className:"transition-all ease-in-out",children:s})]})}function wt(){var R,L;const s=e.useEditorStore(b=>b.card.customCardPreferences),{data:r}=Ms(),t=(r==null?void 0:r.plugins)||[],n=e.useEditorStore(b=>b.card),o=e.useEditorStore(b=>b.frame),a=(s==null?void 0:s.visualType)||"single",{setCustomCardPreferences:i}=e.useEditorActions(),{components:c,manifest:l}=e.useCustomVisual((s==null?void 0:s.url)||""),x=(R=l==null?void 0:l.visuals)==null?void 0:R.find(b=>b.name===(s==null?void 0:s.componentName));function d(b,C){if(!s)return;const v={...(s==null?void 0:s.dataInputCardIds)||{},[b]:{cardId:C,hookRef:null}};i({...s,dataInputCardIds:v})}function g(b){var w,v;const C=(w=o==null?void 0:o.cards)==null?void 0:w.filter(D=>{var m;return((m=D==null?void 0:D.customCardPreferences)==null?void 0:m.visualType)!=="multiple"}).map(D=>({value:D.id,label:D.tabTitle||D.title}));return e.jsxRuntimeExports.jsx("div",{className:"space-y-2",children:(v=b==null?void 0:b.dataInputs)==null?void 0:v.map((D,m)=>{var N,E;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:D}),e.jsxRuntimeExports.jsx(Z,{className:"col-span-6 h-8 w-full justify-between",label:"",options:C||[],value:((E=(N=s==null?void 0:s.dataInputCardIds)==null?void 0:N[m])==null?void 0:E.cardId)||"",onValueChange:j=>d(m,j)})]},m+Math.random())})})}function f(b,C,w=[]){var v,D;return s?b==="input"?e.jsxRuntimeExports.jsx(e.Input,{className:`h-8 w-full ${e.removeRing}`,value:((v=s==null?void 0:s.settings)==null?void 0:v[C])||"",onChange:m=>{i({...s,settings:{...s==null?void 0:s.settings,[C]:m.target.value}})}},C):b==="select"?e.jsxRuntimeExports.jsx(Z,{className:"h-8 w-full",label:"",options:w,value:((D=s==null?void 0:s.settings)==null?void 0:D[C])||"",onValueChange:m=>{i({...s,settings:{...s==null?void 0:s.settings,[C]:m}})}}):null:null}function u(b){const C=Object.entries((b==null?void 0:b.settings)||{});return e.jsxRuntimeExports.jsx("div",{className:"space-y-3",children:C.map(([w,v])=>e.jsxRuntimeExports.jsxs("div",{className:"space-y-2",children:[e.jsxRuntimeExports.jsx(e.Label,{children:v.title}),f(v.ui,w,v.options)]},w))})}function p(b){s&&i({...s,visualType:b,componentName:""})}return e.jsxRuntimeExports.jsxs("div",{className:"p-6",children:[e.jsxRuntimeExports.jsx(Ee,{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(Nt,{options:[{value:"single",label:"Single Visual"},{value:"multiple",label:"Multi-Visual"}],value:a,onValueChange:p}),((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===a).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"}),((L=n==null?void 0:n.customCardPreferences)==null?void 0:L.componentName)&&e.jsxRuntimeExports.jsxs(Ee,{summary:"Component Settings",children:[x&&x.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(x)})]}),x&&x.settings&&e.jsxRuntimeExports.jsx("div",{className:"space-y-3",children:e.jsxRuntimeExports.jsx("div",{className:"px-2",children:u(x)})})]})]})}function me(){const[s,r]=S.useState([]);e.useEditorStore(d=>d.card.cfg);const t=e.useEditorStore(d=>d.card.preferences),{setCardCfg:n,setFilterOnClickColumnIndex:o,setCardPreferences:a}=e.useEditorStore(d=>d.actions),i=e.useEditorStore(d=>d.queryResultColumns);e.useEditorStore(d=>{var g;return(g=d.card.preferences)==null?void 0:g.filterOnClickColumnIndex}),S.useEffect(()=>{i&&r(new Array(i.length).fill(!1))},[i]);function c(d,g){var f,u;g?t!=null&&t.onClickFilter&&((f=t==null?void 0:t.onClickFilter)==null?void 0:f.length)>0?a({...t,onClickFilter:[...t.onClickFilter,{columnIndex:d,expression:""}]}):a({...t,onClickFilter:[{columnIndex:d,expression:""}]}):(a({...t,onClickFilter:(u=t==null?void 0:t.onClickFilter)==null?void 0:u.filter(p=>p.columnIndex!==d)}),r(p=>{const R=[...p];return R[d]=!1,R}))}function l(d,g){var u;const f=(u=t==null?void 0:t.onClickFilter)==null?void 0:u.map(p=>p.columnIndex===d?{...p,expression:g.target.value}:p);a({...t,onClickFilter:f})}function x(d){var g,f,u,p;if(s!=null&&s[d]||(f=(g=t==null?void 0:t.onClickFilter)==null?void 0:g.find(R=>R.columnIndex===d))!=null&&f.expression)return e.jsxRuntimeExports.jsx(e.Input,{value:(p=(u=t==null?void 0:t.onClickFilter)==null?void 0:u.find(R=>R.columnIndex===d))==null?void 0:p.expression,onChange:R=>l(d,R),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((d,g)=>{var f,u;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:!!((f=t==null?void 0:t.onClickFilter)!=null&&f.find(p=>p.columnIndex===g)),onCheckedChange:p=>c(g,p)}),e.jsxRuntimeExports.jsx("label",{className:"text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70",children:d}),e.jsxRuntimeExports.jsx("div",{className:"flex items-center gap-2",children:((u=t==null?void 0:t.onClickFilter)==null?void 0:u.find(p=>p.columnIndex===g))&&e.jsxRuntimeExports.jsx(qe,{onClick:()=>{r(p=>{const R=[...p];return R[g]=!p[g],R})},className:"invisible size-3 cursor-pointer text-gray-400 group-hover:visible"})})]}),x(g)]})},d)})]})}function Le(){var i,c,l;const s=e.useEditorStore(x=>x.card.preferences),r=e.useEditorStore(x=>x.card.cfg),{setCardCfg:t,setCardPreferences:n,setChartOrientation:o}=e.useEditorStore(x=>x.actions);(i=r==null?void 0:r.options)!=null&&i.indexAxis;function a(x){o(x)}return e.jsxRuntimeExports.jsxs(e.RadioGroup,{value:((c=s==null?void 0:s.chartOptions)==null?void 0:c.indexAxis)||((l=r==null?void 0:r.options)==null?void 0:l.indexAxis)||"x",onValueChange:a,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 Ke(s,r){var n,o,a;const t=e.getNumberAxis(s,r);return((a=(o=(n=s==null?void 0:s.chartOptions)==null?void 0:n.scales)==null?void 0:o[t])==null?void 0:a.type)||"linear"}function Vs(){var U,_,W,k,F,B;const[s,r]=S.useState(!1),t=e.useEditorStore(A=>{var T;return(T=A.card)==null?void 0:T.preferences}),n=e.useEditorStore(A=>{var T;return(T=A.card)==null?void 0:T.cfg}),o=e.getNumberAxis(t,n),[a,i]=S.useState(Ke(t)),[c,l]=S.useState(((W=(_=(U=t==null?void 0:t.chartOptions)==null?void 0:U.scales)==null?void 0:_[o])==null?void 0:W.min)||""),[x,d]=S.useState(((B=(F=(k=t==null?void 0:t.chartOptions)==null?void 0:k.scales)==null?void 0:F[o])==null?void 0:B.max)||""),[g,f]=S.useState(c||x?"custom":"auto"),[u,p]=S.useState(""),[R,L]=S.useState(0),[b,C]=S.useState(""),[w,v]=S.useState(""),[D,m]=S.useState(""),N=e.useEditorStore(A=>A.actions.setCardPreferences),{updateCardInFrame:E}=e.useEditorActions(),j=e.useEditorStore(A=>A.card),I=e.useEditorStore(A=>{var T;return(T=A.card)==null?void 0:T.type}),O=["pie","doughnut","polarArea"].includes(I);S.useEffect(()=>{var A,T,G,V,P,Q,se,Y,ne,re,oe,te,$,X;i(Ke(t)),l(((G=(T=(A=t==null?void 0:t.chartOptions)==null?void 0:A.scales)==null?void 0:T[o])==null?void 0:G.min)===0?0:""),d(((Q=(P=(V=t==null?void 0:t.chartOptions)==null?void 0:V.scales)==null?void 0:P[o])==null?void 0:Q.max)||""),p(((re=(ne=(Y=(se=t==null?void 0:t.chartOptions)==null?void 0:se.scales)==null?void 0:Y[o])==null?void 0:ne.ticks)==null?void 0:re.stepSize)||""),L(((oe=t==null?void 0:t.numberAxisFormat)==null?void 0:oe.decimalPlaces)||0),C(((te=t==null?void 0:t.numberAxisFormat)==null?void 0:te.suffix)||""),v((($=t==null?void 0:t.numberAxisFormat)==null?void 0:$.currency)||""),m(((X=t==null?void 0:t.numberAxisFormat)==null?void 0:X.locale)||"")},[s,t,o]);function z(A,T){return T===""||/^[0-9\b]+$/.test(T)?Number(T):Number(A)}function M(){const A=[...new Set(e.LOCALE_CURRENCY_PAIRS.map(T=>T.currency))];return e.jsxRuntimeExports.jsxs(e.jsxRuntimeExports.Fragment,{children:[e.jsxRuntimeExports.jsxs("div",{className:"grid grid-cols-6 items-center gap-2",children:[e.jsxRuntimeExports.jsx(e.Label,{className:"col-span-2 hover:cursor-pointer hover:underline",htmlFor:"currency",children:e.jsxRuntimeExports.jsx("a",{target:"_blank",href:"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat",children:"Currency"})}),e.jsxRuntimeExports.jsxs(e.Select,{value:w||"none",onValueChange:T=>v(T==="none"?"":T),children:[e.jsxRuntimeExports.jsx(e.SelectTrigger,{className:"col-span-2 h-8 w-full focus:ring-1 focus:ring-offset-0",children:e.jsxRuntimeExports.jsx(e.SelectValue,{})}),e.jsxRuntimeExports.jsx(e.SelectContent,{children:e.jsxRuntimeExports.jsxs(e.SelectGroup,{children:[e.jsxRuntimeExports.jsx(e.SelectLabel,{children:"Currency"}),e.jsxRuntimeExports.jsx(e.SelectItem,{value:"none",children:"None"}),A.map(T=>e.jsxRuntimeExports.jsx(e.SelectItem,{value:T,children:T},T))]})})]}),e.jsxRuntimeExports.jsxs(e.Select,{value:D,onValueChange:T=>m(T),children:[e.jsxRuntimeExports.jsx(e.SelectTrigger,{className:"col-span-2 h-8 w-full focus:ring-1 focus:ring-offset-0",children:e.jsxRuntimeExports.jsx(e.SelectValue,{})}),e.jsxRuntimeExports.jsx(e.SelectContent,{children:e.jsxRuntimeExports.jsxs(e.SelectGroup,{children:[e.jsxRuntimeExports.jsx(e.SelectLabel,{children:"Locale"}),e.LOCALE_CURRENCY_PAIRS.map(T=>e.jsxRuntimeExports.jsx(e.SelectItem,{value:T.locale,children:T.locale},T.locale))]})})]})]}),e.jsxRuntimeExports.jsxs("div",{className:"grid grid-cols-9 items-center gap-2",children:[e.jsxRuntimeExports.jsx(e.Label,{className:"col-span-3",htmlFor:"format",children:"Decimals"}),e.jsxRuntimeExports.jsx(e.Input,{value:R,onChange:T=>L(Number(T.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:A=>l(T=>z(T,A.target.value)),className:`col-span-1 h-8 w-full ${ve}`}),e.jsxRuntimeExports.jsx(e.Input,{value:x,onChange:A=>d(T=>z(T,A.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:u,onChange:A=>p(T=>z(T,A.target.value)),id:"step-size",className:`col-span-1 h-8 w-full ${ve}`})]})]})}function H(){var V;let A={};g==="custom"&&(A={min:c,max:x,ticks:{stepSize:u}});const T={...t||{},chartOptions:{...t==null?void 0:t.chartOptions,scales:{...(V=t==null?void 0:t.chartOptions)==null?void 0:V.scales,[o]:{type:a,...a==="linear"?A:{}}}},numberAxisFormat:{decimalPlaces:R,suffix:b,currency:w,locale:D}};console.log(T),N(T);const G={...j,preferences:T};E(G)}return e.jsxRuntimeExports.jsxs(e.Popover,{onOpenChange:A=>r(A),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:O,value:a,onValueChange:A=>i(A),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"})]})})]})]}),a=="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:O,id:"scale-option",value:g,onValueChange:A=>f(A),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"&&a=="linear"&&q(),M(),e.jsxRuntimeExports.jsx(e.SelectSeparator,{}),e.jsxRuntimeExports.jsx("div",{className:"grid grid-cols-3",children:e.jsxRuntimeExports.jsx(e.Button,{onClick:H,variant:"secondary",className:"col-span-1 col-start-3 h-8 w-full",children:"Apply"})})]})]})})]})}function kt({idx:s}){var c;const r=e.useEditorStore(l=>{var x;return(x=l.card)==null?void 0:x.preferences}),t=e.useEditorStore(l=>{var x;return(x=l.card.preferences)==null?void 0:x.datasetOptions}),n=e.useEditorStore(l=>l.actions.setCardPreferences),o=(c=r==null?void 0:r.chartOptions)==null?void 0:c.indexAxis,a=t==null?void 0:t.find(l=>l.idx===s);function i(l,x){(l==="end"||l==="start")&&e.getContrastColor(e.getCanvasBackgroundColor());const d={display:l!=="none",align:l,anchor:l,clamp:!0};if(!a)n({...r,datasetOptions:[...t||[],{idx:x,datalabels:d}]});else{const g={...a};g.datalabels=d;const f=t==null?void 0:t.map(u=>u.idx===x?g:u);n({...r,datasetOptions:f})}}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(l=>l.card),r=e.useEditorStore(l=>{var x,d,g;return(g=(d=(x=l==null?void 0:l.card)==null?void 0:x.preferences)==null?void 0:d.chartOptions)==null?void 0:g.indexAxis}),t=r==="y"?"Y axis":"X axis",n=r==="y"?"X axis":"Y axis",{keys:o,metricKeys:a,dimensionKeys:i}=e.getKeys(s.data||[]);let c=a;if(["stackedBar","stackedLine"].includes(s.type)){const l=e.pivotData({dataArray:s.data||[],groupKey:i[0],pivotKey:i[1],valueKey:c[0]}),{metricKeys:x}=e.getKeys(l);c=x}return o.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:t}),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:i[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:n}),e.jsxRuntimeExports.jsx(Vs,{})]}),e.jsxRuntimeExports.jsx("div",{className:"my-1 space-y-1",children:c.map((l,x)=>e.jsxRuntimeExports.jsx(It,{col:l,idx:x},l))})]})]})}function It({col:s,idx:r}){const t=e.useEditorStore(c=>{var l;return(l=c.card)==null?void 0:l.preferences}),n=e.useEditorStore(c=>{var l;return(l=c.card.preferences)==null?void 0:l.datasetOptions}),o=n==null?void 0:n.find(c=>c.idx===r),{setCardPreferences:a}=e.useEditorStore(c=>c.actions);function i(c){if(!o)a({...t,datasetOptions:[...n||[],{idx:r,type:c==="area"?"line":c,fill:c==="area"?"origin":""}]});else{const l={...o};l.type=c==="area"?"line":c,l.fill=c==="area"?"origin":"";const x=n==null?void 0:n.map(d=>d.idx===r?l:d);a({...t,datasetOptions:x})}}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(kt,{idx:r})]})]})}function _s(){const s=e.useEditorStore(f=>f.selectedConnectionId),r=e.useEditorStore(f=>f.selectedDatamodelId),t=e.useEditorStore(f=>f.selectedDatabaseName),n=e.useEditorStore(f=>f.selectedSchemaName),o=e.useEditorStore(f=>f.selectedTableName),a=e.useDashboardStore(f=>f.dashboard.filters)||[],i=e.useDashboardStore(f=>f.actions.addFilter),c=e.useDashboardStore(f=>f.actions.removeFilter),l=e.useDashboardStore(f=>f.actions.removeFilterValue),{modelItems:x,tableName:d}=ae();function g(f,u="dashboard"){var m;const p=e.fmt(f.column_name),R=e.fmt(t||""),L=e.fmt(n||""),b=e.fmt(d);let C=e.getQualifiedTableName(L,b),w=`${C}.${p}`;const v=(m=x==null?void 0:x.find(N=>N.id===r))==null?void 0:m.name;r&&r!=="none"&&(w=`${e.DATAMODEL_NAMESPCACE}.${v}.${p}`,C=`${e.DATAMODEL_NAMESPCACE}.${v}`);const D=a==null?void 0:a.find(N=>N.column===w&&N.table===b&&(N.database===R||N.database===t));if(D)l(D.id),c(D.id);else{const N=e.v4();return d==="api"&&s?(i({location:u,id:N,column:w,title:f.column_name,dataType:f.data_type,table:"api",database:"",connectionId:s,operation:"in",sql:e.getDefaultFilterSql(f.data_type,C,p)}),N):(i({id:N,location:u,column:w,title:f.column_name,dataType:f.data_type,table:o||"",database:t||"",connectionId:s||"",operation:"in",sql:e.getDefaultFilterSql(f.data_type,C,p)}),N)}}return{assignFilter:g}}function pe(){const s=e.useDashboardStore(c=>c.dashboard.filters),r=e.useEditorStore(c=>c.frame),{setFrame:t}=e.useEditorActions(),{columns:n}=ae(),{assignFilter:o}=_s();function a(c){const l=o(c,"frame");t({...r,filterId:l})}const i=s==null?void 0:s.find(c=>c.id===r.filterId);return e.jsxRuntimeExports.jsxs("div",{className:"space-y-3",children:[e.jsxRuntimeExports.jsx(e.Label,{children:"Card Filter"}),e.jsxRuntimeExports.jsx(Lt,{onSelect:a,columns:n}),i&&e.jsxRuntimeExports.jsx(e.FilterHeader,{filter:i})]})}function Lt({columns:s,onSelect:r}){var i;const[t,n]=Ge.useState(!1),[o,a]=Ge.useState("");return e.jsxRuntimeExports.jsxs(e.Popover,{open:t,onOpenChange:n,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:l=>{const x=l===o?"":l;a(x),n(!1),x&&r(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:r=>r.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(Le,{}),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(me,{}),e.jsxRuntimeExports.jsx(pe,{})]})]})]})})}function He(){var o,a,i;const s=e.useEditorStore(c=>c.card.cfg),r=e.useEditorStore(c=>c.actions.setCardCfg),t=e.useEditorStore(c=>c.card.type);function n(c){var d;const l={datalabels:{display:c!=="none",align:c,anchor:c,clamp:!0}},x={...s,options:{...s==null?void 0:s.options,plugins:{...(d=s==null?void 0:s.options)==null?void 0:d.plugins,...l}}};r(x),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=(a=(o=s==null?void 0:s.options)==null?void 0:o.plugins)==null?void 0:a.datalabels)==null?void 0:i.anchor,onValueChange:n,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 Tt({cardType:s}){function r(t){const n="SELECT label, [group], x-axis, y-axis, radius FROM table",o="SELECT label, [group], x-axis, y-axis FROM table";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"?n:o}),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:a=>a.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:r(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(He,{})})]}),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(me,{}),e.jsxRuntimeExports.jsx(pe,{})]})]})]})})}const At={datasets:[{type:"line",label:"Sum_sales",data:[]},{type:"bar",label:"Sum_profit",data:[]}]},Ot={datasets:[{fill:"origin",type:"line",label:"Sum_sales",data:[]}]};function zt(){const s=e.useEditorStore(r=>r.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:Ft(s)}),e.jsxRuntimeExports.jsx("section",{className:"",children:["line","bar"].includes(s)&&e.jsxRuntimeExports.jsx(Le,{})}),!["kpi"].includes(s)&&e.jsxRuntimeExports.jsxs("div",{className:"space-y-4",children:[e.jsxRuntimeExports.jsx(He,{}),e.jsxRuntimeExports.jsx(me,{}),e.jsxRuntimeExports.jsx(pe,{})]})]})}function Ft(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(At,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(Ot,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 Mt(){var l,x,d,g,f;const s=e.useEditorStore(u=>u.card.preferences),r=e.useEditorStore(u=>u.actions.setCardPreferences),t=e.useEditorStore(u=>u.actions.setNumberFormat);e.useEditorStore(u=>{var p,R;return(R=(p=u.card.preferences)==null?void 0:p.formatNumber)==null?void 0:R.decimalPlaces});const n=e.useEditorStore(u=>{var p,R;return(R=(p=u.card.preferences)==null?void 0:p.formatNumber)==null?void 0:R.locale}),o=e.useEditorStore(u=>{var p,R;return(R=(p=u.card.preferences)==null?void 0:p.formatNumber)==null?void 0:R.currency});e.useEditorStore(u=>u.actions.setFilterOnClickField);const a=e.useEditorStore(u=>{var p,R;return(R=(p=u.card.preferences)==null?void 0:p.formatNumber)==null?void 0:R.colorRanges})||[],i=e.useEditorStore(u=>u.actions.setColorRanges),c=[...new Set(e.LOCALE_CURRENCY_PAIRS.map(u=>u.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:!!((l=s==null?void 0:s.formatNumber)!=null&&l.enabled),onCheckedChange:u=>{r({...s,formatNumber:{...s==null?void 0:s.formatNumber,enabled:u}})}}),e.jsxRuntimeExports.jsx(e.Label,{children:"Format Number"})]}),((x=s==null?void 0:s.formatNumber)==null?void 0:x.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:n||"en-US",onValueChange:u=>{var p,R,L;return t(((p=s==null?void 0:s.formatNumber)==null?void 0:p.decimalPlaces)||0,((R=s==null?void 0:s.formatNumber)==null?void 0:R.currency)||"",u||"en-US",((L=s==null?void 0:s.formatNumber)==null?void 0:L.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.LOCALE_CURRENCY_PAIRS.map(u=>e.jsxRuntimeExports.jsx(e.SelectItem,{value:u.locale,children:u.locale},u.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:u=>{var p,R,L;return t(((p=s==null?void 0:s.formatNumber)==null?void 0:p.decimalPlaces)||0,u==="none"?"":u,((R=s==null?void 0:s.formatNumber)==null?void 0:R.locale)||"",((L=s==null?void 0:s.formatNumber)==null?void 0:L.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(u=>e.jsxRuntimeExports.jsx(e.SelectItem,{value:u,children:u},u))]})})]})]})]}),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=(d=s==null?void 0:s.formatNumber)==null?void 0:d.decimalPlaces)==null?void 0:g.toString())||"0",onValueChange:u=>{var p,R,L;return t(Number(u),((p=s==null?void 0:s.formatNumber)==null?void 0:p.currency)||"",((R=s==null?void 0:s.formatNumber)==null?void 0:R.locale)||"",((L=s==null?void 0:s.formatNumber)==null?void 0:L.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(u=>e.jsxRuntimeExports.jsx(e.SelectItem,{value:u,children:u},u))})]})]}),e.jsxRuntimeExports.jsxs("div",{className:"w-full space-y-1",children:[e.jsxRuntimeExports.jsx(e.Label,{children:"Suffix"}),e.jsxRuntimeExports.jsx(e.Input,{value:((f=s==null?void 0:s.formatNumber)==null?void 0:f.suffix)||"",className:"h-8 font-mono text-xs focus-visible:ring-0 focus-visible:ring-ring focus-visible:ring-offset-0",placeholder:"K, M, B, %",onChange:u=>{var p,R,L;return t(((p=s==null?void 0:s.formatNumber)==null?void 0:p.decimalPlaces)||0,((R=s==null?void 0:s.formatNumber)==null?void 0:R.currency)||"",((L=s==null?void 0:s.formatNumber)==null?void 0:L.locale)||"",u.target.value)}})]})]})]})}),e.jsxRuntimeExports.jsx(e.Separator,{className:"my-3"}),e.jsxRuntimeExports.jsx(e.ColorFormat,{colorRanges:a,setColorRanges:i})]})]})}function Vt(){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(Mt,{})}),e.jsxRuntimeExports.jsx("div",{}),e.jsxRuntimeExports.jsx("div",{})]})}const qt=[{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"}],_t=["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"],Bt=_t.map(s=>({label:s,value:s}));function Ht(){var l,x,d,g,f,u,p,R,L,b,C,w,v,D,m,N,E,j;const s=e.useEditorStore(I=>I.card),r=(x=(l=s==null?void 0:s.preferences)==null?void 0:l.mapVisualOptions)==null?void 0:x.topoJsonUrl,[t,n]=S.useState(((g=(d=s==null?void 0:s.preferences)==null?void 0:d.mapVisualOptions)==null?void 0:g.customTopoJsonUrl)||""),{setCardPreferences:o}=e.useEditorActions(),{data:a}=e.useTopoJson(s),i=Object.keys((a==null?void 0:a.objects)||{}).map(I=>({label:I,value:I}))||[],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(Ee,{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(Ee,{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:I=>{console.log("value",I),o({...s.preferences,mapVisualOptions:{topoJsonUrl:I}})},value:r||"",label:"Select Map"}),r==="custom"&&e.jsxRuntimeExports.jsx(e.Input,{onChange:I=>{n(I.target.value)},onBlur:()=>{var I;console.log("onBlur",t),o({...s.preferences,mapVisualOptions:{...(I=s.preferences)==null?void 0:I.mapVisualOptions,customTopoJsonUrl:t}})},value:t,className:`h-9 w-full ${e.removeRing}`,placeholder:"Custom URL"}),a&&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:((u=(f=s.preferences)==null?void 0:f.mapVisualOptions)==null?void 0:u.objectKey)||"",label:"Map Object",onValueChange:I=>{var O;o({...s.preferences,mapVisualOptions:{...(O=s.preferences)==null?void 0:O.mapVisualOptions,objectKey:I}})}})]}),e.jsxRuntimeExports.jsxs("div",{className:"space-y-1",children:[e.jsxRuntimeExports.jsx(e.Label,{children:"Projection"}),e.jsxRuntimeExports.jsx(Z,{className:"h-9",options:qt,value:((R=(p=s.preferences)==null?void 0:p.mapVisualOptions)==null?void 0:R.projection)||"",label:"Projection",onValueChange:I=>{var O;o({...s.preferences,mapVisualOptions:{...(O=s.preferences)==null?void 0:O.mapVisualOptions,projection:I}})}})]}),e.jsxRuntimeExports.jsxs("div",{className:"space-y-1",children:[e.jsxRuntimeExports.jsx(e.Label,{children:"Colors"}),e.jsxRuntimeExports.jsx(Z,{className:"h-9",options:Bt,value:((b=(L=s.preferences)==null?void 0:L.mapVisualOptions)==null?void 0:b.colorScale)||"",label:"Select Color Scale",onValueChange:I=>{var O;o({...s.preferences,mapVisualOptions:{...(O=s.preferences)==null?void 0:O.mapVisualOptions,colorScale:I}})}})]})]})]})}),e.jsxRuntimeExports.jsx(e.Separator,{className:"my-4"}),e.jsxRuntimeExports.jsx(Ee,{className:"px-2",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:((w=(C=s.preferences)==null?void 0:C.mapVisualOptions)==null?void 0:w.projectionScale)||1,onChange:I=>{var O;o({...s.preferences,mapVisualOptions:{...(O=s.preferences)==null?void 0:O.mapVisualOptions,projectionScale:Number(I.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:((m=(D=(v=s.preferences)==null?void 0:v.mapVisualOptions)==null?void 0:D.projectionOffset)==null?void 0:m[0])||0,onChange:I=>{var O,z,M,q;o({...s.preferences,mapVisualOptions:{...(O=s.preferences)==null?void 0:O.mapVisualOptions,projectionOffset:[Number(I.target.value),((q=(M=(z=s.preferences)==null?void 0:z.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:((j=(E=(N=s.preferences)==null?void 0:N.mapVisualOptions)==null?void 0:E.projectionOffset)==null?void 0:j[1])||0,onChange:I=>{var O,z,M,q;o({...s.preferences,mapVisualOptions:{...(O=s.preferences)==null?void 0:O.mapVisualOptions,projectionOffset:[((q=(M=(z=s.preferences)==null?void 0:z.mapVisualOptions)==null?void 0:M.projectionOffset)==null?void 0:q[0])||0,Number(I.target.value)]}})}})]})})]})}function Pt(){var n;const s=e.useEditorStore(o=>o.card.preferences),{setCardPreferences:r}=e.useEditorStore(o=>o.actions);function t(o){r({...s,textVisualOptions:{...s==null?void 0:s.textVisualOptions,isDynamicText:o==="dynamic"}})}return e.jsxRuntimeExports.jsxs(e.RadioGroup,{value:(n=s==null?void 0:s.textVisualOptions)!=null&&n.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:r,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:r||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:n=>n.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(Le,{}),s!=="text"&&e.jsxRuntimeExports.jsx(He,{}),s==="text"&&e.jsxRuntimeExports.jsx(Pt,{})]})]}),!["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(me,{}),e.jsxRuntimeExports.jsx(pe,{})]})]})]})})}function $t(){const s=e.useEditorStore(n=>{var o,a;return(a=(o=n==null?void 0:n.card)==null?void 0:o.preferences)==null?void 0:a.sortChart}),{setSortChart:r}=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:n=>{r(n)}})]})}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:n=>n.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(Le,{}),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(me,{}),e.jsxRuntimeExports.jsx(pe,{})]})]})]})})}function Gt({}){const s=e.useEditorStore(n=>{var o;return(o=n.card)==null?void 0:o.preferences}),r=e.useEditorStore(n=>n.actions.setCardPreferences),t=n=>{r({...s,allowDownload:n})};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(me,{}),e.jsxRuntimeExports.jsx(pe,{})]})]})}),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 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 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."]})]}),Jt=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 r(t){switch(t){case"stackedBar":case"stackedLine":return e.jsxRuntimeExports.jsx($t,{});case"pyramid":return e.jsxRuntimeExports.jsx(Se,{docContent:Ut,cardType:t});case"kpi":return e.jsxRuntimeExports.jsx(Vt,{});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(Tt,{cardType:t});case"table":return e.jsxRuntimeExports.jsx(Gt,{cardType:t});case"text":return e.jsxRuntimeExports.jsx(Se,{docContent:Jt,cardType:t,suffix:"Visual"});case"map":return e.jsxRuntimeExports.jsx(Ht,{});case"custom":return e.jsxRuntimeExports.jsx(wt,{});default:return e.jsxRuntimeExports.jsx(zt,{})}}return e.jsxRuntimeExports.jsx(e.ScrollArea,{className:"h-full w-full text-sm",children:r(s)})}function Wt(){const s=e.useEditorStore(r=>r.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(jt,{})}),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(Je,{})})]}):e.jsxRuntimeExports.jsx(Je,{})})]})}function Yt({authToken:s,onSave:r,onClose:t}){e.useDashboardStore(i=>i.themeStyle);const n=e.useEditorStore(i=>i.actions.setOnSave),o=e.useEditorStore(i=>i.actions.setOnClose),a=e.useDashboardStore(i=>i.actions.setAuthToken);return S.useEffect(()=>{r&&n(r),t&&o(t)},[r,n,t,o]),S.useEffect(()=>{s&&s.accessToken&&a(s)},[s,a]),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(Wt,{})})]})})}function Xt(){e.useDashboardStore(i=>i.selectedCardId);const s=e.useDashboardStore(i=>i.selectedSheetId),{setIsVisualEditing:r}=e.useDashboardStore(i=>i.actions),t=e.useDashboardStore(i=>i.isVisualEditing),n=e.useDashboardStore(i=>i.actions.updateFrame);function o(i){s&&(n(s,i),r(!1))}function a(){r(!1)}return e.jsxRuntimeExports.jsx("div",{role:"editor-container",className:e.cn("flex grow",{block:t,hidden:!t}),children:e.jsxRuntimeExports.jsx(Yt,{onSave:o,onClose:a})})}function Zt(){e.useEditorStore(i=>i.selectedConnectionId),e.useEditorStore(i=>i.selectedDatamodelId);const s=e.useEditorStore(i=>i.selectedDatabaseName);e.useEditorStore(i=>i.selectedSchemaName);const r=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:n,columns:o}=ae(),{assignFilter:a}=_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(l=>l.column===e.fmt(i.column_name)&&l.table===r&&l.database===s);return e.jsxRuntimeExports.jsx("div",{onClick:()=>a(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 en(){e.useDashboardStore(r=>r.showFilters);const s=e.useDashboardStore(r=>r.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(Zt,{})})})]})}function sn(){const s=e.useDashboardStore(t=>t.showFilters),r=e.useDashboardStore(t=>t.isVisualEditing);return e.jsxRuntimeExports.jsxs("div",{role:"dashboard-plus-main",className:e.cn("grow",{hidden:r,flex:!r}),children:[e.jsxRuntimeExports.jsx(e.DashboardTabs,{}),s&&e.jsxRuntimeExports.jsx("div",{role:"filter-aside-container",className:"flex",children:e.jsxRuntimeExports.jsx(en,{})})]})}function tn(){const s=e.useDashboardStore(n=>n.dashboard),r=e.useDashboardStore(n=>n.actions.setDashboard),t=e.useDashboardStore(n=>n.showDashboardJSON);return e.useDashboardStore(n=>n.actions.setShowDashboardJSON),e.jsxRuntimeExports.jsx("div",{className:e.cn(" p-2",{hidden:!t}),children:e.jsxRuntimeExports.jsx(e.de,{onChange:n=>{if(n)try{JSON.parse(n),r(JSON.parse(n))}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 nn({showControls:s=!1,showFooter:r=!0,...t}){return e.jsxRuntimeExports.jsx(e.ErrorBoundary,{FallbackComponent:e.Fallback,children:e.jsxRuntimeExports.jsxs(e.SemaphorContextProvider,{dashboardProps:t,children:[e.jsxRuntimeExports.jsx(e.Te,{}),e.jsxRuntimeExports.jsxs(e.UXProvider,{children:[e.jsxRuntimeExports.jsx(tn,{}),e.jsxRuntimeExports.jsxs(e.DashboardPanel,{...t,children:[s&&e.jsxRuntimeExports.jsx(Ys,{}),e.jsxRuntimeExports.jsx(Xt,{}),e.jsxRuntimeExports.jsx(sn,{})]})]})]})})}exports.Box=We;exports.ChartArea=Ye;exports.ChartColumnIncreasing=we;exports.ChartLine=ke;exports.ChartNoAxesGantt=Ae;exports.ChartPie=Oe;exports.ChartScatter=ze;exports.CircleX=Xe;exports.CopyPlus=Ze;exports.DashboardPlus=nn;exports.Database=es;exports.EllipsisVertical=Fe;exports.Eraser=ss;exports.Eye=ns;exports.EyeClosed=ts;exports.Glasses=rs;exports.Hammer=os;exports.Hash=is;exports.House=as;exports.Key=Me;exports.ListEnd=ls;exports.ListStart=cs;exports.ListX=xs;exports.LoaderCircle=de;exports.Map=Ve;exports.MessageSquareMore=us;exports.Network=ds;exports.Pencil=qe;exports.Play=ms;exports.Plug2=ps;exports.Save=js;exports.SelectComponent=ue;exports.Shapes=_e;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=Be;exports.useEditorAside=ae;
245
+ Visual Query Syntax: ${ot}`,{data:m,isLoading:N,isFetching:E,isError:j,refetch:I}=e.useQuery({queryKey:["ai-query"],queryFn:()=>e.getRequest("https://semaphor.cloud/api/v1/ai",(l==null?void 0:l.accessToken)||"",{user_content:`userContent: ${v} ${x?D:""}`}),enabled:!1});function O(k){if(k.toLowerCase().includes("bar"))p("bar");else if(k.toLowerCase().includes("line"))p("line");else if(k.toLowerCase().includes("bubble"))p("bubble");else if(k.toLowerCase().includes("scatter"))p("scatter");else if(k.toLowerCase().includes("stacked"))p("stackedBar");else if(k.toLowerCase().includes("pie"))p("pie");else if(k.toLowerCase().includes("donut")||k.toLowerCase().includes("doughnut"))p("doughnut");else if(k.toLowerCase().includes("radar"))p("radar");else return p("bar"),!1;return!0}S.useEffect(()=>{m&&L(k=>[...k,{role:"ai",content:m.response}])},[m]),S.useEffect(()=>{const k=setTimeout(()=>{var F;c.current&&(c.current.scroll({top:c.current.scrollHeight,behavior:"smooth"}),(F=i.current)==null||F.focus())},100);return()=>clearTimeout(k)},[R]);function z(){t&&(L(k=>[...k,{role:"user",content:t}]),O(t)&&d(!0),n(""),I())}S.useEffect(()=>{o&&(z(),a(!1))},[o,a]);const M={fontFamily:"Arial, sans-serif",lineHeight:1.6,fontSize:15,width:"100%"},q={fontFamily:"monospace",fontSize:14,lineHeight:1.6},H={fontFamily:"Arial, sans-serif",lineHeight:1.6,fontSize:15,padding:"2px 0",marginLeft:20,listStyleType:"disc"},U={p:({node:k,...F})=>e.jsxRuntimeExports.jsx("p",{style:M,...F}),code:({node:k,...F})=>e.jsxRuntimeExports.jsx("code",{className:"rounded-sm bg-muted px-2 py-1 text-sm",...F}),pre:({node:k,...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:B=>{const A=_(B);A&&(r(!1),g(A),u(!0))},size:"sm",variant:"outline",children:e.jsxRuntimeExports.jsx(e.PlayIcon,{})})]})]}),li:({node:k,...F})=>e.jsxRuntimeExports.jsx("li",{style:H,...F})};function _(k){const F=k.currentTarget.closest("pre");if(!F)return;const B=F.textContent||F.innerText;return navigator.clipboard.writeText(B).then(()=>console.log("Text copied to clipboard")).catch(A=>console.error("Error in copying text: ",A)),B}function W(){return R==null?void 0:R.map((k,F)=>k.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:k.content})]},F):k.role==="ai"?e.jsxRuntimeExports.jsx(e.Markdown,{className:"w-full overflow-auto py-1",components:U,children:m==null?void 0:m.response.replace(/DuckDB/gi,"Semaphor")},F):e.jsxRuntimeExports.jsx("div",{},F))}return e.jsxRuntimeExports.jsxs(e.Dialog,{open:s,onOpenChange:r,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:W()})}),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:k=>{k.key==="Enter"&&!k.shiftKey&&(k.preventDefault(),n(""),z())},placeholder:"Type your question here...",onFocus:k=>{const F=k.target,B=F.value.length;F.setSelectionRange(B,B)},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:N||E,value:t,onChange:k=>n(k.target.value)})," ",e.jsxRuntimeExports.jsx(e.Button,{className:"h-8",size:"sm",variant:"ghost",onClick:z,children:!N&&!E?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},Ue=S.createContext&&S.createContext(Cs),at=["attr","size","title"];function lt(s,r){if(s==null)return{};var t=ct(s,r),n,o;if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(s);for(o=0;o<a.length;o++)n=a[o],!(r.indexOf(n)>=0)&&Object.prototype.propertyIsEnumerable.call(s,n)&&(t[n]=s[n])}return t}function ct(s,r){if(s==null)return{};var t={},n=Object.keys(s),o,a;for(a=0;a<n.length;a++)o=n[a],!(r.indexOf(o)>=0)&&(t[o]=s[o]);return t}function Ce(){return Ce=Object.assign?Object.assign.bind():function(s){for(var r=1;r<arguments.length;r++){var t=arguments[r];for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(s[n]=t[n])}return s},Ce.apply(this,arguments)}function Qe(s,r){var t=Object.keys(s);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(s);r&&(n=n.filter(function(o){return Object.getOwnPropertyDescriptor(s,o).enumerable})),t.push.apply(t,n)}return t}function Ne(s){for(var r=1;r<arguments.length;r++){var t=arguments[r]!=null?arguments[r]:{};r%2?Qe(Object(t),!0).forEach(function(n){xt(s,n,t[n])}):Object.getOwnPropertyDescriptors?Object.defineProperties(s,Object.getOwnPropertyDescriptors(t)):Qe(Object(t)).forEach(function(n){Object.defineProperty(s,n,Object.getOwnPropertyDescriptor(t,n))})}return s}function xt(s,r,t){return r=ut(r),r in s?Object.defineProperty(s,r,{value:t,enumerable:!0,configurable:!0,writable:!0}):s[r]=t,s}function ut(s){var r=dt(s,"string");return typeof r=="symbol"?r:String(r)}function dt(s,r){if(typeof s!="object"||s===null)return s;var t=s[Symbol.toPrimitive];if(t!==void 0){var n=t.call(s,r||"default");if(typeof n!="object")return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return(r==="string"?String:Number)(s)}function Ns(s){return s&&s.map((r,t)=>S.createElement(r.tag,Ne({key:t},r.attr),Ns(r.child)))}function ee(s){return r=>S.createElement(mt,Ce({attr:Ne({},s.attr)},r),Ns(s.child))}function mt(s){var r=t=>{var{attr:n,size:o,title:a}=s,i=lt(s,at),c=o||t.size||"1em",l;return t.className&&(l=t.className),s.className&&(l=(l?l+" ":"")+s.className),S.createElement("svg",Ce({stroke:"currentColor",fill:"currentColor",strokeWidth:"0"},t.attr,n,i,{className:l,style:Ne(Ne({color:s.color||t.color},t.style),s.style),height:c,width:c,xmlns:"http://www.w3.org/2000/svg"}),a&&S.createElement("title",null,a),s.children)};return Ue!==void 0?S.createElement(Ue.Consumer,null,t=>r(t)):r(Cs)}function pt(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 jt(){const{theme:s}=e.useTheme(),r=S.useRef(),t=S.useRef(),[n,o]=S.useState(!1),[a,i]=S.useState(!1),[c,l]=S.useState(!1),[x,d]=S.useState(""),[g,f]=S.useState(!1),{authToken:u}=e.useSemaphorContext(),p=e.useDashboardStore(h=>h.selectedSheetId),R=e.useDashboardStore(h=>h.dashboard.baseQueries),L=e.useEditorStore(h=>h.card),b=e.useDashboardStore(h=>h.theme),C=e.useEditorStore(h=>h.isShowingVisual);e.useDashboardStore(h=>h.onAcceptChanges);const w=e.useEditorStore(h=>h.selectedConnectionId),v=e.useEditorStore(h=>h.selectedDatabaseName),D=e.useEditorStore(h=>h.selectedDatamodelId),m=e.useEditorStore(h=>h.selectedSchemaName);e.useDashboardStore(h=>h.actions.updateFrameCard);const N=e.useEditorStore(h=>h.selectedTableName),E=e.useEditorStore(h=>h.card.sql),j=e.useEditorStore(h=>h.card.python),I=e.resolveBaseQuery(E,R),O=e.useEditorStore(h=>h.selectedConnectionId),z=e.useEditorStore(h=>h.frame),M=e.useDashboardStore(h=>h.dashboard.filters),q=e.useDashboardStore(h=>h.filterValues),H=M==null?void 0:M.filter(h=>h.sheetId===p||!h.sheetId),U=q==null?void 0:q.filter(h=>(H==null?void 0:H.some(J=>J.id===h.filterId))||h.filterId.endsWith(p)),_=e.useEditorStore(h=>h.applyFilters),{setCardCustomCfg:W,setQueryResultColumns:k,setFilterValues:F,setCardSql:B,setCardPython:A,setQueryError:T,setPythonStdOut:G,setCardPreferences:V}=e.useEditorStore(h=>h.actions),P=e.useEditorStore(h=>h.onSave),Q=e.useEditorStore(h=>h.actions.setApplyFilters),se=e.useEditorStore(h=>h.onClose),Y=e.useEditorStore(h=>h.actions.setCardData),ne=e.useEditorStore(h=>h.actions.setSqlGen),re=e.useEditorStore(h=>h.runSql),oe=e.useEditorStore(h=>h.actions.setRunSql),te=e.useEditorStore(h=>h.actions.setIsSqlRunning),{data:$,isLoading:X,isFetching:le,isSuccess:fe,isError:ce,error:je,status:Pe,refetch:xe}=e.useQuery({queryKey:[I,j],queryFn:()=>e.postRequest("https://semaphor.cloud/api/v1/query",(u==null?void 0:u.accessToken)||"",{connection_id:O,sql:I,python:j===e.PYTHON_DEFAULT_CODE?"":j,active_filters:_?U:[],cache_config:e.getCacheConfig()}),enabled:!1,retry:!1});S.useEffect(()=>{if($&&(Y($.records),$.rowLimitExceeded&&e.Jt.error("Row limit (10,000) exceeded. Refine your query.",{position:"top-center",richColors:!0}),G(($==null?void 0:$.output)||""),$.records.length>0)){const{dimensionKeys:h}=e.getKeys($.records);k(h)}},[$,Y,k,G]),S.useEffect(()=>{re&&(xe(),oe(!1))},[re,xe,oe]),S.useEffect(()=>{(X||le)&&te(!0),(ce||fe)&&te(!1),ce?(T(je.message),Y([]),k([]),G("")):T("")},[X,le,$,G,ce,fe,te,Y,k,T,je]);function ge(){B(""),Y([]),ne({}),W(""),V({})}const he=h=>{t.current=h};function Re(h,J){if(h.length===0)return"";if(J){const ie=h.find(K=>K.id===J);if(ie){const K=ie.tabTitle;if(K=="All__Header")return h[0].id;if(K&&K.endsWith("__Header")){const Ps=K.split("__")[0],$e=h.find($s=>$s.tabTitle===Ps);return $e?$e.id:h[0].id}return J}}return h[0].id}function be(){let h=E;E&&!E.includes("{{")&&(h=et(E),B(h));const J={...L,lastSelectedSchema:m,lastSelectedDatamodelId:D,lastSelectedDatabase:v,lastSelectedTable:N,connectionId:w,type:C?L.type:"table",sql:h,customCfg:C?L.customCfg:null},ie=z.cards.map(De=>De.id===L.id?J:De),K={...z,cards:ie,activeCardId:Re(ie,z.activeCardId)};P==null||P(K)}function ye(){se==null||se()}S.useEffect(()=>{const h=r.current,J=t.current;if(h){const ie=window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light",K=b==="system"?ie:b;h.editor.defineTheme("default",{base:K==="light"?"vs":"vs-dark",inherit:!0,rules:[],colors:{"editor.background":K==="light"?"#ffffff":e.getCssVariableValue("--semaphor-background")}}),h.editor.setTheme("default")}return J&&h&&J.addCommand(h.KeyMod.Shift|h.KeyCode.Enter,function(){return console.log("Executing query..."),xe(),!1}),()=>{}},[s,b,r.current]);function y(h){r.current=h}function Bs(){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(tt,{checked:_,onCheckedChange:()=>Q(!_),text:"Apply Filters"}),e.jsxRuntimeExports.jsx(rt,{}),U&&a&&e.jsxRuntimeExports.jsx(e.Cross2Icon,{onClick:()=>i(!1),className:"bg-background/50 text-foreground/50 hover:cursor-pointer hover:text-foreground"})]}),e.jsxRuntimeExports.jsx(e.Ft,{theme:"default",onChange:h=>{if(h)try{JSON.parse(h),F(JSON.parse(h))}catch{}},defaultLanguage:"json",className:"mt-1 min-h-[220px]",value:JSON.stringify(U,null,2),options:{readOnly:!0,minimap:{enabled:!1},lineNumbers:"off",glyphMargin:!1,wordWrap:"on",scrollbar:{verticalScrollbarSize:0,horizontalScrollbarSize:0},fontSize:12,renderLineHighlight:"none"}})]})}),U&&!a&&e.jsxRuntimeExports.jsx(e.Filter,{onClick:()=>i(!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":_})})]})}function Hs(){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:n?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:h=>{B(h)},value:E,options:{minimap:{enabled:!1},wordWrap:"on",scrollbar:{verticalScrollbarSize:0,horizontalScrollbarSize:0},fontSize:14,renderLineHighlight:"none"},defaultLanguage:"sql",beforeMount:y,onMount:he})}),n&&e.jsxRuntimeExports.jsx("code",{className:"absolute right-6 top-3 text-sm text-muted-foreground/70",children:"sql"})]}),n&&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:h=>{A(h&&h.trim()||"")},value:j||e.PYTHON_DEFAULT_CODE,options:{minimap:{enabled:!1},wordWrap:"on",scrollbar:{verticalScrollbarSize:0,horizontalScrollbarSize:0},fontSize:14,renderLineHighlight:"none"},defaultLanguage:"python",beforeMount:y,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:[Hs(),Bs()]}),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:X||le,onClick:()=>{xe()},className:"shrink-0",size:"sm",variant:"outline",children:[X||le?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(st,{error:je.message,setShowAIDialog:l,setTriggerAIRun:f,setUserInputforAI:d}),e.jsxRuntimeExports.jsxs(e.Button,{onClick:ge,className:"",size:"sm",variant:"outline",children:[e.jsxRuntimeExports.jsx(ss,{className:"mr-2 size-4"}),"Clear"]}),e.jsxRuntimeExports.jsx(e.Toggle,{pressed:n,onPressedChange:h=>o(h),className:"",size:"sm",variant:"outline",children:e.jsxRuntimeExports.jsx(pt,{className:"size-4 text-foreground/70"})}),e.jsxRuntimeExports.jsx(it,{open:c,setOpen:l,userInput:x,triggerAIRun:g,setTriggerAIRun:f,setUserInput:h=>d(h)})]}),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 ht({data:s}){var i;const[r,t]=S.useState([]),o=Object.keys(s[0]).map(c=>({accessorKey:c,header:({column:l})=>{const x=l.getIsSorted();return e.jsxRuntimeExports.jsx("div",{className:"flex gap-2",children:e.jsxRuntimeExports.jsxs("div",{className:"flex cursor-pointer items-center",onClick:()=>l.toggleSorting(l.getIsSorted()==="asc"),children:[c,x==="asc"?e.jsxRuntimeExports.jsx(e.TriangleUpIcon,{className:"ml-2 h-5 w-5"}):x==="desc"?e.jsxRuntimeExports.jsx(e.TriangleDownIcon,{className:"ml-2 h-5 w-5"}):null]})})}})),a=e.useReactTable({data:s,columns:o,getCoreRowModel:e.getCoreRowModel(),getPaginationRowModel:e.getPaginationRowModel(),onSortingChange:t,getSortedRowModel:e.getSortedRowModel(),manualPagination:!0,state:{sorting:r}});return e.jsxRuntimeExports.jsxs(e.Table$1,{children:[e.jsxRuntimeExports.jsx(e.TableHeader,{children:a.getHeaderGroups().map(c=>e.jsxRuntimeExports.jsx(e.TableRow,{children:c.headers.map(l=>e.jsxRuntimeExports.jsx(e.TableHead,{className:"sticky top-0 bg-muted",children:l.isPlaceholder?null:e.flexRender(l.column.columnDef.header,l.getContext())},l.id))},c.id))}),e.jsxRuntimeExports.jsx(e.TableBody,{children:(i=a.getRowModel().rows)!=null&&i.length?a.getRowModel().rows.map(c=>e.jsxRuntimeExports.jsx(e.TableRow,{className:"whitespace-nowrap py-2","data-state":c.getIsSelected()&&"selected",children:c.getVisibleCells().map(l=>e.jsxRuntimeExports.jsx(e.TableCell,{children:e.flexRender(l.column.columnDef.cell,l.getContext())},l.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 Et({card:s}){var x,d,g,f,u,p,R,L,b,C;const r=e.useDashboardStore(w=>w.themeStyle),t={colors:((d=(x=r==null?void 0:r.chart)==null?void 0:x.dataset)==null?void 0:d.backgroundColor)||[]};(g=s.customCardPreferences)!=null&&g.inputData;const{getCard:n}=e.useCustomVisual(((f=s.customCardPreferences)==null?void 0:f.url)||""),o=((u=s.customCardPreferences)==null?void 0:u.visualType)||"single",a=e.useEditorStore(w=>w.frame);if(e.useEditorActions(),!((p=s.customCardPreferences)!=null&&p.componentName))return null;const i=n((R=s.customCardPreferences)==null?void 0:R.componentName),c=w=>{console.log("data",w),s.customCardPreferences},l=Object.keys(((L=s.customCardPreferences)==null?void 0:L.dataInputCardIds)||{}).map(w=>{var m,N,E;const v=(N=(m=s.customCardPreferences)==null?void 0:m.dataInputCardIds)==null?void 0:N[w].cardId,D=(E=a==null?void 0:a.cards)==null?void 0:E.find(j=>j.id===v);return D||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:[i&&o==="single"&&e.jsxRuntimeExports.jsx(i,{theme:t,settings:(b=s.customCardPreferences)==null?void 0:b.settings,onDataChange:c,data:s.data}),i&&o==="multiple"&&e.jsxRuntimeExports.jsx("div",{className:"flex flex-col gap-2",children:e.jsxRuntimeExports.jsx(i,{theme:t,onDataChange:c,settings:l.map(w=>{var v;return(v=w==null?void 0:w.customCardPreferences)==null?void 0:v.settings}),data:l.map(w=>(w==null?void 0:w.data)||[])})})]},(C=s.customCardPreferences)==null?void 0:C.componentName)})}function ws({className:s,...r}){var L,b;S.useState(0);const t=e.useDashboardStore(C=>C.themeStyle),n=e.useEditorStore(C=>C.card),o=((L=n.customCardPreferences)==null?void 0:L.showCardHeader)??!0,a=e.useEditorStore(C=>C.frame),i=e.useDashboardStore(C=>C.dashboard.filters);e.useDashboardStore(C=>C.filterValues),e.useEditorStore(C=>C.actions.setRunSql);const{updateFilter:c}=e.useDashboardActions(),l=i==null?void 0:i.find(C=>C.id===a.filterId),x=e.useEditorStore(C=>C.actions.setCard),{data:d,isLoading:g,isFetching:f,isError:u}=e.useTopoJson(n);if(S.useEffect(()=>{},[n.data,n.type,n.cfg,n.customCfg,t,n.preferences]),!n.id)return null;let p;n.data&&n.data.length>0&&(p=e.createChartConfig({data:n.data,cardType:n.type,cfg:n.cfg,customCfg:n.customCfg,preferences:n.preferences,topoJson:d}));function R(C){return e.jsxRuntimeExports.jsx(Et,{card:C})}return e.jsxRuntimeExports.jsxs(e.Card,{role:"editor-visual-card",className:e.cn("relative flex h-full flex-col rounded-none",s),...r,children:[o&&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:n.title,onSave:C=>x({...n,title:C}),children:e.jsxRuntimeExports.jsx("div",{className:"flex items-center gap-5",children:e.jsxRuntimeExports.jsx(e.CardTitle,{className:"text-base",children:n.title||"Edit title..."})})},n.title),e.jsxRuntimeExports.jsx(e.Editable,{text:n.description||"",onSave:C=>x({...n,description:C}),children:e.jsxRuntimeExports.jsx(e.CardDescription,{children:n.description||"Edit description..."})},n.description)]}),l&&e.jsxRuntimeExports.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxRuntimeExports.jsx(e.Editable,{className:"my-1",text:l.title||l.column,onSave:C=>c({...l,title:C}),children:e.jsxRuntimeExports.jsx(e.Label,{children:l.title})}),e.getFilterComponent(l)]})]}),e.jsxRuntimeExports.jsxs(e.CardContent,{className:"flex grow flex-col",children:[n.type==="custom"&&R(n),!["table","custom"].includes(n.type)&&p&&e.jsxRuntimeExports.jsx(e.ChartJsVisual,{cfg:p},JSON.stringify(p)+JSON.stringify(n.preferences)+((b=n==null?void 0:n.preferences)==null?void 0:b.customVisualCode)),n.type==="table"&&n.data&&n.data.length>0&&e.jsxRuntimeExports.jsx(e.$57acba87d6e25586$export$ccf8d8d7bbf3c2cc,{className:"flex min-h-0 flex-1 grow basis-0",children:e.jsxRuntimeExports.jsx(e.TableVisual,{card:n,data:n==null?void 0:n.data})})]})]})}function ft(){const[s,r]=S.useState(!1),[t,n]=S.useState(""),[o,a]=S.useState(""),[i,c]=S.useState(""),[l,x]=S.useState(""),d=e.useEditorStore(v=>v.card),g=e.useEditorStore(v=>v.card.customCfg),{data:f}=e.useTopoJson(d),{setCardCustomCfg:u,setCustomVisualCode:p}=e.useEditorActions();function R(v){var N,E;const D={...v,data:{...v==null?void 0:v.data,datasets:(E=(N=v==null?void 0:v.data)==null?void 0:N.datasets)==null?void 0:E.map(j=>({...j,data:[]}))}};return JSON.stringify(D,null,1)}function L(){var D,m;if(!d.data||d.data.length===0)return;const v=e.createChartConfig({data:d.data,cardType:d.type,cfg:d.cfg,preferences:d.preferences,topoJson:f});v&&(n(JSON.stringify(v,null,1)),(D=d==null?void 0:d.preferences)!=null&&D.customVisualCode&&c((m=d==null?void 0:d.preferences)==null?void 0:m.customVisualCode),g&&a(JSON.stringify(g,null,1)))}function b(){if(i&&p(i),!!o)try{const v=JSON.parse(o);return v?(u(v),x(""),a(""),v):void 0}catch(v){console.log(v),x("Invalid JSON")}}function C(){a(""),u(null)}function w(){let v;if(g){const D=e._.cloneDeep(d.cfg),m=e._.merge(D,g);return v=R(m),v}return t?(v=R(JSON.parse(t)),v):""}return e.jsxRuntimeExports.jsxs(e.Dialog,{open:s,onOpenChange:r,children:[e.jsxRuntimeExports.jsx(e.DialogTrigger,{asChild:!0,children:e.jsxRuntimeExports.jsx(e.Button,{onClick:L,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(Me,{onClick:()=>{navigator.clipboard.writeText(d.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(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:w(),onChange:v=>a(v)})}),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:v=>c(v||"")})})]})]}),e.jsxRuntimeExports.jsxs(e.DialogFooter,{className:"flex items-center",children:[e.jsxRuntimeExports.jsx(e.Label,{className:"mr-2 text-red-500",children:l}),e.jsxRuntimeExports.jsx(e.Button,{disabled:!g,onClick:C,variant:"outline",children:"Reset"}),e.jsxRuntimeExports.jsx(e.Button,{onClick:b,variant:"outline",children:"Apply"}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>r(!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:"M137.39,24.06A16,16,0,0,0,120,40V80.67a15.86,15.86,0,0,0,13.25,15.76A32,32,0,1,1,96,129.68c-.41-8.22,1.27-15,5-20.26h0a15.86,15.86,0,0,0-1.69-20.47L71.69,60.68a16,16,0,0,0-23.63,1.1A103.6,103.6,0,0,0,55,202.05,103.24,103.24,0,0,0,128,232h1.49A104.3,104.3,0,0,0,232,129.48C232.75,75.18,191.19,28.88,137.39,24.06ZM60.32,71.94l27.61,28.19,0,.06A43.29,43.29,0,0,0,80.44,120H40.36A87.13,87.13,0,0,1,60.32,71.94ZM40.37,136h40.3A48,48,0,0,0,120,175.34v40.3A88,88,0,0,1,40.37,136Zm149.77,54.14A87.45,87.45,0,0,1,136,215.61V175.34a47.55,47.55,0,0,0,24.73-12.23A48,48,0,0,0,136,80.66L136,40c45.52,4.08,80.67,43.28,80,89.25A87.45,87.45,0,0,1,190.14,190.14Z"},child:[]}]})(s)}function Ls(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 Ds(s){return ee({tag:"svg",attr:{viewBox:"0 0 24 24",strokeWidth:"2",stroke:"currentColor",fill:"none",strokeLinecap:"round",strokeLinejoin:"round"},child:[{tag:"path",attr:{stroke:"none",d:"M0 0h24v24H0z",fill:"none"},child:[]},{tag:"path",attr:{d:"M6 16m-3 0a3 3 0 1 0 6 0a3 3 0 1 0 -6 0"},child:[]},{tag:"path",attr:{d:"M16 19m-2 0a2 2 0 1 0 4 0a2 2 0 1 0 -4 0"},child:[]},{tag:"path",attr:{d:"M14.5 7.5m-4.5 0a4.5 4.5 0 1 0 9 0a4.5 4.5 0 1 0 -9 0"},child:[]}]})(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[r,t]=S.useState(null);return S.useEffect(()=>{s&&(async()=>{const a=(await Promise.resolve().then(()=>require("./lucide-react-C382QbK3.js")))[s];t(a)})()},[s]),r}function Ms(){const{authToken:s}=e.useSemaphorContext(),{data:r,isLoading:t,isFetching:n,isError:o}=e.useQuery({queryKey:["plugins",s==null?void 0:s.accessToken],queryFn:()=>e.getPlugins(s==null?void 0:s.accessToken)});return{data:r,isLoading:t,isFetching:n,isError:o}}function gt({onChartTypeChange:s}){const[r,t]=S.useState([]),{data:n}=Ms();return S.useEffect(()=>{(async()=>{var a;if(n){const c=(await Promise.all((a=n==null?void 0:n.plugins)==null?void 0:a.map(async l=>(await e.loadManifest(l.value)).visuals.map(g=>({name:g.name,icon:g.icon,url:l.value}))))).flat();t(c)}})()},[n]),r.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:r.map((o,a)=>e.jsxRuntimeExports.jsx(Rt,{text:o.name,onClick:()=>s("custom",o),icon:o.icon},o.url+o.name+a))})]})}const Rt=({text:s,icon:r,onClick:t})=>{const n=Fs(r||""),o=s.charAt(0).toUpperCase();return e.jsxRuntimeExports.jsx(e.Button,{onClick:t,title:s,variant:"ghost",children:n?e.jsxRuntimeExports.jsx(n,{className:"h-4 w-4"}):o})};function bt(){var d,g;const[s,r]=S.useState(!1),t=e.useEditorStore(f=>f.card),n=t.type,{setCardType:o,setCardPreferences:a,setChartOrientation:i}=e.useEditorStore(f=>f.actions),{setCardCustomCfg:c,setCustomCardPreferences:l}=e.useEditorActions();function x(f,u){c(null),a({}),o(f),u&&l({type:"component",visualType:"single",url:u.url,componentName:u.name,icon:u.icon}),r(!1)}return e.jsxRuntimeExports.jsxs(e.Popover,{open:s,onOpenChange:r,children:[e.jsxRuntimeExports.jsx(e.PopoverTrigger,{asChild:!0,children:e.jsxRuntimeExports.jsx(e.Button,{size:"sm",variant:"outline",children:e.jsxRuntimeExports.jsx(yt,{className:"h-4 w-4",chartType:n,customIcon:(d=t.customCardPreferences)==null?void 0:d.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:()=>x("bar"),className:"font-normal",variant:"ghost",children:e.jsxRuntimeExports.jsx(we,{className:"size-5"})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>x("line"),variant:"ghost",children:e.jsxRuntimeExports.jsx(ke,{className:"size-5"})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>x("stackedBar"),variant:"ghost",children:e.jsxRuntimeExports.jsx(As,{className:"size-5",strokeWidth:0})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>x("stackedLine"),variant:"ghost",children:e.jsxRuntimeExports.jsx(Ts,{className:"size-5",strokeWidth:0})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>x("scatter"),variant:"ghost",children:e.jsxRuntimeExports.jsx(ze,{className:"size-5"})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>x("bubble"),variant:"ghost",children:e.jsxRuntimeExports.jsx(Ds,{className:"size-4"})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>x("pie"),variant:"ghost",children:e.jsxRuntimeExports.jsx(Oe,{className:"size-5"})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>x("doughnut"),variant:"ghost",children:e.jsxRuntimeExports.jsx(Is,{className:"size-5",strokeWidth:1})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>x("radar"),variant:"ghost",children:e.jsxRuntimeExports.jsx(ks,{className:"size-5 font-extralight",strokeWidth:.5})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>x("polarArea"),variant:"ghost",children:e.jsxRuntimeExports.jsx(Ls,{className:"size-5"})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>x("pyramid"),variant:"ghost",children:e.jsxRuntimeExports.jsx(zs,{className:"size-5"})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>x("range"),variant:"ghost",children:e.jsxRuntimeExports.jsx(Ae,{className:"size-5"})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>x("table"),variant:"ghost",children:e.jsxRuntimeExports.jsx(e.Table,{className:"size-5"})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>x("kpi"),variant:"ghost",children:e.jsxRuntimeExports.jsx(Os,{className:"size-6"})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>x("text"),variant:"ghost",children:e.jsxRuntimeExports.jsx(Ie,{className:"size-4"})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>x("map"),variant:"ghost",children:e.jsxRuntimeExports.jsx(Ve,{className:"size-4"})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>x("custom"),variant:"ghost",children:e.jsxRuntimeExports.jsx(_e,{className:"size-4"})})]}),e.jsxRuntimeExports.jsx(gt,{onChartTypeChange:x})]})]})}function yt({chartType:s,className:r,customIcon:t,componentName:n}){const o=Fs(t||"");switch(s){case"bar":return e.jsxRuntimeExports.jsx(we,{className:r});case"line":return e.jsxRuntimeExports.jsx(ke,{className:r});case"pie":return e.jsxRuntimeExports.jsx(Oe,{className:r});case"radar":return e.jsxRuntimeExports.jsx(ks,{className:r});case"scatter":return e.jsxRuntimeExports.jsx(ze,{className:r});case"bubble":return e.jsxRuntimeExports.jsx(Ds,{className:r});case"doughnut":return e.jsxRuntimeExports.jsx(Is,{className:r});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(Ls,{className:r});case"pyramid":return e.jsxRuntimeExports.jsx(zs,{className:r});case"range":return e.jsxRuntimeExports.jsx(Ae,{className:r});case"kpi":return e.jsxRuntimeExports.jsx(Os,{className:r});case"text":return e.jsxRuntimeExports.jsx(Ie,{className:r});case"map":return e.jsxRuntimeExports.jsx(Ve,{className:r});case"custom":return t&&o?e.jsxRuntimeExports.jsx(o,{className:r}):n?n==null?void 0:n.charAt(0).toUpperCase():e.jsxRuntimeExports.jsx(_e,{className:r});default:return e.jsxRuntimeExports.jsx(e.Table,{className:r})}}function vt(){var o;const s=e.useEditorStore(a=>a.card),r=((o=s.customCardPreferences)==null?void 0:o.showCardHeader)??!0,{setCustomCardPreferences:t}=e.useEditorActions(),n=a=>{s.customCardPreferences&&t({...s.customCardPreferences,showCardHeader:a===!0})};return e.jsxRuntimeExports.jsxs(e.DropdownMenu,{children:[e.jsxRuntimeExports.jsx(e.DropdownMenuTrigger,{asChild:!0,children:e.jsxRuntimeExports.jsx(Fe,{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:r,onCheckedChange:n,children:"Card Header"}),e.jsxRuntimeExports.jsxs(e.DropdownMenuItem,{onClick:()=>{navigator.clipboard.writeText(s.id),e.Jt.success("Card ID copied to clipboard")},className:"cursor-pointer space-x-2",children:[e.jsxRuntimeExports.jsx(Me,{className:"size-4"}),e.jsxRuntimeExports.jsx("span",{children:"Copy Card ID"})]})]})]})}function Je(){const s=e.useEditorStore(m=>m.frame),r=e.useEditorStore(m=>m.card),t=e.useEditorStore(m=>m.card.data),n=e.useEditorStore(m=>m.isShowingVisual),o=e.useEditorStore(m=>m.isSqlRunning),a=e.useEditorStore(m=>m.queryError),i=e.useEditorStore(m=>m.pythonStdOut),c=e.useEditorStore(m=>m.actions.setRunSql);e.useEditorStore(m=>m.onSave),e.useEditorStore(m=>m.onClose),e.useEditorStore(m=>m.actions.setCardSql),e.useEditorStore(m=>m.actions.setCardType),e.useEditorStore(m=>m.actions.setSqlGen);const{setFrame:l,setCard:x,updateCardInFrame:d}=e.useEditorActions();if(!r)return e.jsxRuntimeExports.jsx(e.jsxRuntimeExports.Fragment,{children:"No Active Card"});function g(){const m={id:e.v4(),title:"Title",description:"Description",preferences:{onClickFilter:[{columnIndex:0,expression:""}]},type:"bar",sql:"",data:[]};f(m)}function f(m){const N={...s,cards:[...s.cards,m],activeCardId:m.id};l(N),x(m)}function u(){const m={...r,id:e.v4(),title:`${r.title} Copy`,tabTitle:`${r.tabTitle} Copy`};f(m)}function p(m){const N=s.cards.filter(I=>I.id!==m),E=N[0],j={...s,cards:N,activeCardId:E.id};l(j),x(E)}function R(m){const N={...s,cards:s.cards.map(j=>j.id===r.id?r:j),activeCardId:m};l(N);const E=N.cards.find(j=>j.id===m);x(E),E.sql&&E.data&&E.data.length===0&&c(!0)}const L=(m,N)=>{console.log("handleDragStart",N),m.dataTransfer.setData("tabIndex",N.toString())},b=m=>{m.preventDefault()},C=(m,N)=>{const E=m.dataTransfer.getData("tabIndex");if(E===N.toString())return;const j=Array.from(s.cards),[I]=j.splice(parseInt(E),1);j.splice(N,0,I),l({...s,cards:j})};function w(m,N){return m.cards.length===1&&(N.displayTab===!0||N.displayTab===void 0)||m.activeCardId!==N.id&&(N.displayTab===!0||N.displayTab===void 0)?null:e.jsxRuntimeExports.jsx("div",{onClick:()=>{const E=N.displayTab===void 0?!1:!N.displayTab;x({...N,displayTab:E}),d({...N,displayTab:E})},children:N.displayTab===!0||N.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 v(){return e.jsxRuntimeExports.jsxs(e.Tabs,{onValueChange:R,value:s.activeCardId,className:"flex grow flex-col",children:[s.cards.map(m=>e.jsxRuntimeExports.jsx(e.TabsContent,{className:"mt-0 grow",value:m.id,children:D()},m.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((m,N)=>e.jsxRuntimeExports.jsx(e.Editable,{text:m.tabTitle||m.title,onSave:E=>{x({...r,tabTitle:E}),d({...r,tabTitle:E})},children:e.jsxRuntimeExports.jsxs(e.TabsTrigger,{draggable:!0,onDragStart:E=>L(E,N),onDragOver:b,onDrop:E=>C(E,N),className:"",value:m.id,children:[w(s,m),m.tabTitle||m.title,s.activeCardId===m.id&&s.cards.length>1&&e.jsxRuntimeExports.jsx(e.X,{className:"ml-2 size-3.5 text-muted-foreground hover:text-foreground",onClick:()=>p(m.id)})]})},m.id)),e.jsxRuntimeExports.jsx(e.Button,{className:"ml-1 h-8 px-2 hover:bg-muted-foreground/50",variant:"outline",onClick:g,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:u,children:e.jsxRuntimeExports.jsx(Ze,{className:"h-4 w-4"})})]})})]})}function D(){return r.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,{isLoading:o,card:r})})}):r.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.TextCard,{isLoading:o,card:r})})}):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:[o&&e.jsxRuntimeExports.jsx(de,{className:"absolute bottom-0 left-0 right-0 top-0 z-10 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:[n&&e.jsxRuntimeExports.jsxs("div",{className:"flex grow items-center gap-2",children:[e.jsxRuntimeExports.jsx(bt,{}),!["table","custom"].includes(r.type)&&e.jsxRuntimeExports.jsx(ft,{}),e.jsxRuntimeExports.jsx(vt,{})]}),e.jsxRuntimeExports.jsx(Ct,{})]}),n?v():e.jsxRuntimeExports.jsxs("div",{className:"flex min-h-0 w-full flex-1 grow basis-0 px-6",children:[i&&e.jsxRuntimeExports.jsx(St,{}),r.data&&r.data.length>0&&e.jsxRuntimeExports.jsx(ht,{data:t||[]}),a&&e.jsxRuntimeExports.jsx("span",{className:"font-mono text-sm",children:a})]})]})}function St(){const s=e.useEditorStore(t=>t.pythonStdOut);if(!s)return null;const r=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:r},className:"bg-muted p-2 font-mono text-sm"}),e.jsxRuntimeExports.jsx(e.Separator,{className:"mb-2"})]})}function Ct(){const s=e.useEditorStore(t=>t.isShowingVisual),r=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:()=>r(!s),id:"visualize",className:"data-[state=checked]:bg-foreground/50"})]})}function Nt({options:s,value:r,onValueChange:t}){return e.jsxRuntimeExports.jsx(e.RadioGroup,{value:r,onValueChange:t,className:"flex gap-4",defaultValue:s[0].value,children:s.map(n=>e.jsxRuntimeExports.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsxRuntimeExports.jsx(e.RadioGroupItem,{value:n.value,id:n.value}),e.jsxRuntimeExports.jsx("label",{className:"text-sm",htmlFor:n.value,children:n.label})]},n.value))})}function Z({label:s,options:r,value:t,onValueChange:n,className:o}){return e.jsxRuntimeExports.jsxs(e.Select,{value:t,onValueChange:n,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}),r.map(a=>e.jsxRuntimeExports.jsx(e.SelectItem,{value:a.value,children:a.label},a.value))]})})]})}function Ee({children:s,summary:r,open:t,className:n}){return e.jsxRuntimeExports.jsxs("details",{open:t,className:e.cn("space-y-4 [&_summary>svg]:open:-rotate-180",n),children:[e.jsxRuntimeExports.jsxs("summary",{className:"flex cursor-pointer list-none items-center justify-between gap-4",children:[e.jsxRuntimeExports.jsx(e.Label,{children:r}),e.jsxRuntimeExports.jsx(e.ChevronUp,{className:"h-4 w-4"})]}),e.jsxRuntimeExports.jsx("div",{className:"transition-all ease-in-out",children:s})]})}function wt(){var R,L;const s=e.useEditorStore(b=>b.card.customCardPreferences),{data:r}=Ms(),t=(r==null?void 0:r.plugins)||[],n=e.useEditorStore(b=>b.card),o=e.useEditorStore(b=>b.frame),a=(s==null?void 0:s.visualType)||"single",{setCustomCardPreferences:i}=e.useEditorActions(),{components:c,manifest:l}=e.useCustomVisual((s==null?void 0:s.url)||""),x=(R=l==null?void 0:l.visuals)==null?void 0:R.find(b=>b.name===(s==null?void 0:s.componentName));function d(b,C){if(!s)return;const v={...(s==null?void 0:s.dataInputCardIds)||{},[b]:{cardId:C,hookRef:null}};i({...s,dataInputCardIds:v})}function g(b){var w,v;const C=(w=o==null?void 0:o.cards)==null?void 0:w.filter(D=>{var m;return((m=D==null?void 0:D.customCardPreferences)==null?void 0:m.visualType)!=="multiple"}).map(D=>({value:D.id,label:D.tabTitle||D.title}));return e.jsxRuntimeExports.jsx("div",{className:"space-y-2",children:(v=b==null?void 0:b.dataInputs)==null?void 0:v.map((D,m)=>{var N,E;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:D}),e.jsxRuntimeExports.jsx(Z,{className:"col-span-6 h-8 w-full justify-between",label:"",options:C||[],value:((E=(N=s==null?void 0:s.dataInputCardIds)==null?void 0:N[m])==null?void 0:E.cardId)||"",onValueChange:j=>d(m,j)})]},m+Math.random())})})}function f(b,C,w=[]){var v,D;return s?b==="input"?e.jsxRuntimeExports.jsx(e.Input,{className:`h-8 w-full ${e.removeRing}`,value:((v=s==null?void 0:s.settings)==null?void 0:v[C])||"",onChange:m=>{i({...s,settings:{...s==null?void 0:s.settings,[C]:m.target.value}})}},C):b==="select"?e.jsxRuntimeExports.jsx(Z,{className:"h-8 w-full",label:"",options:w,value:((D=s==null?void 0:s.settings)==null?void 0:D[C])||"",onValueChange:m=>{i({...s,settings:{...s==null?void 0:s.settings,[C]:m}})}}):null:null}function u(b){const C=Object.entries((b==null?void 0:b.settings)||{});return e.jsxRuntimeExports.jsx("div",{className:"space-y-3",children:C.map(([w,v])=>e.jsxRuntimeExports.jsxs("div",{className:"space-y-2",children:[e.jsxRuntimeExports.jsx(e.Label,{children:v.title}),f(v.ui,w,v.options)]},w))})}function p(b){s&&i({...s,visualType:b,componentName:""})}return e.jsxRuntimeExports.jsxs("div",{className:"p-6",children:[e.jsxRuntimeExports.jsx(Ee,{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(Nt,{options:[{value:"single",label:"Single Visual"},{value:"multiple",label:"Multi-Visual"}],value:a,onValueChange:p}),((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===a).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"}),((L=n==null?void 0:n.customCardPreferences)==null?void 0:L.componentName)&&e.jsxRuntimeExports.jsxs(Ee,{summary:"Component Settings",children:[x&&x.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(x)})]}),x&&x.settings&&e.jsxRuntimeExports.jsx("div",{className:"space-y-3",children:e.jsxRuntimeExports.jsx("div",{className:"px-2",children:u(x)})})]})]})}function me(){const[s,r]=S.useState([]);e.useEditorStore(d=>d.card.cfg);const t=e.useEditorStore(d=>d.card.preferences),{setCardCfg:n,setFilterOnClickColumnIndex:o,setCardPreferences:a}=e.useEditorStore(d=>d.actions),i=e.useEditorStore(d=>d.queryResultColumns);e.useEditorStore(d=>{var g;return(g=d.card.preferences)==null?void 0:g.filterOnClickColumnIndex}),S.useEffect(()=>{i&&r(new Array(i.length).fill(!1))},[i]);function c(d,g){var f,u;g?t!=null&&t.onClickFilter&&((f=t==null?void 0:t.onClickFilter)==null?void 0:f.length)>0?a({...t,onClickFilter:[...t.onClickFilter,{columnIndex:d,expression:""}]}):a({...t,onClickFilter:[{columnIndex:d,expression:""}]}):(a({...t,onClickFilter:(u=t==null?void 0:t.onClickFilter)==null?void 0:u.filter(p=>p.columnIndex!==d)}),r(p=>{const R=[...p];return R[d]=!1,R}))}function l(d,g){var u;const f=(u=t==null?void 0:t.onClickFilter)==null?void 0:u.map(p=>p.columnIndex===d?{...p,expression:g.target.value}:p);a({...t,onClickFilter:f})}function x(d){var g,f,u,p;if(s!=null&&s[d]||(f=(g=t==null?void 0:t.onClickFilter)==null?void 0:g.find(R=>R.columnIndex===d))!=null&&f.expression)return e.jsxRuntimeExports.jsx(e.Input,{value:(p=(u=t==null?void 0:t.onClickFilter)==null?void 0:u.find(R=>R.columnIndex===d))==null?void 0:p.expression,onChange:R=>l(d,R),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((d,g)=>{var f,u;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:!!((f=t==null?void 0:t.onClickFilter)!=null&&f.find(p=>p.columnIndex===g)),onCheckedChange:p=>c(g,p)}),e.jsxRuntimeExports.jsx("label",{className:"text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70",children:d}),e.jsxRuntimeExports.jsx("div",{className:"flex items-center gap-2",children:((u=t==null?void 0:t.onClickFilter)==null?void 0:u.find(p=>p.columnIndex===g))&&e.jsxRuntimeExports.jsx(qe,{onClick:()=>{r(p=>{const R=[...p];return R[g]=!p[g],R})},className:"invisible size-3 cursor-pointer text-gray-400 group-hover:visible"})})]}),x(g)]})},d)})]})}function Le(){var i,c,l;const s=e.useEditorStore(x=>x.card.preferences),r=e.useEditorStore(x=>x.card.cfg),{setCardCfg:t,setCardPreferences:n,setChartOrientation:o}=e.useEditorStore(x=>x.actions);(i=r==null?void 0:r.options)!=null&&i.indexAxis;function a(x){o(x)}return e.jsxRuntimeExports.jsxs(e.RadioGroup,{value:((c=s==null?void 0:s.chartOptions)==null?void 0:c.indexAxis)||((l=r==null?void 0:r.options)==null?void 0:l.indexAxis)||"x",onValueChange:a,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 Ke(s,r){var n,o,a;const t=e.getNumberAxis(s,r);return((a=(o=(n=s==null?void 0:s.chartOptions)==null?void 0:n.scales)==null?void 0:o[t])==null?void 0:a.type)||"linear"}function Vs(){var U,_,W,k,F,B;const[s,r]=S.useState(!1),t=e.useEditorStore(A=>{var T;return(T=A.card)==null?void 0:T.preferences}),n=e.useEditorStore(A=>{var T;return(T=A.card)==null?void 0:T.cfg}),o=e.getNumberAxis(t,n),[a,i]=S.useState(Ke(t)),[c,l]=S.useState(((W=(_=(U=t==null?void 0:t.chartOptions)==null?void 0:U.scales)==null?void 0:_[o])==null?void 0:W.min)||""),[x,d]=S.useState(((B=(F=(k=t==null?void 0:t.chartOptions)==null?void 0:k.scales)==null?void 0:F[o])==null?void 0:B.max)||""),[g,f]=S.useState(c||x?"custom":"auto"),[u,p]=S.useState(""),[R,L]=S.useState(0),[b,C]=S.useState(""),[w,v]=S.useState(""),[D,m]=S.useState(""),N=e.useEditorStore(A=>A.actions.setCardPreferences),{updateCardInFrame:E}=e.useEditorActions(),j=e.useEditorStore(A=>A.card),I=e.useEditorStore(A=>{var T;return(T=A.card)==null?void 0:T.type}),O=["pie","doughnut","polarArea"].includes(I);S.useEffect(()=>{var A,T,G,V,P,Q,se,Y,ne,re,oe,te,$,X;i(Ke(t)),l(((G=(T=(A=t==null?void 0:t.chartOptions)==null?void 0:A.scales)==null?void 0:T[o])==null?void 0:G.min)===0?0:""),d(((Q=(P=(V=t==null?void 0:t.chartOptions)==null?void 0:V.scales)==null?void 0:P[o])==null?void 0:Q.max)||""),p(((re=(ne=(Y=(se=t==null?void 0:t.chartOptions)==null?void 0:se.scales)==null?void 0:Y[o])==null?void 0:ne.ticks)==null?void 0:re.stepSize)||""),L(((oe=t==null?void 0:t.numberAxisFormat)==null?void 0:oe.decimalPlaces)||0),C(((te=t==null?void 0:t.numberAxisFormat)==null?void 0:te.suffix)||""),v((($=t==null?void 0:t.numberAxisFormat)==null?void 0:$.currency)||""),m(((X=t==null?void 0:t.numberAxisFormat)==null?void 0:X.locale)||"")},[s,t,o]);function z(A,T){return T===""||/^[0-9\b]+$/.test(T)?Number(T):Number(A)}function M(){const A=[...new Set(e.LOCALE_CURRENCY_PAIRS.map(T=>T.currency))];return e.jsxRuntimeExports.jsxs(e.jsxRuntimeExports.Fragment,{children:[e.jsxRuntimeExports.jsxs("div",{className:"grid grid-cols-6 items-center gap-2",children:[e.jsxRuntimeExports.jsx(e.Label,{className:"col-span-2 hover:cursor-pointer hover:underline",htmlFor:"currency",children:e.jsxRuntimeExports.jsx("a",{target:"_blank",href:"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat",children:"Currency"})}),e.jsxRuntimeExports.jsxs(e.Select,{value:w||"none",onValueChange:T=>v(T==="none"?"":T),children:[e.jsxRuntimeExports.jsx(e.SelectTrigger,{className:"col-span-2 h-8 w-full focus:ring-1 focus:ring-offset-0",children:e.jsxRuntimeExports.jsx(e.SelectValue,{})}),e.jsxRuntimeExports.jsx(e.SelectContent,{children:e.jsxRuntimeExports.jsxs(e.SelectGroup,{children:[e.jsxRuntimeExports.jsx(e.SelectLabel,{children:"Currency"}),e.jsxRuntimeExports.jsx(e.SelectItem,{value:"none",children:"None"}),A.map(T=>e.jsxRuntimeExports.jsx(e.SelectItem,{value:T,children:T},T))]})})]}),e.jsxRuntimeExports.jsxs(e.Select,{value:D,onValueChange:T=>m(T),children:[e.jsxRuntimeExports.jsx(e.SelectTrigger,{className:"col-span-2 h-8 w-full focus:ring-1 focus:ring-offset-0",children:e.jsxRuntimeExports.jsx(e.SelectValue,{})}),e.jsxRuntimeExports.jsx(e.SelectContent,{children:e.jsxRuntimeExports.jsxs(e.SelectGroup,{children:[e.jsxRuntimeExports.jsx(e.SelectLabel,{children:"Locale"}),e.LOCALE_CURRENCY_PAIRS.map(T=>e.jsxRuntimeExports.jsx(e.SelectItem,{value:T.locale,children:T.locale},T.locale))]})})]})]}),e.jsxRuntimeExports.jsxs("div",{className:"grid grid-cols-9 items-center gap-2",children:[e.jsxRuntimeExports.jsx(e.Label,{className:"col-span-3",htmlFor:"format",children:"Decimals"}),e.jsxRuntimeExports.jsx(e.Input,{value:R,onChange:T=>L(Number(T.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:A=>l(T=>z(T,A.target.value)),className:`col-span-1 h-8 w-full ${ve}`}),e.jsxRuntimeExports.jsx(e.Input,{value:x,onChange:A=>d(T=>z(T,A.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:u,onChange:A=>p(T=>z(T,A.target.value)),id:"step-size",className:`col-span-1 h-8 w-full ${ve}`})]})]})}function H(){var V;let A={};g==="custom"&&(A={min:c,max:x,ticks:{stepSize:u}});const T={...t||{},chartOptions:{...t==null?void 0:t.chartOptions,scales:{...(V=t==null?void 0:t.chartOptions)==null?void 0:V.scales,[o]:{type:a,...a==="linear"?A:{}}}},numberAxisFormat:{decimalPlaces:R,suffix:b,currency:w,locale:D}};console.log(T),N(T);const G={...j,preferences:T};E(G)}return e.jsxRuntimeExports.jsxs(e.Popover,{onOpenChange:A=>r(A),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:O,value:a,onValueChange:A=>i(A),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"})]})})]})]}),a=="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:O,id:"scale-option",value:g,onValueChange:A=>f(A),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"&&a=="linear"&&q(),M(),e.jsxRuntimeExports.jsx(e.SelectSeparator,{}),e.jsxRuntimeExports.jsx("div",{className:"grid grid-cols-3",children:e.jsxRuntimeExports.jsx(e.Button,{onClick:H,variant:"secondary",className:"col-span-1 col-start-3 h-8 w-full",children:"Apply"})})]})]})})]})}function kt({idx:s}){var c;const r=e.useEditorStore(l=>{var x;return(x=l.card)==null?void 0:x.preferences}),t=e.useEditorStore(l=>{var x;return(x=l.card.preferences)==null?void 0:x.datasetOptions}),n=e.useEditorStore(l=>l.actions.setCardPreferences),o=(c=r==null?void 0:r.chartOptions)==null?void 0:c.indexAxis,a=t==null?void 0:t.find(l=>l.idx===s);function i(l,x){(l==="end"||l==="start")&&e.getContrastColor(e.getCanvasBackgroundColor());const d={display:l!=="none",align:l,anchor:l,clamp:!0};if(!a)n({...r,datasetOptions:[...t||[],{idx:x,datalabels:d}]});else{const g={...a};g.datalabels=d;const f=t==null?void 0:t.map(u=>u.idx===x?g:u);n({...r,datasetOptions:f})}}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(l=>l.card),r=e.useEditorStore(l=>{var x,d,g;return(g=(d=(x=l==null?void 0:l.card)==null?void 0:x.preferences)==null?void 0:d.chartOptions)==null?void 0:g.indexAxis}),t=r==="y"?"Y axis":"X axis",n=r==="y"?"X axis":"Y axis",{keys:o,metricKeys:a,dimensionKeys:i}=e.getKeys(s.data||[]);let c=a;if(["stackedBar","stackedLine"].includes(s.type)){const l=e.pivotData({dataArray:s.data||[],groupKey:i[0],pivotKey:i[1],valueKey:c[0]}),{metricKeys:x}=e.getKeys(l);c=x}return o.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:t}),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:i[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:n}),e.jsxRuntimeExports.jsx(Vs,{})]}),e.jsxRuntimeExports.jsx("div",{className:"my-1 space-y-1",children:c.map((l,x)=>e.jsxRuntimeExports.jsx(It,{col:l,idx:x},l))})]})]})}function It({col:s,idx:r}){const t=e.useEditorStore(c=>{var l;return(l=c.card)==null?void 0:l.preferences}),n=e.useEditorStore(c=>{var l;return(l=c.card.preferences)==null?void 0:l.datasetOptions}),o=n==null?void 0:n.find(c=>c.idx===r),{setCardPreferences:a}=e.useEditorStore(c=>c.actions);function i(c){if(!o)a({...t,datasetOptions:[...n||[],{idx:r,type:c==="area"?"line":c,fill:c==="area"?"origin":""}]});else{const l={...o};l.type=c==="area"?"line":c,l.fill=c==="area"?"origin":"";const x=n==null?void 0:n.map(d=>d.idx===r?l:d);a({...t,datasetOptions:x})}}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(kt,{idx:r})]})]})}function _s(){const s=e.useEditorStore(f=>f.selectedConnectionId),r=e.useEditorStore(f=>f.selectedDatamodelId),t=e.useEditorStore(f=>f.selectedDatabaseName),n=e.useEditorStore(f=>f.selectedSchemaName),o=e.useEditorStore(f=>f.selectedTableName),a=e.useDashboardStore(f=>f.dashboard.filters)||[],i=e.useDashboardStore(f=>f.actions.addFilter),c=e.useDashboardStore(f=>f.actions.removeFilter),l=e.useDashboardStore(f=>f.actions.removeFilterValue),{modelItems:x,tableName:d}=ae();function g(f,u="dashboard"){var m;const p=e.fmt(f.column_name),R=e.fmt(t||""),L=e.fmt(n||""),b=e.fmt(d);let C=e.getQualifiedTableName(L,b),w=`${C}.${p}`;const v=(m=x==null?void 0:x.find(N=>N.id===r))==null?void 0:m.name;r&&r!=="none"&&(w=`${e.DATAMODEL_NAMESPCACE}.${v}.${p}`,C=`${e.DATAMODEL_NAMESPCACE}.${v}`);const D=a==null?void 0:a.find(N=>N.column===w&&N.table===b&&(N.database===R||N.database===t));if(D)l(D.id),c(D.id);else{const N=e.v4();return d==="api"&&s?(i({location:u,id:N,column:w,title:f.column_name,dataType:f.data_type,table:"api",database:"",connectionId:s,operation:"in",sql:e.getDefaultFilterSql(f.data_type,C,p)}),N):(i({id:N,location:u,column:w,title:f.column_name,dataType:f.data_type,table:o||"",database:t||"",connectionId:s||"",operation:"in",sql:e.getDefaultFilterSql(f.data_type,C,p)}),N)}}return{assignFilter:g}}function pe(){const s=e.useDashboardStore(c=>c.dashboard.filters),r=e.useEditorStore(c=>c.frame),{setFrame:t}=e.useEditorActions(),{columns:n}=ae(),{assignFilter:o}=_s();function a(c){const l=o(c,"frame");t({...r,filterId:l})}const i=s==null?void 0:s.find(c=>c.id===r.filterId);return e.jsxRuntimeExports.jsxs("div",{className:"space-y-3",children:[e.jsxRuntimeExports.jsx(e.Label,{children:"Card Filter"}),e.jsxRuntimeExports.jsx(Lt,{onSelect:a,columns:n}),i&&e.jsxRuntimeExports.jsx(e.FilterHeader,{filter:i})]})}function Lt({columns:s,onSelect:r}){var i;const[t,n]=Ge.useState(!1),[o,a]=Ge.useState("");return e.jsxRuntimeExports.jsxs(e.Popover,{open:t,onOpenChange:n,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:l=>{const x=l===o?"":l;a(x),n(!1),x&&r(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:r=>r.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(Le,{}),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(me,{}),e.jsxRuntimeExports.jsx(pe,{})]})]})]})})}function He(){var o,a,i;const s=e.useEditorStore(c=>c.card.cfg),r=e.useEditorStore(c=>c.actions.setCardCfg),t=e.useEditorStore(c=>c.card.type);function n(c){var d;const l={datalabels:{display:c!=="none",align:c,anchor:c,clamp:!0}},x={...s,options:{...s==null?void 0:s.options,plugins:{...(d=s==null?void 0:s.options)==null?void 0:d.plugins,...l}}};r(x),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=(a=(o=s==null?void 0:s.options)==null?void 0:o.plugins)==null?void 0:a.datalabels)==null?void 0:i.anchor,onValueChange:n,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 Tt({cardType:s}){function r(t){const n="SELECT label, [group], x-axis, y-axis, radius FROM table",o="SELECT label, [group], x-axis, y-axis FROM table";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"?n:o}),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:a=>a.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:r(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(He,{})})]}),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(me,{}),e.jsxRuntimeExports.jsx(pe,{})]})]})]})})}const At={datasets:[{type:"line",label:"Sum_sales",data:[]},{type:"bar",label:"Sum_profit",data:[]}]},Ot={datasets:[{fill:"origin",type:"line",label:"Sum_sales",data:[]}]};function zt(){const s=e.useEditorStore(r=>r.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:Ft(s)}),e.jsxRuntimeExports.jsx("section",{className:"",children:["line","bar"].includes(s)&&e.jsxRuntimeExports.jsx(Le,{})}),!["kpi"].includes(s)&&e.jsxRuntimeExports.jsxs("div",{className:"space-y-4",children:[e.jsxRuntimeExports.jsx(He,{}),e.jsxRuntimeExports.jsx(me,{}),e.jsxRuntimeExports.jsx(pe,{})]})]})}function Ft(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(At,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(Ot,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 Mt(){var l,x,d,g,f;const s=e.useEditorStore(u=>u.card.preferences),r=e.useEditorStore(u=>u.actions.setCardPreferences),t=e.useEditorStore(u=>u.actions.setNumberFormat);e.useEditorStore(u=>{var p,R;return(R=(p=u.card.preferences)==null?void 0:p.formatNumber)==null?void 0:R.decimalPlaces});const n=e.useEditorStore(u=>{var p,R;return(R=(p=u.card.preferences)==null?void 0:p.formatNumber)==null?void 0:R.locale}),o=e.useEditorStore(u=>{var p,R;return(R=(p=u.card.preferences)==null?void 0:p.formatNumber)==null?void 0:R.currency});e.useEditorStore(u=>u.actions.setFilterOnClickField);const a=e.useEditorStore(u=>{var p,R;return(R=(p=u.card.preferences)==null?void 0:p.formatNumber)==null?void 0:R.colorRanges})||[],i=e.useEditorStore(u=>u.actions.setColorRanges),c=[...new Set(e.LOCALE_CURRENCY_PAIRS.map(u=>u.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:!!((l=s==null?void 0:s.formatNumber)!=null&&l.enabled),onCheckedChange:u=>{r({...s,formatNumber:{...s==null?void 0:s.formatNumber,enabled:u}})}}),e.jsxRuntimeExports.jsx(e.Label,{children:"Format Number"})]}),((x=s==null?void 0:s.formatNumber)==null?void 0:x.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:n||"en-US",onValueChange:u=>{var p,R,L;return t(((p=s==null?void 0:s.formatNumber)==null?void 0:p.decimalPlaces)||0,((R=s==null?void 0:s.formatNumber)==null?void 0:R.currency)||"",u||"en-US",((L=s==null?void 0:s.formatNumber)==null?void 0:L.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.LOCALE_CURRENCY_PAIRS.map(u=>e.jsxRuntimeExports.jsx(e.SelectItem,{value:u.locale,children:u.locale},u.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:u=>{var p,R,L;return t(((p=s==null?void 0:s.formatNumber)==null?void 0:p.decimalPlaces)||0,u==="none"?"":u,((R=s==null?void 0:s.formatNumber)==null?void 0:R.locale)||"",((L=s==null?void 0:s.formatNumber)==null?void 0:L.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(u=>e.jsxRuntimeExports.jsx(e.SelectItem,{value:u,children:u},u))]})})]})]})]}),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=(d=s==null?void 0:s.formatNumber)==null?void 0:d.decimalPlaces)==null?void 0:g.toString())||"0",onValueChange:u=>{var p,R,L;return t(Number(u),((p=s==null?void 0:s.formatNumber)==null?void 0:p.currency)||"",((R=s==null?void 0:s.formatNumber)==null?void 0:R.locale)||"",((L=s==null?void 0:s.formatNumber)==null?void 0:L.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(u=>e.jsxRuntimeExports.jsx(e.SelectItem,{value:u,children:u},u))})]})]}),e.jsxRuntimeExports.jsxs("div",{className:"w-full space-y-1",children:[e.jsxRuntimeExports.jsx(e.Label,{children:"Suffix"}),e.jsxRuntimeExports.jsx(e.Input,{value:((f=s==null?void 0:s.formatNumber)==null?void 0:f.suffix)||"",className:"h-8 font-mono text-xs focus-visible:ring-0 focus-visible:ring-ring focus-visible:ring-offset-0",placeholder:"K, M, B, %",onChange:u=>{var p,R,L;return t(((p=s==null?void 0:s.formatNumber)==null?void 0:p.decimalPlaces)||0,((R=s==null?void 0:s.formatNumber)==null?void 0:R.currency)||"",((L=s==null?void 0:s.formatNumber)==null?void 0:L.locale)||"",u.target.value)}})]})]})]})}),e.jsxRuntimeExports.jsx(e.Separator,{className:"my-3"}),e.jsxRuntimeExports.jsx(e.ColorFormat,{colorRanges:a,setColorRanges:i})]})]})}function Vt(){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(Mt,{})}),e.jsxRuntimeExports.jsx("div",{}),e.jsxRuntimeExports.jsx("div",{})]})}const qt=[{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"}],_t=["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"],Bt=_t.map(s=>({label:s,value:s}));function Ht(){var l,x,d,g,f,u,p,R,L,b,C,w,v,D,m,N,E,j;const s=e.useEditorStore(I=>I.card),r=(x=(l=s==null?void 0:s.preferences)==null?void 0:l.mapVisualOptions)==null?void 0:x.topoJsonUrl,[t,n]=S.useState(((g=(d=s==null?void 0:s.preferences)==null?void 0:d.mapVisualOptions)==null?void 0:g.customTopoJsonUrl)||""),{setCardPreferences:o}=e.useEditorActions(),{data:a}=e.useTopoJson(s),i=Object.keys((a==null?void 0:a.objects)||{}).map(I=>({label:I,value:I}))||[],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(Ee,{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(Ee,{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:I=>{console.log("value",I),o({...s.preferences,mapVisualOptions:{topoJsonUrl:I}})},value:r||"",label:"Select Map"}),r==="custom"&&e.jsxRuntimeExports.jsx(e.Input,{onChange:I=>{n(I.target.value)},onBlur:()=>{var I;console.log("onBlur",t),o({...s.preferences,mapVisualOptions:{...(I=s.preferences)==null?void 0:I.mapVisualOptions,customTopoJsonUrl:t}})},value:t,className:`h-9 w-full ${e.removeRing}`,placeholder:"Custom URL"}),a&&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:((u=(f=s.preferences)==null?void 0:f.mapVisualOptions)==null?void 0:u.objectKey)||"",label:"Map Object",onValueChange:I=>{var O;o({...s.preferences,mapVisualOptions:{...(O=s.preferences)==null?void 0:O.mapVisualOptions,objectKey:I}})}})]}),e.jsxRuntimeExports.jsxs("div",{className:"space-y-1",children:[e.jsxRuntimeExports.jsx(e.Label,{children:"Projection"}),e.jsxRuntimeExports.jsx(Z,{className:"h-9",options:qt,value:((R=(p=s.preferences)==null?void 0:p.mapVisualOptions)==null?void 0:R.projection)||"",label:"Projection",onValueChange:I=>{var O;o({...s.preferences,mapVisualOptions:{...(O=s.preferences)==null?void 0:O.mapVisualOptions,projection:I}})}})]}),e.jsxRuntimeExports.jsxs("div",{className:"space-y-1",children:[e.jsxRuntimeExports.jsx(e.Label,{children:"Colors"}),e.jsxRuntimeExports.jsx(Z,{className:"h-9",options:Bt,value:((b=(L=s.preferences)==null?void 0:L.mapVisualOptions)==null?void 0:b.colorScale)||"",label:"Select Color Scale",onValueChange:I=>{var O;o({...s.preferences,mapVisualOptions:{...(O=s.preferences)==null?void 0:O.mapVisualOptions,colorScale:I}})}})]})]})]})}),e.jsxRuntimeExports.jsx(e.Separator,{className:"my-4"}),e.jsxRuntimeExports.jsx(Ee,{className:"px-2",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:((w=(C=s.preferences)==null?void 0:C.mapVisualOptions)==null?void 0:w.projectionScale)||1,onChange:I=>{var O;o({...s.preferences,mapVisualOptions:{...(O=s.preferences)==null?void 0:O.mapVisualOptions,projectionScale:Number(I.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:((m=(D=(v=s.preferences)==null?void 0:v.mapVisualOptions)==null?void 0:D.projectionOffset)==null?void 0:m[0])||0,onChange:I=>{var O,z,M,q;o({...s.preferences,mapVisualOptions:{...(O=s.preferences)==null?void 0:O.mapVisualOptions,projectionOffset:[Number(I.target.value),((q=(M=(z=s.preferences)==null?void 0:z.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:((j=(E=(N=s.preferences)==null?void 0:N.mapVisualOptions)==null?void 0:E.projectionOffset)==null?void 0:j[1])||0,onChange:I=>{var O,z,M,q;o({...s.preferences,mapVisualOptions:{...(O=s.preferences)==null?void 0:O.mapVisualOptions,projectionOffset:[((q=(M=(z=s.preferences)==null?void 0:z.mapVisualOptions)==null?void 0:M.projectionOffset)==null?void 0:q[0])||0,Number(I.target.value)]}})}})]})})]})}function Pt(){var n;const s=e.useEditorStore(o=>o.card.preferences),{setCardPreferences:r}=e.useEditorStore(o=>o.actions);function t(o){r({...s,textVisualOptions:{...s==null?void 0:s.textVisualOptions,isDynamicText:o==="dynamic"}})}return e.jsxRuntimeExports.jsxs(e.RadioGroup,{value:(n=s==null?void 0:s.textVisualOptions)!=null&&n.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:r,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:r||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:n=>n.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(Le,{}),s!=="text"&&e.jsxRuntimeExports.jsx(He,{}),s==="text"&&e.jsxRuntimeExports.jsx(Pt,{})]})]}),!["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(me,{}),e.jsxRuntimeExports.jsx(pe,{})]})]})]})})}function $t(){const s=e.useEditorStore(n=>{var o,a;return(a=(o=n==null?void 0:n.card)==null?void 0:o.preferences)==null?void 0:a.sortChart}),{setSortChart:r}=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:n=>{r(n)}})]})}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:n=>n.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(Le,{}),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(me,{}),e.jsxRuntimeExports.jsx(pe,{})]})]})]})})}function Gt({}){const s=e.useEditorStore(n=>{var o;return(o=n.card)==null?void 0:o.preferences}),r=e.useEditorStore(n=>n.actions.setCardPreferences),t=n=>{r({...s,allowDownload:n})};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(me,{}),e.jsxRuntimeExports.jsx(pe,{})]})]})}),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 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 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."]})]}),Jt=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 r(t){switch(t){case"stackedBar":case"stackedLine":return e.jsxRuntimeExports.jsx($t,{});case"pyramid":return e.jsxRuntimeExports.jsx(Se,{docContent:Ut,cardType:t});case"kpi":return e.jsxRuntimeExports.jsx(Vt,{});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(Tt,{cardType:t});case"table":return e.jsxRuntimeExports.jsx(Gt,{cardType:t});case"text":return e.jsxRuntimeExports.jsx(Se,{docContent:Jt,cardType:t,suffix:"Visual"});case"map":return e.jsxRuntimeExports.jsx(Ht,{});case"custom":return e.jsxRuntimeExports.jsx(wt,{});default:return e.jsxRuntimeExports.jsx(zt,{})}}return e.jsxRuntimeExports.jsx(e.ScrollArea,{className:"h-full w-full text-sm",children:r(s)})}function Wt(){const s=e.useEditorStore(r=>r.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(jt,{})}),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(Je,{})})]}):e.jsxRuntimeExports.jsx(Je,{})})]})}function Yt({authToken:s,onSave:r,onClose:t}){e.useDashboardStore(i=>i.themeStyle);const n=e.useEditorStore(i=>i.actions.setOnSave),o=e.useEditorStore(i=>i.actions.setOnClose),a=e.useDashboardStore(i=>i.actions.setAuthToken);return S.useEffect(()=>{r&&n(r),t&&o(t)},[r,n,t,o]),S.useEffect(()=>{s&&s.accessToken&&a(s)},[s,a]),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(Wt,{})})]})})}function Xt(){e.useDashboardStore(i=>i.selectedCardId);const s=e.useDashboardStore(i=>i.selectedSheetId),{setIsVisualEditing:r}=e.useDashboardStore(i=>i.actions),t=e.useDashboardStore(i=>i.isVisualEditing),n=e.useDashboardStore(i=>i.actions.updateFrame);function o(i){s&&(n(s,i),r(!1))}function a(){r(!1)}return e.jsxRuntimeExports.jsx("div",{role:"editor-container",className:e.cn("flex grow",{block:t,hidden:!t}),children:e.jsxRuntimeExports.jsx(Yt,{onSave:o,onClose:a})})}function Zt(){e.useEditorStore(i=>i.selectedConnectionId),e.useEditorStore(i=>i.selectedDatamodelId);const s=e.useEditorStore(i=>i.selectedDatabaseName);e.useEditorStore(i=>i.selectedSchemaName);const r=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:n,columns:o}=ae(),{assignFilter:a}=_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(l=>l.column===e.fmt(i.column_name)&&l.table===r&&l.database===s);return e.jsxRuntimeExports.jsx("div",{onClick:()=>a(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 en(){e.useDashboardStore(r=>r.showFilters);const s=e.useDashboardStore(r=>r.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(Zt,{})})})]})}function sn(){const s=e.useDashboardStore(t=>t.showFilters),r=e.useDashboardStore(t=>t.isVisualEditing);return e.jsxRuntimeExports.jsxs("div",{role:"dashboard-plus-main",className:e.cn("grow",{hidden:r,flex:!r}),children:[e.jsxRuntimeExports.jsx(e.DashboardTabs,{}),s&&e.jsxRuntimeExports.jsx("div",{role:"filter-aside-container",className:"flex",children:e.jsxRuntimeExports.jsx(en,{})})]})}function tn(){const s=e.useDashboardStore(n=>n.dashboard),r=e.useDashboardStore(n=>n.actions.setDashboard),t=e.useDashboardStore(n=>n.showDashboardJSON);return e.useDashboardStore(n=>n.actions.setShowDashboardJSON),e.jsxRuntimeExports.jsx("div",{className:e.cn(" p-2",{hidden:!t}),children:e.jsxRuntimeExports.jsx(e.de,{onChange:n=>{if(n)try{JSON.parse(n),r(JSON.parse(n))}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 nn({showControls:s=!1,showFooter:r=!0,...t}){return e.jsxRuntimeExports.jsx(e.ErrorBoundary,{FallbackComponent:e.Fallback,children:e.jsxRuntimeExports.jsxs(e.SemaphorContextProvider,{dashboardProps:t,children:[e.jsxRuntimeExports.jsx(e.Te,{}),e.jsxRuntimeExports.jsxs(e.UXProvider,{children:[e.jsxRuntimeExports.jsx(tn,{}),e.jsxRuntimeExports.jsxs(e.DashboardPanel,{...t,children:[s&&e.jsxRuntimeExports.jsx(Ys,{}),e.jsxRuntimeExports.jsx(Xt,{}),e.jsxRuntimeExports.jsx(sn,{})]})]})]})})}exports.Box=We;exports.ChartArea=Ye;exports.ChartColumnIncreasing=we;exports.ChartLine=ke;exports.ChartNoAxesGantt=Ae;exports.ChartPie=Oe;exports.ChartScatter=ze;exports.CircleX=Xe;exports.CopyPlus=Ze;exports.DashboardPlus=nn;exports.Database=es;exports.EllipsisVertical=Fe;exports.Eraser=ss;exports.Eye=ns;exports.EyeClosed=ts;exports.Glasses=rs;exports.Hammer=os;exports.Hash=is;exports.House=as;exports.Key=Me;exports.ListEnd=ls;exports.ListStart=cs;exports.ListX=xs;exports.LoaderCircle=de;exports.Map=Ve;exports.MessageSquareMore=us;exports.Network=ds;exports.Pencil=qe;exports.Play=ms;exports.Plug2=ps;exports.Save=js;exports.SelectComponent=ue;exports.Shapes=_e;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=Be;exports.useEditorAside=ae;
@@ -8675,7 +8675,7 @@ const Ee = bM()(
8675
8675
  n.isSessionExpired = !1, n.currentBreakpoint = "lg", n.dashboard = {
8676
8676
  id: "",
8677
8677
  style: v0
8678
- }, n.showContext = !1, n.selectedSheetId = null, n.selectedCardId = null, n.selectedFrameId = null, n.selectedCard = null, n.showFilters = !1, n.isDashboardEditing = !0, n.isVisualEditing = !1, n.showDashboardJSON = !1, n.filteringCards = [], n.selectedLensId = void 0, n.filterValues = void 0;
8678
+ }, n.showContext = !1, n.selectedSheetId = null, n.selectedCardId = null, n.selectedFrameId = null, n.selectedCard = null, n.showFilters = !1, n.isDashboardEditing = !1, n.isVisualEditing = !1, n.showDashboardJSON = !1, n.filteringCards = [], n.selectedLensId = void 0, n.filterValues = void 0;
8679
8679
  });
8680
8680
  },
8681
8681
  setGlobalCacheConfig: (n) => {