react-semaphor 0.1.63 → 0.1.64
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-C7mXurPl.js → dashboard-plus-BuCiUxZH.js} +1 -1
- package/dist/chunks/{dashboard-plus-BT1JEFt7.js → dashboard-plus-Dr_jkDZA.js} +8 -1
- package/dist/index.cjs +1 -1
- package/dist/index.js +1 -1
- package/dist/surfboard/index.cjs +1 -1
- package/dist/surfboard/index.js +1 -1
- package/package.json +1 -1
|
@@ -230,6 +230,6 @@ ${v.joinType} JOIN ${S.name}
|
|
|
230
230
|
|
|
231
231
|
${u?`Python:
|
|
232
232
|
${u}`:""}
|
|
233
|
-
`;P(R)}function z(){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($a,{jsonString:JSON.stringify(x,null,2)})})}),x&&x.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 K(){return e.jsxs(s.ResizablePanelGroup,{className:"flex grow pb-1",direction:"vertical",role:"editor-resizable-group",children:[e.jsxs(s.ResizablePanel,{id:"1",order:1,defaultSize:a?20:100,className:"relative flex grow",children:[e.jsx("div",{id:"sql-container",className:"relative flex w-[99%]",children:e.jsx(za,{})}),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(qa,{})}),e.jsx("code",{className:"absolute right-6 top-3 text-xs text-muted-foreground/70",children:"python"})]})]})]})}function U(){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:N||A,onClick:()=>{L()},className:"h-8 shrink-0",size:"sm",children:[N||A?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(Va,{errorSql:D,sql:j==null?void 0:j.sql,error:I,onDebugWithAssistant:B}),e.jsx(Qe,{}),e.jsxs(s.Toggle,{pressed:a,onPressedChange:R=>r(R),className:"h-8",size:"sm",variant:"outline",children:[e.jsx(Ra,{className:"mr-2 size-4 text-foreground/70"}),"Python"]}),!o&&e.jsxs("button",{disabled:o,onClick:()=>{M(!0)},className:"flex h-9 w-full cursor-text items-center justify-start px-3 text-left text-sm text-muted-foreground",children:[e.jsx(s.Sparkles,{className:"mr-2 size-4 text-foreground/70"}),"Type your question..."]})]})})}return e.jsxs("section",{role:"editor-section",className:"flex grow flex-col justify-end",children:[e.jsxs("div",{className:"relative flex grow justify-between overflow-y-scroll",children:[K(),z()]}),U()]})}const Ua=[{value:"table",label:"Table",icon:s.Table2},{value:"aggregateTable",label:"Aggregate",icon:s.Layers},{value:"pivotTable",label:"Pivot",icon:Re}];function Ka({className:t}){const n=s.useEditorStore(d=>d.card),{setCardType:a,setCard:r,updateCardInFrame:l}=s.useEditorActions(),c=["table","aggregateTable","pivotTable"].includes(n.type),i=s.hasValidCardConfig(n.config);if(!c||!i)return null;const o=d=>{var x;const u=d;if(u==="aggregateTable"&&((x=n.config)!=null&&x.pivotByColumns)&&n.config.pivotByColumns.length>0){const m={...n,type:u,config:{...n.config,pivotByColumns:[]}};r(m),l(m)}else{a(u);const m={...n,type:u};l(m)}};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:Ua.map(d=>{const u=d.icon,x=n.type===d.value;return e.jsxs("div",{className:"flex items-center",children:[e.jsx(s.RadioGroupItem,{value:d.value,id:`table-type-${d.value}`,className:"peer sr-only"}),e.jsxs(s.Label,{htmlFor:`table-type-${d.value}`,className:s.cn("flex cursor-pointer items-center gap-1.5 rounded-md px-3 py-1 text-sm font-medium transition-all",x?"bg-muted text-foreground shadow-sm":"text-muted-foreground hover:bg-muted/50"),children:[e.jsx(u,{className:"h-3.5 w-3.5"}),d.label]})]},d.value)})})})}function _a({card:t}){var P,M,T,y,f,j,N,A,C,O,F;const[n,a]=w.useState(!1),[r,l]=w.useState([]),{authToken:c}=s.useSemaphorContext(),{theme:i}=s.useTheme(),o=s.getTokenParams(c==null?void 0:c.accessToken),d=s.useDashboardStore(D=>D.themeStyle),u={mode:i||"system",colors:((M=(P=d==null?void 0:d.chart)==null?void 0:P.dataset)==null?void 0:M.backgroundColor)||[]};(T=t.customCardPreferences)!=null&&T.inputData;const{getCard:x}=s.useCustomVisual(((y=t.customCardPreferences)==null?void 0:y.url)||""),m=((f=t.customCardPreferences)==null?void 0:f.visualType)||"single",h=s.useEditorStore(D=>D.frame),{setCustomCardPreferences:p}=s.useEditorActions(),{data:b}=s.useDashboardCardQuery(t),g=w.useCallback((D,E)=>{l(L=>({...L,[D]:E}))},[]);if(!((j=t.customCardPreferences)!=null&&j.componentName))return null;const v=x((N=t.customCardPreferences)==null?void 0:N.componentName);function S(D){a(D)}const k=Object.keys(((A=t.customCardPreferences)==null?void 0:A.dataInputCardIds)||{}).map(D=>{var I,B,z;const E=(B=(I=t.customCardPreferences)==null?void 0:I.dataInputCardIds)==null?void 0:B[D].cardId,L=(z=h==null?void 0:h.cards)==null?void 0:z.find(K=>K.id===E);return L||null});return e.jsx("div",{className:"semaphor-custom mb-3 flex grow basis-0 flex-col space-y-2 overflow-y-auto",children:e.jsxs(w.Suspense,{fallback:e.jsx(e.Fragment,{}),children:[v&&m==="single"&&e.jsx(v,{editing:!0,params:o,theme:u,settings:(C=t.customCardPreferences)==null?void 0:C.settings,onDataChange:g,data:(b==null?void 0:b.records)||[]}),v&&m==="multiple"&&e.jsxs(e.Fragment,{children:[Object.keys(((O=t.customCardPreferences)==null?void 0:O.dataInputCardIds)||{}).map(D=>{var I,B,z;const E=(B=(I=t.customCardPreferences)==null?void 0:I.dataInputCardIds)==null?void 0:B[D].cardId,L=(z=h==null?void 0:h.cards)==null?void 0:z.find(K=>K.id===E);if(L)return e.jsx(s.MultiInputEmptyRenderer,{onLoadingStatus:S,onDataChange:g,dataInputIndex:D,card:L},L.id+D)}),e.jsx("div",{className:"flex flex-col gap-2",children:e.jsx(v,{theme:u,onDataChange:g,settings:k.map(D=>{var E;return(E=D==null?void 0:D.customCardPreferences)==null?void 0:E.settings}),data:k.map(D=>D!=null&&D.id?r==null?void 0:r[D.id]:[])})})]})]},(F=t.customCardPreferences)==null?void 0:F.componentName)})}function Ha({type:t,isLinked:n,className:a}){const r=s.useDashboardStore(h=>h.selectedFrameId),l=s.useManagementStore(h=>h.selectedVisual),c=s.useEditorStore(h=>h.frame);let i;if(t)i=t;else if(n!==void 0)i=n?"linked":"library";else if(!!!(c!=null&&c.visualId||l!=null&&l.id)&&r)i="local";else if(l&&!r)i="library";else if(c!=null&&c.visualId&&r)i="linked";else if(l!=null&&l.id&&r)i="library";else return null;if(i==="local")return null;const o={linked:"border-purple-200/70 bg-gradient-to-r from-purple-50/50 to-purple-100/30 text-purple-900 shadow-sm hover:from-purple-100/60 hover:to-purple-100/50 hover:shadow-md dark:border-purple-800/50 dark:from-purple-950/40 dark:to-purple-900/30 dark:text-purple-100 dark:hover:from-purple-950/60 dark:hover:to-purple-900/50",library:"border-blue-200/70 bg-gradient-to-r from-blue-50/50 to-blue-100/30 text-blue-900 shadow-sm hover:from-blue-100/60 hover:to-blue-100/50 hover:shadow-md dark:border-blue-800/50 dark:from-blue-950/40 dark:to-blue-900/30 dark:text-blue-100 dark:hover:from-blue-950/60 dark:hover:to-blue-900/50"},d={linked:"Linked to library: Changes made here update the library visual and all linked instances.",library:"Library visual: Share and reuse this visual across multiple dashboards."},u={linked:"border-purple-200 bg-purple-50 text-purple-900 dark:border-purple-800 dark:bg-purple-950 dark:text-purple-100",library:"border-blue-200 bg-blue-50 text-blue-900 dark:border-blue-800 dark:bg-blue-950 dark:text-blue-100"},x={linked:"fill-purple-50 dark:fill-purple-950",library:"fill-blue-50 dark:fill-blue-950"},m={linked:e.jsx(At,{className:"h-3.5 w-3.5"}),library:e.jsx(It,{className:"h-3.5 w-3.5"})};return e.jsx(s.TooltipProvider,{children:e.jsxs(s.Tooltip,{delayDuration:300,children:[e.jsx(s.TooltipTrigger,{asChild:!0,children:e.jsx(s.Badge,{variant:"outline",className:s.cn("cursor-help select-none transition-all",o[i],a),children:m[i]})}),e.jsxs(s.TooltipContent,{side:"bottom",className:s.cn("max-w-xs",u[i]),children:[e.jsx(s.TooltipArrow,{className:x[i]}),e.jsx("p",{children:d[i]})]})]})})}function Us({className:t,...n}){var I;const a=s.useEditorStore(B=>B.card),r=((I=a.customCardPreferences)==null?void 0:I.showCardHeader)??!0,l=s.useEditorStore(B=>B.frame),c=s.useDashboardStore(B=>B.dashboard.filters),[i,o]=w.useState(!1),{currentUser:d}=s.useCurrentUserInfo(),{tokenProps:u}=w.useContext(s.SemaphorContext),x=s.useEditorStore(B=>B.actions.setRunSql),{updateFilter:m}=s.useDashboardActions(),h=c==null?void 0:c.find(B=>B.id===l.filterId),{data:p,isLoading:b,isFetching:g,errorMessage:v,errorSql:S,pagination:k}=s.useDashboardCardQuery(a),{setCard:P,updateCardInFrame:M,setIsDevMode:T,setCardSql:y}=s.useEditorActions(),{data:f}=s.useTopoJson(a),j=w.useMemo(()=>{var B;return a.type!=="pivotTable"||!((B=p==null?void 0:p.records)!=null&&B.length)?null:{records:p.records,columnSubtotalMeta:p.columnSubtotalMeta,subtotalColumns:p.subtotalColumns||[],pivotSchema:p.pivotSchema||[],groupByColumns:p.groupByColumns}},[a.type,p==null?void 0:p.records,p==null?void 0:p.columnSubtotalMeta,p==null?void 0:p.subtotalColumns,p==null?void 0:p.pivotSchema,p==null?void 0:p.groupByColumns]),N=s.usePivotTableConfig(a,j),A=B=>{T(!0),y(B||S||a.sql||a.python||""),setTimeout(()=>{x(!0)},100)},C=()=>{o(!0)},O=w.useMemo(()=>{const B=typeof window<"u"?window.location.href:"",z=typeof navigator<"u"?navigator.userAgent:"",K=typeof window<"u"?`${window.innerWidth}x${window.innerHeight}`:"";return{category:s.FeedbackCategory.QUERY_GENERATION,user:d,tokenContext:u,systemState:{cardConfig:a.config,dataSource:a.dataSource,dashboardFilters:c,errorMessage:v||void 0,errorSql:S||a.sql||a.python,generatedSql:S||a.sql},metadata:{url:B,userAgent:z,timestamp:new Date().toISOString(),viewport:K}}},[d,u,a,c,v,S]),F=(B,z)=>{var U,R;const K={...a,paginationConfig:{page:B+1,pageSize:z}};P(K),M(K),a.sql&&((R=(U=a.preferences)==null?void 0:U.tablePrefs)!=null&&R.enableDevModePagination)&&x(!0)},D=w.useMemo(()=>!a.id||!(p!=null&&p.records)?null:s.createChartConfig({card:a,data:p==null?void 0:p.records,cardType:a.type,queryConfig:a.queryConfig,customCfg:a.customCfg,preferences:a.preferences,topoJson:f}),[a,p==null?void 0:p.records,f]);function E(B){return e.jsx(s.ErrorBoundary,{FallbackComponent:s.FallbackVisual,children:e.jsx(_a,{card:B})})}function L(){if(p!=null&&p.records&&(p==null?void 0:p.records.length)===0&&!b&&!g)return v?e.jsx("div",{className:"flex h-full flex-col items-start justify-start overflow-auto p-4",children:e.jsx(Ze,{error:v,errorSql:S||a.sql||a.python,onOpenInEditor:A,onSendFeedback:C,showFeedbackButton:!0,errorTitle:"Unable to Create Visual"})}):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((b||g)&&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 E(a);if(!["table","pivotTable","aggregateTable","custom"].includes(a.type)&&D)return e.jsx("div",{className:"relative h-full min-h-0 w-full flex-1 grow basis-0",children:b||g?e.jsx(e.Fragment,{}):e.jsx(s.ChartJsVisual,{cfg:D})});if(a.type==="table")return e.jsx("div",{className:"relative mb-2 flex h-full min-h-0 w-full flex-1 grow basis-0",children:e.jsx(s.TableVisual,{card:a,data:(p==null?void 0:p.records)||[],paginationMetadata:k,onPaginationChange:F,isLoading:b||g})});if(a.type==="pivotTable"&&N)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:N.data,options:N.options,onAggregationChange:B=>{const z=s.handleAggregationChange(B,a.config),K={...a,config:z};P(K),M(K)},onAggregationLabelChange:B=>{const z=s.handleAggregationLabelChange(B,a.config),K={...a,config:z};P(K),M(K)}})});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:(p==null?void 0:p.records)||[],groupByColumns:p==null?void 0:p.groupByColumns,pivotSchema:p==null?void 0:p.pivotSchema,paginationMetadata:k,onPaginationChange:F,onAggregationChange:B=>{const z=s.handleAggregationChange(B,a.config),K={...a,config:z};P(K),M(K)},isLoading:b||g})})}return e.jsxs(s.Card,{role:"editor-visual-card",className:s.cn("relative flex h-full flex-col rounded-none",t),...n,children:[r&&e.jsxs(s.CardHeader,{className:"flex flex-row items-start justify-between py-4",children:[e.jsxs("div",{className:"flex-1",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(s.CardTitle,{className:"text-base",children:e.jsx(s.EditableText,{value:a.title,onSave:B=>P({...a,title:B}),isEditable:!0,placeholder:"Add title",displayClassName:"text-base font-semibold",inputClassName:"text-base font-semibold"})}),e.jsx(Ha,{}),e.jsx("div",{className:"ml-auto",children:e.jsx(Ka,{})})]}),e.jsx("div",{className:"w-1/2",children:e.jsx(s.EditableText,{value:a.description||"",onSave:B=>P({...a,description:B}),isEditable:!0,placeholder:"Add description",displayClassName:"text-sm text-muted-foreground",inputClassName:"text-sm"})})]}),h&&e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(s.Label,{className:"my-1",children:e.jsx(s.EditableText,{value:h.title||h.column,onSave:B=>m({...h,title:B}),isEditable:!0,placeholder:"Filter",displayClassName:"text-sm",inputClassName:"text-sm"})}),e.jsx(s.FilterComponent,{filter:h})]})]}),e.jsx(s.CardContent,{className:"flex grow flex-col",children:L()}),e.jsx(s.FeedbackDialog,{open:i,onOpenChange:o,feedbackData:O,showDebugInfo:!0})]})}const qe=({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}),Ja=()=>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."})]})]}),Qa=({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(qe,{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(qe,{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(qe,{language:"javascript",value:t,onChange:l})})]}),Wa=({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 Ya(){const[t,n]=w.useState(!1),[a,r]=w.useState(""),[l,c]=w.useState(""),[i,o]=w.useState(""),[d,u]=w.useState(""),x=s.useEditorStore(T=>T.card),m=s.useEditorStore(T=>T.card.customCfg),h=m?JSON.stringify(m,null,2):"",{data:p}=s.useDashboardCardQuery(x),{data:b}=s.useTopoJson(x),{setCardCustomCfg:g,setCustomVisualCode:v}=s.useEditorActions(),S=T=>{var y,f;return JSON.stringify({...T,data:{...T.data,datasets:(f=(y=T.data)==null?void 0:y.datasets)==null?void 0:f.map(j=>({...j,data:[]}))}},null,2)},k=()=>{var y,f;if(!((y=p==null?void 0:p.records)!=null&&y.length))return;const T=s.createChartConfig({card:x,data:p.records,cardType:x.type,queryConfig:x.queryConfig,preferences:x.preferences,topoJson:b});if(T){r(S(T)),o(((f=x.preferences)==null?void 0:f.customVisualCode)||"");const j=s.merge(T,m);c(S(j))}},P=()=>{try{if(i&&v(i),l){const T=JSON.parse(l),y=s.getObjectDiff(JSON.parse(a),T);g(y),u("")}}catch{u("Invalid JSON configuration")}},M=Object.keys(m||{}).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:k,className:M?"":"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(Ja,{}),e.jsxs("div",{className:"flex grow gap-2",children:[e.jsx(s.ErrorBoundary,{FallbackComponent:s.FallbackVisual,children:e.jsx(Us,{className:"w-1/2 rounded shadow-none"})}),e.jsx(Qa,{customCode:i,cardCustomCfgString:h,mergedConfig:l,onConfigChange:T=>c(T??""),onCodeChange:T=>o(T??"")})]}),e.jsx(Wa,{error:d,hasCardCustomConfig:!!m,onReset:()=>{c(a),g(null)},onApply:P,onClose:()=>n(!1)})]})]})}function ze(t){const[n,a]=w.useState(null);return n}function Ks(){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 _s(){const{data:t,isLoading:n,isError:a}=Ks(),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:d=>Math.min(1e3*2**d,3e4)}))}),l=[];let c=n,i=a;return r.forEach((o,d)=>{var u;if(o.isLoading&&(c=!0),o.isError&&(i=!0),o.data&&((u=t==null?void 0:t.plugins)!=null&&u[d])){const x=t.plugins[d],m=o.data.visuals.map(h=>({name:h.name,pluginName:x.label,componentType:h.componentType,pluginType:x.type,icon:h.icon,chartType:h.chartType,url:x.value}));l.push(...m)}}),{data:l,isLoading:c,isError:i}}function Xa({onChartTypeChange:t}){const{setCardCustomCfg:n,setCardPreferences:a,setCardType:r,setCustomCardPreferences:l}=s.useEditorActions(),{data:c,isLoading:i,isError:o}=_s(),d=w.useCallback((u,x)=>{n(null),a({}),r(u),x&&l({type:"component",visualType:"single",url:x.url,componentName:x.name,icon:x.icon}),t==null||t()},[n,a,r,l,t]);return i?e.jsxs(e.Fragment,{children:[e.jsx(s.Separator,{className:"my-3"}),e.jsx("div",{className:"py-4 text-center text-sm text-muted-foreground",children:"Loading custom visuals..."})]}):o?e.jsxs(e.Fragment,{children:[e.jsx(s.Separator,{className:"my-3"}),e.jsx("div",{className:"py-4 text-center 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-3"}),e.jsx("div",{className:"mb-2",children:e.jsx("span",{className:"text-xs font-medium text-muted-foreground",children:"Custom Charts"})}),e.jsx("div",{className:"grid grid-cols-3 gap-2",children:c.map((u,x)=>e.jsx(Za,{text:u.name,onClick:()=>d("custom",u),icon:u.icon},`${u.url}-${u.name}-${x}`))})]})}const Za=({text:t,icon:n,onClick:a})=>{const r=ze();return e.jsxs("button",{onClick:a,className:"flex flex-col items-center gap-2 rounded-lg border border-border bg-background p-3 transition-all hover:border-primary/50 hover:bg-muted/50 hover:shadow-sm",children:[r?e.jsx(r,{className:"h-6 w-6"}):e.jsx(Ae,{className:"h-6 w-6 text-muted-foreground"}),e.jsx("span",{title:t,className:"line-clamp-2 text-center text-xs font-medium text-foreground",children:t})]})};function en({onChartTypeChange:t,iconClassName:n,searchQuery:a=""}){const{setCardType:r,setCardPreferences:l,setIsDevMode:c}=s.useEditorStore(h=>h.actions),{setCardCustomCfg:i,setCustomCardPreferences:o,setQueryConfig:d}=s.useEditorActions();function u(h,p){i(null),l({}),r(h),["custom","text","map"].includes(h)&&(c(!0),d(void 0)),t==null||t()}const m=[{type:"table",name:"Table",icon:s.Table2},{type:"bar",name:"Bar Chart",icon:s.ChartColumnIncreasing},{type:"line",name:"Line Chart",icon:s.ChartLine},{type:"stackedBar",name:"Stacked Bar",icon:s.ChartColumnStacked},{type:"stackedLine",name:"Stacked Line",icon:s.MdStackedLineChart},{type:"scatter",name:"Scatter",icon:s.ChartScatter},{type:"bubble",name:"Bubble",icon:s.TbChartBubble},{type:"pie",name:"Pie Chart",icon:s.ChartPie},{type:"doughnut",name:"Doughnut",icon:s.Donut},{type:"funnel",name:"Funnel",icon:s.TbChartFunnel},{type:"radar",name:"Radar",icon:s.Radar},{type:"polarArea",name:"Polar Area",icon:s.PiChartPolar},{type:"tornado",name:"Tornado",icon:s.Tornado},{type:"range",name:"Range",icon:s.ChartNoAxesGantt},{type:"kpi",name:"KPI",icon:s.TiSortNumerically},{type:"text",name:"Text",icon:s.BookType},{type:"map",name:"Map",icon:s.Map},{type:"custom",name:"Custom",icon:Ae}].filter(h=>h.name.toLowerCase().includes(a.toLowerCase()));return e.jsx("div",{className:"grid grid-cols-3 gap-2",children:m.map(h=>{const p=h.icon;return e.jsxs("button",{onClick:()=>u(h.type),className:"flex flex-col items-center gap-2 rounded-lg border border-border bg-background p-3 transition-all hover:border-primary/50 hover:bg-muted/50 hover:shadow-sm",children:[e.jsx(p,{className:s.cn("h-6 w-6",n),strokeWidth:h.icon===s.MdStackedLineChart?0:void 0}),e.jsx("span",{className:"text-xs font-medium text-foreground",children:h.name})]},h.type)})})}function sn({chartType:t,className:n,customIcon:a,componentName:r}){const l=ze();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(s.Type,{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(Ae,{className:n});default:return e.jsx(s.Table2,{className:n})}}function Hs({variant:t="ghost"}){var o,d;const[n,a]=w.useState(!1),[r,l]=w.useState(""),c=s.useEditorStore(u=>u.card),i=c.type;return e.jsxs(s.Popover,{open:n,onOpenChange:u=>{a(u),u||l("")},children:[e.jsx(s.PopoverTrigger,{asChild:!0,children:e.jsx(s.Button,{size:"sm",variant:t||"ghost",children:e.jsx(sn,{className:"size-4",chartType:i,customIcon:(o=c.customCardPreferences)==null?void 0:o.icon,componentName:(d=c.customCardPreferences)==null?void 0:d.componentName})})}),e.jsxs(s.PopoverContent,{onOpenAutoFocus:u=>u.preventDefault(),className:"z-[70] w-[360px] p-3",children:[e.jsxs("div",{className:"mb-3 flex items-center gap-2 rounded-sm border border-border bg-background px-3 py-2",children:[e.jsx(s.Search,{className:"h-4 w-4 text-muted-foreground"}),e.jsx(s.Input$1,{placeholder:"Search charts...",value:r,onChange:u=>l(u.target.value),className:"h-auto border-0 p-0 text-sm focus-visible:ring-0 focus-visible:ring-offset-0"})]}),e.jsxs("div",{className:"max-h-[400px] overflow-y-auto",children:[e.jsx(en,{onChartTypeChange:()=>a(!1),searchQuery:r}),e.jsx(Xa,{onChartTypeChange:()=>a(!1)})]})]})]})}function tn({error:t,className:n="",textClassName:a="",copyButtonClassName:r=""}){const[l,c]=w.useState(!1),i=w.useRef(null),o=w.useRef(!1);function d(){t&&!o.current&&navigator.clipboard.writeText(t)}function u(h){(h.key==="Enter"||h.key===" ")&&(h.preventDefault(),d())}function x(){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 m(){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:i,className:`cursor-pointer select-text break-all font-mono text-xs text-red-700 dark:text-red-300 ${a}`,onClick:d,onKeyDown:u,onMouseUp:x,onMouseDown:m,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 an(){const t=s.useEditorStore(c=>{var i,o;return(o=(i=c.card.preferences)==null?void 0:i.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(us,{className:"size-4"}):e.jsx(ds,{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(us,{className:"size-4"}):e.jsx(ds,{className:"size-4"})})}return e.jsx(e.Fragment,{children:n==="funnel"?l():r()})}function nn({className:t}){var h,p,b,g,v,S,k,P;const n=s.useEditorStore(M=>M.card),{setCardPreferences:a,updateCardInFrame:r,setCard:l}=s.useEditorActions(),[c,i]=w.useState(!1),o=((p=(h=n.preferences)==null?void 0:h.displayOptions)==null?void 0:p.showFilterInfo)??!0,d=((g=(b=n.preferences)==null?void 0:b.displayOptions)==null?void 0:g.showCardToolbar)??!0,u=((S=(v=n.preferences)==null?void 0:v.displayOptions)==null?void 0:S.showChrome)??!0,x=((P=(k=n.preferences)==null?void 0:k.displayOptions)==null?void 0:P.allowScroll)??!0,m=(M,T)=>{var j;const y={...n.preferences,displayOptions:{...(j=n.preferences)==null?void 0:j.displayOptions,[M]:T}};a(y);const f={...n,preferences:y};l(f),r(f)};return e.jsx("div",{className:s.cn("flex items-center",t),children:e.jsxs(s.DropdownMenu,{modal:!1,open:c,onOpenChange:i,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(Ts,{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:M=>{m("showFilterInfo",M)},onSelect:M=>M.preventDefault(),className:"pr-2",children:[e.jsx("span",{className:"flex-1",children:"Filter Info"}),e.jsx("span",{className:"ml-4 text-xs text-muted-foreground",children:"Badge"})]}),e.jsxs(s.DropdownMenuCheckboxItem,{checked:d,onCheckedChange:M=>{m("showCardToolbar",M)},onSelect:M=>M.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:M=>{m("showChrome",M)},onSelect:M=>M.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:x,onCheckedChange:M=>{m("allowScroll",M)},onSelect:M=>M.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 Js(){const t=s.useEditorStore(c=>c.card),n=s.useEditorStore(c=>{var i,o;return(o=(i=c.card)==null?void 0:i.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(an,{})}),!["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(Re,{className:"size-4"}),a==="x"&&e.jsx(bt,{className:"size-4"}),a==="y"&&e.jsx(Rt,{className:"size-4"}),a==="none"&&e.jsx(qt,{className:"size-4"})]}),e.jsx(nn,{})]})}function rn(){const t=s.useEditorStore(b=>b.frame),n=s.useEditorStore(b=>b.card),{setFrame:a,setActiveTabCardId:r,setCard:l,updateCardInFrame:c}=s.useEditorActions(),i=(b,g)=>{b.dataTransfer.setData("tabIndex",g.toString())},o=b=>{b.preventDefault()},d=(b,g)=>{const v=b.dataTransfer.getData("tabIndex");if(v===g.toString())return;const S=Array.from(t.cards),[k]=S.splice(parseInt(v),1);S.splice(g,0,k),a({...t,cards:S})};function u(b){const g=t.cards.filter(k=>k.id!==b),v=g[0],S={...t,cards:g,activeCardId:v.id};a(S),r(v.id),l(v)}function x(b,g){const v={...t,cards:[...t.cards,g],activeCardId:b.id};a(v),r(g.id)}function m(){const b={...n,id:s.v4(),title:`${n.title} Copy`,tabTitle:`${n.tabTitle||n.title} Copy`};x(n,b)}function h(b){const g={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"};x(b,g)}function p(b,g){return b.cards.length===1&&(g.displayTab===!0||g.displayTab===void 0)||b.activeCardId!==g.id&&(g.displayTab===!0||g.displayTab===void 0)?null:e.jsx("div",{onClick:()=>{const v=g.displayTab===void 0?!1:!g.displayTab;l({...g,displayTab:v}),c({...g,displayTab:v})},children:g.displayTab===!0||g.displayTab===void 0?e.jsx(s.Eye,{className:"mr-2 size-3.5 text-muted-foreground hover:text-foreground"}):e.jsx(Ct,{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,g)=>e.jsxs(s.TabsTrigger,{draggable:!0,onDragStart:v=>i(v,g),onDragOver:o,onDrop:v=>d(v,g),className:"",value:b.id,children:[p(t,b),e.jsx(s.Editable,{enabled:t.activeCardId===b.id,text:b.tabTitle||b.title,onSave:v=>{l({...n,tabTitle:v}),c({...n,tabTitle:v})},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:v=>{v.stopPropagation(),m()}}),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 Qs(){const t=s.useEditorStore(v=>v.frame),n=s.useEditorStore(v=>v.card),a=s.useEditorStore(v=>v.isSqlRunning),r=s.useEditorStore(v=>v.isDevMode),{setFrame:l,setActiveTabCardId:c,setCard:i,setIsDevMode:o,setRunSql:d}=s.useEditorActions(),{data:u,isLoading:x,isFetching:m,isError:h}=s.useDashboardCardQuery(n);function p(v){const S=t.cards.find(k=>k.id===v);if(S!=null&&S.sql){r||o(!0),c(v);return}if(S!=null&&S.queryConfig){r&&o(!1),b(v),c(v);return}r||b(v),c(v)}function b(v){const S={...t,cards:t.cards.map(P=>P.id===n.id?n:P),activeCardId:v};l(S);const k=S.cards.find(P=>P.id===v);k.sql&&d(!0),i(k)}function g(){return n.type==="kpi"?x||m?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:x||m,isError:h})})}):n.type==="text"?x||m?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(Us,{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(v=>e.jsx(s.TabsContent,{className:"mt-0 grow",value:v.id,children:g()},v.id)),e.jsx(rn,{})]})}function ps({children:t}){var y,f;s.useEditorStore(j=>j.frame);const n=s.useEditorStore(j=>j.card),a=s.useEditorStore(j=>j.isDevMode),r=s.useEditorStore(j=>j.isShowingVisual),l=s.useDashboardStore(j=>j.isVisualEditing),c=s.useEditorStore(j=>j.pythonStdOut);s.useEditorStore(j=>j.actions.setRunSql);const{setFrame:i,setCard:o,setActiveTabCardId:d,runAssistant:u,setIsDevMode:x,setCardPreferences:m}=s.useEditorActions(),{data:h,isLoading:p,isFetching:b,errorMessage:g,refetch:v}=s.useDashboardCardQuery(n),[S,k]=w.useState(!1);w.useEffect(()=>{b||k(!1)},[b]);function P(){const j=JSON.stringify(h==null?void 0:h.records,null,2),N=new Blob([j],{type:"application/json"}),A=URL.createObjectURL(N),C=document.createElement("a");C.href=A,C.download=`${n.title}.json`,C.click()}function M(){const N=[Object.keys(h==null?void 0:h.records.reduce((F,D)=>({...F,...D}),{})).join(","),...((h==null?void 0:h.records)||[]).map(F=>Object.values(F).join(","))].join(`
|
|
233
|
+
`;P(R)}function z(){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($a,{jsonString:JSON.stringify(x,null,2)})})}),x&&x.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 K(){return e.jsxs(s.ResizablePanelGroup,{className:"flex grow pb-1",direction:"vertical",role:"editor-resizable-group",children:[e.jsxs(s.ResizablePanel,{id:"1",order:1,defaultSize:a?20:100,className:"relative flex grow",children:[e.jsx("div",{id:"sql-container",className:"relative flex w-[99%]",children:e.jsx(za,{})}),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(qa,{})}),e.jsx("code",{className:"absolute right-6 top-3 text-xs text-muted-foreground/70",children:"python"})]})]})]})}function U(){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:N||A,onClick:()=>{L()},className:"h-8 shrink-0",size:"sm",children:[N||A?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(Va,{errorSql:D,sql:j==null?void 0:j.sql,error:I,onDebugWithAssistant:B}),e.jsx(Qe,{}),e.jsxs(s.Toggle,{pressed:a,onPressedChange:R=>r(R),className:"h-8",size:"sm",variant:"outline",children:[e.jsx(Ra,{className:"mr-2 size-4 text-foreground/70"}),"Python"]}),!o&&e.jsxs("button",{disabled:o,onClick:()=>{M(!0)},className:"flex h-9 w-full cursor-text items-center justify-start px-3 text-left text-sm text-muted-foreground",children:[e.jsx(s.Sparkles,{className:"mr-2 size-4 text-foreground/70"}),"Type your question..."]})]})})}return e.jsxs("section",{role:"editor-section",className:"flex grow flex-col justify-end",children:[e.jsxs("div",{className:"relative flex grow justify-between overflow-y-scroll",children:[K(),z()]}),U()]})}const Ua=[{value:"table",label:"Table",icon:s.Table2},{value:"aggregateTable",label:"Aggregate",icon:s.Layers},{value:"pivotTable",label:"Pivot",icon:Re}];function Ka({className:t}){const n=s.useEditorStore(d=>d.card),{setCardType:a,setCard:r,updateCardInFrame:l}=s.useEditorActions(),c=["table","aggregateTable","pivotTable"].includes(n.type),i=s.hasValidCardConfig(n.config);if(!c||!i)return null;const o=d=>{var x;const u=d;if(u==="aggregateTable"&&((x=n.config)!=null&&x.pivotByColumns)&&n.config.pivotByColumns.length>0){const m={...n,type:u,config:{...n.config,pivotByColumns:[]}};r(m),l(m)}else{a(u);const m={...n,type:u};l(m)}};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:Ua.map(d=>{const u=d.icon,x=n.type===d.value;return e.jsxs("div",{className:"flex items-center",children:[e.jsx(s.RadioGroupItem,{value:d.value,id:`table-type-${d.value}`,className:"peer sr-only"}),e.jsxs(s.Label,{htmlFor:`table-type-${d.value}`,className:s.cn("flex cursor-pointer items-center gap-1.5 rounded-md px-3 py-1 text-sm font-medium transition-all",x?"bg-muted text-foreground shadow-sm":"text-muted-foreground hover:bg-muted/50"),children:[e.jsx(u,{className:"h-3.5 w-3.5"}),d.label]})]},d.value)})})})}function _a({card:t}){var P,M,T,y,f,j,N,A,C,O,F;const[n,a]=w.useState(!1),[r,l]=w.useState([]),{authToken:c}=s.useSemaphorContext(),{theme:i}=s.useTheme(),o=s.getTokenParams(c==null?void 0:c.accessToken),d=s.useDashboardStore(D=>D.themeStyle),u={mode:i||"system",colors:((M=(P=d==null?void 0:d.chart)==null?void 0:P.dataset)==null?void 0:M.backgroundColor)||[]};(T=t.customCardPreferences)!=null&&T.inputData;const{getCard:x}=s.useCustomVisual(((y=t.customCardPreferences)==null?void 0:y.url)||""),m=((f=t.customCardPreferences)==null?void 0:f.visualType)||"single",h=s.useEditorStore(D=>D.frame),{setCustomCardPreferences:p}=s.useEditorActions(),{data:b}=s.useDashboardCardQuery(t),g=w.useCallback((D,E)=>{l(L=>({...L,[D]:E}))},[]);if(!((j=t.customCardPreferences)!=null&&j.componentName))return null;const v=x((N=t.customCardPreferences)==null?void 0:N.componentName);function S(D){a(D)}const k=Object.keys(((A=t.customCardPreferences)==null?void 0:A.dataInputCardIds)||{}).map(D=>{var I,B,z;const E=(B=(I=t.customCardPreferences)==null?void 0:I.dataInputCardIds)==null?void 0:B[D].cardId,L=(z=h==null?void 0:h.cards)==null?void 0:z.find(K=>K.id===E);return L||null});return e.jsx("div",{className:"semaphor-custom mb-3 flex grow basis-0 flex-col space-y-2 overflow-y-auto",children:e.jsxs(w.Suspense,{fallback:e.jsx(e.Fragment,{}),children:[v&&m==="single"&&e.jsx(v,{editing:!0,params:o,theme:u,settings:(C=t.customCardPreferences)==null?void 0:C.settings,onDataChange:g,data:(b==null?void 0:b.records)||[]}),v&&m==="multiple"&&e.jsxs(e.Fragment,{children:[Object.keys(((O=t.customCardPreferences)==null?void 0:O.dataInputCardIds)||{}).map(D=>{var I,B,z;const E=(B=(I=t.customCardPreferences)==null?void 0:I.dataInputCardIds)==null?void 0:B[D].cardId,L=(z=h==null?void 0:h.cards)==null?void 0:z.find(K=>K.id===E);if(L)return e.jsx(s.MultiInputEmptyRenderer,{onLoadingStatus:S,onDataChange:g,dataInputIndex:D,card:L},L.id+D)}),e.jsx("div",{className:"flex flex-col gap-2",children:e.jsx(v,{theme:u,onDataChange:g,settings:k.map(D=>{var E;return(E=D==null?void 0:D.customCardPreferences)==null?void 0:E.settings}),data:k.map(D=>D!=null&&D.id?r==null?void 0:r[D.id]:[])})})]})]},(F=t.customCardPreferences)==null?void 0:F.componentName)})}function Ha({type:t,isLinked:n,className:a}){const r=s.useDashboardStore(h=>h.selectedFrameId),l=s.useManagementStore(h=>h.selectedVisual),c=s.useEditorStore(h=>h.frame);let i;if(t)i=t;else if(n!==void 0)i=n?"linked":"library";else if(!!!(c!=null&&c.visualId||l!=null&&l.id)&&r)i="local";else if(l&&!r)i="library";else if(c!=null&&c.visualId&&r)i="linked";else if(l!=null&&l.id&&r)i="library";else return null;if(i==="local")return null;const o={linked:"border-purple-200/70 bg-gradient-to-r from-purple-50/50 to-purple-100/30 text-purple-900 shadow-sm hover:from-purple-100/60 hover:to-purple-100/50 hover:shadow-md dark:border-purple-800/50 dark:from-purple-950/40 dark:to-purple-900/30 dark:text-purple-100 dark:hover:from-purple-950/60 dark:hover:to-purple-900/50",library:"border-blue-200/70 bg-gradient-to-r from-blue-50/50 to-blue-100/30 text-blue-900 shadow-sm hover:from-blue-100/60 hover:to-blue-100/50 hover:shadow-md dark:border-blue-800/50 dark:from-blue-950/40 dark:to-blue-900/30 dark:text-blue-100 dark:hover:from-blue-950/60 dark:hover:to-blue-900/50"},d={linked:"Linked to library: Changes made here update the library visual and all linked instances.",library:"Library visual: Share and reuse this visual across multiple dashboards."},u={linked:"border-purple-200 bg-purple-50 text-purple-900 dark:border-purple-800 dark:bg-purple-950 dark:text-purple-100",library:"border-blue-200 bg-blue-50 text-blue-900 dark:border-blue-800 dark:bg-blue-950 dark:text-blue-100"},x={linked:"fill-purple-50 dark:fill-purple-950",library:"fill-blue-50 dark:fill-blue-950"},m={linked:e.jsx(At,{className:"h-3.5 w-3.5"}),library:e.jsx(It,{className:"h-3.5 w-3.5"})};return e.jsx(s.TooltipProvider,{children:e.jsxs(s.Tooltip,{delayDuration:300,children:[e.jsx(s.TooltipTrigger,{asChild:!0,children:e.jsx(s.Badge,{variant:"outline",className:s.cn("cursor-help select-none transition-all",o[i],a),children:m[i]})}),e.jsxs(s.TooltipContent,{side:"bottom",className:s.cn("max-w-xs",u[i]),children:[e.jsx(s.TooltipArrow,{className:x[i]}),e.jsx("p",{children:d[i]})]})]})})}function Us({className:t,...n}){var I;const a=s.useEditorStore(B=>B.card),r=((I=a.customCardPreferences)==null?void 0:I.showCardHeader)??!0,l=s.useEditorStore(B=>B.frame),c=s.useDashboardStore(B=>B.dashboard.filters),[i,o]=w.useState(!1),{currentUser:d}=s.useCurrentUserInfo(),{tokenProps:u}=w.useContext(s.SemaphorContext),x=s.useEditorStore(B=>B.actions.setRunSql),{updateFilter:m}=s.useDashboardActions(),h=c==null?void 0:c.find(B=>B.id===l.filterId),{data:p,isLoading:b,isFetching:g,errorMessage:v,errorSql:S,pagination:k}=s.useDashboardCardQuery(a),{setCard:P,updateCardInFrame:M,setIsDevMode:T,setCardSql:y}=s.useEditorActions(),{data:f}=s.useTopoJson(a),j=w.useMemo(()=>{var B;return a.type!=="pivotTable"||!((B=p==null?void 0:p.records)!=null&&B.length)?null:{records:p.records,columnSubtotalMeta:p.columnSubtotalMeta,subtotalColumns:p.subtotalColumns||[],pivotSchema:p.pivotSchema||[],groupByColumns:p.groupByColumns}},[a.type,p==null?void 0:p.records,p==null?void 0:p.columnSubtotalMeta,p==null?void 0:p.subtotalColumns,p==null?void 0:p.pivotSchema,p==null?void 0:p.groupByColumns]),N=s.usePivotTableConfig(a,j),A=B=>{T(!0),y(B||S||a.sql||a.python||""),setTimeout(()=>{x(!0)},100)},C=()=>{o(!0)},O=w.useMemo(()=>{const B=typeof window<"u"?window.location.href:"",z=typeof navigator<"u"?navigator.userAgent:"",K=typeof window<"u"?`${window.innerWidth}x${window.innerHeight}`:"";return{category:s.FeedbackCategory.QUERY_GENERATION,user:d,tokenContext:u,systemState:{cardConfig:a.config,dataSource:a.dataSource,dashboardFilters:c,errorMessage:v||void 0,errorSql:S||a.sql||a.python,generatedSql:S||a.sql},metadata:{url:B,userAgent:z,timestamp:new Date().toISOString(),viewport:K}}},[d,u,a,c,v,S]),F=(B,z)=>{var U,R;const K={...a,paginationConfig:{page:B+1,pageSize:z}};P(K),M(K),a.sql&&((R=(U=a.preferences)==null?void 0:U.tablePrefs)!=null&&R.enableDevModePagination)&&x(!0)},D=w.useMemo(()=>!a.id||!(p!=null&&p.records)?null:s.createChartConfig({card:a,data:p==null?void 0:p.records,cardType:a.type,queryConfig:a.queryConfig,customCfg:a.customCfg,preferences:a.preferences,topoJson:f}),[a.id,p==null?void 0:p.records,a.type,a.customCfg,a.preferences,f]);function E(B){return e.jsx(s.ErrorBoundary,{FallbackComponent:s.FallbackVisual,children:e.jsx(_a,{card:B})})}function L(){if(p!=null&&p.records&&(p==null?void 0:p.records.length)===0&&!b&&!g)return v?e.jsx("div",{className:"flex h-full flex-col items-start justify-start overflow-auto p-4",children:e.jsx(Ze,{error:v,errorSql:S||a.sql||a.python,onOpenInEditor:A,onSendFeedback:C,showFeedbackButton:!0,errorTitle:"Unable to Create Visual"})}):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((b||g)&&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 E(a);if(!["table","pivotTable","aggregateTable","custom"].includes(a.type)&&D)return e.jsx("div",{className:"relative h-full min-h-0 w-full flex-1 grow basis-0",children:b||g?e.jsx(e.Fragment,{}):e.jsx(s.ChartJsVisual,{cfg:D})});if(a.type==="table")return e.jsx("div",{className:"relative mb-2 flex h-full min-h-0 w-full flex-1 grow basis-0",children:e.jsx(s.TableVisual,{card:a,data:(p==null?void 0:p.records)||[],paginationMetadata:k,onPaginationChange:F,isLoading:b||g})});if(a.type==="pivotTable"&&N)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:N.data,options:N.options,onAggregationChange:B=>{const z=s.handleAggregationChange(B,a.config),K={...a,config:z};P(K),M(K)},onAggregationLabelChange:B=>{const z=s.handleAggregationLabelChange(B,a.config),K={...a,config:z};P(K),M(K)}})});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:(p==null?void 0:p.records)||[],groupByColumns:p==null?void 0:p.groupByColumns,pivotSchema:p==null?void 0:p.pivotSchema,paginationMetadata:k,onPaginationChange:F,onAggregationChange:B=>{const z=s.handleAggregationChange(B,a.config),K={...a,config:z};P(K),M(K)},isLoading:b||g})})}return e.jsxs(s.Card,{role:"editor-visual-card",className:s.cn("relative flex h-full flex-col rounded-none",t),...n,children:[r&&e.jsxs(s.CardHeader,{className:"flex flex-row items-start justify-between py-4",children:[e.jsxs("div",{className:"flex-1",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(s.CardTitle,{className:"text-base",children:e.jsx(s.EditableText,{value:a.title,onSave:B=>P({...a,title:B}),isEditable:!0,placeholder:"Add title",displayClassName:"text-base font-semibold",inputClassName:"text-base font-semibold"})}),e.jsx(Ha,{}),e.jsx("div",{className:"ml-auto",children:e.jsx(Ka,{})})]}),e.jsx("div",{className:"w-1/2",children:e.jsx(s.EditableText,{value:a.description||"",onSave:B=>P({...a,description:B}),isEditable:!0,placeholder:"Add description",displayClassName:"text-sm text-muted-foreground",inputClassName:"text-sm"})})]}),h&&e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(s.Label,{className:"my-1",children:e.jsx(s.EditableText,{value:h.title||h.column,onSave:B=>m({...h,title:B}),isEditable:!0,placeholder:"Filter",displayClassName:"text-sm",inputClassName:"text-sm"})}),e.jsx(s.FilterComponent,{filter:h})]})]}),e.jsx(s.CardContent,{className:"flex grow flex-col",children:L()}),e.jsx(s.FeedbackDialog,{open:i,onOpenChange:o,feedbackData:O,showDebugInfo:!0})]})}const qe=({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}),Ja=()=>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."})]})]}),Qa=({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(qe,{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(qe,{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(qe,{language:"javascript",value:t,onChange:l})})]}),Wa=({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 Ya(){const[t,n]=w.useState(!1),[a,r]=w.useState(""),[l,c]=w.useState(""),[i,o]=w.useState(""),[d,u]=w.useState(""),x=s.useEditorStore(T=>T.card),m=s.useEditorStore(T=>T.card.customCfg),h=m?JSON.stringify(m,null,2):"",{data:p}=s.useDashboardCardQuery(x),{data:b}=s.useTopoJson(x),{setCardCustomCfg:g,setCustomVisualCode:v}=s.useEditorActions(),S=T=>{var y,f;return JSON.stringify({...T,data:{...T.data,datasets:(f=(y=T.data)==null?void 0:y.datasets)==null?void 0:f.map(j=>({...j,data:[]}))}},null,2)},k=()=>{var y,f;if(!((y=p==null?void 0:p.records)!=null&&y.length))return;const T=s.createChartConfig({card:x,data:p.records,cardType:x.type,queryConfig:x.queryConfig,preferences:x.preferences,topoJson:b});if(T){r(S(T)),o(((f=x.preferences)==null?void 0:f.customVisualCode)||"");const j=s.merge(T,m);c(S(j))}},P=()=>{try{if(i&&v(i),l){const T=JSON.parse(l),y=s.getObjectDiff(JSON.parse(a),T);g(y),u("")}}catch{u("Invalid JSON configuration")}},M=Object.keys(m||{}).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:k,className:M?"":"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(Ja,{}),e.jsxs("div",{className:"flex grow gap-2",children:[e.jsx(s.ErrorBoundary,{FallbackComponent:s.FallbackVisual,children:e.jsx(Us,{className:"w-1/2 rounded shadow-none"})}),e.jsx(Qa,{customCode:i,cardCustomCfgString:h,mergedConfig:l,onConfigChange:T=>c(T??""),onCodeChange:T=>o(T??"")})]}),e.jsx(Wa,{error:d,hasCardCustomConfig:!!m,onReset:()=>{c(a),g(null)},onApply:P,onClose:()=>n(!1)})]})]})}function ze(t){const[n,a]=w.useState(null);return n}function Ks(){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 _s(){const{data:t,isLoading:n,isError:a}=Ks(),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:d=>Math.min(1e3*2**d,3e4)}))}),l=[];let c=n,i=a;return r.forEach((o,d)=>{var u;if(o.isLoading&&(c=!0),o.isError&&(i=!0),o.data&&((u=t==null?void 0:t.plugins)!=null&&u[d])){const x=t.plugins[d],m=o.data.visuals.map(h=>({name:h.name,pluginName:x.label,componentType:h.componentType,pluginType:x.type,icon:h.icon,chartType:h.chartType,url:x.value}));l.push(...m)}}),{data:l,isLoading:c,isError:i}}function Xa({onChartTypeChange:t}){const{setCardCustomCfg:n,setCardPreferences:a,setCardType:r,setCustomCardPreferences:l}=s.useEditorActions(),{data:c,isLoading:i,isError:o}=_s(),d=w.useCallback((u,x)=>{n(null),a({}),r(u),x&&l({type:"component",visualType:"single",url:x.url,componentName:x.name,icon:x.icon}),t==null||t()},[n,a,r,l,t]);return i?e.jsxs(e.Fragment,{children:[e.jsx(s.Separator,{className:"my-3"}),e.jsx("div",{className:"py-4 text-center text-sm text-muted-foreground",children:"Loading custom visuals..."})]}):o?e.jsxs(e.Fragment,{children:[e.jsx(s.Separator,{className:"my-3"}),e.jsx("div",{className:"py-4 text-center 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-3"}),e.jsx("div",{className:"mb-2",children:e.jsx("span",{className:"text-xs font-medium text-muted-foreground",children:"Custom Charts"})}),e.jsx("div",{className:"grid grid-cols-3 gap-2",children:c.map((u,x)=>e.jsx(Za,{text:u.name,onClick:()=>d("custom",u),icon:u.icon},`${u.url}-${u.name}-${x}`))})]})}const Za=({text:t,icon:n,onClick:a})=>{const r=ze();return e.jsxs("button",{onClick:a,className:"flex flex-col items-center gap-2 rounded-lg border border-border bg-background p-3 transition-all hover:border-primary/50 hover:bg-muted/50 hover:shadow-sm",children:[r?e.jsx(r,{className:"h-6 w-6"}):e.jsx(Ae,{className:"h-6 w-6 text-muted-foreground"}),e.jsx("span",{title:t,className:"line-clamp-2 text-center text-xs font-medium text-foreground",children:t})]})};function en({onChartTypeChange:t,iconClassName:n,searchQuery:a=""}){const{setCardType:r,setCardPreferences:l,setIsDevMode:c}=s.useEditorStore(h=>h.actions),{setCardCustomCfg:i,setCustomCardPreferences:o,setQueryConfig:d}=s.useEditorActions();function u(h,p){i(null),l({}),r(h),["custom","text","map"].includes(h)&&(c(!0),d(void 0)),t==null||t()}const m=[{type:"table",name:"Table",icon:s.Table2},{type:"bar",name:"Bar Chart",icon:s.ChartColumnIncreasing},{type:"line",name:"Line Chart",icon:s.ChartLine},{type:"stackedBar",name:"Stacked Bar",icon:s.ChartColumnStacked},{type:"stackedLine",name:"Stacked Line",icon:s.MdStackedLineChart},{type:"scatter",name:"Scatter",icon:s.ChartScatter},{type:"bubble",name:"Bubble",icon:s.TbChartBubble},{type:"pie",name:"Pie Chart",icon:s.ChartPie},{type:"doughnut",name:"Doughnut",icon:s.Donut},{type:"funnel",name:"Funnel",icon:s.TbChartFunnel},{type:"radar",name:"Radar",icon:s.Radar},{type:"polarArea",name:"Polar Area",icon:s.PiChartPolar},{type:"tornado",name:"Tornado",icon:s.Tornado},{type:"range",name:"Range",icon:s.ChartNoAxesGantt},{type:"kpi",name:"KPI",icon:s.TiSortNumerically},{type:"text",name:"Text",icon:s.BookType},{type:"map",name:"Map",icon:s.Map},{type:"custom",name:"Custom",icon:Ae}].filter(h=>h.name.toLowerCase().includes(a.toLowerCase()));return e.jsx("div",{className:"grid grid-cols-3 gap-2",children:m.map(h=>{const p=h.icon;return e.jsxs("button",{onClick:()=>u(h.type),className:"flex flex-col items-center gap-2 rounded-lg border border-border bg-background p-3 transition-all hover:border-primary/50 hover:bg-muted/50 hover:shadow-sm",children:[e.jsx(p,{className:s.cn("h-6 w-6",n),strokeWidth:h.icon===s.MdStackedLineChart?0:void 0}),e.jsx("span",{className:"text-xs font-medium text-foreground",children:h.name})]},h.type)})})}function sn({chartType:t,className:n,customIcon:a,componentName:r}){const l=ze();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(s.Type,{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(Ae,{className:n});default:return e.jsx(s.Table2,{className:n})}}function Hs({variant:t="ghost"}){var o,d;const[n,a]=w.useState(!1),[r,l]=w.useState(""),c=s.useEditorStore(u=>u.card),i=c.type;return e.jsxs(s.Popover,{open:n,onOpenChange:u=>{a(u),u||l("")},children:[e.jsx(s.PopoverTrigger,{asChild:!0,children:e.jsx(s.Button,{size:"sm",variant:t||"ghost",children:e.jsx(sn,{className:"size-4",chartType:i,customIcon:(o=c.customCardPreferences)==null?void 0:o.icon,componentName:(d=c.customCardPreferences)==null?void 0:d.componentName})})}),e.jsxs(s.PopoverContent,{onOpenAutoFocus:u=>u.preventDefault(),className:"z-[70] w-[360px] p-3",children:[e.jsxs("div",{className:"mb-3 flex items-center gap-2 rounded-sm border border-border bg-background px-3 py-2",children:[e.jsx(s.Search,{className:"h-4 w-4 text-muted-foreground"}),e.jsx(s.Input$1,{placeholder:"Search charts...",value:r,onChange:u=>l(u.target.value),className:"h-auto border-0 p-0 text-sm focus-visible:ring-0 focus-visible:ring-offset-0"})]}),e.jsxs("div",{className:"max-h-[400px] overflow-y-auto",children:[e.jsx(en,{onChartTypeChange:()=>a(!1),searchQuery:r}),e.jsx(Xa,{onChartTypeChange:()=>a(!1)})]})]})]})}function tn({error:t,className:n="",textClassName:a="",copyButtonClassName:r=""}){const[l,c]=w.useState(!1),i=w.useRef(null),o=w.useRef(!1);function d(){t&&!o.current&&navigator.clipboard.writeText(t)}function u(h){(h.key==="Enter"||h.key===" ")&&(h.preventDefault(),d())}function x(){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 m(){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:i,className:`cursor-pointer select-text break-all font-mono text-xs text-red-700 dark:text-red-300 ${a}`,onClick:d,onKeyDown:u,onMouseUp:x,onMouseDown:m,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 an(){const t=s.useEditorStore(c=>{var i,o;return(o=(i=c.card.preferences)==null?void 0:i.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(us,{className:"size-4"}):e.jsx(ds,{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(us,{className:"size-4"}):e.jsx(ds,{className:"size-4"})})}return e.jsx(e.Fragment,{children:n==="funnel"?l():r()})}function nn({className:t}){var h,p,b,g,v,S,k,P;const n=s.useEditorStore(M=>M.card),{setCardPreferences:a,updateCardInFrame:r,setCard:l}=s.useEditorActions(),[c,i]=w.useState(!1),o=((p=(h=n.preferences)==null?void 0:h.displayOptions)==null?void 0:p.showFilterInfo)??!0,d=((g=(b=n.preferences)==null?void 0:b.displayOptions)==null?void 0:g.showCardToolbar)??!0,u=((S=(v=n.preferences)==null?void 0:v.displayOptions)==null?void 0:S.showChrome)??!0,x=((P=(k=n.preferences)==null?void 0:k.displayOptions)==null?void 0:P.allowScroll)??!0,m=(M,T)=>{var j;const y={...n.preferences,displayOptions:{...(j=n.preferences)==null?void 0:j.displayOptions,[M]:T}};a(y);const f={...n,preferences:y};l(f),r(f)};return e.jsx("div",{className:s.cn("flex items-center",t),children:e.jsxs(s.DropdownMenu,{modal:!1,open:c,onOpenChange:i,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(Ts,{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:M=>{m("showFilterInfo",M)},onSelect:M=>M.preventDefault(),className:"pr-2",children:[e.jsx("span",{className:"flex-1",children:"Filter Info"}),e.jsx("span",{className:"ml-4 text-xs text-muted-foreground",children:"Badge"})]}),e.jsxs(s.DropdownMenuCheckboxItem,{checked:d,onCheckedChange:M=>{m("showCardToolbar",M)},onSelect:M=>M.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:M=>{m("showChrome",M)},onSelect:M=>M.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:x,onCheckedChange:M=>{m("allowScroll",M)},onSelect:M=>M.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 Js(){const t=s.useEditorStore(c=>c.card),n=s.useEditorStore(c=>{var i,o;return(o=(i=c.card)==null?void 0:i.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(an,{})}),!["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(Re,{className:"size-4"}),a==="x"&&e.jsx(bt,{className:"size-4"}),a==="y"&&e.jsx(Rt,{className:"size-4"}),a==="none"&&e.jsx(qt,{className:"size-4"})]}),e.jsx(nn,{})]})}function rn(){const t=s.useEditorStore(b=>b.frame),n=s.useEditorStore(b=>b.card),{setFrame:a,setActiveTabCardId:r,setCard:l,updateCardInFrame:c}=s.useEditorActions(),i=(b,g)=>{b.dataTransfer.setData("tabIndex",g.toString())},o=b=>{b.preventDefault()},d=(b,g)=>{const v=b.dataTransfer.getData("tabIndex");if(v===g.toString())return;const S=Array.from(t.cards),[k]=S.splice(parseInt(v),1);S.splice(g,0,k),a({...t,cards:S})};function u(b){const g=t.cards.filter(k=>k.id!==b),v=g[0],S={...t,cards:g,activeCardId:v.id};a(S),r(v.id),l(v)}function x(b,g){const v={...t,cards:[...t.cards,g],activeCardId:b.id};a(v),r(g.id)}function m(){const b={...n,id:s.v4(),title:`${n.title} Copy`,tabTitle:`${n.tabTitle||n.title} Copy`};x(n,b)}function h(b){const g={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"};x(b,g)}function p(b,g){return b.cards.length===1&&(g.displayTab===!0||g.displayTab===void 0)||b.activeCardId!==g.id&&(g.displayTab===!0||g.displayTab===void 0)?null:e.jsx("div",{onClick:()=>{const v=g.displayTab===void 0?!1:!g.displayTab;l({...g,displayTab:v}),c({...g,displayTab:v})},children:g.displayTab===!0||g.displayTab===void 0?e.jsx(s.Eye,{className:"mr-2 size-3.5 text-muted-foreground hover:text-foreground"}):e.jsx(Ct,{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,g)=>e.jsxs(s.TabsTrigger,{draggable:!0,onDragStart:v=>i(v,g),onDragOver:o,onDrop:v=>d(v,g),className:"",value:b.id,children:[p(t,b),e.jsx(s.Editable,{enabled:t.activeCardId===b.id,text:b.tabTitle||b.title,onSave:v=>{l({...n,tabTitle:v}),c({...n,tabTitle:v})},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:v=>{v.stopPropagation(),m()}}),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 Qs(){const t=s.useEditorStore(v=>v.frame),n=s.useEditorStore(v=>v.card),a=s.useEditorStore(v=>v.isSqlRunning),r=s.useEditorStore(v=>v.isDevMode),{setFrame:l,setActiveTabCardId:c,setCard:i,setIsDevMode:o,setRunSql:d}=s.useEditorActions(),{data:u,isLoading:x,isFetching:m,isError:h}=s.useDashboardCardQuery(n);function p(v){const S=t.cards.find(k=>k.id===v);if(S!=null&&S.sql){r||o(!0),c(v);return}if(S!=null&&S.queryConfig){r&&o(!1),b(v),c(v);return}r||b(v),c(v)}function b(v){const S={...t,cards:t.cards.map(P=>P.id===n.id?n:P),activeCardId:v};l(S);const k=S.cards.find(P=>P.id===v);k.sql&&d(!0),i(k)}function g(){return n.type==="kpi"?x||m?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:x||m,isError:h})})}):n.type==="text"?x||m?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(Us,{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(v=>e.jsx(s.TabsContent,{className:"mt-0 grow",value:v.id,children:g()},v.id)),e.jsx(rn,{})]})}function ps({children:t}){var y,f;s.useEditorStore(j=>j.frame);const n=s.useEditorStore(j=>j.card),a=s.useEditorStore(j=>j.isDevMode),r=s.useEditorStore(j=>j.isShowingVisual),l=s.useDashboardStore(j=>j.isVisualEditing),c=s.useEditorStore(j=>j.pythonStdOut);s.useEditorStore(j=>j.actions.setRunSql);const{setFrame:i,setCard:o,setActiveTabCardId:d,runAssistant:u,setIsDevMode:x,setCardPreferences:m}=s.useEditorActions(),{data:h,isLoading:p,isFetching:b,errorMessage:g,refetch:v}=s.useDashboardCardQuery(n),[S,k]=w.useState(!1);w.useEffect(()=>{b||k(!1)},[b]);function P(){const j=JSON.stringify(h==null?void 0:h.records,null,2),N=new Blob([j],{type:"application/json"}),A=URL.createObjectURL(N),C=document.createElement("a");C.href=A,C.download=`${n.title}.json`,C.click()}function M(){const N=[Object.keys(h==null?void 0:h.records.reduce((F,D)=>({...F,...D}),{})).join(","),...((h==null?void 0:h.records)||[]).map(F=>Object.values(F).join(","))].join(`
|
|
234
234
|
`),A=new Blob([N],{type:"text/csv"}),C=URL.createObjectURL(A),O=document.createElement("a");O.href=C,O.download=`${n.title}.csv`,O.click()}function T(){const j=`Can you get the documentation for ${n.type} chart?`;u(j)}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(Hs,{}),l&&e.jsx(s.IconButton,{tooltip:"Visual Docs",onClick:T,children:e.jsx(ft,{className:"size-4"})}),!["table","custom"].includes(n.type)&&l&&e.jsx(Ya,{})]}),!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:M,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:P,children:e.jsx(St,{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:()=>{k(!0),v()},children:e.jsx(s.RefreshCcw,{className:s.cn("h-4 w-4",{"animate-spin":S})})}),e.jsx(Js,{})]}),n.type==="table"&&n.sql&&a&&e.jsxs("div",{className:"mr-2 flex items-center gap-3",children:[e.jsx(s.Checkbox,{id:"pagination",checked:((f=(y=n.preferences)==null?void 0:y.tablePrefs)==null?void 0:f.enableDevModePagination)??!1,onCheckedChange:j=>{var N;m({...n.preferences,tablePrefs:{...(N=n.preferences)==null?void 0:N.tablePrefs,enableDevModePagination:j}}),v()}}),e.jsx(s.Label,{htmlFor:"pagination",children:"Paginate Results"})]}),a&&e.jsx(on,{})]}),r?e.jsx(Qs,{}):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(ln,{})}),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)||[]}),g&&e.jsx(tn,{error:g})]})]})]}):e.jsx(e.Fragment,{children:"No Active Card"})}function ln(){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 on(){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 ye({defaultValue:t,label:n,options:a,value:r,onValueChange:l,className:c,icon:i,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:[i&&e.jsx("span",{children:i}),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(d=>e.jsx(s.SelectItem,{value:d.value,children:d.label},d.value))]})})]})}function cn(){var g,v;const t=s.useEditorStore(S=>S.card.customCardPreferences),{data:n}=Ks(),a=(n==null?void 0:n.plugins)||[],r=s.useEditorStore(S=>S.card),l=s.useEditorStore(S=>S.frame),c=(t==null?void 0:t.visualType)||"single",{setCustomCardPreferences:i}=s.useEditorActions(),{components:o,manifest:d}=s.useCustomVisual((t==null?void 0:t.url)||""),u=(g=d==null?void 0:d.visuals)==null?void 0:g.find(S=>S.name===(t==null?void 0:t.componentName));function x(S,k){if(!t)return;const M={...(t==null?void 0:t.dataInputCardIds)||{},[S]:{cardId:k,hookRef:null}};i({...t,dataInputCardIds:M})}function m(S){var P,M;const k=(P=l==null?void 0:l.cards)==null?void 0:P.filter(T=>{var y;return((y=T==null?void 0:T.customCardPreferences)==null?void 0:y.visualType)!=="multiple"}).map(T=>({value:T.id,label:T.tabTitle||T.title}));return e.jsx("div",{className:"space-y-2",children:(M=S==null?void 0:S.dataInputs)==null?void 0:M.map((T,y)=>{var f,j;return e.jsxs("div",{className:"grid grid-cols-10 gap-2",children:[e.jsx("div",{className:"col-span-4 flex items-center",children:T}),e.jsx(ye,{className:"col-span-6 h-8 w-full justify-between",label:"",options:k||[],value:((j=(f=t==null?void 0:t.dataInputCardIds)==null?void 0:f[y])==null?void 0:j.cardId)||"",onValueChange:N=>x(y,N)})]},y+Math.random())})})}function h(S,k,P=[],M=""){var T,y;return t?S==="input"?e.jsx(s.Input,{className:`h-8 w-full ${s.removeRing}`,value:((T=t==null?void 0:t.settings)==null?void 0:T[k])||M,onChange:f=>{i({...t,settings:{...t==null?void 0:t.settings,[k]:f.target.value}})}},k):S==="select"?e.jsx(ye,{className:"h-8 w-full",label:"",options:P,value:((y=t==null?void 0:t.settings)==null?void 0:y[k])||M,onValueChange:f=>{i({...t,settings:{...t==null?void 0:t.settings,[k]:f}})}}):null:null}function p(S){const k=Object.entries((S==null?void 0:S.settings)||{});return e.jsx("div",{className:"space-y-3",children:k.map(([P,M])=>e.jsxs("div",{className:"space-y-1",children:[e.jsx(s.Label,{children:M.title}),h(M.ui,P,M.options,M.defaultValue)]},P))})}function b(S){t&&i({...t,visualType:S,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(ye,{icon:e.jsx(pt,{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:S=>i({...t||{url:"",componentName:""},url:S})}),((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(ye,{icon:e.jsx(vt,{className:"h-3.5 w-3.5"}),className:"h-9 w-full",label:"Select Component",options:(o==null?void 0:o.filter(S=>S.type===c).map(S=>({value:S.name,label:S.name})))||[],value:t.componentName,onValueChange:S=>{console.log("changing value",S),i({...t,componentName:S})}})})]})})]}),((v=r==null?void 0:r.customCardPreferences)==null?void 0:v.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:m(u)})]}),u&&u.settings&&e.jsx("div",{className:"space-y-3",children:e.jsx("div",{className:"px-2",children:p(u)})})]})]})]})}function Te(){const[t,n]=w.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 x;return(x=u.card.preferences)==null?void 0:x.filterOnClickColumnIndex}),w.useEffect(()=>{c&&n(new Array(c.length).fill(!1))},[c]);function i(u,x){var m,h;x?a!=null&&a.onClickFilter&&((m=a==null?void 0:a.onClickFilter)==null?void 0:m.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,x){var h;const m=(h=a==null?void 0:a.onClickFilter)==null?void 0:h.map(p=>p.columnIndex===u?{...p,expression:x.target.value}:p);l({...a,onClickFilter:m})}function d(u){var x,m,h,p;if(t!=null&&t[u]||(m=(x=a==null?void 0:a.onClickFilter)==null?void 0:x.find(b=>b.columnIndex===u))!=null&&m.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,x)=>{var m,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:!!((m=a==null?void 0:a.onClickFilter)!=null&&m.find(p=>p.columnIndex===x)),onCheckedChange:p=>i(x,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===x))&&e.jsx(s.Pencil,{onClick:()=>{n(p=>{const b=[...p];return b[x]=!p[x],b})},className:"invisible size-3 cursor-pointer text-gray-400 group-hover:visible"})})]}),d(x)]})},u)})})}function dn({idx:t}){var o;const n=s.useEditorStore(d=>{var u;return(u=d.card)==null?void 0:u.preferences}),a=s.useEditorStore(d=>{var u;return(u=d.card.preferences)==null?void 0:u.datasetOptions}),r=s.useEditorStore(d=>d.actions.setCardPreferences),l=(o=n==null?void 0:n.chartOptions)==null?void 0:o.indexAxis,c=a==null?void 0:a.find(d=>d.idx===t);function i(d,u){(d==="end"||d==="start")&&s.getContrastColor(s.getCanvasBackgroundColor());const x={display:d!=="none",align:d,anchor:d,clamp:!0};if(!c)r({...n,datasetOptions:[...a||[],{idx:u,datalabels:x}]});else{const m={...c};m.datalabels=x;const h=a==null?void 0:a.map(p=>p.idx===u?m:p);r({...n,datasetOptions:h})}}return e.jsxs(s.Popover,{children:[e.jsx(s.PopoverTrigger,{children:e.jsx(Es,{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:()=>i("none",t),className:"h-7 p-1 text-xs font-normal",children:e.jsx(s.X,{className:"size-3.5"})}),e.jsx("button",{onClick:()=>i("start",t),className:"h-7 p-1 text-xs font-normal",children:e.jsx(Ft,{className:s.cn("h-4 w-4",{"rotate-90":l==="y"})})}),e.jsx("button",{onClick:()=>i("center",t),className:"h-7 p-1 text-xs font-normal",children:e.jsx(Lt,{className:s.cn("h-4 w-4",{"rotate-90":l==="y"})})}),e.jsx("button",{onClick:()=>i("end",t),className:"h-7 p-1 text-xs font-normal",children:e.jsx(Mt,{className:s.cn("h-4 w-4",{"rotate-90":l==="y"})})})]})})]})}function un(){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:i}=s.getKeys(c);l=i.slice(1)}return{transformedMetricKeys:l,dimensionKeys:a.slice(0,1),keys:a,defaultMetricKeys:r}}function es({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 Ws(){const t=s.useEditorStore(d=>d.card),n=s.useEditorStore(d=>{var u,x,m;return(m=(x=(u=d==null?void 0:d.card)==null?void 0:u.preferences)==null?void 0:x.chartOptions)==null?void 0:m.indexAxis}),{data:a}=s.useDashboardCardQuery(t),r=n==="y"?"Metric":"Dimension",l=n==="y"?"Dimension":"Metric",{dimensionKeys:c,transformedMetricKeys:i,keys:o}=un();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(d=>e.jsx("p",{className:"flex h-8 items-center rounded-md bg-muted/70 px-3 hover:bg-muted",title:d,children:Ys(d)},d))})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(s.Label,{children:l}),e.jsx("div",{className:"my-1 max-h-[125px] space-y-1 overflow-y-auto",children:i.map((d,u)=>e.jsx(Xs,{className:"flex h-8 items-center bg-muted/70 px-3 hover:bg-muted",iconClassName:"invisible group-hover:visible",col:d,idx:u},d))})]})]})}function Ys(t,n=30){return t.length>n?t.slice(0,n)+"...":t}function Xs({col:t,idx:n,className:a,iconClassName:r,children:l}){const c=s.useEditorStore(x=>{var m;return(m=x.card)==null?void 0:m.preferences}),i=s.useEditorStore(x=>{var m,h;return(h=(m=x.card)==null?void 0:m.preferences)==null?void 0:h.datasetOptions}),o=i==null?void 0:i.find(x=>x.idx===n),{setCardPreferences:d}=s.useEditorStore(x=>x.actions);function u(x){if(!o)d({...c,datasetOptions:[...i||[],{idx:n,type:x==="area"?"line":x,fill:x==="area"?"origin":""}]});else{const m={...o};m.type=x==="area"?"line":x,m.fill=x==="area"?"origin":"";const h=i==null?void 0:i.map(p=>p.idx===n?m:p);d({...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(es,{className:"max-w-[100px]",title:t,children:Ys(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(dn,{idx:n})]})]})}function Fe(){const t=s.useDashboardStore(o=>o.dashboard.filters),n=s.useEditorStore(o=>o.frame),{setFrame:a}=s.useEditorActions(),{columns:r}=s.useEditorAside(),{assignFilter:l}=Vs();function c(o){const d=l(o,"frame");a({...n,filterId:d})}const i=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(mn,{onSelect:c,columns:r}),i&&e.jsx(s.FilterHeader,{filter:i})]})}function mn({columns:t,onSelect:n}){var i;const[a,r]=Ue.useState(!1),[l,c]=Ue.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?(i=t.find(o=>o.column_name===l))==null?void 0:i.column_name:"Select Column...",e.jsx(s.CaretSortIcon,{className:"ml-2 h-4 w-4 shrink-0 opacity-50"})]})}),e.jsx(s.PopoverContent,{className:"w-[200px] p-0",children:e.jsxs(s.Command,{children:[e.jsx(s.CommandInput,{placeholder:"Search column",className:"h-9"}),e.jsxs(s.CommandList,{children:[e.jsx(s.CommandEmpty,{children:"No framework found."}),e.jsx(s.CommandGroup,{children:t==null?void 0:t.map(o=>e.jsxs(s.CommandItem,{value:o.column_name,onSelect:d=>{const u=d===l?"":d;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 hn({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(Ws,{})})]}),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(Te,{}),e.jsx(Fe,{})]})]})]})})}function xn({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(Te,{}),e.jsx(Fe,{})]})]})]})})}function Zs(){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 x;const d={datalabels:{display:o!=="none",align:o,anchor:o,clamp:!0}},u={...a,chartOptions:{...a==null?void 0:a.chartOptions,plugins:{...(x=a==null?void 0:a.chartOptions)==null?void 0:x.plugins,...d}}};r(u)}function c(){var o,d,u;return e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"font-medium",children:"Data Labels"}),e.jsxs(s.Select,{value:((u=(d=(o=a==null?void 0:a.chartOptions)==null?void 0:o.plugins)==null?void 0:d.datalabels)==null?void 0:u.anchor)||"none",onValueChange:l,defaultValue:"none",children:[e.jsx(s.SelectTrigger,{className:"h-8 w-full focus:ring-1 focus:ring-offset-0",children:e.jsx(s.SelectValue,{placeholder:"Select position"})}),e.jsx(s.SelectContent,{children:e.jsxs(s.SelectGroup,{children:[e.jsx(s.SelectLabel,{children:"Data Labels"}),e.jsx(s.SelectItem,{value:"none",children:"None"}),!["pyramid","funnel"].includes(t)&&e.jsx(s.SelectItem,{value:"start",children:"Start"}),e.jsx(s.SelectItem,{value:"center",children:"Center"}),!["pyramid","funnel"].includes(t)&&e.jsx(s.SelectItem,{value:"end",children:"End"})]})})]})]})}function i(){var o,d,u;return e.jsx("div",{children:e.jsxs(s.Select,{value:((u=(d=(o=a==null?void 0:a.chartOptions)==null?void 0:o.plugins)==null?void 0:d.datalabels)==null?void 0:u.anchor)||"none",onValueChange:l,defaultValue:"none",children:[e.jsx(s.SelectTrigger,{className:"h-8 w-full text-xs",children:e.jsx(s.SelectValue,{placeholder:"Select position"})}),e.jsx(s.SelectContent,{children:e.jsxs(s.SelectGroup,{children:[e.jsx(s.SelectItem,{className:"text-xs",value:"none",children:"None"}),!["pyramid","funnel"].includes(t)&&e.jsx(s.SelectItem,{className:"text-xs",value:"start",children:"Start"}),e.jsx(s.SelectItem,{className:"text-xs",value:"center",children:"Center"}),!["pyramid","funnel"].includes(t)&&e.jsx(s.SelectItem,{className:"text-xs",value:"end",children:"End"})]})})]})})}return e.jsx(e.Fragment,{children:n?c():i()})}const pn={datasets:[{type:"line",label:"Sum_sales",data:[]},{type:"bar",label:"Sum_profit",data:[]}]},fn={datasets:[{fill:"origin",type:"line",label:"Sum_sales",data:[]}]};function gn(){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:jn(t)}),!["kpi"].includes(t)&&e.jsxs("div",{className:"space-y-4",children:[e.jsx(Zs,{}),e.jsx(Te,{}),e.jsx(Fe,{})]})]})}function jn(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(pn,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(fn,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 bn({colorRanges:t,setColorRanges:n}){const a={start:-1/0,end:100,color:""};function r(i,o,d){const u=[...t];u[i]={...u[i],[o]:d},n(u)}function l(i){const o=[...t];o.splice(i,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((i,o)=>e.jsxs("div",{className:"flex items-center gap-2 px-2",children:[e.jsx(s.Input,{onChange:d=>r(o,"start",d.target.value),value:i.start,className:s.cn(`h-7 ${s.removeRing}`)}),e.jsx("span",{children:"-"}),e.jsx(s.Input,{value:i.end,onChange:d=>r(o,"end",d.target.value),className:s.cn(`h-7 ${s.removeRing}`)}),e.jsx(s.Input,{onChange:d=>r(o,"color",d.target.value),value:i.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 vn(){var x,m,h,p,b;const t=s.useEditorStore(g=>g.card.preferences),n=s.useEditorStore(g=>g.actions.setCardPreferences),a=s.useEditorStore(g=>g.card),r=s.hasValidCardConfig(a.config),l=s.useEditorStore(g=>g.actions.setNumberFormat);s.useEditorStore(g=>{var v,S;return(S=(v=g.card.preferences)==null?void 0:v.formatNumber)==null?void 0:S.decimalPlaces});const c=s.useEditorStore(g=>{var v,S;return(S=(v=g.card.preferences)==null?void 0:v.formatNumber)==null?void 0:S.locale}),i=s.useEditorStore(g=>{var v,S;return(S=(v=g.card.preferences)==null?void 0:v.formatNumber)==null?void 0:S.currency});s.useEditorStore(g=>g.actions.setFilterOnClickField);const o=s.useEditorStore(g=>{var v,S;return(S=(v=g.card.preferences)==null?void 0:v.formatNumber)==null?void 0:S.colorRanges})||[],d=s.useEditorStore(g=>g.actions.setColorRanges),u=[...new Set(s.LOCALE_CURRENCY_PAIRS.map(g=>g.currency))];return e.jsxs("div",{children:[!r&&e.jsxs("div",{className:"mb-3 flex items-center gap-2",children:[e.jsx(s.Checkbox,{checked:!!((x=t==null?void 0:t.formatNumber)!=null&&x.enabled),onCheckedChange:g=>{n({...t,formatNumber:{...t==null?void 0:t.formatNumber,enabled:g}})}}),e.jsx(s.Label,{children:"Format Number"})]}),(((m=t==null?void 0:t.formatNumber)==null?void 0:m.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:g=>{var v,S,k;return l(((v=t==null?void 0:t.formatNumber)==null?void 0:v.decimalPlaces)||0,((S=t==null?void 0:t.formatNumber)==null?void 0:S.currency)||"",g,((k=t==null?void 0:t.formatNumber)==null?void 0:k.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(g=>e.jsx(s.SelectItem,{value:g.locale,children:g.locale},g.locale))]})})]})]}),e.jsxs("div",{className:"w-full space-y-1",children:[e.jsx(s.Label,{children:"Currency"}),e.jsxs(s.Select,{value:i||"none",onValueChange:g=>{var v,S,k;console.log("currency",g),l(((v=t==null?void 0:t.formatNumber)==null?void 0:v.decimalPlaces)||0,g==="none"?"":g,((S=t==null?void 0:t.formatNumber)==null?void 0:S.locale)||"",((k=t==null?void 0:t.formatNumber)==null?void 0:k.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(g=>e.jsx(s.SelectItem,{value:g,children:g},g))]})})]})]})]}),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:g=>{var v,S,k;return l(Number(g),((v=t==null?void 0:t.formatNumber)==null?void 0:v.currency)||"",((S=t==null?void 0:t.formatNumber)==null?void 0:S.locale)||"",((k=t==null?void 0:t.formatNumber)==null?void 0:k.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(g=>e.jsx(s.SelectItem,{value:g,children:g},g))})]})]}),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:g=>{var v,S,k;return l(((v=t==null?void 0:t.formatNumber)==null?void 0:v.decimalPlaces)||0,((S=t==null?void 0:t.formatNumber)==null?void 0:S.currency)||"",((k=t==null?void 0:t.formatNumber)==null?void 0:k.locale)||"",g.target.value)}})]})]})]})}),e.jsx(s.Separator,{className:"my-3"}),e.jsx(bn,{colorRanges:o,setColorRanges:d})]})]})}function yn(){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(vn,{})}),e.jsx("div",{}),e.jsx("div",{})]})}function $e({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 Nn=[{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"}],Cn=["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"],Sn=Cn.map(t=>({label:t,value:t}));function wn(){var d,u,x,m,h,p,b,g,v,S,k,P,M,T,y,f,j,N;const t=s.useEditorStore(A=>A.card),n=(u=(d=t==null?void 0:t.preferences)==null?void 0:d.mapVisualOptions)==null?void 0:u.topoJsonUrl,[a,r]=w.useState(((m=(x=t==null?void 0:t.preferences)==null?void 0:x.mapVisualOptions)==null?void 0:m.customTopoJsonUrl)||""),{setCardPreferences:l}=s.useEditorActions(),{data:c}=s.useTopoJson(t),i=Object.keys((c==null?void 0:c.objects)||{}).map(A=>({label:A,value:A}))||[],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($e,{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($e,{open:!0,summary:"Settings",children:e.jsxs("div",{className:"space-y-3 px-2",children:[e.jsx(ye,{className:"h-9",options:o,onValueChange:A=>{console.log("value",A),l({...t.preferences,mapVisualOptions:{topoJsonUrl:A}})},value:n||"",label:"Select Map"}),n==="custom"&&e.jsx(s.Input,{onChange:A=>{r(A.target.value)},onBlur:()=>{var A;console.log("onBlur",a),l({...t.preferences,mapVisualOptions:{...(A=t.preferences)==null?void 0:A.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(ye,{className:"h-9",options:i,value:((p=(h=t.preferences)==null?void 0:h.mapVisualOptions)==null?void 0:p.objectKey)||"",label:"Map Object",onValueChange:A=>{var C;l({...t.preferences,mapVisualOptions:{...(C=t.preferences)==null?void 0:C.mapVisualOptions,objectKey:A}})}})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(s.Label,{children:"Projection"}),e.jsx(ye,{className:"h-9",options:Nn,value:((g=(b=t.preferences)==null?void 0:b.mapVisualOptions)==null?void 0:g.projection)||"",label:"Projection",onValueChange:A=>{var C;l({...t.preferences,mapVisualOptions:{...(C=t.preferences)==null?void 0:C.mapVisualOptions,projection:A}})}})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(s.Label,{children:"Colors"}),e.jsx(ye,{className:"h-9",options:Sn,value:((S=(v=t.preferences)==null?void 0:v.mapVisualOptions)==null?void 0:S.colorScale)||"",label:"Select Color Scale",onValueChange:A=>{var C;l({...t.preferences,mapVisualOptions:{...(C=t.preferences)==null?void 0:C.mapVisualOptions,colorScale:A}})}})]})]})]})}),e.jsx(s.Separator,{className:"my-4"}),e.jsx($e,{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:((P=(k=t.preferences)==null?void 0:k.mapVisualOptions)==null?void 0:P.projectionScale)||1,onChange:A=>{var C;l({...t.preferences,mapVisualOptions:{...(C=t.preferences)==null?void 0:C.mapVisualOptions,projectionScale:Number(A.target.value)}})}}),e.jsx(s.Label,{children:"X"}),e.jsx(s.Input,{className:`h-9 w-full ${s.removeRing}`,type:"number",step:10,value:((y=(T=(M=t.preferences)==null?void 0:M.mapVisualOptions)==null?void 0:T.projectionOffset)==null?void 0:y[0])||0,onChange:A=>{var C,O,F,D;l({...t.preferences,mapVisualOptions:{...(C=t.preferences)==null?void 0:C.mapVisualOptions,projectionOffset:[Number(A.target.value),((D=(F=(O=t.preferences)==null?void 0:O.mapVisualOptions)==null?void 0:F.projectionOffset)==null?void 0:D[1])||0]}})}}),e.jsx(s.Label,{children:"Y"}),e.jsx(s.Input,{className:`h-9 w-full ${s.removeRing}`,type:"number",step:10,value:((N=(j=(f=t.preferences)==null?void 0:f.mapVisualOptions)==null?void 0:j.projectionOffset)==null?void 0:N[1])||0,onChange:A=>{var C,O,F,D;l({...t.preferences,mapVisualOptions:{...(C=t.preferences)==null?void 0:C.mapVisualOptions,projectionOffset:[((D=(F=(O=t.preferences)==null?void 0:O.mapVisualOptions)==null?void 0:F.projectionOffset)==null?void 0:D[0])||0,Number(A.target.value)]}})}})]})}),e.jsx(s.Separator,{className:"my-4"}),e.jsx(Te,{})]})}function Dn(){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 Oe({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(Dn,{})})]}),!["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(Te,{}),e.jsx(Fe,{})]})]})]})})}function kn(){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(ye,{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(Ws,{})]})]}),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(Te,{}),e.jsx(Fe,{})]})]})]})})}function Tn({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(Te,{}),e.jsx(Fe,{})]})]})}),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 et({color:t,onColorChange:n,onClose:a}){const[r,l]=w.useState(0),[c,i]=w.useState(100),[o,d]=w.useState(50),[u,x]=w.useState(t);w.useEffect(()=>{const v=fs(t);if(v){const S=gs(v.r,v.g,v.b);l(S.h),i(S.s),d(S.l),x(t)}},[t]);const m=v=>{l(v),p(v,c,o)},h=v=>{const S=v.currentTarget.getBoundingClientRect(),k=Math.max(0,Math.min(1,(v.clientX-S.left)/S.width)),P=Math.max(0,Math.min(1,(v.clientY-S.top)/S.height)),M=k*100,T=(1-P)*100;i(M),d(T),p(r,M,T)},p=(v,S,k)=>{const P=In(v,S,k),M=En(P.r,P.g,P.b);x(M)},b=v=>{if(x(v),/^#[0-9A-Fa-f]{6}$/.test(v)){const S=fs(v);if(S){const k=gs(S.r,S.g,S.b);l(k.h),i(k.s),d(k.l)}}},g=()=>{/^#[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:v=>{v.buttons===1&&h(v)},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:v=>m(Number(v.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:v=>b(v.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:g,children:"OK"})]})]})}function fs(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 En(t,n,a){return"#"+((1<<24)+(t<<16)+(n<<8)+a).toString(16).slice(1)}function gs(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,i=0;const o=(r+l)/2;if(r!==l){const d=r-l;switch(i=o>.5?d/(2-r-l):d/(r+l),r){case t:c=((n-a)/d+(n<a?6:0))/6;break;case n:c=((a-t)/d+2)/6;break;case a:c=((t-n)/d+4)/6;break}}return{h:Math.round(c*360),s:Math.round(i*100),l:Math.round(o*100)}}function In(t,n,a){t/=360,n/=100,a/=100;let r,l,c;if(n===0)r=l=c=a;else{const i=(u,x,m)=>(m<0&&(m+=1),m>1&&(m-=1),m<.16666666666666666?u+(x-u)*6*m:m<.5?x:m<.6666666666666666?u+(x-u)*(.6666666666666666-m)*6:u),o=a<.5?a*(1+n):a+n-a*n,d=2*a-o;r=i(d,o,t+1/3),l=i(d,o,t),c=i(d,o,t-1/3)}return{r:Math.round(r*255),g:Math.round(l*255),b:Math.round(c*255)}}const An=["#000000","#ffffff","#6b7280","#dc2626","#ea580c","#ca8a04","#16a34a","#0891b2","#2563eb","#7c3aed","#c026d3","#e11d48","#0f172a","#f3f4f6","#fbbf24"];function st(){var P,M,T,y,f,j,N,A,C,O;const t=s.useEditorStore(F=>F.card),n=s.useEditorStore(F=>{var D;return(D=F.card)==null?void 0:D.preferences}),{setCardPreferences:a,updateCardInFrame:r}=s.useEditorActions(),{data:l}=s.useDashboardCardQuery(t),[c,i]=w.useState({}),[o,d]=w.useState(null),[u,x]=w.useState(null),m=w.useMemo(()=>{var L,I,B,z,K,U,R;if(!(l!=null&&l.records)||l.records.length===0)return[];const F=(t==null?void 0:t.type)==="stackedBar"||(t==null?void 0:t.type)==="stackedLine",D=(t==null?void 0:t.type)==="bar"||(t==null?void 0:t.type)==="line",E=((L=t==null?void 0:t.config)==null?void 0:L.pivotByColumns)&&t.config.pivotByColumns.length>0;if((F||D)&&E){if(l.pivotSchema&&Array.isArray(l.pivotSchema)){const _=new Set;return l.pivotSchema.forEach(Z=>{Z.alias&&_.add(Z.alias)}),Array.from(_)}if(l.records.length>0){const _=l.records[0],Z=Object.keys(_),ne=new Set;(I=t==null?void 0:t.config)!=null&&I.groupByColumns&&t.config.groupByColumns.forEach(H=>{ne.add(H.label||H.name),ne.add(H.alias||H.name)});const te=new Set;return(B=t==null?void 0:t.config)!=null&&B.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 ee=H.entityName||H.qualifiedEntityName;ee&&(te.add(`${ee}_${$}`),te.add(`${ee}_${$}_count`))}),Z.filter(H=>!ne.has(H)&&!te.has(H))}}if((D||F)&&!E&&((K=(z=t==null?void 0:t.config)==null?void 0:z.metricColumns)!=null&&K.length))return t.config.metricColumns.map(_=>_.alias||_.label||_.name);if((R=(U=t==null?void 0:t.config)==null?void 0:U.groupByColumns)!=null&&R.length){const _=t.config.groupByColumns[0],Z=_.label||_.name,ne=new Set;return l.records.forEach(te=>{const J=te[Z];J!=null&&ne.add(String(J))}),Array.from(ne)}return[]},[l,(P=t==null?void 0:t.config)==null?void 0:P.groupByColumns,(M=t==null?void 0:t.config)==null?void 0:M.pivotByColumns,(T=t==null?void 0:t.config)==null?void 0:T.metricColumns,t==null?void 0:t.type]),h=w.useMemo(()=>s.getDefaultChartColors(),[]);w.useEffect(()=>{const F={};m.forEach((D,E)=>{F[D]=s.getColorForValue(D,E,n==null?void 0:n.colorConfig)}),i(F)},[m,n==null?void 0:n.colorConfig,h]);const p=(F,D)=>{const E={...c,[F]:D};i(E);const L={...n||{},colorConfig:{segments:E}};a(L);const I={...t,preferences:L};r(I)},b=(F,D)=>{var K;const E=h[D%h.length],{[F]:L,...I}=((K=n==null?void 0:n.colorConfig)==null?void 0:K.segments)||{},B={...n||{},colorConfig:{segments:I}};a(B);const z={...t,preferences:B};r(z),i(U=>({...U,[F]:E}))};if(!m.length||!((t==null?void 0:t.type)==="stackedBar"||(t==null?void 0:t.type)==="stackedLine"?((f=(y=t==null?void 0:t.config)==null?void 0:y.groupByColumns)==null?void 0:f.length)||((N=(j=t==null?void 0:t.config)==null?void 0:j.pivotByColumns)==null?void 0:N.length):(C=(A=t==null?void 0:t.config)==null?void 0:A.groupByColumns)==null?void 0:C.length)||["table","kpi","text","custom"].includes(t.type))return null;const S=()=>{const F={...n||{},colorConfig:{segments:{}}};a(F);const D={...t,preferences:F};r(D);const E={};m.forEach((L,I)=>{E[L]=s.getColorForValue(L,I,void 0)}),i(E)},k=Object.keys(((O=n==null?void 0:n.colorConfig)==null?void 0:O.segments)||{}).length>0;return e.jsxs(s.AccordionItem,{value:"colors",className:"border-b-0",children:[e.jsx(s.AccordionTrigger,{className:"flex w-full items-center gap-2 py-2 text-sm font-medium hover:no-underline",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Bt,{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:k&&e.jsxs("button",{className:"ml-auto flex items-center gap-1 text-xs text-muted-foreground hover:text-foreground",onClick:S,children:[e.jsx(ms,{className:"h-3 w-3"}),"Reset All"]})})}),e.jsx("div",{className:"max-h-[200px] space-y-2 overflow-y-auto pr-1",children:m.map((F,D)=>{const E=s.isDefaultColor(c[F],D),L=!E;return e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(s.Popover,{open:o===F,onOpenChange:I=>d(I?F: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[F]}})}),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((I,B)=>e.jsxs("button",{className:s.cn("relative h-5 w-5 rounded border-2 transition-all hover:scale-110",c[F]===I?"border-gray-900":"border-transparent"),style:{backgroundColor:I},onClick:()=>{p(F,I),d(null)},children:[B===D%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:I})]},`default-${B}`))})]}),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:An.map((I,B)=>e.jsx("button",{className:s.cn("h-5 w-5 rounded border transition-all hover:scale-110",c[F]===I?"border-2 border-gray-900":I==="#ffffff"?"border border-gray-300":"border border-transparent"),style:{backgroundColor:I},onClick:()=>{p(F,I),d(null)},children:e.jsx("span",{className:"sr-only",children:I})},`preset-${B}`))})]}),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:()=>{x({value:F,color:c[F]}),d(null)},children:"Custom color"}),!E&&e.jsxs("button",{className:"flex items-center gap-1 text-sm text-muted-foreground hover:text-foreground",onClick:()=>{b(F,D),d(null)},children:[e.jsx(ms,{className:"h-3 w-3"}),"Reset"]})]})]})})]}),e.jsx("span",{className:"flex-1 truncate text-sm",children:F}),L&&e.jsx("span",{className:"text-xs text-muted-foreground",children:"(custom)"})]},F)})}),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:()=>x(null)}),e.jsx("div",{className:"relative rounded-lg bg-white shadow-lg",children:e.jsx(et,{color:u.color,onColorChange:F=>{p(u.value,F),x(null)},onClose:()=>x(null)})})]})]})})]})}function Ne({value:t,onSave:n,placeholder:a="",type:r="text",className:l=""}){const[c,i]=w.useState(t??""),[o,d]=w.useState(!1);w.useEffect(()=>{i(t??"")},[t]);const u=()=>{n(c),d(!1)},x=()=>{i(t??""),d(!1)};return e.jsxs("div",{className:`flex items-center gap-2 ${l}`,children:[e.jsx(s.Input$1,{placeholder:a,type:r,value:o?c:t??"",onChange:m=>{i(m.target.value),d(!0)},onFocus:()=>d(!0),onClick:m=>m.stopPropagation(),className:"h-8 text-xs",onPointerDown:m=>m.stopPropagation(),onKeyDown:m=>{m.stopPropagation(),m.key==="Enter"&&o&&c!==t?u():m.key==="Escape"&&x()},"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:x,children:e.jsx(s.X,{className:"h-4 w-4 text-muted-foreground"})})]})]})}const Fn=["auto","number","currency","percent","scientific","date"],Mn=[{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"}],Ln=[{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"}],Pn=t=>t.charAt(0).toUpperCase()+t.slice(1);function ss({formatOptions:t={},onFormatOptionsChange:n,showTitle:a=!0,title:r="NUMBER FORMAT"}){const l=t.type||"auto",c=(o,d)=>{n({...t,[o]:d})},i=()=>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:Fn.map(o=>e.jsx(s.SelectItem,{value:o,className:"text-xs",children:o==="auto"?"Auto (Default)":Pn(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??i(),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:Mn.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:Ln.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 js({axis:t,label:n,type:a,config:r,onChange:l}){var m,h,p,b,g,v,S,k,P,M,T,y;const c=(f,j)=>{l({...r,[f]:j})},i=(f,j)=>{var N,A;l({...r,name:{enabled:f==="enabled"?j:((N=r==null?void 0:r.name)==null?void 0:N.enabled)??!1,text:f==="text"?j:(A=r==null?void 0:r.name)==null?void 0:A.text}})},o=(f,j)=>{var N,A;l({...r,labels:{enabled:f==="enabled"?j:((N=r==null?void 0:r.labels)==null?void 0:N.enabled)??!0,rotation:f==="rotation"?j:(A=r==null?void 0:r.labels)==null?void 0:A.rotation}})},d=(f,j)=>{l({...r,scale:{...r==null?void 0:r.scale,[f]:j===""?"auto":Number(j)}})},u=t==="x"?["auto","top","bottom"]:["auto","left","right"],x=["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:f=>c("enabled",f),onClick:f=>f.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:((m=r==null?void 0:r.name)==null?void 0:m.enabled)??!1,onCheckedChange:f=>i("enabled",f)})]}),((h=r==null?void 0:r.name)==null?void 0:h.enabled)&&e.jsx(Ne,{placeholder:`${n} title`,value:((p=r==null?void 0:r.name)==null?void 0:p.text)||"",onSave:f=>i("text",f),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:f=>c("position",f),children:[e.jsx(s.SelectTrigger,{className:"h-8 text-xs",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{children:u.map(f=>e.jsx(s.SelectItem,{value:f,className:"text-xs",children:f==="auto"?"Auto (Default)":s.titleCase(f)},f))})]})]}),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:f=>o("enabled",f)})]}),((g=r==null?void 0:r.labels)==null?void 0:g.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(((v=r==null?void 0:r.labels)==null?void 0:v.rotation)||"auto"),onValueChange:f=>o("rotation",f==="auto"?"auto":Number(f)),children:[e.jsx(s.SelectTrigger,{className:"h-8 text-xs",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{children:x.map(f=>e.jsx(s.SelectItem,{value:f,className:"text-xs",children:f==="auto"?"Auto (Default)":`${f}°`},f))})]})]})]}),a==="value"&&e.jsx(ss,{formatOptions:(r==null?void 0:r.formatOptions)||{},onFormatOptionsChange:f=>l({...r,formatOptions:f}),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(Ne,{type:"number",placeholder:"auto",value:((S=r==null?void 0:r.scale)==null?void 0:S.min)==="auto"||((k=r==null?void 0:r.scale)==null?void 0:k.min)===void 0?"":String(r.scale.min),onSave:f=>d("min",f),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(Ne,{type:"number",placeholder:"auto",value:((P=r==null?void 0:r.scale)==null?void 0:P.max)==="auto"||((M=r==null?void 0:r.scale)==null?void 0:M.max)===void 0?"":String(r.scale.max),onSave:f=>d("max",f),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(Ne,{type:"number",placeholder:"auto",value:((T=r==null?void 0:r.scale)==null?void 0:T.stepSize)==="auto"||((y=r==null?void 0:r.scale)==null?void 0:y.stepSize)===void 0?"":String(r.scale.stepSize),onSave:f=>d("stepSize",f),className:""})})]})]})]})]})]})}function tt(){const t=s.useEditorStore(i=>i.card),n=s.useEditorStore(i=>{var o;return(o=i.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=(i,o)=>{const u={...n||{},[i==="x"?"xAxisConfig":"yAxisConfig"]:o};a(u);const x={...t,preferences:u};r(x)};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(Ts,{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(js,{axis:"x",label:"X-Axis",type:l.xAxisType,config:n==null?void 0:n.xAxisConfig,onChange:i=>c("x",i)}),l.hasYAxis&&e.jsx(js,{axis:"y",label:"Y-Axis",type:l.yAxisType,config:n==null?void 0:n.yAxisConfig,onChange:i=>c("y",i)})]})})]})}function at(){const t=s.useEditorStore(u=>u.card),n=s.useEditorStore(u=>{var x,m,h,p;return(p=(h=(m=(x=u.card)==null?void 0:x.preferences)==null?void 0:m.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"),i=(u,x)=>{const m={...n,[u]:x};a(m)},o=["top","bottom","left","right"],d=["start","center","end"];return e.jsxs(s.AccordionItem,{value:"legend",className:"border-b-0",children:[e.jsx(s.AccordionTrigger,{className:"flex w-full items-center gap-2 py-2 text-sm font-medium hover:no-underline",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Et,{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=>i("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=>i("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=>i("align",u),children:[e.jsx(s.SelectTrigger,{className:"h-8 text-xs",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{children:d.map(u=>e.jsx(s.SelectItem,{value:u,className:"text-xs",children:s.titleCase(u)},u))})]})]})]})]})})]})}function nt(){var j,N,A,C,O,F,D,E,L;const t=s.useEditorStore(I=>I.card),n=s.useEditorStore(I=>{var B,z;return(z=(B=I.card)==null?void 0:B.preferences)==null?void 0:z.dataLabelsConfig}),a=s.useEditorStore(I=>{var B;return(B=I.card)==null?void 0:B.preferences}),{setCardPreferences:r,updateCardInFrame:l}=s.useEditorActions();if(!t||!s.chartSupportsDataLabels(t.type))return null;const c=((j=a==null?void 0:a.chartOptions)==null?void 0:j.indexAxis)==="y",i=t.type==="stackedBar"||t.type==="stackedLine",o=t.type==="pie"||t.type==="doughnut"||t.type==="polarArea"||t.type==="funnel",d=!o,u=(A=(N=a==null?void 0:a.chartOptions)==null?void 0:N.plugins)==null?void 0:A.datalabels,x=(u==null?void 0:u.display)!==!1&&((u==null?void 0:u.anchor)||(u==null?void 0:u.align)),m=(n==null?void 0:n.enabled)!==void 0?n.enabled:x,h=(I,B)=>{const z={...n,[I]:B},K={...t.preferences||{},dataLabelsConfig:z};r(K);const U={...t,preferences:K};l(U)},p=(I,B)=>{const z={...n,font:{...n==null?void 0:n.font,[I]:B}},K={...t.preferences||{},dataLabelsConfig:z};r(K);const U={...t,preferences:K};l(U)},b=(I,B)=>{const z={...n,formatOptions:{...n==null?void 0:n.formatOptions,[I]:B}},K={...t.preferences||{},dataLabelsConfig:z};r(K);const U={...t,preferences:K};l(U)},v=(()=>{const I=t.type;return I==="stackedBar"||I==="stackedLine"||I==="pie"||I==="doughnut"?"center":c?"right":"top"})();let S=[];i||o?S=["center"]:S=["auto",...(c?["center","left","right"]:["center","top","bottom"]).filter(B=>B!==v),"custom"];const k=()=>s.titleCase(v),P=["center","start","end"],M=["center","start","end","top","bottom"],T=d?["auto","number","currency","percent","none"]:["number","currency","percent","none"],y=[{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"}],f=[{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(Gt,{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:m,onCheckedChange:I=>h("enabled",I)})]}),m&&e.jsxs(e.Fragment,{children:[!i&&!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:I=>h("position",I),children:[e.jsx(s.SelectTrigger,{className:"h-8 text-xs",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{children:S.map(I=>e.jsx(s.SelectItem,{value:I,className:"text-xs",children:I==="auto"?k():I==="custom"?"Custom (Advanced)":s.titleCase(I)},I))})]})]}),i&&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:I=>h("showTotal",I)})]}),(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:I=>h("anchor",I),children:[e.jsx(s.SelectTrigger,{className:"h-8 text-xs flex-1",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{children:P.map(I=>e.jsx(s.SelectItem,{value:I,className:"text-xs",children:s.titleCase(I)},I))})]})]}),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:I=>h("align",I),children:[e.jsx(s.SelectTrigger,{className:"h-8 text-xs flex-1",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{children:M.map(I=>e.jsx(s.SelectItem,{value:I,className:"text-xs",children:s.titleCase(I)},I))})]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(s.Label,{className:"text-xs font-medium",children:"Format"}),e.jsxs(s.Select,{value:(n==null?void 0:n.format)||(d?"auto":"none"),onValueChange:I=>h("format",I),children:[e.jsx(s.SelectTrigger,{className:"h-8 text-xs",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{children:T.map(I=>e.jsx(s.SelectItem,{value:I,className:"text-xs",children:I==="auto"&&d?"Auto (Use Axis)":I==="none"?"None (Raw Value)":s.titleCase(I)},I))})]})]}),(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(Ne,{type:"number",placeholder:"0",value:String(((C=n==null?void 0:n.formatOptions)==null?void 0:C.decimalPlaces)??(n.format==="currency"?2:n.format==="percent"?1:0)),onSave:I=>b("decimalPlaces",Number(I)),className:""})})]}),n.format==="currency"&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(s.Label,{className:"text-xs text-muted-foreground w-20",children:"Currency"}),e.jsxs(s.Select,{value:((O=n==null?void 0:n.formatOptions)==null?void 0:O.currency)||"USD",onValueChange:I=>b("currency",I),children:[e.jsx(s.SelectTrigger,{className:"h-8 text-xs flex-1",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{children:y.map(I=>e.jsx(s.SelectItem,{value:I.value,className:"text-xs",children:I.label},I.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:((F=n==null?void 0:n.formatOptions)==null?void 0:F.useSuffix)??!1,onCheckedChange:I=>b("useSuffix",I)})]}),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:((D=n==null?void 0:n.formatOptions)==null?void 0:D.locale)||"en-US",onValueChange:I=>b("locale",I),children:[e.jsx(s.SelectTrigger,{className:"h-8 text-xs flex-1",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{children:f.map(I=>e.jsx(s.SelectItem,{value:I.value,className:"text-xs",children:I.label},I.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(Ne,{type:"number",placeholder:"12",value:String(((E=n==null?void 0:n.font)==null?void 0:E.size)||12),onSave:I=>p("size",Number(I)),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:((L=n==null?void 0:n.font)==null?void 0:L.weight)||"normal",onValueChange:I=>p("weight",I),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:I=>{I==="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(Ne,{type:"number",placeholder:"0",value:String((n==null?void 0:n.rotation)||0),onSave:I=>h("rotation",Number(I)),className:""})}),e.jsx("span",{className:"text-xs text-muted-foreground",children:"degrees"})]})]})]})]})})]})}function On(){return e.jsxs("div",{className:"space-y-4 px-6 py-4",children:[e.jsx("h3",{className:"text-sm font-medium",children:"Chart Configuration"}),e.jsxs(s.Accordion,{type:"single",collapsible:!0,className:"w-full px-2",children:[e.jsx(st,{}),e.jsx(tt,{}),e.jsx(at,{}),e.jsx(nt,{})]})]})}const Bn=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."]})]}),Vn=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."]})]}),Rn=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 zn(){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(On,{})]});switch(a){case"stackedBar":case"stackedLine":return l(e.jsx(kn,{}));case"tornado":case"pyramid":return l(e.jsx(Oe,{docContent:Bn,cardType:a}));case"kpi":return e.jsx(yn,{});case"line":case"bar":return l(e.jsx(hn,{cardType:a}));case"range":return l(e.jsx(Oe,{docContent:Vn,cardType:a}));case"pie":case"doughnut":case"polarArea":case"radar":case"funnel":return l(e.jsx(Oe,{cardType:a}));case"bubble":case"scatter":return l(e.jsx(xn,{cardType:a}));case"table":return e.jsx(Tn,{cardType:a});case"text":return e.jsx(Oe,{docContent:Rn,cardType:a,suffix:"Visual"});case"map":return e.jsx(wn,{});case"custom":return e.jsx(cn,{});default:return l(e.jsx(gn,{}))}}return e.jsxs(s.ScrollArea,{className:"h-full w-full text-sm",children:[n(t),e.jsx(s.ScrollBar,{orientation:"horizontal"})]})}function qn(){const t=w.useRef(null),n=w.useRef(null),a=s.useEditorStore(l=>l.isShowingVisual),r=s.useEditorStore(l=>l.showAIDialog);return w.useEffect(()=>{var l,c,i,o;r?((l=t.current)==null||l.resize(0),(c=n.current)==null||c.resize(0)):((i=t.current)==null||i.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(Ga,{})}),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(zn,{})})}),!r&&e.jsx(s.ResizableHandle,{}),e.jsx(s.ResizablePanel,{minSize:40,defaultSize:75,maxSize:100,children:e.jsx(ps,{})})]}):e.jsx(ps,{})})]})}function $n(t){var ae;s.useAIInteractionStore(q=>q.currentAIContext);const[n,a]=w.useState(""),[r,l]=w.useState(null),{authToken:c,tokenProps:i}=s.useSemaphorContext(),o=s.useEditorStore(q=>{var Q;return(Q=q==null?void 0:q.card)==null?void 0:Q.sql}),d=s.useEditorStore(q=>q.isDevMode),u=s.useEditorStore(q=>{var Q;return(Q=q==null?void 0:q.card)==null?void 0:Q.python}),{setCardPython:x,setCardSql:m,setRunSql:h,switchCardType:p,setQueryConfig:b}=s.useEditorActions(),g=s.useEditorStore(q=>q.currentAssitantScope)||[],v=s.useEditorStore(q=>q.userInputForAI),S=s.useEditorStore(q=>q.triggerAIRun),k=s.useEditorStore(q=>q.card),P=s.useEditorStore(q=>q.selectedDatabaseName),M=s.useEditorStore(q=>q.selectedTableName),T=s.useEditorStore(q=>q.selectedConnectionId),y=s.useEditorStore(q=>q.selectedSchemaName),f=s.useDashboardStore(q=>q.dashboard.aiScopeTables),{errorMessage:j,refetch:N,data:A}=s.useDashboardCardQuery(k),{setTriggerAIRun:C,setCurrentAssitantScope:O,setCardConfig:F}=s.useEditorActions(),{selectedDatamodelName:D,connectionType:E,selectedDatamodelId:L}=s.useEditorAside(),I=(ae=s.useDashboardQuery().data)==null?void 0:ae.assistantProfileId,{messages:B,setMessages:z,regenerate:K,error:U,sendMessage:R,status:_,addToolResult:Z,stop:ne,clearError:te}=s.useChat({transport:new s.DefaultChatTransport({api:`${i.apiServiceUrl}/v1/assistant`,headers:()=>({Authorization:`Bearer ${c==null?void 0:c.accessToken}`}),body:()=>{const q=s.useAIInteractionStore.getState();return{random:Math.random(),assistantId:"editor-assistant",assistantProfileId:I,isDevMode:d,aiContext:q.currentAIContext,reasoningEffort:q.reasoningEffort,showReasoning:q.showReasoning}},credentials:"omit",prepareSendMessagesRequest:({messages:q,body:Q})=>({body:{...Q,messages:s.cleanupIncompleteMessages(q)}})}),onError:q=>{var Q;if(q.name==="AbortError"||(Q=q.message)!=null&&Q.includes("aborted")){console.log("[Editor Assistant] Stream aborted (expected)");return}console.error("[Editor Assistant] Stream error:",q)},onToolCall:J,onFinish({isAbort:q,isDisconnect:Q,isError:le}){a(""),console.log(q?"[Editor Assistant] Stream aborted by user":Q?"[Editor Assistant] Stream disconnected (network error)":le?"[Editor Assistant] Stream error occurred":"[Editor Assistant] Stream completed successfully")}});w.useEffect(()=>{S&&v&&(R({role:"user",parts:[{type:"text",text:v}]}),C(!1))},[S,v,R,C]);async function J({toolCall:q}){var Q,le,pe,fe,de,V,se,Y,je,ge,be,ve,he,Ee,Se,we;if(["createChartFromSql","createForecast"].includes(q.toolName)){const W=((Q=q.input)==null?void 0:Q.sql)??((le=q.args)==null?void 0:le.sql),re=((pe=q.input)==null?void 0:pe.python)??((fe=q.args)==null?void 0:fe.python),oe=((de=q.input)==null?void 0:de.chartType)??((V=q.args)==null?void 0:V.chartType);p(oe),m(W),x(re),h(!0),Z({tool:q.toolName,toolCallId:q.toolCallId,output:{status:"success",message:"Let the user know that chart is created"}})}else if(q.toolName==="getUserSql"){if(!o){Z({tool:q.toolName,toolCallId:q.toolCallId,output:{status:"error",message:"No SQL found"}});return}Z({tool:q.toolName,toolCallId:q.toolCallId,output:{status:"success",sql:o,python:u||""}})}else if(q.toolName==="generateQueryConfig"){a("Generating query config...");const W=((se=q.input)==null?void 0:se.chartType)??((Y=q.args)==null?void 0:Y.chartType),re=((je=q.input)==null?void 0:je.queryConfig)??((ge=q.args)==null?void 0:ge.queryConfig);((be=q.input)==null?void 0:be.cardConfig)??((ve=q.args)==null||ve.cardConfig),p(W),F(re),m(void 0),x(void 0);const oe=await N();if((he=oe==null?void 0:oe.data)!=null&&he.error){Z({tool:q.toolName,toolCallId:q.toolCallId,output:{status:"error",queryConfig:re,message:(Ee=oe==null?void 0:oe.data)==null?void 0:Ee.error.message}});return}if((Se=oe==null?void 0:oe.data)!=null&&Se.records){Z({tool:q.toolName,toolCallId:q.toolCallId,output:{status:"success",queryConfig:re,message:"The data has been visualized"}});return}Z({tool:q.toolName,toolCallId:q.toolCallId,output:{status:"success",queryConfig:re,message:"The data has been visualized",records:(we=oe==null?void 0:oe.data)==null?void 0:we.records}})}else a("Analyzing...")}function H(q){const Q=s.removeFromScopeArray(g,q);$(Q)}function $(q){const Q=s.sanitizeAIScope(q);O(Q),z(le=>[...le,{id:crypto.randomUUID(),role:"system",parts:[{type:"text",text:`Current scope of tables. Always use the table reference format when generating SQL | ${JSON.stringify(Q)}`}]}])}function ee(){const q={databaseName:P||"",schemaName:y||"",tableName:M||"",datamodelId:L||"",datamodelName:s.resolveDatamodelName(D),connectionId:T||"",connectionType:E||""},Q=s.dedup([...g,q]);$(Q)}function X(){const q={databaseName:P||"",schemaName:y||"",tableName:M||"",datamodelName:s.resolveDatamodelName(D),connectionId:T||"",connectionType:E||"",datamodelId:L||""};if(!s.isInAiScopeArray([...f||[],...g],q)||g.length===0){const le=s.dedup([...f||[],...g,q]).filter(pe=>pe.connectionId===q.connectionId);$(le)}}const ue=!["ready","error"].includes(_),me=s.getErrorMessage(U);return{messages:B,setMessages:z,sendMessage:R,regenerate:K,isLoading:ue,handleSetAIScope:X,handleAddCurrentTableToScope:ee,removeFromCurrentSelections:H,currentAssitantScope:g,setCurrentAssitantScope:O,stop:ne,status:_,toolStatus:n,llmUsage:r,onFinish:t,errorMessage:me,clearError:te}}const Gn=[{title:"Help me write a query for",subtitle:"orders by month"},{title:"Create a bar chart for",subtitle:"sales by category"}];function bs({isFullscreen:t,onFullscreenChange:n,fullscreenContainer:a}){const r=w.useRef(null),[l,c]=w.useState(!1),[i,o]=w.useState(s.isDevEnv),[d,u]=w.useState(!1),[x,m]=w.useState(!1),[h,p]=w.useState(!1),b=t??h,g=s.useCurrentAIContext(),{setCurrentAIContext:v}=s.useAIActions(),{clearQueue:S}=s.useQueueActions(),{clearFileAttachments:k}=s.useFileActions(),P=s.useFileAttachments("editor"),M=s.useDashboardStore(W=>W.dashboard.aiContext),T=s.useEditorStore(W=>W.card.dataSource),y=s.useEditorStore(W=>W.actions.setCardSql),f=s.useEditorStore(W=>W.actions.setRunSql),j=s.useEditorStore(W=>W.showAIDialog),N=s.useDashboardStore(W=>W.handleOpenAssistantProfile),{setShowAIDialog:A,setCardPython:C}=s.useEditorActions(),{setDataSource:O}=s.useEditorActions(),{assistantProfile:F}=s.useAssistantProfile(),{messages:D,setMessages:E,sendMessage:L,isLoading:I,stop:B,status:z,llmUsage:K,errorMessage:U,clearError:R}=$n(),[_,Z]=w.useState(""),ne=W=>{Z(W.target.value)},te=W=>{W.preventDefault();const re=_.trim();if(!re&&P.length===0)return;const oe=[];re&&oe.push({type:"text",text:re}),P.forEach(De=>{De.data&&oe.push({type:"file",mediaType:De.type,filename:De.name,url:`data:${De.type};base64,${De.data}`})}),L({role:"user",parts:oe}),Z(""),k("editor"),Q({force:!0})},{visibleMessages:J,hasMoreMessages:H,totalMessageCount:$,loadMoreMessages:ee,resetMessageWindow:X}=s.useMessageWindow(D,{maxVisibleMessages:15,initialLoadCount:10,loadMoreCount:5}),{scrollRef:ue,isAtBottom:me,hasNewMessages:ae,newMessageCount:q,scrollToBottom:Q,handleScroll:le,resetNewMessageCount:pe}=s.useAutoScroll(J,{threshold:50,behavior:"smooth",isStreaming:I});w.useEffect(()=>{var W;j&&((W=r.current)==null||W.focus(),v({selectedEntities:(T==null?void 0:T.selectedEntities)||[]}))},[j,T,v]),s.useAutoSubmitQueue({assistantType:"editor",status:z,isLoading:I,sendMessage:L});const{hasActiveTools:fe}=s.useActiveToolStatus(D),de=w.useCallback(W=>{n==null||n(W),t===void 0&&p(W)},[t,n]);w.useEffect(()=>{if(!b)return;function W(re){re.key==="Escape"&&de(!1)}return window.addEventListener("keydown",W),()=>{window.removeEventListener("keydown",W)}},[b,de]);const V=w.useCallback(W=>{L({role:"user",parts:[{type:"text",text:W}]}),Q({force:!0})},[L,Q]),se=w.useCallback(async()=>{const W=JSON.stringify(D??[],null,2);try{if(typeof navigator>"u"||!navigator.clipboard)throw new Error("Clipboard API unavailable");await navigator.clipboard.writeText(W),s.ue.success("Conversation copied")}catch(re){console.error("Failed to copy conversation",re),s.ue.error("Unable to copy conversation")}},[D]),Y=w.useCallback(()=>{de(!b)},[b,de]);function je(W,re){re==="sql"?(y(W),f(!0)):re==="python"&&(C(W),f(!0))}function ge(){g.selectedEntities.length===0&&v({selectedEntities:(M==null?void 0:M.selectedEntities)||[]})}function be(W){ge();const re={role:"user",parts:[{type:"text",text:W.title+" "+W.subtitle}]};L(re)}function ve(W){ge(),L({role:"user",parts:[{type:"text",text:W}]})}function he(){return e.jsxs(s.DropdownMenu,{children:[e.jsx(s.DropdownMenuTrigger,{asChild:!0,children:e.jsx(s.Button,{className:"h-7 p-2 text-muted-foreground 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:i,onCheckedChange:o,children:"Tool Invocations"}),e.jsx(s.DropdownMenuCheckboxItem,{checked:d,onCheckedChange:u,children:"System Message"})]})]})}function Ee(){return e.jsx("div",{"data-role":"header",children:e.jsx("div",{className:"text-lg font-semibold",children:"Assistant"})})}const Se=(_==null?void 0:_.length)===0&&(D==null?void 0:D.filter(W=>W.role==="user").length)===0,we=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:[Ee(),N&&e.jsx(s.Button,{variant:"outline",size:"sm",className:"h-7 p-2",onClick:N,children:(F==null?void 0:F.name)||"Default Profile"}),e.jsxs("div",{"data-role":"header-actions",className:"flex items-center",children:[he(),i&&e.jsx(s.Button,{variant:"ghost",size:"sm",className:"ml-2 h-7 px-2 text-muted-foreground hover:text-foreground",onClick:se,children:"Copy Conversation"}),e.jsx(s.IconButton,{tooltip:b?"Exit Fullscreen":"Expand",className:"h-7 p-2 text-muted-foreground hover:text-foreground",onClick:Y,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:()=>{E([]),S("editor"),R(),X()},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:()=>{A(!1)},children:e.jsx(s.X,{className:"size-4"})})]})]}),e.jsx(s.CustomScrollArea,{ref:ue,className:"mt-2 flex w-full grow basis-0",onScroll:le,children:e.jsxs("div",{className:"space-y-4 py-2 pr-3","data-role":"messages",children:[H&&e.jsx("div",{className:"flex justify-center py-2",children:e.jsxs(s.Button,{variant:"outline",size:"sm",onClick:ee,className:"text-xs",children:["Load ",Math.min(5,$-J.length)," ","more messages (",$-J.length," ","hidden)"]})}),e.jsx(s.PrintMessages,{messages:J,showTools:i,handleRun:je,showSystemMessage:d,onQuickReply:V,disableQuickReplies:I}),!fe&&e.jsx(s.AssistantStatus,{status:z,errorMessage:U})]})}),!me&&e.jsx("div",{className:"absolute bottom-24 right-8 z-10",children:e.jsxs(s.Button,{onClick:()=>{Q({force:!0}),pe()},size:"sm",variant:"secondary",className:"rounded-full shadow-lg","aria-label":"Scroll to bottom",children:[e.jsx(s.ChevronDown,{className:"h-4 w-4"}),ae&&q>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:q>9?"9+":q})]})}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{children:[Se&&!F&&e.jsx(s.Placeholders,{onClick:be,placeholders:Gn}),e.jsx("div",{children:Se&&F&&e.jsx(s.SeedQuestions,{seedQuestions:F.seedQuestions||[],handleSeedQuestionClick:ve})})]}),e.jsx(s.PendingMessagesDisplay,{assistantType:"editor",className:"mb-3"}),e.jsx(s.ChatInputWithContext,{ref:r,setInput:Z,stop:B,input:_,handleInputChange:ne,handleSubmit:W=>{ge(),te(W),Q({force:!0})},isLoading:I,status:z,assistantType:"editor",onFocus:()=>{}})]}),K&&l&&e.jsx("div",{className:"flex h-8 items-center justify-between",children:e.jsxs("div",{className:"text-xs text-muted-foreground",children:["Usage: ",K.inputTokens," prompt tokens, ",K.outputTokens," ","completion tokens, ",K.totalTokens," total tokens"]})}),e.jsx(s.DataSourceDialog,{incomingSelectedEntities:(T==null?void 0:T.selectedEntities)||[],open:x,onOpenChange:m,dataSource:T||s.EMPTY_DATA_SOURCE,dialogMode:"aiContext"})]});return b&&a?ht.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:we})}),a):we}function ts(t,n){const[a,r]=w.useState(()=>{const l=localStorage.getItem(t);return l?JSON.parse(l):n});return w.useEffect(()=>{localStorage.setItem(t,JSON.stringify(a))},[a,t]),[a,r]}const Un="chart-selector-standard-first";function Kn(){const[t,n]=ts(Un,!0);return{standardFirst:t,updatePreference:n}}const vs=({pluginVisual:t,index:n,onSelect:a})=>{const r=ze(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}`)},ys=["default","standardPlugin","customPlugin"];function _n({selectedChart:t,onChartChange:n}){var M;const[a,r]=w.useState(!1),{data:l}=_s();Kn();const i=((M=s.useEditorStore(T=>T.card).customCardPreferences)==null?void 0:M.url)||"";Je(i);const{setCardType:o,setCardPreferences:d,setIsDevMode:u}=s.useEditorStore(T=>T.actions),{setCardCustomCfg:x,setCustomCardPreferences:m,setQueryConfig:h}=s.useEditorActions(),[p,b]=ts("chart-section-active",null),g=w.useMemo(()=>p?[p,...ys.filter(T=>T!==p)]:ys,[p]);function v(T){x(null),d({}),o(T),["custom","map"].includes(T)&&(u(!0),h(void 0)),n(T),r(!1)}function S(T){x(null),d({}),o("custom"),m({type:"component",visualType:"single",url:T.url,componentName:T.name,icon:T.icon,pluginChartType:T.chartType}),h(void 0),n("custom"),r(!1)}const k=()=>{var y;if(t==="custom"){const f=s.useEditorStore.getState().card;return((y=f==null?void 0:f.customCardPreferences)==null?void 0:y.componentName)||"Custom Visual"}const T=s.chartTypes.find(f=>f.id===t);return(T==null?void 0:T.label)||"Select chart type"},P=()=>{var y,f;if(t==="custom"){const j=s.useEditorStore.getState().card,N=(y=j==null?void 0:j.customCardPreferences)==null?void 0:y.icon,A=(f=j==null?void 0:j.customCardPreferences)==null?void 0:f.componentName;if(N&&A)return e.jsx(Hn,{icon:N,componentName:A});if(A){const C=s.getAutoDetectedChartIcon(A);if(C)return C}return e.jsx(Ae,{className:"h-4 w-4"})}const T=s.chartTypes.find(j=>j.id===t);if(T){const j=T.icon;return e.jsx(j,{className:"h-4 w-4"})}return e.jsx(Ae,{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:[P(),e.jsx("span",{children:k()})]}),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."}),g.map(T=>{if(T==="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:y=>b(y?"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(y=>{const f=y.icon;return e.jsx(s.CommandItem,{value:`${y.label} ${y.id} chart graph visualization`,onSelect:()=>v(y.id),className:"flex items-center gap-2",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(f,{className:"h-4 w-4"}),e.jsx("span",{children:y.label})]})},y.id)})},"default");if(T==="standardPlugin"){const y=l.filter(f=>f.pluginType==="standard");return y.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:f=>b(f?"standardPlugin":null),className:"scale-75"})]})]}),className:"[&_[cmdk-group-heading]]:text-sm [&_[cmdk-group-heading]]:font-medium [&_[cmdk-group-heading]]:text-muted-foreground",children:y.filter(f=>f.componentType==="chart").map((f,j)=>e.jsx(vs,{pluginVisual:f,index:j,onSelect:()=>S(f)},`${f.url}-${f.name}-${j}`))},"standardPlugin"):null}if(T==="customPlugin"){const y=l.filter(f=>f.pluginType==="custom");return y.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:f=>b(f?"customPlugin":null),className:"scale-75"})]})]}),className:"[&_[cmdk-group-heading]]:text-sm [&_[cmdk-group-heading]]:font-medium [&_[cmdk-group-heading]]:text-muted-foreground",children:y.map((f,j)=>e.jsx(vs,{pluginVisual:f,index:j,onSelect:()=>S(f)},`${f.url}-${f.name}-${j}`))},"customPlugin"):null}return null})]})]})})]})})}const Hn=({icon:t,componentName:n})=>{const a=ze(),r=s.getAutoDetectedChartIcon(n);return a?e.jsx(a,{className:"h-4 w-4"}):r||e.jsx(Ae,{className:"h-4 w-4"})},Jn=[{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 Qn({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:Jn.map(c=>{if(c.requiresPivot&&!r)return null;const i=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(i,{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 as=({dataType:t})=>s.getFieldIconComponent(t);function Wn({aliasTemplate:t,onAliasTemplateChange:n}){var d;const[a,r]=w.useState(t),[l,c]=w.useState(!1),i=(d=s.useEditorStore(u=>{var x;return(x=u.card.config)==null?void 0:x.pivotByColumns}))==null?void 0:d[0],o=i?`e.g. Min Sales in {{${i.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 Yn({valueAliases:t,onValueAliasesChange:n}){const[a,r]=w.useState(null),[l,c]=w.useState(""),[i,o]=w.useState(""),d=()=>{n({...t,"":""})},u=m=>{const h={...t};delete h[m],n(h)},x=m=>{const h={...t};delete h[m],h[l]=i,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(([m,h],p)=>e.jsx("div",{className:"flex items-center gap-2",children:a===m?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"?x(m):b.key==="Escape"&&r(null)},"aria-label":"Edit value alias key"}),e.jsx(s.Input$1,{placeholder:"Alias label",value:i,onChange:b=>o(b.target.value),className:"h-8 w-24 text-xs",onPointerDown:b=>b.stopPropagation(),onKeyDown:b=>{b.key==="Enter"?x(m):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:()=>x(m),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:m,className:"h-8 w-24 text-xs",readOnly:!0,onClick:()=>{r(m),c(m),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(m),c(m),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(m),"aria-label":"Remove value alias",children:e.jsx(s.X,{className:"h-3 w-3"})})]})},m+p)),e.jsxs(s.Button,{variant:"outline",size:"sm",className:"mt-1 h-8 text-xs",onClick:d,children:[e.jsx(s.Plus,{className:"mr-1 h-3 w-3"})," Add Value Alias"]})]})]})}function Xn({column:t}){const n=s.useEditorStore(d=>d.card.type),a=s.useEditorStore(d=>{var u,x;return(x=(u=d.card)==null?void 0:u.config)==null?void 0:x.metricColumns}),r=(a==null?void 0:a.map(d=>d.label))||[],l=r==null?void 0:r.find(d=>d===t.label||d===t.name),c=l?r.indexOf(l):-1;function i(){return e.jsx("div",{className:"pr-1",children:l&&e.jsx(Xs,{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(Zs,{})]})}return e.jsxs("div",{className:"space-y-1",children:[["stackedBar","stackedLine","bar","line"].includes(n)&&i(),["pie","doughnut"].includes(n)&&o()]})}function Zn({field:t,searchQuery:n="",limit:a=500}){const{authToken:r,tokenProps:l}=s.useSemaphorContext(),c=s.useEditorStore(u=>u.card),i=c==null?void 0:c.dataSource,o=["attribute-values",t.entityName,t.name,n,a],d=s.useQuery({queryKey:o,queryFn:async()=>{if(!(i!=null&&i.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},x={connection_id:i.connectionId,cardConfig:u,cardDataSource:i,cache_config:s.getCacheConfig({card:c})};console.log("requestBody",x);const m=await s.postRequestRegular(`${l.apiServiceUrl}/v1/query`,(r==null?void 0:r.accessToken)||"",x);if(m!=null&&m.error)return console.error("Error fetching attribute values:",m.error),[];const h=t.name;return((m==null?void 0:m.records)||[]).map(b=>{const g=b[h]||b[t.alias||h]||b[t.label];return{id:g||"",value:g||"",label:String(g||"(empty)")}})}catch(u){return console.error("Error fetching attribute values:",u),[]}},enabled:!!t&&!!(i!=null&&i.connectionId),staleTime:5*60*1e3,gcTime:10*60*1e3});return{values:d.data||[],isLoading:d.isLoading,isFetching:d.isFetching,isError:d.isError,error:d.error,refetch:d.refetch}}function er({open:t,onOpenChange:n,availableFields:a,existingFilters:r,editingCondition:l,onSave:c}){var P,M;const i=!!l,[o,d]=w.useState(i?"values":"fields"),[u,x]=w.useState(""),[m,h]=w.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(T=>{var f;return i?!1:!((f=r==null?void 0:r.conditions)==null?void 0:f.some(j=>j.field.id===T.id))&&T.label.toLowerCase().includes(u.toLowerCase())}),b=T=>{h({...m,field:T}),d("values")},g=()=>{if(m.field&&m.selectedValues.length>0){const T={id:m.id,field:m.field,operator:"in",value:m.selectedValues};let y;if(i){const f=((r==null?void 0:r.conditions)||[]).map(j=>j.id===l.id?T:j);y={...r,conditions:f}}else{const f=(r==null?void 0:r.conditions)||[];y={id:(r==null?void 0:r.id)||s.v4(),logicalOperator:"AND",negate:!1,conditions:[...f,T],groups:[]}}c(y),n(!1)}},v=()=>{if(!i||!l)return;const T=((r==null?void 0:r.conditions)||[]).filter(y=>y.id!==l.id);if(T.length>0){const y={...r,conditions:T};c(y)}else c(void 0);n(!1)},S=T=>{h({...m,selectedValues:T})},k=()=>{i&&l?(h({id:l.id,field:l.field,selectedValues:Array.isArray(l.value)?l.value:[l.value]}),d("values")):(h({id:s.v4(),field:null,selectedValues:[]}),d("fields")),x("")};return w.useEffect(()=>{t&&k()},[t,i,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:i?`Edit Filter: ${(P=m.field)==null?void 0:P.label}`:o==="fields"?"Select Field to Filter":`Select Values for ${(M=m.field)==null?void 0:M.label}`})}),e.jsxs("div",{className:"space-y-4",children:[!i&&(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(T=>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:[T.field.label,":"]}),e.jsx("span",{className:"text-muted-foreground",children:Array.isArray(T.value)?`${T.value.length} values`:String(T.value)})]},T.id))})]}),o==="fields"&&!i?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:T=>x(T.target.value),className:"pl-10"})]}),e.jsx("div",{className:"grid grid-cols-2 gap-2 max-h-[400px] overflow-y-auto",children:p.map(T=>e.jsxs(s.Button,{variant:"outline",className:"justify-start h-auto py-2 px-3",onClick:()=>b(T),children:[e.jsx(as,{dataType:s.getDataType(T.dataType)}),e.jsxs("div",{className:"ml-2 text-left",children:[e.jsx("div",{className:"text-sm font-medium",children:T.label}),e.jsxs("div",{className:"text-xs text-muted-foreground",children:[T.entityName,".",T.name]})]})]},T.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(sr,{field:m.field,selectedValues:m.selectedValues,onValuesChange:S,onBack:i?void 0:()=>d("fields")}),e.jsxs("div",{className:"flex justify-between pt-4 border-t",children:[e.jsx("div",{children:i?e.jsx(s.Button,{variant:"destructive",onClick:v,children:"Delete Filter"}):e.jsx(s.Button,{variant:"outline",onClick:k,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:g,disabled:!m.field||m.selectedValues.length===0,children:"Apply"})]})]})]})]})})}function sr({field:t,selectedValues:n,onValuesChange:a,onBack:r}){const[l,c]=w.useState(""),{values:i,isLoading:o,isFetching:d}=Zn({field:t,searchQuery:l,limit:500}),u=l?i.filter(h=>String(h.value).toLowerCase().includes(l.toLowerCase())):i,x=h=>{const p=n.includes(h);a(p?n.filter(b=>b!==h):[...n,h])},m=()=>{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||d?e.jsx("div",{className:"flex items-center justify-center py-8",children:e.jsx(s.LoaderCircle,{className:"h-6 w-6 animate-spin"})}):e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-2 pb-2 border-b",children:[e.jsx(s.Checkbox,{checked:n.length===u.length&&u.length>0,onCheckedChange:m}),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:()=>x(h.value),children:[e.jsx(s.Checkbox,{checked:n.includes(h.value),onCheckedChange:()=>x(h.value)}),e.jsx(es,{className:"text-sm",children:h.label})]},h.id))})]})]})}function tr({field:t,zone:n,index:a,sortDirection:r,onSortDirectionChange:l,hasPivotColumns:c=!1,cardType:i}){var rs,ls,os,is;const{attributes:o,listeners:d,setNodeRef:u,transform:x,transition:m,isDragging:h}=s.useSortable({id:t.id}),p=s.useEditorStore(G=>G.card),{updateLabel:b,handleAggregationChange:g,handleDateFormatChange:v,handleGranularityChange:S,handleAliasTemplateChange:k,handleValueAliasesChange:P,removeField:M,handleKpiComparisonTypeChange:T,handleKpiShowTrendlineChange:y,handleKpiTrendlineWindowChange:f,handleKpiTrendlineGranularityChange:j,handleKpiTargetValueChange:N}=Ye(p),[A,C]=w.useState(!1),[O,F]=w.useState(!1),[D,E]=w.useState(null),[L,I]=w.useState(t.dateFormat||"YYYY-MM-DD"),[B,z]=w.useState(t.customFormat||""),[K,U]=w.useState(!!t.customFormat),[R,_]=w.useState(t.granularity||"day"),[Z,ne]=w.useState(t.aliasTemplate||""),[te,J]=w.useState(t.valueAliases||{}),[H,$]=w.useState((rs=t.parameters)==null?void 0:rs.filters),ee=G=>{G==="custom"?U(!0):(U(!1),I(G),n==="groupBy"&&v(a,G,""))},X=G=>{z(G),n==="groupBy"&&v(a,"custom",G)},ue=G=>{var xe;_(G);const ce=(xe=s.getDateFormatOptionsForGranularity(G)[0])==null?void 0:xe.value;ce&&!K&&(I(ce),n==="groupBy"&&v(a,ce,"")),n==="groupBy"&&S(a,G)},me=G=>{ne(G),n==="metrics"&&k(a,G)},ae=G=>{J(G),n==="metrics"&&P(a,G)},q=G=>{b(n,a,G)},Q=G=>{var ie;if($(G),n==="metrics"){const ce={...t,parameters:{...t.parameters,filters:G}},xe=[...((ie=p.config)==null?void 0:ie.metricColumns)||[]];xe[a]=ce,s.useEditorStore.getState().actions.updateCardConfig(p.id,{metricColumns:xe})}F(!1)},le=()=>{M(n,a)},pe={transform:s.CSS.Transform.toString(x),transition:m},fe=s.getDataType(t.dataType),de=fe==="date",V=i==="kpi",se=s.getDateFormatOptionsForGranularity(R),Y=n!=="pivotBy",je=de&&n==="groupBy"&&(!V||((ls=p.config)==null?void 0:ls.comparisonType)==="start_vs_end"),ge=!V&&de&&n==="groupBy",be=i&&s.COMPARISON_SUPPORTED_CHART_TYPES.includes(i)&&de&&n==="groupBy",ve=i==="kpi"&&de&&n==="groupBy",he=i&&i!=="pivotTable"&&n==="metrics"&&((os=p.config)==null?void 0:os.comparisonType)==="target",Ee=n==="metrics",Se=()=>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}`}),we=()=>Y?e.jsxs("div",{className:"space-y-1",children:[e.jsx(s.Label,{className:"text-xs font-medium text-muted-foreground",children:"Label"}),e.jsx(Ne,{value:t.label??"",onSave:q,placeholder:"Display label...",type:"text"})]}):null,W=()=>je?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:R,onValueChange:ue,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,re=()=>ge?e.jsxs(e.Fragment,{children:[W(),e.jsxs("div",{className:"space-y-1",children:[e.jsx(s.Label,{className:"text-xs font-medium text-muted-foreground",children:"Date Format"}),e.jsxs(s.Select,{value:K?"custom":L,onValueChange:ee,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:se.map(G=>e.jsx(s.SelectItem,{className:"text-xs",value:G.value,children:G.label},G.value))})]}),K&&e.jsxs("div",{className:"mt-2 space-y-1",children:[e.jsx(s.Input$1,{placeholder:"Enter custom format (e.g., YYYY-MM-DD HH:mm)",value:B,onChange:G=>{G.stopPropagation(),X(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,oe=()=>{var ce,xe,Ce,Me,cs;const G=be,ie=ve;return!G&&!ie?null:e.jsxs(e.Fragment,{children:[G&&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:((ce=p.config)==null?void 0:ce.comparisonType)||"none",onValueChange:T,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"})]})]})]}),ie&&e.jsxs(e.Fragment,{children:[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:((xe=p.config)==null?void 0:xe.showTrendline)||!1,onCheckedChange:y})]})}),((Ce=p.config)==null?void 0:Ce.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:((Me=p.config)==null?void 0:Me.trendlineWindow)||30,onChange:ut=>{const mt=parseInt(ut.target.value)||30;f(mt)},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:((cs=p.config)==null?void 0:cs.trendlineGranularity)||"day",onValueChange:j,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"})]})]})]})]})]})]})},De=()=>{var G,ie;return he?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(Ne,{value:((G=p.config)==null?void 0:G.targetValue)!==void 0&&((ie=p.config)==null?void 0:ie.targetValue)!==null?String(p.config.targetValue):"",onSave:ce=>{!isNaN(Number(ce))&&ce!==null?N(Number(ce)):N(0)},placeholder:"Enter target value...",type:"text"})]}):null},it=()=>Ee?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=>{g(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:()=>{E(G),F(!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((ie,ce)=>e.jsx("div",{children:String(ie)},ce))})]})})]})}),e.jsx(s.Button,{variant:"ghost",size:"sm",className:"ml-auto h-4 w-4 p-0",onClick:ie=>{var xe;ie.stopPropagation();const ce=H.conditions.filter(Ce=>Ce.id!==G.id);if(ce.length>0){const Ce={...H,conditions:ce};Q(Ce)}else if($(void 0),n==="metrics"){const Ce={...t,parameters:{...t.parameters,filters:void 0}},Me=[...((xe=p.config)==null?void 0:xe.metricColumns)||[]];Me[a]=Ce,s.useEditorStore.getState().actions.updateCardConfig(p.id,{metricColumns:Me})}},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:()=>{E(null),F(!0)},children:[e.jsx(s.Filter,{className:"mr-2 h-3 w-3"}),"Add attribute filter"]})]}),e.jsx(Xn,{column:t}),c&&e.jsxs(e.Fragment,{children:[e.jsx(Wn,{aliasTemplate:Z,onAliasTemplateChange:me}),e.jsx(Yn,{valueAliases:te,onValueAliasesChange:ae})]})]}):null,{columns:ct=[]}=s.useColumns(),dt=(H==null?void 0:H.conditions)&&H.conditions.length>0;return e.jsxs(e.Fragment,{children:[e.jsxs("div",{ref:u,style:pe,...o,...d,className:`group mx-auto flex w-full flex-col gap-2 rounded border border-border bg-background p-2 transition-all hover:shadow-sm dark:border-gray-800 ${h?"z-50 scale-95 opacity-50":"border-slate-200"} ${n==="filters"?"cursor-default":"cursor-move"}`,children:[e.jsxs("div",{className:"flex grow items-center gap-2",children:[e.jsx(as,{dataType:fe}),e.jsx(es,{className:s.cn("w-[140px] flex-1 text-sm",dt&&"w-[120px]"),children:s.getMetricDisplayLabel(t)}),n==="metrics"&&((is=H==null?void 0:H.conditions)==null?void 0:is.length)&&!A&&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(),C(!A)},children:e.jsx(s.ChevronDown,{className:`h-3 w-3 transition-transform ${A?"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 ie=r==="asc"?"desc":"asc";console.log("DraggableField - New direction to set:",ie),l(ie)},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(),le()},children:e.jsx(s.X,{className:"h-2.5 w-2.5"})})]}),A&&e.jsxs("div",{className:"space-y-3",children:[Se(),we(),i==="kpi"&&W(),re(),oe(),De(),it()]})]}),O&&e.jsx(er,{open:O,onOpenChange:G=>{F(G),G||E(null)},availableFields:ct,existingFilters:H,editingCondition:D,onSave:G=>{var ie;if(G)Q(G);else if($(void 0),n==="metrics"){const ce={...t,parameters:{...t.parameters,filters:void 0}},xe=[...((ie=p.config)==null?void 0:ie.metricColumns)||[]];xe[a]=ce,s.useEditorStore.getState().actions.updateCardConfig(p.id,{metricColumns:xe})}E(null)}})]})}function ar({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 Be({zone:t,fields:n,label:a,placeholder:r,shouldShow:l,hasPivotColumns:c=!1,activeField:i=null}){const{isOver:o,setNodeRef:d}=s.useDroppable({id:t}),{updateSortByColumn:u}=s.useEditorActions(),x=s.useEditorStore(v=>v.card),m=s.useEditorStore(v=>v.card.type),h=n.length>0,p=w.useMemo(()=>!i||!o?!0:Le(i,t,m).isValid,[i,o,t,m]),b=(v,S)=>{var P;!((P=x.config)!=null&&P.sortByColumns)||x.config.sortByColumns.findIndex(M=>M.id===v)===-1||u(x.id,v,{direction:S})};if(t==="sortBy"&&l===!1)return null;const g=t!=="sortBy"&&m!=="kpi";return e.jsxs("div",{className:"mb-4 w-full",children:[e.jsxs("div",{className:"mb-2 flex items-center gap-2",children:[e.jsx(s.Label,{className:s.cn("block text-sm font-medium",{}),children:a}),g&&e.jsx(ar,{concept:t})]}),e.jsx("div",{ref:d,className:s.cn("rounded-lg border-2 border-dotted p-0.5 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-muted-foreground/30 bg-muted/40":!o&&h,"min-h-[60px] border-muted-foreground/20 bg-background":!o&&!h}),children:n.length===0?e.jsx("div",{className:"flex min-h-[60px] items-center justify-center text-sm text-muted-foreground/60",children:r}):e.jsx(s.SortableContext,{items:n.map(v=>v.id),strategy:s.verticalListSortingStrategy,children:e.jsx("div",{className:"flex flex-wrap gap-1",children:n.map((v,S)=>{const P=v.direction;return e.jsx("div",{className:"flex w-full items-center gap-2",children:e.jsx("div",{className:"flex-1",children:e.jsx(tr,{field:v,zone:t,index:S,sortDirection:P,onSortDirectionChange:M=>b(v.id,M),hasPivotColumns:c,cardType:m})})},v.id)})})})})]})}const Ns=[{value:"green",color:"#16a34a",label:"Green"},{value:"red",color:"#dc2626",label:"Red"},{value:"neutral",color:"#6b7280",label:"Neutral"}],nr=["#16a34a","#dc2626","#6b7280","#2563eb","#ca8a04","#7c3aed","#0891b2","#e11d48","#ea580c"];function Ge({value:t,onChange:n,label:a}){const[r,l]=w.useState(!1),[c,i]=w.useState(!1),o=()=>{const d=Ns.find(u=>u.value===t);return d?d.color:t.startsWith("#")?t:Ns[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:nr.map(d=>e.jsx("button",{className:s.cn("h-5 w-5 rounded border-2 transition-all",o()===d?"border-gray-900":"border-transparent"),style:{backgroundColor:d},onClick:()=>{n(d),l(!1)},children:e.jsx("span",{className:"sr-only",children:d})},d))}),e.jsx("button",{className:"w-full rounded border border-input px-2 py-1 text-xs hover:bg-muted",onClick:()=>{i(!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:()=>i(!1)}),e.jsx("div",{className:"relative rounded-lg bg-white shadow-lg",children:e.jsx(et,{color:o(),onColorChange:d=>{n(d),i(!1)},onClose:()=>i(!1)})})]})]})}const Cs={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%
|
|
235
235
|
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 rr(){var h,p,b,g,v,S,k,P,M,T,y;const t=s.useEditorStore(f=>f.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=((g=(b=t.preferences)==null?void 0:b.kpiVisualOptions)==null?void 0:g.metricComparison)||{},d=f=>{var N;const j={...t.preferences,kpiVisualOptions:{...(N=t.preferences)==null?void 0:N.kpiVisualOptions,metricComparison:{...o,...f}}};n(j)},u=c||o.enabled,x=((v=t.config)==null?void 0:v.comparisonType)||"none",m=x==="previous_period"||x==="same_period_last_year"||x==="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(Dt,{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:f=>d({enabled:f,...f&&!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 f=o.calculationType||"difference",j=Cs[f];return e.jsxs("div",{className:"space-y-2 text-xs",children:[e.jsx("div",{className:"text-sm font-semibold",children:j==null?void 0:j.label}),e.jsx("p",{children:j==null?void 0:j.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:j==null?void 0:j.formula})]}),e.jsxs("div",{className:"border-t pt-1.5 italic",children:[e.jsx("span",{className:"font-medium",children:"Example:"})," ",j==null?void 0:j.example]})]})})()})]})]}),e.jsxs(s.Select,{value:o.calculationType||"difference",onValueChange:f=>d({calculationType:f}),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(Cs).map(([f,j])=>e.jsx(s.SelectItem,{value:f,className:"text-xs",children:j.label},f))})]})]}),e.jsx(ss,{formatOptions:o.formatOptions||{},onFormatOptionsChange:f=>d({formatOptions:f}),showTitle:!0,title:"COMPARISON FORMAT"}),(m||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:f=>d({position:f}),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:f=>d({showArrow:f})}),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:f=>d({showColor:f})}),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(Ge,{value:((S=o.colorConfig)==null?void 0:S.increase)||"green",onChange:f=>d({colorConfig:{...o.colorConfig,increase:f}}),label:"Primary > Secondary"}),e.jsx(Ge,{value:((k=o.colorConfig)==null?void 0:k.decrease)||"red",onChange:f=>d({colorConfig:{...o.colorConfig,decrease:f}}),label:"Primary < Secondary"}),e.jsx(Ge,{value:((P=o.colorConfig)==null?void 0:P.noChange)||"neutral",onChange:f=>d({colorConfig:{...o.colorConfig,noChange:f}}),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:f=>d({conditionalLabel:f})}),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:((M=o.conditionalLabels)==null?void 0:M.increase)??"Increase",onChange:f=>d({conditionalLabels:{...o.conditionalLabels,increase:f.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:((T=o.conditionalLabels)==null?void 0:T.decrease)??"Decrease",onChange:f=>d({conditionalLabels:{...o.conditionalLabels,decrease:f.target.value}}),placeholder:"Decrease",className:"h-7 text-xs"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(s.Label,{htmlFor:"label-no-change",className:"text-xs text-muted-foreground",children:"Primary = Secondary"}),e.jsx(s.Input,{id:"label-no-change",type:"text",value:((y=o.conditionalLabels)==null?void 0:y.noChange)??"No change",onChange:f=>d({conditionalLabels:{...o.conditionalLabels,noChange:f.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:f=>d({labelName:f.target.value}),placeholder:"e.g. Previous, Last Period",className:"h-7 text-xs"})]})]})]})]})]})}function lr(){var l,c;const t=s.useEditorStore(i=>i.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=i=>{var d;const o={...t.preferences,kpiVisualOptions:{...(d=t.preferences)==null?void 0:d.kpiVisualOptions,formatOptions:i}};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(s.Hash,{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(ss,{formatOptions:a,onFormatOptionsChange:r,showTitle:!1})})]})}function or({groupByFields:t,pivotByFields:n,metricsFields:a,sortByFields:r,activeField:l}){const c=s.useEditorStore(v=>{var S;return((S=v.card.customCardPreferences)==null?void 0:S.url)&&v.card.type==="custom"}),i=s.useEditorStore(v=>v.card),o=i==null?void 0:i.type,d=t.length>0||a.length>0,u=o!=="kpi"||a.length<=2,x=o!=="kpi",m=o!=="kpi"&&d,h=["pie","doughnut","polar","funnel","aggregateTable"].includes(o),p=x&&!h,b=()=>o==="kpi"?{label:"Trend By",placeholder:"Drop fields to trend data"}:{label:"Rows",placeholder:"Drop fields to group data"},g=()=>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(Be,{zone:"groupBy",fields:t,label:b().label,placeholder:b().placeholder,activeField:l}),p&&e.jsx(Be,{zone:"pivotBy",fields:n,label:"Columns",placeholder:"Drop fields to pivot data",activeField:l}),e.jsx(Be,{zone:"metrics",fields:a,label:g().label,placeholder:g().placeholder,hasPivotColumns:n.length>0,activeField:l}),m&&e.jsx(Be,{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(lr,{}),e.jsx(rr,{}),e.jsx(st,{}),e.jsx(tt,{}),e.jsx(at,{}),e.jsx(nt,{})]})})]})]})}function ir({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(d=>{var h,p,b,g;const u=`${(h=d.source)==null?void 0:h.entityName}.${(p=d.source)==null?void 0:p.name}`,x=`${(b=d.target)==null?void 0:b.entityName}.${(g=d.target)==null?void 0:g.name}`,m=d.operator||"=";return`${u} ${m} ${x}`}).join(" AND "),i=o=>!o.joinKeyGroups||o.joinKeyGroups.length===0?"No conditions defined":o.joinKeyGroups.length===1?c(o.joinKeyGroups[0].keys):o.joinKeyGroups.map((d,u)=>({id:u,operator:d.operator,condition:c(d.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(_t,{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,d)=>{const u=i(o),x=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:x?u.map(m=>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:m.condition}),m.operator&&e.jsxs("span",{className:"ml-2 text-xs text-muted-foreground",children:["(",m.operator,")"]})]},m.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||d)})})})]})})]}),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 Ss={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 cr({selectedChart:t,onChartChange:n,groupByFields:a,pivotByFields:r,metricsFields:l,sortByFields:c,activeField:i}){var f,j;const[o,d]=w.useState(()=>Ss.getItem("chart-selector-expanded")==="true"),[u,x]=w.useState(!1),m=s.useEditorStore(N=>N.card),h=s.useEditorStore(N=>N.actions.updateCardConfig),p=a.length>0||r.length>0||l.length>0,{data:b,autoJoinMetadata:g}=s.useDashboardCardQuery(m),v=((f=m==null?void 0:m.config)==null?void 0:f.joinPlan)||(g!=null&&g.autoResolved?g.resolvedJoinPlan:{baseEntity:{type:"table",name:"",database:"",schema:"",connectionId:"",connectionType:"none",dialect:"none"},joins:[]}),S=((j=m==null?void 0:m.dataSource)==null?void 0:j.selectedEntities)||[],k=N=>{h(m.id,{...m==null?void 0:m.config,joinPlan:N}),x(!1)},P=()=>{h(m.id,{...m==null?void 0:m.config,joinPlan:void 0}),x(!1)},M=()=>{x(!1)},T=()=>{x(!0)};w.useEffect(()=>{Ss.setItem("chart-selector-expanded",String(o))},[o]);const y=()=>{d(N=>!N)};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(_n,{selectedChart:t,onChartChange:n})}),e.jsxs("div",{"data-content":"Chart Quick Selector",className:"flex items-center justify-center gap-1",children:[e.jsx(Qn,{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:y,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(Qe,{})})}),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(ir,{onEditJoins:T}),e.jsx(or,{groupByFields:a,pivotByFields:r,metricsFields:l,sortByFields:c,activeField:i})]}),e.jsx(s.ScrollBar,{orientation:"horizontal"})]}),e.jsx(He,{open:u,onOpenChange:x,joinPlan:v,availableDataSources:S,onSave:k,onCancel:M,onRemove:P,children:e.jsx("div",{})})]})}function dr({initialFilters:t,availableFields:n}={}){const[a,r]=w.useState(t||{id:`group-${Date.now()}`,logicalOperator:"AND",negate:!1,conditions:[],groups:[]});s.useEditorStore(T=>T.card.dataSource);const{columns:l,isLoading:c}=s.useColumns(),o=n||l||[],d={id:"default",qualifiedFieldName:"default",name:"default",dataType:"string",label:"Default",entityId:"default",entityName:"Default",entityType:"table"},u=T=>{const y=f=>{if(f.id===T){const j=o[0]||d,N=s.getDataType(j.dataType)==="date";return{...f,conditions:[...f.conditions,{id:`condition-${Date.now()}`,field:j,operator:N?"between":"=",value:N?[]:""}]}}return{...f,groups:f.groups.map(y)}};r(y(a))},x=T=>{const y=f=>{if(f.id===T){const j=o[0]||d,N=s.getDataType(j.dataType)==="date";return{...f,groups:[...f.groups,{id:`group-${Date.now()}`,logicalOperator:"AND",negate:!1,conditions:[{id:`condition-${Date.now()}`,field:j,operator:N?"between":"=",value:N?[]:""}],groups:[]}]}}return{...f,groups:f.groups.map(y)}};r(y(a))},m=(T,y)=>{const f=j=>j.id===T?{...j,conditions:j.conditions.filter(N=>N.id!==y)}:{...j,groups:j.groups.map(f)};r(f(a))},h=(T,y)=>{const f=j=>j.id===T?{...j,groups:j.groups.filter(N=>N.id!==y)}:{...j,groups:j.groups.map(f)};r(f(a))},p=(T,y,f,j)=>{if(f==="field")throw new Error("Use a dedicated method to update the field property with a Field object");const N=A=>A.id===T?{...A,conditions:A.conditions.map(C=>C.id===y?{...C,[f]:j}:C)}:{...A,groups:A.groups.map(N)};r(N(a))},b=(T,y,f)=>{const j=N=>N.id===T?{...N,conditions:N.conditions.map(A=>A.id===y?{...A,...f}:A)}:{...N,groups:N.groups.map(j)};r(j(a))},g=(T,y)=>{const f=j=>j.id===T?{...j,logicalOperator:y}:{...j,groups:j.groups.map(f)};r(f(a))},v=(T,y)=>{const f=j=>j.id===T?{...j,negate:y}:{...j,groups:j.groups.map(f)};r(f(a))},S=(T,y,f)=>{const j=N=>N.id===T?{...N,conditions:s.arrayMove(N.conditions,y,f)}:{...N,groups:N.groups.map(j)};r(j(a))},k=(T,y,f)=>{const j=N=>N.id===T?{...N,groups:s.arrayMove(N.groups,y,f)}:{...N,groups:N.groups.map(j)};r(j(a))},P=T=>{if(!T||T.conditions.length===0&&T.groups.length===0)return"-- No filters defined";const y=j=>{let N="";typeof j.field=="object"?N=j.field.entityName?`${j.field.entityName}.${j.field.name}`:j.field.name:N=String(j.field);const A=j.operator;let C=j.value;if(j.field.dataType==="string"&&!["in","not in"].includes(j.operator))typeof C=="string"?C=`'${C}'`:Array.isArray(C)&&(C=`'${C.join(", ")}'`);else if(j.field.dataType==="date"||j.field.dataType==="datetime"||j.field.dataType==="timestamp")if(j.operator==="between"&&Array.isArray(C)&&C.length===2){const O=C[0]?`'${C[0]}'`:"NULL",F=C[1]?`'${C[1]}'`:"NULL";return`${N} BETWEEN ${O} AND ${F}`}else if((j.operator==="in"||j.operator==="not in")&&Array.isArray(C)){const O=C.map(F=>F?`'${F}'`:"NULL").join(", ");return`${N} ${A} (${O})`}else typeof C=="string"||C instanceof Date?C=`'${C}'`:Array.isArray(C)&&C.length>0&&(C=`'${C[0]}'`);else if(["in","not in"].includes(j.operator)){let O=[];Array.isArray(C)?O=C.map(F=>typeof F=="string"?`'${F}'`:String(F)):typeof C=="string"?O=C.split(",").map(F=>{const D=F.trim();return j.field.dataType==="string"?`'${D}'`:D}):typeof C=="number"&&(O=[String(C)]),C=`(${O.join(", ")})`}switch(A){case"contains":return typeof C=="string"?`${N} LIKE '%${C.replace(/'/g,"")}'`:`${N} LIKE '%${String(C)}'`;case"startsWith":return typeof C=="string"?`${N} LIKE '${C.replace(/'/g,"")}%'`:`${N} LIKE '${String(C)}%'`;case"endsWith":return typeof C=="string"?`${N} LIKE '%${C.replace(/'/g,"")}'`:`${N} LIKE '%${String(C)}'`;case"isNull":return`${N} IS NULL`;case"isNotNull":return`${N} IS NOT NULL`;default:return`${N} ${A} ${C}`}},f=j=>{const N=j.conditions.map(y),A=j.groups.map(D=>f(D)),C=[...N,...A].filter(Boolean);if(C.length===0)return"";const O=C.join(` ${j.logicalOperator} `),F=C.length>1?`(${O})`:O;return j.negate?`NOT ${F}`:F};return f(T)},M=a.conditions.length>0||a.groups.length>0;return{currentFilters:a,setCurrentFilters:r,availableFields:o,isLoading:c,addCondition:u,addGroup:x,removeCondition:m,removeGroup:h,updateCondition:p,updateConditionFields:b,updateGroupOperator:g,updateGroupNegate:v,reorderConditions:S,reorderGroups:k,generateSQLPreview:P,hasAnyFilters:M}}function ur({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 mr=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"})}},hr=t=>{if(t.qualifiedEntityName){const n=t.qualifiedEntityName.split(".");return n.length>1?n[0]:"default"}return"default"};function xr({value:t,onValueChange:n,availableFields:a,placeholder:r="Select field",className:l="w-64"}){const[c,i]=w.useState(!1),o=w.useMemo(()=>{const d={};return a.forEach(u=>{const x=hr(u);d[x]||(d[x]={}),d[x][u.entityId]||(d[x][u.entityId]=[]),d[x][u.entityId].push(u)}),d},[a]);return e.jsxs(s.Popover,{modal:!0,open:c,onOpenChange:i,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(ur,{children:[t.entityName,".",t.name]})}):r,e.jsx(gt,{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(([d,u])=>e.jsx(s.CommandGroup,{heading:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(s.Database,{className:"h-3 w-3"}),d]}),children:Object.entries(u).map(([x,m])=>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:[mr(m[0].entityType),e.jsx("span",{children:m[0].entityName})]}),m.map((h,p)=>e.jsxs(s.CommandItem,{value:h.id,onSelect:()=>{n(h),i(!1)},className:"overflow-x-auto",children:[e.jsx(s.Check,{className:s.cn("mr-2 h-4 w-4",(t==null?void 0:t.id)===h.id?"opacity-100":"opacity-0")}),e.jsxs("div",{className:"flex min-w-0 flex-1 flex-col",children:[e.jsx("div",{className:"flex items-center gap-2",children:e.jsx("span",{className:"",children:h.name})}),e.jsx("div",{className:"flex items-center gap-2 text-xs text-gray-500",children:h.description&&e.jsx("span",{children:h.description})})]})]},h.id+p))]},`${d}-${x}`))},d))})]})})]})}function ns(t){var g;const n=s.useEditorStore(v=>v.card),{authToken:a,tokenProps:r}=s.useSemaphorContext(),l=s.useEditorStore(v=>v.card.config),c=l==null?void 0:l.joinPlan,i={...t,alias:t.name,label:"value",role:"groupby"},o={...t,role:"metric",label:"count",alias:"count",aggregate:"COUNT"},d={...i,role:"sortby",direction:"asc"},u={joinPlan:c,groupByColumns:[i],metricColumns:[o],sortByColumns:[d]},x=((g=n.dataSource)==null?void 0:g.connectionId)||n.connectionId,{data:m,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:x,cardConfig:u,cardDataSource:n.dataSource})}catch(v){console.log(t),console.error("error",v)}},enabled:!!x,refetchOnMount:!0,refetchOnWindowFocus:!1});return{filterValues:((m==null?void 0:m.records)||[]).map(v=>({label:v.value||"BLANK",value:v.value||"BLANK",count:(v==null?void 0:v.count)||0})),isPending:h,error:p}}function pr({field:t,selected:n,onChange:a,placeholder:r="Select items...",className:l}){const[c,i]=Ue.useState(!1),{filterValues:o}=ns(t),d=x=>{a(n.filter(m=>m!==x))},u=x=>{n.includes(x)?a(n.filter(m=>m!==x)):a([...n,x])};return e.jsx("div",{className:s.cn("w-full",l),children:e.jsxs(s.Popover,{open:c,onOpenChange:i,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(x=>{const m=o.find(h=>h.value===x);return e.jsxs(s.Badge,{variant:"secondary",className:"text-xs",children:[m==null?void 0:m.label,e.jsx("div",{className:"ml-1 rounded-full outline-none ring-offset-background focus:ring-2 focus:ring-ring focus:ring-offset-2",onKeyDown:h=>{h.key==="Enter"&&d(x)},onMouseDown:h=>{h.preventDefault(),h.stopPropagation()},onClick:h=>{h.stopPropagation(),d(x)},children:e.jsx(s.X,{className:"h-3 w-3 text-muted-foreground hover:text-foreground"})})]},x)}):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((x,m)=>e.jsxs(s.CommandItem,{onSelect:()=>u(x.value),children:[e.jsx(s.Check,{className:s.cn("mr-2 h-4 w-4",n.includes(x.value)?"opacity-100":"opacity-0")}),e.jsxs("div",{className:"flex grow items-center justify-between gap-4",children:[e.jsx("span",{children:x.label}),e.jsx("span",{className:"text-xs text-muted-foreground",children:x.count})]})]},x.value+m))})]})]})})]})})}function fr({field:t,value:n,onChange:a,placeholder:r="Select value...",className:l}){const{filterValues:c,isPending:i,error:o}=ns(t);return i?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((d,u)=>e.jsx(s.SelectItem,{className:"hover:bg-muted",value:d.value,children:d.label},d.value+u))})]})}function gr({value:t,operator:n,onChange:a,className:r}){var d;const{tokenProps:l}=s.useSemaphorContext(),c=(d=l==null?void 0:l.params)==null?void 0:d.timeZone,i=w.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,x=t[1]?new Date(t[1]):void 0;if(u&&x)return{from:u,to:x}}}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]),x=t.length>1?new Date(t[t.length-1]):u;if(!isNaN(u.getTime()))return{from:u,to:x}}}},[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 x=new Date(u.from);x.setHours(23,59,59,999),a([u.from.toISOString(),x.toISOString()])}else if(u.to){const x=new Date(u.to);x.setHours(0,0,0,0),a([x.toISOString(),u.to.toISOString()])}};return e.jsx(s.DateRangePicker,{value:i,onChange:o,timezone:c,showRelativeTab:!0,className:r,placeholder:"Select date..."})}const jr=["=","!=",">",">=","<","<=","contains","startsWith","endsWith","in","not in","isNull","isNotNull"],br=["=","!=","contains","startsWith","endsWith","in","not in","isNull","isNotNull"],vr=["=","!=",">",">=","<","<=","in","not in","isNull","isNotNull"],yr=["=","!=","isNull","isNotNull"],Nr=["between","isNull","isNotNull"],Cr={"=":"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 ws(t){return Cr[t]||s.titleCase(t)}function Sr(t){switch(t){case"string":return br;case"number":return vr;case"boolean":return yr;case"date":return Nr;default:return jr}}function rt({condition:t,index:n,groupId:a,groupLogicalOperator:r,onUpdateCondition:l,onRemoveCondition:c,onUpdateGroupOperator:i,availableFields:o,updateConditionFields:d}){const{attributes:u,listeners:x,setNodeRef:m,transform:h,transition:p,isDragging:b}=s.useSortable({id:t.id}),{isPending:g,error:v}=ns(t.field),S={transform:s.CSS.Transform.toString(h),transition:p};return e.jsxs("div",{ref:m,style:S,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,...x,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:k=>i(a,k),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(xr,{value:t.field,onValueChange:k=>{const P=k,M=s.getDataType(P.dataType)==="date";d(a,t.id,{field:P,value:"",operator:M?"between":"="})},availableFields:o,placeholder:"Select field",className:"w-64"}),e.jsxs(s.Select,{value:t.operator,onValueChange:k=>{k==="in"||k==="not in"?d(a,t.id,{operator:k,value:[]}):k==="isNull"||k==="isNotNull"?d(a,t.id,{operator:k,value:null}):d(a,t.id,{operator:k,value:""})},children:[e.jsx(s.SelectTrigger,{className:"w-32",children:e.jsx(s.SelectValue,{children:t.operator?ws(t.operator):""})}),e.jsx(s.SelectContent,{children:Sr(s.getDataType(t.field.dataType)).map(k=>e.jsx(s.SelectItem,{className:"hover:bg-muted",value:k,children:ws(k)},k))})]}),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"?g?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..."]}):v?e.jsx("div",{className:"flex-1 p-2 text-xs text-red-500",children:"Error loading values"}):e.jsx(pr,{field:t.field,selected:Array.isArray(t.value)&&t.value.every(k=>typeof k=="string")?t.value:[],onChange:k=>d(a,t.id,{value:k}),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:k=>d(a,t.id,{value:k.target.value}),className:"flex-1",placeholder:t.operator.charAt(0).toUpperCase()+t.operator.slice(1)+"..."}):e.jsx(fr,{field:t.field,value:typeof t.value=="string"?t.value:"",onChange:k=>d(a,t.id,{value:k}),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:k=>d(a,t.id,{value:k==="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(gr,{value:t.value,operator:t.operator,onChange:k=>d(a,t.id,{value:k}),className:"flex-1"}):e.jsx(s.Input$1,{value:typeof t.value=="string"||typeof t.value=="number"?t.value:"",onChange:k=>l(a,t.id,"value",k.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 wr({group:t,depth:n,parentGroupId:a,onUpdateGroupOperator:r,onUpdateGroupNegate:l,onRemoveGroup:c,onUpdateCondition:i,onUpdateField:o,onRemoveCondition:d,onReorderConditions:u,onReorderGroups:x,onAddCondition:m,onAddGroup:h,availableFields:p,renderFilterGroup:b,updateConditionFields:g}){const{attributes:v,listeners:S,setNodeRef:k,transform:P,transition:M,isDragging:T}=s.useSortable({id:t.id}),y={transform:s.CSS.Transform.toString(P),transition:M},f=N=>{const{active:A,over:C}=N;if(C&&A.id!==C.id){const O=t.conditions.findIndex(D=>D.id===A.id),F=t.conditions.findIndex(D=>D.id===C.id);O!==-1&&F!==-1&&u(t.id,O,F)}},j=N=>{const{active:A,over:C}=N;if(C&&A.id!==C.id&&a){const O=t.groups.findIndex(D=>D.id===A.id),F=t.groups.findIndex(D=>D.id===C.id);O!==-1&&F!==-1&&x(a,O,F)}};return e.jsxs("div",{ref:k,style:y,className:`rounded-lg ${n>0?"mt-2 border border-border":""} ${T?"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",{...v,...S,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:N=>r(t.id,N),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:f,children:e.jsx(s.SortableContext,{items:t.conditions.map(N=>N.id),strategy:s.verticalListSortingStrategy,children:t.conditions.map((N,A)=>e.jsx(rt,{condition:N,index:A,groupId:t.id,groupLogicalOperator:t.logicalOperator,onUpdateCondition:i,onUpdateField:o,onRemoveCondition:d,onUpdateGroupOperator:r,availableFields:p,updateConditionFields:g},N.id))})}),e.jsx(s.DndContext,{sensors:s.useSensors(s.useSensor(s.PointerSensor),s.useSensor(s.KeyboardSensor,{coordinateGetter:s.sortableKeyboardCoordinates})),collisionDetection:s.closestCenter,onDragEnd:j,children:e.jsx(s.SortableContext,{items:t.groups.map(N=>N.id),strategy:s.verticalListSortingStrategy,children:t.groups.map(N=>b(N,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:()=>m(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 Dr({filters:t,availableFields:n,onSave:a,onClearAll:r,onCancel:l}){const{currentFilters:c,availableFields:i,isLoading:o,addCondition:d,addGroup:u,removeCondition:x,removeGroup:m,updateCondition:h,updateConditionFields:p,updateGroupOperator:b,updateGroupNegate:g,reorderConditions:v,reorderGroups:S,generateSQLPreview:k,hasAnyFilters:P,setCurrentFilters:M}=dr({initialFilters:t,availableFields:n}),T=s.useSensors(s.useSensor(s.PointerSensor),s.useSensor(s.KeyboardSensor,{coordinateGetter:s.sortableKeyboardCoordinates})),[y,f]=w.useState(!1),j=(C,O,F)=>{const D=E=>E.id===C?{...E,conditions:E.conditions.map(L=>L.id===O?{...L,field:F,dataType:F.dataType}:L)}:{...E,groups:E.groups.map(D)};M(D(c))},N=(C,O=0,F)=>O===0?e.jsx("div",{className:"rounded-lg",children:e.jsxs("div",{className:"p-3 px-0",children:[e.jsx(s.DndContext,{sensors:T,collisionDetection:s.closestCenter,onDragEnd:D=>{const{active:E,over:L}=D;if(L&&E.id!==L.id){const I=C.conditions.findIndex(z=>z.id===E.id),B=C.conditions.findIndex(z=>z.id===L.id);I!==-1&&B!==-1&&v(C.id,I,B)}},children:e.jsx(s.SortableContext,{items:C.conditions.map(D=>D.id),strategy:s.verticalListSortingStrategy,children:C.conditions.map((D,E)=>e.jsx(rt,{condition:D,index:E,groupId:C.id,groupLogicalOperator:C.logicalOperator,onUpdateCondition:h,onUpdateField:j,onRemoveCondition:x,onUpdateGroupOperator:b,availableFields:i,updateConditionFields:p},D.id))})}),e.jsx(s.DndContext,{sensors:T,collisionDetection:s.closestCenter,onDragEnd:D=>{const{active:E,over:L}=D;if(L&&E.id!==L.id){const I=C.groups.findIndex(z=>z.id===E.id),B=C.groups.findIndex(z=>z.id===L.id);I!==-1&&B!==-1&&S(C.id,I,B)}},children:e.jsx(s.SortableContext,{items:C.groups.map(D=>D.id),strategy:s.verticalListSortingStrategy,children:C.groups.map(D=>N(D,O+1,C.id))})}),e.jsxs("div",{className:"mt-3 flex items-center gap-2",children:[e.jsxs(s.Button,{size:"sm",className:"h-7 text-xs",variant:"outline",onClick:()=>d(C.id),children:[e.jsx(s.Plus,{className:"mr-1 h-3 w-3"}),"Add Condition"]}),y&&e.jsxs(s.Button,{variant:"outline",size:"sm",className:"h-7 text-xs",onClick:()=>u(C.id),children:[e.jsx(s.Plus,{className:"mr-1 h-3 w-3"}),"Add Group"]})]})]})},C.id):e.jsx(wr,{group:C,depth:O,parentGroupId:F,onUpdateGroupOperator:b,onUpdateGroupNegate:g,onRemoveGroup:m,onUpdateCondition:h,onUpdateField:j,onRemoveCondition:x,onReorderConditions:v,onReorderGroups:S,onAddCondition:d,onAddGroup:u,availableFields:i,renderFilterGroup:N,updateConditionFields:p},C.id),A=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..."})]}):N(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:y,onCheckedChange:C=>f(C)}),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)"})]})}),P&&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:k(c)})})]})]})})}),e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx(s.Button,{size:"sm",variant:"outline",onClick:l,children:"Cancel"}),A>0&&e.jsx(s.Button,{variant:"outline",size:"sm",onClick:r,children:"Clear All"}),e.jsx(s.Button,{size:"sm",onClick:()=>a(P?c:null),children:"Apply Filters"})]})]})}function kr({cardId:t,filters:n,onFiltersChange:a,onClearFilters:r,availableFields:l,isOpen:c,onOpenChange:i}){const o=u=>{a(t,u),i(!1)},d=()=>{r(t),i(!1)};return e.jsxs(s.Dialog,{modal:!1,open:c,onOpenChange:i,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(Dr,{filters:n,availableFields:l,onSave:o,onCancel:()=>i(!1),onClearAll:d})]})]})}function Tr({activeCardId:t,sourceFields:n,getFieldsForContainer:a,setFieldsForContainer:r}){var v,S;const[l,c]=w.useState(null),i=s.useEditorStore(k=>k.card),o=s.useEditorStore(k=>k.actions.updateCardConfig),d=(v=i==null?void 0:i.config)==null?void 0:v.joinPlan,u=(S=i==null?void 0:i.dataSource)==null?void 0:S.semanticDomainId,{data:x}=We(u),m=[...n,...a("groupBy"),...a("pivotBy"),...a("metrics"),...a("sortBy")],h=w.useCallback(k=>k.startsWith("card-")?null:k.startsWith("source-")||n.find(P=>P.id===k)?"source":a("groupBy").find(P=>P.id===k)?"groupBy":a("metrics").find(P=>P.id===k)?"metrics":a("pivotBy").find(P=>P.id===k)?"pivotBy":a("sortBy").find(P=>P.id===k)?"sortBy":null,[n,a]),p=w.useCallback(k=>{c(k.active.id)},[]),b=w.useCallback(k=>{var N;const{active:P,over:M}=k;if(!M||!t){c(null);return}const T=P.id,y=M.id,f=h(T),j=h(y)||y;if(j==="sortBy"){if(f==="source"){const A=n.find(O=>O.id===T);if(!A){c(null);return}if(!(a("groupBy").some(O=>O.name===A.name&&O.qualifiedEntityName===A.qualifiedEntityName)||a("metrics").some(O=>O.name===A.name&&O.qualifiedEntityName===A.qualifiedEntityName))){c(null);return}}else if(f==="pivotBy"){c(null);return}else if(f!=="groupBy"&&f!=="metrics"&&f!=="sortBy"){c(null);return}}if(f==="source"&&j==="sortBy"){const A=[...n].find(D=>D.id===T);if(!A){c(null);return}const C=a("sortBy");if(s.fieldAlreadyExists(A,C)){c(null);return}const O=Le(A,"sortBy",i.type);if(!O.isValid){s.ue.error("Invalid Field Type",{description:O.reason,position:"top-center",duration:3e3}),c(null);return}const F=s.getNewField(A,"sortBy",C);c(null),r("sortBy",[...C,F]);return}if(f==="source"&&j!=="source"&&j!=="sortBy"){const A=[...n].find(L=>L.id===T);if(!A){c(null);return}const C=[...a("groupBy"),...a("pivotBy"),...a("metrics"),...a("sortBy")];if(C.length>0){const L=C[0].qualifiedEntityName;if(!L){c(null);return}if(L!==A.qualifiedEntityName&&A.qualifiedEntityName)if(u&&(x!=null&&x.joinabilityMap)){if(s.calculateFieldState(A,{joinabilityMap:x.joinabilityMap,selectedFields:C,baseEntityName:(N=d==null?void 0:d.baseEntity)==null?void 0:N.name}).state==="unreachable"){s.showJoinRequiredNotification(),c(null);return}}else{if(!d){s.showJoinRequiredNotification(),c(null);return}if(!s.areEntitiesJoined(L,A.qualifiedEntityName,d)){s.showJoinRequiredNotification(),c(null);return}}}const O=a(j);if(s.fieldAlreadyExists(A,O)){c(null);return}const F=Le(A,j,i.type);if(!F.isValid){s.ue.error("Invalid Field Type",{description:F.reason,position:"top-center",duration:3e3}),c(null);return}const D=s.getNewField(A,j,O),E=[...O,D];c(null),r(j,E),j==="metrics"&&t&&_e(i.type,i.config,o,t,E);return}if(f&&j&&f!=="source"&&j!=="source"&&f!==j){const A=a(f),C=a(j),O=A.find(I=>I.id===T);if(!O){c(null);return}const F=Le(O,j,i.type);if(!F.isValid){s.ue.error("Invalid Field Type",{description:F.reason,position:"top-center",duration:3e3}),c(null);return}const D=s.getNewField(O,j,C);if(c(null),j==="sortBy"){s.fieldAlreadyExists(O,C)||r(j,[...C,D]);return}const E=A.filter(I=>I.id!==T),L=[...C,D];r(f,E),r(j,L),j==="metrics"&&t&&_e(i.type,i.config,o,t,L);return}if(f&&j&&f===j&&f!=="source"){const A=a(f),C=A.findIndex(F=>F.id===T),O=A.findIndex(F=>F.id===y);if(C!==O){const F=s.arrayMove(A,C,O);r(f,F)}}c(null)},[t,n,a,r,h,d,u,x,i.type,o,i.config]),g=l?m.find(k=>k.id===l):null;return{activeId:l,activeField:g,handleDragStart:p,handleDragEnd:b}}function Er({activeView:t,onViewChange:n}){const a=s.useEditorStore(i=>i.card),{config:r}=w.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:i=>n(i),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 Ir=[{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 Ar(){var d,u;const t=s.useEditorStore(x=>x.card),{updateRowLimit:n}=s.useEditorActions(),[a,r]=w.useState(!1),[l,c]=w.useState(""),i=x=>{if(x==="custom"){r(!0);return}r(!1),n(t.id,parseInt(x))},o=x=>{const m=x.target.value;c(m),m&&!isNaN(parseInt(m))&&n(t.id,parseInt(m))};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=(d=t.config)==null?void 0:d.rowLimit)==null?void 0:u.toString())||"100",onValueChange:i,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:Ir.map(x=>e.jsx(s.SelectItem,{value:x.value,children:x.label},x.value))})]})})}function Fr({isOpen:t,onClose:n}){const a=Is(n,{enabled:t}),r=s.useEditorStore(x=>{var m;return((m=x.card.customCardPreferences)==null?void 0:m.url)||""}),l=s.useEditorStore(x=>x.card),c=s.useEditorStore(x=>{var m;return((m=x.card.customCardPreferences)==null?void 0:m.pluginChartType)||""}),i=s.useEditorStore(x=>{var m;return((m=x.card.customCardPreferences)==null?void 0:m.settings)||{}}),{data:o}=s.useDashboardCardQuery(l),{getCard:d}=s.useCustomVisual(r),u=w.useMemo(()=>!r||r.trim()===""?null:d("Chart Settings"),[d,r]);return e.jsx("div",{ref:a,className:s.cn("absolute right-0 top-0 z-40 h-full w-[350px] border-l bg-background shadow-lg transition-transform duration-300",t?"translate-x-0":"translate-x-full"),style:{willChange:"transform"},tabIndex:t?0:-1,"aria-hidden":!t,children:e.jsxs("div",{className:"flex h-full flex-col p-4 px-5 pr-4",children:[e.jsxs("div",{className:"mb-4 flex items-center justify-between",children:[e.jsx("h2",{className:"text-base font-semibold",children:"Chart Settings"}),e.jsx(s.IconButton,{"aria-label":"Hide Chart Settings",tooltip:"Hide",onClick:n,className:"h-7 p-2 text-muted-foreground hover:text-foreground",children:e.jsx(s.X,{className:"size-3.5"})})]}),e.jsx("div",{className:"h-full min-h-0 flex-1",children:u&&e.jsx(w.Suspense,{fallback:e.jsx("div",{children:"Loading chart settings..."}),children:e.jsx(u,{chartData:(o==null?void 0:o.records)||[],chartType:c,settings:i})})})]})})}function Mr({activeView:t,onViewChange:n,showDebug:a,onDebugToggle:r,onFiltersClick:l,activeCard:c,columns:i,columnsLoading:o,columnsError:d}){var Z,ne,te;const u=s.useEditorStore(J=>J.card),x=s.useDashboardStore(J=>J.filterValues),{updateCardConfig:m,setCard:h,updateCardInFrame:p,setShowAIDialog:b}=s.useEditorActions(),g=s.useEditorStore(J=>J.showAIDialog),v=s.useDashboardStore(J=>J.isVisualEditing),[S,k]=w.useState(!1),[P,M]=w.useState(!1),[T,y]=w.useState(null),{config:f}=w.useContext(s.SemaphorContext).tokenProps,j=(f==null?void 0:f.showInfoTab)!==!1,N=s.useEditorStore(J=>{var H;return((H=J.card.customCardPreferences)==null?void 0:H.url)&&J.card.type==="custom"}),{data:A,errorMessage:C,isLoading:O,isFetching:F,errorSql:D,pagination:E,refetch:L,comparisonMetadata:I}=s.useDashboardCardQuery(c),[B,z]=w.useState(!1);w.useEffect(()=>{F||z(!1)},[F]);const K=(J,H)=>{const $={...c,paginationConfig:{page:J+1,pageSize:H}};h($),p($)};function U(){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(x||{},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 (",i.length,")"]}),e.jsx("pre",{className:"max-h-40 overflow-auto rounded border bg-background p-3 text-xs",children:o?"Loading...":d?"Error loading columns":JSON.stringify(i.slice(0,5),null,2)})]})]})]})}const R=J=>{if(!u.config)return;if(!J.length){m(u.id,{...u.config,sortByColumns:[]});return}const H=u.config,$=J.map(({id:ee,desc:X})=>{var q,Q;const ue=(q=H.metricColumns)==null?void 0:q.find(le=>le.label===ee),me=(Q=H.groupByColumns)==null?void 0:Q.find(le=>le.label===ee),ae=ue||me;return ae?{id:s.getFieldId("sortBy",ae),name:ae.name,dataType:ae.dataType,label:ae.label,qualifiedEntityName:ae.qualifiedEntityName,entityId:ae.entityId,entityName:ae.entityName,entityType:ae.entityType,role:"sortby",direction:X?"desc":"asc"}:null}).filter(ee=>ee!==null);m(u.id,{...H,sortByColumns:$})},_=w.useMemo(()=>{var J,H;return(H=(J=u.config)==null?void 0:J.sortByColumns)==null?void 0:H.map($=>({id:$.label,desc:$.direction==="desc"}))},[(Z=u.config)==null?void 0:Z.sortByColumns]);return e.jsxs("div",{className:s.cn("relative flex w-0 grow flex-col",{"border-l":g&&v}),children:[a&&U(),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"&&g&&e.jsx(Hs,{variant:"outline"}),e.jsx(Er,{activeView:t,onViewChange:n}),e.jsx(s.FilterInfo,{cardId:c.id,cardFilters:(ne=c.config)==null?void 0:ne.filters,cardFilterCount:s.getFilterCount(((te=c.config)==null?void 0:te.filters)||null),onFiltersClick:l}),I&&e.jsx(s.ComparisonMetadataBadge,{metadata:I,variant:"compact"}),e.jsx("div",{className:"ml-2",children:e.jsx(Ar,{})}),g&&e.jsx(Qe,{})]}),e.jsxs("div",{className:s.cn("flex grow items-center justify-end gap-2"),children:[e.jsx(s.IconButton,{tooltip:"Refresh",disabled:O||F,onClick:()=>{z(!0),L()},children:e.jsx(s.RefreshCcw,{className:s.cn("h-4 w-4",{"animate-spin":B})})}),t==="chart"&&e.jsx(Js,{}),!g&&e.jsx(s.IconButton,{onClick:()=>b(!g),tooltip:"AI",className:"h-8","aria-label":"AI",children:e.jsx(s.Sparkles,{className:"size-4"})}),r&&s.isDevEnv]})]}),!S&&N&&e.jsx(s.IconButton,{"aria-label":"Open Chart Settings",tooltip:"Open Chart Settings",onClick:()=>k(!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 min-h-0 grow flex-col",children:[t==="chart"&&e.jsx("div",{className:"flex grow flex-col pb-6",children:e.jsx(Qs,{})}),t==="table"&&(A==null?void 0:A.records)&&e.jsx("div",{className:"relative flex h-full min-h-0 max-w-full flex-1 grow basis-0 p-6",children:e.jsx(s.TableVisual,{card:c,data:(A==null?void 0:A.records)||[],paginationMetadata:E,onPaginationChange:K,isLoading:O||F,onSortChange:R,sortState:_})}),t==="info"&&j&&e.jsx("div",{className:"flex min-h-0 flex-1 flex-col pb-6",children:e.jsx("div",{className:"flex min-h-0 flex-1 flex-col rounded-md bg-background px-6",children:C?e.jsx(Ze,{error:C,errorSql:D,onSendFeedback:()=>{const J=s.prepareFeedbackData(s.FeedbackCategory.QUERY_GENERATION,{cardConfig:u.config,dataSource:c.dataSource,dashboardFilters:x,errorMessage:C,errorSql:D,generatedSql:A==null?void 0:A.sql});y(J),M(!0)},onOpenInEditor:()=>{b(!0),setTimeout(()=>{const J=s.useEditorStore.getState().actions;J.setIsDevMode(!0),J.setCardSql(D||""),setTimeout(()=>{J.setRunSql(!0)},100)},100)}}):e.jsx($s,{sql:A==null?void 0:A.sql,error:C,errorSql:D})})})]}),e.jsx(Fr,{isOpen:S,onClose:()=>k(!1)}),T&&e.jsx(s.FeedbackDialog,{open:P,onOpenChange:M,feedbackData:T})]})]})}function Lr({activeField:t}){const[n,a]=w.useState(!0);return w.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(as,{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 Pr=()=>{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 Or(){var z,K;const[t,n]=w.useState("chart"),[a,r]=w.useState(!1),[l,c]=w.useState(!1),[i,o]=w.useState(!0),d=s.useEditorStore(U=>U.showAIDialog),u=s.useDashboardStore(U=>U.isVisualEditing),{setCardType:x}=s.useEditorActions(),m=s.useEditorStore(U=>U.card.type);w.useEffect(()=>Pr(),[]);const h=U=>{x(U)},p=s.useEditorStore(U=>U.frame),b=s.useEditorStore(U=>U.card);s.useEditorStore(U=>U.activeTabCardId),s.useEditorStore(U=>U.actions.getAvailableFields);const{addCard:g,removeCard:v,updateCard:S,setActiveCard:k,updateFilters:P}=s.useEditorActions(),{columns:M=[],isLoading:T,error:y}=s.useColumns(),f=s.useSensors(s.useSensor(s.PointerSensor,{activationConstraint:{distance:8}})),j=b,{getFieldsForContainer:N,setFieldsForContainer:A}=Ye(j),{activeField:C,handleDragStart:O,handleDragEnd:F}=Tr({activeCardId:p.activeCardId,sourceFields:M,getFieldsForContainer:N,setFieldsForContainer:A}),D=(U,R)=>{R&&P(U,R)},E=U=>{var R;S(U,{config:{...(R=p.cards.find(_=>_.id===U))==null?void 0:R.config,filters:void 0}})},L=M,I=U=>{if(!U)return 0;let R=U.conditions.length;return U.groups.forEach(_=>{R+=I(_)}),R},B=I(((z=j==null?void 0:j.config)==null?void 0:z.filters)||null);return e.jsxs(s.DndContext,{sensors:f,collisionDetection:s.closestCenter,onDragStart:O,onDragEnd:F,children:[e.jsxs("div",{className:"flex h-full grow",children:[e.jsx(qs,{isVisible:i,onToggleVisibility:()=>o(!i)}),e.jsxs("div",{className:"flex flex-1 transition-all duration-300 ease-in-out",children:[!d&&e.jsx(cr,{selectedChart:m,onChartChange:h,groupByFields:N("groupBy"),pivotByFields:N("pivotBy"),metricsFields:N("metrics"),sortByFields:N("sortBy"),activeField:C}),e.jsx(Mr,{selectedChart:m,activeView:t,onViewChange:n,showDebug:a,onDebugToggle:()=>r(!a),onFiltersClick:()=>c(!0),filterCount:B,activeCard:j,dataSourceState:b.dataSource||s.EMPTY_DATA_SOURCE,columns:M,columnsLoading:T,columnsError:y,getFieldsForContainer:N,cards:p.cards,activeCardId:p.activeCardId,addCard:g,setActiveCard:k})]}),!i&&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"})})})]}),j&&e.jsx(kr,{cardId:j.id,filters:((K=j.config)==null?void 0:K.filters)||null,onFiltersChange:D,onClearFilters:E,availableFields:L,isOpen:l,onOpenChange:c}),e.jsx(s.DragOverlay,{dropAnimation:null,children:e.jsx(Lr,{activeField:C||null})})]})}function Br({authToken:t,onSave:n,onClose:a}){const r=w.useRef(null),l=s.useEditorStore(y=>y.showAIDialog),c=s.useEditorStore(y=>y.isDevMode),i=s.useAssistantLayoutStore(y=>y.setFullscreen),o=s.useAssistantLayoutStore(y=>y.setPanelOpen),d=s.useAssistantLayoutStore(y=>y.setContainer),u=s.useAssistantPanel("editor"),x=s.useFullscreenAssistant(),m=s.useAssistantContainer("editor"),h=x==="editor",p=w.useCallback(y=>{d("editor",y)},[d]),{setAuthToken:b}=s.useDashboardActions(),{setShowAIDialog:g,setOnSave:v,setOnClose:S}=s.useEditorActions(),{setActiveAssistantType:k}=s.useAIActions();w.useEffect(()=>{n&&v(n),a&&S(a)},[n,v,a,S]),w.useEffect(()=>{t&&t.accessToken&&b(t)},[t,b]),w.useEffect(()=>{var y,f;l?((y=r.current)==null||y.resize(40),o("editor",!0),k("editor")):((f=r.current)==null||f.resize(0),o("editor",!1),x==="editor"&&i(null),k(null))},[l,o,k,i,x]);function P(y){y<1?(g(!1),o("editor",!1),x==="editor"&&i(null),k(null)):(l||(g(!0),k("editor")),u.isOpen||o("editor",!0))}function M(){return e.jsxs(e.Fragment,{children:[e.jsx(qs,{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(qn,{})}),e.jsx(s.ResizableHandle,{}),e.jsx(s.ResizablePanel,{"data-role":"editor-assistant-panel",ref:r,onResize:P,defaultSize:u.isOpen?40:0,className:"flex",children:e.jsx("div",{className:"grow overflow-y-auto",children:e.jsx(bs,{isFullscreen:h,onFullscreenChange:y=>i(y?"editor":null),fullscreenContainer:m})})})]}),e.jsx("div",{ref:p,className:s.cn("absolute inset-0",!h&&"pointer-events-none")})]})]})}function T(){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(Or,{})}),e.jsx(s.ResizableHandle,{}),e.jsx(s.ResizablePanel,{"data-role":"editor-assistant-panel",ref:r,onResize:P,defaultSize:u.isOpen?40:0,className:"flex",children:e.jsx("div",{className:"grow overflow-y-auto",children:e.jsx(bs,{isFullscreen:h,onFullscreenChange:y=>i(y?"editor":null),fullscreenContainer:m})})})]}),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:M()}):T()})}function Vr(){s.useDashboardStore(i=>i.selectedCardId);const t=s.useDashboardStore(i=>i.selectedSheetId),{setIsVisualEditing:n}=s.useDashboardStore(i=>i.actions),a=s.useDashboardStore(i=>i.isVisualEditing),r=s.useDashboardStore(i=>i.actions.updateFrame);function l(i){t&&(r(t,i),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(Br,{onSave:l,onClose:c})})}function Rr(){zs();const t=s.useDashboardStore(d=>d.selectedSheetId),n=s.useDashboardStore(d=>d.selectedFrameId),a=s.useDashboardStore(d=>d.dashboard),r=s.useDashboardStore(d=>d.actions.getSelectedFrame),{setSelectedFrameId:l}=s.useDashboardActions(),{setCard:c}=s.useEditorActions(),i=s.useEditorStore(d=>d.card.dataSource);return w.useEffect(()=>{var u,x;let d=r();if(!d){const m=(u=a==null?void 0:a.sheets)==null?void 0:u.find(p=>p.id===t),h=(x=m==null?void 0:m.frames)==null?void 0:x[0];h&&(l(h.id),d=h)}if(d){const m=d.cards.find(h=>h.id===d.activeCardId);m&&c(m)}},[r,t,n,a,l,c]),{hasEntities:!!(i!=null&&i.selectedEntities&&i.selectedEntities.length>0)}}function zr(){const t=s.useDashboardStore(a=>a.actions.setShowFilters),{hasEntities:n}=Rr();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(Rs,{context:"filter"})})})})]})}function qr(){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 $r(){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(qr,{}),e.jsx(s.DashboardTabs,{})]}),t&&e.jsx("div",{role:"filter-aside-container",className:"flex",children:e.jsx(zr,{})})]})}function Gr(){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 lt(){return e.jsx(s.ScrollArea,{className:"w-full flex-1",children:e.jsxs("div",{className:"space-y-4 px-4 py-2",children:[e.jsx("div",{className:"h-9 w-full rounded bg-muted animate-pulse"}),e.jsx("div",{className:"h-9 w-full rounded bg-muted animate-pulse"}),e.jsx("div",{className:"space-y-3 pt-2",children:[...Array(3)].map((t,n)=>e.jsxs("div",{className:"flex gap-3 animate-pulse",children:[e.jsx("div",{className:"h-8 w-8 rounded bg-muted flex-shrink-0"}),e.jsxs("div",{className:"flex-1 space-y-1.5",children:[e.jsx("div",{className:"h-4 w-2/3 rounded bg-muted"}),e.jsx("div",{className:"h-3 w-4/5 rounded bg-muted"})]})]},n))})]})})}const Ur=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 Kr({visual:t,isDeleting:n,isDuplicating:a,onAddVisual:r,onOpenVisual:l,onEditDetails:c,onDeleteClick:i,onDuplicateVisual:o,onShareVisual:d,formatDate:u}){var T,y,f,j;const{selectVisual:x}=s.useManagementActions(),m=s.useIsVisualSelected(t.id),h=Ur(t.id),{isConsoleMode:p}=s.useDashboardPreferences(),b=w.useRef(null),[g,v]=w.useState(!1),[S,k]=w.useState(!1);w.useEffect(()=>{a?(v(!0),k(!0)):S&&(v(!1),k(!1))},[a,S]),w.useEffect(()=>{h&&b.current&&b.current.scrollIntoView({behavior:"smooth",block:"center"})},[h]);const P=()=>e.jsx(Re,{className:"h-4 w-4"}),M=()=>{x(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":m&&"border-primary"),onClick:M,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:P()}),e.jsxs("div",{className:"min-w-0 flex-1 flex flex-col",children:[e.jsxs("div",{className:"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.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx("p",{className:"text-xs text-muted-foreground line-clamp-2 flex-1",title:t.description||"No description",children:(T=t.description)!=null&&T.trim()?t.description:"No description"}),e.jsxs("div",{className:s.cn("invisible flex flex-shrink-0 items-center gap-1 transition-opacity duration-150 group-hover:visible",m&&"visible"),onClick:N=>N.stopPropagation(),children:[e.jsx(s.Button,{size:"sm",variant:"ghost",className:"h-6 w-6 p-0",onClick:N=>{N.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:N=>{N.stopPropagation(),c==null||c(t)},title:"Edit details",children:e.jsx(s.PenLine,{className:"h-3 w-3"})}),e.jsxs(s.DropdownMenu,{modal:!1,open:g,onOpenChange:v,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:N=>{N.stopPropagation(),r(t)},children:[e.jsx(s.Plus,{className:"mr-2 h-3 w-3"}),"Add"]}),e.jsxs(s.DropdownMenuItem,{onClick:N=>{N.stopPropagation(),l==null||l(t)},children:[e.jsx(wt,{className:"mr-2 h-3 w-3"}),"Open"]}),e.jsxs(s.DropdownMenuItem,{onClick:N=>{N.preventDefault(),N.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:N=>{N.stopPropagation(),c==null||c(t)},children:[e.jsx(s.PenLine,{className:"mr-2 h-3 w-3"}),"Edit details"]}),e.jsxs(s.DropdownMenuItem,{onClick:N=>{N.stopPropagation(),d(t)},children:[e.jsx(s.Users,{className:"mr-2 h-3 w-3"}),"Share"]}),e.jsx(s.DropdownMenuSeparator,{}),e.jsxs(s.DropdownMenuItem,{onClick:N=>{N.stopPropagation(),i(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:[(((y=t.ownership.createdBy)==null?void 0:y.type)==="tenant"||((f=t.ownership.createdBy)==null?void 0:f.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:((j=t.ownership.createdBy)==null?void 0:j.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 _r({open:t,onOpenChange:n,onSubmit:a,isCreating:r}){const[l,c]=w.useState(""),[i,o]=w.useState("");w.useEffect(()=>{t||(c(""),o(""))},[t]);const d=()=>{l.trim()&&a({title:l,description:i})},u=x=>{n(x)};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:x=>c(x.target.value),disabled:r,onKeyDown:x=>{x.key==="Enter"&&!x.shiftKey&&(x.preventDefault(),d())}})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(s.Label,{htmlFor:"description",children:"Description (optional)"}),e.jsx(s.Input$1,{id:"description",placeholder:"Enter visual description...",value:i,onChange:x=>o(x.target.value),disabled:r})]})]}),e.jsxs(s.DialogFooter,{children:[e.jsx(s.Button,{variant:"outline",onClick:()=>u(!1),disabled:r,children:"Cancel"}),e.jsx(s.Button,{onClick:d,disabled:!l.trim()||r,children:r?e.jsxs(e.Fragment,{children:[e.jsx(s.LoaderCircle,{className:"mr-2 h-4 w-4 animate-spin"}),"Creating..."]}):"Create Visual"})]})]})})}function Hr(){const[t,n]=w.useState(""),[a,r]=w.useState(!1),[l,c]=w.useState(!1),[i,o]=w.useState(null),[d,u]=w.useState(!1),[x,m]=w.useState(null),[h,p]=w.useState(null),[b,g]=w.useState(null),{selectVisual:v}=s.useManagementActions(),{handleEditLibraryVisual:S,handleAddLibraryVisual:k}=ke(),{resources:P,isLoading:M,isError:T,createResource:y,updateResource:f,deleteResource:j,duplicateResource:N,isCreating:A,isDeleting:C}=s.useVisualManagement(()=>{u(!1),m(null)},$=>{r(!1),$&&(v($),S($))});s.useCurrentUserInfo();const O=P.filter($=>{var ee,X;return((ee=$==null?void 0:$.title)==null?void 0:ee.toLowerCase().includes(t.toLowerCase()))||((X=$==null?void 0:$.description)==null?void 0:X.toLowerCase().includes(t.toLowerCase()))}),F=$=>new Date($).toLocaleDateString("en-US",{month:"short",day:"numeric",year:"numeric"}),D=$=>{y({title:$.title,description:$.description,isPrivate:!1})},E=$=>{m($),u(!0)},L=()=>{x&&j(x.id)},{startUpdating:I,stopUpdating:B,isUpdating:z}=s.useResourceUpdateState(),K=($,ee,X)=>{var q;const ue=Object.fromEntries(Object.entries(ee).filter(([,Q])=>Q!==void 0));if(Object.keys(ue).length===0){(q=X==null?void 0:X.onSuccess)==null||q.call(X);return}const me=Object.keys(ue),ae=me.length===1?me[0]:void 0;I($,ae),f({resourceId:$,data:ue},{onSuccess:()=>{var Q;B($,ae),(Q=X==null?void 0:X.onSuccess)==null||Q.call(X)},onError:()=>{var Q;B($,ae),(Q=X==null?void 0:X.onError)==null||Q.call(X)}})},U=$=>{p($),N($,{onSettled:()=>p(null)})},R=$=>{S($)},_=$=>{k($)},Z=$=>{const ee=P.find(X=>X.id===$);ee&&f({resourceId:$,data:{isPrivate:!ee.isPrivate}})},ne=$=>{o($),c(!0)},te=$=>{g($)},J=()=>{g(null)},H=({title:$,description:ee})=>{if(!b)return;const X={};$!==b.title&&(X.title=$),(b.description||"")!==ee&&(X.description=ee),K(b.id,X,{onSuccess:()=>{g(null)}})};return M?e.jsx(lt,{}):T?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:[P&&P.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:O.length===0?e.jsxs("div",{className:"py-8 text-center",children:[e.jsx("div",{className:"mb-3",children:e.jsx(Re,{className:"mx-auto h-12 w-12 text-muted-foreground/50"})}),e.jsx("h3",{className:"mb-1 font-medium text-foreground",children:t?"No visuals found":"No visuals yet"}),e.jsx("p",{className:"mb-4 text-sm text-muted-foreground",children:t?"Try adjusting your search":"Create your first visual component to get started"}),!t&&e.jsxs(s.Button,{size:"sm",className:"bg-primary hover:bg-primary/90",onClick:()=>r(!0),children:[e.jsx(s.Plus,{className:"mr-2 h-4 w-4"}),"Create Visual"]})]}):O.map($=>e.jsx(Kr,{visual:$,onAddVisual:_,onOpenVisual:R,onEditDetails:te,onDeleteClick:E,onDuplicateVisual:U,onTogglePrivacy:Z,onShareVisual:ne,isDeleting:C,isDuplicating:h===$.id,formatDate:F},$.id))})}),l&&i&&e.jsx(s.ShareDialog,{resource:i,resourceType:s.ResourceType.VISUAL,onClose:()=>{c(!1),o(null)}}),b&&e.jsx(s.ResourceEditDialog,{open:!!b,resourceLabel:"Visual",initialTitle:b.title||"",initialDescription:b.description||"",onClose:J,onSave:H,isSaving:z(b.id)}),e.jsx(s.AlertDialog,{open:d,onOpenChange:$=>{!$&&C||(u($),$||m(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 "',x==null?void 0:x.title,'"? This action cannot be undone.']})]}),e.jsxs(s.AlertDialogFooter,{children:[e.jsx(s.AlertDialogCancel,{disabled:C,children:"Cancel"}),e.jsxs(s.AlertDialogAction,{onClick:$=>{$.preventDefault(),$.stopPropagation(),L()},className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",disabled:C,children:[C?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"}),C?"Deleting...":"Delete"]})]})]})}),e.jsx(_r,{open:a,onOpenChange:r,onSubmit:D,isCreating:A}),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 Jr({dashboard:t,isDeleting:n,isDuplicating:a,onLoadDashboard:r,onEditDetails:l,onDeleteClick:c,onDuplicateDashboard:i,onShareDashboard:o,formatDate:d,onDashboardItemClick:u}){var k,P;const{selectDashboard:x}=s.useManagementActions(),m=s.useIsDashboardSelected(t.id),{userContext:h,isLoading:p}=s.useCurrentUserInfo(),b=((k=h==null?void 0:h.permissions)==null?void 0:k.canEdit)??!1,g=p||!b,v=()=>e.jsx(s.LayoutDashboard,{className:"h-4 w-4"}),S=()=>{x(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",m&&"border-primary"),onClick:S,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:v()}),e.jsxs("div",{className:"min-w-0 flex-1 flex flex-col",children:[e.jsxs("div",{className:"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.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx("p",{className:"text-xs text-muted-foreground line-clamp-2 flex-1",title:t.description||"No description",children:(P=t.description)!=null&&P.trim()?t.description:"No description"}),e.jsx(s.DashboardActionsMenu,{dashboard:t,isDeleting:n,isDuplicating:a,shouldHideActions:g,onEditDetails:l,onDeleteClick:c,onDuplicateDashboard:i,onShareDashboard:o,formatDate:d})]})]})]})},t.id)}function Qr({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 Wr(t){var de;const{onLoadDashboard:n,onEditDashboard:a,onDashboardItemClick:r}=t,[l,c]=w.useState(""),[i,o]=w.useState(!1),[d,u]=w.useState(!1),[x,m]=w.useState(null),[h,p]=w.useState(!1),[b,g]=w.useState(null),[v,S]=w.useState(null),[k,P]=w.useState(null),M=s.useManagementStore(V=>V.lastSelectedDashboard),T=s.useManagementStore(V=>V.selectedDashboard),y=s.useManagementStore(V=>V.actions.selectDashboard),f=s.useManagementStore(V=>V.actions.clearSelectedDashboard),{tokenProps:j,id:N}=s.useSemaphorContext();s.useRoleAwareDisplayPreferences();const{onCreateSuccess:A}=s.useDashboardCreation({onDashboardSelect:r}),{resources:C,isLoading:O,isError:F,createResource:D,updateResource:E,deleteResource:L,duplicateResource:I,isCreating:B,isDeleting:z,refetch:K}=s.useDashboardManagement(()=>{p(!1);const V=b==null?void 0:b.id;g(null),(T==null?void 0:T.id)===V&&(!(j!=null&&j.dashboard_id)&&!N?f():M&&M.id!==V&&y(M))},V=>{o(!1),A(V,K)}),{currentUser:U,userContext:R}=s.useCurrentUserInfo(),_=((de=R==null?void 0:R.permissions)==null?void 0:de.canCreateDashboard)??!1,Z=C.filter(V=>{var se,Y;return((se=V==null?void 0:V.title)==null?void 0:se.toLowerCase().includes(l.toLowerCase()))||((Y=V==null?void 0:V.description)==null?void 0:Y.toLowerCase().includes(l.toLowerCase()))}),ne=V=>new Date(V).toLocaleDateString("en-US",{month:"short",day:"numeric",year:"numeric"}),te=V=>{D({title:V.title,description:V.description,isPrivate:!1})},J=V=>{n==null||n(V)},H=V=>{g(V),p(!0)},$=()=>{b&&L(b.id)},ee=V=>{S(V),I(V,{onSettled:()=>S(null)})},{startUpdating:X,stopUpdating:ue,isUpdating:me}=s.useResourceUpdateState(),ae=(V,se,Y)=>{var ve;const je=Object.fromEntries(Object.entries(se).filter(([,he])=>he!==void 0));if(Object.keys(je).length===0){(ve=Y==null?void 0:Y.onSuccess)==null||ve.call(Y);return}const ge=Object.keys(je),be=ge.length===1?ge[0]:void 0;X(V,be),E({resourceId:V,data:je},{onSuccess:()=>{var he;ue(V,be),(he=Y==null?void 0:Y.onSuccess)==null||he.call(Y)},onError:()=>{var he;ue(V,be),(he=Y==null?void 0:Y.onError)==null||he.call(Y)}})},q=V=>{const se=C.find(Y=>Y.id===V);se&&E({resourceId:V,data:{isPrivate:!se.isPrivate}})},Q=V=>{m(V),U==null||U.type,u(!0)},le=V=>{a==null||a(V.id),P(V)},pe=()=>{P(null)},fe=({title:V,description:se})=>{if(!k)return;const Y={};V!==k.title&&(Y.title=V),(k.description||"")!==se&&(Y.description=se),ae(k.id,Y,{onSuccess:()=>{P(null)}})};return O?e.jsx(lt,{}):F?e.jsx(Qr,{onRetry:()=>window.location.reload()}):e.jsxs("div",{className:"relative flex h-full flex-1 flex-col gap-4",children:[C&&C.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:V=>c(V.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:Z.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":_?"Create your first dashboard to get started":"No dashboards have been shared with you yet"}),_&&!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"]})]}):Z.map(V=>e.jsx(Jr,{dashboard:V,isDeleting:z,isDuplicating:v===V.id,onLoadDashboard:J,onEditDetails:le,onDeleteClick:H,onDuplicateDashboard:ee,onTogglePrivacy:q,onShareDashboard:Q,formatDate:ne,onDashboardItemClick:r},V.id))})}),d&&x&&e.jsx(s.ShareDialog,{resource:x,resourceType:s.ResourceType.DASHBOARD,onClose:()=>{u(!1),m(null)}}),e.jsx(s.AlertDialog,{open:h,onOpenChange:V=>{!V&&z||(p(V),V||g(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:z,children:"Cancel"}),e.jsxs(s.AlertDialogAction,{onClick:V=>{V.preventDefault(),V.stopPropagation(),$()},className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",disabled:z,children:[z?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"}),z?"Deleting...":"Delete"]})]})]})}),k&&e.jsx(s.ResourceEditDialog,{open:!!k,resourceLabel:"Dashboard",initialTitle:k.title||"",initialDescription:k.description||"",onClose:pe,onSave:fe,isSaving:me(k.id)}),e.jsx(s.CreateDashboardDialog,{open:i,onOpenChange:o,onSubmit:te,isCreating:B}),_&&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 ot({isOpen:t,onClose:n,className:a,onDashboardItemClick:r,variant:l="inline"}){s.useDashboardStore(y=>y.dashboard);const c=s.useDashboardStore(y=>y.isDashboardEditing),{setDashboard:i,addSheet:o}=s.useDashboardStore(y=>y.actions),{currentUser:d}=s.useCurrentUserInfo(),u=d,{permissions:x}=s.useRoleAwareDisplayPreferences(),h=s.useSelectedDashboard()&&x.canAccessVisuals&&c,p="dashboards",[b,g]=ts("resource-management-active-tab",p),v=h?b:"dashboards",S=l==="overlay",k=Is(n,{enabled:t&&S}),P=s.cn("flex h-full flex-col border-r bg-background",S?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),M=y=>{},T=y=>{console.log("Editing dashboard:",y)};return e.jsx(s.TooltipProvider,{children:(!S||t)&&e.jsxs("div",{ref:k,className:P,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:u&&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:u.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:u.name}),e.jsx("div",{className:"text-xs text-muted-foreground",children:u.email}),u.role&&e.jsxs("div",{className:"text-xs text-muted-foreground",children:["Role:"," ",s.toTitleCase(u.role.replace(/_/g," "))]}),e.jsxs("div",{className:"text-xs text-muted-foreground",children:["ID: ",u.id]})]})})]}),e.jsx("div",{className:"flex items-center gap-2",children:e.jsx("span",{className:"text-sm font-medium text-foreground",children:u.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(Vt,{className:"h-4 w-4"})})]}),e.jsx("div",{className:"flex flex-1 flex-col overflow-hidden",children:e.jsxs(s.Tabs,{value:v,onValueChange:h?g:void 0,className:"flex h-9 grow flex-col",children:[h&&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(Wr,{onLoadDashboard:M,onEditDashboard:T,onDashboardItemClick:r})}),h&&e.jsx(s.TabsContent,{value:"visuals",className:"flex-1 px-4 py-4",children:e.jsx(Hr,{})})]})})]})})}function Yr({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,i=20,o=30,d=r,u=w.useRef(null),x=w.useRef(null);w.useEffect(()=>{u.current&&x.current&&(r?(u.current.resize(c),x.current.resize(100-c)):(u.current.resize(0),x.current.resize(100)))},[r]);const{preferences:m}=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:m,children:[e.jsx(Gr,{}),e.jsxs("main",{className:"relative flex h-full w-full flex-col",children:[t&&e.jsx(wa,{}),e.jsxs(s.ResizablePanelGroup,{direction:"horizontal",className:"flex grow overflow-hidden",children:[e.jsx(s.ResizablePanel,{ref:u,className:s.cn("flex h-full max-w-[26rem] overflow-hidden",{"min-w-[20rem]":d}),defaultSize:d?c:0,minSize:d?i:0,maxSize:d?o:0,children:e.jsx(ot,{isOpen:r,onClose:()=>l(!1),variant:"inline"})}),e.jsx(s.ResizableHandle,{className:s.cn("",{"w-0":!d})}),e.jsx(s.ResizablePanel,{ref:x,className:"flex min-w-0 flex-1",defaultSize:d?100-c:100,minSize:d?40:100,children:e.jsxs(s.Container,{...a,type:"dashboard",children:[e.jsx(Vr,{}),e.jsx($r,{})]})})]})]})]})})]})})}exports.AdvancedModeToggle=Ps;exports.DashboardPlus=Yr;exports.ResourceManagementPanel=ot;exports.ScheduleDashboard=Fs;exports.VisualEditingControls=Ls;exports.cleanCard=As;exports.getDashbaordStateWithoutData=Ve;
|
|
@@ -6454,7 +6454,14 @@ function rl({
|
|
|
6454
6454
|
customCfg: s.customCfg,
|
|
6455
6455
|
preferences: s.preferences,
|
|
6456
6456
|
topoJson: g
|
|
6457
|
-
}), [
|
|
6457
|
+
}), [
|
|
6458
|
+
s.id,
|
|
6459
|
+
f == null ? void 0 : f.records,
|
|
6460
|
+
s.type,
|
|
6461
|
+
s.customCfg,
|
|
6462
|
+
s.preferences,
|
|
6463
|
+
g
|
|
6464
|
+
]);
|
|
6458
6465
|
function E(z) {
|
|
6459
6466
|
return /* @__PURE__ */ e(ya, { FallbackComponent: Ks, children: /* @__PURE__ */ e(Kd, { card: z }) });
|
|
6460
6467
|
}
|
package/dist/index.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./chunks/index-DHzLB6Yx.js"),v=require("./types/index.cjs"),c=require("./chunks/dashboard-plus-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./chunks/index-DHzLB6Yx.js"),v=require("./types/index.cjs"),c=require("./chunks/dashboard-plus-BuCiUxZH.js"),a=require("react/jsx-runtime"),x=require("react");require("react-dom");function j(r){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(r){for(const s in r)if(s!=="default"){const i=Object.getOwnPropertyDescriptor(r,s);Object.defineProperty(t,s,i.get?i:{enumerable:!0,get:()=>r[s]})}}return t.default=r,Object.freeze(t)}const p=j(x);/**
|
|
2
2
|
* @license lucide-react v0.453.0 - ISC
|
|
3
3
|
*
|
|
4
4
|
* This source code is licensed under the ISC license.
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { c as x, E as y, F as N, S as w, U as A, a as L, C as _, u as E, b as v, d as P, P as k, e as W, B as F, f as M, g as R, h as O, i as Q, j as V, I as B, k as I, l as j, m as q, n as U, o as z } from "./chunks/index-Dji-XteI.js";
|
|
2
2
|
import { D as ne, v as ie, R as de, r as le, r as ce, s as Ye, a0 as ue, L as he, x as pe, z as fe, N as me, M as Me, T as Ce, V as De, K as ve, w as ye, J as ge, O as be, H as Te, G as Se, A as xe, W as Ne, Q as we, t as Ae, Y as Le, _ as _e, Z as Ee, $ as Pe, y as ke, p as We, a2 as Fe, X as Re, a1 as Oe, q as Qe } from "./chunks/index-Dji-XteI.js";
|
|
3
3
|
import { EMPTY_SELECTION as Be } from "./types/index.js";
|
|
4
|
-
import { A as je, R as qe, S as Ue, D as ze, V as Ge, c as He, g as $e } from "./chunks/dashboard-plus-
|
|
4
|
+
import { A as je, R as qe, S as Ue, D as ze, V as Ge, c as He, g as $e } from "./chunks/dashboard-plus-Dr_jkDZA.js";
|
|
5
5
|
import { jsx as e, jsxs as d } from "react/jsx-runtime";
|
|
6
6
|
import * as h from "react";
|
|
7
7
|
import { useMemo as G } from "react";
|
package/dist/surfboard/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("../chunks/dashboard-plus-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("../chunks/dashboard-plus-BuCiUxZH.js"),r=require("../types/index.cjs");exports.Surfboard=e.DashboardPlus;exports.EMPTY_SELECTION=r.EMPTY_SELECTION;
|
package/dist/surfboard/index.js
CHANGED