react-semaphor 0.0.618 → 0.0.620
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.
- package/dist/chunks/{dashboard-plus-BpMGpCEZ.js → dashboard-plus-CwH87Va_.js} +2 -2
- package/dist/chunks/{dashboard-plus-CgfFsIpk.js → dashboard-plus-DbTekpm4.js} +1 -1
- package/dist/chunks/index-CcuNR3a7.js +919 -0
- package/dist/chunks/{index-lV-NY-Ph.js → index-DyxKgRLI.js} +16470 -16331
- package/dist/dashboard/index.cjs +1 -1
- package/dist/dashboard/index.js +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.js +3 -3
- package/dist/style.css +1 -1
- package/dist/surfboard/index.cjs +1 -1
- package/dist/surfboard/index.js +1 -1
- package/dist/types/dashboard.d.ts +1 -1
- package/dist/types/main.d.ts +1 -1
- package/dist/types/surfboard.d.ts +1 -1
- package/dist/types/types.d.ts +1 -1
- package/package.json +1 -1
- package/dist/chunks/index-B5af7bTk.js +0 -919
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";const e=require("react/jsx-runtime"),s=require("./index-
|
|
1
|
+
"use strict";const e=require("react/jsx-runtime"),s=require("./index-CcuNR3a7.js"),I=require("react");require("react-dom");function sa(t){const a=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(t){for(const n in t)if(n!=="default"){const r=Object.getOwnPropertyDescriptor(t,n);Object.defineProperty(a,n,r.get?r:{enumerable:!0,get:()=>t[n]})}}return a.default=t,Object.freeze(a)}const ke=sa(I);/**
|
|
2
2
|
* @license lucide-react v0.453.0 - ISC
|
|
3
3
|
*
|
|
4
4
|
* This source code is licensed under the ISC license.
|
|
@@ -344,7 +344,7 @@
|
|
|
344
344
|
|
|
345
345
|
${d?`Python:
|
|
346
346
|
${d}`:""}
|
|
347
|
-
`;v(Y)}function R(){return e.jsxs(e.Fragment,{children:[r&&e.jsx("div",{className:"relative flex w-1/3 min-w-0 grow overflow-hidden text-xs",role:"editor-filter-container",children:e.jsx("div",{className:"mt-2 w-[99%]",children:e.jsx(_n,{jsonString:JSON.stringify(u,null,2)})})}),u&&u.length>0&&e.jsx(s.Button,{variant:"ghost",onClick:()=>l(!r),className:"absolute bottom-0 right-6 size-7 p-1",children:r?e.jsx(s.X,{className:"size-3.5 text-muted-foreground"}):e.jsx(s.Filter,{className:"size-3.5 text-muted-foreground"})})]})}function P(){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:a?20:100,className:"relative flex grow",children:[e.jsx("div",{id:"sql-container",className:"relative flex w-[99%]",children:e.jsx(zn,{})}),a&&e.jsx("code",{className:"absolute right-6 top-3 text-xs text-muted-foreground/70",children:"sql"})]}),a&&e.jsxs(e.Fragment,{children:[e.jsx(s.ResizableHandle,{withHandle:!0,className:"border"}),e.jsxs(s.ResizablePanel,{id:"2",order:2,defaultSize:80,className:"relative flex grow",children:[e.jsx("div",{id:"python-container",className:"relative flex w-[99%] pt-0",children:e.jsx(Vn,{})}),e.jsx("code",{className:"absolute right-6 top-3 text-xs text-muted-foreground/70",children:"python"})]})]})]})}function K(){return e.jsxs("div",{role:"editor-controls",className:"item-center flex flex-wrap justify-between gap-2 px-6 py-4",children:[e.jsxs("div",{className:"flex grow items-center gap-2",children:[e.jsxs(s.Button,{title:"Shift + Enter",disabled:D||N,onClick:()=>{A()},className:"h-8 shrink-0",size:"sm",children:[D||N?e.jsx(s.LoaderCircle,{className:"mr-2 h-4 w-4 animate-spin"}):e.jsx(s.Play,{className:"mr-2 h-4 w-4"}),"Run"]}),e.jsx(wt,{errorSql:T,sql:y==null?void 0:y.sql,error:O,onDebugWithAssistant:M}),e.jsx(rs,{}),e.jsx(s.Toggle,{pressed:a,onPressedChange:Y=>n(Y),className:"h-8",size:"sm",variant:"outline",children:e.jsx(Pn,{className:"size-4 text-foreground/70"})}),e.jsx("button",{disabled:c,onClick:()=>{k(!0)},className:"h-9 w-full cursor-text px-3 text-left text-sm text-muted-foreground",children:c?"":"Type your question..."})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Ds,{}),e.jsx(ws,{})]})]})}return e.jsxs("section",{role:"editor-section",className:"flex grow flex-col justify-end",children:[e.jsxs("div",{className:"relative flex grow justify-between overflow-y-scroll",children:[P(),R()]}),K()]})}const $n=[{value:"table",label:"Table",icon:s.Table2},{value:"aggregateTable",label:"Aggregate",icon:s.Layers},{value:"pivotTable",label:"Pivot",icon:ns}];function qn({className:t}){const a=s.useEditorStore(d=>d.card),{setCardType:n,setCard:r,updateCardInFrame:l}=s.useEditorActions(),o=["table","aggregateTable","pivotTable"].includes(a.type),c=s.hasValidCardConfig(a.config);if(!o||!c)return null;const i=d=>{var m;const u=d;if(u==="aggregateTable"&&((m=a.config)!=null&&m.pivotByColumns)&&a.config.pivotByColumns.length>0){const h={...a,type:u,config:{...a.config,pivotByColumns:[]}};r(h),l(h)}else{n(u);const h={...a,type:u};l(h)}};return e.jsx("div",{className:s.cn("flex items-center",t),children:e.jsx(s.RadioGroup,{value:a.type,onValueChange:i,className:"flex flex-row items-center justify-between gap-1 rounded-lg border p-1",children:$n.map(d=>{const u=d.icon;return e.jsxs("div",{className:"flex items-center",children:[e.jsx(s.RadioGroupItem,{value:d.value,id:`table-type-${d.value}`,className:"peer sr-only"}),e.jsxs(s.Label,{htmlFor:`table-type-${d.value}`,className:s.cn("flex cursor-pointer items-center gap-1.5 rounded-md px-3 py-1 text-sm font-medium transition-all","hover:bg-muted","peer-data-[state=checked]:bg-background peer-data-[state=checked]:shadow-sm"),children:[e.jsx(u,{className:"h-3.5 w-3.5"}),d.label]})]},d.value)})})})}function Gn({card:t}){var v,k,L,C,S,y,D,N,B,w,F;const[a,n]=I.useState(!1),[r,l]=I.useState([]),{authToken:o}=s.useSemaphorContext(),c=s.getTokenParams(o==null?void 0:o.accessToken),i=s.useDashboardStore(T=>T.themeStyle),d={colors:((k=(v=i==null?void 0:i.chart)==null?void 0:v.dataset)==null?void 0:k.backgroundColor)||[]};(L=t.customCardPreferences)!=null&&L.inputData;const{getCard:u}=s.useCustomVisual(((C=t.customCardPreferences)==null?void 0:C.url)||""),m=((S=t.customCardPreferences)==null?void 0:S.visualType)||"single",h=s.useEditorStore(T=>T.frame),{setCustomCardPreferences:f}=s.useEditorActions(),{data:g}=s.useDashboardCardQuery(t),b=I.useCallback((T,E)=>{l(A=>({...A,[T]:E}))},[]);if(!((y=t.customCardPreferences)!=null&&y.componentName))return null;const p=u((D=t.customCardPreferences)==null?void 0:D.componentName);function j(T){n(T)}const x=Object.keys(((N=t.customCardPreferences)==null?void 0:N.dataInputCardIds)||{}).map(T=>{var O,M,R;const E=(M=(O=t.customCardPreferences)==null?void 0:O.dataInputCardIds)==null?void 0:M[T].cardId,A=(R=h==null?void 0:h.cards)==null?void 0:R.find(P=>P.id===E);return A||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(I.Suspense,{fallback:e.jsx(e.Fragment,{}),children:[p&&m==="single"&&e.jsx(p,{editing:!0,params:c,theme:d,settings:(B=t.customCardPreferences)==null?void 0:B.settings,onDataChange:b,data:(g==null?void 0:g.records)||[]}),p&&m==="multiple"&&e.jsxs(e.Fragment,{children:[Object.keys(((w=t.customCardPreferences)==null?void 0:w.dataInputCardIds)||{}).map(T=>{var O,M,R;const E=(M=(O=t.customCardPreferences)==null?void 0:O.dataInputCardIds)==null?void 0:M[T].cardId,A=(R=h==null?void 0:h.cards)==null?void 0:R.find(P=>P.id===E);if(A)return e.jsx(s.MultiInputEmptyRenderer,{onLoadingStatus:j,onDataChange:b,dataInputIndex:T,card:A},A.id+T)}),e.jsx("div",{className:"flex flex-col gap-2",children:e.jsx(p,{theme:d,onDataChange:b,settings:x.map(T=>{var E;return(E=T==null?void 0:T.customCardPreferences)==null?void 0:E.settings}),data:x.map(T=>T!=null&&T.id?r==null?void 0:r[T.id]:[])})})]})]},(F=t.customCardPreferences)==null?void 0:F.componentName)})}function kt({className:t,...a}){var D;const n=s.useEditorStore(N=>N.card),r=s.isExplorerCard(n),l=((D=n.customCardPreferences)==null?void 0:D.showCardHeader)??!0,o=s.useEditorStore(N=>N.frame),c=s.useDashboardStore(N=>N.dashboard.filters),i=s.useEditorStore(N=>N.actions.setRunSql),{updateFilter:d}=s.useDashboardActions(),u=c==null?void 0:c.find(N=>N.id===o.filterId),{data:m,isLoading:h,isFetching:f,errorMessage:g,pagination:b}=s.useDashboardCardQuery(n),{setCard:p,updateCardInFrame:j}=s.useEditorActions(),{data:x}=s.useTopoJson(n),v=I.useMemo(()=>{var N;return n.type!=="pivotTable"||!((N=m==null?void 0:m.records)!=null&&N.length)?null:{records:m.records,columnSubtotalMeta:m.columnSubtotalMeta,subtotalColumns:m.subtotalColumns||[],pivotSchema:m.pivotSchema||[],groupByColumns:m.groupByColumns}},[n.type,m==null?void 0:m.records,m==null?void 0:m.columnSubtotalMeta,m==null?void 0:m.subtotalColumns,m==null?void 0:m.pivotSchema,m==null?void 0:m.groupByColumns]),k=s.usePivotTableConfig(n,v),L=(N,B)=>{var F,T;const w={...n,paginationConfig:{page:N+1,pageSize:B}};p(w),j(w),n.sql&&((T=(F=n.preferences)==null?void 0:F.tablePrefs)!=null&&T.enableDevModePagination)&&i(!0)},C=I.useMemo(()=>!n.id||!(m!=null&&m.records)?null:s.createChartConfig({card:n,data:m==null?void 0:m.records,cardType:n.type,queryConfig:n.queryConfig,customCfg:n.customCfg,preferences:n.preferences,topoJson:x}),[n.id,m==null?void 0:m.records,n.type,n.queryConfig,n.customCfg,n.preferences,x]);function S(N){return e.jsx(s.ErrorBoundary,{FallbackComponent:s.FallbackVisual,children:e.jsx(Gn,{card:N})})}function y(){if(m!=null&&m.records&&(m==null?void 0:m.records.length)===0&&!h&&!f)return g?e.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-2",children:[e.jsx(s.SearchX,{className:"size-8 text-destructive"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:r?"Error fetching data. Please check your chart configuration":"Error fetching data. Please check your SQL or Python code."})]}):e.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-2",children:[e.jsx(s.TreePalm,{className:"size-8 text-muted-foreground"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"No results to display"})]});if((h||f)&&n.type!=="table")return e.jsx("div",{className:"z-50 flex h-full items-center justify-center",children:e.jsx(s.LoadingDots,{size:"md",color:"muted","aria-label":"Loading data"})});if(!n.id)return null;if(n.type==="custom")return S(n);if(!["table","pivotTable","aggregateTable","custom"].includes(n.type)&&C)return e.jsx("div",{className:"relative h-full min-h-0 w-full flex-1 grow basis-0",children:h||f?e.jsx(e.Fragment,{}):e.jsx(s.ChartJsVisual,{cfg:C})});if(n.type==="table")return e.jsx("div",{className:"relative mb-2 flex h-full min-h-0 w-full flex-1 grow basis-0",children:e.jsx(s.TableVisual,{card:n,data:(m==null?void 0:m.records)||[],paginationMetadata:b,onPaginationChange:L,isLoading:h||f})});if(n.type==="pivotTable"&&k)return e.jsx("div",{className:"relative mb-2 flex h-full min-h-0 w-full flex-1 grow basis-0",children:e.jsx(s.PivotTableVisual,{card:n,data:k.data,options:k.options,onAggregationChange:N=>{const B=s.handleAggregationChange(N,n.config),w={...n,config:B};p(w),j(w)},onAggregationLabelChange:N=>{const B=s.handleAggregationLabelChange(N,n.config),w={...n,config:B};p(w),j(w)}})});if(n.type==="aggregateTable")return e.jsx("div",{className:"relative mb-2 flex h-full min-h-0 w-full flex-1 grow basis-0",children:e.jsx(s.AggregateTable,{card:n,data:(m==null?void 0:m.records)||[],groupByColumns:m==null?void 0:m.groupByColumns,pivotSchema:m==null?void 0:m.pivotSchema,paginationMetadata:b,onPaginationChange:L,onAggregationChange:N=>{const B=s.handleAggregationChange(N,n.config),w={...n,config:B};p(w),j(w)},isLoading:h||f})})}return e.jsxs(s.Card,{role:"editor-visual-card",className:s.cn("relative flex h-full flex-col rounded-none",t),...a,children:[l&&e.jsxs(s.CardHeader,{className:"flex flex-row items-start justify-between py-4",children:[e.jsxs("div",{className:"flex-1",children:[e.jsxs("div",{className:"flex items-center gap-5",children:[e.jsx(s.CardTitle,{className:"text-base",children:e.jsx(s.EditableText,{value:n.title,onSave:N=>p({...n,title:N}),isEditable:!0,placeholder:"Add title",displayClassName:"text-base font-semibold",inputClassName:"text-base font-semibold"})}),e.jsx(qn,{})]}),e.jsx("div",{className:"w-1/2",children:e.jsx(s.EditableText,{value:n.description||"",onSave:N=>p({...n,description:N}),isEditable:!0,placeholder:"Add description",displayClassName:"text-sm text-muted-foreground",inputClassName:"text-sm"})})]}),u&&e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(s.Label,{className:"my-1",children:e.jsx(s.EditableText,{value:u.title||u.column,onSave:N=>d({...u,title:N}),isEditable:!0,placeholder:"Filter",displayClassName:"text-sm",inputClassName:"text-sm"})}),e.jsx(s.FilterComponent,{filter:u})]})]}),e.jsx(s.CardContent,{className:"flex grow flex-col",children:y()})]})}const hs=({language:t,value:a,onChange:n,readonly:r})=>e.jsx(s.Ft,{className:"h-full w-full overflow-hidden text-xs",theme:"default",options:{minimap:{enabled:!1},wordWrap:"on",scrollbar:{verticalScrollbarSize:0,horizontalScrollbarSize:0},fontSize:12,lineHeight:16,renderLineHighlight:"none",readOnly:r},defaultLanguage:t,value:a,onChange:n}),Hn=()=>e.jsxs(s.DialogHeader,{children:[e.jsx("div",{className:"flex items-center gap-2",children:e.jsx(s.DialogTitle,{children:"Customize Card"})}),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."})]})]}),Wn=({customCode:t,cardCustomCfgString:a,mergedConfig:n,onConfigChange:r,onCodeChange:l})=>e.jsxs(s.Tabs,{defaultValue:"final-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.jsx(s.TabsTrigger,{value:"final-config",children:"Config"}),e.jsx(s.TabsTrigger,{value:"custom-config",children:"Changes"}),e.jsx(s.TabsTrigger,{value:"custom-code",children:"Custom Code"})]}),e.jsx(s.TabsContent,{value:"final-config",className:"mt-0 grow rounded-b border border-t-0",children:e.jsx(hs,{language:"json",value:n,onChange:r})}),e.jsx(s.TabsContent,{value:"custom-config",className:"mt-0 grow rounded-b border border-t-0",children:e.jsx(hs,{readonly:!0,language:"json",value:a,onChange:()=>{}})}),e.jsx(s.TabsContent,{value:"custom-code",className:"mt-0 grow rounded-b border border-t-0",children:e.jsx(hs,{language:"javascript",value:t,onChange:l})})]}),Kn=({error:t,hasCardCustomConfig:a,onReset:n,onApply:r,onClose:l})=>e.jsxs(s.DialogFooter,{className:"flex items-center",children:[e.jsx(s.Label,{className:"mr-2 text-red-500",children:t}),e.jsx(s.Button,{disabled:!a,onClick:n,variant:"outline",children:"Reset"}),e.jsx(s.Button,{onClick:r,variant:"outline",children:"Apply"}),e.jsx(s.Button,{onClick:l,variant:"outline",children:"Close"})]});function Jn(){const[t,a]=I.useState(!1),[n,r]=I.useState(""),[l,o]=I.useState(""),[c,i]=I.useState(""),[d,u]=I.useState(""),m=s.useEditorStore(C=>C.card),h=s.useEditorStore(C=>C.card.customCfg),f=h?JSON.stringify(h,null,2):"",{data:g}=s.useDashboardCardQuery(m),{data:b}=s.useTopoJson(m),{setCardCustomCfg:p,setCustomVisualCode:j}=s.useEditorActions(),x=C=>{var S,y;return JSON.stringify({...C,data:{...C.data,datasets:(y=(S=C.data)==null?void 0:S.datasets)==null?void 0:y.map(D=>({...D,data:[]}))}},null,2)},v=()=>{var S,y;if(!((S=g==null?void 0:g.records)!=null&&S.length))return;const C=s.createChartConfig({card:m,data:g.records,cardType:m.type,queryConfig:m.queryConfig,preferences:m.preferences,topoJson:b});if(C){r(x(C)),i(((y=m.preferences)==null?void 0:y.customVisualCode)||"");const D=s.merge(C,h);o(x(D))}},k=()=>{try{if(c&&j(c),l){const C=JSON.parse(l),S=s.getObjectDiff(JSON.parse(n),C);p(S),u("")}}catch{u("Invalid JSON configuration")}},L=Object.keys(h||{}).length===0;return e.jsxs(s.Dialog,{open:t,onOpenChange:a,children:[e.jsx(s.DialogTrigger,{asChild:!0,children:e.jsx(s.IconButton,{tooltip:"Customize Visual",onClick:v,className:L?"":"text-green-600 hover:text-green-700",children:e.jsx(s.Settings,{className:"h-4 w-4"})})}),e.jsxs(s.DialogContent,{className:"flex h-[600px] grow flex-col overflow-auto sm:min-w-[900px] lg:min-w-[1200px]",children:[e.jsx(Hn,{}),e.jsxs("div",{className:"flex grow gap-2",children:[e.jsx(s.ErrorBoundary,{FallbackComponent:s.FallbackVisual,children:e.jsx(kt,{className:"w-1/2 rounded shadow-none"})}),e.jsx(Wn,{customCode:c,cardCustomCfgString:f,mergedConfig:l,onConfigChange:C=>o(C??""),onCodeChange:C=>i(C??"")})]}),e.jsx(Kn,{error:d,hasCardCustomConfig:!!h,onReset:()=>{o(n),p(null)},onApply:k,onClose:()=>a(!1)})]})]})}function ls(t){const[a,n]=I.useState(null);return a}function Tt(){const{authToken:t}=s.useSemaphorContext(),{data:a,isLoading:n,isFetching:r,isError:l}=s.useQuery({queryKey:["plugins",t==null?void 0:t.accessToken],queryFn:()=>s.getPlugins(t==null?void 0:t.accessToken)});return{data:a,isLoading:n,isFetching:r,isError:l}}function Et(){const{data:t,isLoading:a,isError:n}=Tt(),r=s.useQueries({queries:((t==null?void 0:t.plugins)||[]).map(i=>({queryKey:["manifest",i.value],queryFn:()=>s.loadManifest(i.value),enabled:!!i.value,staleTime:5*60*1e3,gcTime:10*60*1e3,retry:2,retryDelay:d=>Math.min(1e3*2**d,3e4)}))}),l=[];let o=a,c=n;return r.forEach((i,d)=>{var u;if(i.isLoading&&(o=!0),i.isError&&(c=!0),i.data&&((u=t==null?void 0:t.plugins)!=null&&u[d])){const m=t.plugins[d],h=i.data.visuals.map(f=>({name:f.name,pluginName:m.label,componentType:f.componentType,pluginType:m.type,icon:f.icon,chartType:f.chartType,url:m.value}));l.push(...h)}}),{data:l,isLoading:o,isError:c}}function Qn({onChartTypeChange:t}){const{setCardCustomCfg:a,setCardPreferences:n,setCardType:r,setCustomCardPreferences:l}=s.useEditorActions(),{data:o,isLoading:c,isError:i}=Et(),d=I.useCallback((u,m)=>{a(null),n({}),r(u),m&&l({type:"component",visualType:"single",url:m.url,componentName:m.name,icon:m.icon}),t==null||t()},[a,n,r,l,t]);return c?e.jsxs(e.Fragment,{children:[e.jsx(s.Separator,{className:"my-2"}),e.jsx("div",{className:"grid grid-cols-4 place-items-center",children:e.jsx("div",{className:"text-sm text-muted-foreground",children:"Loading custom visuals..."})})]}):i?e.jsxs(e.Fragment,{children:[e.jsx(s.Separator,{className:"my-2"}),e.jsx("div",{className:"grid grid-cols-4 place-items-center",children:e.jsx("div",{className:"text-sm text-destructive",children:"Failed to load custom visuals"})})]}):!o||o.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:o.map((u,m)=>e.jsx(Xn,{text:u.name,onClick:()=>d("custom",u),icon:u.icon},`${u.url}-${u.name}-${m}`))})]})}const Xn=({text:t,icon:a,onClick:n})=>{const r=ls(),l=t.charAt(0).toUpperCase();return e.jsx(s.IconButton,{onClick:n,tooltip:t,children:r?e.jsx(r,{className:"h-4 w-4"}):l})};function It({onChartTypeChange:t,iconClassName:a}){const{setCardType:n,setCardPreferences:r,setIsDevMode:l}=s.useEditorStore(m=>m.actions),{setCardCustomCfg:o,setCustomCardPreferences:c,setQueryConfig:i}=s.useEditorActions();function d(m,h){o(null),r({}),n(m),["custom","text","map"].includes(m)&&(l(!0),i(void 0)),t==null||t()}const u=1e3;return e.jsxs("div",{className:"grid grid-cols-5 place-items-center",children:[e.jsx(s.IconButton,{openDelay:u,tooltip:"Table",onClick:()=>d("table"),className:"h-10 p-4",children:e.jsx(s.Table2,{className:s.cn("size-5",a)})}),e.jsx(s.IconButton,{openDelay:u,tooltip:"Bar Chart",onClick:()=>d("bar"),className:"h-10 p-4",children:e.jsx(s.ChartColumnIncreasing,{className:s.cn("size-5",a)})}),e.jsx(s.IconButton,{openDelay:u,tooltip:"Line Chart",onClick:()=>d("line"),className:"h-10 p-4",children:e.jsx(s.ChartLine,{className:s.cn("size-5",a)})}),e.jsx(s.IconButton,{openDelay:u,tooltip:"Stacked Bar Chart",onClick:()=>d("stackedBar"),className:"h-10 p-4",children:e.jsx(s.ChartColumnStacked,{className:s.cn("size-5",a)})}),e.jsx(s.IconButton,{openDelay:u,tooltip:"Stacked Line Chart",onClick:()=>d("stackedLine"),className:"h-10 p-4",children:e.jsx(s.MdStackedLineChart,{className:s.cn("size-5",a),strokeWidth:0})}),e.jsx(s.IconButton,{openDelay:u,tooltip:"Scatter Chart",onClick:()=>d("scatter"),className:"h-10 p-4",children:e.jsx(s.ChartScatter,{className:s.cn("size-5",a)})}),e.jsx(s.IconButton,{openDelay:u,tooltip:"Bubble Chart",onClick:()=>d("bubble"),className:"h-10 p-4",children:e.jsx(s.TbChartBubble,{className:s.cn("size-5",a)})}),e.jsx(s.IconButton,{openDelay:u,tooltip:"Pie Chart",onClick:()=>d("pie"),className:"h-10 p-4",children:e.jsx(s.ChartPie,{className:s.cn("size-5",a)})}),e.jsx(s.IconButton,{openDelay:u,tooltip:"Doughnut Chart",onClick:()=>d("doughnut"),className:"h-10 p-4",children:e.jsx(s.Donut,{className:s.cn("size-5",a)})}),e.jsx(s.IconButton,{openDelay:u,tooltip:"Funnel Chart",onClick:()=>d("funnel"),className:"h-10 p-4",children:e.jsx(s.TbChartFunnel,{className:s.cn("size-5",a)})}),e.jsx(s.IconButton,{openDelay:u,tooltip:"Radar Chart",onClick:()=>d("radar"),className:"h-10 p-4",children:e.jsx(s.Radar,{className:s.cn("size-5",a)})}),e.jsx(s.IconButton,{openDelay:u,tooltip:"Polar Area Chart",onClick:()=>d("polarArea"),className:"h-10 p-4",children:e.jsx(s.PiChartPolar,{className:s.cn("size-5",a)})}),e.jsx(s.IconButton,{openDelay:u,tooltip:"Tornado Chart",onClick:()=>d("tornado"),className:"h-10 p-4",children:e.jsx(s.Tornado,{className:s.cn("size-5",a)})}),e.jsx(s.IconButton,{tooltip:"Range Chart",onClick:()=>d("range"),className:"h-10 p-4",children:e.jsx(s.ChartNoAxesGantt,{className:s.cn("size-5",a)})}),e.jsx(s.IconButton,{openDelay:u,tooltip:"KPI",onClick:()=>d("kpi"),className:"h-10 p-4",children:e.jsx(s.TiSortNumerically,{className:s.cn("size-5",a)})}),e.jsx(s.IconButton,{openDelay:u,tooltip:"Text",onClick:()=>d("text"),className:"h-10 p-4",children:e.jsx(s.BookType,{className:s.cn("size-5",a)})}),e.jsx(s.IconButton,{tooltip:"Map",onClick:()=>d("map"),className:"h-10 p-4",children:e.jsx(s.Map,{className:s.cn("size-5",a)})}),e.jsx(s.IconButton,{openDelay:u,tooltip:"Custom",onClick:()=>d("custom"),className:"h-10 p-4",children:e.jsx(Ue,{className:s.cn("size-5",a)})})]})}function Zn({chartType:t,className:a,customIcon:n,componentName:r}){const l=ls();switch(t){case"bar":return e.jsx(s.ChartColumnIncreasing,{className:a});case"line":return e.jsx(s.ChartLine,{className:a});case"pie":return e.jsx(s.ChartPie,{className:a});case"radar":return e.jsx(s.Radar,{className:a});case"scatter":return e.jsx(s.ChartScatter,{className:a});case"bubble":return e.jsx(s.TbChartBubble,{className:a});case"doughnut":return e.jsx(s.Donut,{className:a});case"stackedBar":return e.jsx(s.ChartColumnStacked,{className:a});case"stackedLine":return e.jsx(s.MdStackedLineChart,{className:a});case"polarArea":return e.jsx(s.PiChartPolar,{className:a});case"funnel":return e.jsx(s.TbChartFunnel,{className:a});case"tornado":case"pyramid":return e.jsx(s.Tornado,{className:a});case"range":return e.jsx(s.ChartNoAxesGantt,{className:a});case"kpi":return e.jsx(s.TiSortNumerically,{className:a});case"text":return e.jsx(ge,{className:a});case"map":return e.jsx(s.Map,{className:a});case"custom":return n&&l?e.jsx(l,{className:a}):r?r==null?void 0:r.charAt(0).toUpperCase():e.jsx(Ue,{className:a});default:return e.jsx(s.Table2,{className:a})}}function At({variant:t="ghost"}){var o,c;const[a,n]=I.useState(!1),r=s.useEditorStore(i=>i.card),l=r.type;return s.useDashboardStore(i=>i.isVisualEditing),e.jsxs(s.Popover,{open:a,onOpenChange:n,children:[e.jsx(s.PopoverTrigger,{asChild:!0,children:e.jsx(s.Button,{size:"sm",variant:t||"ghost",children:e.jsx(Zn,{className:"size-4",chartType:l,customIcon:(o=r.customCardPreferences)==null?void 0:o.icon,componentName:(c=r.customCardPreferences)==null?void 0:c.componentName})})}),e.jsxs(s.PopoverContentCustom,{onOpenAutoFocus:i=>i.preventDefault(),className:"w-72 p-1",children:[e.jsx(It,{onChartTypeChange:()=>n(!1)}),e.jsx(Qn,{onChartTypeChange:()=>n(!1)})]})]})}function er({error:t,className:a="",textClassName:n="",copyButtonClassName:r=""}){const[l,o]=I.useState(!1),c=I.useRef(null),i=I.useRef(!1);function d(){t&&!i.current&&navigator.clipboard.writeText(t)}function u(f){(f.key==="Enter"||f.key===" ")&&(f.preventDefault(),d())}function m(){const f=window.getSelection();if(f&&f.toString().trim()!==""){const g=f.toString();navigator.clipboard.writeText(g),o(!0),i.current=!0,setTimeout(()=>{o(!1),i.current=!1},1e3)}else i.current=!1}function h(){o(!1),i.current=!1}return e.jsxs("div",{className:`relative rounded-md border border-red-200 bg-red-50 p-3 dark:border-red-800 dark:bg-red-950/20 ${a}`,children:[e.jsx("div",{className:"float-right mb-2 ml-2",children:e.jsx(s.CopyButton,{text:t,className:`h-6 w-6 p-0 text-red-600 hover:text-red-700 dark:text-red-400 dark:hover:text-red-300 ${r}`})}),e.jsx("div",{ref:c,className:`cursor-pointer select-text break-all font-mono text-xs text-red-700 dark:text-red-300 ${n}`,onClick:d,onKeyDown:u,onMouseUp:m,onMouseDown:h,tabIndex:0,role:"button","aria-label":"Click to copy error message or select text to copy",children:t}),l&&e.jsx("div",{className:"absolute bottom-1 right-1 rounded bg-green-100 px-2 py-1 text-xs text-green-600 dark:bg-green-900/30 dark:text-green-400",children:"Copied!"}),e.jsx("div",{className:"clear-both"})]})}function sr(){const t=s.useEditorStore(o=>{var c,i;return(i=(c=o.card.preferences)==null?void 0:c.chartOptions)==null?void 0:i.indexAxis}),a=s.useEditorStore(o=>o.card.type),{setChartOrientation:n}=s.useEditorStore(o=>o.actions);function r(){return e.jsx(s.IconButton,{onClick:()=>{n(t==="x"||t===void 0?"y":"x")},tooltip:"Chart Orientation",children:t==="x"||t===void 0?e.jsx(zs,{className:"size-4"}):e.jsx(Ps,{className:"size-4"})})}function l(){return e.jsx(s.IconButton,{onClick:()=>{n(t==="y"||t===void 0?"x":"y")},tooltip:"Chart Orientation",children:t==="y"||t===void 0?e.jsx(zs,{className:"size-4"}):e.jsx(Ps,{className:"size-4"})})}return e.jsx(e.Fragment,{children:a==="funnel"?l():r()})}function Mt(){const t=s.useEditorStore(c=>c.card),a=s.useEditorStore(c=>c.isShowingVisual),n=s.useEditorStore(c=>{var i,d;return(d=(i=c.card)==null?void 0:i.preferences)==null?void 0:d.chartOptions}),r=s.getChartGridStyle(n),{setChartGrid:l}=s.useEditorActions();function o(){const c=["xy","none","x","y"],d=(c.indexOf(r)+1)%c.length;l(c[d])}return a?e.jsxs("div",{"data-info":"visual-settings",className:"flex items-center",children:[["line","bar","range","stackedBar","stackedLine","horizontalBar","funnel"].includes(t.type)&&e.jsx(e.Fragment,{children:e.jsx(sr,{})}),!["kpi","text","custom","table"].includes(t.type)&&e.jsx(e.Fragment,{}),!["pie","doughnut","funnel","radar","polarArea","table","custom","kpi","text","map"].includes(t.type)&&e.jsxs(s.IconButton,{tooltip:"Grid Style",onClick:o,children:[(r==="xy"||!r)&&e.jsx(ns,{className:"size-4"}),r==="x"&&e.jsx(ma,{className:"size-4"}),r==="y"&&e.jsx(za,{className:"size-4"}),r==="none"&&e.jsx($a,{className:"size-4"})]})]}):null}function tr(){const t=s.useEditorStore(b=>b.frame),a=s.useEditorStore(b=>b.card),{setFrame:n,setActiveTabCardId:r,setCard:l,updateCardInFrame:o}=s.useEditorActions(),c=(b,p)=>{b.dataTransfer.setData("tabIndex",p.toString())},i=b=>{b.preventDefault()},d=(b,p)=>{const j=b.dataTransfer.getData("tabIndex");if(j===p.toString())return;const x=Array.from(t.cards),[v]=x.splice(parseInt(j),1);x.splice(p,0,v),n({...t,cards:x})};function u(b){const p=t.cards.filter(v=>v.id!==b),j=p[0],x={...t,cards:p,activeCardId:j.id};n(x),r(j.id),l(j)}function m(b,p){const j={...t,cards:[...t.cards,p],activeCardId:b.id};n(j),r(p.id)}function h(){const b={...a,id:s.v4(),title:`${a.title} Copy`,tabTitle:`${a.tabTitle||a.title} Copy`};m(a,b)}function f(b){const p={dataSource:b.dataSource,connectionId:b.connectionId,lastSelectedDatabase:b.lastSelectedDatabase,lastSelectedSchema:b.lastSelectedSchema,lastSelectedTable:b.lastSelectedTable,lastSelectedDatamodelId:b.lastSelectedDatamodelId,id:s.v4(),title:"Title",description:"",preferences:{onClickFilter:[{columnIndex:0,expression:""}]},type:"bar",sql:"",data:[],mode:"explorer"};m(b,p)}function g(b,p){return b.cards.length===1&&(p.displayTab===!0||p.displayTab===void 0)||b.activeCardId!==p.id&&(p.displayTab===!0||p.displayTab===void 0)?null:e.jsx("div",{onClick:()=>{const j=p.displayTab===void 0?!1:!p.displayTab;l({...p,displayTab:j}),o({...p,displayTab:j})},children:p.displayTab===!0||p.displayTab===void 0?e.jsx(s.Eye,{className:"mr-2 size-3.5 text-muted-foreground hover:text-foreground"}):e.jsx(fa,{className:"mr-2 size-3.5 text-muted-foreground hover:text-foreground"})})}return e.jsx(s.TabsList,{className:"group mx-4 justify-between overflow-x-auto",children:e.jsxs("div",{className:"flex items-center",children:[t.cards.map((b,p)=>e.jsxs(s.TabsTrigger,{draggable:!0,onDragStart:j=>c(j,p),onDragOver:i,onDrop:j=>d(j,p),className:"",value:b.id,children:[g(t,b),e.jsx(s.Editable,{enabled:t.activeCardId===b.id,text:b.tabTitle||b.title,onSave:j=>{l({...a,tabTitle:j}),o({...a,tabTitle:j})},children:b.tabTitle||b.title},b.id),t.activeCardId===b.id&&t.cards.length>1&&e.jsx(s.X,{className:"ml-2 size-3.5 text-muted-foreground hover:text-foreground",onClick:()=>u(b.id)})]},b.id)),e.jsx(s.Button,{className:"ml-1 h-8 px-2 hover:bg-muted-foreground/50",variant:"outline",onClick:()=>f(a),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:h,children:e.jsx(xa,{className:"h-4 w-4"})})]})})}function Lt(){const t=s.useEditorStore(p=>p.frame),a=s.useEditorStore(p=>p.card),n=s.useEditorStore(p=>p.isSqlRunning),r=s.useEditorStore(p=>p.isDevMode),{setFrame:l,setActiveTabCardId:o,setCard:c,setIsDevMode:i,setRunSql:d}=s.useEditorActions(),{data:u,isLoading:m,isFetching:h}=s.useDashboardCardQuery(a);function f(p){const j=t.cards.find(x=>x.id===p);if(j!=null&&j.sql){r||i(!0),o(p);return}if(j!=null&&j.queryConfig){r&&i(!1),g(p),o(p);return}r||g(p),o(p)}function g(p){const j={...t,cards:t.cards.map(v=>v.id===a.id?a:v),activeCardId:p};l(j);const x=j.cards.find(v=>v.id===p);x.sql&&d(!0),c(x)}function b(){return a.type==="kpi"?m||h?e.jsx("div",{className:"z-50 flex h-full items-center justify-center",children:e.jsx(s.LoadingDots,{size:"md",color:"muted","aria-label":"Loading data"})}):e.jsx("div",{className:"flex h-full items-center justify-center",children:e.jsx("div",{className:"w-1/2 rounded-md border border-border",children:e.jsx(s.KPICard,{card:a,data:u==null?void 0:u.records,isPending:m||h})})}):a.type==="text"?m||h?e.jsx("div",{className:"z-50 flex h-full items-center justify-center",children:e.jsx(s.LoadingDots,{size:"md",color:"muted","aria-label":"Loading data"})}):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:n,card:a,data:u==null?void 0:u.records})})})}):e.jsx(s.ErrorBoundary,{FallbackComponent:s.FallbackVisual,children:e.jsx(kt,{className:"grow border-none shadow-none"})})}return e.jsxs(s.Tabs,{onValueChange:f,value:t.activeCardId,className:"flex grow flex-col",children:[t.cards.map(p=>e.jsx(s.TabsContent,{className:"mt-0 grow",value:p.id,children:b()},p.id)),e.jsx(tr,{})]})}function Je({children:t}){var L,C;s.useEditorStore(S=>S.frame);const a=s.useEditorStore(S=>S.card),n=s.useEditorStore(S=>S.isDevMode),r=s.useEditorStore(S=>S.isShowingVisual),l=s.useDashboardStore(S=>S.isVisualEditing),o=s.useEditorStore(S=>S.pythonStdOut);s.useEditorStore(S=>S.actions.setRunSql);const{setFrame:c,setCard:i,setActiveTabCardId:d,runAssistant:u,setIsDevMode:m,setCardPreferences:h}=s.useEditorActions(),{data:f,isLoading:g,isFetching:b,errorMessage:p,refetch:j}=s.useDashboardCardQuery(a);function x(){const S=JSON.stringify(f==null?void 0:f.records,null,2),y=new Blob([S],{type:"application/json"}),D=URL.createObjectURL(y),N=document.createElement("a");N.href=D,N.download=`${a.title}.json`,N.click()}function v(){const y=[Object.keys(f==null?void 0:f.records.reduce((w,F)=>({...w,...F}),{})).join(","),...((f==null?void 0:f.records)||[]).map(w=>Object.values(w).join(","))].join(`
|
|
347
|
+
`;v(Y)}function R(){return e.jsxs(e.Fragment,{children:[r&&e.jsx("div",{className:"relative flex w-1/3 min-w-0 grow overflow-hidden text-xs",role:"editor-filter-container",children:e.jsx("div",{className:"mt-2 w-[99%]",children:e.jsx(_n,{jsonString:JSON.stringify(u,null,2)})})}),u&&u.length>0&&e.jsx(s.Button,{variant:"ghost",onClick:()=>l(!r),className:"absolute bottom-0 right-6 size-7 p-1",children:r?e.jsx(s.X,{className:"size-3.5 text-muted-foreground"}):e.jsx(s.Filter,{className:"size-3.5 text-muted-foreground"})})]})}function P(){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:a?20:100,className:"relative flex grow",children:[e.jsx("div",{id:"sql-container",className:"relative flex w-[99%]",children:e.jsx(zn,{})}),a&&e.jsx("code",{className:"absolute right-6 top-3 text-xs text-muted-foreground/70",children:"sql"})]}),a&&e.jsxs(e.Fragment,{children:[e.jsx(s.ResizableHandle,{withHandle:!0,className:"border"}),e.jsxs(s.ResizablePanel,{id:"2",order:2,defaultSize:80,className:"relative flex grow",children:[e.jsx("div",{id:"python-container",className:"relative flex w-[99%] pt-0",children:e.jsx(Vn,{})}),e.jsx("code",{className:"absolute right-6 top-3 text-xs text-muted-foreground/70",children:"python"})]})]})]})}function K(){return e.jsxs("div",{role:"editor-controls",className:"item-center flex flex-wrap justify-between gap-2 px-6 py-4",children:[e.jsxs("div",{className:"flex grow items-center gap-2",children:[e.jsxs(s.Button,{title:"Shift + Enter",disabled:D||N,onClick:()=>{A()},className:"h-8 shrink-0",size:"sm",children:[D||N?e.jsx(s.LoaderCircle,{className:"mr-2 h-4 w-4 animate-spin"}):e.jsx(s.Play,{className:"mr-2 h-4 w-4"}),"Run"]}),e.jsx(wt,{errorSql:T,sql:y==null?void 0:y.sql,error:O,onDebugWithAssistant:M}),e.jsx(rs,{}),e.jsx(s.Toggle,{pressed:a,onPressedChange:Y=>n(Y),className:"h-8",size:"sm",variant:"outline",children:e.jsx(Pn,{className:"size-4 text-foreground/70"})}),e.jsx("button",{disabled:c,onClick:()=>{k(!0)},className:"h-9 w-full cursor-text px-3 text-left text-sm text-muted-foreground",children:c?"":"Type your question..."})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Ds,{}),e.jsx(ws,{})]})]})}return e.jsxs("section",{role:"editor-section",className:"flex grow flex-col justify-end",children:[e.jsxs("div",{className:"relative flex grow justify-between overflow-y-scroll",children:[P(),R()]}),K()]})}const $n=[{value:"table",label:"Table",icon:s.Table2},{value:"aggregateTable",label:"Aggregate",icon:s.Layers},{value:"pivotTable",label:"Pivot",icon:ns}];function qn({className:t}){const a=s.useEditorStore(d=>d.card),{setCardType:n,setCard:r,updateCardInFrame:l}=s.useEditorActions(),o=["table","aggregateTable","pivotTable"].includes(a.type),c=s.hasValidCardConfig(a.config);if(!o||!c)return null;const i=d=>{var m;const u=d;if(u==="aggregateTable"&&((m=a.config)!=null&&m.pivotByColumns)&&a.config.pivotByColumns.length>0){const h={...a,type:u,config:{...a.config,pivotByColumns:[]}};r(h),l(h)}else{n(u);const h={...a,type:u};l(h)}};return e.jsx("div",{className:s.cn("flex items-center",t),children:e.jsx(s.RadioGroup,{value:a.type,onValueChange:i,className:"flex flex-row items-center justify-between gap-1 rounded-lg border p-1",children:$n.map(d=>{const u=d.icon;return e.jsxs("div",{className:"flex items-center",children:[e.jsx(s.RadioGroupItem,{value:d.value,id:`table-type-${d.value}`,className:"peer sr-only"}),e.jsxs(s.Label,{htmlFor:`table-type-${d.value}`,className:s.cn("flex cursor-pointer items-center gap-1.5 rounded-md px-3 py-1 text-sm font-medium transition-all","hover:bg-muted","peer-data-[state=checked]:bg-background peer-data-[state=checked]:shadow-sm"),children:[e.jsx(u,{className:"h-3.5 w-3.5"}),d.label]})]},d.value)})})})}function Gn({card:t}){var v,k,L,C,S,y,D,N,B,w,F;const[a,n]=I.useState(!1),[r,l]=I.useState([]),{authToken:o}=s.useSemaphorContext(),c=s.getTokenParams(o==null?void 0:o.accessToken),i=s.useDashboardStore(T=>T.themeStyle),d={colors:((k=(v=i==null?void 0:i.chart)==null?void 0:v.dataset)==null?void 0:k.backgroundColor)||[]};(L=t.customCardPreferences)!=null&&L.inputData;const{getCard:u}=s.useCustomVisual(((C=t.customCardPreferences)==null?void 0:C.url)||""),m=((S=t.customCardPreferences)==null?void 0:S.visualType)||"single",h=s.useEditorStore(T=>T.frame),{setCustomCardPreferences:f}=s.useEditorActions(),{data:g}=s.useDashboardCardQuery(t),b=I.useCallback((T,E)=>{l(A=>({...A,[T]:E}))},[]);if(!((y=t.customCardPreferences)!=null&&y.componentName))return null;const p=u((D=t.customCardPreferences)==null?void 0:D.componentName);function j(T){n(T)}const x=Object.keys(((N=t.customCardPreferences)==null?void 0:N.dataInputCardIds)||{}).map(T=>{var O,M,R;const E=(M=(O=t.customCardPreferences)==null?void 0:O.dataInputCardIds)==null?void 0:M[T].cardId,A=(R=h==null?void 0:h.cards)==null?void 0:R.find(P=>P.id===E);return A||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(I.Suspense,{fallback:e.jsx(e.Fragment,{}),children:[p&&m==="single"&&e.jsx(p,{editing:!0,params:c,theme:d,settings:(B=t.customCardPreferences)==null?void 0:B.settings,onDataChange:b,data:(g==null?void 0:g.records)||[]}),p&&m==="multiple"&&e.jsxs(e.Fragment,{children:[Object.keys(((w=t.customCardPreferences)==null?void 0:w.dataInputCardIds)||{}).map(T=>{var O,M,R;const E=(M=(O=t.customCardPreferences)==null?void 0:O.dataInputCardIds)==null?void 0:M[T].cardId,A=(R=h==null?void 0:h.cards)==null?void 0:R.find(P=>P.id===E);if(A)return e.jsx(s.MultiInputEmptyRenderer,{onLoadingStatus:j,onDataChange:b,dataInputIndex:T,card:A},A.id+T)}),e.jsx("div",{className:"flex flex-col gap-2",children:e.jsx(p,{theme:d,onDataChange:b,settings:x.map(T=>{var E;return(E=T==null?void 0:T.customCardPreferences)==null?void 0:E.settings}),data:x.map(T=>T!=null&&T.id?r==null?void 0:r[T.id]:[])})})]})]},(F=t.customCardPreferences)==null?void 0:F.componentName)})}function kt({className:t,...a}){var D;const n=s.useEditorStore(N=>N.card),r=s.isExplorerCard(n),l=((D=n.customCardPreferences)==null?void 0:D.showCardHeader)??!0,o=s.useEditorStore(N=>N.frame),c=s.useDashboardStore(N=>N.dashboard.filters),i=s.useEditorStore(N=>N.actions.setRunSql),{updateFilter:d}=s.useDashboardActions(),u=c==null?void 0:c.find(N=>N.id===o.filterId),{data:m,isLoading:h,isFetching:f,errorMessage:g,pagination:b}=s.useDashboardCardQuery(n),{setCard:p,updateCardInFrame:j}=s.useEditorActions(),{data:x}=s.useTopoJson(n),v=I.useMemo(()=>{var N;return n.type!=="pivotTable"||!((N=m==null?void 0:m.records)!=null&&N.length)?null:{records:m.records,columnSubtotalMeta:m.columnSubtotalMeta,subtotalColumns:m.subtotalColumns||[],pivotSchema:m.pivotSchema||[],groupByColumns:m.groupByColumns}},[n.type,m==null?void 0:m.records,m==null?void 0:m.columnSubtotalMeta,m==null?void 0:m.subtotalColumns,m==null?void 0:m.pivotSchema,m==null?void 0:m.groupByColumns]),k=s.usePivotTableConfig(n,v),L=(N,B)=>{var F,T;const w={...n,paginationConfig:{page:N+1,pageSize:B}};p(w),j(w),n.sql&&((T=(F=n.preferences)==null?void 0:F.tablePrefs)!=null&&T.enableDevModePagination)&&i(!0)},C=I.useMemo(()=>!n.id||!(m!=null&&m.records)?null:s.createChartConfig({card:n,data:m==null?void 0:m.records,cardType:n.type,queryConfig:n.queryConfig,customCfg:n.customCfg,preferences:n.preferences,topoJson:x}),[n.id,m==null?void 0:m.records,n.type,n.queryConfig,n.customCfg,n.preferences,x]);function S(N){return e.jsx(s.ErrorBoundary,{FallbackComponent:s.FallbackVisual,children:e.jsx(Gn,{card:N})})}function y(){if(m!=null&&m.records&&(m==null?void 0:m.records.length)===0&&!h&&!f)return g?e.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-2",children:[e.jsx(s.SearchX,{className:"size-8 text-destructive"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:r?"Error fetching data. Please check your chart configuration":"Error fetching data. Please check your SQL or Python code."})]}):e.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-2",children:[e.jsx(s.TreePalm,{className:"size-8 text-muted-foreground"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"No results to display"})]});if((h||f)&&n.type!=="table")return e.jsx("div",{className:"z-50 flex h-full items-center justify-center",children:e.jsx(s.LoadingDots,{size:"md",color:"muted","aria-label":"Loading data"})});if(!n.id)return null;if(n.type==="custom")return S(n);if(!["table","pivotTable","aggregateTable","custom"].includes(n.type)&&C)return e.jsx("div",{className:"relative h-full min-h-0 w-full flex-1 grow basis-0",children:h||f?e.jsx(e.Fragment,{}):e.jsx(s.ChartJsVisual,{cfg:C})});if(n.type==="table")return e.jsx("div",{className:"relative mb-2 flex h-full min-h-0 w-full flex-1 grow basis-0",children:e.jsx(s.TableVisual,{card:n,data:(m==null?void 0:m.records)||[],paginationMetadata:b,onPaginationChange:L,isLoading:h||f})});if(n.type==="pivotTable"&&k)return e.jsx("div",{className:"relative mb-2 flex h-full min-h-0 w-full flex-1 grow basis-0",children:e.jsx(s.PivotTableTanstack,{card:n,data:k.data,options:k.options,onAggregationChange:N=>{const B=s.handleAggregationChange(N,n.config),w={...n,config:B};p(w),j(w)},onAggregationLabelChange:N=>{const B=s.handleAggregationLabelChange(N,n.config),w={...n,config:B};p(w),j(w)}})});if(n.type==="aggregateTable")return e.jsx("div",{className:"relative mb-2 flex h-full min-h-0 w-full flex-1 grow basis-0",children:e.jsx(s.AggregateTable,{card:n,data:(m==null?void 0:m.records)||[],groupByColumns:m==null?void 0:m.groupByColumns,pivotSchema:m==null?void 0:m.pivotSchema,paginationMetadata:b,onPaginationChange:L,onAggregationChange:N=>{const B=s.handleAggregationChange(N,n.config),w={...n,config:B};p(w),j(w)},isLoading:h||f})})}return e.jsxs(s.Card,{role:"editor-visual-card",className:s.cn("relative flex h-full flex-col rounded-none",t),...a,children:[l&&e.jsxs(s.CardHeader,{className:"flex flex-row items-start justify-between py-4",children:[e.jsxs("div",{className:"flex-1",children:[e.jsxs("div",{className:"flex items-center gap-5",children:[e.jsx(s.CardTitle,{className:"text-base",children:e.jsx(s.EditableText,{value:n.title,onSave:N=>p({...n,title:N}),isEditable:!0,placeholder:"Add title",displayClassName:"text-base font-semibold",inputClassName:"text-base font-semibold"})}),e.jsx(qn,{})]}),e.jsx("div",{className:"w-1/2",children:e.jsx(s.EditableText,{value:n.description||"",onSave:N=>p({...n,description:N}),isEditable:!0,placeholder:"Add description",displayClassName:"text-sm text-muted-foreground",inputClassName:"text-sm"})})]}),u&&e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(s.Label,{className:"my-1",children:e.jsx(s.EditableText,{value:u.title||u.column,onSave:N=>d({...u,title:N}),isEditable:!0,placeholder:"Filter",displayClassName:"text-sm",inputClassName:"text-sm"})}),e.jsx(s.FilterComponent,{filter:u})]})]}),e.jsx(s.CardContent,{className:"flex grow flex-col",children:y()})]})}const hs=({language:t,value:a,onChange:n,readonly:r})=>e.jsx(s.Ft,{className:"h-full w-full overflow-hidden text-xs",theme:"default",options:{minimap:{enabled:!1},wordWrap:"on",scrollbar:{verticalScrollbarSize:0,horizontalScrollbarSize:0},fontSize:12,lineHeight:16,renderLineHighlight:"none",readOnly:r},defaultLanguage:t,value:a,onChange:n}),Hn=()=>e.jsxs(s.DialogHeader,{children:[e.jsx("div",{className:"flex items-center gap-2",children:e.jsx(s.DialogTitle,{children:"Customize Card"})}),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."})]})]}),Wn=({customCode:t,cardCustomCfgString:a,mergedConfig:n,onConfigChange:r,onCodeChange:l})=>e.jsxs(s.Tabs,{defaultValue:"final-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.jsx(s.TabsTrigger,{value:"final-config",children:"Config"}),e.jsx(s.TabsTrigger,{value:"custom-config",children:"Changes"}),e.jsx(s.TabsTrigger,{value:"custom-code",children:"Custom Code"})]}),e.jsx(s.TabsContent,{value:"final-config",className:"mt-0 grow rounded-b border border-t-0",children:e.jsx(hs,{language:"json",value:n,onChange:r})}),e.jsx(s.TabsContent,{value:"custom-config",className:"mt-0 grow rounded-b border border-t-0",children:e.jsx(hs,{readonly:!0,language:"json",value:a,onChange:()=>{}})}),e.jsx(s.TabsContent,{value:"custom-code",className:"mt-0 grow rounded-b border border-t-0",children:e.jsx(hs,{language:"javascript",value:t,onChange:l})})]}),Kn=({error:t,hasCardCustomConfig:a,onReset:n,onApply:r,onClose:l})=>e.jsxs(s.DialogFooter,{className:"flex items-center",children:[e.jsx(s.Label,{className:"mr-2 text-red-500",children:t}),e.jsx(s.Button,{disabled:!a,onClick:n,variant:"outline",children:"Reset"}),e.jsx(s.Button,{onClick:r,variant:"outline",children:"Apply"}),e.jsx(s.Button,{onClick:l,variant:"outline",children:"Close"})]});function Jn(){const[t,a]=I.useState(!1),[n,r]=I.useState(""),[l,o]=I.useState(""),[c,i]=I.useState(""),[d,u]=I.useState(""),m=s.useEditorStore(C=>C.card),h=s.useEditorStore(C=>C.card.customCfg),f=h?JSON.stringify(h,null,2):"",{data:g}=s.useDashboardCardQuery(m),{data:b}=s.useTopoJson(m),{setCardCustomCfg:p,setCustomVisualCode:j}=s.useEditorActions(),x=C=>{var S,y;return JSON.stringify({...C,data:{...C.data,datasets:(y=(S=C.data)==null?void 0:S.datasets)==null?void 0:y.map(D=>({...D,data:[]}))}},null,2)},v=()=>{var S,y;if(!((S=g==null?void 0:g.records)!=null&&S.length))return;const C=s.createChartConfig({card:m,data:g.records,cardType:m.type,queryConfig:m.queryConfig,preferences:m.preferences,topoJson:b});if(C){r(x(C)),i(((y=m.preferences)==null?void 0:y.customVisualCode)||"");const D=s.merge(C,h);o(x(D))}},k=()=>{try{if(c&&j(c),l){const C=JSON.parse(l),S=s.getObjectDiff(JSON.parse(n),C);p(S),u("")}}catch{u("Invalid JSON configuration")}},L=Object.keys(h||{}).length===0;return e.jsxs(s.Dialog,{open:t,onOpenChange:a,children:[e.jsx(s.DialogTrigger,{asChild:!0,children:e.jsx(s.IconButton,{tooltip:"Customize Visual",onClick:v,className:L?"":"text-green-600 hover:text-green-700",children:e.jsx(s.Settings,{className:"h-4 w-4"})})}),e.jsxs(s.DialogContent,{className:"flex h-[600px] grow flex-col overflow-auto sm:min-w-[900px] lg:min-w-[1200px]",children:[e.jsx(Hn,{}),e.jsxs("div",{className:"flex grow gap-2",children:[e.jsx(s.ErrorBoundary,{FallbackComponent:s.FallbackVisual,children:e.jsx(kt,{className:"w-1/2 rounded shadow-none"})}),e.jsx(Wn,{customCode:c,cardCustomCfgString:f,mergedConfig:l,onConfigChange:C=>o(C??""),onCodeChange:C=>i(C??"")})]}),e.jsx(Kn,{error:d,hasCardCustomConfig:!!h,onReset:()=>{o(n),p(null)},onApply:k,onClose:()=>a(!1)})]})]})}function ls(t){const[a,n]=I.useState(null);return a}function Tt(){const{authToken:t}=s.useSemaphorContext(),{data:a,isLoading:n,isFetching:r,isError:l}=s.useQuery({queryKey:["plugins",t==null?void 0:t.accessToken],queryFn:()=>s.getPlugins(t==null?void 0:t.accessToken)});return{data:a,isLoading:n,isFetching:r,isError:l}}function Et(){const{data:t,isLoading:a,isError:n}=Tt(),r=s.useQueries({queries:((t==null?void 0:t.plugins)||[]).map(i=>({queryKey:["manifest",i.value],queryFn:()=>s.loadManifest(i.value),enabled:!!i.value,staleTime:5*60*1e3,gcTime:10*60*1e3,retry:2,retryDelay:d=>Math.min(1e3*2**d,3e4)}))}),l=[];let o=a,c=n;return r.forEach((i,d)=>{var u;if(i.isLoading&&(o=!0),i.isError&&(c=!0),i.data&&((u=t==null?void 0:t.plugins)!=null&&u[d])){const m=t.plugins[d],h=i.data.visuals.map(f=>({name:f.name,pluginName:m.label,componentType:f.componentType,pluginType:m.type,icon:f.icon,chartType:f.chartType,url:m.value}));l.push(...h)}}),{data:l,isLoading:o,isError:c}}function Qn({onChartTypeChange:t}){const{setCardCustomCfg:a,setCardPreferences:n,setCardType:r,setCustomCardPreferences:l}=s.useEditorActions(),{data:o,isLoading:c,isError:i}=Et(),d=I.useCallback((u,m)=>{a(null),n({}),r(u),m&&l({type:"component",visualType:"single",url:m.url,componentName:m.name,icon:m.icon}),t==null||t()},[a,n,r,l,t]);return c?e.jsxs(e.Fragment,{children:[e.jsx(s.Separator,{className:"my-2"}),e.jsx("div",{className:"grid grid-cols-4 place-items-center",children:e.jsx("div",{className:"text-sm text-muted-foreground",children:"Loading custom visuals..."})})]}):i?e.jsxs(e.Fragment,{children:[e.jsx(s.Separator,{className:"my-2"}),e.jsx("div",{className:"grid grid-cols-4 place-items-center",children:e.jsx("div",{className:"text-sm text-destructive",children:"Failed to load custom visuals"})})]}):!o||o.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:o.map((u,m)=>e.jsx(Xn,{text:u.name,onClick:()=>d("custom",u),icon:u.icon},`${u.url}-${u.name}-${m}`))})]})}const Xn=({text:t,icon:a,onClick:n})=>{const r=ls(),l=t.charAt(0).toUpperCase();return e.jsx(s.IconButton,{onClick:n,tooltip:t,children:r?e.jsx(r,{className:"h-4 w-4"}):l})};function It({onChartTypeChange:t,iconClassName:a}){const{setCardType:n,setCardPreferences:r,setIsDevMode:l}=s.useEditorStore(m=>m.actions),{setCardCustomCfg:o,setCustomCardPreferences:c,setQueryConfig:i}=s.useEditorActions();function d(m,h){o(null),r({}),n(m),["custom","text","map"].includes(m)&&(l(!0),i(void 0)),t==null||t()}const u=1e3;return e.jsxs("div",{className:"grid grid-cols-5 place-items-center",children:[e.jsx(s.IconButton,{openDelay:u,tooltip:"Table",onClick:()=>d("table"),className:"h-10 p-4",children:e.jsx(s.Table2,{className:s.cn("size-5",a)})}),e.jsx(s.IconButton,{openDelay:u,tooltip:"Bar Chart",onClick:()=>d("bar"),className:"h-10 p-4",children:e.jsx(s.ChartColumnIncreasing,{className:s.cn("size-5",a)})}),e.jsx(s.IconButton,{openDelay:u,tooltip:"Line Chart",onClick:()=>d("line"),className:"h-10 p-4",children:e.jsx(s.ChartLine,{className:s.cn("size-5",a)})}),e.jsx(s.IconButton,{openDelay:u,tooltip:"Stacked Bar Chart",onClick:()=>d("stackedBar"),className:"h-10 p-4",children:e.jsx(s.ChartColumnStacked,{className:s.cn("size-5",a)})}),e.jsx(s.IconButton,{openDelay:u,tooltip:"Stacked Line Chart",onClick:()=>d("stackedLine"),className:"h-10 p-4",children:e.jsx(s.MdStackedLineChart,{className:s.cn("size-5",a),strokeWidth:0})}),e.jsx(s.IconButton,{openDelay:u,tooltip:"Scatter Chart",onClick:()=>d("scatter"),className:"h-10 p-4",children:e.jsx(s.ChartScatter,{className:s.cn("size-5",a)})}),e.jsx(s.IconButton,{openDelay:u,tooltip:"Bubble Chart",onClick:()=>d("bubble"),className:"h-10 p-4",children:e.jsx(s.TbChartBubble,{className:s.cn("size-5",a)})}),e.jsx(s.IconButton,{openDelay:u,tooltip:"Pie Chart",onClick:()=>d("pie"),className:"h-10 p-4",children:e.jsx(s.ChartPie,{className:s.cn("size-5",a)})}),e.jsx(s.IconButton,{openDelay:u,tooltip:"Doughnut Chart",onClick:()=>d("doughnut"),className:"h-10 p-4",children:e.jsx(s.Donut,{className:s.cn("size-5",a)})}),e.jsx(s.IconButton,{openDelay:u,tooltip:"Funnel Chart",onClick:()=>d("funnel"),className:"h-10 p-4",children:e.jsx(s.TbChartFunnel,{className:s.cn("size-5",a)})}),e.jsx(s.IconButton,{openDelay:u,tooltip:"Radar Chart",onClick:()=>d("radar"),className:"h-10 p-4",children:e.jsx(s.Radar,{className:s.cn("size-5",a)})}),e.jsx(s.IconButton,{openDelay:u,tooltip:"Polar Area Chart",onClick:()=>d("polarArea"),className:"h-10 p-4",children:e.jsx(s.PiChartPolar,{className:s.cn("size-5",a)})}),e.jsx(s.IconButton,{openDelay:u,tooltip:"Tornado Chart",onClick:()=>d("tornado"),className:"h-10 p-4",children:e.jsx(s.Tornado,{className:s.cn("size-5",a)})}),e.jsx(s.IconButton,{tooltip:"Range Chart",onClick:()=>d("range"),className:"h-10 p-4",children:e.jsx(s.ChartNoAxesGantt,{className:s.cn("size-5",a)})}),e.jsx(s.IconButton,{openDelay:u,tooltip:"KPI",onClick:()=>d("kpi"),className:"h-10 p-4",children:e.jsx(s.TiSortNumerically,{className:s.cn("size-5",a)})}),e.jsx(s.IconButton,{openDelay:u,tooltip:"Text",onClick:()=>d("text"),className:"h-10 p-4",children:e.jsx(s.BookType,{className:s.cn("size-5",a)})}),e.jsx(s.IconButton,{tooltip:"Map",onClick:()=>d("map"),className:"h-10 p-4",children:e.jsx(s.Map,{className:s.cn("size-5",a)})}),e.jsx(s.IconButton,{openDelay:u,tooltip:"Custom",onClick:()=>d("custom"),className:"h-10 p-4",children:e.jsx(Ue,{className:s.cn("size-5",a)})})]})}function Zn({chartType:t,className:a,customIcon:n,componentName:r}){const l=ls();switch(t){case"bar":return e.jsx(s.ChartColumnIncreasing,{className:a});case"line":return e.jsx(s.ChartLine,{className:a});case"pie":return e.jsx(s.ChartPie,{className:a});case"radar":return e.jsx(s.Radar,{className:a});case"scatter":return e.jsx(s.ChartScatter,{className:a});case"bubble":return e.jsx(s.TbChartBubble,{className:a});case"doughnut":return e.jsx(s.Donut,{className:a});case"stackedBar":return e.jsx(s.ChartColumnStacked,{className:a});case"stackedLine":return e.jsx(s.MdStackedLineChart,{className:a});case"polarArea":return e.jsx(s.PiChartPolar,{className:a});case"funnel":return e.jsx(s.TbChartFunnel,{className:a});case"tornado":case"pyramid":return e.jsx(s.Tornado,{className:a});case"range":return e.jsx(s.ChartNoAxesGantt,{className:a});case"kpi":return e.jsx(s.TiSortNumerically,{className:a});case"text":return e.jsx(ge,{className:a});case"map":return e.jsx(s.Map,{className:a});case"custom":return n&&l?e.jsx(l,{className:a}):r?r==null?void 0:r.charAt(0).toUpperCase():e.jsx(Ue,{className:a});default:return e.jsx(s.Table2,{className:a})}}function At({variant:t="ghost"}){var o,c;const[a,n]=I.useState(!1),r=s.useEditorStore(i=>i.card),l=r.type;return s.useDashboardStore(i=>i.isVisualEditing),e.jsxs(s.Popover,{open:a,onOpenChange:n,children:[e.jsx(s.PopoverTrigger,{asChild:!0,children:e.jsx(s.Button,{size:"sm",variant:t||"ghost",children:e.jsx(Zn,{className:"size-4",chartType:l,customIcon:(o=r.customCardPreferences)==null?void 0:o.icon,componentName:(c=r.customCardPreferences)==null?void 0:c.componentName})})}),e.jsxs(s.PopoverContentCustom,{onOpenAutoFocus:i=>i.preventDefault(),className:"w-72 p-1",children:[e.jsx(It,{onChartTypeChange:()=>n(!1)}),e.jsx(Qn,{onChartTypeChange:()=>n(!1)})]})]})}function er({error:t,className:a="",textClassName:n="",copyButtonClassName:r=""}){const[l,o]=I.useState(!1),c=I.useRef(null),i=I.useRef(!1);function d(){t&&!i.current&&navigator.clipboard.writeText(t)}function u(f){(f.key==="Enter"||f.key===" ")&&(f.preventDefault(),d())}function m(){const f=window.getSelection();if(f&&f.toString().trim()!==""){const g=f.toString();navigator.clipboard.writeText(g),o(!0),i.current=!0,setTimeout(()=>{o(!1),i.current=!1},1e3)}else i.current=!1}function h(){o(!1),i.current=!1}return e.jsxs("div",{className:`relative rounded-md border border-red-200 bg-red-50 p-3 dark:border-red-800 dark:bg-red-950/20 ${a}`,children:[e.jsx("div",{className:"float-right mb-2 ml-2",children:e.jsx(s.CopyButton,{text:t,className:`h-6 w-6 p-0 text-red-600 hover:text-red-700 dark:text-red-400 dark:hover:text-red-300 ${r}`})}),e.jsx("div",{ref:c,className:`cursor-pointer select-text break-all font-mono text-xs text-red-700 dark:text-red-300 ${n}`,onClick:d,onKeyDown:u,onMouseUp:m,onMouseDown:h,tabIndex:0,role:"button","aria-label":"Click to copy error message or select text to copy",children:t}),l&&e.jsx("div",{className:"absolute bottom-1 right-1 rounded bg-green-100 px-2 py-1 text-xs text-green-600 dark:bg-green-900/30 dark:text-green-400",children:"Copied!"}),e.jsx("div",{className:"clear-both"})]})}function sr(){const t=s.useEditorStore(o=>{var c,i;return(i=(c=o.card.preferences)==null?void 0:c.chartOptions)==null?void 0:i.indexAxis}),a=s.useEditorStore(o=>o.card.type),{setChartOrientation:n}=s.useEditorStore(o=>o.actions);function r(){return e.jsx(s.IconButton,{onClick:()=>{n(t==="x"||t===void 0?"y":"x")},tooltip:"Chart Orientation",children:t==="x"||t===void 0?e.jsx(zs,{className:"size-4"}):e.jsx(Ps,{className:"size-4"})})}function l(){return e.jsx(s.IconButton,{onClick:()=>{n(t==="y"||t===void 0?"x":"y")},tooltip:"Chart Orientation",children:t==="y"||t===void 0?e.jsx(zs,{className:"size-4"}):e.jsx(Ps,{className:"size-4"})})}return e.jsx(e.Fragment,{children:a==="funnel"?l():r()})}function Mt(){const t=s.useEditorStore(c=>c.card),a=s.useEditorStore(c=>c.isShowingVisual),n=s.useEditorStore(c=>{var i,d;return(d=(i=c.card)==null?void 0:i.preferences)==null?void 0:d.chartOptions}),r=s.getChartGridStyle(n),{setChartGrid:l}=s.useEditorActions();function o(){const c=["xy","none","x","y"],d=(c.indexOf(r)+1)%c.length;l(c[d])}return a?e.jsxs("div",{"data-info":"visual-settings",className:"flex items-center",children:[["line","bar","range","stackedBar","stackedLine","horizontalBar","funnel"].includes(t.type)&&e.jsx(e.Fragment,{children:e.jsx(sr,{})}),!["kpi","text","custom","table"].includes(t.type)&&e.jsx(e.Fragment,{}),!["pie","doughnut","funnel","radar","polarArea","table","custom","kpi","text","map"].includes(t.type)&&e.jsxs(s.IconButton,{tooltip:"Grid Style",onClick:o,children:[(r==="xy"||!r)&&e.jsx(ns,{className:"size-4"}),r==="x"&&e.jsx(ma,{className:"size-4"}),r==="y"&&e.jsx(za,{className:"size-4"}),r==="none"&&e.jsx($a,{className:"size-4"})]})]}):null}function tr(){const t=s.useEditorStore(b=>b.frame),a=s.useEditorStore(b=>b.card),{setFrame:n,setActiveTabCardId:r,setCard:l,updateCardInFrame:o}=s.useEditorActions(),c=(b,p)=>{b.dataTransfer.setData("tabIndex",p.toString())},i=b=>{b.preventDefault()},d=(b,p)=>{const j=b.dataTransfer.getData("tabIndex");if(j===p.toString())return;const x=Array.from(t.cards),[v]=x.splice(parseInt(j),1);x.splice(p,0,v),n({...t,cards:x})};function u(b){const p=t.cards.filter(v=>v.id!==b),j=p[0],x={...t,cards:p,activeCardId:j.id};n(x),r(j.id),l(j)}function m(b,p){const j={...t,cards:[...t.cards,p],activeCardId:b.id};n(j),r(p.id)}function h(){const b={...a,id:s.v4(),title:`${a.title} Copy`,tabTitle:`${a.tabTitle||a.title} Copy`};m(a,b)}function f(b){const p={dataSource:b.dataSource,connectionId:b.connectionId,lastSelectedDatabase:b.lastSelectedDatabase,lastSelectedSchema:b.lastSelectedSchema,lastSelectedTable:b.lastSelectedTable,lastSelectedDatamodelId:b.lastSelectedDatamodelId,id:s.v4(),title:"Title",description:"",preferences:{onClickFilter:[{columnIndex:0,expression:""}]},type:"bar",sql:"",data:[],mode:"explorer"};m(b,p)}function g(b,p){return b.cards.length===1&&(p.displayTab===!0||p.displayTab===void 0)||b.activeCardId!==p.id&&(p.displayTab===!0||p.displayTab===void 0)?null:e.jsx("div",{onClick:()=>{const j=p.displayTab===void 0?!1:!p.displayTab;l({...p,displayTab:j}),o({...p,displayTab:j})},children:p.displayTab===!0||p.displayTab===void 0?e.jsx(s.Eye,{className:"mr-2 size-3.5 text-muted-foreground hover:text-foreground"}):e.jsx(fa,{className:"mr-2 size-3.5 text-muted-foreground hover:text-foreground"})})}return e.jsx(s.TabsList,{className:"group mx-4 justify-between overflow-x-auto",children:e.jsxs("div",{className:"flex items-center",children:[t.cards.map((b,p)=>e.jsxs(s.TabsTrigger,{draggable:!0,onDragStart:j=>c(j,p),onDragOver:i,onDrop:j=>d(j,p),className:"",value:b.id,children:[g(t,b),e.jsx(s.Editable,{enabled:t.activeCardId===b.id,text:b.tabTitle||b.title,onSave:j=>{l({...a,tabTitle:j}),o({...a,tabTitle:j})},children:b.tabTitle||b.title},b.id),t.activeCardId===b.id&&t.cards.length>1&&e.jsx(s.X,{className:"ml-2 size-3.5 text-muted-foreground hover:text-foreground",onClick:()=>u(b.id)})]},b.id)),e.jsx(s.Button,{className:"ml-1 h-8 px-2 hover:bg-muted-foreground/50",variant:"outline",onClick:()=>f(a),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:h,children:e.jsx(xa,{className:"h-4 w-4"})})]})})}function Lt(){const t=s.useEditorStore(p=>p.frame),a=s.useEditorStore(p=>p.card),n=s.useEditorStore(p=>p.isSqlRunning),r=s.useEditorStore(p=>p.isDevMode),{setFrame:l,setActiveTabCardId:o,setCard:c,setIsDevMode:i,setRunSql:d}=s.useEditorActions(),{data:u,isLoading:m,isFetching:h}=s.useDashboardCardQuery(a);function f(p){const j=t.cards.find(x=>x.id===p);if(j!=null&&j.sql){r||i(!0),o(p);return}if(j!=null&&j.queryConfig){r&&i(!1),g(p),o(p);return}r||g(p),o(p)}function g(p){const j={...t,cards:t.cards.map(v=>v.id===a.id?a:v),activeCardId:p};l(j);const x=j.cards.find(v=>v.id===p);x.sql&&d(!0),c(x)}function b(){return a.type==="kpi"?m||h?e.jsx("div",{className:"z-50 flex h-full items-center justify-center",children:e.jsx(s.LoadingDots,{size:"md",color:"muted","aria-label":"Loading data"})}):e.jsx("div",{className:"flex h-full items-center justify-center",children:e.jsx("div",{className:"w-1/2 rounded-md border border-border",children:e.jsx(s.KPICard,{card:a,data:u==null?void 0:u.records,isPending:m||h})})}):a.type==="text"?m||h?e.jsx("div",{className:"z-50 flex h-full items-center justify-center",children:e.jsx(s.LoadingDots,{size:"md",color:"muted","aria-label":"Loading data"})}):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:n,card:a,data:u==null?void 0:u.records})})})}):e.jsx(s.ErrorBoundary,{FallbackComponent:s.FallbackVisual,children:e.jsx(kt,{className:"grow border-none shadow-none"})})}return e.jsxs(s.Tabs,{onValueChange:f,value:t.activeCardId,className:"flex grow flex-col",children:[t.cards.map(p=>e.jsx(s.TabsContent,{className:"mt-0 grow",value:p.id,children:b()},p.id)),e.jsx(tr,{})]})}function Je({children:t}){var L,C;s.useEditorStore(S=>S.frame);const a=s.useEditorStore(S=>S.card),n=s.useEditorStore(S=>S.isDevMode),r=s.useEditorStore(S=>S.isShowingVisual),l=s.useDashboardStore(S=>S.isVisualEditing),o=s.useEditorStore(S=>S.pythonStdOut);s.useEditorStore(S=>S.actions.setRunSql);const{setFrame:c,setCard:i,setActiveTabCardId:d,runAssistant:u,setIsDevMode:m,setCardPreferences:h}=s.useEditorActions(),{data:f,isLoading:g,isFetching:b,errorMessage:p,refetch:j}=s.useDashboardCardQuery(a);function x(){const S=JSON.stringify(f==null?void 0:f.records,null,2),y=new Blob([S],{type:"application/json"}),D=URL.createObjectURL(y),N=document.createElement("a");N.href=D,N.download=`${a.title}.json`,N.click()}function v(){const y=[Object.keys(f==null?void 0:f.records.reduce((w,F)=>({...w,...F}),{})).join(","),...((f==null?void 0:f.records)||[]).map(w=>Object.values(w).join(","))].join(`
|
|
348
348
|
`),D=new Blob([y],{type:"text/csv"}),N=URL.createObjectURL(D),B=document.createElement("a");B.href=N,B.download=`${a.title}.csv`,B.click()}function k(){const S=`Can you get the documentation for ${a.type} chart?`;u(S)}return a?e.jsxs("div",{className:"relative isolate flex h-full flex-col py-2 pb-3",children:[e.jsxs("div",{className:"z-10 mb-0 flex min-h-10 items-center justify-end gap-2 px-6",children:[r&&e.jsxs("div",{className:"flex grow items-center",children:[e.jsx(At,{}),l&&e.jsx(s.IconButton,{tooltip:"Visual Docs",onClick:k,children:e.jsx(ia,{className:"size-4"})}),!["table","custom"].includes(a.type)&&l&&e.jsx(Jn,{})]}),!r&&e.jsxs("div",{className:"flex grow items-center gap-1",children:[e.jsx(s.Button,{className:"h-7 w-fit px-1 font-mono text-xs text-muted-foreground/70",variant:"ghost",size:"icon",onClick:v,children:e.jsx(s.PiFileCsv,{className:"size-4"})}),e.jsx(s.Button,{className:"h-7 w-fit px-1 font-mono text-xs text-muted-foreground/70",variant:"ghost",size:"icon",onClick:x,children:e.jsx(ja,{strokeWidth:1.5,className:"size-4"})}),e.jsx(s.CopyButton,{text:JSON.stringify(f==null?void 0:f.records,null,2),className:"h-7 w-fit px-1 font-mono text-xs text-muted-foreground/70"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[t,e.jsx(Mt,{})]}),a.type==="table"&&a.sql&&!s.hasValidCardConfig(a.config)&&e.jsxs("div",{className:"mr-2 flex items-center gap-3",children:[e.jsx(s.Checkbox,{id:"pagination",checked:((C=(L=a.preferences)==null?void 0:L.tablePrefs)==null?void 0:C.enableDevModePagination)??!1,onCheckedChange:S=>{var y;h({...a.preferences,tablePrefs:{...(y=a.preferences)==null?void 0:y.tablePrefs,enableDevModePagination:S}}),j()}}),e.jsx(s.Label,{htmlFor:"pagination",children:"Paginate Results"})]}),n&&e.jsx(nr,{})]}),r?e.jsx(Lt,{}):e.jsxs(s.ResizablePanelGroup,{className:"px-6",direction:"horizontal",children:[o&&e.jsxs(e.Fragment,{children:[e.jsx(s.ResizablePanel,{id:"1",order:1,defaultSize:30,minSize:10,className:"relative flex h-full min-h-0 w-full flex-1 basis-0",children:o&&e.jsx(ar,{})}),e.jsx(s.ResizableHandle,{})]}),e.jsxs(s.ResizablePanel,{id:"2",order:2,minSize:10,className:s.cn("relative flex h-full min-h-0 w-full flex-1 basis-0",{"px-6":o}),children:[(f==null?void 0:f.records)&&(f==null?void 0:f.records.length)>0&&e.jsx(s.TableVisual,{card:a,data:(f==null?void 0:f.records)||[]}),p&&e.jsx(er,{error:p})]})]})]}):e.jsx(e.Fragment,{children:"No Active Card"})}function ar(){const t=s.useEditorStore(n=>n.pythonStdOut);if(!t)return null;const a=t.replace(/\n/g,"<br>");return e.jsxs("div",{className:"relative flex w-full flex-col",children:[e.jsx("div",{className:"sticky top-0 flex max-h-11 min-h-11 grow items-center font-mono text-xs font-semibold text-foreground/70",children:"Python Output"}),e.jsxs(s.ScrollArea,{className:"overflow-y-auto pt-1 font-mono text-xs text-foreground/90",children:[e.jsx("div",{dangerouslySetInnerHTML:{__html:a}}),e.jsx(s.ScrollBar,{orientation:"horizontal"})]})]})}function nr(){const t=s.useEditorStore(n=>n.isShowingVisual),a=s.useEditorStore(n=>n.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.SmallSwitch,{checked:t,onCheckedChange:()=>a(!t),id:"visualize",className:"data-[state=checked]:bg-foreground/50"})]})}function rr(){var p,j;const t=s.useEditorStore(x=>x.card.customCardPreferences),{data:a}=Tt(),n=(a==null?void 0:a.plugins)||[],r=s.useEditorStore(x=>x.card),l=s.useEditorStore(x=>x.frame),o=(t==null?void 0:t.visualType)||"single",{setCustomCardPreferences:c}=s.useEditorActions(),{components:i,manifest:d}=s.useCustomVisual((t==null?void 0:t.url)||""),u=(p=d==null?void 0:d.visuals)==null?void 0:p.find(x=>x.name===(t==null?void 0:t.componentName));function m(x,v){if(!t)return;const L={...(t==null?void 0:t.dataInputCardIds)||{},[x]:{cardId:v,hookRef:null}};c({...t,dataInputCardIds:L})}function h(x){var k,L;const v=(k=l==null?void 0:l.cards)==null?void 0:k.filter(C=>{var S;return((S=C==null?void 0:C.customCardPreferences)==null?void 0:S.visualType)!=="multiple"}).map(C=>({value:C.id,label:C.tabTitle||C.title}));return e.jsx("div",{className:"space-y-2",children:(L=x==null?void 0:x.dataInputs)==null?void 0:L.map((C,S)=>{var y,D;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(fe,{className:"col-span-6 h-8 w-full justify-between",label:"",options:v||[],value:((D=(y=t==null?void 0:t.dataInputCardIds)==null?void 0:y[S])==null?void 0:D.cardId)||"",onValueChange:N=>m(S,N)})]},S+Math.random())})})}function f(x,v,k=[],L=""){var C,S;return t?x==="input"?e.jsx(s.Input,{className:`h-8 w-full ${s.removeRing}`,value:((C=t==null?void 0:t.settings)==null?void 0:C[v])||L,onChange:y=>{c({...t,settings:{...t==null?void 0:t.settings,[v]:y.target.value}})}},v):x==="select"?e.jsx(fe,{className:"h-8 w-full",label:"",options:k,value:((S=t==null?void 0:t.settings)==null?void 0:S[v])||L,onValueChange:y=>{c({...t,settings:{...t==null?void 0:t.settings,[v]:y}})}}):null:null}function g(x){const v=Object.entries((x==null?void 0:x.settings)||{});return e.jsx("div",{className:"space-y-3",children:v.map(([k,L])=>e.jsxs("div",{className:"space-y-1",children:[e.jsx(s.Label,{children:L.title}),f(L.ui,k,L.options,L.defaultValue)]},k))})}function b(x){t&&c({...t,visualType:x,componentName:""})}return e.jsxs(s.Accordion,{type:"multiple",defaultValue:["component-settings"],className:"px-6 py-2",children:[e.jsxs(s.AccordionItem,{value:"plugin-settings",children:[e.jsx(s.AccordionTrigger,{children:"Plugin"}),e.jsx(s.AccordionContent,{children:e.jsxs("div",{className:"space-y-4 text-sm",children:[e.jsx("div",{className:"space-y-2",children:e.jsxs("div",{className:"space-y-4",children:[e.jsx(fe,{icon:e.jsx(oa,{className:"h-3.5 w-3.5"}),className:"h-9 w-full",label:"Select Plugin",options:n,value:(t==null?void 0:t.url)||"",onValueChange:x=>c({...t||{url:"",componentName:""},url:x})}),((t==null?void 0:t.type)==="component"||(t==null?void 0:t.type)===void 0)&&e.jsx(s.Tabs,{value:o,onValueChange:b,children:e.jsxs(s.TabsList,{className:"h-9 w-full",children:[e.jsx(s.TabsTrigger,{className:"h-7 w-full",value:"single",children:"Single Visual"}),e.jsx(s.TabsTrigger,{className:"h-7 w-full",value:"multiple",children:"Multi-Visual"})]})})]})}),((t==null?void 0:t.type)==="component"||(t==null?void 0:t.type)===void 0)&&t&&e.jsx(e.Fragment,{children:i&&e.jsx(fe,{icon:e.jsx(ha,{className:"h-3.5 w-3.5"}),className:"h-9 w-full",label:"Select Component",options:(i==null?void 0:i.filter(x=>x.type===o).map(x=>({value:x.name,label:x.name})))||[],value:t.componentName,onValueChange:x=>{console.log("changing value",x),c({...t,componentName:x})}})})]})})]}),((j=r==null?void 0:r.customCardPreferences)==null?void 0:j.componentName)&&e.jsxs(s.AccordionItem,{className:"border-none",value:"component-settings",children:[e.jsx(s.AccordionTrigger,{children:"Settings"}),e.jsxs(s.AccordionContent,{children:[u&&u.dataInputs&&e.jsxs("div",{className:"space-y-3",children:[e.jsx(s.Label,{children:"Input Mapping"}),e.jsx("div",{className:"px-2",children:h(u)})]}),u&&u.settings&&e.jsx("div",{className:"space-y-3",children:e.jsx("div",{className:"px-2",children:g(u)})})]})]})]})}function Le(){const[t,a]=I.useState([]),n=s.useEditorStore(u=>u.card.preferences),{setFilterOnClickColumnIndex:r,setCardPreferences:l}=s.useEditorStore(u=>u.actions),o=s.useEditorStore(u=>u.queryResultColumns);s.useEditorStore(u=>{var m;return(m=u.card.preferences)==null?void 0:m.filterOnClickColumnIndex}),I.useEffect(()=>{o&&a(new Array(o.length).fill(!1))},[o]);function c(u,m){var h,f;m?n!=null&&n.onClickFilter&&((h=n==null?void 0:n.onClickFilter)==null?void 0:h.length)>0?l({...n,onClickFilter:[...n.onClickFilter,{columnIndex:u,expression:""}]}):l({...n,onClickFilter:[{columnIndex:u,expression:""}]}):(l({...n,onClickFilter:(f=n==null?void 0:n.onClickFilter)==null?void 0:f.filter(g=>g.columnIndex!==u)}),a(g=>{const b=[...g];return b[u]=!1,b}))}function i(u,m){var f;const h=(f=n==null?void 0:n.onClickFilter)==null?void 0:f.map(g=>g.columnIndex===u?{...g,expression:m.target.value}:g);l({...n,onClickFilter:h})}function d(u){var m,h,f,g;if(t!=null&&t[u]||(h=(m=n==null?void 0:n.onClickFilter)==null?void 0:m.find(b=>b.columnIndex===u))!=null&&h.expression)return e.jsx(s.Input,{value:(g=(f=n==null?void 0:n.onClickFilter)==null?void 0:f.find(b=>b.columnIndex===u))==null?void 0:g.expression,onChange:b=>i(u,b),type:"text",className:"h-9 w-full font-mono text-xs focus-visible:ring-0 focus-visible:ring-ring focus-visible:ring-offset-0",placeholder:"Expression"})}return e.jsx("div",{className:"max-h-[150px] space-y-2 overflow-y-auto",children:o==null?void 0:o.map((u,m)=>{var h,f;return e.jsx("div",{className:"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:!!((h=n==null?void 0:n.onClickFilter)!=null&&h.find(g=>g.columnIndex===m)),onCheckedChange:g=>c(m,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:((f=n==null?void 0:n.onClickFilter)==null?void 0:f.find(g=>g.columnIndex===m))&&e.jsx(s.Pencil,{onClick:()=>{a(g=>{const b=[...g];return b[m]=!g[m],b})},className:"invisible size-3 cursor-pointer text-gray-400 group-hover:visible"})})]}),d(m)]})},u)})})}function lr({idx:t}){var i;const a=s.useEditorStore(d=>{var u;return(u=d.card)==null?void 0:u.preferences}),n=s.useEditorStore(d=>{var u;return(u=d.card.preferences)==null?void 0:u.datasetOptions}),r=s.useEditorStore(d=>d.actions.setCardPreferences),l=(i=a==null?void 0:a.chartOptions)==null?void 0:i.indexAxis,o=n==null?void 0:n.find(d=>d.idx===t);function c(d,u){(d==="end"||d==="start")&&s.getContrastColor(s.getCanvasBackgroundColor());const m={display:d!=="none",align:d,anchor:d,clamp:!0};if(!o)r({...a,datasetOptions:[...n||[],{idx:u,datalabels:m}]});else{const h={...o};h.datalabels=m;const f=n==null?void 0:n.map(g=>g.idx===u?h:g);r({...a,datasetOptions:f})}}return e.jsxs(s.Popover,{children:[e.jsx(s.PopoverTrigger,{children:e.jsx(at,{className:"size-4 rotate-[135deg] cursor-pointer text-muted-foreground hover:text-foreground"})}),e.jsx(s.PopoverContent,{className:"w-fit px-2 py-1",children:e.jsxs("div",{className:"flex gap-1",children:[e.jsx("button",{onClick:()=>c("none",t),className:"h-7 p-1 text-xs font-normal",children:e.jsx(s.X,{className:"size-3.5"})}),e.jsx("button",{onClick:()=>c("start",t),className:"h-7 p-1 text-xs font-normal",children:e.jsx(Sa,{className:s.cn("h-4 w-4",{"rotate-90":l==="y"})})}),e.jsx("button",{onClick:()=>c("center",t),className:"h-7 p-1 text-xs font-normal",children:e.jsx(Da,{className:s.cn("h-4 w-4",{"rotate-90":l==="y"})})}),e.jsx("button",{onClick:()=>c("end",t),className:"h-7 p-1 text-xs font-normal",children:e.jsx(wa,{className:s.cn("h-4 w-4",{"rotate-90":l==="y"})})})]})})]})}function or(){const t=s.useEditorStore(o=>o.card),{data:a}=s.useDashboardCardQuery(t),{keys:n}=s.getKeys((a==null?void 0:a.records)||[]),r=n.slice(1).filter(o=>!s.METADATA_KEYS.includes(o));let l=r;if(["stackedBar","stackedLine"].includes(t.type)){const o=s.pivotData({dataArray:(a==null?void 0:a.records)||[],groupKey:n[0],pivotKey:n[1],valueKey:n[2]}),{keys:c}=s.getKeys(o);l=c.slice(1)}return{transformedMetricKeys:l,dimensionKeys:n.slice(0,1),keys:n,defaultMetricKeys:r}}function os({children:t,className:a,delayDuration:n}){return e.jsx(s.TooltipProvider$1,{children:e.jsxs(s.Tooltip,{delayDuration:n,children:[e.jsx(s.TooltipTrigger,{asChild:!0,children:e.jsx("span",{className:s.cn("overflow-hidden text-ellipsis whitespace-nowrap",a),children:t})}),e.jsx(s.TooltipContent,{children:t})]})})}function Rt(){const t=s.useEditorStore(d=>d.card),a=s.useEditorStore(d=>{var u,m,h;return(h=(m=(u=d==null?void 0:d.card)==null?void 0:u.preferences)==null?void 0:m.chartOptions)==null?void 0:h.indexAxis}),{data:n}=s.useDashboardCardQuery(t),r=a==="y"?"Metric":"Dimension",l=a==="y"?"Dimension":"Metric",{dimensionKeys:o,transformedMetricKeys:c,keys:i}=or();return i.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:"max-h-[125px] space-y-1 overflow-y-auto",children:o.map(d=>e.jsx("p",{className:"flex h-8 items-center rounded-md bg-muted/70 px-3 hover:bg-muted",title:d,children:Ot(d)},d))})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(s.Label,{children:l}),e.jsx("div",{className:"my-1 max-h-[125px] space-y-1 overflow-y-auto",children:c.map((d,u)=>e.jsx(Bt,{className:"flex h-8 items-center bg-muted/70 px-3 hover:bg-muted",iconClassName:"invisible group-hover:visible",col:d,idx:u},d))})]})]})}function Ot(t,a=30){return t.length>a?t.slice(0,a)+"...":t}function Bt({col:t,idx:a,className:n,iconClassName:r,children:l}){const o=s.useEditorStore(m=>{var h;return(h=m.card)==null?void 0:h.preferences}),c=s.useEditorStore(m=>{var h,f;return(f=(h=m.card)==null?void 0:h.preferences)==null?void 0:f.datasetOptions}),i=c==null?void 0:c.find(m=>m.idx===a),{setCardPreferences:d}=s.useEditorStore(m=>m.actions);function u(m){if(!i)d({...o,datasetOptions:[...c||[],{idx:a,type:m==="area"?"line":m,fill:m==="area"?"origin":""}]});else{const h={...i};h.type=m==="area"?"line":m,h.fill=m==="area"?"origin":"";const f=c==null?void 0:c.map(g=>g.idx===a?h:g);d({...o,datasetOptions:f})}}return e.jsxs("div",{className:s.cn("group flex items-center justify-between gap-2 rounded-md",n),children:[l||e.jsx(os,{className:"max-w-[100px]",title:t,children:Ot(t)}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(s.ChartColumnIncreasing,{onClick:()=>u("bar"),className:s.cn("size-4 cursor-pointer text-muted-foreground hover:text-foreground",r)}),e.jsx(s.ChartLine,{onClick:()=>u("line"),className:s.cn("size-4 cursor-pointer text-muted-foreground hover:text-foreground",r)}),e.jsx(s.ChartArea,{onClick:()=>u("area"),className:s.cn("size-4 cursor-pointer text-muted-foreground hover:text-foreground",r)}),e.jsx(lr,{idx:a})]})]})}function ks(){const t=s.useEditorStore(g=>g.selectedConnectionId),a=s.useEditorStore(g=>g.selectedDatamodelId),n=s.useEditorStore(g=>g.selectedDatabaseName),r=s.useEditorStore(g=>g.selectedSchemaName),l=s.useEditorStore(g=>g.selectedTableName),o=s.useDashboardStore(g=>g.dashboard.filters)||[],c=s.useDashboardStore(g=>g.actions.addFilter),i=s.useDashboardStore(g=>g.actions.removeFilter),{removeFilterValues:d}=s.useDashboardActions(),{modelItems:u,tableName:m,connectionType:h}=s.useEditorAside();function f(g,b="dashboard",p){var D;const j=s.fmt(g.column_name),x=s.fmt(n||""),v=s.fmt(r||""),k=s.fmt(m);let L=s.getQualifiedTableName({schemaName:v,tableName:k,connectionType:h,databaseName:x}),C=`${L}.${j}`;const S=(D=u==null?void 0:u.find(N=>N.id===a))==null?void 0:D.name;a&&a!=="none"&&(C=`${s.DATAMODEL_NAMESPCACE}.${S}.${j}`,L=`${s.DATAMODEL_NAMESPCACE}.${S}`),p!=null&&p.qualifiedFieldName&&(C=p.qualifiedFieldName),p!=null&&p.entityName&&(L=p.entityName);const y=o==null?void 0:o.find(N=>N.column===C&&N.table===k&&(N.database===x||N.database===n));if(y)d(y.id),i(y.id);else{const N=s.v4();return m==="api"&&t?(c({location:b,id:N,column:C,title:g.column_name,dataType:g.data_type,table:"api",database:"",connectionId:t,operation:"in",sql:s.getDefaultFilterSql(g.data_type,L,j)}),N):(c({id:N,location:b,column:C,title:g.column_name,dataType:g.data_type,table:l||"",database:n||"",connectionId:t||"",operation:"in",sql:s.getDefaultFilterSql(g.data_type,L,j)}),N)}}return{assignFilter:f}}function Pe(){const t=s.useDashboardStore(i=>i.dashboard.filters),a=s.useEditorStore(i=>i.frame),{setFrame:n}=s.useEditorActions(),{columns:r}=s.useEditorAside(),{assignFilter:l}=ks();function o(i){const d=l(i,"frame");n({...a,filterId:d})}const c=t==null?void 0:t.find(i=>i.id===a.filterId);return e.jsxs("div",{className:"space-y-3",children:[e.jsx(s.Label,{children:"Card Filter"}),e.jsx(ir,{onSelect:o,columns:r}),c&&e.jsx(s.FilterHeader,{filter:c})]})}function ir({columns:t,onSelect:a}){var c;const[n,r]=ke.useState(!1),[l,o]=ke.useState("");return e.jsxs(s.Popover,{open:n,onOpenChange:r,children:[e.jsx(s.PopoverTrigger,{asChild:!0,children:e.jsxs(s.Button,{size:"sm",variant:"outline",role:"combobox","aria-expanded":n,className:"w-full justify-between font-normal",children:[l?(c=t.find(i=>i.column_name===l))==null?void 0:c.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==null?void 0:t.map(i=>e.jsxs(s.CommandItem,{value:i.column_name,onSelect:d=>{const u=d===l?"":d;o(u),r(!1),u&&a(i)},children:[i.column_name,e.jsx(s.CheckIcon,{className:s.cn("ml-auto h-4 w-4",l===i.column_name?"opacity-100":"opacity-0")})]},i.column_name))})]})]})})]})}function cr({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:a=>a.stopPropagation(),className:"text-blue-700",href:"https://docs.semaphor.cloud/docs/charts/bar-line-area",children:"example"})," in the docs."]})]})]}),e.jsxs(s.AccordionItem,{value:"item-2",children:[e.jsx(s.AccordionTrigger,{children:"Settings"}),e.jsx(s.AccordionContent,{className:"space-y-4 px-2",children:e.jsx(Rt,{})})]}),e.jsxs(s.AccordionItem,{value:"item-3",children:[e.jsx(s.AccordionTrigger,{children:"Click Filters"}),e.jsxs(s.AccordionContent,{className:"space-y-4 px-2",children:[e.jsx(Le,{}),e.jsx(Pe,{})]})]})]})})}function dr({cardType:t}){function a(n){return e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"rounded bg-muted px-2 py-1 text-xs",children:n==="bubble"?"SELECT label, [group], x-axis, y-axis, radius FROM table":"SELECT label, [group], x-axis, y-axis FROM table"}),e.jsxs("ul",{className:"ml-6 list-disc text-xs [&>li]:mt-2",children:[e.jsx("li",{children:"label - category"}),e.jsx("li",{children:"group (optional) - category"}),e.jsx("li",{children:"x-axis - number"}),e.jsx("li",{children:"y-axis - number"}),n==="bubble"&&e.jsx("li",{children:"radius - number"})]}),e.jsxs("div",{children:["See ",e.jsx("a",{target:"_blank",onClick:o=>o.stopPropagation(),className:"text-blue-700",href:"https://docs.semaphor.cloud/docs/charts/bubble",children:"example"})," in the docs."]})]})}return e.jsx("div",{className:"space-y-6 px-6 py-2",children:e.jsxs(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:a(t)})]}),e.jsxs(s.AccordionItem,{value:"item-3",children:[e.jsx(s.AccordionTrigger,{children:"Click Filters"}),e.jsxs(s.AccordionContent,{className:"space-y-4 px-2",children:[e.jsx(Le,{}),e.jsx(Pe,{})]})]})]})})}function Ft(){const t=s.useEditorStore(i=>i.card.type),a=s.useEditorStore(i=>i.isDevMode),n=s.useEditorStore(i=>i.card.preferences),{setCardPreferences:r}=s.useEditorStore(i=>i.actions);function l(i){var m;const d={datalabels:{display:i!=="none",align:i,anchor:i,clamp:!0}},u={...n,chartOptions:{...n==null?void 0:n.chartOptions,plugins:{...(m=n==null?void 0:n.chartOptions)==null?void 0:m.plugins,...d}}};r(u)}function o(){var i,d,u;return e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"font-medium",children:"Data Labels"}),e.jsxs(s.Select,{value:((u=(d=(i=n==null?void 0:n.chartOptions)==null?void 0:i.plugins)==null?void 0:d.datalabels)==null?void 0:u.anchor)||"none",onValueChange:l,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"}),!["pyramid","funnel"].includes(t)&&e.jsx(s.SelectItem,{value:"start",children:"Start"}),e.jsx(s.SelectItem,{value:"center",children:"Center"}),!["pyramid","funnel"].includes(t)&&e.jsx(s.SelectItem,{value:"end",children:"End"})]})})]})]})}function c(){var i,d,u;return e.jsx("div",{children:e.jsxs(s.Select,{value:((u=(d=(i=n==null?void 0:n.chartOptions)==null?void 0:i.plugins)==null?void 0:d.datalabels)==null?void 0:u.anchor)||"none",onValueChange:l,defaultValue:"none",children:[e.jsx(s.SelectTrigger,{className:"h-8 w-full text-xs",children:e.jsx(s.SelectValue,{placeholder:"Select position"})}),e.jsx(s.SelectContent,{children:e.jsxs(s.SelectGroup,{children:[e.jsx(s.SelectItem,{className:"text-xs",value:"none",children:"None"}),!["pyramid","funnel"].includes(t)&&e.jsx(s.SelectItem,{className:"text-xs",value:"start",children:"Start"}),e.jsx(s.SelectItem,{className:"text-xs",value:"center",children:"Center"}),!["pyramid","funnel"].includes(t)&&e.jsx(s.SelectItem,{className:"text-xs",value:"end",children:"End"})]})})]})})}return e.jsx(e.Fragment,{children:a?o():c()})}const ur={datasets:[{type:"line",label:"Sum_sales",data:[]},{type:"bar",label:"Sum_profit",data:[]}]},mr={datasets:[{fill:"origin",type:"line",label:"Sum_sales",data:[]}]};function hr(){const t=s.useEditorStore(a=>a.card.type);return e.jsxs("div",{className:"space-y-6 p-6",children:[e.jsx(s.Accordion,{className:" ",type:"single",collapsible:!0,children:xr(t)}),!["kpi"].includes(t)&&e.jsxs("div",{className:"space-y-4",children:[e.jsx(Ft,{}),e.jsx(Le,{}),e.jsx(Pe,{})]})]})}function xr(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(ur,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(mr,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","funnel"].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 pr({colorRanges:t,setColorRanges:a}){const n={start:-1/0,end:100,color:""};function r(c,i,d){const u=[...t];u[c]={...u[c],[i]:d},a(u)}function l(c){const i=[...t];i.splice(c,1),a(i)}function o(){a([...t,n])}return e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(s.Label,{children:"Color Range"}),e.jsx(s.Button,{onClick:o,variant:"secondary",className:"h-5 p-1 text-muted-foreground",children:e.jsx(s.Plus,{className:"size-3"})})]}),t.map((c,i)=>e.jsxs("div",{className:"flex items-center gap-2 px-2",children:[e.jsx(s.Input,{onChange:d=>r(i,"start",d.target.value),value:c.start,className:s.cn(`h-7 ${s.removeRing}`)}),e.jsx("span",{children:"-"}),e.jsx(s.Input,{value:c.end,onChange:d=>r(i,"end",d.target.value),className:s.cn(`h-7 ${s.removeRing}`)}),e.jsx(s.Input,{onChange:d=>r(i,"color",d.target.value),value:c.color,className:s.cn(`h-7 min-w-14 p-0 ${s.removeRing}`),type:"color",list:"presetColors"}),e.jsxs("datalist",{id:"presetColors",children:[e.jsx("option",{children:s.colors.green[600]}),e.jsx("option",{children:s.colors.red[500]}),e.jsx("option",{children:s.colors.yellow[400]}),e.jsx("option",{children:s.colors.orange[500]})]}),e.jsx(s.Button,{onClick:()=>l(i),variant:"secondary",className:"h-5 p-1 text-muted-foreground",children:e.jsx(s.X,{className:"size-3"})})]},i))]})}function fr(){var m,h,f,g,b;const t=s.useEditorStore(p=>p.card.preferences),a=s.useEditorStore(p=>p.actions.setCardPreferences),n=s.useEditorStore(p=>p.card),r=s.isExplorerCard(n),l=s.useEditorStore(p=>p.actions.setNumberFormat);s.useEditorStore(p=>{var j,x;return(x=(j=p.card.preferences)==null?void 0:j.formatNumber)==null?void 0:x.decimalPlaces});const o=s.useEditorStore(p=>{var j,x;return(x=(j=p.card.preferences)==null?void 0:j.formatNumber)==null?void 0:x.locale}),c=s.useEditorStore(p=>{var j,x;return(x=(j=p.card.preferences)==null?void 0:j.formatNumber)==null?void 0:x.currency});s.useEditorStore(p=>p.actions.setFilterOnClickField);const i=s.useEditorStore(p=>{var j,x;return(x=(j=p.card.preferences)==null?void 0:j.formatNumber)==null?void 0:x.colorRanges})||[],d=s.useEditorStore(p=>p.actions.setColorRanges),u=[...new Set(s.LOCALE_CURRENCY_PAIRS.map(p=>p.currency))];return e.jsxs("div",{children:[!r&&e.jsxs("div",{className:"mb-3 flex items-center gap-2",children:[e.jsx(s.Checkbox,{checked:!!((m=t==null?void 0:t.formatNumber)!=null&&m.enabled),onCheckedChange:p=>{a({...t,formatNumber:{...t==null?void 0:t.formatNumber,enabled:p}})}}),e.jsx(s.Label,{children:"Format Number"})]}),(((h=t==null?void 0:t.formatNumber)==null?void 0:h.enabled)===!0||r)&&e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsx("div",{children:e.jsxs("div",{className:"space-y-4",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:o||"none",onValueChange:p=>{var j,x,v;return l(((j=t==null?void 0:t.formatNumber)==null?void 0:j.decimalPlaces)||0,((x=t==null?void 0:t.formatNumber)==null?void 0:x.currency)||"",p,((v=t==null?void 0:t.formatNumber)==null?void 0:v.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:"Auto"},"none"),s.LOCALE_CURRENCY_PAIRS.map(p=>e.jsx(s.SelectItem,{value:p.locale,children:p.locale},p.locale))]})})]})]}),e.jsxs("div",{className:"w-full space-y-1",children:[e.jsx(s.Label,{children:"Currency"}),e.jsxs(s.Select,{value:c||"none",onValueChange:p=>{var j,x,v;console.log("currency",p),l(((j=t==null?void 0:t.formatNumber)==null?void 0:j.decimalPlaces)||0,p==="none"?"":p,((x=t==null?void 0:t.formatNumber)==null?void 0:x.locale)||"",((v=t==null?void 0:t.formatNumber)==null?void 0:v.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"),u.map(p=>e.jsx(s.SelectItem,{value:p,children:p},p))]})})]})]})]}),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:((g=(f=t==null?void 0:t.formatNumber)==null?void 0:f.decimalPlaces)==null?void 0:g.toString())||"0",onValueChange:p=>{var j,x,v;return l(Number(p),((j=t==null?void 0:t.formatNumber)==null?void 0:j.currency)||"",((x=t==null?void 0:t.formatNumber)==null?void 0:x.locale)||"",((v=t==null?void 0:t.formatNumber)==null?void 0:v.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(p=>e.jsx(s.SelectItem,{value:p,children:p},p))})]})]}),e.jsxs("div",{className:"w-full space-y-1",children:[e.jsx(s.Label,{children:"Suffix"}),e.jsx(s.Input,{value:((b=t==null?void 0:t.formatNumber)==null?void 0:b.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:p=>{var j,x,v;return l(((j=t==null?void 0:t.formatNumber)==null?void 0:j.decimalPlaces)||0,((x=t==null?void 0:t.formatNumber)==null?void 0:x.currency)||"",((v=t==null?void 0:t.formatNumber)==null?void 0:v.locale)||"",p.target.value)}})]})]})]})}),e.jsx(s.Separator,{className:"my-3"}),e.jsx(pr,{colorRanges:i,setColorRanges:d})]})]})}function gr(){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/docs/charts/kpi",children:"example"})," in the docs."]})]})]})}),e.jsx("section",{className:"",children:e.jsx(fr,{})}),e.jsx("div",{}),e.jsx("div",{})]})}function xs({children:t,summary:a,open:n,className:r}){return e.jsxs("details",{open:n,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:a}),e.jsx(s.ChevronUp,{className:"h-4 w-4"})]}),e.jsx("div",{className:"transition-all ease-in-out",children:t})]})}const jr=[{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"}],br=["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"],yr=br.map(t=>({label:t,value:t}));function vr(){var d,u,m,h,f,g,b,p,j,x,v,k,L,C,S,y,D,N;const t=s.useEditorStore(B=>B.card),a=(u=(d=t==null?void 0:t.preferences)==null?void 0:d.mapVisualOptions)==null?void 0:u.topoJsonUrl,[n,r]=I.useState(((h=(m=t==null?void 0:t.preferences)==null?void 0:m.mapVisualOptions)==null?void 0:h.customTopoJsonUrl)||""),{setCardPreferences:l}=s.useEditorActions(),{data:o}=s.useTopoJson(t),c=Object.keys((o==null?void 0:o.objects)||{}).map(B=>({label:B,value:B}))||[],i=[{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(xs,{summary:"Map Chart",children:e.jsx("p",{className:"rounded-md bg-muted p-2 font-mono text-xs",children:"SELECT country, value FROM table"})}),e.jsx(s.Separator,{className:"my-4"}),e.jsx(xs,{open:!0,summary:"Settings",children:e.jsxs("div",{className:"space-y-3 px-2",children:[e.jsx(fe,{className:"h-9",options:i,onValueChange:B=>{console.log("value",B),l({...t.preferences,mapVisualOptions:{topoJsonUrl:B}})},value:a||"",label:"Select Map"}),a==="custom"&&e.jsx(s.Input,{onChange:B=>{r(B.target.value)},onBlur:()=>{var B;console.log("onBlur",n),l({...t.preferences,mapVisualOptions:{...(B=t.preferences)==null?void 0:B.mapVisualOptions,customTopoJsonUrl:n}})},value:n,className:`h-9 w-full ${s.removeRing}`,placeholder:"Custom URL"}),o&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(s.Label,{children:"Map Object"}),e.jsx(fe,{className:"h-9",options:c,value:((g=(f=t.preferences)==null?void 0:f.mapVisualOptions)==null?void 0:g.objectKey)||"",label:"Map Object",onValueChange:B=>{var w;l({...t.preferences,mapVisualOptions:{...(w=t.preferences)==null?void 0:w.mapVisualOptions,objectKey:B}})}})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(s.Label,{children:"Projection"}),e.jsx(fe,{className:"h-9",options:jr,value:((p=(b=t.preferences)==null?void 0:b.mapVisualOptions)==null?void 0:p.projection)||"",label:"Projection",onValueChange:B=>{var w;l({...t.preferences,mapVisualOptions:{...(w=t.preferences)==null?void 0:w.mapVisualOptions,projection:B}})}})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(s.Label,{children:"Colors"}),e.jsx(fe,{className:"h-9",options:yr,value:((x=(j=t.preferences)==null?void 0:j.mapVisualOptions)==null?void 0:x.colorScale)||"",label:"Select Color Scale",onValueChange:B=>{var w;l({...t.preferences,mapVisualOptions:{...(w=t.preferences)==null?void 0:w.mapVisualOptions,colorScale:B}})}})]})]})]})}),e.jsx(s.Separator,{className:"my-4"}),e.jsx(xs,{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:((k=(v=t.preferences)==null?void 0:v.mapVisualOptions)==null?void 0:k.projectionScale)||1,onChange:B=>{var w;l({...t.preferences,mapVisualOptions:{...(w=t.preferences)==null?void 0:w.mapVisualOptions,projectionScale:Number(B.target.value)}})}}),e.jsx(s.Label,{children:"X"}),e.jsx(s.Input,{className:`h-9 w-full ${s.removeRing}`,type:"number",step:10,value:((S=(C=(L=t.preferences)==null?void 0:L.mapVisualOptions)==null?void 0:C.projectionOffset)==null?void 0:S[0])||0,onChange:B=>{var w,F,T,E;l({...t.preferences,mapVisualOptions:{...(w=t.preferences)==null?void 0:w.mapVisualOptions,projectionOffset:[Number(B.target.value),((E=(T=(F=t.preferences)==null?void 0:F.mapVisualOptions)==null?void 0:T.projectionOffset)==null?void 0:E[1])||0]}})}}),e.jsx(s.Label,{children:"Y"}),e.jsx(s.Input,{className:`h-9 w-full ${s.removeRing}`,type:"number",step:10,value:((N=(D=(y=t.preferences)==null?void 0:y.mapVisualOptions)==null?void 0:D.projectionOffset)==null?void 0:N[1])||0,onChange:B=>{var w,F,T,E;l({...t.preferences,mapVisualOptions:{...(w=t.preferences)==null?void 0:w.mapVisualOptions,projectionOffset:[((E=(T=(F=t.preferences)==null?void 0:F.mapVisualOptions)==null?void 0:T.projectionOffset)==null?void 0:E[0])||0,Number(B.target.value)]}})}})]})}),e.jsx(s.Separator,{className:"my-4"}),e.jsx(Le,{})]})}function Nr(){var r;const t=s.useEditorStore(l=>l.card.preferences),{setCardPreferences:a}=s.useEditorStore(l=>l.actions);function n(l){a({...t,textVisualOptions:{...t==null?void 0:t.textVisualOptions,isDynamicText:l==="dynamic"}})}return e.jsxs(s.RadioGroup,{value:(r=t==null?void 0:t.textVisualOptions)!=null&&r.isDynamicText?"dynamic":"static",onValueChange:n,className:"flex gap-3",defaultValue:"x",children:[e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(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 Qe({cardType:t,docContent:a,suffix:n="Chart"}){let r="pie-donut-polar";return t==="funnel"&&(r="funnel"),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)} ${n}`}),e.jsx(s.AccordionContent,{children:a||e.jsxs("div",{className:"space-y-4 font-mono text-xs",children:[e.jsx("div",{className:"rounded bg-muted px-2 py-1 text-xs",children:"SELECT label, measure FROM table"}),e.jsxs("ul",{className:"ml-6 list-disc text-xs [&>li]:mt-2",children:[e.jsx("li",{children:"label - category"}),e.jsx("li",{children:"measure - number"})]}),e.jsxs("div",{children:["See ",e.jsx("a",{target:"_blank",onClick:l=>l.stopPropagation(),className:"text-blue-700",href:`https://docs.semaphor.cloud/docs/charts/${r}`,children:"example"})," in the docs."]})]})})]}),t==="text"&&e.jsxs(s.AccordionItem,{value:"item-2",children:[e.jsx(s.AccordionTrigger,{children:"Settings"}),e.jsx(s.AccordionContent,{className:"space-y-4 px-2 py-4",children:e.jsx(Nr,{})})]}),!["range","text"].includes(t)&&e.jsxs(s.AccordionItem,{value:"item-3",children:[e.jsx(s.AccordionTrigger,{children:"Click Filters"}),e.jsxs(s.AccordionContent,{className:"space-y-4 px-2",children:[e.jsx(Le,{}),e.jsx(Pe,{})]})]})]})})}function Cr(){const t=s.useEditorStore(r=>{var l,o;return(o=(l=r==null?void 0:r.card)==null?void 0:l.preferences)==null?void 0:o.sortChart}),{setSortChart:a}=s.useEditorActions();function n(){return e.jsxs("div",{className:"space-y-2",children:[e.jsx(s.Label,{children:"Sort"}),e.jsx(fe,{className:"h-8",label:"Sort Chart",options:[{label:"None",value:"none"},{label:"ASC",value:"asc"},{label:"DESC",value:"desc"}],value:t||"none",onValueChange:r=>{a(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/docs/charts/stacked",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:[n(),e.jsx(Rt,{})]})]}),e.jsxs(s.AccordionItem,{value:"item-3",children:[e.jsx(s.AccordionTrigger,{children:"Click Filters"}),e.jsxs(s.AccordionContent,{className:"space-y-4 px-2",children:[e.jsx(Le,{}),e.jsx(Pe,{})]})]})]})})}function Sr({cardType:t="table"}){console.log("cardType",t);const a=s.useEditorStore(l=>{var o;return(o=l.card)==null?void 0:o.preferences}),n=s.useEditorStore(l=>l.actions.setCardPreferences),r=l=>{n({...a,allowDownload:l})};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:"Click Filters"}),e.jsxs(s.AccordionContent,{className:"space-y-4 px-2",children:[e.jsx(Le,{}),e.jsx(Pe,{})]})]})}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(s.Checkbox,{onCheckedChange:r,id:"allow-download"}),e.jsx("label",{htmlFor:"allow-download",className:"text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70",children:"Allow Download"})]})]})}function Pt({color:t,onColorChange:a,onClose:n}){const[r,l]=I.useState(0),[o,c]=I.useState(100),[i,d]=I.useState(50),[u,m]=I.useState(t);I.useEffect(()=>{const j=$s(t);if(j){const x=qs(j.r,j.g,j.b);l(x.h),c(x.s),d(x.l),m(t)}},[t]);const h=j=>{l(j),g(j,o,i)},f=j=>{const x=j.currentTarget.getBoundingClientRect(),v=Math.max(0,Math.min(1,(j.clientX-x.left)/x.width)),k=Math.max(0,Math.min(1,(j.clientY-x.top)/x.height)),L=v*100,C=(1-k)*100;c(L),d(C),g(r,L,C)},g=(j,x,v)=>{const k=Dr(j,x,v),L=wr(k.r,k.g,k.b);m(L)},b=j=>{if(m(j),/^#[0-9A-Fa-f]{6}$/.test(j)){const x=$s(j);if(x){const v=qs(x.r,x.g,x.b);l(v.h),c(v.s),d(v.l)}}},p=()=>{/^#[0-9A-Fa-f]{6}$/.test(u)&&(a(u),n())};return e.jsxs("div",{className:"p-4 space-y-4 w-[320px]",children:[e.jsxs("div",{className:"relative h-[200px] rounded cursor-crosshair",style:{background:`hsl(${r}, 100%, 50%)`},onClick:f,onMouseMove:j=>{j.buttons===1&&f(j)},children:[e.jsx("div",{className:"absolute inset-0 rounded",style:{background:"linear-gradient(to right, white, transparent)"}}),e.jsx("div",{className:"absolute inset-0 rounded",style:{background:"linear-gradient(to bottom, transparent, black)"}}),e.jsx("div",{className:"absolute w-4 h-4 -ml-2 -mt-2 rounded-full border-2 border-white shadow-md",style:{left:`${o}%`,top:`${100-i}%`,backgroundColor:u}})]}),e.jsx("div",{className:"space-y-2",children:e.jsx("input",{type:"range",min:"0",max:"360",value:r,onChange:j=>h(Number(j.target.value)),className:"w-full h-4 rounded-lg appearance-none cursor-pointer",style:{background:"linear-gradient(to right, #ff0000, #ffff00, #00ff00, #00ffff, #0000ff, #ff00ff, #ff0000)"}})}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(s.Label,{children:"HEX"}),e.jsx(s.Input,{value:u,onChange:j=>b(j.target.value),placeholder:"#000000",className:"font-mono"})]}),e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsxs("div",{className:"text-center",children:[e.jsx("div",{className:"w-12 h-12 rounded-full border shadow-sm",style:{backgroundColor:t}}),e.jsx("span",{className:"text-xs text-muted-foreground mt-1",children:"CURRENT"})]}),e.jsxs("div",{className:"text-center",children:[e.jsx("div",{className:"w-12 h-12 rounded-full border shadow-sm",style:{backgroundColor:u}}),e.jsx("span",{className:"text-xs text-muted-foreground mt-1",children:"NEW"})]})]}),e.jsxs("div",{className:"flex gap-2 justify-end",children:[e.jsx(s.Button,{variant:"outline",onClick:n,children:"Cancel"}),e.jsx(s.Button,{onClick:p,children:"OK"})]})]})}function $s(t){const a=/^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(t);return a?{r:parseInt(a[1],16),g:parseInt(a[2],16),b:parseInt(a[3],16)}:null}function wr(t,a,n){return"#"+((1<<24)+(t<<16)+(a<<8)+n).toString(16).slice(1)}function qs(t,a,n){t/=255,a/=255,n/=255;const r=Math.max(t,a,n),l=Math.min(t,a,n);let o=0,c=0;const i=(r+l)/2;if(r!==l){const d=r-l;switch(c=i>.5?d/(2-r-l):d/(r+l),r){case t:o=((a-n)/d+(a<n?6:0))/6;break;case a:o=((n-t)/d+2)/6;break;case n:o=((t-a)/d+4)/6;break}}return{h:Math.round(o*360),s:Math.round(c*100),l:Math.round(i*100)}}function Dr(t,a,n){t/=360,a/=100,n/=100;let r,l,o;if(a===0)r=l=o=n;else{const c=(u,m,h)=>(h<0&&(h+=1),h>1&&(h-=1),h<.16666666666666666?u+(m-u)*6*h:h<.5?m:h<.6666666666666666?u+(m-u)*(.6666666666666666-h)*6:u),i=n<.5?n*(1+a):n+a-n*a,d=2*n-i;r=c(d,i,t+1/3),l=c(d,i,t),o=c(d,i,t-1/3)}return{r:Math.round(r*255),g:Math.round(l*255),b:Math.round(o*255)}}const kr=["#000000","#ffffff","#6b7280","#dc2626","#ea580c","#ca8a04","#16a34a","#0891b2","#2563eb","#7c3aed","#c026d3","#e11d48","#0f172a","#f3f4f6","#fbbf24"];function zt(){var k,L,C,S,y,D,N,B,w,F;const t=s.useEditorStore(T=>T.card),a=s.useEditorStore(T=>{var E;return(E=T.card)==null?void 0:E.preferences}),{setCardPreferences:n,updateCardInFrame:r}=s.useEditorActions(),{data:l}=s.useDashboardCardQuery(t),[o,c]=I.useState({}),[i,d]=I.useState(null),[u,m]=I.useState(null),h=I.useMemo(()=>{var O,M,R,P,K,Y,te;if(!(l!=null&&l.records)||l.records.length===0)return[];const T=(t==null?void 0:t.type)==="stackedBar"||(t==null?void 0:t.type)==="stackedLine",E=(t==null?void 0:t.type)==="bar"||(t==null?void 0:t.type)==="line",A=((O=t==null?void 0:t.config)==null?void 0:O.pivotByColumns)&&t.config.pivotByColumns.length>0;if((T||E)&&A){if(l.pivotSchema&&Array.isArray(l.pivotSchema)){const X=new Set;return l.pivotSchema.forEach(q=>{q.alias&&X.add(q.alias)}),Array.from(X)}if(l.records.length>0){const X=l.records[0],q=Object.keys(X),H=new Set;(M=t==null?void 0:t.config)!=null&&M.groupByColumns&&t.config.groupByColumns.forEach(z=>{H.add(z.label||z.name),H.add(z.alias||z.name)});const _=new Set;return(R=t==null?void 0:t.config)!=null&&R.metricColumns&&t.config.metricColumns.forEach(z=>{const U=z.alias||z.name;_.add(U),_.add(`${U}_count`),_.add(`${U}_sum`),_.add(`${U}_avg`),_.add(`${U}_min`),_.add(`${U}_max`);const Z=z.entityName||z.qualifiedEntityName;Z&&(_.add(`${Z}_${U}`),_.add(`${Z}_${U}_count`))}),q.filter(z=>!H.has(z)&&!_.has(z))}}if((E||T)&&!A&&((K=(P=t==null?void 0:t.config)==null?void 0:P.metricColumns)!=null&&K.length))return t.config.metricColumns.map(X=>X.alias||X.label||X.name);if((te=(Y=t==null?void 0:t.config)==null?void 0:Y.groupByColumns)!=null&&te.length){const X=t.config.groupByColumns[0],q=X.label||X.name,H=new Set;return l.records.forEach(_=>{const J=_[q];J!=null&&H.add(String(J))}),Array.from(H)}return[]},[l,(k=t==null?void 0:t.config)==null?void 0:k.groupByColumns,(L=t==null?void 0:t.config)==null?void 0:L.pivotByColumns,(C=t==null?void 0:t.config)==null?void 0:C.metricColumns,t==null?void 0:t.type]),f=I.useMemo(()=>s.getDefaultChartColors(),[]);I.useEffect(()=>{const T={};h.forEach((E,A)=>{T[E]=s.getColorForValue(E,A,a==null?void 0:a.colorConfig)}),c(T)},[h,a==null?void 0:a.colorConfig,f]);const g=(T,E)=>{const A={...o,[T]:E};c(A);const O={...a||{},colorConfig:{segments:A}};n(O);const M={...t,preferences:O};r(M)},b=(T,E)=>{var K;const A=f[E%f.length],{[T]:O,...M}=((K=a==null?void 0:a.colorConfig)==null?void 0:K.segments)||{},R={...a||{},colorConfig:{segments:M}};n(R);const P={...t,preferences:R};r(P),c(Y=>({...Y,[T]:A}))};if(!h.length||!((t==null?void 0:t.type)==="stackedBar"||(t==null?void 0:t.type)==="stackedLine"?((y=(S=t==null?void 0:t.config)==null?void 0:S.groupByColumns)==null?void 0:y.length)||((N=(D=t==null?void 0:t.config)==null?void 0:D.pivotByColumns)==null?void 0:N.length):(w=(B=t==null?void 0:t.config)==null?void 0:B.groupByColumns)==null?void 0:w.length)||["table","kpi","text","custom"].includes(t.type))return null;const x=()=>{const T={...a||{},colorConfig:{segments:{}}};n(T);const E={...t,preferences:T};r(E);const A={};h.forEach((O,M)=>{A[O]=s.getColorForValue(O,M,void 0)}),c(A)},v=Object.keys(((F=a==null?void 0:a.colorConfig)==null?void 0:F.segments)||{}).length>0;return e.jsxs(s.AccordionItem,{value:"colors",className:"border-b-0",children:[e.jsx(s.AccordionTrigger,{className:"flex w-full items-center gap-2 py-2 text-sm font-medium hover:no-underline",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Ba,{className:"h-4 w-4 text-muted-foreground"}),e.jsx("span",{children:"Colors"})]})}),e.jsx(s.AccordionContent,{className:"",children:e.jsxs("div",{className:"space-y-3",children:[e.jsx("div",{className:"space-y-2",children:e.jsx("div",{className:"flex items-center justify-between",children:v&&e.jsxs("button",{className:"ml-auto flex items-center gap-1 text-xs text-muted-foreground hover:text-foreground",onClick:x,children:[e.jsx(s.RotateCcw,{className:"h-3 w-3"}),"Reset All"]})})}),e.jsx("div",{className:"max-h-[200px] space-y-2 overflow-y-auto pr-1",children:h.map((T,E)=>{const A=s.isDefaultColor(o[T],E),O=!A;return e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(s.Popover,{open:i===T,onOpenChange:M=>d(M?T:null),children:[e.jsx(s.PopoverTrigger,{asChild:!0,children:e.jsx("button",{className:"h-5 w-5 shrink-0 rounded border border-input shadow-sm transition-colors hover:border-gray-400 focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring",style:{backgroundColor:o[T]}})}),e.jsx(s.PopoverContent,{align:"start",className:"w-auto p-3",children:e.jsxs("div",{className:"space-y-2.5",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"text-xs font-medium text-muted-foreground",children:"Theme Colors"}),e.jsx("div",{className:"grid grid-cols-5 gap-1.5",children:f.slice(0,10).map((M,R)=>e.jsxs("button",{className:s.cn("relative h-5 w-5 rounded border-2 transition-all hover:scale-110",o[T]===M?"border-gray-900":"border-transparent"),style:{backgroundColor:M},onClick:()=>{g(T,M),d(null)},children:[R===E%f.length&&e.jsx("div",{className:"absolute inset-0 flex items-center justify-center",children:e.jsx("div",{className:"rounded-full bg-white/90 px-0.5 text-[8px] font-bold text-gray-900 shadow-sm",children:"D"})}),e.jsx("span",{className:"sr-only",children:M})]},`default-${R}`))})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"text-xs font-medium text-muted-foreground",children:"Popular Colors"}),e.jsx("div",{className:"grid grid-cols-5 gap-1.5",children:kr.map((M,R)=>e.jsx("button",{className:s.cn("h-5 w-5 rounded border transition-all hover:scale-110",o[T]===M?"border-2 border-gray-900":M==="#ffffff"?"border border-gray-300":"border border-transparent"),style:{backgroundColor:M},onClick:()=>{g(T,M),d(null)},children:e.jsx("span",{className:"sr-only",children:M})},`preset-${R}`))})]}),e.jsxs("div",{className:"flex items-center justify-between gap-2 pt-1",children:[e.jsx("button",{className:"text-sm font-medium text-blue-600 hover:text-blue-700",onClick:()=>{m({value:T,color:o[T]}),d(null)},children:"Custom color"}),!A&&e.jsxs("button",{className:"flex items-center gap-1 text-sm text-muted-foreground hover:text-foreground",onClick:()=>{b(T,E),d(null)},children:[e.jsx(s.RotateCcw,{className:"h-3 w-3"}),"Reset"]})]})]})})]}),e.jsx("span",{className:"flex-1 truncate text-sm",children:T}),O&&e.jsx("span",{className:"text-xs text-muted-foreground",children:"(custom)"})]},T)})}),u&&e.jsxs("div",{className:"fixed inset-0 z-50 flex items-center justify-center",children:[e.jsx("div",{className:"absolute inset-0 bg-black/50",onClick:()=>m(null)}),e.jsx("div",{className:"relative rounded-lg bg-white shadow-lg",children:e.jsx(Pt,{color:u.color,onColorChange:T=>{g(u.value,T),m(null)},onClose:()=>m(null)})})]})]})})]})}function ve({value:t,onSave:a,placeholder:n="",type:r="text",className:l=""}){const[o,c]=I.useState(t??""),[i,d]=I.useState(!1);I.useEffect(()=>{c(t??"")},[t]);const u=()=>{a(o),d(!1)},m=()=>{c(t??""),d(!1)};return e.jsxs("div",{className:`flex items-center gap-2 ${l}`,children:[e.jsx(s.Input$1,{placeholder:n,type:r,value:i?o:t??"",onChange:h=>{c(h.target.value),d(!0)},onFocus:()=>d(!0),onClick:h=>h.stopPropagation(),className:"h-8 text-xs",onPointerDown:h=>h.stopPropagation(),onKeyDown:h=>{h.stopPropagation(),h.key==="Enter"&&i&&o!==t?u():h.key==="Escape"&&m()},"aria-label":n||"Edit field"}),i&&o!==t&&e.jsxs(e.Fragment,{children:[e.jsx(s.Button,{variant:"ghost",size:"icon",className:"h-6 w-6 p-0","aria-label":"Confirm edit",onClick:u,children:e.jsx(s.Check,{className:"h-4 w-4 text-green-600"})}),e.jsx(s.Button,{variant:"ghost",size:"icon",className:"h-6 w-6 p-0","aria-label":"Cancel edit",onClick:m,children:e.jsx(s.X,{className:"h-4 w-4 text-muted-foreground"})})]})]})}const Tr=["auto","number","currency","percent","scientific","date"],Er=[{value:"USD",label:"USD - US Dollar"},{value:"EUR",label:"EUR - Euro"},{value:"JPY",label:"JPY - Japanese Yen"},{value:"GBP",label:"GBP - British Pound"},{value:"CNY",label:"CNY - Chinese Yuan"},{value:"CHF",label:"CHF - Swiss Franc"},{value:"CAD",label:"CAD - Canadian Dollar"},{value:"AUD",label:"AUD - Australian Dollar"},{value:"HKD",label:"HKD - Hong Kong Dollar"},{value:"SGD",label:"SGD - Singapore Dollar"},{value:"NZD",label:"NZD - New Zealand Dollar"},{value:"SEK",label:"SEK - Swedish Krona"},{value:"NOK",label:"NOK - Norwegian Krone"},{value:"DKK",label:"DKK - Danish Krone"},{value:"KRW",label:"KRW - South Korean Won"},{value:"INR",label:"INR - Indian Rupee"},{value:"RUB",label:"RUB - Russian Ruble"},{value:"BRL",label:"BRL - Brazilian Real"},{value:"MXN",label:"MXN - Mexican Peso"},{value:"TRY",label:"TRY - Turkish Lira"},{value:"ZAR",label:"ZAR - South African Rand"},{value:"SAR",label:"SAR - Saudi Riyal"},{value:"AED",label:"AED - UAE Dirham"},{value:"ARS",label:"ARS - Argentine Peso"},{value:"CLP",label:"CLP - Chilean Peso"},{value:"COP",label:"COP - Colombian Peso"},{value:"THB",label:"THB - Thai Baht"},{value:"IDR",label:"IDR - Indonesian Rupiah"},{value:"MYR",label:"MYR - Malaysian Ringgit"},{value:"PHP",label:"PHP - Philippine Peso"},{value:"PLN",label:"PLN - Polish Zloty"},{value:"NGN",label:"NGN - Nigerian Naira"},{value:"KES",label:"KES - Kenyan Shilling"},{value:"GHS",label:"GHS - Ghanaian Cedi"},{value:"ZMW",label:"ZMW - Zambian Kwacha"},{value:"ZWL",label:"ZWL - Zimbabwean Dollar"},{value:"EGP",label:"EGP - Egyptian Pound"},{value:"MAD",label:"MAD - Moroccan Dirham"},{value:"UAH",label:"UAH - Ukrainian Hryvnia"},{value:"HUF",label:"HUF - Hungarian Forint"},{value:"CZK",label:"CZK - Czech Koruna"},{value:"RON",label:"RON - Romanian Leu"},{value:"PKR",label:"PKR - Pakistani Rupee"},{value:"BDT",label:"BDT - Bangladeshi Taka"},{value:"VND",label:"VND - Vietnamese Dong"},{value:"TWD",label:"TWD - New Taiwan Dollar"},{value:"ILS",label:"ILS - Israeli New Shekel"}],Ir=[{value:"en-US",label:"English (US)"},{value:"en-GB",label:"English (UK)"},{value:"en-IN",label:"English (India)"},{value:"de-DE",label:"German"},{value:"fr-FR",label:"French"},{value:"es-ES",label:"Spanish"},{value:"it-IT",label:"Italian"},{value:"pt-BR",label:"Portuguese (Brazil)"},{value:"zh-CN",label:"Chinese (Simplified)"},{value:"ja-JP",label:"Japanese"},{value:"ko-KR",label:"Korean"},{value:"ru-RU",label:"Russian"},{value:"ar-SA",label:"Arabic"},{value:"hi-IN",label:"Hindi"},{value:"nl-NL",label:"Dutch"},{value:"sv-SE",label:"Swedish"}],Ar=t=>t.charAt(0).toUpperCase()+t.slice(1);function Ts({formatOptions:t={},onFormatOptionsChange:a,showTitle:n=!0,title:r="NUMBER FORMAT"}){const l=t.type||"auto",o=(i,d)=>{a({...t,[i]:d})},c=()=>l==="currency"?2:l==="percent"?1:0;return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"space-y-2",children:[n&&e.jsx(s.Label,{className:"text-xs font-medium text-muted-foreground",children:r}),e.jsxs(s.Select,{value:l,onValueChange:i=>o("type",i),children:[e.jsx(s.SelectTrigger,{className:"h-8 text-xs",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{children:Tr.map(i=>e.jsx(s.SelectItem,{value:i,className:"text-xs",children:i==="auto"?"Auto (Default)":Ar(i)},i))})]})]}),l!=="auto"&&e.jsxs("div",{className:"space-y-2 border-l-2 border-muted pl-4",children:[["number","currency","percent"].includes(l)&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(s.Label,{className:"w-20 text-xs text-muted-foreground",children:"Decimals"}),e.jsx("div",{className:"flex-1",children:e.jsx(s.Input,{type:"number",min:"0",max:"10",placeholder:"0",value:t.decimalPlaces??c(),onChange:i=>o("decimalPlaces",parseInt(i.target.value)||0),className:"h-8 text-xs"})})]}),l==="currency"&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(s.Label,{className:"w-20 text-xs text-muted-foreground",children:"Currency"}),e.jsxs(s.Select,{value:t.currency||"USD",onValueChange:i=>o("currency",i),children:[e.jsx(s.SelectTrigger,{className:"h-8 flex-1 text-xs",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{children:Er.map(i=>e.jsx(s.SelectItem,{value:i.value,className:"text-xs",children:i.label},i.value))})]})]}),["number","currency"].includes(l)&&e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(s.Label,{className:"text-xs text-muted-foreground",children:"Abbreviate (K, M, B)"}),e.jsx(s.SmallSwitch,{checked:t.useSuffix??!1,onCheckedChange:i=>o("useSuffix",i)})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(s.Label,{className:"w-20 text-xs text-muted-foreground",children:"Locale"}),e.jsxs(s.Select,{value:t.locale||"en-US",onValueChange:i=>o("locale",i),children:[e.jsx(s.SelectTrigger,{className:"h-8 flex-1 text-xs",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{children:Ir.map(i=>e.jsx(s.SelectItem,{value:i.value,className:"text-xs",children:i.label},i.value))})]})]}),l==="number"&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(s.Label,{className:"w-20 text-xs text-muted-foreground",children:"Prefix"}),e.jsx("div",{className:"flex-1",children:e.jsx(s.Input,{placeholder:"e.g., $",value:t.prefix||"",onChange:i=>o("prefix",i.target.value),className:"h-8 text-xs"})})]}),l==="number"&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(s.Label,{className:"w-20 text-xs text-muted-foreground",children:"Suffix"}),e.jsx("div",{className:"flex-1",children:e.jsx(s.Input,{placeholder:"e.g., units",value:t.suffix||"",onChange:i=>o("suffix",i.target.value),className:"h-8 text-xs"})})]}),["number","currency"].includes(l)&&e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(s.Label,{className:"text-xs text-muted-foreground",children:"Negative in ()"}),e.jsx(s.SmallSwitch,{checked:t.negativeInParentheses??!1,onCheckedChange:i=>o("negativeInParentheses",i)})]}),l==="percent"&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(s.Label,{className:"w-20 text-xs text-muted-foreground",children:"Multiply By"}),e.jsx("div",{className:"flex-1",children:e.jsx(s.Input,{type:"number",placeholder:"100",value:t.multiplyBy??"",onChange:i=>o("multiplyBy",i.target.value?parseFloat(i.target.value):void 0),className:"h-8 text-xs"})})]}),l==="date"&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(s.Label,{className:"w-20 text-xs text-muted-foreground",children:"Format"}),e.jsx("div",{className:"flex-1",children:e.jsx(s.Input,{type:"text",placeholder:"MM/DD/YYYY",value:t.dateFormat||"",onChange:i=>o("dateFormat",i.target.value),className:"h-8 text-xs"})})]})]})]})}function Gs({axis:t,label:a,type:n,config:r,onChange:l}){var h,f,g,b,p,j,x,v,k,L,C,S;const o=(y,D)=>{l({...r,[y]:D})},c=(y,D)=>{var N,B;l({...r,name:{enabled:y==="enabled"?D:((N=r==null?void 0:r.name)==null?void 0:N.enabled)??!1,text:y==="text"?D:(B=r==null?void 0:r.name)==null?void 0:B.text}})},i=(y,D)=>{var N,B;l({...r,labels:{enabled:y==="enabled"?D:((N=r==null?void 0:r.labels)==null?void 0:N.enabled)??!0,rotation:y==="rotation"?D:(B=r==null?void 0:r.labels)==null?void 0:B.rotation}})},d=(y,D)=>{l({...r,scale:{...r==null?void 0:r.scale,[y]:D===""?"auto":Number(D)}})},u=t==="x"?["auto","top","bottom"]:["auto","left","right"],m=["auto","0","45","90","-45","-90"];return e.jsxs(s.AccordionItem,{value:`${t}-axis`,className:"border-b-0",children:[e.jsxs("div",{className:"flex w-full items-center justify-between gap-2",children:[e.jsx(s.AccordionTrigger,{className:"flex grow items-center justify-between gap-3 py-2 text-sm font-medium hover:no-underline",children:e.jsx("div",{className:"flex grow items-center justify-between gap-2",children:e.jsx("span",{children:a})})}),e.jsx(s.SmallSwitch,{checked:(r==null?void 0:r.enabled)!==!1,onCheckedChange:y=>o("enabled",y),onClick:y=>y.stopPropagation()})]}),e.jsxs(s.AccordionContent,{className:"space-y-4 pt-2",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(s.Label,{className:"text-xs font-medium",children:"TITLE"}),e.jsx(s.SmallSwitch,{checked:((h=r==null?void 0:r.name)==null?void 0:h.enabled)??!1,onCheckedChange:y=>c("enabled",y)})]}),((f=r==null?void 0:r.name)==null?void 0:f.enabled)&&e.jsx(ve,{placeholder:`${a} title`,value:((g=r==null?void 0:r.name)==null?void 0:g.text)||"",onSave:y=>c("text",y),className:""})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(s.Label,{className:"text-xs font-medium",children:"POSITION"}),e.jsxs(s.Select,{value:(r==null?void 0:r.position)||"auto",onValueChange:y=>o("position",y),children:[e.jsx(s.SelectTrigger,{className:"h-8 text-xs",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{children:u.map(y=>e.jsx(s.SelectItem,{value:y,className:"text-xs",children:y==="auto"?"Auto (Default)":s.titleCase(y)},y))})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(s.Label,{className:"text-xs font-medium",children:"LABELS"}),e.jsx(s.SmallSwitch,{checked:((b=r==null?void 0:r.labels)==null?void 0:b.enabled)!==!1,onCheckedChange:y=>i("enabled",y)})]}),((p=r==null?void 0:r.labels)==null?void 0:p.enabled)!==!1&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(s.Label,{className:"text-xs text-muted-foreground",children:"Rotation"}),e.jsxs(s.Select,{value:String(((j=r==null?void 0:r.labels)==null?void 0:j.rotation)||"auto"),onValueChange:y=>i("rotation",y==="auto"?"auto":Number(y)),children:[e.jsx(s.SelectTrigger,{className:"h-8 text-xs",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{children:m.map(y=>e.jsx(s.SelectItem,{value:y,className:"text-xs",children:y==="auto"?"Auto (Default)":`${y}°`},y))})]})]})]}),n==="value"&&e.jsx(Ts,{formatOptions:(r==null?void 0:r.formatOptions)||{},onFormatOptionsChange:y=>l({...r,formatOptions:y}),showTitle:!0,title:"FORMAT"}),n==="value"&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(s.Label,{className:"text-xs font-medium",children:"SCALE"}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(s.Label,{className:"w-8 text-xs text-muted-foreground",children:"Min"}),e.jsx("div",{className:"flex-1",children:e.jsx(ve,{type:"number",placeholder:"auto",value:((x=r==null?void 0:r.scale)==null?void 0:x.min)==="auto"||((v=r==null?void 0:r.scale)==null?void 0:v.min)===void 0?"":String(r.scale.min),onSave:y=>d("min",y),className:""})})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(s.Label,{className:"w-8 text-xs text-muted-foreground",children:"Max"}),e.jsx("div",{className:"flex-1",children:e.jsx(ve,{type:"number",placeholder:"auto",value:((k=r==null?void 0:r.scale)==null?void 0:k.max)==="auto"||((L=r==null?void 0:r.scale)==null?void 0:L.max)===void 0?"":String(r.scale.max),onSave:y=>d("max",y),className:""})})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(s.Label,{className:"w-8 text-xs text-muted-foreground",children:"Step"}),e.jsx("div",{className:"flex-1",children:e.jsx(ve,{type:"number",placeholder:"auto",value:((C=r==null?void 0:r.scale)==null?void 0:C.stepSize)==="auto"||((S=r==null?void 0:r.scale)==null?void 0:S.stepSize)===void 0?"":String(r.scale.stepSize),onSave:y=>d("stepSize",y),className:""})})]})]})]})]})]})}function Vt(){const t=s.useEditorStore(c=>c.card),a=s.useEditorStore(c=>{var i;return(i=c.card)==null?void 0:i.preferences}),{setCardPreferences:n,updateCardInFrame:r}=s.useEditorActions();if(!t||["tornado","pyramid","kpi"].includes(t.type))return null;const l=s.AxisConfigurator.getAxisInfo(t.type,a);if(!l.hasXAxis&&!l.hasYAxis)return null;const o=(c,i)=>{const u={...a||{},[c==="x"?"xAxisConfig":"yAxisConfig"]:i};n(u);const m={...t,preferences:u};r(m)};return e.jsxs(s.AccordionItem,{value:"axes",className:"border-b-0",children:[e.jsx(s.AccordionTrigger,{className:"flex w-full items-center gap-2 py-2 text-sm font-medium hover:no-underline",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Ya,{className:"h-4 w-4 text-muted-foreground"}),e.jsx("span",{children:"Axes"})]})}),e.jsx(s.AccordionContent,{className:"pt-2",children:e.jsxs(s.Accordion,{type:"single",collapsible:!0,className:"w-full",children:[l.hasXAxis&&e.jsx(Gs,{axis:"x",label:"X-Axis",type:l.xAxisType,config:a==null?void 0:a.xAxisConfig,onChange:c=>o("x",c)}),l.hasYAxis&&e.jsx(Gs,{axis:"y",label:"Y-Axis",type:l.yAxisType,config:a==null?void 0:a.yAxisConfig,onChange:c=>o("y",c)})]})})]})}function _t(){const t=s.useEditorStore(u=>u.card),a=s.useEditorStore(u=>{var m,h,f,g;return(g=(f=(h=(m=u.card)==null?void 0:m.preferences)==null?void 0:h.chartOptions)==null?void 0:f.plugins)==null?void 0:g.legend}),{setLegendOptions:n}=s.useEditorActions();if(!t||!s.chartSupportsLegend(t.type))return null;const r="bottom",l="center",o=!(t.type==="stackedBar"||t.type==="stackedLine"),c=(u,m)=>{const h={...a,[u]:m};n(h)},i=["top","bottom","left","right"],d=["start","center","end"];return e.jsxs(s.AccordionItem,{value:"legend",className:"border-b-0",children:[e.jsx(s.AccordionTrigger,{className:"flex w-full items-center gap-2 py-2 text-sm font-medium hover:no-underline",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Ca,{className:"h-4 w-4 text-muted-foreground"}),e.jsx("span",{children:"Legend"})]})}),e.jsx(s.AccordionContent,{className:"pt-2",children:e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(s.Label,{className:"text-xs font-medium",children:"Display"}),e.jsx(s.SmallSwitch,{checked:(a==null?void 0:a.display)??o,onCheckedChange:u=>c("display",u)})]}),((a==null?void 0:a.display)??o)&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(s.Label,{className:"text-xs font-medium",children:"Position"}),e.jsxs(s.Select,{value:(a==null?void 0:a.position)||r,onValueChange:u=>c("position",u),children:[e.jsx(s.SelectTrigger,{className:"h-8 text-xs",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{children:i.map(u=>e.jsx(s.SelectItem,{value:u,className:"text-xs",children:s.titleCase(u)},u))})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(s.Label,{className:"text-xs font-medium",children:"Alignment"}),e.jsxs(s.Select,{value:(a==null?void 0:a.align)||l,onValueChange:u=>c("align",u),children:[e.jsx(s.SelectTrigger,{className:"h-8 text-xs",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{children:d.map(u=>e.jsx(s.SelectItem,{value:u,className:"text-xs",children:s.titleCase(u)},u))})]})]})]})]})})]})}function Ut(){var D,N,B,w,F,T,E,A,O;const t=s.useEditorStore(M=>M.card),a=s.useEditorStore(M=>{var R,P;return(P=(R=M.card)==null?void 0:R.preferences)==null?void 0:P.dataLabelsConfig}),n=s.useEditorStore(M=>{var R;return(R=M.card)==null?void 0:R.preferences}),{setCardPreferences:r,updateCardInFrame:l}=s.useEditorActions();if(!t||!s.chartSupportsDataLabels(t.type))return null;const o=((D=n==null?void 0:n.chartOptions)==null?void 0:D.indexAxis)==="y",c=t.type==="stackedBar"||t.type==="stackedLine",i=t.type==="pie"||t.type==="doughnut"||t.type==="polarArea"||t.type==="funnel",d=!i,u=(B=(N=n==null?void 0:n.chartOptions)==null?void 0:N.plugins)==null?void 0:B.datalabels,m=(u==null?void 0:u.display)!==!1&&((u==null?void 0:u.anchor)||(u==null?void 0:u.align)),h=(a==null?void 0:a.enabled)!==void 0?a.enabled:m,f=(M,R)=>{const P={...a,[M]:R},K={...t.preferences||{},dataLabelsConfig:P};r(K);const Y={...t,preferences:K};l(Y)},g=(M,R)=>{const P={...a,font:{...a==null?void 0:a.font,[M]:R}},K={...t.preferences||{},dataLabelsConfig:P};r(K);const Y={...t,preferences:K};l(Y)},b=(M,R)=>{const P={...a,formatOptions:{...a==null?void 0:a.formatOptions,[M]:R}},K={...t.preferences||{},dataLabelsConfig:P};r(K);const Y={...t,preferences:K};l(Y)},j=(()=>{const M=t.type;return M==="stackedBar"||M==="stackedLine"||M==="pie"||M==="doughnut"?"center":o?"right":"top"})();let x=[];c||i?x=["center"]:x=["auto",...(o?["center","left","right"]:["center","top","bottom"]).filter(R=>R!==j),"custom"];const v=()=>s.titleCase(j),k=["center","start","end"],L=["center","start","end","top","bottom"],C=d?["auto","number","currency","percent","none"]:["number","currency","percent","none"],S=[{value:"USD",label:"USD - US Dollar"},{value:"EUR",label:"EUR - Euro"},{value:"GBP",label:"GBP - British Pound"},{value:"JPY",label:"JPY - Japanese Yen"},{value:"CNY",label:"CNY - Chinese Yuan"},{value:"INR",label:"INR - Indian Rupee"},{value:"CAD",label:"CAD - Canadian Dollar"},{value:"AUD",label:"AUD - Australian Dollar"}],y=[{value:"en-US",label:"English (US)"},{value:"en-GB",label:"English (UK)"},{value:"de-DE",label:"German"},{value:"fr-FR",label:"French"},{value:"es-ES",label:"Spanish"},{value:"it-IT",label:"Italian"},{value:"pt-BR",label:"Portuguese (Brazil)"},{value:"zh-CN",label:"Chinese (Simplified)"}];return e.jsxs(s.AccordionItem,{value:"data-labels",className:"border-b-0",children:[e.jsx(s.AccordionTrigger,{className:"flex w-full items-center gap-2 py-2 text-sm font-medium hover:no-underline",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Ga,{className:"h-4 w-4 text-muted-foreground"}),e.jsx("span",{children:"Data Labels"})]})}),e.jsx(s.AccordionContent,{className:"pt-2",children:e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(s.Label,{className:"text-xs font-medium",children:"Display"}),e.jsx(s.SmallSwitch,{checked:h,onCheckedChange:M=>f("enabled",M)})]}),h&&e.jsxs(e.Fragment,{children:[!c&&!i&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(s.Label,{className:"text-xs font-medium",children:"Position"}),e.jsxs(s.Select,{value:(a==null?void 0:a.position)||"auto",onValueChange:M=>f("position",M),children:[e.jsx(s.SelectTrigger,{className:"h-8 text-xs",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{children:x.map(M=>e.jsx(s.SelectItem,{value:M,className:"text-xs",children:M==="auto"?v():M==="custom"?"Custom (Advanced)":s.titleCase(M)},M))})]})]}),c&&e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(s.Label,{className:"text-xs font-medium",children:"Show Total"}),e.jsx(s.SmallSwitch,{checked:(a==null?void 0:a.showTotal)??!1,onCheckedChange:M=>f("showTotal",M)})]}),(a==null?void 0:a.position)==="custom"&&e.jsxs("div",{className:"space-y-2 pl-4 border-l-2 border-muted",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(s.Label,{className:"text-xs text-muted-foreground w-16",children:"Anchor"}),e.jsxs(s.Select,{value:(a==null?void 0:a.anchor)||"center",onValueChange:M=>f("anchor",M),children:[e.jsx(s.SelectTrigger,{className:"h-8 text-xs flex-1",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{children:k.map(M=>e.jsx(s.SelectItem,{value:M,className:"text-xs",children:s.titleCase(M)},M))})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(s.Label,{className:"text-xs text-muted-foreground w-16",children:"Align"}),e.jsxs(s.Select,{value:String((a==null?void 0:a.align)||"center"),onValueChange:M=>f("align",M),children:[e.jsx(s.SelectTrigger,{className:"h-8 text-xs flex-1",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{children:L.map(M=>e.jsx(s.SelectItem,{value:M,className:"text-xs",children:s.titleCase(M)},M))})]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(s.Label,{className:"text-xs font-medium",children:"Format"}),e.jsxs(s.Select,{value:(a==null?void 0:a.format)||(d?"auto":"none"),onValueChange:M=>f("format",M),children:[e.jsx(s.SelectTrigger,{className:"h-8 text-xs",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{children:C.map(M=>e.jsx(s.SelectItem,{value:M,className:"text-xs",children:M==="auto"&&d?"Auto (Use Axis)":M==="none"?"None (Raw Value)":s.titleCase(M)},M))})]})]}),(a==null?void 0:a.format)&&!["auto","none"].includes(a.format)&&e.jsxs("div",{className:"space-y-2 pl-4 border-l-2 border-muted",children:[["number","currency","percent"].includes(a.format)&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(s.Label,{className:"text-xs text-muted-foreground w-20",children:"Decimals"}),e.jsx("div",{className:"flex-1",children:e.jsx(ve,{type:"number",placeholder:"0",value:String(((w=a==null?void 0:a.formatOptions)==null?void 0:w.decimalPlaces)??(a.format==="currency"?2:a.format==="percent"?1:0)),onSave:M=>b("decimalPlaces",Number(M)),className:""})})]}),a.format==="currency"&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(s.Label,{className:"text-xs text-muted-foreground w-20",children:"Currency"}),e.jsxs(s.Select,{value:((F=a==null?void 0:a.formatOptions)==null?void 0:F.currency)||"USD",onValueChange:M=>b("currency",M),children:[e.jsx(s.SelectTrigger,{className:"h-8 text-xs flex-1",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{children:S.map(M=>e.jsx(s.SelectItem,{value:M.value,className:"text-xs",children:M.label},M.value))})]})]}),["number","currency"].includes(a.format)&&e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(s.Label,{className:"text-xs text-muted-foreground",children:"Abbreviate (K, M, B)"}),e.jsx(s.SmallSwitch,{checked:((T=a==null?void 0:a.formatOptions)==null?void 0:T.useSuffix)??!1,onCheckedChange:M=>b("useSuffix",M)})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(s.Label,{className:"text-xs text-muted-foreground w-20",children:"Locale"}),e.jsxs(s.Select,{value:((E=a==null?void 0:a.formatOptions)==null?void 0:E.locale)||"en-US",onValueChange:M=>b("locale",M),children:[e.jsx(s.SelectTrigger,{className:"h-8 text-xs flex-1",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{children:y.map(M=>e.jsx(s.SelectItem,{value:M.value,className:"text-xs",children:M.label},M.value))})]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(s.Label,{className:"text-xs font-medium",children:"Appearance"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(s.Label,{className:"text-xs text-muted-foreground w-20",children:"Size"}),e.jsx("div",{className:"flex-1",children:e.jsx(ve,{type:"number",placeholder:"12",value:String(((A=a==null?void 0:a.font)==null?void 0:A.size)||12),onSave:M=>g("size",Number(M)),className:""})})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(s.Label,{className:"text-xs text-muted-foreground w-20",children:"Weight"}),e.jsxs(s.Select,{value:((O=a==null?void 0:a.font)==null?void 0:O.weight)||"normal",onValueChange:M=>g("weight",M),children:[e.jsx(s.SelectTrigger,{className:"h-8 text-xs flex-1",children:e.jsx(s.SelectValue,{})}),e.jsxs(s.SelectContent,{children:[e.jsx(s.SelectItem,{value:"normal",className:"text-xs",children:"Normal"}),e.jsx(s.SelectItem,{value:"bold",className:"text-xs",children:"Bold"})]})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(s.Label,{className:"text-xs text-muted-foreground w-20",children:"Color"}),e.jsxs(s.Select,{value:(a==null?void 0:a.color)==="auto"||!(a!=null&&a.color)?"auto":"custom",onValueChange:M=>{M==="auto"&&f("color","auto")},children:[e.jsx(s.SelectTrigger,{className:"h-8 text-xs flex-1",children:e.jsx(s.SelectValue,{})}),e.jsxs(s.SelectContent,{children:[e.jsx(s.SelectItem,{value:"auto",className:"text-xs",children:"Auto (Smart Contrast)"}),e.jsx(s.SelectItem,{value:"custom",disabled:!0,className:"text-xs",children:"Custom (Coming Soon)"})]})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(s.Label,{className:"text-xs text-muted-foreground w-20",children:"Rotation"}),e.jsx("div",{className:"flex-1",children:e.jsx(ve,{type:"number",placeholder:"0",value:String((a==null?void 0:a.rotation)||0),onSave:M=>f("rotation",Number(M)),className:""})}),e.jsx("span",{className:"text-xs text-muted-foreground",children:"degrees"})]})]})]})]})})]})}function Mr(){return e.jsxs("div",{className:"space-y-4 px-6 py-4",children:[e.jsx("h3",{className:"text-sm font-medium",children:"Chart Configuration"}),e.jsxs(s.Accordion,{type:"single",collapsible:!0,className:"w-full px-2",children:[e.jsx(zt,{}),e.jsx(Vt,{}),e.jsx(_t,{}),e.jsx(Ut,{})]})]})}const Lr=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/docs/charts/tornado",children:"example"})," in the docs."]})]}),Rr=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/docs/charts/range",children:"example"})," in the docs."]})]}),Or=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/docs/charts/text",children:"example"})," in the docs."]})]});function Br(){const t=s.useEditorStore(n=>n.card.type);function a(n){const r=["kpi","table","text","map","custom"],l=o=>r.includes(n)?o:e.jsxs(e.Fragment,{children:[o,e.jsx(Mr,{})]});switch(n){case"stackedBar":case"stackedLine":return l(e.jsx(Cr,{}));case"tornado":case"pyramid":return l(e.jsx(Qe,{docContent:Lr,cardType:n}));case"kpi":return e.jsx(gr,{});case"line":case"bar":return l(e.jsx(cr,{cardType:n}));case"range":return l(e.jsx(Qe,{docContent:Rr,cardType:n}));case"pie":case"doughnut":case"polarArea":case"radar":case"funnel":return l(e.jsx(Qe,{cardType:n}));case"bubble":case"scatter":return l(e.jsx(dr,{cardType:n}));case"table":return e.jsx(Sr,{cardType:n});case"text":return e.jsx(Qe,{docContent:Or,cardType:n,suffix:"Visual"});case"map":return e.jsx(vr,{});case"custom":return e.jsx(rr,{});default:return l(e.jsx(hr,{}))}}return e.jsxs(s.ScrollArea,{className:"h-full w-full text-sm",children:[a(t),e.jsx(s.ScrollBar,{orientation:"horizontal"})]})}function Yt({label:t,column:a,functions:n,onFunctionChange:r}){let l=n[0];"aggregate"in a?l=n.find(c=>c.value===a.aggregate)||n[0]:"granularity"in a&&(l=n.find(c=>c.value===a.granularity)||n[0]);function o(c){r(c)}return e.jsx(fe,{className:"flex h-8 w-8 justify-center overflow-clip rounded-none border-none bg-muted px-0 [&>svg]:hidden",icon:l.logo,options:n,value:l.value,onValueChange:c=>o(c),label:t,showPlaceholderLabel:!1})}const Fr=[{label:"Sum",value:"SUM",logo:e.jsx(tt,{className:"size-3.5"})},{label:"Count",value:"COUNT",logo:e.jsx(Ne,{className:"size-3.5"})},{label:"Unique",value:"DISTINCT",logo:e.jsx(ba,{className:"size-3.5"})},{label:"Average",value:"AVG",logo:e.jsx(na,{className:"size-3.5"})},{label:"Min",value:"MIN",logo:e.jsx(s.ArrowDown,{className:"size-3.5"})},{label:"Max",value:"MAX",logo:e.jsx(s.ArrowUp,{className:"size-3.5"})}];function Pr({column:t}){const{updateMetricColumnOld:a}=s.useEditorActions();let n=Fr;s.isTextDataType(t.type)&&(n=n.filter(l=>["COUNT","DISTINCT"].includes(l.value))),s.isNumberDataType(t.type)&&(n=n.filter(l=>!["DISTINCT"].includes(l.value)));function r(l){const o={...t,aggregate:l,label:$e(t.name,l)};a(t.id,o)}return e.jsx(Yt,{column:t,functions:n,onFunctionChange:l=>r(l),label:"Aggregation"})}const zr=[{label:"Day (D)",value:"day",logo:e.jsx(s.Label,{className:"cursor-pointer text-xs",children:"D"})},{label:"Week (W)",value:"week",logo:e.jsx(s.Label,{className:"cursor-pointer text-xs",children:"W"})},{label:"Month (M)",value:"month",logo:e.jsx(s.Label,{className:"cursor-pointer text-xs",children:"M"})},{label:"Year (Y)",value:"year",logo:e.jsx(s.Label,{className:"cursor-pointer text-xs",children:"Y"})}];function Vr({column:t}){const{updateGroupByColumnOld:a}=s.useEditorActions();function n(r){const l={...t,granularity:r,label:Fe(t.name,r)};a(t.id,l)}return e.jsx(Yt,{column:t,functions:zr,onFunctionChange:r=>n(r),label:"Granularity"})}function _r({col:t,onChange:a,droppableId:n}){const{columns:r}=s.useDataColumns(),l=I.useMemo(()=>{let i=[];(n===Ee||n===Ie||n===Ae)&&(i=r);const d=i==null?void 0:i.filter(u=>u.column_name!==t.name);return d==null?void 0:d.map(u=>({id:u.column_name,value:u.column_name}))},[r,n,t.name]),o=[{id:t.name,value:t.name}];function c(i){const d=r==null?void 0:r.find(u=>{var m;return u.column_name===((m=i[0])==null?void 0:m.id)});d&&a(d)}return l!=null&&l.length?e.jsx(s.ComboBox2,{multiple:!1,options:l,selectedOptions:o,onChange:c,selectAllChecked:!1,onSelectAllCheckedChange:()=>{},inputClassName:"border-none bg-muted pl-0 pr-8"}):e.jsx("input",{disabled:!0,type:"text",className:"overflow-hidden truncate text-ellipsis whitespace-nowrap bg-muted text-sm",value:t.name})}function $t({column:t}){const a=s.useEditorStore(d=>d.card.type),n=s.useEditorStore(d=>{var u,m;return(m=(u=d.card)==null?void 0:u.config)==null?void 0:m.metricColumns}),r=(n==null?void 0:n.map(d=>d.label))||[],l=r==null?void 0:r.find(d=>d===t.label||d===t.name),o=l?r.indexOf(l):-1;function c(){return e.jsx("div",{className:"pr-1",children:l&&e.jsx(Bt,{idx:o,col:l,children:e.jsx("div",{className:"w-[130px] text-xs text-muted-foreground",children:"Display Series As"})})})}function i(){return e.jsxs("div",{className:"space-y-1",children:[e.jsx(s.Label,{className:"text-xs font-medium text-muted-foreground",children:"Data Labels"}),e.jsx(Ft,{})]})}return e.jsxs("div",{className:"space-y-1",children:[["stackedBar","stackedLine","bar","line"].includes(a)&&c(),["pie","doughnut"].includes(a)&&i()]})}function Ur({column:t,type:a,onRemoveColumn:n,droppableId:r}){const[l,o]=I.useState(!1),{updateGroupByColumnOld:c,updateMetricColumnOld:i,updatePivotByColumnOld:d}=s.useEditorActions(),{attributes:u,listeners:m,setNodeRef:h,transform:f,transition:g,isDragging:b}=s.useSortable({id:t.id,data:{type:a}}),p=f?{opacity:b?.5:void 0,transform:s.CSS.Translate.toString(f),transition:g}:void 0,j=s.isTextDataType(t.type);function x(S){const y=s.isNumberDataType(S.data_type),D=s.isTextDataType(S.data_type),N=s.isDateDataType(S.data_type),B=y?"number":D?"string":N?"date":"string";if(r===Ee){if(D){const w={id:t.id,name:S.column_name,type:B,role:"groupby"};c(t.id,w)}if(N){const w={id:t.id,name:S.column_name,type:B,role:"groupby",label:Fe(S.column_name,"month"),granularity:"month"};c(t.id,w)}}if(r===Ae){if(D){const w={id:t.id,name:S.column_name,type:B,role:"groupby"};d(t.id,w)}if(N){const w={id:t.id,name:S.column_name,type:B,label:Fe(S.column_name,"month"),granularity:"month",role:"groupby"};d(t.id,w)}}if(r===Ie){const w={id:t.id,name:S.column_name,type:B,role:"metric",label:$e(S.column_name,"SUM"),aggregate:y?"SUM":"COUNT"};i(t.id,w)}}function v(){if(r===Ie)return e.jsx("div",{"data-setting-container":"",className:"mt-1.5 max-h-32 overflow-y-auto rounded-md border border-border p-3 text-sm",children:e.jsx($t,{column:t})})}function k(){const S=s.isDateDataType(t.type);if(r===Ie)return e.jsx(Pr,{column:t});if((r===Ee||r===Ae)&&S)return e.jsx(Vr,{column:t})}function L(){return e.jsx("div",{className:s.cn("grow",{"pl-3":(r===Ee||r===Ae)&&j}),children:e.jsx(_r,{col:t,onChange:x,droppableId:r})})}function C(){return e.jsx("div",{"data-setting-actions":"",className:"flex h-full items-center gap-2",children:e.jsx("button",{className:"h-full pl-2",onClick:()=>o(!l),children:l?e.jsx(Ua,{className:s.cn("size-3 cursor-pointer items-center justify-center rounded-r-sm text-muted-foreground")}):e.jsx(et,{className:s.cn("size-3 cursor-pointer items-center justify-center rounded-r-sm text-muted-foreground")})})})}return e.jsx("div",{...m,...u,ref:h,style:p,children:e.jsxs("div",{className:"group flex items-center justify-between gap-2",children:[e.jsxs("div",{className:"grow",children:[e.jsxs("div",{className:"flex h-8 grow items-center justify-between rounded-md bg-muted",children:[C(),k(),L()]}),l&&v()]}),e.jsx("div",{className:s.cn("opacity-0 transition-opacity duration-200 group-hover:opacity-100",{hidden:l}),children:e.jsx("button",{onClick:()=>n(t.id),children:e.jsx(s.X,{className:"size-3 cursor-pointer text-muted-foreground"})})})]})})}function ps({id:t,label:a,columns:n,previewColumns:r,sortableType:l,onRemoveColumn:o}){var p,j;const{setNodeRef:c,isOver:i,over:d}=s.useDroppable({id:t}),u=s.useDndStore(x=>x.activeId),m=s.useEditorStore(x=>{var v;return(v=x.card)==null?void 0:v.type}),h=i||((j=(p=d==null?void 0:d.data)==null?void 0:p.current)==null?void 0:j.type)===l,f=u?r:n,g=l===ts?"Rows":l===as?"Pivot Columns":"Columns";function b(){if(!f||f.length===0)return e.jsx("div",{className:"mr-5 flex h-8 grow items-center space-x-2 rounded-md border border-dashed border-muted-foreground/80 bg-background px-2 py-1 text-sm text-muted-foreground",children:e.jsx("span",{className:"invisible text-muted-foreground/70 group-hover:visible",children:"Drag here"})})}return e.jsx(s.SortableContext,{items:n==null?void 0:n.map(x=>x.id),children:e.jsxs("div",{className:s.cn("group space-y-2 rounded-md p-4",h&&"border border-muted-foreground/20"),ref:c,children:[e.jsxs("div",{className:"flex items-center justify-between pr-5",children:[e.jsx(s.Label,{className:"text-sm",children:a}),m!=="table"&&e.jsx("span",{className:"text-xs text-muted-foreground/50",children:g})]}),b(),e.jsx("div",{className:"space-y-2",children:f==null?void 0:f.map(x=>x.id===vt.id?e.jsx(Yr,{},x.id):e.jsx(Ur,{droppableId:t,type:l,column:x,onRemoveColumn:o},x.id))})]})})}function Yr(){return e.jsx("div",{className:"mr-5 flex h-8 grow items-center space-x-2 rounded-md border border-dashed border-muted-foreground bg-background px-2 py-1 text-sm",children:e.jsx("span",{className:"text-muted-foreground/70",children:"Drop here"})})}function qt({children:t,id:a,type:n}){const{attributes:r,listeners:l,setNodeRef:o,transform:c,transition:i,isDragging:d}=s.useSortable({id:a,data:{type:n}}),u=c?{opacity:d?.5:void 0,transform:s.CSS.Translate.toString(c),transition:i}:void 0;return e.jsx("div",{...l,...r,ref:o,style:u,children:t})}function $r(){const t=s.useEditorStore(x=>{var v;return(v=x.card.queryConfig)==null?void 0:v.orderBy})||[],a=s.useEditorStore(x=>{var v;return(v=x.card.queryConfig)==null?void 0:v.groupByColumns})||[],n=s.useEditorStore(x=>{var v;return(v=x.card.queryConfig)==null?void 0:v.metricColumns})||[],{addOrderByColumn:r,removeOrderByColumn:l,updateOrderByColumn:o}=s.useEditorActions(),c=[...a,...n];if(c.length===0)return e.jsx(e.Fragment,{});const i=e.jsx(la,{className:"size-3.5 text-muted-foreground hover:text-foreground"}),d=e.jsx(aa,{className:"size-3.5 text-muted-foreground hover:text-foreground"}),u=e.jsx(ra,{className:"size-3.5 text-muted-foreground hover:text-foreground"}),m=e.jsx(ta,{className:"size-3.5 text-muted-foreground hover:text-foreground"}),h=c==null?void 0:c.filter(x=>!t.some(v=>v.columnId===x.id)).map(x=>({id:x.id,value:x.label||x.name}));function f(x,v){const k=g(x);return k?k.role==="metric"?v==="asc"?u:m:v==="asc"?i:d:null}function g(x){return c.find(v=>v.id===x)}function b(x){const v=t.find(k=>k.columnId===x);if(v){const k={...v,direction:v.direction==="asc"?"desc":"asc"};o(k)}}const p=x=>{r({columnId:x.id,direction:"asc"})};function j(x){const v=t.find(k=>k.columnId===x);v&&l(v)}return e.jsx(s.SortableContext,{items:t.map(x=>Ve(x.columnId)),children:e.jsxs("div",{className:"space-y-2 rounded-md p-4 text-sm",children:[e.jsx(s.Label,{className:"text-sm",children:"Sort By"}),h.length>0&&e.jsx("div",{className:"mr-5",children:e.jsx(s.ComboBox2,{multiple:!1,options:h,selectedOptions:[],onChange:x=>p(x[0]),selectAllChecked:!1,onSelectAllCheckedChange:()=>{},inputClassName:"h-8 bg-muted border-none"})}),t.map(x=>{var v,k;return e.jsx(qt,{id:Ve(x.columnId),type:Ss,children:e.jsx("div",{className:"group flex h-8 items-center gap-2 rounded-sm p-0",children:e.jsxs("div",{className:"flex h-full grow items-center justify-between gap-2",children:[e.jsxs("div",{className:"flex h-full grow items-center justify-between gap-2 rounded-sm bg-muted px-2",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(et,{className:"size-3 cursor-move text-muted-foreground hover:text-foreground"}),e.jsx(os,{className:"w-[175px] text-sm",children:((v=g(x.columnId))==null?void 0:v.label)||((k=g(x.columnId))==null?void 0:k.name)})]}),e.jsx("button",{title:x.direction==="asc"?"Ascending":"Descending",onClick:()=>b(x.columnId),className:"rounded-sm p-0",children:f(x.columnId,x.direction)})]}),e.jsx("div",{children:e.jsx("button",{onClick:()=>j(x.columnId),className:"rounded-sm p-0",children:e.jsx(s.X,{className:"size-3 text-muted-foreground opacity-0 transition-opacity duration-200 hover:text-foreground group-hover:opacity-100"})})})]})},x.columnId)},Ve(x.columnId))})]})})}function qr(){const t=s.useEditorStore(j=>{var x;return((x=j.card.queryConfig)==null?void 0:x.groupByColumns)||[]}),a=s.useEditorStore(j=>j.card.type),n=s.useDndStore(j=>j.previewGroupByColumns),r=s.useEditorStore(j=>{var x;return((x=j.card.queryConfig)==null?void 0:x.metricColumns)||[]}),l=s.useDndStore(j=>j.previewMetricColumns),o=s.useEditorStore(j=>{var x;return((x=j.card.queryConfig)==null?void 0:x.pivotColumns)||[]}),c=s.useDndStore(j=>j.previewPivotColumns),{removeColumnFromGroupBy:i,removeColumnFromMetricColumns:d,removeColumnFromPivotBy:u}=s.useEditorActions();function m(j){i(j)}function h(j){d(j)}function f(j){u(j)}let g="Group By",b="Metrics",p="Stack By";return a==="table"&&(g="Rows",b="Metrics",p="Columns"),e.jsxs("div",{className:"flex h-full w-full flex-col gap-3 py-4",children:[e.jsx(It,{iconClassName:"size-[19px]"}),e.jsxs(s.CustomScrollArea,{className:"flex min-h-0 grow basis-0 flex-col gap-4 overflow-y-auto",children:[e.jsxs("div",{className:"flex flex-col gap-4 p-4",children:[e.jsx(ps,{onRemoveColumn:m,sortableType:ts,id:Ee,label:g,columns:t,previewColumns:n}),e.jsx(ps,{onRemoveColumn:f,sortableType:as,id:Ae,label:p,columns:o,previewColumns:c}),e.jsx(ps,{onRemoveColumn:h,sortableType:bs,id:Ie,label:b,columns:r,previewColumns:l}),e.jsx($r,{})]}),e.jsx(s.ScrollBar,{orientation:"horizontal"})]})]})}function Es({children:t,column:a,id:n,sortableType:r,className:l}){const[o,c]=I.useState(!1),{removeEditorFilter:i,clearEditorFilter:d}=s.useEditorActions(),u=s.useEditorStore(h=>{var f,g;return(g=(f=h.card.queryConfig)==null?void 0:f.filters)==null?void 0:g.some(b=>b.filterColumnName===a.name)});function m(h){i(h)}return e.jsx(qt,{id:n,type:r,children:e.jsxs("div",{className:s.cn("group space-y-1 rounded-md bg-muted px-3 py-2",{"border-border":o}),children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(s.Label,{className:"text-sm",children:a.name}),u&&e.jsx("button",{onClick:()=>d(a),children:e.jsx(s.FilterX,{className:"size-3 cursor-pointer items-center justify-center text-muted-foreground hover:text-foreground"})})]}),e.jsx("div",{"data-setting-actions":"",className:"invisible flex h-full items-center gap-2 group-hover:visible",children:e.jsx("button",{onClick:()=>m(a),children:e.jsx(s.X,{className:"size-3.5 cursor-pointer items-center justify-center rounded-r-sm text-muted-foreground"})})})]}),e.jsxs("div",{className:s.cn("group flex items-center rounded-t-md text-sm",!o&&"rounded-b-md",o&&"border border-border"),children:[e.jsx("div",{children:e.jsx(s.GripVertical,{className:"mr-2 size-3.5 cursor-move items-center justify-center p-0 text-muted-foreground/60 hover:text-foreground"})}),e.jsx("div",{className:s.cn("grow cursor-pointer overflow-hidden truncate text-ellipsis whitespace-nowrap",l),children:t})]})]})})}function Gr({column:t,sortableType:a}){const n=s.useDashboardStore(k=>k.themeStyle),r=s.useEditorStore(k=>{var L,C;return(C=(L=k.card)==null?void 0:L.queryConfig)==null?void 0:C.filters}),l=s.useEditorStore(k=>{var L,C;return(C=(L=k.card.queryConfig)==null?void 0:L.filterColumns)==null?void 0:C.find(S=>S.name===t.name)}),{selectedConnectionId:o,selectedDatabaseName:c,selectedTableName:i}=s.useEditorAside(),d=I.useMemo(()=>{var k;return(k=r==null?void 0:r.find(L=>L.filterColumnName===t.name))==null?void 0:k.filterValue},[r,t.name]),u=I.useMemo(()=>Array.isArray(d)?d.map(k=>({id:k,value:k})):[],[d]),{updateEditorFilterValue:m}=s.useEditorActions(),h={column:t.name,sql:t.sql,id:t.name,connectionId:o,dataType:t.type},{data:f,isLoading:g,isFetching:b,isError:p}=s.useFilterQuery(h),j=I.useMemo(()=>{var L;return h.column?(L=f==null?void 0:f.records)==null?void 0:L.map(C=>{let S=h.column.split(".").slice(-1)[0].replace(/"/g,"");return C[S]===void 0&&(S=S.toLowerCase()),{id:C[S],value:C[S]}}):[]},[f,h.column]);function x(k){const L=k.map(C=>C.id);m(t.name,L)}function v(){return g||b?e.jsx(s.Skeleton,{style:{borderRadius:n==null?void 0:n.controlInputRadius},className:"h-8 min-w-60 bg-foreground/10"}):p?e.jsx("div",{className:"flex h-8 min-w-60 items-center bg-muted px-2 text-sm",children:"Error"}):e.jsx(s.ComboBox2,{renderFilterModeButton:()=>e.jsx(Hr,{columnName:t.name}),showNegativeIndicator:(l==null?void 0:l.mode)==="exclude",options:j,onChange:x,selectedOptions:u,selectAllChecked:!1,onSelectAllCheckedChange:()=>{}})}return e.jsx(Es,{className:"w-60",id:t.id,sortableType:a,column:t,children:v()})}function Hr({columnName:t}){const{setEditorFilterMode:a}=s.useEditorActions(),n=s.useEditorStore(l=>{var o,c;return(c=(o=l.card.queryConfig)==null?void 0:o.filterColumns)==null?void 0:c.find(i=>i.name===t)});function r(){(n==null?void 0:n.mode)==="exclude"?a(t,"include"):a(t,"exclude")}return e.jsx(s.Button,{onClick:r,variant:"secondary",size:"sm",className:s.cn("h-5 text-xs hover:underline",{}),children:s.titleCase((n==null?void 0:n.mode)==="exclude"?"exclude":"include")})}function Wr({open:t,setOpen:a,dateRange:n,setDateRange:r,containerClassName:l,inputClassName:o,title:c,onApply:i,onClear:d}){const u=s.useDashboardStore(m=>m.themeStyle);return e.jsx("div",{className:s.cn("grid gap-2",l),children:e.jsxs(s.Popover,{open:t,onOpenChange:a,children:[e.jsx(s.PopoverTrigger,{style:{borderRadius:u==null?void 0:u.controlInputRadius},asChild:!0,children:e.jsxs(s.Button,{size:"sm",id:"date",variant:"outline",className:s.cn("h-9 w-full justify-start rounded-sm text-left font-normal",!n&&"text-muted-foreground",o),children:[e.jsx(s.Calendar,{className:"mr-2 h-4 w-4"}),n!=null&&n.from?n.to?e.jsxs(e.Fragment,{children:[s.format(n.from,"LLL dd, y")," -"," ",s.format(n.to,"LLL dd, y")]}):s.format(n.from,"LLL dd, y"):e.jsx("span",{children:"Pick a date"})]})}),e.jsxs(s.PopoverContent,{style:{borderRadius:u==null?void 0:u.controlInputRadius},className:"w-auto p-0",align:"start",children:[e.jsx("div",{className:"px-4 pt-3",children:e.jsx(s.Label,{children:c})}),e.jsx(s.Calendar$1,{initialFocus:!0,mode:"range",defaultMonth:n==null?void 0:n.from,selected:n,onSelect:r,numberOfMonths:2}),e.jsxs("div",{className:"flex justify-end gap-2 px-4 py-3",children:[e.jsx(s.Button,{style:{borderRadius:u==null?void 0:u.controlInputRadius},size:"sm",variant:"outline",onClick:m=>{m.stopPropagation(),i(n),a(!1)},children:"Apply"}),e.jsx(s.Button,{style:{borderRadius:u==null?void 0:u.controlInputRadius},size:"sm",variant:"outline",onClick:d,children:"Clear"})]})]})]})})}function Kr({column:t,sortableType:a}){const[n,r]=I.useState(!1),{selectedConnectionId:l,selectedDatabaseName:o,selectedTableName:c}=s.useEditorAside(),i={column:t.name,sql:t.sql,id:t.name,connectionId:l,title:"",dataType:t.type},{isLoading:d,isFetching:u,isError:m,data:h}=s.useFilterQuery(i),f=h==null?void 0:h.records,{dateRange:g,setDateRange:b,initialDateRange:p}=s.useDateRangeFromRecords(f),{updateEditorFilterValue:j}=s.useEditorActions();function x(L){var S,y;const C={gte:(S=L==null?void 0:L.from)==null?void 0:S.toISOString(),lte:(y=L==null?void 0:L.to)==null?void 0:y.toISOString()};j(t.name,C)}function v(){j(t.name,null,!0),b(p)}function k(){return d||u?e.jsx("div",{children:e.jsx(s.Skeleton,{className:"h-8 w-72 bg-foreground/10"})}):m?e.jsx("div",{className:"h-8 w-72 bg-muted px-2",children:"Error"}):f?e.jsx(Wr,{title:i.title,open:n,inputClassName:"h-8",setOpen:r,dateRange:g,setDateRange:b,onApply:x,onClear:v}):e.jsx(s.Label,{className:"flex h-8 w-72 items-center bg-muted px-2",children:"No Data"})}return e.jsx(Es,{className:"w-72",id:t.id,sortableType:a,column:t,children:k()})}function Jr({id:t,label:a,columns:n,previewColumns:r,sortableType:l}){var b,p;const{setNodeRef:o,isOver:c,over:i}=s.useDroppable({id:t}),d=s.useDndStore(j=>j.activeId),u={},m=c||((p=(b=i==null?void 0:i.data)==null?void 0:b.current)==null?void 0:p.type)===l;function h(){if(!g||g.length===0)return e.jsx("div",{className:"flex h-8 grow items-center space-x-2 rounded-md border border-dashed border-muted-foreground/80 bg-background px-2 py-1 text-sm text-muted-foreground",children:e.jsx("span",{className:"invisible text-muted-foreground/70 group-hover:visible",children:"Drag here"})})}function f(j){const x=s.isDateDataType(j.type);return j.id===vt.id?e.jsx(Es,{id:j.id,sortableType:l,column:j,children:e.jsx(Qr,{})},j.id):x?e.jsx(Kr,{droppableId:t,sortableType:l,column:j},j.id):e.jsx(Gr,{droppableId:t,sortableType:l,column:j},j.id)}const g=d?r:n;return e.jsx(s.SortableContext,{items:n==null?void 0:n.map(j=>j.id),children:e.jsxs("div",{className:s.cn("group space-y-2 rounded-md border-muted-foreground/50 p-4",m&&"border border-muted-foreground/20"),ref:o,style:u,children:[e.jsx(s.Label,{className:"text-sm",children:a}),h(),e.jsx("div",{className:"flex flex-wrap items-center gap-4",children:g==null?void 0:g.map(j=>f(j))})]})})}function Qr(){return e.jsx("div",{className:"flex h-8 w-60 items-center space-x-2 rounded-md border border-dashed border-muted-foreground bg-background px-2 py-1 text-sm text-muted-foreground",children:"Drop here"})}function Xr(){const t=s.useEditorStore(l=>{var o;return((o=l.card.queryConfig)==null?void 0:o.filterColumns)||[]}),a=s.useDndStore(l=>l.previewFilterColumns),{removeColumnFromFilterColumns:n}=s.useEditorActions();function r(l){n(l)}return e.jsx("section",{className:"size-full px-4 pb-4",children:e.jsx(Jr,{onRemoveColumn:r,sortableType:vs,id:ys,label:"Filters",columns:t,previewColumns:a})})}function Zr(){const t=s.useEditorStore(c=>c.card),a=s.useEditorStore(c=>c.showAIDialog),{setShowAIDialog:n}=s.useEditorActions(),{data:r,errorMessage:l,errorSql:o}=s.useDashboardCardQuery(t);return e.jsxs("section",{className:"flex justify-between gap-2 p-4",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(rs,{}),!a&&e.jsxs(s.Button,{onClick:()=>n(!0),variant:"secondary",size:"sm",children:[e.jsx(Ma,{className:"mr-2 h-4 w-4"}),"Assistant"]}),e.jsx(wt,{sql:r==null?void 0:r.sql,error:l,errorSql:o})]}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"rounded-full bg-green-300 px-3 py-1 text-xs font-medium text-black",children:"Preview"}),e.jsx(Ds,{}),e.jsx(ws,{variant:"default"})]})]})}function el(){const t=I.useRef(null),a=I.useRef(null),n=s.useEditorStore(i=>i.isShowingVisual),r=s.useEditorStore(i=>i.showAIDialog),l=s.useEditorStore(i=>i.isDevMode);I.useEffect(()=>{var i,d,u,m;r?((i=t.current)==null||i.resize(0),(d=a.current)==null||d.resize(0)):((u=t.current)==null||u.resize(25),(m=a.current)==null||m.resize(25))},[r]);function o(){return e.jsxs(e.Fragment,{children:[e.jsx(s.ResizablePanel,{role:"query-section",className:"flex",minSize:20,defaultSize:40,children:e.jsx(Yn,{})}),e.jsx(s.ResizableHandle,{withHandle:!0}),e.jsx(s.ResizablePanel,{className:"pb-1",role:"visual-section",minSize:0,defaultSize:60,children:n&&!r?e.jsxs(s.ResizablePanelGroup,{direction:"horizontal",children:[e.jsx(e.Fragment,{children:e.jsx(s.ResizablePanel,{ref:t,className:"flex",defaultSize:25,maxSize:30,children:e.jsx(Br,{})})}),!r&&e.jsx(s.ResizableHandle,{}),e.jsx(s.ResizablePanel,{minSize:40,defaultSize:75,maxSize:100,children:e.jsx(Je,{})})]}):e.jsx(Je,{})})]})}function c(){return e.jsx(e.Fragment,{children:e.jsx("div",{className:"grow","data-biz-mode-container":"",children:n?e.jsxs(s.ResizablePanelGroup,{direction:"horizontal",children:[e.jsx(e.Fragment,{children:e.jsx(s.ResizablePanel,{ref:a,defaultSize:25,maxSize:30,children:e.jsx(qr,{})})}),e.jsx(s.ResizableHandle,{}),e.jsx(s.ResizablePanel,{defaultSize:75,maxSize:100,children:e.jsxs(s.ResizablePanelGroup,{direction:"vertical",children:[e.jsxs(s.ResizablePanel,{className:"flex min-h-fit flex-col",minSize:10,defaultSize:20,children:[e.jsx(Zr,{}),e.jsx(Xr,{})]}),e.jsx(s.ResizableHandle,{}),e.jsx(s.ResizablePanel,{minSize:60,defaultSize:80,children:e.jsx(Je,{})})]})})]}):e.jsx(Je,{})})})}return e.jsx(s.ResizablePanelGroup,{direction:"vertical",className:"min-h-[250px] min-w-full max-w-lg",children:l?o():c()})}function sl(t){s.useAIInteractionStore(V=>V.currentAIContext);const[a,n]=I.useState(""),[r,l]=I.useState(null),{authToken:o}=s.useSemaphorContext(),c=s.useEditorStore(V=>{var se;return(se=V==null?void 0:V.card)==null?void 0:se.sql}),i=s.useEditorStore(V=>V.isDevMode),d=s.useEditorStore(V=>{var se;return(se=V==null?void 0:V.card)==null?void 0:se.python}),{setCardPython:u,setCardSql:m,setRunSql:h,switchCardType:f,setQueryConfig:g}=s.useEditorActions(),b=s.useEditorStore(V=>V.currentAssitantScope)||[],p=s.useEditorStore(V=>V.userInputForAI),j=s.useEditorStore(V=>V.triggerAIRun),x=s.useEditorStore(V=>V.card),v=s.useEditorStore(V=>V.selectedDatabaseName),k=s.useEditorStore(V=>V.selectedTableName),L=s.useEditorStore(V=>V.selectedConnectionId),C=s.useEditorStore(V=>V.selectedSchemaName),S=s.useDashboardStore(V=>V.dashboard.aiScopeTables),{errorMessage:y,refetch:D,data:N}=s.useDashboardCardQuery(x),{setTriggerAIRun:B,setCurrentAssitantScope:w,setCardConfig:F}=s.useEditorActions(),{selectedDatamodelName:T,connectionType:E,selectedDatamodelId:A}=s.useEditorAside(),{messages:O,setMessages:M,regenerate:R,error:P,sendMessage:K,status:Y,addToolResult:te,stop:X,clearError:q}=s.useChat({transport:new s.DefaultChatTransport({api:"https://semaphor.cloud/api/v1/assistant",headers:()=>({Authorization:`Bearer ${o==null?void 0:o.accessToken}`}),body:()=>{const V=s.useAIInteractionStore.getState();return{random:Math.random(),assistantId:"editor-assistant",isDevMode:i,aiContext:V.currentAIContext,reasoningEffort:V.reasoningEffort,showReasoning:V.showReasoning}},credentials:"omit",prepareSendMessagesRequest:({messages:V,body:se})=>({body:{...se,messages:s.cleanupIncompleteMessages(V)}})}),onError:V=>{console.log("on error",V)},onToolCall:H,onFinish(){n("")}});I.useEffect(()=>{j&&p&&(K({role:"user",parts:[{type:"text",text:p}]}),B(!1))},[j,p,K,B]);async function H({toolCall:V}){var se,ne,$,W,re,ie,he,Q,oe,ee,ae,ue,je,Ge,He,We;if(["createChartFromSql","createForecast"].includes(V.toolName)){const ze=((se=V.input)==null?void 0:se.sql)??((ne=V.args)==null?void 0:ne.sql),Ce=(($=V.input)==null?void 0:$.python)??((W=V.args)==null?void 0:W.python),me=((re=V.input)==null?void 0:re.chartType)??((ie=V.args)==null?void 0:ie.chartType);f(me),m(ze),u(Ce),h(!0),te({tool:V.toolName,toolCallId:V.toolCallId,output:{status:"success",message:"Let the user know that chart is created"}})}else if(V.toolName==="getUserSql"){if(!c){te({tool:V.toolName,toolCallId:V.toolCallId,output:{status:"error",message:"No SQL found"}});return}te({tool:V.toolName,toolCallId:V.toolCallId,output:{status:"success",sql:c,python:d||""}})}else if(V.toolName==="generateQueryConfig"){n("Generating query config...");const ze=((he=V.input)==null?void 0:he.chartType)??((Q=V.args)==null?void 0:Q.chartType),Ce=((oe=V.input)==null?void 0:oe.queryConfig)??((ee=V.args)==null?void 0:ee.queryConfig);((ae=V.input)==null?void 0:ae.cardConfig)??((ue=V.args)==null||ue.cardConfig),f(ze),F(Ce),m(void 0),u(void 0);const me=await D();if((je=me==null?void 0:me.data)!=null&&je.error){te({tool:V.toolName,toolCallId:V.toolCallId,output:{status:"error",queryConfig:Ce,message:(Ge=me==null?void 0:me.data)==null?void 0:Ge.error.message}});return}if((He=me==null?void 0:me.data)!=null&&He.records){te({tool:V.toolName,toolCallId:V.toolCallId,output:{status:"success",queryConfig:Ce,message:"The data has been visualized"}});return}te({tool:V.toolName,toolCallId:V.toolCallId,output:{status:"success",queryConfig:Ce,message:"The data has been visualized",records:(We=me==null?void 0:me.data)==null?void 0:We.records}})}else n("Analyzing...")}function _(V){const se=s.removeFromScopeArray(b,V);J(se)}function J(V){const se=s.sanitizeAIScope(V);w(se),M(ne=>[...ne,{id:crypto.randomUUID(),role:"system",parts:[{type:"text",text:`Current scope of tables. Always use the table reference format when generating SQL | ${JSON.stringify(se)}`}]}])}function z(){const V={databaseName:v||"",schemaName:C||"",tableName:k||"",datamodelId:A||"",datamodelName:s.resolveDatamodelName(T),connectionId:L||"",connectionType:E||""},se=s.dedup([...b,V]);J(se)}function U(){const V={databaseName:v||"",schemaName:C||"",tableName:k||"",datamodelName:s.resolveDatamodelName(T),connectionId:L||"",connectionType:E||"",datamodelId:A||""};if(!s.isInAiScopeArray([...S||[],...b],V)||b.length===0){const ne=s.dedup([...S||[],...b,V]).filter($=>$.connectionId===V.connectionId);J(ne)}}const Z=!["ready","error"].includes(Y),le=s.getErrorMessage(P);return{messages:O,setMessages:M,sendMessage:K,regenerate:R,isLoading:Z,handleSetAIScope:U,handleAddCurrentTableToScope:z,removeFromCurrentSelections:_,currentAssitantScope:b,setCurrentAssitantScope:w,stop:X,status:Y,toolStatus:a,llmUsage:r,onFinish:t,errorMessage:le,clearError:q}}const tl=[{title:"Help me write a query for",subtitle:"orders by month"},{title:"Create a bar chart for",subtitle:"sales by category"}];function Hs(){const t=I.useRef(null),[a,n]=I.useState(!1),[r,l]=I.useState(s.isDevEnv),[o,c]=I.useState(!1),[i,d]=I.useState(!1),u=s.useCurrentAIContext(),{setCurrentAIContext:m}=s.useAIActions(),{clearQueue:h}=s.useQueueActions(),{clearFileAttachments:f}=s.useFileActions(),g=s.useFileAttachments("editor"),b=s.useDashboardStore(ee=>ee.dashboard.aiContext),p=s.useEditorStore(ee=>ee.card.dataSource),j=s.useEditorStore(ee=>ee.actions.setCardSql),x=s.useEditorStore(ee=>ee.actions.setRunSql),v=s.useEditorStore(ee=>ee.showAIDialog),k=s.useDashboardStore(ee=>ee.handleOpenAssistantProfile),{setShowAIDialog:L,setCardPython:C}=s.useEditorActions(),{setDataSource:S}=s.useEditorActions(),{assistantProfile:y}=s.useAssistantProfile(),{messages:D,setMessages:N,sendMessage:B,isLoading:w,stop:F,status:T,llmUsage:E,errorMessage:A,clearError:O}=sl(),[M,R]=I.useState(""),P=ee=>{R(ee.target.value)},K=ee=>{ee.preventDefault();const ae=M.trim();if(!ae&&g.length===0)return;const ue=[];ae&&ue.push({type:"text",text:ae}),g.forEach(je=>{je.data&&ue.push({type:"file",mediaType:je.type,filename:je.name,url:`data:${je.type};base64,${je.data}`})}),B({role:"user",parts:ue}),R(""),f("editor"),Z({force:!0})},{visibleMessages:Y,hasMoreMessages:te,totalMessageCount:X,loadMoreMessages:q,resetMessageWindow:H}=s.useMessageWindow(D,{maxVisibleMessages:15,initialLoadCount:10,loadMoreCount:5}),{scrollRef:_,isAtBottom:J,hasNewMessages:z,newMessageCount:U,scrollToBottom:Z,handleScroll:le,resetNewMessageCount:V}=s.useAutoScroll(Y,{threshold:50,delay:0,dependencies:[T,D.length]});I.useEffect(()=>{var ee;v&&((ee=t.current)==null||ee.focus(),m({selectedEntities:(p==null?void 0:p.selectedEntities)||[]}))},[v,p,m]),s.useAutoSubmitQueue({assistantType:"editor",status:T,isLoading:w,sendMessage:B});const{hasActiveTools:se}=s.useActiveToolStatus(D);function ne(ee,ae){ae==="sql"?(j(ee),x(!0)):ae==="python"&&(C(ee),x(!0))}function $(){var ee;(ee=b==null?void 0:b.selectedEntities)==null||ee[0],d(!0)}function W(){u.selectedEntities.length===0&&m({selectedEntities:(b==null?void 0:b.selectedEntities)||[]})}function re(ee){W();const ae={role:"user",parts:[{type:"text",text:ee.title+" "+ee.subtitle}]};B(ae)}function ie(ee){W(),B({role:"user",parts:[{type:"text",text:ee}]})}function he(){return e.jsxs(s.DropdownMenu,{children:[e.jsx(s.DropdownMenuTrigger,{asChild:!0,children:e.jsx(s.Button,{className:"h-7 p-2 text-muted-foreground/50 hover:text-foreground",size:"sm",variant:"ghost",children:e.jsx(s.EllipsisVertical,{className:"size-3.5"})})}),e.jsxs(s.DropdownMenuContent,{align:"end",children:[e.jsx(s.DropdownMenuLabel,{children:"Options"}),e.jsx(s.DropdownMenuSeparator,{}),e.jsx(s.DropdownMenuCheckboxItem,{checked:a,onCheckedChange:n,children:"Token Usage"}),e.jsx(s.DropdownMenuCheckboxItem,{checked:r,onCheckedChange:l,children:"Tool Invocations"}),e.jsx(s.DropdownMenuCheckboxItem,{checked:o,onCheckedChange:c,children:"System Message"})]})]})}function Q(){return e.jsx("div",{"data-role":"header",children:e.jsx("div",{className:"text-lg font-semibold",children:"Assistant"})})}const oe=(M==null?void 0:M.length)===0&&(D==null?void 0:D.filter(ee=>ee.role==="user").length)===0;return e.jsxs("div",{"data-role":"editor-assistant",className:"flex h-full w-full flex-col justify-between px-6 py-4",children:[e.jsxs("div",{"data-role":"header-section",className:"flex items-start justify-between gap-2",children:[Q(),k&&e.jsx(s.Button,{variant:"outline",size:"sm",className:"h-7 p-2",onClick:k,children:(y==null?void 0:y.name)||"Default Profile"}),e.jsxs("div",{"data-role":"header-actions",className:"flex items-center",children:[he(),s.isDevEnv,e.jsx(s.IconButton,{tooltip:"Add Context",className:"h-7 p-2 text-muted-foreground/50 hover:text-foreground",onClick:$,children:e.jsx(s.Settings,{className:"size-4"})}),e.jsx(s.IconButton,{className:"h-7 p-2 text-muted-foreground/50 hover:text-foreground",tooltip:"New Chat",onClick:()=>{N([]),h("editor"),O(),H()},children:e.jsx(s.SquarePen,{className:"size-4"})}),e.jsx(s.Button,{variant:"ghost",className:"h-7 p-2 text-muted-foreground/50 hover:text-foreground",size:"sm",onClick:()=>{L(!1)},children:e.jsx(s.ArrowRightToLine,{className:"size-4"})})]})]}),e.jsx(s.CustomScrollArea,{ref:_,className:"mt-2 flex w-full grow basis-0",onScroll:le,children:e.jsxs("div",{className:"space-y-4 py-2 pr-3","data-role":"messages",children:[te&&e.jsx("div",{className:"flex justify-center py-2",children:e.jsxs(s.Button,{variant:"outline",size:"sm",onClick:q,className:"text-xs",children:["Load ",Math.min(5,X-Y.length)," more messages (",X-Y.length," hidden)"]})}),e.jsx(s.PrintMessages,{messages:Y,showTools:r,handleRun:ne,showSystemMessage:o}),!se&&e.jsx(s.AssistantStatus,{status:T,errorMessage:A})]})}),!J&&e.jsx("div",{className:"absolute bottom-24 right-8 z-10",children:e.jsxs(s.Button,{onClick:()=>{Z({force:!0}),V()},size:"sm",variant:"secondary",className:"rounded-full shadow-lg","aria-label":"Scroll to bottom",children:[e.jsx(s.ChevronDown,{className:"h-4 w-4"}),z&&U>0&&e.jsx("span",{className:"ml-1.5 flex h-5 w-5 items-center justify-center rounded-full bg-primary text-xs text-primary-foreground",children:U>9?"9+":U})]})}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{children:[oe&&!y&&e.jsx(s.Placeholders,{onClick:re,placeholders:tl}),e.jsx("div",{children:oe&&y&&e.jsx(s.SeedQuestions,{seedQuestions:y.seedQuestions||[],handleSeedQuestionClick:ie})})]}),e.jsx(s.PendingMessagesDisplay,{assistantType:"editor",className:"mb-3"}),e.jsx(s.ChatInputWithContext,{ref:t,setInput:R,stop:F,input:M,handleInputChange:P,handleSubmit:ee=>{W(),K(ee),Z({force:!0})},isLoading:w,status:T,assistantType:"editor",onFocus:()=>{}})]}),E&&a&&e.jsx("div",{className:"flex h-8 items-center justify-between",children:e.jsxs("div",{className:"text-xs text-muted-foreground",children:["Usage: ",E.inputTokens," prompt tokens, ",E.outputTokens," ","completion tokens, ",E.totalTokens," total tokens"]})}),e.jsx(s.DataSourceDialog,{incomingSelectedEntities:(p==null?void 0:p.selectedEntities)||[],open:i,onOpenChange:d,dataSource:p||s.EMPTY_DATA_SOURCE,fallbackDataSource:s.EMPTY_DATA_SOURCE,dialogMode:"aiContext"})]})}const Is=t=>{var w;const{updateCardConfig:a,updateGroupByColumn:n,updateMetricColumn:r,updatePivotByColumn:l,updateSortByColumn:o,removeGroupByColumn:c,removeMetricColumn:i,removePivotByColumn:d,removeSortByColumn:u}=s.useEditorActions(),m=s.useEditorStore(F=>F.card.type),h=t==null?void 0:t.id,f=I.useCallback(F=>{if(!(t!=null&&t.config))return[];switch(F){case"groupBy":return(t.config.groupByColumns||[]).map(T=>({id:T.id,name:T.name,dataType:T.dataType,label:T.label!==void 0?T.label:T.name,qualifiedEntityName:T.qualifiedEntityName,entityId:T.entityId,entityName:T.entityName,entityType:T.entityType,dateFormat:T.dateFormat,customFormat:T.customFormat,granularity:T.granularity}));case"metrics":return t.config.metricColumns||[];case"pivotBy":return(t.config.pivotByColumns||[]).map(T=>({id:T.id,name:T.name,dataType:T.dataType,label:T.label!==void 0?T.label:T.name,qualifiedEntityName:T.qualifiedEntityName,entityId:T.entityId,entityName:T.entityName,entityType:T.entityType}));case"sortBy":return(t.config.sortByColumns||[]).map(T=>({id:T.id,name:T.name,dataType:T.dataType,label:T.label!==void 0?T.label:T.name,qualifiedEntityName:T.qualifiedEntityName,entityId:T.entityId,entityName:T.entityName,entityType:T.entityType,direction:T.direction}));case"source":return[];default:return[]}},[t]),g=I.useCallback((F,T)=>{if(h)switch(F){case"groupBy":{a(h,{groupByColumns:T});break}case"metrics":{a(h,{metricColumns:T});break}case"pivotBy":{a(h,{pivotByColumns:T});break}case"sortBy":{a(h,{sortByColumns:T});break}}},[h,a]),b=I.useCallback((F,T,E)=>{if(!h)return;const O=f(F)[T];if(O)switch(F){case"groupBy":n(h,O.id,{label:E});break;case"metrics":r(h,O.id,{label:E});break;case"pivotBy":l(h,O.id,{label:E});break;case"sortBy":o(h,O.id,{label:E});break}},[h,f,n,r,l,o]),p=I.useCallback((F,T)=>{if(!h)return;const A=f("metrics")[F];A&&r(h,A.id,{aggregate:T,label:s.getAggregationLabel(A.name,T)})},[h,f,r]),j=I.useCallback((F,T,E)=>{if(!h)return;const O=f("groupBy")[F];if(!O)return;const M={dateFormat:T};T==="custom"&&E?M.customFormat=E:M.customFormat=void 0,n(h,O.id,M)},[h,f,n]),x=I.useCallback((F,T)=>{if(!h)return;const A=f("groupBy")[F];A&&n(h,A.id,{granularity:T})},[h,f,n]),v=I.useCallback((F,T)=>{if(!h)return;const A=f("metrics")[F];A&&r(h,A.id,{aliasTemplate:T})},[h,f,r]),k=I.useCallback((F,T)=>{if(console.log("handleValueAliasesChange",F,T),!h)return;console.log("handleValueAliasesChange",F,T);const A=f("metrics")[F];A&&(console.log("handleValueAliasesChange",T),r(h,A.id,{valueAliases:T}))},[h,f,r]),L=I.useCallback(F=>{h&&a(h,{comparisonType:F})},[h,a]),C=I.useCallback(F=>{h&&a(h,{showTrendline:F})},[h,a]),S=I.useCallback(F=>{h&&a(h,{trendlineWindow:F})},[h,a]),y=I.useCallback(F=>{h&&a(h,{trendlineGranularity:F})},[h,a]),D=I.useCallback(F=>{h&&a(h,{targetValue:F})},[h,a]),N=I.useCallback(F=>{var P;if(!h)return;const T=[...f("groupBy"),...f("pivotBy"),...f("metrics"),...f("sortBy")],E=(P=t==null?void 0:t.config)==null?void 0:P.joinPlan,A=s.validateEntityConsistency(F,T,E);if(!A.isValid){A.showError&&s.showJoinRequiredNotification();return}const O=s.getSmartContainerForField(F,T),M=f(O);if(s.fieldAlreadyExists(F,M))return;const R=s.getNewField(F,O,M);R&&g(O,[...M,R])},[h,(w=t==null?void 0:t.config)==null?void 0:w.joinPlan,f,g]),B=I.useCallback((F,T)=>{if(!h)return;const A=f(F)[T];if(A){if(F!=="sortBy"){const O=f("sortBy"),M=O.filter(R=>!(R.name===A.name&&R.qualifiedEntityName===A.qualifiedEntityName));M.length!==O.length&&a(h,{sortByColumns:M})}switch(F){case"groupBy":c(h,A.id);break;case"metrics":i(h,A.id);break;case"pivotBy":d(h,A.id);break;case"sortBy":u(h,A.id);break}}},[h,f,c,i,d,u,a]);return{getFieldsForContainer:f,setFieldsForContainer:g,updateLabel:b,handleAggregationChange:p,handleDateFormatChange:j,handleGranularityChange:x,handleAliasTemplateChange:v,handleValueAliasesChange:k,removeField:B,handleFieldClick:N,handleKpiComparisonTypeChange:L,handleKpiShowTrendlineChange:C,handleKpiTrendlineWindowChange:S,handleKpiTrendlineGranularityChange:y,handleKpiTargetValueChange:D,cardType:m}};function al({field:t}){return e.jsxs("div",{className:"w-64 bg-background p-0",children:[e.jsxs("div",{className:"mb-2 flex items-start justify-between gap-2",children:[e.jsx("h3",{className:"text-sm font-medium text-foreground",children:t.label||t.name}),e.jsx("span",{className:"rounded bg-muted px-2 py-0.5 font-mono text-xs text-muted-foreground",children:t.dataType})]}),t.description&&e.jsx("p",{className:"mb-3 text-xs text-muted-foreground",children:t.description}),e.jsx("div",{className:"overflow-x-auto border-t border-border pb-2 pt-2",children:e.jsx("span",{className:"font-mono text-xs text-muted-foreground",children:t.name})})]})}function nl({field:t}){const{attributes:a,listeners:n,setNodeRef:r,transform:l,transition:o,isDragging:c}=s.useSortable({id:t.id}),[i,d]=I.useState(!1),u=s.useEditorStore(b=>b.card),{handleFieldClick:m}=Is(u),h={transform:s.CSS.Transform.toString(l),transition:o};s.getDataType(t.dataType);const f=b=>{const p=(b||"").toLowerCase();switch(s.getDataType(p)){case"number":return Ne;case"date":return s.Calendar;case"boolean":return Me;case"json":return Oe;case"geo":return _e;default:return ge}},g=b=>{const p=(b||"").toLowerCase(),j=s.getDataType(p);return j==="string"?e.jsx("div",{className:"flex size-6 shrink-0 items-center justify-center rounded-sm bg-blue-100 text-xs text-blue-700 dark:bg-blue-950 dark:text-blue-300",children:e.jsx(ge,{className:"h-3 w-3"})}):j==="number"?e.jsx("div",{className:"flex size-6 shrink-0 items-center justify-center rounded-sm bg-green-100 text-xs text-green-700 dark:bg-green-950 dark:text-green-300",children:e.jsx(Ne,{className:"h-3 w-3"})}):j==="date"?e.jsx("div",{className:"flex size-6 shrink-0 items-center justify-center rounded-sm bg-purple-100 text-xs text-purple-700 dark:bg-purple-950 dark:text-purple-300",children:e.jsx(s.Calendar,{className:"h-3 w-3"})}):j==="boolean"?e.jsx("div",{className:"flex size-6 shrink-0 items-center justify-center rounded-sm bg-orange-100 text-xs text-orange-700 dark:bg-orange-950 dark:text-orange-300",children:e.jsx(Me,{className:"h-3 w-3"})}):j==="json"?e.jsx("div",{className:"flex size-6 shrink-0 items-center justify-center rounded-sm bg-gray-100 text-xs text-gray-700 dark:bg-gray-950 dark:text-gray-300",children:e.jsx(Oe,{className:"h-3 w-3"})}):j==="geo"?e.jsx("div",{className:"bg-orange -100 flex size-6 shrink-0 items-center justify-center rounded-sm text-xs text-orange-700 dark:bg-orange-950 dark:text-orange-300",children:e.jsx(_e,{className:"h-3 w-3"})}):j==="calculated"?e.jsx("div",{className:"flex size-6 shrink-0 items-center justify-center rounded-sm bg-gray-100 text-xs text-gray-700 dark:bg-gray-950 dark:text-gray-300",children:e.jsx(qe,{className:"h-3 w-3"})}):null};return f(t.dataType),e.jsxs("div",{ref:r,style:h,...a,...n,className:`group/container overflow-hidden rounded-lg transition-all ${c?"scale-95 opacity-50":"border border-transparent hover:bg-muted"}`,children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-3 p-2",onClick:()=>m(t),children:[g(t.dataType),e.jsx(s.TooltipProvider$1,{children:e.jsxs(s.Tooltip,{children:[e.jsx(s.TooltipTrigger,{asChild:!0,children:e.jsx("div",{className:"min-w-0 flex-1 overflow-hidden",children:e.jsx("span",{className:`block text-sm text-foreground/80 hover:text-foreground dark:text-muted-foreground ${i?"whitespace-normal break-words":"truncate"}`,children:t.label||t.name})})}),e.jsx(s.TooltipContent,{side:"bottom",align:"start",className:"ml-5 max-w-xs px-4 pb-2 pt-4",children:e.jsx(al,{field:t})})]})})]}),i&&e.jsx("div",{className:"text-muted-foreground-700 px-2 pb-3 text-sm",children:e.jsx(s.Card,{className:"",children:e.jsxs(s.CardContent,{className:"space-y-2 p-3",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(at,{className:"h-4 w-4 text-muted-foreground"}),e.jsx("span",{className:"break-all",children:t.label||t.name})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Ha,{className:"h-4 w-4 text-muted-foreground"}),e.jsx("span",{className:"break-all",children:t.name})]}),e.jsx(s.Badge,{variant:"outline",className:"mt-2 text-xs",children:t.dataType})]})})})]})}function rl(){const[t,a]=I.useState(""),[n,r]=I.useState("all"),l=s.useEditorStore(k=>k.card.dataSource),{columns:o=[],columnGroups:c=[],isLoading:i,error:d}=s.useColumns(),u=o.filter(k=>k.name.toLowerCase().includes(t.toLowerCase())||k.dataType.toLowerCase().includes(t.toLowerCase())||k.qualifiedEntityName&&k.qualifiedEntityName.toLowerCase().includes(t.toLowerCase())),m=k=>{if(k.dataType==="number"||k.dataType==="integer"||k.dataType==="float"||k.dataType==="decimal"||k.dataType==="currency")return"metrics";const L=s.getDataType(k.dataType);return["date","string","boolean"].includes(L)?"dimensions":L==="number"?"metrics":"dimensions"},f=(n==="all"?u:u.filter(k=>m(k)===n)).reduce((k,L)=>{const C=L.qualifiedEntityName||"Other Fields";return k[C]||(k[C]={label:s.toLabel(L.entityName),fields:[]}),k[C].fields.push(L),k},{}),b=Object.keys(f),p=u.filter(k=>m(k)==="dimensions").length,j=u.filter(k=>m(k)==="metrics").length,x=u.filter(k=>m(k)==="calculated").length,v=u.length>0;return i?e.jsx("div",{className:"flex h-[calc(100vh-200px)] w-[290px] flex-col items-center justify-center",children:e.jsx(s.LoadingDots,{size:"md",color:"muted","aria-label":"Loading data"})}):d?e.jsxs("div",{className:"flex h-[calc(100vh-200px)] w-[290px] flex-col items-center justify-center",children:[e.jsx(s.Database,{className:"mb-4 h-12 w-12 text-red-300"}),e.jsx("p",{className:"mb-2 text-sm text-red-500",children:"Error loading fields"}),e.jsx("p",{className:"px-4 text-center text-xs text-red-400",children:d.message||"Failed to load column data"})]}):!l||!l.selectedEntities||l.selectedEntities.length===0?e.jsx(s.ScrollArea,{className:"h-[calc(100vh-200px)] w-[290px]",children:e.jsxs("div",{className:"flex flex-col items-center justify-center py-8 text-center",children:[e.jsx(s.Database,{className:"mb-4 h-12 w-12 text-gray-300"}),e.jsx("p",{className:"mb-2 text-sm text-gray-500",children:"No data source selected"}),e.jsx("p",{className:"px-4 text-xs text-gray-400",children:"Select a table, view, or dataset from the data source panel to see available fields"})]})}):e.jsxs("div",{className:"mt-2 flex h-[calc(100vh-200px)] w-full grow flex-col gap-2 px-6 pb-6",children:[e.jsxs("div",{className:"mt-1 flex-shrink-0 space-y-2",children:[o.length>0&&e.jsxs("div",{className:"relative mb-4",children:[e.jsx(s.Search,{className:"absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 transform text-muted-foreground"}),e.jsx(s.Input$1,{className:"pl-10",type:"text",placeholder:"Search fields...",value:t,onChange:k=>a(k.target.value)})]}),v&&e.jsx(s.Tabs,{defaultValue:"all",value:n,onValueChange:k=>r(k),className:"mb-4",children:e.jsxs(s.TabsList,{className:"grid h-9 w-full grid-cols-4",children:[e.jsxs(s.TabsTrigger,{value:"all",className:"text-xs",children:["All",e.jsx("span",{className:"ml-2 text-xs font-semibold",children:u.length})]}),e.jsxs(s.TabsTrigger,{value:"dimensions",className:"text-xs",children:[e.jsx(s.Layers,{className:"size-4 shrink-0"}),e.jsx("span",{className:"ml-2 text-xs font-semibold",children:p})]}),e.jsxs(s.TabsTrigger,{value:"metrics",className:"text-xs",children:[e.jsx(s.ChartColumn,{className:"size-4 shrink-0"}),e.jsx("span",{className:"ml-2 text-xs font-semibold",children:j})]}),e.jsxs(s.TabsTrigger,{value:"calculated",className:"text-xs",children:[e.jsx(qe,{className:"size-4 shrink-0"}),e.jsx("span",{className:"ml-2 text-xs font-semibold",children:x})]})]})})]}),e.jsxs(s.CustomScrollArea,{className:"py-2",children:[e.jsx(s.Accordion,{type:"multiple",defaultValue:b,className:"space-y-2",children:Object.entries(f).map(([k,L])=>{const C=c.find(S=>S.entityName===k)||{entityName:k,label:L.label};return e.jsxs(s.AccordionItem,{value:k,className:"border-none",children:[e.jsx(s.AccordionTrigger,{className:"group rounded-md px-2.5 py-2 text-muted-foreground hover:bg-muted hover:no-underline",children:e.jsxs("div",{title:C.label||C.entityName,className:"flex items-center gap-2",children:[e.jsx("span",{className:"max-w-[190px] truncate text-ellipsis whitespace-nowrap text-sm font-medium text-primary",children:C.label||C.entityName}),e.jsx(s.Badge,{variant:"secondary",className:"rounded-full text-xs text-muted-foreground group-hover:bg-background",children:L.fields.length})]})}),e.jsx(s.AccordionContent,{className:"pb-2",children:e.jsx("div",{className:"space-y-1",children:L.fields.map(S=>e.jsx(nl,{field:S},S.id))})})]},k)})}),Object.keys(f).length===0&&o.length===0&&e.jsxs("div",{className:"py-8 text-center text-sm text-gray-500",children:[e.jsx("p",{children:"No fields found for selected data source"}),e.jsx("p",{className:"mt-1 text-xs text-gray-400",children:"Try selecting different data sources"})]}),Object.keys(f).length===0&&o.length>0&&e.jsx("div",{className:"py-4 text-center text-sm text-gray-500",children:"No fields found for this category"}),e.jsx(s.ScrollBar,{orientation:"horizontal"}),e.jsx(s.ScrollBar,{orientation:"vertical"})]})]})}function ll(){return e.jsxs("div",{className:" h-full flex flex-col items-center",children:[" ",e.jsx(rl,{})," "]})}function ol({initialJoinPlan:t,availableDataSources:a}){const[n,r]=I.useState(t),[l,o]=I.useState(new Set),c=()=>{const S=n.joins.length>0?Math.max(...n.joins.map(D=>D.sequence))+1:1,y={id:`join-${Date.now()}`,source:{type:"table",name:"",database:"",schema:""},target:{type:"table",name:"",database:"",schema:""},joinType:"INNER",sequence:S,joinKeyGroups:[{id:"group-"+Date.now()+"-"+Math.random().toString(36).substr(2,9),operator:"AND",keys:[]}]};r({...n,joins:[...n.joins,y]}),o(new Set([...l,y.id]))},i=S=>{r({...n,joins:n.joins.filter(y=>y.id!==S)}),o(new Set([...l].filter(y=>y!==S)))},d=(S,y)=>{var w,F;const D=n.joins.find(T=>T.id===S);if(!D)return;const N={...D,...y},B=n.joins.map(T=>T.id===S?N:T);if((w=N.source)!=null&&w.name&&((F=N.target)!=null&&F.name)&&N.joinKeyGroups[0].keys.length===0){const T=a.find(M=>{var R;return M.name===((R=N.source)==null?void 0:R.name)}),E=a.find(M=>{var R;return M.name===((R=N.target)==null?void 0:R.name)}),A={id:`key-${Date.now()}`,source:{id:`source-${Date.now()}`,name:"",dataType:"",label:"",qualifiedFieldName:"",entityId:(T==null?void 0:T.name)||"",entityName:(T==null?void 0:T.name)||"",entityType:(T==null?void 0:T.type)||"table"},target:{id:`target-${Date.now()}`,name:"",dataType:"",label:"",qualifiedFieldName:"",entityId:(E==null?void 0:E.name)||"",entityName:(E==null?void 0:E.name)||"",entityType:(E==null?void 0:E.type)||"table"},operator:"="},O=[...N.joinKeyGroups];O[0]={...O[0],keys:[A]},N.joinKeyGroups=O,B[B.findIndex(M=>M.id===S)]=N}r({...n,joins:B})};return{joinPlan:n,expandedJoins:l,setJoinPlan:r,addJoin:c,removeJoin:i,updateJoin:d,moveJoinUp:S=>{const y=n.joins.findIndex(D=>D.id===S);if(y>0){const D=[...n.joins],N={...D[y]},B={...D[y-1]};D[y]=B,D[y-1]=N,D.forEach((F,T)=>{F.sequence=T+1});const w={...n,joins:D};r(w)}},moveJoinDown:S=>{const y=n.joins.findIndex(D=>D.id===S);if(y<n.joins.length-1){const D=[...n.joins],N={...D[y]},B={...D[y+1]};D[y]=B,D[y+1]=N,D.forEach((F,T)=>{F.sequence=T+1});const w={...n,joins:D};r(w)}},toggleJoinExpansion:S=>{const y=new Set(l);y.has(S)?y.delete(S):y.add(S),o(y)},getAvailableSourceEntities:S=>{if(n.joins.length===0)return a;const y=n.joins.findIndex(N=>N.id===S);if(y===0)return a;const D=new Set;return n.baseEntity.name&&D.add(n.baseEntity.name),n.joins.slice(0,y).forEach(N=>{D.add(N.source.name),D.add(N.target.name)}),a.filter(N=>D.has(N.name))},getAvailableTargetEntities:S=>a.filter(y=>y.name!==S),addJoinKeyGroup:S=>{const y=n.joins.find(N=>N.id===S);if(!y)return;const D=[...y.joinKeyGroups,{id:"group-"+Date.now()+"-"+Math.random().toString(36).substr(2,9),operator:"AND",keys:[]}];d(S,{joinKeyGroups:D})},updateGroupOperator:(S,y,D)=>{const N=n.joins.find(w=>w.id===S);if(!N)return;const B=[...N.joinKeyGroups];B[y]={...B[y],operator:D},d(S,{joinKeyGroups:B})},removeJoinKeyGroup:(S,y)=>{const D=n.joins.find(B=>B.id===S);if(!D)return;const N=[...D.joinKeyGroups];N.splice(y,1),d(S,{joinKeyGroups:N})},addJoinKey:(S,y)=>{const D=n.joins.find(T=>T.id===S);if(!D)return;const N=a.find(T=>T.name===D.source.name),B=a.find(T=>T.name===D.target.name),w=[...D.joinKeyGroups],F={id:`key-${Date.now()}`,source:{id:`source-${Date.now()}`,name:"",dataType:"",label:"",qualifiedFieldName:"",entityId:(N==null?void 0:N.name)||"",entityName:(N==null?void 0:N.name)||"",entityType:(N==null?void 0:N.type)||"table"},target:{id:`target-${Date.now()}`,name:"",dataType:"",label:"",qualifiedFieldName:"",entityId:(B==null?void 0:B.name)||"",entityName:(B==null?void 0:B.name)||"",entityType:(B==null?void 0:B.type)||"table"},operator:"="};w[y]={...w[y],keys:[...w[y].keys,F]},d(S,{joinKeyGroups:w})},updateJoinKey:(S,y,D,N,B)=>{const w=n.joins.find(O=>O.id===S);if(!w)return;const F=a.find(O=>O.name===w.source.name),T=a.find(O=>O.name===w.target.name),E=[...w.joinKeyGroups],A=E[y].keys[D];N==="sourceColumnName"&&F?E[y].keys[D]={...A,source:{...A.source,name:B}}:N==="targetColumnName"&&T?E[y].keys[D]={...A,target:{...A.target,name:B}}:N==="operator"&&(E[y].keys[D]={...A,operator:B}),d(S,{joinKeyGroups:E})},removeJoinKey:(S,y,D)=>{const N=n.joins.find(w=>w.id===S);if(!N)return;const B=[...N.joinKeyGroups];B[y].keys.splice(D,1),d(S,{joinKeyGroups:B})},generateSQLPreview:()=>{const S=[...n.joins].sort((N,B)=>N.sequence-B.sequence),y=n.baseEntity;if(!y.name)return"SELECT * FROM table -- Please select a base entity";let D=`SELECT *
|
|
349
349
|
FROM ${y.name}`;return S.forEach(N=>{const B=a.find(T=>T.name===N.target.name);if(!B)return;const w=N.joinKeyGroups.filter(T=>T.keys&&T.keys.length>0).map(T=>{const E=T.keys.filter(A=>{var O,M,R,P;return((O=A.source)==null?void 0:O.name)&&((M=A.target)==null?void 0:M.name)&&((R=A.source)==null?void 0:R.entityName)&&((P=A.target)==null?void 0:P.entityName)}).map(A=>`${A.source.entityName}.${A.source.name} ${A.operator} ${A.target.entityName}.${A.target.name}`);return E.length>1?`(${E.join(` ${T.operator} `)})`:E[0]}).filter(Boolean),F=w.length>1?w.join(" OR "):w[0]||"condition_here";D+=`
|
|
350
350
|
${N.joinType} JOIN ${B.name}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { jsxs as a, jsx as e, Fragment as te } from "react/jsx-runtime";
|
|
2
|
-
import { L as re, M as Lr, u as ne, N as ma, O as ha, P as _, Q as pa, R as Je, T as hs, I as St, V as at, W as vt, X as Pr, Y as _e, Z as Nt, _ as bt, $ as Ct, a0 as Rt, a1 as B, a2 as De, a3 as Qt, a4 as ve, a5 as _r, a6 as xa, a7 as Mi, a8 as ir, a9 as ps, aa as G, ab as fs, ac as Ei, ad as Vr, ae as Br, af as da, ag as Me, j as or, ah as he, ai as pe, aj as fe, ak as ge, al as ya, am as va, an as X, ao as ut, ap as Ai, aq as mt, ar as ht, as as cr, at as kt, au as it, av as Fe, aw as aa, ax as Be, ay as je, az as Ue, aA as Qe, aB as bn, aC as de, aD as He, aE as Ii, aF as Ka, aG as Oi, aH as Ja, aI as Pa, aJ as Ri, aK as Fi, aL as jr, aM as nt, aN as gs, aO as zi, aP as Tn, aQ as Pt, aR as Wt, aS as wt, aT as rt, aU as Ur, aV as Yr, aW as ka, aX as Re, aY as Te, aZ as Da, a_ as Dt, a$ as Ta, b0 as Li, b1 as na, b2 as et, b3 as Ha, b4 as st, b5 as xs, b6 as Cn, b7 as Tt, b8 as Qa, b9 as Za, ba as Pi, bb as fa, bc as ys, bd as vs, be as Ns, bf as bs, bg as Ze, bh as _i, bi as Ma, bj as Xa, bk as $r, bl as Cs, bm as Mn, bn as ws, bo as Vi, bp as qr, bq as Ss, br as Bi, bs as ji, bt as _t, bu as Vt, bv as Ie, bw as Kt, bx as en, by as Gr, K as ie, bz as Ui, bA as yt, J as E, bB as Yi, bC as Wr, bD as Kr, bE as Jr, bF as Hr, bG as Qr, bH as Zr, bI as Xr, bJ as el, bK as tl, bL as $i, bM as Ea, bN as Ut, bO as ks, bP as qi, bQ as Ds, bR as En, bS as Gi, bT as Wi, bU as Ki, i as Ji, bV as al, bW as _a, bX as Mt, bY as tn, bZ as an, b_ as nn, b$ as sn, c0 as ra, c1 as Aa, c2 as Ft, c3 as rn, A as Et, c4 as nl, r as sl, q as rl, l as xt, c5 as Pe, c6 as Hi, c7 as Zt, c8 as Jt, c9 as ll, ca as Qi, k as il, cb as Va, cc as Yt, cd as Zi, n as Ht, m as At, o as It, ce as Xn, cf as Ts, cg as An, ch as In, ci as Xt, x as dr, cj as Ve, ck as On, cl as yn, cm as Ba, cn as es, co as ol, cp as cl, cq as Ms, cr as Xi, cs as eo, ct as dl, cu as to, cv as Rn, cw as ao, cx as Na, cy as no, cz as so, cA as ts, cB as $t, cC as qe, cD as qt, cE as ro, cF as lo, cG as ul, cH as io, cI as Es, cJ as oo, cK as As, cL as Is, cM as co, cN as ml, cO as hl, cP as uo, cQ as mo, cR as ja, cS as ho, cT as Os, cU as po, cV as fo, cW as ur, cX as go, E as ln, b as Rs, cY as Fs, cZ as xo, c_ as yo, c$ as vo, d0 as No, d1 as bo, d2 as pl, d3 as zs, d4 as fl, d5 as gl, d6 as xl, d7 as yl, d8 as vl, d9 as Ls, da as Ps, db as Nl, dc as bl, dd as Cl, de as _s, df as Fn, dg as zn, dh as Co, di as wo, dj as So, dk as ko, dl as Do, dm as To, dn as Mo, dp as Xe, dq as tt, dr as be, ds as Ce, dt as we, du as Eo, dv as Ao, dw as Io, dx as Oo, dy as Ro, y as Fo, dz as mr, dA as wl, dB as zo, dC as Lo, dD as hn, dE as hr, dF as Po, dG as pr, dH as fr, dI as _o, dJ as Vo, dK as Bo, dL as jo, dM as Vs, dN as Bs, dO as js, dP as Ia, dQ as Us, dR as ea, dS as Uo, dT as Ln, dU as Sl, dV as jn, dW as Yo, dX as $o, dY as gr, dZ as qo, d_ as Go, d$ as Wo, e0 as Ko, e1 as Jo, w as xr, e2 as yr, e3 as Ho, e4 as Qo, e5 as Zo, e6 as Xo, e7 as ec, e8 as tc, e9 as ac, ea as nc, eb as sc, ec as rc, ed as lc, ee as ic, ef as oc, eg as cc, eh as dc, ei as uc, ej as mc, ek as hc, el as pc, em as Ys, en as Un, eo as fc, ep as gc, eq as as, er as xc, es as vn, et as Nn, eu as Oa, ev as yc, ew as vr, ex as vc, ey as ns, ez as kl, eA as $s, eB as Dl, eC as Yn, eD as qs, eE as Nc, eF as bc, eG as Cc, eH as Ua, eI as wc, eJ as ss, eK as Sc, eL as kc, eM as Dc, eN as rs, eO as ls, eP as wn, eQ as Tc, eR as ba, eS as Ya, eT as Mc, eU as Ec, eV as Ac, eW as Ic, eX as Oc, eY as Rc, eZ as Fc, F as Tl, e_ as zc, e$ as Lc, p as Pc, f0 as _c, B as Vc, f1 as Bc, f2 as jc, S as Uc, f3 as Yc, U as $c, f4 as qc, C as Gc } from "./index-
|
|
2
|
+
import { L as re, M as Lr, u as ne, N as ma, O as ha, P as _, Q as pa, R as Je, T as hs, I as St, V as at, W as vt, X as Pr, Y as _e, Z as Nt, _ as bt, $ as Ct, a0 as Rt, a1 as B, a2 as De, a3 as Qt, a4 as ve, a5 as _r, a6 as xa, a7 as Mi, a8 as ir, a9 as ps, aa as G, ab as fs, ac as Ei, ad as Vr, ae as Br, af as da, ag as Me, j as or, ah as he, ai as pe, aj as fe, ak as ge, al as ya, am as va, an as X, ao as ut, ap as Ai, aq as mt, ar as ht, as as cr, at as kt, au as it, av as Fe, aw as aa, ax as Be, ay as je, az as Ue, aA as Qe, aB as bn, aC as de, aD as He, aE as Ii, aF as Ka, aG as Oi, aH as Ja, aI as Pa, aJ as Ri, aK as Fi, aL as jr, aM as nt, aN as gs, aO as zi, aP as Tn, aQ as Pt, aR as Wt, aS as wt, aT as rt, aU as Ur, aV as Yr, aW as ka, aX as Re, aY as Te, aZ as Da, a_ as Dt, a$ as Ta, b0 as Li, b1 as na, b2 as et, b3 as Ha, b4 as st, b5 as xs, b6 as Cn, b7 as Tt, b8 as Qa, b9 as Za, ba as Pi, bb as fa, bc as ys, bd as vs, be as Ns, bf as bs, bg as Ze, bh as _i, bi as Ma, bj as Xa, bk as $r, bl as Cs, bm as Mn, bn as ws, bo as Vi, bp as qr, bq as Ss, br as Bi, bs as ji, bt as _t, bu as Vt, bv as Ie, bw as Kt, bx as en, by as Gr, K as ie, bz as Ui, bA as yt, J as E, bB as Yi, bC as Wr, bD as Kr, bE as Jr, bF as Hr, bG as Qr, bH as Zr, bI as Xr, bJ as el, bK as tl, bL as $i, bM as Ea, bN as Ut, bO as ks, bP as qi, bQ as Ds, bR as En, bS as Gi, bT as Wi, bU as Ki, i as Ji, bV as al, bW as _a, bX as Mt, bY as tn, bZ as an, b_ as nn, b$ as sn, c0 as ra, c1 as Aa, c2 as Ft, c3 as rn, A as Et, c4 as nl, r as sl, q as rl, l as xt, c5 as Pe, c6 as Hi, c7 as Zt, c8 as Jt, c9 as ll, ca as Qi, k as il, cb as Va, cc as Yt, cd as Zi, n as Ht, m as At, o as It, ce as Xn, cf as Ts, cg as An, ch as In, ci as Xt, x as dr, cj as Ve, ck as On, cl as yn, cm as Ba, cn as es, co as ol, cp as cl, cq as Ms, cr as Xi, cs as eo, ct as dl, cu as to, cv as Rn, cw as ao, cx as Na, cy as no, cz as so, cA as ts, cB as $t, cC as qe, cD as qt, cE as ro, cF as lo, cG as ul, cH as io, cI as Es, cJ as oo, cK as As, cL as Is, cM as co, cN as ml, cO as hl, cP as uo, cQ as mo, cR as ja, cS as ho, cT as Os, cU as po, cV as fo, cW as ur, cX as go, E as ln, b as Rs, cY as Fs, cZ as xo, c_ as yo, c$ as vo, d0 as No, d1 as bo, d2 as pl, d3 as zs, d4 as fl, d5 as gl, d6 as xl, d7 as yl, d8 as vl, d9 as Ls, da as Ps, db as Nl, dc as bl, dd as Cl, de as _s, df as Fn, dg as zn, dh as Co, di as wo, dj as So, dk as ko, dl as Do, dm as To, dn as Mo, dp as Xe, dq as tt, dr as be, ds as Ce, dt as we, du as Eo, dv as Ao, dw as Io, dx as Oo, dy as Ro, y as Fo, dz as mr, dA as wl, dB as zo, dC as Lo, dD as hn, dE as hr, dF as Po, dG as pr, dH as fr, dI as _o, dJ as Vo, dK as Bo, dL as jo, dM as Vs, dN as Bs, dO as js, dP as Ia, dQ as Us, dR as ea, dS as Uo, dT as Ln, dU as Sl, dV as jn, dW as Yo, dX as $o, dY as gr, dZ as qo, d_ as Go, d$ as Wo, e0 as Ko, e1 as Jo, w as xr, e2 as yr, e3 as Ho, e4 as Qo, e5 as Zo, e6 as Xo, e7 as ec, e8 as tc, e9 as ac, ea as nc, eb as sc, ec as rc, ed as lc, ee as ic, ef as oc, eg as cc, eh as dc, ei as uc, ej as mc, ek as hc, el as pc, em as Ys, en as Un, eo as fc, ep as gc, eq as as, er as xc, es as vn, et as Nn, eu as Oa, ev as yc, ew as vr, ex as vc, ey as ns, ez as kl, eA as $s, eB as Dl, eC as Yn, eD as qs, eE as Nc, eF as bc, eG as Cc, eH as Ua, eI as wc, eJ as ss, eK as Sc, eL as kc, eM as Dc, eN as rs, eO as ls, eP as wn, eQ as Tc, eR as ba, eS as Ya, eT as Mc, eU as Ec, eV as Ac, eW as Ic, eX as Oc, eY as Rc, eZ as Fc, F as Tl, e_ as zc, e$ as Lc, p as Pc, f0 as _c, B as Vc, f1 as Bc, f2 as jc, S as Uc, f3 as Yc, U as $c, f4 as qc, C as Gc } from "./index-DyxKgRLI.js";
|
|
3
3
|
import * as sa from "react";
|
|
4
4
|
import ct, { useState as V, useEffect as Ee, useRef as zt, useMemo as Ge, useCallback as Se, Suspense as Ml, useContext as Wc } from "react";
|
|
5
5
|
import "react-dom";
|