react-semaphor 0.0.308 → 0.0.309

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 s=require("./index-Jo1TFjn8.js"),e=require("react/jsx-runtime"),w=require("react");require("react-dom");function $s(t){const n=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(t){for(const a in t)if(a!=="default"){const r=Object.getOwnPropertyDescriptor(t,a);Object.defineProperty(n,a,r.get?r:{enumerable:!0,get:()=>t[a]})}}return n.default=t,Object.freeze(n)}const Qe=$s(w);/**
1
+ "use strict";const s=require("./index-UYL_Ugbq.js"),e=require("react/jsx-runtime"),w=require("react");require("react-dom");function $s(t){const n=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(t){for(const a in t)if(a!=="default"){const r=Object.getOwnPropertyDescriptor(t,a);Object.defineProperty(n,a,r.get?r:{enumerable:!0,get:()=>t[a]})}}return n.default=t,Object.freeze(n)}const Qe=$s(w);/**
2
2
  * @license lucide-react v0.453.0 - ISC
3
3
  *
4
4
  * This source code is licensed under the ISC license.
@@ -188,7 +188,7 @@
188
188
  *
189
189
  * This source code is licensed under the ISC license.
190
190
  * See the LICENSE file in the root directory of this source tree.
191
- */const Ss=s.createLucideIcon("User",[["path",{d:"M19 21v-2a4 4 0 0 0-4-4H9a4 4 0 0 0-4 4v2",key:"975kel"}],["circle",{cx:"12",cy:"7",r:"4",key:"17ys0d"}]]);function Pe(t){var n;return{...t,sheets:(n=t==null?void 0:t.sheets)==null?void 0:n.map(a=>{var r;return{...a,frames:(r=a.frames)==null?void 0:r.map(o=>{var l;return{...o,cards:(l=o.cards)==null?void 0:l.map(i=>Cs(i))}})}})}}function Cs(t){var n,a,r,o;return{...t,cfg:{...t.cfg,data:{...(n=t.cfg)==null?void 0:n.data,labels:[],datasets:(o=(r=(a=t.cfg)==null?void 0:a.data)==null?void 0:r.datasets)==null?void 0:o.map(l=>({...l,data:[]}))}},customCfg:Qs(t.customCfg),data:[]}}function Qs(t){var n,a;return t?{...t,data:{...t==null?void 0:t.data,labels:[],datasets:(a=(n=t==null?void 0:t.data)==null?void 0:n.datasets)==null?void 0:a.map(r=>({...r,data:[]}))}}:null}async function Us(t,n,a,r){if(!r)return null;const o=JSON.stringify(n),l="https://semaphor.cloud/api/v1/lens";return await s.postRequest(l,r,{name:t,template:o,filterValues:a,operation:"create"})}async function ze(t,n){if(!n)return null;const{id:a,template:r,filterValues:o,isDefault:l,shared:i}=t,d="https://semaphor.cloud/api/v1/lens";return await s.postRequest(d,n,{lensId:a,template:r,filterValues:o,isDefault:l,shared:i,operation:"update"})}async function Js(t,n){if(!n)return null;const a="https://semaphor.cloud/api/v1/lens";return await s.postRequest(a,n,{operation:"delete",lensId:t})}function Ks(){const[t,n]=w.useState(""),[a,r]=w.useState(!1),o=s.useDashboardStore(j=>j.lenses),{setLenses:l,setSelectedLensId:i}=s.useDashboardActions(),[d,c]=w.useState(!1),[x,u]=w.useState(!1),y=s.useDashboardStore(j=>j.dashboard),f=s.useDashboardStore(j=>j.filterValues),{authToken:m}=s.useSemaphorContext();async function g(){c(!0);const j=Pe(y),L=await Us(t,j,f,m==null?void 0:m.accessToken);L&&(l([...o||[],L]),i(L.id),u(!1)),c(!1)}return e.jsxs(s.Dialog,{open:x,onOpenChange:u,children:[e.jsx(s.DialogTrigger,{asChild:!0,children:e.jsxs(s.Button,{variant:"secondary",className:"h-7 p-2",size:"sm",children:[e.jsx(s.Plus,{className:"mr-2 h-4 w-4",strokeWidth:1.5}),"Lens"]})}),e.jsxs(s.DialogContent,{className:"sm:max-w-[425px]",children:[e.jsxs(s.DialogHeader,{children:[e.jsx(s.DialogTitle,{children:"Create Lens"}),e.jsx(s.DialogDescription,{children:"Lenses are private by default and are only visible to you."})]}),e.jsx("div",{className:"grid gap-4 py-4",children:e.jsxs("div",{className:"grid grid-cols-8 items-center gap-4",children:[e.jsx(s.Label,{className:"text-right",children:"Name"}),e.jsx(s.Input,{value:t,onChange:j=>{n(j.target.value)},id:"name",className:"col-span-7 focus-visible:ring-0 focus-visible:ring-ring focus-visible:ring-offset-0"})]})}),a&&e.jsx("p",{className:"text-sm",children:"The lens name already exists. Use a differnet name."}),e.jsx(s.DialogFooter,{children:e.jsx(s.Button,{size:"sm",variant:"outline",type:"submit",onClick:g,disabled:d,children:d?"Creating...":"Add"})})]})]})}function Ws(){const[t,n]=w.useState(!1),a=s.useDashboardStore(u=>u.lenses),r=s.useDashboardStore(u=>u.selectedLensId),{setLenses:o,setSelectedLensId:l}=s.useDashboardActions(),{authToken:i}=s.useSemaphorContext();async function d(u){l(u)}async function c(u){if(await Js(u,i==null?void 0:i.accessToken)){const f=a==null?void 0:a.filter(m=>m.id!==u);o(f||[]),l("original")}}async function x(u){const y=a==null?void 0:a.map(g=>g.id===u.id?{...g,isDefault:!u.isDefault}:{...g,isDefault:!1});o(y||[]);const f={...u,isDefault:!u.isDefault};await ze(f,i==null?void 0:i.accessToken);const m=a==null?void 0:a.find(g=>g.isDefault);if(m&&m.id!==u.id){const g={...m,isDefault:!1};await ze(g,i==null?void 0:i.accessToken)}}return e.jsxs(s.DropdownMenu,{open:t,onOpenChange:n,children:[e.jsx(s.DropdownMenuTrigger,{asChild:!0,children:e.jsx(s.Button,{variant:"ghost",className:"h-7 p-2",children:e.jsx(rs,{className:"h-4 w-4",strokeWidth:1.5})})}),e.jsxs(s.DropdownMenuContent,{align:"end",className:"w-60",children:[e.jsx(s.DropdownMenuLabel,{className:"px-3",children:"Lenses"}),e.jsx(s.DropdownMenuSeparator,{}),e.jsxs(s.DropdownMenuRadioGroup,{value:r,onValueChange:d,children:[e.jsx(s.DropdownMenuRadioItem,{value:"original",children:"Original"}),a==null?void 0:a.map(u=>e.jsxs(s.DropdownMenuRadioItem,{className:"group flex justify-between gap-2",value:u.id,children:[e.jsx("p",{children:u.name}),e.jsxs("span",{className:"flex items-center gap-3",children:[e.jsx(ls,{onClick:y=>{y.preventDefault(),x(u)},className:s.cn("size-3.5 text-muted-foreground hover:cursor-pointer hover:text-foreground group-hover:visible",{invisible:!u.isDefault,"text-green-500":u.isDefault}),strokeWidth:1.5}),e.jsx(s.Cross2Icon,{onClick:y=>{y.preventDefault(),c(u.id)},className:"invisible size-3.5 text-muted-foreground hover:cursor-pointer hover:text-foreground group-hover:visible",strokeWidth:1.5})]})]},u.id))]})]})]})}function Ys(){const{authToken:t}=s.useSemaphorContext(),n=s.useDashboardStore(p=>p.lenses),a=s.useDashboardStore(p=>p.selectedLensId),r=n==null?void 0:n.find(p=>p.id===a),o=s.useDashboardStore(p=>p.dashboard);s.useDashboardStore(p=>p.selectedSheetId);const l=s.useDashboardStore(p=>p.isDashboardEditing),i=s.useEditorStore(p=>p.selectedConnectionId),[d,c]=w.useState(!1),x=s.useDashboardStore(p=>p.filterValues),u=s.useDashboardStore(p=>p.isVisualEditing),y=s.useDashboardStore(p=>p.showFilters);s.useDashboardStore(p=>p.showDashboardJSON);const f=s.useDashboardStore(p=>p.onSaveFunction),m=s.useDashboardStore(p=>p.actions.setShowFilters),{addFrame:g,setSelectedFrameId:j}=s.useDashboardStore(p=>p.actions),{getSelectedSheet:L,setIsDashboardEditing:S,setShowDashboardJSON:A}=s.useDashboardStore(p=>p.actions),D=L(),{tenantId:M,endUserId:C}=w.useMemo(()=>s.getTenantAndEndUserId(t==null?void 0:t.accessToken),[t==null?void 0:t.accessToken]),E=w.useMemo(()=>M||C,[M,C]),O=()=>{if(!l||!D)return;const p={connectionId:i,id:s.v4(),title:"Title",description:"Description",preferences:{onClickFilter:[{columnIndex:0,expression:""}]},type:"bar",sql:"select COUNT(*) from YOUR_TABLE",data:[]},I={id:s.v4(),cards:[p],activeCardId:p.id};g(D.id,I),j(I.id)},h=()=>{S(!0)};async function v(){if(c(!0),!a||!r)return;const p=Pe(o),I=JSON.stringify(p),z={...r,template:I,filterValues:x};await ze(z,t==null?void 0:t.accessToken),s.Jt.success("Lens saved"),f==null||f(p),c(!1)}return u?null:e.jsxs("div",{className:"flex items-center justify-between gap-2 border-b bg-muted/50 py-2 pl-3 pr-2",role:"dashboard-controls",children:[!u&&e.jsx("div",{className:"flex items-center gap-3",children:e.jsx(s.Label,{children:r==null?void 0:r.name})}),e.jsxs("div",{className:"flex gap-2",children:[l&&!u&&E&&e.jsx(Ks,{}),!u&&E&&e.jsx(Ws,{}),l&&!u&&e.jsxs(s.Button,{variant:"secondary",className:"h-7 p-2",size:"sm",disabled:!l,onClick:O,children:[e.jsx(s.Plus,{className:"mr-2 h-4 w-4",strokeWidth:1.5}),"Frame"]}),!l&&e.jsx(s.Button,{variant:"ghost",className:"h-7 p-2",onClick:h,size:"sm",children:e.jsx(Be,{className:"h-4 w-4",strokeWidth:1.5})}),l&&!u&&e.jsx(s.Button,{variant:"ghost",role:"close",className:"h-7 p-2",onClick:()=>{S(!1),A(!1)},size:"sm",children:e.jsx(s.Cross2Icon,{className:"h-4 w-4",strokeWidth:1.5})}),l&&!u&&E&&e.jsx(s.Button,{className:"h-7 p-2",variant:"ghost",disabled:d,onClick:v,size:"sm",children:e.jsx(fs,{className:"h-4 w-4",strokeWidth:1.5})}),!y&&!u&&l&&e.jsx(s.Button,{className:"h-7 p-2",variant:"ghost",onClick:()=>m(!0),size:"sm",children:e.jsx(s.Filter,{className:"h-4 w-4",strokeWidth:1.5})}),!u&&l&&!1,!u&&!1]})]})}function he({title:t,items:n,value:a,isLoading:r,isError:o,connectionTooltip:l,onChange:i,showNone:d=!1,className:c,showIcon:x=!0,disabled:u=!1}){const y=r?"Loading...":o?"Error":a;function f(){if(t==="Connection")return e.jsx(ps,{className:"size-4 rotate-90"});if(t==="Database")return e.jsx(ss,{className:"size-4"});if(t==="Schema")return e.jsx(ms,{className:"size-4"});if(t==="Table")return e.jsx(s.Table,{className:"size-4"});if(t==="Model")return e.jsx(Ye,{className:"size-4"})}return e.jsxs("div",{className:"flex items-center gap-2",children:[x&&e.jsx("div",{className:"shrink-0",children:l?e.jsxs(s.Tooltip,{children:[e.jsx(s.TooltipTrigger,{children:f()}),e.jsx(s.TooltipContent,{className:"text-xs",align:"start",children:l})]}):f()}),e.jsxs(s.Select,{disabled:u,value:y,onValueChange:i,children:[e.jsx(s.SelectTrigger,{className:s.cn("h-9 w-full focus:ring-1 focus:ring-offset-0",c),children:e.jsx(s.SelectValue,{placeholder:r?"Loading...":o?"Error":`Select ${t}`})}),e.jsx(s.SelectContent,{children:e.jsxs(s.SelectGroup,{children:[r?e.jsx(s.SelectLabel,{children:"Loading..."}):e.jsx(s.SelectLabel,{children:t}),e.jsxs(e.Fragment,{children:[d&&e.jsx(s.SelectItem,{value:"none",children:"None"},"none"),n&&n.map((m,g)=>e.jsx(s.SelectItem,{value:m.id,children:m.name},g))]}),(r||o)&&e.jsx(s.SelectItem,{value:y,children:y})]})})]})]})}function Xs({column:t}){const[n,a]=w.useState(!1),r=s.useEditorStore(m=>m.selectedTableName),o=s.useEditorStore(m=>m.selectedSchemaName),l=s.useEditorStore(m=>m.selectedDatamodelId),i=s.useEditorStore(m=>m.sqlGen),{modelItems:d}=ie(),c=s.useEditorStore(m=>m.actions.setSqlGen),x=s.useEditorStore(m=>m.actions.setCardSql),u=s.useEditorStore(m=>m.actions.setRunSql);function y(m,g){var A;const j=s.createSqlGenConfig(m,i,g),L=(A=d==null?void 0:d.find(D=>D.id===l))==null?void 0:A.name;c(j);const S=s.getSql(j,s.fmt(o||""),s.fmt(r),L);S&&(x(S),u(!0)),a(!1)}function f(){return e.jsxs("ul",{className:"text-xs",children:[e.jsx("li",{onClick:()=>y(t,"COUNT"),className:"cursor-pointer p-1 px-3 transition-colors hover:bg-muted",children:"Count"}),e.jsx("li",{onClick:()=>y(t,"AVG"),className:"cursor-pointer p-1 px-3 transition-colors hover:bg-muted",children:"Avg"}),e.jsx("li",{onClick:()=>y(t,"SUM"),className:"cursor-pointer p-1 px-3 transition-colors hover:bg-muted",children:"Sum"}),e.jsx("li",{onClick:()=>y(t,"MAX"),className:"cursor-pointer p-1 px-3 transition-colors hover:bg-muted",children:"Max"}),e.jsx("li",{onClick:()=>y(t,"MIN"),className:"cursor-pointer p-1 px-3 transition-colors hover:bg-muted",children:"Min"})]})}return e.jsxs(s.HoverCard,{openDelay:0,open:n,onOpenChange:a,children:[e.jsx(s.HoverCardTrigger,{asChild:!0,children:e.jsx(Re,{className:"invisible size-3.5 cursor-pointer text-foreground/40 group-hover:visible"})}),e.jsx(s.HoverCardContent,{align:"center",className:"w-20 rounded-md p-0 shadow-none",children:f()})]})}function Ns({column:t}){return e.jsxs(s.Tooltip,{children:[e.jsx(s.$a093c7e1ec25a057$export$8c610744efcf8a1d,{asChild:!0,children:s.TEXT_DATA_TYPES.includes(t.data_type.toLowerCase())?e.jsx(Le,{className:"size-3"}):s.NUMBER_DATA_TYPES.includes(t.data_type.toLowerCase())?e.jsx(is,{className:"size-3"}):s.DATE_DATA_TYPES.includes(t.data_type.toLowerCase())?e.jsx(s.Calendar,{className:"size-3"}):s.BOOLEAN_DATA_TYPES.includes(t.data_type.toLowerCase())?e.jsx(vs,{className:"size-3"}):e.jsx(gs,{className:"size-3"})}),e.jsx(s.TooltipContent,{children:e.jsx("p",{className:"font-mono text-xs",children:t.data_type})})]})}function Zs({schemaName:t,tableName:n,columns:a,status:r}){const o=s.useEditorStore(h=>h.sqlGen),l=s.useEditorStore(h=>h.selectedConnectionId),i=s.useEditorStore(h=>h.selectedDatabaseName),d=s.useEditorStore(h=>h.selectedSchemaName),c=s.useEditorStore(h=>h.selectedTableName),x=s.useEditorStore(h=>h.selectedDatamodelId),u=s.useDashboardStore(h=>h.dashboard.aiScopeTables),{setAIScopeTables:y}=s.useDashboardStore(h=>h.actions),f=s.useEditorStore(h=>h.actions.setRunSql),m=s.useEditorStore(h=>h.actions.setSqlGen),g=s.useEditorStore(h=>h.actions.setIsShowingVisual),j=s.useEditorStore(h=>h.actions.setCardSql),{connectionType:L,modelItems:S}=ie();function A(h){var z;const v=s.createSqlGenConfig(h,o);m(v);const p=(z=S==null?void 0:S.find(R=>R.id===x))==null?void 0:z.name,I=s.getSql(v,s.fmt(t),s.fmt(n),p);I&&(j(I),f(!0))}function D(){return(u==null?void 0:u.find(h=>h.connectinonId===l&&h.tableName===c))!==void 0}function M(h){if(h===!0&&c&&l){const v={connectinonId:l,connectionType:L,databaseName:i,schemaName:d,tableName:c},I=[...u||[],v].filter((z,R,_)=>_.findIndex(H=>H.connectinonId===z.connectinonId&&H.tableName===z.tableName)===R);y(I),s.Jt.success(`Added '${c}' to AI Scope`,{position:"top-right",duration:2500,richColors:!0})}else{const v=(u||[]).filter(p=>p.connectinonId!==l&&p.tableName!==c);y(v),s.Jt(`Removed '${c}' from AI Scope`,{position:"top-right",duration:2e3,richColors:!0})}}function C(){var z;let h=s.getQualifiedTableName(t,n);const v=(z=S==null?void 0:S.find(R=>R.id===x))==null?void 0:z.name;console.log("modelName",v),x&&x!=="none"&&(h=`${s.DATAMODEL_NAMESPCACE}.${v}`);let p=h;return(R=>/[A-Z]/.test(R))(n)&&(p=p.split(".").map(_=>`"${_}"`).join(".")),p}function E(){const h=C();g(!1);const v=L==="MSSQL"?`SELECT top 10 * FROM ${h}`:`SELECT * FROM ${h} LIMIT 10`;j(v),f(!0)}function O(){const h=C();j(`SELECT COUNT(*) as count FROM ${h}`),f(!0)}return e.jsxs("div",{className:"flex grow flex-col space-y-4 px-4",children:[e.jsxs("div",{className:"flex items-center justify-center gap-1",children:[e.jsx(s.Toggle,{title:`${D()?"Remove from":"Add to"} AI Scope`,pressed:D(),onPressedChange:M,variant:"outline",className:"h-9 px-2",children:e.jsx(s.Bot,{className:s.cn("size-4",{"text-primary":D(),"text-muted-foreground":!D()})})}),e.jsxs(s.Button,{disabled:r!=="Success",onClick:E,size:"sm",variant:"secondary",className:"flex",children:[r!=="Success"?e.jsx(me,{className:"mr-2 h-4 w-4 animate-spin text-foreground/50"}):e.jsx(bs,{className:"mr-2 size-4"}),"Top 10"]}),e.jsxs(s.Button,{disabled:r!=="Success",onClick:O,size:"sm",variant:"secondary",className:"flex",children:[r!=="Success"?e.jsx(me,{className:"mr-2 h-4 w-4 animate-spin text-foreground/50"}):e.jsx(js,{className:"mr-2 size-4"}),"Count"]})]}),e.jsxs(s.ScrollArea,{className:"flex-1 basis-0 overflow-y-auto border-b border-t border-muted py-3",children:[a==null?void 0:a.map(h=>e.jsxs("div",{onClick:()=>A(h),className:s.cn("group mx-3 flex cursor-pointer items-center justify-between rounded px-2 py-[6px] text-sm transition-colors hover:bg-muted/50",{"bg-muted":s.isColumnInSqlGen(h,o)}),children:[e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(Ns,{column:h}),e.jsx("span",{children:h.column_name})]}),e.jsx("div",{onClick:v=>v.stopPropagation(),className:"flex items-center justify-end",children:s.NUMBER_DATA_TYPES.includes(h.data_type)&&e.jsx(Xs,{column:h})})]},h.column_name)),e.jsx(s.ScrollBar,{orientation:"vertical"}),e.jsx(s.ScrollBar,{orientation:"horizontal"})]})]})}function ie(t,n){var ge,ve,Se,Ce,je;let a=w.useMemo(()=>[],[]);const r=s.useSemaphorContext().authToken||t,o=s.useEditorStore(N=>N.selectedConnectionId),l=s.useEditorStore(N=>N.selectedDatamodelId),i=s.useEditorStore(N=>N.selectedDatabaseName),d=s.useEditorStore(N=>N.selectedSchemaName),c=s.useEditorStore(N=>N.selectedTableName),x=s.useEditorStore(N=>N.actions.setCurrentColumns),u=s.useEditorStore(N=>N.actions.setSelectedConnectionId),y=s.useEditorStore(N=>N.actions.setSelectedDatamodelId),f=s.useEditorStore(N=>N.actions.setSelectedDatabaseName),m=s.useEditorStore(N=>N.actions.setSelectedSchemaName),g=s.useEditorStore(N=>N.actions.setSelectedTableName),j=s.useEditorStore(N=>N.actions.setCardSql);function L(N){return o&&i&&d&&i!=="NA"?!0:o&&N==="API"?!1:!!(o&&N==="S3")}function S(N){return!!(o&&i&&i!=="NA"&&d&&c||o&&(N==="S3"||N==="API")||l&&l)}function A(N){return o&&N?!(N==="API"||N==="S3"):!1}const{data:D,isLoading:M,isError:C}=s.useQuery({queryKey:["connections"],queryFn:()=>s.getRequest("https://semaphor.cloud/api/v1/connections",(r==null?void 0:r.accessToken)||""),enabled:!!(r!=null&&r.accessToken)}),{data:E,isLoading:O,isError:h}=s.useQuery({queryKey:["models",o],queryFn:()=>s.getRequest("https://semaphor.cloud/api/v1/datamodels",(r==null?void 0:r.accessToken)||"",{connection_id:o}),enabled:!!(r!=null&&r.accessToken)&&!!o}),v=D==null?void 0:D.connections.find(N=>N.id===o),p=v==null?void 0:v.type,I=(v==null?void 0:v.type)==="API"||(v==null?void 0:v.type)==="S3",{data:z,isLoading:R,isFetching:_,isError:H,refetch:K}=s.useQuery({queryKey:["databases",o],queryFn:()=>s.getRequest("https://semaphor.cloud/api/v1/databases",(r==null?void 0:r.accessToken)||"",{connection_id:o}),enabled:A(p)}),{data:B,isLoading:J,isFetching:k,isError:V,refetch:G}=s.useQuery({queryKey:["schemas",o,i],queryFn:()=>s.getRequest("https://semaphor.cloud/api/v1/schemas",(r==null?void 0:r.accessToken)||"",{connection_id:o,database_name:i}),enabled:!!o&&!!i&&!I&&i!=="NA"}),{data:F,isLoading:T,isFetching:$,isError:q,refetch:P}=s.useQuery({queryKey:["tables",o,i,d],queryFn:()=>s.getRequest("https://semaphor.cloud/api/v1/tables",(r==null?void 0:r.accessToken)||"",{connection_id:o,database_name:i,schema_name:d}),enabled:L(p)}),{data:W,isLoading:te,isFetching:ce,isError:ae}=s.useQuery({queryKey:["columns",o,i,l,d,c],queryFn:()=>s.getRequest("https://semaphor.cloud/api/v1/columns",(r==null?void 0:r.accessToken)||"",{connection_id:o,datamodel_id:l||"",database_name:i,schema_name:d,table_name:c}),enabled:S(p)});w.useEffect(()=>{x(a)},[W,x,a]),w.useEffect(()=>{},[I,j,g,m,f,v]);const re=(v==null?void 0:v.type)==="API"?(ge=v==null?void 0:v.type)==null?void 0:ge.toLowerCase():c||"",ne=I?"":d||"";function Q(N){m(N),g("")}function X(N){f(N==="none"?"":N),m(""),g(""),N!=="none"&&N!==""&&y("")}function Z(N){u(N)}function ye(N){y(N==="none"?"":N),N!=="none"&&N!==""&&f("")}z&&((ve=z==null?void 0:z.databases)==null?void 0:ve.length)>0,B&&((Se=B==null?void 0:B.schemas)==null?void 0:Se.length)>0,W&&((Ce=W==null?void 0:W.columns)==null?void 0:Ce.length)>0&&(a=W.columns.map(N=>({...N,data_type:N.data_type.toLowerCase()}))),H&&(a=[]),(ae||C)&&(a=[]);const de=D==null?void 0:D.connections.map(N=>({id:N.id,name:N.name,type:N.type})),pe=(je=E==null?void 0:E.datamodels)==null?void 0:je.map(N=>({id:N.id,name:N.name})),fe=z==null?void 0:z.databases.map(N=>({id:N.database_name,name:N.database_name})),ue=B==null?void 0:B.schemas.map(N=>({id:N.schema_name,name:N.schema_name})),Ae=F==null?void 0:F.tables.map(N=>({id:N.table_name,name:N.table_name}));return{connectionItems:de,isConnectionsLoading:M,isConnectionsError:C,modelItems:pe,isModelsLoading:O,isModelsError:h,databaseItems:fe,isDatabasesLoadingOrFetching:R||_,isDatabaseError:H,schemaItems:ue,isSchemaLoadingOrFetching:J||k,isSchemaError:V,tableItems:Ae,isTableLoadingOrFetching:T||$,isTableError:q,columns:a,isColumnsLoadingOrFetching:te||ce,isColumnsError:ae,isNonDbConnection:I,connectionType:p,tableName:re,schemaName:ne,handleConnectionChange:Z,handleDatamodelChange:ye,handleDatabaseChange:X,handleSchemaChange:Q}}function ws({ColumnsComponent:t}){var $;const n=s.useEditorStore(q=>q.selectedConnectionId),a=s.useEditorStore(q=>q.selectedDatamodelId),r=s.useEditorStore(q=>q.selectedDatabaseName),o=s.useEditorStore(q=>q.selectedSchemaName),l=s.useEditorStore(q=>q.selectedTableName),i=s.useEditorStore(q=>q.actions.setSelectedTableName),{connectionItems:d,modelItems:c,schemaItems:x,databaseItems:u,tableItems:y,columns:f,isConnectionsLoading:m,isModelsLoading:g,isConnectionsError:j,isModelsError:L,isDatabasesLoadingOrFetching:S,isDatabaseError:A,isSchemaLoadingOrFetching:D,isSchemaError:M,isColumnsError:C,isColumnsLoadingOrFetching:E,isTableLoadingOrFetching:O,isTableError:h,connectionType:v,isNonDbConnection:p,handleConnectionChange:I,handleDatabaseChange:z,handleSchemaChange:R,handleDatamodelChange:_,tableName:H,schemaName:K}=ie();function B(){return t?t(K,H,f):e.jsx(Zs,{schemaName:K,tableName:H,columns:f,status:E?"Loading...":C?"Error":"Success"})}function J(){window.location.href="mailto:support@semaphor.cloud?subject=Help&body=I need help with..."}function k(){if(!n||v==="S3"||v==="API")return null;if(!a||a==="none")return e.jsx(he,{showNone:!0,onChange:z,isError:A,isLoading:S,items:u,value:r||"",title:"Database"})}function V(){if(n&&!p&&(!r||r==="none")&&(!a||a==="none"))return e.jsxs("div",{className:"grid grid-cols-3",children:[e.jsx("div",{className:"col-span-1 grid place-items-center",children:e.jsx(s.Separator,{})}),e.jsx("div",{className:"col-span-1 grid place-items-center",children:e.jsx(s.Label,{children:"OR"})}),e.jsx("div",{className:"col-span-1 grid place-items-center",children:e.jsx(s.Separator,{})})]})}function G(){if(!n||v==="S3"||v==="API")return null;if(!r||r==="none")return e.jsx(he,{showNone:!0,onChange:_,isError:L,isLoading:g,items:c,value:a||"",title:"Model"})}function F(){return!n||v==="S3"||v==="API"||!r||r==="none"?null:e.jsx(he,{onChange:R,isError:M,isLoading:D,items:x,value:o||"",title:"Schema"})}function T(){function q(){let P=!1;return v==="API"?(P=!1,P):((v==="S3"||n&&r&&r!=="none"&&o)&&(P=!0),P)}return q()?e.jsx(he,{onChange:i,isError:h,items:y,isLoading:O,value:l||"",title:"Table"}):null}return e.jsxs("aside",{className:"xbg-red-100 flex grow flex-col justify-between",children:[e.jsxs("section",{className:"space-y-3 px-6 py-4",children:[e.jsx(he,{items:d,title:"Connection",value:n||"",onChange:I,isLoading:m,isError:j,connectionTooltip:(($=d==null?void 0:d.find(q=>q.id===n))==null?void 0:$.type)||""}),G(),V(),k(),F(),T()]}),B(),e.jsx("div",{className:"flex items-end justify-center gap-2 px-6 py-4",children:e.jsxs(s.Button,{onClick:J,size:"sm",variant:"secondary",className:"w-full",children:[e.jsx(hs,{className:"mr-2 size-4"}),"Help"]})})]})}function et(t){const n=t.toUpperCase().indexOf("WHERE"),a=t.toUpperCase().indexOf("GROUP BY"),r=t.toUpperCase().indexOf("LIMIT"),o=t.toUpperCase().indexOf("ORDER BY");let l=t.length;if(o!==-1&&(l=o),r!==-1&&r<l&&(l=r),n!==-1){const i=t.substring(0,n),d=t.substring(n);return`${i} {{ filters | where }} AND ${d.substring(6)}`}else if(a!==-1){const i=t.substring(0,a),d=t.substring(a);return`${i} {{ filters | where }} ${d}`}else{const i=t.substring(0,l),d=t.substring(l);return`${i} {{ filters | where }} ${d}`}}function st({error:t,setShowAIDialog:n,setUserInputforAI:a,setTriggerAIRun:r}){return e.jsxs(s.HoverCard,{openDelay:0,children:[e.jsx(s.HoverCardTrigger,{asChild:!0,children:e.jsx(s.Button,{variant:"link",className:"h-5 p-0",children:e.jsx(Ze,{className:"h-4 w-4 text-red-500"})})}),e.jsx(s.HoverCardContent,{align:"start",className:"min-w-fit max-w-[500px]",children:e.jsx("div",{className:"flex justify-between space-x-4",children:e.jsxs("div",{className:"flex grow flex-col space-y-2",children:[e.jsx(s.ScrollArea,{className:"max-h-[250px] min-h-0 overflow-scroll",children:e.jsx("p",{className:"overflow-auto rounded-md bg-muted p-2 text-xs leading-relaxed",children:t})}),e.jsxs(s.Button,{onClick:()=>{n(!0),a(t),r(!0)},size:"sm",variant:"outline",children:[e.jsx(os,{className:"mr-2 h-4 w-4"}),"Debug with AI"]})]})})})]})}function tt({text:t,onCheckedChange:n,checked:a}){return e.jsxs("div",{className:"xbg-red-100 ml-6 flex items-center gap-2",children:[e.jsx(s.Checkbox,{checked:a,onCheckedChange:n}),e.jsx("label",{className:"text-xs leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70",children:t})]})}function at(){const{authToken:t}=s.useSemaphorContext(),n=s.useEditorStore(l=>l.selectedConnectionId),{data:a}=s.useQuery({queryKey:["connections"],queryFn:()=>s.getRequest("https://semaphor.cloud/api/v1/connections",(t==null?void 0:t.accessToken)||""),enabled:!!(t!=null&&t.accessToken)}),r=a==null?void 0:a.connections.find(l=>l.id===n);return r==null?void 0:r.type}function nt(){const{authToken:t}=s.useSemaphorContext(),n=w.useRef(null),a=s.useEditorStore(c=>c.applyFilters),[r,o]=w.useState(""),l=s.useEditorStore(c=>c.filterValues),i=s.useEditorStore(c=>c.card.sql),d=at();return e.jsxs(s.HoverCard,{openDelay:0,onOpenChange:async c=>{if(!c)return;console.log("onOpenChange");const x=await s.postRequest("https://semaphor.cloud/api/v1/filter-sql",(t==null?void 0:t.accessToken)||"",{sql:i,active_filters:l,connection_type:d});console.log(x),x.sql?(console.log(x.records),o(x.sql)):o("Error")},children:[e.jsx(s.HoverCardTrigger,{asChild:!0,children:a&&e.jsx("p",{className:"p-0 text-xs hover:cursor-pointer",children:"|  Filter Query"})}),e.jsxs(s.HoverCardContent,{align:"end",className:"w-[600px]",children:[e.jsx("div",{className:"flex justify-between space-x-4",children:e.jsx("div",{className:"rounded-sm bg-muted p-2",children:e.jsxs("code",{ref:n,className:"font-mono text-sm",children:[r,e.jsx(s.ClipboardCopyIcon,{onClick:()=>s.copyToClipboard(n),className:"ml-3 inline-block h-4 w-4 opacity-70 hover:cursor-pointer hover:opacity-100"})]})})}),e.jsxs("div",{className:"flex items-center gap-2 pt-2",children:[e.jsx(s.InfoCircledIcon,{className:"h-4 w-4 opacity-70"}),e.jsx("span",{className:"text-xs text-muted-foreground",children:"A preview of the query with filters applied."})]})]})]})}const rt=`
191
+ */const Ss=s.createLucideIcon("User",[["path",{d:"M19 21v-2a4 4 0 0 0-4-4H9a4 4 0 0 0-4 4v2",key:"975kel"}],["circle",{cx:"12",cy:"7",r:"4",key:"17ys0d"}]]);function Pe(t){var n;return{...t,sheets:(n=t==null?void 0:t.sheets)==null?void 0:n.map(a=>{var r;return{...a,frames:(r=a.frames)==null?void 0:r.map(o=>{var l;return{...o,cards:(l=o.cards)==null?void 0:l.map(i=>Cs(i))}})}})}}function Cs(t){var n,a,r,o;return{...t,cfg:{...t.cfg,data:{...(n=t.cfg)==null?void 0:n.data,labels:[],datasets:(o=(r=(a=t.cfg)==null?void 0:a.data)==null?void 0:r.datasets)==null?void 0:o.map(l=>({...l,data:[]}))}},customCfg:Qs(t.customCfg),data:[]}}function Qs(t){var n,a;return t?{...t,data:{...t==null?void 0:t.data,labels:[],datasets:(a=(n=t==null?void 0:t.data)==null?void 0:n.datasets)==null?void 0:a.map(r=>({...r,data:[]}))}}:null}async function Us(t,n,a,r){if(!r)return null;const o=JSON.stringify(n),l="https://semaphor.cloud/api/v1/lens";return await s.postRequest(l,r,{name:t,template:o,filterValues:a,operation:"create"})}async function ze(t,n){if(!n)return null;const{id:a,template:r,filterValues:o,isDefault:l,shared:i}=t,d="https://semaphor.cloud/api/v1/lens";return await s.postRequest(d,n,{lensId:a,template:r,filterValues:o,isDefault:l,shared:i,operation:"update"})}async function Js(t,n){if(!n)return null;const a="https://semaphor.cloud/api/v1/lens";return await s.postRequest(a,n,{operation:"delete",lensId:t})}function Ks(){const[t,n]=w.useState(""),[a,r]=w.useState(!1),o=s.useDashboardStore(j=>j.lenses),{setLenses:l,setSelectedLensId:i}=s.useDashboardActions(),[d,c]=w.useState(!1),[x,u]=w.useState(!1),y=s.useDashboardStore(j=>j.dashboard),f=s.useDashboardStore(j=>j.filterValues),{authToken:m}=s.useSemaphorContext();async function g(){c(!0);const j=Pe(y),L=await Us(t,j,f,m==null?void 0:m.accessToken);L&&(l([...o||[],L]),i(L.id),u(!1)),c(!1)}return e.jsxs(s.Dialog,{open:x,onOpenChange:u,children:[e.jsx(s.DialogTrigger,{asChild:!0,children:e.jsxs(s.Button,{variant:"secondary",className:"h-7 p-2",size:"sm",children:[e.jsx(s.Plus,{className:"mr-2 h-4 w-4",strokeWidth:1.5}),"Lens"]})}),e.jsxs(s.DialogContent,{className:"sm:max-w-[425px]",children:[e.jsxs(s.DialogHeader,{children:[e.jsx(s.DialogTitle,{children:"Create Lens"}),e.jsx(s.DialogDescription,{children:"Lenses are private by default and are only visible to you."})]}),e.jsx("div",{className:"grid gap-4 py-4",children:e.jsxs("div",{className:"grid grid-cols-8 items-center gap-4",children:[e.jsx(s.Label,{className:"text-right",children:"Name"}),e.jsx(s.Input,{value:t,onChange:j=>{n(j.target.value)},id:"name",className:"col-span-7 focus-visible:ring-0 focus-visible:ring-ring focus-visible:ring-offset-0"})]})}),a&&e.jsx("p",{className:"text-sm",children:"The lens name already exists. Use a differnet name."}),e.jsx(s.DialogFooter,{children:e.jsx(s.Button,{size:"sm",variant:"outline",type:"submit",onClick:g,disabled:d,children:d?"Creating...":"Add"})})]})]})}function Ws(){const[t,n]=w.useState(!1),a=s.useDashboardStore(u=>u.lenses),r=s.useDashboardStore(u=>u.selectedLensId),{setLenses:o,setSelectedLensId:l}=s.useDashboardActions(),{authToken:i}=s.useSemaphorContext();async function d(u){l(u)}async function c(u){if(await Js(u,i==null?void 0:i.accessToken)){const f=a==null?void 0:a.filter(m=>m.id!==u);o(f||[]),l("original")}}async function x(u){const y=a==null?void 0:a.map(g=>g.id===u.id?{...g,isDefault:!u.isDefault}:{...g,isDefault:!1});o(y||[]);const f={...u,isDefault:!u.isDefault};await ze(f,i==null?void 0:i.accessToken);const m=a==null?void 0:a.find(g=>g.isDefault);if(m&&m.id!==u.id){const g={...m,isDefault:!1};await ze(g,i==null?void 0:i.accessToken)}}return e.jsxs(s.DropdownMenu,{open:t,onOpenChange:n,children:[e.jsx(s.DropdownMenuTrigger,{asChild:!0,children:e.jsx(s.Button,{variant:"ghost",className:"h-7 p-2",children:e.jsx(rs,{className:"h-4 w-4",strokeWidth:1.5})})}),e.jsxs(s.DropdownMenuContent,{align:"end",className:"w-60",children:[e.jsx(s.DropdownMenuLabel,{className:"px-3",children:"Lenses"}),e.jsx(s.DropdownMenuSeparator,{}),e.jsxs(s.DropdownMenuRadioGroup,{value:r,onValueChange:d,children:[e.jsx(s.DropdownMenuRadioItem,{value:"original",children:"Original"}),a==null?void 0:a.map(u=>e.jsxs(s.DropdownMenuRadioItem,{className:"group flex justify-between gap-2",value:u.id,children:[e.jsx("p",{children:u.name}),e.jsxs("span",{className:"flex items-center gap-3",children:[e.jsx(ls,{onClick:y=>{y.preventDefault(),x(u)},className:s.cn("size-3.5 text-muted-foreground hover:cursor-pointer hover:text-foreground group-hover:visible",{invisible:!u.isDefault,"text-green-500":u.isDefault}),strokeWidth:1.5}),e.jsx(s.Cross2Icon,{onClick:y=>{y.preventDefault(),c(u.id)},className:"invisible size-3.5 text-muted-foreground hover:cursor-pointer hover:text-foreground group-hover:visible",strokeWidth:1.5})]})]},u.id))]})]})]})}function Ys(){const{authToken:t}=s.useSemaphorContext(),n=s.useDashboardStore(p=>p.lenses),a=s.useDashboardStore(p=>p.selectedLensId),r=n==null?void 0:n.find(p=>p.id===a),o=s.useDashboardStore(p=>p.dashboard);s.useDashboardStore(p=>p.selectedSheetId);const l=s.useDashboardStore(p=>p.isDashboardEditing),i=s.useEditorStore(p=>p.selectedConnectionId),[d,c]=w.useState(!1),x=s.useDashboardStore(p=>p.filterValues),u=s.useDashboardStore(p=>p.isVisualEditing),y=s.useDashboardStore(p=>p.showFilters);s.useDashboardStore(p=>p.showDashboardJSON);const f=s.useDashboardStore(p=>p.onSaveFunction),m=s.useDashboardStore(p=>p.actions.setShowFilters),{addFrame:g,setSelectedFrameId:j}=s.useDashboardStore(p=>p.actions),{getSelectedSheet:L,setIsDashboardEditing:S,setShowDashboardJSON:A}=s.useDashboardStore(p=>p.actions),D=L(),{tenantId:M,endUserId:C}=w.useMemo(()=>s.getTenantAndEndUserId(t==null?void 0:t.accessToken),[t==null?void 0:t.accessToken]),E=w.useMemo(()=>M||C,[M,C]),O=()=>{if(!l||!D)return;const p={connectionId:i,id:s.v4(),title:"Title",description:"Description",preferences:{onClickFilter:[{columnIndex:0,expression:""}]},type:"bar",sql:"select COUNT(*) from YOUR_TABLE",data:[]},I={id:s.v4(),cards:[p],activeCardId:p.id};g(D.id,I),j(I.id)},h=()=>{S(!0)};async function v(){if(c(!0),!a||!r)return;const p=Pe(o),I=JSON.stringify(p),z={...r,template:I,filterValues:x};await ze(z,t==null?void 0:t.accessToken),s.Jt.success("Lens saved"),f==null||f(p),c(!1)}return u?null:e.jsxs("div",{className:"flex items-center justify-between gap-2 border-b bg-muted/50 py-2 pl-3 pr-2",role:"dashboard-controls",children:[!u&&e.jsx("div",{className:"flex items-center gap-3",children:e.jsx(s.Label,{children:r==null?void 0:r.name})}),e.jsxs("div",{className:"flex gap-2",children:[l&&!u&&E&&e.jsx(Ks,{}),!u&&E&&e.jsx(Ws,{}),l&&!u&&e.jsxs(s.Button,{variant:"secondary",className:"h-7 p-2",size:"sm",disabled:!l,onClick:O,children:[e.jsx(s.Plus,{className:"mr-2 h-4 w-4",strokeWidth:1.5}),"Frame"]}),!l&&e.jsx(s.Button,{variant:"ghost",className:"h-7 p-2",onClick:h,size:"sm",children:e.jsx(Be,{className:"h-4 w-4",strokeWidth:1.5})}),l&&!u&&e.jsx(s.Button,{variant:"ghost",role:"close",className:"h-7 p-2",onClick:()=>{S(!1),A(!1)},size:"sm",children:e.jsx(s.Cross2Icon,{className:"h-4 w-4",strokeWidth:1.5})}),l&&!u&&E&&e.jsx(s.Button,{className:"h-7 p-2",variant:"ghost",disabled:d,onClick:v,size:"sm",children:e.jsx(fs,{className:"h-4 w-4",strokeWidth:1.5})}),!y&&!u&&l&&e.jsx(s.Button,{className:"h-7 p-2",variant:"ghost",onClick:()=>m(!0),size:"sm",children:e.jsx(s.Filter,{className:"h-4 w-4",strokeWidth:1.5})}),!u&&l&&!1,!u&&!1]})]})}function he({title:t,items:n,value:a,isLoading:r,isError:o,connectionTooltip:l,onChange:i,showNone:d=!1,className:c,showIcon:x=!0,disabled:u=!1}){const y=r?"Loading...":o?"Error":a;function f(){if(t==="Connection")return e.jsx(ps,{className:"size-4 rotate-90"});if(t==="Database")return e.jsx(ss,{className:"size-4"});if(t==="Schema")return e.jsx(ms,{className:"size-4"});if(t==="Table")return e.jsx(s.Table,{className:"size-4"});if(t==="Model")return e.jsx(Ye,{className:"size-4"})}return e.jsxs("div",{className:"flex items-center gap-2",children:[x&&e.jsx("div",{className:"shrink-0",children:l?e.jsxs(s.Tooltip,{children:[e.jsx(s.TooltipTrigger,{children:f()}),e.jsx(s.TooltipContent,{className:"text-xs",align:"start",children:l})]}):f()}),e.jsxs(s.Select,{disabled:u,value:y,onValueChange:i,children:[e.jsx(s.SelectTrigger,{className:s.cn("h-9 w-full focus:ring-1 focus:ring-offset-0",c),children:e.jsx(s.SelectValue,{placeholder:r?"Loading...":o?"Error":`Select ${t}`})}),e.jsx(s.SelectContent,{children:e.jsxs(s.SelectGroup,{children:[r?e.jsx(s.SelectLabel,{children:"Loading..."}):e.jsx(s.SelectLabel,{children:t}),e.jsxs(e.Fragment,{children:[d&&e.jsx(s.SelectItem,{value:"none",children:"None"},"none"),n&&n.map((m,g)=>e.jsx(s.SelectItem,{value:m.id,children:m.name},g))]}),(r||o)&&e.jsx(s.SelectItem,{value:y,children:y})]})})]})]})}function Xs({column:t}){const[n,a]=w.useState(!1),r=s.useEditorStore(m=>m.selectedTableName),o=s.useEditorStore(m=>m.selectedSchemaName),l=s.useEditorStore(m=>m.selectedDatamodelId),i=s.useEditorStore(m=>m.sqlGen),{modelItems:d}=ie(),c=s.useEditorStore(m=>m.actions.setSqlGen),x=s.useEditorStore(m=>m.actions.setCardSql),u=s.useEditorStore(m=>m.actions.setRunSql);function y(m,g){var A;const j=s.createSqlGenConfig(m,i,g),L=(A=d==null?void 0:d.find(D=>D.id===l))==null?void 0:A.name;c(j);const S=s.getSql(j,s.fmt(o||""),s.fmt(r),L);S&&(x(S),u(!0)),a(!1)}function f(){return e.jsxs("ul",{className:"text-xs",children:[e.jsx("li",{onClick:()=>y(t,"COUNT"),className:"cursor-pointer p-1 px-3 transition-colors hover:bg-muted",children:"Count"}),e.jsx("li",{onClick:()=>y(t,"AVG"),className:"cursor-pointer p-1 px-3 transition-colors hover:bg-muted",children:"Avg"}),e.jsx("li",{onClick:()=>y(t,"SUM"),className:"cursor-pointer p-1 px-3 transition-colors hover:bg-muted",children:"Sum"}),e.jsx("li",{onClick:()=>y(t,"MAX"),className:"cursor-pointer p-1 px-3 transition-colors hover:bg-muted",children:"Max"}),e.jsx("li",{onClick:()=>y(t,"MIN"),className:"cursor-pointer p-1 px-3 transition-colors hover:bg-muted",children:"Min"})]})}return e.jsxs(s.HoverCard,{openDelay:0,open:n,onOpenChange:a,children:[e.jsx(s.HoverCardTrigger,{asChild:!0,children:e.jsx(Re,{className:"invisible size-3.5 cursor-pointer text-foreground/40 group-hover:visible"})}),e.jsx(s.HoverCardContent,{align:"center",className:"w-20 rounded-md p-0 shadow-none",children:f()})]})}function Ns({column:t}){return e.jsxs(s.Tooltip,{children:[e.jsx(s.TooltipTrigger$1,{asChild:!0,children:s.TEXT_DATA_TYPES.includes(t.data_type.toLowerCase())?e.jsx(Le,{className:"size-3"}):s.NUMBER_DATA_TYPES.includes(t.data_type.toLowerCase())?e.jsx(is,{className:"size-3"}):s.DATE_DATA_TYPES.includes(t.data_type.toLowerCase())?e.jsx(s.Calendar,{className:"size-3"}):s.BOOLEAN_DATA_TYPES.includes(t.data_type.toLowerCase())?e.jsx(vs,{className:"size-3"}):e.jsx(gs,{className:"size-3"})}),e.jsx(s.TooltipContent,{children:e.jsx("p",{className:"font-mono text-xs",children:t.data_type})})]})}function Zs({schemaName:t,tableName:n,columns:a,status:r}){const o=s.useEditorStore(h=>h.sqlGen),l=s.useEditorStore(h=>h.selectedConnectionId),i=s.useEditorStore(h=>h.selectedDatabaseName),d=s.useEditorStore(h=>h.selectedSchemaName),c=s.useEditorStore(h=>h.selectedTableName),x=s.useEditorStore(h=>h.selectedDatamodelId),u=s.useDashboardStore(h=>h.dashboard.aiScopeTables),{setAIScopeTables:y}=s.useDashboardStore(h=>h.actions),f=s.useEditorStore(h=>h.actions.setRunSql),m=s.useEditorStore(h=>h.actions.setSqlGen),g=s.useEditorStore(h=>h.actions.setIsShowingVisual),j=s.useEditorStore(h=>h.actions.setCardSql),{connectionType:L,modelItems:S}=ie();function A(h){var z;const v=s.createSqlGenConfig(h,o);m(v);const p=(z=S==null?void 0:S.find(R=>R.id===x))==null?void 0:z.name,I=s.getSql(v,s.fmt(t),s.fmt(n),p);I&&(j(I),f(!0))}function D(){return(u==null?void 0:u.find(h=>h.connectinonId===l&&h.tableName===c))!==void 0}function M(h){if(h===!0&&c&&l){const v={connectinonId:l,connectionType:L,databaseName:i,schemaName:d,tableName:c},I=[...u||[],v].filter((z,R,_)=>_.findIndex(H=>H.connectinonId===z.connectinonId&&H.tableName===z.tableName)===R);y(I),s.Jt.success(`Added '${c}' to AI Scope`,{position:"top-right",duration:2500,richColors:!0})}else{const v=(u||[]).filter(p=>p.connectinonId!==l&&p.tableName!==c);y(v),s.Jt(`Removed '${c}' from AI Scope`,{position:"top-right",duration:2e3,richColors:!0})}}function C(){var z;let h=s.getQualifiedTableName(t,n);const v=(z=S==null?void 0:S.find(R=>R.id===x))==null?void 0:z.name;console.log("modelName",v),x&&x!=="none"&&(h=`${s.DATAMODEL_NAMESPCACE}.${v}`);let p=h;return(R=>/[A-Z]/.test(R))(n)&&(p=p.split(".").map(_=>`"${_}"`).join(".")),p}function E(){const h=C();g(!1);const v=L==="MSSQL"?`SELECT top 10 * FROM ${h}`:`SELECT * FROM ${h} LIMIT 10`;j(v),f(!0)}function O(){const h=C();j(`SELECT COUNT(*) as count FROM ${h}`),f(!0)}return e.jsxs("div",{className:"flex grow flex-col space-y-4 px-4",children:[e.jsxs("div",{className:"flex items-center justify-center gap-1",children:[e.jsx(s.Toggle,{title:`${D()?"Remove from":"Add to"} AI Scope`,pressed:D(),onPressedChange:M,variant:"outline",className:"h-9 px-2",children:e.jsx(s.Bot,{className:s.cn("size-4",{"text-primary":D(),"text-muted-foreground":!D()})})}),e.jsxs(s.Button,{disabled:r!=="Success",onClick:E,size:"sm",variant:"secondary",className:"flex",children:[r!=="Success"?e.jsx(me,{className:"mr-2 h-4 w-4 animate-spin text-foreground/50"}):e.jsx(bs,{className:"mr-2 size-4"}),"Top 10"]}),e.jsxs(s.Button,{disabled:r!=="Success",onClick:O,size:"sm",variant:"secondary",className:"flex",children:[r!=="Success"?e.jsx(me,{className:"mr-2 h-4 w-4 animate-spin text-foreground/50"}):e.jsx(js,{className:"mr-2 size-4"}),"Count"]})]}),e.jsxs(s.ScrollArea,{className:"flex-1 basis-0 overflow-y-auto border-b border-t border-muted py-3",children:[a==null?void 0:a.map(h=>e.jsxs("div",{onClick:()=>A(h),className:s.cn("group mx-3 flex cursor-pointer items-center justify-between rounded px-2 py-[6px] text-sm transition-colors hover:bg-muted/50",{"bg-muted":s.isColumnInSqlGen(h,o)}),children:[e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(Ns,{column:h}),e.jsx("span",{children:h.column_name})]}),e.jsx("div",{onClick:v=>v.stopPropagation(),className:"flex items-center justify-end",children:s.NUMBER_DATA_TYPES.includes(h.data_type)&&e.jsx(Xs,{column:h})})]},h.column_name)),e.jsx(s.ScrollBar,{orientation:"vertical"}),e.jsx(s.ScrollBar,{orientation:"horizontal"})]})]})}function ie(t,n){var ge,ve,Se,Ce,je;let a=w.useMemo(()=>[],[]);const r=s.useSemaphorContext().authToken||t,o=s.useEditorStore(N=>N.selectedConnectionId),l=s.useEditorStore(N=>N.selectedDatamodelId),i=s.useEditorStore(N=>N.selectedDatabaseName),d=s.useEditorStore(N=>N.selectedSchemaName),c=s.useEditorStore(N=>N.selectedTableName),x=s.useEditorStore(N=>N.actions.setCurrentColumns),u=s.useEditorStore(N=>N.actions.setSelectedConnectionId),y=s.useEditorStore(N=>N.actions.setSelectedDatamodelId),f=s.useEditorStore(N=>N.actions.setSelectedDatabaseName),m=s.useEditorStore(N=>N.actions.setSelectedSchemaName),g=s.useEditorStore(N=>N.actions.setSelectedTableName),j=s.useEditorStore(N=>N.actions.setCardSql);function L(N){return o&&i&&d&&i!=="NA"?!0:o&&N==="API"?!1:!!(o&&N==="S3")}function S(N){return!!(o&&i&&i!=="NA"&&d&&c||o&&(N==="S3"||N==="API")||l&&l)}function A(N){return o&&N?!(N==="API"||N==="S3"):!1}const{data:D,isLoading:M,isError:C}=s.useQuery({queryKey:["connections"],queryFn:()=>s.getRequest("https://semaphor.cloud/api/v1/connections",(r==null?void 0:r.accessToken)||""),enabled:!!(r!=null&&r.accessToken)}),{data:E,isLoading:O,isError:h}=s.useQuery({queryKey:["models",o],queryFn:()=>s.getRequest("https://semaphor.cloud/api/v1/datamodels",(r==null?void 0:r.accessToken)||"",{connection_id:o}),enabled:!!(r!=null&&r.accessToken)&&!!o}),v=D==null?void 0:D.connections.find(N=>N.id===o),p=v==null?void 0:v.type,I=(v==null?void 0:v.type)==="API"||(v==null?void 0:v.type)==="S3",{data:z,isLoading:R,isFetching:_,isError:H,refetch:K}=s.useQuery({queryKey:["databases",o],queryFn:()=>s.getRequest("https://semaphor.cloud/api/v1/databases",(r==null?void 0:r.accessToken)||"",{connection_id:o}),enabled:A(p)}),{data:B,isLoading:J,isFetching:k,isError:V,refetch:G}=s.useQuery({queryKey:["schemas",o,i],queryFn:()=>s.getRequest("https://semaphor.cloud/api/v1/schemas",(r==null?void 0:r.accessToken)||"",{connection_id:o,database_name:i}),enabled:!!o&&!!i&&!I&&i!=="NA"}),{data:F,isLoading:T,isFetching:$,isError:q,refetch:P}=s.useQuery({queryKey:["tables",o,i,d],queryFn:()=>s.getRequest("https://semaphor.cloud/api/v1/tables",(r==null?void 0:r.accessToken)||"",{connection_id:o,database_name:i,schema_name:d}),enabled:L(p)}),{data:W,isLoading:te,isFetching:ce,isError:ae}=s.useQuery({queryKey:["columns",o,i,l,d,c],queryFn:()=>s.getRequest("https://semaphor.cloud/api/v1/columns",(r==null?void 0:r.accessToken)||"",{connection_id:o,datamodel_id:l||"",database_name:i,schema_name:d,table_name:c}),enabled:S(p)});w.useEffect(()=>{x(a)},[W,x,a]),w.useEffect(()=>{},[I,j,g,m,f,v]);const re=(v==null?void 0:v.type)==="API"?(ge=v==null?void 0:v.type)==null?void 0:ge.toLowerCase():c||"",ne=I?"":d||"";function Q(N){m(N),g("")}function X(N){f(N==="none"?"":N),m(""),g(""),N!=="none"&&N!==""&&y("")}function Z(N){u(N)}function ye(N){y(N==="none"?"":N),N!=="none"&&N!==""&&f("")}z&&((ve=z==null?void 0:z.databases)==null?void 0:ve.length)>0,B&&((Se=B==null?void 0:B.schemas)==null?void 0:Se.length)>0,W&&((Ce=W==null?void 0:W.columns)==null?void 0:Ce.length)>0&&(a=W.columns.map(N=>({...N,data_type:N.data_type.toLowerCase()}))),H&&(a=[]),(ae||C)&&(a=[]);const de=D==null?void 0:D.connections.map(N=>({id:N.id,name:N.name,type:N.type})),pe=(je=E==null?void 0:E.datamodels)==null?void 0:je.map(N=>({id:N.id,name:N.name})),fe=z==null?void 0:z.databases.map(N=>({id:N.database_name,name:N.database_name})),ue=B==null?void 0:B.schemas.map(N=>({id:N.schema_name,name:N.schema_name})),Ae=F==null?void 0:F.tables.map(N=>({id:N.table_name,name:N.table_name}));return{connectionItems:de,isConnectionsLoading:M,isConnectionsError:C,modelItems:pe,isModelsLoading:O,isModelsError:h,databaseItems:fe,isDatabasesLoadingOrFetching:R||_,isDatabaseError:H,schemaItems:ue,isSchemaLoadingOrFetching:J||k,isSchemaError:V,tableItems:Ae,isTableLoadingOrFetching:T||$,isTableError:q,columns:a,isColumnsLoadingOrFetching:te||ce,isColumnsError:ae,isNonDbConnection:I,connectionType:p,tableName:re,schemaName:ne,handleConnectionChange:Z,handleDatamodelChange:ye,handleDatabaseChange:X,handleSchemaChange:Q}}function ws({ColumnsComponent:t}){var $;const n=s.useEditorStore(q=>q.selectedConnectionId),a=s.useEditorStore(q=>q.selectedDatamodelId),r=s.useEditorStore(q=>q.selectedDatabaseName),o=s.useEditorStore(q=>q.selectedSchemaName),l=s.useEditorStore(q=>q.selectedTableName),i=s.useEditorStore(q=>q.actions.setSelectedTableName),{connectionItems:d,modelItems:c,schemaItems:x,databaseItems:u,tableItems:y,columns:f,isConnectionsLoading:m,isModelsLoading:g,isConnectionsError:j,isModelsError:L,isDatabasesLoadingOrFetching:S,isDatabaseError:A,isSchemaLoadingOrFetching:D,isSchemaError:M,isColumnsError:C,isColumnsLoadingOrFetching:E,isTableLoadingOrFetching:O,isTableError:h,connectionType:v,isNonDbConnection:p,handleConnectionChange:I,handleDatabaseChange:z,handleSchemaChange:R,handleDatamodelChange:_,tableName:H,schemaName:K}=ie();function B(){return t?t(K,H,f):e.jsx(Zs,{schemaName:K,tableName:H,columns:f,status:E?"Loading...":C?"Error":"Success"})}function J(){window.location.href="mailto:support@semaphor.cloud?subject=Help&body=I need help with..."}function k(){if(!n||v==="S3"||v==="API")return null;if(!a||a==="none")return e.jsx(he,{showNone:!0,onChange:z,isError:A,isLoading:S,items:u,value:r||"",title:"Database"})}function V(){if(n&&!p&&(!r||r==="none")&&(!a||a==="none"))return e.jsxs("div",{className:"grid grid-cols-3",children:[e.jsx("div",{className:"col-span-1 grid place-items-center",children:e.jsx(s.Separator,{})}),e.jsx("div",{className:"col-span-1 grid place-items-center",children:e.jsx(s.Label,{children:"OR"})}),e.jsx("div",{className:"col-span-1 grid place-items-center",children:e.jsx(s.Separator,{})})]})}function G(){if(!n||v==="S3"||v==="API")return null;if(!r||r==="none")return e.jsx(he,{showNone:!0,onChange:_,isError:L,isLoading:g,items:c,value:a||"",title:"Model"})}function F(){return!n||v==="S3"||v==="API"||!r||r==="none"?null:e.jsx(he,{onChange:R,isError:M,isLoading:D,items:x,value:o||"",title:"Schema"})}function T(){function q(){let P=!1;return v==="API"?(P=!1,P):((v==="S3"||n&&r&&r!=="none"&&o)&&(P=!0),P)}return q()?e.jsx(he,{onChange:i,isError:h,items:y,isLoading:O,value:l||"",title:"Table"}):null}return e.jsxs("aside",{className:"xbg-red-100 flex grow flex-col justify-between",children:[e.jsxs("section",{className:"space-y-3 px-6 py-4",children:[e.jsx(he,{items:d,title:"Connection",value:n||"",onChange:I,isLoading:m,isError:j,connectionTooltip:(($=d==null?void 0:d.find(q=>q.id===n))==null?void 0:$.type)||""}),G(),V(),k(),F(),T()]}),B(),e.jsx("div",{className:"flex items-end justify-center gap-2 px-6 py-4",children:e.jsxs(s.Button,{onClick:J,size:"sm",variant:"secondary",className:"w-full",children:[e.jsx(hs,{className:"mr-2 size-4"}),"Help"]})})]})}function et(t){const n=t.toUpperCase().indexOf("WHERE"),a=t.toUpperCase().indexOf("GROUP BY"),r=t.toUpperCase().indexOf("LIMIT"),o=t.toUpperCase().indexOf("ORDER BY");let l=t.length;if(o!==-1&&(l=o),r!==-1&&r<l&&(l=r),n!==-1){const i=t.substring(0,n),d=t.substring(n);return`${i} {{ filters | where }} AND ${d.substring(6)}`}else if(a!==-1){const i=t.substring(0,a),d=t.substring(a);return`${i} {{ filters | where }} ${d}`}else{const i=t.substring(0,l),d=t.substring(l);return`${i} {{ filters | where }} ${d}`}}function st({error:t,setShowAIDialog:n,setUserInputforAI:a,setTriggerAIRun:r}){return e.jsxs(s.HoverCard,{openDelay:0,children:[e.jsx(s.HoverCardTrigger,{asChild:!0,children:e.jsx(s.Button,{variant:"link",className:"h-5 p-0",children:e.jsx(Ze,{className:"h-4 w-4 text-red-500"})})}),e.jsx(s.HoverCardContent,{align:"start",className:"min-w-fit max-w-[500px]",children:e.jsx("div",{className:"flex justify-between space-x-4",children:e.jsxs("div",{className:"flex grow flex-col space-y-2",children:[e.jsx(s.ScrollArea,{className:"max-h-[250px] min-h-0 overflow-scroll",children:e.jsx("p",{className:"overflow-auto rounded-md bg-muted p-2 text-xs leading-relaxed",children:t})}),e.jsxs(s.Button,{onClick:()=>{n(!0),a(t),r(!0)},size:"sm",variant:"outline",children:[e.jsx(os,{className:"mr-2 h-4 w-4"}),"Debug with AI"]})]})})})]})}function tt({text:t,onCheckedChange:n,checked:a}){return e.jsxs("div",{className:"xbg-red-100 ml-6 flex items-center gap-2",children:[e.jsx(s.Checkbox,{checked:a,onCheckedChange:n}),e.jsx("label",{className:"text-xs leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70",children:t})]})}function at(){const{authToken:t}=s.useSemaphorContext(),n=s.useEditorStore(l=>l.selectedConnectionId),{data:a}=s.useQuery({queryKey:["connections"],queryFn:()=>s.getRequest("https://semaphor.cloud/api/v1/connections",(t==null?void 0:t.accessToken)||""),enabled:!!(t!=null&&t.accessToken)}),r=a==null?void 0:a.connections.find(l=>l.id===n);return r==null?void 0:r.type}function nt(){const{authToken:t}=s.useSemaphorContext(),n=w.useRef(null),a=s.useEditorStore(c=>c.applyFilters),[r,o]=w.useState(""),l=s.useEditorStore(c=>c.filterValues),i=s.useEditorStore(c=>c.card.sql),d=at();return e.jsxs(s.HoverCard,{openDelay:0,onOpenChange:async c=>{if(!c)return;console.log("onOpenChange");const x=await s.postRequest("https://semaphor.cloud/api/v1/filter-sql",(t==null?void 0:t.accessToken)||"",{sql:i,active_filters:l,connection_type:d});console.log(x),x.sql?(console.log(x.records),o(x.sql)):o("Error")},children:[e.jsx(s.HoverCardTrigger,{asChild:!0,children:a&&e.jsx("p",{className:"p-0 text-xs hover:cursor-pointer",children:"|  Filter Query"})}),e.jsxs(s.HoverCardContent,{align:"end",className:"w-[600px]",children:[e.jsx("div",{className:"flex justify-between space-x-4",children:e.jsx("div",{className:"rounded-sm bg-muted p-2",children:e.jsxs("code",{ref:n,className:"font-mono text-sm",children:[r,e.jsx(s.ClipboardCopyIcon,{onClick:()=>s.copyToClipboard(n),className:"ml-3 inline-block h-4 w-4 opacity-70 hover:cursor-pointer hover:opacity-100"})]})})}),e.jsxs("div",{className:"flex items-center gap-2 pt-2",children:[e.jsx(s.InfoCircledIcon,{className:"h-4 w-4 opacity-70"}),e.jsx("span",{className:"text-xs text-muted-foreground",children:"A preview of the query with filters applied."})]})]})]})}const rt=`
192
192
 
193
193
  Use the following syntax to create a chart query. Please replace the x-axis, y-axis, stack-by, label, and measure with the actual column names of the table.
194
194
 
@@ -242,4 +242,4 @@ SELECT label, measure FROM table
242
242
  Table Columns: ${S==null?void 0:S.map(k=>`${k.column_name} | ${k.data_type}`).join(", ")}
243
243
  User SQL: ${A}
244
244
  ${f&&`Base Queries: ${JSON.stringify(f)} `}`,C=` When the user asks for a specific chart please use the following query structure to generate the chart query. Do not make up the column names. Use only the table columns provided above for the query. Replace x-axis, y-axis, and lables with the appropriate column names.
245
- Visual Query Syntax: ${rt}`,{data:E,isLoading:O,isFetching:h,isError:v,refetch:p}=s.useQuery({queryKey:["ai-query"],queryFn:()=>s.getRequest("https://semaphor.cloud/api/v1/ai",(c==null?void 0:c.accessToken)||"",{user_content:`userContent: ${M} ${x?C:""}`}),enabled:!1});function I(k){if(k.toLowerCase().includes("bar"))g("bar");else if(k.toLowerCase().includes("line"))g("line");else if(k.toLowerCase().includes("bubble"))g("bubble");else if(k.toLowerCase().includes("scatter"))g("scatter");else if(k.toLowerCase().includes("stacked"))g("stackedBar");else if(k.toLowerCase().includes("pie"))g("pie");else if(k.toLowerCase().includes("donut")||k.toLowerCase().includes("doughnut"))g("doughnut");else if(k.toLowerCase().includes("radar"))g("radar");else return g("bar"),!1;return!0}w.useEffect(()=>{E&&L(k=>[...k,{role:"ai",content:E.response}])},[E]),w.useEffect(()=>{const k=setTimeout(()=>{var V;d.current&&(d.current.scroll({top:d.current.scrollHeight,behavior:"smooth"}),(V=i.current)==null||V.focus())},100);return()=>clearTimeout(k)},[j]);function z(){a&&(L(k=>[...k,{role:"user",content:a}]),I(a)&&u(!0),r(""),p())}w.useEffect(()=>{o&&(z(),l(!1))},[o,l]);const R={fontFamily:"Arial, sans-serif",lineHeight:1.6,fontSize:15,width:"100%"},_={fontFamily:"monospace",fontSize:14,lineHeight:1.6},H={fontFamily:"Arial, sans-serif",lineHeight:1.6,fontSize:15,padding:"2px 0",marginLeft:20,listStyleType:"disc"},K={p:({node:k,...V})=>e.jsx("p",{style:R,...V}),code:({node:k,...V})=>e.jsx("code",{className:"rounded-sm bg-muted px-2 py-1 text-sm",...V}),pre:({node:k,...V})=>e.jsxs("pre",{className:"space-y-2 rounded-sm bg-muted/50 p-3",style:_,children:[e.jsx("code",{className:"whitespace-normal text-sm",children:V.children}),e.jsxs("div",{className:"flex justify-start gap-2",children:[e.jsx(s.Button,{onClick:B,size:"sm",variant:"outline",children:e.jsx(s.ClipboardCopyIcon,{})}),e.jsx(s.Button,{onClick:G=>{const F=B(G);F&&(n(!1),y(F),m(!0))},size:"sm",variant:"outline",children:e.jsx(s.PlayIcon,{})})]})]}),li:({node:k,...V})=>e.jsx("li",{style:H,...V})};function B(k){const V=k.currentTarget.closest("pre");if(!V)return;const G=V.textContent||V.innerText;return navigator.clipboard.writeText(G).then(()=>console.log("Text copied to clipboard")).catch(F=>console.error("Error in copying text: ",F)),G}function J(){return j==null?void 0:j.map((k,V)=>k.role==="user"?e.jsxs("div",{className:"flex items-start rounded-md bg-muted p-3 text-sm",children:[e.jsx(Ss,{className:"mr-2 h-5 w-5"}),e.jsx("div",{children:k.content})]},V):k.role==="ai"?e.jsx(s.Markdown,{className:"w-full overflow-auto py-1",components:K,children:E==null?void 0:E.response.replace(/DuckDB/gi,"Semaphor")},V):e.jsx("div",{},V))}return e.jsxs(s.Dialog,{open:t,onOpenChange:n,children:[e.jsx(s.DialogTrigger,{asChild:!0,children:e.jsx(s.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.jsxs(s.DialogContent,{className:"flex flex-col justify-between overflow-auto sm:max-w-[425px] md:max-h-[625px] md:min-w-[625px]",children:[e.jsxs(s.DialogHeader,{children:[e.jsx(s.DialogTitle,{children:"Assistant"}),e.jsx(s.DialogDescription,{children:"What can I help you with?"})]}),e.jsx("div",{ref:d,className:"h-[625px] w-full overflow-auto border-t border-t-muted",children:e.jsx("div",{className:"space-y-4 py-2 pr-3",role:"messages",children:J()})}),e.jsx("div",{children:e.jsxs("div",{className:"flex w-full items-center rounded-md border",children:[e.jsx(s.Textarea,{autoFocus:!0,ref:i,onKeyDown:k=>{k.key==="Enter"&&!k.shiftKey&&(k.preventDefault(),r(""),z())},placeholder:"Type your question here...",onFocus:k=>{const V=k.target,G=V.value.length;V.setSelectionRange(G,G)},className:s.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:O||h,value:a,onChange:k=>r(k.target.value)})," ",e.jsx(s.Button,{className:"h-8",size:"sm",variant:"ghost",onClick:z,children:!O&&!h?e.jsx(s.PaperPlaneIcon,{}):e.jsx(me,{className:"mr-2 h-4 w-4 animate-spin text-foreground/50"})})]})})]})]})}var Es={color:void 0,size:void 0,className:void 0,style:void 0,attr:void 0},Ue=w.createContext&&w.createContext(Es),it=["attr","size","title"];function lt(t,n){if(t==null)return{};var a=ct(t,n),r,o;if(Object.getOwnPropertySymbols){var l=Object.getOwnPropertySymbols(t);for(o=0;o<l.length;o++)r=l[o],!(n.indexOf(r)>=0)&&Object.prototype.propertyIsEnumerable.call(t,r)&&(a[r]=t[r])}return a}function ct(t,n){if(t==null)return{};var a={},r=Object.keys(t),o,l;for(l=0;l<r.length;l++)o=r[l],!(n.indexOf(o)>=0)&&(a[o]=t[o]);return a}function Ee(){return Ee=Object.assign?Object.assign.bind():function(t){for(var n=1;n<arguments.length;n++){var a=arguments[n];for(var r in a)Object.prototype.hasOwnProperty.call(a,r)&&(t[r]=a[r])}return t},Ee.apply(this,arguments)}function Je(t,n){var a=Object.keys(t);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(t);n&&(r=r.filter(function(o){return Object.getOwnPropertyDescriptor(t,o).enumerable})),a.push.apply(a,r)}return a}function ke(t){for(var n=1;n<arguments.length;n++){var a=arguments[n]!=null?arguments[n]:{};n%2?Je(Object(a),!0).forEach(function(r){dt(t,r,a[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(a)):Je(Object(a)).forEach(function(r){Object.defineProperty(t,r,Object.getOwnPropertyDescriptor(a,r))})}return t}function dt(t,n,a){return n=ut(n),n in t?Object.defineProperty(t,n,{value:a,enumerable:!0,configurable:!0,writable:!0}):t[n]=a,t}function ut(t){var n=ht(t,"string");return typeof n=="symbol"?n:String(n)}function ht(t,n){if(typeof t!="object"||t===null)return t;var a=t[Symbol.toPrimitive];if(a!==void 0){var r=a.call(t,n||"default");if(typeof r!="object")return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return(n==="string"?String:Number)(t)}function ks(t){return t&&t.map((n,a)=>w.createElement(n.tag,ke({key:a},n.attr),ks(n.child)))}function se(t){return n=>w.createElement(mt,Ee({attr:ke({},t.attr)},n),ks(t.child))}function mt(t){var n=a=>{var{attr:r,size:o,title:l}=t,i=lt(t,it),d=o||a.size||"1em",c;return a.className&&(c=a.className),t.className&&(c=(c?c+" ":"")+t.className),w.createElement("svg",Ee({stroke:"currentColor",fill:"currentColor",strokeWidth:"0"},a.attr,r,i,{className:c,style:ke(ke({color:t.color||a.color},a.style),t.style),height:d,width:d,xmlns:"http://www.w3.org/2000/svg"}),l&&w.createElement("title",null,l),t.children)};return Ue!==void 0?w.createElement(Ue.Consumer,null,a=>n(a)):n(Es)}function xt(t){return se({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:[]}]})(t)}function pt(){const[t,n]=w.useState({queryKey:[],queryData:null}),{theme:a}=s.useTheme(),r=s.useQueryClient(),o=w.useRef(),l=w.useRef(),[i,d]=w.useState(!1),[c,x]=w.useState(!1),[u,y]=w.useState(!1),[f,m]=w.useState(""),[g,j]=w.useState(!1),L=s.useDashboardStore(b=>b.selectedSheetId);s.useDashboardStore(b=>b.dashboard.baseQueries);const S=s.useEditorStore(b=>b.card),A=s.useDashboardStore(b=>b.theme),D=s.useEditorStore(b=>b.isShowingVisual);s.useDashboardStore(b=>b.onAcceptChanges);const M=s.useEditorStore(b=>b.selectedConnectionId),C=s.useEditorStore(b=>b.selectedDatabaseName),E=s.useEditorStore(b=>b.selectedDatamodelId),O=s.useEditorStore(b=>b.selectedSchemaName);s.useDashboardStore(b=>b.actions.updateFrameCard);const h=s.useEditorStore(b=>b.selectedTableName),v=s.useEditorStore(b=>b.card.sql),p=s.useEditorStore(b=>b.card.python),I=s.useEditorStore(b=>b.frame),z=s.useDashboardStore(b=>b.dashboard.filters),R=s.useDashboardStore(b=>b.filterValues),_=z==null?void 0:z.filter(b=>b.sheetId===L||!b.sheetId),H=R==null?void 0:R.filter(b=>(_==null?void 0:_.some(U=>U.id===b.filterId))||b.filterId.endsWith(L)),K=s.useEditorStore(b=>b.applyFilters),{setCardCustomCfg:B,setQueryResultColumns:J,setFilterValues:k,setCardSql:V,setCard:G,setCardPython:F,setQueryError:T,setPythonStdOut:$,setCardPreferences:q}=s.useEditorStore(b=>b.actions),P=s.useEditorStore(b=>b.onSave),W=s.useEditorStore(b=>b.actions.setApplyFilters),te=s.useEditorStore(b=>b.onClose),ce=s.useEditorStore(b=>b.actions.setSqlGen),ae=s.useEditorStore(b=>b.runSql),re=s.useEditorStore(b=>b.actions.setRunSql);s.useEditorStore(b=>b.actions.setCardCfg);const ne=s.useEditorStore(b=>b.actions.setIsSqlRunning),{data:Q,isLoading:X,isFetching:Z,isSuccess:ye,isError:de,error:pe,queryKey:fe,refetch:ue}=s.useDashboardCardQuery(S);w.useEffect(()=>{if(Q&&(Q.rowLimitExceeded&&s.Jt.error("Row limit (10,000) exceeded. Refine your query.",{position:"top-center",richColors:!0}),$((Q==null?void 0:Q.output)||""),Q.records.length>0)){const{dimensionKeys:b}=s.getKeys(Q.records);J(b)}},[Q,J,$]),w.useEffect(()=>{(X||Z)&&ne(!0),(de||ye)&&ne(!1),de?(T(pe.message),J([]),$("")):T("")},[X,Z,Q,$,de,ye,ne,J,T,pe]),w.useEffect(()=>{ae&&(ue(),re(!1))},[ae,ue,re]);function Ae(){const b=r.getQueryData(fe);t.queryData||n({queryKey:fe,queryData:b}),r.setQueryData(fe,null),V(""),ce({}),B(""),q({})}const ge=b=>{l.current=b};function ve(b,U){if(b.length===0)return"";if(U){const oe=b.find(Y=>Y.id===U);if(oe){const Y=oe.tabTitle;if(Y=="All__Header")return b[0].id;if(Y&&Y.endsWith("__Header")){const Ps=Y.split("__")[0],$e=b.find(Gs=>Gs.tabTitle===Ps);return $e?$e.id:b[0].id}return U}}return b[0].id}function Se(){let b=v;v&&!v.includes("{{")&&(b=et(v),V(b));const U={...S,lastSelectedSchema:O,lastSelectedDatamodelId:E,lastSelectedDatabase:C,lastSelectedTable:h,connectionId:M,type:D?S.type:"table",sql:b,customCfg:D?S.customCfg:null},oe=I.cards.map(Oe=>Oe.id===S.id?U:Oe),Y={...I,cards:oe,activeCardId:ve(oe,I.activeCardId)};P==null||P(Y)}function Ce(){const{queryKey:b,queryData:U}=t;b&&U&&r.setQueryData(b,U),te==null||te()}w.useEffect(()=>{const b=o.current,U=l.current;if(b){const oe=window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light",Y=A==="system"?oe:A;b.editor.defineTheme("default",{base:Y==="light"?"vs":"vs-dark",inherit:!0,rules:[],colors:{"editor.background":Y==="light"?"#ffffff":s.getCssVariableValue("--semaphor-background")}}),b.editor.setTheme("default")}return U&&b&&U.addCommand(b.KeyMod.Shift|b.KeyCode.Enter,function(){return console.log("Executing query..."),ue(),!1}),()=>{}},[a,A,o.current]);function je(b){o.current=b}function N(){return e.jsxs(e.Fragment,{children:[c&&e.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.jsxs("div",{className:"w-[99%]",children:[e.jsxs("div",{className:"flex items-center gap-2 pt-3",children:[e.jsx(tt,{checked:K,onCheckedChange:()=>W(!K),text:"Apply Filters"}),e.jsx(nt,{}),H&&c&&e.jsx(s.Cross2Icon,{onClick:()=>x(!1),className:"bg-background/50 text-foreground/50 hover:cursor-pointer hover:text-foreground"})]}),e.jsx(s.Ft,{theme:"default",onChange:b=>{if(b)try{JSON.parse(b),k(JSON.parse(b))}catch{}},defaultLanguage:"json",className:"mt-1 min-h-[220px]",value:JSON.stringify(H,null,2),options:{readOnly:!0,minimap:{enabled:!1},lineNumbers:"off",glyphMargin:!1,wordWrap:"on",scrollbar:{verticalScrollbarSize:0,horizontalScrollbarSize:0},fontSize:12,renderLineHighlight:"none"}})]})}),H&&!c&&e.jsx(s.Filter,{onClick:()=>x(!0),className:s.cn("absolute bottom-4 right-6 h-3 w-3 text-foreground/50 hover:cursor-pointer hover:text-foreground",{"font-bold text-red-800":K})})]})}function Hs(){return e.jsxs(s.ResizablePanelGroup,{className:"flex grow pb-1",direction:"vertical",role:"editor-resizable-group",children:[e.jsxs(s.ResizablePanel,{id:"1",order:1,defaultSize:i?20:100,className:"relative flex grow",children:[e.jsx("div",{role:"sql-container",className:"relative flex w-[99%]",children:e.jsx(s.Ft,{theme:"default",className:"pt-3",onChange:b=>{V(b)},value:v,options:{minimap:{enabled:!1},wordWrap:"on",scrollbar:{verticalScrollbarSize:0,horizontalScrollbarSize:0},fontSize:14,renderLineHighlight:"none"},defaultLanguage:"sql",beforeMount:je,onMount:ge})}),i&&e.jsx("code",{className:"absolute right-6 top-3 text-sm text-muted-foreground/70",children:"sql"})]}),i&&e.jsxs(e.Fragment,{children:[e.jsx(s.ResizableHandle,{withHandle:!0,className:"border"}),e.jsxs(s.ResizablePanel,{id:"2",order:2,defaultSize:80,className:"relative flex grow",children:[e.jsx("div",{role:"python-container",className:"relative flex w-[99%] pt-0",children:e.jsx(s.Ft,{className:"pt-3",theme:"default",onChange:b=>{F(b&&b.trim()||"")},value:p||s.PYTHON_DEFAULT_CODE,options:{minimap:{enabled:!1},wordWrap:"on",scrollbar:{verticalScrollbarSize:0,horizontalScrollbarSize:0},fontSize:14,renderLineHighlight:"none"},defaultLanguage:"python",beforeMount:je,onMount:ge})}),e.jsx("code",{className:"absolute right-6 top-3 text-sm text-muted-foreground/70",children:"python"})]})]})]})}return e.jsxs("section",{role:"editor-section",className:"flex grow flex-col justify-end",children:[e.jsxs("div",{role:"sql-editor",className:"relative flex grow justify-between overflow-y-scroll",children:[Hs(),N()]}),e.jsxs("div",{role:"editor-controls",className:"item-center flex flex-wrap justify-between gap-2 px-6 py-4",children:[e.jsxs("div",{className:"flex grow items-center gap-2",children:[e.jsxs(s.Button,{title:"Shift + Enter",disabled:X||Z,onClick:()=>{ue()},className:"shrink-0",size:"sm",variant:"outline",children:[X||Z?e.jsx(me,{className:"mr-2 h-4 w-4 animate-spin text-foreground/50"}):e.jsx(xs,{className:"mr-2 h-4 w-4"}),"Run"]}),de&&e.jsx(st,{error:pe.message,setShowAIDialog:y,setTriggerAIRun:j,setUserInputforAI:m}),e.jsxs(s.Button,{onClick:Ae,className:"",size:"sm",variant:"outline",children:[e.jsx(ts,{className:"mr-2 size-4"}),"Clear"]}),e.jsx(s.Toggle,{pressed:i,onPressedChange:b=>d(b),className:"",size:"sm",variant:"outline",children:e.jsx(xt,{className:"size-4 text-foreground/70"})}),e.jsx(ot,{open:u,setOpen:y,userInput:f,triggerAIRun:g,setTriggerAIRun:j,setUserInput:b=>m(b)})]}),e.jsxs("div",{className:"flex items-end gap-2",children:[e.jsxs(s.Button,{onClick:Se,size:"sm",variant:"outline",children:[e.jsx(s.Check,{className:"mr-2 size-4 font-bold text-green-600"}),"Accept"]}),e.jsxs(s.Button,{onClick:Ce,className:"w-full",size:"sm",variant:"outline",children:[e.jsx(s.Cross2Icon,{className:"mr-2 size-4"}),"Close"]})]})]})]})}function ft({data:t}){var i;const[n,a]=w.useState([]),o=Object.keys(t[0]).map(d=>({accessorKey:d,header:({column:c})=>{const x=c.getIsSorted();return e.jsx("div",{className:"flex gap-2",children:e.jsxs("div",{className:"flex cursor-pointer items-center",onClick:()=>c.toggleSorting(c.getIsSorted()==="asc"),children:[d,x==="asc"?e.jsx(s.TriangleUpIcon,{className:"ml-2 h-5 w-5"}):x==="desc"?e.jsx(s.TriangleDownIcon,{className:"ml-2 h-5 w-5"}):null]})})}})),l=s.useReactTable({data:t,columns:o,getCoreRowModel:s.getCoreRowModel(),getPaginationRowModel:s.getPaginationRowModel(),onSortingChange:a,getSortedRowModel:s.getSortedRowModel(),manualPagination:!0,state:{sorting:n}});return e.jsxs(s.Table$1,{children:[e.jsx(s.TableHeader,{children:l.getHeaderGroups().map(d=>e.jsx(s.TableRow,{children:d.headers.map(c=>e.jsx(s.TableHead,{className:"sticky top-0 bg-muted",children:c.isPlaceholder?null:s.flexRender(c.column.columnDef.header,c.getContext())},c.id))},d.id))}),e.jsx(s.TableBody,{children:(i=l.getRowModel().rows)!=null&&i.length?l.getRowModel().rows.map(d=>e.jsx(s.TableRow,{className:"whitespace-nowrap py-2","data-state":d.getIsSelected()&&"selected",children:d.getVisibleCells().map(c=>e.jsx(s.TableCell,{children:s.flexRender(c.column.columnDef.cell,c.getContext())},c.id))},d.id)):e.jsx(s.TableRow,{children:e.jsx(s.TableCell,{colSpan:o.length,className:"h-24 text-center",children:"No results."})})})]})}function gt({card:t}){var f,m,g,j,L,S,A,D,M,C;const{authToken:n}=s.useSemaphorContext(),a=s.getTokenParams(n==null?void 0:n.accessToken),r=s.useDashboardStore(E=>E.themeStyle),o={colors:((m=(f=r==null?void 0:r.chart)==null?void 0:f.dataset)==null?void 0:m.backgroundColor)||[]};(g=t.customCardPreferences)!=null&&g.inputData;const{getCard:l}=s.useCustomVisual(((j=t.customCardPreferences)==null?void 0:j.url)||""),i=((L=t.customCardPreferences)==null?void 0:L.visualType)||"single",d=s.useEditorStore(E=>E.frame);s.useEditorActions();const{data:c}=s.useDashboardCardQuery(t);if(!((S=t.customCardPreferences)!=null&&S.componentName))return null;const x=l((A=t.customCardPreferences)==null?void 0:A.componentName),u=E=>{console.log("data",E),t.customCardPreferences},y=Object.keys(((D=t.customCardPreferences)==null?void 0:D.dataInputCardIds)||{}).map(E=>{var v,p,I;const O=(p=(v=t.customCardPreferences)==null?void 0:v.dataInputCardIds)==null?void 0:p[E].cardId,h=(I=d==null?void 0:d.cards)==null?void 0:I.find(z=>z.id===O);return h||null});return e.jsx("div",{className:"semaphor-custom mb-3 flex grow basis-0 flex-col space-y-2 overflow-y-auto",children:e.jsxs(w.Suspense,{fallback:e.jsx(e.Fragment,{}),children:[x&&i==="single"&&e.jsx(x,{params:a,theme:o,settings:(M=t.customCardPreferences)==null?void 0:M.settings,onDataChange:u,data:(c==null?void 0:c.records)||[]}),x&&i==="multiple"&&e.jsx("div",{className:"flex flex-col gap-2",children:e.jsx(x,{theme:o,onDataChange:u,settings:y.map(E=>{var O;return(O=E==null?void 0:E.customCardPreferences)==null?void 0:O.settings}),data:y.map(E=>(E==null?void 0:E.data)||[])})})]},(C=t.customCardPreferences)==null?void 0:C.componentName)})}function Is({className:t,...n}){var m,g;const a=s.useEditorStore(j=>j.card),r=((m=a.customCardPreferences)==null?void 0:m.showCardHeader)??!0,o=s.useEditorStore(j=>j.frame),l=s.useDashboardStore(j=>j.dashboard.filters);s.useEditorStore(j=>j.actions.setRunSql);const{updateFilter:i}=s.useDashboardActions(),d=l==null?void 0:l.find(j=>j.id===o.filterId),{data:c}=s.useDashboardCardQuery(a),{setCard:x}=s.useEditorActions(),{data:u}=s.useTopoJson(a);if(!a.id)return null;let y;c!=null&&c.records&&(c==null?void 0:c.records.length)>0&&(y=s.createChartConfig({data:c==null?void 0:c.records,cardType:a.type,cfg:a.cfg,customCfg:a.customCfg,preferences:a.preferences,topoJson:u}));function f(j){return e.jsx(gt,{card:j})}return e.jsxs(s.Card,{role:"editor-visual-card",className:s.cn("relative flex h-full flex-col rounded-none",t),...n,children:[r&&e.jsxs(s.CardHeader,{className:"flex flex-row items-start justify-between py-4",children:[e.jsxs("div",{children:[e.jsx(s.Editable,{text:a.title,onSave:j=>x({...a,title:j}),children:e.jsx("div",{className:"flex items-center gap-5",children:e.jsx(s.CardTitle,{className:"text-base",children:a.title||"Edit title..."})})},a.title),e.jsx(s.Editable,{text:a.description||"",onSave:j=>x({...a,description:j}),children:e.jsx(s.CardDescription,{children:a.description||"Edit description..."})},a.description)]}),d&&e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(s.Editable,{className:"my-1",text:d.title||d.column,onSave:j=>i({...d,title:j}),children:e.jsx(s.Label,{children:d.title})}),s.getFilterComponent(d)]})]}),e.jsxs(s.CardContent,{className:"flex grow flex-col",children:[a.type==="custom"&&f(a),!["table","custom"].includes(a.type)&&y&&e.jsx(s.ChartJsVisual,{cfg:y},JSON.stringify(y)+JSON.stringify(a.preferences)+((g=a==null?void 0:a.preferences)==null?void 0:g.customVisualCode)),a.type==="table"&&(c==null?void 0:c.records)&&(c==null?void 0:c.records.length)>0&&e.jsx(s.ScrollArea$1,{className:"flex min-h-0 flex-1 grow basis-0",children:e.jsx(s.TableVisual,{card:a,data:c==null?void 0:c.records})})]})]})}function jt(){const[t,n]=w.useState(!1),[a,r]=w.useState(""),[o,l]=w.useState(""),[i,d]=w.useState(""),[c,x]=w.useState(""),u=s.useEditorStore(C=>C.card),y=s.useEditorStore(C=>C.card.customCfg),{data:f}=s.useDashboardCardQuery(u),{data:m}=s.useTopoJson(u),{setCardCustomCfg:g,setCustomVisualCode:j}=s.useEditorActions();function L(C){var h,v;const E={...C,data:{...C==null?void 0:C.data,datasets:(v=(h=C==null?void 0:C.data)==null?void 0:h.datasets)==null?void 0:v.map(p=>({...p,data:[]}))}};return JSON.stringify(E,null,1)}function S(){var E,O;if(!(f!=null&&f.records)||(f==null?void 0:f.records.length)===0)return;const C=s.createChartConfig({data:f==null?void 0:f.records,cardType:u.type,cfg:u.cfg,preferences:u.preferences,topoJson:m});C&&(r(JSON.stringify(C,null,1)),(E=u==null?void 0:u.preferences)!=null&&E.customVisualCode&&d((O=u==null?void 0:u.preferences)==null?void 0:O.customVisualCode),y&&l(JSON.stringify(y,null,1)))}function A(){if(i&&j(i),!!o)try{const C=JSON.parse(o);return C?(g(C),x(""),l(""),C):void 0}catch(C){console.log(C),x("Invalid JSON")}}function D(){l(""),g(null)}function M(){let C;if(y){const E=s._.cloneDeep(u.cfg),O=s._.merge(E,y);return C=L(O),C}return a?(C=L(JSON.parse(a)),C):""}return e.jsxs(s.Dialog,{open:t,onOpenChange:n,children:[e.jsx(s.DialogTrigger,{asChild:!0,children:e.jsx(s.Button,{onClick:S,className:` ${y&&"border-foreground/50 dark:border-foreground/70"}`,size:"sm",variant:"outline",children:e.jsx(s.Settings,{className:"h-4 w-4"})})}),e.jsxs(s.DialogContent,{className:"max-h-[70vh] min-h-[70vh] overflow-auto sm:min-w-[900px] lg:min-w-[1200px]",children:[e.jsxs(s.DialogHeader,{className:"",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(s.DialogTitle,{children:"Customize Card"}),e.jsxs(s.Tooltip,{children:[e.jsx(s.TooltipTrigger,{children:e.jsx(qe,{onClick:()=>{navigator.clipboard.writeText(u.id)},className:"size-3 cursor-pointer text-muted-foreground/70 transition-colors hover:text-muted-foreground"})}),e.jsx(s.TooltipContent,{side:"right",align:"center",children:e.jsx("p",{className:"text-xs",children:"Copy Card ID"})})]})]}),e.jsxs(s.DialogDescription,{children:["See the configuration options and documentation",e.jsx("a",{target:"_blank",className:"ml-1 text-blue-500 underline",href:"https://www.chartjs.org/docs/latest/samples/bar/vertical.html",children:"here."})]})]}),e.jsxs("div",{className:"flex grow gap-2",children:[e.jsx(s.ErrorBoundary,{FallbackComponent:s.FallbackEditorCard,children:e.jsx(Is,{className:"w-1/2 rounded shadow-none"})}),e.jsxs(s.Tabs,{defaultValue:"custom-config",className:"flex w-1/2 flex-col",children:[e.jsxs(s.TabsList,{className:"justify-start rounded-sm rounded-b-none border border-b-0",children:[e.jsxs(s.TabsTrigger,{value:"custom-config",children:[y&&e.jsx(s.CheckIcon,{className:"mr-1 h-5 w-5 text-green-600"}),y?"Custom Config":"Default Config"]}),e.jsx(s.TabsTrigger,{className:"",value:"output",children:"Output"}),e.jsx(s.TabsTrigger,{className:"",value:"custom-code",children:"Custom Code"})]}),e.jsx(s.TabsContent,{className:"bg-red-x mt-0 grow rounded-b border border-t-0 p-2",value:"output",children:e.jsx(s.Textarea,{disabled:!0,value:a,className:"h-full resize-none border-none font-mono focus-visible:ring-0 focus-visible:ring-offset-0"})}),e.jsx(s.TabsContent,{className:"mt-0 grow rounded-b border border-t-0",value:"custom-config",children:e.jsx(s.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:M(),onChange:C=>l(C)})}),e.jsx(s.TabsContent,{className:"mt-0 grow rounded-b border border-t-0",value:"custom-code",children:e.jsx(s.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:C=>d(C||"")})})]})]}),e.jsxs(s.DialogFooter,{className:"flex items-center",children:[e.jsx(s.Label,{className:"mr-2 text-red-500",children:c}),e.jsx(s.Button,{disabled:!y,onClick:D,variant:"outline",children:"Reset"}),e.jsx(s.Button,{onClick:A,variant:"outline",children:"Apply"}),e.jsx(s.Button,{onClick:()=>n(!1),variant:"outline",children:"Close"})]})]})]})}function Ds(t){return se({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:[]}]})(t)}function Ls(t){return se({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:[]}]})(t)}function Ts(t){return se({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:[]}]})(t)}function As(t){return se({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:[]}]})(t)}function Os(t){return se({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:[]}]})(t)}function zs(t){return se({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:[]}]})(t)}function Fs(t){return se({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:[]}]})(t)}function Ms(t){return se({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:[]}]})(t)}function Vs(t){const[n,a]=w.useState(null);return w.useEffect(()=>{t&&(async()=>{const l=(await Promise.resolve().then(()=>require("./lucide-react-3gFVi9lq.js")))[t];a(l)})()},[t]),n}function Rs(){const{authToken:t}=s.useSemaphorContext(),{data:n,isLoading:a,isFetching:r,isError:o}=s.useQuery({queryKey:["plugins",t==null?void 0:t.accessToken],queryFn:()=>s.getPlugins(t==null?void 0:t.accessToken)});return{data:n,isLoading:a,isFetching:r,isError:o}}function bt({onChartTypeChange:t}){const[n,a]=w.useState([]),{data:r}=Rs();return w.useEffect(()=>{(async()=>{var l;if(r){const d=(await Promise.all((l=r==null?void 0:r.plugins)==null?void 0:l.map(async c=>(await s.loadManifest(c.value)).visuals.map(y=>({name:y.name,icon:y.icon,url:c.value}))))).flat();a(d)}})()},[r]),n.length===0?null:e.jsxs(e.Fragment,{children:[e.jsx(s.Separator,{className:"my-2"}),e.jsx("div",{className:"grid grid-cols-4 place-items-center",children:n.map((o,l)=>e.jsx(yt,{text:o.name,onClick:()=>t("custom",o),icon:o.icon},o.url+o.name+l))})]})}const yt=({text:t,icon:n,onClick:a})=>{const r=Vs(n||""),o=t.charAt(0).toUpperCase();return e.jsx(s.Button,{onClick:a,title:t,variant:"ghost",children:r?e.jsx(r,{className:"h-4 w-4"}):o})};function vt(){var u,y;const[t,n]=w.useState(!1),a=s.useEditorStore(f=>f.card),r=a.type,{setCardType:o,setCardPreferences:l,setChartOrientation:i}=s.useEditorStore(f=>f.actions),{setCardCustomCfg:d,setCustomCardPreferences:c}=s.useEditorActions();function x(f,m){d(null),l({}),o(f),m&&c({type:"component",visualType:"single",url:m.url,componentName:m.name,icon:m.icon}),n(!1)}return e.jsxs(s.Popover,{open:t,onOpenChange:n,children:[e.jsx(s.PopoverTrigger,{asChild:!0,children:e.jsx(s.Button,{size:"sm",variant:"outline",children:e.jsx(St,{className:"h-4 w-4",chartType:r,customIcon:(u=a.customCardPreferences)==null?void 0:u.icon,componentName:(y=a.customCardPreferences)==null?void 0:y.componentName})})}),e.jsxs(s.PopoverContent,{className:"w-50",children:[e.jsxs("div",{className:"grid grid-cols-4 place-items-center",children:[e.jsx(s.Button,{onClick:()=>x("bar"),className:"font-normal",variant:"ghost",children:e.jsx(Ie,{className:"size-5"})}),e.jsx(s.Button,{onClick:()=>x("line"),variant:"ghost",children:e.jsx(De,{className:"size-5"})}),e.jsx(s.Button,{onClick:()=>x("stackedBar"),variant:"ghost",children:e.jsx(zs,{className:"size-5",strokeWidth:0})}),e.jsx(s.Button,{onClick:()=>x("stackedLine"),variant:"ghost",children:e.jsx(Os,{className:"size-5",strokeWidth:0})}),e.jsx(s.Button,{onClick:()=>x("scatter"),variant:"ghost",children:e.jsx(Ve,{className:"size-5"})}),e.jsx(s.Button,{onClick:()=>x("bubble"),variant:"ghost",children:e.jsx(As,{className:"size-4"})}),e.jsx(s.Button,{onClick:()=>x("pie"),variant:"ghost",children:e.jsx(Me,{className:"size-5"})}),e.jsx(s.Button,{onClick:()=>x("doughnut"),variant:"ghost",children:e.jsx(Ls,{className:"size-5",strokeWidth:1})}),e.jsx(s.Button,{onClick:()=>x("radar"),variant:"ghost",children:e.jsx(Ds,{className:"size-5 font-extralight",strokeWidth:.5})}),e.jsx(s.Button,{onClick:()=>x("polarArea"),variant:"ghost",children:e.jsx(Ts,{className:"size-5"})}),e.jsx(s.Button,{onClick:()=>x("pyramid"),variant:"ghost",children:e.jsx(Ms,{className:"size-5"})}),e.jsx(s.Button,{onClick:()=>x("range"),variant:"ghost",children:e.jsx(Fe,{className:"size-5"})}),e.jsx(s.Button,{onClick:()=>x("table"),variant:"ghost",children:e.jsx(s.Table,{className:"size-5"})}),e.jsx(s.Button,{onClick:()=>x("kpi"),variant:"ghost",children:e.jsx(Fs,{className:"size-6"})}),e.jsx(s.Button,{onClick:()=>x("text"),variant:"ghost",children:e.jsx(Le,{className:"size-4"})}),e.jsx(s.Button,{onClick:()=>x("map"),variant:"ghost",children:e.jsx(_e,{className:"size-4"})}),e.jsx(s.Button,{onClick:()=>x("custom"),variant:"ghost",children:e.jsx(He,{className:"size-4"})})]}),e.jsx(bt,{onChartTypeChange:x})]})]})}function St({chartType:t,className:n,customIcon:a,componentName:r}){const o=Vs(a||"");switch(t){case"bar":return e.jsx(Ie,{className:n});case"line":return e.jsx(De,{className:n});case"pie":return e.jsx(Me,{className:n});case"radar":return e.jsx(Ds,{className:n});case"scatter":return e.jsx(Ve,{className:n});case"bubble":return e.jsx(As,{className:n});case"doughnut":return e.jsx(Ls,{className:n});case"stackedBar":return e.jsx(zs,{className:"size-4 text-foreground/70"});case"stackedLine":return e.jsx(Os,{className:"size-4 text-foreground/70"});case"polarArea":return e.jsx(Ts,{className:n});case"pyramid":return e.jsx(Ms,{className:n});case"range":return e.jsx(Fe,{className:n});case"kpi":return e.jsx(Fs,{className:n});case"text":return e.jsx(Le,{className:n});case"map":return e.jsx(_e,{className:n});case"custom":return a&&o?e.jsx(o,{className:n}):r?r==null?void 0:r.charAt(0).toUpperCase():e.jsx(He,{className:n});default:return e.jsx(s.Table,{className:n})}}function Ct(){var o;const t=s.useEditorStore(l=>l.card),n=((o=t.customCardPreferences)==null?void 0:o.showCardHeader)??!0,{setCustomCardPreferences:a}=s.useEditorActions(),r=l=>{t.customCardPreferences&&a({...t.customCardPreferences,showCardHeader:l===!0})};return e.jsxs(s.DropdownMenu,{children:[e.jsx(s.DropdownMenuTrigger,{asChild:!0,children:e.jsx(Re,{className:"size-4 cursor-pointer text-muted-foreground/70 transition-colors hover:text-muted-foreground"})}),e.jsxs(s.DropdownMenuContent,{align:"start",className:"w-40 text-muted-foreground",children:[e.jsx(s.DropdownMenuCheckboxItem,{checked:n,onCheckedChange:r,children:"Card Header"}),e.jsxs(s.DropdownMenuItem,{onClick:()=>{navigator.clipboard.writeText(t.id),s.Jt.success("Card ID copied to clipboard")},className:"cursor-pointer space-x-2",children:[e.jsx(qe,{className:"size-4"}),e.jsx("span",{children:"Copy Card ID"})]})]})]})}function Ke(){const t=s.useEditorStore(h=>h.frame),n=s.useEditorStore(h=>h.card),a=s.useEditorStore(h=>h.isShowingVisual),r=s.useEditorStore(h=>h.isSqlRunning),o=s.useEditorStore(h=>h.queryError),l=s.useEditorStore(h=>h.pythonStdOut),i=s.useEditorStore(h=>h.actions.setRunSql);s.useEditorStore(h=>h.onSave),s.useEditorStore(h=>h.onClose),s.useEditorStore(h=>h.actions.setCardSql),s.useEditorStore(h=>h.actions.setCardType),s.useEditorStore(h=>h.actions.setSqlGen);const{setFrame:d,setCard:c,updateCardInFrame:x}=s.useEditorActions(),{data:u,isLoading:y,isFetching:f}=s.useDashboardCardQuery(n);if(!n)return e.jsx(e.Fragment,{children:"No Active Card"});function m(){const h={connectionId:n.connectionId,id:s.v4(),title:"Title",description:"Description",preferences:{onClickFilter:[{columnIndex:0,expression:""}]},type:"bar",sql:"",data:[]};g(h)}function g(h){const v={...t,cards:[...t.cards,h],activeCardId:h.id};d(v),c(h)}function j(){const h={...n,id:s.v4(),title:`${n.title} Copy`,tabTitle:`${n.tabTitle} Copy`};g(h)}function L(h){const v=t.cards.filter(z=>z.id!==h),p=v[0],I={...t,cards:v,activeCardId:p.id};d(I),c(p)}function S(h){const v={...t,cards:t.cards.map(I=>I.id===n.id?n:I),activeCardId:h};d(v);const p=v.cards.find(I=>I.id===h);p.sql&&i(!0),c(p)}const A=(h,v)=>{console.log("handleDragStart",v),h.dataTransfer.setData("tabIndex",v.toString())},D=h=>{h.preventDefault()},M=(h,v)=>{const p=h.dataTransfer.getData("tabIndex");if(p===v.toString())return;const I=Array.from(t.cards),[z]=I.splice(parseInt(p),1);I.splice(v,0,z),d({...t,cards:I})};function C(h,v){return h.cards.length===1&&(v.displayTab===!0||v.displayTab===void 0)||h.activeCardId!==v.id&&(v.displayTab===!0||v.displayTab===void 0)?null:e.jsx("div",{onClick:()=>{const p=v.displayTab===void 0?!1:!v.displayTab;c({...v,displayTab:p}),x({...v,displayTab:p})},children:v.displayTab===!0||v.displayTab===void 0?e.jsx(ns,{className:"mr-2 size-3.5 text-muted-foreground hover:text-foreground"}):e.jsx(as,{className:"mr-2 size-3.5 text-muted-foreground hover:text-foreground"})})}function E(){return e.jsxs(s.Tabs,{onValueChange:S,value:t.activeCardId,className:"flex grow flex-col",children:[t.cards.map(h=>e.jsx(s.TabsContent,{className:"mt-0 grow",value:h.id,children:O()},h.id)),e.jsx(s.TabsList,{className:"group mx-6 justify-between",children:e.jsxs("div",{className:"flex items-center",children:[t.cards.map((h,v)=>e.jsx(s.Editable,{text:h.tabTitle||h.title,onSave:p=>{c({...n,tabTitle:p}),x({...n,tabTitle:p})},children:e.jsxs(s.TabsTrigger,{draggable:!0,onDragStart:p=>A(p,v),onDragOver:D,onDrop:p=>M(p,v),className:"",value:h.id,children:[C(t,h),h.tabTitle||h.title,t.activeCardId===h.id&&t.cards.length>1&&e.jsx(s.X,{className:"ml-2 size-3.5 text-muted-foreground hover:text-foreground",onClick:()=>L(h.id)})]})},h.id)),e.jsx(s.Button,{className:"ml-1 h-8 px-2 hover:bg-muted-foreground/50",variant:"outline",onClick:m,children:e.jsx(s.Plus,{className:"h-4 w-4"})}),e.jsx(s.Button,{className:"invisible ml-1 h-8 px-2 hover:bg-muted-foreground/50 group-hover:visible",variant:"outline",onClick:j,children:e.jsx(es,{className:"h-4 w-4"})})]})})]})}function O(){return n.type==="kpi"?e.jsx("div",{className:"flex h-full items-center justify-center",children:e.jsx("div",{className:"w-1/2 rounded-md border",children:e.jsx(s.KPICard,{card:n,data:u==null?void 0:u.records})})}):n.type==="text"?e.jsx("div",{className:"flex h-full items-center justify-center",children:e.jsx("div",{className:"w-1/2 rounded-md border",children:e.jsx(s.ScrollArea,{className:"mx-3 my-6 h-[300px] overflow-y-auto break-words px-3",children:e.jsx(s.TextCard,{isLoading:r,card:n,data:u==null?void 0:u.records})})})}):e.jsx(s.ErrorBoundary,{FallbackComponent:s.FallbackEditorCard,children:e.jsx(Is,{className:"grow border-none shadow-none"})})}return e.jsxs("div",{className:"relative flex h-full flex-col py-3",children:[(y||f)&&e.jsx(me,{className:"absolute bottom-0 left-0 right-0 top-0 z-50 m-auto h-10 w-10 animate-spin text-foreground/10"}),e.jsxs("div",{className:"mb-0 flex min-h-10 items-center justify-end gap-2 px-6",children:[a&&e.jsxs("div",{className:"flex grow items-center gap-2",children:[e.jsx(vt,{}),!["table","custom"].includes(n.type)&&e.jsx(jt,{}),e.jsx(Ct,{})]}),e.jsx(wt,{})]}),a?E():e.jsxs("div",{className:"flex min-h-0 w-full flex-1 grow basis-0 px-6",children:[l&&e.jsx(Nt,{}),(u==null?void 0:u.records)&&(u==null?void 0:u.records.length)>0&&e.jsx(ft,{data:(u==null?void 0:u.records)||[]}),o&&e.jsx("span",{className:"font-mono text-sm",children:o})]})]})}function Nt(){const t=s.useEditorStore(a=>a.pythonStdOut);if(!t)return null;const n=t.replace(/\n/g,"<br>");return e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"font-mono text-sm",children:"Output:"}),e.jsx("div",{dangerouslySetInnerHTML:{__html:n},className:"bg-muted p-2 font-mono text-sm"}),e.jsx(s.Separator,{className:"mb-2"})]})}function wt(){const t=s.useEditorStore(a=>a.isShowingVisual),n=s.useEditorStore(a=>a.actions.setIsShowingVisual);return e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(s.Label,{htmlFor:"visualize",children:"Chart"}),e.jsx(s.Switch,{checked:t,onCheckedChange:()=>n(!t),id:"visualize",className:"data-[state=checked]:bg-foreground/50"})]})}function Et({options:t,value:n,onValueChange:a}){return e.jsx(s.RadioGroup,{value:n,onValueChange:a,className:"flex gap-4",defaultValue:t[0].value,children:t.map(r=>e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(s.RadioGroupItem,{value:r.value,id:r.value}),e.jsx("label",{className:"text-sm",htmlFor:r.value,children:r.label})]},r.value))})}function ee({label:t,options:n,value:a,onValueChange:r,className:o}){return e.jsxs(s.Select,{value:a,onValueChange:r,children:[e.jsx(s.SelectTrigger,{className:s.cn("w-full focus:ring-0 focus:ring-offset-0",o),children:e.jsx(s.SelectValue,{placeholder:t})}),e.jsx(s.SelectContent,{children:e.jsxs(s.SelectGroup,{children:[e.jsx(s.SelectLabel,{children:t}),n.map(l=>e.jsx(s.SelectItem,{value:l.value,children:l.label},l.value))]})})]})}function be({children:t,summary:n,open:a,className:r}){return e.jsxs("details",{open:a,className:s.cn("space-y-4 [&_summary>svg]:open:-rotate-180",r),children:[e.jsxs("summary",{className:"flex cursor-pointer list-none items-center justify-between gap-4",children:[e.jsx(s.Label,{children:n}),e.jsx(s.ChevronUp,{className:"h-4 w-4"})]}),e.jsx("div",{className:"transition-all ease-in-out",children:t})]})}function kt(){var j,L;const t=s.useEditorStore(S=>S.card.customCardPreferences),{data:n}=Rs(),a=(n==null?void 0:n.plugins)||[],r=s.useEditorStore(S=>S.card),o=s.useEditorStore(S=>S.frame),l=(t==null?void 0:t.visualType)||"single",{setCustomCardPreferences:i}=s.useEditorActions(),{components:d,manifest:c}=s.useCustomVisual((t==null?void 0:t.url)||""),x=(j=c==null?void 0:c.visuals)==null?void 0:j.find(S=>S.name===(t==null?void 0:t.componentName));function u(S,A){if(!t)return;const M={...(t==null?void 0:t.dataInputCardIds)||{},[S]:{cardId:A,hookRef:null}};i({...t,dataInputCardIds:M})}function y(S){var D,M;const A=(D=o==null?void 0:o.cards)==null?void 0:D.filter(C=>{var E;return((E=C==null?void 0:C.customCardPreferences)==null?void 0:E.visualType)!=="multiple"}).map(C=>({value:C.id,label:C.tabTitle||C.title}));return e.jsx("div",{className:"space-y-2",children:(M=S==null?void 0:S.dataInputs)==null?void 0:M.map((C,E)=>{var O,h;return e.jsxs("div",{className:"grid grid-cols-10 gap-2",children:[e.jsx("div",{className:"col-span-4 flex items-center",children:C}),e.jsx(ee,{className:"col-span-6 h-8 w-full justify-between",label:"",options:A||[],value:((h=(O=t==null?void 0:t.dataInputCardIds)==null?void 0:O[E])==null?void 0:h.cardId)||"",onValueChange:v=>u(E,v)})]},E+Math.random())})})}function f(S,A,D=[]){var M,C;return t?S==="input"?e.jsx(s.Input,{className:`h-8 w-full ${s.removeRing}`,value:((M=t==null?void 0:t.settings)==null?void 0:M[A])||"",onChange:E=>{i({...t,settings:{...t==null?void 0:t.settings,[A]:E.target.value}})}},A):S==="select"?e.jsx(ee,{className:"h-8 w-full",label:"",options:D,value:((C=t==null?void 0:t.settings)==null?void 0:C[A])||"",onValueChange:E=>{i({...t,settings:{...t==null?void 0:t.settings,[A]:E}})}}):null:null}function m(S){const A=Object.entries((S==null?void 0:S.settings)||{});return e.jsx("div",{className:"space-y-3",children:A.map(([D,M])=>e.jsxs("div",{className:"space-y-2",children:[e.jsx(s.Label,{children:M.title}),f(M.ui,D,M.options)]},D))})}function g(S){t&&i({...t,visualType:S,componentName:""})}return e.jsxs("div",{className:"p-6",children:[e.jsx(be,{summary:"Plugin Settings",children:e.jsx("div",{className:"space-y-4 text-sm",children:e.jsxs("div",{className:"space-y-4 text-sm",children:[e.jsx("div",{className:"space-y-2",children:e.jsx("div",{className:"px-2",children:e.jsx(ee,{className:"h-8 w-full",label:"",options:a,value:(t==null?void 0:t.url)||"",onValueChange:S=>i({...t||{url:"",componentName:""},url:S})})})}),((t==null?void 0:t.type)==="component"||(t==null?void 0:t.type)===void 0)&&e.jsx(Et,{options:[{value:"single",label:"Single Visual"},{value:"multiple",label:"Multi-Visual"}],value:l,onValueChange:g}),((t==null?void 0:t.type)==="component"||(t==null?void 0:t.type)===void 0)&&t&&e.jsx(e.Fragment,{children:e.jsxs("div",{className:"space-y-2",children:[e.jsx(s.Label,{children:"Component"}),e.jsx("div",{className:"space-y-2 px-2",children:d&&e.jsx(ee,{className:"h-8 w-full",label:"",options:(d==null?void 0:d.filter(S=>S.type===l).map(S=>({value:S.name,label:S.name})))||[],value:t.componentName,onValueChange:S=>{console.log("changing value",S),i({...t,componentName:S})}})})]})})]})})}),e.jsx(s.Separator,{className:"my-4"}),((L=r==null?void 0:r.customCardPreferences)==null?void 0:L.componentName)&&e.jsxs(be,{summary:"Component Settings",children:[x&&x.dataInputs&&e.jsxs("div",{className:"space-y-3",children:[e.jsx(s.Label,{children:"Input Mapping"}),e.jsx("div",{className:"px-2",children:y(x)})]}),x&&x.settings&&e.jsx("div",{className:"space-y-3",children:e.jsx("div",{className:"px-2",children:m(x)})})]})]})}function le(){const[t,n]=w.useState([]);s.useEditorStore(u=>u.card.cfg);const a=s.useEditorStore(u=>u.card.preferences),{setCardCfg:r,setFilterOnClickColumnIndex:o,setCardPreferences:l}=s.useEditorStore(u=>u.actions),i=s.useEditorStore(u=>u.queryResultColumns);s.useEditorStore(u=>{var y;return(y=u.card.preferences)==null?void 0:y.filterOnClickColumnIndex}),w.useEffect(()=>{i&&n(new Array(i.length).fill(!1))},[i]);function d(u,y){var f,m;y?a!=null&&a.onClickFilter&&((f=a==null?void 0:a.onClickFilter)==null?void 0:f.length)>0?l({...a,onClickFilter:[...a.onClickFilter,{columnIndex:u,expression:""}]}):l({...a,onClickFilter:[{columnIndex:u,expression:""}]}):(l({...a,onClickFilter:(m=a==null?void 0:a.onClickFilter)==null?void 0:m.filter(g=>g.columnIndex!==u)}),n(g=>{const j=[...g];return j[u]=!1,j}))}function c(u,y){var m;const f=(m=a==null?void 0:a.onClickFilter)==null?void 0:m.map(g=>g.columnIndex===u?{...g,expression:y.target.value}:g);l({...a,onClickFilter:f})}function x(u){var y,f,m,g;if(t!=null&&t[u]||(f=(y=a==null?void 0:a.onClickFilter)==null?void 0:y.find(j=>j.columnIndex===u))!=null&&f.expression)return e.jsx(s.Input,{value:(g=(m=a==null?void 0:a.onClickFilter)==null?void 0:m.find(j=>j.columnIndex===u))==null?void 0:g.expression,onChange:j=>c(u,j),type:"text",className:"h-9 w-full font-mono text-xs focus-visible:ring-0 focus-visible:ring-ring focus-visible:ring-offset-0",placeholder:"Expression"})}return e.jsxs("div",{className:"space-y-2",children:[e.jsx(s.Label,{children:"On Click"}),i==null?void 0:i.map((u,y)=>{var f,m;return e.jsx("div",{className:"xbg-red-100 group flex items-center justify-between space-y-2",children:e.jsxs("div",{className:"grow",children:[e.jsxs("div",{className:"flex items-center space-x-2 py-2",children:[e.jsx(s.Checkbox,{checked:!!((f=a==null?void 0:a.onClickFilter)!=null&&f.find(g=>g.columnIndex===y)),onCheckedChange:g=>d(y,g)}),e.jsx("label",{className:"text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70",children:u}),e.jsx("div",{className:"flex items-center gap-2",children:((m=a==null?void 0:a.onClickFilter)==null?void 0:m.find(g=>g.columnIndex===y))&&e.jsx(Be,{onClick:()=>{n(g=>{const j=[...g];return j[y]=!g[y],j})},className:"invisible size-3 cursor-pointer text-gray-400 group-hover:visible"})})]}),x(y)]})},u)})]})}function Te(){var i,d,c;const t=s.useEditorStore(x=>x.card.preferences),n=s.useEditorStore(x=>x.card.cfg),{setCardCfg:a,setCardPreferences:r,setChartOrientation:o}=s.useEditorStore(x=>x.actions);(i=n==null?void 0:n.options)!=null&&i.indexAxis;function l(x){o(x)}return e.jsxs(s.RadioGroup,{value:((d=t==null?void 0:t.chartOptions)==null?void 0:d.indexAxis)||((c=n==null?void 0:n.options)==null?void 0:c.indexAxis)||"x",onValueChange:l,className:"flex gap-3",defaultValue:"x",children:[e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(s.RadioGroupItem,{value:"x",id:"r1"}),e.jsx("label",{className:"text-sm",htmlFor:"r1",children:"Vertical"})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(s.RadioGroupItem,{value:"y",id:"r2"}),e.jsx("label",{className:"text-sm",htmlFor:"r2",children:"Horizontal"})]})]})}const Ne="focus-visible:ring-0 focus-visible:ring-ring focus-visible:ring-offset-0";function We(t,n){var r,o,l;const a=s.getNumberAxis(t,n);return((l=(o=(r=t==null?void 0:t.chartOptions)==null?void 0:r.scales)==null?void 0:o[a])==null?void 0:l.type)||"linear"}function qs(){var K,B,J,k,V,G;const[t,n]=w.useState(!1),a=s.useEditorStore(F=>{var T;return(T=F.card)==null?void 0:T.preferences}),r=s.useEditorStore(F=>{var T;return(T=F.card)==null?void 0:T.cfg}),o=s.getNumberAxis(a,r),[l,i]=w.useState(We(a)),[d,c]=w.useState(((J=(B=(K=a==null?void 0:a.chartOptions)==null?void 0:K.scales)==null?void 0:B[o])==null?void 0:J.min)||""),[x,u]=w.useState(((G=(V=(k=a==null?void 0:a.chartOptions)==null?void 0:k.scales)==null?void 0:V[o])==null?void 0:G.max)||""),[y,f]=w.useState(d||x?"custom":"auto"),[m,g]=w.useState(""),[j,L]=w.useState(0),[S,A]=w.useState(""),[D,M]=w.useState(""),[C,E]=w.useState(""),O=s.useEditorStore(F=>F.actions.setCardPreferences),{updateCardInFrame:h}=s.useEditorActions(),v=s.useEditorStore(F=>F.card),p=s.useEditorStore(F=>{var T;return(T=F.card)==null?void 0:T.type}),I=["pie","doughnut","polarArea"].includes(p);w.useEffect(()=>{var F,T,$,q,P,W,te,ce,ae,re,ne,Q,X,Z;i(We(a)),c((($=(T=(F=a==null?void 0:a.chartOptions)==null?void 0:F.scales)==null?void 0:T[o])==null?void 0:$.min)===0?0:""),u(((W=(P=(q=a==null?void 0:a.chartOptions)==null?void 0:q.scales)==null?void 0:P[o])==null?void 0:W.max)||""),g(((re=(ae=(ce=(te=a==null?void 0:a.chartOptions)==null?void 0:te.scales)==null?void 0:ce[o])==null?void 0:ae.ticks)==null?void 0:re.stepSize)||""),L(((ne=a==null?void 0:a.numberAxisFormat)==null?void 0:ne.decimalPlaces)||0),A(((Q=a==null?void 0:a.numberAxisFormat)==null?void 0:Q.suffix)||""),M(((X=a==null?void 0:a.numberAxisFormat)==null?void 0:X.currency)||""),E(((Z=a==null?void 0:a.numberAxisFormat)==null?void 0:Z.locale)||"")},[t,a,o]);function z(F,T){return T===""||/^[0-9\b]+$/.test(T)?Number(T):Number(F)}function R(){const F=[...new Set(s.LOCALE_CURRENCY_PAIRS.map(T=>T.currency))];return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"grid grid-cols-6 items-center gap-2",children:[e.jsx(s.Label,{className:"col-span-2 hover:cursor-pointer hover:underline",htmlFor:"currency",children:e.jsx("a",{target:"_blank",href:"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat",children:"Currency"})}),e.jsxs(s.Select,{value:D||"none",onValueChange:T=>M(T==="none"?"":T),children:[e.jsx(s.SelectTrigger,{className:"col-span-2 h-8 w-full focus:ring-1 focus:ring-offset-0",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{children:e.jsxs(s.SelectGroup,{children:[e.jsx(s.SelectLabel,{children:"Currency"}),e.jsx(s.SelectItem,{value:"none",children:"None"}),F.map(T=>e.jsx(s.SelectItem,{value:T,children:T},T))]})})]}),e.jsxs(s.Select,{value:C,onValueChange:T=>E(T),children:[e.jsx(s.SelectTrigger,{className:"col-span-2 h-8 w-full focus:ring-1 focus:ring-offset-0",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{children:e.jsxs(s.SelectGroup,{children:[e.jsx(s.SelectLabel,{children:"Locale"}),s.LOCALE_CURRENCY_PAIRS.map(T=>e.jsx(s.SelectItem,{value:T.locale,children:T.locale},T.locale))]})})]})]}),e.jsxs("div",{className:"grid grid-cols-9 items-center gap-2",children:[e.jsx(s.Label,{className:"col-span-3",htmlFor:"format",children:"Decimals"}),e.jsx(s.Input,{value:j,onChange:T=>L(Number(T.target.value)),id:"format",className:`col-span-6 h-8 w-full tracking-wide ${Ne}`})]})]})}function _(){return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"grid grid-cols-3 items-center gap-2",children:[e.jsx(s.Label,{htmlFor:"range",children:"Range"}),e.jsx(s.Input,{id:"min",value:d,onChange:F=>c(T=>z(T,F.target.value)),className:`col-span-1 h-8 w-full ${Ne}`}),e.jsx(s.Input,{value:x,onChange:F=>u(T=>z(T,F.target.value)),id:"max",className:`col-span-1 h-8 w-full ${Ne}`})]}),e.jsxs("div",{className:"grid grid-cols-3 items-center gap-2",children:[e.jsx(s.Label,{htmlFor:"step-size",children:"Step Size"}),e.jsx(s.Input,{value:m,onChange:F=>g(T=>z(T,F.target.value)),id:"step-size",className:`col-span-1 h-8 w-full ${Ne}`})]})]})}function H(){var q;let F={};y==="custom"&&(F={min:d,max:x,ticks:{stepSize:m}});const T={...a||{},chartOptions:{...a==null?void 0:a.chartOptions,scales:{...(q=a==null?void 0:a.chartOptions)==null?void 0:q.scales,[o]:{type:l,...l==="linear"?F:{}}}},numberAxisFormat:{decimalPlaces:j,suffix:S,currency:D,locale:C}};console.log(T),O(T);const $={...v,preferences:T};h($)}return e.jsxs(s.Popover,{onOpenChange:F=>n(F),children:[e.jsx(s.PopoverTrigger,{asChild:!0,children:e.jsx(s.SliderIcon,{className:"size-4 cursor-pointer text-muted-foreground hover:text-foreground"})}),e.jsx(s.PopoverContent,{align:"center",className:"max-w-65",children:e.jsxs("div",{className:"grid gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("h4",{className:"font-medium leading-none",children:"Scale Options"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Set the scale for the number axis"})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsxs("div",{className:"grid grid-cols-3 items-center gap-2",children:[e.jsx(s.Label,{htmlFor:"scale",children:"Type"}),e.jsxs(s.Select,{disabled:I,value:l,onValueChange:F=>i(F),children:[e.jsx(s.SelectTrigger,{className:"col-span-2 h-8 w-full focus:ring-1 focus:ring-offset-0",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{id:"type",children:e.jsxs(s.SelectGroup,{children:[e.jsx(s.SelectLabel,{children:"Option"}),e.jsx(s.SelectItem,{value:"linear",children:"Linear"}),e.jsx(s.SelectItem,{value:"logarithmic",children:"Logarithmic"})]})})]})]}),l=="linear"&&e.jsxs("div",{className:"grid grid-cols-3 items-center gap-2 py-1",children:[e.jsx(s.Label,{htmlFor:"scale-option",children:"Setup"}),e.jsxs(s.RadioGroup,{disabled:I,id:"scale-option",value:y,onValueChange:F=>f(F),className:"col-span-2 flex gap-3",defaultValue:"x",children:[e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(s.RadioGroupItem,{value:"auto",id:"r1"}),e.jsx("label",{className:"text-sm",htmlFor:"r1",children:"Auto"})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(s.RadioGroupItem,{value:"custom",id:"r2"}),e.jsx("label",{className:"text-sm",htmlFor:"r2",children:"Custom"})]})]})]}),y==="custom"&&l=="linear"&&_(),R(),e.jsx(s.SelectSeparator,{}),e.jsx("div",{className:"grid grid-cols-3",children:e.jsx(s.Button,{onClick:H,variant:"secondary",className:"col-span-1 col-start-3 h-8 w-full",children:"Apply"})})]})]})})]})}function It({idx:t}){var d;const n=s.useEditorStore(c=>{var x;return(x=c.card)==null?void 0:x.preferences}),a=s.useEditorStore(c=>{var x;return(x=c.card.preferences)==null?void 0:x.datasetOptions}),r=s.useEditorStore(c=>c.actions.setCardPreferences),o=(d=n==null?void 0:n.chartOptions)==null?void 0:d.indexAxis,l=a==null?void 0:a.find(c=>c.idx===t);function i(c,x){(c==="end"||c==="start")&&s.getContrastColor(s.getCanvasBackgroundColor());const u={display:c!=="none",align:c,anchor:c,clamp:!0};if(!l)r({...n,datasetOptions:[...a||[],{idx:x,datalabels:u}]});else{const y={...l};y.datalabels=u;const f=a==null?void 0:a.map(m=>m.idx===x?y:m);r({...n,datasetOptions:f})}}return e.jsxs(s.Popover,{children:[e.jsx(s.PopoverTrigger,{children:e.jsx(ys,{className:"invisible size-4 rotate-[135deg] cursor-pointer text-muted-foreground hover:text-foreground group-hover:visible"})}),e.jsx(s.PopoverContent,{className:"w-fit p-1",children:e.jsxs("div",{className:"flex gap-1",children:[e.jsx(s.Button,{onClick:()=>i("none",t),size:"sm",variant:"secondary",className:"h-7 p-1 text-xs font-normal",children:e.jsx(s.X,{className:"size-4"})}),e.jsx(s.Button,{onClick:()=>i("start",t),size:"sm",variant:"secondary",className:"h-7 p-1 text-xs font-normal",children:e.jsx(cs,{className:s.cn("h-4 w-4",{"rotate-90":o==="y"})})}),e.jsx(s.Button,{onClick:()=>i("center",t),size:"sm",variant:"secondary",className:"h-7 p-1 text-xs font-normal",children:e.jsx(us,{className:s.cn("h-4 w-4",{"rotate-90":o==="y"})})}),e.jsx(s.Button,{onClick:()=>i("end",t),size:"sm",variant:"secondary",className:"h-7 p-1 text-xs font-normal",children:e.jsx(ds,{className:s.cn("h-4 w-4",{"rotate-90":o==="y"})})})]})})]})}function _s(){const t=s.useEditorStore(x=>x.card),n=s.useEditorStore(x=>{var u,y,f;return(f=(y=(u=x==null?void 0:x.card)==null?void 0:u.preferences)==null?void 0:y.chartOptions)==null?void 0:f.indexAxis}),{data:a}=s.useDashboardCardQuery(t),r=n==="y"?"Y axis":"X axis",o=n==="y"?"X axis":"Y axis",{keys:l,metricKeys:i,dimensionKeys:d}=s.getKeys((a==null?void 0:a.records)||[]);let c=i;if(["stackedBar","stackedLine"].includes(t.type)){const x=s.pivotData({dataArray:(a==null?void 0:a.records)||[],groupKey:d[0],pivotKey:d[1],valueKey:c[0]}),{metricKeys:u}=s.getKeys(x);c=u}return l.length===0?null:e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(s.Label,{children:r}),e.jsx("div",{className:"my-1 space-y-1",children:e.jsx("div",{className:"rounded-md bg-muted/70 px-2 py-1 hover:bg-muted",children:e.jsx("p",{children:d[0]})})})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between gap-5",children:[e.jsx(s.Label,{children:o}),e.jsx(qs,{})]}),e.jsx("div",{className:"my-1 space-y-1",children:c.map((x,u)=>e.jsx(Dt,{col:x,idx:u},x))})]})]})}function Dt({col:t,idx:n}){const a=s.useEditorStore(d=>{var c;return(c=d.card)==null?void 0:c.preferences}),r=s.useEditorStore(d=>{var c;return(c=d.card.preferences)==null?void 0:c.datasetOptions}),o=r==null?void 0:r.find(d=>d.idx===n),{setCardPreferences:l}=s.useEditorStore(d=>d.actions);function i(d){if(!o)l({...a,datasetOptions:[...r||[],{idx:n,type:d==="area"?"line":d,fill:d==="area"?"origin":""}]});else{const c={...o};c.type=d==="area"?"line":d,c.fill=d==="area"?"origin":"";const x=r==null?void 0:r.map(u=>u.idx===n?c:u);l({...a,datasetOptions:x})}}return e.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.jsx("p",{children:t}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(Ie,{onClick:()=>i("bar"),className:"invisible size-4 cursor-pointer text-muted-foreground hover:text-foreground group-hover:visible"}),e.jsx(De,{onClick:()=>i("line"),className:"invisible size-4 cursor-pointer text-muted-foreground hover:text-foreground group-hover:visible"}),e.jsx(Xe,{onClick:()=>i("area"),className:"invisible size-4 cursor-pointer text-muted-foreground hover:text-foreground group-hover:visible"}),e.jsx(s.Separator,{orientation:"vertical",className:"invisible size-4 cursor-pointer py-2 text-muted-foreground hover:text-foreground group-hover:visible"}),e.jsx(It,{idx:n})]})]})}function Bs(){const t=s.useEditorStore(f=>f.selectedConnectionId),n=s.useEditorStore(f=>f.selectedDatamodelId),a=s.useEditorStore(f=>f.selectedDatabaseName),r=s.useEditorStore(f=>f.selectedSchemaName),o=s.useEditorStore(f=>f.selectedTableName),l=s.useDashboardStore(f=>f.dashboard.filters)||[],i=s.useDashboardStore(f=>f.actions.addFilter),d=s.useDashboardStore(f=>f.actions.removeFilter),c=s.useDashboardStore(f=>f.actions.removeFilterValue),{modelItems:x,tableName:u}=ie();function y(f,m="dashboard"){var E;const g=s.fmt(f.column_name),j=s.fmt(a||""),L=s.fmt(r||""),S=s.fmt(u);let A=s.getQualifiedTableName(L,S),D=`${A}.${g}`;const M=(E=x==null?void 0:x.find(O=>O.id===n))==null?void 0:E.name;n&&n!=="none"&&(D=`${s.DATAMODEL_NAMESPCACE}.${M}.${g}`,A=`${s.DATAMODEL_NAMESPCACE}.${M}`);const C=l==null?void 0:l.find(O=>O.column===D&&O.table===S&&(O.database===j||O.database===a));if(C)c(C.id),d(C.id);else{const O=s.v4();return u==="api"&&t?(i({location:m,id:O,column:D,title:f.column_name,dataType:f.data_type,table:"api",database:"",connectionId:t,operation:"in",sql:s.getDefaultFilterSql(f.data_type,A,g)}),O):(i({id:O,location:m,column:D,title:f.column_name,dataType:f.data_type,table:o||"",database:a||"",connectionId:t||"",operation:"in",sql:s.getDefaultFilterSql(f.data_type,A,g)}),O)}}return{assignFilter:y}}function xe(){const t=s.useDashboardStore(d=>d.dashboard.filters),n=s.useEditorStore(d=>d.frame),{setFrame:a}=s.useEditorActions(),{columns:r}=ie(),{assignFilter:o}=Bs();function l(d){const c=o(d,"frame");a({...n,filterId:c})}const i=t==null?void 0:t.find(d=>d.id===n.filterId);return e.jsxs("div",{className:"space-y-3",children:[e.jsx(s.Label,{children:"Card Filter"}),e.jsx(Lt,{onSelect:l,columns:r}),i&&e.jsx(s.FilterHeader,{filter:i})]})}function Lt({columns:t,onSelect:n}){var i;const[a,r]=Qe.useState(!1),[o,l]=Qe.useState("");return e.jsxs(s.Popover,{open:a,onOpenChange:r,children:[e.jsx(s.PopoverTrigger,{asChild:!0,children:e.jsxs(s.Button,{size:"sm",variant:"outline",role:"combobox","aria-expanded":a,className:"w-full justify-between font-normal",children:[o?(i=t.find(d=>d.column_name===o))==null?void 0:i.column_name:"Select Column...",e.jsx(s.CaretSortIcon,{className:"ml-2 h-4 w-4 shrink-0 opacity-50"})]})}),e.jsx(s.PopoverContent,{className:"w-[200px] p-0",children:e.jsxs(s.Command,{children:[e.jsx(s.CommandInput,{placeholder:"Search column",className:"h-9"}),e.jsxs(s.CommandList,{children:[e.jsx(s.CommandEmpty,{children:"No framework found."}),e.jsx(s.CommandGroup,{children:t.map(d=>e.jsxs(s.CommandItem,{value:d.column_name,onSelect:c=>{const x=c===o?"":c;l(x),r(!1),x&&n(d)},children:[d.column_name,e.jsx(s.CheckIcon,{className:s.cn("ml-auto h-4 w-4",o===d.column_name?"opacity-100":"opacity-0")})]},d.column_name))})]})]})})]})}function Tt({cardType:t}){return e.jsx("div",{className:"space-y-6 px-6 py-2",children:e.jsxs(s.Accordion,{defaultValue:["item-2"],type:"multiple",children:[e.jsxs(s.AccordionItem,{value:"item-1",children:[e.jsx(s.AccordionTrigger,{children:`${s.titleCase(t)} Chart`}),e.jsxs(s.AccordionContent,{className:"space-y-4 font-mono text-xs",children:[e.jsx("div",{className:"rounded bg-muted px-2 py-1 text-xs",children:"SELECT x-axis, y-axis-1, y-axis-2,... FROM table"}),e.jsxs("ul",{className:"ml-6 list-disc text-xs [&>li]:mt-2",children:[e.jsx("li",{children:"x-axis - category"}),e.jsx("li",{children:"y-axis1 - number"}),e.jsx("li",{children:"y-axis2 - number"})]}),e.jsxs("div",{children:["See ",e.jsx("a",{target:"_blank",onClick:n=>n.stopPropagation(),className:"text-blue-700",href:"https://docs.semaphor.cloud/concepts/visuals#line-chart",children:"example"})," in the docs."]})]})]}),e.jsxs(s.AccordionItem,{value:"item-2",children:[e.jsx(s.AccordionTrigger,{children:"Settings"}),e.jsxs(s.AccordionContent,{className:"space-y-4 px-2",children:[e.jsx(Te,{}),e.jsx(_s,{})]})]}),e.jsxs(s.AccordionItem,{value:"item-3",children:[e.jsx(s.AccordionTrigger,{children:"Filters"}),e.jsxs(s.AccordionContent,{className:"space-y-4 px-2",children:[e.jsx(le,{}),e.jsx(xe,{})]})]})]})})}function Ge(){var o,l,i;const t=s.useEditorStore(d=>d.card.cfg),n=s.useEditorStore(d=>d.actions.setCardCfg),a=s.useEditorStore(d=>d.card.type);function r(d){var u;const c={datalabels:{display:d!=="none",align:d,anchor:d,clamp:!0}},x={...t,options:{...t==null?void 0:t.options,plugins:{...(u=t==null?void 0:t.options)==null?void 0:u.plugins,...c}}};n(x),console.log(d)}return e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("label",{className:"font-medium",children:"Data Labels"}),!["pyramid"].includes(a)&&e.jsx(qs,{})]}),e.jsxs(s.Select,{value:(i=(l=(o=t==null?void 0:t.options)==null?void 0:o.plugins)==null?void 0:l.datalabels)==null?void 0:i.anchor,onValueChange:r,defaultValue:"none",children:[e.jsx(s.SelectTrigger,{className:"h-8 w-full focus:ring-1 focus:ring-offset-0",children:e.jsx(s.SelectValue,{placeholder:"Select position"})}),e.jsx(s.SelectContent,{children:e.jsxs(s.SelectGroup,{children:[e.jsx(s.SelectLabel,{children:"Data Labels"}),e.jsx(s.SelectItem,{value:"none",children:"None"}),a!=="pyramid"&&e.jsx(s.SelectItem,{value:"start",children:"Start"}),e.jsx(s.SelectItem,{value:"center",children:"Center"}),a!=="pyramid"&&e.jsx(s.SelectItem,{value:"end",children:"End"})]})})]})]})}function At({cardType:t}){function n(a){const r="SELECT label, [group], x-axis, y-axis, radius FROM table",o="SELECT label, [group], x-axis, y-axis FROM table";return e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"rounded bg-muted px-2 py-1 text-xs",children:a==="bubble"?r:o}),e.jsxs("ul",{className:"ml-6 list-disc text-xs [&>li]:mt-2",children:[e.jsx("li",{children:"label - category"}),e.jsx("li",{children:"group - category"}),e.jsx("li",{children:"x-axis - category"}),e.jsx("li",{children:"y-axis - category"}),a==="bubble"&&e.jsx("li",{children:"radius - number"})]}),e.jsxs("div",{children:["See ",e.jsx("a",{target:"_blank",onClick:l=>l.stopPropagation(),className:"text-blue-700",href:"https://docs.semaphor.cloud/concepts/visuals#pie-chart",children:"example"})," in the docs."]})]})}return e.jsx("div",{className:"space-y-6 px-6 py-2",children:e.jsxs(s.Accordion,{defaultValue:["item-2"],type:"multiple",children:[e.jsxs(s.AccordionItem,{value:"item-1",children:[e.jsx(s.AccordionTrigger,{children:`${s.titleCase(t)} Chart`}),e.jsx(s.AccordionContent,{className:"space-y-4 font-mono text-xs",children:n(t)})]}),e.jsxs(s.AccordionItem,{value:"item-2",children:[e.jsx(s.AccordionTrigger,{children:"Settings"}),e.jsx(s.AccordionContent,{className:"px-2",children:e.jsx(Ge,{})})]}),e.jsxs(s.AccordionItem,{value:"item-3",children:[e.jsx(s.AccordionTrigger,{children:"Filters"}),e.jsxs(s.AccordionContent,{className:"space-y-4 px-2",children:[e.jsx(le,{}),e.jsx(xe,{})]})]})]})})}const Ot={datasets:[{type:"line",label:"Sum_sales",data:[]},{type:"bar",label:"Sum_profit",data:[]}]},zt={datasets:[{fill:"origin",type:"line",label:"Sum_sales",data:[]}]};function Ft(){const t=s.useEditorStore(n=>n.card.type);return e.jsxs("div",{className:"space-y-6 p-6",children:[e.jsx(s.Accordion,{className:" ",type:"single",collapsible:!0,children:Mt(t)}),e.jsx("section",{className:"",children:["line","bar"].includes(t)&&e.jsx(Te,{})}),!["kpi"].includes(t)&&e.jsxs("div",{className:"space-y-4",children:[e.jsx(Ge,{}),e.jsx(le,{}),e.jsx(xe,{})]})]})}function Mt(t){if(["line","bar"].includes(t))return e.jsxs(e.Fragment,{children:[e.jsxs(s.AccordionItem,{value:"item-1",children:[e.jsx(s.AccordionTrigger,{className:"font-normal",children:e.jsx("p",{children:"Chart Query"})}),e.jsxs(s.AccordionContent,{className:" ",children:[e.jsx("div",{className:"rounded bg-muted px-2 py-1 font-mono text-xs font-semibold",children:"SELECT x-axis, y-axis-1, y-axis-2, y-axis-3,... FROM table"}),e.jsxs("ul",{className:"my-6 ml-6 list-disc text-xs font-normal [&>li]:mt-2",children:[e.jsx("li",{children:"X-axis - Category (ex. city)"}),e.jsx("li",{children:"Y-axis - Number (ex. population)"})]})]})]}),e.jsxs(s.AccordionItem,{value:"item-2",children:[e.jsx(s.AccordionTrigger,{className:"font-normal",children:"Mixed Chart"}),e.jsxs(s.AccordionContent,{className:"space-y-2 text-xs",children:[e.jsxs("p",{children:["Click ",e.jsx("b",{children:"Customize"})," and change the `type` property in the dataset."]}),e.jsx("pre",{children:JSON.stringify(Ot,null,2)})]})]}),e.jsxs(s.AccordionItem,{value:"item-3",children:[e.jsx(s.AccordionTrigger,{className:"font-normal",children:"Area Chart"}),e.jsxs(s.AccordionContent,{className:"space-y-2 text-xs",children:[e.jsxs("p",{children:["Click ",e.jsx("b",{children:"Customize"})," and add `fill` property to the dataset. See",e.jsx("a",{className:"mx-1 text-blue-500 hover:underline",href:"https://www.chartjs.org/docs/latest/samples/area/line-boundaries.html",target:"_blank",children:"docs"}),"for more options."]}),e.jsx("pre",{children:JSON.stringify(zt,null,2)})]})]})]});if(t==="bubble")return e.jsx(e.Fragment,{children:e.jsxs(s.AccordionItem,{value:"item-1",children:[e.jsx(s.AccordionTrigger,{className:"font-normal",children:e.jsxs("p",{children:["How to create a ",e.jsx("span",{children:t})," chart query?"]})}),e.jsxs(s.AccordionContent,{className:" ",children:[e.jsx("div",{className:"rounded bg-muted px-2 py-1 font-mono text-xs font-semibold",children:"SELECT label, x-axis, y-axis, radius FROM table"}),e.jsxs("ul",{className:"my-6 ml-6 list-disc text-xs font-normal [&>li]:mt-2",children:[e.jsx("li",{children:"Label - Category (ex. city)"}),e.jsx("li",{children:"Bubble Group (opt) - Category (ex. state)"}),e.jsx("li",{children:"X-axis - Number (ex. avg. age)"}),e.jsx("li",{children:"Y-axis - Number (ex. avg. weight)"}),e.jsx("li",{children:"Radius - Number (ex. population)"})]})]})]})});if(t==="scatter")return e.jsx(e.Fragment,{children:e.jsxs(s.AccordionItem,{value:"item-1",children:[e.jsx(s.AccordionTrigger,{className:"font-normal",children:e.jsxs("p",{children:["How to create a ",e.jsx("span",{children:t})," chart query?"]})}),e.jsxs(s.AccordionContent,{className:" ",children:[e.jsx("div",{className:"rounded bg-muted px-2 py-1 font-mono text-xs font-semibold",children:"SELECT label, x-axis, y-axis FROM table"}),e.jsxs("ul",{className:"my-6 ml-6 list-disc text-xs font-normal [&>li]:mt-2",children:[e.jsx("li",{children:"Label - Category (ex. city)"}),e.jsx("li",{children:"Group (opt) - Category (ex. state)"}),e.jsx("li",{children:"X-axis - Number (ex. avg. age)"}),e.jsx("li",{children:"Y-axis - Number (ex. avg. weight)"})]})]})]})});if(["pie","doughnut","polarArea"].includes(t))return e.jsx(e.Fragment,{children:e.jsxs(s.AccordionItem,{value:"item-1",children:[e.jsx(s.AccordionTrigger,{className:"font-normal",children:e.jsxs("p",{children:[e.jsx("span",{children:t==="polarArea"?"Polar":t.charAt(0).toUpperCase()+t.slice(1)})," ","chart query"]})}),e.jsxs(s.AccordionContent,{className:" ",children:[e.jsx("div",{className:"rounded bg-muted px-2 py-1 font-mono text-xs font-semibold",children:"SELECT label, measure FROM table"}),e.jsxs("ul",{className:"my-6 ml-6 list-disc text-xs font-normal [&>li]:mt-2",children:[e.jsx("li",{children:"Label - Category (ex. city)"}),e.jsx("li",{children:"Measure - Number (ex. population)"})]})]})]})})}function Vt(){var c,x,u,y,f;const t=s.useEditorStore(m=>m.card.preferences),n=s.useEditorStore(m=>m.actions.setCardPreferences),a=s.useEditorStore(m=>m.actions.setNumberFormat);s.useEditorStore(m=>{var g,j;return(j=(g=m.card.preferences)==null?void 0:g.formatNumber)==null?void 0:j.decimalPlaces});const r=s.useEditorStore(m=>{var g,j;return(j=(g=m.card.preferences)==null?void 0:g.formatNumber)==null?void 0:j.locale}),o=s.useEditorStore(m=>{var g,j;return(j=(g=m.card.preferences)==null?void 0:g.formatNumber)==null?void 0:j.currency});s.useEditorStore(m=>m.actions.setFilterOnClickField);const l=s.useEditorStore(m=>{var g,j;return(j=(g=m.card.preferences)==null?void 0:g.formatNumber)==null?void 0:j.colorRanges})||[],i=s.useEditorStore(m=>m.actions.setColorRanges),d=[...new Set(s.LOCALE_CURRENCY_PAIRS.map(m=>m.currency))];return e.jsxs("div",{children:[e.jsxs("div",{className:"mb-3 flex items-center gap-2",children:[e.jsx(s.Checkbox,{checked:!!((c=t==null?void 0:t.formatNumber)!=null&&c.enabled),onCheckedChange:m=>{n({...t,formatNumber:{...t==null?void 0:t.formatNumber,enabled:m}})}}),e.jsx(s.Label,{children:"Format Number"})]}),((x=t==null?void 0:t.formatNumber)==null?void 0:x.enabled)===!0&&e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsx("div",{children:e.jsxs("div",{className:"space-y-4 p-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("div",{className:"w-full space-y-1",children:[e.jsx(s.Label,{children:"Locale"}),e.jsxs(s.Select,{value:r||"none",onValueChange:m=>{var g,j,L;return a(((g=t==null?void 0:t.formatNumber)==null?void 0:g.decimalPlaces)||0,((j=t==null?void 0:t.formatNumber)==null?void 0:j.currency)||"",m,((L=t==null?void 0:t.formatNumber)==null?void 0:L.suffix)||"")},children:[e.jsx(s.SelectTrigger,{className:"col-span-6 h-8 w-full focus:ring-1 focus:ring-offset-0",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{children:e.jsxs(s.SelectGroup,{children:[e.jsx(s.SelectLabel,{children:"Format"}),e.jsx(s.SelectItem,{value:"none",children:"None"},"none"),s.LOCALE_CURRENCY_PAIRS.map(m=>e.jsx(s.SelectItem,{value:m.locale,children:m.locale},m.locale))]})})]})]}),e.jsxs("div",{className:"w-full space-y-1",children:[e.jsx(s.Label,{children:"Currency"}),e.jsxs(s.Select,{value:o||"none",onValueChange:m=>{var g,j,L;console.log("currency",m),a(((g=t==null?void 0:t.formatNumber)==null?void 0:g.decimalPlaces)||0,m==="none"?"":m,((j=t==null?void 0:t.formatNumber)==null?void 0:j.locale)||"",((L=t==null?void 0:t.formatNumber)==null?void 0:L.suffix)||"")},children:[e.jsx(s.SelectTrigger,{className:"col-span-6 h-8 w-full focus:ring-1 focus:ring-offset-0",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{children:e.jsxs(s.SelectGroup,{children:[e.jsx(s.SelectLabel,{children:"Currency"}),e.jsx(s.SelectItem,{value:"none",children:"None"},"none"),d.map(m=>e.jsx(s.SelectItem,{value:m,children:m},m))]})})]})]})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs("div",{className:"w-full space-y-1",children:[e.jsx(s.Label,{children:"Decimals"}),e.jsxs(s.Select,{value:((y=(u=t==null?void 0:t.formatNumber)==null?void 0:u.decimalPlaces)==null?void 0:y.toString())||"0",onValueChange:m=>{var g,j,L;return a(Number(m),((g=t==null?void 0:t.formatNumber)==null?void 0:g.currency)||"",((j=t==null?void 0:t.formatNumber)==null?void 0:j.locale)||"",((L=t==null?void 0:t.formatNumber)==null?void 0:L.suffix)||"")},children:[e.jsx(s.SelectTrigger,{className:"col-span-3 h-8 w-full focus:ring-1 focus:ring-offset-0",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{children:["0","1","2","3","4"].map(m=>e.jsx(s.SelectItem,{value:m,children:m},m))})]})]}),e.jsxs("div",{className:"w-full space-y-1",children:[e.jsx(s.Label,{children:"Suffix"}),e.jsx(s.Input,{value:((f=t==null?void 0:t.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:m=>{var g,j,L;return a(((g=t==null?void 0:t.formatNumber)==null?void 0:g.decimalPlaces)||0,((j=t==null?void 0:t.formatNumber)==null?void 0:j.currency)||"",((L=t==null?void 0:t.formatNumber)==null?void 0:L.locale)||"",m.target.value)}})]})]})]})}),e.jsx(s.Separator,{className:"my-3"}),e.jsx(s.ColorFormat,{colorRanges:l,setColorRanges:i})]})]})}function Rt(){return e.jsxs("div",{className:"space-y-6 px-6 py-2",children:[e.jsx(s.Accordion,{type:"single",collapsible:!0,children:e.jsxs(s.AccordionItem,{value:"item-1",children:[e.jsx(s.AccordionTrigger,{className:"",children:"KPI Query"}),e.jsxs(s.AccordionContent,{className:"font-mono",children:[e.jsx("div",{className:"rounded bg-muted px-2 py-1 font-mono text-xs",children:"SELECT current, previous FROM table"}),e.jsxs("ul",{className:"my-6 ml-6 list-disc text-xs [&>li]:mt-2",children:[e.jsx("li",{children:"current - number"}),e.jsx("li",{children:"previous - number"})]}),e.jsxs("div",{children:["See ",e.jsx("a",{target:"_blank",onClick:t=>t.stopPropagation(),className:"text-blue-700",href:"https://docs.semaphor.cloud/concepts/visuals#kpi",children:"example"})," in the docs."]})]})]})}),e.jsx("section",{className:"",children:e.jsx(Vt,{})}),e.jsx("div",{}),e.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(t=>({label:t,value:t}));function Ht(){var c,x,u,y,f,m,g,j,L,S,A,D,M,C,E,O,h,v;const t=s.useEditorStore(p=>p.card),n=(x=(c=t==null?void 0:t.preferences)==null?void 0:c.mapVisualOptions)==null?void 0:x.topoJsonUrl,[a,r]=w.useState(((y=(u=t==null?void 0:t.preferences)==null?void 0:u.mapVisualOptions)==null?void 0:y.customTopoJsonUrl)||""),{setCardPreferences:o}=s.useEditorActions(),{data:l}=s.useTopoJson(t),i=Object.keys((l==null?void 0:l.objects)||{}).map(p=>({label:p,value:p}))||[],d=[{label:"US States 10m",value:"https://unpkg.com/us-atlas/states-10m.json"},{label:"Countries 50m",value:"https://unpkg.com/world-atlas/countries-50m.json"},{label:"Custom",value:"custom"}];return e.jsxs("div",{className:"p-6",children:[e.jsx(be,{summary:"Map Query",children:e.jsx("p",{className:"rounded-md bg-muted p-2 font-mono text-xs",children:"SELECT country, value FROM table"})}),e.jsx(s.Separator,{className:"my-4"}),e.jsx(be,{open:!0,summary:"Settings",children:e.jsxs("div",{className:"space-y-3 px-2",children:[e.jsx(ee,{className:"h-9",options:d,onValueChange:p=>{console.log("value",p),o({...t.preferences,mapVisualOptions:{topoJsonUrl:p}})},value:n||"",label:"Select Map"}),n==="custom"&&e.jsx(s.Input,{onChange:p=>{r(p.target.value)},onBlur:()=>{var p;console.log("onBlur",a),o({...t.preferences,mapVisualOptions:{...(p=t.preferences)==null?void 0:p.mapVisualOptions,customTopoJsonUrl:a}})},value:a,className:`h-9 w-full ${s.removeRing}`,placeholder:"Custom URL"}),l&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(s.Label,{children:"Map Object"}),e.jsx(ee,{className:"h-9",options:i,value:((m=(f=t.preferences)==null?void 0:f.mapVisualOptions)==null?void 0:m.objectKey)||"",label:"Map Object",onValueChange:p=>{var I;o({...t.preferences,mapVisualOptions:{...(I=t.preferences)==null?void 0:I.mapVisualOptions,objectKey:p}})}})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(s.Label,{children:"Projection"}),e.jsx(ee,{className:"h-9",options:qt,value:((j=(g=t.preferences)==null?void 0:g.mapVisualOptions)==null?void 0:j.projection)||"",label:"Projection",onValueChange:p=>{var I;o({...t.preferences,mapVisualOptions:{...(I=t.preferences)==null?void 0:I.mapVisualOptions,projection:p}})}})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(s.Label,{children:"Colors"}),e.jsx(ee,{className:"h-9",options:Bt,value:((S=(L=t.preferences)==null?void 0:L.mapVisualOptions)==null?void 0:S.colorScale)||"",label:"Select Color Scale",onValueChange:p=>{var I;o({...t.preferences,mapVisualOptions:{...(I=t.preferences)==null?void 0:I.mapVisualOptions,colorScale:p}})}})]})]})]})}),e.jsx(s.Separator,{className:"my-4"}),e.jsx(be,{className:"",summary:"Scale Options",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(s.Input,{className:`h-9 w-full ${s.removeRing}`,type:"number",step:.1,value:((D=(A=t.preferences)==null?void 0:A.mapVisualOptions)==null?void 0:D.projectionScale)||1,onChange:p=>{var I;o({...t.preferences,mapVisualOptions:{...(I=t.preferences)==null?void 0:I.mapVisualOptions,projectionScale:Number(p.target.value)}})}}),e.jsx(s.Label,{children:"X"}),e.jsx(s.Input,{className:`h-9 w-full ${s.removeRing}`,type:"number",step:10,value:((E=(C=(M=t.preferences)==null?void 0:M.mapVisualOptions)==null?void 0:C.projectionOffset)==null?void 0:E[0])||0,onChange:p=>{var I,z,R,_;o({...t.preferences,mapVisualOptions:{...(I=t.preferences)==null?void 0:I.mapVisualOptions,projectionOffset:[Number(p.target.value),((_=(R=(z=t.preferences)==null?void 0:z.mapVisualOptions)==null?void 0:R.projectionOffset)==null?void 0:_[1])||0]}})}}),e.jsx(s.Label,{children:"Y"}),e.jsx(s.Input,{className:`h-9 w-full ${s.removeRing}`,type:"number",step:10,value:((v=(h=(O=t.preferences)==null?void 0:O.mapVisualOptions)==null?void 0:h.projectionOffset)==null?void 0:v[1])||0,onChange:p=>{var I,z,R,_;o({...t.preferences,mapVisualOptions:{...(I=t.preferences)==null?void 0:I.mapVisualOptions,projectionOffset:[((_=(R=(z=t.preferences)==null?void 0:z.mapVisualOptions)==null?void 0:R.projectionOffset)==null?void 0:_[0])||0,Number(p.target.value)]}})}})]})}),e.jsx(s.Separator,{className:"my-4"}),e.jsx(le,{})]})}function Pt(){var r;const t=s.useEditorStore(o=>o.card.preferences),{setCardPreferences:n}=s.useEditorStore(o=>o.actions);function a(o){n({...t,textVisualOptions:{...t==null?void 0:t.textVisualOptions,isDynamicText:o==="dynamic"}})}return e.jsxs(s.RadioGroup,{value:(r=t==null?void 0:t.textVisualOptions)!=null&&r.isDynamicText?"dynamic":"static",onValueChange:a,className:"flex gap-3",defaultValue:"x",children:[e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(s.RadioGroupItem,{value:"static",id:"r1"}),e.jsx("label",{className:"text-sm",htmlFor:"r1",children:"Static"})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(s.RadioGroupItem,{value:"dynamic",id:"r2"}),e.jsx("label",{className:"text-sm",htmlFor:"r2",children:"Dynamic"})]})]})}function we({cardType:t,docContent:n,suffix:a="Chart"}){return e.jsx("div",{className:"space-y-6 px-6 py-2",children:e.jsxs(s.Accordion,{defaultValue:["item-2"],type:"multiple",children:[e.jsxs(s.AccordionItem,{value:"item-1",children:[e.jsx(s.AccordionTrigger,{children:`${s.titleCase(t)} ${a}`}),e.jsx(s.AccordionContent,{children:n||e.jsxs("div",{className:"space-y-4 font-mono text-xs",children:[e.jsx("div",{className:"rounded bg-muted px-2 py-1 text-xs",children:"SELECT label, measure FROM table"}),e.jsxs("ul",{className:"ml-6 list-disc text-xs [&>li]:mt-2",children:[e.jsx("li",{children:"label - category"}),e.jsx("li",{children:"measure - number"})]}),e.jsxs("div",{children:["See ",e.jsx("a",{target:"_blank",onClick:r=>r.stopPropagation(),className:"text-blue-700",href:"https://docs.semaphor.cloud/concepts/visuals#pie-chart",children:"example"})," in the docs."]})]})})]}),e.jsxs(s.AccordionItem,{value:"item-2",children:[e.jsx(s.AccordionTrigger,{children:"Settings"}),e.jsxs(s.AccordionContent,{className:"space-y-4 px-2",children:[t==="range"&&e.jsx(Te,{}),t!=="text"&&e.jsx(Ge,{}),t==="text"&&e.jsx(Pt,{})]})]}),!["range","text"].includes(t)&&e.jsxs(s.AccordionItem,{value:"item-3",children:[e.jsx(s.AccordionTrigger,{children:"Filters"}),e.jsxs(s.AccordionContent,{className:"space-y-4 px-2",children:[e.jsx(le,{}),e.jsx(xe,{})]})]})]})})}function Gt(){const t=s.useEditorStore(r=>{var o,l;return(l=(o=r==null?void 0:r.card)==null?void 0:o.preferences)==null?void 0:l.sortChart}),{setSortChart:n}=s.useEditorActions();function a(){return e.jsxs("div",{className:"space-y-2",children:[e.jsx(s.Label,{children:"Sort"}),e.jsx(ee,{className:"h-8",label:"Sort Chart",options:[{label:"None",value:"none"},{label:"ASC",value:"asc"},{label:"DESC",value:"desc"}],value:t||"none",onValueChange:r=>{n(r)}})]})}return e.jsx("div",{className:"space-y-6 px-6 py-2",children:e.jsxs(s.Accordion,{defaultValue:["item-2"],type:"multiple",children:[e.jsxs(s.AccordionItem,{value:"item-1",children:[e.jsx(s.AccordionTrigger,{children:"Stacked Chart"}),e.jsxs(s.AccordionContent,{className:"space-y-4 font-mono text-xs",children:[e.jsx("div",{className:"rounded bg-muted px-2 py-1 text-xs",children:"SELECT x-axis, stack-by, y-axis FROM table"}),e.jsxs("ul",{className:"ml-6 list-disc text-xs [&>li]:mt-2",children:[e.jsx("li",{children:"x-axis - category"}),e.jsx("li",{children:"stack by - category"}),e.jsx("li",{children:"y-axis - number"})]}),e.jsxs("div",{children:["See ",e.jsx("a",{target:"_blank",onClick:r=>r.stopPropagation(),className:"text-blue-700",href:"https://docs.semaphor.cloud/concepts/visuals#stacked-chart",children:"example"})," in the docs."]})]})]}),e.jsxs(s.AccordionItem,{value:"item-2",children:[e.jsx(s.AccordionTrigger,{children:"Settings"}),e.jsxs(s.AccordionContent,{className:"space-y-4 px-2",children:[e.jsx(Te,{}),a(),e.jsx(_s,{})]})]}),e.jsxs(s.AccordionItem,{value:"item-3",children:[e.jsx(s.AccordionTrigger,{children:"Filters"}),e.jsxs(s.AccordionContent,{className:"space-y-4 px-2",children:[e.jsx(le,{}),e.jsx(xe,{})]})]})]})})}function $t({}){const t=s.useEditorStore(r=>{var o;return(o=r.card)==null?void 0:o.preferences}),n=s.useEditorStore(r=>r.actions.setCardPreferences),a=r=>{n({...t,allowDownload:r})};return e.jsxs("div",{className:"space-y-6 px-6 py-2",children:[e.jsx(s.Accordion,{defaultValue:["item-3"],type:"multiple",children:e.jsxs(s.AccordionItem,{value:"item-3",children:[e.jsx(s.AccordionTrigger,{children:"Filters"}),e.jsxs(s.AccordionContent,{className:"space-y-4 px-2",children:[e.jsx(le,{}),e.jsx(xe,{})]})]})}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(s.Checkbox,{onCheckedChange:a,id:"allow-download"}),e.jsx("label",{htmlFor:"allow-download",className:"text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70",children:"Allow Download"})]})]})}const Qt=e.jsxs("div",{className:"space-y-4 font-mono text-xs",children:[e.jsx("div",{className:"rounded bg-muted px-2 py-1 text-xs",children:"SELECT dimension, cohort, metric FROM table"}),e.jsxs("div",{children:["See ",e.jsx("a",{target:"_blank",onClick:t=>t.stopPropagation(),className:"text-blue-700",href:"https://docs.semaphor.cloud/concepts/visuals#pyramid-chart",children:"example"})," in the docs."]})]}),Ut=e.jsxs("div",{className:"space-y-4 font-mono text-xs",children:[e.jsx("div",{className:"rounded bg-muted px-2 py-1 text-xs",children:"SELECT y-axis, label, range-from, range-to, range-value FROM table"}),e.jsxs("div",{children:["See ",e.jsx("a",{target:"_blank",onClick:t=>t.stopPropagation(),className:"text-blue-700",href:"https://docs.semaphor.cloud/concepts/visuals#range-charts",children:"example"})," in the docs."]})]}),Jt=e.jsxs("div",{className:"space-y-4 font-mono text-xs",children:[e.jsx("div",{className:"rounded bg-muted px-2 py-1 text-xs",children:"SELECT text FROM table limit 1"}),e.jsxs("div",{children:["See ",e.jsx("a",{target:"_blank",onClick:t=>t.stopPropagation(),className:"text-blue-700",href:"https://docs.semaphor.cloud/concepts/visuals#text-visual",children:"example"})," in the docs."]})]});function Kt(){const t=s.useEditorStore(a=>a.card.type);function n(a){switch(a){case"stackedBar":case"stackedLine":return e.jsx(Gt,{});case"pyramid":return e.jsx(we,{docContent:Qt,cardType:a});case"kpi":return e.jsx(Rt,{});case"line":case"bar":return e.jsx(Tt,{cardType:a});case"range":return e.jsx(we,{docContent:Ut,cardType:a});case"pie":case"doughnut":case"polarArea":case"radar":return e.jsx(we,{cardType:a});case"bubble":case"scatter":return e.jsx(At,{cardType:a});case"table":return e.jsx($t,{cardType:a});case"text":return e.jsx(we,{docContent:Jt,cardType:a,suffix:"Visual"});case"map":return e.jsx(Ht,{});case"custom":return e.jsx(kt,{});default:return e.jsx(Ft,{})}}return e.jsx(s.ScrollArea,{className:"h-full w-full text-sm",children:n(t)})}function Wt(){const t=s.useEditorStore(n=>n.isShowingVisual);return e.jsxs(s.ResizablePanelGroup,{direction:"vertical",className:"min-h-[250px] min-w-full max-w-lg",children:[e.jsx(s.ResizablePanel,{role:"query-section",className:"flex",minSize:20,defaultSize:40,children:e.jsx(pt,{})}),e.jsx(s.ResizableHandle,{withHandle:!0,className:"border"}),e.jsx(s.ResizablePanel,{className:"pb-1",role:"visual-section",minSize:0,defaultSize:60,children:t?e.jsxs(s.ResizablePanelGroup,{direction:"horizontal",children:[e.jsx(e.Fragment,{children:e.jsx(s.ResizablePanel,{className:"flex min-w-[275px]",minSize:20,defaultSize:25,maxSize:30,children:e.jsx(Kt,{})})}),e.jsx(s.ResizableHandle,{className:"border"}),e.jsx(s.ResizablePanel,{minSize:40,defaultSize:75,maxSize:100,children:e.jsx(Ke,{})})]}):e.jsx(Ke,{})})]})}function Yt({authToken:t,onSave:n,onClose:a}){s.useDashboardStore(i=>i.themeStyle);const r=s.useEditorStore(i=>i.actions.setOnSave),o=s.useEditorStore(i=>i.actions.setOnClose),l=s.useDashboardStore(i=>i.actions.setAuthToken);return w.useEffect(()=>{n&&r(n),a&&o(a)},[n,r,a,o]),w.useEffect(()=>{t&&t.accessToken&&l(t)},[t,l]),e.jsx(s.ErrorBoundary,{FallbackComponent:s.Fallback,children:e.jsxs(s.EditorPanel,{style:{},className:"rounded-none",role:"editor-panel",children:[e.jsx(s.EditorAside,{className:"rounded-none border-r-[1.5px]",children:e.jsx(ws,{})}),e.jsx(s.EditorMain,{children:e.jsx(Wt,{})})]})})}function Xt(){s.useDashboardStore(i=>i.selectedCardId);const t=s.useDashboardStore(i=>i.selectedSheetId),{setIsVisualEditing:n}=s.useDashboardStore(i=>i.actions),a=s.useDashboardStore(i=>i.isVisualEditing),r=s.useDashboardStore(i=>i.actions.updateFrame);function o(i){t&&(r(t,i),n(!1))}function l(){n(!1)}return e.jsx("div",{role:"editor-container",className:s.cn("flex grow",{"max-h-0 overflow-hidden":!a}),children:e.jsx(Yt,{onSave:o,onClose:l})})}function Zt(){s.useEditorStore(i=>i.selectedConnectionId),s.useEditorStore(i=>i.selectedDatamodelId);const t=s.useEditorStore(i=>i.selectedDatabaseName);s.useEditorStore(i=>i.selectedSchemaName);const n=s.useEditorStore(i=>i.selectedTableName),a=s.useDashboardStore(i=>i.dashboard.filters)||[];s.useDashboardStore(i=>i.actions.addFilter),s.useDashboardStore(i=>i.actions.removeFilter),s.useDashboardStore(i=>i.actions.removeFilterValue);const{modelItems:r,columns:o}=ie(),{assignFilter:l}=Bs();return e.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 d=a==null?void 0:a.find(c=>c.column===s.fmt(i.column_name)&&c.table===n&&c.database===t);return e.jsx("div",{onClick:()=>l(i),className:s.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":d}),children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Ns,{column:i}),e.jsx("span",{children:i.column_name})]})},i.column_name)})})}function ea(){s.useDashboardStore(n=>n.showFilters);const t=s.useDashboardStore(n=>n.actions.setShowFilters);return e.jsxs("section",{className:"relative flex grow flex-col border-l px-4",children:[e.jsxs("div",{className:"mt-4 flex items-center justify-between gap-2 px-3",children:[e.jsx(s.Label,{className:"text-lg",children:"Filters"}),e.jsx(s.Button,{onClick:()=>t(!1),className:"h-7 w-7 p-0",variant:"ghost",children:e.jsx(s.Cross2Icon,{})})]}),e.jsx("div",{className:"flex grow",children:e.jsx(ws,{ColumnsComponent:()=>e.jsx(Zt,{})})})]})}function sa(){const t=s.useDashboardStore(a=>a.showFilters),n=s.useDashboardStore(a=>a.isVisualEditing);return e.jsxs("div",{role:"dashboard-plus-main",className:s.cn("",{"max-h-0 overflow-hidden":n,"flex grow":!n}),children:[e.jsx(s.DashboardTabs,{}),t&&e.jsx("div",{role:"filter-aside-container",className:"flex",children:e.jsx(ea,{})})]})}function ta(){const t=s.useDashboardStore(r=>r.dashboard),n=s.useDashboardStore(r=>r.actions.setDashboard),a=s.useDashboardStore(r=>r.showDashboardJSON);return s.useDashboardStore(r=>r.actions.setShowDashboardJSON),e.jsx("div",{className:s.cn(" p-2",{hidden:!a}),children:e.jsx(s.de,{onChange:r=>{if(r)try{JSON.parse(r),n(JSON.parse(r))}catch{}},defaultLanguage:"json",className:"h-[550px] overflow-y-auto ",value:JSON.stringify(t,null,2),options:{minimap:{enabled:!1},glyphMargin:!1,wordWrap:"on",scrollbar:{verticalScrollbarSize:0,horizontalScrollbarSize:0},fontSize:12,renderLineHighlight:"none"}})})}function aa({showControls:t=!1,showFooter:n=!0,...a}){return e.jsx(s.ErrorBoundary,{FallbackComponent:s.Fallback,children:e.jsxs(s.SemaphorContextProvider,{dashboardProps:a,children:[e.jsx(s.Te,{}),e.jsxs(s.UXProvider,{children:[e.jsx(ta,{}),e.jsxs(s.DashboardPanel,{...a,children:[t&&e.jsx(Ys,{}),e.jsx(Xt,{}),e.jsx(sa,{})]})]})]})})}exports.Box=Ye;exports.ChartArea=Xe;exports.ChartColumnIncreasing=Ie;exports.ChartLine=De;exports.ChartNoAxesGantt=Fe;exports.ChartPie=Me;exports.ChartScatter=Ve;exports.CircleX=Ze;exports.CopyPlus=es;exports.DashboardPlus=aa;exports.Database=ss;exports.EllipsisVertical=Re;exports.Eraser=ts;exports.Eye=ns;exports.EyeClosed=as;exports.Glasses=rs;exports.Hammer=os;exports.Hash=is;exports.House=ls;exports.Key=qe;exports.ListEnd=cs;exports.ListStart=ds;exports.ListX=us;exports.LoaderCircle=me;exports.Map=_e;exports.MessageSquareMore=hs;exports.Network=ms;exports.Pencil=Be;exports.Play=xs;exports.Plug2=ps;exports.Save=fs;exports.SelectComponent=he;exports.Shapes=He;exports.ShieldQuestion=gs;exports.Sigma=js;exports.SwatchBook=bs;exports.Tag=ys;exports.ToggleLeft=vs;exports.Type=Le;exports.User=Ss;exports.cleanCard=Cs;exports.getDashbaordStateWithoutData=Pe;exports.useEditorAside=ie;
245
+ Visual Query Syntax: ${rt}`,{data:E,isLoading:O,isFetching:h,isError:v,refetch:p}=s.useQuery({queryKey:["ai-query"],queryFn:()=>s.getRequest("https://semaphor.cloud/api/v1/ai",(c==null?void 0:c.accessToken)||"",{user_content:`userContent: ${M} ${x?C:""}`}),enabled:!1});function I(k){if(k.toLowerCase().includes("bar"))g("bar");else if(k.toLowerCase().includes("line"))g("line");else if(k.toLowerCase().includes("bubble"))g("bubble");else if(k.toLowerCase().includes("scatter"))g("scatter");else if(k.toLowerCase().includes("stacked"))g("stackedBar");else if(k.toLowerCase().includes("pie"))g("pie");else if(k.toLowerCase().includes("donut")||k.toLowerCase().includes("doughnut"))g("doughnut");else if(k.toLowerCase().includes("radar"))g("radar");else return g("bar"),!1;return!0}w.useEffect(()=>{E&&L(k=>[...k,{role:"ai",content:E.response}])},[E]),w.useEffect(()=>{const k=setTimeout(()=>{var V;d.current&&(d.current.scroll({top:d.current.scrollHeight,behavior:"smooth"}),(V=i.current)==null||V.focus())},100);return()=>clearTimeout(k)},[j]);function z(){a&&(L(k=>[...k,{role:"user",content:a}]),I(a)&&u(!0),r(""),p())}w.useEffect(()=>{o&&(z(),l(!1))},[o,l]);const R={fontFamily:"Arial, sans-serif",lineHeight:1.6,fontSize:15,width:"100%"},_={fontFamily:"monospace",fontSize:14,lineHeight:1.6},H={fontFamily:"Arial, sans-serif",lineHeight:1.6,fontSize:15,padding:"2px 0",marginLeft:20,listStyleType:"disc"},K={p:({node:k,...V})=>e.jsx("p",{style:R,...V}),code:({node:k,...V})=>e.jsx("code",{className:"rounded-sm bg-muted px-2 py-1 text-sm",...V}),pre:({node:k,...V})=>e.jsxs("pre",{className:"space-y-2 rounded-sm bg-muted/50 p-3",style:_,children:[e.jsx("code",{className:"whitespace-normal text-sm",children:V.children}),e.jsxs("div",{className:"flex justify-start gap-2",children:[e.jsx(s.Button,{onClick:B,size:"sm",variant:"outline",children:e.jsx(s.ClipboardCopyIcon,{})}),e.jsx(s.Button,{onClick:G=>{const F=B(G);F&&(n(!1),y(F),m(!0))},size:"sm",variant:"outline",children:e.jsx(s.PlayIcon,{})})]})]}),li:({node:k,...V})=>e.jsx("li",{style:H,...V})};function B(k){const V=k.currentTarget.closest("pre");if(!V)return;const G=V.textContent||V.innerText;return navigator.clipboard.writeText(G).then(()=>console.log("Text copied to clipboard")).catch(F=>console.error("Error in copying text: ",F)),G}function J(){return j==null?void 0:j.map((k,V)=>k.role==="user"?e.jsxs("div",{className:"flex items-start rounded-md bg-muted p-3 text-sm",children:[e.jsx(Ss,{className:"mr-2 h-5 w-5"}),e.jsx("div",{children:k.content})]},V):k.role==="ai"?e.jsx(s.Markdown,{className:"w-full overflow-auto py-1",components:K,children:E==null?void 0:E.response.replace(/DuckDB/gi,"Semaphor")},V):e.jsx("div",{},V))}return e.jsxs(s.Dialog,{open:t,onOpenChange:n,children:[e.jsx(s.DialogTrigger,{asChild:!0,children:e.jsx(s.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.jsxs(s.DialogContent,{className:"flex flex-col justify-between overflow-auto sm:max-w-[425px] md:max-h-[625px] md:min-w-[625px]",children:[e.jsxs(s.DialogHeader,{children:[e.jsx(s.DialogTitle,{children:"Assistant"}),e.jsx(s.DialogDescription,{children:"What can I help you with?"})]}),e.jsx("div",{ref:d,className:"h-[625px] w-full overflow-auto border-t border-t-muted",children:e.jsx("div",{className:"space-y-4 py-2 pr-3",role:"messages",children:J()})}),e.jsx("div",{children:e.jsxs("div",{className:"flex w-full items-center rounded-md border",children:[e.jsx(s.Textarea,{autoFocus:!0,ref:i,onKeyDown:k=>{k.key==="Enter"&&!k.shiftKey&&(k.preventDefault(),r(""),z())},placeholder:"Type your question here...",onFocus:k=>{const V=k.target,G=V.value.length;V.setSelectionRange(G,G)},className:s.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:O||h,value:a,onChange:k=>r(k.target.value)})," ",e.jsx(s.Button,{className:"h-8",size:"sm",variant:"ghost",onClick:z,children:!O&&!h?e.jsx(s.PaperPlaneIcon,{}):e.jsx(me,{className:"mr-2 h-4 w-4 animate-spin text-foreground/50"})})]})})]})]})}var Es={color:void 0,size:void 0,className:void 0,style:void 0,attr:void 0},Ue=w.createContext&&w.createContext(Es),it=["attr","size","title"];function lt(t,n){if(t==null)return{};var a=ct(t,n),r,o;if(Object.getOwnPropertySymbols){var l=Object.getOwnPropertySymbols(t);for(o=0;o<l.length;o++)r=l[o],!(n.indexOf(r)>=0)&&Object.prototype.propertyIsEnumerable.call(t,r)&&(a[r]=t[r])}return a}function ct(t,n){if(t==null)return{};var a={},r=Object.keys(t),o,l;for(l=0;l<r.length;l++)o=r[l],!(n.indexOf(o)>=0)&&(a[o]=t[o]);return a}function Ee(){return Ee=Object.assign?Object.assign.bind():function(t){for(var n=1;n<arguments.length;n++){var a=arguments[n];for(var r in a)Object.prototype.hasOwnProperty.call(a,r)&&(t[r]=a[r])}return t},Ee.apply(this,arguments)}function Je(t,n){var a=Object.keys(t);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(t);n&&(r=r.filter(function(o){return Object.getOwnPropertyDescriptor(t,o).enumerable})),a.push.apply(a,r)}return a}function ke(t){for(var n=1;n<arguments.length;n++){var a=arguments[n]!=null?arguments[n]:{};n%2?Je(Object(a),!0).forEach(function(r){dt(t,r,a[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(a)):Je(Object(a)).forEach(function(r){Object.defineProperty(t,r,Object.getOwnPropertyDescriptor(a,r))})}return t}function dt(t,n,a){return n=ut(n),n in t?Object.defineProperty(t,n,{value:a,enumerable:!0,configurable:!0,writable:!0}):t[n]=a,t}function ut(t){var n=ht(t,"string");return typeof n=="symbol"?n:String(n)}function ht(t,n){if(typeof t!="object"||t===null)return t;var a=t[Symbol.toPrimitive];if(a!==void 0){var r=a.call(t,n||"default");if(typeof r!="object")return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return(n==="string"?String:Number)(t)}function ks(t){return t&&t.map((n,a)=>w.createElement(n.tag,ke({key:a},n.attr),ks(n.child)))}function se(t){return n=>w.createElement(mt,Ee({attr:ke({},t.attr)},n),ks(t.child))}function mt(t){var n=a=>{var{attr:r,size:o,title:l}=t,i=lt(t,it),d=o||a.size||"1em",c;return a.className&&(c=a.className),t.className&&(c=(c?c+" ":"")+t.className),w.createElement("svg",Ee({stroke:"currentColor",fill:"currentColor",strokeWidth:"0"},a.attr,r,i,{className:c,style:ke(ke({color:t.color||a.color},a.style),t.style),height:d,width:d,xmlns:"http://www.w3.org/2000/svg"}),l&&w.createElement("title",null,l),t.children)};return Ue!==void 0?w.createElement(Ue.Consumer,null,a=>n(a)):n(Es)}function xt(t){return se({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:[]}]})(t)}function pt(){const[t,n]=w.useState({queryKey:[],queryData:null}),{theme:a}=s.useTheme(),r=s.useQueryClient(),o=w.useRef(),l=w.useRef(),[i,d]=w.useState(!1),[c,x]=w.useState(!1),[u,y]=w.useState(!1),[f,m]=w.useState(""),[g,j]=w.useState(!1),L=s.useDashboardStore(b=>b.selectedSheetId);s.useDashboardStore(b=>b.dashboard.baseQueries);const S=s.useEditorStore(b=>b.card),A=s.useDashboardStore(b=>b.theme),D=s.useEditorStore(b=>b.isShowingVisual);s.useDashboardStore(b=>b.onAcceptChanges);const M=s.useEditorStore(b=>b.selectedConnectionId),C=s.useEditorStore(b=>b.selectedDatabaseName),E=s.useEditorStore(b=>b.selectedDatamodelId),O=s.useEditorStore(b=>b.selectedSchemaName);s.useDashboardStore(b=>b.actions.updateFrameCard);const h=s.useEditorStore(b=>b.selectedTableName),v=s.useEditorStore(b=>b.card.sql),p=s.useEditorStore(b=>b.card.python),I=s.useEditorStore(b=>b.frame),z=s.useDashboardStore(b=>b.dashboard.filters),R=s.useDashboardStore(b=>b.filterValues),_=z==null?void 0:z.filter(b=>b.sheetId===L||!b.sheetId),H=R==null?void 0:R.filter(b=>(_==null?void 0:_.some(U=>U.id===b.filterId))||b.filterId.endsWith(L)),K=s.useEditorStore(b=>b.applyFilters),{setCardCustomCfg:B,setQueryResultColumns:J,setFilterValues:k,setCardSql:V,setCard:G,setCardPython:F,setQueryError:T,setPythonStdOut:$,setCardPreferences:q}=s.useEditorStore(b=>b.actions),P=s.useEditorStore(b=>b.onSave),W=s.useEditorStore(b=>b.actions.setApplyFilters),te=s.useEditorStore(b=>b.onClose),ce=s.useEditorStore(b=>b.actions.setSqlGen),ae=s.useEditorStore(b=>b.runSql),re=s.useEditorStore(b=>b.actions.setRunSql);s.useEditorStore(b=>b.actions.setCardCfg);const ne=s.useEditorStore(b=>b.actions.setIsSqlRunning),{data:Q,isLoading:X,isFetching:Z,isSuccess:ye,isError:de,error:pe,queryKey:fe,refetch:ue}=s.useDashboardCardQuery(S);w.useEffect(()=>{if(Q&&(Q.rowLimitExceeded&&s.Jt.error("Row limit (10,000) exceeded. Refine your query.",{position:"top-center",richColors:!0}),$((Q==null?void 0:Q.output)||""),Q.records.length>0)){const{dimensionKeys:b}=s.getKeys(Q.records);J(b)}},[Q,J,$]),w.useEffect(()=>{(X||Z)&&ne(!0),(de||ye)&&ne(!1),de?(T(pe.message),J([]),$("")):T("")},[X,Z,Q,$,de,ye,ne,J,T,pe]),w.useEffect(()=>{ae&&(ue(),re(!1))},[ae,ue,re]);function Ae(){const b=r.getQueryData(fe);t.queryData||n({queryKey:fe,queryData:b}),r.setQueryData(fe,null),V(""),ce({}),B(""),q({})}const ge=b=>{l.current=b};function ve(b,U){if(b.length===0)return"";if(U){const oe=b.find(Y=>Y.id===U);if(oe){const Y=oe.tabTitle;if(Y=="All__Header")return b[0].id;if(Y&&Y.endsWith("__Header")){const Ps=Y.split("__")[0],$e=b.find(Gs=>Gs.tabTitle===Ps);return $e?$e.id:b[0].id}return U}}return b[0].id}function Se(){let b=v;v&&!v.includes("{{")&&(b=et(v),V(b));const U={...S,lastSelectedSchema:O,lastSelectedDatamodelId:E,lastSelectedDatabase:C,lastSelectedTable:h,connectionId:M,type:D?S.type:"table",sql:b,customCfg:D?S.customCfg:null},oe=I.cards.map(Oe=>Oe.id===S.id?U:Oe),Y={...I,cards:oe,activeCardId:ve(oe,I.activeCardId)};P==null||P(Y)}function Ce(){const{queryKey:b,queryData:U}=t;b&&U&&r.setQueryData(b,U),te==null||te()}w.useEffect(()=>{const b=o.current,U=l.current;if(b){const oe=window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light",Y=A==="system"?oe:A;b.editor.defineTheme("default",{base:Y==="light"?"vs":"vs-dark",inherit:!0,rules:[],colors:{"editor.background":Y==="light"?"#ffffff":s.getCssVariableValue("--semaphor-background")}}),b.editor.setTheme("default")}return U&&b&&U.addCommand(b.KeyMod.Shift|b.KeyCode.Enter,function(){return console.log("Executing query..."),ue(),!1}),()=>{}},[a,A,o.current]);function je(b){o.current=b}function N(){return e.jsxs(e.Fragment,{children:[c&&e.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.jsxs("div",{className:"w-[99%]",children:[e.jsxs("div",{className:"flex items-center gap-2 pt-3",children:[e.jsx(tt,{checked:K,onCheckedChange:()=>W(!K),text:"Apply Filters"}),e.jsx(nt,{}),H&&c&&e.jsx(s.Cross2Icon,{onClick:()=>x(!1),className:"bg-background/50 text-foreground/50 hover:cursor-pointer hover:text-foreground"})]}),e.jsx(s.Ft,{theme:"default",onChange:b=>{if(b)try{JSON.parse(b),k(JSON.parse(b))}catch{}},defaultLanguage:"json",className:"mt-1 min-h-[220px]",value:JSON.stringify(H,null,2),options:{readOnly:!0,minimap:{enabled:!1},lineNumbers:"off",glyphMargin:!1,wordWrap:"on",scrollbar:{verticalScrollbarSize:0,horizontalScrollbarSize:0},fontSize:12,renderLineHighlight:"none"}})]})}),H&&!c&&e.jsx(s.Filter,{onClick:()=>x(!0),className:s.cn("absolute bottom-4 right-6 h-3 w-3 text-foreground/50 hover:cursor-pointer hover:text-foreground",{"font-bold text-red-800":K})})]})}function Hs(){return e.jsxs(s.ResizablePanelGroup,{className:"flex grow pb-1",direction:"vertical",role:"editor-resizable-group",children:[e.jsxs(s.ResizablePanel,{id:"1",order:1,defaultSize:i?20:100,className:"relative flex grow",children:[e.jsx("div",{role:"sql-container",className:"relative flex w-[99%]",children:e.jsx(s.Ft,{theme:"default",className:"pt-3",onChange:b=>{V(b)},value:v,options:{minimap:{enabled:!1},wordWrap:"on",scrollbar:{verticalScrollbarSize:0,horizontalScrollbarSize:0},fontSize:14,renderLineHighlight:"none"},defaultLanguage:"sql",beforeMount:je,onMount:ge})}),i&&e.jsx("code",{className:"absolute right-6 top-3 text-sm text-muted-foreground/70",children:"sql"})]}),i&&e.jsxs(e.Fragment,{children:[e.jsx(s.ResizableHandle,{withHandle:!0,className:"border"}),e.jsxs(s.ResizablePanel,{id:"2",order:2,defaultSize:80,className:"relative flex grow",children:[e.jsx("div",{role:"python-container",className:"relative flex w-[99%] pt-0",children:e.jsx(s.Ft,{className:"pt-3",theme:"default",onChange:b=>{F(b&&b.trim()||"")},value:p||s.PYTHON_DEFAULT_CODE,options:{minimap:{enabled:!1},wordWrap:"on",scrollbar:{verticalScrollbarSize:0,horizontalScrollbarSize:0},fontSize:14,renderLineHighlight:"none"},defaultLanguage:"python",beforeMount:je,onMount:ge})}),e.jsx("code",{className:"absolute right-6 top-3 text-sm text-muted-foreground/70",children:"python"})]})]})]})}return e.jsxs("section",{role:"editor-section",className:"flex grow flex-col justify-end",children:[e.jsxs("div",{role:"sql-editor",className:"relative flex grow justify-between overflow-y-scroll",children:[Hs(),N()]}),e.jsxs("div",{role:"editor-controls",className:"item-center flex flex-wrap justify-between gap-2 px-6 py-4",children:[e.jsxs("div",{className:"flex grow items-center gap-2",children:[e.jsxs(s.Button,{title:"Shift + Enter",disabled:X||Z,onClick:()=>{ue()},className:"shrink-0",size:"sm",variant:"outline",children:[X||Z?e.jsx(me,{className:"mr-2 h-4 w-4 animate-spin text-foreground/50"}):e.jsx(xs,{className:"mr-2 h-4 w-4"}),"Run"]}),de&&e.jsx(st,{error:pe.message,setShowAIDialog:y,setTriggerAIRun:j,setUserInputforAI:m}),e.jsxs(s.Button,{onClick:Ae,className:"",size:"sm",variant:"outline",children:[e.jsx(ts,{className:"mr-2 size-4"}),"Clear"]}),e.jsx(s.Toggle,{pressed:i,onPressedChange:b=>d(b),className:"",size:"sm",variant:"outline",children:e.jsx(xt,{className:"size-4 text-foreground/70"})}),e.jsx(ot,{open:u,setOpen:y,userInput:f,triggerAIRun:g,setTriggerAIRun:j,setUserInput:b=>m(b)})]}),e.jsxs("div",{className:"flex items-end gap-2",children:[e.jsxs(s.Button,{onClick:Se,size:"sm",variant:"outline",children:[e.jsx(s.Check,{className:"mr-2 size-4 font-bold text-green-600"}),"Accept"]}),e.jsxs(s.Button,{onClick:Ce,className:"w-full",size:"sm",variant:"outline",children:[e.jsx(s.Cross2Icon,{className:"mr-2 size-4"}),"Close"]})]})]})]})}function ft({data:t}){var i;const[n,a]=w.useState([]),o=Object.keys(t[0]).map(d=>({accessorKey:d,header:({column:c})=>{const x=c.getIsSorted();return e.jsx("div",{className:"flex gap-2",children:e.jsxs("div",{className:"flex cursor-pointer items-center",onClick:()=>c.toggleSorting(c.getIsSorted()==="asc"),children:[d,x==="asc"?e.jsx(s.TriangleUpIcon,{className:"ml-2 h-5 w-5"}):x==="desc"?e.jsx(s.TriangleDownIcon,{className:"ml-2 h-5 w-5"}):null]})})}})),l=s.useReactTable({data:t,columns:o,getCoreRowModel:s.getCoreRowModel(),getPaginationRowModel:s.getPaginationRowModel(),onSortingChange:a,getSortedRowModel:s.getSortedRowModel(),manualPagination:!0,state:{sorting:n}});return e.jsxs(s.Table$1,{children:[e.jsx(s.TableHeader,{children:l.getHeaderGroups().map(d=>e.jsx(s.TableRow,{children:d.headers.map(c=>e.jsx(s.TableHead,{className:"sticky top-0 bg-muted",children:c.isPlaceholder?null:s.flexRender(c.column.columnDef.header,c.getContext())},c.id))},d.id))}),e.jsx(s.TableBody,{children:(i=l.getRowModel().rows)!=null&&i.length?l.getRowModel().rows.map(d=>e.jsx(s.TableRow,{className:"whitespace-nowrap py-2","data-state":d.getIsSelected()&&"selected",children:d.getVisibleCells().map(c=>e.jsx(s.TableCell,{children:s.flexRender(c.column.columnDef.cell,c.getContext())},c.id))},d.id)):e.jsx(s.TableRow,{children:e.jsx(s.TableCell,{colSpan:o.length,className:"h-24 text-center",children:"No results."})})})]})}function gt({card:t}){var f,m,g,j,L,S,A,D,M,C;const{authToken:n}=s.useSemaphorContext(),a=s.getTokenParams(n==null?void 0:n.accessToken),r=s.useDashboardStore(E=>E.themeStyle),o={colors:((m=(f=r==null?void 0:r.chart)==null?void 0:f.dataset)==null?void 0:m.backgroundColor)||[]};(g=t.customCardPreferences)!=null&&g.inputData;const{getCard:l}=s.useCustomVisual(((j=t.customCardPreferences)==null?void 0:j.url)||""),i=((L=t.customCardPreferences)==null?void 0:L.visualType)||"single",d=s.useEditorStore(E=>E.frame);s.useEditorActions();const{data:c}=s.useDashboardCardQuery(t);if(!((S=t.customCardPreferences)!=null&&S.componentName))return null;const x=l((A=t.customCardPreferences)==null?void 0:A.componentName),u=E=>{console.log("data",E),t.customCardPreferences},y=Object.keys(((D=t.customCardPreferences)==null?void 0:D.dataInputCardIds)||{}).map(E=>{var v,p,I;const O=(p=(v=t.customCardPreferences)==null?void 0:v.dataInputCardIds)==null?void 0:p[E].cardId,h=(I=d==null?void 0:d.cards)==null?void 0:I.find(z=>z.id===O);return h||null});return e.jsx("div",{className:"semaphor-custom mb-3 flex grow basis-0 flex-col space-y-2 overflow-y-auto",children:e.jsxs(w.Suspense,{fallback:e.jsx(e.Fragment,{}),children:[x&&i==="single"&&e.jsx(x,{params:a,theme:o,settings:(M=t.customCardPreferences)==null?void 0:M.settings,onDataChange:u,data:(c==null?void 0:c.records)||[]}),x&&i==="multiple"&&e.jsx("div",{className:"flex flex-col gap-2",children:e.jsx(x,{theme:o,onDataChange:u,settings:y.map(E=>{var O;return(O=E==null?void 0:E.customCardPreferences)==null?void 0:O.settings}),data:y.map(E=>(E==null?void 0:E.data)||[])})})]},(C=t.customCardPreferences)==null?void 0:C.componentName)})}function Is({className:t,...n}){var m,g;const a=s.useEditorStore(j=>j.card),r=((m=a.customCardPreferences)==null?void 0:m.showCardHeader)??!0,o=s.useEditorStore(j=>j.frame),l=s.useDashboardStore(j=>j.dashboard.filters);s.useEditorStore(j=>j.actions.setRunSql);const{updateFilter:i}=s.useDashboardActions(),d=l==null?void 0:l.find(j=>j.id===o.filterId),{data:c}=s.useDashboardCardQuery(a),{setCard:x}=s.useEditorActions(),{data:u}=s.useTopoJson(a);if(!a.id)return null;let y;c!=null&&c.records&&(c==null?void 0:c.records.length)>0&&(y=s.createChartConfig({data:c==null?void 0:c.records,cardType:a.type,cfg:a.cfg,customCfg:a.customCfg,preferences:a.preferences,topoJson:u}));function f(j){return e.jsx(gt,{card:j})}return e.jsxs(s.Card,{role:"editor-visual-card",className:s.cn("relative flex h-full flex-col rounded-none",t),...n,children:[r&&e.jsxs(s.CardHeader,{className:"flex flex-row items-start justify-between py-4",children:[e.jsxs("div",{children:[e.jsx(s.Editable,{text:a.title,onSave:j=>x({...a,title:j}),children:e.jsx("div",{className:"flex items-center gap-5",children:e.jsx(s.CardTitle,{className:"text-base",children:a.title||"Edit title..."})})},a.title),e.jsx(s.Editable,{text:a.description||"",onSave:j=>x({...a,description:j}),children:e.jsx(s.CardDescription,{children:a.description||"Edit description..."})},a.description)]}),d&&e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(s.Editable,{className:"my-1",text:d.title||d.column,onSave:j=>i({...d,title:j}),children:e.jsx(s.Label,{children:d.title})}),s.getFilterComponent(d)]})]}),e.jsxs(s.CardContent,{className:"flex grow flex-col",children:[a.type==="custom"&&f(a),!["table","custom"].includes(a.type)&&y&&e.jsx(s.ChartJsVisual,{cfg:y},JSON.stringify(y)+JSON.stringify(a.preferences)+((g=a==null?void 0:a.preferences)==null?void 0:g.customVisualCode)),a.type==="table"&&(c==null?void 0:c.records)&&(c==null?void 0:c.records.length)>0&&e.jsx(s.ScrollArea$1,{className:"flex min-h-0 flex-1 grow basis-0",children:e.jsx(s.TableVisual,{card:a,data:c==null?void 0:c.records})})]})]})}function jt(){const[t,n]=w.useState(!1),[a,r]=w.useState(""),[o,l]=w.useState(""),[i,d]=w.useState(""),[c,x]=w.useState(""),u=s.useEditorStore(C=>C.card),y=s.useEditorStore(C=>C.card.customCfg),{data:f}=s.useDashboardCardQuery(u),{data:m}=s.useTopoJson(u),{setCardCustomCfg:g,setCustomVisualCode:j}=s.useEditorActions();function L(C){var h,v;const E={...C,data:{...C==null?void 0:C.data,datasets:(v=(h=C==null?void 0:C.data)==null?void 0:h.datasets)==null?void 0:v.map(p=>({...p,data:[]}))}};return JSON.stringify(E,null,1)}function S(){var E,O;if(!(f!=null&&f.records)||(f==null?void 0:f.records.length)===0)return;const C=s.createChartConfig({data:f==null?void 0:f.records,cardType:u.type,cfg:u.cfg,preferences:u.preferences,topoJson:m});C&&(r(JSON.stringify(C,null,1)),(E=u==null?void 0:u.preferences)!=null&&E.customVisualCode&&d((O=u==null?void 0:u.preferences)==null?void 0:O.customVisualCode),y&&l(JSON.stringify(y,null,1)))}function A(){if(i&&j(i),!!o)try{const C=JSON.parse(o);return C?(g(C),x(""),l(""),C):void 0}catch(C){console.log(C),x("Invalid JSON")}}function D(){l(""),g(null)}function M(){let C;if(y){const E=s._.cloneDeep(u.cfg),O=s._.merge(E,y);return C=L(O),C}return a?(C=L(JSON.parse(a)),C):""}return e.jsxs(s.Dialog,{open:t,onOpenChange:n,children:[e.jsx(s.DialogTrigger,{asChild:!0,children:e.jsx(s.Button,{onClick:S,className:` ${y&&"border-foreground/50 dark:border-foreground/70"}`,size:"sm",variant:"outline",children:e.jsx(s.Settings,{className:"h-4 w-4"})})}),e.jsxs(s.DialogContent,{className:"max-h-[70vh] min-h-[70vh] overflow-auto sm:min-w-[900px] lg:min-w-[1200px]",children:[e.jsxs(s.DialogHeader,{className:"",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(s.DialogTitle,{children:"Customize Card"}),e.jsxs(s.Tooltip,{children:[e.jsx(s.TooltipTrigger,{children:e.jsx(qe,{onClick:()=>{navigator.clipboard.writeText(u.id)},className:"size-3 cursor-pointer text-muted-foreground/70 transition-colors hover:text-muted-foreground"})}),e.jsx(s.TooltipContent,{side:"right",align:"center",children:e.jsx("p",{className:"text-xs",children:"Copy Card ID"})})]})]}),e.jsxs(s.DialogDescription,{children:["See the configuration options and documentation",e.jsx("a",{target:"_blank",className:"ml-1 text-blue-500 underline",href:"https://www.chartjs.org/docs/latest/samples/bar/vertical.html",children:"here."})]})]}),e.jsxs("div",{className:"flex grow gap-2",children:[e.jsx(s.ErrorBoundary,{FallbackComponent:s.FallbackEditorCard,children:e.jsx(Is,{className:"w-1/2 rounded shadow-none"})}),e.jsxs(s.Tabs,{defaultValue:"custom-config",className:"flex w-1/2 flex-col",children:[e.jsxs(s.TabsList,{className:"justify-start rounded-sm rounded-b-none border border-b-0",children:[e.jsxs(s.TabsTrigger,{value:"custom-config",children:[y&&e.jsx(s.CheckIcon,{className:"mr-1 h-5 w-5 text-green-600"}),y?"Custom Config":"Default Config"]}),e.jsx(s.TabsTrigger,{className:"",value:"output",children:"Output"}),e.jsx(s.TabsTrigger,{className:"",value:"custom-code",children:"Custom Code"})]}),e.jsx(s.TabsContent,{className:"bg-red-x mt-0 grow rounded-b border border-t-0 p-2",value:"output",children:e.jsx(s.Textarea,{disabled:!0,value:a,className:"h-full resize-none border-none font-mono focus-visible:ring-0 focus-visible:ring-offset-0"})}),e.jsx(s.TabsContent,{className:"mt-0 grow rounded-b border border-t-0",value:"custom-config",children:e.jsx(s.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:M(),onChange:C=>l(C)})}),e.jsx(s.TabsContent,{className:"mt-0 grow rounded-b border border-t-0",value:"custom-code",children:e.jsx(s.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:C=>d(C||"")})})]})]}),e.jsxs(s.DialogFooter,{className:"flex items-center",children:[e.jsx(s.Label,{className:"mr-2 text-red-500",children:c}),e.jsx(s.Button,{disabled:!y,onClick:D,variant:"outline",children:"Reset"}),e.jsx(s.Button,{onClick:A,variant:"outline",children:"Apply"}),e.jsx(s.Button,{onClick:()=>n(!1),variant:"outline",children:"Close"})]})]})]})}function Ds(t){return se({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:[]}]})(t)}function Ls(t){return se({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:[]}]})(t)}function Ts(t){return se({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:[]}]})(t)}function As(t){return se({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:[]}]})(t)}function Os(t){return se({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:[]}]})(t)}function zs(t){return se({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:[]}]})(t)}function Fs(t){return se({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:[]}]})(t)}function Ms(t){return se({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:[]}]})(t)}function Vs(t){const[n,a]=w.useState(null);return w.useEffect(()=>{t&&(async()=>{const l=(await Promise.resolve().then(()=>require("./lucide-react-NFP4u5cT.js")))[t];a(l)})()},[t]),n}function Rs(){const{authToken:t}=s.useSemaphorContext(),{data:n,isLoading:a,isFetching:r,isError:o}=s.useQuery({queryKey:["plugins",t==null?void 0:t.accessToken],queryFn:()=>s.getPlugins(t==null?void 0:t.accessToken)});return{data:n,isLoading:a,isFetching:r,isError:o}}function bt({onChartTypeChange:t}){const[n,a]=w.useState([]),{data:r}=Rs();return w.useEffect(()=>{(async()=>{var l;if(r){const d=(await Promise.all((l=r==null?void 0:r.plugins)==null?void 0:l.map(async c=>(await s.loadManifest(c.value)).visuals.map(y=>({name:y.name,icon:y.icon,url:c.value}))))).flat();a(d)}})()},[r]),n.length===0?null:e.jsxs(e.Fragment,{children:[e.jsx(s.Separator,{className:"my-2"}),e.jsx("div",{className:"grid grid-cols-4 place-items-center",children:n.map((o,l)=>e.jsx(yt,{text:o.name,onClick:()=>t("custom",o),icon:o.icon},o.url+o.name+l))})]})}const yt=({text:t,icon:n,onClick:a})=>{const r=Vs(n||""),o=t.charAt(0).toUpperCase();return e.jsx(s.Button,{onClick:a,title:t,variant:"ghost",children:r?e.jsx(r,{className:"h-4 w-4"}):o})};function vt(){var u,y;const[t,n]=w.useState(!1),a=s.useEditorStore(f=>f.card),r=a.type,{setCardType:o,setCardPreferences:l,setChartOrientation:i}=s.useEditorStore(f=>f.actions),{setCardCustomCfg:d,setCustomCardPreferences:c}=s.useEditorActions();function x(f,m){d(null),l({}),o(f),m&&c({type:"component",visualType:"single",url:m.url,componentName:m.name,icon:m.icon}),n(!1)}return e.jsxs(s.Popover,{open:t,onOpenChange:n,children:[e.jsx(s.PopoverTrigger,{asChild:!0,children:e.jsx(s.Button,{size:"sm",variant:"outline",children:e.jsx(St,{className:"h-4 w-4",chartType:r,customIcon:(u=a.customCardPreferences)==null?void 0:u.icon,componentName:(y=a.customCardPreferences)==null?void 0:y.componentName})})}),e.jsxs(s.PopoverContent,{className:"w-50",children:[e.jsxs("div",{className:"grid grid-cols-4 place-items-center",children:[e.jsx(s.Button,{onClick:()=>x("bar"),className:"font-normal",variant:"ghost",children:e.jsx(Ie,{className:"size-5"})}),e.jsx(s.Button,{onClick:()=>x("line"),variant:"ghost",children:e.jsx(De,{className:"size-5"})}),e.jsx(s.Button,{onClick:()=>x("stackedBar"),variant:"ghost",children:e.jsx(zs,{className:"size-5",strokeWidth:0})}),e.jsx(s.Button,{onClick:()=>x("stackedLine"),variant:"ghost",children:e.jsx(Os,{className:"size-5",strokeWidth:0})}),e.jsx(s.Button,{onClick:()=>x("scatter"),variant:"ghost",children:e.jsx(Ve,{className:"size-5"})}),e.jsx(s.Button,{onClick:()=>x("bubble"),variant:"ghost",children:e.jsx(As,{className:"size-4"})}),e.jsx(s.Button,{onClick:()=>x("pie"),variant:"ghost",children:e.jsx(Me,{className:"size-5"})}),e.jsx(s.Button,{onClick:()=>x("doughnut"),variant:"ghost",children:e.jsx(Ls,{className:"size-5",strokeWidth:1})}),e.jsx(s.Button,{onClick:()=>x("radar"),variant:"ghost",children:e.jsx(Ds,{className:"size-5 font-extralight",strokeWidth:.5})}),e.jsx(s.Button,{onClick:()=>x("polarArea"),variant:"ghost",children:e.jsx(Ts,{className:"size-5"})}),e.jsx(s.Button,{onClick:()=>x("pyramid"),variant:"ghost",children:e.jsx(Ms,{className:"size-5"})}),e.jsx(s.Button,{onClick:()=>x("range"),variant:"ghost",children:e.jsx(Fe,{className:"size-5"})}),e.jsx(s.Button,{onClick:()=>x("table"),variant:"ghost",children:e.jsx(s.Table,{className:"size-5"})}),e.jsx(s.Button,{onClick:()=>x("kpi"),variant:"ghost",children:e.jsx(Fs,{className:"size-6"})}),e.jsx(s.Button,{onClick:()=>x("text"),variant:"ghost",children:e.jsx(Le,{className:"size-4"})}),e.jsx(s.Button,{onClick:()=>x("map"),variant:"ghost",children:e.jsx(_e,{className:"size-4"})}),e.jsx(s.Button,{onClick:()=>x("custom"),variant:"ghost",children:e.jsx(He,{className:"size-4"})})]}),e.jsx(bt,{onChartTypeChange:x})]})]})}function St({chartType:t,className:n,customIcon:a,componentName:r}){const o=Vs(a||"");switch(t){case"bar":return e.jsx(Ie,{className:n});case"line":return e.jsx(De,{className:n});case"pie":return e.jsx(Me,{className:n});case"radar":return e.jsx(Ds,{className:n});case"scatter":return e.jsx(Ve,{className:n});case"bubble":return e.jsx(As,{className:n});case"doughnut":return e.jsx(Ls,{className:n});case"stackedBar":return e.jsx(zs,{className:"size-4 text-foreground/70"});case"stackedLine":return e.jsx(Os,{className:"size-4 text-foreground/70"});case"polarArea":return e.jsx(Ts,{className:n});case"pyramid":return e.jsx(Ms,{className:n});case"range":return e.jsx(Fe,{className:n});case"kpi":return e.jsx(Fs,{className:n});case"text":return e.jsx(Le,{className:n});case"map":return e.jsx(_e,{className:n});case"custom":return a&&o?e.jsx(o,{className:n}):r?r==null?void 0:r.charAt(0).toUpperCase():e.jsx(He,{className:n});default:return e.jsx(s.Table,{className:n})}}function Ct(){var o;const t=s.useEditorStore(l=>l.card),n=((o=t.customCardPreferences)==null?void 0:o.showCardHeader)??!0,{setCustomCardPreferences:a}=s.useEditorActions(),r=l=>{t.customCardPreferences&&a({...t.customCardPreferences,showCardHeader:l===!0})};return e.jsxs(s.DropdownMenu,{children:[e.jsx(s.DropdownMenuTrigger,{asChild:!0,children:e.jsx(Re,{className:"size-4 cursor-pointer text-muted-foreground/70 transition-colors hover:text-muted-foreground"})}),e.jsxs(s.DropdownMenuContent,{align:"start",className:"w-40 text-muted-foreground",children:[e.jsx(s.DropdownMenuCheckboxItem,{checked:n,onCheckedChange:r,children:"Card Header"}),e.jsxs(s.DropdownMenuItem,{onClick:()=>{navigator.clipboard.writeText(t.id),s.Jt.success("Card ID copied to clipboard")},className:"cursor-pointer space-x-2",children:[e.jsx(qe,{className:"size-4"}),e.jsx("span",{children:"Copy Card ID"})]})]})]})}function Ke(){const t=s.useEditorStore(h=>h.frame),n=s.useEditorStore(h=>h.card),a=s.useEditorStore(h=>h.isShowingVisual),r=s.useEditorStore(h=>h.isSqlRunning),o=s.useEditorStore(h=>h.queryError),l=s.useEditorStore(h=>h.pythonStdOut),i=s.useEditorStore(h=>h.actions.setRunSql);s.useEditorStore(h=>h.onSave),s.useEditorStore(h=>h.onClose),s.useEditorStore(h=>h.actions.setCardSql),s.useEditorStore(h=>h.actions.setCardType),s.useEditorStore(h=>h.actions.setSqlGen);const{setFrame:d,setCard:c,updateCardInFrame:x}=s.useEditorActions(),{data:u,isLoading:y,isFetching:f}=s.useDashboardCardQuery(n);if(!n)return e.jsx(e.Fragment,{children:"No Active Card"});function m(){const h={connectionId:n.connectionId,id:s.v4(),title:"Title",description:"Description",preferences:{onClickFilter:[{columnIndex:0,expression:""}]},type:"bar",sql:"",data:[]};g(h)}function g(h){const v={...t,cards:[...t.cards,h],activeCardId:h.id};d(v),c(h)}function j(){const h={...n,id:s.v4(),title:`${n.title} Copy`,tabTitle:`${n.tabTitle} Copy`};g(h)}function L(h){const v=t.cards.filter(z=>z.id!==h),p=v[0],I={...t,cards:v,activeCardId:p.id};d(I),c(p)}function S(h){const v={...t,cards:t.cards.map(I=>I.id===n.id?n:I),activeCardId:h};d(v);const p=v.cards.find(I=>I.id===h);p.sql&&i(!0),c(p)}const A=(h,v)=>{console.log("handleDragStart",v),h.dataTransfer.setData("tabIndex",v.toString())},D=h=>{h.preventDefault()},M=(h,v)=>{const p=h.dataTransfer.getData("tabIndex");if(p===v.toString())return;const I=Array.from(t.cards),[z]=I.splice(parseInt(p),1);I.splice(v,0,z),d({...t,cards:I})};function C(h,v){return h.cards.length===1&&(v.displayTab===!0||v.displayTab===void 0)||h.activeCardId!==v.id&&(v.displayTab===!0||v.displayTab===void 0)?null:e.jsx("div",{onClick:()=>{const p=v.displayTab===void 0?!1:!v.displayTab;c({...v,displayTab:p}),x({...v,displayTab:p})},children:v.displayTab===!0||v.displayTab===void 0?e.jsx(ns,{className:"mr-2 size-3.5 text-muted-foreground hover:text-foreground"}):e.jsx(as,{className:"mr-2 size-3.5 text-muted-foreground hover:text-foreground"})})}function E(){return e.jsxs(s.Tabs,{onValueChange:S,value:t.activeCardId,className:"flex grow flex-col",children:[t.cards.map(h=>e.jsx(s.TabsContent,{className:"mt-0 grow",value:h.id,children:O()},h.id)),e.jsx(s.TabsList,{className:"group mx-6 justify-between",children:e.jsxs("div",{className:"flex items-center",children:[t.cards.map((h,v)=>e.jsx(s.Editable,{text:h.tabTitle||h.title,onSave:p=>{c({...n,tabTitle:p}),x({...n,tabTitle:p})},children:e.jsxs(s.TabsTrigger,{draggable:!0,onDragStart:p=>A(p,v),onDragOver:D,onDrop:p=>M(p,v),className:"",value:h.id,children:[C(t,h),h.tabTitle||h.title,t.activeCardId===h.id&&t.cards.length>1&&e.jsx(s.X,{className:"ml-2 size-3.5 text-muted-foreground hover:text-foreground",onClick:()=>L(h.id)})]})},h.id)),e.jsx(s.Button,{className:"ml-1 h-8 px-2 hover:bg-muted-foreground/50",variant:"outline",onClick:m,children:e.jsx(s.Plus,{className:"h-4 w-4"})}),e.jsx(s.Button,{className:"invisible ml-1 h-8 px-2 hover:bg-muted-foreground/50 group-hover:visible",variant:"outline",onClick:j,children:e.jsx(es,{className:"h-4 w-4"})})]})})]})}function O(){return n.type==="kpi"?e.jsx("div",{className:"flex h-full items-center justify-center",children:e.jsx("div",{className:"w-1/2 rounded-md border",children:e.jsx(s.KPICard,{card:n,data:u==null?void 0:u.records})})}):n.type==="text"?e.jsx("div",{className:"flex h-full items-center justify-center",children:e.jsx("div",{className:"w-1/2 rounded-md border",children:e.jsx(s.ScrollArea,{className:"mx-3 my-6 h-[300px] overflow-y-auto break-words px-3",children:e.jsx(s.TextCard,{isLoading:r,card:n,data:u==null?void 0:u.records})})})}):e.jsx(s.ErrorBoundary,{FallbackComponent:s.FallbackEditorCard,children:e.jsx(Is,{className:"grow border-none shadow-none"})})}return e.jsxs("div",{className:"relative flex h-full flex-col py-3",children:[(y||f)&&e.jsx(me,{className:"absolute bottom-0 left-0 right-0 top-0 z-50 m-auto h-10 w-10 animate-spin text-foreground/10"}),e.jsxs("div",{className:"mb-0 flex min-h-10 items-center justify-end gap-2 px-6",children:[a&&e.jsxs("div",{className:"flex grow items-center gap-2",children:[e.jsx(vt,{}),!["table","custom"].includes(n.type)&&e.jsx(jt,{}),e.jsx(Ct,{})]}),e.jsx(wt,{})]}),a?E():e.jsxs("div",{className:"flex min-h-0 w-full flex-1 grow basis-0 px-6",children:[l&&e.jsx(Nt,{}),(u==null?void 0:u.records)&&(u==null?void 0:u.records.length)>0&&e.jsx(ft,{data:(u==null?void 0:u.records)||[]}),o&&e.jsx("span",{className:"font-mono text-sm",children:o})]})]})}function Nt(){const t=s.useEditorStore(a=>a.pythonStdOut);if(!t)return null;const n=t.replace(/\n/g,"<br>");return e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"font-mono text-sm",children:"Output:"}),e.jsx("div",{dangerouslySetInnerHTML:{__html:n},className:"bg-muted p-2 font-mono text-sm"}),e.jsx(s.Separator,{className:"mb-2"})]})}function wt(){const t=s.useEditorStore(a=>a.isShowingVisual),n=s.useEditorStore(a=>a.actions.setIsShowingVisual);return e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(s.Label,{htmlFor:"visualize",children:"Chart"}),e.jsx(s.Switch,{checked:t,onCheckedChange:()=>n(!t),id:"visualize",className:"data-[state=checked]:bg-foreground/50"})]})}function Et({options:t,value:n,onValueChange:a}){return e.jsx(s.RadioGroup,{value:n,onValueChange:a,className:"flex gap-4",defaultValue:t[0].value,children:t.map(r=>e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(s.RadioGroupItem,{value:r.value,id:r.value}),e.jsx("label",{className:"text-sm",htmlFor:r.value,children:r.label})]},r.value))})}function ee({label:t,options:n,value:a,onValueChange:r,className:o}){return e.jsxs(s.Select,{value:a,onValueChange:r,children:[e.jsx(s.SelectTrigger,{className:s.cn("w-full focus:ring-0 focus:ring-offset-0",o),children:e.jsx(s.SelectValue,{placeholder:t})}),e.jsx(s.SelectContent,{children:e.jsxs(s.SelectGroup,{children:[e.jsx(s.SelectLabel,{children:t}),n.map(l=>e.jsx(s.SelectItem,{value:l.value,children:l.label},l.value))]})})]})}function be({children:t,summary:n,open:a,className:r}){return e.jsxs("details",{open:a,className:s.cn("space-y-4 [&_summary>svg]:open:-rotate-180",r),children:[e.jsxs("summary",{className:"flex cursor-pointer list-none items-center justify-between gap-4",children:[e.jsx(s.Label,{children:n}),e.jsx(s.ChevronUp,{className:"h-4 w-4"})]}),e.jsx("div",{className:"transition-all ease-in-out",children:t})]})}function kt(){var j,L;const t=s.useEditorStore(S=>S.card.customCardPreferences),{data:n}=Rs(),a=(n==null?void 0:n.plugins)||[],r=s.useEditorStore(S=>S.card),o=s.useEditorStore(S=>S.frame),l=(t==null?void 0:t.visualType)||"single",{setCustomCardPreferences:i}=s.useEditorActions(),{components:d,manifest:c}=s.useCustomVisual((t==null?void 0:t.url)||""),x=(j=c==null?void 0:c.visuals)==null?void 0:j.find(S=>S.name===(t==null?void 0:t.componentName));function u(S,A){if(!t)return;const M={...(t==null?void 0:t.dataInputCardIds)||{},[S]:{cardId:A,hookRef:null}};i({...t,dataInputCardIds:M})}function y(S){var D,M;const A=(D=o==null?void 0:o.cards)==null?void 0:D.filter(C=>{var E;return((E=C==null?void 0:C.customCardPreferences)==null?void 0:E.visualType)!=="multiple"}).map(C=>({value:C.id,label:C.tabTitle||C.title}));return e.jsx("div",{className:"space-y-2",children:(M=S==null?void 0:S.dataInputs)==null?void 0:M.map((C,E)=>{var O,h;return e.jsxs("div",{className:"grid grid-cols-10 gap-2",children:[e.jsx("div",{className:"col-span-4 flex items-center",children:C}),e.jsx(ee,{className:"col-span-6 h-8 w-full justify-between",label:"",options:A||[],value:((h=(O=t==null?void 0:t.dataInputCardIds)==null?void 0:O[E])==null?void 0:h.cardId)||"",onValueChange:v=>u(E,v)})]},E+Math.random())})})}function f(S,A,D=[]){var M,C;return t?S==="input"?e.jsx(s.Input,{className:`h-8 w-full ${s.removeRing}`,value:((M=t==null?void 0:t.settings)==null?void 0:M[A])||"",onChange:E=>{i({...t,settings:{...t==null?void 0:t.settings,[A]:E.target.value}})}},A):S==="select"?e.jsx(ee,{className:"h-8 w-full",label:"",options:D,value:((C=t==null?void 0:t.settings)==null?void 0:C[A])||"",onValueChange:E=>{i({...t,settings:{...t==null?void 0:t.settings,[A]:E}})}}):null:null}function m(S){const A=Object.entries((S==null?void 0:S.settings)||{});return e.jsx("div",{className:"space-y-3",children:A.map(([D,M])=>e.jsxs("div",{className:"space-y-2",children:[e.jsx(s.Label,{children:M.title}),f(M.ui,D,M.options)]},D))})}function g(S){t&&i({...t,visualType:S,componentName:""})}return e.jsxs("div",{className:"p-6",children:[e.jsx(be,{summary:"Plugin Settings",children:e.jsx("div",{className:"space-y-4 text-sm",children:e.jsxs("div",{className:"space-y-4 text-sm",children:[e.jsx("div",{className:"space-y-2",children:e.jsx("div",{className:"px-2",children:e.jsx(ee,{className:"h-8 w-full",label:"",options:a,value:(t==null?void 0:t.url)||"",onValueChange:S=>i({...t||{url:"",componentName:""},url:S})})})}),((t==null?void 0:t.type)==="component"||(t==null?void 0:t.type)===void 0)&&e.jsx(Et,{options:[{value:"single",label:"Single Visual"},{value:"multiple",label:"Multi-Visual"}],value:l,onValueChange:g}),((t==null?void 0:t.type)==="component"||(t==null?void 0:t.type)===void 0)&&t&&e.jsx(e.Fragment,{children:e.jsxs("div",{className:"space-y-2",children:[e.jsx(s.Label,{children:"Component"}),e.jsx("div",{className:"space-y-2 px-2",children:d&&e.jsx(ee,{className:"h-8 w-full",label:"",options:(d==null?void 0:d.filter(S=>S.type===l).map(S=>({value:S.name,label:S.name})))||[],value:t.componentName,onValueChange:S=>{console.log("changing value",S),i({...t,componentName:S})}})})]})})]})})}),e.jsx(s.Separator,{className:"my-4"}),((L=r==null?void 0:r.customCardPreferences)==null?void 0:L.componentName)&&e.jsxs(be,{summary:"Component Settings",children:[x&&x.dataInputs&&e.jsxs("div",{className:"space-y-3",children:[e.jsx(s.Label,{children:"Input Mapping"}),e.jsx("div",{className:"px-2",children:y(x)})]}),x&&x.settings&&e.jsx("div",{className:"space-y-3",children:e.jsx("div",{className:"px-2",children:m(x)})})]})]})}function le(){const[t,n]=w.useState([]);s.useEditorStore(u=>u.card.cfg);const a=s.useEditorStore(u=>u.card.preferences),{setCardCfg:r,setFilterOnClickColumnIndex:o,setCardPreferences:l}=s.useEditorStore(u=>u.actions),i=s.useEditorStore(u=>u.queryResultColumns);s.useEditorStore(u=>{var y;return(y=u.card.preferences)==null?void 0:y.filterOnClickColumnIndex}),w.useEffect(()=>{i&&n(new Array(i.length).fill(!1))},[i]);function d(u,y){var f,m;y?a!=null&&a.onClickFilter&&((f=a==null?void 0:a.onClickFilter)==null?void 0:f.length)>0?l({...a,onClickFilter:[...a.onClickFilter,{columnIndex:u,expression:""}]}):l({...a,onClickFilter:[{columnIndex:u,expression:""}]}):(l({...a,onClickFilter:(m=a==null?void 0:a.onClickFilter)==null?void 0:m.filter(g=>g.columnIndex!==u)}),n(g=>{const j=[...g];return j[u]=!1,j}))}function c(u,y){var m;const f=(m=a==null?void 0:a.onClickFilter)==null?void 0:m.map(g=>g.columnIndex===u?{...g,expression:y.target.value}:g);l({...a,onClickFilter:f})}function x(u){var y,f,m,g;if(t!=null&&t[u]||(f=(y=a==null?void 0:a.onClickFilter)==null?void 0:y.find(j=>j.columnIndex===u))!=null&&f.expression)return e.jsx(s.Input,{value:(g=(m=a==null?void 0:a.onClickFilter)==null?void 0:m.find(j=>j.columnIndex===u))==null?void 0:g.expression,onChange:j=>c(u,j),type:"text",className:"h-9 w-full font-mono text-xs focus-visible:ring-0 focus-visible:ring-ring focus-visible:ring-offset-0",placeholder:"Expression"})}return e.jsxs("div",{className:"space-y-2",children:[e.jsx(s.Label,{children:"On Click"}),i==null?void 0:i.map((u,y)=>{var f,m;return e.jsx("div",{className:"xbg-red-100 group flex items-center justify-between space-y-2",children:e.jsxs("div",{className:"grow",children:[e.jsxs("div",{className:"flex items-center space-x-2 py-2",children:[e.jsx(s.Checkbox,{checked:!!((f=a==null?void 0:a.onClickFilter)!=null&&f.find(g=>g.columnIndex===y)),onCheckedChange:g=>d(y,g)}),e.jsx("label",{className:"text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70",children:u}),e.jsx("div",{className:"flex items-center gap-2",children:((m=a==null?void 0:a.onClickFilter)==null?void 0:m.find(g=>g.columnIndex===y))&&e.jsx(Be,{onClick:()=>{n(g=>{const j=[...g];return j[y]=!g[y],j})},className:"invisible size-3 cursor-pointer text-gray-400 group-hover:visible"})})]}),x(y)]})},u)})]})}function Te(){var i,d,c;const t=s.useEditorStore(x=>x.card.preferences),n=s.useEditorStore(x=>x.card.cfg),{setCardCfg:a,setCardPreferences:r,setChartOrientation:o}=s.useEditorStore(x=>x.actions);(i=n==null?void 0:n.options)!=null&&i.indexAxis;function l(x){o(x)}return e.jsxs(s.RadioGroup,{value:((d=t==null?void 0:t.chartOptions)==null?void 0:d.indexAxis)||((c=n==null?void 0:n.options)==null?void 0:c.indexAxis)||"x",onValueChange:l,className:"flex gap-3",defaultValue:"x",children:[e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(s.RadioGroupItem,{value:"x",id:"r1"}),e.jsx("label",{className:"text-sm",htmlFor:"r1",children:"Vertical"})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(s.RadioGroupItem,{value:"y",id:"r2"}),e.jsx("label",{className:"text-sm",htmlFor:"r2",children:"Horizontal"})]})]})}const Ne="focus-visible:ring-0 focus-visible:ring-ring focus-visible:ring-offset-0";function We(t,n){var r,o,l;const a=s.getNumberAxis(t,n);return((l=(o=(r=t==null?void 0:t.chartOptions)==null?void 0:r.scales)==null?void 0:o[a])==null?void 0:l.type)||"linear"}function qs(){var K,B,J,k,V,G;const[t,n]=w.useState(!1),a=s.useEditorStore(F=>{var T;return(T=F.card)==null?void 0:T.preferences}),r=s.useEditorStore(F=>{var T;return(T=F.card)==null?void 0:T.cfg}),o=s.getNumberAxis(a,r),[l,i]=w.useState(We(a)),[d,c]=w.useState(((J=(B=(K=a==null?void 0:a.chartOptions)==null?void 0:K.scales)==null?void 0:B[o])==null?void 0:J.min)||""),[x,u]=w.useState(((G=(V=(k=a==null?void 0:a.chartOptions)==null?void 0:k.scales)==null?void 0:V[o])==null?void 0:G.max)||""),[y,f]=w.useState(d||x?"custom":"auto"),[m,g]=w.useState(""),[j,L]=w.useState(0),[S,A]=w.useState(""),[D,M]=w.useState(""),[C,E]=w.useState(""),O=s.useEditorStore(F=>F.actions.setCardPreferences),{updateCardInFrame:h}=s.useEditorActions(),v=s.useEditorStore(F=>F.card),p=s.useEditorStore(F=>{var T;return(T=F.card)==null?void 0:T.type}),I=["pie","doughnut","polarArea"].includes(p);w.useEffect(()=>{var F,T,$,q,P,W,te,ce,ae,re,ne,Q,X,Z;i(We(a)),c((($=(T=(F=a==null?void 0:a.chartOptions)==null?void 0:F.scales)==null?void 0:T[o])==null?void 0:$.min)===0?0:""),u(((W=(P=(q=a==null?void 0:a.chartOptions)==null?void 0:q.scales)==null?void 0:P[o])==null?void 0:W.max)||""),g(((re=(ae=(ce=(te=a==null?void 0:a.chartOptions)==null?void 0:te.scales)==null?void 0:ce[o])==null?void 0:ae.ticks)==null?void 0:re.stepSize)||""),L(((ne=a==null?void 0:a.numberAxisFormat)==null?void 0:ne.decimalPlaces)||0),A(((Q=a==null?void 0:a.numberAxisFormat)==null?void 0:Q.suffix)||""),M(((X=a==null?void 0:a.numberAxisFormat)==null?void 0:X.currency)||""),E(((Z=a==null?void 0:a.numberAxisFormat)==null?void 0:Z.locale)||"")},[t,a,o]);function z(F,T){return T===""||/^[0-9\b]+$/.test(T)?Number(T):Number(F)}function R(){const F=[...new Set(s.LOCALE_CURRENCY_PAIRS.map(T=>T.currency))];return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"grid grid-cols-6 items-center gap-2",children:[e.jsx(s.Label,{className:"col-span-2 hover:cursor-pointer hover:underline",htmlFor:"currency",children:e.jsx("a",{target:"_blank",href:"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat",children:"Currency"})}),e.jsxs(s.Select,{value:D||"none",onValueChange:T=>M(T==="none"?"":T),children:[e.jsx(s.SelectTrigger,{className:"col-span-2 h-8 w-full focus:ring-1 focus:ring-offset-0",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{children:e.jsxs(s.SelectGroup,{children:[e.jsx(s.SelectLabel,{children:"Currency"}),e.jsx(s.SelectItem,{value:"none",children:"None"}),F.map(T=>e.jsx(s.SelectItem,{value:T,children:T},T))]})})]}),e.jsxs(s.Select,{value:C,onValueChange:T=>E(T),children:[e.jsx(s.SelectTrigger,{className:"col-span-2 h-8 w-full focus:ring-1 focus:ring-offset-0",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{children:e.jsxs(s.SelectGroup,{children:[e.jsx(s.SelectLabel,{children:"Locale"}),s.LOCALE_CURRENCY_PAIRS.map(T=>e.jsx(s.SelectItem,{value:T.locale,children:T.locale},T.locale))]})})]})]}),e.jsxs("div",{className:"grid grid-cols-9 items-center gap-2",children:[e.jsx(s.Label,{className:"col-span-3",htmlFor:"format",children:"Decimals"}),e.jsx(s.Input,{value:j,onChange:T=>L(Number(T.target.value)),id:"format",className:`col-span-6 h-8 w-full tracking-wide ${Ne}`})]})]})}function _(){return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"grid grid-cols-3 items-center gap-2",children:[e.jsx(s.Label,{htmlFor:"range",children:"Range"}),e.jsx(s.Input,{id:"min",value:d,onChange:F=>c(T=>z(T,F.target.value)),className:`col-span-1 h-8 w-full ${Ne}`}),e.jsx(s.Input,{value:x,onChange:F=>u(T=>z(T,F.target.value)),id:"max",className:`col-span-1 h-8 w-full ${Ne}`})]}),e.jsxs("div",{className:"grid grid-cols-3 items-center gap-2",children:[e.jsx(s.Label,{htmlFor:"step-size",children:"Step Size"}),e.jsx(s.Input,{value:m,onChange:F=>g(T=>z(T,F.target.value)),id:"step-size",className:`col-span-1 h-8 w-full ${Ne}`})]})]})}function H(){var q;let F={};y==="custom"&&(F={min:d,max:x,ticks:{stepSize:m}});const T={...a||{},chartOptions:{...a==null?void 0:a.chartOptions,scales:{...(q=a==null?void 0:a.chartOptions)==null?void 0:q.scales,[o]:{type:l,...l==="linear"?F:{}}}},numberAxisFormat:{decimalPlaces:j,suffix:S,currency:D,locale:C}};console.log(T),O(T);const $={...v,preferences:T};h($)}return e.jsxs(s.Popover,{onOpenChange:F=>n(F),children:[e.jsx(s.PopoverTrigger,{asChild:!0,children:e.jsx(s.SliderIcon,{className:"size-4 cursor-pointer text-muted-foreground hover:text-foreground"})}),e.jsx(s.PopoverContent,{align:"center",className:"max-w-65",children:e.jsxs("div",{className:"grid gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("h4",{className:"font-medium leading-none",children:"Scale Options"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Set the scale for the number axis"})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsxs("div",{className:"grid grid-cols-3 items-center gap-2",children:[e.jsx(s.Label,{htmlFor:"scale",children:"Type"}),e.jsxs(s.Select,{disabled:I,value:l,onValueChange:F=>i(F),children:[e.jsx(s.SelectTrigger,{className:"col-span-2 h-8 w-full focus:ring-1 focus:ring-offset-0",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{id:"type",children:e.jsxs(s.SelectGroup,{children:[e.jsx(s.SelectLabel,{children:"Option"}),e.jsx(s.SelectItem,{value:"linear",children:"Linear"}),e.jsx(s.SelectItem,{value:"logarithmic",children:"Logarithmic"})]})})]})]}),l=="linear"&&e.jsxs("div",{className:"grid grid-cols-3 items-center gap-2 py-1",children:[e.jsx(s.Label,{htmlFor:"scale-option",children:"Setup"}),e.jsxs(s.RadioGroup,{disabled:I,id:"scale-option",value:y,onValueChange:F=>f(F),className:"col-span-2 flex gap-3",defaultValue:"x",children:[e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(s.RadioGroupItem,{value:"auto",id:"r1"}),e.jsx("label",{className:"text-sm",htmlFor:"r1",children:"Auto"})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(s.RadioGroupItem,{value:"custom",id:"r2"}),e.jsx("label",{className:"text-sm",htmlFor:"r2",children:"Custom"})]})]})]}),y==="custom"&&l=="linear"&&_(),R(),e.jsx(s.SelectSeparator,{}),e.jsx("div",{className:"grid grid-cols-3",children:e.jsx(s.Button,{onClick:H,variant:"secondary",className:"col-span-1 col-start-3 h-8 w-full",children:"Apply"})})]})]})})]})}function It({idx:t}){var d;const n=s.useEditorStore(c=>{var x;return(x=c.card)==null?void 0:x.preferences}),a=s.useEditorStore(c=>{var x;return(x=c.card.preferences)==null?void 0:x.datasetOptions}),r=s.useEditorStore(c=>c.actions.setCardPreferences),o=(d=n==null?void 0:n.chartOptions)==null?void 0:d.indexAxis,l=a==null?void 0:a.find(c=>c.idx===t);function i(c,x){(c==="end"||c==="start")&&s.getContrastColor(s.getCanvasBackgroundColor());const u={display:c!=="none",align:c,anchor:c,clamp:!0};if(!l)r({...n,datasetOptions:[...a||[],{idx:x,datalabels:u}]});else{const y={...l};y.datalabels=u;const f=a==null?void 0:a.map(m=>m.idx===x?y:m);r({...n,datasetOptions:f})}}return e.jsxs(s.Popover,{children:[e.jsx(s.PopoverTrigger,{children:e.jsx(ys,{className:"invisible size-4 rotate-[135deg] cursor-pointer text-muted-foreground hover:text-foreground group-hover:visible"})}),e.jsx(s.PopoverContent,{className:"w-fit p-1",children:e.jsxs("div",{className:"flex gap-1",children:[e.jsx(s.Button,{onClick:()=>i("none",t),size:"sm",variant:"secondary",className:"h-7 p-1 text-xs font-normal",children:e.jsx(s.X,{className:"size-4"})}),e.jsx(s.Button,{onClick:()=>i("start",t),size:"sm",variant:"secondary",className:"h-7 p-1 text-xs font-normal",children:e.jsx(cs,{className:s.cn("h-4 w-4",{"rotate-90":o==="y"})})}),e.jsx(s.Button,{onClick:()=>i("center",t),size:"sm",variant:"secondary",className:"h-7 p-1 text-xs font-normal",children:e.jsx(us,{className:s.cn("h-4 w-4",{"rotate-90":o==="y"})})}),e.jsx(s.Button,{onClick:()=>i("end",t),size:"sm",variant:"secondary",className:"h-7 p-1 text-xs font-normal",children:e.jsx(ds,{className:s.cn("h-4 w-4",{"rotate-90":o==="y"})})})]})})]})}function _s(){const t=s.useEditorStore(x=>x.card),n=s.useEditorStore(x=>{var u,y,f;return(f=(y=(u=x==null?void 0:x.card)==null?void 0:u.preferences)==null?void 0:y.chartOptions)==null?void 0:f.indexAxis}),{data:a}=s.useDashboardCardQuery(t),r=n==="y"?"Y axis":"X axis",o=n==="y"?"X axis":"Y axis",{keys:l,metricKeys:i,dimensionKeys:d}=s.getKeys((a==null?void 0:a.records)||[]);let c=i;if(["stackedBar","stackedLine"].includes(t.type)){const x=s.pivotData({dataArray:(a==null?void 0:a.records)||[],groupKey:d[0],pivotKey:d[1],valueKey:c[0]}),{metricKeys:u}=s.getKeys(x);c=u}return l.length===0?null:e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(s.Label,{children:r}),e.jsx("div",{className:"my-1 space-y-1",children:e.jsx("div",{className:"rounded-md bg-muted/70 px-2 py-1 hover:bg-muted",children:e.jsx("p",{children:d[0]})})})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between gap-5",children:[e.jsx(s.Label,{children:o}),e.jsx(qs,{})]}),e.jsx("div",{className:"my-1 space-y-1",children:c.map((x,u)=>e.jsx(Dt,{col:x,idx:u},x))})]})]})}function Dt({col:t,idx:n}){const a=s.useEditorStore(d=>{var c;return(c=d.card)==null?void 0:c.preferences}),r=s.useEditorStore(d=>{var c;return(c=d.card.preferences)==null?void 0:c.datasetOptions}),o=r==null?void 0:r.find(d=>d.idx===n),{setCardPreferences:l}=s.useEditorStore(d=>d.actions);function i(d){if(!o)l({...a,datasetOptions:[...r||[],{idx:n,type:d==="area"?"line":d,fill:d==="area"?"origin":""}]});else{const c={...o};c.type=d==="area"?"line":d,c.fill=d==="area"?"origin":"";const x=r==null?void 0:r.map(u=>u.idx===n?c:u);l({...a,datasetOptions:x})}}return e.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.jsx("p",{children:t}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(Ie,{onClick:()=>i("bar"),className:"invisible size-4 cursor-pointer text-muted-foreground hover:text-foreground group-hover:visible"}),e.jsx(De,{onClick:()=>i("line"),className:"invisible size-4 cursor-pointer text-muted-foreground hover:text-foreground group-hover:visible"}),e.jsx(Xe,{onClick:()=>i("area"),className:"invisible size-4 cursor-pointer text-muted-foreground hover:text-foreground group-hover:visible"}),e.jsx(s.Separator,{orientation:"vertical",className:"invisible size-4 cursor-pointer py-2 text-muted-foreground hover:text-foreground group-hover:visible"}),e.jsx(It,{idx:n})]})]})}function Bs(){const t=s.useEditorStore(f=>f.selectedConnectionId),n=s.useEditorStore(f=>f.selectedDatamodelId),a=s.useEditorStore(f=>f.selectedDatabaseName),r=s.useEditorStore(f=>f.selectedSchemaName),o=s.useEditorStore(f=>f.selectedTableName),l=s.useDashboardStore(f=>f.dashboard.filters)||[],i=s.useDashboardStore(f=>f.actions.addFilter),d=s.useDashboardStore(f=>f.actions.removeFilter),c=s.useDashboardStore(f=>f.actions.removeFilterValue),{modelItems:x,tableName:u}=ie();function y(f,m="dashboard"){var E;const g=s.fmt(f.column_name),j=s.fmt(a||""),L=s.fmt(r||""),S=s.fmt(u);let A=s.getQualifiedTableName(L,S),D=`${A}.${g}`;const M=(E=x==null?void 0:x.find(O=>O.id===n))==null?void 0:E.name;n&&n!=="none"&&(D=`${s.DATAMODEL_NAMESPCACE}.${M}.${g}`,A=`${s.DATAMODEL_NAMESPCACE}.${M}`);const C=l==null?void 0:l.find(O=>O.column===D&&O.table===S&&(O.database===j||O.database===a));if(C)c(C.id),d(C.id);else{const O=s.v4();return u==="api"&&t?(i({location:m,id:O,column:D,title:f.column_name,dataType:f.data_type,table:"api",database:"",connectionId:t,operation:"in",sql:s.getDefaultFilterSql(f.data_type,A,g)}),O):(i({id:O,location:m,column:D,title:f.column_name,dataType:f.data_type,table:o||"",database:a||"",connectionId:t||"",operation:"in",sql:s.getDefaultFilterSql(f.data_type,A,g)}),O)}}return{assignFilter:y}}function xe(){const t=s.useDashboardStore(d=>d.dashboard.filters),n=s.useEditorStore(d=>d.frame),{setFrame:a}=s.useEditorActions(),{columns:r}=ie(),{assignFilter:o}=Bs();function l(d){const c=o(d,"frame");a({...n,filterId:c})}const i=t==null?void 0:t.find(d=>d.id===n.filterId);return e.jsxs("div",{className:"space-y-3",children:[e.jsx(s.Label,{children:"Card Filter"}),e.jsx(Lt,{onSelect:l,columns:r}),i&&e.jsx(s.FilterHeader,{filter:i})]})}function Lt({columns:t,onSelect:n}){var i;const[a,r]=Qe.useState(!1),[o,l]=Qe.useState("");return e.jsxs(s.Popover,{open:a,onOpenChange:r,children:[e.jsx(s.PopoverTrigger,{asChild:!0,children:e.jsxs(s.Button,{size:"sm",variant:"outline",role:"combobox","aria-expanded":a,className:"w-full justify-between font-normal",children:[o?(i=t.find(d=>d.column_name===o))==null?void 0:i.column_name:"Select Column...",e.jsx(s.CaretSortIcon,{className:"ml-2 h-4 w-4 shrink-0 opacity-50"})]})}),e.jsx(s.PopoverContent,{className:"w-[200px] p-0",children:e.jsxs(s.Command,{children:[e.jsx(s.CommandInput,{placeholder:"Search column",className:"h-9"}),e.jsxs(s.CommandList,{children:[e.jsx(s.CommandEmpty,{children:"No framework found."}),e.jsx(s.CommandGroup,{children:t.map(d=>e.jsxs(s.CommandItem,{value:d.column_name,onSelect:c=>{const x=c===o?"":c;l(x),r(!1),x&&n(d)},children:[d.column_name,e.jsx(s.CheckIcon,{className:s.cn("ml-auto h-4 w-4",o===d.column_name?"opacity-100":"opacity-0")})]},d.column_name))})]})]})})]})}function Tt({cardType:t}){return e.jsx("div",{className:"space-y-6 px-6 py-2",children:e.jsxs(s.Accordion,{defaultValue:["item-2"],type:"multiple",children:[e.jsxs(s.AccordionItem,{value:"item-1",children:[e.jsx(s.AccordionTrigger,{children:`${s.titleCase(t)} Chart`}),e.jsxs(s.AccordionContent,{className:"space-y-4 font-mono text-xs",children:[e.jsx("div",{className:"rounded bg-muted px-2 py-1 text-xs",children:"SELECT x-axis, y-axis-1, y-axis-2,... FROM table"}),e.jsxs("ul",{className:"ml-6 list-disc text-xs [&>li]:mt-2",children:[e.jsx("li",{children:"x-axis - category"}),e.jsx("li",{children:"y-axis1 - number"}),e.jsx("li",{children:"y-axis2 - number"})]}),e.jsxs("div",{children:["See ",e.jsx("a",{target:"_blank",onClick:n=>n.stopPropagation(),className:"text-blue-700",href:"https://docs.semaphor.cloud/concepts/visuals#line-chart",children:"example"})," in the docs."]})]})]}),e.jsxs(s.AccordionItem,{value:"item-2",children:[e.jsx(s.AccordionTrigger,{children:"Settings"}),e.jsxs(s.AccordionContent,{className:"space-y-4 px-2",children:[e.jsx(Te,{}),e.jsx(_s,{})]})]}),e.jsxs(s.AccordionItem,{value:"item-3",children:[e.jsx(s.AccordionTrigger,{children:"Filters"}),e.jsxs(s.AccordionContent,{className:"space-y-4 px-2",children:[e.jsx(le,{}),e.jsx(xe,{})]})]})]})})}function Ge(){var o,l,i;const t=s.useEditorStore(d=>d.card.cfg),n=s.useEditorStore(d=>d.actions.setCardCfg),a=s.useEditorStore(d=>d.card.type);function r(d){var u;const c={datalabels:{display:d!=="none",align:d,anchor:d,clamp:!0}},x={...t,options:{...t==null?void 0:t.options,plugins:{...(u=t==null?void 0:t.options)==null?void 0:u.plugins,...c}}};n(x),console.log(d)}return e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("label",{className:"font-medium",children:"Data Labels"}),!["pyramid"].includes(a)&&e.jsx(qs,{})]}),e.jsxs(s.Select,{value:(i=(l=(o=t==null?void 0:t.options)==null?void 0:o.plugins)==null?void 0:l.datalabels)==null?void 0:i.anchor,onValueChange:r,defaultValue:"none",children:[e.jsx(s.SelectTrigger,{className:"h-8 w-full focus:ring-1 focus:ring-offset-0",children:e.jsx(s.SelectValue,{placeholder:"Select position"})}),e.jsx(s.SelectContent,{children:e.jsxs(s.SelectGroup,{children:[e.jsx(s.SelectLabel,{children:"Data Labels"}),e.jsx(s.SelectItem,{value:"none",children:"None"}),a!=="pyramid"&&e.jsx(s.SelectItem,{value:"start",children:"Start"}),e.jsx(s.SelectItem,{value:"center",children:"Center"}),a!=="pyramid"&&e.jsx(s.SelectItem,{value:"end",children:"End"})]})})]})]})}function At({cardType:t}){function n(a){const r="SELECT label, [group], x-axis, y-axis, radius FROM table",o="SELECT label, [group], x-axis, y-axis FROM table";return e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"rounded bg-muted px-2 py-1 text-xs",children:a==="bubble"?r:o}),e.jsxs("ul",{className:"ml-6 list-disc text-xs [&>li]:mt-2",children:[e.jsx("li",{children:"label - category"}),e.jsx("li",{children:"group - category"}),e.jsx("li",{children:"x-axis - category"}),e.jsx("li",{children:"y-axis - category"}),a==="bubble"&&e.jsx("li",{children:"radius - number"})]}),e.jsxs("div",{children:["See ",e.jsx("a",{target:"_blank",onClick:l=>l.stopPropagation(),className:"text-blue-700",href:"https://docs.semaphor.cloud/concepts/visuals#pie-chart",children:"example"})," in the docs."]})]})}return e.jsx("div",{className:"space-y-6 px-6 py-2",children:e.jsxs(s.Accordion,{defaultValue:["item-2"],type:"multiple",children:[e.jsxs(s.AccordionItem,{value:"item-1",children:[e.jsx(s.AccordionTrigger,{children:`${s.titleCase(t)} Chart`}),e.jsx(s.AccordionContent,{className:"space-y-4 font-mono text-xs",children:n(t)})]}),e.jsxs(s.AccordionItem,{value:"item-2",children:[e.jsx(s.AccordionTrigger,{children:"Settings"}),e.jsx(s.AccordionContent,{className:"px-2",children:e.jsx(Ge,{})})]}),e.jsxs(s.AccordionItem,{value:"item-3",children:[e.jsx(s.AccordionTrigger,{children:"Filters"}),e.jsxs(s.AccordionContent,{className:"space-y-4 px-2",children:[e.jsx(le,{}),e.jsx(xe,{})]})]})]})})}const Ot={datasets:[{type:"line",label:"Sum_sales",data:[]},{type:"bar",label:"Sum_profit",data:[]}]},zt={datasets:[{fill:"origin",type:"line",label:"Sum_sales",data:[]}]};function Ft(){const t=s.useEditorStore(n=>n.card.type);return e.jsxs("div",{className:"space-y-6 p-6",children:[e.jsx(s.Accordion,{className:" ",type:"single",collapsible:!0,children:Mt(t)}),e.jsx("section",{className:"",children:["line","bar"].includes(t)&&e.jsx(Te,{})}),!["kpi"].includes(t)&&e.jsxs("div",{className:"space-y-4",children:[e.jsx(Ge,{}),e.jsx(le,{}),e.jsx(xe,{})]})]})}function Mt(t){if(["line","bar"].includes(t))return e.jsxs(e.Fragment,{children:[e.jsxs(s.AccordionItem,{value:"item-1",children:[e.jsx(s.AccordionTrigger,{className:"font-normal",children:e.jsx("p",{children:"Chart Query"})}),e.jsxs(s.AccordionContent,{className:" ",children:[e.jsx("div",{className:"rounded bg-muted px-2 py-1 font-mono text-xs font-semibold",children:"SELECT x-axis, y-axis-1, y-axis-2, y-axis-3,... FROM table"}),e.jsxs("ul",{className:"my-6 ml-6 list-disc text-xs font-normal [&>li]:mt-2",children:[e.jsx("li",{children:"X-axis - Category (ex. city)"}),e.jsx("li",{children:"Y-axis - Number (ex. population)"})]})]})]}),e.jsxs(s.AccordionItem,{value:"item-2",children:[e.jsx(s.AccordionTrigger,{className:"font-normal",children:"Mixed Chart"}),e.jsxs(s.AccordionContent,{className:"space-y-2 text-xs",children:[e.jsxs("p",{children:["Click ",e.jsx("b",{children:"Customize"})," and change the `type` property in the dataset."]}),e.jsx("pre",{children:JSON.stringify(Ot,null,2)})]})]}),e.jsxs(s.AccordionItem,{value:"item-3",children:[e.jsx(s.AccordionTrigger,{className:"font-normal",children:"Area Chart"}),e.jsxs(s.AccordionContent,{className:"space-y-2 text-xs",children:[e.jsxs("p",{children:["Click ",e.jsx("b",{children:"Customize"})," and add `fill` property to the dataset. See",e.jsx("a",{className:"mx-1 text-blue-500 hover:underline",href:"https://www.chartjs.org/docs/latest/samples/area/line-boundaries.html",target:"_blank",children:"docs"}),"for more options."]}),e.jsx("pre",{children:JSON.stringify(zt,null,2)})]})]})]});if(t==="bubble")return e.jsx(e.Fragment,{children:e.jsxs(s.AccordionItem,{value:"item-1",children:[e.jsx(s.AccordionTrigger,{className:"font-normal",children:e.jsxs("p",{children:["How to create a ",e.jsx("span",{children:t})," chart query?"]})}),e.jsxs(s.AccordionContent,{className:" ",children:[e.jsx("div",{className:"rounded bg-muted px-2 py-1 font-mono text-xs font-semibold",children:"SELECT label, x-axis, y-axis, radius FROM table"}),e.jsxs("ul",{className:"my-6 ml-6 list-disc text-xs font-normal [&>li]:mt-2",children:[e.jsx("li",{children:"Label - Category (ex. city)"}),e.jsx("li",{children:"Bubble Group (opt) - Category (ex. state)"}),e.jsx("li",{children:"X-axis - Number (ex. avg. age)"}),e.jsx("li",{children:"Y-axis - Number (ex. avg. weight)"}),e.jsx("li",{children:"Radius - Number (ex. population)"})]})]})]})});if(t==="scatter")return e.jsx(e.Fragment,{children:e.jsxs(s.AccordionItem,{value:"item-1",children:[e.jsx(s.AccordionTrigger,{className:"font-normal",children:e.jsxs("p",{children:["How to create a ",e.jsx("span",{children:t})," chart query?"]})}),e.jsxs(s.AccordionContent,{className:" ",children:[e.jsx("div",{className:"rounded bg-muted px-2 py-1 font-mono text-xs font-semibold",children:"SELECT label, x-axis, y-axis FROM table"}),e.jsxs("ul",{className:"my-6 ml-6 list-disc text-xs font-normal [&>li]:mt-2",children:[e.jsx("li",{children:"Label - Category (ex. city)"}),e.jsx("li",{children:"Group (opt) - Category (ex. state)"}),e.jsx("li",{children:"X-axis - Number (ex. avg. age)"}),e.jsx("li",{children:"Y-axis - Number (ex. avg. weight)"})]})]})]})});if(["pie","doughnut","polarArea"].includes(t))return e.jsx(e.Fragment,{children:e.jsxs(s.AccordionItem,{value:"item-1",children:[e.jsx(s.AccordionTrigger,{className:"font-normal",children:e.jsxs("p",{children:[e.jsx("span",{children:t==="polarArea"?"Polar":t.charAt(0).toUpperCase()+t.slice(1)})," ","chart query"]})}),e.jsxs(s.AccordionContent,{className:" ",children:[e.jsx("div",{className:"rounded bg-muted px-2 py-1 font-mono text-xs font-semibold",children:"SELECT label, measure FROM table"}),e.jsxs("ul",{className:"my-6 ml-6 list-disc text-xs font-normal [&>li]:mt-2",children:[e.jsx("li",{children:"Label - Category (ex. city)"}),e.jsx("li",{children:"Measure - Number (ex. population)"})]})]})]})})}function Vt(){var c,x,u,y,f;const t=s.useEditorStore(m=>m.card.preferences),n=s.useEditorStore(m=>m.actions.setCardPreferences),a=s.useEditorStore(m=>m.actions.setNumberFormat);s.useEditorStore(m=>{var g,j;return(j=(g=m.card.preferences)==null?void 0:g.formatNumber)==null?void 0:j.decimalPlaces});const r=s.useEditorStore(m=>{var g,j;return(j=(g=m.card.preferences)==null?void 0:g.formatNumber)==null?void 0:j.locale}),o=s.useEditorStore(m=>{var g,j;return(j=(g=m.card.preferences)==null?void 0:g.formatNumber)==null?void 0:j.currency});s.useEditorStore(m=>m.actions.setFilterOnClickField);const l=s.useEditorStore(m=>{var g,j;return(j=(g=m.card.preferences)==null?void 0:g.formatNumber)==null?void 0:j.colorRanges})||[],i=s.useEditorStore(m=>m.actions.setColorRanges),d=[...new Set(s.LOCALE_CURRENCY_PAIRS.map(m=>m.currency))];return e.jsxs("div",{children:[e.jsxs("div",{className:"mb-3 flex items-center gap-2",children:[e.jsx(s.Checkbox,{checked:!!((c=t==null?void 0:t.formatNumber)!=null&&c.enabled),onCheckedChange:m=>{n({...t,formatNumber:{...t==null?void 0:t.formatNumber,enabled:m}})}}),e.jsx(s.Label,{children:"Format Number"})]}),((x=t==null?void 0:t.formatNumber)==null?void 0:x.enabled)===!0&&e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsx("div",{children:e.jsxs("div",{className:"space-y-4 p-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("div",{className:"w-full space-y-1",children:[e.jsx(s.Label,{children:"Locale"}),e.jsxs(s.Select,{value:r||"none",onValueChange:m=>{var g,j,L;return a(((g=t==null?void 0:t.formatNumber)==null?void 0:g.decimalPlaces)||0,((j=t==null?void 0:t.formatNumber)==null?void 0:j.currency)||"",m,((L=t==null?void 0:t.formatNumber)==null?void 0:L.suffix)||"")},children:[e.jsx(s.SelectTrigger,{className:"col-span-6 h-8 w-full focus:ring-1 focus:ring-offset-0",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{children:e.jsxs(s.SelectGroup,{children:[e.jsx(s.SelectLabel,{children:"Format"}),e.jsx(s.SelectItem,{value:"none",children:"None"},"none"),s.LOCALE_CURRENCY_PAIRS.map(m=>e.jsx(s.SelectItem,{value:m.locale,children:m.locale},m.locale))]})})]})]}),e.jsxs("div",{className:"w-full space-y-1",children:[e.jsx(s.Label,{children:"Currency"}),e.jsxs(s.Select,{value:o||"none",onValueChange:m=>{var g,j,L;console.log("currency",m),a(((g=t==null?void 0:t.formatNumber)==null?void 0:g.decimalPlaces)||0,m==="none"?"":m,((j=t==null?void 0:t.formatNumber)==null?void 0:j.locale)||"",((L=t==null?void 0:t.formatNumber)==null?void 0:L.suffix)||"")},children:[e.jsx(s.SelectTrigger,{className:"col-span-6 h-8 w-full focus:ring-1 focus:ring-offset-0",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{children:e.jsxs(s.SelectGroup,{children:[e.jsx(s.SelectLabel,{children:"Currency"}),e.jsx(s.SelectItem,{value:"none",children:"None"},"none"),d.map(m=>e.jsx(s.SelectItem,{value:m,children:m},m))]})})]})]})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs("div",{className:"w-full space-y-1",children:[e.jsx(s.Label,{children:"Decimals"}),e.jsxs(s.Select,{value:((y=(u=t==null?void 0:t.formatNumber)==null?void 0:u.decimalPlaces)==null?void 0:y.toString())||"0",onValueChange:m=>{var g,j,L;return a(Number(m),((g=t==null?void 0:t.formatNumber)==null?void 0:g.currency)||"",((j=t==null?void 0:t.formatNumber)==null?void 0:j.locale)||"",((L=t==null?void 0:t.formatNumber)==null?void 0:L.suffix)||"")},children:[e.jsx(s.SelectTrigger,{className:"col-span-3 h-8 w-full focus:ring-1 focus:ring-offset-0",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{children:["0","1","2","3","4"].map(m=>e.jsx(s.SelectItem,{value:m,children:m},m))})]})]}),e.jsxs("div",{className:"w-full space-y-1",children:[e.jsx(s.Label,{children:"Suffix"}),e.jsx(s.Input,{value:((f=t==null?void 0:t.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:m=>{var g,j,L;return a(((g=t==null?void 0:t.formatNumber)==null?void 0:g.decimalPlaces)||0,((j=t==null?void 0:t.formatNumber)==null?void 0:j.currency)||"",((L=t==null?void 0:t.formatNumber)==null?void 0:L.locale)||"",m.target.value)}})]})]})]})}),e.jsx(s.Separator,{className:"my-3"}),e.jsx(s.ColorFormat,{colorRanges:l,setColorRanges:i})]})]})}function Rt(){return e.jsxs("div",{className:"space-y-6 px-6 py-2",children:[e.jsx(s.Accordion,{type:"single",collapsible:!0,children:e.jsxs(s.AccordionItem,{value:"item-1",children:[e.jsx(s.AccordionTrigger,{className:"",children:"KPI Query"}),e.jsxs(s.AccordionContent,{className:"font-mono",children:[e.jsx("div",{className:"rounded bg-muted px-2 py-1 font-mono text-xs",children:"SELECT current, previous FROM table"}),e.jsxs("ul",{className:"my-6 ml-6 list-disc text-xs [&>li]:mt-2",children:[e.jsx("li",{children:"current - number"}),e.jsx("li",{children:"previous - number"})]}),e.jsxs("div",{children:["See ",e.jsx("a",{target:"_blank",onClick:t=>t.stopPropagation(),className:"text-blue-700",href:"https://docs.semaphor.cloud/concepts/visuals#kpi",children:"example"})," in the docs."]})]})]})}),e.jsx("section",{className:"",children:e.jsx(Vt,{})}),e.jsx("div",{}),e.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(t=>({label:t,value:t}));function Ht(){var c,x,u,y,f,m,g,j,L,S,A,D,M,C,E,O,h,v;const t=s.useEditorStore(p=>p.card),n=(x=(c=t==null?void 0:t.preferences)==null?void 0:c.mapVisualOptions)==null?void 0:x.topoJsonUrl,[a,r]=w.useState(((y=(u=t==null?void 0:t.preferences)==null?void 0:u.mapVisualOptions)==null?void 0:y.customTopoJsonUrl)||""),{setCardPreferences:o}=s.useEditorActions(),{data:l}=s.useTopoJson(t),i=Object.keys((l==null?void 0:l.objects)||{}).map(p=>({label:p,value:p}))||[],d=[{label:"US States 10m",value:"https://unpkg.com/us-atlas/states-10m.json"},{label:"Countries 50m",value:"https://unpkg.com/world-atlas/countries-50m.json"},{label:"Custom",value:"custom"}];return e.jsxs("div",{className:"p-6",children:[e.jsx(be,{summary:"Map Query",children:e.jsx("p",{className:"rounded-md bg-muted p-2 font-mono text-xs",children:"SELECT country, value FROM table"})}),e.jsx(s.Separator,{className:"my-4"}),e.jsx(be,{open:!0,summary:"Settings",children:e.jsxs("div",{className:"space-y-3 px-2",children:[e.jsx(ee,{className:"h-9",options:d,onValueChange:p=>{console.log("value",p),o({...t.preferences,mapVisualOptions:{topoJsonUrl:p}})},value:n||"",label:"Select Map"}),n==="custom"&&e.jsx(s.Input,{onChange:p=>{r(p.target.value)},onBlur:()=>{var p;console.log("onBlur",a),o({...t.preferences,mapVisualOptions:{...(p=t.preferences)==null?void 0:p.mapVisualOptions,customTopoJsonUrl:a}})},value:a,className:`h-9 w-full ${s.removeRing}`,placeholder:"Custom URL"}),l&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(s.Label,{children:"Map Object"}),e.jsx(ee,{className:"h-9",options:i,value:((m=(f=t.preferences)==null?void 0:f.mapVisualOptions)==null?void 0:m.objectKey)||"",label:"Map Object",onValueChange:p=>{var I;o({...t.preferences,mapVisualOptions:{...(I=t.preferences)==null?void 0:I.mapVisualOptions,objectKey:p}})}})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(s.Label,{children:"Projection"}),e.jsx(ee,{className:"h-9",options:qt,value:((j=(g=t.preferences)==null?void 0:g.mapVisualOptions)==null?void 0:j.projection)||"",label:"Projection",onValueChange:p=>{var I;o({...t.preferences,mapVisualOptions:{...(I=t.preferences)==null?void 0:I.mapVisualOptions,projection:p}})}})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(s.Label,{children:"Colors"}),e.jsx(ee,{className:"h-9",options:Bt,value:((S=(L=t.preferences)==null?void 0:L.mapVisualOptions)==null?void 0:S.colorScale)||"",label:"Select Color Scale",onValueChange:p=>{var I;o({...t.preferences,mapVisualOptions:{...(I=t.preferences)==null?void 0:I.mapVisualOptions,colorScale:p}})}})]})]})]})}),e.jsx(s.Separator,{className:"my-4"}),e.jsx(be,{className:"",summary:"Scale Options",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(s.Input,{className:`h-9 w-full ${s.removeRing}`,type:"number",step:.1,value:((D=(A=t.preferences)==null?void 0:A.mapVisualOptions)==null?void 0:D.projectionScale)||1,onChange:p=>{var I;o({...t.preferences,mapVisualOptions:{...(I=t.preferences)==null?void 0:I.mapVisualOptions,projectionScale:Number(p.target.value)}})}}),e.jsx(s.Label,{children:"X"}),e.jsx(s.Input,{className:`h-9 w-full ${s.removeRing}`,type:"number",step:10,value:((E=(C=(M=t.preferences)==null?void 0:M.mapVisualOptions)==null?void 0:C.projectionOffset)==null?void 0:E[0])||0,onChange:p=>{var I,z,R,_;o({...t.preferences,mapVisualOptions:{...(I=t.preferences)==null?void 0:I.mapVisualOptions,projectionOffset:[Number(p.target.value),((_=(R=(z=t.preferences)==null?void 0:z.mapVisualOptions)==null?void 0:R.projectionOffset)==null?void 0:_[1])||0]}})}}),e.jsx(s.Label,{children:"Y"}),e.jsx(s.Input,{className:`h-9 w-full ${s.removeRing}`,type:"number",step:10,value:((v=(h=(O=t.preferences)==null?void 0:O.mapVisualOptions)==null?void 0:h.projectionOffset)==null?void 0:v[1])||0,onChange:p=>{var I,z,R,_;o({...t.preferences,mapVisualOptions:{...(I=t.preferences)==null?void 0:I.mapVisualOptions,projectionOffset:[((_=(R=(z=t.preferences)==null?void 0:z.mapVisualOptions)==null?void 0:R.projectionOffset)==null?void 0:_[0])||0,Number(p.target.value)]}})}})]})}),e.jsx(s.Separator,{className:"my-4"}),e.jsx(le,{})]})}function Pt(){var r;const t=s.useEditorStore(o=>o.card.preferences),{setCardPreferences:n}=s.useEditorStore(o=>o.actions);function a(o){n({...t,textVisualOptions:{...t==null?void 0:t.textVisualOptions,isDynamicText:o==="dynamic"}})}return e.jsxs(s.RadioGroup,{value:(r=t==null?void 0:t.textVisualOptions)!=null&&r.isDynamicText?"dynamic":"static",onValueChange:a,className:"flex gap-3",defaultValue:"x",children:[e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(s.RadioGroupItem,{value:"static",id:"r1"}),e.jsx("label",{className:"text-sm",htmlFor:"r1",children:"Static"})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(s.RadioGroupItem,{value:"dynamic",id:"r2"}),e.jsx("label",{className:"text-sm",htmlFor:"r2",children:"Dynamic"})]})]})}function we({cardType:t,docContent:n,suffix:a="Chart"}){return e.jsx("div",{className:"space-y-6 px-6 py-2",children:e.jsxs(s.Accordion,{defaultValue:["item-2"],type:"multiple",children:[e.jsxs(s.AccordionItem,{value:"item-1",children:[e.jsx(s.AccordionTrigger,{children:`${s.titleCase(t)} ${a}`}),e.jsx(s.AccordionContent,{children:n||e.jsxs("div",{className:"space-y-4 font-mono text-xs",children:[e.jsx("div",{className:"rounded bg-muted px-2 py-1 text-xs",children:"SELECT label, measure FROM table"}),e.jsxs("ul",{className:"ml-6 list-disc text-xs [&>li]:mt-2",children:[e.jsx("li",{children:"label - category"}),e.jsx("li",{children:"measure - number"})]}),e.jsxs("div",{children:["See ",e.jsx("a",{target:"_blank",onClick:r=>r.stopPropagation(),className:"text-blue-700",href:"https://docs.semaphor.cloud/concepts/visuals#pie-chart",children:"example"})," in the docs."]})]})})]}),e.jsxs(s.AccordionItem,{value:"item-2",children:[e.jsx(s.AccordionTrigger,{children:"Settings"}),e.jsxs(s.AccordionContent,{className:"space-y-4 px-2",children:[t==="range"&&e.jsx(Te,{}),t!=="text"&&e.jsx(Ge,{}),t==="text"&&e.jsx(Pt,{})]})]}),!["range","text"].includes(t)&&e.jsxs(s.AccordionItem,{value:"item-3",children:[e.jsx(s.AccordionTrigger,{children:"Filters"}),e.jsxs(s.AccordionContent,{className:"space-y-4 px-2",children:[e.jsx(le,{}),e.jsx(xe,{})]})]})]})})}function Gt(){const t=s.useEditorStore(r=>{var o,l;return(l=(o=r==null?void 0:r.card)==null?void 0:o.preferences)==null?void 0:l.sortChart}),{setSortChart:n}=s.useEditorActions();function a(){return e.jsxs("div",{className:"space-y-2",children:[e.jsx(s.Label,{children:"Sort"}),e.jsx(ee,{className:"h-8",label:"Sort Chart",options:[{label:"None",value:"none"},{label:"ASC",value:"asc"},{label:"DESC",value:"desc"}],value:t||"none",onValueChange:r=>{n(r)}})]})}return e.jsx("div",{className:"space-y-6 px-6 py-2",children:e.jsxs(s.Accordion,{defaultValue:["item-2"],type:"multiple",children:[e.jsxs(s.AccordionItem,{value:"item-1",children:[e.jsx(s.AccordionTrigger,{children:"Stacked Chart"}),e.jsxs(s.AccordionContent,{className:"space-y-4 font-mono text-xs",children:[e.jsx("div",{className:"rounded bg-muted px-2 py-1 text-xs",children:"SELECT x-axis, stack-by, y-axis FROM table"}),e.jsxs("ul",{className:"ml-6 list-disc text-xs [&>li]:mt-2",children:[e.jsx("li",{children:"x-axis - category"}),e.jsx("li",{children:"stack by - category"}),e.jsx("li",{children:"y-axis - number"})]}),e.jsxs("div",{children:["See ",e.jsx("a",{target:"_blank",onClick:r=>r.stopPropagation(),className:"text-blue-700",href:"https://docs.semaphor.cloud/concepts/visuals#stacked-chart",children:"example"})," in the docs."]})]})]}),e.jsxs(s.AccordionItem,{value:"item-2",children:[e.jsx(s.AccordionTrigger,{children:"Settings"}),e.jsxs(s.AccordionContent,{className:"space-y-4 px-2",children:[e.jsx(Te,{}),a(),e.jsx(_s,{})]})]}),e.jsxs(s.AccordionItem,{value:"item-3",children:[e.jsx(s.AccordionTrigger,{children:"Filters"}),e.jsxs(s.AccordionContent,{className:"space-y-4 px-2",children:[e.jsx(le,{}),e.jsx(xe,{})]})]})]})})}function $t({}){const t=s.useEditorStore(r=>{var o;return(o=r.card)==null?void 0:o.preferences}),n=s.useEditorStore(r=>r.actions.setCardPreferences),a=r=>{n({...t,allowDownload:r})};return e.jsxs("div",{className:"space-y-6 px-6 py-2",children:[e.jsx(s.Accordion,{defaultValue:["item-3"],type:"multiple",children:e.jsxs(s.AccordionItem,{value:"item-3",children:[e.jsx(s.AccordionTrigger,{children:"Filters"}),e.jsxs(s.AccordionContent,{className:"space-y-4 px-2",children:[e.jsx(le,{}),e.jsx(xe,{})]})]})}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(s.Checkbox,{onCheckedChange:a,id:"allow-download"}),e.jsx("label",{htmlFor:"allow-download",className:"text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70",children:"Allow Download"})]})]})}const Qt=e.jsxs("div",{className:"space-y-4 font-mono text-xs",children:[e.jsx("div",{className:"rounded bg-muted px-2 py-1 text-xs",children:"SELECT dimension, cohort, metric FROM table"}),e.jsxs("div",{children:["See ",e.jsx("a",{target:"_blank",onClick:t=>t.stopPropagation(),className:"text-blue-700",href:"https://docs.semaphor.cloud/concepts/visuals#pyramid-chart",children:"example"})," in the docs."]})]}),Ut=e.jsxs("div",{className:"space-y-4 font-mono text-xs",children:[e.jsx("div",{className:"rounded bg-muted px-2 py-1 text-xs",children:"SELECT y-axis, label, range-from, range-to, range-value FROM table"}),e.jsxs("div",{children:["See ",e.jsx("a",{target:"_blank",onClick:t=>t.stopPropagation(),className:"text-blue-700",href:"https://docs.semaphor.cloud/concepts/visuals#range-charts",children:"example"})," in the docs."]})]}),Jt=e.jsxs("div",{className:"space-y-4 font-mono text-xs",children:[e.jsx("div",{className:"rounded bg-muted px-2 py-1 text-xs",children:"SELECT text FROM table limit 1"}),e.jsxs("div",{children:["See ",e.jsx("a",{target:"_blank",onClick:t=>t.stopPropagation(),className:"text-blue-700",href:"https://docs.semaphor.cloud/concepts/visuals#text-visual",children:"example"})," in the docs."]})]});function Kt(){const t=s.useEditorStore(a=>a.card.type);function n(a){switch(a){case"stackedBar":case"stackedLine":return e.jsx(Gt,{});case"pyramid":return e.jsx(we,{docContent:Qt,cardType:a});case"kpi":return e.jsx(Rt,{});case"line":case"bar":return e.jsx(Tt,{cardType:a});case"range":return e.jsx(we,{docContent:Ut,cardType:a});case"pie":case"doughnut":case"polarArea":case"radar":return e.jsx(we,{cardType:a});case"bubble":case"scatter":return e.jsx(At,{cardType:a});case"table":return e.jsx($t,{cardType:a});case"text":return e.jsx(we,{docContent:Jt,cardType:a,suffix:"Visual"});case"map":return e.jsx(Ht,{});case"custom":return e.jsx(kt,{});default:return e.jsx(Ft,{})}}return e.jsx(s.ScrollArea,{className:"h-full w-full text-sm",children:n(t)})}function Wt(){const t=s.useEditorStore(n=>n.isShowingVisual);return e.jsxs(s.ResizablePanelGroup,{direction:"vertical",className:"min-h-[250px] min-w-full max-w-lg",children:[e.jsx(s.ResizablePanel,{role:"query-section",className:"flex",minSize:20,defaultSize:40,children:e.jsx(pt,{})}),e.jsx(s.ResizableHandle,{withHandle:!0,className:"border"}),e.jsx(s.ResizablePanel,{className:"pb-1",role:"visual-section",minSize:0,defaultSize:60,children:t?e.jsxs(s.ResizablePanelGroup,{direction:"horizontal",children:[e.jsx(e.Fragment,{children:e.jsx(s.ResizablePanel,{className:"flex min-w-[275px]",minSize:20,defaultSize:25,maxSize:30,children:e.jsx(Kt,{})})}),e.jsx(s.ResizableHandle,{className:"border"}),e.jsx(s.ResizablePanel,{minSize:40,defaultSize:75,maxSize:100,children:e.jsx(Ke,{})})]}):e.jsx(Ke,{})})]})}function Yt({authToken:t,onSave:n,onClose:a}){s.useDashboardStore(i=>i.themeStyle);const r=s.useEditorStore(i=>i.actions.setOnSave),o=s.useEditorStore(i=>i.actions.setOnClose),l=s.useDashboardStore(i=>i.actions.setAuthToken);return w.useEffect(()=>{n&&r(n),a&&o(a)},[n,r,a,o]),w.useEffect(()=>{t&&t.accessToken&&l(t)},[t,l]),e.jsx(s.ErrorBoundary,{FallbackComponent:s.Fallback,children:e.jsxs(s.EditorPanel,{style:{},className:"rounded-none",role:"editor-panel",children:[e.jsx(s.EditorAside,{className:"rounded-none border-r-[1.5px]",children:e.jsx(ws,{})}),e.jsx(s.EditorMain,{children:e.jsx(Wt,{})})]})})}function Xt(){s.useDashboardStore(i=>i.selectedCardId);const t=s.useDashboardStore(i=>i.selectedSheetId),{setIsVisualEditing:n}=s.useDashboardStore(i=>i.actions),a=s.useDashboardStore(i=>i.isVisualEditing),r=s.useDashboardStore(i=>i.actions.updateFrame);function o(i){t&&(r(t,i),n(!1))}function l(){n(!1)}return e.jsx("div",{role:"editor-container",className:s.cn("flex grow",{"max-h-0 overflow-hidden":!a}),children:e.jsx(Yt,{onSave:o,onClose:l})})}function Zt(){s.useEditorStore(i=>i.selectedConnectionId),s.useEditorStore(i=>i.selectedDatamodelId);const t=s.useEditorStore(i=>i.selectedDatabaseName);s.useEditorStore(i=>i.selectedSchemaName);const n=s.useEditorStore(i=>i.selectedTableName),a=s.useDashboardStore(i=>i.dashboard.filters)||[];s.useDashboardStore(i=>i.actions.addFilter),s.useDashboardStore(i=>i.actions.removeFilter),s.useDashboardStore(i=>i.actions.removeFilterValue);const{modelItems:r,columns:o}=ie(),{assignFilter:l}=Bs();return e.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 d=a==null?void 0:a.find(c=>c.column===s.fmt(i.column_name)&&c.table===n&&c.database===t);return e.jsx("div",{onClick:()=>l(i),className:s.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":d}),children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Ns,{column:i}),e.jsx("span",{children:i.column_name})]})},i.column_name)})})}function ea(){s.useDashboardStore(n=>n.showFilters);const t=s.useDashboardStore(n=>n.actions.setShowFilters);return e.jsxs("section",{className:"relative flex grow flex-col border-l px-4",children:[e.jsxs("div",{className:"mt-4 flex items-center justify-between gap-2 px-3",children:[e.jsx(s.Label,{className:"text-lg",children:"Filters"}),e.jsx(s.Button,{onClick:()=>t(!1),className:"h-7 w-7 p-0",variant:"ghost",children:e.jsx(s.Cross2Icon,{})})]}),e.jsx("div",{className:"flex grow",children:e.jsx(ws,{ColumnsComponent:()=>e.jsx(Zt,{})})})]})}function sa(){const t=s.useDashboardStore(a=>a.showFilters),n=s.useDashboardStore(a=>a.isVisualEditing);return e.jsxs("div",{role:"dashboard-plus-main",className:s.cn("",{"max-h-0 overflow-hidden":n,"flex grow":!n}),children:[e.jsx(s.DashboardTabs,{}),t&&e.jsx("div",{role:"filter-aside-container",className:"flex",children:e.jsx(ea,{})})]})}function ta(){const t=s.useDashboardStore(r=>r.dashboard),n=s.useDashboardStore(r=>r.actions.setDashboard),a=s.useDashboardStore(r=>r.showDashboardJSON);return s.useDashboardStore(r=>r.actions.setShowDashboardJSON),e.jsx("div",{className:s.cn(" p-2",{hidden:!a}),children:e.jsx(s.de,{onChange:r=>{if(r)try{JSON.parse(r),n(JSON.parse(r))}catch{}},defaultLanguage:"json",className:"h-[550px] overflow-y-auto ",value:JSON.stringify(t,null,2),options:{minimap:{enabled:!1},glyphMargin:!1,wordWrap:"on",scrollbar:{verticalScrollbarSize:0,horizontalScrollbarSize:0},fontSize:12,renderLineHighlight:"none"}})})}function aa({showControls:t=!1,showFooter:n=!0,...a}){return e.jsx(s.ErrorBoundary,{FallbackComponent:s.Fallback,children:e.jsxs(s.SemaphorContextProvider,{dashboardProps:a,children:[e.jsx(s.Te,{}),e.jsxs(s.UXProvider,{children:[e.jsx(ta,{}),e.jsxs(s.DashboardPanel,{...a,children:[t&&e.jsx(Ys,{}),e.jsx(Xt,{}),e.jsx(sa,{})]})]})]})})}exports.Box=Ye;exports.ChartArea=Xe;exports.ChartColumnIncreasing=Ie;exports.ChartLine=De;exports.ChartNoAxesGantt=Fe;exports.ChartPie=Me;exports.ChartScatter=Ve;exports.CircleX=Ze;exports.CopyPlus=es;exports.DashboardPlus=aa;exports.Database=ss;exports.EllipsisVertical=Re;exports.Eraser=ts;exports.Eye=ns;exports.EyeClosed=as;exports.Glasses=rs;exports.Hammer=os;exports.Hash=is;exports.House=ls;exports.Key=qe;exports.ListEnd=cs;exports.ListStart=ds;exports.ListX=us;exports.LoaderCircle=me;exports.Map=_e;exports.MessageSquareMore=hs;exports.Network=ms;exports.Pencil=Be;exports.Play=xs;exports.Plug2=ps;exports.Save=fs;exports.SelectComponent=he;exports.Shapes=He;exports.ShieldQuestion=gs;exports.Sigma=js;exports.SwatchBook=bs;exports.Tag=ys;exports.ToggleLeft=vs;exports.Type=Le;exports.User=Ss;exports.cleanCard=Cs;exports.getDashbaordStateWithoutData=Pe;exports.useEditorAside=ie;