react-semaphor 0.1.24 → 0.1.26
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-CMp3oxNw.js → dashboard-plus-BZ8k_sGe.js} +2 -2
- package/dist/chunks/{dashboard-plus-GkFNN0KA.js → dashboard-plus-qMRXHdYf.js} +4 -5
- package/dist/chunks/{index-B4jH4p_x.js → index-Bo0bvCRT.js} +63 -63
- package/dist/chunks/{index-BTJ5Owu2.js → index-CE57mw6l.js} +4107 -4132
- 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-Bo0bvCRT.js"),k=require("react"),Vt=require("react-dom");function zt(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=zt(k);/**
|
|
2
2
|
* @license lucide-react v0.453.0 - ISC
|
|
3
3
|
*
|
|
4
4
|
* This source code is licensed under the ISC license.
|
|
@@ -276,5 +276,5 @@ ${j.joinType} JOIN ${N.name}
|
|
|
276
276
|
${u?`Python:
|
|
277
277
|
${u}`:""}
|
|
278
278
|
`;L(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(Pn,{jsonString:JSON.stringify(m,null,2)})})}),m&&m.length>0&&e.jsx(s.Button,{variant:"ghost",onClick:()=>c(!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 q(){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(Fn,{})}),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(On,{})}),e.jsx("code",{className:"absolute right-6 top-3 text-xs text-muted-foreground/70",children:"python"})]})]})]})}function Y(){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:v||R,onClick:()=>{O()},className:"h-8 shrink-0",size:"sm",children:[v||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(Rn,{errorSql:T,sql:y==null?void 0:y.sql,error:E,onDebugWithAssistant:P}),e.jsx(is,{}),e.jsx(s.Toggle,{pressed:a,onPressedChange:z=>r(z),className:"h-8",size:"sm",variant:"outline",children:e.jsx(Ln,{className:"size-4 text-foreground/70"})}),e.jsx("button",{disabled:o,onClick:()=>{A(!0)},className:"h-9 w-full cursor-text px-3 text-left text-sm text-muted-foreground",children:o?"":"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:[q(),B()]}),Y()]})}const Vn=[{value:"table",label:"Table",icon:s.Table2},{value:"aggregateTable",label:"Aggregate",icon:s.Layers},{value:"pivotTable",label:"Pivot",icon:Qe}];function zn({className:t}){const n=s.useEditorStore(i=>i.card),{setCardType:a,setCard:r,updateCardInFrame:l}=s.useEditorActions(),c=["table","aggregateTable","pivotTable"].includes(n.type),d=s.hasValidCardConfig(n.config);if(!c||!d)return null;const o=i=>{var m;const u=i;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:o,className:"flex flex-row items-center justify-between gap-1 rounded-lg border p-1",children:Vn.map(i=>{const u=i.icon,m=n.type===i.value;return e.jsxs("div",{className:"flex items-center",children:[e.jsx(s.RadioGroupItem,{value:i.value,id:`table-type-${i.value}`,className:"peer sr-only"}),e.jsxs(s.Label,{htmlFor:`table-type-${i.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"}),i.label]})]},i.value)})})})}function Un({card:t}){var L,A,w,D,g,y,v,R,S,F,I;const[n,a]=k.useState(!1),[r,l]=k.useState([]),{authToken:c}=s.useSemaphorContext(),{theme:d}=s.useTheme(),o=s.getTokenParams(c==null?void 0:c.accessToken),i=s.useDashboardStore(T=>T.themeStyle),u={mode:d||"system",colors:((A=(L=i==null?void 0:i.chart)==null?void 0:L.dataset)==null?void 0:A.backgroundColor)||[]};(w=t.customCardPreferences)!=null&&w.inputData;const{getCard:m}=s.useCustomVisual(((D=t.customCardPreferences)==null?void 0:D.url)||""),x=((g=t.customCardPreferences)==null?void 0:g.visualType)||"single",h=s.useEditorStore(T=>T.frame),{setCustomCardPreferences:p}=s.useEditorActions(),{data:b}=s.useDashboardCardQuery(t),f=k.useCallback((T,M)=>{l(O=>({...O,[T]:M}))},[]);if(!((y=t.customCardPreferences)!=null&&y.componentName))return null;const j=m((v=t.customCardPreferences)==null?void 0:v.componentName);function N(T){a(T)}const C=Object.keys(((R=t.customCardPreferences)==null?void 0:R.dataInputCardIds)||{}).map(T=>{var E,P,B;const M=(P=(E=t.customCardPreferences)==null?void 0:E.dataInputCardIds)==null?void 0:P[T].cardId,O=(B=h==null?void 0:h.cards)==null?void 0:B.find(q=>q.id===M);return O||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(k.Suspense,{fallback:e.jsx(e.Fragment,{}),children:[j&&x==="single"&&e.jsx(j,{editing:!0,params:o,theme:u,settings:(S=t.customCardPreferences)==null?void 0:S.settings,onDataChange:f,data:(b==null?void 0:b.records)||[]}),j&&x==="multiple"&&e.jsxs(e.Fragment,{children:[Object.keys(((F=t.customCardPreferences)==null?void 0:F.dataInputCardIds)||{}).map(T=>{var E,P,B;const M=(P=(E=t.customCardPreferences)==null?void 0:E.dataInputCardIds)==null?void 0:P[T].cardId,O=(B=h==null?void 0:h.cards)==null?void 0:B.find(q=>q.id===M);if(O)return e.jsx(s.MultiInputEmptyRenderer,{onLoadingStatus:N,onDataChange:f,dataInputIndex:T,card:O},O.id+T)}),e.jsx("div",{className:"flex flex-col gap-2",children:e.jsx(j,{theme:u,onDataChange:f,settings:C.map(T=>{var M;return(M=T==null?void 0:T.customCardPreferences)==null?void 0:M.settings}),data:C.map(T=>T!=null&&T.id?r==null?void 0:r[T.id]:[])})})]})]},(I=t.customCardPreferences)==null?void 0:I.componentName)})}function ft({className:t,...n}){var y;const a=s.useEditorStore(v=>v.card),r=s.hasValidCardConfig(a.config),l=((y=a.customCardPreferences)==null?void 0:y.showCardHeader)??!0,c=s.useEditorStore(v=>v.frame),d=s.useDashboardStore(v=>v.dashboard.filters),o=s.useEditorStore(v=>v.actions.setRunSql),{updateFilter:i}=s.useDashboardActions(),u=d==null?void 0:d.find(v=>v.id===c.filterId),{data:m,isLoading:x,isFetching:h,errorMessage:p,pagination:b}=s.useDashboardCardQuery(a),{setCard:f,updateCardInFrame:j}=s.useEditorActions(),{data:N}=s.useTopoJson(a),C=k.useMemo(()=>{var v;return a.type!=="pivotTable"||!((v=m==null?void 0:m.records)!=null&&v.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]),L=s.usePivotTableConfig(a,C),A=(v,R)=>{var F,I;const S={...a,paginationConfig:{page:v+1,pageSize:R}};f(S),j(S),a.sql&&((I=(F=a.preferences)==null?void 0:F.tablePrefs)!=null&&I.enableDevModePagination)&&o(!0)},w=k.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:N}),[a.id,m==null?void 0:m.records,a.type,a.queryConfig,a.customCfg,a.preferences,N]);function D(v){return e.jsx(s.ErrorBoundary,{FallbackComponent:s.FallbackVisual,children:e.jsx(Un,{card:v})})}function g(){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 D(a);if(!["table","pivotTable","aggregateTable","custom"].includes(a.type)&&w)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:w})});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:b,onPaginationChange:A,isLoading:x||h})});if(a.type==="pivotTable"&&L)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:L.data,options:L.options,onAggregationChange:v=>{const R=s.handleAggregationChange(v,a.config),S={...a,config:R};f(S),j(S)},onAggregationLabelChange:v=>{const R=s.handleAggregationLabelChange(v,a.config),S={...a,config:R};f(S),j(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:b,onPaginationChange:A,onAggregationChange:v=>{const R=s.handleAggregationChange(v,a.config),S={...a,config:R};f(S),j(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:v=>f({...a,title:v}),isEditable:!0,placeholder:"Add title",displayClassName:"text-base font-semibold",inputClassName:"text-base font-semibold"})}),e.jsx(zn,{})]}),e.jsx("div",{className:"w-1/2",children:e.jsx(s.EditableText,{value:a.description||"",onSave:v=>f({...a,description:v}),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:v=>i({...u,title:v}),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:g()})]})}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}),_n=()=>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."})]})]}),Gn=({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})})]}),$n=({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 Yn(){const[t,n]=k.useState(!1),[a,r]=k.useState(""),[l,c]=k.useState(""),[d,o]=k.useState(""),[i,u]=k.useState(""),m=s.useEditorStore(w=>w.card),x=s.useEditorStore(w=>w.card.customCfg),h=x?JSON.stringify(x,null,2):"",{data:p}=s.useDashboardCardQuery(m),{data:b}=s.useTopoJson(m),{setCardCustomCfg:f,setCustomVisualCode:j}=s.useEditorActions(),N=w=>{var D,g;return JSON.stringify({...w,data:{...w.data,datasets:(g=(D=w.data)==null?void 0:D.datasets)==null?void 0:g.map(y=>({...y,data:[]}))}},null,2)},C=()=>{var D,g;if(!((D=p==null?void 0:p.records)!=null&&D.length))return;const w=s.createChartConfig({card:m,data:p.records,cardType:m.type,queryConfig:m.queryConfig,preferences:m.preferences,topoJson:b});if(w){r(N(w)),o(((g=m.preferences)==null?void 0:g.customVisualCode)||"");const y=s.merge(w,x);c(N(y))}},L=()=>{try{if(d&&j(d),l){const w=JSON.parse(l),D=s.getObjectDiff(JSON.parse(a),w);f(D),u("")}}catch{u("Invalid JSON configuration")}},A=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:A?"":"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(_n,{}),e.jsxs("div",{className:"flex grow gap-2",children:[e.jsx(s.ErrorBoundary,{FallbackComponent:s.FallbackVisual,children:e.jsx(ft,{className:"w-1/2 rounded shadow-none"})}),e.jsx(Gn,{customCode:d,cardCustomCfgString:h,mergedConfig:l,onConfigChange:w=>c(w??""),onCodeChange:w=>o(w??"")})]}),e.jsx($n,{error:i,hasCardCustomConfig:!!x,onReset:()=>{c(a),f(null)},onApply:L,onClose:()=>n(!1)})]})]})}function Je(t){const[n,a]=k.useState(null);return n}function gt(){const{authToken:t,tokenProps:n}=s.useSemaphorContext(),{data:a,isLoading:r,isFetching:l,isError:c}=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:c}}function jt(){const{data:t,isLoading:n,isError:a}=gt(),r=s.useQueries({queries:((t==null?void 0:t.plugins)||[]).map(o=>({queryKey:["manifest",o.value],queryFn:()=>s.loadManifest(o.value),enabled:!!o.value,staleTime:5*60*1e3,gcTime:10*60*1e3,retry:2,retryDelay:i=>Math.min(1e3*2**i,3e4)}))}),l=[];let c=n,d=a;return r.forEach((o,i)=>{var u;if(o.isLoading&&(c=!0),o.isError&&(d=!0),o.data&&((u=t==null?void 0:t.plugins)!=null&&u[i])){const m=t.plugins[i],x=o.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:c,isError:d}}function qn({onChartTypeChange:t}){const{setCardCustomCfg:n,setCardPreferences:a,setCardType:r,setCustomCardPreferences:l}=s.useEditorActions(),{data:c,isLoading:d,isError:o}=jt(),i=k.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 d?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..."})})]}):o?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"})})]}):!c||c.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:c.map((u,m)=>e.jsx(Kn,{text:u.name,onClick:()=>i("custom",u),icon:u.icon},`${u.url}-${u.name}-${m}`))})]})}const Kn=({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 Hn({onChartTypeChange:t,iconClassName:n}){const{setCardType:a,setCardPreferences:r,setIsDevMode:l}=s.useEditorStore(m=>m.actions),{setCardCustomCfg:c,setCustomCardPreferences:d,setQueryConfig:o}=s.useEditorActions();function i(m,x){c(null),r({}),a(m),["custom","text","map"].includes(m)&&(l(!0),o(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:()=>i("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:()=>i("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:()=>i("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:()=>i("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:()=>i("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:()=>i("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:()=>i("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:()=>i("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:()=>i("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:()=>i("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:()=>i("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:()=>i("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:()=>i("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:()=>i("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:()=>i("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:()=>i("text"),className:"h-10 p-4",children:e.jsx(s.BookType,{className:s.cn("size-5",n)})}),e.jsx(s.IconButton,{tooltip:"Map",onClick:()=>i("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:()=>i("custom"),className:"h-10 p-4",children:e.jsx(ze,{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(ze,{className:n});default:return e.jsx(s.Table2,{className:n})}}function bt({variant:t="ghost"}){var c,d;const[n,a]=k.useState(!1),r=s.useEditorStore(o=>o.card),l=r.type;return s.useDashboardStore(o=>o.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:(c=r.customCardPreferences)==null?void 0:c.icon,componentName:(d=r.customCardPreferences)==null?void 0:d.componentName})})}),e.jsxs(s.PopoverContentCustom,{onOpenAutoFocus:o=>o.preventDefault(),className:"z-[51] w-72 p-1",children:[e.jsx(Hn,{onChartTypeChange:()=>a(!1)}),e.jsx(qn,{onChartTypeChange:()=>a(!1)})]})]})}function Wn({error:t,className:n="",textClassName:a="",copyButtonClassName:r=""}){const[l,c]=k.useState(!1),d=k.useRef(null),o=k.useRef(!1);function i(){t&&!o.current&&navigator.clipboard.writeText(t)}function u(h){(h.key==="Enter"||h.key===" ")&&(h.preventDefault(),i())}function m(){const h=window.getSelection();if(h&&h.toString().trim()!==""){const p=h.toString();navigator.clipboard.writeText(p),c(!0),o.current=!0,setTimeout(()=>{c(!1),o.current=!1},1e3)}else o.current=!1}function x(){c(!1),o.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:d,className:`cursor-pointer select-text break-all font-mono text-xs text-red-700 dark:text-red-300 ${a}`,onClick:i,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 Jn(){const t=s.useEditorStore(c=>{var d,o;return(o=(d=c.card.preferences)==null?void 0:d.chartOptions)==null?void 0:o.indexAxis}),n=s.useEditorStore(c=>c.card.type),{setChartOrientation:a}=s.useEditorStore(c=>c.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(Cs,{className:"size-4"}):e.jsx(Ns,{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(Cs,{className:"size-4"}):e.jsx(Ns,{className:"size-4"})})}return e.jsx(e.Fragment,{children:n==="funnel"?l():r()})}function Xn({className:t}){var h,p,b,f,j,N,C,L;const n=s.useEditorStore(A=>A.card),{setCardPreferences:a,updateCardInFrame:r,setCard:l}=s.useEditorActions(),[c,d]=k.useState(!1),o=((p=(h=n.preferences)==null?void 0:h.displayOptions)==null?void 0:p.showFilterInfo)??!0,i=((f=(b=n.preferences)==null?void 0:b.displayOptions)==null?void 0:f.showCardToolbar)??!0,u=((N=(j=n.preferences)==null?void 0:j.displayOptions)==null?void 0:N.showChrome)??!0,m=((L=(C=n.preferences)==null?void 0:C.displayOptions)==null?void 0:L.allowScroll)??!0,x=(A,w)=>{var y;const D={...n.preferences,displayOptions:{...(y=n.preferences)==null?void 0:y.displayOptions,[A]:w}};a(D);const g={...n,preferences:D};l(g),r(g)};return e.jsx("div",{className:s.cn("flex items-center",t),children:e.jsxs(s.DropdownMenu,{modal:!1,open:c,onOpenChange:d,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(_s,{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:o,onCheckedChange:A=>{x("showFilterInfo",A)},onSelect:A=>A.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:i,onCheckedChange:A=>{x("showCardToolbar",A)},onSelect:A=>A.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:A=>{x("showChrome",A)},onSelect:A=>A.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:A=>{x("allowScroll",A)},onSelect:A=>A.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 vt(){const t=s.useEditorStore(c=>c.card),n=s.useEditorStore(c=>{var d,o;return(o=(d=c.card)==null?void 0:d.preferences)==null?void 0:o.chartOptions}),a=s.getChartGridStyle(n),{setChartGrid:r}=s.useEditorActions();function l(){const c=["xy","none","x","y"],o=(c.indexOf(a)+1)%c.length;r(c[o])}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(Jn,{})}),!["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(Qe,{className:"size-4"}),a==="x"&&e.jsx(Yt,{className:"size-4"}),a==="y"&&e.jsx(ma,{className:"size-4"}),a==="none"&&e.jsx(fa,{className:"size-4"})]}),e.jsx(Xn,{})]})}function Zn(){const t=s.useEditorStore(b=>b.frame),n=s.useEditorStore(b=>b.card),{setFrame:a,setActiveTabCardId:r,setCard:l,updateCardInFrame:c}=s.useEditorActions(),d=(b,f)=>{b.dataTransfer.setData("tabIndex",f.toString())},o=b=>{b.preventDefault()},i=(b,f)=>{const j=b.dataTransfer.getData("tabIndex");if(j===f.toString())return;const N=Array.from(t.cards),[C]=N.splice(parseInt(j),1);N.splice(f,0,C),a({...t,cards:N})};function u(b){const f=t.cards.filter(C=>C.id!==b),j=f[0],N={...t,cards:f,activeCardId:j.id};a(N),r(j.id),l(j)}function m(b,f){const j={...t,cards:[...t.cards,f],activeCardId:b.id};a(j),r(f.id)}function x(){const b={...n,id:s.v4(),title:`${n.title} Copy`,tabTitle:`${n.tabTitle||n.title} Copy`};m(n,b)}function h(b){const f={dataSource:b.dataSource,connectionId:b.connectionId,lastSelectedDatabase:b.lastSelectedDatabase,lastSelectedSchema:b.lastSelectedSchema,lastSelectedTable:b.lastSelectedTable,lastSelectedDatamodelId:b.lastSelectedDatamodelId,id:s.v4(),title:"Title",description:"",preferences:{onClickFilter:[{columnIndex:0,expression:""}]},type:"bar",sql:"",data:[],mode:"explorer"};m(b,f)}function p(b,f){return b.cards.length===1&&(f.displayTab===!0||f.displayTab===void 0)||b.activeCardId!==f.id&&(f.displayTab===!0||f.displayTab===void 0)?null:e.jsx("div",{onClick:()=>{const j=f.displayTab===void 0?!1:!f.displayTab;l({...f,displayTab:j}),c({...f,displayTab:j})},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((b,f)=>e.jsxs(s.TabsTrigger,{draggable:!0,onDragStart:j=>d(j,f),onDragOver:o,onDrop:j=>i(j,f),className:"",value:b.id,children:[p(t,b),e.jsx(s.Editable,{enabled:t.activeCardId===b.id,text:b.tabTitle||b.title,onSave:j=>{l({...n,tabTitle:j}),c({...n,tabTitle:j})},children:b.tabTitle||b.title},b.id),t.activeCardId===b.id&&e.jsx(s.CopyPlus,{className:"ml-2 size-3.5 text-muted-foreground hover:text-foreground",onClick:j=>{j.stopPropagation(),x()}}),t.activeCardId===b.id&&t.cards.length>1&&e.jsx(s.X,{className:"ml-2 size-3.5 text-muted-foreground hover:text-foreground",onClick:()=>u(b.id)})]},b.id)),e.jsx(s.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 yt(){const t=s.useEditorStore(j=>j.frame),n=s.useEditorStore(j=>j.card),a=s.useEditorStore(j=>j.isSqlRunning),r=s.useEditorStore(j=>j.isDevMode),{setFrame:l,setActiveTabCardId:c,setCard:d,setIsDevMode:o,setRunSql:i}=s.useEditorActions(),{data:u,isLoading:m,isFetching:x,isError:h}=s.useDashboardCardQuery(n);function p(j){const N=t.cards.find(C=>C.id===j);if(N!=null&&N.sql){r||o(!0),c(j);return}if(N!=null&&N.queryConfig){r&&o(!1),b(j),c(j);return}r||b(j),c(j)}function b(j){const N={...t,cards:t.cards.map(L=>L.id===n.id?n:L),activeCardId:j};l(N);const C=N.cards.find(L=>L.id===j);C.sql&&i(!0),d(C)}function f(){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,isError:h})})}):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(ft,{className:"grow border-none shadow-none"})})}return e.jsxs(s.Tabs,{onValueChange:p,value:t.activeCardId,className:"flex grow flex-col",children:[t.cards.map(j=>e.jsx(s.TabsContent,{className:"mt-0 grow",value:j.id,children:f()},j.id)),e.jsx(Zn,{})]})}function Es({children:t}){var D,g;s.useEditorStore(y=>y.frame);const n=s.useEditorStore(y=>y.card),a=s.useEditorStore(y=>y.isDevMode),r=s.useEditorStore(y=>y.isShowingVisual),l=s.useDashboardStore(y=>y.isVisualEditing),c=s.useEditorStore(y=>y.pythonStdOut);s.useEditorStore(y=>y.actions.setRunSql);const{setFrame:d,setCard:o,setActiveTabCardId:i,runAssistant:u,setIsDevMode:m,setCardPreferences:x}=s.useEditorActions(),{data:h,isLoading:p,isFetching:b,errorMessage:f,refetch:j}=s.useDashboardCardQuery(n),[N,C]=k.useState(!1);k.useEffect(()=>{b||C(!1)},[b]);function L(){const y=JSON.stringify(h==null?void 0:h.records,null,2),v=new Blob([y],{type:"application/json"}),R=URL.createObjectURL(v),S=document.createElement("a");S.href=R,S.download=`${n.title}.json`,S.click()}function A(){const v=[Object.keys(h==null?void 0:h.records.reduce((I,T)=>({...I,...T}),{})).join(","),...((h==null?void 0:h.records)||[]).map(I=>Object.values(I).join(","))].join(`
|
|
279
|
-
`),R=new Blob([v],{type:"text/csv"}),S=URL.createObjectURL(R),F=document.createElement("a");F.href=S,F.download=`${n.title}.csv`,F.click()}function w(){const y=`Can you get the documentation for ${n.type} chart?`;u(y)}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(bt,{}),l&&e.jsx(s.IconButton,{tooltip:"Visual Docs",onClick:w,children:e.jsx(_t,{className:"size-4"})}),!["table","custom"].includes(n.type)&&l&&e.jsx(Yn,{})]}),!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:A,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:L,children:e.jsx(Jt,{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||b,onClick:()=>{C(!0),j()},children:e.jsx(s.RefreshCcw,{className:s.cn("h-4 w-4",{"animate-spin":N})})}),e.jsx(vt,{})]}),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:((g=(D=n.preferences)==null?void 0:D.tablePrefs)==null?void 0:g.enableDevModePagination)??!1,onCheckedChange:y=>{var v;x({...n.preferences,tablePrefs:{...(v=n.preferences)==null?void 0:v.tablePrefs,enableDevModePagination:y}}),j()}}),e.jsx(s.Label,{htmlFor:"pagination",children:"Paginate Results"})]}),a&&e.jsx(sr,{})]}),r?e.jsx(yt,{}):e.jsxs(s.ResizablePanelGroup,{className:"px-6",direction:"horizontal",children:[c&&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:c&&e.jsx(er,{})}),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":c}),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(Wn,{error:f})]})]})]}):e.jsx(e.Fragment,{children:"No Active Card"})}function er(){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 sr(){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:c,icon:d,showPlaceholderLabel:o=!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",c),children:e.jsxs("div",{className:"flex items-center gap-2",children:[d&&e.jsx("span",{children:d}),o&&e.jsx(s.SelectValue,{placeholder:n})]})}),e.jsx(s.SelectContent,{children:e.jsxs(s.SelectGroup,{children:[e.jsx(s.SelectLabel,{children:n}),a.map(i=>e.jsx(s.SelectItem,{value:i.value,children:i.label},i.value))]})})]})}function tr(){var f,j;const t=s.useEditorStore(N=>N.card.customCardPreferences),{data:n}=gt(),a=(n==null?void 0:n.plugins)||[],r=s.useEditorStore(N=>N.card),l=s.useEditorStore(N=>N.frame),c=(t==null?void 0:t.visualType)||"single",{setCustomCardPreferences:d}=s.useEditorActions(),{components:o,manifest:i}=s.useCustomVisual((t==null?void 0:t.url)||""),u=(f=i==null?void 0:i.visuals)==null?void 0:f.find(N=>N.name===(t==null?void 0:t.componentName));function m(N,C){if(!t)return;const A={...(t==null?void 0:t.dataInputCardIds)||{},[N]:{cardId:C,hookRef:null}};d({...t,dataInputCardIds:A})}function x(N){var L,A;const C=(L=l==null?void 0:l.cards)==null?void 0:L.filter(w=>{var D;return((D=w==null?void 0:w.customCardPreferences)==null?void 0:D.visualType)!=="multiple"}).map(w=>({value:w.id,label:w.tabTitle||w.title}));return e.jsx("div",{className:"space-y-2",children:(A=N==null?void 0:N.dataInputs)==null?void 0:A.map((w,D)=>{var g,y;return e.jsxs("div",{className:"grid grid-cols-10 gap-2",children:[e.jsx("div",{className:"col-span-4 flex items-center",children:w}),e.jsx(Se,{className:"col-span-6 h-8 w-full justify-between",label:"",options:C||[],value:((y=(g=t==null?void 0:t.dataInputCardIds)==null?void 0:g[D])==null?void 0:y.cardId)||"",onValueChange:v=>m(D,v)})]},D+Math.random())})})}function h(N,C,L=[],A=""){var w,D;return t?N==="input"?e.jsx(s.Input,{className:`h-8 w-full ${s.removeRing}`,value:((w=t==null?void 0:t.settings)==null?void 0:w[C])||A,onChange:g=>{d({...t,settings:{...t==null?void 0:t.settings,[C]:g.target.value}})}},C):N==="select"?e.jsx(Se,{className:"h-8 w-full",label:"",options:L,value:((D=t==null?void 0:t.settings)==null?void 0:D[C])||A,onValueChange:g=>{d({...t,settings:{...t==null?void 0:t.settings,[C]:g}})}}):null:null}function p(N){const C=Object.entries((N==null?void 0:N.settings)||{});return e.jsx("div",{className:"space-y-3",children:C.map(([L,A])=>e.jsxs("div",{className:"space-y-1",children:[e.jsx(s.Label,{children:A.title}),h(A.ui,L,A.options,A.defaultValue)]},L))})}function b(N){t&&d({...t,visualType:N,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(Ut,{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:N=>d({...t||{url:"",componentName:""},url:N})}),((t==null?void 0:t.type)==="component"||(t==null?void 0:t.type)===void 0)&&e.jsx(s.Tabs,{value:c,onValueChange:b,children:e.jsxs(s.TabsList,{className:"h-9 w-full",children:[e.jsx(s.TabsTrigger,{className:"h-7 w-full",value:"single",children:"Single Visual"}),e.jsx(s.TabsTrigger,{className:"h-7 w-full",value:"multiple",children:"Multi-Visual"})]})})]})}),((t==null?void 0:t.type)==="component"||(t==null?void 0:t.type)===void 0)&&t&&e.jsx(e.Fragment,{children:o&&e.jsx(Se,{icon:e.jsx(qt,{className:"h-3.5 w-3.5"}),className:"h-9 w-full",label:"Select Component",options:(o==null?void 0:o.filter(N=>N.type===c).map(N=>({value:N.name,label:N.name})))||[],value:t.componentName,onValueChange:N=>{console.log("changing value",N),d({...t,componentName:N})}})})]})})]}),((j=r==null?void 0:r.customCardPreferences)==null?void 0:j.componentName)&&e.jsxs(s.AccordionItem,{className:"border-none",value:"component-settings",children:[e.jsx(s.AccordionTrigger,{children:"Settings"}),e.jsxs(s.AccordionContent,{children:[u&&u.dataInputs&&e.jsxs("div",{className:"space-y-3",children:[e.jsx(s.Label,{children:"Input Mapping"}),e.jsx("div",{className:"px-2",children: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]=k.useState([]),a=s.useEditorStore(u=>u.card.preferences),{setFilterOnClickColumnIndex:r,setCardPreferences:l}=s.useEditorStore(u=>u.actions),c=s.useEditorStore(u=>u.queryResultColumns);s.useEditorStore(u=>{var m;return(m=u.card.preferences)==null?void 0:m.filterOnClickColumnIndex}),k.useEffect(()=>{c&&n(new Array(c.length).fill(!1))},[c]);function d(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 b=[...p];return b[u]=!1,b}))}function o(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 i(u){var m,x,h,p;if(t!=null&&t[u]||(x=(m=a==null?void 0:a.onClickFilter)==null?void 0:m.find(b=>b.columnIndex===u))!=null&&x.expression)return e.jsx(s.Input,{value:(p=(h=a==null?void 0:a.onClickFilter)==null?void 0:h.find(b=>b.columnIndex===u))==null?void 0:p.expression,onChange:b=>o(u,b),type:"text",className:"h-9 w-full font-mono text-xs focus-visible:ring-0 focus-visible:ring-ring focus-visible:ring-offset-0",placeholder:"Expression"})}return e.jsx("div",{className:"max-h-[150px] space-y-2 overflow-y-auto",children:c==null?void 0:c.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=>d(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 b=[...p];return b[m]=!p[m],b})},className:"invisible size-3 cursor-pointer text-gray-400 group-hover:visible"})})]}),i(m)]})},u)})})}function ar({idx:t}){var o;const n=s.useEditorStore(i=>{var u;return(u=i.card)==null?void 0:u.preferences}),a=s.useEditorStore(i=>{var u;return(u=i.card.preferences)==null?void 0:u.datasetOptions}),r=s.useEditorStore(i=>i.actions.setCardPreferences),l=(o=n==null?void 0:n.chartOptions)==null?void 0:o.indexAxis,c=a==null?void 0:a.find(i=>i.idx===t);function d(i,u){(i==="end"||i==="start")&&s.getContrastColor(s.getCanvasBackgroundColor());const m={display:i!=="none",align:i,anchor:i,clamp:!0};if(!c)r({...n,datasetOptions:[...a||[],{idx:u,datalabels:m}]});else{const x={...c};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(Gs,{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:()=>d("none",t),className:"h-7 p-1 text-xs font-normal",children:e.jsx(s.X,{className:"size-3.5"})}),e.jsx("button",{onClick:()=>d("start",t),className:"h-7 p-1 text-xs font-normal",children:e.jsx(aa,{className:s.cn("h-4 w-4",{"rotate-90":l==="y"})})}),e.jsx("button",{onClick:()=>d("center",t),className:"h-7 p-1 text-xs font-normal",children:e.jsx(ra,{className:s.cn("h-4 w-4",{"rotate-90":l==="y"})})}),e.jsx("button",{onClick:()=>d("end",t),className:"h-7 p-1 text-xs font-normal",children:e.jsx(na,{className:s.cn("h-4 w-4",{"rotate-90":l==="y"})})})]})})]})}function nr(){const t=s.useEditorStore(c=>c.card),{data:n}=s.useDashboardCardQuery(t),{keys:a}=s.getKeys((n==null?void 0:n.records)||[]),r=a.slice(1).filter(c=>!s.METADATA_KEYS.includes(c));let l=r;if(["stackedBar","stackedLine"].includes(t.type)){const c=s.pivotData({dataArray:(n==null?void 0:n.records)||[],groupKey:a[0],pivotKey:a[1],valueKey:a[2]}),{keys:d}=s.getKeys(c);l=d.slice(1)}return{transformedMetricKeys:l,dimensionKeys:a.slice(0,1),keys:a,defaultMetricKeys:r}}function ms({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 Nt(){const t=s.useEditorStore(i=>i.card),n=s.useEditorStore(i=>{var u,m,x;return(x=(m=(u=i==null?void 0:i.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:c,transformedMetricKeys:d,keys:o}=nr();return o.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:c.map(i=>e.jsx("p",{className:"flex h-8 items-center rounded-md bg-muted/70 px-3 hover:bg-muted",title:i,children:Ct(i)},i))})]}),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:d.map((i,u)=>e.jsx(St,{className:"flex h-8 items-center bg-muted/70 px-3 hover:bg-muted",iconClassName:"invisible group-hover:visible",col:i,idx:u},i))})]})]})}function Ct(t,n=30){return t.length>n?t.slice(0,n)+"...":t}function St({col:t,idx:n,className:a,iconClassName:r,children:l}){const c=s.useEditorStore(m=>{var x;return(x=m.card)==null?void 0:x.preferences}),d=s.useEditorStore(m=>{var x,h;return(h=(x=m.card)==null?void 0:x.preferences)==null?void 0:h.datasetOptions}),o=d==null?void 0:d.find(m=>m.idx===n),{setCardPreferences:i}=s.useEditorStore(m=>m.actions);function u(m){if(!o)i({...c,datasetOptions:[...d||[],{idx:n,type:m==="area"?"line":m,fill:m==="area"?"origin":""}]});else{const x={...o};x.type=m==="area"?"line":m,x.fill=m==="area"?"origin":"";const h=d==null?void 0:d.map(p=>p.idx===n?x:p);i({...c,datasetOptions:h})}}return e.jsxs("div",{className:s.cn("group flex items-center justify-between gap-2 rounded-md",a),children:[l||e.jsx(ms,{className:"max-w-[100px]",title:t,children:Ct(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(ar,{idx:n})]})]})}function Pe(){const t=s.useDashboardStore(o=>o.dashboard.filters),n=s.useEditorStore(o=>o.frame),{setFrame:a}=s.useEditorActions(),{columns:r}=s.useEditorAside(),{assignFilter:l}=ct();function c(o){const i=l(o,"frame");a({...n,filterId:i})}const d=t==null?void 0:t.find(o=>o.id===n.filterId);return e.jsxs("div",{className:"space-y-3",children:[e.jsx(s.Label,{children:"Card Filter"}),e.jsx(rr,{onSelect:c,columns:r}),d&&e.jsx(s.FilterHeader,{filter:d})]})}function rr({columns:t,onSelect:n}){var d;const[a,r]=ss.useState(!1),[l,c]=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?(d=t.find(o=>o.column_name===l))==null?void 0:d.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(o=>e.jsxs(s.CommandItem,{value:o.column_name,onSelect:i=>{const u=i===l?"":i;c(u),r(!1),u&&n(o)},children:[o.column_name,e.jsx(s.CheckIcon,{className:s.cn("ml-auto h-4 w-4",l===o.column_name?"opacity-100":"opacity-0")})]},o.column_name))})]})]})})]})}function lr({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(Nt,{})})]}),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 or({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:c=>c.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 wt(){const t=s.useEditorStore(o=>o.card.type),n=s.useEditorStore(o=>o.isDevMode),a=s.useEditorStore(o=>o.card.preferences),{setCardPreferences:r}=s.useEditorStore(o=>o.actions);function l(o){var m;const i={datalabels:{display:o!=="none",align:o,anchor:o,clamp:!0}},u={...a,chartOptions:{...a==null?void 0:a.chartOptions,plugins:{...(m=a==null?void 0:a.chartOptions)==null?void 0:m.plugins,...i}}};r(u)}function c(){var o,i,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=(i=(o=a==null?void 0:a.chartOptions)==null?void 0:o.plugins)==null?void 0:i.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 d(){var o,i,u;return e.jsx("div",{children:e.jsxs(s.Select,{value:((u=(i=(o=a==null?void 0:a.chartOptions)==null?void 0:o.plugins)==null?void 0:i.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?c():d()})}const ir={datasets:[{type:"line",label:"Sum_sales",data:[]},{type:"bar",label:"Sum_profit",data:[]}]},cr={datasets:[{fill:"origin",type:"line",label:"Sum_sales",data:[]}]};function dr(){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:ur(t)}),!["kpi"].includes(t)&&e.jsxs("div",{className:"space-y-4",children:[e.jsx(wt,{}),e.jsx(Me,{}),e.jsx(Pe,{})]})]})}function ur(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(ir,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(cr,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 mr({colorRanges:t,setColorRanges:n}){const a={start:-1/0,end:100,color:""};function r(d,o,i){const u=[...t];u[d]={...u[d],[o]:i},n(u)}function l(d){const o=[...t];o.splice(d,1),n(o)}function c(){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:c,variant:"secondary",className:"h-5 p-1 text-muted-foreground",children:e.jsx(s.Plus,{className:"size-3"})})]}),t.map((d,o)=>e.jsxs("div",{className:"flex items-center gap-2 px-2",children:[e.jsx(s.Input,{onChange:i=>r(o,"start",i.target.value),value:d.start,className:s.cn(`h-7 ${s.removeRing}`)}),e.jsx("span",{children:"-"}),e.jsx(s.Input,{value:d.end,onChange:i=>r(o,"end",i.target.value),className:s.cn(`h-7 ${s.removeRing}`)}),e.jsx(s.Input,{onChange:i=>r(o,"color",i.target.value),value:d.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(o),variant:"secondary",className:"h-5 p-1 text-muted-foreground",children:e.jsx(s.X,{className:"size-3"})})]},o))]})}function hr(){var m,x,h,p,b;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 j,N;return(N=(j=f.card.preferences)==null?void 0:j.formatNumber)==null?void 0:N.decimalPlaces});const c=s.useEditorStore(f=>{var j,N;return(N=(j=f.card.preferences)==null?void 0:j.formatNumber)==null?void 0:N.locale}),d=s.useEditorStore(f=>{var j,N;return(N=(j=f.card.preferences)==null?void 0:j.formatNumber)==null?void 0:N.currency});s.useEditorStore(f=>f.actions.setFilterOnClickField);const o=s.useEditorStore(f=>{var j,N;return(N=(j=f.card.preferences)==null?void 0:j.formatNumber)==null?void 0:N.colorRanges})||[],i=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:c||"none",onValueChange:f=>{var j,N,C;return l(((j=t==null?void 0:t.formatNumber)==null?void 0:j.decimalPlaces)||0,((N=t==null?void 0:t.formatNumber)==null?void 0:N.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:d||"none",onValueChange:f=>{var j,N,C;console.log("currency",f),l(((j=t==null?void 0:t.formatNumber)==null?void 0:j.decimalPlaces)||0,f==="none"?"":f,((N=t==null?void 0:t.formatNumber)==null?void 0:N.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 j,N,C;return l(Number(f),((j=t==null?void 0:t.formatNumber)==null?void 0:j.currency)||"",((N=t==null?void 0:t.formatNumber)==null?void 0:N.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:((b=t==null?void 0:t.formatNumber)==null?void 0:b.suffix)||"",className:"h-8 font-mono text-xs focus-visible:ring-0 focus-visible:ring-ring focus-visible:ring-offset-0",placeholder:"K, M, B, %",onChange:f=>{var j,N,C;return l(((j=t==null?void 0:t.formatNumber)==null?void 0:j.decimalPlaces)||0,((N=t==null?void 0:t.formatNumber)==null?void 0:N.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(mr,{colorRanges:o,setColorRanges:i})]})]})}function xr(){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(hr,{})}),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 pr=[{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"}],fr=["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"],gr=fr.map(t=>({label:t,value:t}));function jr(){var i,u,m,x,h,p,b,f,j,N,C,L,A,w,D,g,y,v;const t=s.useEditorStore(R=>R.card),n=(u=(i=t==null?void 0:t.preferences)==null?void 0:i.mapVisualOptions)==null?void 0:u.topoJsonUrl,[a,r]=k.useState(((x=(m=t==null?void 0:t.preferences)==null?void 0:m.mapVisualOptions)==null?void 0:x.customTopoJsonUrl)||""),{setCardPreferences:l}=s.useEditorActions(),{data:c}=s.useTopoJson(t),d=Object.keys((c==null?void 0:c.objects)||{}).map(R=>({label:R,value:R}))||[],o=[{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:o,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"}),c&&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:d,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:pr,value:((f=(b=t.preferences)==null?void 0:b.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:gr,value:((N=(j=t.preferences)==null?void 0:j.mapVisualOptions)==null?void 0:N.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:((L=(C=t.preferences)==null?void 0:C.mapVisualOptions)==null?void 0:L.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:((D=(w=(A=t.preferences)==null?void 0:A.mapVisualOptions)==null?void 0:w.projectionOffset)==null?void 0:D[0])||0,onChange:R=>{var S,F,I,T;l({...t.preferences,mapVisualOptions:{...(S=t.preferences)==null?void 0:S.mapVisualOptions,projectionOffset:[Number(R.target.value),((T=(I=(F=t.preferences)==null?void 0:F.mapVisualOptions)==null?void 0:I.projectionOffset)==null?void 0:T[1])||0]}})}}),e.jsx(s.Label,{children:"Y"}),e.jsx(s.Input,{className:`h-9 w-full ${s.removeRing}`,type:"number",step:10,value:((v=(y=(g=t.preferences)==null?void 0:g.mapVisualOptions)==null?void 0:y.projectionOffset)==null?void 0:v[1])||0,onChange:R=>{var S,F,I,T;l({...t.preferences,mapVisualOptions:{...(S=t.preferences)==null?void 0:S.mapVisualOptions,projectionOffset:[((T=(I=(F=t.preferences)==null?void 0:F.mapVisualOptions)==null?void 0:I.projectionOffset)==null?void 0:T[0])||0,Number(R.target.value)]}})}})]})}),e.jsx(s.Separator,{className:"my-4"}),e.jsx(Me,{})]})}function br(){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(br,{})})]}),!["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 vr(){const t=s.useEditorStore(r=>{var l,c;return(c=(l=r==null?void 0:r.card)==null?void 0:l.preferences)==null?void 0:c.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(Nt,{})]})]}),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 yr({cardType:t="table"}){console.log("cardType",t);const n=s.useEditorStore(l=>{var c;return(c=l.card)==null?void 0:c.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 Dt({color:t,onColorChange:n,onClose:a}){const[r,l]=k.useState(0),[c,d]=k.useState(100),[o,i]=k.useState(50),[u,m]=k.useState(t);k.useEffect(()=>{const j=Is(t);if(j){const N=As(j.r,j.g,j.b);l(N.h),d(N.s),i(N.l),m(t)}},[t]);const x=j=>{l(j),p(j,c,o)},h=j=>{const N=j.currentTarget.getBoundingClientRect(),C=Math.max(0,Math.min(1,(j.clientX-N.left)/N.width)),L=Math.max(0,Math.min(1,(j.clientY-N.top)/N.height)),A=C*100,w=(1-L)*100;d(A),i(w),p(r,A,w)},p=(j,N,C)=>{const L=Cr(j,N,C),A=Nr(L.r,L.g,L.b);m(A)},b=j=>{if(m(j),/^#[0-9A-Fa-f]{6}$/.test(j)){const N=Is(j);if(N){const C=As(N.r,N.g,N.b);l(C.h),d(C.s),i(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:j=>{j.buttons===1&&h(j)},children:[e.jsx("div",{className:"absolute inset-0 rounded",style:{background:"linear-gradient(to right, white, transparent)"}}),e.jsx("div",{className:"absolute inset-0 rounded",style:{background:"linear-gradient(to bottom, transparent, black)"}}),e.jsx("div",{className:"absolute w-4 h-4 -ml-2 -mt-2 rounded-full border-2 border-white shadow-md",style:{left:`${c}%`,top:`${100-o}%`,backgroundColor:u}})]}),e.jsx("div",{className:"space-y-2",children:e.jsx("input",{type:"range",min:"0",max:"360",value:r,onChange:j=>x(Number(j.target.value)),className:"w-full h-4 rounded-lg appearance-none cursor-pointer",style:{background:"linear-gradient(to right, #ff0000, #ffff00, #00ff00, #00ffff, #0000ff, #ff00ff, #ff0000)"}})}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(s.Label,{children:"HEX"}),e.jsx(s.Input,{value:u,onChange:j=>b(j.target.value),placeholder:"#000000",className:"font-mono"})]}),e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsxs("div",{className:"text-center",children:[e.jsx("div",{className:"w-12 h-12 rounded-full border shadow-sm",style:{backgroundColor:t}}),e.jsx("span",{className:"text-xs text-muted-foreground mt-1",children:"CURRENT"})]}),e.jsxs("div",{className:"text-center",children:[e.jsx("div",{className:"w-12 h-12 rounded-full border shadow-sm",style:{backgroundColor:u}}),e.jsx("span",{className:"text-xs text-muted-foreground mt-1",children:"NEW"})]})]}),e.jsxs("div",{className:"flex gap-2 justify-end",children:[e.jsx(s.Button,{variant:"outline",onClick:a,children:"Cancel"}),e.jsx(s.Button,{onClick:f,children:"OK"})]})]})}function Is(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 Nr(t,n,a){return"#"+((1<<24)+(t<<16)+(n<<8)+a).toString(16).slice(1)}function As(t,n,a){t/=255,n/=255,a/=255;const r=Math.max(t,n,a),l=Math.min(t,n,a);let c=0,d=0;const o=(r+l)/2;if(r!==l){const i=r-l;switch(d=o>.5?i/(2-r-l):i/(r+l),r){case t:c=((n-a)/i+(n<a?6:0))/6;break;case n:c=((a-t)/i+2)/6;break;case a:c=((t-n)/i+4)/6;break}}return{h:Math.round(c*360),s:Math.round(d*100),l:Math.round(o*100)}}function Cr(t,n,a){t/=360,n/=100,a/=100;let r,l,c;if(n===0)r=l=c=a;else{const d=(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),o=a<.5?a*(1+n):a+n-a*n,i=2*a-o;r=d(i,o,t+1/3),l=d(i,o,t),c=d(i,o,t-1/3)}return{r:Math.round(r*255),g:Math.round(l*255),b:Math.round(c*255)}}const Sr=["#000000","#ffffff","#6b7280","#dc2626","#ea580c","#ca8a04","#16a34a","#0891b2","#2563eb","#7c3aed","#c026d3","#e11d48","#0f172a","#f3f4f6","#fbbf24"];function Tt(){var L,A,w,D,g,y,v,R,S,F;const t=s.useEditorStore(I=>I.card),n=s.useEditorStore(I=>{var T;return(T=I.card)==null?void 0:T.preferences}),{setCardPreferences:a,updateCardInFrame:r}=s.useEditorActions(),{data:l}=s.useDashboardCardQuery(t),[c,d]=k.useState({}),[o,i]=k.useState(null),[u,m]=k.useState(null),x=k.useMemo(()=>{var O,E,P,B,q,Y,z;if(!(l!=null&&l.records)||l.records.length===0)return[];const I=(t==null?void 0:t.type)==="stackedBar"||(t==null?void 0:t.type)==="stackedLine",T=(t==null?void 0:t.type)==="bar"||(t==null?void 0:t.type)==="line",M=((O=t==null?void 0:t.config)==null?void 0:O.pivotByColumns)&&t.config.pivotByColumns.length>0;if((I||T)&&M){if(l.pivotSchema&&Array.isArray(l.pivotSchema)){const W=new Set;return l.pivotSchema.forEach(X=>{X.alias&&W.add(X.alias)}),Array.from(W)}if(l.records.length>0){const W=l.records[0],X=Object.keys(W),se=new Set;(E=t==null?void 0:t.config)!=null&&E.groupByColumns&&t.config.groupByColumns.forEach(H=>{se.add(H.label||H.name),se.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 $=H.alias||H.name;te.add($),te.add(`${$}_count`),te.add(`${$}_sum`),te.add(`${$}_avg`),te.add(`${$}_min`),te.add(`${$}_max`);const ae=H.entityName||H.qualifiedEntityName;ae&&(te.add(`${ae}_${$}`),te.add(`${ae}_${$}_count`))}),X.filter(H=>!se.has(H)&&!te.has(H))}}if((T||I)&&!M&&((q=(B=t==null?void 0:t.config)==null?void 0:B.metricColumns)!=null&&q.length))return t.config.metricColumns.map(W=>W.alias||W.label||W.name);if((z=(Y=t==null?void 0:t.config)==null?void 0:Y.groupByColumns)!=null&&z.length){const W=t.config.groupByColumns[0],X=W.label||W.name,se=new Set;return l.records.forEach(te=>{const ie=te[X];ie!=null&&se.add(String(ie))}),Array.from(se)}return[]},[l,(L=t==null?void 0:t.config)==null?void 0:L.groupByColumns,(A=t==null?void 0:t.config)==null?void 0:A.pivotByColumns,(w=t==null?void 0:t.config)==null?void 0:w.metricColumns,t==null?void 0:t.type]),h=k.useMemo(()=>s.getDefaultChartColors(),[]);k.useEffect(()=>{const I={};x.forEach((T,M)=>{I[T]=s.getColorForValue(T,M,n==null?void 0:n.colorConfig)}),d(I)},[x,n==null?void 0:n.colorConfig,h]);const p=(I,T)=>{const M={...c,[I]:T};d(M);const O={...n||{},colorConfig:{segments:M}};a(O);const E={...t,preferences:O};r(E)},b=(I,T)=>{var q;const M=h[T%h.length],{[I]:O,...E}=((q=n==null?void 0:n.colorConfig)==null?void 0:q.segments)||{},P={...n||{},colorConfig:{segments:E}};a(P);const B={...t,preferences:P};r(B),d(Y=>({...Y,[I]:M}))};if(!x.length||!((t==null?void 0:t.type)==="stackedBar"||(t==null?void 0:t.type)==="stackedLine"?((g=(D=t==null?void 0:t.config)==null?void 0:D.groupByColumns)==null?void 0:g.length)||((v=(y=t==null?void 0:t.config)==null?void 0:y.pivotByColumns)==null?void 0:v.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 N=()=>{const I={...n||{},colorConfig:{segments:{}}};a(I);const T={...t,preferences:I};r(T);const M={};x.forEach((O,E)=>{M[O]=s.getColorForValue(O,E,void 0)}),d(M)},C=Object.keys(((F=n==null?void 0:n.colorConfig)==null?void 0:F.segments)||{}).length>0;return e.jsxs(s.AccordionItem,{value:"colors",className:"border-b-0",children:[e.jsx(s.AccordionTrigger,{className:"flex w-full items-center gap-2 py-2 text-sm font-medium hover:no-underline",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(da,{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:N,children:[e.jsx(Ss,{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((I,T)=>{const M=s.isDefaultColor(c[I],T),O=!M;return e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(s.Popover,{open:o===I,onOpenChange:E=>i(E?I: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:c[I]}})}),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((E,P)=>e.jsxs("button",{className:s.cn("relative h-5 w-5 rounded border-2 transition-all hover:scale-110",c[I]===E?"border-gray-900":"border-transparent"),style:{backgroundColor:E},onClick:()=>{p(I,E),i(null)},children:[P===T%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:E})]},`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:Sr.map((E,P)=>e.jsx("button",{className:s.cn("h-5 w-5 rounded border transition-all hover:scale-110",c[I]===E?"border-2 border-gray-900":E==="#ffffff"?"border border-gray-300":"border border-transparent"),style:{backgroundColor:E},onClick:()=>{p(I,E),i(null)},children:e.jsx("span",{className:"sr-only",children:E})},`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:I,color:c[I]}),i(null)},children:"Custom color"}),!M&&e.jsxs("button",{className:"flex items-center gap-1 text-sm text-muted-foreground hover:text-foreground",onClick:()=>{b(I,T),i(null)},children:[e.jsx(Ss,{className:"h-3 w-3"}),"Reset"]})]})]})})]}),e.jsx("span",{className:"flex-1 truncate text-sm",children:I}),O&&e.jsx("span",{className:"text-xs text-muted-foreground",children:"(custom)"})]},I)})}),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(Dt,{color:u.color,onColorChange:I=>{p(u.value,I),m(null)},onClose:()=>m(null)})})]})]})})]})}function we({value:t,onSave:n,placeholder:a="",type:r="text",className:l=""}){const[c,d]=k.useState(t??""),[o,i]=k.useState(!1);k.useEffect(()=>{d(t??"")},[t]);const u=()=>{n(c),i(!1)},m=()=>{d(t??""),i(!1)};return e.jsxs("div",{className:`flex items-center gap-2 ${l}`,children:[e.jsx(s.Input$1,{placeholder:a,type:r,value:o?c:t??"",onChange:x=>{d(x.target.value),i(!0)},onFocus:()=>i(!0),onClick:x=>x.stopPropagation(),className:"h-8 text-xs",onPointerDown:x=>x.stopPropagation(),onKeyDown:x=>{x.stopPropagation(),x.key==="Enter"&&o&&c!==t?u():x.key==="Escape"&&m()},"aria-label":a||"Edit field"}),o&&c!==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 wr=["auto","number","currency","percent","scientific","date"],Dr=[{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"}],Tr=[{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"}],kr=t=>t.charAt(0).toUpperCase()+t.slice(1);function hs({formatOptions:t={},onFormatOptionsChange:n,showTitle:a=!0,title:r="NUMBER FORMAT"}){const l=t.type||"auto",c=(o,i)=>{n({...t,[o]:i})},d=()=>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:o=>c("type",o),children:[e.jsx(s.SelectTrigger,{className:"h-8 text-xs",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{children:wr.map(o=>e.jsx(s.SelectItem,{value:o,className:"text-xs",children:o==="auto"?"Auto (Default)":kr(o)},o))})]})]}),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??d(),onChange:o=>c("decimalPlaces",parseInt(o.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:o=>c("currency",o),children:[e.jsx(s.SelectTrigger,{className:"h-8 flex-1 text-xs",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{children:Dr.map(o=>e.jsx(s.SelectItem,{value:o.value,className:"text-xs",children:o.label},o.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:o=>c("useSuffix",o)})]}),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:o=>c("locale",o),children:[e.jsx(s.SelectTrigger,{className:"h-8 flex-1 text-xs",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{children:Tr.map(o=>e.jsx(s.SelectItem,{value:o.value,className:"text-xs",children:o.label},o.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:o=>c("prefix",o.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:o=>c("suffix",o.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:o=>c("negativeInParentheses",o)})]}),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:o=>c("multiplyBy",o.target.value?parseFloat(o.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:o=>c("dateFormat",o.target.value),className:"h-8 text-xs"})})]})]})]})}function Ms({axis:t,label:n,type:a,config:r,onChange:l}){var x,h,p,b,f,j,N,C,L,A,w,D;const c=(g,y)=>{l({...r,[g]:y})},d=(g,y)=>{var v,R;l({...r,name:{enabled:g==="enabled"?y:((v=r==null?void 0:r.name)==null?void 0:v.enabled)??!1,text:g==="text"?y:(R=r==null?void 0:r.name)==null?void 0:R.text}})},o=(g,y)=>{var v,R;l({...r,labels:{enabled:g==="enabled"?y:((v=r==null?void 0:r.labels)==null?void 0:v.enabled)??!0,rotation:g==="rotation"?y:(R=r==null?void 0:r.labels)==null?void 0:R.rotation}})},i=(g,y)=>{l({...r,scale:{...r==null?void 0:r.scale,[g]:y===""?"auto":Number(y)}})},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:g=>c("enabled",g),onClick:g=>g.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:g=>d("enabled",g)})]}),((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:g=>d("text",g),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:g=>c("position",g),children:[e.jsx(s.SelectTrigger,{className:"h-8 text-xs",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{children:u.map(g=>e.jsx(s.SelectItem,{value:g,className:"text-xs",children:g==="auto"?"Auto (Default)":s.titleCase(g)},g))})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(s.Label,{className:"text-xs font-medium",children:"LABELS"}),e.jsx(s.SmallSwitch,{checked:((b=r==null?void 0:r.labels)==null?void 0:b.enabled)!==!1,onCheckedChange:g=>o("enabled",g)})]}),((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(((j=r==null?void 0:r.labels)==null?void 0:j.rotation)||"auto"),onValueChange:g=>o("rotation",g==="auto"?"auto":Number(g)),children:[e.jsx(s.SelectTrigger,{className:"h-8 text-xs",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{children:m.map(g=>e.jsx(s.SelectItem,{value:g,className:"text-xs",children:g==="auto"?"Auto (Default)":`${g}°`},g))})]})]})]}),a==="value"&&e.jsx(hs,{formatOptions:(r==null?void 0:r.formatOptions)||{},onFormatOptionsChange:g=>l({...r,formatOptions:g}),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:((N=r==null?void 0:r.scale)==null?void 0:N.min)==="auto"||((C=r==null?void 0:r.scale)==null?void 0:C.min)===void 0?"":String(r.scale.min),onSave:g=>i("min",g),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:((L=r==null?void 0:r.scale)==null?void 0:L.max)==="auto"||((A=r==null?void 0:r.scale)==null?void 0:A.max)===void 0?"":String(r.scale.max),onSave:g=>i("max",g),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:((w=r==null?void 0:r.scale)==null?void 0:w.stepSize)==="auto"||((D=r==null?void 0:r.scale)==null?void 0:D.stepSize)===void 0?"":String(r.scale.stepSize),onSave:g=>i("stepSize",g),className:""})})]})]})]})]})]})}function kt(){const t=s.useEditorStore(d=>d.card),n=s.useEditorStore(d=>{var o;return(o=d.card)==null?void 0:o.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 c=(d,o)=>{const u={...n||{},[d==="x"?"xAxisConfig":"yAxisConfig"]:o};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(_s,{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(Ms,{axis:"x",label:"X-Axis",type:l.xAxisType,config:n==null?void 0:n.xAxisConfig,onChange:d=>c("x",d)}),l.hasYAxis&&e.jsx(Ms,{axis:"y",label:"Y-Axis",type:l.yAxisType,config:n==null?void 0:n.yAxisConfig,onChange:d=>c("y",d)})]})})]})}function Et(){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",c=!(t.type==="stackedBar"||t.type==="stackedLine"),d=(u,m)=>{const x={...n,[u]:m};a(x)},o=["top","bottom","left","right"],i=["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(ta,{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)??c,onCheckedChange:u=>d("display",u)})]}),((n==null?void 0:n.display)??c)&&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=>d("position",u),children:[e.jsx(s.SelectTrigger,{className:"h-8 text-xs",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{children:o.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=>d("align",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))})]})]})]})]})})]})}function It(){var y,v,R,S,F,I,T,M,O;const t=s.useEditorStore(E=>E.card),n=s.useEditorStore(E=>{var P,B;return(B=(P=E.card)==null?void 0:P.preferences)==null?void 0:B.dataLabelsConfig}),a=s.useEditorStore(E=>{var P;return(P=E.card)==null?void 0:P.preferences}),{setCardPreferences:r,updateCardInFrame:l}=s.useEditorActions();if(!t||!s.chartSupportsDataLabels(t.type))return null;const c=((y=a==null?void 0:a.chartOptions)==null?void 0:y.indexAxis)==="y",d=t.type==="stackedBar"||t.type==="stackedLine",o=t.type==="pie"||t.type==="doughnut"||t.type==="polarArea"||t.type==="funnel",i=!o,u=(R=(v=a==null?void 0:a.chartOptions)==null?void 0:v.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=(E,P)=>{const B={...n,[E]:P},q={...t.preferences||{},dataLabelsConfig:B};r(q);const Y={...t,preferences:q};l(Y)},p=(E,P)=>{const B={...n,font:{...n==null?void 0:n.font,[E]:P}},q={...t.preferences||{},dataLabelsConfig:B};r(q);const Y={...t,preferences:q};l(Y)},b=(E,P)=>{const B={...n,formatOptions:{...n==null?void 0:n.formatOptions,[E]:P}},q={...t.preferences||{},dataLabelsConfig:B};r(q);const Y={...t,preferences:q};l(Y)},j=(()=>{const E=t.type;return E==="stackedBar"||E==="stackedLine"||E==="pie"||E==="doughnut"?"center":c?"right":"top"})();let N=[];d||o?N=["center"]:N=["auto",...(c?["center","left","right"]:["center","top","bottom"]).filter(P=>P!==j),"custom"];const C=()=>s.titleCase(j),L=["center","start","end"],A=["center","start","end","top","bottom"],w=i?["auto","number","currency","percent","none"]:["number","currency","percent","none"],D=[{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"}],g=[{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(ja,{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:E=>h("enabled",E)})]}),x&&e.jsxs(e.Fragment,{children:[!d&&!o&&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:E=>h("position",E),children:[e.jsx(s.SelectTrigger,{className:"h-8 text-xs",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{children:N.map(E=>e.jsx(s.SelectItem,{value:E,className:"text-xs",children:E==="auto"?C():E==="custom"?"Custom (Advanced)":s.titleCase(E)},E))})]})]}),d&&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:E=>h("showTotal",E)})]}),(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:E=>h("anchor",E),children:[e.jsx(s.SelectTrigger,{className:"h-8 text-xs flex-1",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{children:L.map(E=>e.jsx(s.SelectItem,{value:E,className:"text-xs",children:s.titleCase(E)},E))})]})]}),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:E=>h("align",E),children:[e.jsx(s.SelectTrigger,{className:"h-8 text-xs flex-1",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{children:A.map(E=>e.jsx(s.SelectItem,{value:E,className:"text-xs",children:s.titleCase(E)},E))})]})]})]}),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)||(i?"auto":"none"),onValueChange:E=>h("format",E),children:[e.jsx(s.SelectTrigger,{className:"h-8 text-xs",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{children:w.map(E=>e.jsx(s.SelectItem,{value:E,className:"text-xs",children:E==="auto"&&i?"Auto (Use Axis)":E==="none"?"None (Raw Value)":s.titleCase(E)},E))})]})]}),(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:E=>b("decimalPlaces",Number(E)),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:((F=n==null?void 0:n.formatOptions)==null?void 0:F.currency)||"USD",onValueChange:E=>b("currency",E),children:[e.jsx(s.SelectTrigger,{className:"h-8 text-xs flex-1",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{children:D.map(E=>e.jsx(s.SelectItem,{value:E.value,className:"text-xs",children:E.label},E.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:((I=n==null?void 0:n.formatOptions)==null?void 0:I.useSuffix)??!1,onCheckedChange:E=>b("useSuffix",E)})]}),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:((T=n==null?void 0:n.formatOptions)==null?void 0:T.locale)||"en-US",onValueChange:E=>b("locale",E),children:[e.jsx(s.SelectTrigger,{className:"h-8 text-xs flex-1",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{children:g.map(E=>e.jsx(s.SelectItem,{value:E.value,className:"text-xs",children:E.label},E.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(((M=n==null?void 0:n.font)==null?void 0:M.size)||12),onSave:E=>p("size",Number(E)),className:""})})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(s.Label,{className:"text-xs text-muted-foreground w-20",children:"Weight"}),e.jsxs(s.Select,{value:((O=n==null?void 0:n.font)==null?void 0:O.weight)||"normal",onValueChange:E=>p("weight",E),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:E=>{E==="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:E=>h("rotation",Number(E)),className:""})}),e.jsx("span",{className:"text-xs text-muted-foreground",children:"degrees"})]})]})]})]})})]})}function Er(){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(Tt,{}),e.jsx(kt,{}),e.jsx(Et,{}),e.jsx(It,{})]})]})}const Ir=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."]})]}),Ar=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."]})]}),Mr=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 Rr(){const t=s.useEditorStore(a=>a.card.type);function n(a){const r=["kpi","table","text","map","custom"],l=c=>r.includes(a)?c:e.jsxs(e.Fragment,{children:[c,e.jsx(Er,{})]});switch(a){case"stackedBar":case"stackedLine":return l(e.jsx(vr,{}));case"tornado":case"pyramid":return l(e.jsx(Ge,{docContent:Ir,cardType:a}));case"kpi":return e.jsx(xr,{});case"line":case"bar":return l(e.jsx(lr,{cardType:a}));case"range":return l(e.jsx(Ge,{docContent:Ar,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(or,{cardType:a}));case"table":return e.jsx(yr,{cardType:a});case"text":return e.jsx(Ge,{docContent:Mr,cardType:a,suffix:"Visual"});case"map":return e.jsx(jr,{});case"custom":return e.jsx(tr,{});default:return l(e.jsx(dr,{}))}}return e.jsxs(s.ScrollArea,{className:"h-full w-full text-sm",children:[n(t),e.jsx(s.ScrollBar,{orientation:"horizontal"})]})}function Lr(){const t=k.useRef(null),n=k.useRef(null),a=s.useEditorStore(l=>l.isShowingVisual),r=s.useEditorStore(l=>l.showAIDialog);return k.useEffect(()=>{var l,c,d,o;r?((l=t.current)==null||l.resize(0),(c=n.current)==null||c.resize(0)):((d=t.current)==null||d.resize(25),(o=n.current)==null||o.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(Bn,{})}),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(Rr,{})})}),!r&&e.jsx(s.ResizableHandle,{}),e.jsx(s.ResizablePanel,{minSize:40,defaultSize:75,maxSize:100,children:e.jsx(Es,{})})]}):e.jsx(Es,{})})]})}function Fr(t){s.useAIInteractionStore(U=>U.currentAIContext);const[n,a]=k.useState(""),[r,l]=k.useState(null),{authToken:c,tokenProps:d}=s.useSemaphorContext(),o=s.useEditorStore(U=>{var ee;return(ee=U==null?void 0:U.card)==null?void 0:ee.sql}),i=s.useEditorStore(U=>U.isDevMode),u=s.useEditorStore(U=>{var ee;return(ee=U==null?void 0:U.card)==null?void 0:ee.python}),{setCardPython:m,setCardSql:x,setRunSql:h,switchCardType:p,setQueryConfig:b}=s.useEditorActions(),f=s.useEditorStore(U=>U.currentAssitantScope)||[],j=s.useEditorStore(U=>U.userInputForAI),N=s.useEditorStore(U=>U.triggerAIRun),C=s.useEditorStore(U=>U.card),L=s.useEditorStore(U=>U.selectedDatabaseName),A=s.useEditorStore(U=>U.selectedTableName),w=s.useEditorStore(U=>U.selectedConnectionId),D=s.useEditorStore(U=>U.selectedSchemaName),g=s.useDashboardStore(U=>U.dashboard.aiScopeTables),{errorMessage:y,refetch:v,data:R}=s.useDashboardCardQuery(C),{setTriggerAIRun:S,setCurrentAssitantScope:F,setCardConfig:I}=s.useEditorActions(),{selectedDatamodelName:T,connectionType:M,selectedDatamodelId:O}=s.useEditorAside(),{messages:E,setMessages:P,regenerate:B,error:q,sendMessage:Y,status:z,addToolResult:W,stop:X,clearError:se}=s.useChat({transport:new s.DefaultChatTransport({api:`${d.apiServiceUrl}/v1/assistant`,headers:()=>({Authorization:`Bearer ${c==null?void 0:c.accessToken}`}),body:()=>{const U=s.useAIInteractionStore.getState();return{random:Math.random(),assistantId:"editor-assistant",isDevMode:i,aiContext:U.currentAIContext,reasoningEffort:U.reasoningEffort,showReasoning:U.showReasoning}},credentials:"omit",prepareSendMessagesRequest:({messages:U,body:ee})=>({body:{...ee,messages:s.cleanupIncompleteMessages(U)}})}),onError:U=>{var ee;if(U.name==="AbortError"||(ee=U.message)!=null&&ee.includes("aborted")){console.log("[Editor Assistant] Stream aborted (expected)");return}console.error("[Editor Assistant] Stream error:",U)},onToolCall:te,onFinish({isAbort:U,isDisconnect:ee,isError:ce}){a(""),console.log(U?"[Editor Assistant] Stream aborted by user":ee?"[Editor Assistant] Stream disconnected (network error)":ce?"[Editor Assistant] Stream error occurred":"[Editor Assistant] Stream completed successfully")}});k.useEffect(()=>{N&&j&&(Y({role:"user",parts:[{type:"text",text:j}]}),S(!1))},[N,j,Y,S]);async function te({toolCall:U}){var ee,ce,le,fe,ue,K,_,V,Z,oe,de,ne,me,pe,Re,Le;if(["createChartFromSql","createForecast"].includes(U.toolName)){const De=((ee=U.input)==null?void 0:ee.sql)??((ce=U.args)==null?void 0:ce.sql),ve=((le=U.input)==null?void 0:le.python)??((fe=U.args)==null?void 0:fe.python),J=((ue=U.input)==null?void 0:ue.chartType)??((K=U.args)==null?void 0:K.chartType);p(J),x(De),m(ve),h(!0),W({tool:U.toolName,toolCallId:U.toolCallId,output:{status:"success",message:"Let the user know that chart is created"}})}else if(U.toolName==="getUserSql"){if(!o){W({tool:U.toolName,toolCallId:U.toolCallId,output:{status:"error",message:"No SQL found"}});return}W({tool:U.toolName,toolCallId:U.toolCallId,output:{status:"success",sql:o,python:u||""}})}else if(U.toolName==="generateQueryConfig"){a("Generating query config...");const De=((_=U.input)==null?void 0:_.chartType)??((V=U.args)==null?void 0:V.chartType),ve=((Z=U.input)==null?void 0:Z.queryConfig)??((oe=U.args)==null?void 0:oe.queryConfig);((de=U.input)==null?void 0:de.cardConfig)??((ne=U.args)==null||ne.cardConfig),p(De),I(ve),x(void 0),m(void 0);const J=await v();if((me=J==null?void 0:J.data)!=null&&me.error){W({tool:U.toolName,toolCallId:U.toolCallId,output:{status:"error",queryConfig:ve,message:(pe=J==null?void 0:J.data)==null?void 0:pe.error.message}});return}if((Re=J==null?void 0:J.data)!=null&&Re.records){W({tool:U.toolName,toolCallId:U.toolCallId,output:{status:"success",queryConfig:ve,message:"The data has been visualized"}});return}W({tool:U.toolName,toolCallId:U.toolCallId,output:{status:"success",queryConfig:ve,message:"The data has been visualized",records:(Le=J==null?void 0:J.data)==null?void 0:Le.records}})}else a("Analyzing...")}function ie(U){const ee=s.removeFromScopeArray(f,U);H(ee)}function H(U){const ee=s.sanitizeAIScope(U);F(ee),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(ee)}`}]}])}function $(){const U={databaseName:L||"",schemaName:D||"",tableName:A||"",datamodelId:O||"",datamodelName:s.resolveDatamodelName(T),connectionId:w||"",connectionType:M||""},ee=s.dedup([...f,U]);H(ee)}function ae(){const U={databaseName:L||"",schemaName:D||"",tableName:A||"",datamodelName:s.resolveDatamodelName(T),connectionId:w||"",connectionType:M||"",datamodelId:O||""};if(!s.isInAiScopeArray([...g||[],...f],U)||f.length===0){const ce=s.dedup([...g||[],...f,U]).filter(le=>le.connectionId===U.connectionId);H(ce)}}const Q=!["ready","error"].includes(z),re=s.getErrorMessage(q);return{messages:E,setMessages:P,sendMessage:Y,regenerate:B,isLoading:Q,handleSetAIScope:ae,handleAddCurrentTableToScope:$,removeFromCurrentSelections:ie,currentAssitantScope:f,setCurrentAssitantScope:F,stop:X,status:z,toolStatus:n,llmUsage:r,onFinish:t,errorMessage:re,clearError:se}}const Or=[{title:"Help me write a query for",subtitle:"orders by month"},{title:"Create a bar chart for",subtitle:"sales by category"}];function Rs({isFullscreen:t,onFullscreenChange:n,fullscreenContainer:a}){const r=k.useRef(null),[l,c]=k.useState(!1),[d,o]=k.useState(s.isDevEnv),[i,u]=k.useState(!1),[m,x]=k.useState(!1),[h,p]=k.useState(!1),b=t??h,f=s.useCurrentAIContext(),{setCurrentAIContext:j}=s.useAIActions(),{clearQueue:N}=s.useQueueActions(),{clearFileAttachments:C}=s.useFileActions(),L=s.useFileAttachments("editor"),A=s.useDashboardStore(J=>J.dashboard.aiContext),w=s.useEditorStore(J=>J.card.dataSource),D=s.useEditorStore(J=>J.actions.setCardSql),g=s.useEditorStore(J=>J.actions.setRunSql),y=s.useEditorStore(J=>J.showAIDialog),v=s.useDashboardStore(J=>J.handleOpenAssistantProfile),{setShowAIDialog:R,setCardPython:S}=s.useEditorActions(),{setDataSource:F}=s.useEditorActions(),{assistantProfile:I}=s.useAssistantProfile(),{messages:T,setMessages:M,sendMessage:O,isLoading:E,stop:P,status:B,llmUsage:q,errorMessage:Y,clearError:z}=Fr(),[W,X]=k.useState(""),se=J=>{X(J.target.value)},te=J=>{J.preventDefault();const ge=W.trim();if(!ge&&L.length===0)return;const Be=[];ge&&Be.push({type:"text",text:ge}),L.forEach(ke=>{ke.data&&Be.push({type:"file",mediaType:ke.type,filename:ke.name,url:`data:${ke.type};base64,${ke.data}`})}),O({role:"user",parts:Be}),X(""),C("editor"),le({force:!0})},{visibleMessages:ie,hasMoreMessages:H,totalMessageCount:$,loadMoreMessages:ae,resetMessageWindow:Q}=s.useMessageWindow(T,{maxVisibleMessages:15,initialLoadCount:10,loadMoreCount:5}),{scrollRef:re,isAtBottom:U,hasNewMessages:ee,newMessageCount:ce,scrollToBottom:le,handleScroll:fe,resetNewMessageCount:ue}=s.useAutoScroll(ie,{threshold:50,delay:0,dependencies:[B,T.length]});k.useEffect(()=>{var J;y&&((J=r.current)==null||J.focus(),j({selectedEntities:(w==null?void 0:w.selectedEntities)||[]}))},[y,w,j]),s.useAutoSubmitQueue({assistantType:"editor",status:B,isLoading:E,sendMessage:O});const{hasActiveTools:K}=s.useActiveToolStatus(T),_=k.useCallback(J=>{n==null||n(J),t===void 0&&p(J)},[t,n]);k.useEffect(()=>{if(!b)return;function J(ge){ge.key==="Escape"&&_(!1)}return window.addEventListener("keydown",J),()=>{window.removeEventListener("keydown",J)}},[b,_]);const V=k.useCallback(J=>{O({role:"user",parts:[{type:"text",text:J}]}),le({force:!0})},[O,le]),Z=k.useCallback(async()=>{const J=JSON.stringify(T??[],null,2);try{if(typeof navigator>"u"||!navigator.clipboard)throw new Error("Clipboard API unavailable");await navigator.clipboard.writeText(J),s.ue.success("Conversation copied")}catch(ge){console.error("Failed to copy conversation",ge),s.ue.error("Unable to copy conversation")}},[T]),oe=k.useCallback(()=>{_(!b)},[b,_]);function de(J,ge){ge==="sql"?(D(J),g(!0)):ge==="python"&&(S(J),g(!0))}function ne(){f.selectedEntities.length===0&&j({selectedEntities:(A==null?void 0:A.selectedEntities)||[]})}function me(J){ne();const ge={role:"user",parts:[{type:"text",text:J.title+" "+J.subtitle}]};O(ge)}function pe(J){ne(),O({role:"user",parts:[{type:"text",text:J}]})}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:c,children:"Token Usage"}),e.jsx(s.DropdownMenuCheckboxItem,{checked:d,onCheckedChange:o,children:"Tool Invocations"}),e.jsx(s.DropdownMenuCheckboxItem,{checked:i,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=(W==null?void 0:W.length)===0&&(T==null?void 0:T.filter(J=>J.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",b&&"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(),v&&e.jsx(s.Button,{variant:"outline",size:"sm",className:"h-7 p-2",onClick:v,children:(I==null?void 0:I.name)||"Default Profile"}),e.jsxs("div",{"data-role":"header-actions",className:"flex items-center",children:[Re(),d&&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:b?"Exit Fullscreen":"Expand",className:"h-7 p-2 text-muted-foreground hover:text-foreground",onClick:oe,children:b?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:()=>{M([]),N("editor"),z(),Q()},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,$-ie.length)," ","more messages (",$-ie.length," ","hidden)"]})}),e.jsx(s.PrintMessages,{messages:ie,showTools:d,handleRun:de,showSystemMessage:i,onQuickReply:V,disableQuickReplies:E}),!K&&e.jsx(s.AssistantStatus,{status:B,errorMessage:Y})]})}),!U&&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"}),ee&&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&&!I&&e.jsx(s.Placeholders,{onClick:me,placeholders:Or}),e.jsx("div",{children:De&&I&&e.jsx(s.SeedQuestions,{seedQuestions:I.seedQuestions||[],handleSeedQuestionClick:pe})})]}),e.jsx(s.PendingMessagesDisplay,{assistantType:"editor",className:"mb-3"}),e.jsx(s.ChatInputWithContext,{ref:r,setInput:X,stop:P,input:W,handleInputChange:se,handleSubmit:J=>{ne(),te(J),le({force:!0})},isLoading:E,status:B,assistantType:"editor",onFocus:()=>{}})]}),q&&l&&e.jsx("div",{className:"flex h-8 items-center justify-between",children:e.jsxs("div",{className:"text-xs text-muted-foreground",children:["Usage: ",q.inputTokens," prompt tokens, ",q.outputTokens," ","completion tokens, ",q.totalTokens," total tokens"]})}),e.jsx(s.DataSourceDialog,{incomingSelectedEntities:(w==null?void 0:w.selectedEntities)||[],open:m,onOpenChange:x,dataSource:w||s.EMPTY_DATA_SOURCE,dialogMode:"aiContext"})]});return b&&a?Vt.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 xs(t,n){const[a,r]=k.useState(()=>{const l=localStorage.getItem(t);return l?JSON.parse(l):n});return k.useEffect(()=>{localStorage.setItem(t,JSON.stringify(a))},[a,t]),[a,r]}const Pr="chart-selector-standard-first";function Br(){const[t,n]=xs(Pr,!0);return{standardFirst:t,updatePreference:n}}const Ls=({pluginVisual:t,index:n,onSelect:a})=>{const r=Je(t.icon||""),l=t.name.charAt(0).toUpperCase(),c=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"}):c||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}`)},Fs=["default","standardPlugin","customPlugin"];function Vr({selectedChart:t,onChartChange:n}){var A;const[a,r]=k.useState(!1),{data:l}=jt();Br();const d=((A=s.useEditorStore(w=>w.card).customCardPreferences)==null?void 0:A.url)||"";os(d);const{setCardType:o,setCardPreferences:i,setIsDevMode:u}=s.useEditorStore(w=>w.actions),{setCardCustomCfg:m,setCustomCardPreferences:x,setQueryConfig:h}=s.useEditorActions(),[p,b]=xs("chart-section-active",null),f=k.useMemo(()=>p?[p,...Fs.filter(w=>w!==p)]:Fs,[p]);function j(w){m(null),i({}),o(w),["custom","map"].includes(w)&&(u(!0),h(void 0)),n(w),r(!1)}function N(w){m(null),i({}),o("custom"),x({type:"component",visualType:"single",url:w.url,componentName:w.name,icon:w.icon,pluginChartType:w.chartType}),h(void 0),n("custom"),r(!1)}const C=()=>{var D;if(t==="custom"){const g=s.useEditorStore.getState().card;return((D=g==null?void 0:g.customCardPreferences)==null?void 0:D.componentName)||"Custom Visual"}const w=s.chartTypes.find(g=>g.id===t);return(w==null?void 0:w.label)||"Select chart type"},L=()=>{var D,g;if(t==="custom"){const y=s.useEditorStore.getState().card,v=(D=y==null?void 0:y.customCardPreferences)==null?void 0:D.icon,R=(g=y==null?void 0:y.customCardPreferences)==null?void 0:g.componentName;if(v&&R)return e.jsx(zr,{icon:v,componentName:R});if(R){const S=s.getAutoDetectedChartIcon(R);if(S)return S}return e.jsx(ze,{className:"h-4 w-4"})}const w=s.chartTypes.find(y=>y.id===t);if(w){const y=w.icon;return e.jsx(y,{className:"h-4 w-4"})}return e.jsx(ze,{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:[L(),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(w=>{if(w==="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:D=>b(D?"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(D=>{const g=D.icon;return e.jsx(s.CommandItem,{value:`${D.label} ${D.id} chart graph visualization`,onSelect:()=>j(D.id),className:"flex items-center gap-2",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(g,{className:"h-4 w-4"}),e.jsx("span",{children:D.label})]})},D.id)})},"default");if(w==="standardPlugin"){const D=l.filter(g=>g.pluginType==="standard");return D.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:g=>b(g?"standardPlugin":null),className:"scale-75"})]})]}),className:"[&_[cmdk-group-heading]]:text-sm [&_[cmdk-group-heading]]:font-medium [&_[cmdk-group-heading]]:text-muted-foreground",children:D.filter(g=>g.componentType==="chart").map((g,y)=>e.jsx(Ls,{pluginVisual:g,index:y,onSelect:()=>N(g)},`${g.url}-${g.name}-${y}`))},"standardPlugin"):null}if(w==="customPlugin"){const D=l.filter(g=>g.pluginType==="custom");return D.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:g=>b(g?"customPlugin":null),className:"scale-75"})]})]}),className:"[&_[cmdk-group-heading]]:text-sm [&_[cmdk-group-heading]]:font-medium [&_[cmdk-group-heading]]:text-muted-foreground",children:D.map((g,y)=>e.jsx(Ls,{pluginVisual:g,index:y,onSelect:()=>N(g)},`${g.url}-${g.name}-${y}`))},"customPlugin"):null}return null})]})]})})]})})}const zr=({icon:t,componentName:n})=>{const a=Je(),r=s.getAutoDetectedChartIcon(n);return a?e.jsx(a,{className:"h-4 w-4"}):r||e.jsx(ze,{className:"h-4 w-4"})},Ur=[{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 _r({selectedChart:t,onChartChange:n}){var l;const a=s.useEditorStore(c=>c.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:Ur.map(c=>{if(c.requiresPivot&&!r)return null;const d=c.icon,o=t===c.id;return e.jsxs(s.Tooltip,{children:[e.jsx(s.TooltipTrigger,{asChild:!0,children:e.jsxs(s.Button,{variant:"ghost",size:"sm",onClick:()=>n(c.id),className:s.cn("h-8 w-8 p-0",o&&"bg-accent text-accent-foreground"),children:[e.jsx(d,{className:"h-4 w-4"}),e.jsx("span",{className:"sr-only",children:c.label})]})}),e.jsx(s.TooltipContent,{side:"bottom",children:e.jsx("p",{children:c.label})})]},c.id)})})}const ps=({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(rs,{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($s,{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 Gr({aliasTemplate:t,onAliasTemplateChange:n}){var i;const[a,r]=k.useState(t),[l,c]=k.useState(!1),d=(i=s.useEditorStore(u=>{var m;return(m=u.card.config)==null?void 0:m.pivotByColumns}))==null?void 0:i[0],o=d?`e.g. Min Sales in {{${d.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:o,value:l?a:t,onChange:u=>{r(u.target.value),c(!0)},onFocus:()=>c(!0),onPointerDown:u=>u.stopPropagation(),className:"h-8 text-xs",onKeyDown:u=>{u.key==="Enter"&&l&&a!==t?(n(a),c(!1)):u.key==="Escape"&&(r(t),c(!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),c(!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),c(!1)},children:e.jsx(s.X,{className:"h-4 w-4 text-gray-400"})})]})]})]})}function $r({valueAliases:t,onValueAliasesChange:n}){const[a,r]=k.useState(null),[l,c]=k.useState(""),[d,o]=k.useState(""),i=()=>{n({...t,"":""})},u=x=>{const h={...t};delete h[x],n(h)},m=x=>{const h={...t};delete h[x],h[l]=d,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:b=>c(b.target.value),className:"h-8 w-24 text-xs",onPointerDown:b=>b.stopPropagation(),onKeyDown:b=>{b.key==="Enter"?m(x):b.key==="Escape"&&r(null)},"aria-label":"Edit value alias key"}),e.jsx(s.Input$1,{placeholder:"Alias label",value:d,onChange:b=>o(b.target.value),className:"h-8 w-24 text-xs",onPointerDown:b=>b.stopPropagation(),onKeyDown:b=>{b.key==="Enter"?m(x):b.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),c(x),o(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),c(x),o(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:i,children:[e.jsx(s.Plus,{className:"mr-1 h-3 w-3"})," Add Value Alias"]})]})]})}function Yr({column:t}){const n=s.useEditorStore(i=>i.card.type),a=s.useEditorStore(i=>{var u,m;return(m=(u=i.card)==null?void 0:u.config)==null?void 0:m.metricColumns}),r=(a==null?void 0:a.map(i=>i.label))||[],l=r==null?void 0:r.find(i=>i===t.label||i===t.name),c=l?r.indexOf(l):-1;function d(){return e.jsx("div",{className:"pr-1",children:l&&e.jsx(St,{idx:c,col:l,children:e.jsx("div",{className:"w-[130px] text-xs text-muted-foreground",children:"Display Series As"})})})}function o(){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(wt,{})]})}return e.jsxs("div",{className:"space-y-1",children:[["stackedBar","stackedLine","bar","line"].includes(n)&&d(),["pie","doughnut"].includes(n)&&o()]})}function qr({field:t,searchQuery:n="",limit:a=500}){const{authToken:r,tokenProps:l}=s.useSemaphorContext(),c=s.useEditorStore(u=>u.card),d=c==null?void 0:c.dataSource,o=["attribute-values",t.entityName,t.name,n,a],i=s.useQuery({queryKey:o,queryFn:async()=>{if(!(d!=null&&d.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:d.connectionId,cardConfig:u,cardDataSource:d,cache_config:s.getCacheConfig({card:c})};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(b=>{const f=b[h]||b[t.alias||h]||b[t.label];return{id:f||"",value:f||"",label:String(f||"(empty)")}})}catch(u){return console.error("Error fetching attribute values:",u),[]}},enabled:!!t&&!!(d!=null&&d.connectionId),staleTime:5*60*1e3,gcTime:10*60*1e3});return{values:i.data||[],isLoading:i.isLoading,isFetching:i.isFetching,isError:i.isError,error:i.error,refetch:i.refetch}}function Kr({open:t,onOpenChange:n,availableFields:a,existingFilters:r,editingCondition:l,onSave:c}){var L,A;const d=!!l,[o,i]=k.useState(d?"values":"fields"),[u,m]=k.useState(""),[x,h]=k.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(w=>{var g;return d?!1:!((g=r==null?void 0:r.conditions)==null?void 0:g.some(y=>y.field.id===w.id))&&w.label.toLowerCase().includes(u.toLowerCase())}),b=w=>{h({...x,field:w}),i("values")},f=()=>{if(x.field&&x.selectedValues.length>0){const w={id:x.id,field:x.field,operator:"in",value:x.selectedValues};let D;if(d){const g=((r==null?void 0:r.conditions)||[]).map(y=>y.id===l.id?w:y);D={...r,conditions:g}}else{const g=(r==null?void 0:r.conditions)||[];D={id:(r==null?void 0:r.id)||s.v4(),logicalOperator:"AND",negate:!1,conditions:[...g,w],groups:[]}}c(D),n(!1)}},j=()=>{if(!d||!l)return;const w=((r==null?void 0:r.conditions)||[]).filter(D=>D.id!==l.id);if(w.length>0){const D={...r,conditions:w};c(D)}else c(void 0);n(!1)},N=w=>{h({...x,selectedValues:w})},C=()=>{d&&l?(h({id:l.id,field:l.field,selectedValues:Array.isArray(l.value)?l.value:[l.value]}),i("values")):(h({id:s.v4(),field:null,selectedValues:[]}),i("fields")),m("")};return k.useEffect(()=>{t&&C()},[t,d,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:d?`Edit Filter: ${(L=x.field)==null?void 0:L.label}`:o==="fields"?"Select Field to Filter":`Select Values for ${(A=x.field)==null?void 0:A.label}`})}),e.jsxs("div",{className:"space-y-4",children:[!d&&(r==null?void 0:r.conditions)&&r.conditions.length>0&&o==="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(w=>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:[w.field.label,":"]}),e.jsx("span",{className:"text-muted-foreground",children:Array.isArray(w.value)?`${w.value.length} values`:String(w.value)})]},w.id))})]}),o==="fields"&&!d?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:w=>m(w.target.value),className:"pl-10"})]}),e.jsx("div",{className:"grid grid-cols-2 gap-2 max-h-[400px] overflow-y-auto",children:p.map(w=>e.jsxs(s.Button,{variant:"outline",className:"justify-start h-auto py-2 px-3",onClick:()=>b(w),children:[e.jsx(ps,{dataType:s.getDataType(w.dataType)}),e.jsxs("div",{className:"ml-2 text-left",children:[e.jsx("div",{className:"text-sm font-medium",children:w.label}),e.jsxs("div",{className:"text-xs text-muted-foreground",children:[w.entityName,".",w.name]})]})]},w.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(Hr,{field:x.field,selectedValues:x.selectedValues,onValuesChange:N,onBack:d?void 0:()=>i("fields")}),e.jsxs("div",{className:"flex justify-between pt-4 border-t",children:[e.jsx("div",{children:d?e.jsx(s.Button,{variant:"destructive",onClick:j,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 Hr({field:t,selectedValues:n,onValuesChange:a,onBack:r}){const[l,c]=k.useState(""),{values:d,isLoading:o,isFetching:i}=qr({field:t,searchQuery:l,limit:500}),u=l?d.filter(h=>String(h.value).toLowerCase().includes(l.toLowerCase())):d,m=h=>{const p=n.includes(h);a(p?n.filter(b=>b!==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=>c(h.target.value),className:"pl-10"})]}),o||i?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(ms,{className:"text-sm",children:h.label})]},h.id))})]})]})}function Qr({field:t,zone:n,index:a,sortDirection:r,onSortDirectionChange:l,hasPivotColumns:c=!1,cardType:d}){var gs,js,bs,vs;const{attributes:o,listeners:i,setNodeRef:u,transform:m,transition:x,isDragging:h}=s.useSortable({id:t.id}),p=s.useEditorStore(G=>G.card),{updateLabel:b,handleAggregationChange:f,handleDateFormatChange:j,handleGranularityChange:N,handleAliasTemplateChange:C,handleValueAliasesChange:L,removeField:A,handleKpiComparisonTypeChange:w,handleKpiShowTrendlineChange:D,handleKpiTrendlineWindowChange:g,handleKpiTrendlineGranularityChange:y,handleKpiTargetValueChange:v}=ds(p),[R,S]=k.useState(!1),[F,I]=k.useState(!1),[T,M]=k.useState(null),[O,E]=k.useState(t.dateFormat||"YYYY-MM-DD"),[P,B]=k.useState(t.customFormat||""),[q,Y]=k.useState(!!t.customFormat),[z,W]=k.useState(t.granularity||"day"),[X,se]=k.useState(t.aliasTemplate||""),[te,ie]=k.useState(t.valueAliases||{}),[H,$]=k.useState((gs=t.parameters)==null?void 0:gs.filters),ae=G=>{G==="custom"?Y(!0):(Y(!1),E(G),n==="groupBy"&&j(a,G,""))},Q=G=>{B(G),n==="groupBy"&&j(a,"custom",G)},re=G=>{var je;W(G);const xe=(je=Z(G)[0])==null?void 0:je.value;xe&&!q&&(E(xe),n==="groupBy"&&j(a,xe,"")),n==="groupBy"&&N(a,G)},U=G=>{se(G),n==="metrics"&&C(a,G)},ee=G=>{ie(G),n==="metrics"&&L(a,G)},ce=G=>{b(n,a,G)},le=G=>{var he;if($(G),n==="metrics"){const xe={...t,parameters:{...t.parameters,filters:G}},je=[...((he=p.config)==null?void 0:he.metricColumns)||[]];je[a]=xe,s.useEditorStore.getState().actions.updateCardConfig(p.id,{metricColumns:je})}I(!1)},fe=()=>{A(n,a)},ue={transform:s.CSS.Transform.toString(m),transition:x},K=s.getDataType(t.dataType),_=K==="date",V=d==="kpi",Z=G=>{switch(G){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..."}]}},oe=Z(z),de=n!=="pivotBy",ne=_&&n==="groupBy"&&(!V||((js=p.config)==null?void 0:js.comparisonType)==="start_vs_end"),me=!V&&_&&n==="groupBy",pe=V&&_&&n==="groupBy",Re=V&&n==="metrics"&&((bs=p.config)==null?void 0:bs.comparisonType)==="target",Le=n==="metrics",De=()=>e.jsx("div",{title:`${t.entityName}.${t.name}`,onPointerDown:G=>{G.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,J=()=>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(G=>e.jsx(s.SelectItem,{className:"text-xs",value:G,children:s.toTitleCase(G)},G))})]})]}):null,ge=()=>me?e.jsxs(e.Fragment,{children:[J(),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:q?"custom":O,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:oe.map(G=>e.jsx(s.SelectItem,{className:"text-xs",value:G.value,children:G.label},G.value))})]}),q&&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:G=>{G.stopPropagation(),Q(G.target.value)},onClick:G=>G.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 G,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:((G=p.config)==null?void 0:G.comparisonType)||"none",onValueChange:w,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:"start_vs_end",children:"Start vs End"})]})]})]}),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:D})]})}),((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:Ue=>{const Bt=parseInt(Ue.target.value)||30;g(Bt)},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:y,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 G,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:((G=p.config)==null?void 0:G.targetValue)!==void 0&&((he=p.config)==null?void 0:he.targetValue)!==null?String(p.config.targetValue):"",onSave:xe=>{!isNaN(Number(xe))&&xe!==null?v(Number(xe)):v(0)},placeholder:"Enter target value...",type:"text"})]}):null},Ft=()=>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:G=>{f(a,G)},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(G=>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:()=>{M(G),I(!0)},children:[e.jsxs("span",{className:"font-medium",children:[G.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(G.value)?G.value.length===1?String(G.value[0]):G.value.length<=2?G.value.join(", "):`${G.value.slice(0,2).join(", ")} +${G.value.length-2}`:String(G.value)})}),Array.isArray(G.value)&&G.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 (",G.value.length,"):"]}),e.jsx("div",{className:"max-h-[200px] overflow-y-auto",children:G.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!==G.id);if(xe.length>0){const Te={...H,conditions:xe};le(Te)}else if($(void 0),n==="metrics"){const Te={...t,parameters:{...t.parameters,filters:void 0}},Ue=[...((je=p.config)==null?void 0:je.metricColumns)||[]];Ue[a]=Te,s.useEditorStore.getState().actions.updateCardConfig(p.id,{metricColumns:Ue})}},children:e.jsx(s.X,{className:"h-3 w-3"})})]},G.id))}),e.jsxs(s.Button,{variant:"outline",size:"sm",className:"h-8 w-full justify-start text-xs",onClick:()=>{M(null),I(!0)},children:[e.jsx(s.Filter,{className:"mr-2 h-3 w-3"}),"Add attribute filter"]})]}),e.jsx(Yr,{column:t}),c&&e.jsxs(e.Fragment,{children:[e.jsx(Gr,{aliasTemplate:X,onAliasTemplateChange:U}),e.jsx($r,{valueAliases:te,onValueAliasesChange:ee})]})]}):null,{columns:Ot=[]}=s.useColumns(),Pt=(H==null?void 0:H.conditions)&&H.conditions.length>0;return e.jsxs(e.Fragment,{children:[e.jsxs("div",{ref:u,style:ue,...o,...i,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(ps,{dataType:K}),e.jsx(ms,{className:s.cn("w-[140px] flex-1 text-sm",Pt&&"w-[120px]"),children:s.getMetricDisplayLabel(t)}),n==="metrics"&&((vs=H==null?void 0:H.conditions)==null?void 0:vs.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(G=>e.jsxs("div",{children:[G.field.label,":"," ",Array.isArray(G.value)?`${G.value.length} values`:String(G.value)]},G.id))})})]})}),n!=="sortBy"&&e.jsx(s.Button,{variant:"ghost",size:"sm",className:"h-6 w-6 p-0",onClick:G=>{G.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:G=>{G.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:G=>{G.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(),d==="kpi"&&J(),ge(),Be(),ke(),Ft()]})]}),F&&e.jsx(Kr,{open:F,onOpenChange:G=>{I(G),G||M(null)},availableFields:Ot,existingFilters:H,editingCondition:T,onSave:G=>{var he;if(G)le(G);else if($(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})}M(null)}})]})}function Wr({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:c=!1,activeField:d=null}){const{isOver:o,setNodeRef:i}=s.useDroppable({id:t}),{updateSortByColumn:u}=s.useEditorActions(),m=s.useEditorStore(j=>j.card),x=s.useEditorStore(j=>j.card.type),h=n.length>0,p=k.useMemo(()=>!d||!o?!0:Ve(d,t,x).isValid,[d,o,t,x]),b=(j,N)=>{var L;!((L=m.config)!=null&&L.sortByColumns)||m.config.sortByColumns.findIndex(A=>A.id===j)===-1||u(m.id,j,{direction:N})};if(t==="sortBy"&&l===!1)return null;const f=t!=="sortBy"&&x!=="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}),f&&e.jsx(Wr,{concept:t})]}),e.jsx("div",{ref:i,className:s.cn("rounded-lg border-2 border-dashed p-1 transition-all",{"border-green-500 bg-green-50 dark:bg-green-950":o&&p,"border-red-500 bg-red-50 dark:bg-red-950":o&&!p,"border-blue-200 bg-blue-50/30 dark:border-blue-800 dark:bg-blue-950/30":!o&&h,"min-h-[60px] border-muted-foreground/20 bg-background":!o&&!h}),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(j=>j.id),strategy:s.verticalListSortingStrategy,children:e.jsx("div",{className:"flex flex-wrap gap-1",children:n.map((j,N)=>{const L=j.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:j,zone:t,index:N,sortDirection:L,onSortDirectionChange:A=>b(j.id,A),hasPivotColumns:c,cardType:x})})},j.id)})})})})]})}const Os=[{value:"green",color:"#16a34a",label:"Green"},{value:"red",color:"#dc2626",label:"Red"},{value:"neutral",color:"#6b7280",label:"Neutral"}],Jr=["#16a34a","#dc2626","#6b7280","#2563eb","#ca8a04","#7c3aed","#0891b2","#e11d48","#ea580c"];function es({value:t,onChange:n,label:a}){const[r,l]=k.useState(!1),[c,d]=k.useState(!1),o=()=>{const i=Os.find(u=>u.value===t);return i?i.color:t.startsWith("#")?t:Os[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:o()},"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:Jr.map(i=>e.jsx("button",{className:s.cn("h-5 w-5 rounded border-2 transition-all",o()===i?"border-gray-900":"border-transparent"),style:{backgroundColor:i},onClick:()=>{n(i),l(!1)},children:e.jsx("span",{className:"sr-only",children:i})},i))}),e.jsx("button",{className:"w-full rounded border border-input px-2 py-1 text-xs hover:bg-muted",onClick:()=>{d(!0),l(!1)},children:"Custom color..."})]})})]}),e.jsx("span",{className:"text-xs text-muted-foreground",children:a})]}),c&&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:()=>d(!1)}),e.jsx("div",{className:"relative rounded-lg bg-white shadow-lg",children:e.jsx(Dt,{color:o(),onColorChange:i=>{n(i),d(!1)},onClose:()=>d(!1)})})]})]})}const Ps={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%
|
|
279
|
+
`),R=new Blob([v],{type:"text/csv"}),S=URL.createObjectURL(R),F=document.createElement("a");F.href=S,F.download=`${n.title}.csv`,F.click()}function w(){const y=`Can you get the documentation for ${n.type} chart?`;u(y)}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(bt,{}),l&&e.jsx(s.IconButton,{tooltip:"Visual Docs",onClick:w,children:e.jsx(_t,{className:"size-4"})}),!["table","custom"].includes(n.type)&&l&&e.jsx(Yn,{})]}),!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:A,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:L,children:e.jsx(Jt,{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||b,onClick:()=>{C(!0),j()},children:e.jsx(s.RefreshCcw,{className:s.cn("h-4 w-4",{"animate-spin":N})})}),e.jsx(vt,{})]}),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:((g=(D=n.preferences)==null?void 0:D.tablePrefs)==null?void 0:g.enableDevModePagination)??!1,onCheckedChange:y=>{var v;x({...n.preferences,tablePrefs:{...(v=n.preferences)==null?void 0:v.tablePrefs,enableDevModePagination:y}}),j()}}),e.jsx(s.Label,{htmlFor:"pagination",children:"Paginate Results"})]}),a&&e.jsx(sr,{})]}),r?e.jsx(yt,{}):e.jsxs(s.ResizablePanelGroup,{className:"px-6",direction:"horizontal",children:[c&&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:c&&e.jsx(er,{})}),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":c}),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(Wn,{error:f})]})]})]}):e.jsx(e.Fragment,{children:"No Active Card"})}function er(){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 sr(){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:c,icon:d,showPlaceholderLabel:o=!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",c),children:e.jsxs("div",{className:"flex items-center gap-2",children:[d&&e.jsx("span",{children:d}),o&&e.jsx(s.SelectValue,{placeholder:n})]})}),e.jsx(s.SelectContent,{children:e.jsxs(s.SelectGroup,{children:[e.jsx(s.SelectLabel,{children:n}),a.map(i=>e.jsx(s.SelectItem,{value:i.value,children:i.label},i.value))]})})]})}function tr(){var f,j;const t=s.useEditorStore(N=>N.card.customCardPreferences),{data:n}=gt(),a=(n==null?void 0:n.plugins)||[],r=s.useEditorStore(N=>N.card),l=s.useEditorStore(N=>N.frame),c=(t==null?void 0:t.visualType)||"single",{setCustomCardPreferences:d}=s.useEditorActions(),{components:o,manifest:i}=s.useCustomVisual((t==null?void 0:t.url)||""),u=(f=i==null?void 0:i.visuals)==null?void 0:f.find(N=>N.name===(t==null?void 0:t.componentName));function m(N,C){if(!t)return;const A={...(t==null?void 0:t.dataInputCardIds)||{},[N]:{cardId:C,hookRef:null}};d({...t,dataInputCardIds:A})}function x(N){var L,A;const C=(L=l==null?void 0:l.cards)==null?void 0:L.filter(w=>{var D;return((D=w==null?void 0:w.customCardPreferences)==null?void 0:D.visualType)!=="multiple"}).map(w=>({value:w.id,label:w.tabTitle||w.title}));return e.jsx("div",{className:"space-y-2",children:(A=N==null?void 0:N.dataInputs)==null?void 0:A.map((w,D)=>{var g,y;return e.jsxs("div",{className:"grid grid-cols-10 gap-2",children:[e.jsx("div",{className:"col-span-4 flex items-center",children:w}),e.jsx(Se,{className:"col-span-6 h-8 w-full justify-between",label:"",options:C||[],value:((y=(g=t==null?void 0:t.dataInputCardIds)==null?void 0:g[D])==null?void 0:y.cardId)||"",onValueChange:v=>m(D,v)})]},D+Math.random())})})}function h(N,C,L=[],A=""){var w,D;return t?N==="input"?e.jsx(s.Input,{className:`h-8 w-full ${s.removeRing}`,value:((w=t==null?void 0:t.settings)==null?void 0:w[C])||A,onChange:g=>{d({...t,settings:{...t==null?void 0:t.settings,[C]:g.target.value}})}},C):N==="select"?e.jsx(Se,{className:"h-8 w-full",label:"",options:L,value:((D=t==null?void 0:t.settings)==null?void 0:D[C])||A,onValueChange:g=>{d({...t,settings:{...t==null?void 0:t.settings,[C]:g}})}}):null:null}function p(N){const C=Object.entries((N==null?void 0:N.settings)||{});return e.jsx("div",{className:"space-y-3",children:C.map(([L,A])=>e.jsxs("div",{className:"space-y-1",children:[e.jsx(s.Label,{children:A.title}),h(A.ui,L,A.options,A.defaultValue)]},L))})}function b(N){t&&d({...t,visualType:N,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(Ut,{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:N=>d({...t||{url:"",componentName:""},url:N})}),((t==null?void 0:t.type)==="component"||(t==null?void 0:t.type)===void 0)&&e.jsx(s.Tabs,{value:c,onValueChange:b,children:e.jsxs(s.TabsList,{className:"h-9 w-full",children:[e.jsx(s.TabsTrigger,{className:"h-7 w-full",value:"single",children:"Single Visual"}),e.jsx(s.TabsTrigger,{className:"h-7 w-full",value:"multiple",children:"Multi-Visual"})]})})]})}),((t==null?void 0:t.type)==="component"||(t==null?void 0:t.type)===void 0)&&t&&e.jsx(e.Fragment,{children:o&&e.jsx(Se,{icon:e.jsx(qt,{className:"h-3.5 w-3.5"}),className:"h-9 w-full",label:"Select Component",options:(o==null?void 0:o.filter(N=>N.type===c).map(N=>({value:N.name,label:N.name})))||[],value:t.componentName,onValueChange:N=>{console.log("changing value",N),d({...t,componentName:N})}})})]})})]}),((j=r==null?void 0:r.customCardPreferences)==null?void 0:j.componentName)&&e.jsxs(s.AccordionItem,{className:"border-none",value:"component-settings",children:[e.jsx(s.AccordionTrigger,{children:"Settings"}),e.jsxs(s.AccordionContent,{children:[u&&u.dataInputs&&e.jsxs("div",{className:"space-y-3",children:[e.jsx(s.Label,{children:"Input Mapping"}),e.jsx("div",{className:"px-2",children: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]=k.useState([]),a=s.useEditorStore(u=>u.card.preferences),{setFilterOnClickColumnIndex:r,setCardPreferences:l}=s.useEditorStore(u=>u.actions),c=s.useEditorStore(u=>u.queryResultColumns);s.useEditorStore(u=>{var m;return(m=u.card.preferences)==null?void 0:m.filterOnClickColumnIndex}),k.useEffect(()=>{c&&n(new Array(c.length).fill(!1))},[c]);function d(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 b=[...p];return b[u]=!1,b}))}function o(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 i(u){var m,x,h,p;if(t!=null&&t[u]||(x=(m=a==null?void 0:a.onClickFilter)==null?void 0:m.find(b=>b.columnIndex===u))!=null&&x.expression)return e.jsx(s.Input,{value:(p=(h=a==null?void 0:a.onClickFilter)==null?void 0:h.find(b=>b.columnIndex===u))==null?void 0:p.expression,onChange:b=>o(u,b),type:"text",className:"h-9 w-full font-mono text-xs focus-visible:ring-0 focus-visible:ring-ring focus-visible:ring-offset-0",placeholder:"Expression"})}return e.jsx("div",{className:"max-h-[150px] space-y-2 overflow-y-auto",children:c==null?void 0:c.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=>d(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 b=[...p];return b[m]=!p[m],b})},className:"invisible size-3 cursor-pointer text-gray-400 group-hover:visible"})})]}),i(m)]})},u)})})}function ar({idx:t}){var o;const n=s.useEditorStore(i=>{var u;return(u=i.card)==null?void 0:u.preferences}),a=s.useEditorStore(i=>{var u;return(u=i.card.preferences)==null?void 0:u.datasetOptions}),r=s.useEditorStore(i=>i.actions.setCardPreferences),l=(o=n==null?void 0:n.chartOptions)==null?void 0:o.indexAxis,c=a==null?void 0:a.find(i=>i.idx===t);function d(i,u){(i==="end"||i==="start")&&s.getContrastColor(s.getCanvasBackgroundColor());const m={display:i!=="none",align:i,anchor:i,clamp:!0};if(!c)r({...n,datasetOptions:[...a||[],{idx:u,datalabels:m}]});else{const x={...c};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(Gs,{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:()=>d("none",t),className:"h-7 p-1 text-xs font-normal",children:e.jsx(s.X,{className:"size-3.5"})}),e.jsx("button",{onClick:()=>d("start",t),className:"h-7 p-1 text-xs font-normal",children:e.jsx(aa,{className:s.cn("h-4 w-4",{"rotate-90":l==="y"})})}),e.jsx("button",{onClick:()=>d("center",t),className:"h-7 p-1 text-xs font-normal",children:e.jsx(ra,{className:s.cn("h-4 w-4",{"rotate-90":l==="y"})})}),e.jsx("button",{onClick:()=>d("end",t),className:"h-7 p-1 text-xs font-normal",children:e.jsx(na,{className:s.cn("h-4 w-4",{"rotate-90":l==="y"})})})]})})]})}function nr(){const t=s.useEditorStore(c=>c.card),{data:n}=s.useDashboardCardQuery(t),{keys:a}=s.getKeys((n==null?void 0:n.records)||[]),r=a.slice(1).filter(c=>!s.METADATA_KEYS.includes(c));let l=r;if(["stackedBar","stackedLine"].includes(t.type)){const c=s.pivotData({dataArray:(n==null?void 0:n.records)||[],groupKey:a[0],pivotKey:a[1],valueKey:a[2]}),{keys:d}=s.getKeys(c);l=d.slice(1)}return{transformedMetricKeys:l,dimensionKeys:a.slice(0,1),keys:a,defaultMetricKeys:r}}function ms({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 Nt(){const t=s.useEditorStore(i=>i.card),n=s.useEditorStore(i=>{var u,m,x;return(x=(m=(u=i==null?void 0:i.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:c,transformedMetricKeys:d,keys:o}=nr();return o.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:c.map(i=>e.jsx("p",{className:"flex h-8 items-center rounded-md bg-muted/70 px-3 hover:bg-muted",title:i,children:Ct(i)},i))})]}),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:d.map((i,u)=>e.jsx(St,{className:"flex h-8 items-center bg-muted/70 px-3 hover:bg-muted",iconClassName:"invisible group-hover:visible",col:i,idx:u},i))})]})]})}function Ct(t,n=30){return t.length>n?t.slice(0,n)+"...":t}function St({col:t,idx:n,className:a,iconClassName:r,children:l}){const c=s.useEditorStore(m=>{var x;return(x=m.card)==null?void 0:x.preferences}),d=s.useEditorStore(m=>{var x,h;return(h=(x=m.card)==null?void 0:x.preferences)==null?void 0:h.datasetOptions}),o=d==null?void 0:d.find(m=>m.idx===n),{setCardPreferences:i}=s.useEditorStore(m=>m.actions);function u(m){if(!o)i({...c,datasetOptions:[...d||[],{idx:n,type:m==="area"?"line":m,fill:m==="area"?"origin":""}]});else{const x={...o};x.type=m==="area"?"line":m,x.fill=m==="area"?"origin":"";const h=d==null?void 0:d.map(p=>p.idx===n?x:p);i({...c,datasetOptions:h})}}return e.jsxs("div",{className:s.cn("group flex items-center justify-between gap-2 rounded-md",a),children:[l||e.jsx(ms,{className:"max-w-[100px]",title:t,children:Ct(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(ar,{idx:n})]})]})}function Pe(){const t=s.useDashboardStore(o=>o.dashboard.filters),n=s.useEditorStore(o=>o.frame),{setFrame:a}=s.useEditorActions(),{columns:r}=s.useEditorAside(),{assignFilter:l}=ct();function c(o){const i=l(o,"frame");a({...n,filterId:i})}const d=t==null?void 0:t.find(o=>o.id===n.filterId);return e.jsxs("div",{className:"space-y-3",children:[e.jsx(s.Label,{children:"Card Filter"}),e.jsx(rr,{onSelect:c,columns:r}),d&&e.jsx(s.FilterHeader,{filter:d})]})}function rr({columns:t,onSelect:n}){var d;const[a,r]=ss.useState(!1),[l,c]=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?(d=t.find(o=>o.column_name===l))==null?void 0:d.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(o=>e.jsxs(s.CommandItem,{value:o.column_name,onSelect:i=>{const u=i===l?"":i;c(u),r(!1),u&&n(o)},children:[o.column_name,e.jsx(s.CheckIcon,{className:s.cn("ml-auto h-4 w-4",l===o.column_name?"opacity-100":"opacity-0")})]},o.column_name))})]})]})})]})}function lr({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(Nt,{})})]}),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 or({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:c=>c.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 wt(){const t=s.useEditorStore(o=>o.card.type),n=s.useEditorStore(o=>o.isDevMode),a=s.useEditorStore(o=>o.card.preferences),{setCardPreferences:r}=s.useEditorStore(o=>o.actions);function l(o){var m;const i={datalabels:{display:o!=="none",align:o,anchor:o,clamp:!0}},u={...a,chartOptions:{...a==null?void 0:a.chartOptions,plugins:{...(m=a==null?void 0:a.chartOptions)==null?void 0:m.plugins,...i}}};r(u)}function c(){var o,i,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=(i=(o=a==null?void 0:a.chartOptions)==null?void 0:o.plugins)==null?void 0:i.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 d(){var o,i,u;return e.jsx("div",{children:e.jsxs(s.Select,{value:((u=(i=(o=a==null?void 0:a.chartOptions)==null?void 0:o.plugins)==null?void 0:i.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?c():d()})}const ir={datasets:[{type:"line",label:"Sum_sales",data:[]},{type:"bar",label:"Sum_profit",data:[]}]},cr={datasets:[{fill:"origin",type:"line",label:"Sum_sales",data:[]}]};function dr(){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:ur(t)}),!["kpi"].includes(t)&&e.jsxs("div",{className:"space-y-4",children:[e.jsx(wt,{}),e.jsx(Me,{}),e.jsx(Pe,{})]})]})}function ur(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(ir,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(cr,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 mr({colorRanges:t,setColorRanges:n}){const a={start:-1/0,end:100,color:""};function r(d,o,i){const u=[...t];u[d]={...u[d],[o]:i},n(u)}function l(d){const o=[...t];o.splice(d,1),n(o)}function c(){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:c,variant:"secondary",className:"h-5 p-1 text-muted-foreground",children:e.jsx(s.Plus,{className:"size-3"})})]}),t.map((d,o)=>e.jsxs("div",{className:"flex items-center gap-2 px-2",children:[e.jsx(s.Input,{onChange:i=>r(o,"start",i.target.value),value:d.start,className:s.cn(`h-7 ${s.removeRing}`)}),e.jsx("span",{children:"-"}),e.jsx(s.Input,{value:d.end,onChange:i=>r(o,"end",i.target.value),className:s.cn(`h-7 ${s.removeRing}`)}),e.jsx(s.Input,{onChange:i=>r(o,"color",i.target.value),value:d.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(o),variant:"secondary",className:"h-5 p-1 text-muted-foreground",children:e.jsx(s.X,{className:"size-3"})})]},o))]})}function hr(){var m,x,h,p,b;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 j,N;return(N=(j=f.card.preferences)==null?void 0:j.formatNumber)==null?void 0:N.decimalPlaces});const c=s.useEditorStore(f=>{var j,N;return(N=(j=f.card.preferences)==null?void 0:j.formatNumber)==null?void 0:N.locale}),d=s.useEditorStore(f=>{var j,N;return(N=(j=f.card.preferences)==null?void 0:j.formatNumber)==null?void 0:N.currency});s.useEditorStore(f=>f.actions.setFilterOnClickField);const o=s.useEditorStore(f=>{var j,N;return(N=(j=f.card.preferences)==null?void 0:j.formatNumber)==null?void 0:N.colorRanges})||[],i=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:c||"none",onValueChange:f=>{var j,N,C;return l(((j=t==null?void 0:t.formatNumber)==null?void 0:j.decimalPlaces)||0,((N=t==null?void 0:t.formatNumber)==null?void 0:N.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:d||"none",onValueChange:f=>{var j,N,C;console.log("currency",f),l(((j=t==null?void 0:t.formatNumber)==null?void 0:j.decimalPlaces)||0,f==="none"?"":f,((N=t==null?void 0:t.formatNumber)==null?void 0:N.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 j,N,C;return l(Number(f),((j=t==null?void 0:t.formatNumber)==null?void 0:j.currency)||"",((N=t==null?void 0:t.formatNumber)==null?void 0:N.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:((b=t==null?void 0:t.formatNumber)==null?void 0:b.suffix)||"",className:"h-8 font-mono text-xs focus-visible:ring-0 focus-visible:ring-ring focus-visible:ring-offset-0",placeholder:"K, M, B, %",onChange:f=>{var j,N,C;return l(((j=t==null?void 0:t.formatNumber)==null?void 0:j.decimalPlaces)||0,((N=t==null?void 0:t.formatNumber)==null?void 0:N.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(mr,{colorRanges:o,setColorRanges:i})]})]})}function xr(){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(hr,{})}),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 pr=[{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"}],fr=["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"],gr=fr.map(t=>({label:t,value:t}));function jr(){var i,u,m,x,h,p,b,f,j,N,C,L,A,w,D,g,y,v;const t=s.useEditorStore(R=>R.card),n=(u=(i=t==null?void 0:t.preferences)==null?void 0:i.mapVisualOptions)==null?void 0:u.topoJsonUrl,[a,r]=k.useState(((x=(m=t==null?void 0:t.preferences)==null?void 0:m.mapVisualOptions)==null?void 0:x.customTopoJsonUrl)||""),{setCardPreferences:l}=s.useEditorActions(),{data:c}=s.useTopoJson(t),d=Object.keys((c==null?void 0:c.objects)||{}).map(R=>({label:R,value:R}))||[],o=[{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:o,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"}),c&&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:d,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:pr,value:((f=(b=t.preferences)==null?void 0:b.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:gr,value:((N=(j=t.preferences)==null?void 0:j.mapVisualOptions)==null?void 0:N.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:((L=(C=t.preferences)==null?void 0:C.mapVisualOptions)==null?void 0:L.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:((D=(w=(A=t.preferences)==null?void 0:A.mapVisualOptions)==null?void 0:w.projectionOffset)==null?void 0:D[0])||0,onChange:R=>{var S,F,I,T;l({...t.preferences,mapVisualOptions:{...(S=t.preferences)==null?void 0:S.mapVisualOptions,projectionOffset:[Number(R.target.value),((T=(I=(F=t.preferences)==null?void 0:F.mapVisualOptions)==null?void 0:I.projectionOffset)==null?void 0:T[1])||0]}})}}),e.jsx(s.Label,{children:"Y"}),e.jsx(s.Input,{className:`h-9 w-full ${s.removeRing}`,type:"number",step:10,value:((v=(y=(g=t.preferences)==null?void 0:g.mapVisualOptions)==null?void 0:y.projectionOffset)==null?void 0:v[1])||0,onChange:R=>{var S,F,I,T;l({...t.preferences,mapVisualOptions:{...(S=t.preferences)==null?void 0:S.mapVisualOptions,projectionOffset:[((T=(I=(F=t.preferences)==null?void 0:F.mapVisualOptions)==null?void 0:I.projectionOffset)==null?void 0:T[0])||0,Number(R.target.value)]}})}})]})}),e.jsx(s.Separator,{className:"my-4"}),e.jsx(Me,{})]})}function br(){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(br,{})})]}),!["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 vr(){const t=s.useEditorStore(r=>{var l,c;return(c=(l=r==null?void 0:r.card)==null?void 0:l.preferences)==null?void 0:c.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(Nt,{})]})]}),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 yr({cardType:t="table"}){console.log("cardType",t);const n=s.useEditorStore(l=>{var c;return(c=l.card)==null?void 0:c.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 Dt({color:t,onColorChange:n,onClose:a}){const[r,l]=k.useState(0),[c,d]=k.useState(100),[o,i]=k.useState(50),[u,m]=k.useState(t);k.useEffect(()=>{const j=Is(t);if(j){const N=As(j.r,j.g,j.b);l(N.h),d(N.s),i(N.l),m(t)}},[t]);const x=j=>{l(j),p(j,c,o)},h=j=>{const N=j.currentTarget.getBoundingClientRect(),C=Math.max(0,Math.min(1,(j.clientX-N.left)/N.width)),L=Math.max(0,Math.min(1,(j.clientY-N.top)/N.height)),A=C*100,w=(1-L)*100;d(A),i(w),p(r,A,w)},p=(j,N,C)=>{const L=Cr(j,N,C),A=Nr(L.r,L.g,L.b);m(A)},b=j=>{if(m(j),/^#[0-9A-Fa-f]{6}$/.test(j)){const N=Is(j);if(N){const C=As(N.r,N.g,N.b);l(C.h),d(C.s),i(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:j=>{j.buttons===1&&h(j)},children:[e.jsx("div",{className:"absolute inset-0 rounded",style:{background:"linear-gradient(to right, white, transparent)"}}),e.jsx("div",{className:"absolute inset-0 rounded",style:{background:"linear-gradient(to bottom, transparent, black)"}}),e.jsx("div",{className:"absolute w-4 h-4 -ml-2 -mt-2 rounded-full border-2 border-white shadow-md",style:{left:`${c}%`,top:`${100-o}%`,backgroundColor:u}})]}),e.jsx("div",{className:"space-y-2",children:e.jsx("input",{type:"range",min:"0",max:"360",value:r,onChange:j=>x(Number(j.target.value)),className:"w-full h-4 rounded-lg appearance-none cursor-pointer",style:{background:"linear-gradient(to right, #ff0000, #ffff00, #00ff00, #00ffff, #0000ff, #ff00ff, #ff0000)"}})}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(s.Label,{children:"HEX"}),e.jsx(s.Input,{value:u,onChange:j=>b(j.target.value),placeholder:"#000000",className:"font-mono"})]}),e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsxs("div",{className:"text-center",children:[e.jsx("div",{className:"w-12 h-12 rounded-full border shadow-sm",style:{backgroundColor:t}}),e.jsx("span",{className:"text-xs text-muted-foreground mt-1",children:"CURRENT"})]}),e.jsxs("div",{className:"text-center",children:[e.jsx("div",{className:"w-12 h-12 rounded-full border shadow-sm",style:{backgroundColor:u}}),e.jsx("span",{className:"text-xs text-muted-foreground mt-1",children:"NEW"})]})]}),e.jsxs("div",{className:"flex gap-2 justify-end",children:[e.jsx(s.Button,{variant:"outline",onClick:a,children:"Cancel"}),e.jsx(s.Button,{onClick:f,children:"OK"})]})]})}function Is(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 Nr(t,n,a){return"#"+((1<<24)+(t<<16)+(n<<8)+a).toString(16).slice(1)}function As(t,n,a){t/=255,n/=255,a/=255;const r=Math.max(t,n,a),l=Math.min(t,n,a);let c=0,d=0;const o=(r+l)/2;if(r!==l){const i=r-l;switch(d=o>.5?i/(2-r-l):i/(r+l),r){case t:c=((n-a)/i+(n<a?6:0))/6;break;case n:c=((a-t)/i+2)/6;break;case a:c=((t-n)/i+4)/6;break}}return{h:Math.round(c*360),s:Math.round(d*100),l:Math.round(o*100)}}function Cr(t,n,a){t/=360,n/=100,a/=100;let r,l,c;if(n===0)r=l=c=a;else{const d=(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),o=a<.5?a*(1+n):a+n-a*n,i=2*a-o;r=d(i,o,t+1/3),l=d(i,o,t),c=d(i,o,t-1/3)}return{r:Math.round(r*255),g:Math.round(l*255),b:Math.round(c*255)}}const Sr=["#000000","#ffffff","#6b7280","#dc2626","#ea580c","#ca8a04","#16a34a","#0891b2","#2563eb","#7c3aed","#c026d3","#e11d48","#0f172a","#f3f4f6","#fbbf24"];function Tt(){var L,A,w,D,g,y,v,R,S,F;const t=s.useEditorStore(I=>I.card),n=s.useEditorStore(I=>{var T;return(T=I.card)==null?void 0:T.preferences}),{setCardPreferences:a,updateCardInFrame:r}=s.useEditorActions(),{data:l}=s.useDashboardCardQuery(t),[c,d]=k.useState({}),[o,i]=k.useState(null),[u,m]=k.useState(null),x=k.useMemo(()=>{var O,E,P,B,q,Y,z;if(!(l!=null&&l.records)||l.records.length===0)return[];const I=(t==null?void 0:t.type)==="stackedBar"||(t==null?void 0:t.type)==="stackedLine",T=(t==null?void 0:t.type)==="bar"||(t==null?void 0:t.type)==="line",M=((O=t==null?void 0:t.config)==null?void 0:O.pivotByColumns)&&t.config.pivotByColumns.length>0;if((I||T)&&M){if(l.pivotSchema&&Array.isArray(l.pivotSchema)){const W=new Set;return l.pivotSchema.forEach(X=>{X.alias&&W.add(X.alias)}),Array.from(W)}if(l.records.length>0){const W=l.records[0],X=Object.keys(W),se=new Set;(E=t==null?void 0:t.config)!=null&&E.groupByColumns&&t.config.groupByColumns.forEach(H=>{se.add(H.label||H.name),se.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 $=H.alias||H.name;te.add($),te.add(`${$}_count`),te.add(`${$}_sum`),te.add(`${$}_avg`),te.add(`${$}_min`),te.add(`${$}_max`);const ae=H.entityName||H.qualifiedEntityName;ae&&(te.add(`${ae}_${$}`),te.add(`${ae}_${$}_count`))}),X.filter(H=>!se.has(H)&&!te.has(H))}}if((T||I)&&!M&&((q=(B=t==null?void 0:t.config)==null?void 0:B.metricColumns)!=null&&q.length))return t.config.metricColumns.map(W=>W.alias||W.label||W.name);if((z=(Y=t==null?void 0:t.config)==null?void 0:Y.groupByColumns)!=null&&z.length){const W=t.config.groupByColumns[0],X=W.label||W.name,se=new Set;return l.records.forEach(te=>{const ie=te[X];ie!=null&&se.add(String(ie))}),Array.from(se)}return[]},[l,(L=t==null?void 0:t.config)==null?void 0:L.groupByColumns,(A=t==null?void 0:t.config)==null?void 0:A.pivotByColumns,(w=t==null?void 0:t.config)==null?void 0:w.metricColumns,t==null?void 0:t.type]),h=k.useMemo(()=>s.getDefaultChartColors(),[]);k.useEffect(()=>{const I={};x.forEach((T,M)=>{I[T]=s.getColorForValue(T,M,n==null?void 0:n.colorConfig)}),d(I)},[x,n==null?void 0:n.colorConfig,h]);const p=(I,T)=>{const M={...c,[I]:T};d(M);const O={...n||{},colorConfig:{segments:M}};a(O);const E={...t,preferences:O};r(E)},b=(I,T)=>{var q;const M=h[T%h.length],{[I]:O,...E}=((q=n==null?void 0:n.colorConfig)==null?void 0:q.segments)||{},P={...n||{},colorConfig:{segments:E}};a(P);const B={...t,preferences:P};r(B),d(Y=>({...Y,[I]:M}))};if(!x.length||!((t==null?void 0:t.type)==="stackedBar"||(t==null?void 0:t.type)==="stackedLine"?((g=(D=t==null?void 0:t.config)==null?void 0:D.groupByColumns)==null?void 0:g.length)||((v=(y=t==null?void 0:t.config)==null?void 0:y.pivotByColumns)==null?void 0:v.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 N=()=>{const I={...n||{},colorConfig:{segments:{}}};a(I);const T={...t,preferences:I};r(T);const M={};x.forEach((O,E)=>{M[O]=s.getColorForValue(O,E,void 0)}),d(M)},C=Object.keys(((F=n==null?void 0:n.colorConfig)==null?void 0:F.segments)||{}).length>0;return e.jsxs(s.AccordionItem,{value:"colors",className:"border-b-0",children:[e.jsx(s.AccordionTrigger,{className:"flex w-full items-center gap-2 py-2 text-sm font-medium hover:no-underline",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(da,{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:N,children:[e.jsx(Ss,{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((I,T)=>{const M=s.isDefaultColor(c[I],T),O=!M;return e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(s.Popover,{open:o===I,onOpenChange:E=>i(E?I: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:c[I]}})}),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((E,P)=>e.jsxs("button",{className:s.cn("relative h-5 w-5 rounded border-2 transition-all hover:scale-110",c[I]===E?"border-gray-900":"border-transparent"),style:{backgroundColor:E},onClick:()=>{p(I,E),i(null)},children:[P===T%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:E})]},`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:Sr.map((E,P)=>e.jsx("button",{className:s.cn("h-5 w-5 rounded border transition-all hover:scale-110",c[I]===E?"border-2 border-gray-900":E==="#ffffff"?"border border-gray-300":"border border-transparent"),style:{backgroundColor:E},onClick:()=>{p(I,E),i(null)},children:e.jsx("span",{className:"sr-only",children:E})},`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:I,color:c[I]}),i(null)},children:"Custom color"}),!M&&e.jsxs("button",{className:"flex items-center gap-1 text-sm text-muted-foreground hover:text-foreground",onClick:()=>{b(I,T),i(null)},children:[e.jsx(Ss,{className:"h-3 w-3"}),"Reset"]})]})]})})]}),e.jsx("span",{className:"flex-1 truncate text-sm",children:I}),O&&e.jsx("span",{className:"text-xs text-muted-foreground",children:"(custom)"})]},I)})}),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(Dt,{color:u.color,onColorChange:I=>{p(u.value,I),m(null)},onClose:()=>m(null)})})]})]})})]})}function we({value:t,onSave:n,placeholder:a="",type:r="text",className:l=""}){const[c,d]=k.useState(t??""),[o,i]=k.useState(!1);k.useEffect(()=>{d(t??"")},[t]);const u=()=>{n(c),i(!1)},m=()=>{d(t??""),i(!1)};return e.jsxs("div",{className:`flex items-center gap-2 ${l}`,children:[e.jsx(s.Input$1,{placeholder:a,type:r,value:o?c:t??"",onChange:x=>{d(x.target.value),i(!0)},onFocus:()=>i(!0),onClick:x=>x.stopPropagation(),className:"h-8 text-xs",onPointerDown:x=>x.stopPropagation(),onKeyDown:x=>{x.stopPropagation(),x.key==="Enter"&&o&&c!==t?u():x.key==="Escape"&&m()},"aria-label":a||"Edit field"}),o&&c!==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 wr=["auto","number","currency","percent","scientific","date"],Dr=[{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"}],Tr=[{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"}],kr=t=>t.charAt(0).toUpperCase()+t.slice(1);function hs({formatOptions:t={},onFormatOptionsChange:n,showTitle:a=!0,title:r="NUMBER FORMAT"}){const l=t.type||"auto",c=(o,i)=>{n({...t,[o]:i})},d=()=>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:o=>c("type",o),children:[e.jsx(s.SelectTrigger,{className:"h-8 text-xs",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{children:wr.map(o=>e.jsx(s.SelectItem,{value:o,className:"text-xs",children:o==="auto"?"Auto (Default)":kr(o)},o))})]})]}),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??d(),onChange:o=>c("decimalPlaces",parseInt(o.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:o=>c("currency",o),children:[e.jsx(s.SelectTrigger,{className:"h-8 flex-1 text-xs",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{children:Dr.map(o=>e.jsx(s.SelectItem,{value:o.value,className:"text-xs",children:o.label},o.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:o=>c("useSuffix",o)})]}),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:o=>c("locale",o),children:[e.jsx(s.SelectTrigger,{className:"h-8 flex-1 text-xs",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{children:Tr.map(o=>e.jsx(s.SelectItem,{value:o.value,className:"text-xs",children:o.label},o.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:o=>c("prefix",o.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:o=>c("suffix",o.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:o=>c("negativeInParentheses",o)})]}),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:o=>c("multiplyBy",o.target.value?parseFloat(o.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:o=>c("dateFormat",o.target.value),className:"h-8 text-xs"})})]})]})]})}function Ms({axis:t,label:n,type:a,config:r,onChange:l}){var x,h,p,b,f,j,N,C,L,A,w,D;const c=(g,y)=>{l({...r,[g]:y})},d=(g,y)=>{var v,R;l({...r,name:{enabled:g==="enabled"?y:((v=r==null?void 0:r.name)==null?void 0:v.enabled)??!1,text:g==="text"?y:(R=r==null?void 0:r.name)==null?void 0:R.text}})},o=(g,y)=>{var v,R;l({...r,labels:{enabled:g==="enabled"?y:((v=r==null?void 0:r.labels)==null?void 0:v.enabled)??!0,rotation:g==="rotation"?y:(R=r==null?void 0:r.labels)==null?void 0:R.rotation}})},i=(g,y)=>{l({...r,scale:{...r==null?void 0:r.scale,[g]:y===""?"auto":Number(y)}})},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:g=>c("enabled",g),onClick:g=>g.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:g=>d("enabled",g)})]}),((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:g=>d("text",g),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:g=>c("position",g),children:[e.jsx(s.SelectTrigger,{className:"h-8 text-xs",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{children:u.map(g=>e.jsx(s.SelectItem,{value:g,className:"text-xs",children:g==="auto"?"Auto (Default)":s.titleCase(g)},g))})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(s.Label,{className:"text-xs font-medium",children:"LABELS"}),e.jsx(s.SmallSwitch,{checked:((b=r==null?void 0:r.labels)==null?void 0:b.enabled)!==!1,onCheckedChange:g=>o("enabled",g)})]}),((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(((j=r==null?void 0:r.labels)==null?void 0:j.rotation)||"auto"),onValueChange:g=>o("rotation",g==="auto"?"auto":Number(g)),children:[e.jsx(s.SelectTrigger,{className:"h-8 text-xs",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{children:m.map(g=>e.jsx(s.SelectItem,{value:g,className:"text-xs",children:g==="auto"?"Auto (Default)":`${g}°`},g))})]})]})]}),a==="value"&&e.jsx(hs,{formatOptions:(r==null?void 0:r.formatOptions)||{},onFormatOptionsChange:g=>l({...r,formatOptions:g}),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:((N=r==null?void 0:r.scale)==null?void 0:N.min)==="auto"||((C=r==null?void 0:r.scale)==null?void 0:C.min)===void 0?"":String(r.scale.min),onSave:g=>i("min",g),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:((L=r==null?void 0:r.scale)==null?void 0:L.max)==="auto"||((A=r==null?void 0:r.scale)==null?void 0:A.max)===void 0?"":String(r.scale.max),onSave:g=>i("max",g),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:((w=r==null?void 0:r.scale)==null?void 0:w.stepSize)==="auto"||((D=r==null?void 0:r.scale)==null?void 0:D.stepSize)===void 0?"":String(r.scale.stepSize),onSave:g=>i("stepSize",g),className:""})})]})]})]})]})]})}function kt(){const t=s.useEditorStore(d=>d.card),n=s.useEditorStore(d=>{var o;return(o=d.card)==null?void 0:o.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 c=(d,o)=>{const u={...n||{},[d==="x"?"xAxisConfig":"yAxisConfig"]:o};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(_s,{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(Ms,{axis:"x",label:"X-Axis",type:l.xAxisType,config:n==null?void 0:n.xAxisConfig,onChange:d=>c("x",d)}),l.hasYAxis&&e.jsx(Ms,{axis:"y",label:"Y-Axis",type:l.yAxisType,config:n==null?void 0:n.yAxisConfig,onChange:d=>c("y",d)})]})})]})}function Et(){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",c=!(t.type==="stackedBar"||t.type==="stackedLine"),d=(u,m)=>{const x={...n,[u]:m};a(x)},o=["top","bottom","left","right"],i=["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(ta,{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)??c,onCheckedChange:u=>d("display",u)})]}),((n==null?void 0:n.display)??c)&&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=>d("position",u),children:[e.jsx(s.SelectTrigger,{className:"h-8 text-xs",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{children:o.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=>d("align",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))})]})]})]})]})})]})}function It(){var y,v,R,S,F,I,T,M,O;const t=s.useEditorStore(E=>E.card),n=s.useEditorStore(E=>{var P,B;return(B=(P=E.card)==null?void 0:P.preferences)==null?void 0:B.dataLabelsConfig}),a=s.useEditorStore(E=>{var P;return(P=E.card)==null?void 0:P.preferences}),{setCardPreferences:r,updateCardInFrame:l}=s.useEditorActions();if(!t||!s.chartSupportsDataLabels(t.type))return null;const c=((y=a==null?void 0:a.chartOptions)==null?void 0:y.indexAxis)==="y",d=t.type==="stackedBar"||t.type==="stackedLine",o=t.type==="pie"||t.type==="doughnut"||t.type==="polarArea"||t.type==="funnel",i=!o,u=(R=(v=a==null?void 0:a.chartOptions)==null?void 0:v.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=(E,P)=>{const B={...n,[E]:P},q={...t.preferences||{},dataLabelsConfig:B};r(q);const Y={...t,preferences:q};l(Y)},p=(E,P)=>{const B={...n,font:{...n==null?void 0:n.font,[E]:P}},q={...t.preferences||{},dataLabelsConfig:B};r(q);const Y={...t,preferences:q};l(Y)},b=(E,P)=>{const B={...n,formatOptions:{...n==null?void 0:n.formatOptions,[E]:P}},q={...t.preferences||{},dataLabelsConfig:B};r(q);const Y={...t,preferences:q};l(Y)},j=(()=>{const E=t.type;return E==="stackedBar"||E==="stackedLine"||E==="pie"||E==="doughnut"?"center":c?"right":"top"})();let N=[];d||o?N=["center"]:N=["auto",...(c?["center","left","right"]:["center","top","bottom"]).filter(P=>P!==j),"custom"];const C=()=>s.titleCase(j),L=["center","start","end"],A=["center","start","end","top","bottom"],w=i?["auto","number","currency","percent","none"]:["number","currency","percent","none"],D=[{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"}],g=[{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(ja,{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:E=>h("enabled",E)})]}),x&&e.jsxs(e.Fragment,{children:[!d&&!o&&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:E=>h("position",E),children:[e.jsx(s.SelectTrigger,{className:"h-8 text-xs",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{children:N.map(E=>e.jsx(s.SelectItem,{value:E,className:"text-xs",children:E==="auto"?C():E==="custom"?"Custom (Advanced)":s.titleCase(E)},E))})]})]}),d&&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:E=>h("showTotal",E)})]}),(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:E=>h("anchor",E),children:[e.jsx(s.SelectTrigger,{className:"h-8 text-xs flex-1",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{children:L.map(E=>e.jsx(s.SelectItem,{value:E,className:"text-xs",children:s.titleCase(E)},E))})]})]}),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:E=>h("align",E),children:[e.jsx(s.SelectTrigger,{className:"h-8 text-xs flex-1",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{children:A.map(E=>e.jsx(s.SelectItem,{value:E,className:"text-xs",children:s.titleCase(E)},E))})]})]})]}),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)||(i?"auto":"none"),onValueChange:E=>h("format",E),children:[e.jsx(s.SelectTrigger,{className:"h-8 text-xs",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{children:w.map(E=>e.jsx(s.SelectItem,{value:E,className:"text-xs",children:E==="auto"&&i?"Auto (Use Axis)":E==="none"?"None (Raw Value)":s.titleCase(E)},E))})]})]}),(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:E=>b("decimalPlaces",Number(E)),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:((F=n==null?void 0:n.formatOptions)==null?void 0:F.currency)||"USD",onValueChange:E=>b("currency",E),children:[e.jsx(s.SelectTrigger,{className:"h-8 text-xs flex-1",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{children:D.map(E=>e.jsx(s.SelectItem,{value:E.value,className:"text-xs",children:E.label},E.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:((I=n==null?void 0:n.formatOptions)==null?void 0:I.useSuffix)??!1,onCheckedChange:E=>b("useSuffix",E)})]}),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:((T=n==null?void 0:n.formatOptions)==null?void 0:T.locale)||"en-US",onValueChange:E=>b("locale",E),children:[e.jsx(s.SelectTrigger,{className:"h-8 text-xs flex-1",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{children:g.map(E=>e.jsx(s.SelectItem,{value:E.value,className:"text-xs",children:E.label},E.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(((M=n==null?void 0:n.font)==null?void 0:M.size)||12),onSave:E=>p("size",Number(E)),className:""})})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(s.Label,{className:"text-xs text-muted-foreground w-20",children:"Weight"}),e.jsxs(s.Select,{value:((O=n==null?void 0:n.font)==null?void 0:O.weight)||"normal",onValueChange:E=>p("weight",E),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:E=>{E==="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:E=>h("rotation",Number(E)),className:""})}),e.jsx("span",{className:"text-xs text-muted-foreground",children:"degrees"})]})]})]})]})})]})}function Er(){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(Tt,{}),e.jsx(kt,{}),e.jsx(Et,{}),e.jsx(It,{})]})]})}const Ir=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."]})]}),Ar=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."]})]}),Mr=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 Rr(){const t=s.useEditorStore(a=>a.card.type);function n(a){const r=["kpi","table","text","map","custom"],l=c=>r.includes(a)?c:e.jsxs(e.Fragment,{children:[c,e.jsx(Er,{})]});switch(a){case"stackedBar":case"stackedLine":return l(e.jsx(vr,{}));case"tornado":case"pyramid":return l(e.jsx(Ge,{docContent:Ir,cardType:a}));case"kpi":return e.jsx(xr,{});case"line":case"bar":return l(e.jsx(lr,{cardType:a}));case"range":return l(e.jsx(Ge,{docContent:Ar,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(or,{cardType:a}));case"table":return e.jsx(yr,{cardType:a});case"text":return e.jsx(Ge,{docContent:Mr,cardType:a,suffix:"Visual"});case"map":return e.jsx(jr,{});case"custom":return e.jsx(tr,{});default:return l(e.jsx(dr,{}))}}return e.jsxs(s.ScrollArea,{className:"h-full w-full text-sm",children:[n(t),e.jsx(s.ScrollBar,{orientation:"horizontal"})]})}function Lr(){const t=k.useRef(null),n=k.useRef(null),a=s.useEditorStore(l=>l.isShowingVisual),r=s.useEditorStore(l=>l.showAIDialog);return k.useEffect(()=>{var l,c,d,o;r?((l=t.current)==null||l.resize(0),(c=n.current)==null||c.resize(0)):((d=t.current)==null||d.resize(25),(o=n.current)==null||o.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(Bn,{})}),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(Rr,{})})}),!r&&e.jsx(s.ResizableHandle,{}),e.jsx(s.ResizablePanel,{minSize:40,defaultSize:75,maxSize:100,children:e.jsx(Es,{})})]}):e.jsx(Es,{})})]})}function Fr(t){s.useAIInteractionStore(U=>U.currentAIContext);const[n,a]=k.useState(""),[r,l]=k.useState(null),{authToken:c,tokenProps:d}=s.useSemaphorContext(),o=s.useEditorStore(U=>{var ee;return(ee=U==null?void 0:U.card)==null?void 0:ee.sql}),i=s.useEditorStore(U=>U.isDevMode),u=s.useEditorStore(U=>{var ee;return(ee=U==null?void 0:U.card)==null?void 0:ee.python}),{setCardPython:m,setCardSql:x,setRunSql:h,switchCardType:p,setQueryConfig:b}=s.useEditorActions(),f=s.useEditorStore(U=>U.currentAssitantScope)||[],j=s.useEditorStore(U=>U.userInputForAI),N=s.useEditorStore(U=>U.triggerAIRun),C=s.useEditorStore(U=>U.card),L=s.useEditorStore(U=>U.selectedDatabaseName),A=s.useEditorStore(U=>U.selectedTableName),w=s.useEditorStore(U=>U.selectedConnectionId),D=s.useEditorStore(U=>U.selectedSchemaName),g=s.useDashboardStore(U=>U.dashboard.aiScopeTables),{errorMessage:y,refetch:v,data:R}=s.useDashboardCardQuery(C),{setTriggerAIRun:S,setCurrentAssitantScope:F,setCardConfig:I}=s.useEditorActions(),{selectedDatamodelName:T,connectionType:M,selectedDatamodelId:O}=s.useEditorAside(),{messages:E,setMessages:P,regenerate:B,error:q,sendMessage:Y,status:z,addToolResult:W,stop:X,clearError:se}=s.useChat({transport:new s.DefaultChatTransport({api:`${d.apiServiceUrl}/v1/assistant`,headers:()=>({Authorization:`Bearer ${c==null?void 0:c.accessToken}`}),body:()=>{const U=s.useAIInteractionStore.getState();return{random:Math.random(),assistantId:"editor-assistant",isDevMode:i,aiContext:U.currentAIContext,reasoningEffort:U.reasoningEffort,showReasoning:U.showReasoning}},credentials:"omit",prepareSendMessagesRequest:({messages:U,body:ee})=>({body:{...ee,messages:s.cleanupIncompleteMessages(U)}})}),onError:U=>{var ee;if(U.name==="AbortError"||(ee=U.message)!=null&&ee.includes("aborted")){console.log("[Editor Assistant] Stream aborted (expected)");return}console.error("[Editor Assistant] Stream error:",U)},onToolCall:te,onFinish({isAbort:U,isDisconnect:ee,isError:ce}){a(""),console.log(U?"[Editor Assistant] Stream aborted by user":ee?"[Editor Assistant] Stream disconnected (network error)":ce?"[Editor Assistant] Stream error occurred":"[Editor Assistant] Stream completed successfully")}});k.useEffect(()=>{N&&j&&(Y({role:"user",parts:[{type:"text",text:j}]}),S(!1))},[N,j,Y,S]);async function te({toolCall:U}){var ee,ce,le,fe,ue,K,_,V,Z,oe,de,ne,me,pe,Re,Le;if(["createChartFromSql","createForecast"].includes(U.toolName)){const De=((ee=U.input)==null?void 0:ee.sql)??((ce=U.args)==null?void 0:ce.sql),ve=((le=U.input)==null?void 0:le.python)??((fe=U.args)==null?void 0:fe.python),J=((ue=U.input)==null?void 0:ue.chartType)??((K=U.args)==null?void 0:K.chartType);p(J),x(De),m(ve),h(!0),W({tool:U.toolName,toolCallId:U.toolCallId,output:{status:"success",message:"Let the user know that chart is created"}})}else if(U.toolName==="getUserSql"){if(!o){W({tool:U.toolName,toolCallId:U.toolCallId,output:{status:"error",message:"No SQL found"}});return}W({tool:U.toolName,toolCallId:U.toolCallId,output:{status:"success",sql:o,python:u||""}})}else if(U.toolName==="generateQueryConfig"){a("Generating query config...");const De=((_=U.input)==null?void 0:_.chartType)??((V=U.args)==null?void 0:V.chartType),ve=((Z=U.input)==null?void 0:Z.queryConfig)??((oe=U.args)==null?void 0:oe.queryConfig);((de=U.input)==null?void 0:de.cardConfig)??((ne=U.args)==null||ne.cardConfig),p(De),I(ve),x(void 0),m(void 0);const J=await v();if((me=J==null?void 0:J.data)!=null&&me.error){W({tool:U.toolName,toolCallId:U.toolCallId,output:{status:"error",queryConfig:ve,message:(pe=J==null?void 0:J.data)==null?void 0:pe.error.message}});return}if((Re=J==null?void 0:J.data)!=null&&Re.records){W({tool:U.toolName,toolCallId:U.toolCallId,output:{status:"success",queryConfig:ve,message:"The data has been visualized"}});return}W({tool:U.toolName,toolCallId:U.toolCallId,output:{status:"success",queryConfig:ve,message:"The data has been visualized",records:(Le=J==null?void 0:J.data)==null?void 0:Le.records}})}else a("Analyzing...")}function ie(U){const ee=s.removeFromScopeArray(f,U);H(ee)}function H(U){const ee=s.sanitizeAIScope(U);F(ee),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(ee)}`}]}])}function $(){const U={databaseName:L||"",schemaName:D||"",tableName:A||"",datamodelId:O||"",datamodelName:s.resolveDatamodelName(T),connectionId:w||"",connectionType:M||""},ee=s.dedup([...f,U]);H(ee)}function ae(){const U={databaseName:L||"",schemaName:D||"",tableName:A||"",datamodelName:s.resolveDatamodelName(T),connectionId:w||"",connectionType:M||"",datamodelId:O||""};if(!s.isInAiScopeArray([...g||[],...f],U)||f.length===0){const ce=s.dedup([...g||[],...f,U]).filter(le=>le.connectionId===U.connectionId);H(ce)}}const Q=!["ready","error"].includes(z),re=s.getErrorMessage(q);return{messages:E,setMessages:P,sendMessage:Y,regenerate:B,isLoading:Q,handleSetAIScope:ae,handleAddCurrentTableToScope:$,removeFromCurrentSelections:ie,currentAssitantScope:f,setCurrentAssitantScope:F,stop:X,status:z,toolStatus:n,llmUsage:r,onFinish:t,errorMessage:re,clearError:se}}const Or=[{title:"Help me write a query for",subtitle:"orders by month"},{title:"Create a bar chart for",subtitle:"sales by category"}];function Rs({isFullscreen:t,onFullscreenChange:n,fullscreenContainer:a}){const r=k.useRef(null),[l,c]=k.useState(!1),[d,o]=k.useState(s.isDevEnv),[i,u]=k.useState(!1),[m,x]=k.useState(!1),[h,p]=k.useState(!1),b=t??h,f=s.useCurrentAIContext(),{setCurrentAIContext:j}=s.useAIActions(),{clearQueue:N}=s.useQueueActions(),{clearFileAttachments:C}=s.useFileActions(),L=s.useFileAttachments("editor"),A=s.useDashboardStore(J=>J.dashboard.aiContext),w=s.useEditorStore(J=>J.card.dataSource),D=s.useEditorStore(J=>J.actions.setCardSql),g=s.useEditorStore(J=>J.actions.setRunSql),y=s.useEditorStore(J=>J.showAIDialog),v=s.useDashboardStore(J=>J.handleOpenAssistantProfile),{setShowAIDialog:R,setCardPython:S}=s.useEditorActions(),{setDataSource:F}=s.useEditorActions(),{assistantProfile:I}=s.useAssistantProfile(),{messages:T,setMessages:M,sendMessage:O,isLoading:E,stop:P,status:B,llmUsage:q,errorMessage:Y,clearError:z}=Fr(),[W,X]=k.useState(""),se=J=>{X(J.target.value)},te=J=>{J.preventDefault();const ge=W.trim();if(!ge&&L.length===0)return;const Be=[];ge&&Be.push({type:"text",text:ge}),L.forEach(ke=>{ke.data&&Be.push({type:"file",mediaType:ke.type,filename:ke.name,url:`data:${ke.type};base64,${ke.data}`})}),O({role:"user",parts:Be}),X(""),C("editor"),le({force:!0})},{visibleMessages:ie,hasMoreMessages:H,totalMessageCount:$,loadMoreMessages:ae,resetMessageWindow:Q}=s.useMessageWindow(T,{maxVisibleMessages:15,initialLoadCount:10,loadMoreCount:5}),{scrollRef:re,isAtBottom:U,hasNewMessages:ee,newMessageCount:ce,scrollToBottom:le,handleScroll:fe,resetNewMessageCount:ue}=s.useAutoScroll(ie,{threshold:50,behavior:"smooth"});k.useEffect(()=>{var J;y&&((J=r.current)==null||J.focus(),j({selectedEntities:(w==null?void 0:w.selectedEntities)||[]}))},[y,w,j]),s.useAutoSubmitQueue({assistantType:"editor",status:B,isLoading:E,sendMessage:O});const{hasActiveTools:K}=s.useActiveToolStatus(T),_=k.useCallback(J=>{n==null||n(J),t===void 0&&p(J)},[t,n]);k.useEffect(()=>{if(!b)return;function J(ge){ge.key==="Escape"&&_(!1)}return window.addEventListener("keydown",J),()=>{window.removeEventListener("keydown",J)}},[b,_]);const V=k.useCallback(J=>{O({role:"user",parts:[{type:"text",text:J}]}),le({force:!0})},[O,le]),Z=k.useCallback(async()=>{const J=JSON.stringify(T??[],null,2);try{if(typeof navigator>"u"||!navigator.clipboard)throw new Error("Clipboard API unavailable");await navigator.clipboard.writeText(J),s.ue.success("Conversation copied")}catch(ge){console.error("Failed to copy conversation",ge),s.ue.error("Unable to copy conversation")}},[T]),oe=k.useCallback(()=>{_(!b)},[b,_]);function de(J,ge){ge==="sql"?(D(J),g(!0)):ge==="python"&&(S(J),g(!0))}function ne(){f.selectedEntities.length===0&&j({selectedEntities:(A==null?void 0:A.selectedEntities)||[]})}function me(J){ne();const ge={role:"user",parts:[{type:"text",text:J.title+" "+J.subtitle}]};O(ge)}function pe(J){ne(),O({role:"user",parts:[{type:"text",text:J}]})}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:c,children:"Token Usage"}),e.jsx(s.DropdownMenuCheckboxItem,{checked:d,onCheckedChange:o,children:"Tool Invocations"}),e.jsx(s.DropdownMenuCheckboxItem,{checked:i,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=(W==null?void 0:W.length)===0&&(T==null?void 0:T.filter(J=>J.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",b&&"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(),v&&e.jsx(s.Button,{variant:"outline",size:"sm",className:"h-7 p-2",onClick:v,children:(I==null?void 0:I.name)||"Default Profile"}),e.jsxs("div",{"data-role":"header-actions",className:"flex items-center",children:[Re(),d&&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:b?"Exit Fullscreen":"Expand",className:"h-7 p-2 text-muted-foreground hover:text-foreground",onClick:oe,children:b?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:()=>{M([]),N("editor"),z(),Q()},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,$-ie.length)," ","more messages (",$-ie.length," ","hidden)"]})}),e.jsx(s.PrintMessages,{messages:ie,showTools:d,handleRun:de,showSystemMessage:i,onQuickReply:V,disableQuickReplies:E}),!K&&e.jsx(s.AssistantStatus,{status:B,errorMessage:Y})]})}),!U&&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"}),ee&&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&&!I&&e.jsx(s.Placeholders,{onClick:me,placeholders:Or}),e.jsx("div",{children:De&&I&&e.jsx(s.SeedQuestions,{seedQuestions:I.seedQuestions||[],handleSeedQuestionClick:pe})})]}),e.jsx(s.PendingMessagesDisplay,{assistantType:"editor",className:"mb-3"}),e.jsx(s.ChatInputWithContext,{ref:r,setInput:X,stop:P,input:W,handleInputChange:se,handleSubmit:J=>{ne(),te(J),le({force:!0})},isLoading:E,status:B,assistantType:"editor",onFocus:()=>{}})]}),q&&l&&e.jsx("div",{className:"flex h-8 items-center justify-between",children:e.jsxs("div",{className:"text-xs text-muted-foreground",children:["Usage: ",q.inputTokens," prompt tokens, ",q.outputTokens," ","completion tokens, ",q.totalTokens," total tokens"]})}),e.jsx(s.DataSourceDialog,{incomingSelectedEntities:(w==null?void 0:w.selectedEntities)||[],open:m,onOpenChange:x,dataSource:w||s.EMPTY_DATA_SOURCE,dialogMode:"aiContext"})]});return b&&a?Vt.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 xs(t,n){const[a,r]=k.useState(()=>{const l=localStorage.getItem(t);return l?JSON.parse(l):n});return k.useEffect(()=>{localStorage.setItem(t,JSON.stringify(a))},[a,t]),[a,r]}const Pr="chart-selector-standard-first";function Br(){const[t,n]=xs(Pr,!0);return{standardFirst:t,updatePreference:n}}const Ls=({pluginVisual:t,index:n,onSelect:a})=>{const r=Je(t.icon||""),l=t.name.charAt(0).toUpperCase(),c=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"}):c||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}`)},Fs=["default","standardPlugin","customPlugin"];function Vr({selectedChart:t,onChartChange:n}){var A;const[a,r]=k.useState(!1),{data:l}=jt();Br();const d=((A=s.useEditorStore(w=>w.card).customCardPreferences)==null?void 0:A.url)||"";os(d);const{setCardType:o,setCardPreferences:i,setIsDevMode:u}=s.useEditorStore(w=>w.actions),{setCardCustomCfg:m,setCustomCardPreferences:x,setQueryConfig:h}=s.useEditorActions(),[p,b]=xs("chart-section-active",null),f=k.useMemo(()=>p?[p,...Fs.filter(w=>w!==p)]:Fs,[p]);function j(w){m(null),i({}),o(w),["custom","map"].includes(w)&&(u(!0),h(void 0)),n(w),r(!1)}function N(w){m(null),i({}),o("custom"),x({type:"component",visualType:"single",url:w.url,componentName:w.name,icon:w.icon,pluginChartType:w.chartType}),h(void 0),n("custom"),r(!1)}const C=()=>{var D;if(t==="custom"){const g=s.useEditorStore.getState().card;return((D=g==null?void 0:g.customCardPreferences)==null?void 0:D.componentName)||"Custom Visual"}const w=s.chartTypes.find(g=>g.id===t);return(w==null?void 0:w.label)||"Select chart type"},L=()=>{var D,g;if(t==="custom"){const y=s.useEditorStore.getState().card,v=(D=y==null?void 0:y.customCardPreferences)==null?void 0:D.icon,R=(g=y==null?void 0:y.customCardPreferences)==null?void 0:g.componentName;if(v&&R)return e.jsx(zr,{icon:v,componentName:R});if(R){const S=s.getAutoDetectedChartIcon(R);if(S)return S}return e.jsx(ze,{className:"h-4 w-4"})}const w=s.chartTypes.find(y=>y.id===t);if(w){const y=w.icon;return e.jsx(y,{className:"h-4 w-4"})}return e.jsx(ze,{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:[L(),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(w=>{if(w==="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:D=>b(D?"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(D=>{const g=D.icon;return e.jsx(s.CommandItem,{value:`${D.label} ${D.id} chart graph visualization`,onSelect:()=>j(D.id),className:"flex items-center gap-2",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(g,{className:"h-4 w-4"}),e.jsx("span",{children:D.label})]})},D.id)})},"default");if(w==="standardPlugin"){const D=l.filter(g=>g.pluginType==="standard");return D.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:g=>b(g?"standardPlugin":null),className:"scale-75"})]})]}),className:"[&_[cmdk-group-heading]]:text-sm [&_[cmdk-group-heading]]:font-medium [&_[cmdk-group-heading]]:text-muted-foreground",children:D.filter(g=>g.componentType==="chart").map((g,y)=>e.jsx(Ls,{pluginVisual:g,index:y,onSelect:()=>N(g)},`${g.url}-${g.name}-${y}`))},"standardPlugin"):null}if(w==="customPlugin"){const D=l.filter(g=>g.pluginType==="custom");return D.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:g=>b(g?"customPlugin":null),className:"scale-75"})]})]}),className:"[&_[cmdk-group-heading]]:text-sm [&_[cmdk-group-heading]]:font-medium [&_[cmdk-group-heading]]:text-muted-foreground",children:D.map((g,y)=>e.jsx(Ls,{pluginVisual:g,index:y,onSelect:()=>N(g)},`${g.url}-${g.name}-${y}`))},"customPlugin"):null}return null})]})]})})]})})}const zr=({icon:t,componentName:n})=>{const a=Je(),r=s.getAutoDetectedChartIcon(n);return a?e.jsx(a,{className:"h-4 w-4"}):r||e.jsx(ze,{className:"h-4 w-4"})},Ur=[{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 _r({selectedChart:t,onChartChange:n}){var l;const a=s.useEditorStore(c=>c.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:Ur.map(c=>{if(c.requiresPivot&&!r)return null;const d=c.icon,o=t===c.id;return e.jsxs(s.Tooltip,{children:[e.jsx(s.TooltipTrigger,{asChild:!0,children:e.jsxs(s.Button,{variant:"ghost",size:"sm",onClick:()=>n(c.id),className:s.cn("h-8 w-8 p-0",o&&"bg-accent text-accent-foreground"),children:[e.jsx(d,{className:"h-4 w-4"}),e.jsx("span",{className:"sr-only",children:c.label})]})}),e.jsx(s.TooltipContent,{side:"bottom",children:e.jsx("p",{children:c.label})})]},c.id)})})}const ps=({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(rs,{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($s,{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 Gr({aliasTemplate:t,onAliasTemplateChange:n}){var i;const[a,r]=k.useState(t),[l,c]=k.useState(!1),d=(i=s.useEditorStore(u=>{var m;return(m=u.card.config)==null?void 0:m.pivotByColumns}))==null?void 0:i[0],o=d?`e.g. Min Sales in {{${d.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:o,value:l?a:t,onChange:u=>{r(u.target.value),c(!0)},onFocus:()=>c(!0),onPointerDown:u=>u.stopPropagation(),className:"h-8 text-xs",onKeyDown:u=>{u.key==="Enter"&&l&&a!==t?(n(a),c(!1)):u.key==="Escape"&&(r(t),c(!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),c(!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),c(!1)},children:e.jsx(s.X,{className:"h-4 w-4 text-gray-400"})})]})]})]})}function $r({valueAliases:t,onValueAliasesChange:n}){const[a,r]=k.useState(null),[l,c]=k.useState(""),[d,o]=k.useState(""),i=()=>{n({...t,"":""})},u=x=>{const h={...t};delete h[x],n(h)},m=x=>{const h={...t};delete h[x],h[l]=d,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:b=>c(b.target.value),className:"h-8 w-24 text-xs",onPointerDown:b=>b.stopPropagation(),onKeyDown:b=>{b.key==="Enter"?m(x):b.key==="Escape"&&r(null)},"aria-label":"Edit value alias key"}),e.jsx(s.Input$1,{placeholder:"Alias label",value:d,onChange:b=>o(b.target.value),className:"h-8 w-24 text-xs",onPointerDown:b=>b.stopPropagation(),onKeyDown:b=>{b.key==="Enter"?m(x):b.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),c(x),o(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),c(x),o(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:i,children:[e.jsx(s.Plus,{className:"mr-1 h-3 w-3"})," Add Value Alias"]})]})]})}function Yr({column:t}){const n=s.useEditorStore(i=>i.card.type),a=s.useEditorStore(i=>{var u,m;return(m=(u=i.card)==null?void 0:u.config)==null?void 0:m.metricColumns}),r=(a==null?void 0:a.map(i=>i.label))||[],l=r==null?void 0:r.find(i=>i===t.label||i===t.name),c=l?r.indexOf(l):-1;function d(){return e.jsx("div",{className:"pr-1",children:l&&e.jsx(St,{idx:c,col:l,children:e.jsx("div",{className:"w-[130px] text-xs text-muted-foreground",children:"Display Series As"})})})}function o(){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(wt,{})]})}return e.jsxs("div",{className:"space-y-1",children:[["stackedBar","stackedLine","bar","line"].includes(n)&&d(),["pie","doughnut"].includes(n)&&o()]})}function qr({field:t,searchQuery:n="",limit:a=500}){const{authToken:r,tokenProps:l}=s.useSemaphorContext(),c=s.useEditorStore(u=>u.card),d=c==null?void 0:c.dataSource,o=["attribute-values",t.entityName,t.name,n,a],i=s.useQuery({queryKey:o,queryFn:async()=>{if(!(d!=null&&d.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:d.connectionId,cardConfig:u,cardDataSource:d,cache_config:s.getCacheConfig({card:c})};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(b=>{const f=b[h]||b[t.alias||h]||b[t.label];return{id:f||"",value:f||"",label:String(f||"(empty)")}})}catch(u){return console.error("Error fetching attribute values:",u),[]}},enabled:!!t&&!!(d!=null&&d.connectionId),staleTime:5*60*1e3,gcTime:10*60*1e3});return{values:i.data||[],isLoading:i.isLoading,isFetching:i.isFetching,isError:i.isError,error:i.error,refetch:i.refetch}}function Kr({open:t,onOpenChange:n,availableFields:a,existingFilters:r,editingCondition:l,onSave:c}){var L,A;const d=!!l,[o,i]=k.useState(d?"values":"fields"),[u,m]=k.useState(""),[x,h]=k.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(w=>{var g;return d?!1:!((g=r==null?void 0:r.conditions)==null?void 0:g.some(y=>y.field.id===w.id))&&w.label.toLowerCase().includes(u.toLowerCase())}),b=w=>{h({...x,field:w}),i("values")},f=()=>{if(x.field&&x.selectedValues.length>0){const w={id:x.id,field:x.field,operator:"in",value:x.selectedValues};let D;if(d){const g=((r==null?void 0:r.conditions)||[]).map(y=>y.id===l.id?w:y);D={...r,conditions:g}}else{const g=(r==null?void 0:r.conditions)||[];D={id:(r==null?void 0:r.id)||s.v4(),logicalOperator:"AND",negate:!1,conditions:[...g,w],groups:[]}}c(D),n(!1)}},j=()=>{if(!d||!l)return;const w=((r==null?void 0:r.conditions)||[]).filter(D=>D.id!==l.id);if(w.length>0){const D={...r,conditions:w};c(D)}else c(void 0);n(!1)},N=w=>{h({...x,selectedValues:w})},C=()=>{d&&l?(h({id:l.id,field:l.field,selectedValues:Array.isArray(l.value)?l.value:[l.value]}),i("values")):(h({id:s.v4(),field:null,selectedValues:[]}),i("fields")),m("")};return k.useEffect(()=>{t&&C()},[t,d,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:d?`Edit Filter: ${(L=x.field)==null?void 0:L.label}`:o==="fields"?"Select Field to Filter":`Select Values for ${(A=x.field)==null?void 0:A.label}`})}),e.jsxs("div",{className:"space-y-4",children:[!d&&(r==null?void 0:r.conditions)&&r.conditions.length>0&&o==="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(w=>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:[w.field.label,":"]}),e.jsx("span",{className:"text-muted-foreground",children:Array.isArray(w.value)?`${w.value.length} values`:String(w.value)})]},w.id))})]}),o==="fields"&&!d?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:w=>m(w.target.value),className:"pl-10"})]}),e.jsx("div",{className:"grid grid-cols-2 gap-2 max-h-[400px] overflow-y-auto",children:p.map(w=>e.jsxs(s.Button,{variant:"outline",className:"justify-start h-auto py-2 px-3",onClick:()=>b(w),children:[e.jsx(ps,{dataType:s.getDataType(w.dataType)}),e.jsxs("div",{className:"ml-2 text-left",children:[e.jsx("div",{className:"text-sm font-medium",children:w.label}),e.jsxs("div",{className:"text-xs text-muted-foreground",children:[w.entityName,".",w.name]})]})]},w.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(Hr,{field:x.field,selectedValues:x.selectedValues,onValuesChange:N,onBack:d?void 0:()=>i("fields")}),e.jsxs("div",{className:"flex justify-between pt-4 border-t",children:[e.jsx("div",{children:d?e.jsx(s.Button,{variant:"destructive",onClick:j,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 Hr({field:t,selectedValues:n,onValuesChange:a,onBack:r}){const[l,c]=k.useState(""),{values:d,isLoading:o,isFetching:i}=qr({field:t,searchQuery:l,limit:500}),u=l?d.filter(h=>String(h.value).toLowerCase().includes(l.toLowerCase())):d,m=h=>{const p=n.includes(h);a(p?n.filter(b=>b!==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=>c(h.target.value),className:"pl-10"})]}),o||i?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(ms,{className:"text-sm",children:h.label})]},h.id))})]})]})}function Qr({field:t,zone:n,index:a,sortDirection:r,onSortDirectionChange:l,hasPivotColumns:c=!1,cardType:d}){var gs,js,bs,vs;const{attributes:o,listeners:i,setNodeRef:u,transform:m,transition:x,isDragging:h}=s.useSortable({id:t.id}),p=s.useEditorStore(G=>G.card),{updateLabel:b,handleAggregationChange:f,handleDateFormatChange:j,handleGranularityChange:N,handleAliasTemplateChange:C,handleValueAliasesChange:L,removeField:A,handleKpiComparisonTypeChange:w,handleKpiShowTrendlineChange:D,handleKpiTrendlineWindowChange:g,handleKpiTrendlineGranularityChange:y,handleKpiTargetValueChange:v}=ds(p),[R,S]=k.useState(!1),[F,I]=k.useState(!1),[T,M]=k.useState(null),[O,E]=k.useState(t.dateFormat||"YYYY-MM-DD"),[P,B]=k.useState(t.customFormat||""),[q,Y]=k.useState(!!t.customFormat),[z,W]=k.useState(t.granularity||"day"),[X,se]=k.useState(t.aliasTemplate||""),[te,ie]=k.useState(t.valueAliases||{}),[H,$]=k.useState((gs=t.parameters)==null?void 0:gs.filters),ae=G=>{G==="custom"?Y(!0):(Y(!1),E(G),n==="groupBy"&&j(a,G,""))},Q=G=>{B(G),n==="groupBy"&&j(a,"custom",G)},re=G=>{var je;W(G);const xe=(je=Z(G)[0])==null?void 0:je.value;xe&&!q&&(E(xe),n==="groupBy"&&j(a,xe,"")),n==="groupBy"&&N(a,G)},U=G=>{se(G),n==="metrics"&&C(a,G)},ee=G=>{ie(G),n==="metrics"&&L(a,G)},ce=G=>{b(n,a,G)},le=G=>{var he;if($(G),n==="metrics"){const xe={...t,parameters:{...t.parameters,filters:G}},je=[...((he=p.config)==null?void 0:he.metricColumns)||[]];je[a]=xe,s.useEditorStore.getState().actions.updateCardConfig(p.id,{metricColumns:je})}I(!1)},fe=()=>{A(n,a)},ue={transform:s.CSS.Transform.toString(m),transition:x},K=s.getDataType(t.dataType),_=K==="date",V=d==="kpi",Z=G=>{switch(G){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..."}]}},oe=Z(z),de=n!=="pivotBy",ne=_&&n==="groupBy"&&(!V||((js=p.config)==null?void 0:js.comparisonType)==="start_vs_end"),me=!V&&_&&n==="groupBy",pe=V&&_&&n==="groupBy",Re=V&&n==="metrics"&&((bs=p.config)==null?void 0:bs.comparisonType)==="target",Le=n==="metrics",De=()=>e.jsx("div",{title:`${t.entityName}.${t.name}`,onPointerDown:G=>{G.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,J=()=>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(G=>e.jsx(s.SelectItem,{className:"text-xs",value:G,children:s.toTitleCase(G)},G))})]})]}):null,ge=()=>me?e.jsxs(e.Fragment,{children:[J(),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:q?"custom":O,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:oe.map(G=>e.jsx(s.SelectItem,{className:"text-xs",value:G.value,children:G.label},G.value))})]}),q&&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:G=>{G.stopPropagation(),Q(G.target.value)},onClick:G=>G.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 G,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:((G=p.config)==null?void 0:G.comparisonType)||"none",onValueChange:w,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:"start_vs_end",children:"Start vs End"})]})]})]}),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:D})]})}),((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:Ue=>{const Bt=parseInt(Ue.target.value)||30;g(Bt)},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:y,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 G,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:((G=p.config)==null?void 0:G.targetValue)!==void 0&&((he=p.config)==null?void 0:he.targetValue)!==null?String(p.config.targetValue):"",onSave:xe=>{!isNaN(Number(xe))&&xe!==null?v(Number(xe)):v(0)},placeholder:"Enter target value...",type:"text"})]}):null},Ft=()=>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:G=>{f(a,G)},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(G=>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:()=>{M(G),I(!0)},children:[e.jsxs("span",{className:"font-medium",children:[G.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(G.value)?G.value.length===1?String(G.value[0]):G.value.length<=2?G.value.join(", "):`${G.value.slice(0,2).join(", ")} +${G.value.length-2}`:String(G.value)})}),Array.isArray(G.value)&&G.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 (",G.value.length,"):"]}),e.jsx("div",{className:"max-h-[200px] overflow-y-auto",children:G.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!==G.id);if(xe.length>0){const Te={...H,conditions:xe};le(Te)}else if($(void 0),n==="metrics"){const Te={...t,parameters:{...t.parameters,filters:void 0}},Ue=[...((je=p.config)==null?void 0:je.metricColumns)||[]];Ue[a]=Te,s.useEditorStore.getState().actions.updateCardConfig(p.id,{metricColumns:Ue})}},children:e.jsx(s.X,{className:"h-3 w-3"})})]},G.id))}),e.jsxs(s.Button,{variant:"outline",size:"sm",className:"h-8 w-full justify-start text-xs",onClick:()=>{M(null),I(!0)},children:[e.jsx(s.Filter,{className:"mr-2 h-3 w-3"}),"Add attribute filter"]})]}),e.jsx(Yr,{column:t}),c&&e.jsxs(e.Fragment,{children:[e.jsx(Gr,{aliasTemplate:X,onAliasTemplateChange:U}),e.jsx($r,{valueAliases:te,onValueAliasesChange:ee})]})]}):null,{columns:Ot=[]}=s.useColumns(),Pt=(H==null?void 0:H.conditions)&&H.conditions.length>0;return e.jsxs(e.Fragment,{children:[e.jsxs("div",{ref:u,style:ue,...o,...i,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(ps,{dataType:K}),e.jsx(ms,{className:s.cn("w-[140px] flex-1 text-sm",Pt&&"w-[120px]"),children:s.getMetricDisplayLabel(t)}),n==="metrics"&&((vs=H==null?void 0:H.conditions)==null?void 0:vs.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(G=>e.jsxs("div",{children:[G.field.label,":"," ",Array.isArray(G.value)?`${G.value.length} values`:String(G.value)]},G.id))})})]})}),n!=="sortBy"&&e.jsx(s.Button,{variant:"ghost",size:"sm",className:"h-6 w-6 p-0",onClick:G=>{G.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:G=>{G.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:G=>{G.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(),d==="kpi"&&J(),ge(),Be(),ke(),Ft()]})]}),F&&e.jsx(Kr,{open:F,onOpenChange:G=>{I(G),G||M(null)},availableFields:Ot,existingFilters:H,editingCondition:T,onSave:G=>{var he;if(G)le(G);else if($(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})}M(null)}})]})}function Wr({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:c=!1,activeField:d=null}){const{isOver:o,setNodeRef:i}=s.useDroppable({id:t}),{updateSortByColumn:u}=s.useEditorActions(),m=s.useEditorStore(j=>j.card),x=s.useEditorStore(j=>j.card.type),h=n.length>0,p=k.useMemo(()=>!d||!o?!0:Ve(d,t,x).isValid,[d,o,t,x]),b=(j,N)=>{var L;!((L=m.config)!=null&&L.sortByColumns)||m.config.sortByColumns.findIndex(A=>A.id===j)===-1||u(m.id,j,{direction:N})};if(t==="sortBy"&&l===!1)return null;const f=t!=="sortBy"&&x!=="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}),f&&e.jsx(Wr,{concept:t})]}),e.jsx("div",{ref:i,className:s.cn("rounded-lg border-2 border-dashed p-1 transition-all",{"border-green-500 bg-green-50 dark:bg-green-950":o&&p,"border-red-500 bg-red-50 dark:bg-red-950":o&&!p,"border-blue-200 bg-blue-50/30 dark:border-blue-800 dark:bg-blue-950/30":!o&&h,"min-h-[60px] border-muted-foreground/20 bg-background":!o&&!h}),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(j=>j.id),strategy:s.verticalListSortingStrategy,children:e.jsx("div",{className:"flex flex-wrap gap-1",children:n.map((j,N)=>{const L=j.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:j,zone:t,index:N,sortDirection:L,onSortDirectionChange:A=>b(j.id,A),hasPivotColumns:c,cardType:x})})},j.id)})})})})]})}const Os=[{value:"green",color:"#16a34a",label:"Green"},{value:"red",color:"#dc2626",label:"Red"},{value:"neutral",color:"#6b7280",label:"Neutral"}],Jr=["#16a34a","#dc2626","#6b7280","#2563eb","#ca8a04","#7c3aed","#0891b2","#e11d48","#ea580c"];function es({value:t,onChange:n,label:a}){const[r,l]=k.useState(!1),[c,d]=k.useState(!1),o=()=>{const i=Os.find(u=>u.value===t);return i?i.color:t.startsWith("#")?t:Os[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:o()},"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:Jr.map(i=>e.jsx("button",{className:s.cn("h-5 w-5 rounded border-2 transition-all",o()===i?"border-gray-900":"border-transparent"),style:{backgroundColor:i},onClick:()=>{n(i),l(!1)},children:e.jsx("span",{className:"sr-only",children:i})},i))}),e.jsx("button",{className:"w-full rounded border border-input px-2 py-1 text-xs hover:bg-muted",onClick:()=>{d(!0),l(!1)},children:"Custom color..."})]})})]}),e.jsx("span",{className:"text-xs text-muted-foreground",children:a})]}),c&&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:()=>d(!1)}),e.jsx("div",{className:"relative rounded-lg bg-white shadow-lg",children:e.jsx(Dt,{color:o(),onColorChange:i=>{n(i),d(!1)},onClose:()=>d(!1)})})]})]})}const Ps={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 Xr(){var h,p,b,f,j,N,C,L,A,w,D;const t=s.useEditorStore(g=>g.card),{setCardPreferences:n}=s.useEditorActions(),a=((h=t.config)==null?void 0:h.metricColumns)||[],r=((p=t.config)==null?void 0:p.groupByColumns)||[],l=a.length===2&&r.length===0,c=a.length>=1&&r.length>0;if(!(t.type==="kpi"&&(l||c)))return null;const o=((f=(b=t.preferences)==null?void 0:b.kpiVisualOptions)==null?void 0:f.metricComparison)||{},i=g=>{var v;const y={...t.preferences,kpiVisualOptions:{...(v=t.preferences)==null?void 0:v.kpiVisualOptions,metricComparison:{...o,...g}}};n(y)},u=c||o.enabled,m=((j=t.config)==null?void 0:j.comparisonType)||"none",x=m==="previous_period"||m==="same_period_last_year"||m==="start_vs_end";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(Zt,{className:"h-4 w-4"}),e.jsx("span",{children:"Comparison"})]})}),e.jsxs(s.AccordionContent,{className:"space-y-4 pb-4 pt-2",children:[l&&a.length===2&&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:g=>i({enabled:g,...g&&!o.calculationType?{calculationType:"difference"}:{}})})]}),u&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(s.Label,{htmlFor:"calculation-type",className:"text-xs font-medium uppercase text-muted-foreground",children:"Calculated as"}),e.jsxs(s.Tooltip,{children:[e.jsx(s.TooltipTrigger,{asChild:!0,children:e.jsx(s.Info,{className:"h-3 w-3 cursor-help text-muted-foreground"})}),e.jsx(s.TooltipContent,{side:"right",className:"max-w-xs",children:(()=>{const g=o.calculationType||"difference",y=Ps[g];return e.jsxs("div",{className:"space-y-2 text-xs",children:[e.jsx("div",{className:"text-sm font-semibold",children:y==null?void 0:y.label}),e.jsx("p",{children:y==null?void 0:y.description}),e.jsxs("div",{children:[e.jsx("span",{className:"font-medium",children:"Formula:"})," ",e.jsx("code",{className:"rounded bg-muted px-1 py-0.5 text-[10px]",children:y==null?void 0:y.formula})]}),e.jsxs("div",{className:"border-t pt-1.5 italic",children:[e.jsx("span",{className:"font-medium",children:"Example:"})," ",y==null?void 0:y.example]})]})})()})]})]}),e.jsxs(s.Select,{value:o.calculationType||"difference",onValueChange:g=>i({calculationType:g}),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(Ps).map(([g,y])=>e.jsx(s.SelectItem,{value:g,className:"text-xs",children:y.label},g))})]})]}),e.jsx(hs,{formatOptions:o.formatOptions||{},onFormatOptionsChange:g=>i({formatOptions:g}),showTitle:!0,title:"COMPARISON FORMAT"}),(x||l)&&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"}),l&&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||"right",onValueChange:g=>i({position:g}),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:"right",className:"text-xs",children:"Right"}),e.jsx(s.SelectItem,{value:"left",className:"text-xs",children:"Left"}),e.jsx(s.SelectItem,{value:"top",className:"text-xs",children:"Top"})]})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(s.Checkbox,{id:"show-arrow",checked:o.showArrow!==!1,onCheckedChange:g=>i({showArrow:g})}),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:g=>i({showColor:g})}),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:((N=o.colorConfig)==null?void 0:N.increase)||"green",onChange:g=>i({colorConfig:{...o.colorConfig,increase:g}}),label:"Primary > Secondary"}),e.jsx(es,{value:((C=o.colorConfig)==null?void 0:C.decrease)||"red",onChange:g=>i({colorConfig:{...o.colorConfig,decrease:g}}),label:"Primary < Secondary"}),e.jsx(es,{value:((L=o.colorConfig)==null?void 0:L.noChange)||"neutral",onChange:g=>i({colorConfig:{...o.colorConfig,noChange:g}}),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:g=>i({conditionalLabel:g})}),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:((A=o.conditionalLabels)==null?void 0:A.increase)??"Increase",onChange:g=>i({conditionalLabels:{...o.conditionalLabels,increase:g.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:((w=o.conditionalLabels)==null?void 0:w.decrease)??"Decrease",onChange:g=>i({conditionalLabels:{...o.conditionalLabels,decrease:g.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:((D=o.conditionalLabels)==null?void 0:D.noChange)??"No change",onChange:g=>i({conditionalLabels:{...o.conditionalLabels,noChange:g.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:"Previous Label"}),e.jsx(s.Input,{id:"label-name",type:"text",value:o.labelName??"",onChange:g=>i({labelName:g.target.value}),placeholder:"e.g. Previous, Last Period",className:"h-7 text-xs"})]})]})]})]})]})}function Zr(){var l,c;const t=s.useEditorStore(d=>d.card),{setCardPreferences:n}=s.useEditorActions();if(t.type!=="kpi")return null;const a=((c=(l=t.preferences)==null?void 0:l.kpiVisualOptions)==null?void 0:c.formatOptions)||{},r=d=>{var i;const o={...t.preferences,kpiVisualOptions:{...(i=t.preferences)==null?void 0:i.kpiVisualOptions,formatOptions:d}};n(o)};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(rs,{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(hs,{formatOptions:a,onFormatOptionsChange:r,showTitle:!1})})]})}function el({groupByFields:t,pivotByFields:n,metricsFields:a,sortByFields:r,activeField:l}){const c=s.useEditorStore(j=>{var N;return((N=j.card.customCardPreferences)==null?void 0:N.url)&&j.card.type==="custom"}),d=s.useEditorStore(j=>j.card),o=d==null?void 0:d.type,i=t.length>0||a.length>0,u=o!=="kpi"||a.length<=2,m=o!=="kpi",x=o!=="kpi"&&i,h=["pie","doughnut","polar","funnel","aggregateTable"].includes(o),p=m&&!h,b=()=>o==="kpi"?{label:"Trend By",placeholder:"Drop fields to trend data"}:{label:"Rows",placeholder:"Drop fields to group data"},f=()=>o==="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:[u&&e.jsx($e,{zone:"groupBy",fields:t,label:b().label,placeholder:b().placeholder,activeField:l}),p&&e.jsx($e,{zone:"pivotBy",fields:n,label:"Columns",placeholder:"Drop fields to pivot data",activeField:l}),e.jsx($e,{zone:"metrics",fields:a,label:f().label,placeholder:f().placeholder,hasPivotColumns:n.length>0,activeField:l}),x&&e.jsx($e,{zone:"sortBy",fields:r,label:"Sort By",placeholder:"Drop fields from Rows or Metrics",activeField:l})]})]}),!c&&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(Zr,{}),e.jsx(Xr,{}),e.jsx(Tt,{}),e.jsx(kt,{}),e.jsx(Et,{}),e.jsx(It,{})]})})]})]})}function sl({onEditJoins:t}){const n=s.useEditorStore(o=>o.card),{autoJoinMetadata:a}=s.useDashboardCardQuery(n);if(!(a!=null&&a.autoResolved))return null;const{resolvedJoinPlan:r}=a,l=(r==null?void 0:r.joins)||[];if(l.length===0)return null;const c=o=>!o||o.length===0?"No conditions":o.map(i=>{var h,p,b,f;const u=`${(h=i.source)==null?void 0:h.entityName}.${(p=i.source)==null?void 0:p.name}`,m=`${(b=i.target)==null?void 0:b.entityName}.${(f=i.target)==null?void 0:f.name}`,x=i.operator||"=";return`${u} ${x} ${m}`}).join(" AND "),d=o=>!o.joinKeyGroups||o.joinKeyGroups.length===0?"No conditions defined":o.joinKeyGroups.length===1?c(o.joinKeyGroups[0].keys):o.joinKeyGroups.map((i,u)=>({id:u,operator:i.operator,condition:c(i.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:"flex items-center justify-between p-3",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(ya,{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.TooltipProvider,{children:e.jsxs(s.Tooltip,{children:[e.jsx(s.TooltipTrigger,{asChild:!0,children:e.jsx(s.Badge,{variant:"secondary",className:"cursor-help bg-blue-100 text-xs text-blue-700 dark:bg-blue-900 dark:text-blue-300",children:l.length})}),e.jsx(s.TooltipContent,{side:"bottom",align:"start",className:"max-w-md p-3",children:e.jsx("div",{className:"space-y-2",children:l.map((o,i)=>{const u=d(o),m=Array.isArray(u);return e.jsxs("div",{className:"rounded-md border border-border bg-background p-2",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:o.source.name}),e.jsx(s.ArrowRight,{className:"size-3 text-muted-foreground"}),e.jsx("span",{className:"font-medium text-foreground",children:o.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:o.joinType})]}),e.jsx("div",{className:"mt-1 space-y-1",children:m?u.map(x=>e.jsxs("div",{className:"rounded bg-muted/30 px-2 py-1",children:[e.jsx("code",{className:"block break-all text-xs text-muted-foreground",children:x.condition}),x.operator&&e.jsxs("span",{className:"ml-2 text-xs text-muted-foreground",children:["(",x.operator,")"]})]},x.id)):e.jsx("div",{className:"rounded bg-muted/30 px-2 py-1",children:e.jsx("code",{className:"block break-all text-xs text-muted-foreground",children:u})})})]},o.id||i)})})})]})})]}),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"})})]})})}const Bs={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 tl({selectedChart:t,onChartChange:n,groupByFields:a,pivotByFields:r,metricsFields:l,sortByFields:c,activeField:d}){var g,y;const[o,i]=k.useState(()=>Bs.getItem("chart-selector-expanded")==="true"),[u,m]=k.useState(!1),x=s.useEditorStore(v=>v.card),h=s.useEditorStore(v=>v.actions.updateCardConfig),p=a.length>0||r.length>0||l.length>0,{data:b,autoJoinMetadata:f}=s.useDashboardCardQuery(x),j=((g=x==null?void 0:x.config)==null?void 0:g.joinPlan)||(f!=null&&f.autoResolved?f.resolvedJoinPlan:{baseEntity:{type:"table",name:"",database:"",schema:"",connectionId:"",connectionType:"none",dialect:"none"},joins:[]}),N=((y=x==null?void 0:x.dataSource)==null?void 0:y.selectedEntities)||[],C=v=>{h(x.id,{...x==null?void 0:x.config,joinPlan:v}),m(!1)},L=()=>{h(x.id,{...x==null?void 0:x.config,joinPlan:void 0}),m(!1)},A=()=>{m(!1)},w=()=>{m(!0)};k.useEffect(()=>{Bs.setItem("chart-selector-expanded",String(o))},[o]);const D=()=>{i(v=>!v)};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":o}),children:[e.jsx("div",{className:s.cn("overflow-hidden transition-all duration-300 ease-in-out",o?"max-h-[200px] opacity-100":"max-h-0 opacity-0"),children:o&&e.jsx(Vr,{selectedChart:t,onChartChange:n})}),e.jsxs("div",{"data-content":"Chart Quick Selector",className:"flex items-center justify-center gap-1",children:[e.jsx(_r,{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":o?"Hide all charts":"Show all charts",children:o?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:o?"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:p||b}),children:e.jsx(is,{})})}),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(sl,{onEditJoins:w}),e.jsx(el,{groupByFields:a,pivotByFields:r,metricsFields:l,sortByFields:c,activeField:d})]}),e.jsx(s.ScrollBar,{orientation:"horizontal"})]}),e.jsx(ns,{open:u,onOpenChange:m,joinPlan:j,availableDataSources:N,onSave:C,onCancel:A,onRemove:L,children:e.jsx("div",{})})]})}function al({initialFilters:t,availableFields:n}={}){const[a,r]=k.useState(t||{id:`group-${Date.now()}`,logicalOperator:"AND",negate:!1,conditions:[],groups:[]});s.useEditorStore(w=>w.card.dataSource);const{columns:l,isLoading:c}=s.useColumns(),o=n||l||[],i={id:"default",qualifiedFieldName:"default",name:"default",dataType:"string",label:"Default",entityId:"default",entityName:"Default",entityType:"table"},u=w=>{const D=g=>{if(g.id===w){const y=o[0]||i,v=s.getDataType(y.dataType)==="date";return{...g,conditions:[...g.conditions,{id:`condition-${Date.now()}`,field:y,operator:v?"between":"=",value:v?[]:""}]}}return{...g,groups:g.groups.map(D)}};r(D(a))},m=w=>{const D=g=>{if(g.id===w){const y=o[0]||i,v=s.getDataType(y.dataType)==="date";return{...g,groups:[...g.groups,{id:`group-${Date.now()}`,logicalOperator:"AND",negate:!1,conditions:[{id:`condition-${Date.now()}`,field:y,operator:v?"between":"=",value:v?[]:""}],groups:[]}]}}return{...g,groups:g.groups.map(D)}};r(D(a))},x=(w,D)=>{const g=y=>y.id===w?{...y,conditions:y.conditions.filter(v=>v.id!==D)}:{...y,groups:y.groups.map(g)};r(g(a))},h=(w,D)=>{const g=y=>y.id===w?{...y,groups:y.groups.filter(v=>v.id!==D)}:{...y,groups:y.groups.map(g)};r(g(a))},p=(w,D,g,y)=>{if(g==="field")throw new Error("Use a dedicated method to update the field property with a Field object");const v=R=>R.id===w?{...R,conditions:R.conditions.map(S=>S.id===D?{...S,[g]:y}:S)}:{...R,groups:R.groups.map(v)};r(v(a))},b=(w,D,g)=>{const y=v=>v.id===w?{...v,conditions:v.conditions.map(R=>R.id===D?{...R,...g}:R)}:{...v,groups:v.groups.map(y)};r(y(a))},f=(w,D)=>{const g=y=>y.id===w?{...y,logicalOperator:D}:{...y,groups:y.groups.map(g)};r(g(a))},j=(w,D)=>{const g=y=>y.id===w?{...y,negate:D}:{...y,groups:y.groups.map(g)};r(g(a))},N=(w,D,g)=>{const y=v=>v.id===w?{...v,conditions:s.arrayMove(v.conditions,D,g)}:{...v,groups:v.groups.map(y)};r(y(a))},C=(w,D,g)=>{const y=v=>v.id===w?{...v,groups:s.arrayMove(v.groups,D,g)}:{...v,groups:v.groups.map(y)};r(y(a))},L=w=>{if(!w||w.conditions.length===0&&w.groups.length===0)return"-- No filters defined";const D=y=>{let v="";typeof y.field=="object"?v=y.field.entityName?`${y.field.entityName}.${y.field.name}`:y.field.name:v=String(y.field);const R=y.operator;let S=y.value;if(y.field.dataType==="string"&&!["in","not in"].includes(y.operator))typeof S=="string"?S=`'${S}'`:Array.isArray(S)&&(S=`'${S.join(", ")}'`);else if(y.field.dataType==="date"||y.field.dataType==="datetime"||y.field.dataType==="timestamp")if(y.operator==="between"&&Array.isArray(S)&&S.length===2){const F=S[0]?`'${S[0]}'`:"NULL",I=S[1]?`'${S[1]}'`:"NULL";return`${v} BETWEEN ${F} AND ${I}`}else if((y.operator==="in"||y.operator==="not in")&&Array.isArray(S)){const F=S.map(I=>I?`'${I}'`:"NULL").join(", ");return`${v} ${R} (${F})`}else typeof S=="string"||S instanceof Date?S=`'${S}'`:Array.isArray(S)&&S.length>0&&(S=`'${S[0]}'`);else if(["in","not in"].includes(y.operator)){let F=[];Array.isArray(S)?F=S.map(I=>typeof I=="string"?`'${I}'`:String(I)):typeof S=="string"?F=S.split(",").map(I=>{const T=I.trim();return y.field.dataType==="string"?`'${T}'`:T}):typeof S=="number"&&(F=[String(S)]),S=`(${F.join(", ")})`}switch(R){case"contains":return typeof S=="string"?`${v} LIKE '%${S.replace(/'/g,"")}'`:`${v} LIKE '%${String(S)}'`;case"startsWith":return typeof S=="string"?`${v} LIKE '${S.replace(/'/g,"")}%'`:`${v} LIKE '${String(S)}%'`;case"endsWith":return typeof S=="string"?`${v} LIKE '%${S.replace(/'/g,"")}'`:`${v} LIKE '%${String(S)}'`;case"isNull":return`${v} IS NULL`;case"isNotNull":return`${v} IS NOT NULL`;default:return`${v} ${R} ${S}`}},g=y=>{const v=y.conditions.map(D),R=y.groups.map(T=>g(T)),S=[...v,...R].filter(Boolean);if(S.length===0)return"";const F=S.join(` ${y.logicalOperator} `),I=S.length>1?`(${F})`:F;return y.negate?`NOT ${I}`:I};return g(w)},A=a.conditions.length>0||a.groups.length>0;return{currentFilters:a,setCurrentFilters:r,availableFields:o,isLoading:c,addCondition:u,addGroup:m,removeCondition:x,removeGroup:h,updateCondition:p,updateConditionFields:b,updateGroupOperator:f,updateGroupNegate:j,reorderConditions:N,reorderGroups:C,generateSQLPreview:L,hasAnyFilters:A}}function nl({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 rl=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"})}},ll=t=>{if(t.qualifiedEntityName){const n=t.qualifiedEntityName.split(".");return n.length>1?n[0]:"default"}return"default"};function ol({value:t,onValueChange:n,availableFields:a,placeholder:r="Select field",className:l="w-64"}){const[c,d]=k.useState(!1),o=k.useMemo(()=>{const i={};return a.forEach(u=>{const m=ll(u);i[m]||(i[m]={}),i[m][u.entityId]||(i[m][u.entityId]=[]),i[m][u.entityId].push(u)}),i},[a]);return e.jsxs(s.Popover,{modal:!0,open:c,onOpenChange:d,children:[e.jsx(s.PopoverTrigger,{asChild:!0,children:e.jsxs(s.Button,{variant:"outline",role:"combobox","aria-expanded":c,className:s.cn("justify-between",!t&&"text-muted-foreground",l),children:[t?e.jsx("div",{className:"flex items-center gap-2",children:e.jsxs(nl,{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(o).map(([i,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"}),i]}),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:[rl(x[0].entityType),e.jsx("span",{children:x[0].entityName})]}),x.map((h,p)=>e.jsxs(s.CommandItem,{value:h.id,onSelect:()=>{n(h),d(!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))]},`${i}-${m}`))},i))})]})})]})}function fs(t){var f;const n=s.useEditorStore(j=>j.card),{authToken:a,tokenProps:r}=s.useSemaphorContext(),l=s.useEditorStore(j=>j.card.config),c=l==null?void 0:l.joinPlan,d={...t,alias:t.name,label:"value",role:"groupby"},o={...t,role:"metric",label:"count",alias:"count",aggregate:"COUNT"},i={...d,role:"sortby",direction:"asc"},u={joinPlan:c,groupByColumns:[d],metricColumns:[o],sortByColumns:[i]},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(j){console.log(t),console.error("error",j)}},enabled:!!m,refetchOnMount:!0,refetchOnWindowFocus:!1});return{filterValues:((x==null?void 0:x.records)||[]).map(j=>({label:j.value||"BLANK",value:j.value||"BLANK",count:(j==null?void 0:j.count)||0})),isPending:h,error:p}}function il({field:t,selected:n,onChange:a,placeholder:r="Select items...",className:l}){const[c,d]=ss.useState(!1),{filterValues:o}=fs(t),i=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:c,onOpenChange:d,modal:!0,children:[e.jsx(s.PopoverTrigger,{asChild:!0,children:e.jsxs(s.Button,{variant:"outline",role:"combobox","aria-expanded":c,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=o.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"&&i(m)},onMouseDown:h=>{h.preventDefault(),h.stopPropagation()},onClick:h=>{h.stopPropagation(),i(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:o.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 cl({field:t,value:n,onChange:a,placeholder:r="Select value...",className:l}){const{filterValues:c,isPending:d,error:o}=fs(t);return d?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..."]}):o?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:c.map((i,u)=>e.jsx(s.SelectItem,{className:"hover:bg-muted",value:i.value,children:i.label},i.value+u))})]})}function dl({value:t,operator:n,onChange:a,className:r}){var i;const{tokenProps:l}=s.useSemaphorContext(),c=(i=l==null?void 0:l.params)==null?void 0:i.timeZone,d=k.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]),o=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:d,onChange:o,timezone:c,showRelativeTab:!0,className:r,placeholder:"Select date..."})}const ul=["=","!=",">",">=","<","<=","contains","startsWith","endsWith","in","not in","isNull","isNotNull"],ml=["=","!=","contains","startsWith","endsWith","in","not in","isNull","isNotNull"],hl=["=","!=",">",">=","<","<=","in","not in","isNull","isNotNull"],xl=["=","!=","isNull","isNotNull"],pl=["between","isNull","isNotNull"],fl={"=":"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 Vs(t){return fl[t]||s.titleCase(t)}function gl(t){switch(t){case"string":return ml;case"number":return hl;case"boolean":return xl;case"date":return pl;default:return ul}}function At({condition:t,index:n,groupId:a,groupLogicalOperator:r,onUpdateCondition:l,onRemoveCondition:c,onUpdateGroupOperator:d,availableFields:o,updateConditionFields:i}){const{attributes:u,listeners:m,setNodeRef:x,transform:h,transition:p,isDragging:b}=s.useSortable({id:t.id}),{isPending:f,error:j}=fs(t.field),N={transform:s.CSS.Transform.toString(h),transition:p};return e.jsxs("div",{ref:x,style:N,className:`mb-2 flex items-center gap-2 rounded p-2 hover:bg-muted/50 ${b?"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=>d(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(ol,{value:t.field,onValueChange:C=>{const L=C,A=s.getDataType(L.dataType)==="date";i(a,t.id,{field:L,value:"",operator:A?"between":"="})},availableFields:o,placeholder:"Select field",className:"w-64"}),e.jsxs(s.Select,{value:t.operator,onValueChange:C=>{C==="in"||C==="not in"?i(a,t.id,{operator:C,value:[]}):C==="isNull"||C==="isNotNull"?i(a,t.id,{operator:C,value:null}):i(a,t.id,{operator:C,value:""})},children:[e.jsx(s.SelectTrigger,{className:"w-32",children:e.jsx(s.SelectValue,{children:t.operator?Vs(t.operator):""})}),e.jsx(s.SelectContent,{children:gl(s.getDataType(t.field.dataType)).map(C=>e.jsx(s.SelectItem,{className:"hover:bg-muted",value:C,children:Vs(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..."]}):j?e.jsx("div",{className:"flex-1 p-2 text-xs text-red-500",children:"Error loading values"}):e.jsx(il,{field:t.field,selected:Array.isArray(t.value)&&t.value.every(C=>typeof C=="string")?t.value:[],onChange:C=>i(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=>i(a,t.id,{value:C.target.value}),className:"flex-1",placeholder:t.operator.charAt(0).toUpperCase()+t.operator.slice(1)+"..."}):e.jsx(cl,{field:t.field,value:typeof t.value=="string"?t.value:"",onChange:C=>i(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=>i(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(dl,{value:t.value,operator:t.operator,onChange:C=>i(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:()=>c(a,t.id),children:e.jsx(s.X,{className:"h-3 w-3"})})]})}function jl({group:t,depth:n,parentGroupId:a,onUpdateGroupOperator:r,onUpdateGroupNegate:l,onRemoveGroup:c,onUpdateCondition:d,onUpdateField:o,onRemoveCondition:i,onReorderConditions:u,onReorderGroups:m,onAddCondition:x,onAddGroup:h,availableFields:p,renderFilterGroup:b,updateConditionFields:f}){const{attributes:j,listeners:N,setNodeRef:C,transform:L,transition:A,isDragging:w}=s.useSortable({id:t.id}),D={transform:s.CSS.Transform.toString(L),transition:A},g=v=>{const{active:R,over:S}=v;if(S&&R.id!==S.id){const F=t.conditions.findIndex(T=>T.id===R.id),I=t.conditions.findIndex(T=>T.id===S.id);F!==-1&&I!==-1&&u(t.id,F,I)}},y=v=>{const{active:R,over:S}=v;if(S&&R.id!==S.id&&a){const F=t.groups.findIndex(T=>T.id===R.id),I=t.groups.findIndex(T=>T.id===S.id);F!==-1&&I!==-1&&m(a,F,I)}};return e.jsxs("div",{ref:C,style:D,className:`rounded-lg ${n>0?"mt-2 border border-border":""} ${w?"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",{...j,...N,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:v=>r(t.id,v),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&&c(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:g,children:e.jsx(s.SortableContext,{items:t.conditions.map(v=>v.id),strategy:s.verticalListSortingStrategy,children:t.conditions.map((v,R)=>e.jsx(At,{condition:v,index:R,groupId:t.id,groupLogicalOperator:t.logicalOperator,onUpdateCondition:d,onUpdateField:o,onRemoveCondition:i,onUpdateGroupOperator:r,availableFields:p,updateConditionFields:f},v.id))})}),e.jsx(s.DndContext,{sensors:s.useSensors(s.useSensor(s.PointerSensor),s.useSensor(s.KeyboardSensor,{coordinateGetter:s.sortableKeyboardCoordinates})),collisionDetection:s.closestCenter,onDragEnd:y,children:e.jsx(s.SortableContext,{items:t.groups.map(v=>v.id),strategy:s.verticalListSortingStrategy,children:t.groups.map(v=>b(v,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 bl({filters:t,availableFields:n,onSave:a,onClearAll:r,onCancel:l}){const{currentFilters:c,availableFields:d,isLoading:o,addCondition:i,addGroup:u,removeCondition:m,removeGroup:x,updateCondition:h,updateConditionFields:p,updateGroupOperator:b,updateGroupNegate:f,reorderConditions:j,reorderGroups:N,generateSQLPreview:C,hasAnyFilters:L,setCurrentFilters:A}=al({initialFilters:t,availableFields:n}),w=s.useSensors(s.useSensor(s.PointerSensor),s.useSensor(s.KeyboardSensor,{coordinateGetter:s.sortableKeyboardCoordinates})),[D,g]=k.useState(!1),y=(S,F,I)=>{const T=M=>M.id===S?{...M,conditions:M.conditions.map(O=>O.id===F?{...O,field:I,dataType:I.dataType}:O)}:{...M,groups:M.groups.map(T)};A(T(c))},v=(S,F=0,I)=>F===0?e.jsx("div",{className:"rounded-lg",children:e.jsxs("div",{className:"p-3 px-0",children:[e.jsx(s.DndContext,{sensors:w,collisionDetection:s.closestCenter,onDragEnd:T=>{const{active:M,over:O}=T;if(O&&M.id!==O.id){const E=S.conditions.findIndex(B=>B.id===M.id),P=S.conditions.findIndex(B=>B.id===O.id);E!==-1&&P!==-1&&j(S.id,E,P)}},children:e.jsx(s.SortableContext,{items:S.conditions.map(T=>T.id),strategy:s.verticalListSortingStrategy,children:S.conditions.map((T,M)=>e.jsx(At,{condition:T,index:M,groupId:S.id,groupLogicalOperator:S.logicalOperator,onUpdateCondition:h,onUpdateField:y,onRemoveCondition:m,onUpdateGroupOperator:b,availableFields:d,updateConditionFields:p},T.id))})}),e.jsx(s.DndContext,{sensors:w,collisionDetection:s.closestCenter,onDragEnd:T=>{const{active:M,over:O}=T;if(O&&M.id!==O.id){const E=S.groups.findIndex(B=>B.id===M.id),P=S.groups.findIndex(B=>B.id===O.id);E!==-1&&P!==-1&&N(S.id,E,P)}},children:e.jsx(s.SortableContext,{items:S.groups.map(T=>T.id),strategy:s.verticalListSortingStrategy,children:S.groups.map(T=>v(T,F+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:()=>i(S.id),children:[e.jsx(s.Plus,{className:"mr-1 h-3 w-3"}),"Add Condition"]}),D&&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(jl,{group:S,depth:F,parentGroupId:I,onUpdateGroupOperator:b,onUpdateGroupNegate:f,onRemoveGroup:x,onUpdateCondition:h,onUpdateField:y,onRemoveCondition:m,onReorderConditions:j,onReorderGroups:N,onAddCondition:i,onAddGroup:u,availableFields:d,renderFilterGroup:v,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:[o?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..."})]}):v(c),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:D,onCheckedChange:S=>g(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)"})]})}),L&&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(c)})})]})]})})}),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(L?c:null),children:"Apply Filters"})]})]})}function vl({cardId:t,filters:n,onFiltersChange:a,onClearFilters:r,availableFields:l,isOpen:c,onOpenChange:d}){const o=u=>{a(t,u),d(!1)},i=()=>{r(t),d(!1)};return e.jsxs(s.Dialog,{modal:!1,open:c,onOpenChange:d,children:[c&&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(bl,{filters:n,availableFields:l,onSave:o,onCancel:()=>d(!1),onClearAll:i})]})]})}function yl({activeCardId:t,sourceFields:n,getFieldsForContainer:a,setFieldsForContainer:r}){var j,N;const[l,c]=k.useState(null),d=s.useEditorStore(C=>C.card),o=s.useEditorStore(C=>C.actions.updateCardConfig),i=(j=d==null?void 0:d.config)==null?void 0:j.joinPlan,u=(N=d==null?void 0:d.dataSource)==null?void 0:N.semanticDomainId,{data:m}=cs(u),x=[...n,...a("groupBy"),...a("pivotBy"),...a("metrics"),...a("sortBy")],h=k.useCallback(C=>C.startsWith("card-")?null:C.startsWith("source-")||n.find(L=>L.id===C)?"source":a("groupBy").find(L=>L.id===C)?"groupBy":a("metrics").find(L=>L.id===C)?"metrics":a("pivotBy").find(L=>L.id===C)?"pivotBy":a("sortBy").find(L=>L.id===C)?"sortBy":null,[n,a]),p=k.useCallback(C=>{c(C.active.id)},[]),b=k.useCallback(C=>{var v;const{active:L,over:A}=C;if(!A||!t){c(null);return}const w=L.id,D=A.id,g=h(w),y=h(D)||D;if(y==="sortBy"){if(g==="source"){const R=n.find(F=>F.id===w);if(!R){c(null);return}if(!(a("groupBy").some(F=>F.name===R.name&&F.qualifiedEntityName===R.qualifiedEntityName)||a("metrics").some(F=>F.name===R.name&&F.qualifiedEntityName===R.qualifiedEntityName))){c(null);return}}else if(g==="pivotBy"){c(null);return}else if(g!=="groupBy"&&g!=="metrics"&&g!=="sortBy"){c(null);return}}if(g==="source"&&y==="sortBy"){const R=[...n].find(T=>T.id===w);if(!R){c(null);return}const S=a("sortBy");if(s.fieldAlreadyExists(R,S)){c(null);return}const F=Ve(R,"sortBy",d.type);if(!F.isValid){s.ue.error("Invalid Field Type",{description:F.reason,position:"top-center",duration:3e3}),c(null);return}const I=s.getNewField(R,"sortBy",S);c(null),r("sortBy",[...S,I]);return}if(g==="source"&&y!=="source"&&y!=="sortBy"){const R=[...n].find(O=>O.id===w);if(!R){c(null);return}const S=[...a("groupBy"),...a("pivotBy"),...a("metrics"),...a("sortBy")];if(S.length>0){const O=S[0].qualifiedEntityName;if(!O){c(null);return}if(O!==R.qualifiedEntityName&&R.qualifiedEntityName)if(u&&(m!=null&&m.joinabilityMap)){if(s.calculateFieldState(R,{joinabilityMap:m.joinabilityMap,selectedFields:S,baseEntityName:(v=i==null?void 0:i.baseEntity)==null?void 0:v.name}).state==="unreachable"){s.showJoinRequiredNotification(),c(null);return}}else{if(!i){s.showJoinRequiredNotification(),c(null);return}if(!s.areEntitiesJoined(O,R.qualifiedEntityName,i)){s.showJoinRequiredNotification(),c(null);return}}}const F=a(y);if(s.fieldAlreadyExists(R,F)){c(null);return}const I=Ve(R,y,d.type);if(!I.isValid){s.ue.error("Invalid Field Type",{description:I.reason,position:"top-center",duration:3e3}),c(null);return}const T=s.getNewField(R,y,F),M=[...F,T];c(null),r(y,M),y==="metrics"&&t&&as(d.type,d.config,o,t,M);return}if(g&&y&&g!=="source"&&y!=="source"&&g!==y){const R=a(g),S=a(y),F=R.find(E=>E.id===w);if(!F){c(null);return}const I=Ve(F,y,d.type);if(!I.isValid){s.ue.error("Invalid Field Type",{description:I.reason,position:"top-center",duration:3e3}),c(null);return}const T=s.getNewField(F,y,S);if(c(null),y==="sortBy"){s.fieldAlreadyExists(F,S)||r(y,[...S,T]);return}const M=R.filter(E=>E.id!==w),O=[...S,T];r(g,M),r(y,O),y==="metrics"&&t&&as(d.type,d.config,o,t,O);return}if(g&&y&&g===y&&g!=="source"){const R=a(g),S=R.findIndex(I=>I.id===w),F=R.findIndex(I=>I.id===D);if(S!==F){const I=s.arrayMove(R,S,F);r(g,I)}}c(null)},[t,n,a,r,h,i,u,m,d.type,o,d.config]),f=l?x.find(C=>C.id===l):null;return{activeId:l,activeField:f,handleDragStart:p,handleDragEnd:b}}function Nl({activeView:t,onViewChange:n}){const a=s.useEditorStore(d=>d.card),{config:r}=k.useContext(s.SemaphorContext).tokenProps,l=(r==null?void 0:r.showInfoTab)!==!1,{errorMessage:c}=s.useDashboardCardQuery(a);return e.jsx(s.Tabs,{value:t,onValueChange:d=>n(d),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",c&&"text-destructive data-[state=active]:bg-destructive/10 data-[state=active]:text-destructive"),children:c?"Error":"Info"})]})})}const Cl=[{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 Sl(){var i,u;const t=s.useEditorStore(m=>m.card),{updateRowLimit:n}=s.useEditorActions(),[a,r]=k.useState(!1),[l,c]=k.useState(""),d=m=>{if(m==="custom"){r(!0);return}r(!1),n(t.id,parseInt(m))},o=m=>{const x=m.target.value;c(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:o,className:"h-7 w-24",placeholder:"Enter limit",min:1}):e.jsxs(s.Select,{value:((u=(i=t.config)==null?void 0:i.rowLimit)==null?void 0:u.toString())||"100",onValueChange:d,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:Cl.map(m=>e.jsx(s.SelectItem,{value:m.value,children:m.label},m.value))})]})})}function wl({isOpen:t,onClose:n}){const a=Ws(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),c=s.useEditorStore(m=>{var x;return((x=m.card.customCardPreferences)==null?void 0:x.pluginChartType)||""}),d=s.useEditorStore(m=>{var x;return((x=m.card.customCardPreferences)==null?void 0:x.settings)||{}}),{data:o}=s.useDashboardCardQuery(l),{getCard:i}=s.useCustomVisual(r),u=k.useMemo(()=>!r||r.trim()===""?null:i("Chart Settings"),[i,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(k.Suspense,{fallback:e.jsx("div",{children:"Loading chart settings..."}),children:e.jsx(u,{chartData:(o==null?void 0:o.records)||[],chartType:c,settings:d})})})]})})}function Dl({activeView:t,onViewChange:n,showDebug:a,onDebugToggle:r,onFiltersClick:l,activeCard:c,columns:d,columnsLoading:o,columnsError:i}){var H,$,ae;const u=s.useEditorStore(Q=>Q.card),m=s.useDashboardStore(Q=>Q.filterValues);m!=null&&m.length;const{updateCardConfig:x,setCard:h,updateCardInFrame:p,setCardId:b,setShowAIDialog:f}=s.useEditorActions(),{updateCardId:j}=s.useDashboardActions(),[N,C]=k.useState(null),L=s.useEditorStore(Q=>Q.showAIDialog),A=s.useDashboardStore(Q=>Q.isVisualEditing),[w,D]=k.useState(!1),[g,y]=k.useState(!1),[v,R]=k.useState(null),{isConsoleMode:S}=s.useDashboardPreferences(),{config:F}=k.useContext(s.SemaphorContext).tokenProps,I=(F==null?void 0:F.showInfoTab)!==!1,T=s.useEditorStore(Q=>{var re;return((re=Q.card.customCardPreferences)==null?void 0:re.url)&&Q.card.type==="custom"}),{data:M,errorMessage:O,isLoading:E,isFetching:P,errorSql:B,pagination:q,refetch:Y}=s.useDashboardCardQuery(c),[z,W]=k.useState(!1);k.useEffect(()=>{P||W(!1)},[P]);const X=(Q,re)=>{const U={...c,paginationConfig:{page:Q+1,pageSize:re}};h(U),p(U)};function se(){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(c.dataSource||{},null,2)})]}),e.jsxs("div",{children:[e.jsxs("h3",{className:"mb-2 text-sm font-medium",children:["Columns (",d.length,")"]}),e.jsx("pre",{className:"max-h-40 overflow-auto rounded border bg-background p-3 text-xs",children:o?"Loading...":i?"Error loading columns":JSON.stringify(d.slice(0,5),null,2)})]})]})]})}const te=Q=>{if(!u.config)return;if(!Q.length){x(u.id,{...u.config,sortByColumns:[]});return}const re=u.config,U=Q.map(({id:ee,desc:ce})=>{var K,_;const le=(K=re.metricColumns)==null?void 0:K.find(V=>V.label===ee),fe=(_=re.groupByColumns)==null?void 0:_.find(V=>V.label===ee),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(ee=>ee!==null);x(u.id,{...re,sortByColumns:U})},ie=k.useMemo(()=>{var Q,re;return(re=(Q=u.config)==null?void 0:Q.sortByColumns)==null?void 0:re.map(U=>({id:U.label,desc:U.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":L&&A}),children:[a&&se(),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"&&L&&e.jsx(bt,{variant:"outline"}),e.jsx(Nl,{activeView:t,onViewChange:n}),e.jsx(s.FilterInfo,{cardId:c.id,cardFilters:($=c.config)==null?void 0:$.filters,cardFilterCount:s.getFilterCount(((ae=c.config)==null?void 0:ae.filters)||null),onFiltersClick:l}),e.jsx("div",{className:"ml-2",children:e.jsx(Sl,{})}),L&&e.jsx(is,{})]}),e.jsxs("div",{className:s.cn("flex grow items-center justify-end gap-2"),children:[e.jsx(s.IconButton,{tooltip:"Refresh",disabled:E||P,onClick:()=>{W(!0),Y()},children:e.jsx(s.RefreshCcw,{className:s.cn("h-4 w-4",{"animate-spin":z})})}),t==="chart"&&e.jsx(vt,{}),!L&&e.jsx(s.IconButton,{onClick:()=>f(!L),tooltip:"AI",className:"h-8","aria-label":"AI",children:e.jsx(s.Sparkles,{className:"size-4"})}),r&&s.isDevEnv]})]}),!w&&T&&e.jsx(s.IconButton,{"aria-label":"Open Chart Settings",tooltip:"Open Chart Settings",onClick:()=>D(!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(yt,{})}),t==="table"&&(M==null?void 0:M.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:c,data:(M==null?void 0:M.records)||[],paginationMetadata:q,onPaginationChange:X,isLoading:E||P,onSortChange:te,sortState:ie})}),t==="info"&&I&&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:Q=>{const re=s.sanitizeCardId(Q);if(!re){C("Card ID cannot be empty");return}const U=j(u.id,re);if(U.success){b(re);const ee={...u,id:re};h(ee),p(ee),C(null),s.ue.success("Card ID updated successfully")}else C(U.error||"Failed to update Card ID"),s.ue.error(U.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"})]}),N&&e.jsx("p",{className:"text-xs text-destructive",children:N})]}),O||B?e.jsx(ht,{error:O,errorSql:B,onSendFeedback:()=>{const Q=s.prepareFeedbackData(s.FeedbackCategory.QUERY_GENERATION,{cardConfig:u.config,dataSource:c.dataSource,dashboardFilters:m,errorMessage:O,errorSql:B,generatedSql:M==null?void 0:M.sql});R(Q),y(!0)}}):e.jsxs(e.Fragment,{children:[(M==null?void 0:M.sql)&&e.jsx("h3",{className:"mb-1 px-2 font-mono text-xs font-medium",children:"Generated SQL Query"}),e.jsx(xt,{sql:M==null?void 0:M.sql,error:O,errorSql:B})]})]})})]}),e.jsx(wl,{isOpen:w,onClose:()=>D(!1)}),v&&e.jsx(s.FeedbackDialog,{open:g,onOpenChange:y,feedbackData:v})]})]})}function Tl({activeField:t}){const[n,a]=k.useState(!0);return k.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(ps,{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 kl=()=>{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 El(){var B,q;const[t,n]=k.useState("chart"),[a,r]=k.useState(!1),[l,c]=k.useState(!1),[d,o]=k.useState(!0),i=s.useEditorStore(Y=>Y.showAIDialog),u=s.useDashboardStore(Y=>Y.isVisualEditing),{setCardType:m}=s.useEditorActions(),x=s.useEditorStore(Y=>Y.card.type);k.useEffect(()=>kl(),[]);const h=Y=>{m(Y)},p=s.useEditorStore(Y=>Y.frame),b=s.useEditorStore(Y=>Y.card);s.useEditorStore(Y=>Y.activeTabCardId),s.useEditorStore(Y=>Y.actions.getAvailableFields);const{addCard:f,removeCard:j,updateCard:N,setActiveCard:C,updateFilters:L}=s.useEditorActions(),{columns:A=[],isLoading:w,error:D}=s.useColumns(),g=s.useSensors(s.useSensor(s.PointerSensor,{activationConstraint:{distance:8}})),y=b,{getFieldsForContainer:v,setFieldsForContainer:R}=ds(y),{activeField:S,handleDragStart:F,handleDragEnd:I}=yl({activeCardId:p.activeCardId,sourceFields:A,getFieldsForContainer:v,setFieldsForContainer:R}),T=(Y,z)=>{z&&L(Y,z)},M=Y=>{var z;N(Y,{config:{...(z=p.cards.find(W=>W.id===Y))==null?void 0:z.config,filters:void 0}})},O=A,E=Y=>{if(!Y)return 0;let z=Y.conditions.length;return Y.groups.forEach(W=>{z+=E(W)}),z},P=E(((B=y==null?void 0:y.config)==null?void 0:B.filters)||null);return e.jsxs(s.DndContext,{sensors:g,collisionDetection:s.closestCenter,onDragStart:F,onDragEnd:I,children:[e.jsxs("div",{className:"flex h-full grow",children:[e.jsx(mt,{isVisible:d,onToggleVisibility:()=>o(!d)}),e.jsxs("div",{className:"flex flex-1 transition-all duration-300 ease-in-out",children:[!i&&e.jsx(tl,{selectedChart:x,onChartChange:h,groupByFields:v("groupBy"),pivotByFields:v("pivotBy"),metricsFields:v("metrics"),sortByFields:v("sortBy"),activeField:S}),e.jsx(Dl,{selectedChart:x,activeView:t,onViewChange:n,showDebug:a,onDebugToggle:()=>r(!a),onFiltersClick:()=>c(!0),filterCount:P,activeCard:y,dataSourceState:b.dataSource||s.EMPTY_DATA_SOURCE,columns:A,columnsLoading:w,columnsError:D,getFieldsForContainer:v,cards:p.cards,activeCardId:p.activeCardId,addCard:f,setActiveCard:C})]}),!d&&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:()=>o(!0),title:"Show Data Source Panel",children:e.jsx(s.Database,{className:"h-4 w-4"})})})]}),y&&e.jsx(vl,{cardId:y.id,filters:((q=y.config)==null?void 0:q.filters)||null,onFiltersChange:T,onClearFilters:M,availableFields:O,isOpen:l,onOpenChange:c}),e.jsx(s.DragOverlay,{dropAnimation:null,children:e.jsx(Tl,{activeField:S||null})})]})}function Il({authToken:t,onSave:n,onClose:a}){const r=k.useRef(null),l=s.useEditorStore(D=>D.showAIDialog),c=s.useEditorStore(D=>D.isDevMode),d=s.useAssistantLayoutStore(D=>D.setFullscreen),o=s.useAssistantLayoutStore(D=>D.setPanelOpen),i=s.useAssistantLayoutStore(D=>D.setContainer),u=s.useAssistantPanel("editor"),m=s.useFullscreenAssistant(),x=s.useAssistantContainer("editor"),h=m==="editor",p=k.useCallback(D=>{i("editor",D)},[i]),{setAuthToken:b}=s.useDashboardActions(),{setShowAIDialog:f,setOnSave:j,setOnClose:N}=s.useEditorActions(),{setActiveAssistantType:C}=s.useAIActions();k.useEffect(()=>{n&&j(n),a&&N(a)},[n,j,a,N]),k.useEffect(()=>{t&&t.accessToken&&b(t)},[t,b]),k.useEffect(()=>{var D,g;l?((D=r.current)==null||D.resize(40),o("editor",!0),C("editor")):((g=r.current)==null||g.resize(0),o("editor",!1),m==="editor"&&d(null),C(null))},[l,o,C,d,m]);function L(D){D<1?(f(!1),o("editor",!1),m==="editor"&&d(null),C(null)):(l||(f(!0),C("editor")),u.isOpen||o("editor",!0))}function A(){return e.jsxs(e.Fragment,{children:[e.jsx(mt,{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(Lr,{})}),e.jsx(s.ResizableHandle,{}),e.jsx(s.ResizablePanel,{"data-role":"editor-assistant-panel",ref:r,onResize:L,defaultSize:u.isOpen?40:0,className:"flex",children:e.jsx("div",{className:"grow overflow-y-auto",children:e.jsx(Rs,{isFullscreen:h,onFullscreenChange:D=>d(D?"editor":null),fullscreenContainer:x})})})]}),e.jsx("div",{ref:p,className:s.cn("absolute inset-0",!h&&"pointer-events-none")})]})]})}function w(){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(El,{})}),e.jsx(s.ResizableHandle,{}),e.jsx(s.ResizablePanel,{"data-role":"editor-assistant-panel",ref:r,onResize:L,defaultSize:u.isOpen?40:0,className:"flex",children:e.jsx("div",{className:"grow overflow-y-auto",children:e.jsx(Rs,{isFullscreen:h,onFullscreenChange:D=>d(D?"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:c?e.jsx("section",{className:"isolate flex h-full grow","data-content":"editor-panel",children:A()}):w()})}function Al(){s.useDashboardStore(d=>d.selectedCardId);const t=s.useDashboardStore(d=>d.selectedSheetId),{setIsVisualEditing:n}=s.useDashboardStore(d=>d.actions),a=s.useDashboardStore(d=>d.isVisualEditing),r=s.useDashboardStore(d=>d.actions.updateFrame);function l(d){t&&(r(t,d),n(!1))}function c(){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(Il,{onSave:l,onClose:c})})}function Ml(){ut();const t=s.useDashboardStore(i=>i.selectedSheetId),n=s.useDashboardStore(i=>i.selectedFrameId),a=s.useDashboardStore(i=>i.dashboard),r=s.useDashboardStore(i=>i.actions.getSelectedFrame),{setSelectedFrameId:l}=s.useDashboardActions(),{setCard:c}=s.useEditorActions(),d=s.useEditorStore(i=>i.card.dataSource);return k.useEffect(()=>{var u,m;let i=r();if(!i){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),i=h)}if(i){const x=i.cards.find(h=>h.id===i.activeCardId);x&&c(x)}},[r,t,n,a,l,c]),{hasEntities:!!(d!=null&&d.selectedEntities&&d.selectedEntities.length>0)}}function Rl(){const t=s.useDashboardStore(a=>a.actions.setShowFilters),{hasEntities:n}=Ml();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(dt,{context:"filter"})})})})]})}function Ll(){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 Fl(){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(Ll,{}),e.jsx(s.DashboardTabs,{})]}),t&&e.jsx("div",{role:"filter-aside-container",className:"flex",children:e.jsx(Rl,{})})]})}function Ol(){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 Mt(){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 Pl=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 Bl({visual:t,isDeleting:n,isDuplicating:a,onAddVisual:r,onOpenVisual:l,onEditDetails:c,onDeleteClick:d,onDuplicateVisual:o,onShareVisual:i,formatDate:u}){var w,D,g,y;const{selectVisual:m}=s.useManagementActions(),x=s.useIsVisualSelected(t.id),h=Pl(t.id),{isConsoleMode:p}=s.useDashboardPreferences(),b=k.useRef(null),[f,j]=k.useState(!1),[N,C]=k.useState(!1);k.useEffect(()=>{a?(j(!0),C(!0)):N&&(j(!1),C(!1))},[a,N]),k.useEffect(()=>{h&&b.current&&b.current.scrollIntoView({behavior:"smooth",block:"center"})},[h]);const L=()=>e.jsx(Qe,{className:"h-4 w-4"}),A=()=>{m(t),l==null||l(t)};return e.jsx(s.Card,{ref:b,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:A,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:L()}),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:(w=t.description)!=null&&w.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:v=>v.stopPropagation(),children:[e.jsx(s.Button,{size:"sm",variant:"ghost",className:"h-6 w-6 p-0",onClick:v=>{v.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:v=>{v.stopPropagation(),c==null||c(t)},title:"Edit details",children:e.jsx(Ye,{className:"h-3 w-3"})}),e.jsxs(s.DropdownMenu,{modal:!1,open:f,onOpenChange:j,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:v=>{v.stopPropagation(),r(t)},children:[e.jsx(s.Plus,{className:"mr-2 h-3 w-3"}),"Add"]}),e.jsxs(s.DropdownMenuItem,{onClick:v=>{v.stopPropagation(),l==null||l(t)},children:[e.jsx(Xt,{className:"mr-2 h-3 w-3"}),"Open"]}),e.jsxs(s.DropdownMenuItem,{onClick:v=>{v.preventDefault(),v.stopPropagation(),o(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:v=>{v.stopPropagation(),c==null||c(t)},children:[e.jsx(Ye,{className:"mr-2 h-3 w-3"}),"Edit details"]}),e.jsxs(s.DropdownMenuItem,{onClick:v=>{v.stopPropagation(),i(t)},children:[e.jsx(s.Users,{className:"mr-2 h-3 w-3"}),"Share"]}),e.jsx(s.DropdownMenuSeparator,{}),e.jsxs(s.DropdownMenuItem,{onClick:v=>{v.stopPropagation(),d(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:[(((D=t.ownership.createdBy)==null?void 0:D.type)==="tenant"||((g=t.ownership.createdBy)==null?void 0:g.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:((y=t.ownership.createdBy)==null?void 0:y.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 Rt({open:t,resourceLabel:n,initialTitle:a,initialDescription:r="",onClose:l,onSave:c,isSaving:d=!1}){const[o,i]=k.useState(a),[u,m]=k.useState(r??"");k.useEffect(()=>{t&&(i(a),m(r??""))},[t,a,r]);const x=h=>{h.preventDefault();const p=o.trim();p&&c({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:o,onChange:h=>i(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:d,children:"Cancel"}),e.jsx(s.Button,{type:"submit",disabled:d||!o.trim(),children:d?"Saving...":"Save changes"})]})]})})})}function Vl({open:t,onOpenChange:n,onSubmit:a,isCreating:r}){const[l,c]=k.useState(""),[d,o]=k.useState("");k.useEffect(()=>{t||(c(""),o(""))},[t]);const i=()=>{l.trim()&&a({title:l,description:d})},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=>c(m.target.value),disabled:r,onKeyDown:m=>{m.key==="Enter"&&!m.shiftKey&&(m.preventDefault(),i())}})]}),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:d,onChange:m=>o(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:i,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 zl(){const[t,n]=k.useState(""),[a,r]=k.useState(!1),[l,c]=k.useState(!1),[d,o]=k.useState(null),[i,u]=k.useState(!1),[m,x]=k.useState(null),[h,p]=k.useState(null),[b,f]=k.useState(null),{selectVisual:j}=s.useManagementActions(),{handleEditLibraryVisual:N,handleAddLibraryVisual:C}=Ae(),{resources:L,isLoading:A,isError:w,createResource:D,updateResource:g,deleteResource:y,duplicateResource:v,isCreating:R,isDeleting:S}=s.useVisualManagement(()=>{u(!1),x(null)},$=>{r(!1),$&&(j($),N($))});s.useCurrentUserInfo();const F=L.filter($=>{var ae,Q;return((ae=$==null?void 0:$.title)==null?void 0:ae.toLowerCase().includes(t.toLowerCase()))||((Q=$==null?void 0:$.description)==null?void 0:Q.toLowerCase().includes(t.toLowerCase()))}),I=$=>new Date($).toLocaleDateString("en-US",{month:"short",day:"numeric",year:"numeric"}),T=$=>{D({title:$.title,description:$.description,isPrivate:!1})},M=$=>{x($),u(!0)},O=()=>{m&&y(m.id)},{startUpdating:E,stopUpdating:P,isUpdating:B}=s.useResourceUpdateState(),q=($,ae,Q)=>{var ce;const re=Object.fromEntries(Object.entries(ae).filter(([,le])=>le!==void 0));if(Object.keys(re).length===0){(ce=Q==null?void 0:Q.onSuccess)==null||ce.call(Q);return}const U=Object.keys(re),ee=U.length===1?U[0]:void 0;E($,ee),g({resourceId:$,data:re},{onSuccess:()=>{var le;P($,ee),(le=Q==null?void 0:Q.onSuccess)==null||le.call(Q)},onError:()=>{var le;P($,ee),(le=Q==null?void 0:Q.onError)==null||le.call(Q)}})},Y=$=>{p($),v($,{onSettled:()=>p(null)})},z=$=>{N($)},W=$=>{C($)},X=$=>{const ae=L.find(Q=>Q.id===$);ae&&g({resourceId:$,data:{isPrivate:!ae.isPrivate}})},se=$=>{o($),c(!0)},te=$=>{f($)},ie=()=>{f(null)},H=({title:$,description:ae})=>{if(!b)return;const Q={};$!==b.title&&(Q.title=$),(b.description||"")!==ae&&(Q.description=ae),q(b.id,Q,{onSuccess:()=>{f(null)}})};return A?e.jsx(Mt,{}):w?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:[L&&L.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:$=>n($.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:F.length===0?e.jsxs("div",{className:"py-8 text-center",children:[e.jsx("div",{className:"mb-3",children:e.jsx(Qe,{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"]})]}):F.map($=>e.jsx(Bl,{visual:$,onAddVisual:W,onOpenVisual:z,onEditDetails:te,onDeleteClick:M,onDuplicateVisual:Y,onTogglePrivacy:X,onShareVisual:se,isDeleting:S,isDuplicating:h===$.id,formatDate:I},$.id))})}),l&&d&&e.jsx(We,{resource:d,resourceType:s.ResourceType.VISUAL,onClose:()=>{c(!1),o(null)}}),b&&e.jsx(Rt,{open:!!b,resourceLabel:"Visual",initialTitle:b.title||"",initialDescription:b.description||"",onClose:ie,onSave:H,isSaving:B(b.id)}),e.jsx(s.AlertDialog,{open:i,onOpenChange:$=>{!$&&S||(u($),$||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:$=>{$.preventDefault(),$.stopPropagation(),O()},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(Vl,{open:a,onOpenChange:r,onSubmit:T,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 Ul({dashboard:t,isDeleting:n,isDuplicating:a,onLoadDashboard:r,onEditDetails:l,onDeleteClick:c,onDuplicateDashboard:d,onShareDashboard:o,formatDate:i,onDashboardItemClick:u}){var y,v,R,S,F;const{selectDashboard:m}=s.useManagementActions(),x=s.useIsDashboardSelected(t.id),{isConsoleMode:h}=s.useDashboardPreferences(),{currentUser:p,isLoading:b,isError:f}=s.useCurrentUserInfo(),j=!f&&(p==null?void 0:p.type)==="tenant"&&((y=p==null?void 0:p.role)==null?void 0:y.toUpperCase())==="VIEWER",N=b||j,[C,L]=k.useState(!1),[A,w]=k.useState(!1);k.useEffect(()=>{a?(L(!0),w(!0)):A&&(L(!1),w(!1))},[a,A]);const D=()=>e.jsx(s.ChartColumn,{className:"h-4 w-4"}),g=()=>{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:g,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:D()}),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:(v=t.description)!=null&&v.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:I=>I.stopPropagation(),children:[t.permissions.canEdit&&!N&&e.jsx(s.Button,{size:"sm",variant:"ghost",className:"h-6 w-6 p-0",onClick:I=>{I.stopPropagation(),l==null||l(t)},title:"Edit details",children:e.jsx(Ye,{className:"h-3 w-3"})}),!N&&e.jsxs(s.DropdownMenu,{modal:!1,open:C,onOpenChange:L,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:I=>{I.preventDefault(),I.stopPropagation(),d(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:I=>{I.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:I=>{I.stopPropagation(),o(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:I=>{I.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:[(((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:((F=t.ownership.createdBy)==null?void 0:F.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:i(t.lastModified)})]})]})]})]})]})]})},t.id)}function _l({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 Gl(t){const{onLoadDashboard:n,onEditDashboard:a,onDashboardItemClick:r}=t,[l,c]=k.useState(""),[d,o]=k.useState(!1),[i,u]=k.useState(!1),[m,x]=k.useState(null),[h,p]=k.useState(!1),[b,f]=k.useState(null),[j,N]=k.useState(null),[C,L]=k.useState(null),A=s.useManagementStore(K=>K.lastSelectedDashboard),w=s.useManagementStore(K=>K.selectedDashboard),D=s.useManagementStore(K=>K.actions.selectDashboard),g=s.useManagementStore(K=>K.actions.clearSelectedDashboard),{tokenProps:y,id:v}=s.useSemaphorContext(),{permissions:R}=s.useRoleAwareDisplayPreferences(),{onCreateSuccess:S}=s.useDashboardCreation({onDashboardSelect:r}),{resources:F,isLoading:I,isError:T,createResource:M,updateResource:O,deleteResource:E,duplicateResource:P,isCreating:B,isDeleting:q,refetch:Y}=s.useDashboardManagement(()=>{p(!1);const K=b==null?void 0:b.id;f(null),(w==null?void 0:w.id)===K&&(!(y!=null&&y.dashboard_id)&&!v?g():A&&A.id!==K&&D(A))},K=>{o(!1),S(K,Y)}),{currentUser:z}=s.useCurrentUserInfo(),W=F.filter(K=>{var _,V;return((_=K==null?void 0:K.title)==null?void 0:_.toLowerCase().includes(l.toLowerCase()))||((V=K==null?void 0:K.description)==null?void 0:V.toLowerCase().includes(l.toLowerCase()))}),X=K=>new Date(K).toLocaleDateString("en-US",{month:"short",day:"numeric",year:"numeric"}),se=K=>{M({title:K.title,description:K.description,isPrivate:!1})},te=K=>{n==null||n(K)},ie=K=>{f(K),p(!0)},H=()=>{b&&E(b.id)},$=K=>{N(K),P(K,{onSettled:()=>N(null)})},{startUpdating:ae,stopUpdating:Q,isUpdating:re}=s.useResourceUpdateState(),U=(K,_,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 oe=Object.keys(Z),de=oe.length===1?oe[0]:void 0;ae(K,de),O({resourceId:K,data:Z},{onSuccess:()=>{var me;Q(K,de),(me=V==null?void 0:V.onSuccess)==null||me.call(V)},onError:()=>{var me;Q(K,de),(me=V==null?void 0:V.onError)==null||me.call(V)}})},ee=K=>{const _=F.find(V=>V.id===K);_&&O({resourceId:K,data:{isPrivate:!_.isPrivate}})},ce=K=>{x(K),z==null||z.type,u(!0)},le=K=>{a==null||a(K.id),L(K)},fe=()=>{L(null)},ue=({title:K,description:_})=>{if(!C)return;const V={};K!==C.title&&(V.title=K),(C.description||"")!==_&&(V.description=_),U(C.id,V,{onSuccess:()=>{L(null)}})};return I?e.jsx(Mt,{}):T?e.jsx(_l,{onRetry:()=>window.location.reload()}):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:l,onChange:K=>c(K.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:W.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:()=>o(!0),children:[e.jsx(s.Plus,{className:"mr-2 h-4 w-4"}),"Create Dashboard"]})]}):W.map(K=>e.jsx(Ul,{dashboard:K,isDeleting:q,isDuplicating:j===K.id,onLoadDashboard:te,onEditDetails:le,onDeleteClick:ie,onDuplicateDashboard:$,onTogglePrivacy:ee,onShareDashboard:ce,formatDate:X,onDashboardItemClick:r},K.id))})}),i&&m&&e.jsx(We,{resource:m,resourceType:s.ResourceType.DASHBOARD,onClose:()=>{u(!1),x(null)}}),e.jsx(s.AlertDialog,{open:h,onOpenChange:K=>{!K&&q||(p(K),K||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 "',b==null?void 0:b.title,'"? This action cannot be undone.']})]}),e.jsxs(s.AlertDialogFooter,{children:[e.jsx(s.AlertDialogCancel,{disabled:q,children:"Cancel"}),e.jsxs(s.AlertDialogAction,{onClick:K=>{K.preventDefault(),K.stopPropagation(),H()},className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",disabled:q,children:[q?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"}),q?"Deleting...":"Delete"]})]})]})}),C&&e.jsx(Rt,{open:!!C,resourceLabel:"Dashboard",initialTitle:C.title||"",initialDescription:C.description||"",onClose:fe,onSave:ue,isSaving:re(C.id)}),e.jsx(s.CreateDashboardDialog,{open:d,onOpenChange:o,onSubmit:se,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:()=>o(!0),"aria-label":"Create dashboard",children:e.jsx(s.Plus,{className:"h-5 w-5"})})]})}function Lt({isOpen:t,onClose:n,className:a,onDashboardItemClick:r,variant:l="inline"}){s.useDashboardStore(w=>w.dashboard);const{setDashboard:c,addSheet:d}=s.useDashboardStore(w=>w.actions),{currentUser:o}=s.useCurrentUserInfo(),i=o,{permissions:u}=s.useRoleAwareDisplayPreferences(),x=s.useSelectedDashboard()&&u.canAccessVisuals,h="dashboards",[p,b]=xs("resource-management-active-tab",h),f=x?p:"dashboards",j=l==="overlay",N=Ws(n,{enabled:t&&j}),C=s.cn("flex h-full flex-col border-r bg-background",j?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),L=w=>{},A=w=>{console.log("Editing dashboard:",w)};return e.jsx(s.TooltipProvider,{children:(!j||t)&&e.jsxs("div",{ref:N,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:i&&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:i.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:i.name}),e.jsx("div",{className:"text-xs text-muted-foreground",children:i.email}),i.role&&e.jsxs("div",{className:"text-xs text-muted-foreground",children:["Role:"," ",s.toTitleCase(i.role.replace(/_/g," "))]}),e.jsxs("div",{className:"text-xs text-muted-foreground",children:["ID: ",i.id]})]})})]}),e.jsx("div",{className:"flex items-center gap-2",children:e.jsx("span",{className:"text-sm font-medium text-foreground",children:i.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(ua,{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?b: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(Gl,{onLoadDashboard:L,onEditDashboard:A,onDashboardItemClick:r})}),x&&e.jsx(s.TabsContent,{value:"visuals",className:"flex-1 px-4 py-4",children:e.jsx(zl,{})})]})})]})})}function $l({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),c=20,d=20,o=30,i=r,u=k.useRef(null),m=k.useRef(null);k.useEffect(()=>{u.current&&m.current&&(r?(u.current.resize(c),m.current.resize(100-c)):(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(Ol,{}),e.jsxs("main",{className:"relative flex h-full w-full flex-col",children:[t&&e.jsx(vn,{}),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]":i}),defaultSize:i?c:0,minSize:i?d:0,maxSize:i?o:0,children:e.jsx(Lt,{isOpen:r,onClose:()=>l(!1),variant:"inline"})}),e.jsx(s.ResizableHandle,{withHandle:i,className:s.cn("w-1",{"w-0":!i})}),e.jsx(s.ResizablePanel,{ref:m,className:"flex min-w-0 flex-1",defaultSize:i?100-c:100,minSize:i?40:100,children:e.jsxs(s.Container,{...a,type:"dashboard",children:[e.jsx(Al,{}),e.jsx(Fl,{})]})})]})]})]})})]})})}exports.AdvancedModeToggle=lt;exports.DashboardPlus=$l;exports.ResourceManagementPanel=Lt;exports.ScheduleDashboard=qs;exports.ShareDialog=We;exports.VisualBadge=at;exports.VisualEditingControls=rt;exports.cleanCard=Ys;exports.getDashbaordStateWithoutData=Ke;
|