react-semaphor 0.0.566 → 0.0.567
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-CXAL5A12.js → dashboard-plus-0Rn87MhT.js} +543 -555
- package/dist/chunks/{dashboard-plus-wb1r1n95.js → dashboard-plus-ByzYCkhZ.js} +2 -2
- package/dist/chunks/{index-C4zmqaQZ.js → index-D8xxFA1P.js} +31 -31
- package/dist/chunks/{index-BoSWZtuJ.js → index-DAzFInix.js} +1517 -1494
- package/dist/dashboard/index.cjs +1 -1
- package/dist/dashboard/index.js +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.js +2 -2
- package/dist/surfboard/index.cjs +1 -1
- package/dist/surfboard/index.js +1 -1
- package/dist/types/main.d.ts +4 -0
- package/package.json +1 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";var rt=t=>{throw TypeError(t)};var ps=(t,a,n)=>a.has(t)||rt("Cannot "+n);var re=(t,a,n)=>(ps(t,a,"read from private field"),n?n.call(t):a.get(t)),Fe=(t,a,n)=>a.has(t)?rt("Cannot add the same private member more than once"):a instanceof WeakSet?a.add(t):a.set(t,n),Be=(t,a,n,r)=>(ps(t,a,"write to private field"),r?r.call(t,n):a.set(t,n),n),ze=(t,a,n)=>(ps(t,a,"access private method"),n);const e=require("react/jsx-runtime"),s=require("./index-
|
|
1
|
+
"use strict";var rt=t=>{throw TypeError(t)};var ps=(t,a,n)=>a.has(t)||rt("Cannot "+n);var re=(t,a,n)=>(ps(t,a,"read from private field"),n?n.call(t):a.get(t)),Fe=(t,a,n)=>a.has(t)?rt("Cannot add the same private member more than once"):a instanceof WeakSet?a.add(t):a.set(t,n),Be=(t,a,n,r)=>(ps(t,a,"write to private field"),r?r.call(t,n):a.set(t,n),n),ze=(t,a,n)=>(ps(t,a,"access private method"),n);const e=require("react/jsx-runtime"),s=require("./index-D8xxFA1P.js"),I=require("react");require("react-dom");function On(t){const a=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(t){for(const n in t)if(n!=="default"){const r=Object.getOwnPropertyDescriptor(t,n);Object.defineProperty(a,n,r.get?r:{enumerable:!0,get:()=>t[n]})}}return a.default=t,Object.freeze(a)}const ue=On(I);var Ce,Se,de,je,ye,es,Ss,St,Rn=(St=class extends s.Subscribable{constructor(a,n){super();Fe(this,ye);Fe(this,Ce);Fe(this,Se);Fe(this,de);Fe(this,je);Be(this,Ce,a),this.setOptions(n),this.bindMethods(),ze(this,ye,es).call(this)}bindMethods(){this.mutate=this.mutate.bind(this),this.reset=this.reset.bind(this)}setOptions(a){var r;const n=this.options;this.options=re(this,Ce).defaultMutationOptions(a),s.shallowEqualObjects(this.options,n)||re(this,Ce).getMutationCache().notify({type:"observerOptionsUpdated",mutation:re(this,de),observer:this}),n!=null&&n.mutationKey&&this.options.mutationKey&&s.hashKey(n.mutationKey)!==s.hashKey(this.options.mutationKey)?this.reset():((r=re(this,de))==null?void 0:r.state.status)==="pending"&&re(this,de).setOptions(this.options)}onUnsubscribe(){var a;this.hasListeners()||(a=re(this,de))==null||a.removeObserver(this)}onMutationUpdate(a){ze(this,ye,es).call(this),ze(this,ye,Ss).call(this,a)}getCurrentResult(){return re(this,Se)}reset(){var a;(a=re(this,de))==null||a.removeObserver(this),Be(this,de,void 0),ze(this,ye,es).call(this),ze(this,ye,Ss).call(this)}mutate(a,n){var r;return Be(this,je,n),(r=re(this,de))==null||r.removeObserver(this),Be(this,de,re(this,Ce).getMutationCache().build(re(this,Ce),this.options)),re(this,de).addObserver(this),re(this,de).execute(a)}},Ce=new WeakMap,Se=new WeakMap,de=new WeakMap,je=new WeakMap,ye=new WeakSet,es=function(){var n;const a=((n=re(this,de))==null?void 0:n.state)??s.getDefaultState();Be(this,Se,{...a,isPending:a.status==="pending",isSuccess:a.status==="success",isError:a.status==="error",isIdle:a.status==="idle",mutate:this.mutate,reset:this.reset})},Ss=function(a){s.notifyManager.batch(()=>{var n,r,o,i,c,l,d,m;if(re(this,je)&&this.hasListeners()){const u=re(this,Se).variables,h=re(this,Se).context;(a==null?void 0:a.type)==="success"?((r=(n=re(this,je)).onSuccess)==null||r.call(n,a.data,u,h),(i=(o=re(this,je)).onSettled)==null||i.call(o,a.data,null,u,h)):(a==null?void 0:a.type)==="error"&&((l=(c=re(this,je)).onError)==null||l.call(c,a.error,u,h),(m=(d=re(this,je)).onSettled)==null||m.call(d,void 0,a.error,u,h))}this.listeners.forEach(u=>{u(re(this,Se))})})},St);function Le(t,a){const n=s.useQueryClient(),[r]=ue.useState(()=>new Rn(n,t));ue.useEffect(()=>{r.setOptions(t)},[r,t]);const o=ue.useSyncExternalStore(ue.useCallback(c=>r.subscribe(s.notifyManager.batchCalls(c)),[r]),()=>r.getCurrentResult(),()=>r.getCurrentResult()),i=ue.useCallback((c,l)=>{r.mutate(c,l).catch(s.noop)},[r]);if(o.error&&s.shouldThrowError(r.options.throwOnError,[o.error]))throw o.error;return{...o,mutate:i,mutateAsync:o.mutate}}/**
|
|
2
2
|
* @license lucide-react v0.453.0 - ISC
|
|
3
3
|
*
|
|
4
4
|
* This source code is licensed under the ISC license.
|
|
@@ -432,4 +432,4 @@ ${b.joinType} JOIN ${A.name}
|
|
|
432
432
|
ON ${O}`}),D},isValidConfiguration:()=>!(!n.baseEntity.name||n.joins.some(b=>!b.source.name||!b.target.name)||n.joins.some(b=>b.joinKeyGroups.some(A=>A.keys.length===0))||n.joins.some(b=>b.joinKeyGroups.some(A=>A.keys.some(S=>!S.source.name||!S.target.name||!S.operator))))}}function li({joinPlan:t,availableDataSources:a,onSave:n,onRemove:r,onCancel:o}){const{setCardConfig:i}=s.useEditorActions();s.useEditorStore(S=>S.card.config);const{columnGroups:c}=s.useColumns(),{joinPlan:l,expandedJoins:d,setJoinPlan:m,addJoin:u,removeJoin:h,updateJoin:p,moveJoinUp:f,moveJoinDown:j,toggleJoinExpansion:x,getAvailableSourceEntities:y,getAvailableTargetEntities:g,addJoinKeyGroup:C,updateGroupOperator:k,removeJoinKeyGroup:R,addJoinKey:T,updateJoinKey:w,removeJoinKey:v,generateSQLPreview:D,isValidConfiguration:b}=ii({initialJoinPlan:t,availableDataSources:a}),A=S=>{const O=c.find(M=>M.entityName===S);return(O==null?void 0:O.columns)||[]};return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(s.Label,{children:"Base Entity (FROM clause)"}),e.jsxs(s.Select,{value:l.baseEntity.name,onValueChange:S=>{const O=a.find(M=>M.name===S);m({...l,baseEntity:{connectionId:(O==null?void 0:O.connectionId)||"",connectionType:(O==null?void 0:O.connectionType)||"none",type:(O==null?void 0:O.type)||"table",name:S,database:O==null?void 0:O.database,schema:O==null?void 0:O.schema}})},children:[e.jsx(s.SelectTrigger,{children:e.jsx(s.SelectValue,{placeholder:"Select base entity..."})}),e.jsx(s.SelectContent,{children:a.map(S=>e.jsx(s.SelectItem,{className:"hover:bg-muted",value:S.name,children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(s.Badge,{variant:"outline",className:"text-xs",children:S.type}),S.name,e.jsx(s.Badge,{variant:"outline",className:"text-xs text-green-600",children:"BASE"})]})},S.name))})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"This entity will be used as the base table in the FROM clause of the SQL query."})]}),e.jsxs("div",{className:"rounded-md border p-3",children:[e.jsx("div",{className:"mb-2 text-xs font-medium text-muted-foreground",children:"Join SQL Preview"}),e.jsx("code",{className:"block whitespace-pre-wrap break-all text-xs",children:D()})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs(s.Label,{children:["Joins Configuration (",l.joins.length,")"]}),e.jsx("div",{className:"flex items-center gap-2",children:e.jsxs(s.Button,{variant:"outline",size:"sm",onClick:u,children:[e.jsx(s.Plus,{className:"mr-1 h-4 w-4"}),"Add Join"]})})]}),l.joins.length===0?e.jsx("div",{className:"rounded-lg border border-dashed py-8 text-center text-muted-foreground",children:e.jsx("p",{children:"No joins configured. Add a join to connect multiple data sources."})}):e.jsx("div",{className:"max-h-[300px] space-y-4 overflow-y-auto",children:l.joins.map(S=>{const O=a.find(N=>N.name===S.source.name),M=a.find(N=>N.name===S.target.name),E=d.has(S.id);return e.jsxs(s.Card,{className:"border",children:[e.jsx(s.CardHeader,{className:"pb-3",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(s.Badge,{children:S.sequence}),e.jsxs(s.CardTitle,{className:"text-sm",children:["Join ",S.sequence,O&&M&&e.jsxs("span",{className:"ml-2 font-normal text-gray-600",children:["(",O.name," → ",M.name,")"]})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(s.Button,{variant:"ghost",size:"sm",onClick:()=>f(S.id),disabled:S.sequence===1,children:e.jsx(s.ArrowUp,{className:"h-4 w-4"})}),e.jsx(s.Button,{variant:"ghost",size:"sm",onClick:()=>j(S.id),disabled:S.sequence===l.joins.length,children:e.jsx(s.ArrowDown,{className:"h-4 w-4"})}),e.jsx(s.Button,{variant:"ghost",size:"sm",onClick:()=>x(S.id),children:E?e.jsx(s.ChevronUp,{className:"h-4 w-4"}):e.jsx(s.ChevronDown,{className:"h-4 w-4"})}),e.jsx(s.Button,{variant:"ghost",size:"sm",onClick:()=>h(S.id),children:e.jsx(s.X,{className:"h-4 w-4"})})]})]})}),E&&e.jsxs(s.CardContent,{className:"space-y-4 pb-6",children:[e.jsxs("div",{className:"grid grid-cols-1 gap-4 md:grid-cols-3",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(s.Label,{children:"Source"}),e.jsxs(s.Select,{value:S.source.name,onValueChange:N=>{const L=a.find(B=>B.name===N);p(S.id,{source:{connectionId:(L==null?void 0:L.connectionId)||"",connectionType:(L==null?void 0:L.connectionType)||"none",type:(L==null?void 0:L.type)||"table",name:N,database:L==null?void 0:L.database,schema:L==null?void 0:L.schema}})},children:[e.jsx(s.SelectTrigger,{children:e.jsx(s.SelectValue,{placeholder:"Select source..."})}),e.jsx(s.SelectContent,{children:y(S.id).map(N=>e.jsx(s.SelectItem,{className:"hover:bg-muted",value:N.name,children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(s.Badge,{variant:"outline",className:"text-xs",children:N.type}),N.name]})},N.name))})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(s.Label,{children:"Join Type"}),e.jsxs(s.Select,{value:S.joinType,onValueChange:N=>p(S.id,{joinType:N}),children:[e.jsx(s.SelectTrigger,{children:e.jsx(s.SelectValue,{})}),e.jsxs(s.SelectContent,{children:[e.jsx(s.SelectItem,{className:"hover:bg-muted",value:"INNER",children:"INNER JOIN"}),e.jsx(s.SelectItem,{className:"hover:bg-muted",value:"LEFT",children:"LEFT JOIN"}),e.jsx(s.SelectItem,{className:"hover:bg-muted",value:"RIGHT",children:"RIGHT JOIN"}),e.jsx(s.SelectItem,{className:"hover:bg-muted",value:"FULL",children:"FULL JOIN"})]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(s.Label,{children:"Target"}),e.jsxs(s.Select,{value:S.target.name,onValueChange:N=>{const L=a.find(B=>B.name===N);p(S.id,{target:{connectionId:(L==null?void 0:L.connectionId)||"",connectionType:(L==null?void 0:L.connectionType)||"none",type:(L==null?void 0:L.type)||"table",name:N,database:L==null?void 0:L.database,schema:L==null?void 0:L.schema}})},disabled:!S.source.name,children:[e.jsx(s.SelectTrigger,{children:e.jsx(s.SelectValue,{placeholder:"Select target..."})}),e.jsx(s.SelectContent,{children:S.source.name?g(S.source.name).map(N=>e.jsx(s.SelectItem,{className:"hover:bg-muted",value:N.name,children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(s.Badge,{variant:"outline",className:"text-xs",children:N.type}),N.name,N.name===S.source.name&&e.jsx(s.Badge,{variant:"outline",className:"text-xs text-yellow-600",children:"(Self-join)"})]})},N.name)):[]})]})]})]}),S.source.name&&S.target.name&&O&&M&&e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(s.Label,{children:"Join Conditions"}),e.jsxs(s.Button,{type:"button",variant:"outline",size:"sm",onClick:()=>C(S.id),children:[e.jsx(s.Plus,{className:"mr-1 h-3 w-3"})," Add Condition Group"]})]}),S.joinKeyGroups.length===0?e.jsx("div",{className:"rounded-md border p-3 text-center text-sm text-gray-500",children:"No join conditions defined. Add condition groups to specify how data sources should be joined."}):e.jsx("div",{className:"space-y-4",children:S.joinKeyGroups.map((N,L)=>e.jsxs("div",{className:"space-y-3 rounded-md border p-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(s.Label,{children:["Group ",L+1]}),L>0&&e.jsxs("div",{className:"flex items-center gap-2 rounded-md bg-gray-100 px-2 py-1",children:[e.jsx(s.Label,{className:"text-xs font-normal",children:"Join with:"}),e.jsx("span",{className:"text-sm font-medium",children:"OR"})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(s.Select,{value:N.operator,onValueChange:B=>k(S.id,L,B),children:[e.jsx(s.SelectTrigger,{className:"w-[100px]",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,{value:"OR",children:"OR"})]})]}),e.jsx(s.Button,{type:"button",variant:"ghost",size:"sm",onClick:()=>R(S.id,L),children:e.jsx(s.Trash2,{className:"h-4 w-4"})})]})]}),e.jsxs("div",{className:"space-y-2",children:[N.keys.length===0?e.jsx("div",{className:"rounded-md border border-dashed p-3 text-center text-sm text-gray-500",children:"No conditions in this group. Add conditions to specify join criteria."}):e.jsx("div",{className:"space-y-2",children:N.keys.map((B,P)=>e.jsxs("div",{className:"flex flex-col items-start gap-2 rounded-md border p-2 sm:flex-row sm:items-center",children:[P>0&&e.jsx("div",{className:"self-center rounded-md bg-gray-100 px-2 py-1 text-xs font-medium",children:N.operator}),e.jsx("div",{className:"mb-2 w-full sm:mb-0 sm:flex-1",children:e.jsxs(s.Select,{value:B.source.name,onValueChange:V=>w(S.id,L,P,"sourceColumnName",V),children:[e.jsx(s.SelectTrigger,{children:e.jsx(s.SelectValue,{placeholder:"Source column"})}),e.jsx(s.SelectContent,{children:A(S.source.name).map(V=>e.jsx(s.SelectItem,{className:"hover:bg-muted",value:V.name,children:e.jsxs("div",{className:"flex w-full items-center justify-between",children:[e.jsx("span",{children:V.name}),e.jsx(s.Badge,{variant:"outline",className:"ml-2 text-xs",children:V.dataType})]})},V.name))})]})}),e.jsx("div",{className:"mb-2 w-full sm:mb-0 sm:w-20",children:e.jsxs(s.Select,{value:B.operator,onValueChange:V=>w(S.id,L,P,"operator",V),children:[e.jsx(s.SelectTrigger,{children:e.jsx(s.SelectValue,{})}),e.jsxs(s.SelectContent,{children:[e.jsx(s.SelectItem,{className:"hover:bg-muted",value:"=",children:"="}),e.jsx(s.SelectItem,{className:"hover:bg-muted",value:"<",children:"<"}),e.jsx(s.SelectItem,{className:"hover:bg-muted",value:">",children:">"}),e.jsx(s.SelectItem,{className:"hover:bg-muted",value:"<=",children:"<="}),e.jsx(s.SelectItem,{className:"hover:bg-muted",value:">=",children:">="})]})]})}),e.jsx("div",{className:"mb-2 w-full sm:mb-0 sm:flex-1",children:e.jsxs(s.Select,{value:B.target.name,onValueChange:V=>w(S.id,L,P,"targetColumnName",V),children:[e.jsx(s.SelectTrigger,{children:e.jsx(s.SelectValue,{placeholder:"Target column"})}),e.jsx(s.SelectContent,{children:A(S.target.name).map(V=>e.jsx(s.SelectItem,{className:"hover:bg-muted",value:V.name,children:e.jsxs("div",{className:"flex w-full items-center justify-between hover:bg-muted",children:[e.jsx("span",{children:V.name}),e.jsx(s.Badge,{variant:"outline",className:"ml-2 text-xs",children:V.dataType})]})},V.name))})]})}),e.jsx(s.Button,{type:"button",variant:"ghost",size:"sm",className:"self-center",onClick:()=>v(S.id,L,P),children:e.jsx(s.X,{className:"size-3.5"})})]},B.id||P))}),e.jsxs(s.Button,{type:"button",variant:"outline",size:"sm",className:"mt-2",onClick:()=>T(S.id,L),children:[e.jsx(s.Plus,{className:"mr-1 h-3 w-3"})," Add Condition"]})]})]},N.id))})]})]})]},S.id)})})]}),e.jsxs("div",{className:"flex justify-end gap-2 border-t pt-4",children:[e.jsx(s.Button,{variant:"outline",onClick:()=>{r(),o()},children:"Remove All"}),e.jsx(s.Button,{variant:"outline",onClick:o,children:"Cancel"}),e.jsx(s.Button,{onClick:()=>n(l),disabled:!b(),children:"Save"})]})]})}function vt({children:t,open:a,onOpenChange:n,joinPlan:r,availableDataSources:o,onRemove:i,onSave:c,onCancel:l}){return e.jsxs(s.Dialog,{open:a,onOpenChange:n,children:[e.jsxs(s.DialogContent,{className:"max-w-4xl",children:[e.jsxs(s.DialogHeader,{children:[e.jsx(s.DialogTitle,{children:"Join Configuration"}),e.jsx(s.DialogDescription,{children:"Configure the join between the two entities to combine the fields."})]}),e.jsx(li,{joinPlan:r,availableDataSources:o,onSave:c,onCancel:l,onRemove:i})]}),t]})}function ci({joins:t,baseEntityId:a,availableDataSources:n,generateSQLPreview:r}){return e.jsxs("div",{className:"divide-y divide-border",children:[t.length>0&&e.jsxs("div",{className:"p-4",children:[e.jsx("h3",{className:"mb-3 text-left font-semibold",children:"Join Chain"}),e.jsx("div",{className:"flex flex-wrap items-center gap-2",children:(()=>{const o=[...t].sort((c,l)=>c.sequence-l.sequence),i=n.find(c=>c.name===a);return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex items-center gap-1 rounded-md border bg-muted px-2 py-1",children:[e.jsx(s.Badge,{variant:"secondary",className:"text-xs",children:i==null?void 0:i.type}),e.jsx("span",{className:"text-xs font-medium",children:i==null?void 0:i.name}),e.jsx(s.Badge,{variant:"outline",className:"text-xs text-green-600",children:"BASE"})]}),o.map(c=>{const l=n.find(d=>d.name===c.target.name);return e.jsxs("div",{className:"flex items-center",children:[e.jsxs("div",{className:"mx-1 flex items-center gap-1",children:[e.jsx(s.Badge,{variant:"outline",className:"text-xs",children:c.joinType}),e.jsx("span",{className:"text-muted-foreground",children:"→"})]}),e.jsxs("div",{className:"flex items-center gap-1 rounded-md border bg-muted px-2 py-1",children:[e.jsx(s.Badge,{variant:"secondary",className:"text-xs",children:l==null?void 0:l.type}),e.jsx("span",{className:"text-xs font-medium",children:l==null?void 0:l.name})]})]},c.id)})]})})()})]}),e.jsxs("div",{className:"p-4",children:[e.jsxs("h3",{className:"mb-3 text-left text-sm font-medium",children:["Configured Joins (",t.length,")"]}),e.jsx("div",{className:"space-y-2",children:[...t].sort((o,i)=>o.sequence-i.sequence).map((o,i)=>{const c=n.find(d=>d.name===o.source.name),l=n.find(d=>d.name===o.target.name);return e.jsxs("div",{className:"flex items-center gap-2 rounded-md bg-muted p-2 text-left",children:[e.jsx(s.Badge,{variant:"secondary",className:"shrink-0 text-xs",children:i+1}),e.jsx(s.Badge,{variant:"outline",className:"shrink-0 text-xs",children:o.joinType}),e.jsxs("span",{className:"text-xs font-medium",children:[c==null?void 0:c.name," → ",l==null?void 0:l.name]}),e.jsxs(s.Badge,{variant:"outline",className:"ml-auto text-xs",children:[o.joinKeyGroups.reduce((d,m)=>d+m.keys.length,0)," ","condition",o.joinKeyGroups.reduce((d,m)=>d+m.keys.length,0)>1?"s":""]})]},o.id)})})]}),e.jsxs("div",{className:"p-4",children:[e.jsx("h3",{className:"mb-3 text-left text-sm font-medium",children:"SQL Query"}),e.jsx("div",{className:"overflow-x-auto rounded-md border bg-muted p-3",children:e.jsx("pre",{className:"whitespace-pre-wrap break-all text-left font-mono text-xs text-muted-foreground",children:r()})})]})]})}function di(){var u,h;const t=s.useEditorStore(p=>p.card),a=s.useEditorStore(p=>p.actions.updateCardConfig),n=((u=t==null?void 0:t.config)==null?void 0:u.joinPlan)||{baseEntity:{type:"table",name:"",database:"",schema:"",connectionId:"",connectionType:"none",dialect:"none"},joins:[]},[r,o]=I.useState(!1),i=((h=t==null?void 0:t.dataSource)==null?void 0:h.selectedEntities)||[],c=p=>{a(t.id,{...t==null?void 0:t.config,joinPlan:p}),o(!1)},l=()=>{a(t.id,{...t==null?void 0:t.config,joinPlan:void 0})},d=()=>{o(!1)},m=()=>{const p=[...n.joins].sort((x,y)=>x.sequence-y.sequence),f=n.baseEntity;if(!f.name)return"SELECT * FROM table -- Please select a base entity";let j=`SELECT *
|
|
433
433
|
FROM ${f.name}`;return p.forEach(x=>{const y=i.find(k=>k.name===x.target.name);if(!y)return;const g=x.joinKeyGroups.filter(k=>k.keys&&k.keys.length>0).map(k=>{const R=k.keys.filter(T=>{var w,v,D,b;return((w=T.source)==null?void 0:w.name)&&((v=T.target)==null?void 0:v.name)&&((D=T.source)==null?void 0:D.entityName)&&((b=T.target)==null?void 0:b.entityName)}).map(T=>`${T.source.entityName}.${T.source.name} ${T.operator} ${T.target.entityName}.${T.target.name}`);return R.length>1?`(${R.join(` ${k.operator} `)})`:R[0]}).filter(Boolean),C=g.length>1?g.join(" OR "):g[0]||"condition_here";j+=`
|
|
434
434
|
${x.joinType} JOIN ${y.name}
|
|
435
|
-
ON ${C}`}),j};return i.length<2?null:e.jsx(e.Fragment,{children:e.jsx("div",{className:"space-y-4",children:e.jsxs("div",{className:"flex items-center justify-between",children:[n.joins.length>0&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(s.TooltipProvider$1,{children:e.jsxs(s.Tooltip,{children:[e.jsx(s.TooltipTrigger,{asChild:!0,children:e.jsxs(s.Button,{variant:"outline",size:"sm",className:"h-6 text-xs font-semibold",onClick:()=>o(!0),children:[e.jsx(s.Link,{className:s.cn("mr-1 h-3 w-3",{"text-blue-500":n.joins.length>0,"text-gray-500":n.joins.length===0})}),"Join",n.joins.length>1?"s":""," (",n.joins.length,")"]})}),e.jsx(s.TooltipContent,{side:"right",className:"max-w-md overflow-hidden p-0",children:e.jsx(ci,{joins:n.joins,baseEntityId:n.baseEntity.name,availableDataSources:i,generateSQLPreview:m})})]})}),e.jsx(vt,{open:r,onOpenChange:o,joinPlan:n,availableDataSources:i,onSave:c,onCancel:d,onRemove:l,children:e.jsx("div",{})})]}),n.joins.length===0&&e.jsx(vt,{open:r,onOpenChange:o,joinPlan:n,availableDataSources:i,onSave:c,onCancel:d,onRemove:l,children:e.jsxs(s.Button,{onClick:()=>o(!0),variant:"outline",size:"sm",className:"w-full",children:[e.jsx(s.Link,{className:"mr-3 size-4"}),"Configure Joins"]})})]})})})}function ui({open:t,onOpenChange:a}){const[n,r]=I.useState([]),{updateDataSource:o}=s.useEditorActions(),i=s.useDashboardStore(x=>x.dashboard.aiContext),c=(i==null?void 0:i.selectedEntities)||[];I.useEffect(()=>{t&&r([])},[t]);const l=x=>{r(y=>y.some(C=>C.name===x.name&&C.type===x.type)?y.filter(C=>!(C.name===x.name&&C.type===x.type)):[...y,x])},d=()=>{r([...c])},m=()=>{r([])},u=()=>{if(n.length===0)return;const x=n[0],y=x.connectionId||"",g=x.connectionType||"",k=n.some(T=>T.type==="dataset")?"semanticDomain":"database";o({connectionId:y,connectionType:g,mode:k,selectedEntities:n}),a(!1)},h=x=>{switch(x.type){case"table":return e.jsx(s.Table,{className:"h-4 w-4"});case"view":return e.jsx(Ma,{className:"h-4 w-4"});case"model":return e.jsx(sa,{className:"h-4 w-4"});case"dataset":return e.jsx(s.Database,{className:"h-4 w-4"});case"file":case"url":case"upload":return e.jsx(s.FileText,{className:"h-4 w-4"});default:return e.jsx(s.Database,{className:"h-4 w-4"})}},p=x=>"label"in x&&x.label?x.label:x.name,f=x=>{if("description"in x&&x.description)return x.description;const y=[];return x.database&&y.push(x.database),x.schema&&y.push(x.schema),x.name&&y.push(x.name),y.join(".")},j=x=>n.some(y=>y.name===x.name&&y.type===x.type);return c.length===0?e.jsx(s.Dialog,{open:t,onOpenChange:a,children:e.jsxs(s.DialogContent,{className:"max-w-md",children:[e.jsxs(s.DialogHeader,{children:[e.jsx(s.DialogTitle,{children:"No Data Available"}),e.jsx(s.DialogDescription,{children:"No entities are currently available in the AI context. Please add some data sources to the dashboard first."})]}),e.jsx(s.DialogFooter,{children:e.jsx(s.Button,{onClick:()=>a(!1),children:"Close"})})]})}):e.jsx(s.Dialog,{open:t,onOpenChange:a,children:e.jsxs(s.DialogContent,{className:"flex max-w-2xl flex-col",children:[e.jsxs(s.DialogHeader,{children:[e.jsx(s.DialogTitle,{children:"Select Data to Analyze"}),e.jsx(s.DialogDescription,{children:"Choose entities from the dashboard's context"})]}),e.jsxs("div",{className:"flex-1 space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(s.Button,{variant:"outline",size:"sm",onClick:d,disabled:n.length===c.length,children:"Select All"}),e.jsx(s.Button,{variant:"outline",size:"sm",onClick:m,disabled:n.length===0,children:"Clear All"})]}),e.jsxs(s.Badge,{variant:"secondary",children:[n.length," of ",c.length," selected"]})]}),e.jsx(s.Separator,{}),e.jsx(s.ScrollArea,{className:"h-64",children:e.jsx("div",{className:"space-y-2",children:c.map((x,y)=>e.jsxs("div",{className:s.cn("flex items-center gap-3 rounded-lg border p-3 transition-colors hover:bg-muted/50",j(x)&&"border-primary bg-primary/5"),children:[e.jsx(s.Checkbox,{checked:j(x),onCheckedChange:()=>l(x)}),e.jsx("div",{className:"flex items-center gap-2 text-muted-foreground",children:h(x)}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:"truncate font-medium",children:p(x)}),e.jsx("div",{className:"truncate text-sm text-muted-foreground",children:f(x)})]}),e.jsx(s.Badge,{variant:"outline",className:"text-xs",children:x.type})]},`${x.type}-${x.name}-${y}`))})})]}),e.jsx(s.DialogFooter,{children:e.jsx("div",{className:"flex w-full justify-between",children:e.jsxs("div",{className:"flex grow justify-end gap-2",children:[e.jsx(s.Button,{variant:"outline",onClick:()=>a(!1),children:"Cancel"}),e.jsxs(s.Button,{onClick:u,disabled:n.length===0,children:["Select"," ",n.length>0?`(${n.length})`:""]})]})})})]})})}function mi({entity:t,title:a,maxDetails:n=10}){const o=s.getEntityDetails(t).slice(0,n),i=o.find(l=>l.label==="Description"),c=o.filter(l=>l.label==="Description"?!1:!["Connection","Database","Schema"].includes(l.label));return e.jsx(s.TooltipContent,{side:"top",className:"ml-5 max-w-xs",children:e.jsxs("div",{className:"space-y-2",children:[e.jsx("div",{className:"text-sm font-medium",children:a||s.getDisplayName(t)}),i&&e.jsxs("div",{className:"border-t border-border pt-2",children:[e.jsx("div",{className:"mb-1 text-xs text-muted-foreground",children:"Description:"}),e.jsx("div",{className:"text-xs leading-relaxed",children:i.value})]}),c.length>0&&e.jsx("div",{className:"space-y-0.5",children:c.map((l,d)=>e.jsxs("div",{className:"flex justify-between text-xs",children:[e.jsxs("span",{className:"mr-2 text-muted-foreground",children:[l.label,":"]}),e.jsx("span",{className:"font-mono",children:l.value})]},d))})]})})}function hi({entities:t}){return e.jsx(s.TooltipContent,{side:"top",className:"ml-5 max-w-xs",children:e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"text-sm font-medium",children:[t.length," more entities"]}),e.jsx("div",{className:"space-y-1",children:t.map((a,n)=>{const r=s.getEntityDetails(a),o=r.find(c=>c.label==="Description"),i=r.filter(c=>c.label==="Description"?!1:!["Connection","Database","Schema"].includes(c.label)).slice(0,3);return e.jsxs("div",{className:"border-b border-border pb-1 last:border-b-0",children:[e.jsx("div",{className:"text-xs font-medium",children:s.getDisplayName(a)}),o&&e.jsxs("div",{className:"mb-1 mt-1",children:[e.jsx("div",{className:"text-xs text-muted-foreground",children:"Description:"}),e.jsx("div",{className:"text-xs leading-relaxed",children:o.value})]}),i.length>0&&e.jsx("div",{className:"mt-1 space-y-0.5",children:i.map((c,l)=>e.jsxs("div",{className:"flex justify-between text-xs",children:[e.jsxs("span",{className:"mr-2 text-muted-foreground",children:[c.label,":"]}),e.jsx("span",{className:"font-mono",children:c.value})]},l))})]},`remaining-${a.type}-${a.name}-${n}`)})})]})})}function xi({isVisible:t,onToggleVisibility:a}){s.useEditorStore(f=>f.isDevMode),s.useEditorStore(f=>f.card.connectionId),s.useDashboardStore(f=>f.isVisualEditing);const[n,r]=I.useState(!1),[o,i]=I.useState(!1),[c,l]=I.useState(!0),d=s.useEditorStore(f=>f.card.dataSource),{currentUser:m}=be(),{updateDataSource:u}=s.useEditorActions(),h={connectionId:"",connectionType:"",mode:"database",selectedEntities:[]},p={...h,...d,selectedEntities:(d==null?void 0:d.selectedEntities)||[]};return e.jsxs("div",{className:s.cn("flex flex-col overflow-hidden bg-background transition-all duration-300 ease-in-out",{"w-[325px]":t,"w-0":!t}),children:[e.jsxs("div",{children:[e.jsx("div",{className:s.cn("p-4 px-6",{"pb-0":!c}),children:e.jsxs("div",{className:"flex w-full items-center justify-between",children:[e.jsxs("div",{className:"flex cursor-pointer items-center gap-2",children:[e.jsx("h2",{className:"text-brand-100 font-semibold",children:"Data Source"}),e.jsx(s.Button,{variant:"ghost",size:"sm",onClick:()=>l(!c),className:"h-6 w-6 p-0",children:c?e.jsx(s.ChevronDown,{className:"h-4 w-4"}):e.jsx(s.ChevronRight,{className:"h-4 w-4"})})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(s.Button,{size:"sm",variant:"ghost",className:"h-7 w-7 p-0 text-muted-foreground hover:text-foreground",onClick:a,title:"Hide Data Source Panel",children:e.jsx(s.EyeOff,{className:"h-3.5 w-3.5"})}),(m==null?void 0:m.type)==="organization"&&e.jsxs(s.Button,{size:"sm",variant:"outline",className:"h-7",onClick:()=>r(!0),children:[e.jsx(s.Plus,{className:"mr-1 h-3.5 w-3.5"}),"Add"]}),(m==null?void 0:m.type)==="tenant"&&e.jsxs(s.Button,{size:"sm",variant:"outline",className:"h-7",onClick:()=>i(!0),children:[e.jsx(s.Plus,{className:"mr-1 h-3.5 w-3.5"}),"Select"]})]})]})}),e.jsxs("div",{className:`overflow-hidden px-6 ${c?"max-h-96 space-y-4":"max-h-0 py-0 opacity-0"}`,children:[p.selectedEntities.length>0&&e.jsx(s.TooltipProvider$1,{children:e.jsxs("div",{className:"flex flex-wrap gap-1",children:[p.selectedEntities.slice(0,3).map((f,j)=>e.jsxs(s.Tooltip,{children:[e.jsx(s.TooltipTrigger,{asChild:!0,children:e.jsxs(s.Badge,{variant:"secondary",className:"group relative cursor-pointer pr-6 text-xs transition-colors hover:border-red-200 hover:bg-red-50 dark:hover:border-red-800 dark:hover:bg-red-950",children:[s.getDisplayName(f),e.jsx("button",{onClick:x=>{x.stopPropagation();const y=p.selectedEntities.filter(g=>!(g.name===f.name&&g.type===f.type));u({...h,...d,selectedEntities:y})},className:"absolute right-1 top-1/2 -translate-y-1/2 rounded-full p-0.5 hover:bg-red-100",children:e.jsx(s.X,{className:"h-2.5 w-2.5 group-hover:text-red-500"})})]})}),e.jsx(mi,{entity:f})]},`${f.type}-${f.name}-${j}`)),p.selectedEntities.length>3&&e.jsxs(s.Tooltip,{children:[e.jsx(s.TooltipTrigger,{asChild:!0,children:e.jsxs(s.Badge,{variant:"outline",className:"text-xs",children:["+",p.selectedEntities.length-3," more"]})}),e.jsx(hi,{entities:p.selectedEntities.slice(3)})]})]})}),e.jsx(di,{})]})]}),e.jsx(oi,{}),e.jsx(s.DataSourceDialog,{incomingSelectedEntities:(d==null?void 0:d.selectedEntities)||[],dialogMode:"dataSource",open:n,onOpenChange:r,dataSource:p,fallbackDataSource:h}),e.jsx(ui,{open:o,onOpenChange:i})]})}const ss=[{id:"table",icon:Ve,label:"Table"},{id:"pivotTable",icon:Ve,label:"Pivot Table"},{id:"aggregateTable",icon:Ve,label:"Aggregate Table"},{id:"bar",icon:cs,label:"Bar Chart"},{id:"line",icon:ds,label:"Line Chart"},{id:"area",icon:kt,label:"Area Chart"},{id:"stackedBar",icon:As,label:"Stacked Bar Chart"},{id:"combo",icon:Wn,label:"Combo Chart"},{id:"stackedLine",icon:Ks,label:"Stacked Line Chart"},{id:"scatter",icon:Os,label:"Scatter Chart"},{id:"bubble",icon:Hs,label:"Bubble Chart"},{id:"pie",icon:us,label:"Pie Chart"},{id:"doughnut",icon:Rs,label:"Doughnut Chart"},{id:"funnel",icon:Qs,label:"Funnel Chart"},{id:"radar",icon:Bs,label:"Radar Chart"},{id:"polarArea",icon:Gs,label:"Polar Area Chart"},{id:"tornado",icon:zs,label:"Tornado Chart"},{id:"range",icon:Ls,label:"Range Chart"},{id:"kpi",icon:Ws,label:"KPI"},{id:"text",icon:wt,label:"Text"},{id:"map",icon:Fs,label:"Map"}],et=t=>{const a=t.toLowerCase();for(const n of ss)if(n.id==="doughnut"){if(a.includes("doughnut")||a.includes("donut")){const r=n.icon;return I.createElement(r,{className:"h-4 w-4"})}}else if(a.includes(n.id.toLowerCase())){const r=n.icon;return I.createElement(r,{className:"h-4 w-4"})}return null},pi="chart-selector-standard-first";function fi(){const[t,a]=s.useLocalStorageState(pi,!0);return{standardFirst:t,updatePreference:a}}const bt=({pluginVisual:t,index:a,onSelect:n})=>{const r=hs(t.icon||""),o=t.name.charAt(0).toUpperCase(),i=et(t.name);return e.jsx(s.CommandItem,{value:`${t.name} custom visual plugin component`,onSelect:n,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"}):i||e.jsx("div",{className:"flex h-4 w-4 items-center justify-center rounded bg-muted text-xs font-medium",children:o}),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}-${a}`)},Nt=["default","standardPlugin","customPlugin"];function gi({selectedChart:t,onChartChange:a}){var w;const[n,r]=I.useState([]),[o,i]=I.useState(!1),{data:c}=Ys();fi();const d=((w=s.useEditorStore(v=>v.card).customCardPreferences)==null?void 0:w.url)||"";Ps(d);const{setCardType:m,setCardPreferences:u,setIsDevMode:h}=s.useEditorStore(v=>v.actions),{setCardCustomCfg:p,setCustomCardPreferences:f,setQueryConfig:j}=s.useEditorActions(),[x,y]=s.useLocalStorageState("chart-section-active",null),g=I.useMemo(()=>x?[x,...Nt.filter(v=>v!==x)]:Nt,[x]);I.useEffect(()=>{(async()=>{if(c){const b=(await Promise.allSettled(c.plugins.map(async A=>{try{return(await s.loadManifest(A.value)).visuals.map(O=>({name:O.name,icon:O.icon,url:A.value,pluginName:A.label,pluginType:A.type,chartType:O.chartType,componentType:O.componentType}))}catch(S){return console.error(`Failed to load manifest for plugin ${A.label}`,S),[]}}))).filter(A=>A.status==="fulfilled").flatMap(A=>A.value);r(b)}})()},[c]);function C(v){p(null),u({}),m(v),["custom","text","map"].includes(v)&&(h(!0),j(void 0)),a(v),i(!1)}function k(v){p(null),u({}),m("custom"),f({type:"component",visualType:"single",url:v.url,componentName:v.name,icon:v.icon,pluginChartType:v.chartType}),j(void 0),a("custom"),i(!1)}const R=()=>{var D;if(t==="custom"){const b=s.useEditorStore.getState().card;return((D=b==null?void 0:b.customCardPreferences)==null?void 0:D.componentName)||"Custom Visual"}const v=ss.find(b=>b.id===t);return(v==null?void 0:v.label)||"Select chart type"},T=()=>{var D,b;if(t==="custom"){const A=s.useEditorStore.getState().card,S=(D=A==null?void 0:A.customCardPreferences)==null?void 0:D.icon,O=(b=A==null?void 0:A.customCardPreferences)==null?void 0:b.componentName;if(S&&O)return e.jsx(ji,{icon:S,componentName:O});if(O){const M=et(O);if(M)return M}return e.jsx(Ge,{className:"h-4 w-4"})}const v=ss.find(A=>A.id===t);if(v){const A=v.icon;return e.jsx(A,{className:"h-4 w-4"})}return e.jsx(Ge,{className:"h-4 w-4"})};return e.jsx("div",{className:"mb-6",children:e.jsxs(s.Popover,{open:o,onOpenChange:i,children:[e.jsx(s.PopoverTrigger,{asChild:!0,children:e.jsxs(s.Button,{variant:"outline",role:"combobox","aria-expanded":o,className:"w-full justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[T(),e.jsx("span",{children:R()})]}),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(v=>{if(v==="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:x==="default",onCheckedChange:D=>y(D?"default":null),className:"scale-75"})]})]}),className:"[&_[cmdk-group-heading]]:text-sm [&_[cmdk-group-heading]]:font-medium [&_[cmdk-group-heading]]:text-muted-foreground",children:ss.map(D=>{const b=D.icon;return e.jsx(s.CommandItem,{value:`${D.label} ${D.id} chart graph visualization`,onSelect:()=>C(D.id),className:"flex items-center gap-2",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(b,{className:"h-4 w-4"}),e.jsx("span",{children:D.label})]})},D.id)})},"default");if(v==="standardPlugin"){const D=n.filter(b=>b.pluginType==="standard");return D.length?e.jsx(s.CommandGroup,{heading:e.jsxs("div",{className:"group flex w-full items-center justify-between",children:[e.jsx("p",{children:"Standard Visuals"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-xs text-muted-foreground opacity-0 transition-opacity group-hover:opacity-100",children:"Show on top"}),e.jsx(s.Switch,{checked:x==="standardPlugin",onCheckedChange:b=>y(b?"standardPlugin":null),className:"scale-75"})]})]}),className:"[&_[cmdk-group-heading]]:text-sm [&_[cmdk-group-heading]]:font-medium [&_[cmdk-group-heading]]:text-muted-foreground",children:D.filter(b=>b.componentType==="chart").map((b,A)=>e.jsx(bt,{pluginVisual:b,index:A,onSelect:()=>k(b)},`${b.url}-${b.name}-${A}`))},"standardPlugin"):null}if(v==="customPlugin"){const D=n.filter(b=>b.pluginType==="custom");return D.length?e.jsx(s.CommandGroup,{heading:e.jsxs("div",{className:"group flex w-full items-center justify-between",children:[e.jsxs(s.Tooltip,{children:[e.jsx(s.TooltipTrigger,{asChild:!0,children:e.jsxs("span",{className:"flex items-center gap-2",children:["Custom Visuals",e.jsx(s.Info,{className:"h-3.5 w-3.5 text-muted-foreground"})]})}),e.jsx(s.TooltipContent,{side:"right",children:"External visuals that are specific to your project"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-xs text-muted-foreground opacity-0 transition-opacity group-hover:opacity-100",children:"Show on top"}),e.jsx(s.Switch,{checked:x==="customPlugin",onCheckedChange:b=>y(b?"customPlugin":null),className:"scale-75"})]})]}),className:"[&_[cmdk-group-heading]]:text-sm [&_[cmdk-group-heading]]:font-medium [&_[cmdk-group-heading]]:text-muted-foreground",children:D.map((b,A)=>e.jsx(bt,{pluginVisual:b,index:A,onSelect:()=>k(b)},`${b.url}-${b.name}-${A}`))},"customPlugin"):null}return null})]})]})})]})})}const ji=({icon:t,componentName:a})=>{const n=hs(),r=et(a);return n?e.jsx(n,{className:"h-4 w-4"}):r||e.jsx(Ge,{className:"h-4 w-4"})},Sn=({dataType:t})=>{const a=s.getDataType(t);return a==="string"?e.jsx("span",{className:"flex size-6 shrink-0 items-center justify-center rounded-sm bg-blue-100 text-xs text-blue-700 dark:bg-blue-950 dark:text-blue-300",children:e.jsx(Qe,{className:"h-3 w-3"})}):a==="number"?e.jsx("span",{className:"flex size-6 shrink-0 items-center justify-center rounded-sm bg-green-100 text-xs text-green-700 dark:bg-green-950 dark:text-green-300",children:e.jsx(Ye,{className:"h-3 w-3"})}):a==="date"?e.jsx("span",{className:"flex size-6 shrink-0 items-center justify-center rounded-sm bg-purple-100 text-xs text-purple-700 dark:bg-purple-950 dark:text-purple-300",children:e.jsx(s.Calendar,{className:"h-3 w-3"})}):a==="boolean"?e.jsx("span",{className:"flex size-6 shrink-0 items-center justify-center rounded-sm bg-orange-100 text-xs text-orange-700 dark:bg-orange-950 dark:text-orange-300",children:e.jsx(ts,{className:"h-3 w-3"})}):e.jsx("span",{className:"flex size-6 shrink-0 items-center justify-center rounded-sm bg-gray-100 text-xs text-gray-700 dark:bg-gray-950 dark:text-gray-300",children:e.jsx(Qe,{className:"h-3 w-3"})})};function yi({aliasTemplate:t,onAliasTemplateChange:a}){var d;const[n,r]=I.useState(t),[o,i]=I.useState(!1),c=(d=s.useEditorStore(m=>{var u;return(u=m.card.config)==null?void 0:u.pivotByColumns}))==null?void 0:d[0],l=c?`e.g. Min Sales in {{${c.name}}}`:"e.g. Min Sales in {{region}}";return e.jsxs("div",{className:"space-y-1",children:[e.jsx(s.Label,{className:"text-xs font-medium text-gray-600",children:"Pivot Alias Template"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(s.Input$1,{placeholder:l,value:o?n:t,onChange:m=>{r(m.target.value),i(!0)},onFocus:()=>i(!0),onPointerDown:m=>m.stopPropagation(),className:"h-8 text-xs",onKeyDown:m=>{m.key==="Enter"&&o&&n!==t?(a(n),i(!1)):m.key==="Escape"&&(r(t),i(!1))},"aria-label":"Edit alias template"}),o&&n!==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:()=>{a(n),i(!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),i(!1)},children:e.jsx(s.X,{className:"h-4 w-4 text-gray-400"})})]})]})]})}function vi({valueAliases:t,onValueAliasesChange:a}){const[n,r]=I.useState(null),[o,i]=I.useState(""),[c,l]=I.useState(""),d=()=>{a({...t,"":""})},m=h=>{const p={...t};delete p[h],a(p)},u=h=>{const p={...t};delete p[h],p[o]=c,a(p),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(([h,p],f)=>e.jsx("div",{className:"flex items-center gap-2",children:n===h?e.jsxs(e.Fragment,{children:[e.jsx(s.Input$1,{placeholder:"Value key",value:o,onChange:j=>i(j.target.value),className:"h-8 w-24 text-xs",onPointerDown:j=>j.stopPropagation(),onKeyDown:j=>{j.key==="Enter"?u(h):j.key==="Escape"&&r(null)},"aria-label":"Edit value alias key"}),e.jsx(s.Input$1,{placeholder:"Alias label",value:c,onChange:j=>l(j.target.value),className:"h-8 w-24 text-xs",onPointerDown:j=>j.stopPropagation(),onKeyDown:j=>{j.key==="Enter"?u(h):j.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:()=>u(h),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:h,className:"h-8 w-24 text-xs",readOnly:!0,onClick:()=>{r(h),i(h),l(p)},"aria-label":"Edit value alias key"}),e.jsx(s.Input$1,{placeholder:"Alias label",value:p,className:"h-8 w-24 text-xs",readOnly:!0,onClick:()=>{r(h),i(h),l(p)},"aria-label":"Edit value alias label"}),e.jsx(s.Button,{variant:"ghost",size:"sm",className:"h-8 w-8 p-0",onClick:()=>m(h),"aria-label":"Remove value alias",children:e.jsx(s.X,{className:"h-3 w-3"})})]})},h+f)),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 Ct({value:t,onSave:a,placeholder:n="",type:r="text",className:o=""}){const[i,c]=I.useState(t??""),[l,d]=I.useState(!1);I.useEffect(()=>{c(t??"")},[t]);const m=()=>{a(i),d(!1)},u=()=>{c(t??""),d(!1)};return e.jsxs("div",{className:`flex items-center gap-2 ${o}`,children:[e.jsx(s.Input$1,{placeholder:n,type:r,value:l?i:t??"",onChange:h=>{c(h.target.value),d(!0)},onFocus:()=>d(!0),onClick:h=>h.stopPropagation(),className:"h-8 text-xs",onPointerDown:h=>h.stopPropagation(),onKeyDown:h=>{h.stopPropagation(),h.key==="Enter"&&l&&i!==t?m():h.key==="Escape"&&u()},"aria-label":n||"Edit field"}),l&&i!==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: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 edit",onClick:u,children:e.jsx(s.X,{className:"h-4 w-4 text-muted-foreground"})})]})]})}function bi({field:t,zone:a,index:n,sortDirection:r,onSortDirectionChange:o,hasPivotColumns:i=!1,cardType:c}){var nt;const{attributes:l,listeners:d,setNodeRef:m,transform:u,transition:h,isDragging:p}=s.useSortable({id:t.id}),f=s.useEditorStore(W=>W.card),{updateLabel:j,handleAggregationChange:x,handleDateFormatChange:y,handleGranularityChange:g,handleAliasTemplateChange:C,handleValueAliasesChange:k,removeField:R,handleKpiComparisonTypeChange:T,handleKpiShowTrendlineChange:w,handleKpiTrendlineWindowChange:v,handleKpiTrendlineGranularityChange:D,handleKpiTargetValueChange:b}=Zs(f),[A,S]=I.useState(!1),[O,M]=I.useState(t.dateFormat||"YYYY-MM-DD"),[E,N]=I.useState(t.customFormat||""),[L,B]=I.useState(!!t.customFormat),[P,V]=I.useState(t.granularity||"day"),[q,X]=I.useState(t.aliasTemplate||""),[K,$]=I.useState(t.valueAliases||{}),F=W=>{W==="custom"?B(!0):(B(!1),M(W),a==="groupBy"&&y(n,W,""))},U=W=>{N(W),a==="groupBy"&&y(n,"custom",W)},_=W=>{var qe;V(W);const xe=(qe=H(W)[0])==null?void 0:qe.value;xe&&!L&&(M(xe),a==="groupBy"&&y(n,xe,"")),a==="groupBy"&&g(n,W)},Y=W=>{X(W),a==="metrics"&&C(n,W)},Q=W=>{$(W),a==="metrics"&&k(n,W)},G=W=>{j(a,n,W)},Z=()=>{R(a,n)},te={transform:s.CSS.Transform.toString(u),transition:h},ae=s.getDataType(t.dataType),se=ae==="date",oe=c==="kpi",H=W=>{switch(W){case"day":return[{value:"MM-DD-YYYY",label:"01-15-2024 (MM-DD-YYYY)"},{value:"YYYY-MM-DD",label:"2024-01-15 (YYYY-MM-DD)"},{value:"MM/DD/YYYY",label:"01/15/2024 (MM/DD/YYYY)"},{value:"DD/MM/YYYY",label:"15/01/2024 (DD/MM/YYYY)"},{value:"MMMM DD, YYYY",label:"January 15, 2024 (MMMM DD, YYYY)"},{value:"MMM DD, YYYY",label:"Jan 15, 2024 (MMM DD, YYYY)"},{value:"DD MMM YYYY",label:"15 Jan 2024 (DD MMM YYYY)"},{value:"custom",label:"Custom Format..."}];case"week":return[{value:"MM-DD-YYYY",label:"01-15-2024 (MM-DD-YYYY)"},{value:"YYYY-MM-DD",label:"2024-01-15 (YYYY-MM-DD)"},{value:"Week of MMM DD, YYYY",label:"Week of Jan 15, 2024"},{value:"Week of MMMM DD, YYYY",label:"Week of January 15, 2024"},{value:"YYYY-WW",label:"2024-W03 (YYYY-WW)"},{value:"custom",label:"Custom Format..."}];case"month":return[{value:"MMM YYYY",label:"Jan 2024 (MMM YYYY)"},{value:"MMMM YYYY",label:"January 2024 (MMMM YYYY)"},{value:"YYYY-MM",label:"2024-01 (YYYY-MM)"},{value:"MM/YYYY",label:"01/2024 (MM/YYYY)"},{value:"YYYY MMM",label:"2024 Jan (YYYY MMM)"},{value:"custom",label:"Custom Format..."}];case"quarter":return[{value:"Q1 YYYY",label:"Q1 2024 (Q1 YYYY)"},{value:"YYYY Q1",label:"2024 Q1 (YYYY Q1)"},{value:"1st Quarter YYYY",label:"1st Quarter 2024"},{value:"YYYY-Q1",label:"2024-Q1 (YYYY-Q1)"},{value:"Quarter 1, YYYY",label:"Quarter 1, 2024"},{value:"custom",label:"Custom Format..."}];case"year":return[{value:"YYYY",label:"2024 (YYYY)"},{value:"YY",label:"24 (YY)"},{value:"custom",label:"Custom Format..."}];default:return[{value:"MM-DD-YYYY",label:"01-15-2024 (MM-DD-YYYY)"},{value:"YYYY-MM-DD",label:"2024-01-15 (YYYY-MM-DD)"},{value:"MM/DD/YYYY",label:"01/15/2024 (MM/DD/YYYY)"},{value:"DD/MM/YYYY",label:"15/01/2024 (DD/MM/YYYY)"},{value:"MMMM DD, YYYY",label:"January 15, 2024 (MMMM DD, YYYY)"},{value:"MMM DD, YYYY",label:"Jan 15, 2024 (MMM DD, YYYY)"},{value:"DD MMM YYYY",label:"15 Jan 2024 (DD MMM YYYY)"},{value:"YYYY-MM",label:"2024-01 (YYYY-MM)"},{value:"MMMM YYYY",label:"January 2024 (MMMM YYYY)"},{value:"custom",label:"Custom Format..."}]}},z=H(P),J=!oe&&a!=="pivotBy",ie=se&&a==="groupBy",Ne=!oe&&se&&a==="groupBy",Te=oe&&se&&a==="groupBy",ne=oe&&a==="metrics"&&((nt=f.config)==null?void 0:nt.comparisonType)==="target",le=a==="metrics",ce=()=>e.jsx("div",{onPointerDown:W=>{W.stopPropagation()},className:"cursor-default overflow-hidden text-ellipsis whitespace-nowrap px-0.5 text-xs text-gray-500",children:`${t.entityName}.${t.name}`}),kn=()=>J?e.jsx(Ct,{value:t.label??"",onSave:G,placeholder:"Display label...",type:"text"}):null,tt=()=>ie?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:P,onValueChange:_,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(W=>e.jsx(s.SelectItem,{className:"text-xs",value:W,children:s.toTitleCase(W)},W))})]})]}):null,Tn=()=>Ne?e.jsxs(e.Fragment,{children:[tt(),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:L?"custom":O,onValueChange:F,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:z.map(W=>e.jsx(s.SelectItem,{className:"text-xs",value:W.value,children:W.label},W.value))})]}),L&&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:E,onChange:W=>{W.stopPropagation(),U(W.target.value)},onClick:W=>W.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,En=()=>{var W,ge,xe,qe,at;return Te?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(s.Label,{className:"text-xs font-medium text-muted-foreground",children:"Comparison Type"}),e.jsxs(s.Select,{value:((W=f.config)==null?void 0:W.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:"target",children:"Target Value"})]})]})]}),e.jsx("div",{className:"space-y-1",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(s.Label,{className:"text-xs font-medium text-muted-foreground",children:"Show Trendline"}),e.jsx(s.SmallSwitch,{checked:((ge=f.config)==null?void 0:ge.showTrendline)||!1,onCheckedChange:w})]})}),((xe=f.config)==null?void 0:xe.showTrendline)&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(s.Label,{className:"text-xs font-medium text-muted-foreground",children:"Trendline Window"}),e.jsx(s.Input$1,{type:"number",min:"1",max:"365",value:((qe=f.config)==null?void 0:qe.trendlineWindow)||30,onChange:An=>{const Ln=parseInt(An.target.value)||30;v(Ln)},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:((at=f.config)==null?void 0:at.trendlineGranularity)||"day",onValueChange:D,children:[e.jsx(s.SelectTrigger,{className:"h-8 w-full text-xs",children:e.jsx(s.SelectValue,{placeholder:"Select granularity..."})}),e.jsxs(s.SelectContent,{children:[e.jsx(s.SelectItem,{value:"day",children:"Day"}),e.jsx(s.SelectItem,{value:"week",children:"Week"}),e.jsx(s.SelectItem,{value:"month",children:"Month"})]})]})]})]})]}):null},In=()=>{var W,ge;return ne?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(Ct,{value:((W=f.config)==null?void 0:W.targetValue)!==void 0&&((ge=f.config)==null?void 0:ge.targetValue)!==null?String(f.config.targetValue):"",onSave:xe=>{!isNaN(Number(xe))&&xe!==null?b(Number(xe)):b(0)},placeholder:"Enter target value...",type:"text"})]}):null},Mn=()=>le?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(s.Label,{className:"text-xs font-medium text-muted-foreground",children:"Aggregation"}),e.jsxs(s.Select,{value:t.aggregate,onValueChange:W=>{x(n,W)},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.jsx(bn,{column:t}),i&&e.jsxs(e.Fragment,{children:[e.jsx(yi,{aliasTemplate:q,onAliasTemplateChange:Y}),e.jsx(vi,{valueAliases:K,onValueAliasesChange:Q})]})]}):null;return e.jsxs("div",{ref:m,style:te,...l,...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 ${p?"z-50 scale-95 opacity-50":"border-slate-200"} ${a==="filters"?"cursor-default":"cursor-move"}`,children:[e.jsxs("div",{className:"flex grow items-center gap-2",children:[e.jsx(Sn,{dataType:ae}),e.jsx(Js,{className:"w-[140px] flex-1 text-sm",children:t.label||t.name}),a!=="sortBy"&&e.jsx(s.Button,{variant:"ghost",size:"sm",className:"h-6 w-6 p-0 opacity-0 group-hover:opacity-100",onClick:W=>{W.stopPropagation(),S(!A)},children:e.jsx(s.ChevronDown,{className:`h-3 w-3 transition-transform ${A?"rotate-180":""}`})}),a==="sortBy"&&e.jsx(s.Button,{variant:"ghost",size:"sm",className:"h-6 w-6 p-0 group-hover:opacity-100",onClick:W=>{W.stopPropagation(),console.log("DraggableField - Current sortDirection:",r);const ge=r==="asc"?"desc":"asc";console.log("DraggableField - New direction to set:",ge),o(ge)},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 opacity-0 group-hover:opacity-100",onClick:W=>{W.stopPropagation(),Z()},children:e.jsx(s.X,{className:"h-3 w-3"})})]}),A&&e.jsxs("div",{className:"space-y-3",children:[ce(),kn(),c==="kpi"&&tt(),Tn(),En(),In(),Mn()]})]})}function Ni({concept:t}){const a=()=>{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$1,{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:a()})]})})}function Ze({zone:t,fields:a,label:n,placeholder:r,shouldShow:o,hasPivotColumns:i=!1}){const{isOver:c,setNodeRef:l}=s.useDroppable({id:t}),{updateSortByColumn:d}=s.useEditorActions(),m=s.useEditorStore(j=>j.card),u=s.useEditorStore(j=>j.card.type),h=a.length>0,p=(j,x)=>{var g;!((g=m.config)!=null&&g.sortByColumns)||m.config.sortByColumns.findIndex(C=>C.id===j)===-1||d(m.id,j,{direction:x})};if(t==="sortBy"&&o===!1)return null;const f=t!=="sortBy"&&u!=="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:n}),f&&e.jsx(Ni,{concept:t})]}),e.jsx("div",{ref:l,className:`min-h-[60px] rounded-lg border-2 border-dashed p-2 transition-all ${c?"border-blue-500 bg-blue-50 dark:bg-blue-950":h?"border-blue-200 bg-blue-50/30 dark:border-blue-800 dark:bg-blue-950/30":"border-muted-foreground/20 bg-background"}`,children:a.length===0?e.jsx("div",{className:"flex min-h-[40px] items-center justify-center text-sm text-gray-400",children:r}):e.jsx(s.SortableContext,{items:a.map(j=>j.id),strategy:s.verticalListSortingStrategy,children:e.jsx("div",{className:"flex flex-wrap gap-2",children:a.map((j,x)=>{const g=j.direction;return e.jsx("div",{className:"flex w-full items-center gap-2",children:e.jsx("div",{className:"flex-1",children:e.jsx(bi,{field:j,zone:t,index:x,sortDirection:g,onSortDirectionChange:C=>p(j.id,C),hasPivotColumns:i,cardType:u})})},j.id)})})})})]})}function Ci({groupByFields:t,pivotByFields:a,metricsFields:n,sortByFields:r}){const o=s.useEditorStore(h=>h.card),i=o==null?void 0:o.type,c=t.length>0||n.length>0,l=i!=="kpi",d=i!=="kpi"&&c,m=()=>i==="kpi"?{label:"Trend By",placeholder:"Drop fields to trend data"}:{label:"Rows",placeholder:"Drop fields to group data"},u=()=>i==="kpi"?{label:"Metric",placeholder:"Drop field for KPI"}:{label:"Metrics",placeholder:"Drop fields to measure"};return e.jsxs("div",{className:"w-full space-y-4",children:[e.jsx(Ze,{zone:"groupBy",fields:t,label:m().label,placeholder:m().placeholder}),l&&e.jsx(Ze,{zone:"pivotBy",fields:a,label:"Columns",placeholder:"Drop fields to pivot data"}),e.jsx(Ze,{zone:"metrics",fields:n,label:u().label,placeholder:u().placeholder,hasPivotColumns:a.length>0}),d&&e.jsx(Ze,{zone:"sortBy",fields:r,label:"Sort By",placeholder:"Drop fields from Rows or Metrics"})]})}function Si({selectedChart:t,onChartChange:a,groupByFields:n,pivotByFields:r,metricsFields:o,sortByFields:i}){const c=s.useEditorStore(h=>h.showAIDialog),l=n.length>0||r.length>0||o.length>0,{setShowAIDialog:d}=s.useEditorActions(),m=s.useEditorStore(h=>h.card),{data:u}=s.useDashboardCardQuery(m);return e.jsxs("div",{"data-content":"Chart Configuration Panel",className:"flex w-[350px] flex-col",children:[e.jsxs("div",{className:"space-y-4 px-6 pt-4",children:[e.jsx("div",{className:"flex items-center gap-2",children:e.jsx("h2",{className:"font-semibold",children:"Chart Configuration"})}),e.jsx(gi,{selectedChart:t,onChartChange:a})]}),e.jsxs("div",{className:s.cn("flex justify-end gap-2 px-6 pt-6"),children:[e.jsx("div",{className:s.cn("invisible",{visible:l||u}),children:e.jsx(ms,{})}),!c&&e.jsxs(s.Button,{onClick:()=>d(!c),variant:"outline",className:"h-8",size:"sm",children:[e.jsx(Ta,{className:"mr-2 size-4"}),"AI"]})]}),e.jsxs(s.ScrollArea,{className:"w-full flex-1 basis-0 px-6",children:[e.jsx(Ci,{groupByFields:n,pivotByFields:r,metricsFields:o,sortByFields:i}),e.jsx(s.ScrollBar,{orientation:"horizontal"})]})]})}function wi({initialFilters:t,availableFields:a}={}){const[n,r]=I.useState(t||{id:`group-${Date.now()}`,logicalOperator:"AND",negate:!1,conditions:[],groups:[]});s.useEditorStore(T=>T.card.dataSource);const{columns:o,isLoading:i}=s.useColumns(),l=a||o||[],d={id:"default",name:"default",dataType:"string",label:"Default",entityId:"default",entityName:"Default",entityType:"table"},m=T=>{const w=v=>{if(v.id===T){const D=l[0]||d;return{...v,conditions:[...v.conditions,{id:`condition-${Date.now()}`,field:D,operator:"=",value:""}]}}return{...v,groups:v.groups.map(w)}};r(w(n))},u=T=>{const w=v=>{if(v.id===T){const D=l[0]||d;return{...v,groups:[...v.groups,{id:`group-${Date.now()}`,logicalOperator:"AND",negate:!1,conditions:[{id:`condition-${Date.now()}`,field:D,operator:"=",value:""}],groups:[]}]}}return{...v,groups:v.groups.map(w)}};r(w(n))},h=(T,w)=>{const v=D=>D.id===T?{...D,conditions:D.conditions.filter(b=>b.id!==w)}:{...D,groups:D.groups.map(v)};r(v(n))},p=(T,w)=>{const v=D=>D.id===T?{...D,groups:D.groups.filter(b=>b.id!==w)}:{...D,groups:D.groups.map(v)};r(v(n))},f=(T,w,v,D)=>{if(v==="field")throw new Error("Use a dedicated method to update the field property with a Field object");const b=A=>A.id===T?{...A,conditions:A.conditions.map(S=>S.id===w?{...S,[v]:D}:S)}:{...A,groups:A.groups.map(b)};r(b(n))},j=(T,w,v)=>{const D=b=>b.id===T?{...b,conditions:b.conditions.map(A=>A.id===w?{...A,...v}:A)}:{...b,groups:b.groups.map(D)};r(D(n))},x=(T,w)=>{const v=D=>D.id===T?{...D,logicalOperator:w}:{...D,groups:D.groups.map(v)};r(v(n))},y=(T,w)=>{const v=D=>D.id===T?{...D,negate:w}:{...D,groups:D.groups.map(v)};r(v(n))},g=(T,w,v)=>{const D=b=>b.id===T?{...b,conditions:s.arrayMove(b.conditions,w,v)}:{...b,groups:b.groups.map(D)};r(D(n))},C=(T,w,v)=>{const D=b=>b.id===T?{...b,groups:s.arrayMove(b.groups,w,v)}:{...b,groups:b.groups.map(D)};r(D(n))},k=T=>{if(!T||T.conditions.length===0&&T.groups.length===0)return"-- No filters defined";const w=D=>{let b="";typeof D.field=="object"?b=D.field.entityName?`${D.field.entityName}.${D.field.name}`:D.field.name:b=String(D.field);const A=D.operator;let S=D.value;if(D.field.dataType==="string"&&!["in","not in"].includes(D.operator))typeof S=="string"?S=`'${S}'`:Array.isArray(S)&&(S=`'${S.join(", ")}'`);else if(D.field.dataType==="date")(typeof S=="string"||S instanceof Date)&&(S=`DATE('${S}')`);else if(["in","not in"].includes(D.operator)){let O=[];Array.isArray(S)?O=S.map(M=>typeof M=="string"?`'${M}'`:String(M)):typeof S=="string"?O=S.split(",").map(M=>{const E=M.trim();return D.field.dataType==="string"?`'${E}'`:E}):typeof S=="number"&&(O=[String(S)]),S=`(${O.join(", ")})`}switch(A){case"contains":return typeof S=="string"?`${b} LIKE '%${S.replace(/'/g,"")}'`:`${b} LIKE '%${String(S)}'`;case"startsWith":return typeof S=="string"?`${b} LIKE '${S.replace(/'/g,"")}%'`:`${b} LIKE '${String(S)}%'`;case"endsWith":return typeof S=="string"?`${b} LIKE '%${S.replace(/'/g,"")}'`:`${b} LIKE '%${String(S)}'`;default:return`${b} ${A} ${S}`}},v=D=>{const b=D.conditions.map(w),A=D.groups.map(E=>v(E)),S=[...b,...A].filter(Boolean);if(S.length===0)return"";const O=S.join(` ${D.logicalOperator} `),M=S.length>1?`(${O})`:O;return D.negate?`NOT ${M}`:M};return v(T)},R=n.conditions.length>0||n.groups.length>0;return{currentFilters:n,setCurrentFilters:r,availableFields:l,isLoading:i,addCondition:m,addGroup:u,removeCondition:h,removeGroup:p,updateCondition:f,updateConditionFields:j,updateGroupOperator:x,updateGroupNegate:y,reorderConditions:g,reorderGroups:C,generateSQLPreview:k,hasAnyFilters:R}}function Di({children:t,className:a,delayDuration:n}){return e.jsx(s.TooltipProvider$1,{children:e.jsxs(s.Tooltip,{delayDuration:n,children:[e.jsx(s.TooltipTrigger,{asChild:!0,children:e.jsx("div",{className:s.cn("w-[200px] overflow-hidden text-ellipsis whitespace-nowrap text-sm",a),children:t})}),e.jsx(s.PortalTooltipContent,{children:t})]})})}const ki=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(oa,{className:"h-3 w-3"});default:return e.jsx(s.Table,{className:"h-3 w-3"})}},Ti=t=>{if(t.qualifiedEntityName){const a=t.qualifiedEntityName.split(".");return a.length>1?a[0]:"default"}return"default"};function Ei({value:t,onValueChange:a,availableFields:n,placeholder:r="Select field",className:o="w-64"}){const[i,c]=I.useState(!1),l=I.useMemo(()=>{const d={};return n.forEach(m=>{const u=Ti(m);d[u]||(d[u]={}),d[u][m.entityId]||(d[u][m.entityId]=[]),d[u][m.entityId].push(m)}),d},[n]);return e.jsxs(s.Popover,{modal:!0,open:i,onOpenChange:c,children:[e.jsx(s.PopoverTrigger,{asChild:!0,children:e.jsxs(s.Button,{variant:"outline",role:"combobox","aria-expanded":i,className:s.cn("justify-between",!t&&"text-muted-foreground",o),children:[t?e.jsx("div",{className:"flex items-center gap-2",children:e.jsxs(Di,{children:[t.entityName,".",t.name]})}):r,e.jsx(s.ChevronsUpDown,{className:"ml-2 h-4 w-4 shrink-0 opacity-50"})]})}),e.jsx(s.PopoverContent,{className:"z-50 w-80 p-0",align:"start",children:e.jsxs(s.Command,{children:[e.jsx(s.CommandInput,{placeholder:"Search fields...",className:"h-9"}),e.jsx(s.CommandEmpty,{children:"No fields found."}),e.jsx(s.CommandList,{className:"max-h-80",children:Object.entries(l).map(([d,m])=>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(m).map(([u,h])=>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:[ki(h[0].entityType),e.jsx("span",{children:h[0].entityName})]}),h.map((p,f)=>e.jsxs(s.CommandItem,{value:p.id,onSelect:()=>{a(p),c(!1)},className:"overflow-x-auto",children:[e.jsx(s.Check,{className:s.cn("mr-2 h-4 w-4",(t==null?void 0:t.id)===p.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:p.name})}),e.jsx("div",{className:"flex items-center gap-2 text-xs text-gray-500",children:p.description&&e.jsx("span",{children:p.description})})]})]},p.id+f))]},`${d}-${u}`))},d))})]})})]})}function st(t){var j;const a=s.useEditorStore(x=>x.card),{authToken:n}=s.useSemaphorContext(),r=s.useEditorStore(x=>x.card.config),o=r==null?void 0:r.joinPlan,i={...t,alias:t.name,label:"value",role:"groupby"},c={...t,role:"metric",label:"count",alias:"count",aggregate:"COUNT"},l={...i,role:"sortby",direction:"asc"},d={joinPlan:o,groupByColumns:[i],metricColumns:[c],sortByColumns:[l]},m=((j=a.dataSource)==null?void 0:j.connectionId)||a.connectionId,{data:u,isPending:h,error:p}=s.useQuery({queryKey:["filterValues",t.entityId,t.name,t.qualifiedEntityName],queryFn:async()=>{try{return await s.postRequestRegular("https://semaphor.cloud/api/v1/query",(n==null?void 0:n.accessToken)||"",{connection_id:m,cardConfig:d,cardDataSource:a.dataSource})}catch(x){console.log(t),console.error("error",x)}},enabled:!!m,refetchOnMount:!0,refetchOnWindowFocus:!1});return{filterValues:((u==null?void 0:u.records)||[]).map(x=>({label:x[t.name]||"BLANK",value:x[t.name]||"BLANK",count:(x==null?void 0:x.count)||0})),isPending:h,error:p}}function Ii({field:t,selected:a,onChange:n,placeholder:r="Select items...",className:o}){const[i,c]=ue.useState(!1),{filterValues:l}=st(t),d=u=>{n(a.filter(h=>h!==u))},m=u=>{a.includes(u)?n(a.filter(h=>h!==u)):n([...a,u])};return e.jsx("div",{className:s.cn("w-full",o),children:e.jsxs(s.Popover,{open:i,onOpenChange:c,modal:!0,children:[e.jsx(s.PopoverTrigger,{asChild:!0,children:e.jsxs(s.Button,{variant:"outline",role:"combobox","aria-expanded":i,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:a.length>0?a.map(u=>{const h=l.find(p=>p.value===u);return e.jsxs(s.Badge,{variant:"secondary",className:"text-xs",children:[h==null?void 0:h.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:p=>{p.key==="Enter"&&d(u)},onMouseDown:p=>{p.preventDefault(),p.stopPropagation()},onClick:p=>{p.stopPropagation(),d(u)},children:e.jsx(s.X,{className:"h-3 w-3 text-muted-foreground hover:text-foreground"})})]},u)}):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:l.map((u,h)=>e.jsxs(s.CommandItem,{onSelect:()=>m(u.value),children:[e.jsx(s.Check,{className:s.cn("mr-2 h-4 w-4",a.includes(u.value)?"opacity-100":"opacity-0")}),e.jsxs("div",{className:"flex grow items-center justify-between gap-4",children:[e.jsx("span",{children:u.label}),e.jsx("span",{className:"text-xs text-muted-foreground",children:u.count})]})]},u.value+h))})]})]})})]})})}const wn=t=>{if(!t)return 0;let a=t.conditions.length;return t.groups.forEach(n=>{a+=wn(n)}),a};function Mi({field:t,value:a,onChange:n,placeholder:r="Select value...",className:o}){const{filterValues:i,isPending:c,error:l}=st(t);return c?e.jsxs("div",{className:"flex flex-1 items-center justify-center p-2 text-xs text-gray-500",children:[e.jsx(s.LoaderCircle,{className:"mr-2 size-3.5 animate-spin"})," Loading values..."]}):l?e.jsx("div",{className:"flex-1 p-2 text-xs text-red-500",children:"Error loading values"}):e.jsxs(s.Select,{value:a,onValueChange:n,children:[e.jsx(s.SelectTrigger,{className:o||"flex-1",children:e.jsx(s.SelectValue,{placeholder:r,children:a})}),e.jsx(s.SelectContent,{children:i.map((d,m)=>e.jsx(s.SelectItem,{className:"hover:bg-muted",value:d.value,children:d.label},d.value+m))})]})}const Ai=["=","!=",">",">=","<","<=","contains","startsWith","endsWith","in","not in"],Li=["=","!=","contains","startsWith","endsWith","in","not in"],Oi=["=","!=",">",">=","<","<=","in","not in"],Ri=["=","!="],Fi=["=","!=",">",">=","<","<=","in","not in"];function Bi(t){switch(t){case"string":return Li;case"number":return Oi;case"boolean":return Ri;case"date":return Fi;default:return Ai}}function Dn({condition:t,index:a,groupId:n,groupLogicalOperator:r,onUpdateCondition:o,onRemoveCondition:i,onUpdateGroupOperator:c,availableFields:l,updateConditionFields:d}){const{attributes:m,listeners:u,setNodeRef:h,transform:p,transition:f,isDragging:j}=s.useSortable({id:t.id}),{isPending:x,error:y}=st(t.field),g={transform:s.CSS.Transform.toString(p),transition:f};return e.jsxs("div",{ref:h,style:g,className:`mb-2 flex items-center gap-2 rounded p-2 hover:bg-muted/50 ${j?"z-50 opacity-50":""}`,children:[e.jsx("div",{...m,...u,className:"cursor-grab active:cursor-grabbing",children:e.jsx(s.GripVertical,{className:"h-4 w-4 flex-shrink-0 text-gray-400"})}),a>0&&e.jsxs(s.Select,{value:r,onValueChange:C=>c(n,C),children:[e.jsx(s.SelectTrigger,{className:"w-24",children:e.jsx(s.SelectValue,{})}),e.jsxs(s.SelectContent,{children:[e.jsx(s.SelectItem,{value:"AND",children:"AND"}),e.jsx(s.SelectItem,{value:"OR",children:"OR"})]})]}),a===0&&e.jsx("div",{className:"w-24"}),e.jsx(Ei,{value:t.field,onValueChange:C=>{d(n,t.id,{field:C,value:""})},availableFields:l,placeholder:"Select field",className:"w-64"}),e.jsxs(s.Select,{value:t.operator,onValueChange:C=>{C==="in"||C==="not in"?d(n,t.id,{operator:C,value:[]}):d(n,t.id,{operator:C,value:""})},children:[e.jsx(s.SelectTrigger,{className:"w-28",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{children:Bi(s.getDataType(t.field.dataType)).map(C=>e.jsx(s.SelectItem,{className:"hover:bg-muted",value:C,children:C},C))})]}),s.getDataType(t.field.dataType)==="string"?t.operator==="in"||t.operator==="not in"?x?e.jsxs("div",{className:"flex flex-1 items-center justify-center p-2 text-xs text-gray-500",children:[e.jsx(s.LoaderCircle,{className:"mr-2 size-3.5 animate-spin"})," Loading values..."]}):y?e.jsx("div",{className:"flex-1 p-2 text-xs text-red-500",children:"Error loading values"}):e.jsx(Ii,{field:t.field,selected:Array.isArray(t.value)&&t.value.every(C=>typeof C=="string")?t.value:[],onChange:C=>d(n,t.id,{value:C}),placeholder:`Select values for ${t.operator}...`,className:"flex-1"}):["contains","startsWith","endsWith"].includes(t.operator)?e.jsx(s.Input$1,{value:typeof t.value=="string"?t.value:"",onChange:C=>d(n,t.id,{value:C.target.value}),className:"flex-1",placeholder:t.operator.charAt(0).toUpperCase()+t.operator.slice(1)+"..."}):e.jsx(Mi,{field:t.field,value:typeof t.value=="string"?t.value:"",onChange:C=>d(n,t.id,{value:C}),placeholder:"Select value...",className:"flex-1"}):s.getDataType(t.field.dataType)==="boolean"?e.jsxs(s.Select,{value:typeof t.value=="boolean"?String(t.value):"",onValueChange:C=>d(n,t.id,{value:C==="true"}),children:[e.jsx(s.SelectTrigger,{className:"flex-1",children:e.jsx(s.SelectValue,{placeholder:"Select value..."})}),e.jsxs(s.SelectContent,{children:[e.jsx(s.SelectItem,{value:"true",children:"True"}),e.jsx(s.SelectItem,{value:"false",children:"False"})]})]}):e.jsx(s.Input$1,{value:typeof t.value=="string"||typeof t.value=="number"?t.value:"",onChange:C=>o(n,t.id,"value",C.target.value),className:"flex-1",placeholder:t.operator==="in"||t.operator==="not in"?"value1, value2, value3":"Value"}),e.jsx(s.Button,{variant:"ghost",size:"sm",className:"h-7 w-7 flex-shrink-0 p-0",onClick:()=>i(n,t.id),children:e.jsx(s.X,{className:"h-3 w-3"})})]})}function zi({group:t,depth:a,parentGroupId:n,onUpdateGroupOperator:r,onUpdateGroupNegate:o,onRemoveGroup:i,onUpdateCondition:c,onUpdateField:l,onRemoveCondition:d,onReorderConditions:m,onReorderGroups:u,onAddCondition:h,onAddGroup:p,availableFields:f,renderFilterGroup:j,updateConditionFields:x}){const{attributes:y,listeners:g,setNodeRef:C,transform:k,transition:R,isDragging:T}=s.useSortable({id:t.id}),w={transform:s.CSS.Transform.toString(k),transition:R},v=b=>{const{active:A,over:S}=b;if(S&&A.id!==S.id){const O=t.conditions.findIndex(E=>E.id===A.id),M=t.conditions.findIndex(E=>E.id===S.id);O!==-1&&M!==-1&&m(t.id,O,M)}},D=b=>{const{active:A,over:S}=b;if(S&&A.id!==S.id&&n){const O=t.groups.findIndex(E=>E.id===A.id),M=t.groups.findIndex(E=>E.id===S.id);O!==-1&&M!==-1&&u(n,O,M)}};return e.jsxs("div",{ref:C,style:w,className:`rounded-lg ${a>0?"mt-2 border border-border":""} ${T?"z-50 opacity-50":""}`,children:[a>0&&e.jsxs("div",{className:"flex items-center justify-between rounded-t-lg bg-muted p-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{...y,...g,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:()=>o(t.id,!t.negate),children:"NOT"}),e.jsxs(s.Select,{value:t.logicalOperator,onValueChange:b=>r(t.id,b),children:[e.jsx(s.SelectTrigger,{className:"h-7 w-20",children:e.jsx(s.SelectValue,{})}),e.jsxs(s.SelectContent,{children:[e.jsx(s.SelectItem,{className:"hover:bg-muted",value:"AND",children:"AND"}),e.jsx(s.SelectItem,{className:"hover:bg-muted",value:"OR",children:"OR"})]})]}),e.jsx("span",{className:"text-sm font-medium",children:"Group"})]}),e.jsx(s.Button,{variant:"ghost",size:"sm",className:"h-7 w-7 p-0",onClick:()=>n&&i(n,t.id),children:e.jsx(s.Trash2,{className:"h-3 w-3"})})]}),e.jsxs("div",{className:`p-3 ${a>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:v,children:e.jsx(s.SortableContext,{items:t.conditions.map(b=>b.id),strategy:s.verticalListSortingStrategy,children:t.conditions.map((b,A)=>e.jsx(Dn,{condition:b,index:A,groupId:t.id,groupLogicalOperator:t.logicalOperator,onUpdateCondition:c,onUpdateField:l,onRemoveCondition:d,onUpdateGroupOperator:r,availableFields:f,updateConditionFields:x},b.id))})}),e.jsx(s.DndContext,{sensors:s.useSensors(s.useSensor(s.PointerSensor),s.useSensor(s.KeyboardSensor,{coordinateGetter:s.sortableKeyboardCoordinates})),collisionDetection:s.closestCenter,onDragEnd:D,children:e.jsx(s.SortableContext,{items:t.groups.map(b=>b.id),strategy:s.verticalListSortingStrategy,children:t.groups.map(b=>j(b,a+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:()=>h(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:()=>p(t.id),children:[e.jsx(s.Plus,{className:"mr-1 h-3 w-3"}),"Add Group"]})]})]})]})}function Pi({filters:t,availableFields:a,onSave:n,onClearAll:r,onCancel:o}){const{currentFilters:i,availableFields:c,isLoading:l,addCondition:d,addGroup:m,removeCondition:u,removeGroup:h,updateCondition:p,updateConditionFields:f,updateGroupOperator:j,updateGroupNegate:x,reorderConditions:y,reorderGroups:g,generateSQLPreview:C,hasAnyFilters:k,setCurrentFilters:R}=wi({initialFilters:t,availableFields:a}),T=s.useSensors(s.useSensor(s.PointerSensor),s.useSensor(s.KeyboardSensor,{coordinateGetter:s.sortableKeyboardCoordinates})),[w,v]=I.useState(!1),D=(S,O,M)=>{const E=N=>N.id===S?{...N,conditions:N.conditions.map(L=>L.id===O?{...L,field:M,dataType:M.dataType}:L)}:{...N,groups:N.groups.map(E)};R(E(i))},b=(S,O=0,M)=>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:E=>{const{active:N,over:L}=E;if(L&&N.id!==L.id){const B=S.conditions.findIndex(V=>V.id===N.id),P=S.conditions.findIndex(V=>V.id===L.id);B!==-1&&P!==-1&&y(S.id,B,P)}},children:e.jsx(s.SortableContext,{items:S.conditions.map(E=>E.id),strategy:s.verticalListSortingStrategy,children:S.conditions.map((E,N)=>e.jsx(Dn,{condition:E,index:N,groupId:S.id,groupLogicalOperator:S.logicalOperator,onUpdateCondition:p,onUpdateField:D,onRemoveCondition:u,onUpdateGroupOperator:j,availableFields:c,updateConditionFields:f},E.id))})}),e.jsx(s.DndContext,{sensors:T,collisionDetection:s.closestCenter,onDragEnd:E=>{const{active:N,over:L}=E;if(L&&N.id!==L.id){const B=S.groups.findIndex(V=>V.id===N.id),P=S.groups.findIndex(V=>V.id===L.id);B!==-1&&P!==-1&&g(S.id,B,P)}},children:e.jsx(s.SortableContext,{items:S.groups.map(E=>E.id),strategy:s.verticalListSortingStrategy,children:S.groups.map(E=>b(E,O+1,S.id))})}),e.jsxs("div",{className:"mt-3 flex items-center gap-2",children:[e.jsxs(s.Button,{size:"sm",className:"h-7 text-xs",variant:"outline",onClick:()=>d(S.id),children:[e.jsx(s.Plus,{className:"mr-1 h-3 w-3"}),"Add Condition"]}),w&&e.jsxs(s.Button,{variant:"outline",size:"sm",className:"h-7 text-xs",onClick:()=>m(S.id),children:[e.jsx(s.Plus,{className:"mr-1 h-3 w-3"}),"Add Group"]})]})]})},S.id):e.jsx(zi,{group:S,depth:O,parentGroupId:M,onUpdateGroupOperator:j,onUpdateGroupNegate:x,onRemoveGroup:h,onUpdateCondition:p,onUpdateField:D,onRemoveCondition:u,onReorderConditions:y,onReorderGroups:g,onAddCondition:d,onAddGroup:m,availableFields:c,renderFilterGroup:b,updateConditionFields:f},S.id),A=wn(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:[l?e.jsxs("div",{className:"flex items-center justify-center p-4",children:[e.jsx("div",{className:"h-5 w-5 animate-spin rounded-full border-2 border-gray-300 border-t-gray-600"}),e.jsx("span",{className:"ml-2 text-sm text-gray-600",children:"Loading columns..."})]}):b(i),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.Checkbox,{id:"advanced-mode",checked:w,onCheckedChange:S=>v(!!S)}),e.jsx("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)"})]})}),k&&e.jsxs("div",{className:"mt-4 border-t border-border pt-4",children:[e.jsx("div",{className:"mb-2 text-xs font-medium text-muted-foreground",children:"SQL WHERE Clause Preview"}),e.jsx("div",{className:"overflow-x-auto rounded-md border bg-muted p-3",children:e.jsx("pre",{className:"whitespace-pre-wrap font-mono text-xs text-muted-foreground",children:C(i)})})]})]})})}),e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx(s.Button,{size:"sm",variant:"outline",onClick:o,children:"Cancel"}),A>0&&e.jsx(s.Button,{variant:"outline",size:"sm",onClick:r,children:"Clear All"}),e.jsx(s.Button,{size:"sm",onClick:()=>n(k?i:null),children:"Apply Filters"})]})]})}function Vi({cardId:t,filters:a,onFiltersChange:n,onClearFilters:r,availableFields:o,isOpen:i,onOpenChange:c}){const l=m=>{n(t,m),c(!1)},d=()=>{r(t),c(!1)};return e.jsxs(s.Dialog,{modal:!1,open:i,onOpenChange:c,children:[i&&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:m=>{m.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(Pi,{filters:a,availableFields:o,onSave:l,onCancel:()=>c(!1),onClearAll:d})]})]})}function _i({activeCardId:t,sourceFields:a,getFieldsForContainer:n,setFieldsForContainer:r}){var f;const[o,i]=I.useState(null),c=s.useEditorStore(j=>j.card),l=(f=c==null?void 0:c.config)==null?void 0:f.joinPlan,d=[...a,...n("groupBy"),...n("pivotBy"),...n("metrics"),...n("sortBy")],m=I.useCallback(j=>j.startsWith("card-")?null:j.startsWith("source-")||a.find(x=>x.id===j)?"source":n("groupBy").find(x=>x.id===j)?"groupBy":n("metrics").find(x=>x.id===j)?"metrics":n("pivotBy").find(x=>x.id===j)?"pivotBy":n("sortBy").find(x=>x.id===j)?"sortBy":null,[a,n]),u=I.useCallback(j=>{i(j.active.id)},[]),h=I.useCallback(j=>{const{active:x,over:y}=j;if(!y||!t){i(null);return}const g=x.id,C=y.id,k=m(g),R=m(C)||C;if(k==="source"&&R==="sortBy"){i(null);return}if(k==="source"&&R!=="source"&&R!=="sortBy"){const T=[...a].find(b=>b.id===g);if(!T){i(null);return}const w=[...n("groupBy"),...n("pivotBy"),...n("metrics"),...n("sortBy")];if(w.length>0){const b=w[0].qualifiedEntityName;if(!b){i(null);return}if(b!==T.qualifiedEntityName&&T.qualifiedEntityName)if(l){if(!Cn(b,T.qualifiedEntityName,l)){Is(),i(null);return}}else{Is(),i(null);return}}const v=n(R);if(Ms(T,v)){i(null);return}const D=s.getNewField(T,R);i(null),r(R,[...v,D]);return}if(k&&R&&k!=="source"&&R!=="source"&&k!==R){const T=n(k),w=n(R),v=T.find(A=>A.id===g);if(!v){i(null);return}const D=s.getNewField(v,R);if(i(null),R==="sortBy"){if(k==="pivotBy"){i(null);return}Ms(v,w)||r(R,[...w,D]);return}const b=T.filter(A=>A.id!==g);r(k,b),r(R,[...w,D]);return}if(k&&R&&k===R&&k!=="source"){const T=n(k),w=T.findIndex(D=>D.id===g),v=T.findIndex(D=>D.id===C);if(w!==v){const D=s.arrayMove(T,w,v);r(k,D)}}i(null)},[t,a,n,r,m,l]),p=o?d.find(j=>j.id===o):null;return{activeId:o,activeField:p,handleDragStart:u,handleDragEnd:h}}function Ui({onAdvancedToggle:t,onDebugToggle:a,onAccept:n}){const{currentUser:r}=be();r==null||r.role;const[o,i]=I.useState(!1),c=s.useEditorStore(g=>g.isDevMode),l=s.useEditorStore(g=>g.card),d=s.useEditorStore(g=>g.card.dataSource);s.isExplorerCard(l);const{config:m}=I.useContext(s.SemaphorContext).tokenProps,u=(m==null?void 0:m.showAdvancedMode)!==!1,{setIsDevMode:h}=s.useEditorActions(),p=s.useEditorStore(g=>g.showAIDialog),f=s.useEditorStore(g=>g.frame),j=s.useManagementStore(g=>g.selectedVisual),x=(j==null?void 0:j.id)===(f==null?void 0:f.id),{setShowAIDialog:y}=s.useEditorActions();return e.jsxs("div",{className:s.cn("flex items-center justify-between px-6 py-3",p&&"justify-end",!u&&"justify-end"),children:[u&&t&&!p&&e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(s.SmallSwitch,{className:s.cn("",{}),checked:c,onCheckedChange:()=>h(!c),id:"advanced-mode"}),e.jsx("label",{htmlFor:"advanced-mode",className:"text-sm font-medium",children:"Advanced Mode"})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[(r==null?void 0:r.type)!=="tenant"&&e.jsxs(s.DropdownMenu,{modal:!1,children:[e.jsx(s.DropdownMenuTrigger,{asChild:!0,children:e.jsx(s.Button,{variant:"ghost",size:"sm",className:"h-8 p-0",children:e.jsx(s.EllipsisVertical,{className:"size-3.5"})})}),e.jsx(s.DropdownMenuContent,{align:"end",children:e.jsxs(s.DropdownMenuItem,{onClick:()=>{i(!0)},children:[e.jsx(s.Database,{className:"mr-2 h-4 w-4"}),"Set Data Context"]})})]}),e.jsx($s,{}),n&&!x&&e.jsx(qs,{variant:"default"}),x&&e.jsx(Wr,{}),a&&s.isDevEnv]}),o&&e.jsx(s.DataSourceDialog,{incomingSelectedEntities:(d==null?void 0:d.selectedEntities)||[],open:o,onOpenChange:i,dataSource:d||s.EMPTY_DATA_SOURCE,fallbackDataSource:s.EMPTY_DATA_SOURCE,dialogMode:"aiContext"})]})}function qi({activeView:t,onViewChange:a}){const n=s.useEditorStore(o=>o.card),{errorMessage:r}=s.useDashboardCardQuery(n);return e.jsx(s.Tabs,{value:t,onValueChange:o=>a(o),children:e.jsxs(s.TabsList,{className:"h-9 w-fit gap-2 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"}),n.type!=="kpi"&&e.jsx(s.TabsTrigger,{value:"sql",className:s.cn("rounded-md transition data-[state=active]:bg-muted",r&&"text-destructive data-[state=active]:bg-destructive/10 data-[state=active]:text-destructive"),children:r?"Error":"Query"})]})})}const $i=[{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 Yi(){var d,m;const t=s.useEditorStore(u=>u.card),{updateRowLimit:a}=s.useEditorActions(),[n,r]=I.useState(!1),[o,i]=I.useState(""),c=u=>{if(u==="custom"){r(!0);return}r(!1),a(t.id,parseInt(u))},l=u=>{const h=u.target.value;i(h),h&&!isNaN(parseInt(h))&&a(t.id,parseInt(h))};return e.jsx("div",{className:"flex items-center gap-2",children:n?e.jsx(s.Input,{type:"number",value:o,onChange:l,className:"h-7 w-24",placeholder:"Enter limit",min:1}):e.jsxs(s.Select,{value:((m=(d=t.config)==null?void 0:d.rowLimit)==null?void 0:m.toString())||"100",onValueChange:c,children:[e.jsx(s.SelectTrigger,{className:"h-8 w-24 border-none px-1 [&>svg]:hidden",children:e.jsx(s.SelectValue,{placeholder:"Select limit"})}),e.jsx(s.SelectContent,{children:$i.map(u=>e.jsx(s.SelectItem,{value:u.value,children:u.label},u.value))})]})})}function Gi({isOpen:t,onClose:a}){const n=Gt(a,{enabled:t}),r=s.useEditorStore(u=>{var h;return((h=u.card.customCardPreferences)==null?void 0:h.url)||""}),o=s.useEditorStore(u=>u.card),i=s.useEditorStore(u=>{var h;return((h=u.card.customCardPreferences)==null?void 0:h.pluginChartType)||""}),c=s.useEditorStore(u=>{var h;return((h=u.card.customCardPreferences)==null?void 0:h.settings)||{}}),{data:l}=s.useDashboardCardQuery(o),{getCard:d}=s.useCustomVisual(r),m=I.useMemo(()=>!r||r.trim()===""?null:d("Chart Settings"),[d,r]);return e.jsx("div",{ref:n,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:a,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:m&&e.jsx(I.Suspense,{fallback:e.jsx("div",{children:"Loading chart settings..."}),children:e.jsx(m,{chartData:(l==null?void 0:l.records)||[],chartType:i,settings:c})})})]})})}function Hi({activeView:t,onViewChange:a,showDebug:n,onDebugToggle:r,onAccept:o,onClear:i,onAdvancedToggle:c,onFiltersClick:l,filterCount:d,activeCard:m,columns:u,columnsLoading:h,columnsError:p}){var L;const f=s.useEditorStore(B=>B.card);s.useEditorStore(B=>B.frame);const j=s.useDashboardStore(B=>B.filterValues),{updateCardConfig:x,setCard:y,updateCardInFrame:g}=s.useEditorActions(),C=s.useEditorStore(B=>B.showAIDialog),[k,R]=I.useState(!1),T=s.useEditorStore(B=>{var P;return((P=B.card.customCardPreferences)==null?void 0:P.url)&&B.card.type==="custom"}),{data:w,errorMessage:v,isPending:D,isLoading:b,isFetching:A,pagination:S}=s.useDashboardCardQuery(m),O=(B,P)=>{const V={...m,paginationConfig:{page:B+1,pageSize:P}};y(V),g(V)};function M(){return e.jsx("div",{className:"border-b border-border bg-background p-4",children:e.jsxs("div",{className:"space-y-4",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(f.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(j||{},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(m.dataSource||{},null,2)})]}),e.jsxs("div",{children:[e.jsxs("h3",{className:"mb-2 text-sm font-medium",children:["Columns (",u.length,")"]}),e.jsx("pre",{className:"max-h-40 overflow-auto rounded border bg-background p-3 text-xs",children:h?"Loading...":p?"Error loading columns":JSON.stringify(u.slice(0,5),null,2)})]})]})})}const E=B=>{if(!f.config)return;if(!B.length){x(f.id,{...f.config,sortByColumns:[]});return}const P=f.config,V=B.map(({id:q,desc:X})=>{var U,_;const K=(U=P.metricColumns)==null?void 0:U.find(Y=>Y.label===q),$=(_=P.groupByColumns)==null?void 0:_.find(Y=>Y.label===q),F=K||$;return F?{id:s.getFieldId("sortBy",F),name:F.name,dataType:F.dataType,label:F.label,qualifiedEntityName:F.qualifiedEntityName,entityId:F.entityId,entityName:F.entityName,entityType:F.entityType,role:"sortby",direction:X?"desc":"asc"}:null}).filter(q=>q!==null);x(f.id,{...P,sortByColumns:V})},N=I.useMemo(()=>{var B,P;return(P=(B=f.config)==null?void 0:B.sortByColumns)==null?void 0:P.map(V=>({id:V.label,desc:V.direction==="desc"}))},[(L=f.config)==null?void 0:L.sortByColumns]);return e.jsxs("div",{className:"relative flex w-0 grow flex-col",children:[e.jsx(Ui,{showDebug:n,onDebugToggle:r,onAccept:o,onClear:i,onAdvancedToggle:c,onFiltersClick:l,filterCount:d}),n&&M(),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"&&C&&e.jsx(hn,{variant:"outline"}),e.jsx(qi,{activeView:t,onViewChange:a}),l&&e.jsxs(s.IconButton,{tooltip:"Card Filters",className:"h-8 gap-1",onClick:l,children:[e.jsx(s.Filter,{className:"h-3.5 w-3.5"}),d>0&&e.jsx("span",{className:"ml-1 rounded-full bg-blue-100 px-1.5 py-0.5 text-xs text-blue-800",children:d})]}),e.jsx("div",{className:"ml-2",children:e.jsx(Yi,{})}),C&&e.jsx(ms,{})]}),e.jsx("div",{className:s.cn("flex grow items-center justify-end"),children:t==="chart"&&e.jsx(xn,{})})]}),!k&&T&&e.jsx(s.IconButton,{"aria-label":"Open Chart Settings",tooltip:"Open Chart Settings",onClick:()=>R(!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(wa,{className:"size-4"})}),e.jsxs("div",{className:"mt-3 flex grow flex-col",children:[t==="chart"&&e.jsx("div",{className:"flex grow flex-col pb-6",children:e.jsx(pn,{})}),t==="table"&&(w==null?void 0:w.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:m,data:(w==null?void 0:w.records)||[],paginationMetadata:S,onPaginationChange:O,isLoading:b||A,onSortChange:E,sortState:N})}),t==="sql"&&e.jsx("div",{className:"p-6",children:e.jsxs("div",{className:"rounded-md bg-background",children:[(w==null?void 0:w.sql)&&e.jsx("h3",{className:"mb-3 text-sm font-medium",children:"Generated SQL Query"}),e.jsx(rn,{sql:w==null?void 0:w.sql,error:v})]})})]}),e.jsx(Gi,{isOpen:k,onClose:()=>R(!1)})]})]})}function Qi({activeField:t}){const[a,n]=I.useState(!0);return I.useEffect(()=>{t&&n(!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 ${a?"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(Sn,{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 Ki=()=>{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 a=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},n=r=>{var o;if((o=r.reason)!=null&&o.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",a,!0),window.addEventListener("unhandledrejection",n,!0),()=>{console.error=t,window.removeEventListener("error",a,!0),window.removeEventListener("unhandledrejection",n,!0)}};function Wi(){var $,F;const[t,a]=I.useState("chart"),[n,r]=I.useState(!1),[o,i]=I.useState(!1),[c,l]=I.useState(!0),d=s.useEditorStore(U=>U.showAIDialog),m=s.useDashboardStore(U=>U.isVisualEditing),{setCardType:u}=s.useEditorActions(),h=s.useEditorStore(U=>U.card.type);I.useEffect(()=>Ki(),[]);const p=()=>{console.log("Accept clicked - would save/apply current configuration")},f=()=>{console.log("Clear clicked - would reset all configurations")},j=()=>{console.log("Advanced mode toggled")},x=()=>{i(!0)},y=U=>{u(U)},g=s.useEditorStore(U=>U.frame),C=s.useEditorStore(U=>U.card);s.useEditorStore(U=>U.activeTabCardId),s.useEditorStore(U=>U.actions.getAvailableFields);const{addCard:k,removeCard:R,updateCard:T,setActiveCard:w,updateFilters:v}=s.useEditorActions(),{columns:D=[],isLoading:b,error:A}=s.useColumns(),S=s.useSensors(s.useSensor(s.PointerSensor,{activationConstraint:{distance:8}})),O=C,{getFieldsForContainer:M,setFieldsForContainer:E}=Zs(O),{activeField:N,handleDragStart:L,handleDragEnd:B}=_i({activeCardId:g.activeCardId,sourceFields:D,getFieldsForContainer:M,setFieldsForContainer:E}),P=(U,_)=>{_&&v(U,_)},V=U=>{var _;T(U,{config:{...(_=g.cards.find(Y=>Y.id===U))==null?void 0:_.config,filters:void 0}})},q=D,X=U=>{if(!U)return 0;let _=U.conditions.length;return U.groups.forEach(Y=>{_+=X(Y)}),_},K=X((($=O==null?void 0:O.config)==null?void 0:$.filters)||null);return e.jsxs(s.DndContext,{sensors:S,collisionDetection:s.closestCenter,onDragStart:L,onDragEnd:B,children:[e.jsxs("div",{className:"flex h-full grow",children:[e.jsx(xi,{isVisible:c,onToggleVisibility:()=>l(!c)}),e.jsxs("div",{className:"flex flex-1 transition-all duration-300 ease-in-out",children:[!d&&e.jsx(Si,{selectedChart:h,onChartChange:y,groupByFields:M("groupBy"),pivotByFields:M("pivotBy"),metricsFields:M("metrics"),sortByFields:M("sortBy")}),e.jsx(Hi,{selectedChart:h,activeView:t,onViewChange:a,showDebug:n,onDebugToggle:()=>r(!n),onAccept:p,onClear:f,onAdvancedToggle:j,onFiltersClick:x,filterCount:K,activeCard:O,dataSourceState:C.dataSource||s.EMPTY_DATA_SOURCE,columns:D,columnsLoading:b,columnsError:A,getFieldsForContainer:M,cards:g.cards,activeCardId:g.activeCardId,addCard:k,setActiveCard:w})]}),!c&&m&&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:()=>l(!0),title:"Show Data Source Panel",children:e.jsx(s.Database,{className:"h-4 w-4"})})})]}),O&&e.jsx(Vi,{cardId:O.id,filters:((F=O.config)==null?void 0:F.filters)||null,onFiltersChange:P,onClearFilters:V,availableFields:q,isOpen:o,onOpenChange:i}),e.jsx(s.DragOverlay,{dropAnimation:null,children:e.jsx(Qi,{activeField:N||null})})]})}function Ji({authToken:t,onSave:a,onClose:n}){const r=I.useRef(null),o=s.useEditorStore(C=>C.showAIDialog),i=s.useEditorStore(C=>C.isDevMode),{setAuthToken:c}=s.useDashboardActions(),{setShowAIDialog:l,setOnSave:d,setOnClose:m}=s.useEditorActions(),{handleDragOver:u,handleDragEnd:h,handleDragStart:p,handleDragCancel:f,sensors:j}=Br();I.useEffect(()=>{a&&d(a),n&&m(n)},[a,d,n,m]),I.useEffect(()=>{t&&t.accessToken&&c(t)},[t,c]),I.useEffect(()=>{var C,k;o?((C=r.current)==null||C.resize(40),l(!0)):(l(!1),(k=r.current)==null||k.resize(0))},[o,l]);function x(C){C<1?l(!1):o||l(!0)}function y(){return e.jsxs(e.Fragment,{children:[e.jsx(nn,{type:"main"}),e.jsxs(s.ResizablePanelGroup,{"data-content":"editor-main",className:"grow",direction:"horizontal",children:[e.jsx(s.ResizablePanel,{className:"min-w-[510px] rounded-none",children:e.jsx(Zo,{})}),e.jsx(s.ResizableHandle,{}),e.jsx(s.ResizablePanel,{"data-role":"editor-assistant-panel",ref:r,onResize:x,defaultSize:0,children:e.jsx(yt,{})})]})]})}function g(){return e.jsxs(s.ResizablePanelGroup,{"data-content":"explorer",className:"flex grow",direction:"horizontal",children:[e.jsx(s.ResizablePanel,{className:"min-w-[510px] grow rounded-none",children:e.jsx(Wi,{})}),e.jsx(s.ResizableHandle,{}),e.jsx(s.ResizablePanel,{"data-role":"editor-assistant-panel",ref:r,onResize:x,defaultSize:0,children:e.jsx(yt,{})})]})}return e.jsx(s.ErrorBoundary,{FallbackComponent:s.Fallback,children:i?e.jsx(s.DndContext,{sensors:j,onDragStart:p,onDragEnd:h,onDragOver:u,onDragCancel:f,children:e.jsx("section",{className:"isolate flex h-full grow","data-content":"editor-panel",children:y()})}):g()})}function Xi(){s.useDashboardStore(c=>c.selectedCardId);const t=s.useDashboardStore(c=>c.selectedSheetId),{setIsVisualEditing:a}=s.useDashboardStore(c=>c.actions),n=s.useDashboardStore(c=>c.isVisualEditing),r=s.useDashboardStore(c=>c.actions.updateFrame);function o(c){t&&(r(t,c),a(!1))}function i(){a(!1)}return e.jsx("div",{role:"editor-container",className:s.cn("flex-1 grow basis-0 overflow-auto",{"max-h-0 overflow-hidden":!n}),children:e.jsx(Ji,{onSave:o,onClose:i})})}function Zi(){const t=s.useEditorStore(i=>i.selectedDatabaseName),a=s.useEditorStore(i=>i.selectedTableName),n=s.useDashboardStore(i=>i.dashboard.filters)||[],{columns:r}=s.useEditorAside(),{assignFilter:o}=yn();return e.jsx(s.ScrollArea,{className:"flex-1 basis-0 flex-col px-3",children:r==null?void 0:r.map(i=>{const c=n==null?void 0:n.find(l=>l.column===s.fmt(i.column_name)&&l.table===a&&l.database===t);return e.jsx("div",{onClick:()=>o(i),className:s.cn("group flex cursor-pointer items-center justify-between border border-dashed border-background px-3 py-[6px] text-sm transition-colors hover:bg-muted/50",{"bg-muted":c}),children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(_s,{column:i}),e.jsx("span",{children:i.column_name})]})},i.column_name)})})}function el(){s.useDashboardStore(a=>a.showFilters);const t=s.useDashboardStore(a=>a.actions.setShowFilters);return e.jsxs("section",{className:"relative flex min-w-[320px] grow flex-col border-l px-1",children:[e.jsxs("div",{className:"mt-4 flex items-center justify-between gap-2 px-3",children:[e.jsx(s.Label,{className:"px-2 text-lg",children:"Filters"}),e.jsx(s.Button,{onClick:()=>t(!1),className:"h-7 w-7 p-0",variant:"ghost",children:e.jsx(s.Cross2Icon,{})})]}),e.jsx("div",{className:"flex grow",children:e.jsx(nn,{type:"filter",ColumnsComponent:()=>e.jsx(Zi,{})})})]})}function sl(){const t=s.useDashboardStore(r=>r.dashboard.filters),a=s.useDashboardStore(r=>r.theme),n=t==null?void 0:t.filter(r=>r.hide);return n!=null&&n.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)]":a==="light","bg-[repeating-linear-gradient(45deg,_#18171d_0_3px,_#272729_3px_6px)]":a==="dark"}),children:n==null?void 0:n.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 tl(){const t=s.useDashboardStore(r=>r.showFilters),a=s.useDashboardStore(r=>r.isVisualEditing),n=s.useDashboardStore(r=>r.isDashboardEditing);return e.jsxs("div",{role:"dashboard-plus-main",className:s.cn("",{"max-h-0 overflow-hidden":a,"flex grow overflow-auto":!a}),children:[e.jsxs("section",{className:"flex grow flex-col",children:[n&&e.jsx(sl,{}),e.jsx(s.DashboardTabs,{})]}),t&&e.jsx("div",{role:"filter-aside-container",className:"flex",children:e.jsx(el,{})})]})}function nl(){const t=s.useDashboardStore(o=>o.dashboard),a=s.useDashboardStore(o=>o.actions.setDashboard),n=s.useDashboardStore(o=>o.showDashboardJSON),r=s.useDashboardStore(o=>o.actions.setShowDashboardJSON);return e.jsxs("div",{className:s.cn("relative p-2",{hidden:!n}),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:o=>{if(o)try{JSON.parse(o),a(JSON.parse(o))}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 al({showControls:t=!1,showFooter:a=!0,...n}){return typeof window>"u"?null:e.jsx(s.ErrorBoundary,{FallbackComponent:s.Fallback,children:e.jsxs(s.SemaphorContextProvider,{dashboardProps:n,children:[e.jsx(s.$e,{}),e.jsxs(s.UXProvider,{children:[e.jsx(nl,{}),e.jsxs("main",{className:"relative flex h-full w-full flex-col",children:[t&&e.jsx(Ar,{}),e.jsxs(s.DashboardPanel,{...n,children:[e.jsx(Xi,{}),e.jsx(tl,{})]})]})]})]})})}exports.DashboardPlus=al;exports.ResourceManagementPanel=sn;exports.ScheduleDashboard=Bt;exports.SelectComponent=Pe;exports.cleanCard=Ot;exports.downloadPdf=Ft;exports.getDashbaordStateWithoutData=ns;
|
|
435
|
+
ON ${C}`}),j};return i.length<2?null:e.jsx(e.Fragment,{children:e.jsx("div",{className:"space-y-4",children:e.jsxs("div",{className:"flex items-center justify-between",children:[n.joins.length>0&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(s.TooltipProvider$1,{children:e.jsxs(s.Tooltip,{children:[e.jsx(s.TooltipTrigger,{asChild:!0,children:e.jsxs(s.Button,{variant:"outline",size:"sm",className:"h-6 text-xs font-semibold",onClick:()=>o(!0),children:[e.jsx(s.Link,{className:s.cn("mr-1 h-3 w-3",{"text-blue-500":n.joins.length>0,"text-gray-500":n.joins.length===0})}),"Join",n.joins.length>1?"s":""," (",n.joins.length,")"]})}),e.jsx(s.TooltipContent,{side:"right",className:"max-w-md overflow-hidden p-0",children:e.jsx(ci,{joins:n.joins,baseEntityId:n.baseEntity.name,availableDataSources:i,generateSQLPreview:m})})]})}),e.jsx(vt,{open:r,onOpenChange:o,joinPlan:n,availableDataSources:i,onSave:c,onCancel:d,onRemove:l,children:e.jsx("div",{})})]}),n.joins.length===0&&e.jsx(vt,{open:r,onOpenChange:o,joinPlan:n,availableDataSources:i,onSave:c,onCancel:d,onRemove:l,children:e.jsxs(s.Button,{onClick:()=>o(!0),variant:"outline",size:"sm",className:"w-full",children:[e.jsx(s.Link,{className:"mr-3 size-4"}),"Configure Joins"]})})]})})})}function ui({open:t,onOpenChange:a}){const[n,r]=I.useState([]),{updateDataSource:o}=s.useEditorActions(),i=s.useDashboardStore(x=>x.dashboard.aiContext),c=(i==null?void 0:i.selectedEntities)||[];I.useEffect(()=>{t&&r([])},[t]);const l=x=>{r(y=>y.some(C=>C.name===x.name&&C.type===x.type)?y.filter(C=>!(C.name===x.name&&C.type===x.type)):[...y,x])},d=()=>{r([...c])},m=()=>{r([])},u=()=>{if(n.length===0)return;const x=n[0],y=x.connectionId||"",g=x.connectionType||"",k=n.some(T=>T.type==="dataset")?"semanticDomain":"database";o({connectionId:y,connectionType:g,mode:k,selectedEntities:n}),a(!1)},h=x=>{switch(x.type){case"table":return e.jsx(s.Table,{className:"h-4 w-4"});case"view":return e.jsx(Ma,{className:"h-4 w-4"});case"model":return e.jsx(sa,{className:"h-4 w-4"});case"dataset":return e.jsx(s.Database,{className:"h-4 w-4"});case"file":case"url":case"upload":return e.jsx(s.FileText,{className:"h-4 w-4"});default:return e.jsx(s.Database,{className:"h-4 w-4"})}},p=x=>"label"in x&&x.label?x.label:x.name,f=x=>{if("description"in x&&x.description)return x.description;const y=[];return x.database&&y.push(x.database),x.schema&&y.push(x.schema),x.name&&y.push(x.name),y.join(".")},j=x=>n.some(y=>y.name===x.name&&y.type===x.type);return c.length===0?e.jsx(s.Dialog,{open:t,onOpenChange:a,children:e.jsxs(s.DialogContent,{className:"max-w-md",children:[e.jsxs(s.DialogHeader,{children:[e.jsx(s.DialogTitle,{children:"No Data Available"}),e.jsx(s.DialogDescription,{children:"No entities are currently available in the AI context. Please add some data sources to the dashboard first."})]}),e.jsx(s.DialogFooter,{children:e.jsx(s.Button,{onClick:()=>a(!1),children:"Close"})})]})}):e.jsx(s.Dialog,{open:t,onOpenChange:a,children:e.jsxs(s.DialogContent,{className:"flex max-w-2xl flex-col",children:[e.jsxs(s.DialogHeader,{children:[e.jsx(s.DialogTitle,{children:"Select Data to Analyze"}),e.jsx(s.DialogDescription,{children:"Choose entities from the dashboard's context"})]}),e.jsxs("div",{className:"flex-1 space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(s.Button,{variant:"outline",size:"sm",onClick:d,disabled:n.length===c.length,children:"Select All"}),e.jsx(s.Button,{variant:"outline",size:"sm",onClick:m,disabled:n.length===0,children:"Clear All"})]}),e.jsxs(s.Badge,{variant:"secondary",children:[n.length," of ",c.length," selected"]})]}),e.jsx(s.Separator,{}),e.jsx(s.ScrollArea,{className:"h-64",children:e.jsx("div",{className:"space-y-2",children:c.map((x,y)=>e.jsxs("div",{className:s.cn("flex items-center gap-3 rounded-lg border p-3 transition-colors hover:bg-muted/50",j(x)&&"border-primary bg-primary/5"),children:[e.jsx(s.Checkbox,{checked:j(x),onCheckedChange:()=>l(x)}),e.jsx("div",{className:"flex items-center gap-2 text-muted-foreground",children:h(x)}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:"truncate font-medium",children:p(x)}),e.jsx("div",{className:"truncate text-sm text-muted-foreground",children:f(x)})]}),e.jsx(s.Badge,{variant:"outline",className:"text-xs",children:x.type})]},`${x.type}-${x.name}-${y}`))})})]}),e.jsx(s.DialogFooter,{children:e.jsx("div",{className:"flex w-full justify-between",children:e.jsxs("div",{className:"flex grow justify-end gap-2",children:[e.jsx(s.Button,{variant:"outline",onClick:()=>a(!1),children:"Cancel"}),e.jsxs(s.Button,{onClick:u,disabled:n.length===0,children:["Select"," ",n.length>0?`(${n.length})`:""]})]})})})]})})}function mi({entity:t,title:a,maxDetails:n=10}){const o=s.getEntityDetails(t).slice(0,n),i=o.find(l=>l.label==="Description"),c=o.filter(l=>l.label==="Description"?!1:!["Connection","Database","Schema"].includes(l.label));return e.jsx(s.TooltipContent,{side:"top",className:"ml-5 max-w-xs",children:e.jsxs("div",{className:"space-y-2",children:[e.jsx("div",{className:"text-sm font-medium",children:a||s.getDisplayName(t)}),i&&e.jsxs("div",{className:"border-t border-border pt-2",children:[e.jsx("div",{className:"mb-1 text-xs text-muted-foreground",children:"Description:"}),e.jsx("div",{className:"text-xs leading-relaxed",children:i.value})]}),c.length>0&&e.jsx("div",{className:"space-y-0.5",children:c.map((l,d)=>e.jsxs("div",{className:"flex justify-between text-xs",children:[e.jsxs("span",{className:"mr-2 text-muted-foreground",children:[l.label,":"]}),e.jsx("span",{className:"font-mono",children:l.value})]},d))})]})})}function hi({entities:t}){return e.jsx(s.TooltipContent,{side:"top",className:"ml-5 max-w-xs",children:e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"text-sm font-medium",children:[t.length," more entities"]}),e.jsx("div",{className:"space-y-1",children:t.map((a,n)=>{const r=s.getEntityDetails(a),o=r.find(c=>c.label==="Description"),i=r.filter(c=>c.label==="Description"?!1:!["Connection","Database","Schema"].includes(c.label)).slice(0,3);return e.jsxs("div",{className:"border-b border-border pb-1 last:border-b-0",children:[e.jsx("div",{className:"text-xs font-medium",children:s.getDisplayName(a)}),o&&e.jsxs("div",{className:"mb-1 mt-1",children:[e.jsx("div",{className:"text-xs text-muted-foreground",children:"Description:"}),e.jsx("div",{className:"text-xs leading-relaxed",children:o.value})]}),i.length>0&&e.jsx("div",{className:"mt-1 space-y-0.5",children:i.map((c,l)=>e.jsxs("div",{className:"flex justify-between text-xs",children:[e.jsxs("span",{className:"mr-2 text-muted-foreground",children:[c.label,":"]}),e.jsx("span",{className:"font-mono",children:c.value})]},l))})]},`remaining-${a.type}-${a.name}-${n}`)})})]})})}function xi({isVisible:t,onToggleVisibility:a}){const[n,r]=I.useState(!1),[o,i]=I.useState(!1),[c,l]=I.useState(!0),d=s.useEditorStore(p=>p.card.dataSource);be();const{updateDataSource:m}=s.useEditorActions(),u={connectionId:"",connectionType:"",mode:"database",selectedEntities:[]},h={...u,...d,selectedEntities:(d==null?void 0:d.selectedEntities)||[]};return e.jsxs("div",{className:s.cn("flex flex-col overflow-hidden bg-background transition-all duration-300 ease-in-out",{"w-[325px]":t,"w-0":!t}),children:[e.jsxs("div",{children:[e.jsx("div",{className:s.cn("p-4 px-6",{"pb-0":!c}),children:e.jsxs("div",{className:"flex w-full items-center justify-between",children:[e.jsxs("div",{className:"flex cursor-pointer items-center gap-2",children:[e.jsx("h2",{className:"text-brand-100 font-semibold",children:"Data Source"}),e.jsx(s.Button,{variant:"ghost",size:"sm",onClick:()=>l(!c),className:"h-6 w-6 p-0",children:c?e.jsx(s.ChevronDown,{className:"h-4 w-4"}):e.jsx(s.ChevronRight,{className:"h-4 w-4"})})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(s.Button,{size:"sm",variant:"ghost",className:"h-7 w-7 p-0 text-muted-foreground hover:text-foreground",onClick:a,title:"Hide Data Source Panel",children:e.jsx(s.EyeOff,{className:"h-3.5 w-3.5"})}),e.jsxs(s.Button,{size:"sm",variant:"outline",className:"h-7",onClick:()=>r(!0),children:[e.jsx(s.Plus,{className:"mr-1 h-3.5 w-3.5"}),"Add"]})]})]})}),e.jsxs("div",{className:`overflow-hidden px-6 ${c?"max-h-96 space-y-4":"max-h-0 py-0 opacity-0"}`,children:[h.selectedEntities.length>0&&e.jsx(s.TooltipProvider$1,{children:e.jsxs("div",{className:"flex flex-wrap gap-1",children:[h.selectedEntities.slice(0,3).map((p,f)=>e.jsxs(s.Tooltip,{children:[e.jsx(s.TooltipTrigger,{asChild:!0,children:e.jsxs(s.Badge,{variant:"secondary",className:"group relative cursor-pointer pr-6 text-xs transition-colors hover:border-red-200 hover:bg-red-50 dark:hover:border-red-800 dark:hover:bg-red-950",children:[s.getDisplayName(p),e.jsx("button",{onClick:j=>{j.stopPropagation();const x=h.selectedEntities.filter(y=>!(y.name===p.name&&y.type===p.type));m({...u,...d,selectedEntities:x})},className:"absolute right-1 top-1/2 -translate-y-1/2 rounded-full p-0.5 hover:bg-red-100",children:e.jsx(s.X,{className:"h-2.5 w-2.5 group-hover:text-red-500"})})]})}),e.jsx(mi,{entity:p})]},`${p.type}-${p.name}-${f}`)),h.selectedEntities.length>3&&e.jsxs(s.Tooltip,{children:[e.jsx(s.TooltipTrigger,{asChild:!0,children:e.jsxs(s.Badge,{variant:"outline",className:"text-xs",children:["+",h.selectedEntities.length-3," more"]})}),e.jsx(hi,{entities:h.selectedEntities.slice(3)})]})]})}),e.jsx(di,{})]})]}),e.jsx(oi,{}),e.jsx(s.DataSourceDialog,{incomingSelectedEntities:(d==null?void 0:d.selectedEntities)||[],dialogMode:"dataSource",open:n,onOpenChange:r,dataSource:h,fallbackDataSource:u}),e.jsx(ui,{open:o,onOpenChange:i})]})}const ss=[{id:"table",icon:Ve,label:"Table"},{id:"pivotTable",icon:Ve,label:"Pivot Table"},{id:"aggregateTable",icon:Ve,label:"Aggregate Table"},{id:"bar",icon:cs,label:"Bar Chart"},{id:"line",icon:ds,label:"Line Chart"},{id:"area",icon:kt,label:"Area Chart"},{id:"stackedBar",icon:As,label:"Stacked Bar Chart"},{id:"combo",icon:Wn,label:"Combo Chart"},{id:"stackedLine",icon:Ks,label:"Stacked Line Chart"},{id:"scatter",icon:Os,label:"Scatter Chart"},{id:"bubble",icon:Hs,label:"Bubble Chart"},{id:"pie",icon:us,label:"Pie Chart"},{id:"doughnut",icon:Rs,label:"Doughnut Chart"},{id:"funnel",icon:Qs,label:"Funnel Chart"},{id:"radar",icon:Bs,label:"Radar Chart"},{id:"polarArea",icon:Gs,label:"Polar Area Chart"},{id:"tornado",icon:zs,label:"Tornado Chart"},{id:"range",icon:Ls,label:"Range Chart"},{id:"kpi",icon:Ws,label:"KPI"},{id:"text",icon:wt,label:"Text"},{id:"map",icon:Fs,label:"Map"}],et=t=>{const a=t.toLowerCase();for(const n of ss)if(n.id==="doughnut"){if(a.includes("doughnut")||a.includes("donut")){const r=n.icon;return I.createElement(r,{className:"h-4 w-4"})}}else if(a.includes(n.id.toLowerCase())){const r=n.icon;return I.createElement(r,{className:"h-4 w-4"})}return null},pi="chart-selector-standard-first";function fi(){const[t,a]=s.useLocalStorageState(pi,!0);return{standardFirst:t,updatePreference:a}}const bt=({pluginVisual:t,index:a,onSelect:n})=>{const r=hs(t.icon||""),o=t.name.charAt(0).toUpperCase(),i=et(t.name);return e.jsx(s.CommandItem,{value:`${t.name} custom visual plugin component`,onSelect:n,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"}):i||e.jsx("div",{className:"flex h-4 w-4 items-center justify-center rounded bg-muted text-xs font-medium",children:o}),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}-${a}`)},Nt=["default","standardPlugin","customPlugin"];function gi({selectedChart:t,onChartChange:a}){var w;const[n,r]=I.useState([]),[o,i]=I.useState(!1),{data:c}=Ys();fi();const d=((w=s.useEditorStore(v=>v.card).customCardPreferences)==null?void 0:w.url)||"";Ps(d);const{setCardType:m,setCardPreferences:u,setIsDevMode:h}=s.useEditorStore(v=>v.actions),{setCardCustomCfg:p,setCustomCardPreferences:f,setQueryConfig:j}=s.useEditorActions(),[x,y]=s.useLocalStorageState("chart-section-active",null),g=I.useMemo(()=>x?[x,...Nt.filter(v=>v!==x)]:Nt,[x]);I.useEffect(()=>{(async()=>{if(c){const b=(await Promise.allSettled(c.plugins.map(async A=>{try{return(await s.loadManifest(A.value)).visuals.map(O=>({name:O.name,icon:O.icon,url:A.value,pluginName:A.label,pluginType:A.type,chartType:O.chartType,componentType:O.componentType}))}catch(S){return console.error(`Failed to load manifest for plugin ${A.label}`,S),[]}}))).filter(A=>A.status==="fulfilled").flatMap(A=>A.value);r(b)}})()},[c]);function C(v){p(null),u({}),m(v),["custom","text","map"].includes(v)&&(h(!0),j(void 0)),a(v),i(!1)}function k(v){p(null),u({}),m("custom"),f({type:"component",visualType:"single",url:v.url,componentName:v.name,icon:v.icon,pluginChartType:v.chartType}),j(void 0),a("custom"),i(!1)}const R=()=>{var D;if(t==="custom"){const b=s.useEditorStore.getState().card;return((D=b==null?void 0:b.customCardPreferences)==null?void 0:D.componentName)||"Custom Visual"}const v=ss.find(b=>b.id===t);return(v==null?void 0:v.label)||"Select chart type"},T=()=>{var D,b;if(t==="custom"){const A=s.useEditorStore.getState().card,S=(D=A==null?void 0:A.customCardPreferences)==null?void 0:D.icon,O=(b=A==null?void 0:A.customCardPreferences)==null?void 0:b.componentName;if(S&&O)return e.jsx(ji,{icon:S,componentName:O});if(O){const M=et(O);if(M)return M}return e.jsx(Ge,{className:"h-4 w-4"})}const v=ss.find(A=>A.id===t);if(v){const A=v.icon;return e.jsx(A,{className:"h-4 w-4"})}return e.jsx(Ge,{className:"h-4 w-4"})};return e.jsx("div",{className:"mb-6",children:e.jsxs(s.Popover,{open:o,onOpenChange:i,children:[e.jsx(s.PopoverTrigger,{asChild:!0,children:e.jsxs(s.Button,{variant:"outline",role:"combobox","aria-expanded":o,className:"w-full justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[T(),e.jsx("span",{children:R()})]}),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(v=>{if(v==="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:x==="default",onCheckedChange:D=>y(D?"default":null),className:"scale-75"})]})]}),className:"[&_[cmdk-group-heading]]:text-sm [&_[cmdk-group-heading]]:font-medium [&_[cmdk-group-heading]]:text-muted-foreground",children:ss.map(D=>{const b=D.icon;return e.jsx(s.CommandItem,{value:`${D.label} ${D.id} chart graph visualization`,onSelect:()=>C(D.id),className:"flex items-center gap-2",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(b,{className:"h-4 w-4"}),e.jsx("span",{children:D.label})]})},D.id)})},"default");if(v==="standardPlugin"){const D=n.filter(b=>b.pluginType==="standard");return D.length?e.jsx(s.CommandGroup,{heading:e.jsxs("div",{className:"group flex w-full items-center justify-between",children:[e.jsx("p",{children:"Standard Visuals"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-xs text-muted-foreground opacity-0 transition-opacity group-hover:opacity-100",children:"Show on top"}),e.jsx(s.Switch,{checked:x==="standardPlugin",onCheckedChange:b=>y(b?"standardPlugin":null),className:"scale-75"})]})]}),className:"[&_[cmdk-group-heading]]:text-sm [&_[cmdk-group-heading]]:font-medium [&_[cmdk-group-heading]]:text-muted-foreground",children:D.filter(b=>b.componentType==="chart").map((b,A)=>e.jsx(bt,{pluginVisual:b,index:A,onSelect:()=>k(b)},`${b.url}-${b.name}-${A}`))},"standardPlugin"):null}if(v==="customPlugin"){const D=n.filter(b=>b.pluginType==="custom");return D.length?e.jsx(s.CommandGroup,{heading:e.jsxs("div",{className:"group flex w-full items-center justify-between",children:[e.jsxs(s.Tooltip,{children:[e.jsx(s.TooltipTrigger,{asChild:!0,children:e.jsxs("span",{className:"flex items-center gap-2",children:["Custom Visuals",e.jsx(s.Info,{className:"h-3.5 w-3.5 text-muted-foreground"})]})}),e.jsx(s.TooltipContent,{side:"right",children:"External visuals that are specific to your project"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-xs text-muted-foreground opacity-0 transition-opacity group-hover:opacity-100",children:"Show on top"}),e.jsx(s.Switch,{checked:x==="customPlugin",onCheckedChange:b=>y(b?"customPlugin":null),className:"scale-75"})]})]}),className:"[&_[cmdk-group-heading]]:text-sm [&_[cmdk-group-heading]]:font-medium [&_[cmdk-group-heading]]:text-muted-foreground",children:D.map((b,A)=>e.jsx(bt,{pluginVisual:b,index:A,onSelect:()=>k(b)},`${b.url}-${b.name}-${A}`))},"customPlugin"):null}return null})]})]})})]})})}const ji=({icon:t,componentName:a})=>{const n=hs(),r=et(a);return n?e.jsx(n,{className:"h-4 w-4"}):r||e.jsx(Ge,{className:"h-4 w-4"})},Sn=({dataType:t})=>{const a=s.getDataType(t);return a==="string"?e.jsx("span",{className:"flex size-6 shrink-0 items-center justify-center rounded-sm bg-blue-100 text-xs text-blue-700 dark:bg-blue-950 dark:text-blue-300",children:e.jsx(Qe,{className:"h-3 w-3"})}):a==="number"?e.jsx("span",{className:"flex size-6 shrink-0 items-center justify-center rounded-sm bg-green-100 text-xs text-green-700 dark:bg-green-950 dark:text-green-300",children:e.jsx(Ye,{className:"h-3 w-3"})}):a==="date"?e.jsx("span",{className:"flex size-6 shrink-0 items-center justify-center rounded-sm bg-purple-100 text-xs text-purple-700 dark:bg-purple-950 dark:text-purple-300",children:e.jsx(s.Calendar,{className:"h-3 w-3"})}):a==="boolean"?e.jsx("span",{className:"flex size-6 shrink-0 items-center justify-center rounded-sm bg-orange-100 text-xs text-orange-700 dark:bg-orange-950 dark:text-orange-300",children:e.jsx(ts,{className:"h-3 w-3"})}):e.jsx("span",{className:"flex size-6 shrink-0 items-center justify-center rounded-sm bg-gray-100 text-xs text-gray-700 dark:bg-gray-950 dark:text-gray-300",children:e.jsx(Qe,{className:"h-3 w-3"})})};function yi({aliasTemplate:t,onAliasTemplateChange:a}){var d;const[n,r]=I.useState(t),[o,i]=I.useState(!1),c=(d=s.useEditorStore(m=>{var u;return(u=m.card.config)==null?void 0:u.pivotByColumns}))==null?void 0:d[0],l=c?`e.g. Min Sales in {{${c.name}}}`:"e.g. Min Sales in {{region}}";return e.jsxs("div",{className:"space-y-1",children:[e.jsx(s.Label,{className:"text-xs font-medium text-gray-600",children:"Pivot Alias Template"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(s.Input$1,{placeholder:l,value:o?n:t,onChange:m=>{r(m.target.value),i(!0)},onFocus:()=>i(!0),onPointerDown:m=>m.stopPropagation(),className:"h-8 text-xs",onKeyDown:m=>{m.key==="Enter"&&o&&n!==t?(a(n),i(!1)):m.key==="Escape"&&(r(t),i(!1))},"aria-label":"Edit alias template"}),o&&n!==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:()=>{a(n),i(!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),i(!1)},children:e.jsx(s.X,{className:"h-4 w-4 text-gray-400"})})]})]})]})}function vi({valueAliases:t,onValueAliasesChange:a}){const[n,r]=I.useState(null),[o,i]=I.useState(""),[c,l]=I.useState(""),d=()=>{a({...t,"":""})},m=h=>{const p={...t};delete p[h],a(p)},u=h=>{const p={...t};delete p[h],p[o]=c,a(p),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(([h,p],f)=>e.jsx("div",{className:"flex items-center gap-2",children:n===h?e.jsxs(e.Fragment,{children:[e.jsx(s.Input$1,{placeholder:"Value key",value:o,onChange:j=>i(j.target.value),className:"h-8 w-24 text-xs",onPointerDown:j=>j.stopPropagation(),onKeyDown:j=>{j.key==="Enter"?u(h):j.key==="Escape"&&r(null)},"aria-label":"Edit value alias key"}),e.jsx(s.Input$1,{placeholder:"Alias label",value:c,onChange:j=>l(j.target.value),className:"h-8 w-24 text-xs",onPointerDown:j=>j.stopPropagation(),onKeyDown:j=>{j.key==="Enter"?u(h):j.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:()=>u(h),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:h,className:"h-8 w-24 text-xs",readOnly:!0,onClick:()=>{r(h),i(h),l(p)},"aria-label":"Edit value alias key"}),e.jsx(s.Input$1,{placeholder:"Alias label",value:p,className:"h-8 w-24 text-xs",readOnly:!0,onClick:()=>{r(h),i(h),l(p)},"aria-label":"Edit value alias label"}),e.jsx(s.Button,{variant:"ghost",size:"sm",className:"h-8 w-8 p-0",onClick:()=>m(h),"aria-label":"Remove value alias",children:e.jsx(s.X,{className:"h-3 w-3"})})]})},h+f)),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 Ct({value:t,onSave:a,placeholder:n="",type:r="text",className:o=""}){const[i,c]=I.useState(t??""),[l,d]=I.useState(!1);I.useEffect(()=>{c(t??"")},[t]);const m=()=>{a(i),d(!1)},u=()=>{c(t??""),d(!1)};return e.jsxs("div",{className:`flex items-center gap-2 ${o}`,children:[e.jsx(s.Input$1,{placeholder:n,type:r,value:l?i:t??"",onChange:h=>{c(h.target.value),d(!0)},onFocus:()=>d(!0),onClick:h=>h.stopPropagation(),className:"h-8 text-xs",onPointerDown:h=>h.stopPropagation(),onKeyDown:h=>{h.stopPropagation(),h.key==="Enter"&&l&&i!==t?m():h.key==="Escape"&&u()},"aria-label":n||"Edit field"}),l&&i!==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: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 edit",onClick:u,children:e.jsx(s.X,{className:"h-4 w-4 text-muted-foreground"})})]})]})}function bi({field:t,zone:a,index:n,sortDirection:r,onSortDirectionChange:o,hasPivotColumns:i=!1,cardType:c}){var nt;const{attributes:l,listeners:d,setNodeRef:m,transform:u,transition:h,isDragging:p}=s.useSortable({id:t.id}),f=s.useEditorStore(W=>W.card),{updateLabel:j,handleAggregationChange:x,handleDateFormatChange:y,handleGranularityChange:g,handleAliasTemplateChange:C,handleValueAliasesChange:k,removeField:R,handleKpiComparisonTypeChange:T,handleKpiShowTrendlineChange:w,handleKpiTrendlineWindowChange:v,handleKpiTrendlineGranularityChange:D,handleKpiTargetValueChange:b}=Zs(f),[A,S]=I.useState(!1),[O,M]=I.useState(t.dateFormat||"YYYY-MM-DD"),[E,N]=I.useState(t.customFormat||""),[L,B]=I.useState(!!t.customFormat),[P,V]=I.useState(t.granularity||"day"),[q,X]=I.useState(t.aliasTemplate||""),[K,$]=I.useState(t.valueAliases||{}),F=W=>{W==="custom"?B(!0):(B(!1),M(W),a==="groupBy"&&y(n,W,""))},U=W=>{N(W),a==="groupBy"&&y(n,"custom",W)},_=W=>{var qe;V(W);const xe=(qe=H(W)[0])==null?void 0:qe.value;xe&&!L&&(M(xe),a==="groupBy"&&y(n,xe,"")),a==="groupBy"&&g(n,W)},Y=W=>{X(W),a==="metrics"&&C(n,W)},Q=W=>{$(W),a==="metrics"&&k(n,W)},G=W=>{j(a,n,W)},Z=()=>{R(a,n)},te={transform:s.CSS.Transform.toString(u),transition:h},ae=s.getDataType(t.dataType),se=ae==="date",oe=c==="kpi",H=W=>{switch(W){case"day":return[{value:"MM-DD-YYYY",label:"01-15-2024 (MM-DD-YYYY)"},{value:"YYYY-MM-DD",label:"2024-01-15 (YYYY-MM-DD)"},{value:"MM/DD/YYYY",label:"01/15/2024 (MM/DD/YYYY)"},{value:"DD/MM/YYYY",label:"15/01/2024 (DD/MM/YYYY)"},{value:"MMMM DD, YYYY",label:"January 15, 2024 (MMMM DD, YYYY)"},{value:"MMM DD, YYYY",label:"Jan 15, 2024 (MMM DD, YYYY)"},{value:"DD MMM YYYY",label:"15 Jan 2024 (DD MMM YYYY)"},{value:"custom",label:"Custom Format..."}];case"week":return[{value:"MM-DD-YYYY",label:"01-15-2024 (MM-DD-YYYY)"},{value:"YYYY-MM-DD",label:"2024-01-15 (YYYY-MM-DD)"},{value:"Week of MMM DD, YYYY",label:"Week of Jan 15, 2024"},{value:"Week of MMMM DD, YYYY",label:"Week of January 15, 2024"},{value:"YYYY-WW",label:"2024-W03 (YYYY-WW)"},{value:"custom",label:"Custom Format..."}];case"month":return[{value:"MMM YYYY",label:"Jan 2024 (MMM YYYY)"},{value:"MMMM YYYY",label:"January 2024 (MMMM YYYY)"},{value:"YYYY-MM",label:"2024-01 (YYYY-MM)"},{value:"MM/YYYY",label:"01/2024 (MM/YYYY)"},{value:"YYYY MMM",label:"2024 Jan (YYYY MMM)"},{value:"custom",label:"Custom Format..."}];case"quarter":return[{value:"Q1 YYYY",label:"Q1 2024 (Q1 YYYY)"},{value:"YYYY Q1",label:"2024 Q1 (YYYY Q1)"},{value:"1st Quarter YYYY",label:"1st Quarter 2024"},{value:"YYYY-Q1",label:"2024-Q1 (YYYY-Q1)"},{value:"Quarter 1, YYYY",label:"Quarter 1, 2024"},{value:"custom",label:"Custom Format..."}];case"year":return[{value:"YYYY",label:"2024 (YYYY)"},{value:"YY",label:"24 (YY)"},{value:"custom",label:"Custom Format..."}];default:return[{value:"MM-DD-YYYY",label:"01-15-2024 (MM-DD-YYYY)"},{value:"YYYY-MM-DD",label:"2024-01-15 (YYYY-MM-DD)"},{value:"MM/DD/YYYY",label:"01/15/2024 (MM/DD/YYYY)"},{value:"DD/MM/YYYY",label:"15/01/2024 (DD/MM/YYYY)"},{value:"MMMM DD, YYYY",label:"January 15, 2024 (MMMM DD, YYYY)"},{value:"MMM DD, YYYY",label:"Jan 15, 2024 (MMM DD, YYYY)"},{value:"DD MMM YYYY",label:"15 Jan 2024 (DD MMM YYYY)"},{value:"YYYY-MM",label:"2024-01 (YYYY-MM)"},{value:"MMMM YYYY",label:"January 2024 (MMMM YYYY)"},{value:"custom",label:"Custom Format..."}]}},z=H(P),J=!oe&&a!=="pivotBy",ie=se&&a==="groupBy",Ne=!oe&&se&&a==="groupBy",Te=oe&&se&&a==="groupBy",ne=oe&&a==="metrics"&&((nt=f.config)==null?void 0:nt.comparisonType)==="target",le=a==="metrics",ce=()=>e.jsx("div",{onPointerDown:W=>{W.stopPropagation()},className:"cursor-default overflow-hidden text-ellipsis whitespace-nowrap px-0.5 text-xs text-gray-500",children:`${t.entityName}.${t.name}`}),kn=()=>J?e.jsx(Ct,{value:t.label??"",onSave:G,placeholder:"Display label...",type:"text"}):null,tt=()=>ie?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:P,onValueChange:_,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(W=>e.jsx(s.SelectItem,{className:"text-xs",value:W,children:s.toTitleCase(W)},W))})]})]}):null,Tn=()=>Ne?e.jsxs(e.Fragment,{children:[tt(),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:L?"custom":O,onValueChange:F,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:z.map(W=>e.jsx(s.SelectItem,{className:"text-xs",value:W.value,children:W.label},W.value))})]}),L&&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:E,onChange:W=>{W.stopPropagation(),U(W.target.value)},onClick:W=>W.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,En=()=>{var W,ge,xe,qe,at;return Te?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(s.Label,{className:"text-xs font-medium text-muted-foreground",children:"Comparison Type"}),e.jsxs(s.Select,{value:((W=f.config)==null?void 0:W.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:"target",children:"Target Value"})]})]})]}),e.jsx("div",{className:"space-y-1",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(s.Label,{className:"text-xs font-medium text-muted-foreground",children:"Show Trendline"}),e.jsx(s.SmallSwitch,{checked:((ge=f.config)==null?void 0:ge.showTrendline)||!1,onCheckedChange:w})]})}),((xe=f.config)==null?void 0:xe.showTrendline)&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(s.Label,{className:"text-xs font-medium text-muted-foreground",children:"Trendline Window"}),e.jsx(s.Input$1,{type:"number",min:"1",max:"365",value:((qe=f.config)==null?void 0:qe.trendlineWindow)||30,onChange:An=>{const Ln=parseInt(An.target.value)||30;v(Ln)},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:((at=f.config)==null?void 0:at.trendlineGranularity)||"day",onValueChange:D,children:[e.jsx(s.SelectTrigger,{className:"h-8 w-full text-xs",children:e.jsx(s.SelectValue,{placeholder:"Select granularity..."})}),e.jsxs(s.SelectContent,{children:[e.jsx(s.SelectItem,{value:"day",children:"Day"}),e.jsx(s.SelectItem,{value:"week",children:"Week"}),e.jsx(s.SelectItem,{value:"month",children:"Month"})]})]})]})]})]}):null},In=()=>{var W,ge;return ne?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(Ct,{value:((W=f.config)==null?void 0:W.targetValue)!==void 0&&((ge=f.config)==null?void 0:ge.targetValue)!==null?String(f.config.targetValue):"",onSave:xe=>{!isNaN(Number(xe))&&xe!==null?b(Number(xe)):b(0)},placeholder:"Enter target value...",type:"text"})]}):null},Mn=()=>le?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(s.Label,{className:"text-xs font-medium text-muted-foreground",children:"Aggregation"}),e.jsxs(s.Select,{value:t.aggregate,onValueChange:W=>{x(n,W)},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.jsx(bn,{column:t}),i&&e.jsxs(e.Fragment,{children:[e.jsx(yi,{aliasTemplate:q,onAliasTemplateChange:Y}),e.jsx(vi,{valueAliases:K,onValueAliasesChange:Q})]})]}):null;return e.jsxs("div",{ref:m,style:te,...l,...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 ${p?"z-50 scale-95 opacity-50":"border-slate-200"} ${a==="filters"?"cursor-default":"cursor-move"}`,children:[e.jsxs("div",{className:"flex grow items-center gap-2",children:[e.jsx(Sn,{dataType:ae}),e.jsx(Js,{className:"w-[140px] flex-1 text-sm",children:t.label||t.name}),a!=="sortBy"&&e.jsx(s.Button,{variant:"ghost",size:"sm",className:"h-6 w-6 p-0 opacity-0 group-hover:opacity-100",onClick:W=>{W.stopPropagation(),S(!A)},children:e.jsx(s.ChevronDown,{className:`h-3 w-3 transition-transform ${A?"rotate-180":""}`})}),a==="sortBy"&&e.jsx(s.Button,{variant:"ghost",size:"sm",className:"h-6 w-6 p-0 group-hover:opacity-100",onClick:W=>{W.stopPropagation(),console.log("DraggableField - Current sortDirection:",r);const ge=r==="asc"?"desc":"asc";console.log("DraggableField - New direction to set:",ge),o(ge)},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 opacity-0 group-hover:opacity-100",onClick:W=>{W.stopPropagation(),Z()},children:e.jsx(s.X,{className:"h-3 w-3"})})]}),A&&e.jsxs("div",{className:"space-y-3",children:[ce(),kn(),c==="kpi"&&tt(),Tn(),En(),In(),Mn()]})]})}function Ni({concept:t}){const a=()=>{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$1,{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:a()})]})})}function Ze({zone:t,fields:a,label:n,placeholder:r,shouldShow:o,hasPivotColumns:i=!1}){const{isOver:c,setNodeRef:l}=s.useDroppable({id:t}),{updateSortByColumn:d}=s.useEditorActions(),m=s.useEditorStore(j=>j.card),u=s.useEditorStore(j=>j.card.type),h=a.length>0,p=(j,x)=>{var g;!((g=m.config)!=null&&g.sortByColumns)||m.config.sortByColumns.findIndex(C=>C.id===j)===-1||d(m.id,j,{direction:x})};if(t==="sortBy"&&o===!1)return null;const f=t!=="sortBy"&&u!=="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:n}),f&&e.jsx(Ni,{concept:t})]}),e.jsx("div",{ref:l,className:`min-h-[60px] rounded-lg border-2 border-dashed p-2 transition-all ${c?"border-blue-500 bg-blue-50 dark:bg-blue-950":h?"border-blue-200 bg-blue-50/30 dark:border-blue-800 dark:bg-blue-950/30":"border-muted-foreground/20 bg-background"}`,children:a.length===0?e.jsx("div",{className:"flex min-h-[40px] items-center justify-center text-sm text-gray-400",children:r}):e.jsx(s.SortableContext,{items:a.map(j=>j.id),strategy:s.verticalListSortingStrategy,children:e.jsx("div",{className:"flex flex-wrap gap-2",children:a.map((j,x)=>{const g=j.direction;return e.jsx("div",{className:"flex w-full items-center gap-2",children:e.jsx("div",{className:"flex-1",children:e.jsx(bi,{field:j,zone:t,index:x,sortDirection:g,onSortDirectionChange:C=>p(j.id,C),hasPivotColumns:i,cardType:u})})},j.id)})})})})]})}function Ci({groupByFields:t,pivotByFields:a,metricsFields:n,sortByFields:r}){const o=s.useEditorStore(h=>h.card),i=o==null?void 0:o.type,c=t.length>0||n.length>0,l=i!=="kpi",d=i!=="kpi"&&c,m=()=>i==="kpi"?{label:"Trend By",placeholder:"Drop fields to trend data"}:{label:"Rows",placeholder:"Drop fields to group data"},u=()=>i==="kpi"?{label:"Metric",placeholder:"Drop field for KPI"}:{label:"Metrics",placeholder:"Drop fields to measure"};return e.jsxs("div",{className:"w-full space-y-4",children:[e.jsx(Ze,{zone:"groupBy",fields:t,label:m().label,placeholder:m().placeholder}),l&&e.jsx(Ze,{zone:"pivotBy",fields:a,label:"Columns",placeholder:"Drop fields to pivot data"}),e.jsx(Ze,{zone:"metrics",fields:n,label:u().label,placeholder:u().placeholder,hasPivotColumns:a.length>0}),d&&e.jsx(Ze,{zone:"sortBy",fields:r,label:"Sort By",placeholder:"Drop fields from Rows or Metrics"})]})}function Si({selectedChart:t,onChartChange:a,groupByFields:n,pivotByFields:r,metricsFields:o,sortByFields:i}){const c=s.useEditorStore(h=>h.showAIDialog),l=n.length>0||r.length>0||o.length>0,{setShowAIDialog:d}=s.useEditorActions(),m=s.useEditorStore(h=>h.card),{data:u}=s.useDashboardCardQuery(m);return e.jsxs("div",{"data-content":"Chart Configuration Panel",className:"flex w-[350px] flex-col",children:[e.jsxs("div",{className:"space-y-4 px-6 pt-4",children:[e.jsx("div",{className:"flex items-center gap-2",children:e.jsx("h2",{className:"font-semibold",children:"Chart Configuration"})}),e.jsx(gi,{selectedChart:t,onChartChange:a})]}),e.jsxs("div",{className:s.cn("flex justify-end gap-2 px-6 pt-6"),children:[e.jsx("div",{className:s.cn("invisible",{visible:l||u}),children:e.jsx(ms,{})}),!c&&e.jsxs(s.Button,{onClick:()=>d(!c),variant:"outline",className:"h-8",size:"sm",children:[e.jsx(Ta,{className:"mr-2 size-4"}),"AI"]})]}),e.jsxs(s.ScrollArea,{className:"w-full flex-1 basis-0 px-6",children:[e.jsx(Ci,{groupByFields:n,pivotByFields:r,metricsFields:o,sortByFields:i}),e.jsx(s.ScrollBar,{orientation:"horizontal"})]})]})}function wi({initialFilters:t,availableFields:a}={}){const[n,r]=I.useState(t||{id:`group-${Date.now()}`,logicalOperator:"AND",negate:!1,conditions:[],groups:[]});s.useEditorStore(T=>T.card.dataSource);const{columns:o,isLoading:i}=s.useColumns(),l=a||o||[],d={id:"default",name:"default",dataType:"string",label:"Default",entityId:"default",entityName:"Default",entityType:"table"},m=T=>{const w=v=>{if(v.id===T){const D=l[0]||d;return{...v,conditions:[...v.conditions,{id:`condition-${Date.now()}`,field:D,operator:"=",value:""}]}}return{...v,groups:v.groups.map(w)}};r(w(n))},u=T=>{const w=v=>{if(v.id===T){const D=l[0]||d;return{...v,groups:[...v.groups,{id:`group-${Date.now()}`,logicalOperator:"AND",negate:!1,conditions:[{id:`condition-${Date.now()}`,field:D,operator:"=",value:""}],groups:[]}]}}return{...v,groups:v.groups.map(w)}};r(w(n))},h=(T,w)=>{const v=D=>D.id===T?{...D,conditions:D.conditions.filter(b=>b.id!==w)}:{...D,groups:D.groups.map(v)};r(v(n))},p=(T,w)=>{const v=D=>D.id===T?{...D,groups:D.groups.filter(b=>b.id!==w)}:{...D,groups:D.groups.map(v)};r(v(n))},f=(T,w,v,D)=>{if(v==="field")throw new Error("Use a dedicated method to update the field property with a Field object");const b=A=>A.id===T?{...A,conditions:A.conditions.map(S=>S.id===w?{...S,[v]:D}:S)}:{...A,groups:A.groups.map(b)};r(b(n))},j=(T,w,v)=>{const D=b=>b.id===T?{...b,conditions:b.conditions.map(A=>A.id===w?{...A,...v}:A)}:{...b,groups:b.groups.map(D)};r(D(n))},x=(T,w)=>{const v=D=>D.id===T?{...D,logicalOperator:w}:{...D,groups:D.groups.map(v)};r(v(n))},y=(T,w)=>{const v=D=>D.id===T?{...D,negate:w}:{...D,groups:D.groups.map(v)};r(v(n))},g=(T,w,v)=>{const D=b=>b.id===T?{...b,conditions:s.arrayMove(b.conditions,w,v)}:{...b,groups:b.groups.map(D)};r(D(n))},C=(T,w,v)=>{const D=b=>b.id===T?{...b,groups:s.arrayMove(b.groups,w,v)}:{...b,groups:b.groups.map(D)};r(D(n))},k=T=>{if(!T||T.conditions.length===0&&T.groups.length===0)return"-- No filters defined";const w=D=>{let b="";typeof D.field=="object"?b=D.field.entityName?`${D.field.entityName}.${D.field.name}`:D.field.name:b=String(D.field);const A=D.operator;let S=D.value;if(D.field.dataType==="string"&&!["in","not in"].includes(D.operator))typeof S=="string"?S=`'${S}'`:Array.isArray(S)&&(S=`'${S.join(", ")}'`);else if(D.field.dataType==="date")(typeof S=="string"||S instanceof Date)&&(S=`DATE('${S}')`);else if(["in","not in"].includes(D.operator)){let O=[];Array.isArray(S)?O=S.map(M=>typeof M=="string"?`'${M}'`:String(M)):typeof S=="string"?O=S.split(",").map(M=>{const E=M.trim();return D.field.dataType==="string"?`'${E}'`:E}):typeof S=="number"&&(O=[String(S)]),S=`(${O.join(", ")})`}switch(A){case"contains":return typeof S=="string"?`${b} LIKE '%${S.replace(/'/g,"")}'`:`${b} LIKE '%${String(S)}'`;case"startsWith":return typeof S=="string"?`${b} LIKE '${S.replace(/'/g,"")}%'`:`${b} LIKE '${String(S)}%'`;case"endsWith":return typeof S=="string"?`${b} LIKE '%${S.replace(/'/g,"")}'`:`${b} LIKE '%${String(S)}'`;default:return`${b} ${A} ${S}`}},v=D=>{const b=D.conditions.map(w),A=D.groups.map(E=>v(E)),S=[...b,...A].filter(Boolean);if(S.length===0)return"";const O=S.join(` ${D.logicalOperator} `),M=S.length>1?`(${O})`:O;return D.negate?`NOT ${M}`:M};return v(T)},R=n.conditions.length>0||n.groups.length>0;return{currentFilters:n,setCurrentFilters:r,availableFields:l,isLoading:i,addCondition:m,addGroup:u,removeCondition:h,removeGroup:p,updateCondition:f,updateConditionFields:j,updateGroupOperator:x,updateGroupNegate:y,reorderConditions:g,reorderGroups:C,generateSQLPreview:k,hasAnyFilters:R}}function Di({children:t,className:a,delayDuration:n}){return e.jsx(s.TooltipProvider$1,{children:e.jsxs(s.Tooltip,{delayDuration:n,children:[e.jsx(s.TooltipTrigger,{asChild:!0,children:e.jsx("div",{className:s.cn("w-[200px] overflow-hidden text-ellipsis whitespace-nowrap text-sm",a),children:t})}),e.jsx(s.PortalTooltipContent,{children:t})]})})}const ki=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(oa,{className:"h-3 w-3"});default:return e.jsx(s.Table,{className:"h-3 w-3"})}},Ti=t=>{if(t.qualifiedEntityName){const a=t.qualifiedEntityName.split(".");return a.length>1?a[0]:"default"}return"default"};function Ei({value:t,onValueChange:a,availableFields:n,placeholder:r="Select field",className:o="w-64"}){const[i,c]=I.useState(!1),l=I.useMemo(()=>{const d={};return n.forEach(m=>{const u=Ti(m);d[u]||(d[u]={}),d[u][m.entityId]||(d[u][m.entityId]=[]),d[u][m.entityId].push(m)}),d},[n]);return e.jsxs(s.Popover,{modal:!0,open:i,onOpenChange:c,children:[e.jsx(s.PopoverTrigger,{asChild:!0,children:e.jsxs(s.Button,{variant:"outline",role:"combobox","aria-expanded":i,className:s.cn("justify-between",!t&&"text-muted-foreground",o),children:[t?e.jsx("div",{className:"flex items-center gap-2",children:e.jsxs(Di,{children:[t.entityName,".",t.name]})}):r,e.jsx(s.ChevronsUpDown,{className:"ml-2 h-4 w-4 shrink-0 opacity-50"})]})}),e.jsx(s.PopoverContent,{className:"z-50 w-80 p-0",align:"start",children:e.jsxs(s.Command,{children:[e.jsx(s.CommandInput,{placeholder:"Search fields...",className:"h-9"}),e.jsx(s.CommandEmpty,{children:"No fields found."}),e.jsx(s.CommandList,{className:"max-h-80",children:Object.entries(l).map(([d,m])=>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(m).map(([u,h])=>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:[ki(h[0].entityType),e.jsx("span",{children:h[0].entityName})]}),h.map((p,f)=>e.jsxs(s.CommandItem,{value:p.id,onSelect:()=>{a(p),c(!1)},className:"overflow-x-auto",children:[e.jsx(s.Check,{className:s.cn("mr-2 h-4 w-4",(t==null?void 0:t.id)===p.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:p.name})}),e.jsx("div",{className:"flex items-center gap-2 text-xs text-gray-500",children:p.description&&e.jsx("span",{children:p.description})})]})]},p.id+f))]},`${d}-${u}`))},d))})]})})]})}function st(t){var j;const a=s.useEditorStore(x=>x.card),{authToken:n}=s.useSemaphorContext(),r=s.useEditorStore(x=>x.card.config),o=r==null?void 0:r.joinPlan,i={...t,alias:t.name,label:"value",role:"groupby"},c={...t,role:"metric",label:"count",alias:"count",aggregate:"COUNT"},l={...i,role:"sortby",direction:"asc"},d={joinPlan:o,groupByColumns:[i],metricColumns:[c],sortByColumns:[l]},m=((j=a.dataSource)==null?void 0:j.connectionId)||a.connectionId,{data:u,isPending:h,error:p}=s.useQuery({queryKey:["filterValues",t.entityId,t.name,t.qualifiedEntityName],queryFn:async()=>{try{return await s.postRequestRegular("https://semaphor.cloud/api/v1/query",(n==null?void 0:n.accessToken)||"",{connection_id:m,cardConfig:d,cardDataSource:a.dataSource})}catch(x){console.log(t),console.error("error",x)}},enabled:!!m,refetchOnMount:!0,refetchOnWindowFocus:!1});return{filterValues:((u==null?void 0:u.records)||[]).map(x=>({label:x[t.name]||"BLANK",value:x[t.name]||"BLANK",count:(x==null?void 0:x.count)||0})),isPending:h,error:p}}function Ii({field:t,selected:a,onChange:n,placeholder:r="Select items...",className:o}){const[i,c]=ue.useState(!1),{filterValues:l}=st(t),d=u=>{n(a.filter(h=>h!==u))},m=u=>{a.includes(u)?n(a.filter(h=>h!==u)):n([...a,u])};return e.jsx("div",{className:s.cn("w-full",o),children:e.jsxs(s.Popover,{open:i,onOpenChange:c,modal:!0,children:[e.jsx(s.PopoverTrigger,{asChild:!0,children:e.jsxs(s.Button,{variant:"outline",role:"combobox","aria-expanded":i,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:a.length>0?a.map(u=>{const h=l.find(p=>p.value===u);return e.jsxs(s.Badge,{variant:"secondary",className:"text-xs",children:[h==null?void 0:h.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:p=>{p.key==="Enter"&&d(u)},onMouseDown:p=>{p.preventDefault(),p.stopPropagation()},onClick:p=>{p.stopPropagation(),d(u)},children:e.jsx(s.X,{className:"h-3 w-3 text-muted-foreground hover:text-foreground"})})]},u)}):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:l.map((u,h)=>e.jsxs(s.CommandItem,{onSelect:()=>m(u.value),children:[e.jsx(s.Check,{className:s.cn("mr-2 h-4 w-4",a.includes(u.value)?"opacity-100":"opacity-0")}),e.jsxs("div",{className:"flex grow items-center justify-between gap-4",children:[e.jsx("span",{children:u.label}),e.jsx("span",{className:"text-xs text-muted-foreground",children:u.count})]})]},u.value+h))})]})]})})]})})}const wn=t=>{if(!t)return 0;let a=t.conditions.length;return t.groups.forEach(n=>{a+=wn(n)}),a};function Mi({field:t,value:a,onChange:n,placeholder:r="Select value...",className:o}){const{filterValues:i,isPending:c,error:l}=st(t);return c?e.jsxs("div",{className:"flex flex-1 items-center justify-center p-2 text-xs text-gray-500",children:[e.jsx(s.LoaderCircle,{className:"mr-2 size-3.5 animate-spin"})," Loading values..."]}):l?e.jsx("div",{className:"flex-1 p-2 text-xs text-red-500",children:"Error loading values"}):e.jsxs(s.Select,{value:a,onValueChange:n,children:[e.jsx(s.SelectTrigger,{className:o||"flex-1",children:e.jsx(s.SelectValue,{placeholder:r,children:a})}),e.jsx(s.SelectContent,{children:i.map((d,m)=>e.jsx(s.SelectItem,{className:"hover:bg-muted",value:d.value,children:d.label},d.value+m))})]})}const Ai=["=","!=",">",">=","<","<=","contains","startsWith","endsWith","in","not in"],Li=["=","!=","contains","startsWith","endsWith","in","not in"],Oi=["=","!=",">",">=","<","<=","in","not in"],Ri=["=","!="],Fi=["=","!=",">",">=","<","<=","in","not in"];function Bi(t){switch(t){case"string":return Li;case"number":return Oi;case"boolean":return Ri;case"date":return Fi;default:return Ai}}function Dn({condition:t,index:a,groupId:n,groupLogicalOperator:r,onUpdateCondition:o,onRemoveCondition:i,onUpdateGroupOperator:c,availableFields:l,updateConditionFields:d}){const{attributes:m,listeners:u,setNodeRef:h,transform:p,transition:f,isDragging:j}=s.useSortable({id:t.id}),{isPending:x,error:y}=st(t.field),g={transform:s.CSS.Transform.toString(p),transition:f};return e.jsxs("div",{ref:h,style:g,className:`mb-2 flex items-center gap-2 rounded p-2 hover:bg-muted/50 ${j?"z-50 opacity-50":""}`,children:[e.jsx("div",{...m,...u,className:"cursor-grab active:cursor-grabbing",children:e.jsx(s.GripVertical,{className:"h-4 w-4 flex-shrink-0 text-gray-400"})}),a>0&&e.jsxs(s.Select,{value:r,onValueChange:C=>c(n,C),children:[e.jsx(s.SelectTrigger,{className:"w-24",children:e.jsx(s.SelectValue,{})}),e.jsxs(s.SelectContent,{children:[e.jsx(s.SelectItem,{value:"AND",children:"AND"}),e.jsx(s.SelectItem,{value:"OR",children:"OR"})]})]}),a===0&&e.jsx("div",{className:"w-24"}),e.jsx(Ei,{value:t.field,onValueChange:C=>{d(n,t.id,{field:C,value:""})},availableFields:l,placeholder:"Select field",className:"w-64"}),e.jsxs(s.Select,{value:t.operator,onValueChange:C=>{C==="in"||C==="not in"?d(n,t.id,{operator:C,value:[]}):d(n,t.id,{operator:C,value:""})},children:[e.jsx(s.SelectTrigger,{className:"w-28",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{children:Bi(s.getDataType(t.field.dataType)).map(C=>e.jsx(s.SelectItem,{className:"hover:bg-muted",value:C,children:C},C))})]}),s.getDataType(t.field.dataType)==="string"?t.operator==="in"||t.operator==="not in"?x?e.jsxs("div",{className:"flex flex-1 items-center justify-center p-2 text-xs text-gray-500",children:[e.jsx(s.LoaderCircle,{className:"mr-2 size-3.5 animate-spin"})," Loading values..."]}):y?e.jsx("div",{className:"flex-1 p-2 text-xs text-red-500",children:"Error loading values"}):e.jsx(Ii,{field:t.field,selected:Array.isArray(t.value)&&t.value.every(C=>typeof C=="string")?t.value:[],onChange:C=>d(n,t.id,{value:C}),placeholder:`Select values for ${t.operator}...`,className:"flex-1"}):["contains","startsWith","endsWith"].includes(t.operator)?e.jsx(s.Input$1,{value:typeof t.value=="string"?t.value:"",onChange:C=>d(n,t.id,{value:C.target.value}),className:"flex-1",placeholder:t.operator.charAt(0).toUpperCase()+t.operator.slice(1)+"..."}):e.jsx(Mi,{field:t.field,value:typeof t.value=="string"?t.value:"",onChange:C=>d(n,t.id,{value:C}),placeholder:"Select value...",className:"flex-1"}):s.getDataType(t.field.dataType)==="boolean"?e.jsxs(s.Select,{value:typeof t.value=="boolean"?String(t.value):"",onValueChange:C=>d(n,t.id,{value:C==="true"}),children:[e.jsx(s.SelectTrigger,{className:"flex-1",children:e.jsx(s.SelectValue,{placeholder:"Select value..."})}),e.jsxs(s.SelectContent,{children:[e.jsx(s.SelectItem,{value:"true",children:"True"}),e.jsx(s.SelectItem,{value:"false",children:"False"})]})]}):e.jsx(s.Input$1,{value:typeof t.value=="string"||typeof t.value=="number"?t.value:"",onChange:C=>o(n,t.id,"value",C.target.value),className:"flex-1",placeholder:t.operator==="in"||t.operator==="not in"?"value1, value2, value3":"Value"}),e.jsx(s.Button,{variant:"ghost",size:"sm",className:"h-7 w-7 flex-shrink-0 p-0",onClick:()=>i(n,t.id),children:e.jsx(s.X,{className:"h-3 w-3"})})]})}function zi({group:t,depth:a,parentGroupId:n,onUpdateGroupOperator:r,onUpdateGroupNegate:o,onRemoveGroup:i,onUpdateCondition:c,onUpdateField:l,onRemoveCondition:d,onReorderConditions:m,onReorderGroups:u,onAddCondition:h,onAddGroup:p,availableFields:f,renderFilterGroup:j,updateConditionFields:x}){const{attributes:y,listeners:g,setNodeRef:C,transform:k,transition:R,isDragging:T}=s.useSortable({id:t.id}),w={transform:s.CSS.Transform.toString(k),transition:R},v=b=>{const{active:A,over:S}=b;if(S&&A.id!==S.id){const O=t.conditions.findIndex(E=>E.id===A.id),M=t.conditions.findIndex(E=>E.id===S.id);O!==-1&&M!==-1&&m(t.id,O,M)}},D=b=>{const{active:A,over:S}=b;if(S&&A.id!==S.id&&n){const O=t.groups.findIndex(E=>E.id===A.id),M=t.groups.findIndex(E=>E.id===S.id);O!==-1&&M!==-1&&u(n,O,M)}};return e.jsxs("div",{ref:C,style:w,className:`rounded-lg ${a>0?"mt-2 border border-border":""} ${T?"z-50 opacity-50":""}`,children:[a>0&&e.jsxs("div",{className:"flex items-center justify-between rounded-t-lg bg-muted p-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{...y,...g,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:()=>o(t.id,!t.negate),children:"NOT"}),e.jsxs(s.Select,{value:t.logicalOperator,onValueChange:b=>r(t.id,b),children:[e.jsx(s.SelectTrigger,{className:"h-7 w-20",children:e.jsx(s.SelectValue,{})}),e.jsxs(s.SelectContent,{children:[e.jsx(s.SelectItem,{className:"hover:bg-muted",value:"AND",children:"AND"}),e.jsx(s.SelectItem,{className:"hover:bg-muted",value:"OR",children:"OR"})]})]}),e.jsx("span",{className:"text-sm font-medium",children:"Group"})]}),e.jsx(s.Button,{variant:"ghost",size:"sm",className:"h-7 w-7 p-0",onClick:()=>n&&i(n,t.id),children:e.jsx(s.Trash2,{className:"h-3 w-3"})})]}),e.jsxs("div",{className:`p-3 ${a>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:v,children:e.jsx(s.SortableContext,{items:t.conditions.map(b=>b.id),strategy:s.verticalListSortingStrategy,children:t.conditions.map((b,A)=>e.jsx(Dn,{condition:b,index:A,groupId:t.id,groupLogicalOperator:t.logicalOperator,onUpdateCondition:c,onUpdateField:l,onRemoveCondition:d,onUpdateGroupOperator:r,availableFields:f,updateConditionFields:x},b.id))})}),e.jsx(s.DndContext,{sensors:s.useSensors(s.useSensor(s.PointerSensor),s.useSensor(s.KeyboardSensor,{coordinateGetter:s.sortableKeyboardCoordinates})),collisionDetection:s.closestCenter,onDragEnd:D,children:e.jsx(s.SortableContext,{items:t.groups.map(b=>b.id),strategy:s.verticalListSortingStrategy,children:t.groups.map(b=>j(b,a+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:()=>h(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:()=>p(t.id),children:[e.jsx(s.Plus,{className:"mr-1 h-3 w-3"}),"Add Group"]})]})]})]})}function Pi({filters:t,availableFields:a,onSave:n,onClearAll:r,onCancel:o}){const{currentFilters:i,availableFields:c,isLoading:l,addCondition:d,addGroup:m,removeCondition:u,removeGroup:h,updateCondition:p,updateConditionFields:f,updateGroupOperator:j,updateGroupNegate:x,reorderConditions:y,reorderGroups:g,generateSQLPreview:C,hasAnyFilters:k,setCurrentFilters:R}=wi({initialFilters:t,availableFields:a}),T=s.useSensors(s.useSensor(s.PointerSensor),s.useSensor(s.KeyboardSensor,{coordinateGetter:s.sortableKeyboardCoordinates})),[w,v]=I.useState(!1),D=(S,O,M)=>{const E=N=>N.id===S?{...N,conditions:N.conditions.map(L=>L.id===O?{...L,field:M,dataType:M.dataType}:L)}:{...N,groups:N.groups.map(E)};R(E(i))},b=(S,O=0,M)=>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:E=>{const{active:N,over:L}=E;if(L&&N.id!==L.id){const B=S.conditions.findIndex(V=>V.id===N.id),P=S.conditions.findIndex(V=>V.id===L.id);B!==-1&&P!==-1&&y(S.id,B,P)}},children:e.jsx(s.SortableContext,{items:S.conditions.map(E=>E.id),strategy:s.verticalListSortingStrategy,children:S.conditions.map((E,N)=>e.jsx(Dn,{condition:E,index:N,groupId:S.id,groupLogicalOperator:S.logicalOperator,onUpdateCondition:p,onUpdateField:D,onRemoveCondition:u,onUpdateGroupOperator:j,availableFields:c,updateConditionFields:f},E.id))})}),e.jsx(s.DndContext,{sensors:T,collisionDetection:s.closestCenter,onDragEnd:E=>{const{active:N,over:L}=E;if(L&&N.id!==L.id){const B=S.groups.findIndex(V=>V.id===N.id),P=S.groups.findIndex(V=>V.id===L.id);B!==-1&&P!==-1&&g(S.id,B,P)}},children:e.jsx(s.SortableContext,{items:S.groups.map(E=>E.id),strategy:s.verticalListSortingStrategy,children:S.groups.map(E=>b(E,O+1,S.id))})}),e.jsxs("div",{className:"mt-3 flex items-center gap-2",children:[e.jsxs(s.Button,{size:"sm",className:"h-7 text-xs",variant:"outline",onClick:()=>d(S.id),children:[e.jsx(s.Plus,{className:"mr-1 h-3 w-3"}),"Add Condition"]}),w&&e.jsxs(s.Button,{variant:"outline",size:"sm",className:"h-7 text-xs",onClick:()=>m(S.id),children:[e.jsx(s.Plus,{className:"mr-1 h-3 w-3"}),"Add Group"]})]})]})},S.id):e.jsx(zi,{group:S,depth:O,parentGroupId:M,onUpdateGroupOperator:j,onUpdateGroupNegate:x,onRemoveGroup:h,onUpdateCondition:p,onUpdateField:D,onRemoveCondition:u,onReorderConditions:y,onReorderGroups:g,onAddCondition:d,onAddGroup:m,availableFields:c,renderFilterGroup:b,updateConditionFields:f},S.id),A=wn(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:[l?e.jsxs("div",{className:"flex items-center justify-center p-4",children:[e.jsx("div",{className:"h-5 w-5 animate-spin rounded-full border-2 border-gray-300 border-t-gray-600"}),e.jsx("span",{className:"ml-2 text-sm text-gray-600",children:"Loading columns..."})]}):b(i),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.Checkbox,{id:"advanced-mode",checked:w,onCheckedChange:S=>v(!!S)}),e.jsx("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)"})]})}),k&&e.jsxs("div",{className:"mt-4 border-t border-border pt-4",children:[e.jsx("div",{className:"mb-2 text-xs font-medium text-muted-foreground",children:"SQL WHERE Clause Preview"}),e.jsx("div",{className:"overflow-x-auto rounded-md border bg-muted p-3",children:e.jsx("pre",{className:"whitespace-pre-wrap font-mono text-xs text-muted-foreground",children:C(i)})})]})]})})}),e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx(s.Button,{size:"sm",variant:"outline",onClick:o,children:"Cancel"}),A>0&&e.jsx(s.Button,{variant:"outline",size:"sm",onClick:r,children:"Clear All"}),e.jsx(s.Button,{size:"sm",onClick:()=>n(k?i:null),children:"Apply Filters"})]})]})}function Vi({cardId:t,filters:a,onFiltersChange:n,onClearFilters:r,availableFields:o,isOpen:i,onOpenChange:c}){const l=m=>{n(t,m),c(!1)},d=()=>{r(t),c(!1)};return e.jsxs(s.Dialog,{modal:!1,open:i,onOpenChange:c,children:[i&&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:m=>{m.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(Pi,{filters:a,availableFields:o,onSave:l,onCancel:()=>c(!1),onClearAll:d})]})]})}function _i({activeCardId:t,sourceFields:a,getFieldsForContainer:n,setFieldsForContainer:r}){var f;const[o,i]=I.useState(null),c=s.useEditorStore(j=>j.card),l=(f=c==null?void 0:c.config)==null?void 0:f.joinPlan,d=[...a,...n("groupBy"),...n("pivotBy"),...n("metrics"),...n("sortBy")],m=I.useCallback(j=>j.startsWith("card-")?null:j.startsWith("source-")||a.find(x=>x.id===j)?"source":n("groupBy").find(x=>x.id===j)?"groupBy":n("metrics").find(x=>x.id===j)?"metrics":n("pivotBy").find(x=>x.id===j)?"pivotBy":n("sortBy").find(x=>x.id===j)?"sortBy":null,[a,n]),u=I.useCallback(j=>{i(j.active.id)},[]),h=I.useCallback(j=>{const{active:x,over:y}=j;if(!y||!t){i(null);return}const g=x.id,C=y.id,k=m(g),R=m(C)||C;if(k==="source"&&R==="sortBy"){i(null);return}if(k==="source"&&R!=="source"&&R!=="sortBy"){const T=[...a].find(b=>b.id===g);if(!T){i(null);return}const w=[...n("groupBy"),...n("pivotBy"),...n("metrics"),...n("sortBy")];if(w.length>0){const b=w[0].qualifiedEntityName;if(!b){i(null);return}if(b!==T.qualifiedEntityName&&T.qualifiedEntityName)if(l){if(!Cn(b,T.qualifiedEntityName,l)){Is(),i(null);return}}else{Is(),i(null);return}}const v=n(R);if(Ms(T,v)){i(null);return}const D=s.getNewField(T,R);i(null),r(R,[...v,D]);return}if(k&&R&&k!=="source"&&R!=="source"&&k!==R){const T=n(k),w=n(R),v=T.find(A=>A.id===g);if(!v){i(null);return}const D=s.getNewField(v,R);if(i(null),R==="sortBy"){if(k==="pivotBy"){i(null);return}Ms(v,w)||r(R,[...w,D]);return}const b=T.filter(A=>A.id!==g);r(k,b),r(R,[...w,D]);return}if(k&&R&&k===R&&k!=="source"){const T=n(k),w=T.findIndex(D=>D.id===g),v=T.findIndex(D=>D.id===C);if(w!==v){const D=s.arrayMove(T,w,v);r(k,D)}}i(null)},[t,a,n,r,m,l]),p=o?d.find(j=>j.id===o):null;return{activeId:o,activeField:p,handleDragStart:u,handleDragEnd:h}}function Ui({onAdvancedToggle:t,onDebugToggle:a,onAccept:n}){const{currentUser:r}=be();r==null||r.role;const[o,i]=I.useState(!1),c=s.useEditorStore(g=>g.isDevMode),l=s.useEditorStore(g=>g.card),d=s.useEditorStore(g=>g.card.dataSource);s.isExplorerCard(l);const{config:m}=I.useContext(s.SemaphorContext).tokenProps,u=(m==null?void 0:m.showAdvancedMode)!==!1,{setIsDevMode:h}=s.useEditorActions(),p=s.useEditorStore(g=>g.showAIDialog),f=s.useEditorStore(g=>g.frame),j=s.useManagementStore(g=>g.selectedVisual),x=(j==null?void 0:j.id)===(f==null?void 0:f.id),{setShowAIDialog:y}=s.useEditorActions();return e.jsxs("div",{className:s.cn("flex items-center justify-between px-6 py-3",p&&"justify-end",!u&&"justify-end"),children:[u&&t&&!p&&e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(s.SmallSwitch,{className:s.cn("",{}),checked:c,onCheckedChange:()=>h(!c),id:"advanced-mode"}),e.jsx("label",{htmlFor:"advanced-mode",className:"text-sm font-medium",children:"Advanced Mode"})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[(r==null?void 0:r.type)!=="tenant"&&e.jsxs(s.DropdownMenu,{modal:!1,children:[e.jsx(s.DropdownMenuTrigger,{asChild:!0,children:e.jsx(s.Button,{variant:"ghost",size:"sm",className:"h-8 p-0",children:e.jsx(s.EllipsisVertical,{className:"size-3.5"})})}),e.jsx(s.DropdownMenuContent,{align:"end",children:e.jsxs(s.DropdownMenuItem,{onClick:()=>{i(!0)},children:[e.jsx(s.Database,{className:"mr-2 h-4 w-4"}),"Set Data Context"]})})]}),e.jsx($s,{}),n&&!x&&e.jsx(qs,{variant:"default"}),x&&e.jsx(Wr,{}),a&&s.isDevEnv]}),o&&e.jsx(s.DataSourceDialog,{incomingSelectedEntities:(d==null?void 0:d.selectedEntities)||[],open:o,onOpenChange:i,dataSource:d||s.EMPTY_DATA_SOURCE,fallbackDataSource:s.EMPTY_DATA_SOURCE,dialogMode:"aiContext"})]})}function qi({activeView:t,onViewChange:a}){const n=s.useEditorStore(o=>o.card),{errorMessage:r}=s.useDashboardCardQuery(n);return e.jsx(s.Tabs,{value:t,onValueChange:o=>a(o),children:e.jsxs(s.TabsList,{className:"h-9 w-fit gap-2 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"}),n.type!=="kpi"&&e.jsx(s.TabsTrigger,{value:"sql",className:s.cn("rounded-md transition data-[state=active]:bg-muted",r&&"text-destructive data-[state=active]:bg-destructive/10 data-[state=active]:text-destructive"),children:r?"Error":"Query"})]})})}const $i=[{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 Yi(){var d,m;const t=s.useEditorStore(u=>u.card),{updateRowLimit:a}=s.useEditorActions(),[n,r]=I.useState(!1),[o,i]=I.useState(""),c=u=>{if(u==="custom"){r(!0);return}r(!1),a(t.id,parseInt(u))},l=u=>{const h=u.target.value;i(h),h&&!isNaN(parseInt(h))&&a(t.id,parseInt(h))};return e.jsx("div",{className:"flex items-center gap-2",children:n?e.jsx(s.Input,{type:"number",value:o,onChange:l,className:"h-7 w-24",placeholder:"Enter limit",min:1}):e.jsxs(s.Select,{value:((m=(d=t.config)==null?void 0:d.rowLimit)==null?void 0:m.toString())||"100",onValueChange:c,children:[e.jsx(s.SelectTrigger,{className:"h-8 w-24 border-none px-1 [&>svg]:hidden",children:e.jsx(s.SelectValue,{placeholder:"Select limit"})}),e.jsx(s.SelectContent,{children:$i.map(u=>e.jsx(s.SelectItem,{value:u.value,children:u.label},u.value))})]})})}function Gi({isOpen:t,onClose:a}){const n=Gt(a,{enabled:t}),r=s.useEditorStore(u=>{var h;return((h=u.card.customCardPreferences)==null?void 0:h.url)||""}),o=s.useEditorStore(u=>u.card),i=s.useEditorStore(u=>{var h;return((h=u.card.customCardPreferences)==null?void 0:h.pluginChartType)||""}),c=s.useEditorStore(u=>{var h;return((h=u.card.customCardPreferences)==null?void 0:h.settings)||{}}),{data:l}=s.useDashboardCardQuery(o),{getCard:d}=s.useCustomVisual(r),m=I.useMemo(()=>!r||r.trim()===""?null:d("Chart Settings"),[d,r]);return e.jsx("div",{ref:n,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:a,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:m&&e.jsx(I.Suspense,{fallback:e.jsx("div",{children:"Loading chart settings..."}),children:e.jsx(m,{chartData:(l==null?void 0:l.records)||[],chartType:i,settings:c})})})]})})}function Hi({activeView:t,onViewChange:a,showDebug:n,onDebugToggle:r,onAccept:o,onClear:i,onAdvancedToggle:c,onFiltersClick:l,filterCount:d,activeCard:m,columns:u,columnsLoading:h,columnsError:p}){var L;const f=s.useEditorStore(B=>B.card);s.useEditorStore(B=>B.frame);const j=s.useDashboardStore(B=>B.filterValues),{updateCardConfig:x,setCard:y,updateCardInFrame:g}=s.useEditorActions(),C=s.useEditorStore(B=>B.showAIDialog),[k,R]=I.useState(!1),T=s.useEditorStore(B=>{var P;return((P=B.card.customCardPreferences)==null?void 0:P.url)&&B.card.type==="custom"}),{data:w,errorMessage:v,isPending:D,isLoading:b,isFetching:A,pagination:S}=s.useDashboardCardQuery(m),O=(B,P)=>{const V={...m,paginationConfig:{page:B+1,pageSize:P}};y(V),g(V)};function M(){return e.jsx("div",{className:"border-b border-border bg-background p-4",children:e.jsxs("div",{className:"space-y-4",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(f.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(j||{},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(m.dataSource||{},null,2)})]}),e.jsxs("div",{children:[e.jsxs("h3",{className:"mb-2 text-sm font-medium",children:["Columns (",u.length,")"]}),e.jsx("pre",{className:"max-h-40 overflow-auto rounded border bg-background p-3 text-xs",children:h?"Loading...":p?"Error loading columns":JSON.stringify(u.slice(0,5),null,2)})]})]})})}const E=B=>{if(!f.config)return;if(!B.length){x(f.id,{...f.config,sortByColumns:[]});return}const P=f.config,V=B.map(({id:q,desc:X})=>{var U,_;const K=(U=P.metricColumns)==null?void 0:U.find(Y=>Y.label===q),$=(_=P.groupByColumns)==null?void 0:_.find(Y=>Y.label===q),F=K||$;return F?{id:s.getFieldId("sortBy",F),name:F.name,dataType:F.dataType,label:F.label,qualifiedEntityName:F.qualifiedEntityName,entityId:F.entityId,entityName:F.entityName,entityType:F.entityType,role:"sortby",direction:X?"desc":"asc"}:null}).filter(q=>q!==null);x(f.id,{...P,sortByColumns:V})},N=I.useMemo(()=>{var B,P;return(P=(B=f.config)==null?void 0:B.sortByColumns)==null?void 0:P.map(V=>({id:V.label,desc:V.direction==="desc"}))},[(L=f.config)==null?void 0:L.sortByColumns]);return e.jsxs("div",{className:"relative flex w-0 grow flex-col",children:[e.jsx(Ui,{showDebug:n,onDebugToggle:r,onAccept:o,onClear:i,onAdvancedToggle:c,onFiltersClick:l,filterCount:d}),n&&M(),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"&&C&&e.jsx(hn,{variant:"outline"}),e.jsx(qi,{activeView:t,onViewChange:a}),l&&e.jsxs(s.IconButton,{tooltip:"Card Filters",className:"h-8 gap-1",onClick:l,children:[e.jsx(s.Filter,{className:"h-3.5 w-3.5"}),d>0&&e.jsx("span",{className:"ml-1 rounded-full bg-blue-100 px-1.5 py-0.5 text-xs text-blue-800",children:d})]}),e.jsx("div",{className:"ml-2",children:e.jsx(Yi,{})}),C&&e.jsx(ms,{})]}),e.jsx("div",{className:s.cn("flex grow items-center justify-end"),children:t==="chart"&&e.jsx(xn,{})})]}),!k&&T&&e.jsx(s.IconButton,{"aria-label":"Open Chart Settings",tooltip:"Open Chart Settings",onClick:()=>R(!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(wa,{className:"size-4"})}),e.jsxs("div",{className:"mt-3 flex grow flex-col",children:[t==="chart"&&e.jsx("div",{className:"flex grow flex-col pb-6",children:e.jsx(pn,{})}),t==="table"&&(w==null?void 0:w.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:m,data:(w==null?void 0:w.records)||[],paginationMetadata:S,onPaginationChange:O,isLoading:b||A,onSortChange:E,sortState:N})}),t==="sql"&&e.jsx("div",{className:"p-6",children:e.jsxs("div",{className:"rounded-md bg-background",children:[(w==null?void 0:w.sql)&&e.jsx("h3",{className:"mb-3 text-sm font-medium",children:"Generated SQL Query"}),e.jsx(rn,{sql:w==null?void 0:w.sql,error:v})]})})]}),e.jsx(Gi,{isOpen:k,onClose:()=>R(!1)})]})]})}function Qi({activeField:t}){const[a,n]=I.useState(!0);return I.useEffect(()=>{t&&n(!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 ${a?"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(Sn,{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 Ki=()=>{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 a=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},n=r=>{var o;if((o=r.reason)!=null&&o.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",a,!0),window.addEventListener("unhandledrejection",n,!0),()=>{console.error=t,window.removeEventListener("error",a,!0),window.removeEventListener("unhandledrejection",n,!0)}};function Wi(){var $,F;const[t,a]=I.useState("chart"),[n,r]=I.useState(!1),[o,i]=I.useState(!1),[c,l]=I.useState(!0),d=s.useEditorStore(U=>U.showAIDialog),m=s.useDashboardStore(U=>U.isVisualEditing),{setCardType:u}=s.useEditorActions(),h=s.useEditorStore(U=>U.card.type);I.useEffect(()=>Ki(),[]);const p=()=>{console.log("Accept clicked - would save/apply current configuration")},f=()=>{console.log("Clear clicked - would reset all configurations")},j=()=>{console.log("Advanced mode toggled")},x=()=>{i(!0)},y=U=>{u(U)},g=s.useEditorStore(U=>U.frame),C=s.useEditorStore(U=>U.card);s.useEditorStore(U=>U.activeTabCardId),s.useEditorStore(U=>U.actions.getAvailableFields);const{addCard:k,removeCard:R,updateCard:T,setActiveCard:w,updateFilters:v}=s.useEditorActions(),{columns:D=[],isLoading:b,error:A}=s.useColumns(),S=s.useSensors(s.useSensor(s.PointerSensor,{activationConstraint:{distance:8}})),O=C,{getFieldsForContainer:M,setFieldsForContainer:E}=Zs(O),{activeField:N,handleDragStart:L,handleDragEnd:B}=_i({activeCardId:g.activeCardId,sourceFields:D,getFieldsForContainer:M,setFieldsForContainer:E}),P=(U,_)=>{_&&v(U,_)},V=U=>{var _;T(U,{config:{...(_=g.cards.find(Y=>Y.id===U))==null?void 0:_.config,filters:void 0}})},q=D,X=U=>{if(!U)return 0;let _=U.conditions.length;return U.groups.forEach(Y=>{_+=X(Y)}),_},K=X((($=O==null?void 0:O.config)==null?void 0:$.filters)||null);return e.jsxs(s.DndContext,{sensors:S,collisionDetection:s.closestCenter,onDragStart:L,onDragEnd:B,children:[e.jsxs("div",{className:"flex h-full grow",children:[e.jsx(xi,{isVisible:c,onToggleVisibility:()=>l(!c)}),e.jsxs("div",{className:"flex flex-1 transition-all duration-300 ease-in-out",children:[!d&&e.jsx(Si,{selectedChart:h,onChartChange:y,groupByFields:M("groupBy"),pivotByFields:M("pivotBy"),metricsFields:M("metrics"),sortByFields:M("sortBy")}),e.jsx(Hi,{selectedChart:h,activeView:t,onViewChange:a,showDebug:n,onDebugToggle:()=>r(!n),onAccept:p,onClear:f,onAdvancedToggle:j,onFiltersClick:x,filterCount:K,activeCard:O,dataSourceState:C.dataSource||s.EMPTY_DATA_SOURCE,columns:D,columnsLoading:b,columnsError:A,getFieldsForContainer:M,cards:g.cards,activeCardId:g.activeCardId,addCard:k,setActiveCard:w})]}),!c&&m&&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:()=>l(!0),title:"Show Data Source Panel",children:e.jsx(s.Database,{className:"h-4 w-4"})})})]}),O&&e.jsx(Vi,{cardId:O.id,filters:((F=O.config)==null?void 0:F.filters)||null,onFiltersChange:P,onClearFilters:V,availableFields:q,isOpen:o,onOpenChange:i}),e.jsx(s.DragOverlay,{dropAnimation:null,children:e.jsx(Qi,{activeField:N||null})})]})}function Ji({authToken:t,onSave:a,onClose:n}){const r=I.useRef(null),o=s.useEditorStore(C=>C.showAIDialog),i=s.useEditorStore(C=>C.isDevMode),{setAuthToken:c}=s.useDashboardActions(),{setShowAIDialog:l,setOnSave:d,setOnClose:m}=s.useEditorActions(),{handleDragOver:u,handleDragEnd:h,handleDragStart:p,handleDragCancel:f,sensors:j}=Br();I.useEffect(()=>{a&&d(a),n&&m(n)},[a,d,n,m]),I.useEffect(()=>{t&&t.accessToken&&c(t)},[t,c]),I.useEffect(()=>{var C,k;o?((C=r.current)==null||C.resize(40),l(!0)):(l(!1),(k=r.current)==null||k.resize(0))},[o,l]);function x(C){C<1?l(!1):o||l(!0)}function y(){return e.jsxs(e.Fragment,{children:[e.jsx(nn,{type:"main"}),e.jsxs(s.ResizablePanelGroup,{"data-content":"editor-main",className:"grow",direction:"horizontal",children:[e.jsx(s.ResizablePanel,{className:"min-w-[510px] rounded-none",children:e.jsx(Zo,{})}),e.jsx(s.ResizableHandle,{}),e.jsx(s.ResizablePanel,{"data-role":"editor-assistant-panel",ref:r,onResize:x,defaultSize:0,children:e.jsx(yt,{})})]})]})}function g(){return e.jsxs(s.ResizablePanelGroup,{"data-content":"explorer",className:"flex grow",direction:"horizontal",children:[e.jsx(s.ResizablePanel,{className:"min-w-[510px] grow rounded-none",children:e.jsx(Wi,{})}),e.jsx(s.ResizableHandle,{}),e.jsx(s.ResizablePanel,{"data-role":"editor-assistant-panel",ref:r,onResize:x,defaultSize:0,children:e.jsx(yt,{})})]})}return e.jsx(s.ErrorBoundary,{FallbackComponent:s.Fallback,children:i?e.jsx(s.DndContext,{sensors:j,onDragStart:p,onDragEnd:h,onDragOver:u,onDragCancel:f,children:e.jsx("section",{className:"isolate flex h-full grow","data-content":"editor-panel",children:y()})}):g()})}function Xi(){s.useDashboardStore(c=>c.selectedCardId);const t=s.useDashboardStore(c=>c.selectedSheetId),{setIsVisualEditing:a}=s.useDashboardStore(c=>c.actions),n=s.useDashboardStore(c=>c.isVisualEditing),r=s.useDashboardStore(c=>c.actions.updateFrame);function o(c){t&&(r(t,c),a(!1))}function i(){a(!1)}return e.jsx("div",{role:"editor-container",className:s.cn("flex-1 grow basis-0 overflow-auto",{"max-h-0 overflow-hidden":!n}),children:e.jsx(Ji,{onSave:o,onClose:i})})}function Zi(){const t=s.useEditorStore(i=>i.selectedDatabaseName),a=s.useEditorStore(i=>i.selectedTableName),n=s.useDashboardStore(i=>i.dashboard.filters)||[],{columns:r}=s.useEditorAside(),{assignFilter:o}=yn();return e.jsx(s.ScrollArea,{className:"flex-1 basis-0 flex-col px-3",children:r==null?void 0:r.map(i=>{const c=n==null?void 0:n.find(l=>l.column===s.fmt(i.column_name)&&l.table===a&&l.database===t);return e.jsx("div",{onClick:()=>o(i),className:s.cn("group flex cursor-pointer items-center justify-between border border-dashed border-background px-3 py-[6px] text-sm transition-colors hover:bg-muted/50",{"bg-muted":c}),children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(_s,{column:i}),e.jsx("span",{children:i.column_name})]})},i.column_name)})})}function el(){s.useDashboardStore(a=>a.showFilters);const t=s.useDashboardStore(a=>a.actions.setShowFilters);return e.jsxs("section",{className:"relative flex min-w-[320px] grow flex-col border-l px-1",children:[e.jsxs("div",{className:"mt-4 flex items-center justify-between gap-2 px-3",children:[e.jsx(s.Label,{className:"px-2 text-lg",children:"Filters"}),e.jsx(s.Button,{onClick:()=>t(!1),className:"h-7 w-7 p-0",variant:"ghost",children:e.jsx(s.Cross2Icon,{})})]}),e.jsx("div",{className:"flex grow",children:e.jsx(nn,{type:"filter",ColumnsComponent:()=>e.jsx(Zi,{})})})]})}function sl(){const t=s.useDashboardStore(r=>r.dashboard.filters),a=s.useDashboardStore(r=>r.theme),n=t==null?void 0:t.filter(r=>r.hide);return n!=null&&n.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)]":a==="light","bg-[repeating-linear-gradient(45deg,_#18171d_0_3px,_#272729_3px_6px)]":a==="dark"}),children:n==null?void 0:n.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 tl(){const t=s.useDashboardStore(r=>r.showFilters),a=s.useDashboardStore(r=>r.isVisualEditing),n=s.useDashboardStore(r=>r.isDashboardEditing);return e.jsxs("div",{role:"dashboard-plus-main",className:s.cn("",{"max-h-0 overflow-hidden":a,"flex grow overflow-auto":!a}),children:[e.jsxs("section",{className:"flex grow flex-col",children:[n&&e.jsx(sl,{}),e.jsx(s.DashboardTabs,{})]}),t&&e.jsx("div",{role:"filter-aside-container",className:"flex",children:e.jsx(el,{})})]})}function nl(){const t=s.useDashboardStore(o=>o.dashboard),a=s.useDashboardStore(o=>o.actions.setDashboard),n=s.useDashboardStore(o=>o.showDashboardJSON),r=s.useDashboardStore(o=>o.actions.setShowDashboardJSON);return e.jsxs("div",{className:s.cn("relative p-2",{hidden:!n}),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:o=>{if(o)try{JSON.parse(o),a(JSON.parse(o))}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 al({showControls:t=!1,showFooter:a=!0,...n}){return typeof window>"u"?null:e.jsx(s.ErrorBoundary,{FallbackComponent:s.Fallback,children:e.jsxs(s.SemaphorContextProvider,{dashboardProps:n,children:[e.jsx(s.$e,{}),e.jsxs(s.UXProvider,{children:[e.jsx(nl,{}),e.jsxs("main",{className:"relative flex h-full w-full flex-col",children:[t&&e.jsx(Ar,{}),e.jsxs(s.DashboardPanel,{...n,children:[e.jsx(Xi,{}),e.jsx(tl,{})]})]})]})]})})}exports.DashboardPlus=al;exports.ResourceManagementPanel=sn;exports.ScheduleDashboard=Bt;exports.SelectComponent=Pe;exports.cleanCard=Ot;exports.downloadPdf=Ft;exports.getDashbaordStateWithoutData=ns;
|