react-semaphor 0.1.11 → 0.1.12
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-DMGEOoiW.js → dashboard-plus-B9t5rjti.js} +3 -3
- package/dist/chunks/{dashboard-plus-D_xcZ7mX.js → dashboard-plus-Cb-04T5S.js} +1052 -1052
- package/dist/chunks/{index-BlOXjv--.js → index-IA4DqOkm.js} +9195 -9164
- package/dist/chunks/{index-DOujqHIH.js → index-ayPbvue8.js} +180 -180
- 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/surfboard/index.cjs +1 -1
- package/dist/surfboard/index.js +1 -1
- package/package.json +1 -1
|
@@ -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-ayPbvue8.js"),T=require("react"),Ot=require("react-dom");function Pt(t){const n=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(t){for(const a in t)if(a!=="default"){const r=Object.getOwnPropertyDescriptor(t,a);Object.defineProperty(n,a,r.get?r:{enumerable:!0,get:()=>t[a]})}}return n.default=t,Object.freeze(n)}const ss=Pt(T);/**
|
|
2
2
|
* @license lucide-react v0.453.0 - ISC
|
|
3
3
|
*
|
|
4
4
|
* This source code is licensed under the ISC license.
|
|
@@ -275,6 +275,6 @@ ${y.joinType} JOIN ${v.name}
|
|
|
275
275
|
|
|
276
276
|
${u?`Python:
|
|
277
277
|
${u}`:""}
|
|
278
|
-
`;F(z)}function B(){return e.jsxs(e.Fragment,{children:[l&&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(Ln,{jsonString:JSON.stringify(m,null,2)})})}),m&&m.length>0&&e.jsx(s.Button,{variant:"ghost",onClick:()=>o(!l),className:"absolute bottom-0 right-6 size-7 p-1",children:l?e.jsx(s.X,{className:"size-3.5 text-muted-foreground"}):e.jsx(s.Filter,{className:"size-3.5 text-muted-foreground"})})]})}function K(){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(Mn,{})}),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(Rn,{})}),e.jsx("code",{className:"absolute right-6 top-3 text-xs text-muted-foreground/70",children:"python"})]})]})]})}function _(){return e.jsx("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:b||R,onClick:()=>{M()},className:"h-8 shrink-0",size:"sm",children:[b||R?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(In,{errorSql:I,sql:N==null?void 0:N.sql,error:L,onDebugWithAssistant:P}),e.jsx(os,{}),e.jsx(s.Toggle,{pressed:a,onPressedChange:z=>r(z),className:"h-8",size:"sm",variant:"outline",children:e.jsx(An,{className:"size-4 text-foreground/70"})}),e.jsx("button",{disabled:i,onClick:()=>{k(!0)},className:"h-9 w-full cursor-text px-3 text-left text-sm text-muted-foreground",children:i?"":"Type your question..."})]})})}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:[K(),B()]}),_()]})}const On=[{value:"table",label:"Table",icon:s.Table2},{value:"aggregateTable",label:"Aggregate",icon:s.Layers},{value:"pivotTable",label:"Pivot",icon:He}];function Pn({className:t}){const n=s.useEditorStore(d=>d.card),{setCardType:a,setCard:r,updateCardInFrame:l}=s.useEditorActions(),o=["table","aggregateTable","pivotTable"].includes(n.type),c=s.hasValidCardConfig(n.config);if(!o||!c)return null;const i=d=>{var m;const u=d;if(u==="aggregateTable"&&((m=n.config)!=null&&m.pivotByColumns)&&n.config.pivotByColumns.length>0){const x={...n,type:u,config:{...n.config,pivotByColumns:[]}};r(x),l(x)}else{a(u);const x={...n,type:u};l(x)}};return e.jsx("div",{className:s.cn("flex items-center",t),children:e.jsx(s.RadioGroup,{value:n.type,onValueChange:i,className:"flex flex-row items-center justify-between gap-1 rounded-lg border p-1",children:On.map(d=>{const u=d.icon,m=n.type===d.value;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",m?"bg-muted text-foreground shadow-sm":"text-muted-foreground hover:bg-muted/50"),children:[e.jsx(u,{className:"h-3.5 w-3.5"}),d.label]})]},d.value)})})})}function Bn({card:t}){var F,k,D,w,j,N,b,R,S,O,E;const[n,a]=T.useState(!1),[r,l]=T.useState([]),{authToken:o}=s.useSemaphorContext(),{theme:c}=s.useTheme(),i=s.getTokenParams(o==null?void 0:o.accessToken),d=s.useDashboardStore(I=>I.themeStyle),u={mode:c||"system",colors:((k=(F=d==null?void 0:d.chart)==null?void 0:F.dataset)==null?void 0:k.backgroundColor)||[]};(D=t.customCardPreferences)!=null&&D.inputData;const{getCard:m}=s.useCustomVisual(((w=t.customCardPreferences)==null?void 0:w.url)||""),x=((j=t.customCardPreferences)==null?void 0:j.visualType)||"single",h=s.useEditorStore(I=>I.frame),{setCustomCardPreferences:p}=s.useEditorActions(),{data:g}=s.useDashboardCardQuery(t),f=T.useCallback((I,A)=>{l(M=>({...M,[I]:A}))},[]);if(!((N=t.customCardPreferences)!=null&&N.componentName))return null;const y=m((b=t.customCardPreferences)==null?void 0:b.componentName);function v(I){a(I)}const C=Object.keys(((R=t.customCardPreferences)==null?void 0:R.dataInputCardIds)||{}).map(I=>{var L,P,B;const A=(P=(L=t.customCardPreferences)==null?void 0:L.dataInputCardIds)==null?void 0:P[I].cardId,M=(B=h==null?void 0:h.cards)==null?void 0:B.find(K=>K.id===A);return M||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(T.Suspense,{fallback:e.jsx(e.Fragment,{}),children:[y&&x==="single"&&e.jsx(y,{editing:!0,params:i,theme:u,settings:(S=t.customCardPreferences)==null?void 0:S.settings,onDataChange:f,data:(g==null?void 0:g.records)||[]}),y&&x==="multiple"&&e.jsxs(e.Fragment,{children:[Object.keys(((O=t.customCardPreferences)==null?void 0:O.dataInputCardIds)||{}).map(I=>{var L,P,B;const A=(P=(L=t.customCardPreferences)==null?void 0:L.dataInputCardIds)==null?void 0:P[I].cardId,M=(B=h==null?void 0:h.cards)==null?void 0:B.find(K=>K.id===A);if(M)return e.jsx(s.MultiInputEmptyRenderer,{onLoadingStatus:v,onDataChange:f,dataInputIndex:I,card:M},M.id+I)}),e.jsx("div",{className:"flex flex-col gap-2",children:e.jsx(y,{theme:u,onDataChange:f,settings:C.map(I=>{var A;return(A=I==null?void 0:I.customCardPreferences)==null?void 0:A.settings}),data:C.map(I=>I!=null&&I.id?r==null?void 0:r[I.id]:[])})})]})]},(E=t.customCardPreferences)==null?void 0:E.componentName)})}function ht({className:t,...n}){var N;const a=s.useEditorStore(b=>b.card),r=s.isExplorerCard(a),l=((N=a.customCardPreferences)==null?void 0:N.showCardHeader)??!0,o=s.useEditorStore(b=>b.frame),c=s.useDashboardStore(b=>b.dashboard.filters),i=s.useEditorStore(b=>b.actions.setRunSql),{updateFilter:d}=s.useDashboardActions(),u=c==null?void 0:c.find(b=>b.id===o.filterId),{data:m,isLoading:x,isFetching:h,errorMessage:p,pagination:g}=s.useDashboardCardQuery(a),{setCard:f,updateCardInFrame:y}=s.useEditorActions(),{data:v}=s.useTopoJson(a),C=T.useMemo(()=>{var b;return a.type!=="pivotTable"||!((b=m==null?void 0:m.records)!=null&&b.length)?null:{records:m.records,columnSubtotalMeta:m.columnSubtotalMeta,subtotalColumns:m.subtotalColumns||[],pivotSchema:m.pivotSchema||[],groupByColumns:m.groupByColumns}},[a.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]),F=s.usePivotTableConfig(a,C),k=(b,R)=>{var O,E;const S={...a,paginationConfig:{page:b+1,pageSize:R}};f(S),y(S),a.sql&&((E=(O=a.preferences)==null?void 0:O.tablePrefs)!=null&&E.enableDevModePagination)&&i(!0)},D=T.useMemo(()=>!a.id||!(m!=null&&m.records)?null:s.createChartConfig({card:a,data:m==null?void 0:m.records,cardType:a.type,queryConfig:a.queryConfig,customCfg:a.customCfg,preferences:a.preferences,topoJson:v}),[a.id,m==null?void 0:m.records,a.type,a.queryConfig,a.customCfg,a.preferences,v]);function w(b){return e.jsx(s.ErrorBoundary,{FallbackComponent:s.FallbackVisual,children:e.jsx(Bn,{card:b})})}function j(){if(m!=null&&m.records&&(m==null?void 0:m.records.length)===0&&!x&&!h)return p?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((x||h)&&a.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(!a.id)return null;if(a.type==="custom")return w(a);if(!["table","pivotTable","aggregateTable","custom"].includes(a.type)&&D)return e.jsx("div",{className:"relative h-full min-h-0 w-full flex-1 grow basis-0",children:x||h?e.jsx(e.Fragment,{}):e.jsx(s.ChartJsVisual,{cfg:D})});if(a.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:a,data:(m==null?void 0:m.records)||[],paginationMetadata:g,onPaginationChange:k,isLoading:x||h})});if(a.type==="pivotTable"&&F)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:a,data:F.data,options:F.options,onAggregationChange:b=>{const R=s.handleAggregationChange(b,a.config),S={...a,config:R};f(S),y(S)},onAggregationLabelChange:b=>{const R=s.handleAggregationLabelChange(b,a.config),S={...a,config:R};f(S),y(S)}})});if(a.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:a,data:(m==null?void 0:m.records)||[],groupByColumns:m==null?void 0:m.groupByColumns,pivotSchema:m==null?void 0:m.pivotSchema,paginationMetadata:g,onPaginationChange:k,onAggregationChange:b=>{const R=s.handleAggregationChange(b,a.config),S={...a,config:R};f(S),y(S)},isLoading:x||h})})}return e.jsxs(s.Card,{role:"editor-visual-card",className:s.cn("relative flex h-full flex-col rounded-none",t),...n,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 justify-between gap-5",children:[e.jsx(s.CardTitle,{className:"text-base",children:e.jsx(s.EditableText,{value:a.title,onSave:b=>f({...a,title:b}),isEditable:!0,placeholder:"Add title",displayClassName:"text-base font-semibold",inputClassName:"text-base font-semibold"})}),e.jsx(Pn,{})]}),e.jsx("div",{className:"w-1/2",children:e.jsx(s.EditableText,{value:a.description||"",onSave:b=>f({...a,description:b}),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:b=>d({...u,title:b}),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:j()})]})}const Xe=({language:t,value:n,onChange:a,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:n,onChange:a}),Vn=()=>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."})]})]}),zn=({customCode:t,cardCustomCfgString:n,mergedConfig:a,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(Xe,{language:"json",value:a,onChange:r})}),e.jsx(s.TabsContent,{value:"custom-config",className:"mt-0 grow rounded-b border border-t-0",children:e.jsx(Xe,{readonly:!0,language:"json",value:n,onChange:()=>{}})}),e.jsx(s.TabsContent,{value:"custom-code",className:"mt-0 grow rounded-b border border-t-0",children:e.jsx(Xe,{language:"javascript",value:t,onChange:l})})]}),Un=({error:t,hasCardCustomConfig:n,onReset:a,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:!n,onClick:a,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 Gn(){const[t,n]=T.useState(!1),[a,r]=T.useState(""),[l,o]=T.useState(""),[c,i]=T.useState(""),[d,u]=T.useState(""),m=s.useEditorStore(D=>D.card),x=s.useEditorStore(D=>D.card.customCfg),h=x?JSON.stringify(x,null,2):"",{data:p}=s.useDashboardCardQuery(m),{data:g}=s.useTopoJson(m),{setCardCustomCfg:f,setCustomVisualCode:y}=s.useEditorActions(),v=D=>{var w,j;return JSON.stringify({...D,data:{...D.data,datasets:(j=(w=D.data)==null?void 0:w.datasets)==null?void 0:j.map(N=>({...N,data:[]}))}},null,2)},C=()=>{var w,j;if(!((w=p==null?void 0:p.records)!=null&&w.length))return;const D=s.createChartConfig({card:m,data:p.records,cardType:m.type,queryConfig:m.queryConfig,preferences:m.preferences,topoJson:g});if(D){r(v(D)),i(((j=m.preferences)==null?void 0:j.customVisualCode)||"");const N=s.merge(D,x);o(v(N))}},F=()=>{try{if(c&&y(c),l){const D=JSON.parse(l),w=s.getObjectDiff(JSON.parse(a),D);f(w),u("")}}catch{u("Invalid JSON configuration")}},k=Object.keys(x||{}).length===0;return e.jsxs(s.Dialog,{open:t,onOpenChange:n,children:[e.jsx(s.DialogTrigger,{asChild:!0,children:e.jsx(s.IconButton,{tooltip:"Customize Visual",onClick:C,className:k?"":"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(Vn,{}),e.jsxs("div",{className:"flex grow gap-2",children:[e.jsx(s.ErrorBoundary,{FallbackComponent:s.FallbackVisual,children:e.jsx(ht,{className:"w-1/2 rounded shadow-none"})}),e.jsx(zn,{customCode:c,cardCustomCfgString:h,mergedConfig:l,onConfigChange:D=>o(D??""),onCodeChange:D=>i(D??"")})]}),e.jsx(Un,{error:d,hasCardCustomConfig:!!x,onReset:()=>{o(a),f(null)},onApply:F,onClose:()=>n(!1)})]})]})}function Je(t){const[n,a]=T.useState(null);return n}function xt(){const{authToken:t,tokenProps:n}=s.useSemaphorContext(),{data:a,isLoading:r,isFetching:l,isError:o}=s.useQuery({queryKey:["plugins",t==null?void 0:t.accessToken],queryFn:()=>s.getPlugins(n.apiServiceUrl,t==null?void 0:t.accessToken)});return{data:a,isLoading:r,isFetching:l,isError:o}}function pt(){const{data:t,isLoading:n,isError:a}=xt(),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=n,c=a;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],x=i.data.visuals.map(h=>({name:h.name,pluginName:m.label,componentType:h.componentType,pluginType:m.type,icon:h.icon,chartType:h.chartType,url:m.value}));l.push(...x)}}),{data:l,isLoading:o,isError:c}}function _n({onChartTypeChange:t}){const{setCardCustomCfg:n,setCardPreferences:a,setCardType:r,setCustomCardPreferences:l}=s.useEditorActions(),{data:o,isLoading:c,isError:i}=pt(),d=T.useCallback((u,m)=>{n(null),a({}),r(u),m&&l({type:"component",visualType:"single",url:m.url,componentName:m.name,icon:m.icon}),t==null||t()},[n,a,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($n,{text:u.name,onClick:()=>d("custom",u),icon:u.icon},`${u.url}-${u.name}-${m}`))})]})}const $n=({text:t,icon:n,onClick:a})=>{const r=Je(),l=t.charAt(0).toUpperCase();return e.jsx(s.IconButton,{onClick:a,tooltip:t,children:r?e.jsx(r,{className:"h-4 w-4"}):l})};function Yn({onChartTypeChange:t,iconClassName:n}){const{setCardType:a,setCardPreferences:r,setIsDevMode:l}=s.useEditorStore(m=>m.actions),{setCardCustomCfg:o,setCustomCardPreferences:c,setQueryConfig:i}=s.useEditorActions();function d(m,x){o(null),r({}),a(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",n)})}),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",n)})}),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",n)})}),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",n)})}),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",n),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",n)})}),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",n)})}),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",n)})}),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",n)})}),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",n)})}),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",n)})}),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",n)})}),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",n)})}),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",n)})}),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",n)})}),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",n)})}),e.jsx(s.IconButton,{tooltip:"Map",onClick:()=>d("map"),className:"h-10 p-4",children:e.jsx(s.Map,{className:s.cn("size-5",n)})}),e.jsx(s.IconButton,{openDelay:u,tooltip:"Custom",onClick:()=>d("custom"),className:"h-10 p-4",children:e.jsx(Ve,{className:s.cn("size-5",n)})})]})}function qn({chartType:t,className:n,customIcon:a,componentName:r}){const l=Je();switch(t){case"bar":return e.jsx(s.ChartColumnIncreasing,{className:n});case"line":return e.jsx(s.ChartLine,{className:n});case"pie":return e.jsx(s.ChartPie,{className:n});case"radar":return e.jsx(s.Radar,{className:n});case"scatter":return e.jsx(s.ChartScatter,{className:n});case"bubble":return e.jsx(s.TbChartBubble,{className:n});case"doughnut":return e.jsx(s.Donut,{className:n});case"stackedBar":return e.jsx(s.ChartColumnStacked,{className:n});case"stackedLine":return e.jsx(s.MdStackedLineChart,{className:n});case"polarArea":return e.jsx(s.PiChartPolar,{className:n});case"funnel":return e.jsx(s.TbChartFunnel,{className:n});case"tornado":case"pyramid":return e.jsx(s.Tornado,{className:n});case"range":return e.jsx(s.ChartNoAxesGantt,{className:n});case"kpi":return e.jsx(s.TiSortNumerically,{className:n});case"text":return e.jsx(qe,{className:n});case"map":return e.jsx(s.Map,{className:n});case"custom":return a&&l?e.jsx(l,{className:n}):r?r==null?void 0:r.charAt(0).toUpperCase():e.jsx(Ve,{className:n});default:return e.jsx(s.Table2,{className:n})}}function ft({variant:t="ghost"}){var o,c;const[n,a]=T.useState(!1),r=s.useEditorStore(i=>i.card),l=r.type;return s.useDashboardStore(i=>i.isVisualEditing),e.jsxs(s.Popover,{open:n,onOpenChange:a,children:[e.jsx(s.PopoverTrigger,{asChild:!0,children:e.jsx(s.Button,{size:"sm",variant:t||"ghost",children:e.jsx(qn,{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:"z-[51] w-72 p-1",children:[e.jsx(Yn,{onChartTypeChange:()=>a(!1)}),e.jsx(_n,{onChartTypeChange:()=>a(!1)})]})]})}function Kn({error:t,className:n="",textClassName:a="",copyButtonClassName:r=""}){const[l,o]=T.useState(!1),c=T.useRef(null),i=T.useRef(!1);function d(){t&&!i.current&&navigator.clipboard.writeText(t)}function u(h){(h.key==="Enter"||h.key===" ")&&(h.preventDefault(),d())}function m(){const h=window.getSelection();if(h&&h.toString().trim()!==""){const p=h.toString();navigator.clipboard.writeText(p),o(!0),i.current=!0,setTimeout(()=>{o(!1),i.current=!1},1e3)}else i.current=!1}function x(){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 ${n}`,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 ${a}`,onClick:d,onKeyDown:u,onMouseUp:m,onMouseDown:x,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 Qn(){const t=s.useEditorStore(o=>{var c,i;return(i=(c=o.card.preferences)==null?void 0:c.chartOptions)==null?void 0:i.indexAxis}),n=s.useEditorStore(o=>o.card.type),{setChartOrientation:a}=s.useEditorStore(o=>o.actions);function r(){return e.jsx(s.IconButton,{onClick:()=>{a(t==="x"||t===void 0?"y":"x")},tooltip:"Chart Orientation",children:t==="x"||t===void 0?e.jsx(ys,{className:"size-4"}):e.jsx(vs,{className:"size-4"})})}function l(){return e.jsx(s.IconButton,{onClick:()=>{a(t==="y"||t===void 0?"x":"y")},tooltip:"Chart Orientation",children:t==="y"||t===void 0?e.jsx(ys,{className:"size-4"}):e.jsx(vs,{className:"size-4"})})}return e.jsx(e.Fragment,{children:n==="funnel"?l():r()})}function Hn({className:t}){var h,p,g,f,y,v,C,F;const n=s.useEditorStore(k=>k.card),{setCardPreferences:a,updateCardInFrame:r,setCard:l}=s.useEditorActions(),[o,c]=T.useState(!1),i=((p=(h=n.preferences)==null?void 0:h.displayOptions)==null?void 0:p.showFilterInfo)??!0,d=((f=(g=n.preferences)==null?void 0:g.displayOptions)==null?void 0:f.showCardToolbar)??!0,u=((v=(y=n.preferences)==null?void 0:y.displayOptions)==null?void 0:v.showChrome)??!0,m=((F=(C=n.preferences)==null?void 0:C.displayOptions)==null?void 0:F.allowScroll)??!0,x=(k,D)=>{var N;const w={...n.preferences,displayOptions:{...(N=n.preferences)==null?void 0:N.displayOptions,[k]:D}};a(w);const j={...n,preferences:w};l(j),r(j)};return e.jsx("div",{className:s.cn("flex items-center",t),children:e.jsxs(s.DropdownMenu,{modal:!1,open:o,onOpenChange:c,children:[e.jsx(s.DropdownMenuTrigger,{asChild:!0,children:e.jsx(s.IconButton,{className:"h-8 w-8 p-0",tooltip:"Display Options",children:e.jsx(Vs,{className:"h-4 w-4"})})}),e.jsxs(s.DropdownMenuContent,{align:"end",className:"w-64",children:[e.jsx(s.DropdownMenuLabel,{children:"Display Options"}),e.jsx(s.DropdownMenuSeparator,{}),e.jsx("div",{className:"px-2 py-1.5",children:e.jsx("p",{className:"mb-2 text-xs text-muted-foreground",children:"Changes apply to dashboard view only"})}),e.jsxs(s.DropdownMenuCheckboxItem,{checked:i,onCheckedChange:k=>{x("showFilterInfo",k)},onSelect:k=>k.preventDefault(),className:"pr-2",children:[e.jsx("span",{className:"flex-1",children:"Filter Info"}),e.jsx("span",{className:"ml-4 text-xs text-muted-foreground",children:"Badge"})]}),e.jsxs(s.DropdownMenuCheckboxItem,{checked:d,onCheckedChange:k=>{x("showCardToolbar",k)},onSelect:k=>k.preventDefault(),className:"pr-2",children:[e.jsx("span",{className:"flex-1",children:"Card Toolbar"}),e.jsx("span",{className:"ml-4 text-xs text-muted-foreground",children:"Hover actions"})]}),e.jsxs(s.DropdownMenuCheckboxItem,{checked:u,onCheckedChange:k=>{x("showChrome",k)},onSelect:k=>k.preventDefault(),className:"pr-2",children:[e.jsx("span",{className:"flex-1",children:"Card Chrome"}),e.jsx("span",{className:"ml-4 text-xs text-muted-foreground",children:"Frame & padding"})]}),e.jsxs(s.DropdownMenuCheckboxItem,{checked:m,onCheckedChange:k=>{x("allowScroll",k)},onSelect:k=>k.preventDefault(),className:"pr-2",children:[e.jsx("span",{className:"flex-1",children:"Allow Scroll"}),e.jsx("span",{className:"ml-4 text-xs text-muted-foreground",children:"Card content scroll"})]})]})]})})}function gt(){const t=s.useEditorStore(o=>o.card),n=s.useEditorStore(o=>{var c,i;return(i=(c=o.card)==null?void 0:c.preferences)==null?void 0:i.chartOptions}),a=s.getChartGridStyle(n),{setChartGrid:r}=s.useEditorActions();function l(){const o=["xy","none","x","y"],i=(o.indexOf(a)+1)%o.length;r(o[i])}return e.jsxs("div",{"data-info":"visual-settings",className:"flex items-center gap-2",children:[["line","bar","range","stackedBar","stackedLine","horizontalBar","funnel"].includes(t.type)&&e.jsx(e.Fragment,{children:e.jsx(Qn,{})}),!["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:l,children:[(a==="xy"||!a)&&e.jsx(He,{className:"size-4"}),a==="x"&&e.jsx(Gt,{className:"size-4"}),a==="y"&&e.jsx(ca,{className:"size-4"}),a==="none"&&e.jsx(ha,{className:"size-4"})]}),e.jsx(Hn,{})]})}function Wn(){const t=s.useEditorStore(g=>g.frame),n=s.useEditorStore(g=>g.card),{setFrame:a,setActiveTabCardId:r,setCard:l,updateCardInFrame:o}=s.useEditorActions(),c=(g,f)=>{g.dataTransfer.setData("tabIndex",f.toString())},i=g=>{g.preventDefault()},d=(g,f)=>{const y=g.dataTransfer.getData("tabIndex");if(y===f.toString())return;const v=Array.from(t.cards),[C]=v.splice(parseInt(y),1);v.splice(f,0,C),a({...t,cards:v})};function u(g){const f=t.cards.filter(C=>C.id!==g),y=f[0],v={...t,cards:f,activeCardId:y.id};a(v),r(y.id),l(y)}function m(g,f){const y={...t,cards:[...t.cards,f],activeCardId:g.id};a(y),r(f.id)}function x(){const g={...n,id:s.v4(),title:`${n.title} Copy`,tabTitle:`${n.tabTitle||n.title} Copy`};m(n,g)}function h(g){const f={dataSource:g.dataSource,connectionId:g.connectionId,lastSelectedDatabase:g.lastSelectedDatabase,lastSelectedSchema:g.lastSelectedSchema,lastSelectedTable:g.lastSelectedTable,lastSelectedDatamodelId:g.lastSelectedDatamodelId,id:s.v4(),title:"Title",description:"",preferences:{onClickFilter:[{columnIndex:0,expression:""}]},type:"bar",sql:"",data:[],mode:"explorer"};m(g,f)}function p(g,f){return g.cards.length===1&&(f.displayTab===!0||f.displayTab===void 0)||g.activeCardId!==f.id&&(f.displayTab===!0||f.displayTab===void 0)?null:e.jsx("div",{onClick:()=>{const y=f.displayTab===void 0?!1:!f.displayTab;l({...f,displayTab:y}),o({...f,displayTab:y})},children:f.displayTab===!0||f.displayTab===void 0?e.jsx(s.Eye,{className:"mr-2 size-3.5 text-muted-foreground hover:text-foreground"}):e.jsx(qt,{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((g,f)=>e.jsxs(s.TabsTrigger,{draggable:!0,onDragStart:y=>c(y,f),onDragOver:i,onDrop:y=>d(y,f),className:"",value:g.id,children:[p(t,g),e.jsx(s.Editable,{enabled:t.activeCardId===g.id,text:g.tabTitle||g.title,onSave:y=>{l({...n,tabTitle:y}),o({...n,tabTitle:y})},children:g.tabTitle||g.title},g.id),t.activeCardId===g.id&&e.jsx(s.CopyPlus,{className:"ml-2 size-3.5 text-muted-foreground hover:text-foreground",onClick:y=>{y.stopPropagation(),x()}}),t.activeCardId===g.id&&t.cards.length>1&&e.jsx(s.X,{className:"ml-2 size-3.5 text-muted-foreground hover:text-foreground",onClick:()=>u(g.id)})]},g.id)),e.jsx(s.IconButton,{tooltip:"Add Card",className:"ml-1 h-8 px-2 hover:bg-muted-foreground/50",onClick:()=>h(n),children:e.jsx(s.Plus,{className:"h-4 w-4"})})]})})}function jt(){const t=s.useEditorStore(f=>f.frame),n=s.useEditorStore(f=>f.card),a=s.useEditorStore(f=>f.isSqlRunning),r=s.useEditorStore(f=>f.isDevMode),{setFrame:l,setActiveTabCardId:o,setCard:c,setIsDevMode:i,setRunSql:d}=s.useEditorActions(),{data:u,isLoading:m,isFetching:x}=s.useDashboardCardQuery(n);function h(f){const y=t.cards.find(v=>v.id===f);if(y!=null&&y.sql){r||i(!0),o(f);return}if(y!=null&&y.queryConfig){r&&i(!1),p(f),o(f);return}r||p(f),o(f)}function p(f){const y={...t,cards:t.cards.map(C=>C.id===n.id?n:C),activeCardId:f};l(y);const v=y.cards.find(C=>C.id===f);v.sql&&d(!0),c(v)}function g(){return n.type==="kpi"?m||x?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:n,data:u==null?void 0:u.records,isPending:m||x})})}):n.type==="text"?m||x?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:a,card:n,data:u==null?void 0:u.records})})})}):e.jsx(s.ErrorBoundary,{FallbackComponent:s.FallbackVisual,children:e.jsx(ht,{className:"grow border-none shadow-none"})})}return e.jsxs(s.Tabs,{onValueChange:h,value:t.activeCardId,className:"flex grow flex-col",children:[t.cards.map(f=>e.jsx(s.TabsContent,{className:"mt-0 grow",value:f.id,children:g()},f.id)),e.jsx(Wn,{})]})}function Ts({children:t}){var w,j;s.useEditorStore(N=>N.frame);const n=s.useEditorStore(N=>N.card),a=s.useEditorStore(N=>N.isDevMode),r=s.useEditorStore(N=>N.isShowingVisual),l=s.useDashboardStore(N=>N.isVisualEditing),o=s.useEditorStore(N=>N.pythonStdOut);s.useEditorStore(N=>N.actions.setRunSql);const{setFrame:c,setCard:i,setActiveTabCardId:d,runAssistant:u,setIsDevMode:m,setCardPreferences:x}=s.useEditorActions(),{data:h,isLoading:p,isFetching:g,errorMessage:f,refetch:y}=s.useDashboardCardQuery(n),[v,C]=T.useState(!1);T.useEffect(()=>{g||C(!1)},[g]);function F(){const N=JSON.stringify(h==null?void 0:h.records,null,2),b=new Blob([N],{type:"application/json"}),R=URL.createObjectURL(b),S=document.createElement("a");S.href=R,S.download=`${n.title}.json`,S.click()}function k(){const b=[Object.keys(h==null?void 0:h.records.reduce((E,I)=>({...E,...I}),{})).join(","),...((h==null?void 0:h.records)||[]).map(E=>Object.values(E).join(","))].join(`
|
|
279
|
-
`),R=new Blob([b],{type:"text/csv"}),S=URL.createObjectURL(R),O=document.createElement("a");O.href=S,O.download=`${n.title}.csv`,O.click()}function D(){const N=`Can you get the documentation for ${n.type} chart?`;u(N)}return n?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(ft,{}),l&&e.jsx(s.IconButton,{tooltip:"Visual Docs",onClick:D,children:e.jsx(Vt,{className:"size-4"})}),!["table","custom"].includes(n.type)&&l&&e.jsx(Gn,{})]}),!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:k,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:F,children:e.jsx(Qt,{strokeWidth:1.5,className:"size-4"})}),e.jsx(s.CopyButton,{text:JSON.stringify(h==null?void 0:h.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(s.IconButton,{tooltip:"Refresh",disabled:p||g,onClick:()=>{C(!0),y()},children:e.jsx(s.RefreshCcw,{className:s.cn("h-4 w-4",{"animate-spin":v})})}),e.jsx(gt,{})]}),n.type==="table"&&n.sql&&!s.hasValidCardConfig(n.config)&&e.jsxs("div",{className:"mr-2 flex items-center gap-3",children:[e.jsx(s.Checkbox,{id:"pagination",checked:((j=(w=n.preferences)==null?void 0:w.tablePrefs)==null?void 0:j.enableDevModePagination)??!1,onCheckedChange:N=>{var b;x({...n.preferences,tablePrefs:{...(b=n.preferences)==null?void 0:b.tablePrefs,enableDevModePagination:N}}),y()}}),e.jsx(s.Label,{htmlFor:"pagination",children:"Paginate Results"})]}),a&&e.jsx(Xn,{})]}),r?e.jsx(jt,{}):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(Jn,{})}),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:[(h==null?void 0:h.records)&&(h==null?void 0:h.records.length)>0&&e.jsx(s.TableVisual,{card:n,data:(h==null?void 0:h.records)||[]}),f&&e.jsx(Kn,{error:f})]})]})]}):e.jsx(e.Fragment,{children:"No Active Card"})}function Jn(){const t=s.useEditorStore(a=>a.pythonStdOut);if(!t)return null;const n=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:n}}),e.jsx(s.ScrollBar,{orientation:"horizontal"})]})]})}function Xn(){const t=s.useEditorStore(a=>a.isShowingVisual),n=s.useEditorStore(a=>a.actions.setIsShowingVisual);return e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(s.Label,{htmlFor:"visualize",children:"Chart"}),e.jsx(s.SmallSwitch,{checked:t,onCheckedChange:()=>n(!t),id:"visualize",className:"data-[state=checked]:bg-foreground/50"})]})}function Se({defaultValue:t,label:n,options:a,value:r,onValueChange:l,className:o,icon:c,showPlaceholderLabel:i=!0}){return e.jsxs(s.Select,{defaultValue:t,value:r,onValueChange:l,children:[e.jsx(s.SelectTrigger,{className:s.cn("w-full focus:ring-0 focus:ring-offset-0",o),children:e.jsxs("div",{className:"flex items-center gap-2",children:[c&&e.jsx("span",{children:c}),i&&e.jsx(s.SelectValue,{placeholder:n})]})}),e.jsx(s.SelectContent,{children:e.jsxs(s.SelectGroup,{children:[e.jsx(s.SelectLabel,{children:n}),a.map(d=>e.jsx(s.SelectItem,{value:d.value,children:d.label},d.value))]})})]})}function Zn(){var f,y;const t=s.useEditorStore(v=>v.card.customCardPreferences),{data:n}=xt(),a=(n==null?void 0:n.plugins)||[],r=s.useEditorStore(v=>v.card),l=s.useEditorStore(v=>v.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=(f=d==null?void 0:d.visuals)==null?void 0:f.find(v=>v.name===(t==null?void 0:t.componentName));function m(v,C){if(!t)return;const k={...(t==null?void 0:t.dataInputCardIds)||{},[v]:{cardId:C,hookRef:null}};c({...t,dataInputCardIds:k})}function x(v){var F,k;const C=(F=l==null?void 0:l.cards)==null?void 0:F.filter(D=>{var w;return((w=D==null?void 0:D.customCardPreferences)==null?void 0:w.visualType)!=="multiple"}).map(D=>({value:D.id,label:D.tabTitle||D.title}));return e.jsx("div",{className:"space-y-2",children:(k=v==null?void 0:v.dataInputs)==null?void 0:k.map((D,w)=>{var j,N;return e.jsxs("div",{className:"grid grid-cols-10 gap-2",children:[e.jsx("div",{className:"col-span-4 flex items-center",children:D}),e.jsx(Se,{className:"col-span-6 h-8 w-full justify-between",label:"",options:C||[],value:((N=(j=t==null?void 0:t.dataInputCardIds)==null?void 0:j[w])==null?void 0:N.cardId)||"",onValueChange:b=>m(w,b)})]},w+Math.random())})})}function h(v,C,F=[],k=""){var D,w;return t?v==="input"?e.jsx(s.Input,{className:`h-8 w-full ${s.removeRing}`,value:((D=t==null?void 0:t.settings)==null?void 0:D[C])||k,onChange:j=>{c({...t,settings:{...t==null?void 0:t.settings,[C]:j.target.value}})}},C):v==="select"?e.jsx(Se,{className:"h-8 w-full",label:"",options:F,value:((w=t==null?void 0:t.settings)==null?void 0:w[C])||k,onValueChange:j=>{c({...t,settings:{...t==null?void 0:t.settings,[C]:j}})}}):null:null}function p(v){const C=Object.entries((v==null?void 0:v.settings)||{});return e.jsx("div",{className:"space-y-3",children:C.map(([F,k])=>e.jsxs("div",{className:"space-y-1",children:[e.jsx(s.Label,{children:k.title}),h(k.ui,F,k.options,k.defaultValue)]},F))})}function g(v){t&&c({...t,visualType:v,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(Se,{icon:e.jsx(Bt,{className:"h-3.5 w-3.5"}),className:"h-9 w-full",label:"Select Plugin",options:a,value:(t==null?void 0:t.url)||"",onValueChange:v=>c({...t||{url:"",componentName:""},url:v})}),((t==null?void 0:t.type)==="component"||(t==null?void 0:t.type)===void 0)&&e.jsx(s.Tabs,{value:o,onValueChange:g,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(Se,{icon:e.jsx(_t,{className:"h-3.5 w-3.5"}),className:"h-9 w-full",label:"Select Component",options:(i==null?void 0:i.filter(v=>v.type===o).map(v=>({value:v.name,label:v.name})))||[],value:t.componentName,onValueChange:v=>{console.log("changing value",v),c({...t,componentName:v})}})})]})})]}),((y=r==null?void 0:r.customCardPreferences)==null?void 0:y.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:x(u)})]}),u&&u.settings&&e.jsx("div",{className:"space-y-3",children:e.jsx("div",{className:"px-2",children:p(u)})})]})]})]})}function Me(){const[t,n]=T.useState([]),a=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}),T.useEffect(()=>{o&&n(new Array(o.length).fill(!1))},[o]);function c(u,m){var x,h;m?a!=null&&a.onClickFilter&&((x=a==null?void 0:a.onClickFilter)==null?void 0:x.length)>0?l({...a,onClickFilter:[...a.onClickFilter,{columnIndex:u,expression:""}]}):l({...a,onClickFilter:[{columnIndex:u,expression:""}]}):(l({...a,onClickFilter:(h=a==null?void 0:a.onClickFilter)==null?void 0:h.filter(p=>p.columnIndex!==u)}),n(p=>{const g=[...p];return g[u]=!1,g}))}function i(u,m){var h;const x=(h=a==null?void 0:a.onClickFilter)==null?void 0:h.map(p=>p.columnIndex===u?{...p,expression:m.target.value}:p);l({...a,onClickFilter:x})}function d(u){var m,x,h,p;if(t!=null&&t[u]||(x=(m=a==null?void 0:a.onClickFilter)==null?void 0:m.find(g=>g.columnIndex===u))!=null&&x.expression)return e.jsx(s.Input,{value:(p=(h=a==null?void 0:a.onClickFilter)==null?void 0:h.find(g=>g.columnIndex===u))==null?void 0:p.expression,onChange:g=>i(u,g),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 x,h;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:!!((x=a==null?void 0:a.onClickFilter)!=null&&x.find(p=>p.columnIndex===m)),onCheckedChange:p=>c(m,p)}),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:((h=a==null?void 0:a.onClickFilter)==null?void 0:h.find(p=>p.columnIndex===m))&&e.jsx(s.Pencil,{onClick:()=>{n(p=>{const g=[...p];return g[m]=!p[m],g})},className:"invisible size-3 cursor-pointer text-gray-400 group-hover:visible"})})]}),d(m)]})},u)})})}function er({idx:t}){var i;const n=s.useEditorStore(d=>{var u;return(u=d.card)==null?void 0:u.preferences}),a=s.useEditorStore(d=>{var u;return(u=d.card.preferences)==null?void 0:u.datasetOptions}),r=s.useEditorStore(d=>d.actions.setCardPreferences),l=(i=n==null?void 0:n.chartOptions)==null?void 0:i.indexAxis,o=a==null?void 0:a.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({...n,datasetOptions:[...a||[],{idx:u,datalabels:m}]});else{const x={...o};x.datalabels=m;const h=a==null?void 0:a.map(p=>p.idx===u?x:p);r({...n,datasetOptions:h})}}return e.jsxs(s.Popover,{children:[e.jsx(s.PopoverTrigger,{children:e.jsx(zs,{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(ea,{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(ta,{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(sa,{className:s.cn("h-4 w-4",{"rotate-90":l==="y"})})})]})})]})}function sr(){const t=s.useEditorStore(o=>o.card),{data:n}=s.useDashboardCardQuery(t),{keys:a}=s.getKeys((n==null?void 0:n.records)||[]),r=a.slice(1).filter(o=>!s.METADATA_KEYS.includes(o));let l=r;if(["stackedBar","stackedLine"].includes(t.type)){const o=s.pivotData({dataArray:(n==null?void 0:n.records)||[],groupKey:a[0],pivotKey:a[1],valueKey:a[2]}),{keys:c}=s.getKeys(o);l=c.slice(1)}return{transformedMetricKeys:l,dimensionKeys:a.slice(0,1),keys:a,defaultMetricKeys:r}}function us({children:t,className:n,delayDuration:a}){return e.jsx(s.TooltipProvider,{children:e.jsxs(s.Tooltip,{delayDuration:a,children:[e.jsx(s.TooltipTrigger,{asChild:!0,children:e.jsx("span",{className:s.cn("overflow-hidden text-ellipsis whitespace-nowrap",n),children:t})}),e.jsx(s.TooltipContent,{children:t})]})})}function bt(){const t=s.useEditorStore(d=>d.card),n=s.useEditorStore(d=>{var u,m,x;return(x=(m=(u=d==null?void 0:d.card)==null?void 0:u.preferences)==null?void 0:m.chartOptions)==null?void 0:x.indexAxis}),{data:a}=s.useDashboardCardQuery(t),r=n==="y"?"Metric":"Dimension",l=n==="y"?"Dimension":"Metric",{dimensionKeys:o,transformedMetricKeys:c,keys:i}=sr();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:vt(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(yt,{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 vt(t,n=30){return t.length>n?t.slice(0,n)+"...":t}function yt({col:t,idx:n,className:a,iconClassName:r,children:l}){const o=s.useEditorStore(m=>{var x;return(x=m.card)==null?void 0:x.preferences}),c=s.useEditorStore(m=>{var x,h;return(h=(x=m.card)==null?void 0:x.preferences)==null?void 0:h.datasetOptions}),i=c==null?void 0:c.find(m=>m.idx===n),{setCardPreferences:d}=s.useEditorStore(m=>m.actions);function u(m){if(!i)d({...o,datasetOptions:[...c||[],{idx:n,type:m==="area"?"line":m,fill:m==="area"?"origin":""}]});else{const x={...i};x.type=m==="area"?"line":m,x.fill=m==="area"?"origin":"";const h=c==null?void 0:c.map(p=>p.idx===n?x:p);d({...o,datasetOptions:h})}}return e.jsxs("div",{className:s.cn("group flex items-center justify-between gap-2 rounded-md",a),children:[l||e.jsx(us,{className:"max-w-[100px]",title:t,children:vt(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(er,{idx:n})]})]})}function Pe(){const t=s.useDashboardStore(i=>i.dashboard.filters),n=s.useEditorStore(i=>i.frame),{setFrame:a}=s.useEditorActions(),{columns:r}=s.useEditorAside(),{assignFilter:l}=lt();function o(i){const d=l(i,"frame");a({...n,filterId:d})}const c=t==null?void 0:t.find(i=>i.id===n.filterId);return e.jsxs("div",{className:"space-y-3",children:[e.jsx(s.Label,{children:"Card Filter"}),e.jsx(tr,{onSelect:o,columns:r}),c&&e.jsx(s.FilterHeader,{filter:c})]})}function tr({columns:t,onSelect:n}){var c;const[a,r]=ss.useState(!1),[l,o]=ss.useState("");return e.jsxs(s.Popover,{open:a,onOpenChange:r,children:[e.jsx(s.PopoverTrigger,{asChild:!0,children:e.jsxs(s.Button,{size:"sm",variant:"outline",role:"combobox","aria-expanded":a,className:"w-full justify-between font-normal",children:[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&&n(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 ar({cardType:t}){return e.jsx("div",{className:"space-y-6 px-6 py-2",children:e.jsxs(s.Accordion,{defaultValue:["item-2"],type:"multiple",children:[e.jsxs(s.AccordionItem,{value:"item-1",children:[e.jsx(s.AccordionTrigger,{children:`${s.titleCase(t)} Chart`}),e.jsxs(s.AccordionContent,{className:"space-y-4 font-mono text-xs",children:[e.jsx("div",{className:"rounded bg-muted px-2 py-1 text-xs",children:"SELECT x-axis, y-axis-1, y-axis-2,... FROM table"}),e.jsxs("ul",{className:"ml-6 list-disc text-xs [&>li]:mt-2",children:[e.jsx("li",{children:"x-axis - category"}),e.jsx("li",{children:"y-axis1 - number"}),e.jsx("li",{children:"y-axis2 - number"})]}),e.jsxs("div",{children:["See ",e.jsx("a",{target:"_blank",onClick:n=>n.stopPropagation(),className:"text-blue-700",href:"https://docs.semaphor.cloud/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(bt,{})})]}),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(Me,{}),e.jsx(Pe,{})]})]})]})})}function nr({cardType:t}){function n(a){return e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"rounded bg-muted px-2 py-1 text-xs",children:a==="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"}),a==="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:n(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(Me,{}),e.jsx(Pe,{})]})]})]})})}function Nt(){const t=s.useEditorStore(i=>i.card.type),n=s.useEditorStore(i=>i.isDevMode),a=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={...a,chartOptions:{...a==null?void 0:a.chartOptions,plugins:{...(m=a==null?void 0:a.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=a==null?void 0:a.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=a==null?void 0:a.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:n?o():c()})}const rr={datasets:[{type:"line",label:"Sum_sales",data:[]},{type:"bar",label:"Sum_profit",data:[]}]},lr={datasets:[{fill:"origin",type:"line",label:"Sum_sales",data:[]}]};function or(){const t=s.useEditorStore(n=>n.card.type);return e.jsxs("div",{className:"space-y-6 p-6",children:[e.jsx(s.Accordion,{className:" ",type:"single",collapsible:!0,children:ir(t)}),!["kpi"].includes(t)&&e.jsxs("div",{className:"space-y-4",children:[e.jsx(Nt,{}),e.jsx(Me,{}),e.jsx(Pe,{})]})]})}function ir(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(rr,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(lr,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 cr({colorRanges:t,setColorRanges:n}){const a={start:-1/0,end:100,color:""};function r(c,i,d){const u=[...t];u[c]={...u[c],[i]:d},n(u)}function l(c){const i=[...t];i.splice(c,1),n(i)}function o(){n([...t,a])}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 dr(){var m,x,h,p,g;const t=s.useEditorStore(f=>f.card.preferences),n=s.useEditorStore(f=>f.actions.setCardPreferences),a=s.useEditorStore(f=>f.card),r=s.isExplorerCard(a),l=s.useEditorStore(f=>f.actions.setNumberFormat);s.useEditorStore(f=>{var y,v;return(v=(y=f.card.preferences)==null?void 0:y.formatNumber)==null?void 0:v.decimalPlaces});const o=s.useEditorStore(f=>{var y,v;return(v=(y=f.card.preferences)==null?void 0:y.formatNumber)==null?void 0:v.locale}),c=s.useEditorStore(f=>{var y,v;return(v=(y=f.card.preferences)==null?void 0:y.formatNumber)==null?void 0:v.currency});s.useEditorStore(f=>f.actions.setFilterOnClickField);const i=s.useEditorStore(f=>{var y,v;return(v=(y=f.card.preferences)==null?void 0:y.formatNumber)==null?void 0:v.colorRanges})||[],d=s.useEditorStore(f=>f.actions.setColorRanges),u=[...new Set(s.LOCALE_CURRENCY_PAIRS.map(f=>f.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:f=>{n({...t,formatNumber:{...t==null?void 0:t.formatNumber,enabled:f}})}}),e.jsx(s.Label,{children:"Format Number"})]}),(((x=t==null?void 0:t.formatNumber)==null?void 0:x.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:f=>{var y,v,C;return l(((y=t==null?void 0:t.formatNumber)==null?void 0:y.decimalPlaces)||0,((v=t==null?void 0:t.formatNumber)==null?void 0:v.currency)||"",f,((C=t==null?void 0:t.formatNumber)==null?void 0:C.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(f=>e.jsx(s.SelectItem,{value:f.locale,children:f.locale},f.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:f=>{var y,v,C;console.log("currency",f),l(((y=t==null?void 0:t.formatNumber)==null?void 0:y.decimalPlaces)||0,f==="none"?"":f,((v=t==null?void 0:t.formatNumber)==null?void 0:v.locale)||"",((C=t==null?void 0:t.formatNumber)==null?void 0:C.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(f=>e.jsx(s.SelectItem,{value:f,children:f},f))]})})]})]})]}),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:((p=(h=t==null?void 0:t.formatNumber)==null?void 0:h.decimalPlaces)==null?void 0:p.toString())||"0",onValueChange:f=>{var y,v,C;return l(Number(f),((y=t==null?void 0:t.formatNumber)==null?void 0:y.currency)||"",((v=t==null?void 0:t.formatNumber)==null?void 0:v.locale)||"",((C=t==null?void 0:t.formatNumber)==null?void 0:C.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(f=>e.jsx(s.SelectItem,{value:f,children:f},f))})]})]}),e.jsxs("div",{className:"w-full space-y-1",children:[e.jsx(s.Label,{children:"Suffix"}),e.jsx(s.Input,{value:((g=t==null?void 0:t.formatNumber)==null?void 0:g.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:f=>{var y,v,C;return l(((y=t==null?void 0:t.formatNumber)==null?void 0:y.decimalPlaces)||0,((v=t==null?void 0:t.formatNumber)==null?void 0:v.currency)||"",((C=t==null?void 0:t.formatNumber)==null?void 0:C.locale)||"",f.target.value)}})]})]})]})}),e.jsx(s.Separator,{className:"my-3"}),e.jsx(cr,{colorRanges:i,setColorRanges:d})]})]})}function ur(){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(dr,{})}),e.jsx("div",{}),e.jsx("div",{})]})}function Ze({children:t,summary:n,open:a,className:r}){return e.jsxs("details",{open:a,className:s.cn("space-y-4 [&_summary>svg]:open:-rotate-180",r),children:[e.jsxs("summary",{className:"flex cursor-pointer list-none items-center justify-between gap-4",children:[e.jsx(s.Label,{children:n}),e.jsx(s.ChevronUp,{className:"h-4 w-4"})]}),e.jsx("div",{className:"transition-all ease-in-out",children:t})]})}const mr=[{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"}],hr=["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"],xr=hr.map(t=>({label:t,value:t}));function pr(){var d,u,m,x,h,p,g,f,y,v,C,F,k,D,w,j,N,b;const t=s.useEditorStore(R=>R.card),n=(u=(d=t==null?void 0:t.preferences)==null?void 0:d.mapVisualOptions)==null?void 0:u.topoJsonUrl,[a,r]=T.useState(((x=(m=t==null?void 0:t.preferences)==null?void 0:m.mapVisualOptions)==null?void 0:x.customTopoJsonUrl)||""),{setCardPreferences:l}=s.useEditorActions(),{data:o}=s.useTopoJson(t),c=Object.keys((o==null?void 0:o.objects)||{}).map(R=>({label:R,value:R}))||[],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(Ze,{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(Ze,{open:!0,summary:"Settings",children:e.jsxs("div",{className:"space-y-3 px-2",children:[e.jsx(Se,{className:"h-9",options:i,onValueChange:R=>{console.log("value",R),l({...t.preferences,mapVisualOptions:{topoJsonUrl:R}})},value:n||"",label:"Select Map"}),n==="custom"&&e.jsx(s.Input,{onChange:R=>{r(R.target.value)},onBlur:()=>{var R;console.log("onBlur",a),l({...t.preferences,mapVisualOptions:{...(R=t.preferences)==null?void 0:R.mapVisualOptions,customTopoJsonUrl:a}})},value:a,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(Se,{className:"h-9",options:c,value:((p=(h=t.preferences)==null?void 0:h.mapVisualOptions)==null?void 0:p.objectKey)||"",label:"Map Object",onValueChange:R=>{var S;l({...t.preferences,mapVisualOptions:{...(S=t.preferences)==null?void 0:S.mapVisualOptions,objectKey:R}})}})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(s.Label,{children:"Projection"}),e.jsx(Se,{className:"h-9",options:mr,value:((f=(g=t.preferences)==null?void 0:g.mapVisualOptions)==null?void 0:f.projection)||"",label:"Projection",onValueChange:R=>{var S;l({...t.preferences,mapVisualOptions:{...(S=t.preferences)==null?void 0:S.mapVisualOptions,projection:R}})}})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(s.Label,{children:"Colors"}),e.jsx(Se,{className:"h-9",options:xr,value:((v=(y=t.preferences)==null?void 0:y.mapVisualOptions)==null?void 0:v.colorScale)||"",label:"Select Color Scale",onValueChange:R=>{var S;l({...t.preferences,mapVisualOptions:{...(S=t.preferences)==null?void 0:S.mapVisualOptions,colorScale:R}})}})]})]})]})}),e.jsx(s.Separator,{className:"my-4"}),e.jsx(Ze,{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:((F=(C=t.preferences)==null?void 0:C.mapVisualOptions)==null?void 0:F.projectionScale)||1,onChange:R=>{var S;l({...t.preferences,mapVisualOptions:{...(S=t.preferences)==null?void 0:S.mapVisualOptions,projectionScale:Number(R.target.value)}})}}),e.jsx(s.Label,{children:"X"}),e.jsx(s.Input,{className:`h-9 w-full ${s.removeRing}`,type:"number",step:10,value:((w=(D=(k=t.preferences)==null?void 0:k.mapVisualOptions)==null?void 0:D.projectionOffset)==null?void 0:w[0])||0,onChange:R=>{var S,O,E,I;l({...t.preferences,mapVisualOptions:{...(S=t.preferences)==null?void 0:S.mapVisualOptions,projectionOffset:[Number(R.target.value),((I=(E=(O=t.preferences)==null?void 0:O.mapVisualOptions)==null?void 0:E.projectionOffset)==null?void 0:I[1])||0]}})}}),e.jsx(s.Label,{children:"Y"}),e.jsx(s.Input,{className:`h-9 w-full ${s.removeRing}`,type:"number",step:10,value:((b=(N=(j=t.preferences)==null?void 0:j.mapVisualOptions)==null?void 0:N.projectionOffset)==null?void 0:b[1])||0,onChange:R=>{var S,O,E,I;l({...t.preferences,mapVisualOptions:{...(S=t.preferences)==null?void 0:S.mapVisualOptions,projectionOffset:[((I=(E=(O=t.preferences)==null?void 0:O.mapVisualOptions)==null?void 0:E.projectionOffset)==null?void 0:I[0])||0,Number(R.target.value)]}})}})]})}),e.jsx(s.Separator,{className:"my-4"}),e.jsx(Me,{})]})}function fr(){var r;const t=s.useEditorStore(l=>l.card.preferences),{setCardPreferences:n}=s.useEditorStore(l=>l.actions);function a(l){n({...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:a,className:"flex gap-3",defaultValue:"x",children:[e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(s.RadioGroupItem,{value:"static",id:"r1"}),e.jsx("label",{className:"text-sm",htmlFor:"r1",children:"Static"})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(s.RadioGroupItem,{value:"dynamic",id:"r2"}),e.jsx("label",{className:"text-sm",htmlFor:"r2",children:"Dynamic"})]})]})}function Ge({cardType:t,docContent:n,suffix:a="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)} ${a}`}),e.jsx(s.AccordionContent,{children:n||e.jsxs("div",{className:"space-y-4 font-mono text-xs",children:[e.jsx("div",{className:"rounded bg-muted px-2 py-1 text-xs",children:"SELECT label, measure FROM table"}),e.jsxs("ul",{className:"ml-6 list-disc text-xs [&>li]:mt-2",children:[e.jsx("li",{children:"label - category"}),e.jsx("li",{children:"measure - number"})]}),e.jsxs("div",{children:["See ",e.jsx("a",{target:"_blank",onClick: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(fr,{})})]}),!["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(Me,{}),e.jsx(Pe,{})]})]})]})})}function gr(){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:n}=s.useEditorActions();function a(){return e.jsxs("div",{className:"space-y-2",children:[e.jsx(s.Label,{children:"Sort"}),e.jsx(Se,{className:"h-8",label:"Sort Chart",options:[{label:"None",value:"none"},{label:"ASC",value:"asc"},{label:"DESC",value:"desc"}],value:t||"none",onValueChange:r=>{n(r)}})]})}return e.jsx("div",{className:"space-y-6 px-6 py-2",children:e.jsxs(s.Accordion,{defaultValue:["item-2"],type:"multiple",children:[e.jsxs(s.AccordionItem,{value:"item-1",children:[e.jsx(s.AccordionTrigger,{children:"Stacked Chart"}),e.jsxs(s.AccordionContent,{className:"space-y-4 font-mono text-xs",children:[e.jsx("div",{className:"rounded bg-muted px-2 py-1 text-xs",children:"SELECT x-axis, stack-by, y-axis FROM table"}),e.jsxs("ul",{className:"ml-6 list-disc text-xs [&>li]:mt-2",children:[e.jsx("li",{children:"x-axis - category"}),e.jsx("li",{children:"stack by - category"}),e.jsx("li",{children:"y-axis - number"})]}),e.jsxs("div",{children:["See ",e.jsx("a",{target:"_blank",onClick:r=>r.stopPropagation(),className:"text-blue-700",href:"https://docs.semaphor.cloud/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:[a(),e.jsx(bt,{})]})]}),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(Me,{}),e.jsx(Pe,{})]})]})]})})}function jr({cardType:t="table"}){console.log("cardType",t);const n=s.useEditorStore(l=>{var o;return(o=l.card)==null?void 0:o.preferences}),a=s.useEditorStore(l=>l.actions.setCardPreferences),r=l=>{a({...n,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(Me,{}),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 Ct({color:t,onColorChange:n,onClose:a}){const[r,l]=T.useState(0),[o,c]=T.useState(100),[i,d]=T.useState(50),[u,m]=T.useState(t);T.useEffect(()=>{const y=ks(t);if(y){const v=Es(y.r,y.g,y.b);l(v.h),c(v.s),d(v.l),m(t)}},[t]);const x=y=>{l(y),p(y,o,i)},h=y=>{const v=y.currentTarget.getBoundingClientRect(),C=Math.max(0,Math.min(1,(y.clientX-v.left)/v.width)),F=Math.max(0,Math.min(1,(y.clientY-v.top)/v.height)),k=C*100,D=(1-F)*100;c(k),d(D),p(r,k,D)},p=(y,v,C)=>{const F=vr(y,v,C),k=br(F.r,F.g,F.b);m(k)},g=y=>{if(m(y),/^#[0-9A-Fa-f]{6}$/.test(y)){const v=ks(y);if(v){const C=Es(v.r,v.g,v.b);l(C.h),c(C.s),d(C.l)}}},f=()=>{/^#[0-9A-Fa-f]{6}$/.test(u)&&(n(u),a())};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:h,onMouseMove:y=>{y.buttons===1&&h(y)},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:y=>x(Number(y.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:y=>g(y.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:a,children:"Cancel"}),e.jsx(s.Button,{onClick:f,children:"OK"})]})]})}function ks(t){const n=/^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(t);return n?{r:parseInt(n[1],16),g:parseInt(n[2],16),b:parseInt(n[3],16)}:null}function br(t,n,a){return"#"+((1<<24)+(t<<16)+(n<<8)+a).toString(16).slice(1)}function Es(t,n,a){t/=255,n/=255,a/=255;const r=Math.max(t,n,a),l=Math.min(t,n,a);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=((n-a)/d+(n<a?6:0))/6;break;case n:o=((a-t)/d+2)/6;break;case a:o=((t-n)/d+4)/6;break}}return{h:Math.round(o*360),s:Math.round(c*100),l:Math.round(i*100)}}function vr(t,n,a){t/=360,n/=100,a/=100;let r,l,o;if(n===0)r=l=o=a;else{const c=(u,m,x)=>(x<0&&(x+=1),x>1&&(x-=1),x<.16666666666666666?u+(m-u)*6*x:x<.5?m:x<.6666666666666666?u+(m-u)*(.6666666666666666-x)*6:u),i=a<.5?a*(1+n):a+n-a*n,d=2*a-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 yr=["#000000","#ffffff","#6b7280","#dc2626","#ea580c","#ca8a04","#16a34a","#0891b2","#2563eb","#7c3aed","#c026d3","#e11d48","#0f172a","#f3f4f6","#fbbf24"];function St(){var F,k,D,w,j,N,b,R,S,O;const t=s.useEditorStore(E=>E.card),n=s.useEditorStore(E=>{var I;return(I=E.card)==null?void 0:I.preferences}),{setCardPreferences:a,updateCardInFrame:r}=s.useEditorActions(),{data:l}=s.useDashboardCardQuery(t),[o,c]=T.useState({}),[i,d]=T.useState(null),[u,m]=T.useState(null),x=T.useMemo(()=>{var M,L,P,B,K,_,z;if(!(l!=null&&l.records)||l.records.length===0)return[];const E=(t==null?void 0:t.type)==="stackedBar"||(t==null?void 0:t.type)==="stackedLine",I=(t==null?void 0:t.type)==="bar"||(t==null?void 0:t.type)==="line",A=((M=t==null?void 0:t.config)==null?void 0:M.pivotByColumns)&&t.config.pivotByColumns.length>0;if((E||I)&&A){if(l.pivotSchema&&Array.isArray(l.pivotSchema)){const U=new Set;return l.pivotSchema.forEach(W=>{W.alias&&U.add(W.alias)}),Array.from(U)}if(l.records.length>0){const U=l.records[0],W=Object.keys(U),ee=new Set;(L=t==null?void 0:t.config)!=null&&L.groupByColumns&&t.config.groupByColumns.forEach(H=>{ee.add(H.label||H.name),ee.add(H.alias||H.name)});const te=new Set;return(P=t==null?void 0:t.config)!=null&&P.metricColumns&&t.config.metricColumns.forEach(H=>{const q=H.alias||H.name;te.add(q),te.add(`${q}_count`),te.add(`${q}_sum`),te.add(`${q}_avg`),te.add(`${q}_min`),te.add(`${q}_max`);const ae=H.entityName||H.qualifiedEntityName;ae&&(te.add(`${ae}_${q}`),te.add(`${ae}_${q}_count`))}),W.filter(H=>!ee.has(H)&&!te.has(H))}}if((I||E)&&!A&&((K=(B=t==null?void 0:t.config)==null?void 0:B.metricColumns)!=null&&K.length))return t.config.metricColumns.map(U=>U.alias||U.label||U.name);if((z=(_=t==null?void 0:t.config)==null?void 0:_.groupByColumns)!=null&&z.length){const U=t.config.groupByColumns[0],W=U.label||U.name,ee=new Set;return l.records.forEach(te=>{const oe=te[W];oe!=null&&ee.add(String(oe))}),Array.from(ee)}return[]},[l,(F=t==null?void 0:t.config)==null?void 0:F.groupByColumns,(k=t==null?void 0:t.config)==null?void 0:k.pivotByColumns,(D=t==null?void 0:t.config)==null?void 0:D.metricColumns,t==null?void 0:t.type]),h=T.useMemo(()=>s.getDefaultChartColors(),[]);T.useEffect(()=>{const E={};x.forEach((I,A)=>{E[I]=s.getColorForValue(I,A,n==null?void 0:n.colorConfig)}),c(E)},[x,n==null?void 0:n.colorConfig,h]);const p=(E,I)=>{const A={...o,[E]:I};c(A);const M={...n||{},colorConfig:{segments:A}};a(M);const L={...t,preferences:M};r(L)},g=(E,I)=>{var K;const A=h[I%h.length],{[E]:M,...L}=((K=n==null?void 0:n.colorConfig)==null?void 0:K.segments)||{},P={...n||{},colorConfig:{segments:L}};a(P);const B={...t,preferences:P};r(B),c(_=>({..._,[E]:A}))};if(!x.length||!((t==null?void 0:t.type)==="stackedBar"||(t==null?void 0:t.type)==="stackedLine"?((j=(w=t==null?void 0:t.config)==null?void 0:w.groupByColumns)==null?void 0:j.length)||((b=(N=t==null?void 0:t.config)==null?void 0:N.pivotByColumns)==null?void 0:b.length):(S=(R=t==null?void 0:t.config)==null?void 0:R.groupByColumns)==null?void 0:S.length)||["table","kpi","text","custom"].includes(t.type))return null;const v=()=>{const E={...n||{},colorConfig:{segments:{}}};a(E);const I={...t,preferences:E};r(I);const A={};x.forEach((M,L)=>{A[M]=s.getColorForValue(M,L,void 0)}),c(A)},C=Object.keys(((O=n==null?void 0:n.colorConfig)==null?void 0:O.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(oa,{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:C&&e.jsxs("button",{className:"ml-auto flex items-center gap-1 text-xs text-muted-foreground hover:text-foreground",onClick:v,children:[e.jsx(Ns,{className:"h-3 w-3"}),"Reset All"]})})}),e.jsx("div",{className:"max-h-[200px] space-y-2 overflow-y-auto pr-1",children:x.map((E,I)=>{const A=s.isDefaultColor(o[E],I),M=!A;return e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(s.Popover,{open:i===E,onOpenChange:L=>d(L?E: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[E]}})}),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:h.slice(0,10).map((L,P)=>e.jsxs("button",{className:s.cn("relative h-5 w-5 rounded border-2 transition-all hover:scale-110",o[E]===L?"border-gray-900":"border-transparent"),style:{backgroundColor:L},onClick:()=>{p(E,L),d(null)},children:[P===I%h.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:L})]},`default-${P}`))})]}),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:yr.map((L,P)=>e.jsx("button",{className:s.cn("h-5 w-5 rounded border transition-all hover:scale-110",o[E]===L?"border-2 border-gray-900":L==="#ffffff"?"border border-gray-300":"border border-transparent"),style:{backgroundColor:L},onClick:()=>{p(E,L),d(null)},children:e.jsx("span",{className:"sr-only",children:L})},`preset-${P}`))})]}),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:E,color:o[E]}),d(null)},children:"Custom color"}),!A&&e.jsxs("button",{className:"flex items-center gap-1 text-sm text-muted-foreground hover:text-foreground",onClick:()=>{g(E,I),d(null)},children:[e.jsx(Ns,{className:"h-3 w-3"}),"Reset"]})]})]})})]}),e.jsx("span",{className:"flex-1 truncate text-sm",children:E}),M&&e.jsx("span",{className:"text-xs text-muted-foreground",children:"(custom)"})]},E)})}),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(Ct,{color:u.color,onColorChange:E=>{p(u.value,E),m(null)},onClose:()=>m(null)})})]})]})})]})}function we({value:t,onSave:n,placeholder:a="",type:r="text",className:l=""}){const[o,c]=T.useState(t??""),[i,d]=T.useState(!1);T.useEffect(()=>{c(t??"")},[t]);const u=()=>{n(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:a,type:r,value:i?o:t??"",onChange:x=>{c(x.target.value),d(!0)},onFocus:()=>d(!0),onClick:x=>x.stopPropagation(),className:"h-8 text-xs",onPointerDown:x=>x.stopPropagation(),onKeyDown:x=>{x.stopPropagation(),x.key==="Enter"&&i&&o!==t?u():x.key==="Escape"&&m()},"aria-label":a||"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 Nr=["auto","number","currency","percent","scientific","date"],Cr=[{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"}],Sr=[{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"}],wr=t=>t.charAt(0).toUpperCase()+t.slice(1);function ms({formatOptions:t={},onFormatOptionsChange:n,showTitle:a=!0,title:r="NUMBER FORMAT"}){const l=t.type||"auto",o=(i,d)=>{n({...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:[a&&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:Nr.map(i=>e.jsx(s.SelectItem,{value:i,className:"text-xs",children:i==="auto"?"Auto (Default)":wr(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:Cr.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:Sr.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 Is({axis:t,label:n,type:a,config:r,onChange:l}){var x,h,p,g,f,y,v,C,F,k,D,w;const o=(j,N)=>{l({...r,[j]:N})},c=(j,N)=>{var b,R;l({...r,name:{enabled:j==="enabled"?N:((b=r==null?void 0:r.name)==null?void 0:b.enabled)??!1,text:j==="text"?N:(R=r==null?void 0:r.name)==null?void 0:R.text}})},i=(j,N)=>{var b,R;l({...r,labels:{enabled:j==="enabled"?N:((b=r==null?void 0:r.labels)==null?void 0:b.enabled)??!0,rotation:j==="rotation"?N:(R=r==null?void 0:r.labels)==null?void 0:R.rotation}})},d=(j,N)=>{l({...r,scale:{...r==null?void 0:r.scale,[j]:N===""?"auto":Number(N)}})},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:n})})}),e.jsx(s.SmallSwitch,{checked:(r==null?void 0:r.enabled)!==!1,onCheckedChange:j=>o("enabled",j),onClick:j=>j.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:((x=r==null?void 0:r.name)==null?void 0:x.enabled)??!1,onCheckedChange:j=>c("enabled",j)})]}),((h=r==null?void 0:r.name)==null?void 0:h.enabled)&&e.jsx(we,{placeholder:`${n} title`,value:((p=r==null?void 0:r.name)==null?void 0:p.text)||"",onSave:j=>c("text",j),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:j=>o("position",j),children:[e.jsx(s.SelectTrigger,{className:"h-8 text-xs",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{children:u.map(j=>e.jsx(s.SelectItem,{value:j,className:"text-xs",children:j==="auto"?"Auto (Default)":s.titleCase(j)},j))})]})]}),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:((g=r==null?void 0:r.labels)==null?void 0:g.enabled)!==!1,onCheckedChange:j=>i("enabled",j)})]}),((f=r==null?void 0:r.labels)==null?void 0:f.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(((y=r==null?void 0:r.labels)==null?void 0:y.rotation)||"auto"),onValueChange:j=>i("rotation",j==="auto"?"auto":Number(j)),children:[e.jsx(s.SelectTrigger,{className:"h-8 text-xs",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{children:m.map(j=>e.jsx(s.SelectItem,{value:j,className:"text-xs",children:j==="auto"?"Auto (Default)":`${j}°`},j))})]})]})]}),a==="value"&&e.jsx(ms,{formatOptions:(r==null?void 0:r.formatOptions)||{},onFormatOptionsChange:j=>l({...r,formatOptions:j}),showTitle:!0,title:"FORMAT"}),a==="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(we,{type:"number",placeholder:"auto",value:((v=r==null?void 0:r.scale)==null?void 0:v.min)==="auto"||((C=r==null?void 0:r.scale)==null?void 0:C.min)===void 0?"":String(r.scale.min),onSave:j=>d("min",j),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(we,{type:"number",placeholder:"auto",value:((F=r==null?void 0:r.scale)==null?void 0:F.max)==="auto"||((k=r==null?void 0:r.scale)==null?void 0:k.max)===void 0?"":String(r.scale.max),onSave:j=>d("max",j),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(we,{type:"number",placeholder:"auto",value:((D=r==null?void 0:r.scale)==null?void 0:D.stepSize)==="auto"||((w=r==null?void 0:r.scale)==null?void 0:w.stepSize)===void 0?"":String(r.scale.stepSize),onSave:j=>d("stepSize",j),className:""})})]})]})]})]})]})}function wt(){const t=s.useEditorStore(c=>c.card),n=s.useEditorStore(c=>{var i;return(i=c.card)==null?void 0:i.preferences}),{setCardPreferences:a,updateCardInFrame:r}=s.useEditorActions();if(!t||["tornado","pyramid","kpi"].includes(t.type))return null;const l=s.AxisConfigurator.getAxisInfo(t.type,n);if(!l.hasXAxis&&!l.hasYAxis)return null;const o=(c,i)=>{const u={...n||{},[c==="x"?"xAxisConfig":"yAxisConfig"]:i};a(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(Vs,{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(Is,{axis:"x",label:"X-Axis",type:l.xAxisType,config:n==null?void 0:n.xAxisConfig,onChange:c=>o("x",c)}),l.hasYAxis&&e.jsx(Is,{axis:"y",label:"Y-Axis",type:l.yAxisType,config:n==null?void 0:n.yAxisConfig,onChange:c=>o("y",c)})]})})]})}function Dt(){const t=s.useEditorStore(u=>u.card),n=s.useEditorStore(u=>{var m,x,h,p;return(p=(h=(x=(m=u.card)==null?void 0:m.preferences)==null?void 0:x.chartOptions)==null?void 0:h.plugins)==null?void 0:p.legend}),{setLegendOptions:a}=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 x={...n,[u]:m};a(x)},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(Zt,{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:(n==null?void 0:n.display)??o,onCheckedChange:u=>c("display",u)})]}),((n==null?void 0:n.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:(n==null?void 0:n.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:(n==null?void 0:n.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 Tt(){var N,b,R,S,O,E,I,A,M;const t=s.useEditorStore(L=>L.card),n=s.useEditorStore(L=>{var P,B;return(B=(P=L.card)==null?void 0:P.preferences)==null?void 0:B.dataLabelsConfig}),a=s.useEditorStore(L=>{var P;return(P=L.card)==null?void 0:P.preferences}),{setCardPreferences:r,updateCardInFrame:l}=s.useEditorActions();if(!t||!s.chartSupportsDataLabels(t.type))return null;const o=((N=a==null?void 0:a.chartOptions)==null?void 0:N.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=(R=(b=a==null?void 0:a.chartOptions)==null?void 0:b.plugins)==null?void 0:R.datalabels,m=(u==null?void 0:u.display)!==!1&&((u==null?void 0:u.anchor)||(u==null?void 0:u.align)),x=(n==null?void 0:n.enabled)!==void 0?n.enabled:m,h=(L,P)=>{const B={...n,[L]:P},K={...t.preferences||{},dataLabelsConfig:B};r(K);const _={...t,preferences:K};l(_)},p=(L,P)=>{const B={...n,font:{...n==null?void 0:n.font,[L]:P}},K={...t.preferences||{},dataLabelsConfig:B};r(K);const _={...t,preferences:K};l(_)},g=(L,P)=>{const B={...n,formatOptions:{...n==null?void 0:n.formatOptions,[L]:P}},K={...t.preferences||{},dataLabelsConfig:B};r(K);const _={...t,preferences:K};l(_)},y=(()=>{const L=t.type;return L==="stackedBar"||L==="stackedLine"||L==="pie"||L==="doughnut"?"center":o?"right":"top"})();let v=[];c||i?v=["center"]:v=["auto",...(o?["center","left","right"]:["center","top","bottom"]).filter(P=>P!==y),"custom"];const C=()=>s.titleCase(y),F=["center","start","end"],k=["center","start","end","top","bottom"],D=d?["auto","number","currency","percent","none"]:["number","currency","percent","none"],w=[{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"}],j=[{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(pa,{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:x,onCheckedChange:L=>h("enabled",L)})]}),x&&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:(n==null?void 0:n.position)||"auto",onValueChange:L=>h("position",L),children:[e.jsx(s.SelectTrigger,{className:"h-8 text-xs",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{children:v.map(L=>e.jsx(s.SelectItem,{value:L,className:"text-xs",children:L==="auto"?C():L==="custom"?"Custom (Advanced)":s.titleCase(L)},L))})]})]}),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:(n==null?void 0:n.showTotal)??!1,onCheckedChange:L=>h("showTotal",L)})]}),(n==null?void 0:n.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:(n==null?void 0:n.anchor)||"center",onValueChange:L=>h("anchor",L),children:[e.jsx(s.SelectTrigger,{className:"h-8 text-xs flex-1",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{children:F.map(L=>e.jsx(s.SelectItem,{value:L,className:"text-xs",children:s.titleCase(L)},L))})]})]}),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((n==null?void 0:n.align)||"center"),onValueChange:L=>h("align",L),children:[e.jsx(s.SelectTrigger,{className:"h-8 text-xs flex-1",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{children:k.map(L=>e.jsx(s.SelectItem,{value:L,className:"text-xs",children:s.titleCase(L)},L))})]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(s.Label,{className:"text-xs font-medium",children:"Format"}),e.jsxs(s.Select,{value:(n==null?void 0:n.format)||(d?"auto":"none"),onValueChange:L=>h("format",L),children:[e.jsx(s.SelectTrigger,{className:"h-8 text-xs",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{children:D.map(L=>e.jsx(s.SelectItem,{value:L,className:"text-xs",children:L==="auto"&&d?"Auto (Use Axis)":L==="none"?"None (Raw Value)":s.titleCase(L)},L))})]})]}),(n==null?void 0:n.format)&&!["auto","none"].includes(n.format)&&e.jsxs("div",{className:"space-y-2 pl-4 border-l-2 border-muted",children:[["number","currency","percent"].includes(n.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(we,{type:"number",placeholder:"0",value:String(((S=n==null?void 0:n.formatOptions)==null?void 0:S.decimalPlaces)??(n.format==="currency"?2:n.format==="percent"?1:0)),onSave:L=>g("decimalPlaces",Number(L)),className:""})})]}),n.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:((O=n==null?void 0:n.formatOptions)==null?void 0:O.currency)||"USD",onValueChange:L=>g("currency",L),children:[e.jsx(s.SelectTrigger,{className:"h-8 text-xs flex-1",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{children:w.map(L=>e.jsx(s.SelectItem,{value:L.value,className:"text-xs",children:L.label},L.value))})]})]}),["number","currency"].includes(n.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:((E=n==null?void 0:n.formatOptions)==null?void 0:E.useSuffix)??!1,onCheckedChange:L=>g("useSuffix",L)})]}),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:((I=n==null?void 0:n.formatOptions)==null?void 0:I.locale)||"en-US",onValueChange:L=>g("locale",L),children:[e.jsx(s.SelectTrigger,{className:"h-8 text-xs flex-1",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{children:j.map(L=>e.jsx(s.SelectItem,{value:L.value,className:"text-xs",children:L.label},L.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(we,{type:"number",placeholder:"12",value:String(((A=n==null?void 0:n.font)==null?void 0:A.size)||12),onSave:L=>p("size",Number(L)),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:((M=n==null?void 0:n.font)==null?void 0:M.weight)||"normal",onValueChange:L=>p("weight",L),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:(n==null?void 0:n.color)==="auto"||!(n!=null&&n.color)?"auto":"custom",onValueChange:L=>{L==="auto"&&h("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(we,{type:"number",placeholder:"0",value:String((n==null?void 0:n.rotation)||0),onSave:L=>h("rotation",Number(L)),className:""})}),e.jsx("span",{className:"text-xs text-muted-foreground",children:"degrees"})]})]})]})]})})]})}function Dr(){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(St,{}),e.jsx(wt,{}),e.jsx(Dt,{}),e.jsx(Tt,{})]})]})}const Tr=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."]})]}),kr=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."]})]}),Er=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 Ir(){const t=s.useEditorStore(a=>a.card.type);function n(a){const r=["kpi","table","text","map","custom"],l=o=>r.includes(a)?o:e.jsxs(e.Fragment,{children:[o,e.jsx(Dr,{})]});switch(a){case"stackedBar":case"stackedLine":return l(e.jsx(gr,{}));case"tornado":case"pyramid":return l(e.jsx(Ge,{docContent:Tr,cardType:a}));case"kpi":return e.jsx(ur,{});case"line":case"bar":return l(e.jsx(ar,{cardType:a}));case"range":return l(e.jsx(Ge,{docContent:kr,cardType:a}));case"pie":case"doughnut":case"polarArea":case"radar":case"funnel":return l(e.jsx(Ge,{cardType:a}));case"bubble":case"scatter":return l(e.jsx(nr,{cardType:a}));case"table":return e.jsx(jr,{cardType:a});case"text":return e.jsx(Ge,{docContent:Er,cardType:a,suffix:"Visual"});case"map":return e.jsx(pr,{});case"custom":return e.jsx(Zn,{});default:return l(e.jsx(or,{}))}}return e.jsxs(s.ScrollArea,{className:"h-full w-full text-sm",children:[n(t),e.jsx(s.ScrollBar,{orientation:"horizontal"})]})}function Ar(){const t=T.useRef(null),n=T.useRef(null),a=s.useEditorStore(l=>l.isShowingVisual),r=s.useEditorStore(l=>l.showAIDialog);return T.useEffect(()=>{var l,o,c,i;r?((l=t.current)==null||l.resize(0),(o=n.current)==null||o.resize(0)):((c=t.current)==null||c.resize(25),(i=n.current)==null||i.resize(25))},[r]),e.jsxs(s.ResizablePanelGroup,{direction:"vertical",className:"min-h-[250px] min-w-full max-w-lg",children:[e.jsx(s.ResizablePanel,{role:"query-section",className:"flex",minSize:20,defaultSize:40,children:e.jsx(Fn,{})}),e.jsx(s.ResizableHandle,{withHandle:!0}),e.jsx(s.ResizablePanel,{className:"pb-1",role:"visual-section",minSize:0,defaultSize:60,children:a&&!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(Ir,{})})}),!r&&e.jsx(s.ResizableHandle,{}),e.jsx(s.ResizablePanel,{minSize:40,defaultSize:75,maxSize:100,children:e.jsx(Ts,{})})]}):e.jsx(Ts,{})})]})}function Mr(t){s.useAIInteractionStore(G=>G.currentAIContext);const[n,a]=T.useState(""),[r,l]=T.useState(null),{authToken:o,tokenProps:c}=s.useSemaphorContext(),i=s.useEditorStore(G=>{var se;return(se=G==null?void 0:G.card)==null?void 0:se.sql}),d=s.useEditorStore(G=>G.isDevMode),u=s.useEditorStore(G=>{var se;return(se=G==null?void 0:G.card)==null?void 0:se.python}),{setCardPython:m,setCardSql:x,setRunSql:h,switchCardType:p,setQueryConfig:g}=s.useEditorActions(),f=s.useEditorStore(G=>G.currentAssitantScope)||[],y=s.useEditorStore(G=>G.userInputForAI),v=s.useEditorStore(G=>G.triggerAIRun),C=s.useEditorStore(G=>G.card),F=s.useEditorStore(G=>G.selectedDatabaseName),k=s.useEditorStore(G=>G.selectedTableName),D=s.useEditorStore(G=>G.selectedConnectionId),w=s.useEditorStore(G=>G.selectedSchemaName),j=s.useDashboardStore(G=>G.dashboard.aiScopeTables),{errorMessage:N,refetch:b,data:R}=s.useDashboardCardQuery(C),{setTriggerAIRun:S,setCurrentAssitantScope:O,setCardConfig:E}=s.useEditorActions(),{selectedDatamodelName:I,connectionType:A,selectedDatamodelId:M}=s.useEditorAside(),{messages:L,setMessages:P,regenerate:B,error:K,sendMessage:_,status:z,addToolResult:U,stop:W,clearError:ee}=s.useChat({transport:new s.DefaultChatTransport({api:`${c.apiServiceUrl}/v1/assistant`,headers:()=>({Authorization:`Bearer ${o==null?void 0:o.accessToken}`}),body:()=>{const G=s.useAIInteractionStore.getState();return{random:Math.random(),assistantId:"editor-assistant",isDevMode:d,aiContext:G.currentAIContext,reasoningEffort:G.reasoningEffort,showReasoning:G.showReasoning}},credentials:"omit",prepareSendMessagesRequest:({messages:G,body:se})=>({body:{...se,messages:s.cleanupIncompleteMessages(G)}})}),onError:G=>{var se;if(G.name==="AbortError"||(se=G.message)!=null&&se.includes("aborted")){console.log("[Editor Assistant] Stream aborted (expected)");return}console.error("[Editor Assistant] Stream error:",G)},onToolCall:te,onFinish({isAbort:G,isDisconnect:se,isError:ce}){a(""),console.log(G?"[Editor Assistant] Stream aborted by user":se?"[Editor Assistant] Stream disconnected (network error)":ce?"[Editor Assistant] Stream error occurred":"[Editor Assistant] Stream completed successfully")}});T.useEffect(()=>{v&&y&&(_({role:"user",parts:[{type:"text",text:y}]}),S(!1))},[v,y,_,S]);async function te({toolCall:G}){var se,ce,le,fe,ue,Q,$,V,Z,ie,de,ne,me,pe,Re,Le;if(["createChartFromSql","createForecast"].includes(G.toolName)){const De=((se=G.input)==null?void 0:se.sql)??((ce=G.args)==null?void 0:ce.sql),ve=((le=G.input)==null?void 0:le.python)??((fe=G.args)==null?void 0:fe.python),X=((ue=G.input)==null?void 0:ue.chartType)??((Q=G.args)==null?void 0:Q.chartType);p(X),x(De),m(ve),h(!0),U({tool:G.toolName,toolCallId:G.toolCallId,output:{status:"success",message:"Let the user know that chart is created"}})}else if(G.toolName==="getUserSql"){if(!i){U({tool:G.toolName,toolCallId:G.toolCallId,output:{status:"error",message:"No SQL found"}});return}U({tool:G.toolName,toolCallId:G.toolCallId,output:{status:"success",sql:i,python:u||""}})}else if(G.toolName==="generateQueryConfig"){a("Generating query config...");const De=(($=G.input)==null?void 0:$.chartType)??((V=G.args)==null?void 0:V.chartType),ve=((Z=G.input)==null?void 0:Z.queryConfig)??((ie=G.args)==null?void 0:ie.queryConfig);((de=G.input)==null?void 0:de.cardConfig)??((ne=G.args)==null||ne.cardConfig),p(De),E(ve),x(void 0),m(void 0);const X=await b();if((me=X==null?void 0:X.data)!=null&&me.error){U({tool:G.toolName,toolCallId:G.toolCallId,output:{status:"error",queryConfig:ve,message:(pe=X==null?void 0:X.data)==null?void 0:pe.error.message}});return}if((Re=X==null?void 0:X.data)!=null&&Re.records){U({tool:G.toolName,toolCallId:G.toolCallId,output:{status:"success",queryConfig:ve,message:"The data has been visualized"}});return}U({tool:G.toolName,toolCallId:G.toolCallId,output:{status:"success",queryConfig:ve,message:"The data has been visualized",records:(Le=X==null?void 0:X.data)==null?void 0:Le.records}})}else a("Analyzing...")}function oe(G){const se=s.removeFromScopeArray(f,G);H(se)}function H(G){const se=s.sanitizeAIScope(G);O(se),P(ce=>[...ce,{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 q(){const G={databaseName:F||"",schemaName:w||"",tableName:k||"",datamodelId:M||"",datamodelName:s.resolveDatamodelName(I),connectionId:D||"",connectionType:A||""},se=s.dedup([...f,G]);H(se)}function ae(){const G={databaseName:F||"",schemaName:w||"",tableName:k||"",datamodelName:s.resolveDatamodelName(I),connectionId:D||"",connectionType:A||"",datamodelId:M||""};if(!s.isInAiScopeArray([...j||[],...f],G)||f.length===0){const ce=s.dedup([...j||[],...f,G]).filter(le=>le.connectionId===G.connectionId);H(ce)}}const J=!["ready","error"].includes(z),re=s.getErrorMessage(K);return{messages:L,setMessages:P,sendMessage:_,regenerate:B,isLoading:J,handleSetAIScope:ae,handleAddCurrentTableToScope:q,removeFromCurrentSelections:oe,currentAssitantScope:f,setCurrentAssitantScope:O,stop:W,status:z,toolStatus:n,llmUsage:r,onFinish:t,errorMessage:re,clearError:ee}}const Rr=[{title:"Help me write a query for",subtitle:"orders by month"},{title:"Create a bar chart for",subtitle:"sales by category"}];function As({isFullscreen:t,onFullscreenChange:n,fullscreenContainer:a}){const r=T.useRef(null),[l,o]=T.useState(!1),[c,i]=T.useState(s.isDevEnv),[d,u]=T.useState(!1),[m,x]=T.useState(!1),[h,p]=T.useState(!1),g=t??h,f=s.useCurrentAIContext(),{setCurrentAIContext:y}=s.useAIActions(),{clearQueue:v}=s.useQueueActions(),{clearFileAttachments:C}=s.useFileActions(),F=s.useFileAttachments("editor"),k=s.useDashboardStore(X=>X.dashboard.aiContext),D=s.useEditorStore(X=>X.card.dataSource),w=s.useEditorStore(X=>X.actions.setCardSql),j=s.useEditorStore(X=>X.actions.setRunSql),N=s.useEditorStore(X=>X.showAIDialog),b=s.useDashboardStore(X=>X.handleOpenAssistantProfile),{setShowAIDialog:R,setCardPython:S}=s.useEditorActions(),{setDataSource:O}=s.useEditorActions(),{assistantProfile:E}=s.useAssistantProfile(),{messages:I,setMessages:A,sendMessage:M,isLoading:L,stop:P,status:B,llmUsage:K,errorMessage:_,clearError:z}=Mr(),[U,W]=T.useState(""),ee=X=>{W(X.target.value)},te=X=>{X.preventDefault();const ge=U.trim();if(!ge&&F.length===0)return;const Be=[];ge&&Be.push({type:"text",text:ge}),F.forEach(ke=>{ke.data&&Be.push({type:"file",mediaType:ke.type,filename:ke.name,url:`data:${ke.type};base64,${ke.data}`})}),M({role:"user",parts:Be}),W(""),C("editor"),le({force:!0})},{visibleMessages:oe,hasMoreMessages:H,totalMessageCount:q,loadMoreMessages:ae,resetMessageWindow:J}=s.useMessageWindow(I,{maxVisibleMessages:15,initialLoadCount:10,loadMoreCount:5}),{scrollRef:re,isAtBottom:G,hasNewMessages:se,newMessageCount:ce,scrollToBottom:le,handleScroll:fe,resetNewMessageCount:ue}=s.useAutoScroll(oe,{threshold:50,delay:0,dependencies:[B,I.length]});T.useEffect(()=>{var X;N&&((X=r.current)==null||X.focus(),y({selectedEntities:(D==null?void 0:D.selectedEntities)||[]}))},[N,D,y]),s.useAutoSubmitQueue({assistantType:"editor",status:B,isLoading:L,sendMessage:M});const{hasActiveTools:Q}=s.useActiveToolStatus(I),$=T.useCallback(X=>{n==null||n(X),t===void 0&&p(X)},[t,n]);T.useEffect(()=>{if(!g)return;function X(ge){ge.key==="Escape"&&$(!1)}return window.addEventListener("keydown",X),()=>{window.removeEventListener("keydown",X)}},[g,$]);const V=T.useCallback(X=>{M({role:"user",parts:[{type:"text",text:X}]}),le({force:!0})},[M,le]),Z=T.useCallback(async()=>{const X=JSON.stringify(I??[],null,2);try{if(typeof navigator>"u"||!navigator.clipboard)throw new Error("Clipboard API unavailable");await navigator.clipboard.writeText(X),s.ue.success("Conversation copied")}catch(ge){console.error("Failed to copy conversation",ge),s.ue.error("Unable to copy conversation")}},[I]),ie=T.useCallback(()=>{$(!g)},[g,$]);function de(X,ge){ge==="sql"?(w(X),j(!0)):ge==="python"&&(S(X),j(!0))}function ne(){f.selectedEntities.length===0&&y({selectedEntities:(k==null?void 0:k.selectedEntities)||[]})}function me(X){ne();const ge={role:"user",parts:[{type:"text",text:X.title+" "+X.subtitle}]};M(ge)}function pe(X){ne(),M({role:"user",parts:[{type:"text",text:X}]})}function Re(){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 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:l,onCheckedChange:o,children:"Token Usage"}),e.jsx(s.DropdownMenuCheckboxItem,{checked:c,onCheckedChange:i,children:"Tool Invocations"}),e.jsx(s.DropdownMenuCheckboxItem,{checked:d,onCheckedChange:u,children:"System Message"})]})]})}function Le(){return e.jsx("div",{"data-role":"header",children:e.jsx("div",{className:"text-lg font-semibold",children:"Assistant"})})}const De=(U==null?void 0:U.length)===0&&(I==null?void 0:I.filter(X=>X.role==="user").length)===0,ve=e.jsxs("div",{"data-role":"editor-assistant",className:s.cn("flex h-full w-full flex-col justify-between px-6 py-4",g&&"rounded-2xl border border-border/60 bg-background px-8 pb-6 pt-6 shadow-xl"),children:[e.jsxs("div",{"data-role":"header-section",className:"flex items-start justify-between gap-2",children:[Le(),b&&e.jsx(s.Button,{variant:"outline",size:"sm",className:"h-7 p-2",onClick:b,children:(E==null?void 0:E.name)||"Default Profile"}),e.jsxs("div",{"data-role":"header-actions",className:"flex items-center",children:[Re(),c&&e.jsx(s.Button,{variant:"ghost",size:"sm",className:"ml-2 h-7 px-2 text-muted-foreground hover:text-foreground",onClick:Z,children:"Copy Conversation"}),e.jsx(s.IconButton,{tooltip:g?"Exit Fullscreen":"Expand",className:"h-7 p-2 text-muted-foreground hover:text-foreground",onClick:ie,children:g?e.jsx(s.Minimize2,{className:"size-4"}):e.jsx(s.Maximize2,{className:"size-4"})}),e.jsx(s.IconButton,{className:"h-7 p-2 text-muted-foreground hover:text-foreground",tooltip:"New Chat",onClick:()=>{A([]),v("editor"),z(),J()},children:e.jsx(s.SquarePen,{className:"size-4"})}),e.jsx(s.Button,{variant:"ghost",className:"h-7 p-2 text-muted-foreground hover:text-foreground",size:"sm",onClick:()=>{R(!1)},children:e.jsx(s.X,{className:"size-4"})})]})]}),e.jsx(s.CustomScrollArea,{ref:re,className:"mt-2 flex w-full grow basis-0",onScroll:fe,children:e.jsxs("div",{className:"space-y-4 py-2 pr-3","data-role":"messages",children:[H&&e.jsx("div",{className:"flex justify-center py-2",children:e.jsxs(s.Button,{variant:"outline",size:"sm",onClick:ae,className:"text-xs",children:["Load ",Math.min(5,q-oe.length)," ","more messages (",q-oe.length," ","hidden)"]})}),e.jsx(s.PrintMessages,{messages:oe,showTools:c,handleRun:de,showSystemMessage:d,onQuickReply:V,disableQuickReplies:L}),!Q&&e.jsx(s.AssistantStatus,{status:B,errorMessage:_})]})}),!G&&e.jsx("div",{className:"absolute bottom-24 right-8 z-10",children:e.jsxs(s.Button,{onClick:()=>{le({force:!0}),ue()},size:"sm",variant:"secondary",className:"rounded-full shadow-lg","aria-label":"Scroll to bottom",children:[e.jsx(s.ChevronDown,{className:"h-4 w-4"}),se&&ce>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:ce>9?"9+":ce})]})}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{children:[De&&!E&&e.jsx(s.Placeholders,{onClick:me,placeholders:Rr}),e.jsx("div",{children:De&&E&&e.jsx(s.SeedQuestions,{seedQuestions:E.seedQuestions||[],handleSeedQuestionClick:pe})})]}),e.jsx(s.PendingMessagesDisplay,{assistantType:"editor",className:"mb-3"}),e.jsx(s.ChatInputWithContext,{ref:r,setInput:W,stop:P,input:U,handleInputChange:ee,handleSubmit:X=>{ne(),te(X),le({force:!0})},isLoading:L,status:B,assistantType:"editor",onFocus:()=>{}})]}),K&&l&&e.jsx("div",{className:"flex h-8 items-center justify-between",children:e.jsxs("div",{className:"text-xs text-muted-foreground",children:["Usage: ",K.inputTokens," prompt tokens, ",K.outputTokens," ","completion tokens, ",K.totalTokens," total tokens"]})}),e.jsx(s.DataSourceDialog,{incomingSelectedEntities:(D==null?void 0:D.selectedEntities)||[],open:m,onOpenChange:x,dataSource:D||s.EMPTY_DATA_SOURCE,dialogMode:"aiContext"})]});return g&&a?Ot.createPortal(e.jsx("div",{className:"pointer-events-auto absolute inset-0 z-50 flex bg-background px-6 pb-6 pt-[calc(var(--app-header-height,15px)+1rem)]",children:e.jsx("div",{className:"flex h-full w-full",children:ve})}),a):ve}function hs(t,n){const[a,r]=T.useState(()=>{const l=localStorage.getItem(t);return l?JSON.parse(l):n});return T.useEffect(()=>{localStorage.setItem(t,JSON.stringify(a))},[a,t]),[a,r]}const Lr="chart-selector-standard-first";function Fr(){const[t,n]=hs(Lr,!0);return{standardFirst:t,updatePreference:n}}const Ms=({pluginVisual:t,index:n,onSelect:a})=>{const r=Je(t.icon||""),l=t.name.charAt(0).toUpperCase(),o=s.getAutoDetectedChartIcon(t.name);return e.jsx(s.CommandItem,{value:`${t.name} custom visual plugin component`,onSelect:a,className:"group flex items-center gap-2",children:e.jsxs("div",{className:"flex w-full items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[r?e.jsx(r,{className:"h-4 w-4"}):o||e.jsx("div",{className:"flex h-4 w-4 items-center justify-center rounded bg-muted text-xs font-medium",children:l}),e.jsx("span",{children:t.name})]}),e.jsxs(s.Tooltip,{children:[e.jsx(s.TooltipTrigger,{asChild:!0,children:e.jsx("span",{tabIndex:0,className:"opacity-0 outline-none transition-opacity group-hover:opacity-100",children:e.jsx(s.Info,{className:"ml-1 h-3.5 w-3.5 text-muted-foreground"})})}),e.jsx(s.TooltipContent,{side:"right",children:t.pluginName})]})]})},`${t.url}-${t.name}-${n}`)},Rs=["default","standardPlugin","customPlugin"];function Or({selectedChart:t,onChartChange:n}){var k;const[a,r]=T.useState(!1),{data:l}=pt();Fr();const c=((k=s.useEditorStore(D=>D.card).customCardPreferences)==null?void 0:k.url)||"";ls(c);const{setCardType:i,setCardPreferences:d,setIsDevMode:u}=s.useEditorStore(D=>D.actions),{setCardCustomCfg:m,setCustomCardPreferences:x,setQueryConfig:h}=s.useEditorActions(),[p,g]=hs("chart-section-active",null),f=T.useMemo(()=>p?[p,...Rs.filter(D=>D!==p)]:Rs,[p]);function y(D){m(null),d({}),i(D),["custom","map"].includes(D)&&(u(!0),h(void 0)),n(D),r(!1)}function v(D){m(null),d({}),i("custom"),x({type:"component",visualType:"single",url:D.url,componentName:D.name,icon:D.icon,pluginChartType:D.chartType}),h(void 0),n("custom"),r(!1)}const C=()=>{var w;if(t==="custom"){const j=s.useEditorStore.getState().card;return((w=j==null?void 0:j.customCardPreferences)==null?void 0:w.componentName)||"Custom Visual"}const D=s.chartTypes.find(j=>j.id===t);return(D==null?void 0:D.label)||"Select chart type"},F=()=>{var w,j;if(t==="custom"){const N=s.useEditorStore.getState().card,b=(w=N==null?void 0:N.customCardPreferences)==null?void 0:w.icon,R=(j=N==null?void 0:N.customCardPreferences)==null?void 0:j.componentName;if(b&&R)return e.jsx(Pr,{icon:b,componentName:R});if(R){const S=s.getAutoDetectedChartIcon(R);if(S)return S}return e.jsx(Ve,{className:"h-4 w-4"})}const D=s.chartTypes.find(N=>N.id===t);if(D){const N=D.icon;return e.jsx(N,{className:"h-4 w-4"})}return e.jsx(Ve,{className:"h-4 w-4"})};return e.jsx("div",{className:"",children:e.jsxs(s.Popover,{open:a,onOpenChange:r,children:[e.jsx(s.PopoverTrigger,{asChild:!0,children:e.jsxs(s.Button,{variant:"outline",role:"combobox","aria-expanded":a,className:"w-full justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[F(),e.jsx("span",{children:C()})]}),e.jsx(s.ChevronDown,{className:"ml-2 h-4 w-4 shrink-0 opacity-50"})]})}),e.jsx(s.PopoverContent,{className:"w-[300px] p-0",align:"start",children:e.jsxs(s.Command,{children:[e.jsx(s.CommandInput,{placeholder:"Search chart types..."}),e.jsxs(s.CommandList,{className:"mb-2 max-h-[300px]",children:[e.jsx(s.CommandEmpty,{children:"No chart type found."}),f.map(D=>{if(D==="default")return e.jsx(s.CommandGroup,{heading:e.jsxs("div",{className:"group flex w-full items-center justify-between",children:[e.jsxs(s.Tooltip,{children:[e.jsx(s.TooltipTrigger,{asChild:!0,children:e.jsx("span",{className:"flex items-center gap-2",children:"Default Visuals"})}),e.jsx(s.TooltipContent,{side:"right",children:"These are the standard visuals available in Semaphor"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-xs text-muted-foreground opacity-0 transition-opacity group-hover:opacity-100",children:"Show on top"}),e.jsx(s.Switch,{checked:p==="default",onCheckedChange:w=>g(w?"default":null),className:"scale-75"})]})]}),className:"[&_[cmdk-group-heading]]:text-sm [&_[cmdk-group-heading]]:font-medium [&_[cmdk-group-heading]]:text-muted-foreground",children:s.chartTypes.map(w=>{const j=w.icon;return e.jsx(s.CommandItem,{value:`${w.label} ${w.id} chart graph visualization`,onSelect:()=>y(w.id),className:"flex items-center gap-2",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(j,{className:"h-4 w-4"}),e.jsx("span",{children:w.label})]})},w.id)})},"default");if(D==="standardPlugin"){const w=l.filter(j=>j.pluginType==="standard");return w.length?e.jsx(s.CommandGroup,{heading:e.jsxs("div",{className:"group flex w-full items-center justify-between",children:[e.jsx("p",{children:"Standard Visuals"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-xs text-muted-foreground opacity-0 transition-opacity group-hover:opacity-100",children:"Show on top"}),e.jsx(s.Switch,{checked:p==="standardPlugin",onCheckedChange:j=>g(j?"standardPlugin":null),className:"scale-75"})]})]}),className:"[&_[cmdk-group-heading]]:text-sm [&_[cmdk-group-heading]]:font-medium [&_[cmdk-group-heading]]:text-muted-foreground",children:w.filter(j=>j.componentType==="chart").map((j,N)=>e.jsx(Ms,{pluginVisual:j,index:N,onSelect:()=>v(j)},`${j.url}-${j.name}-${N}`))},"standardPlugin"):null}if(D==="customPlugin"){const w=l.filter(j=>j.pluginType==="custom");return w.length?e.jsx(s.CommandGroup,{heading:e.jsxs("div",{className:"group flex w-full items-center justify-between",children:[e.jsxs(s.Tooltip,{children:[e.jsx(s.TooltipTrigger,{asChild:!0,children:e.jsxs("span",{className:"flex items-center gap-2",children:["Custom Visuals",e.jsx(s.Info,{className:"h-3.5 w-3.5 text-muted-foreground"})]})}),e.jsx(s.TooltipContent,{side:"right",children:"External visuals that are specific to your project"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-xs text-muted-foreground opacity-0 transition-opacity group-hover:opacity-100",children:"Show on top"}),e.jsx(s.Switch,{checked:p==="customPlugin",onCheckedChange:j=>g(j?"customPlugin":null),className:"scale-75"})]})]}),className:"[&_[cmdk-group-heading]]:text-sm [&_[cmdk-group-heading]]:font-medium [&_[cmdk-group-heading]]:text-muted-foreground",children:w.map((j,N)=>e.jsx(Ms,{pluginVisual:j,index:N,onSelect:()=>v(j)},`${j.url}-${j.name}-${N}`))},"customPlugin"):null}return null})]})]})})]})})}const Pr=({icon:t,componentName:n})=>{const a=Je(),r=s.getAutoDetectedChartIcon(n);return a?e.jsx(a,{className:"h-4 w-4"}):r||e.jsx(Ve,{className:"h-4 w-4"})},Br=[{id:"table",icon:s.Table2,label:"Table"},{id:"bar",icon:s.ChartColumnIncreasing,label:"Bar Chart"},{id:"line",icon:s.ChartLine,label:"Line Chart"},{id:"stackedBar",icon:s.ChartColumnStacked,label:"Stacked Bar",requiresPivot:!0},{id:"pie",icon:s.ChartPie,label:"Pie Chart"},{id:"doughnut",icon:s.Donut,label:"Donut Chart"},{id:"kpi",icon:s.TiSortNumerically,label:"KPI"}];function Vr({selectedChart:t,onChartChange:n}){var l;const a=s.useEditorStore(o=>o.card),r=((l=a==null?void 0:a.config)==null?void 0:l.pivotByColumns)&&a.config.pivotByColumns.length>0;return e.jsx("div",{className:"flex items-center justify-center gap-1",children:Br.map(o=>{if(o.requiresPivot&&!r)return null;const c=o.icon,i=t===o.id;return e.jsxs(s.Tooltip,{children:[e.jsx(s.TooltipTrigger,{asChild:!0,children:e.jsxs(s.Button,{variant:"ghost",size:"sm",onClick:()=>n(o.id),className:s.cn("h-8 w-8 p-0",i&&"bg-accent text-accent-foreground"),children:[e.jsx(c,{className:"h-4 w-4"}),e.jsx("span",{className:"sr-only",children:o.label})]})}),e.jsx(s.TooltipContent,{side:"bottom",children:e.jsx("p",{children:o.label})})]},o.id)})})}const xs=({dataType:t})=>{const n=s.getDataType(t);return n==="string"?e.jsx("span",{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(qe,{className:"h-3 w-3"})}):n==="number"?e.jsx("span",{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(ns,{className:"h-3 w-3"})}):n==="date"?e.jsx("span",{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"})}):n==="boolean"?e.jsx("span",{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(Us,{className:"h-3 w-3"})}):e.jsx("span",{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"})})};function zr({aliasTemplate:t,onAliasTemplateChange:n}){var d;const[a,r]=T.useState(t),[l,o]=T.useState(!1),c=(d=s.useEditorStore(u=>{var m;return(m=u.card.config)==null?void 0:m.pivotByColumns}))==null?void 0:d[0],i=c?`e.g. Min Sales in {{${c.name}}}`:"e.g. Min Sales in {{region}}";return e.jsxs("div",{className:"space-y-1",children:[e.jsx(s.Label,{className:"text-xs font-medium text-gray-600",children:"Pivot Alias Template"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(s.Input$1,{placeholder:i,value:l?a:t,onChange:u=>{r(u.target.value),o(!0)},onFocus:()=>o(!0),onPointerDown:u=>u.stopPropagation(),className:"h-8 text-xs",onKeyDown:u=>{u.key==="Enter"&&l&&a!==t?(n(a),o(!1)):u.key==="Escape"&&(r(t),o(!1))},"aria-label":"Edit alias template"}),l&&a!==t&&e.jsxs(e.Fragment,{children:[e.jsx(s.Button,{variant:"ghost",size:"icon",className:"h-6 w-6 p-0","aria-label":"Confirm alias template",onClick:()=>{n(a),o(!1)},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 alias template edit",onClick:()=>{r(t),o(!1)},children:e.jsx(s.X,{className:"h-4 w-4 text-gray-400"})})]})]})]})}function Ur({valueAliases:t,onValueAliasesChange:n}){const[a,r]=T.useState(null),[l,o]=T.useState(""),[c,i]=T.useState(""),d=()=>{n({...t,"":""})},u=x=>{const h={...t};delete h[x],n(h)},m=x=>{const h={...t};delete h[x],h[l]=c,n(h),r(null)};return e.jsxs("div",{className:"space-y-1",children:[e.jsx(s.Label,{className:"text-xs font-medium text-muted-foreground",children:"Pivot Value Aliases"}),e.jsxs("div",{className:"space-y-2",children:[Object.entries(t).map(([x,h],p)=>e.jsx("div",{className:"flex items-center gap-2",children:a===x?e.jsxs(e.Fragment,{children:[e.jsx(s.Input$1,{placeholder:"Value key",value:l,onChange:g=>o(g.target.value),className:"h-8 w-24 text-xs",onPointerDown:g=>g.stopPropagation(),onKeyDown:g=>{g.key==="Enter"?m(x):g.key==="Escape"&&r(null)},"aria-label":"Edit value alias key"}),e.jsx(s.Input$1,{placeholder:"Alias label",value:c,onChange:g=>i(g.target.value),className:"h-8 w-24 text-xs",onPointerDown:g=>g.stopPropagation(),onKeyDown:g=>{g.key==="Enter"?m(x):g.key==="Escape"&&r(null)},"aria-label":"Edit value alias label"}),e.jsx(s.Button,{variant:"ghost",size:"icon",className:"h-6 w-6 p-0","aria-label":"Confirm value alias edit",onClick:()=>m(x),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 value alias edit",onClick:()=>r(null),children:e.jsx(s.X,{className:"h-4 w-4 text-muted-foreground"})})]}):e.jsxs(e.Fragment,{children:[e.jsx(s.Input$1,{placeholder:"Value key",value:x,className:"h-8 w-24 text-xs",readOnly:!0,onClick:()=>{r(x),o(x),i(h)},"aria-label":"Edit value alias key"}),e.jsx(s.Input$1,{placeholder:"Alias label",value:h,className:"h-8 w-24 text-xs",readOnly:!0,onClick:()=>{r(x),o(x),i(h)},"aria-label":"Edit value alias label"}),e.jsx(s.Button,{variant:"ghost",size:"sm",className:"h-8 w-8 p-0",onClick:()=>u(x),"aria-label":"Remove value alias",children:e.jsx(s.X,{className:"h-3 w-3"})})]})},x+p)),e.jsxs(s.Button,{variant:"outline",size:"sm",className:"mt-1 h-8 text-xs",onClick:d,children:[e.jsx(s.Plus,{className:"mr-1 h-3 w-3"})," Add Value Alias"]})]})]})}function Gr({column:t}){const n=s.useEditorStore(d=>d.card.type),a=s.useEditorStore(d=>{var u,m;return(m=(u=d.card)==null?void 0:u.config)==null?void 0:m.metricColumns}),r=(a==null?void 0:a.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(yt,{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(Nt,{})]})}return e.jsxs("div",{className:"space-y-1",children:[["stackedBar","stackedLine","bar","line"].includes(n)&&c(),["pie","doughnut"].includes(n)&&i()]})}function _r({field:t,searchQuery:n="",limit:a=500}){const{authToken:r,tokenProps:l}=s.useSemaphorContext(),o=s.useEditorStore(u=>u.card),c=o==null?void 0:o.dataSource,i=["attribute-values",t.entityName,t.name,n,a],d=s.useQuery({queryKey:i,queryFn:async()=>{if(!(c!=null&&c.connectionId))return console.warn("No connection ID available for attribute values query"),[];try{const u={groupByColumns:[{...t,role:"groupby"}],metricColumns:[],filters:n?{id:"search-filter",logicalOperator:"AND",negate:!1,conditions:[{id:"search-condition",field:t,operator:"contains",value:n}],groups:[]}:void 0,rowLimit:a},m={connection_id:c.connectionId,cardConfig:u,cardDataSource:c,cache_config:s.getCacheConfig({card:o})};console.log("requestBody",m);const x=await s.postRequestRegular(`${l.apiServiceUrl}/v1/query`,(r==null?void 0:r.accessToken)||"",m);if(x!=null&&x.error)return console.error("Error fetching attribute values:",x.error),[];const h=t.name;return((x==null?void 0:x.records)||[]).map(g=>{const f=g[h]||g[t.alias||h]||g[t.label];return{id:f||"",value:f||"",label:String(f||"(empty)")}})}catch(u){return console.error("Error fetching attribute values:",u),[]}},enabled:!!t&&!!(c!=null&&c.connectionId),staleTime:5*60*1e3,gcTime:10*60*1e3});return{values:d.data||[],isLoading:d.isLoading,isFetching:d.isFetching,isError:d.isError,error:d.error,refetch:d.refetch}}function $r({open:t,onOpenChange:n,availableFields:a,existingFilters:r,editingCondition:l,onSave:o}){var F,k;const c=!!l,[i,d]=T.useState(c?"values":"fields"),[u,m]=T.useState(""),[x,h]=T.useState({id:(l==null?void 0:l.id)||s.v4(),field:(l==null?void 0:l.field)||null,selectedValues:l?Array.isArray(l.value)?l.value:[l.value]:[]}),p=a.filter(D=>{var j;return c?!1:!((j=r==null?void 0:r.conditions)==null?void 0:j.some(N=>N.field.id===D.id))&&D.label.toLowerCase().includes(u.toLowerCase())}),g=D=>{h({...x,field:D}),d("values")},f=()=>{if(x.field&&x.selectedValues.length>0){const D={id:x.id,field:x.field,operator:"in",value:x.selectedValues};let w;if(c){const j=((r==null?void 0:r.conditions)||[]).map(N=>N.id===l.id?D:N);w={...r,conditions:j}}else{const j=(r==null?void 0:r.conditions)||[];w={id:(r==null?void 0:r.id)||s.v4(),logicalOperator:"AND",negate:!1,conditions:[...j,D],groups:[]}}o(w),n(!1)}},y=()=>{if(!c||!l)return;const D=((r==null?void 0:r.conditions)||[]).filter(w=>w.id!==l.id);if(D.length>0){const w={...r,conditions:D};o(w)}else o(void 0);n(!1)},v=D=>{h({...x,selectedValues:D})},C=()=>{c&&l?(h({id:l.id,field:l.field,selectedValues:Array.isArray(l.value)?l.value:[l.value]}),d("values")):(h({id:s.v4(),field:null,selectedValues:[]}),d("fields")),m("")};return T.useEffect(()=>{t&&C()},[t,c,l]),e.jsx(s.Dialog,{open:t,onOpenChange:n,children:e.jsxs(s.DialogContent,{className:"max-w-2xl",children:[e.jsx(s.DialogHeader,{children:e.jsx(s.DialogTitle,{children:c?`Edit Filter: ${(F=x.field)==null?void 0:F.label}`:i==="fields"?"Select Field to Filter":`Select Values for ${(k=x.field)==null?void 0:k.label}`})}),e.jsxs("div",{className:"space-y-4",children:[!c&&(r==null?void 0:r.conditions)&&r.conditions.length>0&&i==="fields"&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(s.Label,{className:"text-xs font-medium text-muted-foreground",children:"Current Filters:"}),e.jsx("div",{className:"flex flex-wrap gap-2",children:r.conditions.map(D=>e.jsxs("div",{className:"flex items-center gap-1 px-2 py-1 bg-muted rounded-md text-xs",children:[e.jsxs("span",{className:"font-medium",children:[D.field.label,":"]}),e.jsx("span",{className:"text-muted-foreground",children:Array.isArray(D.value)?`${D.value.length} values`:String(D.value)})]},D.id))})]}),i==="fields"&&!c?e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"relative",children:[e.jsx(s.Search,{className:"absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground"}),e.jsx(s.Input$1,{placeholder:"Search fields...",value:u,onChange:D=>m(D.target.value),className:"pl-10"})]}),e.jsx("div",{className:"grid grid-cols-2 gap-2 max-h-[400px] overflow-y-auto",children:p.map(D=>e.jsxs(s.Button,{variant:"outline",className:"justify-start h-auto py-2 px-3",onClick:()=>g(D),children:[e.jsx(xs,{dataType:s.getDataType(D.dataType)}),e.jsxs("div",{className:"ml-2 text-left",children:[e.jsx("div",{className:"text-sm font-medium",children:D.label}),e.jsxs("div",{className:"text-xs text-muted-foreground",children:[D.entityName,".",D.name]})]})]},D.id))}),p.length===0&&u&&e.jsxs("div",{className:"text-center py-4 text-sm text-muted-foreground",children:['No fields found matching "',u,'"']}),p.length===0&&!u&&a.length>0&&e.jsx("div",{className:"text-center py-4 text-sm text-muted-foreground",children:"All available fields are already filtered"})]}):e.jsx(Yr,{field:x.field,selectedValues:x.selectedValues,onValuesChange:v,onBack:c?void 0:()=>d("fields")}),e.jsxs("div",{className:"flex justify-between pt-4 border-t",children:[e.jsx("div",{children:c?e.jsx(s.Button,{variant:"destructive",onClick:y,children:"Delete Filter"}):e.jsx(s.Button,{variant:"outline",onClick:C,children:"Reset"})}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(s.Button,{variant:"outline",onClick:()=>n(!1),children:"Cancel"}),e.jsx(s.Button,{onClick:f,disabled:!x.field||x.selectedValues.length===0,children:"Apply"})]})]})]})]})})}function Yr({field:t,selectedValues:n,onValuesChange:a,onBack:r}){const[l,o]=T.useState(""),{values:c,isLoading:i,isFetching:d}=_r({field:t,searchQuery:l,limit:500}),u=l?c.filter(h=>String(h.value).toLowerCase().includes(l.toLowerCase())):c,m=h=>{const p=n.includes(h);a(p?n.filter(g=>g!==h):[...n,h])},x=()=>{n.length===u.length&&u.length>0?a([]):a(u.map(h=>h.value))};return e.jsxs("div",{className:"space-y-4",children:[r&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(s.Button,{variant:"ghost",size:"sm",onClick:r,children:"← Back"}),e.jsxs(s.Label,{className:"text-sm font-medium",children:["Select values for ",t.label]})]}),e.jsxs("div",{className:"relative",children:[e.jsx(s.Search,{className:"absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground"}),e.jsx(s.Input$1,{placeholder:"Search values...",value:l,onChange:h=>o(h.target.value),className:"pl-10"})]}),i||d?e.jsx("div",{className:"flex items-center justify-center py-8",children:e.jsx(s.LoaderCircle,{className:"h-6 w-6 animate-spin"})}):e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-2 pb-2 border-b",children:[e.jsx(s.Checkbox,{checked:n.length===u.length&&u.length>0,onCheckedChange:x}),e.jsxs(s.Label,{className:"text-sm",children:["Select All (",u.length,")"]})]}),e.jsx("div",{className:"max-h-[300px] overflow-y-auto space-y-1",children:u.map(h=>e.jsxs("div",{className:"flex items-center gap-2 p-2 hover:bg-muted/50 rounded cursor-pointer",onClick:()=>m(h.value),children:[e.jsx(s.Checkbox,{checked:n.includes(h.value),onCheckedChange:()=>m(h.value)}),e.jsx(us,{className:"text-sm",children:h.label})]},h.id))})]})]})}function qr({field:t,zone:n,index:a,sortDirection:r,onSortDirectionChange:l,hasPivotColumns:o=!1,cardType:c}){var fs,gs,js;const{attributes:i,listeners:d,setNodeRef:u,transform:m,transition:x,isDragging:h}=s.useSortable({id:t.id}),p=s.useEditorStore(Y=>Y.card),{updateLabel:g,handleAggregationChange:f,handleDateFormatChange:y,handleGranularityChange:v,handleAliasTemplateChange:C,handleValueAliasesChange:F,removeField:k,handleKpiComparisonTypeChange:D,handleKpiShowTrendlineChange:w,handleKpiTrendlineWindowChange:j,handleKpiTrendlineGranularityChange:N,handleKpiTargetValueChange:b}=cs(p),[R,S]=T.useState(!1),[O,E]=T.useState(!1),[I,A]=T.useState(null),[M,L]=T.useState(t.dateFormat||"YYYY-MM-DD"),[P,B]=T.useState(t.customFormat||""),[K,_]=T.useState(!!t.customFormat),[z,U]=T.useState(t.granularity||"day"),[W,ee]=T.useState(t.aliasTemplate||""),[te,oe]=T.useState(t.valueAliases||{}),[H,q]=T.useState((fs=t.parameters)==null?void 0:fs.filters),ae=Y=>{Y==="custom"?_(!0):(_(!1),L(Y),n==="groupBy"&&y(a,Y,""))},J=Y=>{B(Y),n==="groupBy"&&y(a,"custom",Y)},re=Y=>{var je;U(Y);const xe=(je=Z(Y)[0])==null?void 0:je.value;xe&&!K&&(L(xe),n==="groupBy"&&y(a,xe,"")),n==="groupBy"&&v(a,Y)},G=Y=>{ee(Y),n==="metrics"&&C(a,Y)},se=Y=>{oe(Y),n==="metrics"&&F(a,Y)},ce=Y=>{g(n,a,Y)},le=Y=>{var he;if(q(Y),n==="metrics"){const xe={...t,parameters:{...t.parameters,filters:Y}},je=[...((he=p.config)==null?void 0:he.metricColumns)||[]];je[a]=xe,s.useEditorStore.getState().actions.updateCardConfig(p.id,{metricColumns:je})}E(!1)},fe=()=>{k(n,a)},ue={transform:s.CSS.Transform.toString(m),transition:x},Q=s.getDataType(t.dataType),$=Q==="date",V=c==="kpi",Z=Y=>{switch(Y){case"day":return[{value:"MM-DD-YYYY",label:"01-15-2024 (MM-DD-YYYY)"},{value:"YYYY-MM-DD",label:"2024-01-15 (YYYY-MM-DD)"},{value:"MM/DD/YYYY",label:"01/15/2024 (MM/DD/YYYY)"},{value:"DD/MM/YYYY",label:"15/01/2024 (DD/MM/YYYY)"},{value:"MMMM DD, YYYY",label:"January 15, 2024 (MMMM DD, YYYY)"},{value:"MMM DD, YYYY",label:"Jan 15, 2024 (MMM DD, YYYY)"},{value:"DD MMM YYYY",label:"15 Jan 2024 (DD MMM YYYY)"},{value:"custom",label:"Custom Format..."}];case"week":return[{value:"MM-DD-YYYY",label:"01-15-2024 (MM-DD-YYYY)"},{value:"YYYY-MM-DD",label:"2024-01-15 (YYYY-MM-DD)"},{value:"Week of MMM DD, YYYY",label:"Week of Jan 15, 2024"},{value:"Week of MMMM DD, YYYY",label:"Week of January 15, 2024"},{value:"YYYY-WW",label:"2024-W03 (YYYY-WW)"},{value:"custom",label:"Custom Format..."}];case"month":return[{value:"MMM YYYY",label:"Jan 2024 (MMM YYYY)"},{value:"MMMM YYYY",label:"January 2024 (MMMM YYYY)"},{value:"YYYY-MM",label:"2024-01 (YYYY-MM)"},{value:"MM/YYYY",label:"01/2024 (MM/YYYY)"},{value:"YYYY MMM",label:"2024 Jan (YYYY MMM)"},{value:"custom",label:"Custom Format..."}];case"quarter":return[{value:"Q1 YYYY",label:"Q1 2024 (Q1 YYYY)"},{value:"YYYY Q1",label:"2024 Q1 (YYYY Q1)"},{value:"1st Quarter YYYY",label:"1st Quarter 2024"},{value:"YYYY-Q1",label:"2024-Q1 (YYYY-Q1)"},{value:"Quarter 1, YYYY",label:"Quarter 1, 2024"},{value:"custom",label:"Custom Format..."}];case"year":return[{value:"YYYY",label:"2024 (YYYY)"},{value:"YY",label:"24 (YY)"},{value:"custom",label:"Custom Format..."}];default:return[{value:"MM-DD-YYYY",label:"01-15-2024 (MM-DD-YYYY)"},{value:"YYYY-MM-DD",label:"2024-01-15 (YYYY-MM-DD)"},{value:"MM/DD/YYYY",label:"01/15/2024 (MM/DD/YYYY)"},{value:"DD/MM/YYYY",label:"15/01/2024 (DD/MM/YYYY)"},{value:"MMMM DD, YYYY",label:"January 15, 2024 (MMMM DD, YYYY)"},{value:"MMM DD, YYYY",label:"Jan 15, 2024 (MMM DD, YYYY)"},{value:"DD MMM YYYY",label:"15 Jan 2024 (DD MMM YYYY)"},{value:"YYYY-MM",label:"2024-01 (YYYY-MM)"},{value:"MMMM YYYY",label:"January 2024 (MMMM YYYY)"},{value:"custom",label:"Custom Format..."}]}},ie=Z(z),de=n!=="pivotBy",ne=$&&n==="groupBy",me=!V&&$&&n==="groupBy",pe=V&&$&&n==="groupBy",Re=V&&n==="metrics"&&((gs=p.config)==null?void 0:gs.comparisonType)==="target",Le=n==="metrics",De=()=>e.jsx("div",{title:`${t.entityName}.${t.name}`,onPointerDown:Y=>{Y.stopPropagation()},className:"max-w-[270px] cursor-default overflow-hidden text-ellipsis whitespace-nowrap px-0.5 text-xs text-gray-500",children:`${t.entityName}.${t.name}`}),ve=()=>de?e.jsxs("div",{className:"space-y-1",children:[e.jsx(s.Label,{className:"text-xs font-medium text-muted-foreground",children:"Label"}),e.jsx(we,{value:t.label??"",onSave:ce,placeholder:"Display label...",type:"text"})]}):null,X=()=>ne?e.jsxs("div",{className:"space-y-1",children:[e.jsx(s.Label,{className:"text-xs font-medium text-muted-foreground",children:"Granularity"}),e.jsxs(s.Select,{value:z,onValueChange:re,children:[e.jsx(s.SelectTrigger,{className:"h-8 w-full text-xs",children:e.jsx(s.SelectValue,{placeholder:"Select granularity..."})}),e.jsx(s.SelectContent,{children:["day","week","month","quarter","year"].map(Y=>e.jsx(s.SelectItem,{className:"text-xs",value:Y,children:s.toTitleCase(Y)},Y))})]})]}):null,ge=()=>me?e.jsxs(e.Fragment,{children:[X(),e.jsxs("div",{className:"space-y-1",children:[e.jsx(s.Label,{className:"text-xs font-medium text-muted-foreground",children:"Date Format"}),e.jsxs(s.Select,{value:K?"custom":M,onValueChange:ae,children:[e.jsx(s.SelectTrigger,{className:"h-8 w-full text-xs",children:e.jsx(s.SelectValue,{placeholder:"Select date format..."})}),e.jsx(s.SelectContent,{children:ie.map(Y=>e.jsx(s.SelectItem,{className:"text-xs",value:Y.value,children:Y.label},Y.value))})]}),K&&e.jsxs("div",{className:"mt-2 space-y-1",children:[e.jsx(s.Input$1,{placeholder:"Enter custom format (e.g., YYYY-MM-DD HH:mm)",value:P,onChange:Y=>{Y.stopPropagation(),J(Y.target.value)},onClick:Y=>Y.stopPropagation(),className:"h-8 text-xs"}),e.jsx("div",{className:"text-xs text-muted-foreground",children:"Examples: YYYY-MM-DD, MM/DD/YY, DD-MMM-YYYY HH:mm"})]})]})]}):null,Be=()=>{var Y,he,xe,je,Te;return pe?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(s.Label,{className:"text-xs font-medium text-muted-foreground",children:"Comparison Type"}),e.jsxs(s.Select,{value:((Y=p.config)==null?void 0:Y.comparisonType)||"none",onValueChange:D,children:[e.jsx(s.SelectTrigger,{className:"h-8 w-full text-xs",children:e.jsx(s.SelectValue,{placeholder:"Select comparison type..."})}),e.jsxs(s.SelectContent,{children:[e.jsx(s.SelectItem,{value:"none",children:"No Comparison"}),e.jsx(s.SelectItem,{value:"previous_period",children:"Previous Period"}),e.jsx(s.SelectItem,{value:"same_period_last_year",children:"Same Period Last Year"}),e.jsx(s.SelectItem,{value:"target",children:"Target Value"})]})]})]}),e.jsx("div",{className:"space-y-1",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(s.Label,{className:"text-xs font-medium text-muted-foreground",children:"Show Trendline"}),e.jsx(s.SmallSwitch,{checked:((he=p.config)==null?void 0:he.showTrendline)||!1,onCheckedChange:w})]})}),((xe=p.config)==null?void 0:xe.showTrendline)&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(s.Label,{className:"text-xs font-medium text-muted-foreground",children:"Trendline Window"}),e.jsx(s.Input$1,{type:"number",min:"1",max:"365",value:((je=p.config)==null?void 0:je.trendlineWindow)||30,onChange:ze=>{const Ft=parseInt(ze.target.value)||30;j(Ft)},className:"h-8 text-xs",placeholder:"30"})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(s.Label,{className:"text-xs font-medium text-muted-foreground",children:"Trendline Granularity"}),e.jsxs(s.Select,{value:((Te=p.config)==null?void 0:Te.trendlineGranularity)||"day",onValueChange:N,children:[e.jsx(s.SelectTrigger,{className:"h-8 w-full text-xs",children:e.jsx(s.SelectValue,{placeholder:"Select granularity..."})}),e.jsxs(s.SelectContent,{children:[e.jsx(s.SelectItem,{value:"day",children:"Day"}),e.jsx(s.SelectItem,{value:"week",children:"Week"}),e.jsx(s.SelectItem,{value:"month",children:"Month"})]})]})]})]})]}):null},ke=()=>{var Y,he;return Re?e.jsxs("div",{className:"space-y-1",children:[e.jsx(s.Label,{className:"text-xs font-medium text-muted-foreground",children:"Target Value"}),e.jsx(we,{value:((Y=p.config)==null?void 0:Y.targetValue)!==void 0&&((he=p.config)==null?void 0:he.targetValue)!==null?String(p.config.targetValue):"",onSave:xe=>{!isNaN(Number(xe))&&xe!==null?b(Number(xe)):b(0)},placeholder:"Enter target value...",type:"text"})]}):null},Mt=()=>Le?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(s.Label,{className:"text-xs font-medium text-muted-foreground",children:"Aggregation"}),e.jsxs(s.Select,{value:t.aggregate,onValueChange:Y=>{f(a,Y)},children:[e.jsx(s.SelectTrigger,{className:"h-8 w-full text-xs",children:e.jsx(s.SelectValue,{placeholder:"Select function..."})}),e.jsxs(s.SelectContent,{children:[e.jsx(s.SelectItem,{className:"text-xs",value:"COUNT",children:"Count"}),e.jsx(s.SelectItem,{className:"text-xs",value:"DISTINCT",children:"Count Distinct"}),s.getDataType(t.dataType)==="number"&&e.jsxs(e.Fragment,{children:[e.jsx(s.SelectItem,{className:"text-xs",value:"SUM",children:"Sum"}),e.jsx(s.SelectItem,{className:"text-xs",value:"AVG",children:"Average"}),e.jsx(s.SelectItem,{className:"text-xs",value:"MIN",children:"Min"}),e.jsx(s.SelectItem,{className:"text-xs",value:"MAX",children:"Max"}),e.jsx(s.SelectItem,{className:"text-xs",value:"MEDIAN",children:"Median"})]})]})]})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(s.Label,{className:"text-xs font-medium text-muted-foreground",children:"Attribute Filters"}),(H==null?void 0:H.conditions)&&H.conditions.length>0&&e.jsx("div",{className:"mb-2 space-y-1",children:H.conditions.map(Y=>e.jsxs("div",{className:"flex cursor-pointer items-center gap-2 rounded bg-muted/50 p-2 text-xs transition-colors hover:bg-muted/70",onClick:()=>{A(Y),E(!0)},children:[e.jsxs("span",{className:"font-medium",children:[Y.field.label,":"]}),e.jsx(s.TooltipProvider,{children:e.jsxs(s.Tooltip,{children:[e.jsx(s.TooltipTrigger,{asChild:!0,children:e.jsx("span",{className:"cursor-help text-muted-foreground",children:Array.isArray(Y.value)?Y.value.length===1?String(Y.value[0]):Y.value.length<=2?Y.value.join(", "):`${Y.value.slice(0,2).join(", ")} +${Y.value.length-2}`:String(Y.value)})}),Array.isArray(Y.value)&&Y.value.length>1&&e.jsx(s.TooltipContent,{side:"top",className:"max-w-[300px]",children:e.jsxs("div",{className:"text-xs",children:[e.jsxs("div",{className:"mb-1 font-medium",children:["Selected values (",Y.value.length,"):"]}),e.jsx("div",{className:"max-h-[200px] overflow-y-auto",children:Y.value.map((he,xe)=>e.jsx("div",{children:String(he)},xe))})]})})]})}),e.jsx(s.Button,{variant:"ghost",size:"sm",className:"ml-auto h-4 w-4 p-0",onClick:he=>{var je;he.stopPropagation();const xe=H.conditions.filter(Te=>Te.id!==Y.id);if(xe.length>0){const Te={...H,conditions:xe};le(Te)}else if(q(void 0),n==="metrics"){const Te={...t,parameters:{...t.parameters,filters:void 0}},ze=[...((je=p.config)==null?void 0:je.metricColumns)||[]];ze[a]=Te,s.useEditorStore.getState().actions.updateCardConfig(p.id,{metricColumns:ze})}},children:e.jsx(s.X,{className:"h-3 w-3"})})]},Y.id))}),e.jsxs(s.Button,{variant:"outline",size:"sm",className:"h-8 w-full justify-start text-xs",onClick:()=>{A(null),E(!0)},children:[e.jsx(s.Filter,{className:"mr-2 h-3 w-3"}),"Add attribute filter"]})]}),e.jsx(Gr,{column:t}),o&&e.jsxs(e.Fragment,{children:[e.jsx(zr,{aliasTemplate:W,onAliasTemplateChange:G}),e.jsx(Ur,{valueAliases:te,onValueAliasesChange:se})]})]}):null,{columns:Rt=[]}=s.useColumns(),Lt=(H==null?void 0:H.conditions)&&H.conditions.length>0;return e.jsxs(e.Fragment,{children:[e.jsxs("div",{ref:u,style:ue,...i,...d,className:`group mx-auto flex w-full flex-col gap-2 rounded border border-border bg-background p-2 transition-all hover:shadow-sm dark:border-gray-800 ${h?"z-50 scale-95 opacity-50":"border-slate-200"} ${n==="filters"?"cursor-default":"cursor-move"}`,children:[e.jsxs("div",{className:"flex grow items-center gap-2",children:[e.jsx(xs,{dataType:Q}),e.jsx(us,{className:s.cn("w-[140px] flex-1 text-sm",Lt&&"w-[120px]"),children:s.getMetricDisplayLabel(t)}),n==="metrics"&&((js=H==null?void 0:H.conditions)==null?void 0:js.length)&&!R&&e.jsx(s.TooltipProvider,{children:e.jsxs(s.Tooltip,{children:[e.jsx(s.TooltipTrigger,{asChild:!0,children:e.jsxs("div",{className:"flex items-center gap-1 rounded bg-primary/10 px-1.5 py-0.5 text-xs",children:[e.jsx(s.Filter,{className:"h-3 w-3"}),e.jsx("span",{children:H.conditions.length})]})}),e.jsx(s.TooltipContent,{side:"top",children:e.jsx("div",{className:"text-xs",children:H.conditions.map(Y=>e.jsxs("div",{children:[Y.field.label,":"," ",Array.isArray(Y.value)?`${Y.value.length} values`:String(Y.value)]},Y.id))})})]})}),n!=="sortBy"&&e.jsx(s.Button,{variant:"ghost",size:"sm",className:"h-6 w-6 p-0",onClick:Y=>{Y.stopPropagation(),S(!R)},children:e.jsx(s.ChevronDown,{className:`h-3 w-3 transition-transform ${R?"rotate-180":""}`})}),n==="sortBy"&&e.jsx(s.Button,{variant:"ghost",size:"sm",className:"h-6 w-6 p-0",onClick:Y=>{Y.stopPropagation(),console.log("DraggableField - Current sortDirection:",r);const he=r==="asc"?"desc":"asc";console.log("DraggableField - New direction to set:",he),l(he)},children:r==="asc"?e.jsx(s.ArrowUp,{className:"h-3 w-3"}):e.jsx(s.ArrowDown,{className:"h-3 w-3"})}),e.jsx(s.Button,{variant:"ghost",size:"sm",className:"h-6 w-6 p-0",onClick:Y=>{Y.stopPropagation(),fe()},children:e.jsx(s.X,{className:"h-2.5 w-2.5"})})]}),R&&e.jsxs("div",{className:"space-y-3",children:[De(),ve(),c==="kpi"&&X(),ge(),Be(),ke(),Mt()]})]}),O&&e.jsx($r,{open:O,onOpenChange:Y=>{E(Y),Y||A(null)},availableFields:Rt,existingFilters:H,editingCondition:I,onSave:Y=>{var he;if(Y)le(Y);else if(q(void 0),n==="metrics"){const xe={...t,parameters:{...t.parameters,filters:void 0}},je=[...((he=p.config)==null?void 0:he.metricColumns)||[]];je[a]=xe,s.useEditorStore.getState().actions.updateCardConfig(p.id,{metricColumns:je})}A(null)}})]})}function Kr({concept:t}){const n=()=>{switch(t){case"groupBy":return e.jsxs("div",{className:"w-64 space-y-2",children:[e.jsx("h4",{className:"text-sm font-medium",children:"Rows = Group By"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Fields that define how your data is grouped into rows."}),e.jsxs("div",{className:"rounded-md border bg-white p-2 dark:border-muted dark:bg-muted",children:[e.jsxs("div",{className:"flex border-b pb-1 dark:border-border",children:[e.jsx("div",{className:"w-1/3 bg-blue-100 text-xs font-medium dark:bg-blue-200/20",children:"Product"}),e.jsx("div",{className:"w-1/3 text-center text-xs",children:"Sales"}),e.jsx("div",{className:"w-1/3 text-center text-xs",children:"Profit"})]}),e.jsxs("div",{className:"flex border-b dark:border-border",children:[e.jsx("div",{className:"w-1/3 bg-blue-200/50 text-xs font-medium dark:bg-blue-200/20",children:"Electronics"}),e.jsx("div",{className:"w-1/3 text-center text-xs",children:"$5,200"}),e.jsx("div",{className:"w-1/3 text-center text-xs",children:"$1,300"})]}),e.jsxs("div",{className:"flex border-b dark:border-border",children:[e.jsx("div",{className:"w-1/3 bg-blue-200/30 text-xs font-medium dark:bg-blue-300/20",children:"Clothing"}),e.jsx("div",{className:"w-1/3 text-center text-xs",children:"$3,100"}),e.jsx("div",{className:"w-1/3 text-center text-xs",children:"$620"})]}),e.jsxs("div",{className:"flex",children:[e.jsx("div",{className:"w-1/3 bg-blue-200/20 text-xs font-medium dark:bg-blue-200/20",children:"Food"}),e.jsx("div",{className:"w-1/3 text-center text-xs",children:"$2,400"}),e.jsx("div",{className:"w-1/3 text-center text-xs",children:"$480"})]})]})]});case"pivotBy":return e.jsxs("div",{className:"w-64 space-y-2",children:[e.jsx("h4",{className:"text-sm font-medium",children:"Columns = Pivot By"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Fields that split your data into multiple columns or series."}),e.jsxs("div",{className:"rounded-md border bg-white p-2 dark:border-muted dark:bg-muted",children:[e.jsxs("div",{className:"flex border-b pb-1 dark:border-border",children:[e.jsx("div",{className:"w-1/4 text-xs font-medium",children:"Region"}),e.jsx("div",{className:"w-1/4 rounded-t bg-purple-50 text-center text-xs dark:bg-purple-300/20",children:"North"}),e.jsx("div",{className:"w-1/4 rounded-t bg-purple-100 text-center text-xs dark:bg-purple-400/20",children:"South"}),e.jsx("div",{className:"w-1/4 rounded-t bg-purple-50 text-center text-xs dark:bg-purple-300/20",children:"East"})]}),e.jsxs("div",{className:"flex border-b py-1 dark:border-border",children:[e.jsx("div",{className:"w-1/4 text-xs font-medium",children:"Sales"}),e.jsx("div",{className:"w-1/4 bg-purple-50 text-center text-xs dark:bg-purple-300/20",children:"$2,300"}),e.jsx("div",{className:"w-1/4 bg-purple-100 text-center text-xs dark:bg-purple-400/20",children:"$1,800"}),e.jsx("div",{className:"w-1/4 bg-purple-50 text-center text-xs dark:bg-purple-300/20",children:"$3,400"})]}),e.jsxs("div",{className:"flex py-1",children:[e.jsx("div",{className:"w-1/4 text-xs font-medium",children:"Profit"}),e.jsx("div",{className:"w-1/4 rounded-b bg-purple-50 text-center text-xs dark:bg-purple-300/20",children:"$460"}),e.jsx("div",{className:"w-1/4 rounded-b bg-purple-100 text-center text-xs dark:bg-purple-400/20",children:"$360"}),e.jsx("div",{className:"w-1/4 rounded-b bg-purple-50 text-center text-xs dark:bg-purple-300/20",children:"$680"})]})]})]});case"metrics":return e.jsxs("div",{className:"w-64 space-y-2",children:[e.jsx("h4",{className:"text-sm font-medium",children:"Metrics = Values (Cells)"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Fields that represent the values shown in your visualization."}),e.jsxs("div",{className:"rounded-md border bg-white p-2 dark:border-muted dark:bg-muted",children:[e.jsxs("div",{className:"grid grid-cols-4 gap-1",children:[e.jsx("div",{className:"col-span-1"}),e.jsx("div",{className:"col-span-1 text-center text-xs font-medium",children:"Q1"}),e.jsx("div",{className:"col-span-1 text-center text-xs font-medium",children:"Q2"}),e.jsx("div",{className:"col-span-1 text-center text-xs font-medium",children:"Q3"})]}),e.jsxs("div",{className:"mt-1 grid grid-cols-4 gap-1",children:[e.jsx("div",{className:"text-xs font-medium",children:"Sales"}),e.jsx("div",{className:"rounded bg-blue-100 p-1 text-center text-xs dark:bg-blue-300/20",children:"$2,300"}),e.jsx("div",{className:"rounded bg-blue-200 p-1 text-center text-xs dark:bg-blue-400/20",children:"$3,100"}),e.jsx("div",{className:"rounded bg-blue-300 p-1 text-center text-xs dark:bg-blue-500/20",children:"$4,200"})]}),e.jsxs("div",{className:"mt-1 grid grid-cols-4 gap-1",children:[e.jsx("div",{className:"text-xs font-medium",children:"Profit"}),e.jsx("div",{className:"rounded bg-green-100 p-1 text-center text-xs dark:bg-green-300/20",children:"$460"}),e.jsx("div",{className:"rounded bg-green-200 p-1 text-center text-xs dark:bg-green-400/20",children:"$620"}),e.jsx("div",{className:"rounded bg-green-300 p-1 text-center text-xs dark:bg-green-500/20",children:"$840"})]})]})]});default:return null}};return e.jsx(s.TooltipProvider,{children:e.jsxs(s.Tooltip,{delayDuration:300,children:[e.jsx(s.TooltipTrigger,{asChild:!0,children:e.jsx(s.CircleHelp,{className:"size-4 text-muted-foreground hover:text-foreground"})}),e.jsx(s.TooltipContent,{side:"right",align:"start",className:"p-3",children:n()})]})})}function _e({zone:t,fields:n,label:a,placeholder:r,shouldShow:l,hasPivotColumns:o=!1}){const{isOver:c,setNodeRef:i}=s.useDroppable({id:t}),{updateSortByColumn:d}=s.useEditorActions(),u=s.useEditorStore(g=>g.card),m=s.useEditorStore(g=>g.card.type),x=n.length>0,h=(g,f)=>{var v;!((v=u.config)!=null&&v.sortByColumns)||u.config.sortByColumns.findIndex(C=>C.id===g)===-1||d(u.id,g,{direction:f})};if(t==="sortBy"&&l===!1)return null;const p=t!=="sortBy"&&m!=="kpi";return e.jsxs("div",{className:"mb-4 w-full",children:[e.jsxs("div",{className:"mb-2 flex items-center gap-2",children:[e.jsx(s.Label,{className:s.cn("block text-sm font-medium",{}),children:a}),p&&e.jsx(Kr,{concept:t})]}),e.jsx("div",{ref:i,className:`rounded-lg border-2 border-dashed p-1 transition-all ${c?"border-blue-500 bg-blue-50 dark:bg-blue-950":x?"border-blue-200 bg-blue-50/30 dark:border-blue-800 dark:bg-blue-950/30":"min-h-[60px] border-muted-foreground/20 bg-background"}`,children:n.length===0?e.jsx("div",{className:"flex min-h-[40px] items-center justify-center text-sm text-gray-400",children:r}):e.jsx(s.SortableContext,{items:n.map(g=>g.id),strategy:s.verticalListSortingStrategy,children:e.jsx("div",{className:"flex flex-wrap gap-1",children:n.map((g,f)=>{const v=g.direction;return e.jsx("div",{className:"flex w-full items-center gap-2",children:e.jsx("div",{className:"flex-1",children:e.jsx(qr,{field:g,zone:t,index:f,sortDirection:v,onSortDirectionChange:C=>h(g.id,C),hasPivotColumns:o,cardType:m})})},g.id)})})})})]})}const Ls=[{value:"green",color:"#16a34a",label:"Green"},{value:"red",color:"#dc2626",label:"Red"},{value:"neutral",color:"#6b7280",label:"Neutral"}],Qr=["#16a34a","#dc2626","#6b7280","#2563eb","#ca8a04","#7c3aed","#0891b2","#e11d48","#ea580c"];function es({value:t,onChange:n,label:a}){const[r,l]=T.useState(!1),[o,c]=T.useState(!1),i=()=>{const d=Ls.find(u=>u.value===t);return d?d.color:t.startsWith("#")?t:Ls[2].color};return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(s.Popover,{open:r,onOpenChange:l,children:[e.jsx(s.PopoverTrigger,{asChild:!0,children:e.jsx("button",{className:"size-5 rounded border-2 border-input shadow-sm transition-all hover:scale-110 hover:border-gray-400",style:{backgroundColor:i()},"aria-label":`Change color for ${a}`})}),e.jsx(s.PopoverContent,{align:"start",className:"w-auto p-2",children:e.jsxs("div",{className:"space-y-2",children:[e.jsx("div",{className:"grid grid-cols-3 items-center justify-items-center gap-1",children:Qr.map(d=>e.jsx("button",{className:s.cn("h-5 w-5 rounded border-2 transition-all",i()===d?"border-gray-900":"border-transparent"),style:{backgroundColor:d},onClick:()=>{n(d),l(!1)},children:e.jsx("span",{className:"sr-only",children:d})},d))}),e.jsx("button",{className:"w-full rounded border border-input px-2 py-1 text-xs hover:bg-muted",onClick:()=>{c(!0),l(!1)},children:"Custom color..."})]})})]}),e.jsx("span",{className:"text-xs text-muted-foreground",children:a})]}),o&&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:()=>c(!1)}),e.jsx("div",{className:"relative rounded-lg bg-white shadow-lg",children:e.jsx(Ct,{color:i(),onColorChange:d=>{n(d),c(!1)},onClose:()=>c(!1)})})]})]})}const $e={difference:{label:"Difference",description:"Shows the exact difference between two values.",formula:"Primary - Secondary",example:"Sales increased by $5,000 compared to last year."},change:{label:"Change",description:"Shows the percentage increase or decrease between two values.",formula:"(Primary - Secondary) / Secondary × 100%",example:"Year-over-year sales change of 25%."},change_difference:{label:"Change (difference)",description:"Shows both the percentage change and the exact difference between two values.",formula:`% Change: (Primary - Secondary) / Secondary × 100%
|
|
278
|
+
`;F(z)}function B(){return e.jsxs(e.Fragment,{children:[l&&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(Ln,{jsonString:JSON.stringify(m,null,2)})})}),m&&m.length>0&&e.jsx(s.Button,{variant:"ghost",onClick:()=>o(!l),className:"absolute bottom-0 right-6 size-7 p-1",children:l?e.jsx(s.X,{className:"size-3.5 text-muted-foreground"}):e.jsx(s.Filter,{className:"size-3.5 text-muted-foreground"})})]})}function K(){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(Mn,{})}),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(Rn,{})}),e.jsx("code",{className:"absolute right-6 top-3 text-xs text-muted-foreground/70",children:"python"})]})]})]})}function _(){return e.jsx("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:b||R,onClick:()=>{M()},className:"h-8 shrink-0",size:"sm",children:[b||R?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(In,{errorSql:I,sql:N==null?void 0:N.sql,error:L,onDebugWithAssistant:P}),e.jsx(os,{}),e.jsx(s.Toggle,{pressed:a,onPressedChange:z=>r(z),className:"h-8",size:"sm",variant:"outline",children:e.jsx(An,{className:"size-4 text-foreground/70"})}),e.jsx("button",{disabled:i,onClick:()=>{k(!0)},className:"h-9 w-full cursor-text px-3 text-left text-sm text-muted-foreground",children:i?"":"Type your question..."})]})})}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:[K(),B()]}),_()]})}const On=[{value:"table",label:"Table",icon:s.Table2},{value:"aggregateTable",label:"Aggregate",icon:s.Layers},{value:"pivotTable",label:"Pivot",icon:He}];function Pn({className:t}){const n=s.useEditorStore(d=>d.card),{setCardType:a,setCard:r,updateCardInFrame:l}=s.useEditorActions(),o=["table","aggregateTable","pivotTable"].includes(n.type),c=s.hasValidCardConfig(n.config);if(!o||!c)return null;const i=d=>{var m;const u=d;if(u==="aggregateTable"&&((m=n.config)!=null&&m.pivotByColumns)&&n.config.pivotByColumns.length>0){const x={...n,type:u,config:{...n.config,pivotByColumns:[]}};r(x),l(x)}else{a(u);const x={...n,type:u};l(x)}};return e.jsx("div",{className:s.cn("flex items-center",t),children:e.jsx(s.RadioGroup,{value:n.type,onValueChange:i,className:"flex flex-row items-center justify-between gap-1 rounded-lg border p-1",children:On.map(d=>{const u=d.icon,m=n.type===d.value;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",m?"bg-muted text-foreground shadow-sm":"text-muted-foreground hover:bg-muted/50"),children:[e.jsx(u,{className:"h-3.5 w-3.5"}),d.label]})]},d.value)})})})}function Bn({card:t}){var F,k,D,w,j,N,b,R,S,O,E;const[n,a]=T.useState(!1),[r,l]=T.useState([]),{authToken:o}=s.useSemaphorContext(),{theme:c}=s.useTheme(),i=s.getTokenParams(o==null?void 0:o.accessToken),d=s.useDashboardStore(I=>I.themeStyle),u={mode:c||"system",colors:((k=(F=d==null?void 0:d.chart)==null?void 0:F.dataset)==null?void 0:k.backgroundColor)||[]};(D=t.customCardPreferences)!=null&&D.inputData;const{getCard:m}=s.useCustomVisual(((w=t.customCardPreferences)==null?void 0:w.url)||""),x=((j=t.customCardPreferences)==null?void 0:j.visualType)||"single",h=s.useEditorStore(I=>I.frame),{setCustomCardPreferences:p}=s.useEditorActions(),{data:g}=s.useDashboardCardQuery(t),f=T.useCallback((I,A)=>{l(M=>({...M,[I]:A}))},[]);if(!((N=t.customCardPreferences)!=null&&N.componentName))return null;const y=m((b=t.customCardPreferences)==null?void 0:b.componentName);function v(I){a(I)}const C=Object.keys(((R=t.customCardPreferences)==null?void 0:R.dataInputCardIds)||{}).map(I=>{var L,P,B;const A=(P=(L=t.customCardPreferences)==null?void 0:L.dataInputCardIds)==null?void 0:P[I].cardId,M=(B=h==null?void 0:h.cards)==null?void 0:B.find(K=>K.id===A);return M||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(T.Suspense,{fallback:e.jsx(e.Fragment,{}),children:[y&&x==="single"&&e.jsx(y,{editing:!0,params:i,theme:u,settings:(S=t.customCardPreferences)==null?void 0:S.settings,onDataChange:f,data:(g==null?void 0:g.records)||[]}),y&&x==="multiple"&&e.jsxs(e.Fragment,{children:[Object.keys(((O=t.customCardPreferences)==null?void 0:O.dataInputCardIds)||{}).map(I=>{var L,P,B;const A=(P=(L=t.customCardPreferences)==null?void 0:L.dataInputCardIds)==null?void 0:P[I].cardId,M=(B=h==null?void 0:h.cards)==null?void 0:B.find(K=>K.id===A);if(M)return e.jsx(s.MultiInputEmptyRenderer,{onLoadingStatus:v,onDataChange:f,dataInputIndex:I,card:M},M.id+I)}),e.jsx("div",{className:"flex flex-col gap-2",children:e.jsx(y,{theme:u,onDataChange:f,settings:C.map(I=>{var A;return(A=I==null?void 0:I.customCardPreferences)==null?void 0:A.settings}),data:C.map(I=>I!=null&&I.id?r==null?void 0:r[I.id]:[])})})]})]},(E=t.customCardPreferences)==null?void 0:E.componentName)})}function ht({className:t,...n}){var N;const a=s.useEditorStore(b=>b.card),r=s.hasValidCardConfig(a.config),l=((N=a.customCardPreferences)==null?void 0:N.showCardHeader)??!0,o=s.useEditorStore(b=>b.frame),c=s.useDashboardStore(b=>b.dashboard.filters),i=s.useEditorStore(b=>b.actions.setRunSql),{updateFilter:d}=s.useDashboardActions(),u=c==null?void 0:c.find(b=>b.id===o.filterId),{data:m,isLoading:x,isFetching:h,errorMessage:p,pagination:g}=s.useDashboardCardQuery(a),{setCard:f,updateCardInFrame:y}=s.useEditorActions(),{data:v}=s.useTopoJson(a),C=T.useMemo(()=>{var b;return a.type!=="pivotTable"||!((b=m==null?void 0:m.records)!=null&&b.length)?null:{records:m.records,columnSubtotalMeta:m.columnSubtotalMeta,subtotalColumns:m.subtotalColumns||[],pivotSchema:m.pivotSchema||[],groupByColumns:m.groupByColumns}},[a.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]),F=s.usePivotTableConfig(a,C),k=(b,R)=>{var O,E;const S={...a,paginationConfig:{page:b+1,pageSize:R}};f(S),y(S),a.sql&&((E=(O=a.preferences)==null?void 0:O.tablePrefs)!=null&&E.enableDevModePagination)&&i(!0)},D=T.useMemo(()=>!a.id||!(m!=null&&m.records)?null:s.createChartConfig({card:a,data:m==null?void 0:m.records,cardType:a.type,queryConfig:a.queryConfig,customCfg:a.customCfg,preferences:a.preferences,topoJson:v}),[a.id,m==null?void 0:m.records,a.type,a.queryConfig,a.customCfg,a.preferences,v]);function w(b){return e.jsx(s.ErrorBoundary,{FallbackComponent:s.FallbackVisual,children:e.jsx(Bn,{card:b})})}function j(){if(m!=null&&m.records&&(m==null?void 0:m.records.length)===0&&!x&&!h)return p?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((x||h)&&a.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(!a.id)return null;if(a.type==="custom")return w(a);if(!["table","pivotTable","aggregateTable","custom"].includes(a.type)&&D)return e.jsx("div",{className:"relative h-full min-h-0 w-full flex-1 grow basis-0",children:x||h?e.jsx(e.Fragment,{}):e.jsx(s.ChartJsVisual,{cfg:D})});if(a.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:a,data:(m==null?void 0:m.records)||[],paginationMetadata:g,onPaginationChange:k,isLoading:x||h})});if(a.type==="pivotTable"&&F)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:a,data:F.data,options:F.options,onAggregationChange:b=>{const R=s.handleAggregationChange(b,a.config),S={...a,config:R};f(S),y(S)},onAggregationLabelChange:b=>{const R=s.handleAggregationLabelChange(b,a.config),S={...a,config:R};f(S),y(S)}})});if(a.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:a,data:(m==null?void 0:m.records)||[],groupByColumns:m==null?void 0:m.groupByColumns,pivotSchema:m==null?void 0:m.pivotSchema,paginationMetadata:g,onPaginationChange:k,onAggregationChange:b=>{const R=s.handleAggregationChange(b,a.config),S={...a,config:R};f(S),y(S)},isLoading:x||h})})}return e.jsxs(s.Card,{role:"editor-visual-card",className:s.cn("relative flex h-full flex-col rounded-none",t),...n,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 justify-between gap-5",children:[e.jsx(s.CardTitle,{className:"text-base",children:e.jsx(s.EditableText,{value:a.title,onSave:b=>f({...a,title:b}),isEditable:!0,placeholder:"Add title",displayClassName:"text-base font-semibold",inputClassName:"text-base font-semibold"})}),e.jsx(Pn,{})]}),e.jsx("div",{className:"w-1/2",children:e.jsx(s.EditableText,{value:a.description||"",onSave:b=>f({...a,description:b}),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:b=>d({...u,title:b}),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:j()})]})}const Xe=({language:t,value:n,onChange:a,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:n,onChange:a}),Vn=()=>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."})]})]}),zn=({customCode:t,cardCustomCfgString:n,mergedConfig:a,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(Xe,{language:"json",value:a,onChange:r})}),e.jsx(s.TabsContent,{value:"custom-config",className:"mt-0 grow rounded-b border border-t-0",children:e.jsx(Xe,{readonly:!0,language:"json",value:n,onChange:()=>{}})}),e.jsx(s.TabsContent,{value:"custom-code",className:"mt-0 grow rounded-b border border-t-0",children:e.jsx(Xe,{language:"javascript",value:t,onChange:l})})]}),Un=({error:t,hasCardCustomConfig:n,onReset:a,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:!n,onClick:a,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 Gn(){const[t,n]=T.useState(!1),[a,r]=T.useState(""),[l,o]=T.useState(""),[c,i]=T.useState(""),[d,u]=T.useState(""),m=s.useEditorStore(D=>D.card),x=s.useEditorStore(D=>D.card.customCfg),h=x?JSON.stringify(x,null,2):"",{data:p}=s.useDashboardCardQuery(m),{data:g}=s.useTopoJson(m),{setCardCustomCfg:f,setCustomVisualCode:y}=s.useEditorActions(),v=D=>{var w,j;return JSON.stringify({...D,data:{...D.data,datasets:(j=(w=D.data)==null?void 0:w.datasets)==null?void 0:j.map(N=>({...N,data:[]}))}},null,2)},C=()=>{var w,j;if(!((w=p==null?void 0:p.records)!=null&&w.length))return;const D=s.createChartConfig({card:m,data:p.records,cardType:m.type,queryConfig:m.queryConfig,preferences:m.preferences,topoJson:g});if(D){r(v(D)),i(((j=m.preferences)==null?void 0:j.customVisualCode)||"");const N=s.merge(D,x);o(v(N))}},F=()=>{try{if(c&&y(c),l){const D=JSON.parse(l),w=s.getObjectDiff(JSON.parse(a),D);f(w),u("")}}catch{u("Invalid JSON configuration")}},k=Object.keys(x||{}).length===0;return e.jsxs(s.Dialog,{open:t,onOpenChange:n,children:[e.jsx(s.DialogTrigger,{asChild:!0,children:e.jsx(s.IconButton,{tooltip:"Customize Visual",onClick:C,className:k?"":"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(Vn,{}),e.jsxs("div",{className:"flex grow gap-2",children:[e.jsx(s.ErrorBoundary,{FallbackComponent:s.FallbackVisual,children:e.jsx(ht,{className:"w-1/2 rounded shadow-none"})}),e.jsx(zn,{customCode:c,cardCustomCfgString:h,mergedConfig:l,onConfigChange:D=>o(D??""),onCodeChange:D=>i(D??"")})]}),e.jsx(Un,{error:d,hasCardCustomConfig:!!x,onReset:()=>{o(a),f(null)},onApply:F,onClose:()=>n(!1)})]})]})}function Je(t){const[n,a]=T.useState(null);return n}function xt(){const{authToken:t,tokenProps:n}=s.useSemaphorContext(),{data:a,isLoading:r,isFetching:l,isError:o}=s.useQuery({queryKey:["plugins",t==null?void 0:t.accessToken],queryFn:()=>s.getPlugins(n.apiServiceUrl,t==null?void 0:t.accessToken)});return{data:a,isLoading:r,isFetching:l,isError:o}}function pt(){const{data:t,isLoading:n,isError:a}=xt(),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=n,c=a;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],x=i.data.visuals.map(h=>({name:h.name,pluginName:m.label,componentType:h.componentType,pluginType:m.type,icon:h.icon,chartType:h.chartType,url:m.value}));l.push(...x)}}),{data:l,isLoading:o,isError:c}}function _n({onChartTypeChange:t}){const{setCardCustomCfg:n,setCardPreferences:a,setCardType:r,setCustomCardPreferences:l}=s.useEditorActions(),{data:o,isLoading:c,isError:i}=pt(),d=T.useCallback((u,m)=>{n(null),a({}),r(u),m&&l({type:"component",visualType:"single",url:m.url,componentName:m.name,icon:m.icon}),t==null||t()},[n,a,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($n,{text:u.name,onClick:()=>d("custom",u),icon:u.icon},`${u.url}-${u.name}-${m}`))})]})}const $n=({text:t,icon:n,onClick:a})=>{const r=Je(),l=t.charAt(0).toUpperCase();return e.jsx(s.IconButton,{onClick:a,tooltip:t,children:r?e.jsx(r,{className:"h-4 w-4"}):l})};function Yn({onChartTypeChange:t,iconClassName:n}){const{setCardType:a,setCardPreferences:r,setIsDevMode:l}=s.useEditorStore(m=>m.actions),{setCardCustomCfg:o,setCustomCardPreferences:c,setQueryConfig:i}=s.useEditorActions();function d(m,x){o(null),r({}),a(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",n)})}),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",n)})}),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",n)})}),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",n)})}),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",n),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",n)})}),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",n)})}),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",n)})}),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",n)})}),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",n)})}),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",n)})}),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",n)})}),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",n)})}),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",n)})}),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",n)})}),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",n)})}),e.jsx(s.IconButton,{tooltip:"Map",onClick:()=>d("map"),className:"h-10 p-4",children:e.jsx(s.Map,{className:s.cn("size-5",n)})}),e.jsx(s.IconButton,{openDelay:u,tooltip:"Custom",onClick:()=>d("custom"),className:"h-10 p-4",children:e.jsx(Ve,{className:s.cn("size-5",n)})})]})}function qn({chartType:t,className:n,customIcon:a,componentName:r}){const l=Je();switch(t){case"bar":return e.jsx(s.ChartColumnIncreasing,{className:n});case"line":return e.jsx(s.ChartLine,{className:n});case"pie":return e.jsx(s.ChartPie,{className:n});case"radar":return e.jsx(s.Radar,{className:n});case"scatter":return e.jsx(s.ChartScatter,{className:n});case"bubble":return e.jsx(s.TbChartBubble,{className:n});case"doughnut":return e.jsx(s.Donut,{className:n});case"stackedBar":return e.jsx(s.ChartColumnStacked,{className:n});case"stackedLine":return e.jsx(s.MdStackedLineChart,{className:n});case"polarArea":return e.jsx(s.PiChartPolar,{className:n});case"funnel":return e.jsx(s.TbChartFunnel,{className:n});case"tornado":case"pyramid":return e.jsx(s.Tornado,{className:n});case"range":return e.jsx(s.ChartNoAxesGantt,{className:n});case"kpi":return e.jsx(s.TiSortNumerically,{className:n});case"text":return e.jsx(qe,{className:n});case"map":return e.jsx(s.Map,{className:n});case"custom":return a&&l?e.jsx(l,{className:n}):r?r==null?void 0:r.charAt(0).toUpperCase():e.jsx(Ve,{className:n});default:return e.jsx(s.Table2,{className:n})}}function ft({variant:t="ghost"}){var o,c;const[n,a]=T.useState(!1),r=s.useEditorStore(i=>i.card),l=r.type;return s.useDashboardStore(i=>i.isVisualEditing),e.jsxs(s.Popover,{open:n,onOpenChange:a,children:[e.jsx(s.PopoverTrigger,{asChild:!0,children:e.jsx(s.Button,{size:"sm",variant:t||"ghost",children:e.jsx(qn,{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:"z-[51] w-72 p-1",children:[e.jsx(Yn,{onChartTypeChange:()=>a(!1)}),e.jsx(_n,{onChartTypeChange:()=>a(!1)})]})]})}function Kn({error:t,className:n="",textClassName:a="",copyButtonClassName:r=""}){const[l,o]=T.useState(!1),c=T.useRef(null),i=T.useRef(!1);function d(){t&&!i.current&&navigator.clipboard.writeText(t)}function u(h){(h.key==="Enter"||h.key===" ")&&(h.preventDefault(),d())}function m(){const h=window.getSelection();if(h&&h.toString().trim()!==""){const p=h.toString();navigator.clipboard.writeText(p),o(!0),i.current=!0,setTimeout(()=>{o(!1),i.current=!1},1e3)}else i.current=!1}function x(){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 ${n}`,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 ${a}`,onClick:d,onKeyDown:u,onMouseUp:m,onMouseDown:x,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 Qn(){const t=s.useEditorStore(o=>{var c,i;return(i=(c=o.card.preferences)==null?void 0:c.chartOptions)==null?void 0:i.indexAxis}),n=s.useEditorStore(o=>o.card.type),{setChartOrientation:a}=s.useEditorStore(o=>o.actions);function r(){return e.jsx(s.IconButton,{onClick:()=>{a(t==="x"||t===void 0?"y":"x")},tooltip:"Chart Orientation",children:t==="x"||t===void 0?e.jsx(ys,{className:"size-4"}):e.jsx(vs,{className:"size-4"})})}function l(){return e.jsx(s.IconButton,{onClick:()=>{a(t==="y"||t===void 0?"x":"y")},tooltip:"Chart Orientation",children:t==="y"||t===void 0?e.jsx(ys,{className:"size-4"}):e.jsx(vs,{className:"size-4"})})}return e.jsx(e.Fragment,{children:n==="funnel"?l():r()})}function Hn({className:t}){var h,p,g,f,y,v,C,F;const n=s.useEditorStore(k=>k.card),{setCardPreferences:a,updateCardInFrame:r,setCard:l}=s.useEditorActions(),[o,c]=T.useState(!1),i=((p=(h=n.preferences)==null?void 0:h.displayOptions)==null?void 0:p.showFilterInfo)??!0,d=((f=(g=n.preferences)==null?void 0:g.displayOptions)==null?void 0:f.showCardToolbar)??!0,u=((v=(y=n.preferences)==null?void 0:y.displayOptions)==null?void 0:v.showChrome)??!0,m=((F=(C=n.preferences)==null?void 0:C.displayOptions)==null?void 0:F.allowScroll)??!0,x=(k,D)=>{var N;const w={...n.preferences,displayOptions:{...(N=n.preferences)==null?void 0:N.displayOptions,[k]:D}};a(w);const j={...n,preferences:w};l(j),r(j)};return e.jsx("div",{className:s.cn("flex items-center",t),children:e.jsxs(s.DropdownMenu,{modal:!1,open:o,onOpenChange:c,children:[e.jsx(s.DropdownMenuTrigger,{asChild:!0,children:e.jsx(s.IconButton,{className:"h-8 w-8 p-0",tooltip:"Display Options",children:e.jsx(Vs,{className:"h-4 w-4"})})}),e.jsxs(s.DropdownMenuContent,{align:"end",className:"w-64",children:[e.jsx(s.DropdownMenuLabel,{children:"Display Options"}),e.jsx(s.DropdownMenuSeparator,{}),e.jsx("div",{className:"px-2 py-1.5",children:e.jsx("p",{className:"mb-2 text-xs text-muted-foreground",children:"Changes apply to dashboard view only"})}),e.jsxs(s.DropdownMenuCheckboxItem,{checked:i,onCheckedChange:k=>{x("showFilterInfo",k)},onSelect:k=>k.preventDefault(),className:"pr-2",children:[e.jsx("span",{className:"flex-1",children:"Filter Info"}),e.jsx("span",{className:"ml-4 text-xs text-muted-foreground",children:"Badge"})]}),e.jsxs(s.DropdownMenuCheckboxItem,{checked:d,onCheckedChange:k=>{x("showCardToolbar",k)},onSelect:k=>k.preventDefault(),className:"pr-2",children:[e.jsx("span",{className:"flex-1",children:"Card Toolbar"}),e.jsx("span",{className:"ml-4 text-xs text-muted-foreground",children:"Hover actions"})]}),e.jsxs(s.DropdownMenuCheckboxItem,{checked:u,onCheckedChange:k=>{x("showChrome",k)},onSelect:k=>k.preventDefault(),className:"pr-2",children:[e.jsx("span",{className:"flex-1",children:"Card Chrome"}),e.jsx("span",{className:"ml-4 text-xs text-muted-foreground",children:"Frame & padding"})]}),e.jsxs(s.DropdownMenuCheckboxItem,{checked:m,onCheckedChange:k=>{x("allowScroll",k)},onSelect:k=>k.preventDefault(),className:"pr-2",children:[e.jsx("span",{className:"flex-1",children:"Allow Scroll"}),e.jsx("span",{className:"ml-4 text-xs text-muted-foreground",children:"Card content scroll"})]})]})]})})}function gt(){const t=s.useEditorStore(o=>o.card),n=s.useEditorStore(o=>{var c,i;return(i=(c=o.card)==null?void 0:c.preferences)==null?void 0:i.chartOptions}),a=s.getChartGridStyle(n),{setChartGrid:r}=s.useEditorActions();function l(){const o=["xy","none","x","y"],i=(o.indexOf(a)+1)%o.length;r(o[i])}return e.jsxs("div",{"data-info":"visual-settings",className:"flex items-center gap-2",children:[["line","bar","range","stackedBar","stackedLine","horizontalBar","funnel"].includes(t.type)&&e.jsx(e.Fragment,{children:e.jsx(Qn,{})}),!["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:l,children:[(a==="xy"||!a)&&e.jsx(He,{className:"size-4"}),a==="x"&&e.jsx(Gt,{className:"size-4"}),a==="y"&&e.jsx(ca,{className:"size-4"}),a==="none"&&e.jsx(ha,{className:"size-4"})]}),e.jsx(Hn,{})]})}function Wn(){const t=s.useEditorStore(g=>g.frame),n=s.useEditorStore(g=>g.card),{setFrame:a,setActiveTabCardId:r,setCard:l,updateCardInFrame:o}=s.useEditorActions(),c=(g,f)=>{g.dataTransfer.setData("tabIndex",f.toString())},i=g=>{g.preventDefault()},d=(g,f)=>{const y=g.dataTransfer.getData("tabIndex");if(y===f.toString())return;const v=Array.from(t.cards),[C]=v.splice(parseInt(y),1);v.splice(f,0,C),a({...t,cards:v})};function u(g){const f=t.cards.filter(C=>C.id!==g),y=f[0],v={...t,cards:f,activeCardId:y.id};a(v),r(y.id),l(y)}function m(g,f){const y={...t,cards:[...t.cards,f],activeCardId:g.id};a(y),r(f.id)}function x(){const g={...n,id:s.v4(),title:`${n.title} Copy`,tabTitle:`${n.tabTitle||n.title} Copy`};m(n,g)}function h(g){const f={dataSource:g.dataSource,connectionId:g.connectionId,lastSelectedDatabase:g.lastSelectedDatabase,lastSelectedSchema:g.lastSelectedSchema,lastSelectedTable:g.lastSelectedTable,lastSelectedDatamodelId:g.lastSelectedDatamodelId,id:s.v4(),title:"Title",description:"",preferences:{onClickFilter:[{columnIndex:0,expression:""}]},type:"bar",sql:"",data:[],mode:"explorer"};m(g,f)}function p(g,f){return g.cards.length===1&&(f.displayTab===!0||f.displayTab===void 0)||g.activeCardId!==f.id&&(f.displayTab===!0||f.displayTab===void 0)?null:e.jsx("div",{onClick:()=>{const y=f.displayTab===void 0?!1:!f.displayTab;l({...f,displayTab:y}),o({...f,displayTab:y})},children:f.displayTab===!0||f.displayTab===void 0?e.jsx(s.Eye,{className:"mr-2 size-3.5 text-muted-foreground hover:text-foreground"}):e.jsx(qt,{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((g,f)=>e.jsxs(s.TabsTrigger,{draggable:!0,onDragStart:y=>c(y,f),onDragOver:i,onDrop:y=>d(y,f),className:"",value:g.id,children:[p(t,g),e.jsx(s.Editable,{enabled:t.activeCardId===g.id,text:g.tabTitle||g.title,onSave:y=>{l({...n,tabTitle:y}),o({...n,tabTitle:y})},children:g.tabTitle||g.title},g.id),t.activeCardId===g.id&&e.jsx(s.CopyPlus,{className:"ml-2 size-3.5 text-muted-foreground hover:text-foreground",onClick:y=>{y.stopPropagation(),x()}}),t.activeCardId===g.id&&t.cards.length>1&&e.jsx(s.X,{className:"ml-2 size-3.5 text-muted-foreground hover:text-foreground",onClick:()=>u(g.id)})]},g.id)),e.jsx(s.IconButton,{tooltip:"Add Card",className:"ml-1 h-8 px-2 hover:bg-muted-foreground/50",onClick:()=>h(n),children:e.jsx(s.Plus,{className:"h-4 w-4"})})]})})}function jt(){const t=s.useEditorStore(f=>f.frame),n=s.useEditorStore(f=>f.card),a=s.useEditorStore(f=>f.isSqlRunning),r=s.useEditorStore(f=>f.isDevMode),{setFrame:l,setActiveTabCardId:o,setCard:c,setIsDevMode:i,setRunSql:d}=s.useEditorActions(),{data:u,isLoading:m,isFetching:x}=s.useDashboardCardQuery(n);function h(f){const y=t.cards.find(v=>v.id===f);if(y!=null&&y.sql){r||i(!0),o(f);return}if(y!=null&&y.queryConfig){r&&i(!1),p(f),o(f);return}r||p(f),o(f)}function p(f){const y={...t,cards:t.cards.map(C=>C.id===n.id?n:C),activeCardId:f};l(y);const v=y.cards.find(C=>C.id===f);v.sql&&d(!0),c(v)}function g(){return n.type==="kpi"?m||x?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:n,data:u==null?void 0:u.records,isPending:m||x})})}):n.type==="text"?m||x?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:a,card:n,data:u==null?void 0:u.records})})})}):e.jsx(s.ErrorBoundary,{FallbackComponent:s.FallbackVisual,children:e.jsx(ht,{className:"grow border-none shadow-none"})})}return e.jsxs(s.Tabs,{onValueChange:h,value:t.activeCardId,className:"flex grow flex-col",children:[t.cards.map(f=>e.jsx(s.TabsContent,{className:"mt-0 grow",value:f.id,children:g()},f.id)),e.jsx(Wn,{})]})}function Ts({children:t}){var w,j;s.useEditorStore(N=>N.frame);const n=s.useEditorStore(N=>N.card),a=s.useEditorStore(N=>N.isDevMode),r=s.useEditorStore(N=>N.isShowingVisual),l=s.useDashboardStore(N=>N.isVisualEditing),o=s.useEditorStore(N=>N.pythonStdOut);s.useEditorStore(N=>N.actions.setRunSql);const{setFrame:c,setCard:i,setActiveTabCardId:d,runAssistant:u,setIsDevMode:m,setCardPreferences:x}=s.useEditorActions(),{data:h,isLoading:p,isFetching:g,errorMessage:f,refetch:y}=s.useDashboardCardQuery(n),[v,C]=T.useState(!1);T.useEffect(()=>{g||C(!1)},[g]);function F(){const N=JSON.stringify(h==null?void 0:h.records,null,2),b=new Blob([N],{type:"application/json"}),R=URL.createObjectURL(b),S=document.createElement("a");S.href=R,S.download=`${n.title}.json`,S.click()}function k(){const b=[Object.keys(h==null?void 0:h.records.reduce((E,I)=>({...E,...I}),{})).join(","),...((h==null?void 0:h.records)||[]).map(E=>Object.values(E).join(","))].join(`
|
|
279
|
+
`),R=new Blob([b],{type:"text/csv"}),S=URL.createObjectURL(R),O=document.createElement("a");O.href=S,O.download=`${n.title}.csv`,O.click()}function D(){const N=`Can you get the documentation for ${n.type} chart?`;u(N)}return n?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(ft,{}),l&&e.jsx(s.IconButton,{tooltip:"Visual Docs",onClick:D,children:e.jsx(Vt,{className:"size-4"})}),!["table","custom"].includes(n.type)&&l&&e.jsx(Gn,{})]}),!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:k,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:F,children:e.jsx(Qt,{strokeWidth:1.5,className:"size-4"})}),e.jsx(s.CopyButton,{text:JSON.stringify(h==null?void 0:h.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(s.IconButton,{tooltip:"Refresh",disabled:p||g,onClick:()=>{C(!0),y()},children:e.jsx(s.RefreshCcw,{className:s.cn("h-4 w-4",{"animate-spin":v})})}),e.jsx(gt,{})]}),n.type==="table"&&n.sql&&!s.hasValidCardConfig(n.config)&&e.jsxs("div",{className:"mr-2 flex items-center gap-3",children:[e.jsx(s.Checkbox,{id:"pagination",checked:((j=(w=n.preferences)==null?void 0:w.tablePrefs)==null?void 0:j.enableDevModePagination)??!1,onCheckedChange:N=>{var b;x({...n.preferences,tablePrefs:{...(b=n.preferences)==null?void 0:b.tablePrefs,enableDevModePagination:N}}),y()}}),e.jsx(s.Label,{htmlFor:"pagination",children:"Paginate Results"})]}),a&&e.jsx(Xn,{})]}),r?e.jsx(jt,{}):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(Jn,{})}),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:[(h==null?void 0:h.records)&&(h==null?void 0:h.records.length)>0&&e.jsx(s.TableVisual,{card:n,data:(h==null?void 0:h.records)||[]}),f&&e.jsx(Kn,{error:f})]})]})]}):e.jsx(e.Fragment,{children:"No Active Card"})}function Jn(){const t=s.useEditorStore(a=>a.pythonStdOut);if(!t)return null;const n=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:n}}),e.jsx(s.ScrollBar,{orientation:"horizontal"})]})]})}function Xn(){const t=s.useEditorStore(a=>a.isShowingVisual),n=s.useEditorStore(a=>a.actions.setIsShowingVisual);return e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(s.Label,{htmlFor:"visualize",children:"Chart"}),e.jsx(s.SmallSwitch,{checked:t,onCheckedChange:()=>n(!t),id:"visualize",className:"data-[state=checked]:bg-foreground/50"})]})}function Se({defaultValue:t,label:n,options:a,value:r,onValueChange:l,className:o,icon:c,showPlaceholderLabel:i=!0}){return e.jsxs(s.Select,{defaultValue:t,value:r,onValueChange:l,children:[e.jsx(s.SelectTrigger,{className:s.cn("w-full focus:ring-0 focus:ring-offset-0",o),children:e.jsxs("div",{className:"flex items-center gap-2",children:[c&&e.jsx("span",{children:c}),i&&e.jsx(s.SelectValue,{placeholder:n})]})}),e.jsx(s.SelectContent,{children:e.jsxs(s.SelectGroup,{children:[e.jsx(s.SelectLabel,{children:n}),a.map(d=>e.jsx(s.SelectItem,{value:d.value,children:d.label},d.value))]})})]})}function Zn(){var f,y;const t=s.useEditorStore(v=>v.card.customCardPreferences),{data:n}=xt(),a=(n==null?void 0:n.plugins)||[],r=s.useEditorStore(v=>v.card),l=s.useEditorStore(v=>v.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=(f=d==null?void 0:d.visuals)==null?void 0:f.find(v=>v.name===(t==null?void 0:t.componentName));function m(v,C){if(!t)return;const k={...(t==null?void 0:t.dataInputCardIds)||{},[v]:{cardId:C,hookRef:null}};c({...t,dataInputCardIds:k})}function x(v){var F,k;const C=(F=l==null?void 0:l.cards)==null?void 0:F.filter(D=>{var w;return((w=D==null?void 0:D.customCardPreferences)==null?void 0:w.visualType)!=="multiple"}).map(D=>({value:D.id,label:D.tabTitle||D.title}));return e.jsx("div",{className:"space-y-2",children:(k=v==null?void 0:v.dataInputs)==null?void 0:k.map((D,w)=>{var j,N;return e.jsxs("div",{className:"grid grid-cols-10 gap-2",children:[e.jsx("div",{className:"col-span-4 flex items-center",children:D}),e.jsx(Se,{className:"col-span-6 h-8 w-full justify-between",label:"",options:C||[],value:((N=(j=t==null?void 0:t.dataInputCardIds)==null?void 0:j[w])==null?void 0:N.cardId)||"",onValueChange:b=>m(w,b)})]},w+Math.random())})})}function h(v,C,F=[],k=""){var D,w;return t?v==="input"?e.jsx(s.Input,{className:`h-8 w-full ${s.removeRing}`,value:((D=t==null?void 0:t.settings)==null?void 0:D[C])||k,onChange:j=>{c({...t,settings:{...t==null?void 0:t.settings,[C]:j.target.value}})}},C):v==="select"?e.jsx(Se,{className:"h-8 w-full",label:"",options:F,value:((w=t==null?void 0:t.settings)==null?void 0:w[C])||k,onValueChange:j=>{c({...t,settings:{...t==null?void 0:t.settings,[C]:j}})}}):null:null}function p(v){const C=Object.entries((v==null?void 0:v.settings)||{});return e.jsx("div",{className:"space-y-3",children:C.map(([F,k])=>e.jsxs("div",{className:"space-y-1",children:[e.jsx(s.Label,{children:k.title}),h(k.ui,F,k.options,k.defaultValue)]},F))})}function g(v){t&&c({...t,visualType:v,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(Se,{icon:e.jsx(Bt,{className:"h-3.5 w-3.5"}),className:"h-9 w-full",label:"Select Plugin",options:a,value:(t==null?void 0:t.url)||"",onValueChange:v=>c({...t||{url:"",componentName:""},url:v})}),((t==null?void 0:t.type)==="component"||(t==null?void 0:t.type)===void 0)&&e.jsx(s.Tabs,{value:o,onValueChange:g,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(Se,{icon:e.jsx(_t,{className:"h-3.5 w-3.5"}),className:"h-9 w-full",label:"Select Component",options:(i==null?void 0:i.filter(v=>v.type===o).map(v=>({value:v.name,label:v.name})))||[],value:t.componentName,onValueChange:v=>{console.log("changing value",v),c({...t,componentName:v})}})})]})})]}),((y=r==null?void 0:r.customCardPreferences)==null?void 0:y.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:x(u)})]}),u&&u.settings&&e.jsx("div",{className:"space-y-3",children:e.jsx("div",{className:"px-2",children:p(u)})})]})]})]})}function Me(){const[t,n]=T.useState([]),a=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}),T.useEffect(()=>{o&&n(new Array(o.length).fill(!1))},[o]);function c(u,m){var x,h;m?a!=null&&a.onClickFilter&&((x=a==null?void 0:a.onClickFilter)==null?void 0:x.length)>0?l({...a,onClickFilter:[...a.onClickFilter,{columnIndex:u,expression:""}]}):l({...a,onClickFilter:[{columnIndex:u,expression:""}]}):(l({...a,onClickFilter:(h=a==null?void 0:a.onClickFilter)==null?void 0:h.filter(p=>p.columnIndex!==u)}),n(p=>{const g=[...p];return g[u]=!1,g}))}function i(u,m){var h;const x=(h=a==null?void 0:a.onClickFilter)==null?void 0:h.map(p=>p.columnIndex===u?{...p,expression:m.target.value}:p);l({...a,onClickFilter:x})}function d(u){var m,x,h,p;if(t!=null&&t[u]||(x=(m=a==null?void 0:a.onClickFilter)==null?void 0:m.find(g=>g.columnIndex===u))!=null&&x.expression)return e.jsx(s.Input,{value:(p=(h=a==null?void 0:a.onClickFilter)==null?void 0:h.find(g=>g.columnIndex===u))==null?void 0:p.expression,onChange:g=>i(u,g),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 x,h;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:!!((x=a==null?void 0:a.onClickFilter)!=null&&x.find(p=>p.columnIndex===m)),onCheckedChange:p=>c(m,p)}),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:((h=a==null?void 0:a.onClickFilter)==null?void 0:h.find(p=>p.columnIndex===m))&&e.jsx(s.Pencil,{onClick:()=>{n(p=>{const g=[...p];return g[m]=!p[m],g})},className:"invisible size-3 cursor-pointer text-gray-400 group-hover:visible"})})]}),d(m)]})},u)})})}function er({idx:t}){var i;const n=s.useEditorStore(d=>{var u;return(u=d.card)==null?void 0:u.preferences}),a=s.useEditorStore(d=>{var u;return(u=d.card.preferences)==null?void 0:u.datasetOptions}),r=s.useEditorStore(d=>d.actions.setCardPreferences),l=(i=n==null?void 0:n.chartOptions)==null?void 0:i.indexAxis,o=a==null?void 0:a.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({...n,datasetOptions:[...a||[],{idx:u,datalabels:m}]});else{const x={...o};x.datalabels=m;const h=a==null?void 0:a.map(p=>p.idx===u?x:p);r({...n,datasetOptions:h})}}return e.jsxs(s.Popover,{children:[e.jsx(s.PopoverTrigger,{children:e.jsx(zs,{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(ea,{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(ta,{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(sa,{className:s.cn("h-4 w-4",{"rotate-90":l==="y"})})})]})})]})}function sr(){const t=s.useEditorStore(o=>o.card),{data:n}=s.useDashboardCardQuery(t),{keys:a}=s.getKeys((n==null?void 0:n.records)||[]),r=a.slice(1).filter(o=>!s.METADATA_KEYS.includes(o));let l=r;if(["stackedBar","stackedLine"].includes(t.type)){const o=s.pivotData({dataArray:(n==null?void 0:n.records)||[],groupKey:a[0],pivotKey:a[1],valueKey:a[2]}),{keys:c}=s.getKeys(o);l=c.slice(1)}return{transformedMetricKeys:l,dimensionKeys:a.slice(0,1),keys:a,defaultMetricKeys:r}}function us({children:t,className:n,delayDuration:a}){return e.jsx(s.TooltipProvider,{children:e.jsxs(s.Tooltip,{delayDuration:a,children:[e.jsx(s.TooltipTrigger,{asChild:!0,children:e.jsx("span",{className:s.cn("overflow-hidden text-ellipsis whitespace-nowrap",n),children:t})}),e.jsx(s.TooltipContent,{children:t})]})})}function bt(){const t=s.useEditorStore(d=>d.card),n=s.useEditorStore(d=>{var u,m,x;return(x=(m=(u=d==null?void 0:d.card)==null?void 0:u.preferences)==null?void 0:m.chartOptions)==null?void 0:x.indexAxis}),{data:a}=s.useDashboardCardQuery(t),r=n==="y"?"Metric":"Dimension",l=n==="y"?"Dimension":"Metric",{dimensionKeys:o,transformedMetricKeys:c,keys:i}=sr();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:vt(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(yt,{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 vt(t,n=30){return t.length>n?t.slice(0,n)+"...":t}function yt({col:t,idx:n,className:a,iconClassName:r,children:l}){const o=s.useEditorStore(m=>{var x;return(x=m.card)==null?void 0:x.preferences}),c=s.useEditorStore(m=>{var x,h;return(h=(x=m.card)==null?void 0:x.preferences)==null?void 0:h.datasetOptions}),i=c==null?void 0:c.find(m=>m.idx===n),{setCardPreferences:d}=s.useEditorStore(m=>m.actions);function u(m){if(!i)d({...o,datasetOptions:[...c||[],{idx:n,type:m==="area"?"line":m,fill:m==="area"?"origin":""}]});else{const x={...i};x.type=m==="area"?"line":m,x.fill=m==="area"?"origin":"";const h=c==null?void 0:c.map(p=>p.idx===n?x:p);d({...o,datasetOptions:h})}}return e.jsxs("div",{className:s.cn("group flex items-center justify-between gap-2 rounded-md",a),children:[l||e.jsx(us,{className:"max-w-[100px]",title:t,children:vt(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(er,{idx:n})]})]})}function Pe(){const t=s.useDashboardStore(i=>i.dashboard.filters),n=s.useEditorStore(i=>i.frame),{setFrame:a}=s.useEditorActions(),{columns:r}=s.useEditorAside(),{assignFilter:l}=lt();function o(i){const d=l(i,"frame");a({...n,filterId:d})}const c=t==null?void 0:t.find(i=>i.id===n.filterId);return e.jsxs("div",{className:"space-y-3",children:[e.jsx(s.Label,{children:"Card Filter"}),e.jsx(tr,{onSelect:o,columns:r}),c&&e.jsx(s.FilterHeader,{filter:c})]})}function tr({columns:t,onSelect:n}){var c;const[a,r]=ss.useState(!1),[l,o]=ss.useState("");return e.jsxs(s.Popover,{open:a,onOpenChange:r,children:[e.jsx(s.PopoverTrigger,{asChild:!0,children:e.jsxs(s.Button,{size:"sm",variant:"outline",role:"combobox","aria-expanded":a,className:"w-full justify-between font-normal",children:[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&&n(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 ar({cardType:t}){return e.jsx("div",{className:"space-y-6 px-6 py-2",children:e.jsxs(s.Accordion,{defaultValue:["item-2"],type:"multiple",children:[e.jsxs(s.AccordionItem,{value:"item-1",children:[e.jsx(s.AccordionTrigger,{children:`${s.titleCase(t)} Chart`}),e.jsxs(s.AccordionContent,{className:"space-y-4 font-mono text-xs",children:[e.jsx("div",{className:"rounded bg-muted px-2 py-1 text-xs",children:"SELECT x-axis, y-axis-1, y-axis-2,... FROM table"}),e.jsxs("ul",{className:"ml-6 list-disc text-xs [&>li]:mt-2",children:[e.jsx("li",{children:"x-axis - category"}),e.jsx("li",{children:"y-axis1 - number"}),e.jsx("li",{children:"y-axis2 - number"})]}),e.jsxs("div",{children:["See ",e.jsx("a",{target:"_blank",onClick:n=>n.stopPropagation(),className:"text-blue-700",href:"https://docs.semaphor.cloud/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(bt,{})})]}),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(Me,{}),e.jsx(Pe,{})]})]})]})})}function nr({cardType:t}){function n(a){return e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"rounded bg-muted px-2 py-1 text-xs",children:a==="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"}),a==="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:n(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(Me,{}),e.jsx(Pe,{})]})]})]})})}function Nt(){const t=s.useEditorStore(i=>i.card.type),n=s.useEditorStore(i=>i.isDevMode),a=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={...a,chartOptions:{...a==null?void 0:a.chartOptions,plugins:{...(m=a==null?void 0:a.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=a==null?void 0:a.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=a==null?void 0:a.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:n?o():c()})}const rr={datasets:[{type:"line",label:"Sum_sales",data:[]},{type:"bar",label:"Sum_profit",data:[]}]},lr={datasets:[{fill:"origin",type:"line",label:"Sum_sales",data:[]}]};function or(){const t=s.useEditorStore(n=>n.card.type);return e.jsxs("div",{className:"space-y-6 p-6",children:[e.jsx(s.Accordion,{className:" ",type:"single",collapsible:!0,children:ir(t)}),!["kpi"].includes(t)&&e.jsxs("div",{className:"space-y-4",children:[e.jsx(Nt,{}),e.jsx(Me,{}),e.jsx(Pe,{})]})]})}function ir(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(rr,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(lr,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 cr({colorRanges:t,setColorRanges:n}){const a={start:-1/0,end:100,color:""};function r(c,i,d){const u=[...t];u[c]={...u[c],[i]:d},n(u)}function l(c){const i=[...t];i.splice(c,1),n(i)}function o(){n([...t,a])}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 dr(){var m,x,h,p,g;const t=s.useEditorStore(f=>f.card.preferences),n=s.useEditorStore(f=>f.actions.setCardPreferences),a=s.useEditorStore(f=>f.card),r=s.hasValidCardConfig(a.config),l=s.useEditorStore(f=>f.actions.setNumberFormat);s.useEditorStore(f=>{var y,v;return(v=(y=f.card.preferences)==null?void 0:y.formatNumber)==null?void 0:v.decimalPlaces});const o=s.useEditorStore(f=>{var y,v;return(v=(y=f.card.preferences)==null?void 0:y.formatNumber)==null?void 0:v.locale}),c=s.useEditorStore(f=>{var y,v;return(v=(y=f.card.preferences)==null?void 0:y.formatNumber)==null?void 0:v.currency});s.useEditorStore(f=>f.actions.setFilterOnClickField);const i=s.useEditorStore(f=>{var y,v;return(v=(y=f.card.preferences)==null?void 0:y.formatNumber)==null?void 0:v.colorRanges})||[],d=s.useEditorStore(f=>f.actions.setColorRanges),u=[...new Set(s.LOCALE_CURRENCY_PAIRS.map(f=>f.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:f=>{n({...t,formatNumber:{...t==null?void 0:t.formatNumber,enabled:f}})}}),e.jsx(s.Label,{children:"Format Number"})]}),(((x=t==null?void 0:t.formatNumber)==null?void 0:x.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:f=>{var y,v,C;return l(((y=t==null?void 0:t.formatNumber)==null?void 0:y.decimalPlaces)||0,((v=t==null?void 0:t.formatNumber)==null?void 0:v.currency)||"",f,((C=t==null?void 0:t.formatNumber)==null?void 0:C.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(f=>e.jsx(s.SelectItem,{value:f.locale,children:f.locale},f.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:f=>{var y,v,C;console.log("currency",f),l(((y=t==null?void 0:t.formatNumber)==null?void 0:y.decimalPlaces)||0,f==="none"?"":f,((v=t==null?void 0:t.formatNumber)==null?void 0:v.locale)||"",((C=t==null?void 0:t.formatNumber)==null?void 0:C.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(f=>e.jsx(s.SelectItem,{value:f,children:f},f))]})})]})]})]}),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:((p=(h=t==null?void 0:t.formatNumber)==null?void 0:h.decimalPlaces)==null?void 0:p.toString())||"0",onValueChange:f=>{var y,v,C;return l(Number(f),((y=t==null?void 0:t.formatNumber)==null?void 0:y.currency)||"",((v=t==null?void 0:t.formatNumber)==null?void 0:v.locale)||"",((C=t==null?void 0:t.formatNumber)==null?void 0:C.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(f=>e.jsx(s.SelectItem,{value:f,children:f},f))})]})]}),e.jsxs("div",{className:"w-full space-y-1",children:[e.jsx(s.Label,{children:"Suffix"}),e.jsx(s.Input,{value:((g=t==null?void 0:t.formatNumber)==null?void 0:g.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:f=>{var y,v,C;return l(((y=t==null?void 0:t.formatNumber)==null?void 0:y.decimalPlaces)||0,((v=t==null?void 0:t.formatNumber)==null?void 0:v.currency)||"",((C=t==null?void 0:t.formatNumber)==null?void 0:C.locale)||"",f.target.value)}})]})]})]})}),e.jsx(s.Separator,{className:"my-3"}),e.jsx(cr,{colorRanges:i,setColorRanges:d})]})]})}function ur(){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(dr,{})}),e.jsx("div",{}),e.jsx("div",{})]})}function Ze({children:t,summary:n,open:a,className:r}){return e.jsxs("details",{open:a,className:s.cn("space-y-4 [&_summary>svg]:open:-rotate-180",r),children:[e.jsxs("summary",{className:"flex cursor-pointer list-none items-center justify-between gap-4",children:[e.jsx(s.Label,{children:n}),e.jsx(s.ChevronUp,{className:"h-4 w-4"})]}),e.jsx("div",{className:"transition-all ease-in-out",children:t})]})}const mr=[{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"}],hr=["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"],xr=hr.map(t=>({label:t,value:t}));function pr(){var d,u,m,x,h,p,g,f,y,v,C,F,k,D,w,j,N,b;const t=s.useEditorStore(R=>R.card),n=(u=(d=t==null?void 0:t.preferences)==null?void 0:d.mapVisualOptions)==null?void 0:u.topoJsonUrl,[a,r]=T.useState(((x=(m=t==null?void 0:t.preferences)==null?void 0:m.mapVisualOptions)==null?void 0:x.customTopoJsonUrl)||""),{setCardPreferences:l}=s.useEditorActions(),{data:o}=s.useTopoJson(t),c=Object.keys((o==null?void 0:o.objects)||{}).map(R=>({label:R,value:R}))||[],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(Ze,{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(Ze,{open:!0,summary:"Settings",children:e.jsxs("div",{className:"space-y-3 px-2",children:[e.jsx(Se,{className:"h-9",options:i,onValueChange:R=>{console.log("value",R),l({...t.preferences,mapVisualOptions:{topoJsonUrl:R}})},value:n||"",label:"Select Map"}),n==="custom"&&e.jsx(s.Input,{onChange:R=>{r(R.target.value)},onBlur:()=>{var R;console.log("onBlur",a),l({...t.preferences,mapVisualOptions:{...(R=t.preferences)==null?void 0:R.mapVisualOptions,customTopoJsonUrl:a}})},value:a,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(Se,{className:"h-9",options:c,value:((p=(h=t.preferences)==null?void 0:h.mapVisualOptions)==null?void 0:p.objectKey)||"",label:"Map Object",onValueChange:R=>{var S;l({...t.preferences,mapVisualOptions:{...(S=t.preferences)==null?void 0:S.mapVisualOptions,objectKey:R}})}})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(s.Label,{children:"Projection"}),e.jsx(Se,{className:"h-9",options:mr,value:((f=(g=t.preferences)==null?void 0:g.mapVisualOptions)==null?void 0:f.projection)||"",label:"Projection",onValueChange:R=>{var S;l({...t.preferences,mapVisualOptions:{...(S=t.preferences)==null?void 0:S.mapVisualOptions,projection:R}})}})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(s.Label,{children:"Colors"}),e.jsx(Se,{className:"h-9",options:xr,value:((v=(y=t.preferences)==null?void 0:y.mapVisualOptions)==null?void 0:v.colorScale)||"",label:"Select Color Scale",onValueChange:R=>{var S;l({...t.preferences,mapVisualOptions:{...(S=t.preferences)==null?void 0:S.mapVisualOptions,colorScale:R}})}})]})]})]})}),e.jsx(s.Separator,{className:"my-4"}),e.jsx(Ze,{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:((F=(C=t.preferences)==null?void 0:C.mapVisualOptions)==null?void 0:F.projectionScale)||1,onChange:R=>{var S;l({...t.preferences,mapVisualOptions:{...(S=t.preferences)==null?void 0:S.mapVisualOptions,projectionScale:Number(R.target.value)}})}}),e.jsx(s.Label,{children:"X"}),e.jsx(s.Input,{className:`h-9 w-full ${s.removeRing}`,type:"number",step:10,value:((w=(D=(k=t.preferences)==null?void 0:k.mapVisualOptions)==null?void 0:D.projectionOffset)==null?void 0:w[0])||0,onChange:R=>{var S,O,E,I;l({...t.preferences,mapVisualOptions:{...(S=t.preferences)==null?void 0:S.mapVisualOptions,projectionOffset:[Number(R.target.value),((I=(E=(O=t.preferences)==null?void 0:O.mapVisualOptions)==null?void 0:E.projectionOffset)==null?void 0:I[1])||0]}})}}),e.jsx(s.Label,{children:"Y"}),e.jsx(s.Input,{className:`h-9 w-full ${s.removeRing}`,type:"number",step:10,value:((b=(N=(j=t.preferences)==null?void 0:j.mapVisualOptions)==null?void 0:N.projectionOffset)==null?void 0:b[1])||0,onChange:R=>{var S,O,E,I;l({...t.preferences,mapVisualOptions:{...(S=t.preferences)==null?void 0:S.mapVisualOptions,projectionOffset:[((I=(E=(O=t.preferences)==null?void 0:O.mapVisualOptions)==null?void 0:E.projectionOffset)==null?void 0:I[0])||0,Number(R.target.value)]}})}})]})}),e.jsx(s.Separator,{className:"my-4"}),e.jsx(Me,{})]})}function fr(){var r;const t=s.useEditorStore(l=>l.card.preferences),{setCardPreferences:n}=s.useEditorStore(l=>l.actions);function a(l){n({...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:a,className:"flex gap-3",defaultValue:"x",children:[e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(s.RadioGroupItem,{value:"static",id:"r1"}),e.jsx("label",{className:"text-sm",htmlFor:"r1",children:"Static"})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(s.RadioGroupItem,{value:"dynamic",id:"r2"}),e.jsx("label",{className:"text-sm",htmlFor:"r2",children:"Dynamic"})]})]})}function Ge({cardType:t,docContent:n,suffix:a="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)} ${a}`}),e.jsx(s.AccordionContent,{children:n||e.jsxs("div",{className:"space-y-4 font-mono text-xs",children:[e.jsx("div",{className:"rounded bg-muted px-2 py-1 text-xs",children:"SELECT label, measure FROM table"}),e.jsxs("ul",{className:"ml-6 list-disc text-xs [&>li]:mt-2",children:[e.jsx("li",{children:"label - category"}),e.jsx("li",{children:"measure - number"})]}),e.jsxs("div",{children:["See ",e.jsx("a",{target:"_blank",onClick: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(fr,{})})]}),!["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(Me,{}),e.jsx(Pe,{})]})]})]})})}function gr(){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:n}=s.useEditorActions();function a(){return e.jsxs("div",{className:"space-y-2",children:[e.jsx(s.Label,{children:"Sort"}),e.jsx(Se,{className:"h-8",label:"Sort Chart",options:[{label:"None",value:"none"},{label:"ASC",value:"asc"},{label:"DESC",value:"desc"}],value:t||"none",onValueChange:r=>{n(r)}})]})}return e.jsx("div",{className:"space-y-6 px-6 py-2",children:e.jsxs(s.Accordion,{defaultValue:["item-2"],type:"multiple",children:[e.jsxs(s.AccordionItem,{value:"item-1",children:[e.jsx(s.AccordionTrigger,{children:"Stacked Chart"}),e.jsxs(s.AccordionContent,{className:"space-y-4 font-mono text-xs",children:[e.jsx("div",{className:"rounded bg-muted px-2 py-1 text-xs",children:"SELECT x-axis, stack-by, y-axis FROM table"}),e.jsxs("ul",{className:"ml-6 list-disc text-xs [&>li]:mt-2",children:[e.jsx("li",{children:"x-axis - category"}),e.jsx("li",{children:"stack by - category"}),e.jsx("li",{children:"y-axis - number"})]}),e.jsxs("div",{children:["See ",e.jsx("a",{target:"_blank",onClick:r=>r.stopPropagation(),className:"text-blue-700",href:"https://docs.semaphor.cloud/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:[a(),e.jsx(bt,{})]})]}),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(Me,{}),e.jsx(Pe,{})]})]})]})})}function jr({cardType:t="table"}){console.log("cardType",t);const n=s.useEditorStore(l=>{var o;return(o=l.card)==null?void 0:o.preferences}),a=s.useEditorStore(l=>l.actions.setCardPreferences),r=l=>{a({...n,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(Me,{}),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 Ct({color:t,onColorChange:n,onClose:a}){const[r,l]=T.useState(0),[o,c]=T.useState(100),[i,d]=T.useState(50),[u,m]=T.useState(t);T.useEffect(()=>{const y=ks(t);if(y){const v=Es(y.r,y.g,y.b);l(v.h),c(v.s),d(v.l),m(t)}},[t]);const x=y=>{l(y),p(y,o,i)},h=y=>{const v=y.currentTarget.getBoundingClientRect(),C=Math.max(0,Math.min(1,(y.clientX-v.left)/v.width)),F=Math.max(0,Math.min(1,(y.clientY-v.top)/v.height)),k=C*100,D=(1-F)*100;c(k),d(D),p(r,k,D)},p=(y,v,C)=>{const F=vr(y,v,C),k=br(F.r,F.g,F.b);m(k)},g=y=>{if(m(y),/^#[0-9A-Fa-f]{6}$/.test(y)){const v=ks(y);if(v){const C=Es(v.r,v.g,v.b);l(C.h),c(C.s),d(C.l)}}},f=()=>{/^#[0-9A-Fa-f]{6}$/.test(u)&&(n(u),a())};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:h,onMouseMove:y=>{y.buttons===1&&h(y)},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:y=>x(Number(y.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:y=>g(y.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:a,children:"Cancel"}),e.jsx(s.Button,{onClick:f,children:"OK"})]})]})}function ks(t){const n=/^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(t);return n?{r:parseInt(n[1],16),g:parseInt(n[2],16),b:parseInt(n[3],16)}:null}function br(t,n,a){return"#"+((1<<24)+(t<<16)+(n<<8)+a).toString(16).slice(1)}function Es(t,n,a){t/=255,n/=255,a/=255;const r=Math.max(t,n,a),l=Math.min(t,n,a);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=((n-a)/d+(n<a?6:0))/6;break;case n:o=((a-t)/d+2)/6;break;case a:o=((t-n)/d+4)/6;break}}return{h:Math.round(o*360),s:Math.round(c*100),l:Math.round(i*100)}}function vr(t,n,a){t/=360,n/=100,a/=100;let r,l,o;if(n===0)r=l=o=a;else{const c=(u,m,x)=>(x<0&&(x+=1),x>1&&(x-=1),x<.16666666666666666?u+(m-u)*6*x:x<.5?m:x<.6666666666666666?u+(m-u)*(.6666666666666666-x)*6:u),i=a<.5?a*(1+n):a+n-a*n,d=2*a-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 yr=["#000000","#ffffff","#6b7280","#dc2626","#ea580c","#ca8a04","#16a34a","#0891b2","#2563eb","#7c3aed","#c026d3","#e11d48","#0f172a","#f3f4f6","#fbbf24"];function St(){var F,k,D,w,j,N,b,R,S,O;const t=s.useEditorStore(E=>E.card),n=s.useEditorStore(E=>{var I;return(I=E.card)==null?void 0:I.preferences}),{setCardPreferences:a,updateCardInFrame:r}=s.useEditorActions(),{data:l}=s.useDashboardCardQuery(t),[o,c]=T.useState({}),[i,d]=T.useState(null),[u,m]=T.useState(null),x=T.useMemo(()=>{var M,L,P,B,K,_,z;if(!(l!=null&&l.records)||l.records.length===0)return[];const E=(t==null?void 0:t.type)==="stackedBar"||(t==null?void 0:t.type)==="stackedLine",I=(t==null?void 0:t.type)==="bar"||(t==null?void 0:t.type)==="line",A=((M=t==null?void 0:t.config)==null?void 0:M.pivotByColumns)&&t.config.pivotByColumns.length>0;if((E||I)&&A){if(l.pivotSchema&&Array.isArray(l.pivotSchema)){const U=new Set;return l.pivotSchema.forEach(W=>{W.alias&&U.add(W.alias)}),Array.from(U)}if(l.records.length>0){const U=l.records[0],W=Object.keys(U),ee=new Set;(L=t==null?void 0:t.config)!=null&&L.groupByColumns&&t.config.groupByColumns.forEach(H=>{ee.add(H.label||H.name),ee.add(H.alias||H.name)});const te=new Set;return(P=t==null?void 0:t.config)!=null&&P.metricColumns&&t.config.metricColumns.forEach(H=>{const q=H.alias||H.name;te.add(q),te.add(`${q}_count`),te.add(`${q}_sum`),te.add(`${q}_avg`),te.add(`${q}_min`),te.add(`${q}_max`);const ae=H.entityName||H.qualifiedEntityName;ae&&(te.add(`${ae}_${q}`),te.add(`${ae}_${q}_count`))}),W.filter(H=>!ee.has(H)&&!te.has(H))}}if((I||E)&&!A&&((K=(B=t==null?void 0:t.config)==null?void 0:B.metricColumns)!=null&&K.length))return t.config.metricColumns.map(U=>U.alias||U.label||U.name);if((z=(_=t==null?void 0:t.config)==null?void 0:_.groupByColumns)!=null&&z.length){const U=t.config.groupByColumns[0],W=U.label||U.name,ee=new Set;return l.records.forEach(te=>{const oe=te[W];oe!=null&&ee.add(String(oe))}),Array.from(ee)}return[]},[l,(F=t==null?void 0:t.config)==null?void 0:F.groupByColumns,(k=t==null?void 0:t.config)==null?void 0:k.pivotByColumns,(D=t==null?void 0:t.config)==null?void 0:D.metricColumns,t==null?void 0:t.type]),h=T.useMemo(()=>s.getDefaultChartColors(),[]);T.useEffect(()=>{const E={};x.forEach((I,A)=>{E[I]=s.getColorForValue(I,A,n==null?void 0:n.colorConfig)}),c(E)},[x,n==null?void 0:n.colorConfig,h]);const p=(E,I)=>{const A={...o,[E]:I};c(A);const M={...n||{},colorConfig:{segments:A}};a(M);const L={...t,preferences:M};r(L)},g=(E,I)=>{var K;const A=h[I%h.length],{[E]:M,...L}=((K=n==null?void 0:n.colorConfig)==null?void 0:K.segments)||{},P={...n||{},colorConfig:{segments:L}};a(P);const B={...t,preferences:P};r(B),c(_=>({..._,[E]:A}))};if(!x.length||!((t==null?void 0:t.type)==="stackedBar"||(t==null?void 0:t.type)==="stackedLine"?((j=(w=t==null?void 0:t.config)==null?void 0:w.groupByColumns)==null?void 0:j.length)||((b=(N=t==null?void 0:t.config)==null?void 0:N.pivotByColumns)==null?void 0:b.length):(S=(R=t==null?void 0:t.config)==null?void 0:R.groupByColumns)==null?void 0:S.length)||["table","kpi","text","custom"].includes(t.type))return null;const v=()=>{const E={...n||{},colorConfig:{segments:{}}};a(E);const I={...t,preferences:E};r(I);const A={};x.forEach((M,L)=>{A[M]=s.getColorForValue(M,L,void 0)}),c(A)},C=Object.keys(((O=n==null?void 0:n.colorConfig)==null?void 0:O.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(oa,{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:C&&e.jsxs("button",{className:"ml-auto flex items-center gap-1 text-xs text-muted-foreground hover:text-foreground",onClick:v,children:[e.jsx(Ns,{className:"h-3 w-3"}),"Reset All"]})})}),e.jsx("div",{className:"max-h-[200px] space-y-2 overflow-y-auto pr-1",children:x.map((E,I)=>{const A=s.isDefaultColor(o[E],I),M=!A;return e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(s.Popover,{open:i===E,onOpenChange:L=>d(L?E: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[E]}})}),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:h.slice(0,10).map((L,P)=>e.jsxs("button",{className:s.cn("relative h-5 w-5 rounded border-2 transition-all hover:scale-110",o[E]===L?"border-gray-900":"border-transparent"),style:{backgroundColor:L},onClick:()=>{p(E,L),d(null)},children:[P===I%h.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:L})]},`default-${P}`))})]}),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:yr.map((L,P)=>e.jsx("button",{className:s.cn("h-5 w-5 rounded border transition-all hover:scale-110",o[E]===L?"border-2 border-gray-900":L==="#ffffff"?"border border-gray-300":"border border-transparent"),style:{backgroundColor:L},onClick:()=>{p(E,L),d(null)},children:e.jsx("span",{className:"sr-only",children:L})},`preset-${P}`))})]}),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:E,color:o[E]}),d(null)},children:"Custom color"}),!A&&e.jsxs("button",{className:"flex items-center gap-1 text-sm text-muted-foreground hover:text-foreground",onClick:()=>{g(E,I),d(null)},children:[e.jsx(Ns,{className:"h-3 w-3"}),"Reset"]})]})]})})]}),e.jsx("span",{className:"flex-1 truncate text-sm",children:E}),M&&e.jsx("span",{className:"text-xs text-muted-foreground",children:"(custom)"})]},E)})}),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(Ct,{color:u.color,onColorChange:E=>{p(u.value,E),m(null)},onClose:()=>m(null)})})]})]})})]})}function we({value:t,onSave:n,placeholder:a="",type:r="text",className:l=""}){const[o,c]=T.useState(t??""),[i,d]=T.useState(!1);T.useEffect(()=>{c(t??"")},[t]);const u=()=>{n(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:a,type:r,value:i?o:t??"",onChange:x=>{c(x.target.value),d(!0)},onFocus:()=>d(!0),onClick:x=>x.stopPropagation(),className:"h-8 text-xs",onPointerDown:x=>x.stopPropagation(),onKeyDown:x=>{x.stopPropagation(),x.key==="Enter"&&i&&o!==t?u():x.key==="Escape"&&m()},"aria-label":a||"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 Nr=["auto","number","currency","percent","scientific","date"],Cr=[{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"}],Sr=[{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"}],wr=t=>t.charAt(0).toUpperCase()+t.slice(1);function ms({formatOptions:t={},onFormatOptionsChange:n,showTitle:a=!0,title:r="NUMBER FORMAT"}){const l=t.type||"auto",o=(i,d)=>{n({...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:[a&&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:Nr.map(i=>e.jsx(s.SelectItem,{value:i,className:"text-xs",children:i==="auto"?"Auto (Default)":wr(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:Cr.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:Sr.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 Is({axis:t,label:n,type:a,config:r,onChange:l}){var x,h,p,g,f,y,v,C,F,k,D,w;const o=(j,N)=>{l({...r,[j]:N})},c=(j,N)=>{var b,R;l({...r,name:{enabled:j==="enabled"?N:((b=r==null?void 0:r.name)==null?void 0:b.enabled)??!1,text:j==="text"?N:(R=r==null?void 0:r.name)==null?void 0:R.text}})},i=(j,N)=>{var b,R;l({...r,labels:{enabled:j==="enabled"?N:((b=r==null?void 0:r.labels)==null?void 0:b.enabled)??!0,rotation:j==="rotation"?N:(R=r==null?void 0:r.labels)==null?void 0:R.rotation}})},d=(j,N)=>{l({...r,scale:{...r==null?void 0:r.scale,[j]:N===""?"auto":Number(N)}})},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:n})})}),e.jsx(s.SmallSwitch,{checked:(r==null?void 0:r.enabled)!==!1,onCheckedChange:j=>o("enabled",j),onClick:j=>j.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:((x=r==null?void 0:r.name)==null?void 0:x.enabled)??!1,onCheckedChange:j=>c("enabled",j)})]}),((h=r==null?void 0:r.name)==null?void 0:h.enabled)&&e.jsx(we,{placeholder:`${n} title`,value:((p=r==null?void 0:r.name)==null?void 0:p.text)||"",onSave:j=>c("text",j),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:j=>o("position",j),children:[e.jsx(s.SelectTrigger,{className:"h-8 text-xs",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{children:u.map(j=>e.jsx(s.SelectItem,{value:j,className:"text-xs",children:j==="auto"?"Auto (Default)":s.titleCase(j)},j))})]})]}),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:((g=r==null?void 0:r.labels)==null?void 0:g.enabled)!==!1,onCheckedChange:j=>i("enabled",j)})]}),((f=r==null?void 0:r.labels)==null?void 0:f.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(((y=r==null?void 0:r.labels)==null?void 0:y.rotation)||"auto"),onValueChange:j=>i("rotation",j==="auto"?"auto":Number(j)),children:[e.jsx(s.SelectTrigger,{className:"h-8 text-xs",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{children:m.map(j=>e.jsx(s.SelectItem,{value:j,className:"text-xs",children:j==="auto"?"Auto (Default)":`${j}°`},j))})]})]})]}),a==="value"&&e.jsx(ms,{formatOptions:(r==null?void 0:r.formatOptions)||{},onFormatOptionsChange:j=>l({...r,formatOptions:j}),showTitle:!0,title:"FORMAT"}),a==="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(we,{type:"number",placeholder:"auto",value:((v=r==null?void 0:r.scale)==null?void 0:v.min)==="auto"||((C=r==null?void 0:r.scale)==null?void 0:C.min)===void 0?"":String(r.scale.min),onSave:j=>d("min",j),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(we,{type:"number",placeholder:"auto",value:((F=r==null?void 0:r.scale)==null?void 0:F.max)==="auto"||((k=r==null?void 0:r.scale)==null?void 0:k.max)===void 0?"":String(r.scale.max),onSave:j=>d("max",j),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(we,{type:"number",placeholder:"auto",value:((D=r==null?void 0:r.scale)==null?void 0:D.stepSize)==="auto"||((w=r==null?void 0:r.scale)==null?void 0:w.stepSize)===void 0?"":String(r.scale.stepSize),onSave:j=>d("stepSize",j),className:""})})]})]})]})]})]})}function wt(){const t=s.useEditorStore(c=>c.card),n=s.useEditorStore(c=>{var i;return(i=c.card)==null?void 0:i.preferences}),{setCardPreferences:a,updateCardInFrame:r}=s.useEditorActions();if(!t||["tornado","pyramid","kpi"].includes(t.type))return null;const l=s.AxisConfigurator.getAxisInfo(t.type,n);if(!l.hasXAxis&&!l.hasYAxis)return null;const o=(c,i)=>{const u={...n||{},[c==="x"?"xAxisConfig":"yAxisConfig"]:i};a(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(Vs,{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(Is,{axis:"x",label:"X-Axis",type:l.xAxisType,config:n==null?void 0:n.xAxisConfig,onChange:c=>o("x",c)}),l.hasYAxis&&e.jsx(Is,{axis:"y",label:"Y-Axis",type:l.yAxisType,config:n==null?void 0:n.yAxisConfig,onChange:c=>o("y",c)})]})})]})}function Dt(){const t=s.useEditorStore(u=>u.card),n=s.useEditorStore(u=>{var m,x,h,p;return(p=(h=(x=(m=u.card)==null?void 0:m.preferences)==null?void 0:x.chartOptions)==null?void 0:h.plugins)==null?void 0:p.legend}),{setLegendOptions:a}=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 x={...n,[u]:m};a(x)},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(Zt,{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:(n==null?void 0:n.display)??o,onCheckedChange:u=>c("display",u)})]}),((n==null?void 0:n.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:(n==null?void 0:n.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:(n==null?void 0:n.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 Tt(){var N,b,R,S,O,E,I,A,M;const t=s.useEditorStore(L=>L.card),n=s.useEditorStore(L=>{var P,B;return(B=(P=L.card)==null?void 0:P.preferences)==null?void 0:B.dataLabelsConfig}),a=s.useEditorStore(L=>{var P;return(P=L.card)==null?void 0:P.preferences}),{setCardPreferences:r,updateCardInFrame:l}=s.useEditorActions();if(!t||!s.chartSupportsDataLabels(t.type))return null;const o=((N=a==null?void 0:a.chartOptions)==null?void 0:N.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=(R=(b=a==null?void 0:a.chartOptions)==null?void 0:b.plugins)==null?void 0:R.datalabels,m=(u==null?void 0:u.display)!==!1&&((u==null?void 0:u.anchor)||(u==null?void 0:u.align)),x=(n==null?void 0:n.enabled)!==void 0?n.enabled:m,h=(L,P)=>{const B={...n,[L]:P},K={...t.preferences||{},dataLabelsConfig:B};r(K);const _={...t,preferences:K};l(_)},p=(L,P)=>{const B={...n,font:{...n==null?void 0:n.font,[L]:P}},K={...t.preferences||{},dataLabelsConfig:B};r(K);const _={...t,preferences:K};l(_)},g=(L,P)=>{const B={...n,formatOptions:{...n==null?void 0:n.formatOptions,[L]:P}},K={...t.preferences||{},dataLabelsConfig:B};r(K);const _={...t,preferences:K};l(_)},y=(()=>{const L=t.type;return L==="stackedBar"||L==="stackedLine"||L==="pie"||L==="doughnut"?"center":o?"right":"top"})();let v=[];c||i?v=["center"]:v=["auto",...(o?["center","left","right"]:["center","top","bottom"]).filter(P=>P!==y),"custom"];const C=()=>s.titleCase(y),F=["center","start","end"],k=["center","start","end","top","bottom"],D=d?["auto","number","currency","percent","none"]:["number","currency","percent","none"],w=[{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"}],j=[{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(pa,{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:x,onCheckedChange:L=>h("enabled",L)})]}),x&&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:(n==null?void 0:n.position)||"auto",onValueChange:L=>h("position",L),children:[e.jsx(s.SelectTrigger,{className:"h-8 text-xs",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{children:v.map(L=>e.jsx(s.SelectItem,{value:L,className:"text-xs",children:L==="auto"?C():L==="custom"?"Custom (Advanced)":s.titleCase(L)},L))})]})]}),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:(n==null?void 0:n.showTotal)??!1,onCheckedChange:L=>h("showTotal",L)})]}),(n==null?void 0:n.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:(n==null?void 0:n.anchor)||"center",onValueChange:L=>h("anchor",L),children:[e.jsx(s.SelectTrigger,{className:"h-8 text-xs flex-1",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{children:F.map(L=>e.jsx(s.SelectItem,{value:L,className:"text-xs",children:s.titleCase(L)},L))})]})]}),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((n==null?void 0:n.align)||"center"),onValueChange:L=>h("align",L),children:[e.jsx(s.SelectTrigger,{className:"h-8 text-xs flex-1",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{children:k.map(L=>e.jsx(s.SelectItem,{value:L,className:"text-xs",children:s.titleCase(L)},L))})]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(s.Label,{className:"text-xs font-medium",children:"Format"}),e.jsxs(s.Select,{value:(n==null?void 0:n.format)||(d?"auto":"none"),onValueChange:L=>h("format",L),children:[e.jsx(s.SelectTrigger,{className:"h-8 text-xs",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{children:D.map(L=>e.jsx(s.SelectItem,{value:L,className:"text-xs",children:L==="auto"&&d?"Auto (Use Axis)":L==="none"?"None (Raw Value)":s.titleCase(L)},L))})]})]}),(n==null?void 0:n.format)&&!["auto","none"].includes(n.format)&&e.jsxs("div",{className:"space-y-2 pl-4 border-l-2 border-muted",children:[["number","currency","percent"].includes(n.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(we,{type:"number",placeholder:"0",value:String(((S=n==null?void 0:n.formatOptions)==null?void 0:S.decimalPlaces)??(n.format==="currency"?2:n.format==="percent"?1:0)),onSave:L=>g("decimalPlaces",Number(L)),className:""})})]}),n.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:((O=n==null?void 0:n.formatOptions)==null?void 0:O.currency)||"USD",onValueChange:L=>g("currency",L),children:[e.jsx(s.SelectTrigger,{className:"h-8 text-xs flex-1",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{children:w.map(L=>e.jsx(s.SelectItem,{value:L.value,className:"text-xs",children:L.label},L.value))})]})]}),["number","currency"].includes(n.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:((E=n==null?void 0:n.formatOptions)==null?void 0:E.useSuffix)??!1,onCheckedChange:L=>g("useSuffix",L)})]}),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:((I=n==null?void 0:n.formatOptions)==null?void 0:I.locale)||"en-US",onValueChange:L=>g("locale",L),children:[e.jsx(s.SelectTrigger,{className:"h-8 text-xs flex-1",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{children:j.map(L=>e.jsx(s.SelectItem,{value:L.value,className:"text-xs",children:L.label},L.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(we,{type:"number",placeholder:"12",value:String(((A=n==null?void 0:n.font)==null?void 0:A.size)||12),onSave:L=>p("size",Number(L)),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:((M=n==null?void 0:n.font)==null?void 0:M.weight)||"normal",onValueChange:L=>p("weight",L),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:(n==null?void 0:n.color)==="auto"||!(n!=null&&n.color)?"auto":"custom",onValueChange:L=>{L==="auto"&&h("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(we,{type:"number",placeholder:"0",value:String((n==null?void 0:n.rotation)||0),onSave:L=>h("rotation",Number(L)),className:""})}),e.jsx("span",{className:"text-xs text-muted-foreground",children:"degrees"})]})]})]})]})})]})}function Dr(){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(St,{}),e.jsx(wt,{}),e.jsx(Dt,{}),e.jsx(Tt,{})]})]})}const Tr=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."]})]}),kr=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."]})]}),Er=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 Ir(){const t=s.useEditorStore(a=>a.card.type);function n(a){const r=["kpi","table","text","map","custom"],l=o=>r.includes(a)?o:e.jsxs(e.Fragment,{children:[o,e.jsx(Dr,{})]});switch(a){case"stackedBar":case"stackedLine":return l(e.jsx(gr,{}));case"tornado":case"pyramid":return l(e.jsx(Ge,{docContent:Tr,cardType:a}));case"kpi":return e.jsx(ur,{});case"line":case"bar":return l(e.jsx(ar,{cardType:a}));case"range":return l(e.jsx(Ge,{docContent:kr,cardType:a}));case"pie":case"doughnut":case"polarArea":case"radar":case"funnel":return l(e.jsx(Ge,{cardType:a}));case"bubble":case"scatter":return l(e.jsx(nr,{cardType:a}));case"table":return e.jsx(jr,{cardType:a});case"text":return e.jsx(Ge,{docContent:Er,cardType:a,suffix:"Visual"});case"map":return e.jsx(pr,{});case"custom":return e.jsx(Zn,{});default:return l(e.jsx(or,{}))}}return e.jsxs(s.ScrollArea,{className:"h-full w-full text-sm",children:[n(t),e.jsx(s.ScrollBar,{orientation:"horizontal"})]})}function Ar(){const t=T.useRef(null),n=T.useRef(null),a=s.useEditorStore(l=>l.isShowingVisual),r=s.useEditorStore(l=>l.showAIDialog);return T.useEffect(()=>{var l,o,c,i;r?((l=t.current)==null||l.resize(0),(o=n.current)==null||o.resize(0)):((c=t.current)==null||c.resize(25),(i=n.current)==null||i.resize(25))},[r]),e.jsxs(s.ResizablePanelGroup,{direction:"vertical",className:"min-h-[250px] min-w-full max-w-lg",children:[e.jsx(s.ResizablePanel,{role:"query-section",className:"flex",minSize:20,defaultSize:40,children:e.jsx(Fn,{})}),e.jsx(s.ResizableHandle,{withHandle:!0}),e.jsx(s.ResizablePanel,{className:"pb-1",role:"visual-section",minSize:0,defaultSize:60,children:a&&!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(Ir,{})})}),!r&&e.jsx(s.ResizableHandle,{}),e.jsx(s.ResizablePanel,{minSize:40,defaultSize:75,maxSize:100,children:e.jsx(Ts,{})})]}):e.jsx(Ts,{})})]})}function Mr(t){s.useAIInteractionStore(G=>G.currentAIContext);const[n,a]=T.useState(""),[r,l]=T.useState(null),{authToken:o,tokenProps:c}=s.useSemaphorContext(),i=s.useEditorStore(G=>{var se;return(se=G==null?void 0:G.card)==null?void 0:se.sql}),d=s.useEditorStore(G=>G.isDevMode),u=s.useEditorStore(G=>{var se;return(se=G==null?void 0:G.card)==null?void 0:se.python}),{setCardPython:m,setCardSql:x,setRunSql:h,switchCardType:p,setQueryConfig:g}=s.useEditorActions(),f=s.useEditorStore(G=>G.currentAssitantScope)||[],y=s.useEditorStore(G=>G.userInputForAI),v=s.useEditorStore(G=>G.triggerAIRun),C=s.useEditorStore(G=>G.card),F=s.useEditorStore(G=>G.selectedDatabaseName),k=s.useEditorStore(G=>G.selectedTableName),D=s.useEditorStore(G=>G.selectedConnectionId),w=s.useEditorStore(G=>G.selectedSchemaName),j=s.useDashboardStore(G=>G.dashboard.aiScopeTables),{errorMessage:N,refetch:b,data:R}=s.useDashboardCardQuery(C),{setTriggerAIRun:S,setCurrentAssitantScope:O,setCardConfig:E}=s.useEditorActions(),{selectedDatamodelName:I,connectionType:A,selectedDatamodelId:M}=s.useEditorAside(),{messages:L,setMessages:P,regenerate:B,error:K,sendMessage:_,status:z,addToolResult:U,stop:W,clearError:ee}=s.useChat({transport:new s.DefaultChatTransport({api:`${c.apiServiceUrl}/v1/assistant`,headers:()=>({Authorization:`Bearer ${o==null?void 0:o.accessToken}`}),body:()=>{const G=s.useAIInteractionStore.getState();return{random:Math.random(),assistantId:"editor-assistant",isDevMode:d,aiContext:G.currentAIContext,reasoningEffort:G.reasoningEffort,showReasoning:G.showReasoning}},credentials:"omit",prepareSendMessagesRequest:({messages:G,body:se})=>({body:{...se,messages:s.cleanupIncompleteMessages(G)}})}),onError:G=>{var se;if(G.name==="AbortError"||(se=G.message)!=null&&se.includes("aborted")){console.log("[Editor Assistant] Stream aborted (expected)");return}console.error("[Editor Assistant] Stream error:",G)},onToolCall:te,onFinish({isAbort:G,isDisconnect:se,isError:ce}){a(""),console.log(G?"[Editor Assistant] Stream aborted by user":se?"[Editor Assistant] Stream disconnected (network error)":ce?"[Editor Assistant] Stream error occurred":"[Editor Assistant] Stream completed successfully")}});T.useEffect(()=>{v&&y&&(_({role:"user",parts:[{type:"text",text:y}]}),S(!1))},[v,y,_,S]);async function te({toolCall:G}){var se,ce,le,fe,ue,Q,$,V,Z,ie,de,ne,me,pe,Re,Le;if(["createChartFromSql","createForecast"].includes(G.toolName)){const De=((se=G.input)==null?void 0:se.sql)??((ce=G.args)==null?void 0:ce.sql),ve=((le=G.input)==null?void 0:le.python)??((fe=G.args)==null?void 0:fe.python),X=((ue=G.input)==null?void 0:ue.chartType)??((Q=G.args)==null?void 0:Q.chartType);p(X),x(De),m(ve),h(!0),U({tool:G.toolName,toolCallId:G.toolCallId,output:{status:"success",message:"Let the user know that chart is created"}})}else if(G.toolName==="getUserSql"){if(!i){U({tool:G.toolName,toolCallId:G.toolCallId,output:{status:"error",message:"No SQL found"}});return}U({tool:G.toolName,toolCallId:G.toolCallId,output:{status:"success",sql:i,python:u||""}})}else if(G.toolName==="generateQueryConfig"){a("Generating query config...");const De=(($=G.input)==null?void 0:$.chartType)??((V=G.args)==null?void 0:V.chartType),ve=((Z=G.input)==null?void 0:Z.queryConfig)??((ie=G.args)==null?void 0:ie.queryConfig);((de=G.input)==null?void 0:de.cardConfig)??((ne=G.args)==null||ne.cardConfig),p(De),E(ve),x(void 0),m(void 0);const X=await b();if((me=X==null?void 0:X.data)!=null&&me.error){U({tool:G.toolName,toolCallId:G.toolCallId,output:{status:"error",queryConfig:ve,message:(pe=X==null?void 0:X.data)==null?void 0:pe.error.message}});return}if((Re=X==null?void 0:X.data)!=null&&Re.records){U({tool:G.toolName,toolCallId:G.toolCallId,output:{status:"success",queryConfig:ve,message:"The data has been visualized"}});return}U({tool:G.toolName,toolCallId:G.toolCallId,output:{status:"success",queryConfig:ve,message:"The data has been visualized",records:(Le=X==null?void 0:X.data)==null?void 0:Le.records}})}else a("Analyzing...")}function oe(G){const se=s.removeFromScopeArray(f,G);H(se)}function H(G){const se=s.sanitizeAIScope(G);O(se),P(ce=>[...ce,{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 q(){const G={databaseName:F||"",schemaName:w||"",tableName:k||"",datamodelId:M||"",datamodelName:s.resolveDatamodelName(I),connectionId:D||"",connectionType:A||""},se=s.dedup([...f,G]);H(se)}function ae(){const G={databaseName:F||"",schemaName:w||"",tableName:k||"",datamodelName:s.resolveDatamodelName(I),connectionId:D||"",connectionType:A||"",datamodelId:M||""};if(!s.isInAiScopeArray([...j||[],...f],G)||f.length===0){const ce=s.dedup([...j||[],...f,G]).filter(le=>le.connectionId===G.connectionId);H(ce)}}const J=!["ready","error"].includes(z),re=s.getErrorMessage(K);return{messages:L,setMessages:P,sendMessage:_,regenerate:B,isLoading:J,handleSetAIScope:ae,handleAddCurrentTableToScope:q,removeFromCurrentSelections:oe,currentAssitantScope:f,setCurrentAssitantScope:O,stop:W,status:z,toolStatus:n,llmUsage:r,onFinish:t,errorMessage:re,clearError:ee}}const Rr=[{title:"Help me write a query for",subtitle:"orders by month"},{title:"Create a bar chart for",subtitle:"sales by category"}];function As({isFullscreen:t,onFullscreenChange:n,fullscreenContainer:a}){const r=T.useRef(null),[l,o]=T.useState(!1),[c,i]=T.useState(s.isDevEnv),[d,u]=T.useState(!1),[m,x]=T.useState(!1),[h,p]=T.useState(!1),g=t??h,f=s.useCurrentAIContext(),{setCurrentAIContext:y}=s.useAIActions(),{clearQueue:v}=s.useQueueActions(),{clearFileAttachments:C}=s.useFileActions(),F=s.useFileAttachments("editor"),k=s.useDashboardStore(X=>X.dashboard.aiContext),D=s.useEditorStore(X=>X.card.dataSource),w=s.useEditorStore(X=>X.actions.setCardSql),j=s.useEditorStore(X=>X.actions.setRunSql),N=s.useEditorStore(X=>X.showAIDialog),b=s.useDashboardStore(X=>X.handleOpenAssistantProfile),{setShowAIDialog:R,setCardPython:S}=s.useEditorActions(),{setDataSource:O}=s.useEditorActions(),{assistantProfile:E}=s.useAssistantProfile(),{messages:I,setMessages:A,sendMessage:M,isLoading:L,stop:P,status:B,llmUsage:K,errorMessage:_,clearError:z}=Mr(),[U,W]=T.useState(""),ee=X=>{W(X.target.value)},te=X=>{X.preventDefault();const ge=U.trim();if(!ge&&F.length===0)return;const Be=[];ge&&Be.push({type:"text",text:ge}),F.forEach(ke=>{ke.data&&Be.push({type:"file",mediaType:ke.type,filename:ke.name,url:`data:${ke.type};base64,${ke.data}`})}),M({role:"user",parts:Be}),W(""),C("editor"),le({force:!0})},{visibleMessages:oe,hasMoreMessages:H,totalMessageCount:q,loadMoreMessages:ae,resetMessageWindow:J}=s.useMessageWindow(I,{maxVisibleMessages:15,initialLoadCount:10,loadMoreCount:5}),{scrollRef:re,isAtBottom:G,hasNewMessages:se,newMessageCount:ce,scrollToBottom:le,handleScroll:fe,resetNewMessageCount:ue}=s.useAutoScroll(oe,{threshold:50,delay:0,dependencies:[B,I.length]});T.useEffect(()=>{var X;N&&((X=r.current)==null||X.focus(),y({selectedEntities:(D==null?void 0:D.selectedEntities)||[]}))},[N,D,y]),s.useAutoSubmitQueue({assistantType:"editor",status:B,isLoading:L,sendMessage:M});const{hasActiveTools:Q}=s.useActiveToolStatus(I),$=T.useCallback(X=>{n==null||n(X),t===void 0&&p(X)},[t,n]);T.useEffect(()=>{if(!g)return;function X(ge){ge.key==="Escape"&&$(!1)}return window.addEventListener("keydown",X),()=>{window.removeEventListener("keydown",X)}},[g,$]);const V=T.useCallback(X=>{M({role:"user",parts:[{type:"text",text:X}]}),le({force:!0})},[M,le]),Z=T.useCallback(async()=>{const X=JSON.stringify(I??[],null,2);try{if(typeof navigator>"u"||!navigator.clipboard)throw new Error("Clipboard API unavailable");await navigator.clipboard.writeText(X),s.ue.success("Conversation copied")}catch(ge){console.error("Failed to copy conversation",ge),s.ue.error("Unable to copy conversation")}},[I]),ie=T.useCallback(()=>{$(!g)},[g,$]);function de(X,ge){ge==="sql"?(w(X),j(!0)):ge==="python"&&(S(X),j(!0))}function ne(){f.selectedEntities.length===0&&y({selectedEntities:(k==null?void 0:k.selectedEntities)||[]})}function me(X){ne();const ge={role:"user",parts:[{type:"text",text:X.title+" "+X.subtitle}]};M(ge)}function pe(X){ne(),M({role:"user",parts:[{type:"text",text:X}]})}function Re(){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 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:l,onCheckedChange:o,children:"Token Usage"}),e.jsx(s.DropdownMenuCheckboxItem,{checked:c,onCheckedChange:i,children:"Tool Invocations"}),e.jsx(s.DropdownMenuCheckboxItem,{checked:d,onCheckedChange:u,children:"System Message"})]})]})}function Le(){return e.jsx("div",{"data-role":"header",children:e.jsx("div",{className:"text-lg font-semibold",children:"Assistant"})})}const De=(U==null?void 0:U.length)===0&&(I==null?void 0:I.filter(X=>X.role==="user").length)===0,ve=e.jsxs("div",{"data-role":"editor-assistant",className:s.cn("flex h-full w-full flex-col justify-between px-6 py-4",g&&"rounded-2xl border border-border/60 bg-background px-8 pb-6 pt-6 shadow-xl"),children:[e.jsxs("div",{"data-role":"header-section",className:"flex items-start justify-between gap-2",children:[Le(),b&&e.jsx(s.Button,{variant:"outline",size:"sm",className:"h-7 p-2",onClick:b,children:(E==null?void 0:E.name)||"Default Profile"}),e.jsxs("div",{"data-role":"header-actions",className:"flex items-center",children:[Re(),c&&e.jsx(s.Button,{variant:"ghost",size:"sm",className:"ml-2 h-7 px-2 text-muted-foreground hover:text-foreground",onClick:Z,children:"Copy Conversation"}),e.jsx(s.IconButton,{tooltip:g?"Exit Fullscreen":"Expand",className:"h-7 p-2 text-muted-foreground hover:text-foreground",onClick:ie,children:g?e.jsx(s.Minimize2,{className:"size-4"}):e.jsx(s.Maximize2,{className:"size-4"})}),e.jsx(s.IconButton,{className:"h-7 p-2 text-muted-foreground hover:text-foreground",tooltip:"New Chat",onClick:()=>{A([]),v("editor"),z(),J()},children:e.jsx(s.SquarePen,{className:"size-4"})}),e.jsx(s.Button,{variant:"ghost",className:"h-7 p-2 text-muted-foreground hover:text-foreground",size:"sm",onClick:()=>{R(!1)},children:e.jsx(s.X,{className:"size-4"})})]})]}),e.jsx(s.CustomScrollArea,{ref:re,className:"mt-2 flex w-full grow basis-0",onScroll:fe,children:e.jsxs("div",{className:"space-y-4 py-2 pr-3","data-role":"messages",children:[H&&e.jsx("div",{className:"flex justify-center py-2",children:e.jsxs(s.Button,{variant:"outline",size:"sm",onClick:ae,className:"text-xs",children:["Load ",Math.min(5,q-oe.length)," ","more messages (",q-oe.length," ","hidden)"]})}),e.jsx(s.PrintMessages,{messages:oe,showTools:c,handleRun:de,showSystemMessage:d,onQuickReply:V,disableQuickReplies:L}),!Q&&e.jsx(s.AssistantStatus,{status:B,errorMessage:_})]})}),!G&&e.jsx("div",{className:"absolute bottom-24 right-8 z-10",children:e.jsxs(s.Button,{onClick:()=>{le({force:!0}),ue()},size:"sm",variant:"secondary",className:"rounded-full shadow-lg","aria-label":"Scroll to bottom",children:[e.jsx(s.ChevronDown,{className:"h-4 w-4"}),se&&ce>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:ce>9?"9+":ce})]})}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{children:[De&&!E&&e.jsx(s.Placeholders,{onClick:me,placeholders:Rr}),e.jsx("div",{children:De&&E&&e.jsx(s.SeedQuestions,{seedQuestions:E.seedQuestions||[],handleSeedQuestionClick:pe})})]}),e.jsx(s.PendingMessagesDisplay,{assistantType:"editor",className:"mb-3"}),e.jsx(s.ChatInputWithContext,{ref:r,setInput:W,stop:P,input:U,handleInputChange:ee,handleSubmit:X=>{ne(),te(X),le({force:!0})},isLoading:L,status:B,assistantType:"editor",onFocus:()=>{}})]}),K&&l&&e.jsx("div",{className:"flex h-8 items-center justify-between",children:e.jsxs("div",{className:"text-xs text-muted-foreground",children:["Usage: ",K.inputTokens," prompt tokens, ",K.outputTokens," ","completion tokens, ",K.totalTokens," total tokens"]})}),e.jsx(s.DataSourceDialog,{incomingSelectedEntities:(D==null?void 0:D.selectedEntities)||[],open:m,onOpenChange:x,dataSource:D||s.EMPTY_DATA_SOURCE,dialogMode:"aiContext"})]});return g&&a?Ot.createPortal(e.jsx("div",{className:"pointer-events-auto absolute inset-0 z-50 flex bg-background px-6 pb-6 pt-[calc(var(--app-header-height,15px)+1rem)]",children:e.jsx("div",{className:"flex h-full w-full",children:ve})}),a):ve}function hs(t,n){const[a,r]=T.useState(()=>{const l=localStorage.getItem(t);return l?JSON.parse(l):n});return T.useEffect(()=>{localStorage.setItem(t,JSON.stringify(a))},[a,t]),[a,r]}const Lr="chart-selector-standard-first";function Fr(){const[t,n]=hs(Lr,!0);return{standardFirst:t,updatePreference:n}}const Ms=({pluginVisual:t,index:n,onSelect:a})=>{const r=Je(t.icon||""),l=t.name.charAt(0).toUpperCase(),o=s.getAutoDetectedChartIcon(t.name);return e.jsx(s.CommandItem,{value:`${t.name} custom visual plugin component`,onSelect:a,className:"group flex items-center gap-2",children:e.jsxs("div",{className:"flex w-full items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[r?e.jsx(r,{className:"h-4 w-4"}):o||e.jsx("div",{className:"flex h-4 w-4 items-center justify-center rounded bg-muted text-xs font-medium",children:l}),e.jsx("span",{children:t.name})]}),e.jsxs(s.Tooltip,{children:[e.jsx(s.TooltipTrigger,{asChild:!0,children:e.jsx("span",{tabIndex:0,className:"opacity-0 outline-none transition-opacity group-hover:opacity-100",children:e.jsx(s.Info,{className:"ml-1 h-3.5 w-3.5 text-muted-foreground"})})}),e.jsx(s.TooltipContent,{side:"right",children:t.pluginName})]})]})},`${t.url}-${t.name}-${n}`)},Rs=["default","standardPlugin","customPlugin"];function Or({selectedChart:t,onChartChange:n}){var k;const[a,r]=T.useState(!1),{data:l}=pt();Fr();const c=((k=s.useEditorStore(D=>D.card).customCardPreferences)==null?void 0:k.url)||"";ls(c);const{setCardType:i,setCardPreferences:d,setIsDevMode:u}=s.useEditorStore(D=>D.actions),{setCardCustomCfg:m,setCustomCardPreferences:x,setQueryConfig:h}=s.useEditorActions(),[p,g]=hs("chart-section-active",null),f=T.useMemo(()=>p?[p,...Rs.filter(D=>D!==p)]:Rs,[p]);function y(D){m(null),d({}),i(D),["custom","map"].includes(D)&&(u(!0),h(void 0)),n(D),r(!1)}function v(D){m(null),d({}),i("custom"),x({type:"component",visualType:"single",url:D.url,componentName:D.name,icon:D.icon,pluginChartType:D.chartType}),h(void 0),n("custom"),r(!1)}const C=()=>{var w;if(t==="custom"){const j=s.useEditorStore.getState().card;return((w=j==null?void 0:j.customCardPreferences)==null?void 0:w.componentName)||"Custom Visual"}const D=s.chartTypes.find(j=>j.id===t);return(D==null?void 0:D.label)||"Select chart type"},F=()=>{var w,j;if(t==="custom"){const N=s.useEditorStore.getState().card,b=(w=N==null?void 0:N.customCardPreferences)==null?void 0:w.icon,R=(j=N==null?void 0:N.customCardPreferences)==null?void 0:j.componentName;if(b&&R)return e.jsx(Pr,{icon:b,componentName:R});if(R){const S=s.getAutoDetectedChartIcon(R);if(S)return S}return e.jsx(Ve,{className:"h-4 w-4"})}const D=s.chartTypes.find(N=>N.id===t);if(D){const N=D.icon;return e.jsx(N,{className:"h-4 w-4"})}return e.jsx(Ve,{className:"h-4 w-4"})};return e.jsx("div",{className:"",children:e.jsxs(s.Popover,{open:a,onOpenChange:r,children:[e.jsx(s.PopoverTrigger,{asChild:!0,children:e.jsxs(s.Button,{variant:"outline",role:"combobox","aria-expanded":a,className:"w-full justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[F(),e.jsx("span",{children:C()})]}),e.jsx(s.ChevronDown,{className:"ml-2 h-4 w-4 shrink-0 opacity-50"})]})}),e.jsx(s.PopoverContent,{className:"w-[300px] p-0",align:"start",children:e.jsxs(s.Command,{children:[e.jsx(s.CommandInput,{placeholder:"Search chart types..."}),e.jsxs(s.CommandList,{className:"mb-2 max-h-[300px]",children:[e.jsx(s.CommandEmpty,{children:"No chart type found."}),f.map(D=>{if(D==="default")return e.jsx(s.CommandGroup,{heading:e.jsxs("div",{className:"group flex w-full items-center justify-between",children:[e.jsxs(s.Tooltip,{children:[e.jsx(s.TooltipTrigger,{asChild:!0,children:e.jsx("span",{className:"flex items-center gap-2",children:"Default Visuals"})}),e.jsx(s.TooltipContent,{side:"right",children:"These are the standard visuals available in Semaphor"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-xs text-muted-foreground opacity-0 transition-opacity group-hover:opacity-100",children:"Show on top"}),e.jsx(s.Switch,{checked:p==="default",onCheckedChange:w=>g(w?"default":null),className:"scale-75"})]})]}),className:"[&_[cmdk-group-heading]]:text-sm [&_[cmdk-group-heading]]:font-medium [&_[cmdk-group-heading]]:text-muted-foreground",children:s.chartTypes.map(w=>{const j=w.icon;return e.jsx(s.CommandItem,{value:`${w.label} ${w.id} chart graph visualization`,onSelect:()=>y(w.id),className:"flex items-center gap-2",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(j,{className:"h-4 w-4"}),e.jsx("span",{children:w.label})]})},w.id)})},"default");if(D==="standardPlugin"){const w=l.filter(j=>j.pluginType==="standard");return w.length?e.jsx(s.CommandGroup,{heading:e.jsxs("div",{className:"group flex w-full items-center justify-between",children:[e.jsx("p",{children:"Standard Visuals"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-xs text-muted-foreground opacity-0 transition-opacity group-hover:opacity-100",children:"Show on top"}),e.jsx(s.Switch,{checked:p==="standardPlugin",onCheckedChange:j=>g(j?"standardPlugin":null),className:"scale-75"})]})]}),className:"[&_[cmdk-group-heading]]:text-sm [&_[cmdk-group-heading]]:font-medium [&_[cmdk-group-heading]]:text-muted-foreground",children:w.filter(j=>j.componentType==="chart").map((j,N)=>e.jsx(Ms,{pluginVisual:j,index:N,onSelect:()=>v(j)},`${j.url}-${j.name}-${N}`))},"standardPlugin"):null}if(D==="customPlugin"){const w=l.filter(j=>j.pluginType==="custom");return w.length?e.jsx(s.CommandGroup,{heading:e.jsxs("div",{className:"group flex w-full items-center justify-between",children:[e.jsxs(s.Tooltip,{children:[e.jsx(s.TooltipTrigger,{asChild:!0,children:e.jsxs("span",{className:"flex items-center gap-2",children:["Custom Visuals",e.jsx(s.Info,{className:"h-3.5 w-3.5 text-muted-foreground"})]})}),e.jsx(s.TooltipContent,{side:"right",children:"External visuals that are specific to your project"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-xs text-muted-foreground opacity-0 transition-opacity group-hover:opacity-100",children:"Show on top"}),e.jsx(s.Switch,{checked:p==="customPlugin",onCheckedChange:j=>g(j?"customPlugin":null),className:"scale-75"})]})]}),className:"[&_[cmdk-group-heading]]:text-sm [&_[cmdk-group-heading]]:font-medium [&_[cmdk-group-heading]]:text-muted-foreground",children:w.map((j,N)=>e.jsx(Ms,{pluginVisual:j,index:N,onSelect:()=>v(j)},`${j.url}-${j.name}-${N}`))},"customPlugin"):null}return null})]})]})})]})})}const Pr=({icon:t,componentName:n})=>{const a=Je(),r=s.getAutoDetectedChartIcon(n);return a?e.jsx(a,{className:"h-4 w-4"}):r||e.jsx(Ve,{className:"h-4 w-4"})},Br=[{id:"table",icon:s.Table2,label:"Table"},{id:"bar",icon:s.ChartColumnIncreasing,label:"Bar Chart"},{id:"line",icon:s.ChartLine,label:"Line Chart"},{id:"stackedBar",icon:s.ChartColumnStacked,label:"Stacked Bar",requiresPivot:!0},{id:"pie",icon:s.ChartPie,label:"Pie Chart"},{id:"doughnut",icon:s.Donut,label:"Donut Chart"},{id:"kpi",icon:s.TiSortNumerically,label:"KPI"}];function Vr({selectedChart:t,onChartChange:n}){var l;const a=s.useEditorStore(o=>o.card),r=((l=a==null?void 0:a.config)==null?void 0:l.pivotByColumns)&&a.config.pivotByColumns.length>0;return e.jsx("div",{className:"flex items-center justify-center gap-1",children:Br.map(o=>{if(o.requiresPivot&&!r)return null;const c=o.icon,i=t===o.id;return e.jsxs(s.Tooltip,{children:[e.jsx(s.TooltipTrigger,{asChild:!0,children:e.jsxs(s.Button,{variant:"ghost",size:"sm",onClick:()=>n(o.id),className:s.cn("h-8 w-8 p-0",i&&"bg-accent text-accent-foreground"),children:[e.jsx(c,{className:"h-4 w-4"}),e.jsx("span",{className:"sr-only",children:o.label})]})}),e.jsx(s.TooltipContent,{side:"bottom",children:e.jsx("p",{children:o.label})})]},o.id)})})}const xs=({dataType:t})=>{const n=s.getDataType(t);return n==="string"?e.jsx("span",{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(qe,{className:"h-3 w-3"})}):n==="number"?e.jsx("span",{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(ns,{className:"h-3 w-3"})}):n==="date"?e.jsx("span",{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"})}):n==="boolean"?e.jsx("span",{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(Us,{className:"h-3 w-3"})}):e.jsx("span",{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"})})};function zr({aliasTemplate:t,onAliasTemplateChange:n}){var d;const[a,r]=T.useState(t),[l,o]=T.useState(!1),c=(d=s.useEditorStore(u=>{var m;return(m=u.card.config)==null?void 0:m.pivotByColumns}))==null?void 0:d[0],i=c?`e.g. Min Sales in {{${c.name}}}`:"e.g. Min Sales in {{region}}";return e.jsxs("div",{className:"space-y-1",children:[e.jsx(s.Label,{className:"text-xs font-medium text-gray-600",children:"Pivot Alias Template"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(s.Input$1,{placeholder:i,value:l?a:t,onChange:u=>{r(u.target.value),o(!0)},onFocus:()=>o(!0),onPointerDown:u=>u.stopPropagation(),className:"h-8 text-xs",onKeyDown:u=>{u.key==="Enter"&&l&&a!==t?(n(a),o(!1)):u.key==="Escape"&&(r(t),o(!1))},"aria-label":"Edit alias template"}),l&&a!==t&&e.jsxs(e.Fragment,{children:[e.jsx(s.Button,{variant:"ghost",size:"icon",className:"h-6 w-6 p-0","aria-label":"Confirm alias template",onClick:()=>{n(a),o(!1)},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 alias template edit",onClick:()=>{r(t),o(!1)},children:e.jsx(s.X,{className:"h-4 w-4 text-gray-400"})})]})]})]})}function Ur({valueAliases:t,onValueAliasesChange:n}){const[a,r]=T.useState(null),[l,o]=T.useState(""),[c,i]=T.useState(""),d=()=>{n({...t,"":""})},u=x=>{const h={...t};delete h[x],n(h)},m=x=>{const h={...t};delete h[x],h[l]=c,n(h),r(null)};return e.jsxs("div",{className:"space-y-1",children:[e.jsx(s.Label,{className:"text-xs font-medium text-muted-foreground",children:"Pivot Value Aliases"}),e.jsxs("div",{className:"space-y-2",children:[Object.entries(t).map(([x,h],p)=>e.jsx("div",{className:"flex items-center gap-2",children:a===x?e.jsxs(e.Fragment,{children:[e.jsx(s.Input$1,{placeholder:"Value key",value:l,onChange:g=>o(g.target.value),className:"h-8 w-24 text-xs",onPointerDown:g=>g.stopPropagation(),onKeyDown:g=>{g.key==="Enter"?m(x):g.key==="Escape"&&r(null)},"aria-label":"Edit value alias key"}),e.jsx(s.Input$1,{placeholder:"Alias label",value:c,onChange:g=>i(g.target.value),className:"h-8 w-24 text-xs",onPointerDown:g=>g.stopPropagation(),onKeyDown:g=>{g.key==="Enter"?m(x):g.key==="Escape"&&r(null)},"aria-label":"Edit value alias label"}),e.jsx(s.Button,{variant:"ghost",size:"icon",className:"h-6 w-6 p-0","aria-label":"Confirm value alias edit",onClick:()=>m(x),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 value alias edit",onClick:()=>r(null),children:e.jsx(s.X,{className:"h-4 w-4 text-muted-foreground"})})]}):e.jsxs(e.Fragment,{children:[e.jsx(s.Input$1,{placeholder:"Value key",value:x,className:"h-8 w-24 text-xs",readOnly:!0,onClick:()=>{r(x),o(x),i(h)},"aria-label":"Edit value alias key"}),e.jsx(s.Input$1,{placeholder:"Alias label",value:h,className:"h-8 w-24 text-xs",readOnly:!0,onClick:()=>{r(x),o(x),i(h)},"aria-label":"Edit value alias label"}),e.jsx(s.Button,{variant:"ghost",size:"sm",className:"h-8 w-8 p-0",onClick:()=>u(x),"aria-label":"Remove value alias",children:e.jsx(s.X,{className:"h-3 w-3"})})]})},x+p)),e.jsxs(s.Button,{variant:"outline",size:"sm",className:"mt-1 h-8 text-xs",onClick:d,children:[e.jsx(s.Plus,{className:"mr-1 h-3 w-3"})," Add Value Alias"]})]})]})}function Gr({column:t}){const n=s.useEditorStore(d=>d.card.type),a=s.useEditorStore(d=>{var u,m;return(m=(u=d.card)==null?void 0:u.config)==null?void 0:m.metricColumns}),r=(a==null?void 0:a.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(yt,{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(Nt,{})]})}return e.jsxs("div",{className:"space-y-1",children:[["stackedBar","stackedLine","bar","line"].includes(n)&&c(),["pie","doughnut"].includes(n)&&i()]})}function _r({field:t,searchQuery:n="",limit:a=500}){const{authToken:r,tokenProps:l}=s.useSemaphorContext(),o=s.useEditorStore(u=>u.card),c=o==null?void 0:o.dataSource,i=["attribute-values",t.entityName,t.name,n,a],d=s.useQuery({queryKey:i,queryFn:async()=>{if(!(c!=null&&c.connectionId))return console.warn("No connection ID available for attribute values query"),[];try{const u={groupByColumns:[{...t,role:"groupby"}],metricColumns:[],filters:n?{id:"search-filter",logicalOperator:"AND",negate:!1,conditions:[{id:"search-condition",field:t,operator:"contains",value:n}],groups:[]}:void 0,rowLimit:a},m={connection_id:c.connectionId,cardConfig:u,cardDataSource:c,cache_config:s.getCacheConfig({card:o})};console.log("requestBody",m);const x=await s.postRequestRegular(`${l.apiServiceUrl}/v1/query`,(r==null?void 0:r.accessToken)||"",m);if(x!=null&&x.error)return console.error("Error fetching attribute values:",x.error),[];const h=t.name;return((x==null?void 0:x.records)||[]).map(g=>{const f=g[h]||g[t.alias||h]||g[t.label];return{id:f||"",value:f||"",label:String(f||"(empty)")}})}catch(u){return console.error("Error fetching attribute values:",u),[]}},enabled:!!t&&!!(c!=null&&c.connectionId),staleTime:5*60*1e3,gcTime:10*60*1e3});return{values:d.data||[],isLoading:d.isLoading,isFetching:d.isFetching,isError:d.isError,error:d.error,refetch:d.refetch}}function $r({open:t,onOpenChange:n,availableFields:a,existingFilters:r,editingCondition:l,onSave:o}){var F,k;const c=!!l,[i,d]=T.useState(c?"values":"fields"),[u,m]=T.useState(""),[x,h]=T.useState({id:(l==null?void 0:l.id)||s.v4(),field:(l==null?void 0:l.field)||null,selectedValues:l?Array.isArray(l.value)?l.value:[l.value]:[]}),p=a.filter(D=>{var j;return c?!1:!((j=r==null?void 0:r.conditions)==null?void 0:j.some(N=>N.field.id===D.id))&&D.label.toLowerCase().includes(u.toLowerCase())}),g=D=>{h({...x,field:D}),d("values")},f=()=>{if(x.field&&x.selectedValues.length>0){const D={id:x.id,field:x.field,operator:"in",value:x.selectedValues};let w;if(c){const j=((r==null?void 0:r.conditions)||[]).map(N=>N.id===l.id?D:N);w={...r,conditions:j}}else{const j=(r==null?void 0:r.conditions)||[];w={id:(r==null?void 0:r.id)||s.v4(),logicalOperator:"AND",negate:!1,conditions:[...j,D],groups:[]}}o(w),n(!1)}},y=()=>{if(!c||!l)return;const D=((r==null?void 0:r.conditions)||[]).filter(w=>w.id!==l.id);if(D.length>0){const w={...r,conditions:D};o(w)}else o(void 0);n(!1)},v=D=>{h({...x,selectedValues:D})},C=()=>{c&&l?(h({id:l.id,field:l.field,selectedValues:Array.isArray(l.value)?l.value:[l.value]}),d("values")):(h({id:s.v4(),field:null,selectedValues:[]}),d("fields")),m("")};return T.useEffect(()=>{t&&C()},[t,c,l]),e.jsx(s.Dialog,{open:t,onOpenChange:n,children:e.jsxs(s.DialogContent,{className:"max-w-2xl",children:[e.jsx(s.DialogHeader,{children:e.jsx(s.DialogTitle,{children:c?`Edit Filter: ${(F=x.field)==null?void 0:F.label}`:i==="fields"?"Select Field to Filter":`Select Values for ${(k=x.field)==null?void 0:k.label}`})}),e.jsxs("div",{className:"space-y-4",children:[!c&&(r==null?void 0:r.conditions)&&r.conditions.length>0&&i==="fields"&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(s.Label,{className:"text-xs font-medium text-muted-foreground",children:"Current Filters:"}),e.jsx("div",{className:"flex flex-wrap gap-2",children:r.conditions.map(D=>e.jsxs("div",{className:"flex items-center gap-1 px-2 py-1 bg-muted rounded-md text-xs",children:[e.jsxs("span",{className:"font-medium",children:[D.field.label,":"]}),e.jsx("span",{className:"text-muted-foreground",children:Array.isArray(D.value)?`${D.value.length} values`:String(D.value)})]},D.id))})]}),i==="fields"&&!c?e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"relative",children:[e.jsx(s.Search,{className:"absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground"}),e.jsx(s.Input$1,{placeholder:"Search fields...",value:u,onChange:D=>m(D.target.value),className:"pl-10"})]}),e.jsx("div",{className:"grid grid-cols-2 gap-2 max-h-[400px] overflow-y-auto",children:p.map(D=>e.jsxs(s.Button,{variant:"outline",className:"justify-start h-auto py-2 px-3",onClick:()=>g(D),children:[e.jsx(xs,{dataType:s.getDataType(D.dataType)}),e.jsxs("div",{className:"ml-2 text-left",children:[e.jsx("div",{className:"text-sm font-medium",children:D.label}),e.jsxs("div",{className:"text-xs text-muted-foreground",children:[D.entityName,".",D.name]})]})]},D.id))}),p.length===0&&u&&e.jsxs("div",{className:"text-center py-4 text-sm text-muted-foreground",children:['No fields found matching "',u,'"']}),p.length===0&&!u&&a.length>0&&e.jsx("div",{className:"text-center py-4 text-sm text-muted-foreground",children:"All available fields are already filtered"})]}):e.jsx(Yr,{field:x.field,selectedValues:x.selectedValues,onValuesChange:v,onBack:c?void 0:()=>d("fields")}),e.jsxs("div",{className:"flex justify-between pt-4 border-t",children:[e.jsx("div",{children:c?e.jsx(s.Button,{variant:"destructive",onClick:y,children:"Delete Filter"}):e.jsx(s.Button,{variant:"outline",onClick:C,children:"Reset"})}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(s.Button,{variant:"outline",onClick:()=>n(!1),children:"Cancel"}),e.jsx(s.Button,{onClick:f,disabled:!x.field||x.selectedValues.length===0,children:"Apply"})]})]})]})]})})}function Yr({field:t,selectedValues:n,onValuesChange:a,onBack:r}){const[l,o]=T.useState(""),{values:c,isLoading:i,isFetching:d}=_r({field:t,searchQuery:l,limit:500}),u=l?c.filter(h=>String(h.value).toLowerCase().includes(l.toLowerCase())):c,m=h=>{const p=n.includes(h);a(p?n.filter(g=>g!==h):[...n,h])},x=()=>{n.length===u.length&&u.length>0?a([]):a(u.map(h=>h.value))};return e.jsxs("div",{className:"space-y-4",children:[r&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(s.Button,{variant:"ghost",size:"sm",onClick:r,children:"← Back"}),e.jsxs(s.Label,{className:"text-sm font-medium",children:["Select values for ",t.label]})]}),e.jsxs("div",{className:"relative",children:[e.jsx(s.Search,{className:"absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground"}),e.jsx(s.Input$1,{placeholder:"Search values...",value:l,onChange:h=>o(h.target.value),className:"pl-10"})]}),i||d?e.jsx("div",{className:"flex items-center justify-center py-8",children:e.jsx(s.LoaderCircle,{className:"h-6 w-6 animate-spin"})}):e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-2 pb-2 border-b",children:[e.jsx(s.Checkbox,{checked:n.length===u.length&&u.length>0,onCheckedChange:x}),e.jsxs(s.Label,{className:"text-sm",children:["Select All (",u.length,")"]})]}),e.jsx("div",{className:"max-h-[300px] overflow-y-auto space-y-1",children:u.map(h=>e.jsxs("div",{className:"flex items-center gap-2 p-2 hover:bg-muted/50 rounded cursor-pointer",onClick:()=>m(h.value),children:[e.jsx(s.Checkbox,{checked:n.includes(h.value),onCheckedChange:()=>m(h.value)}),e.jsx(us,{className:"text-sm",children:h.label})]},h.id))})]})]})}function qr({field:t,zone:n,index:a,sortDirection:r,onSortDirectionChange:l,hasPivotColumns:o=!1,cardType:c}){var fs,gs,js;const{attributes:i,listeners:d,setNodeRef:u,transform:m,transition:x,isDragging:h}=s.useSortable({id:t.id}),p=s.useEditorStore(Y=>Y.card),{updateLabel:g,handleAggregationChange:f,handleDateFormatChange:y,handleGranularityChange:v,handleAliasTemplateChange:C,handleValueAliasesChange:F,removeField:k,handleKpiComparisonTypeChange:D,handleKpiShowTrendlineChange:w,handleKpiTrendlineWindowChange:j,handleKpiTrendlineGranularityChange:N,handleKpiTargetValueChange:b}=cs(p),[R,S]=T.useState(!1),[O,E]=T.useState(!1),[I,A]=T.useState(null),[M,L]=T.useState(t.dateFormat||"YYYY-MM-DD"),[P,B]=T.useState(t.customFormat||""),[K,_]=T.useState(!!t.customFormat),[z,U]=T.useState(t.granularity||"day"),[W,ee]=T.useState(t.aliasTemplate||""),[te,oe]=T.useState(t.valueAliases||{}),[H,q]=T.useState((fs=t.parameters)==null?void 0:fs.filters),ae=Y=>{Y==="custom"?_(!0):(_(!1),L(Y),n==="groupBy"&&y(a,Y,""))},J=Y=>{B(Y),n==="groupBy"&&y(a,"custom",Y)},re=Y=>{var je;U(Y);const xe=(je=Z(Y)[0])==null?void 0:je.value;xe&&!K&&(L(xe),n==="groupBy"&&y(a,xe,"")),n==="groupBy"&&v(a,Y)},G=Y=>{ee(Y),n==="metrics"&&C(a,Y)},se=Y=>{oe(Y),n==="metrics"&&F(a,Y)},ce=Y=>{g(n,a,Y)},le=Y=>{var he;if(q(Y),n==="metrics"){const xe={...t,parameters:{...t.parameters,filters:Y}},je=[...((he=p.config)==null?void 0:he.metricColumns)||[]];je[a]=xe,s.useEditorStore.getState().actions.updateCardConfig(p.id,{metricColumns:je})}E(!1)},fe=()=>{k(n,a)},ue={transform:s.CSS.Transform.toString(m),transition:x},Q=s.getDataType(t.dataType),$=Q==="date",V=c==="kpi",Z=Y=>{switch(Y){case"day":return[{value:"MM-DD-YYYY",label:"01-15-2024 (MM-DD-YYYY)"},{value:"YYYY-MM-DD",label:"2024-01-15 (YYYY-MM-DD)"},{value:"MM/DD/YYYY",label:"01/15/2024 (MM/DD/YYYY)"},{value:"DD/MM/YYYY",label:"15/01/2024 (DD/MM/YYYY)"},{value:"MMMM DD, YYYY",label:"January 15, 2024 (MMMM DD, YYYY)"},{value:"MMM DD, YYYY",label:"Jan 15, 2024 (MMM DD, YYYY)"},{value:"DD MMM YYYY",label:"15 Jan 2024 (DD MMM YYYY)"},{value:"custom",label:"Custom Format..."}];case"week":return[{value:"MM-DD-YYYY",label:"01-15-2024 (MM-DD-YYYY)"},{value:"YYYY-MM-DD",label:"2024-01-15 (YYYY-MM-DD)"},{value:"Week of MMM DD, YYYY",label:"Week of Jan 15, 2024"},{value:"Week of MMMM DD, YYYY",label:"Week of January 15, 2024"},{value:"YYYY-WW",label:"2024-W03 (YYYY-WW)"},{value:"custom",label:"Custom Format..."}];case"month":return[{value:"MMM YYYY",label:"Jan 2024 (MMM YYYY)"},{value:"MMMM YYYY",label:"January 2024 (MMMM YYYY)"},{value:"YYYY-MM",label:"2024-01 (YYYY-MM)"},{value:"MM/YYYY",label:"01/2024 (MM/YYYY)"},{value:"YYYY MMM",label:"2024 Jan (YYYY MMM)"},{value:"custom",label:"Custom Format..."}];case"quarter":return[{value:"Q1 YYYY",label:"Q1 2024 (Q1 YYYY)"},{value:"YYYY Q1",label:"2024 Q1 (YYYY Q1)"},{value:"1st Quarter YYYY",label:"1st Quarter 2024"},{value:"YYYY-Q1",label:"2024-Q1 (YYYY-Q1)"},{value:"Quarter 1, YYYY",label:"Quarter 1, 2024"},{value:"custom",label:"Custom Format..."}];case"year":return[{value:"YYYY",label:"2024 (YYYY)"},{value:"YY",label:"24 (YY)"},{value:"custom",label:"Custom Format..."}];default:return[{value:"MM-DD-YYYY",label:"01-15-2024 (MM-DD-YYYY)"},{value:"YYYY-MM-DD",label:"2024-01-15 (YYYY-MM-DD)"},{value:"MM/DD/YYYY",label:"01/15/2024 (MM/DD/YYYY)"},{value:"DD/MM/YYYY",label:"15/01/2024 (DD/MM/YYYY)"},{value:"MMMM DD, YYYY",label:"January 15, 2024 (MMMM DD, YYYY)"},{value:"MMM DD, YYYY",label:"Jan 15, 2024 (MMM DD, YYYY)"},{value:"DD MMM YYYY",label:"15 Jan 2024 (DD MMM YYYY)"},{value:"YYYY-MM",label:"2024-01 (YYYY-MM)"},{value:"MMMM YYYY",label:"January 2024 (MMMM YYYY)"},{value:"custom",label:"Custom Format..."}]}},ie=Z(z),de=n!=="pivotBy",ne=$&&n==="groupBy",me=!V&&$&&n==="groupBy",pe=V&&$&&n==="groupBy",Re=V&&n==="metrics"&&((gs=p.config)==null?void 0:gs.comparisonType)==="target",Le=n==="metrics",De=()=>e.jsx("div",{title:`${t.entityName}.${t.name}`,onPointerDown:Y=>{Y.stopPropagation()},className:"max-w-[270px] cursor-default overflow-hidden text-ellipsis whitespace-nowrap px-0.5 text-xs text-gray-500",children:`${t.entityName}.${t.name}`}),ve=()=>de?e.jsxs("div",{className:"space-y-1",children:[e.jsx(s.Label,{className:"text-xs font-medium text-muted-foreground",children:"Label"}),e.jsx(we,{value:t.label??"",onSave:ce,placeholder:"Display label...",type:"text"})]}):null,X=()=>ne?e.jsxs("div",{className:"space-y-1",children:[e.jsx(s.Label,{className:"text-xs font-medium text-muted-foreground",children:"Granularity"}),e.jsxs(s.Select,{value:z,onValueChange:re,children:[e.jsx(s.SelectTrigger,{className:"h-8 w-full text-xs",children:e.jsx(s.SelectValue,{placeholder:"Select granularity..."})}),e.jsx(s.SelectContent,{children:["day","week","month","quarter","year"].map(Y=>e.jsx(s.SelectItem,{className:"text-xs",value:Y,children:s.toTitleCase(Y)},Y))})]})]}):null,ge=()=>me?e.jsxs(e.Fragment,{children:[X(),e.jsxs("div",{className:"space-y-1",children:[e.jsx(s.Label,{className:"text-xs font-medium text-muted-foreground",children:"Date Format"}),e.jsxs(s.Select,{value:K?"custom":M,onValueChange:ae,children:[e.jsx(s.SelectTrigger,{className:"h-8 w-full text-xs",children:e.jsx(s.SelectValue,{placeholder:"Select date format..."})}),e.jsx(s.SelectContent,{children:ie.map(Y=>e.jsx(s.SelectItem,{className:"text-xs",value:Y.value,children:Y.label},Y.value))})]}),K&&e.jsxs("div",{className:"mt-2 space-y-1",children:[e.jsx(s.Input$1,{placeholder:"Enter custom format (e.g., YYYY-MM-DD HH:mm)",value:P,onChange:Y=>{Y.stopPropagation(),J(Y.target.value)},onClick:Y=>Y.stopPropagation(),className:"h-8 text-xs"}),e.jsx("div",{className:"text-xs text-muted-foreground",children:"Examples: YYYY-MM-DD, MM/DD/YY, DD-MMM-YYYY HH:mm"})]})]})]}):null,Be=()=>{var Y,he,xe,je,Te;return pe?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(s.Label,{className:"text-xs font-medium text-muted-foreground",children:"Comparison Type"}),e.jsxs(s.Select,{value:((Y=p.config)==null?void 0:Y.comparisonType)||"none",onValueChange:D,children:[e.jsx(s.SelectTrigger,{className:"h-8 w-full text-xs",children:e.jsx(s.SelectValue,{placeholder:"Select comparison type..."})}),e.jsxs(s.SelectContent,{children:[e.jsx(s.SelectItem,{value:"none",children:"No Comparison"}),e.jsx(s.SelectItem,{value:"previous_period",children:"Previous Period"}),e.jsx(s.SelectItem,{value:"same_period_last_year",children:"Same Period Last Year"}),e.jsx(s.SelectItem,{value:"target",children:"Target Value"})]})]})]}),e.jsx("div",{className:"space-y-1",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(s.Label,{className:"text-xs font-medium text-muted-foreground",children:"Show Trendline"}),e.jsx(s.SmallSwitch,{checked:((he=p.config)==null?void 0:he.showTrendline)||!1,onCheckedChange:w})]})}),((xe=p.config)==null?void 0:xe.showTrendline)&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(s.Label,{className:"text-xs font-medium text-muted-foreground",children:"Trendline Window"}),e.jsx(s.Input$1,{type:"number",min:"1",max:"365",value:((je=p.config)==null?void 0:je.trendlineWindow)||30,onChange:ze=>{const Ft=parseInt(ze.target.value)||30;j(Ft)},className:"h-8 text-xs",placeholder:"30"})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(s.Label,{className:"text-xs font-medium text-muted-foreground",children:"Trendline Granularity"}),e.jsxs(s.Select,{value:((Te=p.config)==null?void 0:Te.trendlineGranularity)||"day",onValueChange:N,children:[e.jsx(s.SelectTrigger,{className:"h-8 w-full text-xs",children:e.jsx(s.SelectValue,{placeholder:"Select granularity..."})}),e.jsxs(s.SelectContent,{children:[e.jsx(s.SelectItem,{value:"day",children:"Day"}),e.jsx(s.SelectItem,{value:"week",children:"Week"}),e.jsx(s.SelectItem,{value:"month",children:"Month"})]})]})]})]})]}):null},ke=()=>{var Y,he;return Re?e.jsxs("div",{className:"space-y-1",children:[e.jsx(s.Label,{className:"text-xs font-medium text-muted-foreground",children:"Target Value"}),e.jsx(we,{value:((Y=p.config)==null?void 0:Y.targetValue)!==void 0&&((he=p.config)==null?void 0:he.targetValue)!==null?String(p.config.targetValue):"",onSave:xe=>{!isNaN(Number(xe))&&xe!==null?b(Number(xe)):b(0)},placeholder:"Enter target value...",type:"text"})]}):null},Mt=()=>Le?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(s.Label,{className:"text-xs font-medium text-muted-foreground",children:"Aggregation"}),e.jsxs(s.Select,{value:t.aggregate,onValueChange:Y=>{f(a,Y)},children:[e.jsx(s.SelectTrigger,{className:"h-8 w-full text-xs",children:e.jsx(s.SelectValue,{placeholder:"Select function..."})}),e.jsxs(s.SelectContent,{children:[e.jsx(s.SelectItem,{className:"text-xs",value:"COUNT",children:"Count"}),e.jsx(s.SelectItem,{className:"text-xs",value:"DISTINCT",children:"Count Distinct"}),s.getDataType(t.dataType)==="number"&&e.jsxs(e.Fragment,{children:[e.jsx(s.SelectItem,{className:"text-xs",value:"SUM",children:"Sum"}),e.jsx(s.SelectItem,{className:"text-xs",value:"AVG",children:"Average"}),e.jsx(s.SelectItem,{className:"text-xs",value:"MIN",children:"Min"}),e.jsx(s.SelectItem,{className:"text-xs",value:"MAX",children:"Max"}),e.jsx(s.SelectItem,{className:"text-xs",value:"MEDIAN",children:"Median"})]})]})]})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(s.Label,{className:"text-xs font-medium text-muted-foreground",children:"Attribute Filters"}),(H==null?void 0:H.conditions)&&H.conditions.length>0&&e.jsx("div",{className:"mb-2 space-y-1",children:H.conditions.map(Y=>e.jsxs("div",{className:"flex cursor-pointer items-center gap-2 rounded bg-muted/50 p-2 text-xs transition-colors hover:bg-muted/70",onClick:()=>{A(Y),E(!0)},children:[e.jsxs("span",{className:"font-medium",children:[Y.field.label,":"]}),e.jsx(s.TooltipProvider,{children:e.jsxs(s.Tooltip,{children:[e.jsx(s.TooltipTrigger,{asChild:!0,children:e.jsx("span",{className:"cursor-help text-muted-foreground",children:Array.isArray(Y.value)?Y.value.length===1?String(Y.value[0]):Y.value.length<=2?Y.value.join(", "):`${Y.value.slice(0,2).join(", ")} +${Y.value.length-2}`:String(Y.value)})}),Array.isArray(Y.value)&&Y.value.length>1&&e.jsx(s.TooltipContent,{side:"top",className:"max-w-[300px]",children:e.jsxs("div",{className:"text-xs",children:[e.jsxs("div",{className:"mb-1 font-medium",children:["Selected values (",Y.value.length,"):"]}),e.jsx("div",{className:"max-h-[200px] overflow-y-auto",children:Y.value.map((he,xe)=>e.jsx("div",{children:String(he)},xe))})]})})]})}),e.jsx(s.Button,{variant:"ghost",size:"sm",className:"ml-auto h-4 w-4 p-0",onClick:he=>{var je;he.stopPropagation();const xe=H.conditions.filter(Te=>Te.id!==Y.id);if(xe.length>0){const Te={...H,conditions:xe};le(Te)}else if(q(void 0),n==="metrics"){const Te={...t,parameters:{...t.parameters,filters:void 0}},ze=[...((je=p.config)==null?void 0:je.metricColumns)||[]];ze[a]=Te,s.useEditorStore.getState().actions.updateCardConfig(p.id,{metricColumns:ze})}},children:e.jsx(s.X,{className:"h-3 w-3"})})]},Y.id))}),e.jsxs(s.Button,{variant:"outline",size:"sm",className:"h-8 w-full justify-start text-xs",onClick:()=>{A(null),E(!0)},children:[e.jsx(s.Filter,{className:"mr-2 h-3 w-3"}),"Add attribute filter"]})]}),e.jsx(Gr,{column:t}),o&&e.jsxs(e.Fragment,{children:[e.jsx(zr,{aliasTemplate:W,onAliasTemplateChange:G}),e.jsx(Ur,{valueAliases:te,onValueAliasesChange:se})]})]}):null,{columns:Rt=[]}=s.useColumns(),Lt=(H==null?void 0:H.conditions)&&H.conditions.length>0;return e.jsxs(e.Fragment,{children:[e.jsxs("div",{ref:u,style:ue,...i,...d,className:`group mx-auto flex w-full flex-col gap-2 rounded border border-border bg-background p-2 transition-all hover:shadow-sm dark:border-gray-800 ${h?"z-50 scale-95 opacity-50":"border-slate-200"} ${n==="filters"?"cursor-default":"cursor-move"}`,children:[e.jsxs("div",{className:"flex grow items-center gap-2",children:[e.jsx(xs,{dataType:Q}),e.jsx(us,{className:s.cn("w-[140px] flex-1 text-sm",Lt&&"w-[120px]"),children:s.getMetricDisplayLabel(t)}),n==="metrics"&&((js=H==null?void 0:H.conditions)==null?void 0:js.length)&&!R&&e.jsx(s.TooltipProvider,{children:e.jsxs(s.Tooltip,{children:[e.jsx(s.TooltipTrigger,{asChild:!0,children:e.jsxs("div",{className:"flex items-center gap-1 rounded bg-primary/10 px-1.5 py-0.5 text-xs",children:[e.jsx(s.Filter,{className:"h-3 w-3"}),e.jsx("span",{children:H.conditions.length})]})}),e.jsx(s.TooltipContent,{side:"top",children:e.jsx("div",{className:"text-xs",children:H.conditions.map(Y=>e.jsxs("div",{children:[Y.field.label,":"," ",Array.isArray(Y.value)?`${Y.value.length} values`:String(Y.value)]},Y.id))})})]})}),n!=="sortBy"&&e.jsx(s.Button,{variant:"ghost",size:"sm",className:"h-6 w-6 p-0",onClick:Y=>{Y.stopPropagation(),S(!R)},children:e.jsx(s.ChevronDown,{className:`h-3 w-3 transition-transform ${R?"rotate-180":""}`})}),n==="sortBy"&&e.jsx(s.Button,{variant:"ghost",size:"sm",className:"h-6 w-6 p-0",onClick:Y=>{Y.stopPropagation(),console.log("DraggableField - Current sortDirection:",r);const he=r==="asc"?"desc":"asc";console.log("DraggableField - New direction to set:",he),l(he)},children:r==="asc"?e.jsx(s.ArrowUp,{className:"h-3 w-3"}):e.jsx(s.ArrowDown,{className:"h-3 w-3"})}),e.jsx(s.Button,{variant:"ghost",size:"sm",className:"h-6 w-6 p-0",onClick:Y=>{Y.stopPropagation(),fe()},children:e.jsx(s.X,{className:"h-2.5 w-2.5"})})]}),R&&e.jsxs("div",{className:"space-y-3",children:[De(),ve(),c==="kpi"&&X(),ge(),Be(),ke(),Mt()]})]}),O&&e.jsx($r,{open:O,onOpenChange:Y=>{E(Y),Y||A(null)},availableFields:Rt,existingFilters:H,editingCondition:I,onSave:Y=>{var he;if(Y)le(Y);else if(q(void 0),n==="metrics"){const xe={...t,parameters:{...t.parameters,filters:void 0}},je=[...((he=p.config)==null?void 0:he.metricColumns)||[]];je[a]=xe,s.useEditorStore.getState().actions.updateCardConfig(p.id,{metricColumns:je})}A(null)}})]})}function Kr({concept:t}){const n=()=>{switch(t){case"groupBy":return e.jsxs("div",{className:"w-64 space-y-2",children:[e.jsx("h4",{className:"text-sm font-medium",children:"Rows = Group By"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Fields that define how your data is grouped into rows."}),e.jsxs("div",{className:"rounded-md border bg-white p-2 dark:border-muted dark:bg-muted",children:[e.jsxs("div",{className:"flex border-b pb-1 dark:border-border",children:[e.jsx("div",{className:"w-1/3 bg-blue-100 text-xs font-medium dark:bg-blue-200/20",children:"Product"}),e.jsx("div",{className:"w-1/3 text-center text-xs",children:"Sales"}),e.jsx("div",{className:"w-1/3 text-center text-xs",children:"Profit"})]}),e.jsxs("div",{className:"flex border-b dark:border-border",children:[e.jsx("div",{className:"w-1/3 bg-blue-200/50 text-xs font-medium dark:bg-blue-200/20",children:"Electronics"}),e.jsx("div",{className:"w-1/3 text-center text-xs",children:"$5,200"}),e.jsx("div",{className:"w-1/3 text-center text-xs",children:"$1,300"})]}),e.jsxs("div",{className:"flex border-b dark:border-border",children:[e.jsx("div",{className:"w-1/3 bg-blue-200/30 text-xs font-medium dark:bg-blue-300/20",children:"Clothing"}),e.jsx("div",{className:"w-1/3 text-center text-xs",children:"$3,100"}),e.jsx("div",{className:"w-1/3 text-center text-xs",children:"$620"})]}),e.jsxs("div",{className:"flex",children:[e.jsx("div",{className:"w-1/3 bg-blue-200/20 text-xs font-medium dark:bg-blue-200/20",children:"Food"}),e.jsx("div",{className:"w-1/3 text-center text-xs",children:"$2,400"}),e.jsx("div",{className:"w-1/3 text-center text-xs",children:"$480"})]})]})]});case"pivotBy":return e.jsxs("div",{className:"w-64 space-y-2",children:[e.jsx("h4",{className:"text-sm font-medium",children:"Columns = Pivot By"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Fields that split your data into multiple columns or series."}),e.jsxs("div",{className:"rounded-md border bg-white p-2 dark:border-muted dark:bg-muted",children:[e.jsxs("div",{className:"flex border-b pb-1 dark:border-border",children:[e.jsx("div",{className:"w-1/4 text-xs font-medium",children:"Region"}),e.jsx("div",{className:"w-1/4 rounded-t bg-purple-50 text-center text-xs dark:bg-purple-300/20",children:"North"}),e.jsx("div",{className:"w-1/4 rounded-t bg-purple-100 text-center text-xs dark:bg-purple-400/20",children:"South"}),e.jsx("div",{className:"w-1/4 rounded-t bg-purple-50 text-center text-xs dark:bg-purple-300/20",children:"East"})]}),e.jsxs("div",{className:"flex border-b py-1 dark:border-border",children:[e.jsx("div",{className:"w-1/4 text-xs font-medium",children:"Sales"}),e.jsx("div",{className:"w-1/4 bg-purple-50 text-center text-xs dark:bg-purple-300/20",children:"$2,300"}),e.jsx("div",{className:"w-1/4 bg-purple-100 text-center text-xs dark:bg-purple-400/20",children:"$1,800"}),e.jsx("div",{className:"w-1/4 bg-purple-50 text-center text-xs dark:bg-purple-300/20",children:"$3,400"})]}),e.jsxs("div",{className:"flex py-1",children:[e.jsx("div",{className:"w-1/4 text-xs font-medium",children:"Profit"}),e.jsx("div",{className:"w-1/4 rounded-b bg-purple-50 text-center text-xs dark:bg-purple-300/20",children:"$460"}),e.jsx("div",{className:"w-1/4 rounded-b bg-purple-100 text-center text-xs dark:bg-purple-400/20",children:"$360"}),e.jsx("div",{className:"w-1/4 rounded-b bg-purple-50 text-center text-xs dark:bg-purple-300/20",children:"$680"})]})]})]});case"metrics":return e.jsxs("div",{className:"w-64 space-y-2",children:[e.jsx("h4",{className:"text-sm font-medium",children:"Metrics = Values (Cells)"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Fields that represent the values shown in your visualization."}),e.jsxs("div",{className:"rounded-md border bg-white p-2 dark:border-muted dark:bg-muted",children:[e.jsxs("div",{className:"grid grid-cols-4 gap-1",children:[e.jsx("div",{className:"col-span-1"}),e.jsx("div",{className:"col-span-1 text-center text-xs font-medium",children:"Q1"}),e.jsx("div",{className:"col-span-1 text-center text-xs font-medium",children:"Q2"}),e.jsx("div",{className:"col-span-1 text-center text-xs font-medium",children:"Q3"})]}),e.jsxs("div",{className:"mt-1 grid grid-cols-4 gap-1",children:[e.jsx("div",{className:"text-xs font-medium",children:"Sales"}),e.jsx("div",{className:"rounded bg-blue-100 p-1 text-center text-xs dark:bg-blue-300/20",children:"$2,300"}),e.jsx("div",{className:"rounded bg-blue-200 p-1 text-center text-xs dark:bg-blue-400/20",children:"$3,100"}),e.jsx("div",{className:"rounded bg-blue-300 p-1 text-center text-xs dark:bg-blue-500/20",children:"$4,200"})]}),e.jsxs("div",{className:"mt-1 grid grid-cols-4 gap-1",children:[e.jsx("div",{className:"text-xs font-medium",children:"Profit"}),e.jsx("div",{className:"rounded bg-green-100 p-1 text-center text-xs dark:bg-green-300/20",children:"$460"}),e.jsx("div",{className:"rounded bg-green-200 p-1 text-center text-xs dark:bg-green-400/20",children:"$620"}),e.jsx("div",{className:"rounded bg-green-300 p-1 text-center text-xs dark:bg-green-500/20",children:"$840"})]})]})]});default:return null}};return e.jsx(s.TooltipProvider,{children:e.jsxs(s.Tooltip,{delayDuration:300,children:[e.jsx(s.TooltipTrigger,{asChild:!0,children:e.jsx(s.CircleHelp,{className:"size-4 text-muted-foreground hover:text-foreground"})}),e.jsx(s.TooltipContent,{side:"right",align:"start",className:"p-3",children:n()})]})})}function _e({zone:t,fields:n,label:a,placeholder:r,shouldShow:l,hasPivotColumns:o=!1}){const{isOver:c,setNodeRef:i}=s.useDroppable({id:t}),{updateSortByColumn:d}=s.useEditorActions(),u=s.useEditorStore(g=>g.card),m=s.useEditorStore(g=>g.card.type),x=n.length>0,h=(g,f)=>{var v;!((v=u.config)!=null&&v.sortByColumns)||u.config.sortByColumns.findIndex(C=>C.id===g)===-1||d(u.id,g,{direction:f})};if(t==="sortBy"&&l===!1)return null;const p=t!=="sortBy"&&m!=="kpi";return e.jsxs("div",{className:"mb-4 w-full",children:[e.jsxs("div",{className:"mb-2 flex items-center gap-2",children:[e.jsx(s.Label,{className:s.cn("block text-sm font-medium",{}),children:a}),p&&e.jsx(Kr,{concept:t})]}),e.jsx("div",{ref:i,className:`rounded-lg border-2 border-dashed p-1 transition-all ${c?"border-blue-500 bg-blue-50 dark:bg-blue-950":x?"border-blue-200 bg-blue-50/30 dark:border-blue-800 dark:bg-blue-950/30":"min-h-[60px] border-muted-foreground/20 bg-background"}`,children:n.length===0?e.jsx("div",{className:"flex min-h-[40px] items-center justify-center text-sm text-gray-400",children:r}):e.jsx(s.SortableContext,{items:n.map(g=>g.id),strategy:s.verticalListSortingStrategy,children:e.jsx("div",{className:"flex flex-wrap gap-1",children:n.map((g,f)=>{const v=g.direction;return e.jsx("div",{className:"flex w-full items-center gap-2",children:e.jsx("div",{className:"flex-1",children:e.jsx(qr,{field:g,zone:t,index:f,sortDirection:v,onSortDirectionChange:C=>h(g.id,C),hasPivotColumns:o,cardType:m})})},g.id)})})})})]})}const Ls=[{value:"green",color:"#16a34a",label:"Green"},{value:"red",color:"#dc2626",label:"Red"},{value:"neutral",color:"#6b7280",label:"Neutral"}],Qr=["#16a34a","#dc2626","#6b7280","#2563eb","#ca8a04","#7c3aed","#0891b2","#e11d48","#ea580c"];function es({value:t,onChange:n,label:a}){const[r,l]=T.useState(!1),[o,c]=T.useState(!1),i=()=>{const d=Ls.find(u=>u.value===t);return d?d.color:t.startsWith("#")?t:Ls[2].color};return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(s.Popover,{open:r,onOpenChange:l,children:[e.jsx(s.PopoverTrigger,{asChild:!0,children:e.jsx("button",{className:"size-5 rounded border-2 border-input shadow-sm transition-all hover:scale-110 hover:border-gray-400",style:{backgroundColor:i()},"aria-label":`Change color for ${a}`})}),e.jsx(s.PopoverContent,{align:"start",className:"w-auto p-2",children:e.jsxs("div",{className:"space-y-2",children:[e.jsx("div",{className:"grid grid-cols-3 items-center justify-items-center gap-1",children:Qr.map(d=>e.jsx("button",{className:s.cn("h-5 w-5 rounded border-2 transition-all",i()===d?"border-gray-900":"border-transparent"),style:{backgroundColor:d},onClick:()=>{n(d),l(!1)},children:e.jsx("span",{className:"sr-only",children:d})},d))}),e.jsx("button",{className:"w-full rounded border border-input px-2 py-1 text-xs hover:bg-muted",onClick:()=>{c(!0),l(!1)},children:"Custom color..."})]})})]}),e.jsx("span",{className:"text-xs text-muted-foreground",children:a})]}),o&&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:()=>c(!1)}),e.jsx("div",{className:"relative rounded-lg bg-white shadow-lg",children:e.jsx(Ct,{color:i(),onColorChange:d=>{n(d),c(!1)},onClose:()=>c(!1)})})]})]})}const $e={difference:{label:"Difference",description:"Shows the exact difference between two values.",formula:"Primary - Secondary",example:"Sales increased by $5,000 compared to last year."},change:{label:"Change",description:"Shows the percentage increase or decrease between two values.",formula:"(Primary - Secondary) / Secondary × 100%",example:"Year-over-year sales change of 25%."},change_difference:{label:"Change (difference)",description:"Shows both the percentage change and the exact difference between two values.",formula:`% Change: (Primary - Secondary) / Secondary × 100%
|
|
280
280
|
Difference: Primary - Secondary`,example:"Sales grew by 25% ($5,000) compared to last year."},ratio:{label:"Ratio",description:"Shows how much of one value is covered by another — useful for quotas and benchmarks.",formula:"Primary / Secondary × 100%",example:"You've achieved 80% of your sales quota."}};function Hr(){var i,d,u,m,x,h,p,g,f,y;const t=s.useEditorStore(v=>v.card),{setCardPreferences:n}=s.useEditorActions(),a=((i=t.config)==null?void 0:i.metricColumns)||[],r=((d=t.config)==null?void 0:d.groupByColumns)||[];if(!(t.type==="kpi"&&(a.length>=2&&r.length===0||a.length>=1&&r.length>0)))return null;const o=((m=(u=t.preferences)==null?void 0:u.kpiVisualOptions)==null?void 0:m.metricComparison)||{},c=v=>{var F;const C={...t.preferences,kpiVisualOptions:{...(F=t.preferences)==null?void 0:F.kpiVisualOptions,metricComparison:{...o,...v}}};n(C)};return e.jsxs(s.AccordionItem,{value:"comparison",className:"border-none",children:[e.jsx(s.AccordionTrigger,{className:"flex items-center gap-2 py-2 text-sm hover:no-underline",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Wt,{className:"h-4 w-4"}),e.jsx("span",{children:"Comparison"})]})}),e.jsxs(s.AccordionContent,{className:"space-y-4 pb-4 pt-2",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(s.Label,{htmlFor:"enable-comparison",className:"text-xs",children:"Enable Metric Comparison"}),e.jsx(s.SmallSwitch,{id:"enable-comparison",checked:o.enabled||!1,onCheckedChange:v=>c({enabled:v,...v&&!o.calculationType?{calculationType:"difference"}:{}})})]}),o.enabled&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(s.Label,{htmlFor:"calculation-type",className:"text-xs font-medium uppercase text-muted-foreground",children:"Calculated as"}),e.jsxs(s.Select,{value:o.calculationType||"difference",onValueChange:v=>c({calculationType:v}),children:[e.jsx(s.SelectTrigger,{id:"calculation-type",className:"h-7 text-xs",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{children:Object.entries($e).map(([v,C])=>e.jsx(s.SelectItem,{value:v,className:"text-xs",children:C.label},v))})]}),(()=>{var C,F,k;const v=o.calculationType||"difference";return e.jsxs("div",{className:"space-y-2 rounded-md bg-muted/50 p-2 text-xs",children:[e.jsx("p",{className:"text-muted-foreground",children:(C=$e[v])==null?void 0:C.description}),e.jsxs("div",{className:"text-muted-foreground",children:[e.jsx("span",{className:"font-medium",children:"Formula:"})," ",e.jsx("code",{className:"rounded bg-background px-1 py-0.5 text-[10px]",children:(F=$e[v])==null?void 0:F.formula})]}),e.jsxs("div",{className:"border-t pt-1 italic text-muted-foreground",children:[e.jsx("span",{className:"font-medium",children:"Example:"})," ",(k=$e[v])==null?void 0:k.example]})]})})()]}),e.jsx(ms,{formatOptions:o.formatOptions||{},onFormatOptionsChange:v=>c({formatOptions:v}),showTitle:!0,title:"COMPARISON FORMAT"}),e.jsxs("div",{className:"space-y-3 border-t pt-3",children:[e.jsx(s.Label,{className:"text-xs font-medium uppercase text-muted-foreground",children:"Indicator"}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(s.Label,{className:"text-xs text-muted-foreground",children:"Position"}),e.jsxs(s.Select,{value:o.position||"left",onValueChange:v=>c({position:v}),children:[e.jsx(s.SelectTrigger,{className:"h-7 w-20 text-xs",children:e.jsx(s.SelectValue,{})}),e.jsxs(s.SelectContent,{children:[e.jsx(s.SelectItem,{value:"top",className:"text-xs",children:"Top"}),e.jsx(s.SelectItem,{value:"left",className:"text-xs",children:"Left"}),e.jsx(s.SelectItem,{value:"right",className:"text-xs",children:"Right"})]})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(s.Checkbox,{id:"show-arrow",checked:o.showArrow!==!1,onCheckedChange:v=>c({showArrow:v})}),e.jsx(s.Label,{htmlFor:"show-arrow",className:"cursor-pointer text-xs text-muted-foreground",children:"Arrow"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(s.Checkbox,{id:"show-color",checked:o.showColor!==!1,onCheckedChange:v=>c({showColor:v})}),e.jsx(s.Label,{htmlFor:"show-color",className:"cursor-pointer text-xs text-muted-foreground",children:"Color"})]}),o.showColor!==!1&&e.jsxs("div",{className:"space-y-2 border-l-2 border-muted pl-3",children:[e.jsx(es,{value:((x=o.colorConfig)==null?void 0:x.increase)||"green",onChange:v=>c({colorConfig:{...o.colorConfig,increase:v}}),label:"Primary > Secondary"}),e.jsx(es,{value:((h=o.colorConfig)==null?void 0:h.decrease)||"red",onChange:v=>c({colorConfig:{...o.colorConfig,decrease:v}}),label:"Primary < Secondary"}),e.jsx(es,{value:((p=o.colorConfig)==null?void 0:p.noChange)||"neutral",onChange:v=>c({colorConfig:{...o.colorConfig,noChange:v}}),label:"Primary = Secondary"})]})]}),e.jsxs("div",{className:"space-y-3 border-t pt-3",children:[e.jsx(s.Label,{className:"text-xs font-medium uppercase text-muted-foreground",children:"Label"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(s.Checkbox,{id:"conditional-label",checked:o.conditionalLabel||!1,onCheckedChange:v=>c({conditionalLabel:v})}),e.jsx(s.Label,{htmlFor:"conditional-label",className:"cursor-pointer text-xs text-muted-foreground",children:"Conditional"})]}),o.conditionalLabel?e.jsxs("div",{className:"space-y-3 border-l-2 border-muted pl-3",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsxs(s.Label,{htmlFor:"label-increase",className:"text-xs text-muted-foreground",children:["Primary ",">"," Secondary"]}),e.jsx(s.Input,{id:"label-increase",type:"text",value:((g=o.conditionalLabels)==null?void 0:g.increase)??"Increase",onChange:v=>c({conditionalLabels:{...o.conditionalLabels,increase:v.target.value}}),placeholder:"Increase",className:"h-7 text-xs"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs(s.Label,{htmlFor:"label-decrease",className:"text-xs text-muted-foreground",children:["Primary ","<"," Secondary"]}),e.jsx(s.Input,{id:"label-decrease",type:"text",value:((f=o.conditionalLabels)==null?void 0:f.decrease)??"Decrease",onChange:v=>c({conditionalLabels:{...o.conditionalLabels,decrease:v.target.value}}),placeholder:"Decrease",className:"h-7 text-xs"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(s.Label,{htmlFor:"label-no-change",className:"text-xs text-muted-foreground",children:"Primary = Secondary"}),e.jsx(s.Input,{id:"label-no-change",type:"text",value:((y=o.conditionalLabels)==null?void 0:y.noChange)??"No change",onChange:v=>c({conditionalLabels:{...o.conditionalLabels,noChange:v.target.value}}),placeholder:"No change",className:"h-7 text-xs"})]})]}):e.jsxs("div",{className:"space-y-2",children:[e.jsx(s.Label,{htmlFor:"label-name",className:"text-xs text-muted-foreground",children:"Name"}),e.jsx(s.Input,{id:"label-name",type:"text",value:o.labelName??"",onChange:v=>c({labelName:v.target.value}),placeholder:"e.g. Versus, Compared to",className:"h-7 text-xs"})]})]})]})]})]})}function Wr(){var l,o;const t=s.useEditorStore(c=>c.card),{setCardPreferences:n}=s.useEditorActions();if(t.type!=="kpi")return null;const a=((o=(l=t.preferences)==null?void 0:l.kpiVisualOptions)==null?void 0:o.formatOptions)||{},r=c=>{var d;const i={...t.preferences,kpiVisualOptions:{...(d=t.preferences)==null?void 0:d.kpiVisualOptions,formatOptions:c}};n(i)};return e.jsxs(s.AccordionItem,{value:"kpi-format",className:"border-none",children:[e.jsx(s.AccordionTrigger,{className:"flex items-center gap-2 py-2 text-sm hover:no-underline",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(ns,{className:"h-4 w-4"}),e.jsx("span",{children:"Number Format"})]})}),e.jsx(s.AccordionContent,{className:"space-y-4 pb-4 pt-2",children:e.jsx(ms,{formatOptions:a,onFormatOptionsChange:r,showTitle:!1})})]})}function Jr({groupByFields:t,pivotByFields:n,metricsFields:a,sortByFields:r}){const l=s.useEditorStore(g=>{var f;return((f=g.card.customCardPreferences)==null?void 0:f.url)&&g.card.type==="custom"}),o=s.useEditorStore(g=>g.card),c=o==null?void 0:o.type,i=t.length>0||a.length>0,d=c!=="kpi",u=c!=="kpi"&&i,m=["pie","doughnut","polar","funnel","aggregateTable"].includes(c),x=d&&!m,h=()=>c==="kpi"?{label:"Trend By",placeholder:"Drop fields to trend data"}:{label:"Rows",placeholder:"Drop fields to group data"},p=()=>c==="kpi"?{label:"Metric",placeholder:"Drop field for KPI"}:{label:"Metrics",placeholder:"Drop fields to measure"};return e.jsxs(s.Accordion,{type:"single",collapsible:!0,defaultValue:"fields",className:"w-full",children:[e.jsxs(s.AccordionItem,{value:"fields",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(s.List,{className:"h-4 w-4 text-muted-foreground"}),e.jsx("span",{children:"FIELDS"})]})}),e.jsxs(s.AccordionContent,{className:"space-y-4 pt-2",children:[e.jsx(_e,{zone:"groupBy",fields:t,label:h().label,placeholder:h().placeholder}),x&&e.jsx(_e,{zone:"pivotBy",fields:n,label:"Columns",placeholder:"Drop fields to pivot data"}),e.jsx(_e,{zone:"metrics",fields:a,label:p().label,placeholder:p().placeholder,hasPivotColumns:n.length>0}),u&&e.jsx(_e,{zone:"sortBy",fields:r,label:"Sort By",placeholder:"Drop fields from Rows or Metrics"})]})]}),!l&&e.jsxs(s.AccordionItem,{value:"configuration",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(s.Settings2,{className:"h-4 w-4 text-muted-foreground"}),e.jsx("span",{children:"CONFIGURATION"})]})}),e.jsx(s.AccordionContent,{className:"rounded-md border border-border bg-muted/50 px-3 py-0",children:e.jsxs(s.Accordion,{type:"single",collapsible:!0,className:"w-full",children:[e.jsx(Wr,{}),e.jsx(Hr,{}),e.jsx(St,{}),e.jsx(wt,{}),e.jsx(Dt,{}),e.jsx(Tt,{})]})})]})]})}function Xr({onEditJoins:t}){const n=s.useEditorStore(m=>m.card),{autoJoinMetadata:a}=s.useDashboardCardQuery(n),[r,l]=T.useState(!0);if(!(a!=null&&a.autoResolved))return null;const{resolvedJoinPlan:o,relationshipsUsed:c}=a,i=(o==null?void 0:o.joins)||[];if(i.length===0)return null;const d=m=>!m||m.length===0?"No conditions":m.map(x=>{var f,y,v,C;const h=`${(f=x.source)==null?void 0:f.entityName}.${(y=x.source)==null?void 0:y.name}`,p=`${(v=x.target)==null?void 0:v.entityName}.${(C=x.target)==null?void 0:C.name}`,g=x.operator||"=";return`${h} ${g} ${p}`}).join(" AND "),u=m=>!m.joinKeyGroups||m.joinKeyGroups.length===0?"No conditions defined":m.joinKeyGroups.length===1?d(m.joinKeyGroups[0].keys):m.joinKeyGroups.map((x,h)=>({id:h,operator:x.operator,condition:d(x.keys)}));return e.jsx(s.Card,{className:"border-blue-500/30 bg-blue-50/30 dark:bg-blue-950/20",children:e.jsxs("div",{className:s.cn("p-3",{"space-y-3":r}),children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("button",{onClick:()=>l(!r),className:"flex items-center gap-2 transition-opacity hover:opacity-70",children:[e.jsx(ja,{className:"size-4 text-blue-600 dark:text-blue-400"}),e.jsx("h3",{className:"text-sm font-medium text-blue-900 dark:text-blue-100",children:"Auto-Resolved Joins"}),e.jsx(s.Badge,{variant:"secondary",className:"bg-blue-100 text-xs text-blue-700 dark:bg-blue-900 dark:text-blue-300",children:i.length})]}),t&&e.jsx(s.Button,{variant:"ghost",size:"sm",onClick:t,className:"h-7 gap-1 p-2 text-xs text-blue-700 hover:text-blue-900 dark:text-blue-300 dark:hover:text-blue-100",children:e.jsx(s.SquarePen,{className:"size-3.5"})})]}),r&&e.jsx(e.Fragment,{children:e.jsx("div",{className:"space-y-2",children:i.map((m,x)=>{const h=u(m),p=Array.isArray(h);return e.jsxs("div",{className:"rounded-md border border-blue-200/50 bg-background p-2 dark:border-blue-800/50",children:[e.jsxs("div",{className:"mb-1 flex items-center justify-between gap-2",children:[e.jsxs("div",{className:"flex items-center gap-2 text-xs",children:[e.jsx("span",{className:"font-medium text-foreground",children:m.source.name}),e.jsx(s.ArrowRight,{className:"size-3 text-muted-foreground"}),e.jsx("span",{className:"font-medium text-foreground",children:m.target.name})]}),e.jsx(s.Badge,{variant:"outline",className:"border-green-500/40 bg-green-50/30 text-xs text-green-700 dark:bg-green-950/30 dark:text-green-300",children:m.joinType})]}),e.jsx("div",{className:"mt-1 space-y-1",children:p?h.map(g=>e.jsxs("div",{className:"rounded bg-muted/30 px-2 py-1",children:[e.jsx("code",{className:"text-xs text-muted-foreground",children:g.condition}),g.operator&&e.jsxs("span",{className:"ml-2 text-xs text-muted-foreground",children:["(",g.operator,")"]})]},g.id)):e.jsx("div",{className:"rounded bg-muted/30 px-2 py-1",children:e.jsx("code",{className:"text-xs text-muted-foreground",children:h})})})]},m.id||x)})})})]})})}const Fs={getItem(t){if(typeof window>"u")return null;try{return localStorage.getItem(t)}catch(n){return console.warn(`Failed to read from localStorage (${t}):`,n),null}},setItem(t,n){if(!(typeof window>"u"))try{localStorage.setItem(t,n)}catch(a){console.warn(`Failed to write to localStorage (${t}):`,a)}}};function Zr({selectedChart:t,onChartChange:n,groupByFields:a,pivotByFields:r,metricsFields:l,sortByFields:o}){var w,j,N,b,R,S,O,E,I;const[c,i]=T.useState(()=>Fs.getItem("chart-selector-expanded")==="true"),[d,u]=T.useState(!1),m=s.useEditorStore(A=>A.card),x=s.useEditorStore(A=>A.actions.updateCardConfig),h=a.length>0||r.length>0||l.length>0,{data:p,autoJoinMetadata:g}=s.useDashboardCardQuery(m);console.log("🔄 [Chart Config] Query Response:",{hasData:!!p,hasAutoJoinMetadata:!!g,autoResolved:g==null?void 0:g.autoResolved,backendBaseEntity:(j=(w=g==null?void 0:g.resolvedJoinPlan)==null?void 0:w.baseEntity)==null?void 0:j.name,cardConfigBaseEntity:(R=(b=(N=m==null?void 0:m.config)==null?void 0:N.joinPlan)==null?void 0:b.baseEntity)==null?void 0:R.name,joinsCount:(O=(S=g==null?void 0:g.resolvedJoinPlan)==null?void 0:S.joins)==null?void 0:O.length});const f=((E=m==null?void 0:m.config)==null?void 0:E.joinPlan)||(g!=null&&g.autoResolved?g.resolvedJoinPlan:{baseEntity:{type:"table",name:"",database:"",schema:"",connectionId:"",connectionType:"none",dialect:"none"},joins:[]}),y=((I=m==null?void 0:m.dataSource)==null?void 0:I.selectedEntities)||[],v=A=>{x(m.id,{...m==null?void 0:m.config,joinPlan:A}),u(!1)},C=()=>{x(m.id,{...m==null?void 0:m.config,joinPlan:void 0}),u(!1)},F=()=>{u(!1)},k=()=>{u(!0)};T.useEffect(()=>{Fs.setItem("chart-selector-expanded",String(c))},[c]);const D=()=>{i(A=>!A)};return e.jsxs("div",{"data-content":"Chart Configuration Panel",className:"flex w-[350px] flex-col border-x border-border",children:[e.jsxs("div",{className:s.cn("px-6 pt-4",{"space-y-4":c}),children:[e.jsx("div",{className:s.cn("overflow-hidden transition-all duration-300 ease-in-out",c?"max-h-[200px] opacity-100":"max-h-0 opacity-0"),children:c&&e.jsx(Or,{selectedChart:t,onChartChange:n})}),e.jsxs("div",{"data-content":"Chart Quick Selector",className:"flex items-center justify-center gap-1",children:[e.jsx(Vr,{selectedChart:t,onChartChange:n}),e.jsxs(s.Tooltip,{children:[e.jsx(s.TooltipTrigger,{asChild:!0,children:e.jsx(s.Button,{variant:"ghost",size:"sm",onClick:D,className:"h-8 w-8 p-0","aria-label":c?"Hide all charts":"Show all charts",children:c?e.jsx(s.ChevronUp,{className:"h-4 w-4"}):e.jsx(s.ChevronDown,{className:"h-4 w-4"})})}),e.jsx(s.TooltipContent,{side:"bottom",children:e.jsx("p",{children:c?"Hide dropdown":"Show all charts"})})]})]})]}),e.jsx("div",{className:s.cn("flex justify-end gap-2 px-6 py-6"),children:e.jsx("div",{className:s.cn("invisible flex gap-2",{visible:h||p}),children:e.jsx(os,{})})}),e.jsxs(s.ScrollArea,{className:"w-full flex-1 basis-0 px-6 pb-6",children:[e.jsxs("div",{className:"space-y-4",children:[e.jsx(Xr,{onEditJoins:k}),e.jsx(Jr,{groupByFields:a,pivotByFields:r,metricsFields:l,sortByFields:o})]}),e.jsx(s.ScrollBar,{orientation:"horizontal"})]}),e.jsx(as,{open:d,onOpenChange:u,joinPlan:f,availableDataSources:y,onSave:v,onCancel:F,onRemove:C,children:e.jsx("div",{})})]})}function el({initialFilters:t,availableFields:n}={}){const[a,r]=T.useState(t||{id:`group-${Date.now()}`,logicalOperator:"AND",negate:!1,conditions:[],groups:[]});s.useEditorStore(D=>D.card.dataSource);const{columns:l,isLoading:o}=s.useColumns(),i=n||l||[],d={id:"default",qualifiedFieldName:"default",name:"default",dataType:"string",label:"Default",entityId:"default",entityName:"Default",entityType:"table"},u=D=>{const w=j=>{if(j.id===D){const N=i[0]||d,b=s.getDataType(N.dataType)==="date";return{...j,conditions:[...j.conditions,{id:`condition-${Date.now()}`,field:N,operator:b?"between":"=",value:b?[]:""}]}}return{...j,groups:j.groups.map(w)}};r(w(a))},m=D=>{const w=j=>{if(j.id===D){const N=i[0]||d,b=s.getDataType(N.dataType)==="date";return{...j,groups:[...j.groups,{id:`group-${Date.now()}`,logicalOperator:"AND",negate:!1,conditions:[{id:`condition-${Date.now()}`,field:N,operator:b?"between":"=",value:b?[]:""}],groups:[]}]}}return{...j,groups:j.groups.map(w)}};r(w(a))},x=(D,w)=>{const j=N=>N.id===D?{...N,conditions:N.conditions.filter(b=>b.id!==w)}:{...N,groups:N.groups.map(j)};r(j(a))},h=(D,w)=>{const j=N=>N.id===D?{...N,groups:N.groups.filter(b=>b.id!==w)}:{...N,groups:N.groups.map(j)};r(j(a))},p=(D,w,j,N)=>{if(j==="field")throw new Error("Use a dedicated method to update the field property with a Field object");const b=R=>R.id===D?{...R,conditions:R.conditions.map(S=>S.id===w?{...S,[j]:N}:S)}:{...R,groups:R.groups.map(b)};r(b(a))},g=(D,w,j)=>{const N=b=>b.id===D?{...b,conditions:b.conditions.map(R=>R.id===w?{...R,...j}:R)}:{...b,groups:b.groups.map(N)};r(N(a))},f=(D,w)=>{const j=N=>N.id===D?{...N,logicalOperator:w}:{...N,groups:N.groups.map(j)};r(j(a))},y=(D,w)=>{const j=N=>N.id===D?{...N,negate:w}:{...N,groups:N.groups.map(j)};r(j(a))},v=(D,w,j)=>{const N=b=>b.id===D?{...b,conditions:s.arrayMove(b.conditions,w,j)}:{...b,groups:b.groups.map(N)};r(N(a))},C=(D,w,j)=>{const N=b=>b.id===D?{...b,groups:s.arrayMove(b.groups,w,j)}:{...b,groups:b.groups.map(N)};r(N(a))},F=D=>{if(!D||D.conditions.length===0&&D.groups.length===0)return"-- No filters defined";const w=N=>{let b="";typeof N.field=="object"?b=N.field.entityName?`${N.field.entityName}.${N.field.name}`:N.field.name:b=String(N.field);const R=N.operator;let S=N.value;if(N.field.dataType==="string"&&!["in","not in"].includes(N.operator))typeof S=="string"?S=`'${S}'`:Array.isArray(S)&&(S=`'${S.join(", ")}'`);else if(N.field.dataType==="date"||N.field.dataType==="datetime"||N.field.dataType==="timestamp")if(N.operator==="between"&&Array.isArray(S)&&S.length===2){const O=S[0]?`'${S[0]}'`:"NULL",E=S[1]?`'${S[1]}'`:"NULL";return`${b} BETWEEN ${O} AND ${E}`}else if((N.operator==="in"||N.operator==="not in")&&Array.isArray(S)){const O=S.map(E=>E?`'${E}'`:"NULL").join(", ");return`${b} ${R} (${O})`}else typeof S=="string"||S instanceof Date?S=`'${S}'`:Array.isArray(S)&&S.length>0&&(S=`'${S[0]}'`);else if(["in","not in"].includes(N.operator)){let O=[];Array.isArray(S)?O=S.map(E=>typeof E=="string"?`'${E}'`:String(E)):typeof S=="string"?O=S.split(",").map(E=>{const I=E.trim();return N.field.dataType==="string"?`'${I}'`:I}):typeof S=="number"&&(O=[String(S)]),S=`(${O.join(", ")})`}switch(R){case"contains":return typeof S=="string"?`${b} LIKE '%${S.replace(/'/g,"")}'`:`${b} LIKE '%${String(S)}'`;case"startsWith":return typeof S=="string"?`${b} LIKE '${S.replace(/'/g,"")}%'`:`${b} LIKE '${String(S)}%'`;case"endsWith":return typeof S=="string"?`${b} LIKE '%${S.replace(/'/g,"")}'`:`${b} LIKE '%${String(S)}'`;case"isNull":return`${b} IS NULL`;case"isNotNull":return`${b} IS NOT NULL`;default:return`${b} ${R} ${S}`}},j=N=>{const b=N.conditions.map(w),R=N.groups.map(I=>j(I)),S=[...b,...R].filter(Boolean);if(S.length===0)return"";const O=S.join(` ${N.logicalOperator} `),E=S.length>1?`(${O})`:O;return N.negate?`NOT ${E}`:E};return j(D)},k=a.conditions.length>0||a.groups.length>0;return{currentFilters:a,setCurrentFilters:r,availableFields:i,isLoading:o,addCondition:u,addGroup:m,removeCondition:x,removeGroup:h,updateCondition:p,updateConditionFields:g,updateGroupOperator:f,updateGroupNegate:y,reorderConditions:v,reorderGroups:C,generateSQLPreview:F,hasAnyFilters:k}}function sl({children:t,className:n,delayDuration:a}){return e.jsx(s.TooltipProvider,{children:e.jsxs(s.Tooltip,{delayDuration:a,children:[e.jsx(s.TooltipTrigger,{asChild:!0,children:e.jsx("div",{className:s.cn("w-[200px] overflow-hidden text-ellipsis whitespace-nowrap text-sm",n),children:t})}),e.jsx(s.PortalTooltipContent,{children:t})]})})}const tl=t=>{switch(t){case"table":return e.jsx(s.Table,{className:"h-3 w-3"});case"view":return e.jsx(s.Eye,{className:"h-3 w-3"});case"dataset":return e.jsx(s.ChartColumn,{className:"h-3 w-3"});case"file":return e.jsx(s.File,{className:"h-3 w-3"});default:return e.jsx(s.Table,{className:"h-3 w-3"})}},al=t=>{if(t.qualifiedEntityName){const n=t.qualifiedEntityName.split(".");return n.length>1?n[0]:"default"}return"default"};function nl({value:t,onValueChange:n,availableFields:a,placeholder:r="Select field",className:l="w-64"}){const[o,c]=T.useState(!1),i=T.useMemo(()=>{const d={};return a.forEach(u=>{const m=al(u);d[m]||(d[m]={}),d[m][u.entityId]||(d[m][u.entityId]=[]),d[m][u.entityId].push(u)}),d},[a]);return e.jsxs(s.Popover,{modal:!0,open:o,onOpenChange:c,children:[e.jsx(s.PopoverTrigger,{asChild:!0,children:e.jsxs(s.Button,{variant:"outline",role:"combobox","aria-expanded":o,className:s.cn("justify-between",!t&&"text-muted-foreground",l),children:[t?e.jsx("div",{className:"flex items-center gap-2",children:e.jsxs(sl,{children:[t.entityName,".",t.name]})}):r,e.jsx(s.ChevronsUpDown,{className:"ml-2 h-4 w-4 shrink-0 opacity-50"})]})}),e.jsx(s.PopoverContent,{className:"z-50 w-80 p-0",align:"start",children:e.jsxs(s.Command,{children:[e.jsx(s.CommandInput,{placeholder:"Search fields...",className:"h-9"}),e.jsx(s.CommandEmpty,{children:"No fields found."}),e.jsx(s.CommandList,{className:"max-h-80",children:Object.entries(i).map(([d,u])=>e.jsx(s.CommandGroup,{heading:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(s.Database,{className:"h-3 w-3"}),d]}),children:Object.entries(u).map(([m,x])=>e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2 bg-gray-50/50 px-2 py-1 text-xs font-medium text-gray-600",children:[tl(x[0].entityType),e.jsx("span",{children:x[0].entityName})]}),x.map((h,p)=>e.jsxs(s.CommandItem,{value:h.id,onSelect:()=>{n(h),c(!1)},className:"overflow-x-auto",children:[e.jsx(s.Check,{className:s.cn("mr-2 h-4 w-4",(t==null?void 0:t.id)===h.id?"opacity-100":"opacity-0")}),e.jsxs("div",{className:"flex min-w-0 flex-1 flex-col",children:[e.jsx("div",{className:"flex items-center gap-2",children:e.jsx("span",{className:"",children:h.name})}),e.jsx("div",{className:"flex items-center gap-2 text-xs text-gray-500",children:h.description&&e.jsx("span",{children:h.description})})]})]},h.id+p))]},`${d}-${m}`))},d))})]})})]})}function ps(t){var f;const n=s.useEditorStore(y=>y.card),{authToken:a,tokenProps:r}=s.useSemaphorContext(),l=s.useEditorStore(y=>y.card.config),o=l==null?void 0:l.joinPlan,c={...t,alias:t.name,label:"value",role:"groupby"},i={...t,role:"metric",label:"count",alias:"count",aggregate:"COUNT"},d={...c,role:"sortby",direction:"asc"},u={joinPlan:o,groupByColumns:[c],metricColumns:[i],sortByColumns:[d]},m=((f=n.dataSource)==null?void 0:f.connectionId)||n.connectionId,{data:x,isPending:h,error:p}=s.useQuery({queryKey:["filterValues",t.entityId,t.name,t.qualifiedEntityName],queryFn:async()=>{try{return await s.postRequestRegular(`${r.apiServiceUrl}/v1/query`,(a==null?void 0:a.accessToken)||"",{connection_id:m,cardConfig:u,cardDataSource:n.dataSource})}catch(y){console.log(t),console.error("error",y)}},enabled:!!m,refetchOnMount:!0,refetchOnWindowFocus:!1});return{filterValues:((x==null?void 0:x.records)||[]).map(y=>({label:y.value||"BLANK",value:y.value||"BLANK",count:(y==null?void 0:y.count)||0})),isPending:h,error:p}}function rl({field:t,selected:n,onChange:a,placeholder:r="Select items...",className:l}){const[o,c]=ss.useState(!1),{filterValues:i}=ps(t),d=m=>{a(n.filter(x=>x!==m))},u=m=>{n.includes(m)?a(n.filter(x=>x!==m)):a([...n,m])};return e.jsx("div",{className:s.cn("w-full",l),children:e.jsxs(s.Popover,{open:o,onOpenChange:c,modal:!0,children:[e.jsx(s.PopoverTrigger,{asChild:!0,children:e.jsxs(s.Button,{variant:"outline",role:"combobox","aria-expanded":o,className:"h-auto min-h-10 w-full justify-between p-2",children:[e.jsx("div",{className:"flex flex-1 flex-wrap gap-1",children:n.length>0?n.map(m=>{const x=i.find(h=>h.value===m);return e.jsxs(s.Badge,{variant:"secondary",className:"text-xs",children:[x==null?void 0:x.label,e.jsx("div",{className:"ml-1 rounded-full outline-none ring-offset-background focus:ring-2 focus:ring-ring focus:ring-offset-2",onKeyDown:h=>{h.key==="Enter"&&d(m)},onMouseDown:h=>{h.preventDefault(),h.stopPropagation()},onClick:h=>{h.stopPropagation(),d(m)},children:e.jsx(s.X,{className:"h-3 w-3 text-muted-foreground hover:text-foreground"})})]},m)}):e.jsx("span",{className:"text-muted-foreground",children:r})}),e.jsx(s.ChevronDown,{className:"ml-2 h-4 w-4 shrink-0 opacity-50"})]})}),e.jsx(s.PopoverContent,{className:"z-50 w-fit overflow-auto p-0",align:"start",children:e.jsxs(s.Command,{children:[e.jsx(s.CommandInput,{placeholder:"Search..."}),e.jsxs(s.CommandList,{children:[e.jsx(s.CommandEmpty,{children:"No results found."}),e.jsx(s.CommandGroup,{children:i.map((m,x)=>e.jsxs(s.CommandItem,{onSelect:()=>u(m.value),children:[e.jsx(s.Check,{className:s.cn("mr-2 h-4 w-4",n.includes(m.value)?"opacity-100":"opacity-0")}),e.jsxs("div",{className:"flex grow items-center justify-between gap-4",children:[e.jsx("span",{children:m.label}),e.jsx("span",{className:"text-xs text-muted-foreground",children:m.count})]})]},m.value+x))})]})]})})]})})}function ll({field:t,value:n,onChange:a,placeholder:r="Select value...",className:l}){const{filterValues:o,isPending:c,error:i}=ps(t);return c?e.jsxs("div",{className:"flex flex-1 items-center justify-center p-2 text-xs text-gray-500",children:[e.jsx(s.LoaderCircle,{className:"mr-2 size-3.5 animate-spin"})," Loading values..."]}):i?e.jsx("div",{className:"flex-1 p-2 text-xs text-red-500",children:"Error loading values"}):e.jsxs(s.Select,{value:n,onValueChange:a,children:[e.jsx(s.SelectTrigger,{className:l||"flex-1",children:e.jsx(s.SelectValue,{placeholder:r,children:n})}),e.jsx(s.SelectContent,{children:o.map((d,u)=>e.jsx(s.SelectItem,{className:"hover:bg-muted",value:d.value,children:d.label},d.value+u))})]})}function ol({value:t,operator:n,onChange:a,className:r}){var d;const{tokenProps:l}=s.useSemaphorContext(),o=(d=l==null?void 0:l.params)==null?void 0:d.timeZone,c=T.useMemo(()=>{if(t){if(n==="between"||n==="not between"){if(Array.isArray(t)&&t.length===2){const u=t[0]?new Date(t[0]):void 0,m=t[1]?new Date(t[1]):void 0;if(u&&m)return{from:u,to:m}}}else if(n==="="||n==="!="){if(!Array.isArray(t)&&t){const u=new Date(t);if(!isNaN(u.getTime()))return{from:u,to:u}}}else if(n===">"||n===">="){if(!Array.isArray(t)&&t){const u=new Date(t);if(!isNaN(u.getTime()))return{from:u,to:void 0}}}else if(n==="<"||n==="<="){if(!Array.isArray(t)&&t){const u=new Date(t);if(!isNaN(u.getTime()))return{from:void 0,to:u}}}else if((n==="in"||n==="not in")&&Array.isArray(t)&&t.length>0){const u=new Date(t[0]),m=t.length>1?new Date(t[t.length-1]):u;if(!isNaN(u.getTime()))return{from:u,to:m}}}},[t,n]),i=u=>{if(!u){a(void 0);return}if(u.from&&u.to)a([u.from.toISOString(),u.to.toISOString()]);else if(u.from){const m=new Date(u.from);m.setHours(23,59,59,999),a([u.from.toISOString(),m.toISOString()])}else if(u.to){const m=new Date(u.to);m.setHours(0,0,0,0),a([m.toISOString(),u.to.toISOString()])}};return e.jsx(s.DateRangePicker,{value:c,onChange:i,timezone:o,showRelativeTab:!0,className:r,placeholder:"Select date..."})}const il=["=","!=",">",">=","<","<=","contains","startsWith","endsWith","in","not in","isNull","isNotNull"],cl=["=","!=","contains","startsWith","endsWith","in","not in","isNull","isNotNull"],dl=["=","!=",">",">=","<","<=","in","not in","isNull","isNotNull"],ul=["=","!=","isNull","isNotNull"],ml=["between","isNull","isNotNull"],hl={"=":"Equals","!=":"Not Equals",">":"Greater Than",">=":"Greater Than or Equal","<":"Less Than","<=":"Less Than or Equal",contains:"Contains",startsWith:"Starts With",endsWith:"Ends With",in:"In","not in":"Not In",between:"Between",isNull:"Is Null",isNotNull:"Is Not Null","not between":"Not Between"};function Os(t){return hl[t]||s.titleCase(t)}function xl(t){switch(t){case"string":return cl;case"number":return dl;case"boolean":return ul;case"date":return ml;default:return il}}function kt({condition:t,index:n,groupId:a,groupLogicalOperator:r,onUpdateCondition:l,onRemoveCondition:o,onUpdateGroupOperator:c,availableFields:i,updateConditionFields:d}){const{attributes:u,listeners:m,setNodeRef:x,transform:h,transition:p,isDragging:g}=s.useSortable({id:t.id}),{isPending:f,error:y}=ps(t.field),v={transform:s.CSS.Transform.toString(h),transition:p};return e.jsxs("div",{ref:x,style:v,className:`mb-2 flex items-center gap-2 rounded p-2 hover:bg-muted/50 ${g?"z-50 opacity-50":""}`,children:[e.jsx("div",{...u,...m,className:"cursor-grab active:cursor-grabbing",children:e.jsx(s.GripVertical,{className:"h-4 w-4 flex-shrink-0 text-gray-400"})}),n>0&&e.jsxs(s.Select,{value:r,onValueChange:C=>c(a,C),children:[e.jsx(s.SelectTrigger,{className:"w-24",children:e.jsx(s.SelectValue,{})}),e.jsxs(s.SelectContent,{children:[e.jsx(s.SelectItem,{value:"AND",children:"AND"}),e.jsx(s.SelectItem,{value:"OR",children:"OR"})]})]}),n===0&&e.jsx("div",{className:"w-24"}),e.jsx(nl,{value:t.field,onValueChange:C=>{const F=C,k=s.getDataType(F.dataType)==="date";d(a,t.id,{field:F,value:"",operator:k?"between":"="})},availableFields:i,placeholder:"Select field",className:"w-64"}),e.jsxs(s.Select,{value:t.operator,onValueChange:C=>{C==="in"||C==="not in"?d(a,t.id,{operator:C,value:[]}):C==="isNull"||C==="isNotNull"?d(a,t.id,{operator:C,value:null}):d(a,t.id,{operator:C,value:""})},children:[e.jsx(s.SelectTrigger,{className:"w-32",children:e.jsx(s.SelectValue,{children:t.operator?Os(t.operator):""})}),e.jsx(s.SelectContent,{children:xl(s.getDataType(t.field.dataType)).map(C=>e.jsx(s.SelectItem,{className:"hover:bg-muted",value:C,children:Os(C)},C))})]}),t.operator==="isNull"||t.operator==="isNotNull"?e.jsx("div",{className:"flex-1"}):s.getDataType(t.field.dataType)==="string"?t.operator==="in"||t.operator==="not in"?f?e.jsxs("div",{className:"flex flex-1 items-center justify-center p-2 text-xs text-gray-500",children:[e.jsx(s.LoaderCircle,{className:"mr-2 size-3.5 animate-spin"})," Loading values..."]}):y?e.jsx("div",{className:"flex-1 p-2 text-xs text-red-500",children:"Error loading values"}):e.jsx(rl,{field:t.field,selected:Array.isArray(t.value)&&t.value.every(C=>typeof C=="string")?t.value:[],onChange:C=>d(a,t.id,{value:C}),placeholder:`Select values for ${t.operator}...`,className:"flex-1"}):["contains","startsWith","endsWith"].includes(t.operator)?e.jsx(s.Input$1,{value:typeof t.value=="string"?t.value:"",onChange:C=>d(a,t.id,{value:C.target.value}),className:"flex-1",placeholder:t.operator.charAt(0).toUpperCase()+t.operator.slice(1)+"..."}):e.jsx(ll,{field:t.field,value:typeof t.value=="string"?t.value:"",onChange:C=>d(a,t.id,{value:C}),placeholder:"Select value...",className:"flex-1"}):s.getDataType(t.field.dataType)==="boolean"?e.jsxs(s.Select,{value:typeof t.value=="boolean"?String(t.value):"",onValueChange:C=>d(a,t.id,{value:C==="true"}),children:[e.jsx(s.SelectTrigger,{className:"flex-1",children:e.jsx(s.SelectValue,{placeholder:"Select value..."})}),e.jsxs(s.SelectContent,{children:[e.jsx(s.SelectItem,{value:"true",children:"True"}),e.jsx(s.SelectItem,{value:"false",children:"False"})]})]}):s.getDataType(t.field.dataType)==="date"?e.jsx(ol,{value:t.value,operator:t.operator,onChange:C=>d(a,t.id,{value:C}),className:"flex-1"}):e.jsx(s.Input$1,{value:typeof t.value=="string"||typeof t.value=="number"?t.value:"",onChange:C=>l(a,t.id,"value",C.target.value),className:"flex-1",placeholder:t.operator==="in"||t.operator==="not in"?"value1, value2, value3":"Value"}),e.jsx(s.Button,{variant:"ghost",size:"sm",className:"h-7 w-7 flex-shrink-0 p-0",onClick:()=>o(a,t.id),children:e.jsx(s.X,{className:"h-3 w-3"})})]})}function pl({group:t,depth:n,parentGroupId:a,onUpdateGroupOperator:r,onUpdateGroupNegate:l,onRemoveGroup:o,onUpdateCondition:c,onUpdateField:i,onRemoveCondition:d,onReorderConditions:u,onReorderGroups:m,onAddCondition:x,onAddGroup:h,availableFields:p,renderFilterGroup:g,updateConditionFields:f}){const{attributes:y,listeners:v,setNodeRef:C,transform:F,transition:k,isDragging:D}=s.useSortable({id:t.id}),w={transform:s.CSS.Transform.toString(F),transition:k},j=b=>{const{active:R,over:S}=b;if(S&&R.id!==S.id){const O=t.conditions.findIndex(I=>I.id===R.id),E=t.conditions.findIndex(I=>I.id===S.id);O!==-1&&E!==-1&&u(t.id,O,E)}},N=b=>{const{active:R,over:S}=b;if(S&&R.id!==S.id&&a){const O=t.groups.findIndex(I=>I.id===R.id),E=t.groups.findIndex(I=>I.id===S.id);O!==-1&&E!==-1&&m(a,O,E)}};return e.jsxs("div",{ref:C,style:w,className:`rounded-lg ${n>0?"mt-2 border border-border":""} ${D?"z-50 opacity-50":""}`,children:[n>0&&e.jsxs("div",{className:"flex items-center justify-between rounded-t-lg bg-muted p-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{...y,...v,className:"cursor-grab active:cursor-grabbing",children:e.jsx(s.GripVertical,{className:"h-4 w-4 text-muted-foreground"})}),e.jsx(s.Button,{variant:t.negate?"default":"outline",size:"sm",className:"h-7 px-2 text-xs",onClick:()=>l(t.id,!t.negate),children:"NOT"}),e.jsxs(s.Select,{value:t.logicalOperator,onValueChange:b=>r(t.id,b),children:[e.jsx(s.SelectTrigger,{className:"h-7 w-20",children:e.jsx(s.SelectValue,{})}),e.jsxs(s.SelectContent,{children:[e.jsx(s.SelectItem,{className:"hover:bg-muted",value:"AND",children:"AND"}),e.jsx(s.SelectItem,{className:"hover:bg-muted",value:"OR",children:"OR"})]})]}),e.jsx("span",{className:"text-sm font-medium",children:"Group"})]}),e.jsx(s.Button,{variant:"ghost",size:"sm",className:"h-7 w-7 p-0",onClick:()=>a&&o(a,t.id),children:e.jsx(s.Trash2,{className:"h-3 w-3"})})]}),e.jsxs("div",{className:`p-3 ${n>0?"":"px-0"}`,children:[e.jsx(s.DndContext,{sensors:s.useSensors(s.useSensor(s.PointerSensor),s.useSensor(s.KeyboardSensor,{coordinateGetter:s.sortableKeyboardCoordinates})),collisionDetection:s.closestCenter,onDragEnd:j,children:e.jsx(s.SortableContext,{items:t.conditions.map(b=>b.id),strategy:s.verticalListSortingStrategy,children:t.conditions.map((b,R)=>e.jsx(kt,{condition:b,index:R,groupId:t.id,groupLogicalOperator:t.logicalOperator,onUpdateCondition:c,onUpdateField:i,onRemoveCondition:d,onUpdateGroupOperator:r,availableFields:p,updateConditionFields:f},b.id))})}),e.jsx(s.DndContext,{sensors:s.useSensors(s.useSensor(s.PointerSensor),s.useSensor(s.KeyboardSensor,{coordinateGetter:s.sortableKeyboardCoordinates})),collisionDetection:s.closestCenter,onDragEnd:N,children:e.jsx(s.SortableContext,{items:t.groups.map(b=>b.id),strategy:s.verticalListSortingStrategy,children:t.groups.map(b=>g(b,n+1,t.id))})}),e.jsxs("div",{className:"mt-3 flex items-center gap-2",children:[e.jsxs(s.Button,{size:"sm",variant:"outline",className:"h-7 text-xs",onClick:()=>x(t.id),children:[e.jsx(s.Plus,{className:"mr-1 h-3 w-3"}),"Add Condition"]}),e.jsxs(s.Button,{variant:"outline",size:"sm",className:"h-7 text-xs",onClick:()=>h(t.id),children:[e.jsx(s.Plus,{className:"mr-1 h-3 w-3"}),"Add Group"]})]})]})]})}function fl({filters:t,availableFields:n,onSave:a,onClearAll:r,onCancel:l}){const{currentFilters:o,availableFields:c,isLoading:i,addCondition:d,addGroup:u,removeCondition:m,removeGroup:x,updateCondition:h,updateConditionFields:p,updateGroupOperator:g,updateGroupNegate:f,reorderConditions:y,reorderGroups:v,generateSQLPreview:C,hasAnyFilters:F,setCurrentFilters:k}=el({initialFilters:t,availableFields:n}),D=s.useSensors(s.useSensor(s.PointerSensor),s.useSensor(s.KeyboardSensor,{coordinateGetter:s.sortableKeyboardCoordinates})),[w,j]=T.useState(!1),N=(S,O,E)=>{const I=A=>A.id===S?{...A,conditions:A.conditions.map(M=>M.id===O?{...M,field:E,dataType:E.dataType}:M)}:{...A,groups:A.groups.map(I)};k(I(o))},b=(S,O=0,E)=>O===0?e.jsx("div",{className:"rounded-lg",children:e.jsxs("div",{className:"p-3 px-0",children:[e.jsx(s.DndContext,{sensors:D,collisionDetection:s.closestCenter,onDragEnd:I=>{const{active:A,over:M}=I;if(M&&A.id!==M.id){const L=S.conditions.findIndex(B=>B.id===A.id),P=S.conditions.findIndex(B=>B.id===M.id);L!==-1&&P!==-1&&y(S.id,L,P)}},children:e.jsx(s.SortableContext,{items:S.conditions.map(I=>I.id),strategy:s.verticalListSortingStrategy,children:S.conditions.map((I,A)=>e.jsx(kt,{condition:I,index:A,groupId:S.id,groupLogicalOperator:S.logicalOperator,onUpdateCondition:h,onUpdateField:N,onRemoveCondition:m,onUpdateGroupOperator:g,availableFields:c,updateConditionFields:p},I.id))})}),e.jsx(s.DndContext,{sensors:D,collisionDetection:s.closestCenter,onDragEnd:I=>{const{active:A,over:M}=I;if(M&&A.id!==M.id){const L=S.groups.findIndex(B=>B.id===A.id),P=S.groups.findIndex(B=>B.id===M.id);L!==-1&&P!==-1&&v(S.id,L,P)}},children:e.jsx(s.SortableContext,{items:S.groups.map(I=>I.id),strategy:s.verticalListSortingStrategy,children:S.groups.map(I=>b(I,O+1,S.id))})}),e.jsxs("div",{className:"mt-3 flex items-center gap-2",children:[e.jsxs(s.Button,{size:"sm",className:"h-7 text-xs",variant:"outline",onClick:()=>d(S.id),children:[e.jsx(s.Plus,{className:"mr-1 h-3 w-3"}),"Add Condition"]}),w&&e.jsxs(s.Button,{variant:"outline",size:"sm",className:"h-7 text-xs",onClick:()=>u(S.id),children:[e.jsx(s.Plus,{className:"mr-1 h-3 w-3"}),"Add Group"]})]})]})},S.id):e.jsx(pl,{group:S,depth:O,parentGroupId:E,onUpdateGroupOperator:g,onUpdateGroupNegate:f,onRemoveGroup:x,onUpdateCondition:h,onUpdateField:N,onRemoveCondition:m,onReorderConditions:y,onReorderGroups:v,onAddCondition:d,onAddGroup:u,availableFields:c,renderFilterGroup:b,updateConditionFields:p},S.id),R=s.getFilterCount(t);return e.jsxs("div",{className:"space-y-4",children:[e.jsx(s.Card,{children:e.jsx(s.CardContent,{className:"p-4",children:e.jsxs("div",{className:"space-y-4",children:[i?e.jsxs("div",{className:"flex items-center justify-center p-4",children:[e.jsx("div",{className:"h-5 w-5 animate-spin rounded-full border-2 border-gray-300 border-t-gray-600"}),e.jsx("span",{className:"ml-2 text-sm text-gray-600",children:"Loading columns..."})]}):b(o),e.jsx("div",{className:"mt-4 border-t border-border pt-4",children:e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(s.SmallSwitch,{id:"advanced-mode",checked:w,onCheckedChange:S=>j(S)}),e.jsx(s.Label,{htmlFor:"advanced-mode",className:"text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70",children:"Advanced mode (enable grouping)"})]})}),F&&e.jsxs("div",{className:"mt-4 border-t border-border pt-4",children:[e.jsx("div",{className:"mb-2 text-xs font-medium text-muted-foreground",children:"SQL WHERE Clause Preview"}),e.jsx("div",{className:"overflow-x-auto rounded-md border bg-muted p-3",children:e.jsx("pre",{className:"whitespace-pre-wrap font-mono text-xs text-muted-foreground",children:C(o)})})]})]})})}),e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx(s.Button,{size:"sm",variant:"outline",onClick:l,children:"Cancel"}),R>0&&e.jsx(s.Button,{variant:"outline",size:"sm",onClick:r,children:"Clear All"}),e.jsx(s.Button,{size:"sm",onClick:()=>a(F?o:null),children:"Apply Filters"})]})]})}function gl({cardId:t,filters:n,onFiltersChange:a,onClearFilters:r,availableFields:l,isOpen:o,onOpenChange:c}){const i=u=>{a(t,u),c(!1)},d=()=>{r(t),c(!1)};return e.jsxs(s.Dialog,{modal:!1,open:o,onOpenChange:c,children:[o&&e.jsx("div",{className:"pointer-events-none fixed inset-0 z-40 bg-background/80 backdrop-blur-sm"}),e.jsxs(s.DialogContent,{className:"max-h-[80vh] max-w-4xl overflow-y-auto",onInteractOutside:u=>{u.preventDefault()},children:[e.jsxs(s.DialogHeader,{children:[e.jsx(s.DialogTitle,{children:"Card Filters"}),e.jsx(s.DialogDescription,{children:"Add filters to the card to limit the data that is displayed."})]}),e.jsx(fl,{filters:n,availableFields:l,onSave:i,onCancel:()=>c(!1),onClearAll:d})]})]})}function jl({activeCardId:t,sourceFields:n,getFieldsForContainer:a,setFieldsForContainer:r}){var f,y;const[l,o]=T.useState(null),c=s.useEditorStore(v=>v.card),i=(f=c==null?void 0:c.config)==null?void 0:f.joinPlan,d=(y=c==null?void 0:c.dataSource)==null?void 0:y.semanticDomainId,{data:u}=is(d),m=[...n,...a("groupBy"),...a("pivotBy"),...a("metrics"),...a("sortBy")],x=T.useCallback(v=>v.startsWith("card-")?null:v.startsWith("source-")||n.find(C=>C.id===v)?"source":a("groupBy").find(C=>C.id===v)?"groupBy":a("metrics").find(C=>C.id===v)?"metrics":a("pivotBy").find(C=>C.id===v)?"pivotBy":a("sortBy").find(C=>C.id===v)?"sortBy":null,[n,a]),h=T.useCallback(v=>{o(v.active.id)},[]),p=T.useCallback(v=>{var N;const{active:C,over:F}=v;if(!F||!t){o(null);return}const k=C.id,D=F.id,w=x(k),j=x(D)||D;if(j==="sortBy"){if(w==="source"){const b=n.find(S=>S.id===k);if(!b){o(null);return}if(!(a("groupBy").some(S=>S.name===b.name&&S.qualifiedEntityName===b.qualifiedEntityName)||a("metrics").some(S=>S.name===b.name&&S.qualifiedEntityName===b.qualifiedEntityName))){o(null);return}}else if(w==="pivotBy"){o(null);return}else if(w!=="groupBy"&&w!=="metrics"&&w!=="sortBy"){o(null);return}}if(w==="source"&&j==="sortBy"){const b=[...n].find(O=>O.id===k);if(!b){o(null);return}const R=a("sortBy");if(s.fieldAlreadyExists(b,R)){o(null);return}const S=s.getNewField(b,"sortBy",R);o(null),r("sortBy",[...R,S]);return}if(w==="source"&&j!=="source"&&j!=="sortBy"){const b=[...n].find(E=>E.id===k);if(!b){o(null);return}const R=[...a("groupBy"),...a("pivotBy"),...a("metrics"),...a("sortBy")];if(R.length>0){const E=R[0].qualifiedEntityName;if(!E){o(null);return}if(E!==b.qualifiedEntityName&&b.qualifiedEntityName)if(d&&(u!=null&&u.joinabilityMap)){if(s.calculateFieldState(b,{joinabilityMap:u.joinabilityMap,selectedFields:R,baseEntityName:(N=i==null?void 0:i.baseEntity)==null?void 0:N.name}).state==="unreachable"){s.showJoinRequiredNotification(),o(null);return}}else{if(!i){s.showJoinRequiredNotification(),o(null);return}if(!s.areEntitiesJoined(E,b.qualifiedEntityName,i)){s.showJoinRequiredNotification(),o(null);return}}}const S=a(j);if(s.fieldAlreadyExists(b,S)){o(null);return}const O=s.getNewField(b,j,S);o(null),r(j,[...S,O]);return}if(w&&j&&w!=="source"&&j!=="source"&&w!==j){const b=a(w),R=a(j),S=b.find(I=>I.id===k);if(!S){o(null);return}const O=s.getNewField(S,j,R);if(o(null),j==="sortBy"){s.fieldAlreadyExists(S,R)||r(j,[...R,O]);return}const E=b.filter(I=>I.id!==k);r(w,E),r(j,[...R,O]);return}if(w&&j&&w===j&&w!=="source"){const b=a(w),R=b.findIndex(O=>O.id===k),S=b.findIndex(O=>O.id===D);if(R!==S){const O=s.arrayMove(b,R,S);r(w,O)}}o(null)},[t,n,a,r,x,i,d,u]),g=l?m.find(v=>v.id===l):null;return{activeId:l,activeField:g,handleDragStart:h,handleDragEnd:p}}function bl({activeView:t,onViewChange:n}){const a=s.useEditorStore(c=>c.card),{config:r}=T.useContext(s.SemaphorContext).tokenProps,l=(r==null?void 0:r.showInfoTab)!==!1,{errorMessage:o}=s.useDashboardCardQuery(a);return e.jsx(s.Tabs,{value:t,onValueChange:c=>n(c),children:e.jsxs(s.TabsList,{className:"h-9 w-fit gap-1 bg-background p-0",children:[e.jsx(s.TabsTrigger,{value:"chart",className:"rounded-md transition data-[state=active]:bg-muted",children:"Chart"}),e.jsx(s.TabsTrigger,{value:"table",className:"rounded-md transition data-[state=active]:bg-muted",children:"Results"}),a.type!=="kpi"&&l&&e.jsx(s.TabsTrigger,{value:"info",className:s.cn("rounded-md transition data-[state=active]:bg-muted",o&&"text-destructive data-[state=active]:bg-destructive/10 data-[state=active]:text-destructive"),children:o?"Error":"Info"})]})})}const vl=[{value:"10",label:"Top 10"},{value:"20",label:"Top 20"},{value:"50",label:"Top 50"},{value:"100",label:"Top 100"},{value:"200",label:"Top 200"},{value:"500",label:"Top 500"},{value:"1000",label:"Top 1000"}];function yl(){var d,u;const t=s.useEditorStore(m=>m.card),{updateRowLimit:n}=s.useEditorActions(),[a,r]=T.useState(!1),[l,o]=T.useState(""),c=m=>{if(m==="custom"){r(!0);return}r(!1),n(t.id,parseInt(m))},i=m=>{const x=m.target.value;o(x),x&&!isNaN(parseInt(x))&&n(t.id,parseInt(x))};return e.jsx("div",{className:"flex items-center gap-2",children:a?e.jsx(s.Input,{type:"number",value:l,onChange:i,className:"h-7 w-24",placeholder:"Enter limit",min:1}):e.jsxs(s.Select,{value:((u=(d=t.config)==null?void 0:d.rowLimit)==null?void 0:u.toString())||"100",onValueChange:c,children:[e.jsx(s.SelectTrigger,{className:"h-8 w-24 border-none px-1 [&>svg]:hidden",children:e.jsx(s.SelectValue,{placeholder:"Select limit"})}),e.jsx(s.SelectContent,{children:vl.map(m=>e.jsx(s.SelectItem,{value:m.value,children:m.label},m.value))})]})})}function Nl({isOpen:t,onClose:n}){const a=Ks(n,{enabled:t}),r=s.useEditorStore(m=>{var x;return((x=m.card.customCardPreferences)==null?void 0:x.url)||""}),l=s.useEditorStore(m=>m.card),o=s.useEditorStore(m=>{var x;return((x=m.card.customCardPreferences)==null?void 0:x.pluginChartType)||""}),c=s.useEditorStore(m=>{var x;return((x=m.card.customCardPreferences)==null?void 0:x.settings)||{}}),{data:i}=s.useDashboardCardQuery(l),{getCard:d}=s.useCustomVisual(r),u=T.useMemo(()=>!r||r.trim()===""?null:d("Chart Settings"),[d,r]);return e.jsx("div",{ref:a,className:s.cn("absolute right-0 top-0 z-40 h-full w-[350px] border-l bg-background shadow-lg transition-transform duration-300",t?"translate-x-0":"translate-x-full"),style:{willChange:"transform"},tabIndex:t?0:-1,"aria-hidden":!t,children:e.jsxs("div",{className:"flex h-full flex-col p-4 px-5 pr-4",children:[e.jsxs("div",{className:"mb-4 flex items-center justify-between",children:[e.jsx("h2",{className:"text-base font-semibold",children:"Chart Settings"}),e.jsx(s.IconButton,{"aria-label":"Hide Chart Settings",tooltip:"Hide",onClick:n,className:"h-7 p-2 text-muted-foreground hover:text-foreground",children:e.jsx(s.X,{className:"size-3.5"})})]}),e.jsx("div",{className:"h-full min-h-0 flex-1",children:u&&e.jsx(T.Suspense,{fallback:e.jsx("div",{children:"Loading chart settings..."}),children:e.jsx(u,{chartData:(i==null?void 0:i.records)||[],chartType:o,settings:c})})})]})})}function Cl({activeView:t,onViewChange:n,showDebug:a,onDebugToggle:r,onFiltersClick:l,activeCard:o,columns:c,columnsLoading:i,columnsError:d}){var H,q,ae;const u=s.useEditorStore(J=>J.card),m=s.useDashboardStore(J=>J.filterValues);m!=null&&m.length;const{updateCardConfig:x,setCard:h,updateCardInFrame:p,setCardId:g,setShowAIDialog:f}=s.useEditorActions(),{updateCardId:y}=s.useDashboardActions(),[v,C]=T.useState(null),F=s.useEditorStore(J=>J.showAIDialog),k=s.useDashboardStore(J=>J.isVisualEditing),[D,w]=T.useState(!1),[j,N]=T.useState(!1),[b,R]=T.useState(null),{isConsoleMode:S}=s.useDashboardPreferences(),{config:O}=T.useContext(s.SemaphorContext).tokenProps,E=(O==null?void 0:O.showInfoTab)!==!1,I=s.useEditorStore(J=>{var re;return((re=J.card.customCardPreferences)==null?void 0:re.url)&&J.card.type==="custom"}),{data:A,errorMessage:M,isLoading:L,isFetching:P,errorSql:B,pagination:K,refetch:_}=s.useDashboardCardQuery(o),[z,U]=T.useState(!1);T.useEffect(()=>{P||U(!1)},[P]);const W=(J,re)=>{const G={...o,paginationConfig:{page:J+1,pageSize:re}};h(G),p(G)};function ee(){return e.jsxs("div",{className:"relative border-b border-border bg-background p-4",children:[e.jsx("button",{onClick:r,className:"absolute right-4 top-4 rounded-md p-1 hover:bg-muted","aria-label":"Close Debug Panel",children:e.jsx(s.X,{className:"h-4 w-4"})}),e.jsxs("div",{className:"space-y-4 pr-8",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"mb-2 text-sm font-medium",children:"Active Card Config"}),e.jsx("pre",{className:"max-h-40 overflow-auto rounded border bg-background p-3 text-xs",children:JSON.stringify(u.config||{},null,2)})]}),e.jsxs("div",{children:[e.jsx("h3",{className:"mb-2 text-sm font-medium",children:"Dashboard Filters"}),e.jsx("pre",{className:"max-h-40 overflow-auto rounded border bg-background p-3 text-xs",children:JSON.stringify(m||{},null,2)})]}),e.jsxs("div",{children:[e.jsx("h3",{className:"mb-2 text-sm font-medium",children:"Card Data Source State"}),e.jsx("pre",{className:"max-h-40 overflow-auto rounded border bg-background p-3 text-xs",children:JSON.stringify(o.dataSource||{},null,2)})]}),e.jsxs("div",{children:[e.jsxs("h3",{className:"mb-2 text-sm font-medium",children:["Columns (",c.length,")"]}),e.jsx("pre",{className:"max-h-40 overflow-auto rounded border bg-background p-3 text-xs",children:i?"Loading...":d?"Error loading columns":JSON.stringify(c.slice(0,5),null,2)})]})]})]})}const te=J=>{if(!u.config)return;if(!J.length){x(u.id,{...u.config,sortByColumns:[]});return}const re=u.config,G=J.map(({id:se,desc:ce})=>{var Q,$;const le=(Q=re.metricColumns)==null?void 0:Q.find(V=>V.label===se),fe=($=re.groupByColumns)==null?void 0:$.find(V=>V.label===se),ue=le||fe;return ue?{id:s.getFieldId("sortBy",ue),name:ue.name,dataType:ue.dataType,label:ue.label,qualifiedEntityName:ue.qualifiedEntityName,entityId:ue.entityId,entityName:ue.entityName,entityType:ue.entityType,role:"sortby",direction:ce?"desc":"asc"}:null}).filter(se=>se!==null);x(u.id,{...re,sortByColumns:G})},oe=T.useMemo(()=>{var J,re;return(re=(J=u.config)==null?void 0:J.sortByColumns)==null?void 0:re.map(G=>({id:G.label,desc:G.direction==="desc"}))},[(H=u.config)==null?void 0:H.sortByColumns]);return e.jsxs("div",{className:s.cn("relative flex w-0 grow flex-col",{"border-l":F&&k}),children:[a&&ee(),e.jsxs("div",{className:"group/visualization relative flex h-full max-w-full grow flex-col pt-4",children:[e.jsxs("div",{className:"flex items-center gap-2 px-6",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[t==="chart"&&F&&e.jsx(ft,{variant:"outline"}),e.jsx(bl,{activeView:t,onViewChange:n}),e.jsx(s.FilterInfo,{cardId:o.id,cardFilters:(q=o.config)==null?void 0:q.filters,cardFilterCount:s.getFilterCount(((ae=o.config)==null?void 0:ae.filters)||null),onFiltersClick:l}),e.jsx("div",{className:"ml-2",children:e.jsx(yl,{})}),F&&e.jsx(os,{})]}),e.jsxs("div",{className:s.cn("flex grow items-center justify-end gap-2"),children:[e.jsx(s.IconButton,{tooltip:"Refresh",disabled:L||P,onClick:()=>{U(!0),_()},children:e.jsx(s.RefreshCcw,{className:s.cn("h-4 w-4",{"animate-spin":z})})}),t==="chart"&&e.jsx(gt,{}),!F&&e.jsx(s.IconButton,{onClick:()=>f(!F),tooltip:"AI",className:"h-8","aria-label":"AI",children:e.jsx(s.Sparkles,{className:"size-4"})}),r&&s.isDevEnv]})]}),!D&&I&&e.jsx(s.IconButton,{"aria-label":"Open Chart Settings",tooltip:"Open Chart Settings",onClick:()=>w(!0),className:"absolute right-5 top-1/2 z-40 size-10 -translate-y-1/2 rounded-full border border-border bg-background shadow-lg hover:bg-muted focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2",children:e.jsx(s.Settings2,{className:"size-4"})}),e.jsxs("div",{className:"mt-3 flex grow flex-col",children:[t==="chart"&&e.jsx("div",{className:"flex grow flex-col pb-6",children:e.jsx(jt,{})}),t==="table"&&(A==null?void 0:A.records)&&e.jsx("div",{className:"relative flex h-full min-h-0 max-w-full flex-1 grow basis-0 p-6",children:e.jsx(s.TableVisual,{card:o,data:(A==null?void 0:A.records)||[],paginationMetadata:K,onPaginationChange:W,isLoading:L||P,onSortChange:te,sortState:oe})}),t==="info"&&E&&e.jsx("div",{className:"px-6",children:e.jsxs("div",{className:"rounded-md bg-background",children:[e.jsxs("div",{className:"mb-2",children:[S&&e.jsxs("div",{className:"mb-2 flex items-center gap-2",children:[e.jsx("span",{className:"text-xs text-muted-foreground",children:"Card ID:"}),e.jsx(s.EditableText,{value:u.id,onSave:J=>{const re=s.sanitizeCardId(J);if(!re){C("Card ID cannot be empty");return}const G=y(u.id,re);if(G.success){g(re);const se={...u,id:re};h(se),p(se),C(null),s.ue.success("Card ID updated successfully")}else C(G.error||"Failed to update Card ID"),s.ue.error(G.error||"Failed to update Card ID")},isEditable:!0,placeholder:"Enter card ID",displayClassName:"font-mono text-xs text-muted-foreground hover:text-foreground",inputClassName:"font-mono text-xs"}),e.jsx(s.CopyButton,{text:u.id,className:"h-5 w-5"})]}),v&&e.jsx("p",{className:"text-xs text-destructive",children:v})]}),M||B?e.jsx(dt,{error:M,errorSql:B,onSendFeedback:()=>{const J=s.prepareFeedbackData(s.FeedbackCategory.QUERY_GENERATION,{cardConfig:u.config,dataSource:o.dataSource,dashboardFilters:m,errorMessage:M,errorSql:B,generatedSql:A==null?void 0:A.sql});R(J),N(!0)}}):e.jsxs(e.Fragment,{children:[(A==null?void 0:A.sql)&&e.jsx("h3",{className:"mb-1 px-2 font-mono text-xs font-medium",children:"Generated SQL Query"}),e.jsx(ut,{sql:A==null?void 0:A.sql,error:M,errorSql:B})]})]})})]}),e.jsx(Nl,{isOpen:D,onClose:()=>w(!1)}),b&&e.jsx(s.FeedbackDialog,{open:j,onOpenChange:N,feedbackData:b})]})]})}function Sl({activeField:t}){const[n,a]=T.useState(!0);return T.useEffect(()=>{t&&a(!0)},[t]),t?e.jsxs("div",{className:`flex max-w-[300px] items-center gap-2 rounded-lg border border-blue-500 bg-background p-2 shadow-lg transition-all duration-200 ${n?"scale-100 opacity-100":"scale-95 opacity-0"}`,children:[e.jsx(s.GripVertical,{className:"h-3 w-3 shrink-0 text-muted-foreground"}),e.jsx(xs,{dataType:t.dataType}),e.jsx("span",{className:"overflow-hidden text-ellipsis whitespace-nowrap text-sm dark:text-muted-foreground",children:t.label||t.name})]}):null}const wl=()=>{const t=console.error;console.error=(...r)=>{r.length>0&&typeof r[0]=="string"&&r[0].includes("ResizeObserver loop completed with undelivered notifications")||t.apply(console,r)};const n=r=>{if(r.message&&(r.message.includes("ResizeObserver loop completed with undelivered notifications")||r.message.includes("ResizeObserver loop limit exceeded")))return r.preventDefault(),r.stopPropagation(),!1},a=r=>{var l;if((l=r.reason)!=null&&l.message&&(r.reason.message.includes("ResizeObserver loop completed with undelivered notifications")||r.reason.message.includes("ResizeObserver loop limit exceeded")))return r.preventDefault(),!1};return window.addEventListener("error",n,!0),window.addEventListener("unhandledrejection",a,!0),()=>{console.error=t,window.removeEventListener("error",n,!0),window.removeEventListener("unhandledrejection",a,!0)}};function Dl(){var B,K;const[t,n]=T.useState("chart"),[a,r]=T.useState(!1),[l,o]=T.useState(!1),[c,i]=T.useState(!0),d=s.useEditorStore(_=>_.showAIDialog),u=s.useDashboardStore(_=>_.isVisualEditing),{setCardType:m}=s.useEditorActions(),x=s.useEditorStore(_=>_.card.type);T.useEffect(()=>wl(),[]);const h=_=>{m(_)},p=s.useEditorStore(_=>_.frame),g=s.useEditorStore(_=>_.card);s.useEditorStore(_=>_.activeTabCardId),s.useEditorStore(_=>_.actions.getAvailableFields);const{addCard:f,removeCard:y,updateCard:v,setActiveCard:C,updateFilters:F}=s.useEditorActions(),{columns:k=[],isLoading:D,error:w}=s.useColumns(),j=s.useSensors(s.useSensor(s.PointerSensor,{activationConstraint:{distance:8}})),N=g,{getFieldsForContainer:b,setFieldsForContainer:R}=cs(N),{activeField:S,handleDragStart:O,handleDragEnd:E}=jl({activeCardId:p.activeCardId,sourceFields:k,getFieldsForContainer:b,setFieldsForContainer:R}),I=(_,z)=>{z&&F(_,z)},A=_=>{var z;v(_,{config:{...(z=p.cards.find(U=>U.id===_))==null?void 0:z.config,filters:void 0}})},M=k,L=_=>{if(!_)return 0;let z=_.conditions.length;return _.groups.forEach(U=>{z+=L(U)}),z},P=L(((B=N==null?void 0:N.config)==null?void 0:B.filters)||null);return e.jsxs(s.DndContext,{sensors:j,collisionDetection:s.closestCenter,onDragStart:O,onDragEnd:E,children:[e.jsxs("div",{className:"flex h-full grow",children:[e.jsx(ct,{isVisible:c,onToggleVisibility:()=>i(!c)}),e.jsxs("div",{className:"flex flex-1 transition-all duration-300 ease-in-out",children:[!d&&e.jsx(Zr,{selectedChart:x,onChartChange:h,groupByFields:b("groupBy"),pivotByFields:b("pivotBy"),metricsFields:b("metrics"),sortByFields:b("sortBy")}),e.jsx(Cl,{selectedChart:x,activeView:t,onViewChange:n,showDebug:a,onDebugToggle:()=>r(!a),onFiltersClick:()=>o(!0),filterCount:P,activeCard:N,dataSourceState:g.dataSource||s.EMPTY_DATA_SOURCE,columns:k,columnsLoading:D,columnsError:w,getFieldsForContainer:b,cards:p.cards,activeCardId:p.activeCardId,addCard:f,setActiveCard:C})]}),!c&&u&&e.jsx("div",{className:"fixed left-6 top-[105px] z-50",children:e.jsx(s.Button,{size:"sm",variant:"outline",className:"h-10 w-10 rounded-full border-border bg-background p-0 shadow-lg hover:bg-muted",onClick:()=>i(!0),title:"Show Data Source Panel",children:e.jsx(s.Database,{className:"h-4 w-4"})})})]}),N&&e.jsx(gl,{cardId:N.id,filters:((K=N.config)==null?void 0:K.filters)||null,onFiltersChange:I,onClearFilters:A,availableFields:M,isOpen:l,onOpenChange:o}),e.jsx(s.DragOverlay,{dropAnimation:null,children:e.jsx(Sl,{activeField:S||null})})]})}function Tl({authToken:t,onSave:n,onClose:a}){const r=T.useRef(null),l=s.useEditorStore(w=>w.showAIDialog),o=s.useEditorStore(w=>w.isDevMode),c=s.useAssistantLayoutStore(w=>w.setFullscreen),i=s.useAssistantLayoutStore(w=>w.setPanelOpen),d=s.useAssistantLayoutStore(w=>w.setContainer),u=s.useAssistantPanel("editor"),m=s.useFullscreenAssistant(),x=s.useAssistantContainer("editor"),h=m==="editor",p=T.useCallback(w=>{d("editor",w)},[d]),{setAuthToken:g}=s.useDashboardActions(),{setShowAIDialog:f,setOnSave:y,setOnClose:v}=s.useEditorActions(),{setActiveAssistantType:C}=s.useAIActions();T.useEffect(()=>{n&&y(n),a&&v(a)},[n,y,a,v]),T.useEffect(()=>{t&&t.accessToken&&g(t)},[t,g]),T.useEffect(()=>{var w,j;l?((w=r.current)==null||w.resize(40),i("editor",!0),C("editor")):((j=r.current)==null||j.resize(0),i("editor",!1),m==="editor"&&c(null),C(null))},[l,i,C,c,m]);function F(w){w<1?(f(!1),i("editor",!1),m==="editor"&&c(null),C(null)):(l||(f(!0),C("editor")),u.isOpen||i("editor",!0))}function k(){return e.jsxs(e.Fragment,{children:[e.jsx(ct,{isVisible:!0,onToggleVisibility:()=>{}}),e.jsxs("div",{className:"relative flex grow border-l",children:[e.jsxs(s.ResizablePanelGroup,{"data-content":"editor-main",className:s.cn("grow transition-opacity",h&&"pointer-events-none opacity-0"),direction:"horizontal",children:[e.jsx(s.ResizablePanel,{className:"min-w-[510px] rounded-none",children:e.jsx(Ar,{})}),e.jsx(s.ResizableHandle,{}),e.jsx(s.ResizablePanel,{"data-role":"editor-assistant-panel",ref:r,onResize:F,defaultSize:u.isOpen?40:0,className:"flex",children:e.jsx("div",{className:"grow overflow-y-auto",children:e.jsx(As,{isFullscreen:h,onFullscreenChange:w=>c(w?"editor":null),fullscreenContainer:x})})})]}),e.jsx("div",{ref:p,className:s.cn("absolute inset-0",!h&&"pointer-events-none")})]})]})}function D(){return e.jsxs("div",{className:"relative flex h-full grow",children:[e.jsxs(s.ResizablePanelGroup,{"data-content":"explorer",className:s.cn("flex grow transition-opacity",h&&"pointer-events-none opacity-0"),direction:"horizontal",children:[e.jsx(s.ResizablePanel,{className:"min-w-[510px] grow rounded-none",children:e.jsx(Dl,{})}),e.jsx(s.ResizableHandle,{}),e.jsx(s.ResizablePanel,{"data-role":"editor-assistant-panel",ref:r,onResize:F,defaultSize:u.isOpen?40:0,className:"flex",children:e.jsx("div",{className:"grow overflow-y-auto",children:e.jsx(As,{isFullscreen:h,onFullscreenChange:w=>c(w?"editor":null),fullscreenContainer:x})})})]}),e.jsx("div",{ref:p,className:s.cn("absolute inset-0",!h&&"pointer-events-none")})]})}return e.jsx(s.ErrorBoundary,{FallbackComponent:s.Fallback,children:o?e.jsx("section",{className:"isolate flex h-full grow","data-content":"editor-panel",children:k()}):D()})}function kl(){s.useDashboardStore(c=>c.selectedCardId);const t=s.useDashboardStore(c=>c.selectedSheetId),{setIsVisualEditing:n}=s.useDashboardStore(c=>c.actions),a=s.useDashboardStore(c=>c.isVisualEditing),r=s.useDashboardStore(c=>c.actions.updateFrame);function l(c){t&&(r(t,c),n(!1))}function o(){n(!1)}return e.jsx("div",{role:"editor-container",className:s.cn("flex-1 grow basis-0 overflow-auto",{"max-h-0 overflow-hidden":!a}),children:e.jsx(Tl,{onSave:l,onClose:o})})}function El(){it();const t=s.useDashboardStore(d=>d.selectedSheetId),n=s.useDashboardStore(d=>d.selectedFrameId),a=s.useDashboardStore(d=>d.dashboard),r=s.useDashboardStore(d=>d.actions.getSelectedFrame),{setSelectedFrameId:l}=s.useDashboardActions(),{setCard:o}=s.useEditorActions(),c=s.useEditorStore(d=>d.card.dataSource);return T.useEffect(()=>{var u,m;let d=r();if(!d){const x=(u=a==null?void 0:a.sheets)==null?void 0:u.find(p=>p.id===t),h=(m=x==null?void 0:x.frames)==null?void 0:m[0];h&&(l(h.id),d=h)}if(d){const x=d.cards.find(h=>h.id===d.activeCardId);x&&o(x)}},[r,t,n,a,l,o]),{hasEntities:!!(c!=null&&c.selectedEntities&&c.selectedEntities.length>0)}}function Il(){const t=s.useDashboardStore(a=>a.actions.setShowFilters),{hasEntities:n}=El();return e.jsxs("section",{className:"relative flex min-w-[320px] grow flex-col border-l",children:[e.jsxs("div",{className:"mt-4 flex items-center justify-between gap-2 px-4",children:[e.jsx(s.Label,{className:"px-2 text-base",children:"Dashboard Filters"}),e.jsx(s.Button,{onClick:()=>t(!1),className:"h-7 w-7 p-0",variant:"ghost",children:e.jsx(s.Cross2Icon,{})})]}),!n&&e.jsxs("div",{className:"flex h-full flex-col items-center justify-center px-6 py-12 text-center",children:[e.jsx(s.Database,{className:"mb-4 h-12 w-12 text-muted-foreground/50"}),e.jsx("h3",{className:"mb-2 text-sm font-medium text-foreground",children:"No fields configured"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Please configure a data source for this card to enable filtering"})]}),n&&e.jsx("div",{className:"flex grow",children:e.jsx(s.DndContext,{collisionDetection:s.closestCenter,children:e.jsx(s.SortableContext,{items:[],strategy:s.verticalListSortingStrategy,children:e.jsx(ot,{context:"filter"})})})})]})}function Al(){const t=s.useDashboardStore(r=>r.dashboard.filters),n=s.useDashboardStore(r=>r.theme),a=t==null?void 0:t.filter(r=>r.hide);return a!=null&&a.length?e.jsx("div",{className:s.cn("mb-1 flex items-center gap-2 border-y px-0.5 pb-0.5",{"bg-[repeating-linear-gradient(45deg,_#ffffff_0_3px,_#f3f3f3_3px_6px)]":n==="light","bg-[repeating-linear-gradient(45deg,_#18171d_0_3px,_#272729_3px_6px)]":n==="dark"}),children:a==null?void 0:a.map(r=>e.jsxs("div",{className:"flex min-w-[250px] max-w-fit flex-col gap-1 p-2",children:[e.jsx(s.FilterHeader,{filter:r}),e.jsx(s.FilterComponent,{filter:r})]},r.id))}):null}function Ml(){const t=s.useDashboardStore(r=>r.showFilters),n=s.useDashboardStore(r=>r.isVisualEditing),a=s.useDashboardStore(r=>r.isDashboardEditing);return e.jsxs("div",{role:"dashboard-plus-main",className:s.cn("",{"max-h-0 overflow-hidden":n,"flex grow overflow-auto":!n}),children:[e.jsxs("section",{className:"flex grow flex-col",children:[a&&e.jsx(Al,{}),e.jsx(s.DashboardTabs,{})]}),t&&e.jsx("div",{role:"filter-aside-container",className:"flex",children:e.jsx(Il,{})})]})}function Rl(){const t=s.useDashboardStore(l=>l.dashboard),n=s.useDashboardStore(l=>l.actions.setDashboard),a=s.useDashboardStore(l=>l.showDashboardJSON),r=s.useDashboardStore(l=>l.actions.setShowDashboardJSON);return e.jsxs("div",{className:s.cn("relative p-2",{hidden:!a}),children:[e.jsxs(s.Button,{variant:"secondary",size:"sm",className:"absolute right-2 top-2 z-10 h-8",onClick:()=>r(!1),children:[e.jsx(s.X,{className:"mr-2 h-4 w-4"}),"Close"]}),e.jsx(s.de,{onChange:l=>{if(l)try{JSON.parse(l),n(JSON.parse(l))}catch{}},defaultLanguage:"json",className:"h-[550px] overflow-y-auto",value:JSON.stringify(t,null,2),options:{minimap:{enabled:!1},glyphMargin:!1,wordWrap:"on",scrollbar:{verticalScrollbarSize:0,horizontalScrollbarSize:0},fontSize:12,renderLineHighlight:"none"}})]})}function Et(){return e.jsx(s.ScrollArea,{className:"w-full flex-1",children:e.jsxs("div",{className:"space-y-4 px-4",children:[e.jsx("div",{className:"animate-pulse",children:e.jsx("div",{className:"h-8 w-full rounded bg-muted"})}),e.jsx("div",{className:"animate-pulse",children:e.jsx("div",{className:"h-8 w-full rounded bg-muted"})}),e.jsx("div",{className:"space-y-2",children:[...Array(4)].map((t,n)=>e.jsx("div",{className:"animate-pulse",children:e.jsxs("div",{className:"group relative flex items-start gap-3 px-4 py-3",children:[e.jsx("div",{className:"flex-shrink-0",children:e.jsx("div",{className:"flex h-8 w-8 items-center justify-center rounded-md bg-muted"})}),e.jsxs("div",{className:"flex w-full items-start justify-between",children:[e.jsxs("div",{className:"flex-1",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"flex items-center gap-2",children:e.jsx("div",{className:"h-4 w-32 rounded bg-muted"})}),e.jsx("div",{className:"shrink-0",children:e.jsx("div",{className:"h-3.5 w-3.5 rounded bg-muted"})})]}),e.jsx("div",{className:"mt-0.5",children:e.jsx("div",{className:"h-3 w-48 rounded bg-muted"})})]}),e.jsx("div",{className:"absolute right-3 top-2",children:e.jsx("div",{className:"flex items-center opacity-0 transition-opacity duration-150 group-hover:opacity-100",children:e.jsx("div",{className:"h-6 w-6 rounded bg-muted"})})})]})]})},n))})]})})}const Ll=t=>{const n=s.useDashboardStore(l=>l.isVisualEditing),a=s.useDashboardStore(l=>l.selectedFrameId),r=s.useEditorStore(l=>l.frame);return!!(n&&a&&(r==null?void 0:r.visualId)===t)};function Fl({visual:t,isDeleting:n,isDuplicating:a,onAddVisual:r,onOpenVisual:l,onEditDetails:o,onDeleteClick:c,onDuplicateVisual:i,onShareVisual:d,formatDate:u}){var D,w,j,N;const{selectVisual:m}=s.useManagementActions(),x=s.useIsVisualSelected(t.id),h=Ll(t.id),{isConsoleMode:p}=s.useDashboardPreferences(),g=T.useRef(null),[f,y]=T.useState(!1),[v,C]=T.useState(!1);T.useEffect(()=>{a?(y(!0),C(!0)):v&&(y(!1),C(!1))},[a,v]),T.useEffect(()=>{h&&g.current&&g.current.scrollIntoView({behavior:"smooth",block:"center"})},[h]);const F=()=>e.jsx(He,{className:"h-4 w-4"}),k=()=>{m(t),l==null||l(t)};return e.jsx(s.Card,{ref:g,className:s.cn("group cursor-pointer border border-border/50 p-3 transition-colors hover:bg-accent/50",h?"border-purple-500":x&&"border-primary"),onClick:k,children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("div",{className:"mt-0.5 rounded bg-muted p-1.5",children:F()}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"mb-1 flex items-center gap-2",children:[e.jsx("p",{className:"text-sm font-medium text-foreground truncate",title:t.title||"Untitled Visual",children:t.title||"Untitled Visual"}),t.ownership.status==="shared"&&e.jsxs(s.Badge,{variant:"outline",className:"text-xs",children:[e.jsx(s.Users,{className:"mr-1 h-2.5 w-2.5"}),"Shared"]})]}),e.jsx("p",{className:"text-xs text-muted-foreground line-clamp-2",title:t.description||"No description",children:(D=t.description)!=null&&D.trim()?t.description:"No description"})]}),e.jsxs("div",{className:s.cn("invisible ml-2 flex flex-shrink-0 items-center gap-1 transition-opacity duration-150 group-hover:visible",x&&"visible"),onClick:b=>b.stopPropagation(),children:[e.jsx(s.Button,{size:"sm",variant:"ghost",className:"h-6 w-6 p-0",onClick:b=>{b.stopPropagation(),r(t)},title:"Add to dashboard",children:e.jsx(s.Plus,{className:"h-3.5 w-3.5"})}),t.ownership.isOwner&&e.jsx(s.Button,{size:"sm",variant:"ghost",className:"h-6 w-6 p-0",onClick:b=>{b.stopPropagation(),o==null||o(t)},title:"Edit details",children:e.jsx(Ye,{className:"h-3 w-3"})}),e.jsxs(s.DropdownMenu,{modal:!1,open:f,onOpenChange:y,children:[e.jsx(s.DropdownMenuTrigger,{asChild:!0,children:e.jsx(s.Button,{size:"sm",variant:"ghost",className:"h-6 w-6 p-0",children:e.jsx(s.Ellipsis,{className:"h-3 w-3"})})}),e.jsxs(s.DropdownMenuContent,{align:"end",className:"z-[51] w-40",children:[e.jsxs(s.DropdownMenuItem,{onClick:b=>{b.stopPropagation(),r(t)},children:[e.jsx(s.Plus,{className:"mr-2 h-3 w-3"}),"Add"]}),e.jsxs(s.DropdownMenuItem,{onClick:b=>{b.stopPropagation(),l==null||l(t)},children:[e.jsx(Ht,{className:"mr-2 h-3 w-3"}),"Open"]}),e.jsxs(s.DropdownMenuItem,{onClick:b=>{b.preventDefault(),b.stopPropagation(),i(t.id)},disabled:a,children:[a?e.jsx(s.LoaderCircle,{className:"mr-2 h-3 w-3 animate-spin"}):e.jsx(s.Copy,{className:"mr-2 h-3 w-3"}),a?"Duplicating...":"Duplicate"]}),t.ownership.isOwner&&e.jsxs(e.Fragment,{children:[e.jsxs(s.DropdownMenuItem,{onClick:b=>{b.stopPropagation(),o==null||o(t)},children:[e.jsx(Ye,{className:"mr-2 h-3 w-3"}),"Edit details"]}),e.jsxs(s.DropdownMenuItem,{onClick:b=>{b.stopPropagation(),d(t)},children:[e.jsx(s.Users,{className:"mr-2 h-3 w-3"}),"Share"]}),e.jsx(s.DropdownMenuSeparator,{}),e.jsxs(s.DropdownMenuItem,{onClick:b=>{b.stopPropagation(),c(t)},className:"text-destructive",disabled:n,children:[e.jsx(s.Trash2,{className:"mr-2 h-3 w-3"}),n?"Deleting...":"Delete"]})]}),e.jsx(s.DropdownMenuSeparator,{}),e.jsxs("div",{className:"space-y-1 px-2 py-2 text-xs text-slate-500 dark:text-slate-400",children:[(((w=t.ownership.createdBy)==null?void 0:w.type)==="tenant"||((j=t.ownership.createdBy)==null?void 0:j.type)==="organization"&&p)&&e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(s.User,{className:"h-3 w-3"}),e.jsx("span",{children:((N=t.ownership.createdBy)==null?void 0:N.name)||"Unknown"})]}),e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(s.Calendar,{className:"h-3 w-3"}),e.jsx("span",{children:u(t.lastModified)})]})]})]})]})]})]})},t.id)}function It({open:t,resourceLabel:n,initialTitle:a,initialDescription:r="",onClose:l,onSave:o,isSaving:c=!1}){const[i,d]=T.useState(a),[u,m]=T.useState(r??"");T.useEffect(()=>{t&&(d(a),m(r??""))},[t,a,r]);const x=h=>{h.preventDefault();const p=i.trim();p&&o({title:p,description:u.trim()})};return e.jsx(s.Dialog,{open:t,onOpenChange:h=>h?null:l(),children:e.jsx(s.DialogContent,{className:"sm:max-w-md",children:e.jsxs("form",{onSubmit:x,className:"space-y-4",children:[e.jsxs(s.DialogHeader,{children:[e.jsxs(s.DialogTitle,{children:["Edit ",n]}),e.jsxs(s.DialogDescription,{children:["Update the title and description for this ",n.toLowerCase(),"."]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(s.Label,{htmlFor:"resource-title",children:"Title"}),e.jsx(s.Input,{id:"resource-title",value:i,onChange:h=>d(h.target.value),placeholder:`Enter ${n.toLowerCase()} title`,autoFocus:!0})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(s.Label,{htmlFor:"resource-description",children:"Description"}),e.jsx(s.Textarea,{id:"resource-description",value:u,onChange:h=>m(h.target.value),placeholder:`Enter ${n.toLowerCase()} description (optional)`,rows:3})]}),e.jsxs(s.DialogFooter,{className:"mt-6 flex justify-end gap-2 sm:justify-end",children:[e.jsx(s.Button,{type:"button",variant:"outline",onClick:l,disabled:c,children:"Cancel"}),e.jsx(s.Button,{type:"submit",disabled:c||!i.trim(),children:c?"Saving...":"Save changes"})]})]})})})}function Ol({open:t,onOpenChange:n,onSubmit:a,isCreating:r}){const[l,o]=T.useState(""),[c,i]=T.useState("");T.useEffect(()=>{t||(o(""),i(""))},[t]);const d=()=>{l.trim()&&a({title:l,description:c})},u=m=>{n(m)};return e.jsx(s.Dialog,{open:t,onOpenChange:u,children:e.jsxs(s.DialogContent,{children:[e.jsxs(s.DialogHeader,{children:[e.jsx(s.DialogTitle,{children:"Create New Visual"}),e.jsx(s.DialogDescription,{children:"Add a new visual to your library. You can configure it after creation."})]}),e.jsxs("div",{className:"space-y-4 py-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(s.Label,{htmlFor:"title",children:"Visual Title"}),e.jsx(s.Input$1,{id:"title",placeholder:"Enter visual title...",value:l,onChange:m=>o(m.target.value),disabled:r,onKeyDown:m=>{m.key==="Enter"&&!m.shiftKey&&(m.preventDefault(),d())}})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(s.Label,{htmlFor:"description",children:"Description (optional)"}),e.jsx(s.Input$1,{id:"description",placeholder:"Enter visual description...",value:c,onChange:m=>i(m.target.value),disabled:r})]})]}),e.jsxs(s.DialogFooter,{children:[e.jsx(s.Button,{variant:"outline",onClick:()=>u(!1),disabled:r,children:"Cancel"}),e.jsx(s.Button,{onClick:d,disabled:!l.trim()||r,children:r?e.jsxs(e.Fragment,{children:[e.jsx(s.LoaderCircle,{className:"mr-2 h-4 w-4 animate-spin"}),"Creating..."]}):"Create Visual"})]})]})})}function Pl(){const[t,n]=T.useState(""),[a,r]=T.useState(!1),[l,o]=T.useState(!1),[c,i]=T.useState(null),[d,u]=T.useState(!1),[m,x]=T.useState(null),[h,p]=T.useState(null),[g,f]=T.useState(null),{selectVisual:y}=s.useManagementActions(),{handleEditLibraryVisual:v,handleAddLibraryVisual:C}=Ae(),{resources:F,isLoading:k,isError:D,createResource:w,updateResource:j,deleteResource:N,duplicateResource:b,isCreating:R,isDeleting:S}=s.useVisualManagement(()=>{u(!1),x(null)},q=>{r(!1),q&&(y(q),v(q))});s.useCurrentUserInfo();const O=F.filter(q=>{var ae,J;return((ae=q==null?void 0:q.title)==null?void 0:ae.toLowerCase().includes(t.toLowerCase()))||((J=q==null?void 0:q.description)==null?void 0:J.toLowerCase().includes(t.toLowerCase()))}),E=q=>new Date(q).toLocaleDateString("en-US",{month:"short",day:"numeric",year:"numeric"}),I=q=>{w({title:q.title,description:q.description,isPrivate:!1})},A=q=>{x(q),u(!0)},M=()=>{m&&N(m.id)},{startUpdating:L,stopUpdating:P,isUpdating:B}=s.useResourceUpdateState(),K=(q,ae,J)=>{var ce;const re=Object.fromEntries(Object.entries(ae).filter(([,le])=>le!==void 0));if(Object.keys(re).length===0){(ce=J==null?void 0:J.onSuccess)==null||ce.call(J);return}const G=Object.keys(re),se=G.length===1?G[0]:void 0;L(q,se),j({resourceId:q,data:re},{onSuccess:()=>{var le;P(q,se),(le=J==null?void 0:J.onSuccess)==null||le.call(J)},onError:()=>{var le;P(q,se),(le=J==null?void 0:J.onError)==null||le.call(J)}})},_=q=>{p(q),b(q,{onSettled:()=>p(null)})},z=q=>{v(q)},U=q=>{C(q)},W=q=>{const ae=F.find(J=>J.id===q);ae&&j({resourceId:q,data:{isPrivate:!ae.isPrivate}})},ee=q=>{i(q),o(!0)},te=q=>{f(q)},oe=()=>{f(null)},H=({title:q,description:ae})=>{if(!g)return;const J={};q!==g.title&&(J.title=q),(g.description||"")!==ae&&(J.description=ae),K(g.id,J,{onSuccess:()=>{f(null)}})};return k?e.jsx(Et,{}):D?e.jsx(s.ScrollArea,{className:"w-full flex-1 pr-2",children:e.jsxs("div",{className:"py-8 text-center text-muted-foreground",children:[e.jsx("p",{className:"text-sm text-destructive",children:"Failed to load visuals"}),e.jsx(s.Button,{variant:"outline",size:"sm",className:"mt-2",onClick:()=>window.location.reload(),children:"Retry"})]})}):e.jsxs("div",{className:"relative flex h-full flex-1 flex-col gap-4",children:[F&&F.length>5&&e.jsx("div",{className:"space-y-2",children:e.jsx(s.Input$1,{id:"search",placeholder:"Search by title or description...",value:t,onChange:q=>n(q.target.value),className:"h-9"})}),e.jsx("div",{className:"flex flex-1 flex-col",children:e.jsx("div",{className:"flex flex-1 basis-0 flex-col gap-3 overflow-y-auto",children:O.length===0?e.jsxs("div",{className:"py-8 text-center",children:[e.jsx("div",{className:"mb-3",children:e.jsx(He,{className:"mx-auto h-12 w-12 text-muted-foreground/50"})}),e.jsx("h3",{className:"mb-1 font-medium text-foreground",children:t?"No visuals found":"No visuals yet"}),e.jsx("p",{className:"mb-4 text-sm text-muted-foreground",children:t?"Try adjusting your search":"Create your first visual component to get started"}),!t&&e.jsxs(s.Button,{size:"sm",className:"bg-primary hover:bg-primary/90",onClick:()=>r(!0),children:[e.jsx(s.Plus,{className:"mr-2 h-4 w-4"}),"Create Visual"]})]}):O.map(q=>e.jsx(Fl,{visual:q,onAddVisual:U,onOpenVisual:z,onEditDetails:te,onDeleteClick:A,onDuplicateVisual:_,onTogglePrivacy:W,onShareVisual:ee,isDeleting:S,isDuplicating:h===q.id,formatDate:E},q.id))})}),l&&c&&e.jsx(We,{resource:c,resourceType:s.ResourceType.VISUAL,onClose:()=>{o(!1),i(null)}}),g&&e.jsx(It,{open:!!g,resourceLabel:"Visual",initialTitle:g.title||"",initialDescription:g.description||"",onClose:oe,onSave:H,isSaving:B(g.id)}),e.jsx(s.AlertDialog,{open:d,onOpenChange:q=>{!q&&S||(u(q),q||x(null))},children:e.jsxs(s.AlertDialogContent,{children:[e.jsxs(s.AlertDialogHeader,{children:[e.jsx(s.AlertDialogTitle,{children:"Delete Visual"}),e.jsxs(s.AlertDialogDescription,{children:['Are you sure you want to delete "',m==null?void 0:m.title,'"? This action cannot be undone.']})]}),e.jsxs(s.AlertDialogFooter,{children:[e.jsx(s.AlertDialogCancel,{disabled:S,children:"Cancel"}),e.jsxs(s.AlertDialogAction,{onClick:q=>{q.preventDefault(),q.stopPropagation(),M()},className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",disabled:S,children:[S?e.jsx(s.LoaderCircle,{className:"mr-2 h-3.5 w-3.5 animate-spin"}):e.jsx(s.Trash2,{className:"mr-2 h-3.5 w-3.5"}),S?"Deleting...":"Delete"]})]})]})}),e.jsx(Ol,{open:a,onOpenChange:r,onSubmit:I,isCreating:R}),e.jsx(s.Button,{size:"icon",className:"absolute bottom-2 left-2 h-11 w-11 rounded-full shadow-lg shadow-black/15",onClick:()=>r(!0),"aria-label":"Create visual",children:e.jsx(s.Plus,{className:"h-5 w-5"})})]})}function Bl({dashboard:t,isDeleting:n,isDuplicating:a,onLoadDashboard:r,onEditDetails:l,onDeleteClick:o,onDuplicateDashboard:c,onShareDashboard:i,formatDate:d,onDashboardItemClick:u}){var N,b,R,S,O;const{selectDashboard:m}=s.useManagementActions(),x=s.useIsDashboardSelected(t.id),{isConsoleMode:h}=s.useDashboardPreferences(),{currentUser:p,isLoading:g,isError:f}=s.useCurrentUserInfo(),y=!f&&(p==null?void 0:p.type)==="tenant"&&((N=p==null?void 0:p.role)==null?void 0:N.toUpperCase())==="VIEWER",v=g||y,[C,F]=T.useState(!1),[k,D]=T.useState(!1);T.useEffect(()=>{a?(F(!0),D(!0)):k&&(F(!1),D(!1))},[a,k]);const w=()=>e.jsx(s.ChartColumn,{className:"h-4 w-4"}),j=()=>{m(t),r(t.id),u==null||u(t.id)};return e.jsx(s.Card,{className:s.cn("group cursor-pointer border border-border/50 p-3 transition-colors hover:bg-accent/50",x&&"border-primary"),onClick:j,children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("div",{className:"mt-0.5 rounded bg-muted p-1.5",children:w()}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"mb-1 flex items-center gap-2",children:[e.jsx("p",{className:"text-sm font-medium text-foreground truncate",title:t.title||"Untitled Dashboard",children:t.title||"Untitled Dashboard"}),t.ownership.status==="shared"&&e.jsxs(s.Badge,{variant:"outline",className:"text-xs",children:[e.jsx(s.Users,{className:"mr-1 h-2.5 w-2.5"}),"Shared"]})]}),e.jsx("p",{className:"text-xs text-muted-foreground line-clamp-2",title:t.description||"No description",children:(b=t.description)!=null&&b.trim()?t.description:"No description"})]}),e.jsxs("div",{className:"invisible ml-2 flex flex-shrink-0 items-center gap-1 transition-opacity duration-150 group-hover:visible",onClick:E=>E.stopPropagation(),children:[t.permissions.canEdit&&!v&&e.jsx(s.Button,{size:"sm",variant:"ghost",className:"h-6 w-6 p-0",onClick:E=>{E.stopPropagation(),l==null||l(t)},title:"Edit details",children:e.jsx(Ye,{className:"h-3 w-3"})}),!v&&e.jsxs(s.DropdownMenu,{modal:!1,open:C,onOpenChange:F,children:[e.jsx(s.DropdownMenuTrigger,{asChild:!0,children:e.jsx(s.Button,{size:"sm",variant:"ghost",className:"h-6 w-6 p-0",children:e.jsx(s.Ellipsis,{className:"h-3 w-3"})})}),e.jsxs(s.DropdownMenuContent,{align:"end",className:"z-[51] w-40",children:[e.jsxs(s.DropdownMenuItem,{onClick:E=>{E.preventDefault(),E.stopPropagation(),c(t.id)},disabled:a,children:[a?e.jsx(s.LoaderCircle,{className:"mr-2 h-3 w-3 animate-spin"}):e.jsx(s.Copy,{className:"mr-2 h-3 w-3"}),a?"Duplicating...":"Duplicate"]}),t.permissions.canEdit&&e.jsxs(s.DropdownMenuItem,{onClick:E=>{E.stopPropagation(),l==null||l(t)},children:[e.jsx(Ye,{className:"mr-2 h-3 w-3"}),"Edit details"]}),t.permissions.canEdit&&e.jsx(e.Fragment,{children:e.jsxs(s.DropdownMenuItem,{onClick:E=>{E.stopPropagation(),i(t)},children:[e.jsx(s.Users,{className:"mr-2 h-3 w-3"}),"Share"]})}),t.permissions.canDelete&&e.jsxs(e.Fragment,{children:[e.jsx(s.DropdownMenuSeparator,{}),e.jsxs(s.DropdownMenuItem,{onClick:E=>{E.stopPropagation(),o(t)},className:"text-destructive",disabled:n,children:[e.jsx(s.Trash2,{className:"mr-2 h-3 w-3"}),n?"Deleting...":"Delete"]})]}),e.jsx(s.DropdownMenuSeparator,{}),e.jsxs("div",{className:"space-y-1 px-2 py-2 text-xs text-slate-500 dark:text-slate-400",children:[(((R=t.ownership.createdBy)==null?void 0:R.type)==="tenant"||((S=t.ownership.createdBy)==null?void 0:S.type)==="organization"&&h)&&e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(s.User,{className:"h-3 w-3"}),e.jsx("span",{children:((O=t.ownership.createdBy)==null?void 0:O.name)||"Unknown"})]}),e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(s.Calendar,{className:"h-3 w-3"}),e.jsx("span",{children:d(t.lastModified)})]})]})]})]})]})]})},t.id)}function Vl({onRetry:t}){return e.jsx(s.ScrollArea,{className:"w-full flex-1 pr-2",children:e.jsxs("div",{className:"py-8 text-center text-muted-foreground",children:[e.jsx("p",{className:"text-sm text-destructive",children:"Failed to load dashboards"}),e.jsx(s.Button,{variant:"outline",size:"sm",className:"mt-2",onClick:t,children:"Retry"})]})})}function zl(t){const{onLoadDashboard:n,onEditDashboard:a,onDashboardItemClick:r}=t,[l,o]=T.useState(""),[c,i]=T.useState(!1),[d,u]=T.useState(!1),[m,x]=T.useState(null),[h,p]=T.useState(!1),[g,f]=T.useState(null),[y,v]=T.useState(null),[C,F]=T.useState(null),k=s.useManagementStore(Q=>Q.lastSelectedDashboard),D=s.useManagementStore(Q=>Q.selectedDashboard),w=s.useManagementStore(Q=>Q.actions.selectDashboard),j=s.useManagementStore(Q=>Q.actions.clearSelectedDashboard),{tokenProps:N,id:b}=s.useSemaphorContext(),{permissions:R}=s.useRoleAwareDisplayPreferences(),{onCreateSuccess:S}=s.useDashboardCreation({onDashboardSelect:r}),{resources:O,isLoading:E,isError:I,createResource:A,updateResource:M,deleteResource:L,duplicateResource:P,isCreating:B,isDeleting:K,refetch:_}=s.useDashboardManagement(()=>{p(!1);const Q=g==null?void 0:g.id;f(null),(D==null?void 0:D.id)===Q&&(!(N!=null&&N.dashboard_id)&&!b?j():k&&k.id!==Q&&w(k))},Q=>{i(!1),S(Q,_)}),{currentUser:z}=s.useCurrentUserInfo(),U=O.filter(Q=>{var $,V;return(($=Q==null?void 0:Q.title)==null?void 0:$.toLowerCase().includes(l.toLowerCase()))||((V=Q==null?void 0:Q.description)==null?void 0:V.toLowerCase().includes(l.toLowerCase()))}),W=Q=>new Date(Q).toLocaleDateString("en-US",{month:"short",day:"numeric",year:"numeric"}),ee=Q=>{A({title:Q.title,description:Q.description,isPrivate:!1})},te=Q=>{n==null||n(Q)},oe=Q=>{f(Q),p(!0)},H=()=>{g&&L(g.id)},q=Q=>{v(Q),P(Q,{onSettled:()=>v(null)})},{startUpdating:ae,stopUpdating:J,isUpdating:re}=s.useResourceUpdateState(),G=(Q,$,V)=>{var ne;const Z=Object.fromEntries(Object.entries($).filter(([,me])=>me!==void 0));if(Object.keys(Z).length===0){(ne=V==null?void 0:V.onSuccess)==null||ne.call(V);return}const ie=Object.keys(Z),de=ie.length===1?ie[0]:void 0;ae(Q,de),M({resourceId:Q,data:Z},{onSuccess:()=>{var me;J(Q,de),(me=V==null?void 0:V.onSuccess)==null||me.call(V)},onError:()=>{var me;J(Q,de),(me=V==null?void 0:V.onError)==null||me.call(V)}})},se=Q=>{const $=O.find(V=>V.id===Q);$&&M({resourceId:Q,data:{isPrivate:!$.isPrivate}})},ce=Q=>{x(Q),z==null||z.type,u(!0)},le=Q=>{a==null||a(Q.id),F(Q)},fe=()=>{F(null)},ue=({title:Q,description:$})=>{if(!C)return;const V={};Q!==C.title&&(V.title=Q),(C.description||"")!==$&&(V.description=$),G(C.id,V,{onSuccess:()=>{F(null)}})};return E?e.jsx(Et,{}):I?e.jsx(Vl,{onRetry:()=>window.location.reload()}):e.jsxs("div",{className:"relative flex h-full flex-1 flex-col gap-4",children:[O&&O.length>5&&e.jsx("div",{className:"space-y-2",children:e.jsx(s.Input$1,{id:"search",placeholder:"Search by title or description...",value:l,onChange:Q=>o(Q.target.value),className:"h-9"})}),e.jsx("div",{className:"flex flex-1 flex-col",children:e.jsx("div",{className:"flex flex-1 basis-0 flex-col gap-3 overflow-y-auto",children:U.length===0?e.jsxs("div",{className:"py-8 text-center",children:[e.jsx("div",{className:"mb-3",children:e.jsx(s.ChartColumn,{className:"mx-auto h-12 w-12 text-muted-foreground/50"})}),e.jsx("h3",{className:"mb-1 font-medium text-foreground",children:l?"No dashboards found":"No dashboards yet"}),e.jsx("p",{className:"mb-4 text-sm text-muted-foreground",children:l?"Try adjusting your search":R.canCreateDashboards?"Create your first dashboard to get started":"No dashboards have been shared with you yet"}),R.canCreateDashboards&&!l&&e.jsxs(s.Button,{size:"sm",className:"bg-primary hover:bg-primary/90",onClick:()=>i(!0),children:[e.jsx(s.Plus,{className:"mr-2 h-4 w-4"}),"Create Dashboard"]})]}):U.map(Q=>e.jsx(Bl,{dashboard:Q,isDeleting:K,isDuplicating:y===Q.id,onLoadDashboard:te,onEditDetails:le,onDeleteClick:oe,onDuplicateDashboard:q,onTogglePrivacy:se,onShareDashboard:ce,formatDate:W,onDashboardItemClick:r},Q.id))})}),d&&m&&e.jsx(We,{resource:m,resourceType:s.ResourceType.DASHBOARD,onClose:()=>{u(!1),x(null)}}),e.jsx(s.AlertDialog,{open:h,onOpenChange:Q=>{!Q&&K||(p(Q),Q||f(null))},children:e.jsxs(s.AlertDialogContent,{children:[e.jsxs(s.AlertDialogHeader,{children:[e.jsx(s.AlertDialogTitle,{children:"Delete Dashboard"}),e.jsxs(s.AlertDialogDescription,{children:['Are you sure you want to delete "',g==null?void 0:g.title,'"? This action cannot be undone.']})]}),e.jsxs(s.AlertDialogFooter,{children:[e.jsx(s.AlertDialogCancel,{disabled:K,children:"Cancel"}),e.jsxs(s.AlertDialogAction,{onClick:Q=>{Q.preventDefault(),Q.stopPropagation(),H()},className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",disabled:K,children:[K?e.jsx(s.LoaderCircle,{className:"mr-2 h-3.5 w-3.5 animate-spin"}):e.jsx(s.Trash2,{className:"mr-2 h-3.5 w-3.5"}),K?"Deleting...":"Delete"]})]})]})}),C&&e.jsx(It,{open:!!C,resourceLabel:"Dashboard",initialTitle:C.title||"",initialDescription:C.description||"",onClose:fe,onSave:ue,isSaving:re(C.id)}),e.jsx(s.CreateDashboardDialog,{open:c,onOpenChange:i,onSubmit:ee,isCreating:B}),R.canCreateDashboards&&e.jsx(s.Button,{size:"icon",className:"absolute bottom-2 left-2 h-11 w-11 rounded-full shadow-lg shadow-black/15",onClick:()=>i(!0),"aria-label":"Create dashboard",children:e.jsx(s.Plus,{className:"h-5 w-5"})})]})}function At({isOpen:t,onClose:n,className:a,onDashboardItemClick:r,variant:l="inline"}){s.useDashboardStore(D=>D.dashboard);const{setDashboard:o,addSheet:c}=s.useDashboardStore(D=>D.actions),{currentUser:i}=s.useCurrentUserInfo(),d=i,{permissions:u}=s.useRoleAwareDisplayPreferences(),x=s.useSelectedDashboard()&&u.canAccessVisuals,h="dashboards",[p,g]=hs("resource-management-active-tab",h),f=x?p:"dashboards",y=l==="overlay",v=Ks(n,{enabled:t&&y}),C=s.cn("flex h-full flex-col border-r bg-background",y?s.cn("absolute inset-y-0 left-0 z-[51] w-96 shadow-lg transition-transform duration-300 ease-in-out",t?"translate-x-0":"pointer-events-none -translate-x-full"):"w-full max-w-[28rem] min-w-[18rem] overflow-hidden shadow-sm",a),F=D=>{},k=D=>{console.log("Editing dashboard:",D)};return e.jsx(s.TooltipProvider,{children:(!y||t)&&e.jsxs("div",{ref:v,className:C,children:[e.jsxs("div",{className:"flex items-center justify-between border-b border-border p-4",children:[e.jsx("div",{className:"flex items-center gap-2",children:d&&e.jsxs(e.Fragment,{children:[e.jsxs(s.Tooltip,{children:[e.jsx(s.TooltipTrigger,{asChild:!0,children:e.jsx("div",{className:"flex h-8 w-8 cursor-default items-center justify-center rounded-full bg-primary/10",children:e.jsx("span",{className:"text-sm font-medium text-primary",children:d.name.charAt(0).toUpperCase()})})}),e.jsx(s.TooltipContent,{side:"bottom",className:"ml-2 max-w-xs",children:e.jsxs("div",{className:"space-y-1",children:[e.jsx("div",{className:"font-medium",children:d.name}),e.jsx("div",{className:"text-xs text-muted-foreground",children:d.email}),d.role&&e.jsxs("div",{className:"text-xs text-muted-foreground",children:["Role:"," ",s.toTitleCase(d.role.replace(/_/g," "))]}),e.jsxs("div",{className:"text-xs text-muted-foreground",children:["ID: ",d.id]})]})})]}),e.jsx("div",{className:"flex items-center gap-2",children:e.jsx("span",{className:"text-sm font-medium text-foreground",children:d.name})})]})}),e.jsx(s.IconButton,{className:"h-8 w-8 p-0 text-muted-foreground hover:text-foreground",onClick:n,tooltip:"Close Sidebar",children:e.jsx(ia,{className:"h-4 w-4"})})]}),e.jsx("div",{className:"flex flex-1 flex-col overflow-hidden",children:e.jsxs(s.Tabs,{value:f,onValueChange:x?g:void 0,className:"flex h-9 grow flex-col",children:[x&&e.jsx("div",{className:"px-4 pt-4",children:e.jsxs(s.TabsList,{className:"grid w-full grid-cols-2",children:[e.jsx(s.TabsTrigger,{value:"dashboards",className:"text-sm",children:"Dashboards"}),e.jsx(s.TabsTrigger,{value:"visuals",className:"text-sm",children:"Visuals"})]})}),e.jsx(s.TabsContent,{value:"dashboards",className:"flex-1 px-4 py-4",children:e.jsx(zl,{onLoadDashboard:F,onEditDashboard:k,onDashboardItemClick:r})}),x&&e.jsx(s.TabsContent,{value:"visuals",className:"flex-1 px-4 py-4",children:e.jsx(Pl,{})})]})})]})})}function Ul({showControls:t=!1,showFooter:n=!0,...a}){const r=s.useDashboardStore(h=>h.isDashboardPanelOpen);s.useDashboardStore(h=>h.isVisualEditing);const l=s.useDashboardStore(h=>h.actions.setIsDashboardPanelOpen),o=20,c=20,i=30,d=r,u=T.useRef(null),m=T.useRef(null);T.useEffect(()=>{u.current&&m.current&&(r?(u.current.resize(o),m.current.resize(100-o)):(u.current.resize(0),m.current.resize(100)))},[r]);const{preferences:x}=a;return e.jsx(s.ErrorBoundary,{FallbackComponent:s.Fallback,children:e.jsxs(s.SemaphorContextProvider,{dashboardProps:a,children:[e.jsx(s.$e,{}),e.jsx(s.UXProvider,{children:e.jsxs(s.DashboardPreferencesProvider,{preferences:x,children:[e.jsx(Rl,{}),e.jsxs("main",{className:"relative flex h-full w-full flex-col",children:[t&&e.jsx(gn,{}),e.jsxs(s.ResizablePanelGroup,{direction:"horizontal",className:"flex grow overflow-hidden",children:[e.jsx(s.ResizablePanel,{ref:u,className:s.cn("flex h-full max-w-[26rem] overflow-hidden",{"min-w-[20rem]":d}),defaultSize:d?o:0,minSize:d?c:0,maxSize:d?i:0,children:e.jsx(At,{isOpen:r,onClose:()=>l(!1),variant:"inline"})}),e.jsx(s.ResizableHandle,{withHandle:d,className:s.cn("w-1",{"w-0":!d})}),e.jsx(s.ResizablePanel,{ref:m,className:"flex min-w-0 flex-1",defaultSize:d?100-o:100,minSize:d?40:100,children:e.jsxs(s.Container,{...a,type:"dashboard",children:[e.jsx(kl,{}),e.jsx(Ml,{})]})})]})]})]})})]})})}exports.AdvancedModeToggle=at;exports.DashboardPlus=Ul;exports.ResourceManagementPanel=At;exports.ScheduleDashboard=_s;exports.ShareDialog=We;exports.VisualBadge=et;exports.VisualEditingControls=tt;exports.cleanCard=Gs;exports.getDashbaordStateWithoutData=Ke;
|