react-semaphor 0.0.555 → 0.0.557
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-D57SyIC-.js → dashboard-plus-CCV5mAgn.js} +2 -2
- package/dist/chunks/{dashboard-plus-DQb0vxDP.js → dashboard-plus-CZggRVns.js} +2 -2
- package/dist/chunks/{index-HP6jGs2r.js → index-CL8DpfKu.js} +1 -1
- package/dist/chunks/{index-JjE2lTjE.js → index-IrFoACqT.js} +1 -1
- 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/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-IrFoACqT.js"),M=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(M);var Ne,Ce,de,je,ye,es,Ss,St,Rn=(St=class extends s.Subscribable{constructor(a,n){super();Fe(this,ye);Fe(this,Ne);Fe(this,Ce);Fe(this,de);Fe(this,je);Be(this,Ne,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,Ne).defaultMutationOptions(a),s.shallowEqualObjects(this.options,n)||re(this,Ne).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,Ce)}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,Ne).getMutationCache().build(re(this,Ne),this.options)),re(this,de).addObserver(this),re(this,de).execute(a)}},Ne=new WeakMap,Ce=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,Ce,{...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,u;if(re(this,je)&&this.hasListeners()){const m=re(this,Ce).variables,h=re(this,Ce).context;(a==null?void 0:a.type)==="success"?((r=(n=re(this,je)).onSuccess)==null||r.call(n,a.data,m,h),(i=(o=re(this,je)).onSettled)==null||i.call(o,a.data,null,m,h)):(a==null?void 0:a.type)==="error"&&((l=(c=re(this,je)).onError)==null||l.call(c,a.error,m,h),(u=(d=re(this,je)).onSettled)==null||u.call(d,void 0,a.error,m,h))}this.listeners.forEach(m=>{m(re(this,Ce))})})},St);function Ae(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.
|
|
@@ -422,4 +422,4 @@ ${S.joinType} JOIN ${A.name}
|
|
|
422
422
|
ON ${R}`}),D},isValidConfiguration:()=>!(!n.baseEntity.name||n.joins.some(S=>!S.source.name||!S.target.name)||n.joins.some(S=>S.joinKeyGroups.some(A=>A.keys.length===0))||n.joins.some(S=>S.joinKeyGroups.some(A=>A.keys.some(w=>!w.source.name||!w.target.name||!w.operator))))}}function oi({joinPlan:t,availableDataSources:a,onSave:n,onRemove:r,onCancel:o}){const{setCardConfig:i}=s.useEditorActions();s.useEditorStore(w=>w.card.config);const{columnGroups:c}=s.useColumns(),{joinPlan:l,expandedJoins:d,setJoinPlan:u,addJoin:m,removeJoin:h,updateJoin:f,moveJoinUp:p,moveJoinDown:g,toggleJoinExpansion:x,getAvailableSourceEntities:b,getAvailableTargetEntities:j,addJoinKeyGroup:N,updateGroupOperator:C,removeJoinKeyGroup:O,addJoinKey:k,updateJoinKey:I,removeJoinKey:y,generateSQLPreview:D,isValidConfiguration:S}=ri({initialJoinPlan:t,availableDataSources:a}),A=w=>{const R=c.find(E=>E.entityName===w);return(R==null?void 0:R.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:w=>{const R=a.find(E=>E.name===w);u({...l,baseEntity:{connectionId:(R==null?void 0:R.connectionId)||"",connectionType:(R==null?void 0:R.connectionType)||"none",type:(R==null?void 0:R.type)||"table",name:w,database:R==null?void 0:R.database,schema:R==null?void 0:R.schema}})},children:[e.jsx(s.SelectTrigger,{children:e.jsx(s.SelectValue,{placeholder:"Select base entity..."})}),e.jsx(s.SelectContent,{children:a.map(w=>e.jsx(s.SelectItem,{className:"hover:bg-muted",value:w.name,children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(s.Badge,{variant:"outline",className:"text-xs",children:w.type}),w.name,e.jsx(s.Badge,{variant:"outline",className:"text-xs text-green-600",children:"BASE"})]})},w.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:m,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(w=>{const R=a.find(v=>v.name===w.source.name),E=a.find(v=>v.name===w.target.name),T=d.has(w.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:w.sequence}),e.jsxs(s.CardTitle,{className:"text-sm",children:["Join ",w.sequence,R&&E&&e.jsxs("span",{className:"ml-2 font-normal text-gray-600",children:["(",R.name," → ",E.name,")"]})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(s.Button,{variant:"ghost",size:"sm",onClick:()=>p(w.id),disabled:w.sequence===1,children:e.jsx(s.ArrowUp,{className:"h-4 w-4"})}),e.jsx(s.Button,{variant:"ghost",size:"sm",onClick:()=>g(w.id),disabled:w.sequence===l.joins.length,children:e.jsx(s.ArrowDown,{className:"h-4 w-4"})}),e.jsx(s.Button,{variant:"ghost",size:"sm",onClick:()=>x(w.id),children:T?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(w.id),children:e.jsx(s.X,{className:"h-4 w-4"})})]})]})}),T&&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:w.source.name,onValueChange:v=>{const L=a.find(z=>z.name===v);f(w.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:v,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:b(w.id).map(v=>e.jsx(s.SelectItem,{className:"hover:bg-muted",value:v.name,children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(s.Badge,{variant:"outline",className:"text-xs",children:v.type}),v.name]})},v.name))})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(s.Label,{children:"Join Type"}),e.jsxs(s.Select,{value:w.joinType,onValueChange:v=>f(w.id,{joinType: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:"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:w.target.name,onValueChange:v=>{const L=a.find(z=>z.name===v);f(w.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:v,database:L==null?void 0:L.database,schema:L==null?void 0:L.schema}})},disabled:!w.source.name,children:[e.jsx(s.SelectTrigger,{children:e.jsx(s.SelectValue,{placeholder:"Select target..."})}),e.jsx(s.SelectContent,{children:w.source.name?j(w.source.name).map(v=>e.jsx(s.SelectItem,{className:"hover:bg-muted",value:v.name,children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(s.Badge,{variant:"outline",className:"text-xs",children:v.type}),v.name,v.name===w.source.name&&e.jsx(s.Badge,{variant:"outline",className:"text-xs text-yellow-600",children:"(Self-join)"})]})},v.name)):[]})]})]})]}),w.source.name&&w.target.name&&R&&E&&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:()=>N(w.id),children:[e.jsx(s.Plus,{className:"mr-1 h-3 w-3"})," Add Condition Group"]})]}),w.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:w.joinKeyGroups.map((v,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:v.operator,onValueChange:z=>C(w.id,L,z),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:()=>O(w.id,L),children:e.jsx(s.Trash2,{className:"h-4 w-4"})})]})]}),e.jsxs("div",{className:"space-y-2",children:[v.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:v.keys.map((z,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:v.operator}),e.jsx("div",{className:"mb-2 w-full sm:mb-0 sm:flex-1",children:e.jsxs(s.Select,{value:z.source.name,onValueChange:_=>I(w.id,L,P,"sourceColumnName",_),children:[e.jsx(s.SelectTrigger,{children:e.jsx(s.SelectValue,{placeholder:"Source column"})}),e.jsx(s.SelectContent,{children:A(w.source.name).map(_=>e.jsx(s.SelectItem,{className:"hover:bg-muted",value:_.name,children:e.jsxs("div",{className:"flex w-full items-center justify-between",children:[e.jsx("span",{children:_.name}),e.jsx(s.Badge,{variant:"outline",className:"ml-2 text-xs",children:_.dataType})]})},_.name))})]})}),e.jsx("div",{className:"mb-2 w-full sm:mb-0 sm:w-20",children:e.jsxs(s.Select,{value:z.operator,onValueChange:_=>I(w.id,L,P,"operator",_),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:z.target.name,onValueChange:_=>I(w.id,L,P,"targetColumnName",_),children:[e.jsx(s.SelectTrigger,{children:e.jsx(s.SelectValue,{placeholder:"Target column"})}),e.jsx(s.SelectContent,{children:A(w.target.name).map(_=>e.jsx(s.SelectItem,{className:"hover:bg-muted",value:_.name,children:e.jsxs("div",{className:"flex w-full items-center justify-between hover:bg-muted",children:[e.jsx("span",{children:_.name}),e.jsx(s.Badge,{variant:"outline",className:"ml-2 text-xs",children:_.dataType})]})},_.name))})]})}),e.jsx(s.Button,{type:"button",variant:"ghost",size:"sm",className:"self-center",onClick:()=>y(w.id,L,P),children:e.jsx(s.X,{className:"size-3.5"})})]},z.id||P))}),e.jsxs(s.Button,{type:"button",variant:"outline",size:"sm",className:"mt-2",onClick:()=>k(w.id,L),children:[e.jsx(s.Plus,{className:"mr-1 h-3 w-3"})," Add Condition"]})]})]},v.id))})]})]})]},w.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:!S(),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(oi,{joinPlan:r,availableDataSources:o,onSave:c,onCancel:l,onRemove:i})]}),t]})}function ii({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,u)=>d+u.keys.length,0)," ","condition",o.joinKeyGroups.reduce((d,u)=>d+u.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 li(){var m,h;const t=s.useEditorStore(f=>f.card),a=s.useEditorStore(f=>f.actions.updateCardConfig),n=((m=t==null?void 0:t.config)==null?void 0:m.joinPlan)||{baseEntity:{type:"table",name:"",database:"",schema:"",connectionId:"",connectionType:"none",dialect:"none"},joins:[]},[r,o]=M.useState(!1),i=((h=t==null?void 0:t.dataSource)==null?void 0:h.selectedEntities)||[],c=f=>{a(t.id,{...t==null?void 0:t.config,joinPlan:f}),o(!1)},l=()=>{a(t.id,{...t==null?void 0:t.config,joinPlan:void 0})},d=()=>{o(!1)},u=()=>{const f=[...n.joins].sort((x,b)=>x.sequence-b.sequence),p=n.baseEntity;if(!p.name)return"SELECT * FROM table -- Please select a base entity";let g=`SELECT *
|
|
423
423
|
FROM ${p.name}`;return f.forEach(x=>{const b=i.find(C=>C.name===x.target.name);if(!b)return;const j=x.joinKeyGroups.filter(C=>C.keys&&C.keys.length>0).map(C=>{const O=C.keys.filter(k=>{var I,y,D,S;return((I=k.source)==null?void 0:I.name)&&((y=k.target)==null?void 0:y.name)&&((D=k.source)==null?void 0:D.entityName)&&((S=k.target)==null?void 0:S.entityName)}).map(k=>`${k.source.entityName}.${k.source.name} ${k.operator} ${k.target.entityName}.${k.target.name}`);return O.length>1?`(${O.join(` ${C.operator} `)})`:O[0]}).filter(Boolean),N=j.length>1?j.join(" OR "):j[0]||"condition_here";g+=`
|
|
424
424
|
${x.joinType} JOIN ${b.name}
|
|
425
|
-
ON ${N}`}),g};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(ii,{joins:n.joins,baseEntityId:n.baseEntity.name,availableDataSources:i,generateSQLPreview:u})})]})}),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 ci({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 di({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 ui({isVisible:t,onToggleVisibility:a}){s.useEditorStore(m=>m.isDevMode),s.useEditorStore(m=>m.card.connectionId),s.useDashboardStore(m=>m.isVisualEditing);const[n,r]=M.useState(!1),[o,i]=M.useState(!0),c=s.useEditorStore(m=>m.card.dataSource),{updateDataSource:l}=s.useEditorActions(),d={connectionId:"",connectionType:"",mode:"database",selectedEntities:[]},u={...d,...c,selectedEntities:(c==null?void 0:c.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":!o}),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:()=>i(!o),className:"h-6 w-6 p-0",children:o?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 ${o?"max-h-96 space-y-4":"max-h-0 py-0 opacity-0"}`,children:[u.selectedEntities.length>0&&e.jsx(s.TooltipProvider$1,{children:e.jsxs("div",{className:"flex flex-wrap gap-1",children:[u.selectedEntities.slice(0,3).map((m,h)=>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(m),e.jsx("button",{onClick:f=>{f.stopPropagation();const p=u.selectedEntities.filter(g=>!(g.name===m.name&&g.type===m.type));l({...d,...c,selectedEntities:p})},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(ci,{entity:m})]},`${m.type}-${m.name}-${h}`)),u.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:["+",u.selectedEntities.length-3," more"]})}),e.jsx(di,{entities:u.selectedEntities.slice(3)})]})]})}),e.jsx(li,{})]})]}),e.jsx(ai,{}),e.jsx(s.DataSourceDialog,{incomingSelectedEntities:(c==null?void 0:c.selectedEntities)||[],dialogMode:"dataSource",open:n,onOpenChange:r,dataSource:u,fallbackDataSource:d})]})}const ss=[{id:"table",icon:He,label:"Table"},{id:"pivotTable",icon:He,label:"Pivot 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 M.createElement(r,{className:"h-4 w-4"})}}else if(a.includes(n.id.toLowerCase())){const r=n.icon;return M.createElement(r,{className:"h-4 w-4"})}return null},mi="chart-selector-standard-first";function hi(){const[t,a]=s.useLocalStorageState(mi,!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 xi({selectedChart:t,onChartChange:a}){var I;const[n,r]=M.useState([]),[o,i]=M.useState(!1),{data:c}=Ys();hi();const d=((I=s.useEditorStore(y=>y.card).customCardPreferences)==null?void 0:I.url)||"";Ps(d);const{setCardType:u,setCardPreferences:m,setIsDevMode:h}=s.useEditorStore(y=>y.actions),{setCardCustomCfg:f,setCustomCardPreferences:p,setQueryConfig:g}=s.useEditorActions(),[x,b]=s.useLocalStorageState("chart-section-active",null),j=M.useMemo(()=>x?[x,...Nt.filter(y=>y!==x)]:Nt,[x]);M.useEffect(()=>{(async()=>{if(c){const S=(await Promise.allSettled(c.plugins.map(async A=>{try{return(await s.loadManifest(A.value)).visuals.map(R=>({name:R.name,icon:R.icon,url:A.value,pluginName:A.label,pluginType:A.type,chartType:R.chartType,componentType:R.componentType}))}catch(w){return console.error(`Failed to load manifest for plugin ${A.label}`,w),[]}}))).filter(A=>A.status==="fulfilled").flatMap(A=>A.value);r(S)}})()},[c]);function N(y){f(null),m({}),u(y),["custom","text","map"].includes(y)&&(h(!0),g(void 0)),a(y),i(!1)}function C(y){f(null),m({}),u("custom"),p({type:"component",visualType:"single",url:y.url,componentName:y.name,icon:y.icon,pluginChartType:y.chartType}),g(void 0),a("custom"),i(!1)}const O=()=>{var D;if(t==="custom"){const S=s.useEditorStore.getState().card;return((D=S==null?void 0:S.customCardPreferences)==null?void 0:D.componentName)||"Custom Visual"}const y=ss.find(S=>S.id===t);return(y==null?void 0:y.label)||"Select chart type"},k=()=>{var D,S;if(t==="custom"){const A=s.useEditorStore.getState().card,w=(D=A==null?void 0:A.customCardPreferences)==null?void 0:D.icon,R=(S=A==null?void 0:A.customCardPreferences)==null?void 0:S.componentName;if(w&&R)return e.jsx(pi,{icon:w,componentName:R});if(R){const E=et(R);if(E)return E}return e.jsx(Ye,{className:"h-4 w-4"})}const y=ss.find(A=>A.id===t);if(y){const A=y.icon;return e.jsx(A,{className:"h-4 w-4"})}return e.jsx(Ye,{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:[k(),e.jsx("span",{children:O()})]}),e.jsx(s.ChevronDown,{className:"ml-2 h-4 w-4 shrink-0 opacity-50"})]})}),e.jsx(s.PopoverContent,{className:"w-[335px] 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."}),j.map(y=>{if(y==="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=>b(D?"default":null),className:"scale-75"})]})]}),className:"[&_[cmdk-group-heading]]:text-sm [&_[cmdk-group-heading]]:font-medium [&_[cmdk-group-heading]]:text-muted-foreground",children:ss.map(D=>{const S=D.icon;return e.jsx(s.CommandItem,{value:`${D.label} ${D.id} chart graph visualization`,onSelect:()=>N(D.id),className:"flex items-center gap-2",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(S,{className:"h-4 w-4"}),e.jsx("span",{children:D.label})]})},D.id)})},"default");if(y==="standardPlugin"){const D=n.filter(S=>S.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:S=>b(S?"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(S=>S.componentType==="chart").map((S,A)=>e.jsx(bt,{pluginVisual:S,index:A,onSelect:()=>C(S)},`${S.url}-${S.name}-${A}`))},"standardPlugin"):null}if(y==="customPlugin"){const D=n.filter(S=>S.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:S=>b(S?"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((S,A)=>e.jsx(bt,{pluginVisual:S,index:A,onSelect:()=>C(S)},`${S.url}-${S.name}-${A}`))},"customPlugin"):null}return null})]})]})})]})})}const pi=({icon:t,componentName:a})=>{const n=hs(),r=et(a);return n?e.jsx(n,{className:"h-4 w-4"}):r||e.jsx(Ye,{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(qe,{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 fi({aliasTemplate:t,onAliasTemplateChange:a}){var d;const[n,r]=M.useState(t),[o,i]=M.useState(!1),c=(d=s.useEditorStore(u=>{var m;return(m=u.card.config)==null?void 0:m.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:u=>{r(u.target.value),i(!0)},onFocus:()=>i(!0),onPointerDown:u=>u.stopPropagation(),className:"h-8 text-xs",onKeyDown:u=>{u.key==="Enter"&&o&&n!==t?(a(n),i(!1)):u.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 gi({valueAliases:t,onValueAliasesChange:a}){const[n,r]=M.useState(null),[o,i]=M.useState(""),[c,l]=M.useState(""),d=()=>{a({...t,"":""})},u=h=>{const f={...t};delete f[h],a(f)},m=h=>{const f={...t};delete f[h],f[o]=c,a(f),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,f],p)=>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:g=>i(g.target.value),className:"h-8 w-24 text-xs",onPointerDown:g=>g.stopPropagation(),onKeyDown:g=>{g.key==="Enter"?m(h):g.key==="Escape"&&r(null)},"aria-label":"Edit value alias key"}),e.jsx(s.Input$1,{placeholder:"Alias label",value:c,onChange:g=>l(g.target.value),className:"h-8 w-24 text-xs",onPointerDown:g=>g.stopPropagation(),onKeyDown:g=>{g.key==="Enter"?m(h):g.key==="Escape"&&r(null)},"aria-label":"Edit value alias label"}),e.jsx(s.Button,{variant:"ghost",size:"icon",className:"h-6 w-6 p-0","aria-label":"Confirm value alias edit",onClick:()=>m(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(f)},"aria-label":"Edit value alias key"}),e.jsx(s.Input$1,{placeholder:"Alias label",value:f,className:"h-8 w-24 text-xs",readOnly:!0,onClick:()=>{r(h),i(h),l(f)},"aria-label":"Edit value alias label"}),e.jsx(s.Button,{variant:"ghost",size:"sm",className:"h-8 w-8 p-0",onClick:()=>u(h),"aria-label":"Remove value alias",children:e.jsx(s.X,{className:"h-3 w-3"})})]})},h+p)),e.jsxs(s.Button,{variant:"outline",size:"sm",className:"mt-1 h-8 text-xs",onClick:d,children:[e.jsx(s.Plus,{className:"mr-1 h-3 w-3"})," Add Value Alias"]})]})]})}function Ct({value:t,onSave:a,placeholder:n="",type:r="text",className:o=""}){const[i,c]=M.useState(t??""),[l,d]=M.useState(!1);M.useEffect(()=>{c(t??"")},[t]);const u=()=>{a(i),d(!1)},m=()=>{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?u():h.key==="Escape"&&m()},"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:u,children:e.jsx(s.Check,{className:"h-4 w-4 text-green-600"})}),e.jsx(s.Button,{variant:"ghost",size:"icon",className:"h-6 w-6 p-0","aria-label":"Cancel edit",onClick:m,children:e.jsx(s.X,{className:"h-4 w-4 text-muted-foreground"})})]})]})}function ji({field:t,zone:a,index:n,sortDirection:r,onSortDirectionChange:o,hasPivotColumns:i=!1,cardType:c}){var nt;const{attributes:l,listeners:d,setNodeRef:u,transform:m,transition:h,isDragging:f}=s.useSortable({id:t.id}),p=s.useEditorStore(W=>W.card),{updateLabel:g,handleAggregationChange:x,handleDateFormatChange:b,handleGranularityChange:j,handleAliasTemplateChange:N,handleValueAliasesChange:C,removeField:O,handleKpiComparisonTypeChange:k,handleKpiShowTrendlineChange:I,handleKpiTrendlineWindowChange:y,handleKpiTrendlineGranularityChange:D,handleKpiTargetValueChange:S}=Zs(p),[A,w]=M.useState(!1),[R,E]=M.useState(t.dateFormat||"YYYY-MM-DD"),[T,v]=M.useState(t.customFormat||""),[L,z]=M.useState(!!t.customFormat),[P,_]=M.useState(t.granularity||"day"),[V,J]=M.useState(t.aliasTemplate||""),[K,F]=M.useState(t.valueAliases||{}),U=W=>{W==="custom"?z(!0):(z(!1),E(W),a==="groupBy"&&b(n,W,""))},q=W=>{v(W),a==="groupBy"&&b(n,"custom",W)},$=W=>{var Ue;_(W);const xe=(Ue=H(W)[0])==null?void 0:Ue.value;xe&&!L&&(E(xe),a==="groupBy"&&b(n,xe,"")),a==="groupBy"&&j(n,W)},G=W=>{J(W),a==="metrics"&&N(n,W)},Q=W=>{F(W),a==="metrics"&&C(n,W)},Y=W=>{g(a,n,W)},Z=()=>{O(a,n)},te={transform:s.CSS.Transform.toString(m),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..."}]}},B=H(P),X=!oe&&a!=="pivotBy",ie=se&&a==="groupBy",be=!oe&&se&&a==="groupBy",ke=oe&&se&&a==="groupBy",ne=oe&&a==="metrics"&&((nt=p.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=()=>X?e.jsx(Ct,{value:t.label??"",onSave:Y,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=()=>be?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":R,onValueChange:U,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:B.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:T,onChange:W=>{W.stopPropagation(),q(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,Ue,at;return ke?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=p.config)==null?void 0:W.comparisonType)||"none",onValueChange:k,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=p.config)==null?void 0:ge.showTrendline)||!1,onCheckedChange:I})]})}),((xe=p.config)==null?void 0:xe.showTrendline)&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(s.Label,{className:"text-xs font-medium text-muted-foreground",children:"Trendline Window"}),e.jsx(s.Input$1,{type:"number",min:"1",max:"365",value:((Ue=p.config)==null?void 0:Ue.trendlineWindow)||30,onChange:An=>{const Ln=parseInt(An.target.value)||30;y(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=p.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=p.config)==null?void 0:W.targetValue)!==void 0&&((ge=p.config)==null?void 0:ge.targetValue)!==null?String(p.config.targetValue):"",onSave:xe=>{!isNaN(Number(xe))&&xe!==null?S(Number(xe)):S(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(fi,{aliasTemplate:V,onAliasTemplateChange:G}),e.jsx(gi,{valueAliases:K,onValueAliasesChange:Q})]})]}):null;return e.jsxs("div",{ref:u,style:te,...l,...d,className:`group mx-auto flex w-full max-w-[300px] flex-col gap-2 rounded border border-border bg-background p-2 transition-all hover:shadow-sm dark:border-gray-800 ${f?"z-50 scale-95 opacity-50":"border-slate-200"} ${a==="filters"?"cursor-default":"cursor-move"}`,children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(s.GripVertical,{className:"h-3 w-3"}),e.jsx(Sn,{dataType:ae}),e.jsx(Js,{className:"max-w-[180px] 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(),w(!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 yi({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(),u=s.useEditorStore(g=>g.card),m=s.useEditorStore(g=>g.card.type),h=a.length>0,f=(g,x)=>{var j;!((j=u.config)!=null&&j.sortByColumns)||u.config.sortByColumns.findIndex(N=>N.id===g)===-1||d(u.id,g,{direction:x})};if(t==="sortBy"&&o===!1)return null;const p=t!=="sortBy"&&m!=="kpi";return e.jsxs("div",{className:"mb-4",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}),p&&e.jsx(yi,{concept:t})]}),e.jsx("div",{ref:l,className:`min-h-[60px] rounded-lg border-2 border-dashed p-3 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(g=>g.id),strategy:s.verticalListSortingStrategy,children:e.jsx("div",{className:"flex flex-wrap gap-2",children:a.map((g,x)=>{const j=g.direction;return e.jsx("div",{className:"flex w-full items-center gap-2",children:e.jsx("div",{className:"flex-1",children:e.jsx(ji,{field:g,zone:t,index:x,sortDirection:j,onSortDirectionChange:N=>f(g.id,N),hasPivotColumns:i,cardType:m})})},g.id)})})})})]})}function vi({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,u=()=>i==="kpi"?{label:"Trend By",placeholder:"Drop fields to trend data"}:{label:"Rows",placeholder:"Drop fields to group data"},m=()=>i==="kpi"?{label:"Metric",placeholder:"Drop field for KPI"}:{label:"Metrics",placeholder:"Drop fields to measure"};return e.jsxs("div",{className:"space-y-4",children:[e.jsx(Ze,{zone:"groupBy",fields:t,label:u().label,placeholder:u().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:m().label,placeholder:m().placeholder,hasPivotColumns:a.length>0}),d&&e.jsx(Ze,{zone:"sortBy",fields:r,label:"Sort By",placeholder:"Drop fields from Rows or Metrics"})]})}function bi({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(),u=s.useEditorStore(h=>h.card),{data:m}=s.useDashboardCardQuery(u);return e.jsxs("div",{"data-content":"Chart Configuration Panel",className:"flex w-96 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(xi,{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||m}),children:e.jsx(ms,{})}),!c&&e.jsxs(s.Button,{onClick:()=>d(!c),variant:"outline",className:"h-8",size:"sm",children:[e.jsx(ka,{className:"mr-2 size-4"}),"AI"]})]}),e.jsxs(s.ScrollArea,{className:"flex-1 basis-0 px-6",children:[e.jsx(vi,{groupByFields:n,pivotByFields:r,metricsFields:o,sortByFields:i}),e.jsx(s.ScrollBar,{orientation:"horizontal"})]})]})}function Ni({initialFilters:t,availableFields:a}={}){const[n,r]=M.useState(t||{id:`group-${Date.now()}`,logicalOperator:"AND",negate:!1,conditions:[],groups:[]});s.useEditorStore(k=>k.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"},u=k=>{const I=y=>{if(y.id===k){const D=l[0]||d;return{...y,conditions:[...y.conditions,{id:`condition-${Date.now()}`,field:D,operator:"=",value:""}]}}return{...y,groups:y.groups.map(I)}};r(I(n))},m=k=>{const I=y=>{if(y.id===k){const D=l[0]||d;return{...y,groups:[...y.groups,{id:`group-${Date.now()}`,logicalOperator:"AND",negate:!1,conditions:[{id:`condition-${Date.now()}`,field:D,operator:"=",value:""}],groups:[]}]}}return{...y,groups:y.groups.map(I)}};r(I(n))},h=(k,I)=>{const y=D=>D.id===k?{...D,conditions:D.conditions.filter(S=>S.id!==I)}:{...D,groups:D.groups.map(y)};r(y(n))},f=(k,I)=>{const y=D=>D.id===k?{...D,groups:D.groups.filter(S=>S.id!==I)}:{...D,groups:D.groups.map(y)};r(y(n))},p=(k,I,y,D)=>{if(y==="field")throw new Error("Use a dedicated method to update the field property with a Field object");const S=A=>A.id===k?{...A,conditions:A.conditions.map(w=>w.id===I?{...w,[y]:D}:w)}:{...A,groups:A.groups.map(S)};r(S(n))},g=(k,I,y)=>{const D=S=>S.id===k?{...S,conditions:S.conditions.map(A=>A.id===I?{...A,...y}:A)}:{...S,groups:S.groups.map(D)};r(D(n))},x=(k,I)=>{const y=D=>D.id===k?{...D,logicalOperator:I}:{...D,groups:D.groups.map(y)};r(y(n))},b=(k,I)=>{const y=D=>D.id===k?{...D,negate:I}:{...D,groups:D.groups.map(y)};r(y(n))},j=(k,I,y)=>{const D=S=>S.id===k?{...S,conditions:s.arrayMove(S.conditions,I,y)}:{...S,groups:S.groups.map(D)};r(D(n))},N=(k,I,y)=>{const D=S=>S.id===k?{...S,groups:s.arrayMove(S.groups,I,y)}:{...S,groups:S.groups.map(D)};r(D(n))},C=k=>{if(!k||k.conditions.length===0&&k.groups.length===0)return"-- No filters defined";const I=D=>{let S="";typeof D.field=="object"?S=D.field.entityName?`${D.field.entityName}.${D.field.name}`:D.field.name:S=String(D.field);const A=D.operator;let w=D.value;if(D.field.dataType==="string"&&!["in","not in"].includes(D.operator))typeof w=="string"?w=`'${w}'`:Array.isArray(w)&&(w=`'${w.join(", ")}'`);else if(D.field.dataType==="date")(typeof w=="string"||w instanceof Date)&&(w=`DATE('${w}')`);else if(["in","not in"].includes(D.operator)){let R=[];Array.isArray(w)?R=w.map(E=>typeof E=="string"?`'${E}'`:String(E)):typeof w=="string"?R=w.split(",").map(E=>{const T=E.trim();return D.field.dataType==="string"?`'${T}'`:T}):typeof w=="number"&&(R=[String(w)]),w=`(${R.join(", ")})`}switch(A){case"contains":return typeof w=="string"?`${S} LIKE '%${w.replace(/'/g,"")}'`:`${S} LIKE '%${String(w)}'`;case"startsWith":return typeof w=="string"?`${S} LIKE '${w.replace(/'/g,"")}%'`:`${S} LIKE '${String(w)}%'`;case"endsWith":return typeof w=="string"?`${S} LIKE '%${w.replace(/'/g,"")}'`:`${S} LIKE '%${String(w)}'`;default:return`${S} ${A} ${w}`}},y=D=>{const S=D.conditions.map(I),A=D.groups.map(T=>y(T)),w=[...S,...A].filter(Boolean);if(w.length===0)return"";const R=w.join(` ${D.logicalOperator} `),E=w.length>1?`(${R})`:R;return D.negate?`NOT ${E}`:E};return y(k)},O=n.conditions.length>0||n.groups.length>0;return{currentFilters:n,setCurrentFilters:r,availableFields:l,isLoading:i,addCondition:u,addGroup:m,removeCondition:h,removeGroup:f,updateCondition:p,updateConditionFields:g,updateGroupOperator:x,updateGroupNegate:b,reorderConditions:j,reorderGroups:N,generateSQLPreview:C,hasAnyFilters:O}}function Ci({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 Si=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(ra,{className:"h-3 w-3"});default:return e.jsx(s.Table,{className:"h-3 w-3"})}},wi=t=>{if(t.qualifiedEntityName){const a=t.qualifiedEntityName.split(".");return a.length>1?a[0]:"default"}return"default"};function Di({value:t,onValueChange:a,availableFields:n,placeholder:r="Select field",className:o="w-64"}){const[i,c]=M.useState(!1),l=M.useMemo(()=>{const d={};return n.forEach(u=>{const m=wi(u);d[m]||(d[m]={}),d[m][u.entityId]||(d[m][u.entityId]=[]),d[m][u.entityId].push(u)}),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(Ci,{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,u])=>e.jsx(s.CommandGroup,{heading:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(s.Database,{className:"h-3 w-3"}),d]}),children:Object.entries(u).map(([m,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:[Si(h[0].entityType),e.jsx("span",{children:h[0].entityName})]}),h.map((f,p)=>e.jsxs(s.CommandItem,{value:f.id,onSelect:()=>{a(f),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)===f.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:f.name})}),e.jsx("div",{className:"flex items-center gap-2 text-xs text-gray-500",children:f.description&&e.jsx("span",{children:f.description})})]})]},f.id+p))]},`${d}-${m}`))},d))})]})})]})}function st(t){var g;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]},u=((g=a.dataSource)==null?void 0:g.connectionId)||a.connectionId,{data:m,isPending:h,error:f}=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:u,cardConfig:d,cardDataSource:a.dataSource})}catch(x){console.log(t),console.error("error",x)}},enabled:!!u,refetchOnMount:!0,refetchOnWindowFocus:!1});return{filterValues:((m==null?void 0:m.records)||[]).map(x=>({label:x[t.name]||"BLANK",value:x[t.name]||"BLANK",count:(x==null?void 0:x.count)||0})),isPending:h,error:f}}function ki({field:t,selected:a,onChange:n,placeholder:r="Select items...",className:o}){const[i,c]=ue.useState(!1),{filterValues:l}=st(t),d=m=>{n(a.filter(h=>h!==m))},u=m=>{a.includes(m)?n(a.filter(h=>h!==m)):n([...a,m])};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(m=>{const h=l.find(f=>f.value===m);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:f=>{f.key==="Enter"&&d(m)},onMouseDown:f=>{f.preventDefault(),f.stopPropagation()},onClick:f=>{f.stopPropagation(),d(m)},children:e.jsx(s.X,{className:"h-3 w-3 text-muted-foreground hover:text-foreground"})})]},m)}):e.jsx("span",{className:"text-muted-foreground",children:r})}),e.jsx(s.ChevronDown,{className:"ml-2 h-4 w-4 shrink-0 opacity-50"})]})}),e.jsx(s.PopoverContent,{className:"z-50 w-fit overflow-auto p-0",align:"start",children:e.jsxs(s.Command,{children:[e.jsx(s.CommandInput,{placeholder:"Search..."}),e.jsxs(s.CommandList,{children:[e.jsx(s.CommandEmpty,{children:"No results found."}),e.jsx(s.CommandGroup,{children:l.map((m,h)=>e.jsxs(s.CommandItem,{onSelect:()=>u(m.value),children:[e.jsx(s.Check,{className:s.cn("mr-2 h-4 w-4",a.includes(m.value)?"opacity-100":"opacity-0")}),e.jsxs("div",{className:"flex grow items-center justify-between gap-4",children:[e.jsx("span",{children:m.label}),e.jsx("span",{className:"text-xs text-muted-foreground",children:m.count})]})]},m.value+h))})]})]})})]})})}const wn=t=>{if(!t)return 0;let a=t.conditions.length;return t.groups.forEach(n=>{a+=wn(n)}),a};function Ti({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,u)=>e.jsx(s.SelectItem,{className:"hover:bg-muted",value:d.value,children:d.label},d.value+u))})]})}const Ei=["=","!=",">",">=","<","<=","contains","startsWith","endsWith","in","not in"],Ii=["=","!=","contains","startsWith","endsWith","in","not in"],Mi=["=","!=",">",">=","<","<=","in","not in"],Ai=["=","!="],Li=["=","!=",">",">=","<","<=","in","not in"];function Oi(t){switch(t){case"string":return Ii;case"number":return Mi;case"boolean":return Ai;case"date":return Li;default:return Ei}}function Dn({condition:t,index:a,groupId:n,groupLogicalOperator:r,onUpdateCondition:o,onRemoveCondition:i,onUpdateGroupOperator:c,availableFields:l,updateConditionFields:d}){const{attributes:u,listeners:m,setNodeRef:h,transform:f,transition:p,isDragging:g}=s.useSortable({id:t.id}),{isPending:x,error:b}=st(t.field),j={transform:s.CSS.Transform.toString(f),transition:p};return e.jsxs("div",{ref:h,style:j,className:`mb-2 flex items-center gap-2 rounded p-2 hover:bg-muted/50 ${g?"z-50 opacity-50":""}`,children:[e.jsx("div",{...u,...m,className:"cursor-grab active:cursor-grabbing",children:e.jsx(s.GripVertical,{className:"h-4 w-4 flex-shrink-0 text-gray-400"})}),a>0&&e.jsxs(s.Select,{value:r,onValueChange:N=>c(n,N),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(Di,{value:t.field,onValueChange:N=>{d(n,t.id,{field:N,value:""})},availableFields:l,placeholder:"Select field",className:"w-64"}),e.jsxs(s.Select,{value:t.operator,onValueChange:N=>{N==="in"||N==="not in"?d(n,t.id,{operator:N,value:[]}):d(n,t.id,{operator:N,value:""})},children:[e.jsx(s.SelectTrigger,{className:"w-28",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{children:Oi(s.getDataType(t.field.dataType)).map(N=>e.jsx(s.SelectItem,{className:"hover:bg-muted",value:N,children:N},N))})]}),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..."]}):b?e.jsx("div",{className:"flex-1 p-2 text-xs text-red-500",children:"Error loading values"}):e.jsx(ki,{field:t.field,selected:Array.isArray(t.value)&&t.value.every(N=>typeof N=="string")?t.value:[],onChange:N=>d(n,t.id,{value:N}),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:N=>d(n,t.id,{value:N.target.value}),className:"flex-1",placeholder:t.operator.charAt(0).toUpperCase()+t.operator.slice(1)+"..."}):e.jsx(Ti,{field:t.field,value:typeof t.value=="string"?t.value:"",onChange:N=>d(n,t.id,{value:N}),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:N=>d(n,t.id,{value:N==="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:N=>o(n,t.id,"value",N.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 Ri({group:t,depth:a,parentGroupId:n,onUpdateGroupOperator:r,onUpdateGroupNegate:o,onRemoveGroup:i,onUpdateCondition:c,onUpdateField:l,onRemoveCondition:d,onReorderConditions:u,onReorderGroups:m,onAddCondition:h,onAddGroup:f,availableFields:p,renderFilterGroup:g,updateConditionFields:x}){const{attributes:b,listeners:j,setNodeRef:N,transform:C,transition:O,isDragging:k}=s.useSortable({id:t.id}),I={transform:s.CSS.Transform.toString(C),transition:O},y=S=>{const{active:A,over:w}=S;if(w&&A.id!==w.id){const R=t.conditions.findIndex(T=>T.id===A.id),E=t.conditions.findIndex(T=>T.id===w.id);R!==-1&&E!==-1&&u(t.id,R,E)}},D=S=>{const{active:A,over:w}=S;if(w&&A.id!==w.id&&n){const R=t.groups.findIndex(T=>T.id===A.id),E=t.groups.findIndex(T=>T.id===w.id);R!==-1&&E!==-1&&m(n,R,E)}};return e.jsxs("div",{ref:N,style:I,className:`rounded-lg ${a>0?"mt-2 border border-border":""} ${k?"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",{...b,...j,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:S=>r(t.id,S),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:y,children:e.jsx(s.SortableContext,{items:t.conditions.map(S=>S.id),strategy:s.verticalListSortingStrategy,children:t.conditions.map((S,A)=>e.jsx(Dn,{condition:S,index:A,groupId:t.id,groupLogicalOperator:t.logicalOperator,onUpdateCondition:c,onUpdateField:l,onRemoveCondition:d,onUpdateGroupOperator:r,availableFields:p,updateConditionFields:x},S.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(S=>S.id),strategy:s.verticalListSortingStrategy,children:t.groups.map(S=>g(S,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:()=>f(t.id),children:[e.jsx(s.Plus,{className:"mr-1 h-3 w-3"}),"Add Group"]})]})]})]})}function Fi({filters:t,availableFields:a,onSave:n,onClearAll:r,onCancel:o}){const{currentFilters:i,availableFields:c,isLoading:l,addCondition:d,addGroup:u,removeCondition:m,removeGroup:h,updateCondition:f,updateConditionFields:p,updateGroupOperator:g,updateGroupNegate:x,reorderConditions:b,reorderGroups:j,generateSQLPreview:N,hasAnyFilters:C,setCurrentFilters:O}=Ni({initialFilters:t,availableFields:a}),k=s.useSensors(s.useSensor(s.PointerSensor),s.useSensor(s.KeyboardSensor,{coordinateGetter:s.sortableKeyboardCoordinates})),[I,y]=M.useState(!1),D=(w,R,E)=>{const T=v=>v.id===w?{...v,conditions:v.conditions.map(L=>L.id===R?{...L,field:E,dataType:E.dataType}:L)}:{...v,groups:v.groups.map(T)};O(T(i))},S=(w,R=0,E)=>R===0?e.jsx("div",{className:"rounded-lg",children:e.jsxs("div",{className:"p-3 px-0",children:[e.jsx(s.DndContext,{sensors:k,collisionDetection:s.closestCenter,onDragEnd:T=>{const{active:v,over:L}=T;if(L&&v.id!==L.id){const z=w.conditions.findIndex(_=>_.id===v.id),P=w.conditions.findIndex(_=>_.id===L.id);z!==-1&&P!==-1&&b(w.id,z,P)}},children:e.jsx(s.SortableContext,{items:w.conditions.map(T=>T.id),strategy:s.verticalListSortingStrategy,children:w.conditions.map((T,v)=>e.jsx(Dn,{condition:T,index:v,groupId:w.id,groupLogicalOperator:w.logicalOperator,onUpdateCondition:f,onUpdateField:D,onRemoveCondition:m,onUpdateGroupOperator:g,availableFields:c,updateConditionFields:p},T.id))})}),e.jsx(s.DndContext,{sensors:k,collisionDetection:s.closestCenter,onDragEnd:T=>{const{active:v,over:L}=T;if(L&&v.id!==L.id){const z=w.groups.findIndex(_=>_.id===v.id),P=w.groups.findIndex(_=>_.id===L.id);z!==-1&&P!==-1&&j(w.id,z,P)}},children:e.jsx(s.SortableContext,{items:w.groups.map(T=>T.id),strategy:s.verticalListSortingStrategy,children:w.groups.map(T=>S(T,R+1,w.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(w.id),children:[e.jsx(s.Plus,{className:"mr-1 h-3 w-3"}),"Add Condition"]}),I&&e.jsxs(s.Button,{variant:"outline",size:"sm",className:"h-7 text-xs",onClick:()=>u(w.id),children:[e.jsx(s.Plus,{className:"mr-1 h-3 w-3"}),"Add Group"]})]})]})},w.id):e.jsx(Ri,{group:w,depth:R,parentGroupId:E,onUpdateGroupOperator:g,onUpdateGroupNegate:x,onRemoveGroup:h,onUpdateCondition:f,onUpdateField:D,onRemoveCondition:m,onReorderConditions:b,onReorderGroups:j,onAddCondition:d,onAddGroup:u,availableFields:c,renderFilterGroup:S,updateConditionFields:p},w.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..."})]}):S(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:I,onCheckedChange:w=>y(!!w)}),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)"})]})}),C&&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:N(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(C?i:null),children:"Apply Filters"})]})]})}function Bi({cardId:t,filters:a,onFiltersChange:n,onClearFilters:r,availableFields:o,isOpen:i,onOpenChange:c}){const l=u=>{n(t,u),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:u=>{u.preventDefault()},children:[e.jsxs(s.DialogHeader,{children:[e.jsx(s.DialogTitle,{children:"Card Filters"}),e.jsx(s.DialogDescription,{children:"Add filters to the card to limit the data that is displayed."})]}),e.jsx(Fi,{filters:a,availableFields:o,onSave:l,onCancel:()=>c(!1),onClearAll:d})]})]})}function zi({activeCardId:t,sourceFields:a,getFieldsForContainer:n,setFieldsForContainer:r}){var p;const[o,i]=M.useState(null),c=s.useEditorStore(g=>g.card),l=(p=c==null?void 0:c.config)==null?void 0:p.joinPlan,d=[...a,...n("groupBy"),...n("pivotBy"),...n("metrics"),...n("sortBy")],u=M.useCallback(g=>g.startsWith("card-")?null:g.startsWith("source-")||a.find(x=>x.id===g)?"source":n("groupBy").find(x=>x.id===g)?"groupBy":n("metrics").find(x=>x.id===g)?"metrics":n("pivotBy").find(x=>x.id===g)?"pivotBy":n("sortBy").find(x=>x.id===g)?"sortBy":null,[a,n]),m=M.useCallback(g=>{i(g.active.id)},[]),h=M.useCallback(g=>{const{active:x,over:b}=g;if(!b||!t){i(null);return}const j=x.id,N=b.id,C=u(j),O=u(N)||N;if(C==="source"&&O==="sortBy"){i(null);return}if(C==="source"&&O!=="source"&&O!=="sortBy"){const k=[...a].find(S=>S.id===j);if(!k){i(null);return}const I=[...n("groupBy"),...n("pivotBy"),...n("metrics"),...n("sortBy")];if(I.length>0){const S=I[0].qualifiedEntityName;if(!S){i(null);return}if(S!==k.qualifiedEntityName&&k.qualifiedEntityName)if(l){if(!Cn(S,k.qualifiedEntityName,l)){Is(),i(null);return}}else{Is(),i(null);return}}const y=n(O);if(Ms(k,y)){i(null);return}const D=s.getNewField(k,O);i(null),r(O,[...y,D]);return}if(C&&O&&C!=="source"&&O!=="source"&&C!==O){const k=n(C),I=n(O),y=k.find(A=>A.id===j);if(!y){i(null);return}const D=s.getNewField(y,O);if(i(null),O==="sortBy"){if(C==="pivotBy"){i(null);return}Ms(y,I)||r(O,[...I,D]);return}const S=k.filter(A=>A.id!==j);r(C,S),r(O,[...I,D]);return}if(C&&O&&C===O&&C!=="source"){const k=n(C),I=k.findIndex(D=>D.id===j),y=k.findIndex(D=>D.id===N);if(I!==y){const D=s.arrayMove(k,I,y);r(C,D)}}i(null)},[t,a,n,r,u,l]),f=o?d.find(g=>g.id===o):null;return{activeId:o,activeField:f,handleDragStart:m,handleDragEnd:h}}function Pi({onAdvancedToggle:t,onDebugToggle:a,onAccept:n}){const r=s.useEditorStore(p=>p.isDevMode),o=s.useEditorStore(p=>p.card);s.isExplorerCard(o);const{config:i}=M.useContext(s.SemaphorContext).tokenProps,c=(i==null?void 0:i.showAdvancedMode)!==!1,{setIsDevMode:l}=s.useEditorActions(),d=s.useEditorStore(p=>p.showAIDialog),u=s.useEditorStore(p=>p.frame),m=s.useManagementStore(p=>p.selectedVisual),h=(m==null?void 0:m.id)===(u==null?void 0:u.id),{setShowAIDialog:f}=s.useEditorActions();return e.jsxs("div",{className:s.cn("flex items-center justify-between px-6 py-3",d&&"justify-end",!c&&"justify-end"),children:[c&&t&&!d&&e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(s.SmallSwitch,{className:s.cn("",{}),checked:r,onCheckedChange:()=>l(!r),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:[e.jsx(qs,{}),n&&!h&&e.jsx($s,{variant:"default"}),h&&e.jsx(Qr,{}),a&&s.isDevEnv]})]})}function Vi({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 Ui(){var d,u;const t=s.useEditorStore(m=>m.card),{updateRowLimit:a}=s.useEditorActions(),[n,r]=M.useState(!1),[o,i]=M.useState(""),c=m=>{if(m==="custom"){r(!0);return}r(!1),a(t.id,parseInt(m))},l=m=>{const h=m.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:((u=(d=t.config)==null?void 0:d.rowLimit)==null?void 0:u.toString())||"100",onValueChange:c,children:[e.jsx(s.SelectTrigger,{className:"h-8 w-24 border-none px-1 [&>svg]:hidden",children:e.jsx(s.SelectValue,{placeholder:"Select limit"})}),e.jsx(s.SelectContent,{children:_i.map(m=>e.jsx(s.SelectItem,{value:m.value,children:m.label},m.value))})]})})}function $i({isOpen:t,onClose:a}){const n=Gt(a,{enabled:t}),r=s.useEditorStore(m=>{var h;return((h=m.card.customCardPreferences)==null?void 0:h.url)||""}),o=s.useEditorStore(m=>m.card),i=s.useEditorStore(m=>{var h;return((h=m.card.customCardPreferences)==null?void 0:h.pluginChartType)||""}),c=s.useEditorStore(m=>{var h;return((h=m.card.customCardPreferences)==null?void 0:h.settings)||{}}),{data:l}=s.useDashboardCardQuery(o),{getCard:d}=s.useCustomVisual(r),u=M.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:u&&e.jsx(M.Suspense,{fallback:e.jsx("div",{children:"Loading chart settings..."}),children:e.jsx(u,{chartData:(l==null?void 0:l.records)||[],chartType:i,settings:c})})})]})})}function qi({activeView:t,onViewChange:a,showDebug:n,onDebugToggle:r,onAccept:o,onClear:i,onAdvancedToggle:c,onFiltersClick:l,filterCount:d,activeCard:u,columns:m,columnsLoading:h,columnsError:f}){var R;const p=s.useEditorStore(E=>E.card),g=s.useDashboardStore(E=>E.filterValues),{updateCardConfig:x}=s.useEditorActions(),b=s.useEditorStore(E=>E.showAIDialog),[j,N]=M.useState(!1),C=s.useEditorStore(E=>{var T;return((T=E.card.customCardPreferences)==null?void 0:T.url)&&E.card.type==="custom"}),{data:O,errorMessage:k,isPending:I,isLoading:y,isFetching:D}=s.useDashboardCardQuery(u);function S(){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(p.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(g||{},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(u.dataSource||{},null,2)})]}),e.jsxs("div",{children:[e.jsxs("h3",{className:"mb-2 text-sm font-medium",children:["Columns (",m.length,")"]}),e.jsx("pre",{className:"max-h-40 overflow-auto rounded border bg-background p-3 text-xs",children:h?"Loading...":f?"Error loading columns":JSON.stringify(m.slice(0,5),null,2)})]})]})})}const A=E=>{if(!p.config)return;if(!E.length){x(p.id,{...p.config,sortByColumns:[]});return}const T=p.config,v=E.map(({id:L,desc:z})=>{var J,K;const P=(J=T.metricColumns)==null?void 0:J.find(F=>F.label===L),_=(K=T.groupByColumns)==null?void 0:K.find(F=>F.label===L),V=P||_;return V?{id:s.getFieldId("sortBy",V),name:V.name,dataType:V.dataType,label:V.label,qualifiedEntityName:V.qualifiedEntityName,entityId:V.entityId,entityName:V.entityName,entityType:V.entityType,role:"sortby",direction:z?"desc":"asc"}:null}).filter(L=>L!==null);x(p.id,{...T,sortByColumns:v})},w=M.useMemo(()=>{var E,T;return(T=(E=p.config)==null?void 0:E.sortByColumns)==null?void 0:T.map(v=>({id:v.label,desc:v.direction==="desc"}))},[(R=p.config)==null?void 0:R.sortByColumns]);return e.jsxs("div",{className:"relative flex w-0 grow flex-col",children:[e.jsx(Pi,{showDebug:n,onDebugToggle:r,onAccept:o,onClear:i,onAdvancedToggle:c,onFiltersClick:l,filterCount:d}),n&&S(),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"&&b&&e.jsx(hn,{variant:"outline"}),e.jsx(Vi,{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(Ui,{})}),b&&e.jsx(ms,{})]}),e.jsx("div",{className:s.cn("flex grow items-center justify-end"),children:t==="chart"&&e.jsx(xn,{})})]}),!j&&C&&e.jsx(s.IconButton,{"aria-label":"Open Chart Settings",tooltip:"Open Chart Settings",onClick:()=>N(!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(Sa,{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:y||D?e.jsx("div",{className:"m-auto flex h-10 w-10 items-center justify-center rounded-md bg-muted",children:e.jsx(s.LoaderCircle,{className:"h-8 w-8 animate-spin text-muted-foreground"})}):e.jsx(pn,{})}),t==="table"&&(O==null?void 0:O.records)&&e.jsxs("div",{className:"relative flex h-full min-h-0 max-w-full flex-1 grow basis-0 p-6",children:[(y||D)&&e.jsx("div",{className:"absolute flex h-full w-full items-center justify-between",children:e.jsx("div",{className:"z-10 m-auto flex h-10 w-10 items-center justify-center rounded-md bg-muted",children:e.jsx(s.LoaderCircle,{className:"h-8 w-8 animate-spin text-muted-foreground"})})}),e.jsx(s.TableVisual,{card:u,data:O==null?void 0:O.records,onSortChange:A,sortState:w})]}),t==="sql"&&e.jsx("div",{className:"p-6",children:e.jsxs("div",{className:"rounded-md bg-background",children:[(O==null?void 0:O.sql)&&e.jsx("h3",{className:"mb-3 text-sm font-medium",children:"Generated SQL Query"}),e.jsx(rn,{sql:O==null?void 0:O.sql,error:k})]})})]}),e.jsx($i,{isOpen:j,onClose:()=>N(!1)})]})]})}function Yi({activeField:t}){const[a,n]=M.useState(!0);return M.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 Gi=()=>{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 Hi(){var F,U;const[t,a]=M.useState("chart"),[n,r]=M.useState(!1),[o,i]=M.useState(!1),[c,l]=M.useState(!0),d=s.useEditorStore(q=>q.showAIDialog),u=s.useDashboardStore(q=>q.isVisualEditing),{setCardType:m}=s.useEditorActions(),h=s.useEditorStore(q=>q.card.type);M.useEffect(()=>Gi(),[]);const f=()=>{console.log("Accept clicked - would save/apply current configuration")},p=()=>{console.log("Clear clicked - would reset all configurations")},g=()=>{console.log("Advanced mode toggled")},x=()=>{i(!0)},b=q=>{m(q)},j=s.useEditorStore(q=>q.frame),N=s.useEditorStore(q=>q.card);s.useEditorStore(q=>q.activeTabCardId),s.useEditorStore(q=>q.actions.getAvailableFields);const{addCard:C,removeCard:O,updateCard:k,setActiveCard:I,updateFilters:y}=s.useEditorActions(),{columns:D=[],isLoading:S,error:A}=s.useColumns(),w=s.useSensors(s.useSensor(s.PointerSensor,{activationConstraint:{distance:8}})),R=N,{getFieldsForContainer:E,setFieldsForContainer:T}=Zs(R),{activeField:v,handleDragStart:L,handleDragEnd:z}=zi({activeCardId:j.activeCardId,sourceFields:D,getFieldsForContainer:E,setFieldsForContainer:T}),P=(q,$)=>{$&&y(q,$)},_=q=>{var $;k(q,{config:{...($=j.cards.find(G=>G.id===q))==null?void 0:$.config,filters:void 0}})},V=D,J=q=>{if(!q)return 0;let $=q.conditions.length;return q.groups.forEach(G=>{$+=J(G)}),$},K=J(((F=R==null?void 0:R.config)==null?void 0:F.filters)||null);return e.jsxs(s.DndContext,{sensors:w,collisionDetection:s.closestCenter,onDragStart:L,onDragEnd:z,children:[e.jsxs("div",{className:"flex h-full grow",children:[e.jsx(ui,{isVisible:c,onToggleVisibility:()=>l(!c)}),e.jsxs("div",{className:"flex flex-1 transition-all duration-300 ease-in-out",children:[!d&&e.jsx(bi,{selectedChart:h,onChartChange:b,groupByFields:E("groupBy"),pivotByFields:E("pivotBy"),metricsFields:E("metrics"),sortByFields:E("sortBy")}),e.jsx(qi,{selectedChart:h,activeView:t,onViewChange:a,showDebug:n,onDebugToggle:()=>r(!n),onAccept:f,onClear:p,onAdvancedToggle:g,onFiltersClick:x,filterCount:K,activeCard:R,dataSourceState:N.dataSource||s.EMPTY_DATA_SOURCE,columns:D,columnsLoading:S,columnsError:A,getFieldsForContainer:E,cards:j.cards,activeCardId:j.activeCardId,addCard:C,setActiveCard:I})]}),!c&&u&&e.jsx("div",{className:"fixed left-6 top-[105px] z-50",children:e.jsx(s.Button,{size:"sm",variant:"outline",className:"h-10 w-10 rounded-full border-border bg-background p-0 shadow-lg hover:bg-muted",onClick:()=>l(!0),title:"Show Data Source Panel",children:e.jsx(s.Database,{className:"h-4 w-4"})})})]}),R&&e.jsx(Bi,{cardId:R.id,filters:((U=R.config)==null?void 0:U.filters)||null,onFiltersChange:P,onClearFilters:_,availableFields:V,isOpen:o,onOpenChange:i}),e.jsx(s.DragOverlay,{dropAnimation:null,children:e.jsx(Yi,{activeField:v||null})})]})}function Qi({authToken:t,onSave:a,onClose:n}){const r=M.useRef(null),o=s.useEditorStore(N=>N.showAIDialog),i=s.useEditorStore(N=>N.isDevMode),{setAuthToken:c}=s.useDashboardActions(),{setShowAIDialog:l,setOnSave:d,setOnClose:u}=s.useEditorActions(),{handleDragOver:m,handleDragEnd:h,handleDragStart:f,handleDragCancel:p,sensors:g}=Rr();M.useEffect(()=>{a&&d(a),n&&u(n)},[a,d,n,u]),M.useEffect(()=>{t&&t.accessToken&&c(t)},[t,c]),M.useEffect(()=>{var N,C;o?((N=r.current)==null||N.resize(40),l(!0)):(l(!1),(C=r.current)==null||C.resize(0))},[o,l]);function x(N){N<1?l(!1):o||l(!0)}function b(){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(Jo,{})}),e.jsx(s.ResizableHandle,{}),e.jsx(s.ResizablePanel,{"data-role":"editor-assistant-panel",ref:r,onResize:x,defaultSize:0,children:e.jsx(yt,{})})]})]})}function j(){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(Hi,{})}),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:g,onDragStart:f,onDragEnd:h,onDragOver:m,onDragCancel:p,children:e.jsx("section",{className:"isolate flex h-full grow","data-content":"editor-panel",children:b()})}):j()})}function Ki(){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(Qi,{onSave:o,onClose:i})})}function Wi(){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 Ji(){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(Wi,{})})})]})}function Xi(){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 Zi(){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(Xi,{}),e.jsx(s.DashboardTabs,{})]}),t&&e.jsx("div",{role:"filter-aside-container",className:"flex",children:e.jsx(Ji,{})})]})}function el(){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 sl({showControls:t=!1,showFooter:a=!0,...n}){return 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(el,{}),e.jsxs("main",{className:"relative flex h-full flex-col",children:[t&&e.jsx(Ir,{}),e.jsxs(s.DashboardPanel,{...n,children:[e.jsx(Ki,{}),e.jsx(Zi,{})]})]})]})]})})}exports.DashboardPlus=sl;exports.ResourceManagementPanel=sn;exports.ScheduleDashboard=Bt;exports.SelectComponent=Pe;exports.cleanCard=Ot;exports.downloadPdf=Ft;exports.getDashbaordStateWithoutData=ns;
|
|
425
|
+
ON ${N}`}),g};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(ii,{joins:n.joins,baseEntityId:n.baseEntity.name,availableDataSources:i,generateSQLPreview:u})})]})}),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 ci({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 di({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 ui({isVisible:t,onToggleVisibility:a}){s.useEditorStore(m=>m.isDevMode),s.useEditorStore(m=>m.card.connectionId),s.useDashboardStore(m=>m.isVisualEditing);const[n,r]=M.useState(!1),[o,i]=M.useState(!0),c=s.useEditorStore(m=>m.card.dataSource),{updateDataSource:l}=s.useEditorActions(),d={connectionId:"",connectionType:"",mode:"database",selectedEntities:[]},u={...d,...c,selectedEntities:(c==null?void 0:c.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":!o}),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:()=>i(!o),className:"h-6 w-6 p-0",children:o?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 ${o?"max-h-96 space-y-4":"max-h-0 py-0 opacity-0"}`,children:[u.selectedEntities.length>0&&e.jsx(s.TooltipProvider$1,{children:e.jsxs("div",{className:"flex flex-wrap gap-1",children:[u.selectedEntities.slice(0,3).map((m,h)=>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(m),e.jsx("button",{onClick:f=>{f.stopPropagation();const p=u.selectedEntities.filter(g=>!(g.name===m.name&&g.type===m.type));l({...d,...c,selectedEntities:p})},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(ci,{entity:m})]},`${m.type}-${m.name}-${h}`)),u.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:["+",u.selectedEntities.length-3," more"]})}),e.jsx(di,{entities:u.selectedEntities.slice(3)})]})]})}),e.jsx(li,{})]})]}),e.jsx(ai,{}),e.jsx(s.DataSourceDialog,{incomingSelectedEntities:(c==null?void 0:c.selectedEntities)||[],dialogMode:"dataSource",open:n,onOpenChange:r,dataSource:u,fallbackDataSource:d})]})}const ss=[{id:"table",icon:He,label:"Table"},{id:"pivotTable",icon:He,label:"Pivot 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 M.createElement(r,{className:"h-4 w-4"})}}else if(a.includes(n.id.toLowerCase())){const r=n.icon;return M.createElement(r,{className:"h-4 w-4"})}return null},mi="chart-selector-standard-first";function hi(){const[t,a]=s.useLocalStorageState(mi,!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 xi({selectedChart:t,onChartChange:a}){var I;const[n,r]=M.useState([]),[o,i]=M.useState(!1),{data:c}=Ys();hi();const d=((I=s.useEditorStore(y=>y.card).customCardPreferences)==null?void 0:I.url)||"";Ps(d);const{setCardType:u,setCardPreferences:m,setIsDevMode:h}=s.useEditorStore(y=>y.actions),{setCardCustomCfg:f,setCustomCardPreferences:p,setQueryConfig:g}=s.useEditorActions(),[x,b]=s.useLocalStorageState("chart-section-active",null),j=M.useMemo(()=>x?[x,...Nt.filter(y=>y!==x)]:Nt,[x]);M.useEffect(()=>{(async()=>{if(c){const S=(await Promise.allSettled(c.plugins.map(async A=>{try{return(await s.loadManifest(A.value)).visuals.map(R=>({name:R.name,icon:R.icon,url:A.value,pluginName:A.label,pluginType:A.type,chartType:R.chartType,componentType:R.componentType}))}catch(w){return console.error(`Failed to load manifest for plugin ${A.label}`,w),[]}}))).filter(A=>A.status==="fulfilled").flatMap(A=>A.value);r(S)}})()},[c]);function N(y){f(null),m({}),u(y),["custom","text","map"].includes(y)&&(h(!0),g(void 0)),a(y),i(!1)}function C(y){f(null),m({}),u("custom"),p({type:"component",visualType:"single",url:y.url,componentName:y.name,icon:y.icon,pluginChartType:y.chartType}),g(void 0),a("custom"),i(!1)}const O=()=>{var D;if(t==="custom"){const S=s.useEditorStore.getState().card;return((D=S==null?void 0:S.customCardPreferences)==null?void 0:D.componentName)||"Custom Visual"}const y=ss.find(S=>S.id===t);return(y==null?void 0:y.label)||"Select chart type"},k=()=>{var D,S;if(t==="custom"){const A=s.useEditorStore.getState().card,w=(D=A==null?void 0:A.customCardPreferences)==null?void 0:D.icon,R=(S=A==null?void 0:A.customCardPreferences)==null?void 0:S.componentName;if(w&&R)return e.jsx(pi,{icon:w,componentName:R});if(R){const E=et(R);if(E)return E}return e.jsx(Ye,{className:"h-4 w-4"})}const y=ss.find(A=>A.id===t);if(y){const A=y.icon;return e.jsx(A,{className:"h-4 w-4"})}return e.jsx(Ye,{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:[k(),e.jsx("span",{children:O()})]}),e.jsx(s.ChevronDown,{className:"ml-2 h-4 w-4 shrink-0 opacity-50"})]})}),e.jsx(s.PopoverContent,{className:"w-[335px] 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."}),j.map(y=>{if(y==="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=>b(D?"default":null),className:"scale-75"})]})]}),className:"[&_[cmdk-group-heading]]:text-sm [&_[cmdk-group-heading]]:font-medium [&_[cmdk-group-heading]]:text-muted-foreground",children:ss.map(D=>{const S=D.icon;return e.jsx(s.CommandItem,{value:`${D.label} ${D.id} chart graph visualization`,onSelect:()=>N(D.id),className:"flex items-center gap-2",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(S,{className:"h-4 w-4"}),e.jsx("span",{children:D.label})]})},D.id)})},"default");if(y==="standardPlugin"){const D=n.filter(S=>S.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:S=>b(S?"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(S=>S.componentType==="chart").map((S,A)=>e.jsx(bt,{pluginVisual:S,index:A,onSelect:()=>C(S)},`${S.url}-${S.name}-${A}`))},"standardPlugin"):null}if(y==="customPlugin"){const D=n.filter(S=>S.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:S=>b(S?"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((S,A)=>e.jsx(bt,{pluginVisual:S,index:A,onSelect:()=>C(S)},`${S.url}-${S.name}-${A}`))},"customPlugin"):null}return null})]})]})})]})})}const pi=({icon:t,componentName:a})=>{const n=hs(),r=et(a);return n?e.jsx(n,{className:"h-4 w-4"}):r||e.jsx(Ye,{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(qe,{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 fi({aliasTemplate:t,onAliasTemplateChange:a}){var d;const[n,r]=M.useState(t),[o,i]=M.useState(!1),c=(d=s.useEditorStore(u=>{var m;return(m=u.card.config)==null?void 0:m.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:u=>{r(u.target.value),i(!0)},onFocus:()=>i(!0),onPointerDown:u=>u.stopPropagation(),className:"h-8 text-xs",onKeyDown:u=>{u.key==="Enter"&&o&&n!==t?(a(n),i(!1)):u.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 gi({valueAliases:t,onValueAliasesChange:a}){const[n,r]=M.useState(null),[o,i]=M.useState(""),[c,l]=M.useState(""),d=()=>{a({...t,"":""})},u=h=>{const f={...t};delete f[h],a(f)},m=h=>{const f={...t};delete f[h],f[o]=c,a(f),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,f],p)=>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:g=>i(g.target.value),className:"h-8 w-24 text-xs",onPointerDown:g=>g.stopPropagation(),onKeyDown:g=>{g.key==="Enter"?m(h):g.key==="Escape"&&r(null)},"aria-label":"Edit value alias key"}),e.jsx(s.Input$1,{placeholder:"Alias label",value:c,onChange:g=>l(g.target.value),className:"h-8 w-24 text-xs",onPointerDown:g=>g.stopPropagation(),onKeyDown:g=>{g.key==="Enter"?m(h):g.key==="Escape"&&r(null)},"aria-label":"Edit value alias label"}),e.jsx(s.Button,{variant:"ghost",size:"icon",className:"h-6 w-6 p-0","aria-label":"Confirm value alias edit",onClick:()=>m(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(f)},"aria-label":"Edit value alias key"}),e.jsx(s.Input$1,{placeholder:"Alias label",value:f,className:"h-8 w-24 text-xs",readOnly:!0,onClick:()=>{r(h),i(h),l(f)},"aria-label":"Edit value alias label"}),e.jsx(s.Button,{variant:"ghost",size:"sm",className:"h-8 w-8 p-0",onClick:()=>u(h),"aria-label":"Remove value alias",children:e.jsx(s.X,{className:"h-3 w-3"})})]})},h+p)),e.jsxs(s.Button,{variant:"outline",size:"sm",className:"mt-1 h-8 text-xs",onClick:d,children:[e.jsx(s.Plus,{className:"mr-1 h-3 w-3"})," Add Value Alias"]})]})]})}function Ct({value:t,onSave:a,placeholder:n="",type:r="text",className:o=""}){const[i,c]=M.useState(t??""),[l,d]=M.useState(!1);M.useEffect(()=>{c(t??"")},[t]);const u=()=>{a(i),d(!1)},m=()=>{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?u():h.key==="Escape"&&m()},"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:u,children:e.jsx(s.Check,{className:"h-4 w-4 text-green-600"})}),e.jsx(s.Button,{variant:"ghost",size:"icon",className:"h-6 w-6 p-0","aria-label":"Cancel edit",onClick:m,children:e.jsx(s.X,{className:"h-4 w-4 text-muted-foreground"})})]})]})}function ji({field:t,zone:a,index:n,sortDirection:r,onSortDirectionChange:o,hasPivotColumns:i=!1,cardType:c}){var nt;const{attributes:l,listeners:d,setNodeRef:u,transform:m,transition:h,isDragging:f}=s.useSortable({id:t.id}),p=s.useEditorStore(W=>W.card),{updateLabel:g,handleAggregationChange:x,handleDateFormatChange:b,handleGranularityChange:j,handleAliasTemplateChange:N,handleValueAliasesChange:C,removeField:O,handleKpiComparisonTypeChange:k,handleKpiShowTrendlineChange:I,handleKpiTrendlineWindowChange:y,handleKpiTrendlineGranularityChange:D,handleKpiTargetValueChange:S}=Zs(p),[A,w]=M.useState(!1),[R,E]=M.useState(t.dateFormat||"YYYY-MM-DD"),[T,v]=M.useState(t.customFormat||""),[L,z]=M.useState(!!t.customFormat),[P,_]=M.useState(t.granularity||"day"),[V,J]=M.useState(t.aliasTemplate||""),[K,F]=M.useState(t.valueAliases||{}),U=W=>{W==="custom"?z(!0):(z(!1),E(W),a==="groupBy"&&b(n,W,""))},q=W=>{v(W),a==="groupBy"&&b(n,"custom",W)},$=W=>{var Ue;_(W);const xe=(Ue=H(W)[0])==null?void 0:Ue.value;xe&&!L&&(E(xe),a==="groupBy"&&b(n,xe,"")),a==="groupBy"&&j(n,W)},G=W=>{J(W),a==="metrics"&&N(n,W)},Q=W=>{F(W),a==="metrics"&&C(n,W)},Y=W=>{g(a,n,W)},Z=()=>{O(a,n)},te={transform:s.CSS.Transform.toString(m),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..."}]}},B=H(P),X=!oe&&a!=="pivotBy",ie=se&&a==="groupBy",be=!oe&&se&&a==="groupBy",ke=oe&&se&&a==="groupBy",ne=oe&&a==="metrics"&&((nt=p.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=()=>X?e.jsx(Ct,{value:t.label??"",onSave:Y,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=()=>be?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":R,onValueChange:U,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:B.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:T,onChange:W=>{W.stopPropagation(),q(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,Ue,at;return ke?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=p.config)==null?void 0:W.comparisonType)||"none",onValueChange:k,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=p.config)==null?void 0:ge.showTrendline)||!1,onCheckedChange:I})]})}),((xe=p.config)==null?void 0:xe.showTrendline)&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(s.Label,{className:"text-xs font-medium text-muted-foreground",children:"Trendline Window"}),e.jsx(s.Input$1,{type:"number",min:"1",max:"365",value:((Ue=p.config)==null?void 0:Ue.trendlineWindow)||30,onChange:An=>{const Ln=parseInt(An.target.value)||30;y(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=p.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=p.config)==null?void 0:W.targetValue)!==void 0&&((ge=p.config)==null?void 0:ge.targetValue)!==null?String(p.config.targetValue):"",onSave:xe=>{!isNaN(Number(xe))&&xe!==null?S(Number(xe)):S(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(fi,{aliasTemplate:V,onAliasTemplateChange:G}),e.jsx(gi,{valueAliases:K,onValueAliasesChange:Q})]})]}):null;return e.jsxs("div",{ref:u,style:te,...l,...d,className:`group mx-auto flex w-full max-w-[300px] flex-col gap-2 rounded border border-border bg-background p-2 transition-all hover:shadow-sm dark:border-gray-800 ${f?"z-50 scale-95 opacity-50":"border-slate-200"} ${a==="filters"?"cursor-default":"cursor-move"}`,children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(s.GripVertical,{className:"h-3 w-3"}),e.jsx(Sn,{dataType:ae}),e.jsx(Js,{className:"max-w-[180px] 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(),w(!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 yi({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(),u=s.useEditorStore(g=>g.card),m=s.useEditorStore(g=>g.card.type),h=a.length>0,f=(g,x)=>{var j;!((j=u.config)!=null&&j.sortByColumns)||u.config.sortByColumns.findIndex(N=>N.id===g)===-1||d(u.id,g,{direction:x})};if(t==="sortBy"&&o===!1)return null;const p=t!=="sortBy"&&m!=="kpi";return e.jsxs("div",{className:"mb-4",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}),p&&e.jsx(yi,{concept:t})]}),e.jsx("div",{ref:l,className:`min-h-[60px] rounded-lg border-2 border-dashed p-3 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(g=>g.id),strategy:s.verticalListSortingStrategy,children:e.jsx("div",{className:"flex flex-wrap gap-2",children:a.map((g,x)=>{const j=g.direction;return e.jsx("div",{className:"flex w-full items-center gap-2",children:e.jsx("div",{className:"flex-1",children:e.jsx(ji,{field:g,zone:t,index:x,sortDirection:j,onSortDirectionChange:N=>f(g.id,N),hasPivotColumns:i,cardType:m})})},g.id)})})})})]})}function vi({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,u=()=>i==="kpi"?{label:"Trend By",placeholder:"Drop fields to trend data"}:{label:"Rows",placeholder:"Drop fields to group data"},m=()=>i==="kpi"?{label:"Metric",placeholder:"Drop field for KPI"}:{label:"Metrics",placeholder:"Drop fields to measure"};return e.jsxs("div",{className:"space-y-4",children:[e.jsx(Ze,{zone:"groupBy",fields:t,label:u().label,placeholder:u().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:m().label,placeholder:m().placeholder,hasPivotColumns:a.length>0}),d&&e.jsx(Ze,{zone:"sortBy",fields:r,label:"Sort By",placeholder:"Drop fields from Rows or Metrics"})]})}function bi({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(),u=s.useEditorStore(h=>h.card),{data:m}=s.useDashboardCardQuery(u);return e.jsxs("div",{"data-content":"Chart Configuration Panel",className:"flex w-96 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(xi,{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||m}),children:e.jsx(ms,{})}),!c&&e.jsxs(s.Button,{onClick:()=>d(!c),variant:"outline",className:"h-8",size:"sm",children:[e.jsx(ka,{className:"mr-2 size-4"}),"AI"]})]}),e.jsxs(s.ScrollArea,{className:"flex-1 basis-0 px-6",children:[e.jsx(vi,{groupByFields:n,pivotByFields:r,metricsFields:o,sortByFields:i}),e.jsx(s.ScrollBar,{orientation:"horizontal"})]})]})}function Ni({initialFilters:t,availableFields:a}={}){const[n,r]=M.useState(t||{id:`group-${Date.now()}`,logicalOperator:"AND",negate:!1,conditions:[],groups:[]});s.useEditorStore(k=>k.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"},u=k=>{const I=y=>{if(y.id===k){const D=l[0]||d;return{...y,conditions:[...y.conditions,{id:`condition-${Date.now()}`,field:D,operator:"=",value:""}]}}return{...y,groups:y.groups.map(I)}};r(I(n))},m=k=>{const I=y=>{if(y.id===k){const D=l[0]||d;return{...y,groups:[...y.groups,{id:`group-${Date.now()}`,logicalOperator:"AND",negate:!1,conditions:[{id:`condition-${Date.now()}`,field:D,operator:"=",value:""}],groups:[]}]}}return{...y,groups:y.groups.map(I)}};r(I(n))},h=(k,I)=>{const y=D=>D.id===k?{...D,conditions:D.conditions.filter(S=>S.id!==I)}:{...D,groups:D.groups.map(y)};r(y(n))},f=(k,I)=>{const y=D=>D.id===k?{...D,groups:D.groups.filter(S=>S.id!==I)}:{...D,groups:D.groups.map(y)};r(y(n))},p=(k,I,y,D)=>{if(y==="field")throw new Error("Use a dedicated method to update the field property with a Field object");const S=A=>A.id===k?{...A,conditions:A.conditions.map(w=>w.id===I?{...w,[y]:D}:w)}:{...A,groups:A.groups.map(S)};r(S(n))},g=(k,I,y)=>{const D=S=>S.id===k?{...S,conditions:S.conditions.map(A=>A.id===I?{...A,...y}:A)}:{...S,groups:S.groups.map(D)};r(D(n))},x=(k,I)=>{const y=D=>D.id===k?{...D,logicalOperator:I}:{...D,groups:D.groups.map(y)};r(y(n))},b=(k,I)=>{const y=D=>D.id===k?{...D,negate:I}:{...D,groups:D.groups.map(y)};r(y(n))},j=(k,I,y)=>{const D=S=>S.id===k?{...S,conditions:s.arrayMove(S.conditions,I,y)}:{...S,groups:S.groups.map(D)};r(D(n))},N=(k,I,y)=>{const D=S=>S.id===k?{...S,groups:s.arrayMove(S.groups,I,y)}:{...S,groups:S.groups.map(D)};r(D(n))},C=k=>{if(!k||k.conditions.length===0&&k.groups.length===0)return"-- No filters defined";const I=D=>{let S="";typeof D.field=="object"?S=D.field.entityName?`${D.field.entityName}.${D.field.name}`:D.field.name:S=String(D.field);const A=D.operator;let w=D.value;if(D.field.dataType==="string"&&!["in","not in"].includes(D.operator))typeof w=="string"?w=`'${w}'`:Array.isArray(w)&&(w=`'${w.join(", ")}'`);else if(D.field.dataType==="date")(typeof w=="string"||w instanceof Date)&&(w=`DATE('${w}')`);else if(["in","not in"].includes(D.operator)){let R=[];Array.isArray(w)?R=w.map(E=>typeof E=="string"?`'${E}'`:String(E)):typeof w=="string"?R=w.split(",").map(E=>{const T=E.trim();return D.field.dataType==="string"?`'${T}'`:T}):typeof w=="number"&&(R=[String(w)]),w=`(${R.join(", ")})`}switch(A){case"contains":return typeof w=="string"?`${S} LIKE '%${w.replace(/'/g,"")}'`:`${S} LIKE '%${String(w)}'`;case"startsWith":return typeof w=="string"?`${S} LIKE '${w.replace(/'/g,"")}%'`:`${S} LIKE '${String(w)}%'`;case"endsWith":return typeof w=="string"?`${S} LIKE '%${w.replace(/'/g,"")}'`:`${S} LIKE '%${String(w)}'`;default:return`${S} ${A} ${w}`}},y=D=>{const S=D.conditions.map(I),A=D.groups.map(T=>y(T)),w=[...S,...A].filter(Boolean);if(w.length===0)return"";const R=w.join(` ${D.logicalOperator} `),E=w.length>1?`(${R})`:R;return D.negate?`NOT ${E}`:E};return y(k)},O=n.conditions.length>0||n.groups.length>0;return{currentFilters:n,setCurrentFilters:r,availableFields:l,isLoading:i,addCondition:u,addGroup:m,removeCondition:h,removeGroup:f,updateCondition:p,updateConditionFields:g,updateGroupOperator:x,updateGroupNegate:b,reorderConditions:j,reorderGroups:N,generateSQLPreview:C,hasAnyFilters:O}}function Ci({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 Si=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(ra,{className:"h-3 w-3"});default:return e.jsx(s.Table,{className:"h-3 w-3"})}},wi=t=>{if(t.qualifiedEntityName){const a=t.qualifiedEntityName.split(".");return a.length>1?a[0]:"default"}return"default"};function Di({value:t,onValueChange:a,availableFields:n,placeholder:r="Select field",className:o="w-64"}){const[i,c]=M.useState(!1),l=M.useMemo(()=>{const d={};return n.forEach(u=>{const m=wi(u);d[m]||(d[m]={}),d[m][u.entityId]||(d[m][u.entityId]=[]),d[m][u.entityId].push(u)}),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(Ci,{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,u])=>e.jsx(s.CommandGroup,{heading:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(s.Database,{className:"h-3 w-3"}),d]}),children:Object.entries(u).map(([m,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:[Si(h[0].entityType),e.jsx("span",{children:h[0].entityName})]}),h.map((f,p)=>e.jsxs(s.CommandItem,{value:f.id,onSelect:()=>{a(f),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)===f.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:f.name})}),e.jsx("div",{className:"flex items-center gap-2 text-xs text-gray-500",children:f.description&&e.jsx("span",{children:f.description})})]})]},f.id+p))]},`${d}-${m}`))},d))})]})})]})}function st(t){var g;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]},u=((g=a.dataSource)==null?void 0:g.connectionId)||a.connectionId,{data:m,isPending:h,error:f}=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:u,cardConfig:d,cardDataSource:a.dataSource})}catch(x){console.log(t),console.error("error",x)}},enabled:!!u,refetchOnMount:!0,refetchOnWindowFocus:!1});return{filterValues:((m==null?void 0:m.records)||[]).map(x=>({label:x[t.name]||"BLANK",value:x[t.name]||"BLANK",count:(x==null?void 0:x.count)||0})),isPending:h,error:f}}function ki({field:t,selected:a,onChange:n,placeholder:r="Select items...",className:o}){const[i,c]=ue.useState(!1),{filterValues:l}=st(t),d=m=>{n(a.filter(h=>h!==m))},u=m=>{a.includes(m)?n(a.filter(h=>h!==m)):n([...a,m])};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(m=>{const h=l.find(f=>f.value===m);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:f=>{f.key==="Enter"&&d(m)},onMouseDown:f=>{f.preventDefault(),f.stopPropagation()},onClick:f=>{f.stopPropagation(),d(m)},children:e.jsx(s.X,{className:"h-3 w-3 text-muted-foreground hover:text-foreground"})})]},m)}):e.jsx("span",{className:"text-muted-foreground",children:r})}),e.jsx(s.ChevronDown,{className:"ml-2 h-4 w-4 shrink-0 opacity-50"})]})}),e.jsx(s.PopoverContent,{className:"z-50 w-fit overflow-auto p-0",align:"start",children:e.jsxs(s.Command,{children:[e.jsx(s.CommandInput,{placeholder:"Search..."}),e.jsxs(s.CommandList,{children:[e.jsx(s.CommandEmpty,{children:"No results found."}),e.jsx(s.CommandGroup,{children:l.map((m,h)=>e.jsxs(s.CommandItem,{onSelect:()=>u(m.value),children:[e.jsx(s.Check,{className:s.cn("mr-2 h-4 w-4",a.includes(m.value)?"opacity-100":"opacity-0")}),e.jsxs("div",{className:"flex grow items-center justify-between gap-4",children:[e.jsx("span",{children:m.label}),e.jsx("span",{className:"text-xs text-muted-foreground",children:m.count})]})]},m.value+h))})]})]})})]})})}const wn=t=>{if(!t)return 0;let a=t.conditions.length;return t.groups.forEach(n=>{a+=wn(n)}),a};function Ti({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,u)=>e.jsx(s.SelectItem,{className:"hover:bg-muted",value:d.value,children:d.label},d.value+u))})]})}const Ei=["=","!=",">",">=","<","<=","contains","startsWith","endsWith","in","not in"],Ii=["=","!=","contains","startsWith","endsWith","in","not in"],Mi=["=","!=",">",">=","<","<=","in","not in"],Ai=["=","!="],Li=["=","!=",">",">=","<","<=","in","not in"];function Oi(t){switch(t){case"string":return Ii;case"number":return Mi;case"boolean":return Ai;case"date":return Li;default:return Ei}}function Dn({condition:t,index:a,groupId:n,groupLogicalOperator:r,onUpdateCondition:o,onRemoveCondition:i,onUpdateGroupOperator:c,availableFields:l,updateConditionFields:d}){const{attributes:u,listeners:m,setNodeRef:h,transform:f,transition:p,isDragging:g}=s.useSortable({id:t.id}),{isPending:x,error:b}=st(t.field),j={transform:s.CSS.Transform.toString(f),transition:p};return e.jsxs("div",{ref:h,style:j,className:`mb-2 flex items-center gap-2 rounded p-2 hover:bg-muted/50 ${g?"z-50 opacity-50":""}`,children:[e.jsx("div",{...u,...m,className:"cursor-grab active:cursor-grabbing",children:e.jsx(s.GripVertical,{className:"h-4 w-4 flex-shrink-0 text-gray-400"})}),a>0&&e.jsxs(s.Select,{value:r,onValueChange:N=>c(n,N),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(Di,{value:t.field,onValueChange:N=>{d(n,t.id,{field:N,value:""})},availableFields:l,placeholder:"Select field",className:"w-64"}),e.jsxs(s.Select,{value:t.operator,onValueChange:N=>{N==="in"||N==="not in"?d(n,t.id,{operator:N,value:[]}):d(n,t.id,{operator:N,value:""})},children:[e.jsx(s.SelectTrigger,{className:"w-28",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{children:Oi(s.getDataType(t.field.dataType)).map(N=>e.jsx(s.SelectItem,{className:"hover:bg-muted",value:N,children:N},N))})]}),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..."]}):b?e.jsx("div",{className:"flex-1 p-2 text-xs text-red-500",children:"Error loading values"}):e.jsx(ki,{field:t.field,selected:Array.isArray(t.value)&&t.value.every(N=>typeof N=="string")?t.value:[],onChange:N=>d(n,t.id,{value:N}),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:N=>d(n,t.id,{value:N.target.value}),className:"flex-1",placeholder:t.operator.charAt(0).toUpperCase()+t.operator.slice(1)+"..."}):e.jsx(Ti,{field:t.field,value:typeof t.value=="string"?t.value:"",onChange:N=>d(n,t.id,{value:N}),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:N=>d(n,t.id,{value:N==="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:N=>o(n,t.id,"value",N.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 Ri({group:t,depth:a,parentGroupId:n,onUpdateGroupOperator:r,onUpdateGroupNegate:o,onRemoveGroup:i,onUpdateCondition:c,onUpdateField:l,onRemoveCondition:d,onReorderConditions:u,onReorderGroups:m,onAddCondition:h,onAddGroup:f,availableFields:p,renderFilterGroup:g,updateConditionFields:x}){const{attributes:b,listeners:j,setNodeRef:N,transform:C,transition:O,isDragging:k}=s.useSortable({id:t.id}),I={transform:s.CSS.Transform.toString(C),transition:O},y=S=>{const{active:A,over:w}=S;if(w&&A.id!==w.id){const R=t.conditions.findIndex(T=>T.id===A.id),E=t.conditions.findIndex(T=>T.id===w.id);R!==-1&&E!==-1&&u(t.id,R,E)}},D=S=>{const{active:A,over:w}=S;if(w&&A.id!==w.id&&n){const R=t.groups.findIndex(T=>T.id===A.id),E=t.groups.findIndex(T=>T.id===w.id);R!==-1&&E!==-1&&m(n,R,E)}};return e.jsxs("div",{ref:N,style:I,className:`rounded-lg ${a>0?"mt-2 border border-border":""} ${k?"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",{...b,...j,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:S=>r(t.id,S),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:y,children:e.jsx(s.SortableContext,{items:t.conditions.map(S=>S.id),strategy:s.verticalListSortingStrategy,children:t.conditions.map((S,A)=>e.jsx(Dn,{condition:S,index:A,groupId:t.id,groupLogicalOperator:t.logicalOperator,onUpdateCondition:c,onUpdateField:l,onRemoveCondition:d,onUpdateGroupOperator:r,availableFields:p,updateConditionFields:x},S.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(S=>S.id),strategy:s.verticalListSortingStrategy,children:t.groups.map(S=>g(S,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:()=>f(t.id),children:[e.jsx(s.Plus,{className:"mr-1 h-3 w-3"}),"Add Group"]})]})]})]})}function Fi({filters:t,availableFields:a,onSave:n,onClearAll:r,onCancel:o}){const{currentFilters:i,availableFields:c,isLoading:l,addCondition:d,addGroup:u,removeCondition:m,removeGroup:h,updateCondition:f,updateConditionFields:p,updateGroupOperator:g,updateGroupNegate:x,reorderConditions:b,reorderGroups:j,generateSQLPreview:N,hasAnyFilters:C,setCurrentFilters:O}=Ni({initialFilters:t,availableFields:a}),k=s.useSensors(s.useSensor(s.PointerSensor),s.useSensor(s.KeyboardSensor,{coordinateGetter:s.sortableKeyboardCoordinates})),[I,y]=M.useState(!1),D=(w,R,E)=>{const T=v=>v.id===w?{...v,conditions:v.conditions.map(L=>L.id===R?{...L,field:E,dataType:E.dataType}:L)}:{...v,groups:v.groups.map(T)};O(T(i))},S=(w,R=0,E)=>R===0?e.jsx("div",{className:"rounded-lg",children:e.jsxs("div",{className:"p-3 px-0",children:[e.jsx(s.DndContext,{sensors:k,collisionDetection:s.closestCenter,onDragEnd:T=>{const{active:v,over:L}=T;if(L&&v.id!==L.id){const z=w.conditions.findIndex(_=>_.id===v.id),P=w.conditions.findIndex(_=>_.id===L.id);z!==-1&&P!==-1&&b(w.id,z,P)}},children:e.jsx(s.SortableContext,{items:w.conditions.map(T=>T.id),strategy:s.verticalListSortingStrategy,children:w.conditions.map((T,v)=>e.jsx(Dn,{condition:T,index:v,groupId:w.id,groupLogicalOperator:w.logicalOperator,onUpdateCondition:f,onUpdateField:D,onRemoveCondition:m,onUpdateGroupOperator:g,availableFields:c,updateConditionFields:p},T.id))})}),e.jsx(s.DndContext,{sensors:k,collisionDetection:s.closestCenter,onDragEnd:T=>{const{active:v,over:L}=T;if(L&&v.id!==L.id){const z=w.groups.findIndex(_=>_.id===v.id),P=w.groups.findIndex(_=>_.id===L.id);z!==-1&&P!==-1&&j(w.id,z,P)}},children:e.jsx(s.SortableContext,{items:w.groups.map(T=>T.id),strategy:s.verticalListSortingStrategy,children:w.groups.map(T=>S(T,R+1,w.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(w.id),children:[e.jsx(s.Plus,{className:"mr-1 h-3 w-3"}),"Add Condition"]}),I&&e.jsxs(s.Button,{variant:"outline",size:"sm",className:"h-7 text-xs",onClick:()=>u(w.id),children:[e.jsx(s.Plus,{className:"mr-1 h-3 w-3"}),"Add Group"]})]})]})},w.id):e.jsx(Ri,{group:w,depth:R,parentGroupId:E,onUpdateGroupOperator:g,onUpdateGroupNegate:x,onRemoveGroup:h,onUpdateCondition:f,onUpdateField:D,onRemoveCondition:m,onReorderConditions:b,onReorderGroups:j,onAddCondition:d,onAddGroup:u,availableFields:c,renderFilterGroup:S,updateConditionFields:p},w.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..."})]}):S(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:I,onCheckedChange:w=>y(!!w)}),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)"})]})}),C&&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:N(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(C?i:null),children:"Apply Filters"})]})]})}function Bi({cardId:t,filters:a,onFiltersChange:n,onClearFilters:r,availableFields:o,isOpen:i,onOpenChange:c}){const l=u=>{n(t,u),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:u=>{u.preventDefault()},children:[e.jsxs(s.DialogHeader,{children:[e.jsx(s.DialogTitle,{children:"Card Filters"}),e.jsx(s.DialogDescription,{children:"Add filters to the card to limit the data that is displayed."})]}),e.jsx(Fi,{filters:a,availableFields:o,onSave:l,onCancel:()=>c(!1),onClearAll:d})]})]})}function zi({activeCardId:t,sourceFields:a,getFieldsForContainer:n,setFieldsForContainer:r}){var p;const[o,i]=M.useState(null),c=s.useEditorStore(g=>g.card),l=(p=c==null?void 0:c.config)==null?void 0:p.joinPlan,d=[...a,...n("groupBy"),...n("pivotBy"),...n("metrics"),...n("sortBy")],u=M.useCallback(g=>g.startsWith("card-")?null:g.startsWith("source-")||a.find(x=>x.id===g)?"source":n("groupBy").find(x=>x.id===g)?"groupBy":n("metrics").find(x=>x.id===g)?"metrics":n("pivotBy").find(x=>x.id===g)?"pivotBy":n("sortBy").find(x=>x.id===g)?"sortBy":null,[a,n]),m=M.useCallback(g=>{i(g.active.id)},[]),h=M.useCallback(g=>{const{active:x,over:b}=g;if(!b||!t){i(null);return}const j=x.id,N=b.id,C=u(j),O=u(N)||N;if(C==="source"&&O==="sortBy"){i(null);return}if(C==="source"&&O!=="source"&&O!=="sortBy"){const k=[...a].find(S=>S.id===j);if(!k){i(null);return}const I=[...n("groupBy"),...n("pivotBy"),...n("metrics"),...n("sortBy")];if(I.length>0){const S=I[0].qualifiedEntityName;if(!S){i(null);return}if(S!==k.qualifiedEntityName&&k.qualifiedEntityName)if(l){if(!Cn(S,k.qualifiedEntityName,l)){Is(),i(null);return}}else{Is(),i(null);return}}const y=n(O);if(Ms(k,y)){i(null);return}const D=s.getNewField(k,O);i(null),r(O,[...y,D]);return}if(C&&O&&C!=="source"&&O!=="source"&&C!==O){const k=n(C),I=n(O),y=k.find(A=>A.id===j);if(!y){i(null);return}const D=s.getNewField(y,O);if(i(null),O==="sortBy"){if(C==="pivotBy"){i(null);return}Ms(y,I)||r(O,[...I,D]);return}const S=k.filter(A=>A.id!==j);r(C,S),r(O,[...I,D]);return}if(C&&O&&C===O&&C!=="source"){const k=n(C),I=k.findIndex(D=>D.id===j),y=k.findIndex(D=>D.id===N);if(I!==y){const D=s.arrayMove(k,I,y);r(C,D)}}i(null)},[t,a,n,r,u,l]),f=o?d.find(g=>g.id===o):null;return{activeId:o,activeField:f,handleDragStart:m,handleDragEnd:h}}function Pi({onAdvancedToggle:t,onDebugToggle:a,onAccept:n}){const r=s.useEditorStore(p=>p.isDevMode),o=s.useEditorStore(p=>p.card);s.isExplorerCard(o);const{config:i}=M.useContext(s.SemaphorContext).tokenProps,c=(i==null?void 0:i.showAdvancedMode)!==!1,{setIsDevMode:l}=s.useEditorActions(),d=s.useEditorStore(p=>p.showAIDialog),u=s.useEditorStore(p=>p.frame),m=s.useManagementStore(p=>p.selectedVisual),h=(m==null?void 0:m.id)===(u==null?void 0:u.id),{setShowAIDialog:f}=s.useEditorActions();return e.jsxs("div",{className:s.cn("flex items-center justify-between px-6 py-3",d&&"justify-end",!c&&"justify-end"),children:[c&&t&&!d&&e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(s.SmallSwitch,{className:s.cn("",{}),checked:r,onCheckedChange:()=>l(!r),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:[e.jsx(qs,{}),n&&!h&&e.jsx($s,{variant:"default"}),h&&e.jsx(Qr,{}),a&&s.isDevEnv]})]})}function Vi({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 Ui(){var d,u;const t=s.useEditorStore(m=>m.card),{updateRowLimit:a}=s.useEditorActions(),[n,r]=M.useState(!1),[o,i]=M.useState(""),c=m=>{if(m==="custom"){r(!0);return}r(!1),a(t.id,parseInt(m))},l=m=>{const h=m.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:((u=(d=t.config)==null?void 0:d.rowLimit)==null?void 0:u.toString())||"100",onValueChange:c,children:[e.jsx(s.SelectTrigger,{className:"h-8 w-24 border-none px-1 [&>svg]:hidden",children:e.jsx(s.SelectValue,{placeholder:"Select limit"})}),e.jsx(s.SelectContent,{children:_i.map(m=>e.jsx(s.SelectItem,{value:m.value,children:m.label},m.value))})]})})}function $i({isOpen:t,onClose:a}){const n=Gt(a,{enabled:t}),r=s.useEditorStore(m=>{var h;return((h=m.card.customCardPreferences)==null?void 0:h.url)||""}),o=s.useEditorStore(m=>m.card),i=s.useEditorStore(m=>{var h;return((h=m.card.customCardPreferences)==null?void 0:h.pluginChartType)||""}),c=s.useEditorStore(m=>{var h;return((h=m.card.customCardPreferences)==null?void 0:h.settings)||{}}),{data:l}=s.useDashboardCardQuery(o),{getCard:d}=s.useCustomVisual(r),u=M.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:u&&e.jsx(M.Suspense,{fallback:e.jsx("div",{children:"Loading chart settings..."}),children:e.jsx(u,{chartData:(l==null?void 0:l.records)||[],chartType:i,settings:c})})})]})})}function qi({activeView:t,onViewChange:a,showDebug:n,onDebugToggle:r,onAccept:o,onClear:i,onAdvancedToggle:c,onFiltersClick:l,filterCount:d,activeCard:u,columns:m,columnsLoading:h,columnsError:f}){var R;const p=s.useEditorStore(E=>E.card),g=s.useDashboardStore(E=>E.filterValues),{updateCardConfig:x}=s.useEditorActions(),b=s.useEditorStore(E=>E.showAIDialog),[j,N]=M.useState(!1),C=s.useEditorStore(E=>{var T;return((T=E.card.customCardPreferences)==null?void 0:T.url)&&E.card.type==="custom"}),{data:O,errorMessage:k,isPending:I,isLoading:y,isFetching:D}=s.useDashboardCardQuery(u);function S(){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(p.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(g||{},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(u.dataSource||{},null,2)})]}),e.jsxs("div",{children:[e.jsxs("h3",{className:"mb-2 text-sm font-medium",children:["Columns (",m.length,")"]}),e.jsx("pre",{className:"max-h-40 overflow-auto rounded border bg-background p-3 text-xs",children:h?"Loading...":f?"Error loading columns":JSON.stringify(m.slice(0,5),null,2)})]})]})})}const A=E=>{if(!p.config)return;if(!E.length){x(p.id,{...p.config,sortByColumns:[]});return}const T=p.config,v=E.map(({id:L,desc:z})=>{var J,K;const P=(J=T.metricColumns)==null?void 0:J.find(F=>F.label===L),_=(K=T.groupByColumns)==null?void 0:K.find(F=>F.label===L),V=P||_;return V?{id:s.getFieldId("sortBy",V),name:V.name,dataType:V.dataType,label:V.label,qualifiedEntityName:V.qualifiedEntityName,entityId:V.entityId,entityName:V.entityName,entityType:V.entityType,role:"sortby",direction:z?"desc":"asc"}:null}).filter(L=>L!==null);x(p.id,{...T,sortByColumns:v})},w=M.useMemo(()=>{var E,T;return(T=(E=p.config)==null?void 0:E.sortByColumns)==null?void 0:T.map(v=>({id:v.label,desc:v.direction==="desc"}))},[(R=p.config)==null?void 0:R.sortByColumns]);return e.jsxs("div",{className:"relative flex w-0 grow flex-col",children:[e.jsx(Pi,{showDebug:n,onDebugToggle:r,onAccept:o,onClear:i,onAdvancedToggle:c,onFiltersClick:l,filterCount:d}),n&&S(),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"&&b&&e.jsx(hn,{variant:"outline"}),e.jsx(Vi,{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(Ui,{})}),b&&e.jsx(ms,{})]}),e.jsx("div",{className:s.cn("flex grow items-center justify-end"),children:t==="chart"&&e.jsx(xn,{})})]}),!j&&C&&e.jsx(s.IconButton,{"aria-label":"Open Chart Settings",tooltip:"Open Chart Settings",onClick:()=>N(!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(Sa,{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:y||D?e.jsx("div",{className:"m-auto flex h-10 w-10 items-center justify-center rounded-md bg-muted",children:e.jsx(s.LoaderCircle,{className:"h-8 w-8 animate-spin text-muted-foreground"})}):e.jsx(pn,{})}),t==="table"&&(O==null?void 0:O.records)&&e.jsxs("div",{className:"relative flex h-full min-h-0 max-w-full flex-1 grow basis-0 p-6",children:[(y||D)&&e.jsx("div",{className:"absolute flex h-full w-full items-center justify-between",children:e.jsx("div",{className:"z-10 m-auto flex h-10 w-10 items-center justify-center rounded-md bg-muted",children:e.jsx(s.LoaderCircle,{className:"h-8 w-8 animate-spin text-muted-foreground"})})}),e.jsx(s.TableVisual,{card:u,data:O==null?void 0:O.records,onSortChange:A,sortState:w})]}),t==="sql"&&e.jsx("div",{className:"p-6",children:e.jsxs("div",{className:"rounded-md bg-background",children:[(O==null?void 0:O.sql)&&e.jsx("h3",{className:"mb-3 text-sm font-medium",children:"Generated SQL Query"}),e.jsx(rn,{sql:O==null?void 0:O.sql,error:k})]})})]}),e.jsx($i,{isOpen:j,onClose:()=>N(!1)})]})]})}function Yi({activeField:t}){const[a,n]=M.useState(!0);return M.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 Gi=()=>{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 Hi(){var F,U;const[t,a]=M.useState("chart"),[n,r]=M.useState(!1),[o,i]=M.useState(!1),[c,l]=M.useState(!0),d=s.useEditorStore(q=>q.showAIDialog),u=s.useDashboardStore(q=>q.isVisualEditing),{setCardType:m}=s.useEditorActions(),h=s.useEditorStore(q=>q.card.type);M.useEffect(()=>Gi(),[]);const f=()=>{console.log("Accept clicked - would save/apply current configuration")},p=()=>{console.log("Clear clicked - would reset all configurations")},g=()=>{console.log("Advanced mode toggled")},x=()=>{i(!0)},b=q=>{m(q)},j=s.useEditorStore(q=>q.frame),N=s.useEditorStore(q=>q.card);s.useEditorStore(q=>q.activeTabCardId),s.useEditorStore(q=>q.actions.getAvailableFields);const{addCard:C,removeCard:O,updateCard:k,setActiveCard:I,updateFilters:y}=s.useEditorActions(),{columns:D=[],isLoading:S,error:A}=s.useColumns(),w=s.useSensors(s.useSensor(s.PointerSensor,{activationConstraint:{distance:8}})),R=N,{getFieldsForContainer:E,setFieldsForContainer:T}=Zs(R),{activeField:v,handleDragStart:L,handleDragEnd:z}=zi({activeCardId:j.activeCardId,sourceFields:D,getFieldsForContainer:E,setFieldsForContainer:T}),P=(q,$)=>{$&&y(q,$)},_=q=>{var $;k(q,{config:{...($=j.cards.find(G=>G.id===q))==null?void 0:$.config,filters:void 0}})},V=D,J=q=>{if(!q)return 0;let $=q.conditions.length;return q.groups.forEach(G=>{$+=J(G)}),$},K=J(((F=R==null?void 0:R.config)==null?void 0:F.filters)||null);return e.jsxs(s.DndContext,{sensors:w,collisionDetection:s.closestCenter,onDragStart:L,onDragEnd:z,children:[e.jsxs("div",{className:"flex h-full grow",children:[e.jsx(ui,{isVisible:c,onToggleVisibility:()=>l(!c)}),e.jsxs("div",{className:"flex flex-1 transition-all duration-300 ease-in-out",children:[!d&&e.jsx(bi,{selectedChart:h,onChartChange:b,groupByFields:E("groupBy"),pivotByFields:E("pivotBy"),metricsFields:E("metrics"),sortByFields:E("sortBy")}),e.jsx(qi,{selectedChart:h,activeView:t,onViewChange:a,showDebug:n,onDebugToggle:()=>r(!n),onAccept:f,onClear:p,onAdvancedToggle:g,onFiltersClick:x,filterCount:K,activeCard:R,dataSourceState:N.dataSource||s.EMPTY_DATA_SOURCE,columns:D,columnsLoading:S,columnsError:A,getFieldsForContainer:E,cards:j.cards,activeCardId:j.activeCardId,addCard:C,setActiveCard:I})]}),!c&&u&&e.jsx("div",{className:"fixed left-6 top-[105px] z-50",children:e.jsx(s.Button,{size:"sm",variant:"outline",className:"h-10 w-10 rounded-full border-border bg-background p-0 shadow-lg hover:bg-muted",onClick:()=>l(!0),title:"Show Data Source Panel",children:e.jsx(s.Database,{className:"h-4 w-4"})})})]}),R&&e.jsx(Bi,{cardId:R.id,filters:((U=R.config)==null?void 0:U.filters)||null,onFiltersChange:P,onClearFilters:_,availableFields:V,isOpen:o,onOpenChange:i}),e.jsx(s.DragOverlay,{dropAnimation:null,children:e.jsx(Yi,{activeField:v||null})})]})}function Qi({authToken:t,onSave:a,onClose:n}){const r=M.useRef(null),o=s.useEditorStore(N=>N.showAIDialog),i=s.useEditorStore(N=>N.isDevMode),{setAuthToken:c}=s.useDashboardActions(),{setShowAIDialog:l,setOnSave:d,setOnClose:u}=s.useEditorActions(),{handleDragOver:m,handleDragEnd:h,handleDragStart:f,handleDragCancel:p,sensors:g}=Rr();M.useEffect(()=>{a&&d(a),n&&u(n)},[a,d,n,u]),M.useEffect(()=>{t&&t.accessToken&&c(t)},[t,c]),M.useEffect(()=>{var N,C;o?((N=r.current)==null||N.resize(40),l(!0)):(l(!1),(C=r.current)==null||C.resize(0))},[o,l]);function x(N){N<1?l(!1):o||l(!0)}function b(){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(Jo,{})}),e.jsx(s.ResizableHandle,{}),e.jsx(s.ResizablePanel,{"data-role":"editor-assistant-panel",ref:r,onResize:x,defaultSize:0,children:e.jsx(yt,{})})]})]})}function j(){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(Hi,{})}),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:g,onDragStart:f,onDragEnd:h,onDragOver:m,onDragCancel:p,children:e.jsx("section",{className:"isolate flex h-full grow","data-content":"editor-panel",children:b()})}):j()})}function Ki(){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(Qi,{onSave:o,onClose:i})})}function Wi(){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 Ji(){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(Wi,{})})})]})}function Xi(){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 Zi(){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(Xi,{}),e.jsx(s.DashboardTabs,{})]}),t&&e.jsx("div",{role:"filter-aside-container",className:"flex",children:e.jsx(Ji,{})})]})}function el(){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 sl({showControls:t=!1,showFooter:a=!0,...n}){return 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(el,{}),e.jsxs("main",{className:"relative flex h-full w-full flex-col",children:[t&&e.jsx(Ir,{}),e.jsxs(s.DashboardPanel,{...n,children:[e.jsx(Ki,{}),e.jsx(Zi,{})]})]})]})]})})}exports.DashboardPlus=sl;exports.ResourceManagementPanel=sn;exports.ScheduleDashboard=Bt;exports.SelectComponent=Pe;exports.cleanCard=Ot;exports.downloadPdf=Ft;exports.getDashbaordStateWithoutData=ns;
|
|
@@ -4,7 +4,7 @@ var ar = (t) => {
|
|
|
4
4
|
var Fa = (t, a, n) => a.has(t) || ar("Cannot " + n);
|
|
5
5
|
var we = (t, a, n) => (Fa(t, a, "read from private field"), n ? n.call(t) : a.get(t)), an = (t, a, n) => a.has(t) ? ar("Cannot add the same private member more than once") : a instanceof WeakSet ? a.add(t) : a.set(t, n), sn = (t, a, n, r) => (Fa(t, a, "write to private field"), r ? r.call(t, n) : a.set(t, n), n), rn = (t, a, n) => (Fa(t, a, "access private method"), n);
|
|
6
6
|
import { jsxs as s, jsx as e, Fragment as ae } from "react/jsx-runtime";
|
|
7
|
-
import { E as Ti, F as Oi, G as sr, H as Ei, I as zr, J as Ge, K as Ii, L as Ai, M as H, N as is, w as K, A as xt, O as Oe, P as Fn, Q as Fr, R as j, T as Le, U as Ln, V as _n, W as Pn, X as Vn, Y as Q, Z as je, _ as Na, $ as jn, a0 as Un, a1 as ce, a2 as Bn, a3 as Lr, a4 as ln, a5 as Ri, a6 as rr, a7 as _r, a8 as G, a9 as os, aa as Me, ab as zi, ac as ge, ad as ye, ae as ve, af as xe, ag as Vt, ah as jt, ai as ne, aj as Pr, ak as st, al as rt, am as Fi, an as Jt, ao as kt, ap as Lt, aq as Ue, ar as qe, as as Ye, at as ft, au as cs, av as $n, aw as qn, ax as Vr, ay as bt, az as on, aA as mn, aB as lt, aC as Ne, aD as We, aE as ds, aF as Li, aG as da, aH as jr, aI as mt, aJ as Ur, aK as cn, aL as us, aM as Br, aN as Re, aO as oe, aP as Ce, aQ as hn, aR as it, aS as pn, aT as _i, aU as _t, aV as nt, aW as Yn, aX as Ca, aY as wn, aZ as ms, a_ as Sn, a$ as ot, b0 as Kt, b1 as Gn, b2 as Hn, b3 as $r, b4 as Wt, b5 as hs, b6 as ps, b7 as fs, b8 as gs, b9 as fn, ba as Jn, bb as qr, bc as ys, bd as wa, be as vs, bf as Pi, bg as xs, bh as Vi, bi as ji, bj as Qt, bk as Zt, bl as Fe, bm as Et, bn as Yr, C as se, bo as Gt, B as M, bp as Gr, bq as Hr, br as Jr, bs as Kr, bt as Wr, bu as Qr, bv as Zr, bw as Xr, bx as Ui, by as Bi, bz as ua, bA as bs, bB as $i, bC as qi, bD as Yi, bE as el, bF as Ns, bG as gn, bH as Kn, bI as Wn, bJ as Qn, bK as Zn, bL as Ut, bM as yn, bN as kn, v as ct, bO as tl, m as nl, l as al, f as et, bP as Gi, g as ht, bQ as Hi, h as Ht, j as pt, k as Ji, bR as Ki, bS as Wi, bT as At, bU as It, bV as sl, bW as Qi, e as rl, bX as Dn, bY as Dt, bZ as Zi, b_ as Ga, b$ as Cs, c0 as Xn, c1 as yt, c2 as ll, r as ma, q as lr, c3 as ze, c4 as la, c5 as il, c6 as Xi, c7 as eo, c8 as to, c9 as ol, ca as no, cb as Sa, cc as ao, cd as ha, ce as so, cf as Ha, cg as Mt, ch as Ve, ci as Tt, cj as ro, ck as lo, cl as io, cm as oo, cn as co, co as La, cp as uo, cq as ir, cr as mo, cs as or, ct as ho, cu as po, cv as fo, cw as go, cx as ws, cy as yo, cz as cl, cA as Ss, cB as dl, cC as ia, cD as ul, cE as vo, cF as xo, cG as bo, cH as ml, cI as No, cJ as ea, cK as ks, cL as hl, cM as Co, cN as wo, cO as So, cP as pl, cQ as Ds, cR as fl, cS as ko, cT as cr, cU as ka, cV as Da, cW as Ma, cX as Do, cY as Mo, cZ as To, c_ as Nt, c$ as Se, d0 as ke, d1 as De, d2 as Oo, d3 as Eo, d4 as Io, d5 as Ao, s as Ro, d6 as dr, d7 as gl, d8 as zo, d9 as Fo, da as Lo, db as yl, dc as Ms, dd as vn, de as Ts, df as Rt, dg as _o, dh as ta, di as vl, dj as Po, dk as Vo, dl as jo, dm as Uo, dn as Bo, dp as ur, dq as $o, dr as qo, ds as Yo, dt as Go, du as Ho, dv as Jo, dw as Ko, dx as xl, dy as Wo, dz as Qo, dA as Zo, dB as Xo, dC as ec, dD as bl, dE as _a, dF as mr, dG as tc, dH as nc, dI as Ja, dJ as tt, dK as Ta, dL as ac, dM as sc, dN as hr, dO as Nl, dP as Os, dQ as rc, dR as lc, dS as Mn, dT as Ka, dU as ic, dV as oc, dW as pr, dX as Wa, dY as Qa, dZ as pa, d_ as dn, d$ as Tn, e0 as cc, e1 as dc, e2 as Cl, e3 as uc, e4 as mc, S as hc, e5 as pc, e6 as fc, e7 as gc } from "./index-
|
|
7
|
+
import { E as Ti, F as Oi, G as sr, H as Ei, I as zr, J as Ge, K as Ii, L as Ai, M as H, N as is, w as K, A as xt, O as Oe, P as Fn, Q as Fr, R as j, T as Le, U as Ln, V as _n, W as Pn, X as Vn, Y as Q, Z as je, _ as Na, $ as jn, a0 as Un, a1 as ce, a2 as Bn, a3 as Lr, a4 as ln, a5 as Ri, a6 as rr, a7 as _r, a8 as G, a9 as os, aa as Me, ab as zi, ac as ge, ad as ye, ae as ve, af as xe, ag as Vt, ah as jt, ai as ne, aj as Pr, ak as st, al as rt, am as Fi, an as Jt, ao as kt, ap as Lt, aq as Ue, ar as qe, as as Ye, at as ft, au as cs, av as $n, aw as qn, ax as Vr, ay as bt, az as on, aA as mn, aB as lt, aC as Ne, aD as We, aE as ds, aF as Li, aG as da, aH as jr, aI as mt, aJ as Ur, aK as cn, aL as us, aM as Br, aN as Re, aO as oe, aP as Ce, aQ as hn, aR as it, aS as pn, aT as _i, aU as _t, aV as nt, aW as Yn, aX as Ca, aY as wn, aZ as ms, a_ as Sn, a$ as ot, b0 as Kt, b1 as Gn, b2 as Hn, b3 as $r, b4 as Wt, b5 as hs, b6 as ps, b7 as fs, b8 as gs, b9 as fn, ba as Jn, bb as qr, bc as ys, bd as wa, be as vs, bf as Pi, bg as xs, bh as Vi, bi as ji, bj as Qt, bk as Zt, bl as Fe, bm as Et, bn as Yr, C as se, bo as Gt, B as M, bp as Gr, bq as Hr, br as Jr, bs as Kr, bt as Wr, bu as Qr, bv as Zr, bw as Xr, bx as Ui, by as Bi, bz as ua, bA as bs, bB as $i, bC as qi, bD as Yi, bE as el, bF as Ns, bG as gn, bH as Kn, bI as Wn, bJ as Qn, bK as Zn, bL as Ut, bM as yn, bN as kn, v as ct, bO as tl, m as nl, l as al, f as et, bP as Gi, g as ht, bQ as Hi, h as Ht, j as pt, k as Ji, bR as Ki, bS as Wi, bT as At, bU as It, bV as sl, bW as Qi, e as rl, bX as Dn, bY as Dt, bZ as Zi, b_ as Ga, b$ as Cs, c0 as Xn, c1 as yt, c2 as ll, r as ma, q as lr, c3 as ze, c4 as la, c5 as il, c6 as Xi, c7 as eo, c8 as to, c9 as ol, ca as no, cb as Sa, cc as ao, cd as ha, ce as so, cf as Ha, cg as Mt, ch as Ve, ci as Tt, cj as ro, ck as lo, cl as io, cm as oo, cn as co, co as La, cp as uo, cq as ir, cr as mo, cs as or, ct as ho, cu as po, cv as fo, cw as go, cx as ws, cy as yo, cz as cl, cA as Ss, cB as dl, cC as ia, cD as ul, cE as vo, cF as xo, cG as bo, cH as ml, cI as No, cJ as ea, cK as ks, cL as hl, cM as Co, cN as wo, cO as So, cP as pl, cQ as Ds, cR as fl, cS as ko, cT as cr, cU as ka, cV as Da, cW as Ma, cX as Do, cY as Mo, cZ as To, c_ as Nt, c$ as Se, d0 as ke, d1 as De, d2 as Oo, d3 as Eo, d4 as Io, d5 as Ao, s as Ro, d6 as dr, d7 as gl, d8 as zo, d9 as Fo, da as Lo, db as yl, dc as Ms, dd as vn, de as Ts, df as Rt, dg as _o, dh as ta, di as vl, dj as Po, dk as Vo, dl as jo, dm as Uo, dn as Bo, dp as ur, dq as $o, dr as qo, ds as Yo, dt as Go, du as Ho, dv as Jo, dw as Ko, dx as xl, dy as Wo, dz as Qo, dA as Zo, dB as Xo, dC as ec, dD as bl, dE as _a, dF as mr, dG as tc, dH as nc, dI as Ja, dJ as tt, dK as Ta, dL as ac, dM as sc, dN as hr, dO as Nl, dP as Os, dQ as rc, dR as lc, dS as Mn, dT as Ka, dU as ic, dV as oc, dW as pr, dX as Wa, dY as Qa, dZ as pa, d_ as dn, d$ as Tn, e0 as cc, e1 as dc, e2 as Cl, e3 as uc, e4 as mc, S as hc, e5 as pc, e6 as fc, e7 as gc } from "./index-CL8DpfKu.js";
|
|
8
8
|
import * as He from "react";
|
|
9
9
|
import Ie, { useState as V, useCallback as me, useEffect as Te, useRef as at, useMemo as $e, Suspense as wl, useContext as yc } from "react";
|
|
10
10
|
import "react-dom";
|
|
@@ -18177,7 +18177,7 @@ function Gh({
|
|
|
18177
18177
|
/* @__PURE__ */ e(pc, {}),
|
|
18178
18178
|
/* @__PURE__ */ s(fc, { children: [
|
|
18179
18179
|
/* @__PURE__ */ e(jh, {}),
|
|
18180
|
-
/* @__PURE__ */ s("main", { className: "relative flex h-full flex-col", children: [
|
|
18180
|
+
/* @__PURE__ */ s("main", { className: "relative flex h-full w-full flex-col", children: [
|
|
18181
18181
|
t && /* @__PURE__ */ e(yu, {}),
|
|
18182
18182
|
/* @__PURE__ */ s(gc, { ...n, children: [
|
|
18183
18183
|
/* @__PURE__ */ e(Fh, {}),
|
|
@@ -7695,7 +7695,7 @@ const si = Fn(({ children: e, className: t, ...n }, r) => /* @__PURE__ */ p("div
|
|
|
7695
7695
|
tokenProps: r
|
|
7696
7696
|
};
|
|
7697
7697
|
}, [t]);
|
|
7698
|
-
return /* @__PURE__ */ p(oY, { children: /* @__PURE__ */ p(t5.Provider, { value: n, children: /* @__PURE__ */ p(si, { style: { height: "100%" }, children: e }) }) });
|
|
7698
|
+
return /* @__PURE__ */ p(oY, { children: /* @__PURE__ */ p(t5.Provider, { value: n, children: /* @__PURE__ */ p(si, { style: { height: "100%", width: "100%" }, children: e }) }) });
|
|
7699
7699
|
};
|
|
7700
7700
|
function Rr() {
|
|
7701
7701
|
const e = vt(t5);
|