react-semaphor 0.1.174 → 0.1.175

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.
Files changed (25) hide show
  1. package/dist/chunks/{dashboard-controls-BdFhbpoS.js → dashboard-controls-BF1ISsg_.js} +2 -2
  2. package/dist/chunks/{dashboard-controls-Bxjvkywu.js → dashboard-controls-CQNvLMGb.js} +5 -5
  3. package/dist/chunks/{dashboard-json-ClK3yCs7.js → dashboard-json-CMYMYz8t.js} +1 -1
  4. package/dist/chunks/{dashboard-json-BCH4SQkg.js → dashboard-json-DddaSWpl.js} +1 -1
  5. package/dist/chunks/{edit-dashboard-visual-CSI-cZoT.js → edit-dashboard-visual-CYfGc778.js} +2 -2
  6. package/dist/chunks/{edit-dashboard-visual-BEAKONcQ.js → edit-dashboard-visual-DPKlhiyI.js} +1 -1
  7. package/dist/chunks/{editor-action-buttons-BaHzz3CT.js → editor-action-buttons-D2f078Q2.js} +1 -1
  8. package/dist/chunks/{editor-action-buttons-DIFwpB2w.js → editor-action-buttons-DPK6j7ie.js} +2 -2
  9. package/dist/chunks/{index-BAb30JIE.js → index-Ddo6owXU.js} +2 -2
  10. package/dist/chunks/{index-CtuIHKSY.js → index-nz5YKmTp.js} +16 -11
  11. package/dist/chunks/{resource-management-panel-Cs7tkTxZ.js → resource-management-panel-CnlQHXZ9.js} +1 -1
  12. package/dist/chunks/{resource-management-panel-DRMNQIkI.js → resource-management-panel-DpWhJzMn.js} +3 -3
  13. package/dist/chunks/{schedule-dashboard-CInkuI61.js → schedule-dashboard-BL5CTGzo.js} +1 -1
  14. package/dist/chunks/{schedule-dashboard-Bj4mXU5g.js → schedule-dashboard-CA-u7Ov1.js} +3 -3
  15. package/dist/chunks/{use-role-aware-display-preferences-BGTLQ_rf.js → use-role-aware-display-preferences-BAbYQx23.js} +1 -1
  16. package/dist/chunks/{use-role-aware-display-preferences-DgSkQ7I0.js → use-role-aware-display-preferences-CSacCN5X.js} +1 -1
  17. package/dist/chunks/{use-visual-utils-BmwT7aG_.js → use-visual-utils-DV14Lork.js} +1 -1
  18. package/dist/chunks/{use-visual-utils-CeBDoiB8.js → use-visual-utils-Dt5WKeeY.js} +1 -1
  19. package/dist/dashboard/index.cjs +1 -1
  20. package/dist/dashboard/index.js +1 -1
  21. package/dist/index.cjs +1 -1
  22. package/dist/index.js +4 -4
  23. package/dist/surfboard/index.cjs +1 -1
  24. package/dist/surfboard/index.js +1 -1
  25. package/package.json +1 -1
@@ -1009,7 +1009,7 @@ Defaulting to \`null\`.`}var BZ=FZ,I$e=LZ;const vI=T.forwardRef(({className:e,va
1009
1009
  To pick up a draggable item, press the space bar.
1010
1010
  While dragging, use the arrow keys to move the item.
1011
1011
  Press space again to drop the item in its new position, or press escape to cancel.
1012
- `},HLe={onDragStart(e){let{active:t}=e;return"Picked up draggable item "+t.id+"."},onDragOver(e){let{active:t,over:n}=e;return n?"Draggable item "+t.id+" was moved over droppable area "+n.id+".":"Draggable item "+t.id+" is no longer over a droppable area."},onDragEnd(e){let{active:t,over:n}=e;return n?"Draggable item "+t.id+" was dropped over droppable area "+n.id:"Draggable item "+t.id+" was dropped."},onDragCancel(e){let{active:t}=e;return"Dragging was cancelled. Draggable item "+t.id+" was dropped."}};function ULe(e){let{announcements:t=HLe,container:n,hiddenTextDescribedById:r,screenReaderInstructions:s=VLe}=e;const{announce:o,announcement:i}=LLe(),a=Jx("DndLiveRegion"),[l,u]=C.useState(!1);if(C.useEffect(()=>{u(!0)},[]),zLe(C.useMemo(()=>({onDragStart(f){let{active:h}=f;o(t.onDragStart({active:h}))},onDragMove(f){let{active:h,over:m}=f;t.onDragMove&&o(t.onDragMove({active:h,over:m}))},onDragOver(f){let{active:h,over:m}=f;o(t.onDragOver({active:h,over:m}))},onDragEnd(f){let{active:h,over:m}=f;o(t.onDragEnd({active:h,over:m}))},onDragCancel(f){let{active:h,over:m}=f;o(t.onDragCancel({active:h,over:m}))}}),[o,t])),!l)return null;const d=C.createElement(C.Fragment,null,C.createElement(FLe,{id:r,value:s.draggable}),C.createElement($Le,{id:a,announcement:i}));return n?Ln.createPortal(d,n):d}var _r;(function(e){e.DragStart="dragStart",e.DragMove="dragMove",e.DragEnd="dragEnd",e.DragCancel="dragCancel",e.DragOver="dragOver",e.RegisterDroppable="registerDroppable",e.SetDroppableDisabled="setDroppableDisabled",e.UnregisterDroppable="unregisterDroppable"})(_r||(_r={}));function Ww(){}function tm(e,t){return C.useMemo(()=>({sensor:e,options:t??{}}),[e,t])}function lC(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];return C.useMemo(()=>[...t].filter(r=>r!=null),[...t])}const Vi=Object.freeze({x:0,y:0});function aX(e,t){return Math.sqrt(Math.pow(e.x-t.x,2)+Math.pow(e.y-t.y,2))}function WLe(e,t){const n=Uw(e);if(!n)return"0 0";const r={x:(n.x-t.left)/t.width*100,y:(n.y-t.top)/t.height*100};return r.x+"% "+r.y+"%"}function lX(e,t){let{data:{value:n}}=e,{data:{value:r}}=t;return n-r}function qLe(e,t){let{data:{value:n}}=e,{data:{value:r}}=t;return r-n}function b$(e){let{left:t,top:n,height:r,width:s}=e;return[{x:t,y:n},{x:t+s,y:n},{x:t,y:n+r},{x:t+s,y:n+r}]}function cX(e,t){if(!e||e.length===0)return null;const[n]=e;return n[t]}function x$(e,t,n){return t===void 0&&(t=e.left),n===void 0&&(n=e.top),{x:t+e.width*.5,y:n+e.height*.5}}const ey=e=>{let{collisionRect:t,droppableRects:n,droppableContainers:r}=e;const s=x$(t,t.left,t.top),o=[];for(const i of r){const{id:a}=i,l=n.get(a);if(l){const u=aX(x$(l),s);o.push({id:a,data:{droppableContainer:i,value:u}})}}return o.sort(lX)},YLe=e=>{let{collisionRect:t,droppableRects:n,droppableContainers:r}=e;const s=b$(t),o=[];for(const i of r){const{id:a}=i,l=n.get(a);if(l){const u=b$(l),d=s.reduce((h,m,p)=>h+aX(u[p],m),0),f=Number((d/4).toFixed(4));o.push({id:a,data:{droppableContainer:i,value:f}})}}return o.sort(lX)};function GLe(e,t){const n=Math.max(t.top,e.top),r=Math.max(t.left,e.left),s=Math.min(t.left+t.width,e.left+e.width),o=Math.min(t.top+t.height,e.top+e.height),i=s-r,a=o-n;if(r<s&&n<o){const l=t.width*t.height,u=e.width*e.height,d=i*a,f=d/(l+u-d);return Number(f.toFixed(4))}return 0}const KLe=e=>{let{collisionRect:t,droppableRects:n,droppableContainers:r}=e;const s=[];for(const o of r){const{id:i}=o,a=n.get(i);if(a){const l=GLe(a,t);l>0&&s.push({id:i,data:{droppableContainer:o,value:l}})}}return s.sort(qLe)};function ZLe(e,t,n){return{...e,scaleX:t&&n?t.width/n.width:1,scaleY:t&&n?t.height/n.height:1}}function uX(e,t){return e&&t?{x:e.left-t.left,y:e.top-t.top}:Vi}function XLe(e){return function(n){for(var r=arguments.length,s=new Array(r>1?r-1:0),o=1;o<r;o++)s[o-1]=arguments[o];return s.reduce((i,a)=>({...i,top:i.top+e*a.y,bottom:i.bottom+e*a.y,left:i.left+e*a.x,right:i.right+e*a.x}),{...n})}}const QLe=XLe(1);function dX(e){if(e.startsWith("matrix3d(")){const t=e.slice(9,-1).split(/, /);return{x:+t[12],y:+t[13],scaleX:+t[0],scaleY:+t[5]}}else if(e.startsWith("matrix(")){const t=e.slice(7,-1).split(/, /);return{x:+t[4],y:+t[5],scaleX:+t[0],scaleY:+t[3]}}return null}function JLe(e,t,n){const r=dX(t);if(!r)return e;const{scaleX:s,scaleY:o,x:i,y:a}=r,l=e.left-i-(1-s)*parseFloat(n),u=e.top-a-(1-o)*parseFloat(n.slice(n.indexOf(" ")+1)),d=s?e.width/s:e.width,f=o?e.height/o:e.height;return{width:d,height:f,top:u,right:l+d,bottom:u+f,left:l}}const e6e={ignoreTransform:!1};function ip(e,t){t===void 0&&(t=e6e);let n=e.getBoundingClientRect();if(t.ignoreTransform){const{transform:u,transformOrigin:d}=Vs(e).getComputedStyle(e);u&&(n=JLe(n,u,d))}const{top:r,left:s,width:o,height:i,bottom:a,right:l}=n;return{top:r,left:s,width:o,height:i,bottom:a,right:l}}function y$(e){return ip(e,{ignoreTransform:!0})}function t6e(e){const t=e.innerWidth,n=e.innerHeight;return{top:0,left:0,right:t,bottom:n,width:t,height:n}}function n6e(e,t){return t===void 0&&(t=Vs(e).getComputedStyle(e)),t.position==="fixed"}function r6e(e,t){t===void 0&&(t=Vs(e).getComputedStyle(e));const n=/(auto|scroll|overlay)/;return["overflow","overflowX","overflowY"].some(s=>{const o=t[s];return typeof o=="string"?n.test(o):!1})}function cC(e,t){const n=[];function r(s){if(t!=null&&n.length>=t||!s)return n;if(EI(s)&&s.scrollingElement!=null&&!n.includes(s.scrollingElement))return n.push(s.scrollingElement),n;if(!Xx(s)||sX(s)||n.includes(s))return n;const o=Vs(e).getComputedStyle(s);return s!==e&&r6e(s,o)&&n.push(s),n6e(s,o)?n:r(s.parentNode)}return e?r(e):n}function fX(e){const[t]=cC(e,1);return t??null}function s2(e){return!oC||!e?null:sp(e)?e:kI(e)?EI(e)||e===op(e).scrollingElement?window:Xx(e)?e:null:null}function hX(e){return sp(e)?e.scrollX:e.scrollLeft}function mX(e){return sp(e)?e.scrollY:e.scrollTop}function h_(e){return{x:hX(e),y:mX(e)}}var Or;(function(e){e[e.Forward=1]="Forward",e[e.Backward=-1]="Backward"})(Or||(Or={}));function pX(e){return!oC||!e?!1:e===document.scrollingElement}function gX(e){const t={x:0,y:0},n=pX(e)?{height:window.innerHeight,width:window.innerWidth}:{height:e.clientHeight,width:e.clientWidth},r={x:e.scrollWidth-n.width,y:e.scrollHeight-n.height},s=e.scrollTop<=t.y,o=e.scrollLeft<=t.x,i=e.scrollTop>=r.y,a=e.scrollLeft>=r.x;return{isTop:s,isLeft:o,isBottom:i,isRight:a,maxScroll:r,minScroll:t}}const s6e={x:.2,y:.2};function o6e(e,t,n,r,s){let{top:o,left:i,right:a,bottom:l}=n;r===void 0&&(r=10),s===void 0&&(s=s6e);const{isTop:u,isBottom:d,isLeft:f,isRight:h}=gX(e),m={x:0,y:0},p={x:0,y:0},g={height:t.height*s.y,width:t.width*s.x};return!u&&o<=t.top+g.height?(m.y=Or.Backward,p.y=r*Math.abs((t.top+g.height-o)/g.height)):!d&&l>=t.bottom-g.height&&(m.y=Or.Forward,p.y=r*Math.abs((t.bottom-g.height-l)/g.height)),!h&&a>=t.right-g.width?(m.x=Or.Forward,p.x=r*Math.abs((t.right-g.width-a)/g.width)):!f&&i<=t.left+g.width&&(m.x=Or.Backward,p.x=r*Math.abs((t.left+g.width-i)/g.width)),{direction:m,speed:p}}function i6e(e){if(e===document.scrollingElement){const{innerWidth:o,innerHeight:i}=window;return{top:0,left:0,right:o,bottom:i,width:o,height:i}}const{top:t,left:n,right:r,bottom:s}=e.getBoundingClientRect();return{top:t,left:n,right:r,bottom:s,width:e.clientWidth,height:e.clientHeight}}function bX(e){return e.reduce((t,n)=>uh(t,h_(n)),Vi)}function a6e(e){return e.reduce((t,n)=>t+hX(n),0)}function l6e(e){return e.reduce((t,n)=>t+mX(n),0)}function xX(e,t){if(t===void 0&&(t=ip),!e)return;const{top:n,left:r,bottom:s,right:o}=t(e);fX(e)&&(s<=0||o<=0||n>=window.innerHeight||r>=window.innerWidth)&&e.scrollIntoView({block:"center",inline:"center"})}const c6e=[["x",["left","right"],a6e],["y",["top","bottom"],l6e]];class _I{constructor(t,n){this.rect=void 0,this.width=void 0,this.height=void 0,this.top=void 0,this.bottom=void 0,this.right=void 0,this.left=void 0;const r=cC(n),s=bX(r);this.rect={...t},this.width=t.width,this.height=t.height;for(const[o,i,a]of c6e)for(const l of i)Object.defineProperty(this,l,{get:()=>{const u=a(r),d=s[o]-u;return this.rect[l]+d},enumerable:!0});Object.defineProperty(this,"rect",{enumerable:!1})}}class Mg{constructor(t){this.target=void 0,this.listeners=[],this.removeAll=()=>{this.listeners.forEach(n=>{var r;return(r=this.target)==null?void 0:r.removeEventListener(...n)})},this.target=t}add(t,n,r){var s;(s=this.target)==null||s.addEventListener(t,n,r),this.listeners.push([t,n,r])}}function u6e(e){const{EventTarget:t}=Vs(e);return e instanceof t?e:op(e)}function o2(e,t){const n=Math.abs(e.x),r=Math.abs(e.y);return typeof t=="number"?Math.sqrt(n**2+r**2)>t:"x"in t&&"y"in t?n>t.x&&r>t.y:"x"in t?n>t.x:"y"in t?r>t.y:!1}var Bo;(function(e){e.Click="click",e.DragStart="dragstart",e.Keydown="keydown",e.ContextMenu="contextmenu",e.Resize="resize",e.SelectionChange="selectionchange",e.VisibilityChange="visibilitychange"})(Bo||(Bo={}));function v$(e){e.preventDefault()}function d6e(e){e.stopPropagation()}var Wt;(function(e){e.Space="Space",e.Down="ArrowDown",e.Right="ArrowRight",e.Left="ArrowLeft",e.Up="ArrowUp",e.Esc="Escape",e.Enter="Enter",e.Tab="Tab"})(Wt||(Wt={}));const yX={start:[Wt.Space,Wt.Enter],cancel:[Wt.Esc],end:[Wt.Space,Wt.Enter,Wt.Tab]},f6e=(e,t)=>{let{currentCoordinates:n}=t;switch(e.code){case Wt.Right:return{...n,x:n.x+25};case Wt.Left:return{...n,x:n.x-25};case Wt.Down:return{...n,y:n.y+25};case Wt.Up:return{...n,y:n.y-25}}};class ty{constructor(t){this.props=void 0,this.autoScrollEnabled=!1,this.referenceCoordinates=void 0,this.listeners=void 0,this.windowListeners=void 0,this.props=t;const{event:{target:n}}=t;this.props=t,this.listeners=new Mg(op(n)),this.windowListeners=new Mg(Vs(n)),this.handleKeyDown=this.handleKeyDown.bind(this),this.handleCancel=this.handleCancel.bind(this),this.attach()}attach(){this.handleStart(),this.windowListeners.add(Bo.Resize,this.handleCancel),this.windowListeners.add(Bo.VisibilityChange,this.handleCancel),setTimeout(()=>this.listeners.add(Bo.Keydown,this.handleKeyDown))}handleStart(){const{activeNode:t,onStart:n}=this.props,r=t.node.current;r&&xX(r),n(Vi)}handleKeyDown(t){if(aC(t)){const{active:n,context:r,options:s}=this.props,{keyboardCodes:o=yX,coordinateGetter:i=f6e,scrollBehavior:a="smooth"}=s,{code:l}=t;if(o.end.includes(l)){this.handleEnd(t);return}if(o.cancel.includes(l)){this.handleCancel(t);return}const{collisionRect:u}=r.current,d=u?{x:u.left,y:u.top}:Vi;this.referenceCoordinates||(this.referenceCoordinates=d);const f=i(t,{active:n,context:r.current,currentCoordinates:d});if(f){const h=Db(f,d),m={x:0,y:0},{scrollableAncestors:p}=r.current;for(const g of p){const b=t.code,{isTop:x,isRight:y,isLeft:v,isBottom:w,maxScroll:N,minScroll:S}=gX(g),j=i6e(g),E={x:Math.min(b===Wt.Right?j.right-j.width/2:j.right,Math.max(b===Wt.Right?j.left:j.left+j.width/2,f.x)),y:Math.min(b===Wt.Down?j.bottom-j.height/2:j.bottom,Math.max(b===Wt.Down?j.top:j.top+j.height/2,f.y))},_=b===Wt.Right&&!y||b===Wt.Left&&!v,k=b===Wt.Down&&!w||b===Wt.Up&&!x;if(_&&E.x!==f.x){const M=g.scrollLeft+h.x,D=b===Wt.Right&&M<=N.x||b===Wt.Left&&M>=S.x;if(D&&!h.y){g.scrollTo({left:M,behavior:a});return}D?m.x=g.scrollLeft-M:m.x=b===Wt.Right?g.scrollLeft-N.x:g.scrollLeft-S.x,m.x&&g.scrollBy({left:-m.x,behavior:a});break}else if(k&&E.y!==f.y){const M=g.scrollTop+h.y,D=b===Wt.Down&&M<=N.y||b===Wt.Up&&M>=S.y;if(D&&!h.x){g.scrollTo({top:M,behavior:a});return}D?m.y=g.scrollTop-M:m.y=b===Wt.Down?g.scrollTop-N.y:g.scrollTop-S.y,m.y&&g.scrollBy({top:-m.y,behavior:a});break}}this.handleMove(t,uh(Db(f,this.referenceCoordinates),m))}}}handleMove(t,n){const{onMove:r}=this.props;t.preventDefault(),r(n)}handleEnd(t){const{onEnd:n}=this.props;t.preventDefault(),this.detach(),n()}handleCancel(t){const{onCancel:n}=this.props;t.preventDefault(),this.detach(),n()}detach(){this.listeners.removeAll(),this.windowListeners.removeAll()}}ty.activators=[{eventName:"onKeyDown",handler:(e,t,n)=>{let{keyboardCodes:r=yX,onActivation:s}=t,{active:o}=n;const{code:i}=e.nativeEvent;if(r.start.includes(i)){const a=o.activatorNode.current;return a&&e.target!==a?!1:(e.preventDefault(),s==null||s({event:e.nativeEvent}),!0)}return!1}}];function w$(e){return!!(e&&"distance"in e)}function S$(e){return!!(e&&"delay"in e)}class DI{constructor(t,n,r){var s;r===void 0&&(r=u6e(t.event.target)),this.props=void 0,this.events=void 0,this.autoScrollEnabled=!0,this.document=void 0,this.activated=!1,this.initialCoordinates=void 0,this.timeoutId=null,this.listeners=void 0,this.documentListeners=void 0,this.windowListeners=void 0,this.props=t,this.events=n;const{event:o}=t,{target:i}=o;this.props=t,this.events=n,this.document=op(i),this.documentListeners=new Mg(this.document),this.listeners=new Mg(r),this.windowListeners=new Mg(Vs(i)),this.initialCoordinates=(s=Uw(o))!=null?s:Vi,this.handleStart=this.handleStart.bind(this),this.handleMove=this.handleMove.bind(this),this.handleEnd=this.handleEnd.bind(this),this.handleCancel=this.handleCancel.bind(this),this.handleKeydown=this.handleKeydown.bind(this),this.removeTextSelection=this.removeTextSelection.bind(this),this.attach()}attach(){const{events:t,props:{options:{activationConstraint:n,bypassActivationConstraint:r}}}=this;if(this.listeners.add(t.move.name,this.handleMove,{passive:!1}),this.listeners.add(t.end.name,this.handleEnd),t.cancel&&this.listeners.add(t.cancel.name,this.handleCancel),this.windowListeners.add(Bo.Resize,this.handleCancel),this.windowListeners.add(Bo.DragStart,v$),this.windowListeners.add(Bo.VisibilityChange,this.handleCancel),this.windowListeners.add(Bo.ContextMenu,v$),this.documentListeners.add(Bo.Keydown,this.handleKeydown),n){if(r!=null&&r({event:this.props.event,activeNode:this.props.activeNode,options:this.props.options}))return this.handleStart();if(S$(n)){this.timeoutId=setTimeout(this.handleStart,n.delay),this.handlePending(n);return}if(w$(n)){this.handlePending(n);return}}this.handleStart()}detach(){this.listeners.removeAll(),this.windowListeners.removeAll(),setTimeout(this.documentListeners.removeAll,50),this.timeoutId!==null&&(clearTimeout(this.timeoutId),this.timeoutId=null)}handlePending(t,n){const{active:r,onPending:s}=this.props;s(r,t,this.initialCoordinates,n)}handleStart(){const{initialCoordinates:t}=this,{onStart:n}=this.props;t&&(this.activated=!0,this.documentListeners.add(Bo.Click,d6e,{capture:!0}),this.removeTextSelection(),this.documentListeners.add(Bo.SelectionChange,this.removeTextSelection),n(t))}handleMove(t){var n;const{activated:r,initialCoordinates:s,props:o}=this,{onMove:i,options:{activationConstraint:a}}=o;if(!s)return;const l=(n=Uw(t))!=null?n:Vi,u=Db(s,l);if(!r&&a){if(w$(a)){if(a.tolerance!=null&&o2(u,a.tolerance))return this.handleCancel();if(o2(u,a.distance))return this.handleStart()}if(S$(a)&&o2(u,a.tolerance))return this.handleCancel();this.handlePending(a,u);return}t.cancelable&&t.preventDefault(),i(l)}handleEnd(){const{onAbort:t,onEnd:n}=this.props;this.detach(),this.activated||t(this.props.active),n()}handleCancel(){const{onAbort:t,onCancel:n}=this.props;this.detach(),this.activated||t(this.props.active),n()}handleKeydown(t){t.code===Wt.Esc&&this.handleCancel()}removeTextSelection(){var t;(t=this.document.getSelection())==null||t.removeAllRanges()}}const h6e={cancel:{name:"pointercancel"},move:{name:"pointermove"},end:{name:"pointerup"}};class ap extends DI{constructor(t){const{event:n}=t,r=op(n.target);super(t,h6e,r)}}ap.activators=[{eventName:"onPointerDown",handler:(e,t)=>{let{nativeEvent:n}=e,{onActivation:r}=t;return!n.isPrimary||n.button!==0?!1:(r==null||r({event:n}),!0)}}];const m6e={move:{name:"mousemove"},end:{name:"mouseup"}};var m_;(function(e){e[e.RightClick=2]="RightClick"})(m_||(m_={}));class p6e extends DI{constructor(t){super(t,m6e,op(t.event.target))}}p6e.activators=[{eventName:"onMouseDown",handler:(e,t)=>{let{nativeEvent:n}=e,{onActivation:r}=t;return n.button===m_.RightClick?!1:(r==null||r({event:n}),!0)}}];const i2={cancel:{name:"touchcancel"},move:{name:"touchmove"},end:{name:"touchend"}};class g6e extends DI{constructor(t){super(t,i2)}static setup(){return window.addEventListener(i2.move.name,t,{capture:!1,passive:!1}),function(){window.removeEventListener(i2.move.name,t)};function t(){}}}g6e.activators=[{eventName:"onTouchStart",handler:(e,t)=>{let{nativeEvent:n}=e,{onActivation:r}=t;const{touches:s}=n;return s.length>1?!1:(r==null||r({event:n}),!0)}}];var Tg;(function(e){e[e.Pointer=0]="Pointer",e[e.DraggableRect=1]="DraggableRect"})(Tg||(Tg={}));var qw;(function(e){e[e.TreeOrder=0]="TreeOrder",e[e.ReversedTreeOrder=1]="ReversedTreeOrder"})(qw||(qw={}));function b6e(e){let{acceleration:t,activator:n=Tg.Pointer,canScroll:r,draggingRect:s,enabled:o,interval:i=5,order:a=qw.TreeOrder,pointerCoordinates:l,scrollableAncestors:u,scrollableAncestorRects:d,delta:f,threshold:h}=e;const m=y6e({delta:f,disabled:!o}),[p,g]=RLe(),b=C.useRef({x:0,y:0}),x=C.useRef({x:0,y:0}),y=C.useMemo(()=>{switch(n){case Tg.Pointer:return l?{top:l.y,bottom:l.y,left:l.x,right:l.x}:null;case Tg.DraggableRect:return s}},[n,s,l]),v=C.useRef(null),w=C.useCallback(()=>{const S=v.current;if(!S)return;const j=b.current.x*x.current.x,E=b.current.y*x.current.y;S.scrollBy(j,E)},[]),N=C.useMemo(()=>a===qw.TreeOrder?[...u].reverse():u,[a,u]);C.useEffect(()=>{if(!o||!u.length||!y){g();return}for(const S of N){if((r==null?void 0:r(S))===!1)continue;const j=u.indexOf(S),E=d[j];if(!E)continue;const{direction:_,speed:k}=o6e(S,E,y,t,h);for(const M of["x","y"])m[M][_[M]]||(k[M]=0,_[M]=0);if(k.x>0||k.y>0){g(),v.current=S,p(w,i),b.current=k,x.current=_;return}}b.current={x:0,y:0},x.current={x:0,y:0},g()},[t,w,r,g,o,i,JSON.stringify(y),JSON.stringify(m),p,u,N,d,JSON.stringify(h)])}const x6e={x:{[Or.Backward]:!1,[Or.Forward]:!1},y:{[Or.Backward]:!1,[Or.Forward]:!1}};function y6e(e){let{delta:t,disabled:n}=e;const r=Hw(t);return Qx(s=>{if(n||!r||!s)return x6e;const o={x:Math.sign(t.x-r.x),y:Math.sign(t.y-r.y)};return{x:{[Or.Backward]:s.x[Or.Backward]||o.x===-1,[Or.Forward]:s.x[Or.Forward]||o.x===1},y:{[Or.Backward]:s.y[Or.Backward]||o.y===-1,[Or.Forward]:s.y[Or.Forward]||o.y===1}}},[n,t,r])}function v6e(e,t){const n=t!=null?e.get(t):void 0,r=n?n.node.current:null;return Qx(s=>{var o;return t==null?null:(o=r??s)!=null?o:null},[r,t])}function w6e(e,t){return C.useMemo(()=>e.reduce((n,r)=>{const{sensor:s}=r,o=s.activators.map(i=>({eventName:i.eventName,handler:t(i.handler,r)}));return[...n,...o]},[]),[e,t])}var Mb;(function(e){e[e.Always=0]="Always",e[e.BeforeDragging=1]="BeforeDragging",e[e.WhileDragging=2]="WhileDragging"})(Mb||(Mb={}));var p_;(function(e){e.Optimized="optimized"})(p_||(p_={}));const C$=new Map;function S6e(e,t){let{dragging:n,dependencies:r,config:s}=t;const[o,i]=C.useState(null),{frequency:a,measure:l,strategy:u}=s,d=C.useRef(e),f=b(),h=_b(f),m=C.useCallback(function(x){x===void 0&&(x=[]),!h.current&&i(y=>y===null?x:y.concat(x.filter(v=>!y.includes(v))))},[h]),p=C.useRef(null),g=Qx(x=>{if(f&&!n)return C$;if(!x||x===C$||d.current!==e||o!=null){const y=new Map;for(let v of e){if(!v)continue;if(o&&o.length>0&&!o.includes(v.id)&&v.rect.current){y.set(v.id,v.rect.current);continue}const w=v.node.current,N=w?new _I(l(w),w):null;v.rect.current=N,N&&y.set(v.id,N)}return y}return x},[e,o,n,f,l]);return C.useEffect(()=>{d.current=e},[e]),C.useEffect(()=>{f||m()},[n,f]),C.useEffect(()=>{o&&o.length>0&&i(null)},[JSON.stringify(o)]),C.useEffect(()=>{f||typeof a!="number"||p.current!==null||(p.current=setTimeout(()=>{m(),p.current=null},a))},[a,f,m,...r]),{droppableRects:g,measureDroppableContainers:m,measuringScheduled:o!=null};function b(){switch(u){case Mb.Always:return!1;case Mb.BeforeDragging:return n;default:return!n}}}function MI(e,t){return Qx(n=>e?n||(typeof t=="function"?t(e):e):null,[t,e])}function C6e(e,t){return MI(e,t)}function N6e(e){let{callback:t,disabled:n}=e;const r=iC(t),s=C.useMemo(()=>{if(n||typeof window>"u"||typeof window.MutationObserver>"u")return;const{MutationObserver:o}=window;return new o(r)},[r,n]);return C.useEffect(()=>()=>s==null?void 0:s.disconnect(),[s]),s}function uC(e){let{callback:t,disabled:n}=e;const r=iC(t),s=C.useMemo(()=>{if(n||typeof window>"u"||typeof window.ResizeObserver>"u")return;const{ResizeObserver:o}=window;return new o(r)},[n]);return C.useEffect(()=>()=>s==null?void 0:s.disconnect(),[s]),s}function j6e(e){return new _I(ip(e),e)}function N$(e,t,n){t===void 0&&(t=j6e);const[r,s]=C.useState(null);function o(){s(l=>{if(!e)return null;if(e.isConnected===!1){var u;return(u=l??n)!=null?u:null}const d=t(e);return JSON.stringify(l)===JSON.stringify(d)?l:d})}const i=N6e({callback(l){if(e)for(const u of l){const{type:d,target:f}=u;if(d==="childList"&&f instanceof HTMLElement&&f.contains(e)){o();break}}}}),a=uC({callback:o});return Bi(()=>{o(),e?(a==null||a.observe(e),i==null||i.observe(document.body,{childList:!0,subtree:!0})):(a==null||a.disconnect(),i==null||i.disconnect())},[e]),r}function k6e(e){const t=MI(e);return uX(e,t)}const j$=[];function E6e(e){const t=C.useRef(e),n=Qx(r=>e?r&&r!==j$&&e&&t.current&&e.parentNode===t.current.parentNode?r:cC(e):j$,[e]);return C.useEffect(()=>{t.current=e},[e]),n}function _6e(e){const[t,n]=C.useState(null),r=C.useRef(e),s=C.useCallback(o=>{const i=s2(o.target);i&&n(a=>a?(a.set(i,h_(i)),new Map(a)):null)},[]);return C.useEffect(()=>{const o=r.current;if(e!==o){i(o);const a=e.map(l=>{const u=s2(l);return u?(u.addEventListener("scroll",s,{passive:!0}),[u,h_(u)]):null}).filter(l=>l!=null);n(a.length?new Map(a):null),r.current=e}return()=>{i(e),i(o)};function i(a){a.forEach(l=>{const u=s2(l);u==null||u.removeEventListener("scroll",s)})}},[s,e]),C.useMemo(()=>e.length?t?Array.from(t.values()).reduce((o,i)=>uh(o,i),Vi):bX(e):Vi,[e,t])}function k$(e,t){t===void 0&&(t=[]);const n=C.useRef(null);return C.useEffect(()=>{n.current=null},t),C.useEffect(()=>{const r=e!==Vi;r&&!n.current&&(n.current=e),!r&&n.current&&(n.current=null)},[e]),n.current?Db(e,n.current):Vi}function D6e(e){C.useEffect(()=>{if(!oC)return;const t=e.map(n=>{let{sensor:r}=n;return r.setup==null?void 0:r.setup()});return()=>{for(const n of t)n==null||n()}},e.map(t=>{let{sensor:n}=t;return n}))}function M6e(e,t){return C.useMemo(()=>e.reduce((n,r)=>{let{eventName:s,handler:o}=r;return n[s]=i=>{o(i,t)},n},{}),[e,t])}function vX(e){return C.useMemo(()=>e?t6e(e):null,[e])}const E$=[];function T6e(e,t){t===void 0&&(t=ip);const[n]=e,r=vX(n?Vs(n):null),[s,o]=C.useState(E$);function i(){o(()=>e.length?e.map(l=>pX(l)?r:new _I(t(l),l)):E$)}const a=uC({callback:i});return Bi(()=>{a==null||a.disconnect(),i(),e.forEach(l=>a==null?void 0:a.observe(l))},[e]),s}function wX(e){if(!e)return null;if(e.children.length>1)return e;const t=e.children[0];return Xx(t)?t:e}function R6e(e){let{measure:t}=e;const[n,r]=C.useState(null),s=C.useCallback(u=>{for(const{target:d}of u)if(Xx(d)){r(f=>{const h=t(d);return f?{...f,width:h.width,height:h.height}:h});break}},[t]),o=uC({callback:s}),i=C.useCallback(u=>{const d=wX(u);o==null||o.disconnect(),d&&(o==null||o.observe(d)),r(d?t(d):null)},[t,o]),[a,l]=Vw(i);return C.useMemo(()=>({nodeRef:a,rect:n,setRef:l}),[n,a,l])}const I6e=[{sensor:ap,options:{}},{sensor:ty,options:{}}],A6e={current:{}},pv={draggable:{measure:y$},droppable:{measure:y$,strategy:Mb.WhileDragging,frequency:p_.Optimized},dragOverlay:{measure:ip}};class Rg extends Map{get(t){var n;return t!=null&&(n=super.get(t))!=null?n:void 0}toArray(){return Array.from(this.values())}getEnabled(){return this.toArray().filter(t=>{let{disabled:n}=t;return!n})}getNodeFor(t){var n,r;return(n=(r=this.get(t))==null?void 0:r.node.current)!=null?n:void 0}}const P6e={activatorEvent:null,active:null,activeNode:null,activeNodeRect:null,collisions:null,containerNodeRect:null,draggableNodes:new Map,droppableRects:new Map,droppableContainers:new Rg,over:null,dragOverlay:{nodeRef:{current:null},rect:null,setRef:Ww},scrollableAncestors:[],scrollableAncestorRects:[],measuringConfiguration:pv,measureDroppableContainers:Ww,windowRect:null,measuringScheduled:!1},SX={activatorEvent:null,activators:[],active:null,activeNodeRect:null,ariaDescribedById:{draggable:""},dispatch:Ww,draggableNodes:new Map,over:null,measureDroppableContainers:Ww},ny=C.createContext(SX),CX=C.createContext(P6e);function O6e(){return{draggable:{active:null,initialCoordinates:{x:0,y:0},nodes:new Map,translate:{x:0,y:0}},droppable:{containers:new Rg}}}function F6e(e,t){switch(t.type){case _r.DragStart:return{...e,draggable:{...e.draggable,initialCoordinates:t.initialCoordinates,active:t.active}};case _r.DragMove:return e.draggable.active==null?e:{...e,draggable:{...e.draggable,translate:{x:t.coordinates.x-e.draggable.initialCoordinates.x,y:t.coordinates.y-e.draggable.initialCoordinates.y}}};case _r.DragEnd:case _r.DragCancel:return{...e,draggable:{...e.draggable,active:null,initialCoordinates:{x:0,y:0},translate:{x:0,y:0}}};case _r.RegisterDroppable:{const{element:n}=t,{id:r}=n,s=new Rg(e.droppable.containers);return s.set(r,n),{...e,droppable:{...e.droppable,containers:s}}}case _r.SetDroppableDisabled:{const{id:n,key:r,disabled:s}=t,o=e.droppable.containers.get(n);if(!o||r!==o.key)return e;const i=new Rg(e.droppable.containers);return i.set(n,{...o,disabled:s}),{...e,droppable:{...e.droppable,containers:i}}}case _r.UnregisterDroppable:{const{id:n,key:r}=t,s=e.droppable.containers.get(n);if(!s||r!==s.key)return e;const o=new Rg(e.droppable.containers);return o.delete(n),{...e,droppable:{...e.droppable,containers:o}}}default:return e}}function $6e(e){let{disabled:t}=e;const{active:n,activatorEvent:r,draggableNodes:s}=C.useContext(ny),o=Hw(r),i=Hw(n==null?void 0:n.id);return C.useEffect(()=>{if(!t&&!r&&o&&i!=null){if(!aC(o)||document.activeElement===o.target)return;const a=s.get(i);if(!a)return;const{activatorNode:l,node:u}=a;if(!l.current&&!u.current)return;requestAnimationFrame(()=>{for(const d of[l.current,u.current]){if(!d)continue;const f=PLe(d);if(f){f.focus();break}}})}},[r,t,s,i,o]),null}function NX(e,t){let{transform:n,...r}=t;return e!=null&&e.length?e.reduce((s,o)=>o({transform:s,...r}),n):n}function L6e(e){return C.useMemo(()=>({draggable:{...pv.draggable,...e==null?void 0:e.draggable},droppable:{...pv.droppable,...e==null?void 0:e.droppable},dragOverlay:{...pv.dragOverlay,...e==null?void 0:e.dragOverlay}}),[e==null?void 0:e.draggable,e==null?void 0:e.droppable,e==null?void 0:e.dragOverlay])}function z6e(e){let{activeNode:t,measure:n,initialRect:r,config:s=!0}=e;const o=C.useRef(!1),{x:i,y:a}=typeof s=="boolean"?{x:s,y:s}:s;Bi(()=>{if(!i&&!a||!t){o.current=!1;return}if(o.current||!r)return;const u=t==null?void 0:t.node.current;if(!u||u.isConnected===!1)return;const d=n(u),f=uX(d,r);if(i||(f.x=0),a||(f.y=0),o.current=!0,Math.abs(f.x)>0||Math.abs(f.y)>0){const h=fX(u);h&&h.scrollBy({top:f.y,left:f.x})}},[t,i,a,r,n])}const dC=C.createContext({...Vi,scaleX:1,scaleY:1});var rc;(function(e){e[e.Uninitialized=0]="Uninitialized",e[e.Initializing=1]="Initializing",e[e.Initialized=2]="Initialized"})(rc||(rc={}));const ry=C.memo(function(t){var n,r,s,o;let{id:i,accessibility:a,autoScroll:l=!0,children:u,sensors:d=I6e,collisionDetection:f=KLe,measuring:h,modifiers:m,...p}=t;const g=C.useReducer(F6e,void 0,O6e),[b,x]=g,[y,v]=BLe(),[w,N]=C.useState(rc.Uninitialized),S=w===rc.Initialized,{draggable:{active:j,nodes:E,translate:_},droppable:{containers:k}}=b,M=j!=null?E.get(j):null,D=C.useRef({initial:null,translated:null}),R=C.useMemo(()=>{var Le;return j!=null?{id:j,data:(Le=M==null?void 0:M.data)!=null?Le:A6e,rect:D}:null},[j,M]),P=C.useRef(null),[I,L]=C.useState(null),[F,H]=C.useState(null),$=_b(p,Object.values(p)),A=Jx("DndDescribedBy",i),q=C.useMemo(()=>k.getEnabled(),[k]),z=L6e(h),{droppableRects:O,measureDroppableContainers:W,measuringScheduled:B}=S6e(q,{dragging:S,dependencies:[_.x,_.y],config:z.droppable}),Y=v6e(E,j),U=C.useMemo(()=>F?Uw(F):null,[F]),V=Qe(),G=C6e(Y,z.draggable.measure);z6e({activeNode:j!=null?E.get(j):null,config:V.layoutShiftCompensation,initialRect:G,measure:z.draggable.measure});const K=N$(Y,z.draggable.measure,G),J=N$(Y?Y.parentElement:null),Q=C.useRef({activatorEvent:null,active:null,activeNode:Y,collisionRect:null,collisions:null,droppableRects:O,draggableNodes:E,draggingNode:null,draggingNodeRect:null,droppableContainers:k,over:null,scrollableAncestors:[],scrollAdjustedTranslate:null}),re=k.getNodeFor((n=Q.current.over)==null?void 0:n.id),de=R6e({measure:z.dragOverlay.measure}),fe=(r=de.nodeRef.current)!=null?r:Y,ue=S?(s=de.rect)!=null?s:K:null,je=!!(de.nodeRef.current&&de.rect),me=k6e(je?null:K),ne=vX(fe?Vs(fe):null),oe=E6e(S?re??Y:null),pe=T6e(oe),De=NX(m,{transform:{x:_.x-me.x,y:_.y-me.y,scaleX:1,scaleY:1},activatorEvent:F,active:R,activeNodeRect:K,containerNodeRect:J,draggingNodeRect:ue,over:Q.current.over,overlayNodeRect:de.rect,scrollableAncestors:oe,scrollableAncestorRects:pe,windowRect:ne}),ae=U?uh(U,_):null,Te=_6e(oe),Ue=k$(Te),ie=k$(Te,[K]),xe=uh(De,Ue),$e=ue?QLe(ue,De):null,he=R&&$e?f({active:R,collisionRect:$e,droppableRects:O,droppableContainers:q,pointerCoordinates:ae}):null,Ee=cX(he,"id"),[Ve,qe]=C.useState(null),Ae=je?De:uh(De,ie),xt=ZLe(Ae,(o=Ve==null?void 0:Ve.rect)!=null?o:null,K),Ce=C.useRef(null),mt=C.useCallback((Le,ve)=>{let{sensor:Be,options:we}=ve;if(P.current==null)return;const We=E.get(P.current);if(!We)return;const at=Le.nativeEvent,pn=new Be({active:P.current,activeNode:We,event:at,options:we,context:Q,onAbort(Ht){if(!E.get(Ht))return;const{onDragAbort:Vn}=$.current,gr={id:Ht};Vn==null||Vn(gr),y({type:"onDragAbort",event:gr})},onPending(Ht,Ir,Vn,gr){if(!E.get(Ht))return;const{onDragPending:Ao}=$.current,Zi={id:Ht,constraint:Ir,initialCoordinates:Vn,offset:gr};Ao==null||Ao(Zi),y({type:"onDragPending",event:Zi})},onStart(Ht){const Ir=P.current;if(Ir==null)return;const Vn=E.get(Ir);if(!Vn)return;const{onDragStart:gr}=$.current,xu={activatorEvent:at,active:{id:Ir,data:Vn.data,rect:D}};Ln.unstable_batchedUpdates(()=>{gr==null||gr(xu),N(rc.Initializing),x({type:_r.DragStart,initialCoordinates:Ht,active:Ir}),y({type:"onDragStart",event:xu}),L(Ce.current),H(at)})},onMove(Ht){x({type:_r.DragMove,coordinates:Ht})},onEnd:Vt(_r.DragEnd),onCancel:Vt(_r.DragCancel)});Ce.current=pn;function Vt(Ht){return async function(){const{active:Vn,collisions:gr,over:xu,scrollAdjustedTranslate:Ao}=Q.current;let Zi=null;if(Vn&&Ao){const{cancelDrop:yu}=$.current;Zi={activatorEvent:at,active:Vn,collisions:gr,delta:Ao,over:xu},Ht===_r.DragEnd&&typeof yu=="function"&&await Promise.resolve(yu(Zi))&&(Ht=_r.DragCancel)}P.current=null,Ln.unstable_batchedUpdates(()=>{x({type:Ht}),N(rc.Uninitialized),qe(null),L(null),H(null),Ce.current=null;const yu=Ht===_r.DragEnd?"onDragEnd":"onDragCancel";if(Zi){const hp=$.current[yu];hp==null||hp(Zi),y({type:yu,event:Zi})}})}}},[E]),_t=C.useCallback((Le,ve)=>(Be,we)=>{const We=Be.nativeEvent,at=E.get(we);if(P.current!==null||!at||We.dndKit||We.defaultPrevented)return;const pn={active:at};Le(Be,ve.options,pn)===!0&&(We.dndKit={capturedBy:ve.sensor},P.current=we,mt(Be,ve))},[E,mt]),He=w6e(d,_t);D6e(d),Bi(()=>{K&&w===rc.Initializing&&N(rc.Initialized)},[K,w]),C.useEffect(()=>{const{onDragMove:Le}=$.current,{active:ve,activatorEvent:Be,collisions:we,over:We}=Q.current;if(!ve||!Be)return;const at={active:ve,activatorEvent:Be,collisions:we,delta:{x:xe.x,y:xe.y},over:We};Ln.unstable_batchedUpdates(()=>{Le==null||Le(at),y({type:"onDragMove",event:at})})},[xe.x,xe.y]),C.useEffect(()=>{const{active:Le,activatorEvent:ve,collisions:Be,droppableContainers:we,scrollAdjustedTranslate:We}=Q.current;if(!Le||P.current==null||!ve||!We)return;const{onDragOver:at}=$.current,pn=we.get(Ee),Vt=pn&&pn.rect.current?{id:pn.id,rect:pn.rect.current,data:pn.data,disabled:pn.disabled}:null,Ht={active:Le,activatorEvent:ve,collisions:Be,delta:{x:We.x,y:We.y},over:Vt};Ln.unstable_batchedUpdates(()=>{qe(Vt),at==null||at(Ht),y({type:"onDragOver",event:Ht})})},[Ee]),Bi(()=>{Q.current={activatorEvent:F,active:R,activeNode:Y,collisionRect:$e,collisions:he,droppableRects:O,draggableNodes:E,draggingNode:fe,draggingNodeRect:ue,droppableContainers:k,over:Ve,scrollableAncestors:oe,scrollAdjustedTranslate:xe},D.current={initial:ue,translated:$e}},[R,Y,he,$e,E,fe,ue,O,k,Ve,oe,xe]),b6e({...V,delta:_,draggingRect:$e,pointerCoordinates:ae,scrollableAncestors:oe,scrollableAncestorRects:pe});const Jt=C.useMemo(()=>({active:R,activeNode:Y,activeNodeRect:K,activatorEvent:F,collisions:he,containerNodeRect:J,dragOverlay:de,draggableNodes:E,droppableContainers:k,droppableRects:O,over:Ve,measureDroppableContainers:W,scrollableAncestors:oe,scrollableAncestorRects:pe,measuringConfiguration:z,measuringScheduled:B,windowRect:ne}),[R,Y,K,F,he,J,de,E,k,O,Ve,W,oe,pe,z,B,ne]),Ke=C.useMemo(()=>({activatorEvent:F,activators:He,active:R,activeNodeRect:K,ariaDescribedById:{draggable:A},dispatch:x,draggableNodes:E,over:Ve,measureDroppableContainers:W}),[F,He,R,K,x,A,E,Ve,W]);return C.createElement(iX.Provider,{value:v},C.createElement(ny.Provider,{value:Ke},C.createElement(CX.Provider,{value:Jt},C.createElement(dC.Provider,{value:xt},u)),C.createElement($6e,{disabled:(a==null?void 0:a.restoreFocus)===!1})),C.createElement(ULe,{...a,hiddenTextDescribedById:A}));function Qe(){const Le=(I==null?void 0:I.autoScrollEnabled)===!1,ve=typeof l=="object"?l.enabled===!1:l===!1,Be=S&&!Le&&!ve;return typeof l=="object"?{...l,enabled:Be}:{enabled:Be}}}),B6e=C.createContext(null),_$="button",V6e="Draggable";function H6e(e){let{id:t,data:n,disabled:r=!1,attributes:s}=e;const o=Jx(V6e),{activators:i,activatorEvent:a,active:l,activeNodeRect:u,ariaDescribedById:d,draggableNodes:f,over:h}=C.useContext(ny),{role:m=_$,roleDescription:p="draggable",tabIndex:g=0}=s??{},b=(l==null?void 0:l.id)===t,x=C.useContext(b?dC:B6e),[y,v]=Vw(),[w,N]=Vw(),S=M6e(i,t),j=_b(n);Bi(()=>(f.set(t,{id:t,key:o,node:y,activatorNode:w,data:j}),()=>{const _=f.get(t);_&&_.key===o&&f.delete(t)}),[f,t]);const E=C.useMemo(()=>({role:m,tabIndex:g,"aria-disabled":r,"aria-pressed":b&&m===_$?!0:void 0,"aria-roledescription":p,"aria-describedby":d.draggable}),[r,m,g,b,p,d.draggable]);return{active:l,activatorEvent:a,activeNodeRect:u,attributes:E,isDragging:b,listeners:r?void 0:S,node:y,over:h,setNodeRef:v,setActivatorNodeRef:N,transform:x}}function jX(){return C.useContext(CX)}const U6e="Droppable",W6e={timeout:25};function kX(e){let{data:t,disabled:n=!1,id:r,resizeObserverConfig:s}=e;const o=Jx(U6e),{active:i,dispatch:a,over:l,measureDroppableContainers:u}=C.useContext(ny),d=C.useRef({disabled:n}),f=C.useRef(!1),h=C.useRef(null),m=C.useRef(null),{disabled:p,updateMeasurementsFor:g,timeout:b}={...W6e,...s},x=_b(g??r),y=C.useCallback(()=>{if(!f.current){f.current=!0;return}m.current!=null&&clearTimeout(m.current),m.current=setTimeout(()=>{u(Array.isArray(x.current)?x.current:[x.current]),m.current=null},b)},[b]),v=uC({callback:y,disabled:p||!i}),w=C.useCallback((E,_)=>{v&&(_&&(v.unobserve(_),f.current=!1),E&&v.observe(E))},[v]),[N,S]=Vw(w),j=_b(t);return C.useEffect(()=>{!v||!N.current||(v.disconnect(),f.current=!1,v.observe(N.current))},[N,v]),C.useEffect(()=>(a({type:_r.RegisterDroppable,element:{id:r,key:o,disabled:n,node:N,rect:h,data:j}}),()=>a({type:_r.UnregisterDroppable,key:o,id:r})),[r]),C.useEffect(()=>{n!==d.current.disabled&&(a({type:_r.SetDroppableDisabled,id:r,key:o,disabled:n}),d.current.disabled=n)},[r,o,n,a]),{active:i,rect:h,isOver:(l==null?void 0:l.id)===r,node:N,over:l,setNodeRef:S}}function q6e(e){let{animation:t,children:n}=e;const[r,s]=C.useState(null),[o,i]=C.useState(null),a=Hw(n);return!n&&!r&&a&&s(a),Bi(()=>{if(!o)return;const l=r==null?void 0:r.key,u=r==null?void 0:r.props.id;if(l==null||u==null){s(null);return}Promise.resolve(t(u,o)).then(()=>{s(null)})},[t,r,o]),C.createElement(C.Fragment,null,n,r?C.cloneElement(r,{ref:i}):null)}const Y6e={x:0,y:0,scaleX:1,scaleY:1};function G6e(e){let{children:t}=e;return C.createElement(ny.Provider,{value:SX},C.createElement(dC.Provider,{value:Y6e},t))}const K6e={position:"fixed",touchAction:"none"},Z6e=e=>aC(e)?"transform 250ms ease":void 0,X6e=C.forwardRef((e,t)=>{let{as:n,activatorEvent:r,adjustScale:s,children:o,className:i,rect:a,style:l,transform:u,transition:d=Z6e}=e;if(!a)return null;const f=s?u:{...u,scaleX:1,scaleY:1},h={...K6e,width:a.width,height:a.height,top:a.top,left:a.left,transform:ii.Transform.toString(f),transformOrigin:s&&r?WLe(r,a):void 0,transition:typeof d=="function"?d(r):d,...l};return C.createElement(n,{className:i,style:h,ref:t},o)}),Q6e=e=>t=>{let{active:n,dragOverlay:r}=t;const s={},{styles:o,className:i}=e;if(o!=null&&o.active)for(const[a,l]of Object.entries(o.active))l!==void 0&&(s[a]=n.node.style.getPropertyValue(a),n.node.style.setProperty(a,l));if(o!=null&&o.dragOverlay)for(const[a,l]of Object.entries(o.dragOverlay))l!==void 0&&r.node.style.setProperty(a,l);return i!=null&&i.active&&n.node.classList.add(i.active),i!=null&&i.dragOverlay&&r.node.classList.add(i.dragOverlay),function(){for(const[l,u]of Object.entries(s))n.node.style.setProperty(l,u);i!=null&&i.active&&n.node.classList.remove(i.active)}},J6e=e=>{let{transform:{initial:t,final:n}}=e;return[{transform:ii.Transform.toString(t)},{transform:ii.Transform.toString(n)}]},eze={duration:250,easing:"ease",keyframes:J6e,sideEffects:Q6e({styles:{active:{opacity:"0"}}})};function tze(e){let{config:t,draggableNodes:n,droppableContainers:r,measuringConfiguration:s}=e;return iC((o,i)=>{if(t===null)return;const a=n.get(o);if(!a)return;const l=a.node.current;if(!l)return;const u=wX(i);if(!u)return;const{transform:d}=Vs(i).getComputedStyle(i),f=dX(d);if(!f)return;const h=typeof t=="function"?t:nze(t);return xX(l,s.draggable.measure),h({active:{id:o,data:a.data,node:l,rect:s.draggable.measure(l)},draggableNodes:n,dragOverlay:{node:i,rect:s.dragOverlay.measure(u)},droppableContainers:r,measuringConfiguration:s,transform:f})})}function nze(e){const{duration:t,easing:n,sideEffects:r,keyframes:s}={...eze,...e};return o=>{let{active:i,dragOverlay:a,transform:l,...u}=o;if(!t)return;const d={x:a.rect.left-i.rect.left,y:a.rect.top-i.rect.top},f={scaleX:l.scaleX!==1?i.rect.width*l.scaleX/a.rect.width:1,scaleY:l.scaleY!==1?i.rect.height*l.scaleY/a.rect.height:1},h={x:l.x-d.x,y:l.y-d.y,...f},m=s({...u,active:i,dragOverlay:a,transform:{initial:l,final:h}}),[p]=m,g=m[m.length-1];if(JSON.stringify(p)===JSON.stringify(g))return;const b=r==null?void 0:r({active:i,dragOverlay:a,...u}),x=a.node.animate(m,{duration:t,easing:n,fill:"forwards"});return new Promise(y=>{x.onfinish=()=>{b==null||b(),y()}})}}let D$=0;function rze(e){return C.useMemo(()=>{if(e!=null)return D$++,D$},[e])}const EX=C.memo(e=>{let{adjustScale:t=!1,children:n,dropAnimation:r,style:s,transition:o,modifiers:i,wrapperElement:a="div",className:l,zIndex:u=999}=e;const{activatorEvent:d,active:f,activeNodeRect:h,containerNodeRect:m,draggableNodes:p,droppableContainers:g,dragOverlay:b,over:x,measuringConfiguration:y,scrollableAncestors:v,scrollableAncestorRects:w,windowRect:N}=jX(),S=C.useContext(dC),j=rze(f==null?void 0:f.id),E=NX(i,{activatorEvent:d,active:f,activeNodeRect:h,containerNodeRect:m,draggingNodeRect:b.rect,over:x,overlayNodeRect:b.rect,scrollableAncestors:v,scrollableAncestorRects:w,transform:S,windowRect:N}),_=MI(h),k=tze({config:r,draggableNodes:p,droppableContainers:g,measuringConfiguration:y}),M=_?b.setRef:void 0;return C.createElement(G6e,null,C.createElement(q6e,{animation:k},f&&j?C.createElement(X6e,{key:j,id:f.id,ref:M,as:a,activatorEvent:d,adjustScale:t,className:l,transition:o,rect:_,style:{zIndex:u,...s},transform:E},n):null))});function lp(e,t,n){const r=e.slice();return r.splice(n<0?r.length+n:n,0,r.splice(t,1)[0]),r}function sze(e,t){return e.reduce((n,r,s)=>{const o=t.get(r);return o&&(n[s]=o),n},Array(e.length))}function I0(e){return e!==null&&e>=0}function oze(e,t){if(e===t)return!0;if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(e[n]!==t[n])return!1;return!0}function ize(e){return typeof e=="boolean"?{draggable:e,droppable:e}:e}const A0={scaleX:1,scaleY:1},TI=e=>{var t;let{rects:n,activeNodeRect:r,activeIndex:s,overIndex:o,index:i}=e;const a=(t=n[s])!=null?t:r;if(!a)return null;const l=aze(n,i,s);if(i===s){const u=n[o];return u?{x:s<o?u.left+u.width-(a.left+a.width):u.left-a.left,y:0,...A0}:null}return i>s&&i<=o?{x:-a.width-l,y:0,...A0}:i<s&&i>=o?{x:a.width+l,y:0,...A0}:{x:0,y:0,...A0}};function aze(e,t,n){const r=e[t],s=e[t-1],o=e[t+1];return!r||!s&&!o?0:n<t?s?r.left-(s.left+s.width):o.left-(r.left+r.width):o?o.left-(r.left+r.width):r.left-(s.left+s.width)}const _X=e=>{let{rects:t,activeIndex:n,overIndex:r,index:s}=e;const o=lp(t,r,n),i=t[s],a=o[s];return!a||!i?null:{x:a.left-i.left,y:a.top-i.top,scaleX:a.width/i.width,scaleY:a.height/i.height}},P0={scaleX:1,scaleY:1},RI=e=>{var t;let{activeIndex:n,activeNodeRect:r,index:s,rects:o,overIndex:i}=e;const a=(t=o[n])!=null?t:r;if(!a)return null;if(s===n){const u=o[i];return u?{x:0,y:n<i?u.top+u.height-(a.top+a.height):u.top-a.top,...P0}:null}const l=lze(o,s,n);return s>n&&s<=i?{x:0,y:-a.height-l,...P0}:s<n&&s>=i?{x:0,y:a.height+l,...P0}:{x:0,y:0,...P0}};function lze(e,t,n){const r=e[t],s=e[t-1],o=e[t+1];return r?n<t?s?r.top-(s.top+s.height):o?o.top-(r.top+r.height):0:o?o.top-(r.top+r.height):s?r.top-(s.top+s.height):0:0}const DX="Sortable",MX=C.createContext({activeIndex:-1,containerId:DX,disableTransforms:!1,items:[],overIndex:-1,useDragOverlay:!1,sortedRects:[],strategy:_X,disabled:{draggable:!1,droppable:!1}});function sy(e){let{children:t,id:n,items:r,strategy:s=_X,disabled:o=!1}=e;const{active:i,dragOverlay:a,droppableRects:l,over:u,measureDroppableContainers:d}=jX(),f=Jx(DX,n),h=a.rect!==null,m=C.useMemo(()=>r.map(S=>typeof S=="object"&&"id"in S?S.id:S),[r]),p=i!=null,g=i?m.indexOf(i.id):-1,b=u?m.indexOf(u.id):-1,x=C.useRef(m),y=!oze(m,x.current),v=b!==-1&&g===-1||y,w=ize(o);Bi(()=>{y&&p&&d(m)},[y,m,p,d]),C.useEffect(()=>{x.current=m},[m]);const N=C.useMemo(()=>({activeIndex:g,containerId:f,disabled:w,disableTransforms:v,items:m,overIndex:b,useDragOverlay:h,sortedRects:sze(m,l),strategy:s}),[g,f,w.draggable,w.droppable,v,m,b,l,h,s]);return C.createElement(MX.Provider,{value:N},t)}const cze=e=>{let{id:t,items:n,activeIndex:r,overIndex:s}=e;return lp(n,r,s).indexOf(t)},uze=e=>{let{containerId:t,isSorting:n,wasDragging:r,index:s,items:o,newIndex:i,previousItems:a,previousContainerId:l,transition:u}=e;return!u||!r||a!==o&&s===i?!1:n?!0:i!==s&&t===l},dze={duration:200,easing:"ease"},TX="transform",fze=ii.Transition.toString({property:TX,duration:0,easing:"linear"}),hze={roleDescription:"sortable"};function mze(e){let{disabled:t,index:n,node:r,rect:s}=e;const[o,i]=C.useState(null),a=C.useRef(n);return Bi(()=>{if(!t&&n!==a.current&&r.current){const l=s.current;if(l){const u=ip(r.current,{ignoreTransform:!0}),d={x:l.left-u.left,y:l.top-u.top,scaleX:l.width/u.width,scaleY:l.height/u.height};(d.x||d.y)&&i(d)}}n!==a.current&&(a.current=n)},[t,n,r,s]),C.useEffect(()=>{o&&i(null)},[o]),o}function oy(e){let{animateLayoutChanges:t=uze,attributes:n,disabled:r,data:s,getNewIndex:o=cze,id:i,strategy:a,resizeObserverConfig:l,transition:u=dze}=e;const{items:d,containerId:f,activeIndex:h,disabled:m,disableTransforms:p,sortedRects:g,overIndex:b,useDragOverlay:x,strategy:y}=C.useContext(MX),v=pze(r,m),w=d.indexOf(i),N=C.useMemo(()=>({sortable:{containerId:f,index:w,items:d},...s}),[f,s,w,d]),S=C.useMemo(()=>d.slice(d.indexOf(i)),[d,i]),{rect:j,node:E,isOver:_,setNodeRef:k}=kX({id:i,data:N,disabled:v.droppable,resizeObserverConfig:{updateMeasurementsFor:S,...l}}),{active:M,activatorEvent:D,activeNodeRect:R,attributes:P,setNodeRef:I,listeners:L,isDragging:F,over:H,setActivatorNodeRef:$,transform:A}=H6e({id:i,data:N,attributes:{...hze,...n},disabled:v.draggable}),q=TLe(k,I),z=!!M,O=z&&!p&&I0(h)&&I0(b),W=!x&&F,B=W&&O?A:null,U=O?B??(a??y)({rects:g,activeNodeRect:R,activeIndex:h,overIndex:b,index:w}):null,V=I0(h)&&I0(b)?o({id:i,items:d,activeIndex:h,overIndex:b}):w,G=M==null?void 0:M.id,K=C.useRef({activeId:G,items:d,newIndex:V,containerId:f}),J=d!==K.current.items,Q=t({active:M,containerId:f,isDragging:F,isSorting:z,id:i,index:w,items:d,newIndex:K.current.newIndex,previousItems:K.current.items,previousContainerId:K.current.containerId,transition:u,wasDragging:K.current.activeId!=null}),re=mze({disabled:!Q,index:w,node:E,rect:j});return C.useEffect(()=>{z&&K.current.newIndex!==V&&(K.current.newIndex=V),f!==K.current.containerId&&(K.current.containerId=f),d!==K.current.items&&(K.current.items=d)},[z,V,f,d]),C.useEffect(()=>{if(G===K.current.activeId)return;if(G!=null&&K.current.activeId==null){K.current.activeId=G;return}const fe=setTimeout(()=>{K.current.activeId=G},50);return()=>clearTimeout(fe)},[G]),{active:M,activeIndex:h,attributes:P,data:N,rect:j,index:w,newIndex:V,items:d,isOver:_,isSorting:z,isDragging:F,listeners:L,node:E,overIndex:b,over:H,setNodeRef:q,setActivatorNodeRef:$,setDroppableNodeRef:k,setDraggableNodeRef:I,transform:re??U,transition:de()};function de(){if(re||J&&K.current.newIndex===w)return fze;if(!(W&&!aC(D)||!u)&&(z||Q))return ii.Transition.toString({...u,property:TX})}}function pze(e,t){var n,r;return typeof e=="boolean"?{draggable:e,droppable:!1}:{draggable:(n=e==null?void 0:e.draggable)!=null?n:t.draggable,droppable:(r=e==null?void 0:e.droppable)!=null?r:t.droppable}}function Yw(e){if(!e)return!1;const t=e.data.current;return!!(t&&"sortable"in t&&typeof t.sortable=="object"&&"containerId"in t.sortable&&"items"in t.sortable&&"index"in t.sortable)}const gze=[Wt.Down,Wt.Right,Wt.Up,Wt.Left],II=(e,t)=>{let{context:{active:n,collisionRect:r,droppableRects:s,droppableContainers:o,over:i,scrollableAncestors:a}}=t;if(gze.includes(e.code)){if(e.preventDefault(),!n||!r)return;const l=[];o.getEnabled().forEach(f=>{if(!f||f!=null&&f.disabled)return;const h=s.get(f.id);if(h)switch(e.code){case Wt.Down:r.top<h.top&&l.push(f);break;case Wt.Up:r.top>h.top&&l.push(f);break;case Wt.Left:r.left>h.left&&l.push(f);break;case Wt.Right:r.left<h.left&&l.push(f);break}});const u=YLe({collisionRect:r,droppableRects:s,droppableContainers:l});let d=cX(u,"id");if(d===(i==null?void 0:i.id)&&u.length>1&&(d=u[1].id),d!=null){const f=o.get(n.id),h=o.get(d),m=h?s.get(h.id):null,p=h==null?void 0:h.node.current;if(p&&m&&f&&h){const b=cC(p).some((S,j)=>a[j]!==S),x=RX(f,h),y=bze(f,h),v=b||!x?{x:0,y:0}:{x:y?r.width-m.width:0,y:y?r.height-m.height:0},w={x:m.left,y:m.top};return v.x&&v.y?w:Db(w,v)}}}};function RX(e,t){return!Yw(e)||!Yw(t)?!1:e.data.current.sortable.containerId===t.data.current.sortable.containerId}function bze(e,t){return!Yw(e)||!Yw(t)||!RX(e,t)?!1:e.data.current.sortable.index<t.data.current.sortable.index}function xze(e,t,n){const[r,s]=C.useState(null),[o,i]=C.useState(""),a=()=>{const p={id:`hierarchy_${Date.now()}`,label:o||"New Hierarchy",type:"static",steps:[],default:!1};t([...e,p]),i(""),s(p.id)},l=p=>{t(e.filter(g=>g.id!==p))},u=(p,g)=>{t(e.map(b=>b.id===p?{...b,...g}:b))};return{editingHierarchy:r,setEditingHierarchy:s,newHierarchyName:o,setNewHierarchyName:i,createNewHierarchy:a,deleteHierarchy:l,updateHierarchy:u,addStepToHierarchy:(p,g)=>{const b=n.find(v=>v.id===g);if(!b)return;const x={field:b,mode:"drillDown",label:`Drill to ${b.label}`,retainFilters:!0,preferredChartType:"bar"},y=e.find(v=>v.id===p);y&&u(p,{steps:[...y.steps,x]})},removeStepFromHierarchy:(p,g)=>{const b=e.find(x=>x.id===p);if(b){const x=[...b.steps];x.splice(g,1),u(p,{steps:x})}},updateStep:(p,g,b)=>{const x=e.find(y=>y.id===p);if(x){const y=x.steps.map((v,w)=>w===g?{...v,...b}:v);u(p,{steps:y})}},setDefaultHierarchy:p=>{t(e.map(g=>({...g,default:g.id===p})))}}}function yze({step:e,hierarchyId:t,stepIndex:n,onUpdateStep:r,open:s,onOpenChange:o,trigger:i}){return c.jsxs(Xr,{open:s,onOpenChange:o,children:[c.jsx(Qr,{asChild:!0,children:i}),c.jsx(Jr,{className:"z-50 w-80",align:"start",children:c.jsxs("div",{className:"space-y-3",children:[c.jsxs("div",{children:[c.jsx(ce,{className:"mb-1 block text-xs font-medium",children:"Chart Type"}),c.jsxs(nt,{value:e.preferredChartType||"bar",onValueChange:a=>{r(t,n,{preferredChartType:a})},children:[c.jsx(et,{className:"h-8",children:c.jsx(ot,{})}),c.jsxs(tt,{children:[c.jsx(be,{value:"bar",children:"Bar Chart"}),c.jsx(be,{value:"pie",children:"Pie Chart"}),c.jsx(be,{value:"line",children:"Line Chart"}),c.jsx(be,{value:"donut",children:"Donut Chart"}),c.jsx(be,{value:"table",children:"Table"}),c.jsx(be,{value:"metric",children:"Metric"})]})]})]}),c.jsxs("div",{children:[c.jsx(ce,{className:"mb-1 block text-xs font-medium",children:"Step Label"}),c.jsx(Nn,{value:e.label||"",onChange:a=>r(t,n,{label:a.target.value}),placeholder:"Custom drill label",className:"h-8"})]}),c.jsxs("div",{children:[c.jsx(ce,{className:"mb-1 block text-xs font-medium",children:"Breadcrumb Label Template"}),c.jsx(Nn,{value:e.breadcrumbLabelTemplate||"",onChange:a=>r(t,n,{breadcrumbLabelTemplate:a.target.value}),placeholder:"e.g., 'Region: {{value}}'",className:"h-8"})]}),c.jsx("div",{className:"flex items-center gap-4",children:c.jsxs("label",{className:"flex items-center gap-2 text-xs",children:[c.jsx("input",{type:"checkbox",checked:e.retainFilters!==!1,onChange:a=>r(t,n,{retainFilters:a.target.checked}),className:"rounded"}),"Retain filters when drilling"]})}),c.jsx("div",{className:"flex justify-end",children:c.jsx(se,{size:"sm",variant:"outline",onClick:()=>o(!1),children:"Done"})})]})})]})}function vze({field:e,step:t,stepIndex:n,hierarchyId:r,onUpdateStep:s,onRemoveStep:o}){const[i,a]=C.useState(!1),{attributes:l,listeners:u,setNodeRef:d,transform:f,transition:h,isDragging:m}=oy({id:`${r}-${e.id}-${n}`,disabled:!1}),p={transform:ii.Transform.toString(f),transition:h,opacity:m?.8:1,zIndex:m?1e3:1};return c.jsx("div",{ref:d,style:p,className:`relative ${i?"z-[9998]":""}`,...l,children:c.jsx(yze,{step:t,hierarchyId:r,stepIndex:n,onUpdateStep:s,open:i,onOpenChange:a,trigger:c.jsxs("div",{className:`flex cursor-pointer items-center gap-2 rounded-lg border bg-muted px-3 py-2 transition-colors hover:bg-muted/50 ${m?"shadow-lg ring-2 ring-primary":""}`,...u,onClick:g=>{g.stopPropagation(),a(b=>!b)},children:[c.jsxs("div",{className:"pointer-events-none flex items-center gap-2",children:[c.jsx("span",{className:"whitespace-nowrap text-sm font-medium",children:e.label}),t.preferredChartType&&t.preferredChartType!=="bar"&&c.jsx("span",{className:"whitespace-nowrap rounded bg-purple-100 px-1 py-0.5 text-xs text-purple-700 dark:bg-purple-900/50 dark:text-purple-300",children:t.preferredChartType}),t.linkedInsightId&&c.jsx("span",{className:"whitespace-nowrap rounded bg-green-100 px-1 py-0.5 text-xs text-green-700 dark:bg-green-900/50 dark:text-green-300",children:"📊"})]}),c.jsx("button",{className:"pointer-events-auto ml-1 text-xs text-muted-foreground hover:text-red-800 dark:hover:text-red-400",onClick:g=>{g.stopPropagation(),o(r,n)},children:c.jsx(yt,{className:"h-3 w-3"})})]})})})}function wze(e){return{sensors:lC(tm(ap,{activationConstraint:{distance:5}}),tm(ty,{coordinateGetter:II})),handleStepDragEnd:(r,s)=>{const{active:o,over:i}=r;if(!i||o.id===i.id)return;const a=o.id.replace(`${s.id}-`,""),l=i.id.replace(`${s.id}-`,""),u=s.steps.findIndex(f=>f.field.id===a),d=s.steps.findIndex(f=>f.field.id===l);if(u!==-1&&d!==-1&&u!==d){const f=lp(s.steps,u,d);e(s.id,{steps:f})}}}}function Sze({hierarchy:e,onUpdateStep:t,onRemoveStep:n,onUpdateHierarchy:r}){const{sensors:s}=wze(r),[o,i]=C.useState(null),a=e.steps.filter(h=>h&&h.field&&h.field.id),u=a.map(h=>h.field).map((h,m)=>`${e.id}-${h.id}-${m}`),d=h=>{const m=h.active.id,p=Number.parseInt(m.split("-").pop()||"0"),g=a[p],b=g==null?void 0:g.field;i(b||null)},f=h=>{i(null);const{active:m,over:p}=h;if(!p||m.id===p.id)return;const g=Number.parseInt(m.id.split("-").pop()||"0"),b=Number.parseInt(p.id.split("-").pop()||"0");if(g!==b&&g<a.length&&b<a.length){const x=[...e.steps],[y]=x.splice(g,1);x.splice(b,0,y),r(e.id,{steps:x})}};return a.length===0?c.jsx("div",{className:"steps-container",onPointerDown:h=>h.stopPropagation(),children:c.jsx("div",{className:"rounded-lg border bg-muted/50 p-2 text-sm text-muted-foreground",children:"No drill steps configured. Add steps to create a drill hierarchy."})}):c.jsx("div",{className:"steps-container",onPointerDown:h=>h.stopPropagation(),children:c.jsxs(ry,{sensors:s,collisionDetection:ey,onDragStart:d,onDragEnd:f,children:[c.jsx(sy,{items:u,strategy:TI,children:c.jsx("div",{className:"flex flex-wrap items-center gap-2",style:{minHeight:"40px"},children:a.map((h,m)=>{if(!h||!h.field||!h.field.id)return null;const p=[];m>0&&p.push(c.jsx(Lr,{className:"pointer-events-none h-4 w-4 text-gray-400"},`arrow-${m}`));const g=m===0,b=m===a.length-1;return p.push(c.jsx(vze,{field:h.field,step:h,stepIndex:m,hierarchyId:e.id,onUpdateStep:t,onRemoveStep:n,isFirstField:g,isLastField:b},`field-${h.field.id}-${m}`)),p})})}),typeof window<"u"&&Ln.createPortal(c.jsx(EX,{className:"semaphor-scope",style:{zIndex:9999},children:o?c.jsx("div",{className:"flex items-center gap-2 rounded-lg border-2 border-blue-300 bg-blue-200 p-2 shadow-lg dark:border-blue-600 dark:bg-blue-900/70",children:c.jsx("span",{className:"whitespace-nowrap text-sm font-medium",children:o.label})}):null}),document.body)]})})}function Cze({hierarchy:e,sampleFieldReferences:t,onUpdateHierarchy:n,onDeleteHierarchy:r,onUpdateStep:s,onRemoveStep:o,onAddStep:i}){const[a,l]=C.useState(!1),{attributes:u,listeners:d,setNodeRef:f,transform:h,transition:m}=oy({id:e.id,disabled:!1}),p={transform:ii.Transform.toString(h),transition:m},g=e.steps.filter(b=>b.field).map(b=>b.field.id);return c.jsxs("div",{ref:f,style:p,className:"hierarchy-container relative rounded-lg border bg-background p-3 transition-shadow hover:shadow-md",children:[c.jsxs("div",{className:"mb-3 flex cursor-move items-center justify-between",...u,...d,children:[c.jsx("div",{className:"flex items-center gap-2",children:c.jsx("div",{onPointerDown:b=>b.stopPropagation(),onClick:b=>b.stopPropagation(),onKeyDown:b=>b.stopPropagation(),children:c.jsx(ei,{value:e.label||"",onSave:b=>{n(e.id,{label:b})},placeholder:"Hierarchy Name",displayClassName:"font-medium",inputClassName:"font-medium"})})}),c.jsx("div",{className:"flex items-center gap-1",children:c.jsx(se,{size:"sm",variant:"ghost",onClick:b=>{b.stopPropagation(),r(e.id)},onPointerDown:b=>b.stopPropagation(),children:c.jsx(Fl,{className:"h-3 w-3"})})})]}),c.jsx(Sze,{hierarchy:e,onUpdateStep:s,onRemoveStep:o,onUpdateHierarchy:n}),c.jsx("div",{className:"mt-3 border-t pt-3","data-hierarchy-editing":!0,children:a?c.jsxs(Lm,{className:"rounded-lg border",children:[c.jsx(Tx,{placeholder:"Search fields..."}),c.jsxs(zm,{children:[c.jsx(Bm,{children:"No field found."}),c.jsx(Vm,{children:t.filter(b=>!g.includes(b.id)).map(b=>c.jsx(Hm,{value:b.label,onSelect:()=>{i(e.id,b.id),l(!1)},children:b.label},b.id))})]})]}):c.jsxs(se,{type:"button",variant:"outline",size:"sm",onClick:b=>{b.preventDefault(),b.stopPropagation(),l(!0)},children:[c.jsx(Sr,{className:"mr-2 h-4 w-4"}),"Add Step"]})})]})}function Nze({open:e,onOpenChange:t,drillHierarchies:n,onUpdateHierarchies:r,availableFields:s}){const[o,i]=C.useState(n);C.useEffect(()=>{e&&i(n)},[e,n]);const a=C.useMemo(()=>s.filter(y=>Tr(y.dataType)==="string"),[s]),l=lC(tm(ap),tm(ty,{coordinateGetter:II})),{createNewHierarchy:u,deleteHierarchy:d,updateHierarchy:f,addStepToHierarchy:h,removeStepFromHierarchy:m,updateStep:p,setDefaultHierarchy:g}=xze(o,i,a),b=y=>{const{active:v,over:w}=y;if(v.id!==(w==null?void 0:w.id)){const N=o.findIndex(j=>j.id===v.id),S=o.findIndex(j=>j.id===(w==null?void 0:w.id));i(lp(o,N,S))}},x=y=>{y||r(o),t(y)};return c.jsx(ns,{modal:!0,open:e,onOpenChange:x,children:c.jsx(Vr,{className:"flex max-h-[85vh] max-w-3xl flex-col overflow-hidden p-0",onInteractOutside:y=>y.preventDefault(),onEscapeKeyDown:y=>y.preventDefault(),children:c.jsx(um,{trapped:!1,children:c.jsxs("div",{className:"flex max-h-[85vh] max-w-3xl flex-col overflow-hidden",children:[c.jsxs(Hr,{className:"border-b px-6 pb-4 pt-6",children:[c.jsx(Ur,{children:"Manage Drill Hierarchies"}),c.jsx(ys,{children:"Create multiple drill paths for different analysis scenarios. Define step-by-step navigation through your dimensions."})]}),c.jsx(Ls,{className:"flex-1 px-6",children:c.jsxs("div",{className:"space-y-4 py-4",children:[o.length>0&&c.jsx("div",{className:"flex justify-end",children:c.jsxs(se,{type:"button",size:"sm",onClick:y=>{y.preventDefault(),y.stopPropagation(),u()},children:[c.jsx(Sr,{className:"mr-1 h-4 w-4"}),"Add Hierarchy"]})}),o.length>0?c.jsx(ry,{sensors:l,collisionDetection:ey,onDragEnd:b,children:c.jsx(sy,{items:o.map(y=>y.id),strategy:RI,children:c.jsx("div",{className:"space-y-4",children:o.map(y=>c.jsx(Cze,{hierarchy:y,sampleFieldReferences:a,onUpdateHierarchy:f,onDeleteHierarchy:d,onSetDefaultHierarchy:g,onUpdateStep:p,onRemoveStep:m,onAddStep:h},y.id))})})}):c.jsxs("div",{className:"rounded-lg border border-dashed p-8 text-center",children:[c.jsx("p",{className:"mb-2 text-sm text-muted-foreground",children:"No hierarchies configured yet"}),c.jsx("p",{className:"mb-4 text-xs text-muted-foreground",children:"Create your first hierarchy to enable drill-down interactions"}),c.jsxs(se,{type:"button",size:"sm",variant:"outline",onClick:y=>{y.preventDefault(),y.stopPropagation(),u()},children:[c.jsx(Sr,{className:"mr-2 h-4 w-4"}),"Create First Hierarchy"]})]})]})}),c.jsx("div",{className:"flex justify-end gap-2 border-t px-6 py-4",children:c.jsx(se,{variant:"outline",onClick:()=>x(!1),children:"Done"})})]})})})})}function IX(e){switch(e){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..."}]}}function jze({interaction:e,onUpdate:t,card:n,availableFields:r,onUpdateHierarchies:s,onManageHierarchies:o}){var M;const[i,a]=C.useState(!1),[l,u]=C.useState(!1),[d,f]=C.useState(null),[h,m]=C.useState(!1),[p,g]=C.useState({}),b=C.useMemo(()=>{var D;return((D=n.interactionConfig)==null?void 0:D.drillHierarchies)||[]},[(M=n.interactionConfig)==null?void 0:M.drillHierarchies]),x=C.useMemo(()=>{var I,L;const D=[],R=e.trigger;if(!R)return D;let P;if(R.type==="attribute"){const F=r.find($=>$.id===R.field.id);F&&(F.dataType==="date"||F.dataType==="timestamp")&&(P=F)}else if(R.type==="metric"){const F=(L=(I=n.config)==null?void 0:I.groupByColumns)==null?void 0:L.find(H=>H.dataType==="date"||H.dataType==="timestamp");F&&(P=F)}if(P&&pse(P,b)){const F=mse(P);D.push(F)}return D},[r,b,e.trigger,n.config]),y=C.useMemo(()=>[...b,...x],[b,x]),v=y.find(D=>D.id===e.hierarchyId);T.useEffect(()=>{i&&v&&v.type==="date"?f(v.id):i||f(null)},[i,v]);const w=D=>{if(x.some(P=>P.id===D)&&s){const P=x.find(I=>I.id===D);P&&s([...b,P])}t({...e,hierarchyId:D}),a(!1)},N=()=>{a(!1),u(!0),o&&o()},S=D=>{s&&s(D)},j=D=>D.steps.map(P=>P.field.label||P.field.name).join(" → "),E=D=>D&&D.charAt(0).toUpperCase()+D.slice(1),_=(D,R,P)=>{const I=[...D.steps];I[R]={...I[R],field:{...I[R].field,dateFormat:P,customFormat:P==="custom"?p[R]||"":void 0}};const L={...D,steps:I};if(s){const F=b.findIndex(H=>H.id===D.id);if(F>=0){const H=[...b];H[F]=L,s(H)}else s([...b,L])}},k=(D,R,P)=>{g(F=>({...F,[R]:P}));const I=[...D.steps];I[R]={...I[R],field:{...I[R].field,dateFormat:"custom",customFormat:P}};const L={...D,steps:I};if(s){const F=b.findIndex(H=>H.id===D.id);if(F>=0){const H=[...b];H[F]=L,s(H)}else s([...b,L])}};return c.jsxs("div",{className:"space-y-4",children:[c.jsxs("div",{className:"space-y-2",children:[c.jsx(ce,{className:"text-sm font-medium",children:"Choose hierarchy"}),c.jsx("p",{className:"mb-2 text-xs text-muted-foreground",children:"Select which hierarchy to drill through when this interaction triggers"}),y.length>0?c.jsxs(c.Fragment,{children:[c.jsxs(Xr,{open:i,onOpenChange:a,children:[c.jsx(Qr,{asChild:!0,children:c.jsxs(se,{variant:"outline",role:"combobox",className:"w-full justify-between",children:[c.jsx("div",{className:"flex flex-1 flex-col items-start text-left",children:v?c.jsxs(c.Fragment,{children:[c.jsx("div",{className:"flex items-center gap-2",children:c.jsx("span",{className:"font-medium",children:v.label||"Unnamed Hierarchy"})}),c.jsx("span",{className:"text-xs text-muted-foreground",children:j(v)})]}):c.jsx("span",{className:"text-muted-foreground",children:"Select hierarchy..."})}),c.jsxs("div",{className:"flex items-center gap-2",children:[v&&v.type==="date"&&c.jsx(se,{variant:"ghost",size:"sm",className:"h-6 w-6 p-0",onClick:D=>{D.stopPropagation(),m(!h)},children:c.jsx(cm,{className:"h-3 w-3"})}),c.jsx(Lr,{className:"h-4 w-4 shrink-0 opacity-50"})]})]})}),c.jsxs(Jr,{className:"w-[500px] p-0",align:"start",children:[c.jsxs("div",{className:"flex items-center justify-between border-b p-3",children:[c.jsx("span",{className:"text-sm font-medium",children:"Select Hierarchy"}),c.jsxs(se,{variant:"ghost",size:"sm",onClick:N,children:[c.jsx(Sr,{className:"mr-1.5 h-3.5 w-3.5"}),"Create new"]})]}),c.jsxs("div",{className:"p-2",children:[x.length>0&&c.jsxs(c.Fragment,{children:[c.jsx("div",{className:"px-3 py-2",children:c.jsx("span",{className:"text-xs font-medium text-muted-foreground",children:"AUTO-GENERATED"})}),x.map(D=>c.jsx("div",{className:`cursor-pointer rounded-md p-3 hover:bg-muted ${e.hierarchyId===D.id?"bg-muted":""}`,onClick:()=>w(D.id),children:c.jsxs("div",{className:"space-y-1",children:[c.jsx("div",{className:"flex items-center gap-2",children:c.jsx("span",{className:"text-sm font-medium",children:D.label||"Unnamed Hierarchy"})}),c.jsx("div",{className:"text-xs text-muted-foreground",children:j(D)})]})},D.id))]}),b.length>0&&c.jsxs(c.Fragment,{children:[x.length>0&&c.jsx("div",{className:"my-2 border-t"}),b.map(D=>c.jsx("div",{className:`cursor-pointer rounded-md p-3 hover:bg-muted ${e.hierarchyId===D.id?"bg-muted":""}`,onClick:()=>w(D.id),children:c.jsxs("div",{className:"space-y-1",children:[c.jsx("div",{className:"flex items-center gap-2",children:c.jsx("span",{className:"text-sm font-medium",children:D.label||"Unnamed Hierarchy"})}),c.jsx("div",{className:"text-xs text-muted-foreground",children:j(D)})]})},D.id))]})]})]})]}),v&&v.type==="date"&&h&&c.jsxs("div",{className:"mt-3 space-y-3 rounded-md border border-border p-3",children:[c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsx(ce,{className:"text-sm font-medium",children:"Customize Date Formats"}),c.jsx(se,{variant:"ghost",size:"sm",className:"h-6 text-xs",onClick:()=>m(!1),children:"Close"})]}),v.steps.map((D,R)=>{var F;const P=D.field.granularity;if(!P)return null;const I=IX(P),L=D.field.dateFormat||((F=I[0])==null?void 0:F.value);return c.jsxs("div",{className:"space-y-1",children:[c.jsx(ce,{className:"text-xs font-medium text-muted-foreground",children:D.field.label||E(P)}),c.jsxs(nt,{value:L,onValueChange:H=>{_(v,R,H)},children:[c.jsx(et,{className:"h-8 text-xs",children:c.jsx(ot,{})}),c.jsx(tt,{children:I.map(H=>c.jsx(be,{value:H.value,className:"text-xs",children:H.label},H.value))})]}),L==="custom"&&c.jsxs("div",{className:"mt-2 space-y-1",children:[c.jsx(Nn,{placeholder:"Enter custom format (e.g., YYYY-MM-DD)",value:D.field.customFormat||p[R]||"",onChange:H=>{k(v,R,H.target.value)},className:"h-8 text-xs"}),c.jsx("p",{className:"text-[10px] text-muted-foreground",children:"Common tokens: YYYY (year), MM (month), DD (day), HH (hour), mm (minute)"})]})]},R)})]})]}):c.jsxs("div",{className:"rounded-md border border-dashed p-6 text-center",children:[c.jsx("p",{className:"mb-2 text-sm text-muted-foreground",children:"No hierarchies configured"}),c.jsx("p",{className:"mb-4 text-xs text-muted-foreground",children:"Create a hierarchy to define your drill path"}),c.jsxs(se,{variant:"outline",size:"sm",onClick:N,children:[c.jsx(Sr,{className:"mr-2 h-4 w-4"}),"Create hierarchy"]})]})]}),c.jsx(Nze,{open:l,onOpenChange:u,drillHierarchies:b,onUpdateHierarchies:S,availableFields:r})]})}function kze({fields:e,selectedFieldIds:t,onSelectionChange:n,searchPlaceholder:r="Search fields...",className:s=""}){const[o,i]=C.useState(""),a=e.filter(d=>d.label.toLowerCase().includes(o.toLowerCase())||d.qualifiedEntityName&&d.qualifiedEntityName.toLowerCase().includes(o.toLowerCase())),l=()=>{const d=[...new Set([...t,...a.map(f=>f.id)])];n(d)},u=()=>{const d=a.map(f=>f.id);n(t.filter(f=>!d.includes(f)))};return c.jsxs("div",{className:`space-y-2 ${s}`,children:[c.jsxs("div",{className:"mb-3 flex items-center gap-2",children:[c.jsx(Nn,{placeholder:r,value:o,onChange:d=>i(d.target.value),className:"flex-1"}),c.jsxs("span",{className:"text-xs text-muted-foreground",children:[a.length," fields"]})]}),c.jsxs("div",{className:"mb-2 flex items-center gap-2",children:[c.jsx(se,{size:"sm",variant:"outline",onClick:l,children:"Select All"}),c.jsx(se,{size:"sm",variant:"outline",onClick:u,children:"Deselect All"}),c.jsxs("span",{className:"text-xs text-muted-foreground",children:[t.length," selected"]})]}),c.jsx("div",{className:"grid max-h-32 grid-cols-2 gap-2 overflow-y-auto rounded border p-2",children:a.map(d=>c.jsxs("label",{className:"flex cursor-pointer items-center gap-2 rounded p-2 text-xs hover:bg-muted/50",children:[c.jsx(Qt,{checked:t.includes(d.id),onCheckedChange:f=>{n(f?[...t,d.id]:t.filter(h=>h!==d.id))}}),c.jsx("span",{className:"font-medium",children:d.label})]},d.id))}),o&&a.length===0&&c.jsxs("div",{className:"py-4 text-center text-sm text-muted-foreground",children:['No fields found matching "',o,'"']})]})}const Eze=e=>["string","boolean"].includes(Tr(e.dataType));function _ze({interaction:e,availableFields:t,onUpdate:n}){var i;const r=t.filter(Eze),s=((i=e.availableFields)==null?void 0:i.map(a=>a.id))||[],o=a=>{const l=r.filter(u=>a.includes(u.id));n({...e,availableFields:l})};return c.jsx("div",{className:"space-y-4",children:c.jsxs("div",{className:"space-y-2",children:[c.jsx(ce,{children:"Available dimensions"}),c.jsx("p",{className:"text-sm text-muted-foreground",children:"Choose which fields users can explore dynamically"}),c.jsx(kze,{fields:r,selectedFieldIds:s,onSelectionChange:o,searchPlaceholder:"Search fields..."}),s.length===0&&c.jsx("p",{className:"text-xs text-amber-600",children:"⚠️ Please select at least one field"})]})})}function Dze({value:e,onChange:t}){const[n,r]=C.useState(!1),[s,o]=C.useState(""),[i,a]=C.useState("all"),{currentUser:l}=oo(),{data:u,isLoading:d}=bM(Pt.DASHBOARD,s),f=(u==null?void 0:u.dashboards)||[],h=f.filter(g=>i==="me"?g.ownership.createdBy.userId===(l==null?void 0:l.id):!0),m=f.find(g=>g.id===e),p=g=>{t(g.id,g.title),r(!1),o("")};return c.jsxs(Xr,{open:n,onOpenChange:r,children:[c.jsx(Qr,{asChild:!0,children:c.jsx(se,{variant:"outline",className:Z("w-full justify-start text-left font-normal",!e&&"text-muted-foreground"),children:m?c.jsx("span",{className:"truncate",children:m.title}):"Choose dashboard..."})}),c.jsx(Jr,{className:"w-[500px] p-0",align:"start",children:c.jsxs(Bs,{value:i,onValueChange:g=>a(g),children:[c.jsx("div",{className:"p-3 border-b",children:c.jsxs("div",{className:"relative",children:[c.jsx(Ui,{className:"absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground"}),c.jsx(Nn,{placeholder:"Search all dashboards...",value:s,onChange:g=>o(g.target.value),className:"pl-9"})]})}),c.jsxs(vs,{className:"w-full justify-start rounded-none border-b bg-transparent p-0",children:[c.jsx(Gt,{value:"me",className:"rounded-none border-b-2 border-transparent data-[state=active]:border-primary data-[state=active]:bg-transparent",children:"created by me"}),c.jsx(Gt,{value:"all",className:"rounded-none border-b-2 border-transparent data-[state=active]:border-primary data-[state=active]:bg-transparent",children:"all"})]}),c.jsx(sr,{value:i,className:"mt-0",children:c.jsx(Ls,{className:"h-[300px]",children:d?c.jsx("div",{className:"p-8 text-center text-sm text-muted-foreground",children:"Loading dashboards..."}):h.length===0?c.jsx("div",{className:"p-8 text-center text-sm text-muted-foreground",children:s?`No dashboards found matching "${s}"`:i==="me"?"No dashboards created by you":"No dashboards available"}):c.jsx("div",{className:"p-2",children:h.map(g=>c.jsxs("button",{onClick:()=>p(g),className:Z("w-full flex items-start gap-3 p-3 rounded-md hover:bg-muted/50 transition-colors text-left",e===g.id&&"bg-muted"),children:[c.jsx(v8,{className:"h-5 w-5 mt-0.5 text-muted-foreground flex-shrink-0"}),c.jsxs("div",{className:"flex-1 min-w-0",children:[c.jsx("div",{className:"font-medium text-sm truncate",children:g.title}),c.jsx("div",{className:"text-xs text-muted-foreground mt-0.5",children:Mze(g.createdAt)})]})]},g.id))})})})]})})]})}function Mze(e){const t=new Date(e),n=new Date;if(t.getDate()===n.getDate()&&t.getMonth()===n.getMonth()&&t.getFullYear()===n.getFullYear()){const i=t.getHours(),a=t.getMinutes(),l=i>=12?"PM":"AM",u=i%12||12,d=a.toString().padStart(2,"0");return`TODAY AT ${u}:${d} ${l}`}const s=t.toLocaleString("en-US",{month:"short"}).toUpperCase(),o=t.getDate();return`${s} ${o}`}function Tze({interaction:e,onUpdate:t}){return c.jsxs("div",{className:"space-y-4",children:[c.jsxs("div",{className:"space-y-2",children:[c.jsx(ce,{className:"text-sm font-medium",children:"Target dashboard"}),c.jsx("p",{className:"text-xs text-muted-foreground mb-2",children:"Select which dashboard to navigate to when this interaction triggers"}),c.jsx(Dze,{value:e.targetDashboardId,onChange:(n,r)=>{const s={...e,targetDashboardId:n};!e.label&&r&&(s.label=r),t(s)}})]}),c.jsxs("div",{className:"space-y-2",children:[c.jsx(ce,{className:"text-sm font-medium",children:"Propagate Filters"}),c.jsx("p",{className:"text-xs text-muted-foreground mb-2",children:"Choose what filters to pass to the target dashboard"}),c.jsxs(nt,{value:e.contextMode||"full",onValueChange:n=>t({...e,contextMode:n}),children:[c.jsx(et,{children:c.jsxs(ot,{placeholder:"Choose context mode...",children:[e.contextMode==="interactionFilters"&&"Interaction Filters",(e.contextMode==="full"||!e.contextMode)&&"All Filters",e.contextMode==="none"&&"None"]})}),c.jsxs(tt,{children:[c.jsx(be,{value:"interactionFilters",children:c.jsxs("div",{className:"flex flex-col items-start gap-1 py-1",children:[c.jsx("span",{className:"font-medium",children:"Interaction Filters"}),c.jsx("span",{className:"text-xs text-muted-foreground",children:"Pass only the clicked element as a filter"})]})}),c.jsx(be,{value:"full",children:c.jsxs("div",{className:"flex flex-col items-start gap-1 py-1",children:[c.jsx("span",{className:"font-medium",children:"All Filters"}),c.jsx("span",{className:"text-xs text-muted-foreground",children:"Pass current dashboard filters + clicked element"})]})}),c.jsx(be,{value:"none",children:c.jsxs("div",{className:"flex flex-col items-start gap-1 py-1",children:[c.jsx("span",{className:"font-medium",children:"None"}),c.jsx("span",{className:"text-xs text-muted-foreground",children:"Navigate without passing any filters"})]})})]})]})]}),!e.targetDashboardId&&c.jsx("div",{className:"rounded-md bg-amber-50 dark:bg-amber-900/20 border border-amber-200 dark:border-amber-800 p-3",children:c.jsx("p",{className:"text-xs text-amber-800 dark:text-amber-200",children:"⚠ Please select a target dashboard to complete this configuration"})}),e.targetDashboardId&&c.jsx("div",{className:"rounded-md bg-green-50 dark:bg-green-900/20 border border-green-200 dark:border-green-800 p-3",children:c.jsx("p",{className:"text-xs text-green-800 dark:text-green-200",children:"✓ Dashboard drill-through configured successfully"})}),c.jsxs("div",{className:"space-y-2",children:[c.jsx(ce,{className:"text-sm font-medium",children:"Menu label"}),c.jsx(Nn,{value:e.label||"",onChange:n=>t({...e,label:n.target.value}),placeholder:hf(e.mode)}),c.jsx("p",{className:"text-xs text-muted-foreground",children:"How this interaction appears when multiple actions are available"})]})]})}function Rze({value:e,onChange:t}){const[n,r]=C.useState(!1),[s,o]=C.useState(""),[i,a]=C.useState("all"),{currentUser:l}=oo(),{data:u,isLoading:d}=bM(Pt.VISUAL,s),f=(u==null?void 0:u.visuals)||[],h=f.filter(g=>i==="me"?g.ownership.createdBy.userId===(l==null?void 0:l.id):!0),m=f.find(g=>g.id===e),p=g=>{t(g.id,g.title),r(!1),o("")};return c.jsxs(Xr,{open:n,onOpenChange:r,children:[c.jsx(Qr,{asChild:!0,children:c.jsx(se,{variant:"outline",className:Z("w-full justify-start text-left font-normal",!e&&"text-muted-foreground"),children:m?c.jsx("span",{className:"truncate",children:m.title}):"Choose insight..."})}),c.jsx(Jr,{className:"w-[500px] p-0",align:"start",children:c.jsxs(Bs,{value:i,onValueChange:g=>a(g),children:[c.jsx("div",{className:"p-3 border-b",children:c.jsxs("div",{className:"relative",children:[c.jsx(Ui,{className:"absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground"}),c.jsx(Nn,{placeholder:"Search all insights...",value:s,onChange:g=>o(g.target.value),className:"pl-9"})]})}),c.jsxs(vs,{className:"w-full justify-start rounded-none border-b bg-transparent p-0",children:[c.jsx(Gt,{value:"me",className:"rounded-none border-b-2 border-transparent data-[state=active]:border-primary data-[state=active]:bg-transparent",children:"created by me"}),c.jsx(Gt,{value:"all",className:"rounded-none border-b-2 border-transparent data-[state=active]:border-primary data-[state=active]:bg-transparent",children:"all"})]}),c.jsx(sr,{value:i,className:"mt-0",children:c.jsx(Ls,{className:"h-[300px]",children:d?c.jsx("div",{className:"p-8 text-center text-sm text-muted-foreground",children:"Loading insights..."}):h.length===0?c.jsx("div",{className:"p-8 text-center text-sm text-muted-foreground",children:s?`No insights found matching "${s}"`:i==="me"?"No insights created by you":"No insights available"}):c.jsx("div",{className:"p-2",children:h.map(g=>c.jsxs("button",{onClick:()=>p(g),className:Z("w-full flex items-start gap-3 p-3 rounded-md hover:bg-muted/50 transition-colors text-left",e===g.id&&"bg-muted"),children:[c.jsx(im,{className:"h-5 w-5 mt-0.5 text-muted-foreground flex-shrink-0"}),c.jsxs("div",{className:"flex-1 min-w-0",children:[c.jsx("div",{className:"font-medium text-sm truncate",children:g.title}),c.jsx("div",{className:"text-xs text-muted-foreground mt-0.5",children:Ize(g.createdAt)})]})]},g.id))})})})]})})]})}function Ize(e){const t=new Date(e),n=new Date;if(t.getDate()===n.getDate()&&t.getMonth()===n.getMonth()&&t.getFullYear()===n.getFullYear()){const i=t.getHours(),a=t.getMinutes(),l=i>=12?"PM":"AM",u=i%12||12,d=a.toString().padStart(2,"0");return`TODAY AT ${u}:${d} ${l}`}const s=t.toLocaleString("en-US",{month:"short"}).toUpperCase(),o=t.getDate();return`${s} ${o}`}function Aze({interaction:e,onUpdate:t}){return c.jsxs("div",{className:"space-y-4",children:[c.jsxs("div",{className:"space-y-2",children:[c.jsx(ce,{className:"text-sm font-medium",children:"Target insight"}),c.jsx("p",{className:"text-xs text-muted-foreground mb-2",children:"Select the saved insight to navigate to"}),c.jsx(Rze,{value:e.targetInsightId,onChange:(n,r)=>{const s={...e,targetInsightId:n};!e.label&&r&&(s.label=r),t(s)}})]}),c.jsxs("div",{className:"space-y-2",children:[c.jsx(ce,{className:"text-sm font-medium",children:"Propagate Filters"}),c.jsx("p",{className:"text-xs text-muted-foreground mb-2",children:"Choose what filters to pass to the insight"}),c.jsxs(nt,{value:e.contextMode||"full",onValueChange:n=>t({...e,contextMode:n}),children:[c.jsx(et,{children:c.jsxs(ot,{placeholder:"Choose context mode...",children:[e.contextMode==="interactionFilters"&&"Interaction Filters",(e.contextMode==="full"||!e.contextMode)&&"All Filters",e.contextMode==="none"&&"None"]})}),c.jsxs(tt,{children:[c.jsx(be,{value:"interactionFilters",children:c.jsxs("div",{className:"flex flex-col items-start gap-1 py-1",children:[c.jsx("span",{className:"font-medium",children:"Interaction Filters"}),c.jsx("span",{className:"text-xs text-muted-foreground",children:"Pass only the clicked element as a filter"})]})}),c.jsx(be,{value:"full",children:c.jsxs("div",{className:"flex flex-col items-start gap-1 py-1",children:[c.jsx("span",{className:"font-medium",children:"All Filters"}),c.jsx("span",{className:"text-xs text-muted-foreground",children:"Pass all current filters and selections"})]})}),c.jsx(be,{value:"none",children:c.jsxs("div",{className:"flex flex-col items-start gap-1 py-1",children:[c.jsx("span",{className:"font-medium",children:"None"}),c.jsx("span",{className:"text-xs text-muted-foreground",children:"Open insight without any filters"})]})})]})]})]}),c.jsxs("div",{className:"space-y-2",children:[c.jsx(ce,{className:"text-sm font-medium",children:"Display mode"}),c.jsx("p",{className:"text-xs text-muted-foreground mb-2",children:"Choose how the insight should be displayed"}),c.jsxs(nt,{value:e.displayMode||"modal",onValueChange:n=>t({...e,displayMode:n}),children:[c.jsx(et,{children:c.jsx(ot,{placeholder:"Choose display mode..."})}),c.jsxs(tt,{children:[c.jsx(be,{value:"modal",children:c.jsx("div",{className:"flex items-center gap-2",children:c.jsx("span",{children:"Open in modal"})})}),c.jsx(be,{value:"replace-card",children:c.jsx("div",{className:"flex items-center gap-2",children:c.jsx("span",{children:"Replace the card"})})})]})]})]}),!e.targetInsightId&&c.jsx("div",{className:"rounded-md bg-amber-50 dark:bg-amber-900/20 border border-amber-200 dark:border-amber-800 p-3",children:c.jsx("p",{className:"text-xs text-amber-800 dark:text-amber-200",children:"⚠ Please enter a target insight ID to complete this configuration"})}),e.targetInsightId&&c.jsx("div",{className:"rounded-md bg-green-50 dark:bg-green-900/20 border border-green-200 dark:border-green-800 p-3",children:c.jsx("p",{className:"text-xs text-green-800 dark:text-green-200",children:"✓ Insight drill-through configured successfully"})}),c.jsxs("div",{className:"space-y-2",children:[c.jsx(ce,{className:"text-sm font-medium",children:"Menu label"}),c.jsx(Nn,{value:e.label||"",onChange:n=>t({...e,label:n.target.value}),placeholder:hf(e.mode)}),c.jsx("p",{className:"text-xs text-muted-foreground",children:"How this interaction appears when multiple actions are available"})]})]})}function Pze(e){return e.filter(t=>t.role==="groupby"||t.role==="pivotby").map(t=>({id:t.name,label:t.label||t.name,category:"attribute",field:t}))}function Oze(){return[{id:"card_id",label:"Card ID",category:"identifier"},{id:"frame_id",label:"Frame ID",category:"identifier"},{id:"sheet_id",label:"Sheet ID",category:"identifier"}]}function Fze(e,t){const n=`{{${t}}}`;return e.includes(n)}function $ze(e,t){return t.filter(n=>Fze(e,n.id))}function Lze(e,t,n){const r=`{{${t}}}`,s=e.slice(0,n)+r+e.slice(n),o=n+r.length;return{newTemplate:s,newCursorPosition:o}}function zze(e,t){let n=e;return t.forEach(r=>{const s=`{{${r.id}}}`;let o;if(r.category==="identifier")o=`${r.id.toUpperCase()}-abc123`;else{const i=r.label.toLowerCase();i.includes("name")?o="Example Name":i.includes("region")||i.includes("location")?o="California":i.includes("id")?o="ID-12345":i.includes("category")?o="Category A":o="Sample Value"}n=n.replace(new RegExp(s,"g"),o)}),n}const AX=T.forwardRef(({className:e,...t},n)=>c.jsx("textarea",{className:Z("flex min-h-[80px] w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background placeholder:text-muted-foreground disabled:cursor-not-allowed disabled:opacity-50","focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-inset focus-visible:ring-ring focus-visible:ring-offset-0",e),ref:n,...t}));AX.displayName="Textarea";function Bze({open:e,onOpenChange:t,interaction:n,availableFields:r,onSave:s}){const[o,i]=C.useState(n.urlTemplate||""),[a,l]=C.useState(0),[u,d]=C.useState(n.encodeParameters!==!1),[f,h]=C.useState(n.label||""),m=C.useRef(null);C.useEffect(()=>{e&&(i(n.urlTemplate||""),d(n.encodeParameters!==!1),h(n.label||""),l(0))},[e,n.urlTemplate,n.encodeParameters,n.label]);const p=Pze(r),g=Oze(),b=[...p,...g],x=$ze(o,b),y=vse(o),v=o&&y.valid?zze(o,x):"",w=k=>{i(k.target.value),l(k.target.selectionStart)},N=k=>{const M=k.target;l(M.selectionStart)},S=k=>{const M=k.target;l(M.selectionStart)},j=k=>{const{newTemplate:M,newCursorPosition:D}=Lze(o,k.id,a);i(M),l(D),m.current&&(m.current.focus(),setTimeout(()=>{m.current&&m.current.setSelectionRange(D,D)},0))},E=()=>{y.valid&&(s({...n,urlTemplate:o,parameters:x,encodeParameters:u,label:f}),t(!1))},_=()=>{t(!1)};return c.jsx(ns,{open:e,onOpenChange:t,children:c.jsxs(Vr,{className:"max-h-[90vh] max-w-5xl overflow-y-auto",onOpenAutoFocus:k=>{k.preventDefault(),setTimeout(()=>{var M;(M=m.current)==null||M.focus()},0)},children:[c.jsxs(Hr,{children:[c.jsx(Ur,{children:"Configure Drill to URL"}),c.jsx(ys,{children:"Build a custom URL with dynamic parameters that will open when users click on chart elements."})]}),c.jsxs("div",{className:"flex flex-col gap-6 py-4",children:[c.jsxs("div",{className:"grid grid-cols-2 gap-6",children:[c.jsxs("div",{className:"flex flex-col gap-4",children:[c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsx(ce,{htmlFor:"url-template",children:"URL"}),c.jsx(_n,{children:c.jsxs(Zt,{children:[c.jsx(Xt,{asChild:!0,children:c.jsx(Wn,{className:"h-4 w-4 text-muted-foreground"})}),c.jsx(en,{children:c.jsx("p",{className:"max-w-xs text-xs",children:"Enter your URL and click parameters from the right panel to insert them. Parameters will be replaced with actual values when the URL is opened."})})]})})]}),c.jsx(AX,{ref:m,id:"url-template",value:o,onChange:w,onClick:N,onKeyUp:S,placeholder:"https://example.com/product/{{product_id}}?region={{region}}",className:"min-h-[200px] font-mono text-sm"}),!y.valid&&o&&c.jsx("div",{className:"rounded-lg border border-destructive bg-destructive/10 p-3",children:c.jsx("div",{className:"text-sm text-destructive",children:y.errors.map((k,M)=>c.jsx("div",{children:k},M))})}),v&&c.jsxs("div",{className:"space-y-2",children:[c.jsx(ce,{className:"text-xs text-muted-foreground",children:"Preview:"}),c.jsx("div",{className:"rounded-md bg-muted p-3",children:c.jsx("p",{className:"break-all font-mono text-xs",children:v})})]})]}),c.jsxs("div",{className:"flex flex-col gap-4",children:[c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsx(ce,{children:"Parameters"}),c.jsx(_n,{children:c.jsxs(Zt,{children:[c.jsx(Xt,{asChild:!0,children:c.jsx(Wn,{className:"h-4 w-4 text-muted-foreground"})}),c.jsx(en,{children:c.jsx("p",{className:"max-w-xs text-xs",children:"Click any parameter to insert it into your URL at the cursor position. Attributes come from your chart data, Identifiers are system values."})})]})})]}),c.jsxs("div",{className:"flex flex-col gap-6 rounded-lg border p-4",children:[c.jsxs("div",{className:"space-y-3",children:[c.jsx("div",{className:"text-xs font-medium uppercase tracking-wide text-muted-foreground",children:"Attributes"}),c.jsxs("div",{className:"space-y-1",children:[p.map(k=>c.jsx(M$,{parameter:k,isUsed:x.some(M=>M.id===k.id),onClick:()=>j(k)},k.id)),p.length===0&&c.jsx("p",{className:"text-sm text-muted-foreground",children:"No attributes available"})]})]}),c.jsxs("div",{className:"space-y-3",children:[c.jsx("div",{className:"text-xs font-medium uppercase tracking-wide text-muted-foreground",children:"Identifiers"}),c.jsx("div",{className:"space-y-1",children:g.map(k=>c.jsx(M$,{parameter:k,isUsed:x.some(M=>M.id===k.id),onClick:()=>j(k)},k.id))})]})]})]})]}),c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsx(Qt,{id:"encode-params",checked:u,onCheckedChange:k=>d(k===!0)}),c.jsx(ce,{htmlFor:"encode-params",className:"cursor-pointer text-sm font-normal",children:"URL encode parameters"}),c.jsx(_n,{children:c.jsxs(Zt,{children:[c.jsx(Xt,{asChild:!0,children:c.jsx(Wn,{className:"h-4 w-4 text-muted-foreground"})}),c.jsx(en,{children:c.jsx("p",{className:"max-w-xs text-xs",children:"Recommended. Encodes special characters in parameter values to ensure valid URLs (e.g., spaces become %20)."})})]})})]}),c.jsxs("div",{className:"space-y-2",children:[c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsx(ce,{className:"text-sm font-medium",children:"Menu label"}),c.jsx(_n,{children:c.jsxs(Zt,{children:[c.jsx(Xt,{asChild:!0,children:c.jsx(Wn,{className:"h-4 w-4 text-muted-foreground"})}),c.jsx(en,{children:c.jsx("p",{className:"max-w-xs text-xs",children:"How this interaction appears when multiple actions are available"})})]})})]}),c.jsx(Nn,{value:f,onChange:k=>h(k.target.value),placeholder:hf("drillToURL")})]}),c.jsxs("div",{className:"flex items-start gap-2 rounded-lg border bg-muted/50 p-3",children:[c.jsx(Wn,{className:"mt-0.5 h-4 w-4 text-muted-foreground"}),c.jsx("p",{className:"text-xs text-muted-foreground",children:"URLs will always open in a new browser tab when clicked."})]})]}),c.jsxs(xs,{children:[c.jsx(se,{variant:"outline",onClick:_,children:"Cancel"}),c.jsx(se,{onClick:E,disabled:!y.valid,children:"Save"})]})]})})}function M$({parameter:e,isUsed:t,onClick:n}){var o,i;const r=e.category==="attribute"?"🏷️":"#",s=((o=e.field)==null?void 0:o.qualifiedFieldName)||((i=e.field)==null?void 0:i.name);return c.jsxs(se,{type:"button",variant:"ghost",className:"h-auto w-full justify-start gap-2 px-3 py-2 font-normal hover:bg-accent",onClick:n,children:[c.jsx("span",{className:"text-base",children:r}),c.jsxs("div",{className:"flex flex-1 flex-col items-start gap-0.5",children:[c.jsx("span",{className:"text-sm",children:e.label}),s&&c.jsx("span",{className:"text-xs text-muted-foreground",children:s})]}),t&&c.jsx(Fe,{variant:"secondary",className:"ml-auto gap-1",children:c.jsx(Mr,{className:"h-3 w-3"})})]})}function Vze({interaction:e,availableFields:t,onUpdate:n}){const[r,s]=C.useState(!1),o=!!e.urlTemplate;return c.jsxs("div",{className:"flex flex-col gap-4",children:[o?c.jsxs("div",{className:"flex flex-col gap-3 rounded-lg border p-4",children:[c.jsxs("div",{className:"flex items-start justify-between gap-4",children:[c.jsxs("div",{className:"flex-1 space-y-2",children:[c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsx(Kg,{className:"h-4 w-4 text-muted-foreground"}),c.jsx("span",{className:"text-sm font-medium",children:"URL Template"})]}),c.jsx("div",{className:"rounded-md bg-muted p-3",children:c.jsx("p",{className:"break-all font-mono text-xs",children:e.urlTemplate})})]}),c.jsxs(se,{variant:"outline",size:"sm",onClick:()=>s(!0),children:[c.jsx(T1,{className:"mr-2 h-4 w-4"}),"Edit"]})]}),e.parameters&&e.parameters.length>0&&c.jsxs("div",{className:"text-xs text-muted-foreground",children:[e.parameters.length," parameter",e.parameters.length!==1?"s":""," configured"]}),c.jsxs("div",{className:"text-xs text-muted-foreground",children:["URL encoding:"," ",e.encodeParameters!==!1?"enabled":"disabled"]})]}):c.jsxs("div",{className:"flex flex-col items-center gap-3 rounded-lg border border-dashed p-8",children:[c.jsx(Kg,{className:"h-8 w-8 text-muted-foreground"}),c.jsx("p",{className:"text-sm text-muted-foreground",children:"No URL configured"}),c.jsx(se,{variant:"outline",size:"sm",onClick:()=>s(!0),children:"Add Custom URL"})]}),c.jsx(Bze,{open:r,onOpenChange:s,interaction:e,availableFields:t,onSave:n})]})}var fC="Switch",[Hze]=kr(fC),[Uze,Wze]=Hze(fC),PX=T.forwardRef((e,t)=>{const{__scopeSwitch:n,name:r,checked:s,defaultChecked:o,required:i,disabled:a,value:l="on",onCheckedChange:u,form:d,...f}=e,[h,m]=T.useState(null),p=rt(t,v=>m(v)),g=T.useRef(!1),b=h?d||!!h.closest("form"):!0,[x,y]=Br({prop:s,defaultProp:o??!1,onChange:u,caller:fC});return c.jsxs(Uze,{scope:n,checked:x,disabled:a,children:[c.jsx(ze.button,{type:"button",role:"switch","aria-checked":x,"aria-required":i,"data-state":LX(x),"data-disabled":a?"":void 0,disabled:a,value:l,...f,ref:p,onClick:ke(e.onClick,v=>{y(w=>!w),b&&(g.current=v.isPropagationStopped(),g.current||v.stopPropagation())})}),b&&c.jsx($X,{control:h,bubbles:!g.current,name:r,value:l,checked:x,required:i,disabled:a,form:d,style:{transform:"translateX(-100%)"}})]})});PX.displayName=fC;var OX="SwitchThumb",FX=T.forwardRef((e,t)=>{const{__scopeSwitch:n,...r}=e,s=Wze(OX,n);return c.jsx(ze.span,{"data-state":LX(s.checked),"data-disabled":s.disabled?"":void 0,...r,ref:t})});FX.displayName=OX;var qze="SwitchBubbleInput",$X=T.forwardRef(({__scopeSwitch:e,control:t,checked:n,bubbles:r=!0,...s},o)=>{const i=T.useRef(null),a=rt(i,o),l=gx(n),u=ix(t);return T.useEffect(()=>{const d=i.current;if(!d)return;const f=window.HTMLInputElement.prototype,m=Object.getOwnPropertyDescriptor(f,"checked").set;if(l!==n&&m){const p=new Event("click",{bubbles:r});m.call(d,n),d.dispatchEvent(p)}},[l,n,r]),c.jsx("input",{type:"checkbox","aria-hidden":!0,defaultChecked:n,...s,tabIndex:-1,ref:a,style:{...s.style,...u,position:"absolute",pointerEvents:"none",opacity:0,margin:0}})});$X.displayName=qze;function LX(e){return e?"checked":"unchecked"}var iy=PX,AI=FX;const g_=T.forwardRef(({className:e,...t},n)=>c.jsx(iy,{className:Z("peer inline-flex h-6 w-11 shrink-0 cursor-pointer items-center rounded-full border-2 border-transparent transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background disabled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:bg-primary data-[state=unchecked]:bg-input",e),...t,ref:n,children:c.jsx(AI,{className:Z("pointer-events-none block h-5 w-5 rounded-full bg-background shadow-lg ring-0 transition-transform data-[state=checked]:translate-x-5 data-[state=unchecked]:translate-x-0")})}));g_.displayName=iy.displayName;function Yze({interaction:e,onUpdate:t}){return c.jsxs("div",{className:"space-y-4",children:[c.jsxs("div",{className:"space-y-2",children:[c.jsx(ce,{className:"text-sm font-medium",children:"Fetch mode"}),c.jsx("p",{className:"text-xs text-muted-foreground mb-2",children:"Choose when to load the detailed data"}),c.jsxs(nt,{value:e.fetchMode||"lazy",onValueChange:n=>t({...e,fetchMode:n}),children:[c.jsx(et,{children:c.jsx(ot,{placeholder:"Choose fetch mode..."})}),c.jsxs(tt,{children:[c.jsx(be,{value:"lazy",children:c.jsxs("div",{className:"flex flex-col items-start gap-1 py-1",children:[c.jsx("span",{className:"font-medium",children:"Lazy loading"}),c.jsx("span",{className:"text-xs text-muted-foreground",children:"Fetch data only when user clicks"})]})}),c.jsx(be,{value:"preloaded",children:c.jsxs("div",{className:"flex flex-col items-start gap-1 py-1",children:[c.jsx("span",{className:"font-medium",children:"Preloaded"}),c.jsx("span",{className:"text-xs text-muted-foreground",children:"Fetch all data when dashboard loads"})]})})]})]}),c.jsxs("div",{className:"rounded-md bg-blue-50 dark:bg-blue-900/20 border border-blue-200 dark:border-blue-800 p-3 flex gap-2",children:[c.jsx(Wn,{className:"h-4 w-4 text-blue-600 dark:text-blue-400 mt-0.5 flex-shrink-0"}),c.jsx("div",{className:"text-xs text-blue-800 dark:text-blue-200",children:e.fetchMode==="lazy"?c.jsxs(c.Fragment,{children:[c.jsx("div",{className:"font-medium",children:"Lazy loading"}),c.jsx("div",{className:"mt-1",children:"Data is fetched on-demand when the user clicks. Best for large datasets or when detailed data isn't always needed."})]}):c.jsxs(c.Fragment,{children:[c.jsx("div",{className:"font-medium",children:"Preloaded"}),c.jsx("div",{className:"mt-1",children:"Data is fetched when the dashboard loads. Best for small datasets or when instant drill-down is required."})]})})]})]}),c.jsxs("div",{className:"space-y-2",children:[c.jsx(ce,{className:"text-sm font-medium",children:"Record limit"}),c.jsx("p",{className:"text-xs text-muted-foreground mb-2",children:"Maximum number of detailed records to show (0 for unlimited)"}),c.jsx(Nn,{type:"number",min:"0",placeholder:"100",value:e.inlineLimit??100,onChange:n=>{const r=parseInt(n.target.value)||0;t({...e,inlineLimit:r})}})]}),c.jsxs("div",{className:"space-y-2",children:[c.jsx(ce,{className:"text-sm font-medium",children:"Display mode"}),c.jsx("p",{className:"text-xs text-muted-foreground mb-2",children:"How to display the detailed records"}),c.jsxs(nt,{value:e.displayMode||"table",onValueChange:n=>t({...e,displayMode:n}),children:[c.jsx(et,{children:c.jsx(ot,{placeholder:"Choose display mode..."})}),c.jsxs(tt,{children:[c.jsx(be,{value:"table",children:c.jsx("div",{className:"flex items-center gap-2",children:c.jsx("span",{children:"Table view"})})}),c.jsx(be,{value:"list",children:c.jsx("div",{className:"flex items-center gap-2",children:c.jsx("span",{children:"List view"})})}),c.jsx(be,{value:"cards",children:c.jsx("div",{className:"flex items-center gap-2",children:c.jsx("span",{children:"Card view"})})})]})]})]}),c.jsxs("div",{className:"flex items-center justify-between rounded-md border p-3 bg-background",children:[c.jsxs("div",{className:"space-y-0.5",children:[c.jsx(ce,{className:"text-sm font-medium",children:"Show in modal"}),c.jsx("p",{className:"text-xs text-muted-foreground",children:"Display detailed records in a modal overlay"})]}),c.jsx(g_,{checked:e.showInModal??!1,onCheckedChange:n=>t({...e,showInModal:n})})]}),c.jsxs("div",{className:"flex items-center justify-between rounded-md border p-3 bg-background",children:[c.jsxs("div",{className:"space-y-0.5",children:[c.jsx(ce,{className:"text-sm font-medium",children:"Allow export"}),c.jsx("p",{className:"text-xs text-muted-foreground",children:"Enable users to export the detailed records"})]}),c.jsx(g_,{checked:e.allowExport??!0,onCheckedChange:n=>t({...e,allowExport:n})})]}),c.jsxs("div",{className:"rounded-md bg-green-50 dark:bg-green-900/20 border border-green-200 dark:border-green-800 p-3",children:[c.jsx("div",{className:"text-xs text-green-800 dark:text-green-200",children:"✓ Inline drill configured successfully"}),c.jsxs("div",{className:"mt-2 space-y-1 text-xs text-green-700 dark:text-green-300",children:[c.jsxs("div",{children:["Mode: ",e.fetchMode==="lazy"?"Lazy loading":"Preloaded"]}),c.jsxs("div",{children:["Limit: ",e.inlineLimit===0?"Unlimited":`${e.inlineLimit} records`]}),c.jsxs("div",{children:["Display: ",e.displayMode==="table"?"Table view":e.displayMode==="list"?"List view":"Card view"]})]})]}),c.jsxs("div",{className:"space-y-2",children:[c.jsx(ce,{className:"text-sm font-medium",children:"Menu label"}),c.jsx(Nn,{value:e.label||"",onChange:n=>t({...e,label:n.target.value}),placeholder:hf(e.mode)}),c.jsx("p",{className:"text-xs text-muted-foreground",children:"How this interaction appears when multiple actions are available"})]})]})}function Gze({interaction:e,metrics:t,attributes:n,availableFields:r,card:s,onUpdateHierarchies:o,onUpdate:i,onRemove:a}){const l=e.trigger!==void 0,u=e.mode!==void 0,d=l&&u,[f,h]=C.useState(!d),m=()=>{var x;if(!l)return"Configure interaction";const g=`When ${((x=e.trigger)==null?void 0:x.field.label)||"..."}`;if(!u)return`${g} → Choose action`;const b=e.label||hf(e.mode);return`${g} → ${b}`},p=u?Bw(e.mode):null;return c.jsxs(Do,{className:"relative p-0",children:[c.jsx(se,{variant:"ghost",size:"sm",className:"absolute right-2 top-2 z-10 h-8 w-8 p-0",onClick:a,"aria-label":"Remove interaction",children:c.jsx(yt,{className:"h-3 w-3"})}),c.jsxs(Js,{open:f,onOpenChange:h,children:[c.jsx(eo,{asChild:!0,children:c.jsxs(se,{variant:"ghost",className:"h-auto w-full justify-between p-4 pr-12 hover:bg-muted/50",children:[c.jsxs("div",{className:"flex items-center gap-3",children:[p&&c.jsx(p,{className:"h-4 w-4 flex-shrink-0"}),c.jsx("span",{className:"text-left text-sm font-medium",children:m()})]}),f?c.jsx(FD,{className:"h-3 w-3 flex-shrink-0"}):c.jsx(M1,{className:"h-3 w-3 flex-shrink-0"})]})}),c.jsx(to,{children:c.jsxs("div",{className:"space-y-6 border-t p-6",children:[c.jsx("div",{className:"space-y-3",children:l?c.jsxs("div",{className:"space-y-2",children:[c.jsxs("div",{className:"text-sm font-medium",children:["When I click on"," ",c.jsx("span",{className:"text-muted-foreground",children:"(value of)"})]}),e.trigger&&c.jsxs("div",{className:"inline-flex cursor-pointer items-center gap-2 rounded-md border bg-background px-3 py-2 hover:bg-muted/50",onClick:()=>{i({...e,trigger:void 0})},children:[Eb(e.trigger.field.dataType),c.jsx("span",{className:"text-sm font-medium",children:e.trigger.field.label})]})]}):c.jsxs(c.Fragment,{children:[c.jsx("div",{className:"text-sm font-medium",children:"When I click on"}),c.jsx(_Le,{value:e.trigger,onChange:g=>{i({...e,trigger:g})},metrics:t,attributes:n})]})}),l&&c.jsx(c.Fragment,{children:c.jsxs("div",{className:"space-y-3",children:[c.jsx("div",{className:"text-sm font-medium",children:"I want to"}),c.jsx(DLe,{value:e.mode,onChange:g=>{if(!e.trigger){console.error("Trigger must be defined before selecting action");return}const b={mode:g,trigger:e.trigger};switch(g){case"clickFilter":i({...b,mode:"clickFilter",filterFields:[]});break;case"drillDown":i({...b,mode:"drillDown",filterFields:[]});break;case"dynamicDrill":i({...b,mode:"dynamicDrill",availableFields:[]});break;case"drillThrough":i({...b,mode:"drillThrough",filterFields:[],targetDashboardId:""});break;case"drillToDetail":i({...b,mode:"drillToDetail",filterFields:[]});break;case"drillToURL":i({...b,mode:"drillToURL",filterFields:[],urlTemplate:"",parameters:[],encodeParameters:!0});break;case"inlineDrill":i({...b,mode:"inlineDrill",filterFields:[]});break}}})]})}),l&&u&&c.jsxs(c.Fragment,{children:[c.jsx(As,{}),c.jsx(Kze,{interaction:e,metrics:t,attributes:n,availableFields:r,card:s,onUpdateHierarchies:o,onUpdate:i})]})]})})]})]})}function Kze({interaction:e,metrics:t,attributes:n,availableFields:r,card:s,onUpdateHierarchies:o,onUpdate:i}){switch(e.mode){case"clickFilter":return c.jsx(MLe,{interaction:e,onUpdate:a=>i(a)});case"drillDown":return c.jsx(jze,{interaction:e,onUpdate:a=>i(a),card:s,availableFields:r,onUpdateHierarchies:o});case"dynamicDrill":return c.jsx(_ze,{interaction:e,onUpdate:a=>i(a),availableFields:r});case"drillThrough":return c.jsx(Tze,{interaction:e,onUpdate:a=>i(a)});case"drillToDetail":return c.jsx(Aze,{interaction:e,onUpdate:a=>i(a)});case"drillToURL":return c.jsx(Vze,{interaction:e,availableFields:[...t,...n],onUpdate:a=>i(a)});case"inlineDrill":return c.jsx(Yze,{interaction:e,onUpdate:a=>i(a)});default:return c.jsx("div",{className:"text-sm text-muted-foreground",children:"Unknown interaction type"})}}function Zze({interactions:e,metrics:t,attributes:n,availableFields:r,card:s,onUpdateHierarchies:o,onChange:i}){const[a,l]=C.useState(null),u=()=>{const h={};i([...e,h]),l(e.length)},d=(h,m)=>{const p=[...e];p[h]=m,i(p)},f=h=>{const m=e.filter((p,g)=>g!==h);i(m),a===h&&l(null)};return c.jsxs("div",{className:"space-y-4",children:[e.length>0?c.jsx("div",{className:"space-y-3",children:e.map((h,m)=>c.jsx(Gze,{interaction:h,metrics:t,attributes:n,availableFields:r,card:s,onUpdateHierarchies:o,onUpdate:p=>d(m,p),onRemove:()=>f(m)},m))}):c.jsx("div",{className:"border rounded-lg p-8 text-center bg-muted/30",children:c.jsxs("div",{className:"space-y-2",children:[c.jsx("div",{className:"text-sm font-medium",children:"No interactions configured"}),c.jsx("div",{className:"text-xs text-muted-foreground",children:'Click "Add Interaction" to create your first interaction'}),c.jsx("div",{className:"pt-2",children:c.jsxs(se,{onClick:u,size:"sm",variant:"outline",children:[c.jsx(Sr,{className:"mr-2 h-4 w-4"}),"Add First Interaction"]})})]})}),e.length>0&&c.jsx("div",{className:"flex justify-start pt-2",children:c.jsxs(se,{onClick:u,size:"sm",variant:"outline",children:[c.jsx(Sr,{className:"mr-2 h-4 w-4"}),"Add Interaction"]})})]})}function Xze(){var L,F,H;const{open:e,frameId:t,cardId:n,closePopover:r,anchorPosition:s}=fR(),o=Npe(),i=jpe(),{updateCurrentDashboardCard:a}=Ot(),{setCard:l}=Qn(),u=X($=>$.dashboard),d=((L=u==null?void 0:u.sheets)==null?void 0:L.flatMap($=>$.frames||[]).find($=>($==null?void 0:$.id)===t))||null,f=d&&n?d.cards.find($=>$.id===n):null;C.useEffect(()=>{e&&f&&l(f)},[e,f,l]);const{columns:h}=pT(),{metricFields:m,groupByFields:p,pivotByFields:g}=Rz();[...p,...g];const b=h,x=m,y=[...p,...g],v=((F=o.interactionConfig)==null?void 0:F.drillHierarchies)||[],w=((H=o.interactionConfig)==null?void 0:H.allowedDrillTargets)||[],[N,S]=C.useState(v),[j,E]=C.useState(w||[]),[_,k]=C.useState(null),[M,D]=C.useState(()=>Si(o.interactionConfig));C.useRef(null),C.useEffect(()=>{var $,A;e&&(S((($=o.interactionConfig)==null?void 0:$.drillHierarchies)||[]),E(((A=o.interactionConfig)==null?void 0:A.allowedDrillTargets)||[]),k(null),D(Si(o.interactionConfig)))},[e,o.interactionConfig]);const R=()=>{i.updateDrillHierarchies(N),i.updateAllowedDrillTargets(j);const $={...o,interactionConfig:{...o.interactionConfig,drillHierarchies:N,allowedDrillTargets:j,interactions:M}};a($),l($),r()},P=()=>{k(null),r()};if(!e||!t||!n||!f||!s)return null;const I={position:"fixed",left:`${s.left}px`,top:`${s.top}px`,width:`${s.width}px`,height:`${s.height}px`};return c.jsxs(Xr,{modal:!1,open:e,onOpenChange:$=>!$&&r(),children:[c.jsx(Qr,{asChild:!0,children:c.jsx("div",{style:I,className:"pointer-events-none invisible","aria-hidden":"true"})}),c.jsxs(Jr,{onEscapeKeyDown:$=>$.preventDefault(),className:"mt-5 flex max-h-[70vh] w-[600px] max-w-4xl flex-col overflow-hidden p-0",align:"start",side:"right",sideOffset:20,children:[c.jsx(MNe,{className:"fill-border",width:12,height:8}),c.jsxs("div",{className:"flex flex-col border-b px-6 py-4",children:[c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsx("h2",{className:"text-lg font-semibold",children:"Configure Interactions"}),M.length>0&&c.jsx(Fe,{variant:"default",className:"h-5 min-w-5 rounded-full px-1.5 text-xs",children:M.length})]}),c.jsxs("p",{className:"text-sm text-muted-foreground",children:["Set up drill behaviors for"," ",(f==null?void 0:f.title)||(o==null?void 0:o.title)||"this chart"]})]}),c.jsx("div",{className:"min-h-0 flex-1 overflow-y-auto",children:c.jsx("div",{className:"space-y-6 p-6",children:c.jsx("div",{children:c.jsx("div",{className:"grid grid-cols-1 gap-4",children:c.jsx(Zze,{interactions:M,metrics:x,attributes:y,availableFields:b,card:{...o,interactionConfig:{...o.interactionConfig,drillHierarchies:N}},onUpdateHierarchies:S,onChange:D})})})})}),c.jsxs("div",{className:"flex justify-end gap-2 border-t px-6 py-4",children:[c.jsx(se,{variant:"outline",onClick:P,children:"Cancel"}),c.jsx(se,{onClick:R,children:"Save Changes"})]})]})]})}function Qze(e){return Tr(e.dataType)==="date"?220:e.uiType==="tabs"?200:e.uiType==="radio"?180:160}const Jze=100,e8e=400;function t8e({filter:e,isEditing:t=!1,dragListeners:n}){const{removeFilterValues:r,updateFilter:s,removeFilter:o}=Ot(),i=e.showLabel??!0,a=e.toolbarWidth??Qze(e),[l,u]=C.useState(!1),[d,f]=C.useState(a),h=C.useRef(null),m=C.useRef(d);C.useEffect(()=>{m.current=d},[d]),C.useEffect(()=>{l||f(a)},[a,l]);const p=C.useCallback(g=>{g.preventDefault(),g.stopPropagation();const b=g.clientX,x=m.current,y=w=>{const N=w.clientX-b,S=Math.max(Jze,Math.min(e8e,x+N));f(S),m.current=S},v=()=>{document.removeEventListener("mousemove",y),document.removeEventListener("mouseup",v),u(!1);const w=m.current;w!==a&&s({...e,toolbarWidth:w})};u(!0),document.addEventListener("mousemove",y),document.addEventListener("mouseup",v)},[a,e,s]);return c.jsxs("div",{ref:h,style:{width:d},className:Z("group relative flex shrink-0 flex-col gap-1 rounded-md p-2",l&&"select-none"),children:[(t||i)&&c.jsxs("div",{className:"flex items-center justify-between gap-1",children:[c.jsxs("div",{className:Z("flex min-w-0 flex-1 items-center gap-1",t&&n&&"cursor-grab active:cursor-grabbing"),...t?n:{},children:[t&&c.jsx(PD,{className:"size-3 shrink-0 text-muted-foreground/50"}),i&&c.jsx(ce,{className:"truncate text-xs font-medium text-muted-foreground",children:e.title||e.column})]}),c.jsxs("div",{className:"flex shrink-0 items-center gap-1",children:[t&&c.jsx(NI,{filter:e,isEditing:t,trigger:c.jsx("button",{className:"text-muted-foreground hover:text-foreground","aria-label":"Filter settings",children:c.jsx(Nl,{className:"size-3"})})}),t&&c.jsx("button",{onClick:()=>{r(e.id),o(e.id)},className:"text-muted-foreground hover:text-foreground","aria-label":"Remove filter",children:c.jsx(yt,{className:"size-3"})})]})]}),c.jsx("div",{className:"min-h-[32px]",children:c.jsx(rp,{filter:e})}),t&&c.jsx("div",{onMouseDown:p,className:Z("absolute bottom-0 right-0 top-0 w-2 cursor-ew-resize","hover:bg-muted-foreground/20",l&&"bg-primary/20"),"aria-label":"Resize filter"})]})}function n8e({filter:e,isEditing:t=!1,disabled:n=!1}){const{attributes:r,listeners:s,setNodeRef:o,transform:i,transition:a,isDragging:l}=oy({id:e.id,disabled:n||!t}),u={transform:ii.Translate.toString(i),transition:a,opacity:l?.5:1,zIndex:l?10:void 0};return c.jsx("div",{ref:o,style:u,...r,children:c.jsx(t8e,{filter:e,isEditing:t,dragListeners:t?s:void 0})})}function zX({open:e,onOpenChange:t}){const[n,r]=C.useState(!1),[s,o]=C.useState(!1),[i,a]=C.useState({sheetSelection:"current",protectPdf:!1,password:""}),l=X(b=>{var x;return(x=b.dashboard)==null?void 0:x.sheets}),u=X(b=>b.selectedSheetId),{authToken:d,tokenProps:f}=Ge(),h=l==null?void 0:l.find(b=>b.id===u),m=((l==null?void 0:l.length)||0)>1,p=()=>{a({sheetSelection:"current",protectPdf:!1,password:""}),r(!1),t(!1)};async function g(){if(i.protectPdf&&!i.password){Oe.error("Please enter a password to protect the PDF");return}o(!0);const b=i.sheetSelection==="all"?"Generating PDF for all sheets... This may take a while.":i.protectPdf?"Generating protected PDF... may take up to 60 seconds":"Generating PDF... may take up to 60 seconds",x=Oe.loading(b);try{const y=VY();await kY(f.apiServiceUrl,d,i.protectPdf?i.password:void 0,i.sheetSelection,y),Oe.dismiss(x);const v=i.sheetSelection==="all"?"All sheets PDF downloaded successfully!":i.protectPdf?"Protected PDF downloaded successfully!":"PDF downloaded successfully!";Oe.success(v,{duration:2e3}),p()}catch(y){Oe.dismiss(x),Oe.error("Failed to download PDF",{description:"Please try again or contact support.",richColors:!0}),console.error("PDF download error:",y)}finally{o(!1)}}return c.jsx(ns,{open:e,onOpenChange:b=>{if(!b){p();return}t(!0)},children:c.jsxs(Vr,{className:"sm:max-w-[425px]",children:[c.jsxs(Hr,{children:[c.jsx(Ur,{children:"Export Dashboard"}),c.jsx(ys,{children:"Export your dashboard as a PDF document."})]}),c.jsxs("div",{className:"space-y-4 py-4",children:[m&&c.jsxs(c.Fragment,{children:[c.jsxs("div",{className:"space-y-3",children:[c.jsx(ce,{children:"Export Scope"}),c.jsxs(jo,{value:i.sheetSelection,onValueChange:b=>a({...i,sheetSelection:b}),children:[c.jsxs("div",{className:"flex items-center space-x-2",children:[c.jsx(In,{value:"current",id:"scope-current"}),c.jsxs(ce,{htmlFor:"scope-current",className:"cursor-pointer font-normal",children:["This sheet (",(h==null?void 0:h.title)||"Current",")"]})]}),c.jsxs("div",{className:"flex items-center space-x-2",children:[c.jsx(In,{value:"all",id:"scope-all"}),c.jsxs(ce,{htmlFor:"scope-all",className:"cursor-pointer font-normal",children:["All sheets (",l==null?void 0:l.length," sheets)"]})]})]})]}),c.jsx(As,{})]}),c.jsxs("div",{className:"space-y-3",children:[c.jsxs("div",{className:"flex items-center space-x-2",children:[c.jsx(Qt,{id:"protect-pdf",checked:i.protectPdf,onCheckedChange:b=>{a({...i,protectPdf:b,password:b?i.password:""}),b||r(!1)}}),c.jsxs(ce,{htmlFor:"protect-pdf",className:"flex cursor-pointer items-center text-sm font-normal",children:[c.jsx(C8,{className:"mr-2 h-3.5 w-3.5"}),"Password protect PDF"]})]}),i.protectPdf&&c.jsxs("div",{className:"ml-6 space-y-2",children:[c.jsx(ce,{htmlFor:"pdf-password",className:"text-sm",children:"Password"}),c.jsxs("div",{className:"relative",children:[c.jsx(Nn,{id:"pdf-password",type:n?"text":"password",value:i.password,onChange:b=>a({...i,password:b.target.value}),placeholder:"Enter password",className:"pr-10",onKeyDown:b=>{b.key==="Enter"&&i.password&&g()}}),c.jsx(se,{type:"button",variant:"ghost",size:"sm",className:"absolute right-0 top-0 h-full px-3 py-2 hover:bg-transparent",onClick:()=>r(!n),children:n?c.jsx(k1,{className:"h-4 w-4 text-muted-foreground"}):c.jsx($c,{className:"h-4 w-4 text-muted-foreground"})})]}),c.jsx("p",{className:"text-xs text-muted-foreground",children:"Recipients will need this password to open the PDF"})]})]})]}),c.jsxs(xs,{children:[c.jsx(se,{variant:"outline",onClick:p,disabled:s,children:"Cancel"}),c.jsx(se,{onClick:g,disabled:s,children:s?c.jsxs(c.Fragment,{children:[c.jsx(an,{className:"mr-2 h-4 w-4 animate-spin"}),"Exporting..."]}):c.jsxs(c.Fragment,{children:[c.jsx(am,{className:"mr-2 h-4 w-4"}),"Export"]})})]})]})})}function BX({iconClassName:e}){const[t,n]=C.useState(!1),r=X(s=>s.isDownloadingPdf);return c.jsxs(c.Fragment,{children:[c.jsx(se,{variant:"ghost",size:"sm",className:"h-7 p-2",disabled:r,onClick:()=>n(!0),children:c.jsx(am,{className:Z("size-4",e)})}),c.jsx(zX,{open:t,onOpenChange:n})]})}function r8e(e,t){return e.displayMode&&e.displayMode!=="inherit"?e.displayMode:(t==null?void 0:t.displayMode)||"canvas"}function s8e(){var f;const e=X(h=>h.selectedSheetId),t=X(h=>h.dashboard.filters),n=X(h=>h.dashboard.filterLayout),r=X(h=>h.isDashboardEditing),{reorderFilters:s}=Ot(),o=lC(tm(ap,{activationConstraint:{distance:5}})),i=(f=Bl(t,e))==null?void 0:f.filter(h=>!h.hide&&h.location!=="frame"),a=i==null?void 0:i.filter(h=>r8e(h,n)==="toolbar");function l(h){const{active:m,over:p}=h;if(!p||m.id===p.id||!t)return;const g=t.findIndex(x=>x.id===m.id),b=t.findIndex(x=>x.id===p.id);if(g!==-1&&b!==-1){const x=lp(t.map(y=>y.id),g,b);s(x)}}if(!(a!=null&&a.length))return null;const u=(n==null?void 0:n.toolbarWrap)??!1,d=(n==null?void 0:n.showDownloadButton)??!1;return c.jsx(ry,{sensors:o,collisionDetection:ey,onDragEnd:l,children:c.jsx(sy,{items:a.map(h=>h.id),strategy:TI,children:c.jsxs("div",{className:Z("flex items-center gap-2 border-b bg-background px-3 py-2",u?"flex-wrap":"overflow-x-auto"),role:"toolbar","aria-label":"Dashboard filters",children:[a.map(h=>c.jsx(n8e,{filter:h,isEditing:r},h.id)),d&&c.jsx("div",{className:"ml-auto",children:c.jsx(BX,{})})]})})})}const o8e=w4.WidthProvider(w4.Responsive);function i8e(e,t){return e.displayMode&&e.displayMode!=="inherit"?e.displayMode:(t==null?void 0:t.displayMode)||"canvas"}function a8e(){const{open:e}=fR();return e?c.jsx(Xze,{}):null}function l8e({sheet:e}){var v,w;const t=X(N=>N.isDashboardEditing),n=X(N=>N.currentBreakpoint),r=X(N=>N.themeStyle),s=C.useRef(0),o=X(N=>N.selectedSheetId),i=e.layouts,a=X(N=>N.dashboard.filters),l=X(N=>N.dashboard.filterLayout),u=e.frames,{setSheetLayouts:d,setCurrentBreakpoint:f}=X(N=>N.actions);C.useEffect(()=>{document.documentElement.style.setProperty("--placeholder-border-radius",`${r==null?void 0:r.cardBorderRadius}px`)},[r==null?void 0:r.cardBorderRadius]);function h(N){f(N)}function m(N,S){o===e.id&&d(o,S)}if(!o)return null;const p=(N,S)=>c.jsx(VX,{className:"after:content-none",ref:S,handleAxis:N}),g=N=>N&&(N==null?void 0:N.h)===1&&(N==null?void 0:N.w)===1?{...N,h:8,minH:7,w:7}:null;function b(){var j;const N=(j=Bl(a,o))==null?void 0:j.filter(E=>!E.hide),S=N==null?void 0:N.filter(E=>i8e(E,l)==="canvas");return S==null?void 0:S.map(E=>{var M;const _=(M=i==null?void 0:i[n])==null?void 0:M.find(D=>D.i===E.id);if(E.location==="frame")return null;const k=g(_);return c.jsxs("div",{style:{borderRadius:r==null?void 0:r.cardBorderRadius},className:Z("z-50 flex flex-col rounded-md border bg-background px-3 py-2"),...k?{"data-grid":k}:{},children:[c.jsx(jI,{filter:E}),c.jsx(rp,{filter:E})]},E.id)})}function x(){return u==null?void 0:u.map(N=>c.jsx("div",{role:"dashboard-frame-container",className:Z("group isolate overflow-hidden",r==null?void 0:r.dashboardCardContainer),children:c.jsx(Ua,{FallbackComponent:({error:S,resetErrorBoundary:j})=>c.jsx(C3e,{error:S,resetErrorBoundary:j,frame:N}),children:c.jsx(fLe,{frame:N})})},N.id))}const y=((v=r==null?void 0:r.gridLayout)==null?void 0:v.margin)||[10,10];return!u||u.length===0?c.jsx(ELe,{sheetId:e.id}):c.jsxs(e_e,{children:[c.jsx(s8e,{}),c.jsxs(o8e,{margin:y,isDraggable:t,resizeHandles:t?["s","w","e","n","sw","nw","se","ne"]:[],className:Z((w=r==null?void 0:r.gridLayout)==null?void 0:w.className),layouts:i,cols:{lg:48,md:36,sm:24,xs:12,xxs:6},rowHeight:1,onBreakpointChange:h,onLayoutChange:m,onResize:(N,S,j,E,_,k)=>{const M=Date.now();M-s.current>100&&(k.scrollIntoView({behavior:"auto",block:"nearest"}),s.current=M)},onResizeStop:(N,S,j,E,_,k)=>{k.scrollIntoView({behavior:"smooth",block:"nearest"})},resizeHandle:p,children:[b(),x()]}),c.jsx(a8e,{})]})}const VX=C.forwardRef(({className:e,handleAxis:t,...n},r)=>{const s=X(o=>o.themeStyle);return s!=null&&s.cardBorderRadius,c.jsx("div",{ref:r,className:Z(`react-resizable-handle z-20 react-resizable-handle-${t} absolute border-foreground/40`,{"z-30 h-4 w-4":["sw","nw","se","ne"].includes(t),"bottom-0 left-0 cursor-sw-resize":t==="sw","left-0 top-0 cursor-nw-resize":t==="nw","bottom-0 right-0 cursor-se-resize":t==="se","right-0 top-0 cursor-ne-resize":t==="ne","!bottom-0 !left-0 !right-0 !h-2 !w-full cursor-ns-resize":t==="s","!left-0 !right-0 !top-0 !h-2 !w-full cursor-ns-resize":t==="n","!bottom-0 !right-0 !top-0 !h-full !w-2 cursor-ew-resize":t==="e","!bottom-0 !left-0 !top-0 !h-full !w-2 cursor-ew-resize":t==="w"},e),...n})});VX.displayName="ResizeHandle";const hC=C.createContext(null);hC.displayName="PanelGroupContext";const rr={group:"data-panel-group",groupDirection:"data-panel-group-direction",groupId:"data-panel-group-id",panel:"data-panel",panelCollapsible:"data-panel-collapsible",panelId:"data-panel-id",panelSize:"data-panel-size",resizeHandle:"data-resize-handle",resizeHandleActive:"data-resize-handle-active",resizeHandleEnabled:"data-panel-resize-handle-enabled",resizeHandleId:"data-panel-resize-handle-id",resizeHandleState:"data-resize-handle-state"},PI=10,Nd=C.useLayoutEffect,T$=T.useId,c8e=typeof T$=="function"?T$:()=>null;let u8e=0;function OI(e=null){const t=c8e(),n=C.useRef(e||t||null);return n.current===null&&(n.current=""+u8e++),e??n.current}function HX({children:e,className:t="",collapsedSize:n,collapsible:r,defaultSize:s,forwardedRef:o,id:i,maxSize:a,minSize:l,onCollapse:u,onExpand:d,onResize:f,order:h,style:m,tagName:p="div",...g}){const b=C.useContext(hC);if(b===null)throw Error("Panel components must be rendered within a PanelGroup container");const{collapsePanel:x,expandPanel:y,getPanelSize:v,getPanelStyle:w,groupId:N,isPanelCollapsed:S,reevaluatePanelConstraints:j,registerPanel:E,resizePanel:_,unregisterPanel:k}=b,M=OI(i),D=C.useRef({callbacks:{onCollapse:u,onExpand:d,onResize:f},constraints:{collapsedSize:n,collapsible:r,defaultSize:s,maxSize:a,minSize:l},id:M,idIsFromProps:i!==void 0,order:h});C.useRef({didLogMissingDefaultSizeWarning:!1}),Nd(()=>{const{callbacks:P,constraints:I}=D.current,L={...I};D.current.id=M,D.current.idIsFromProps=i!==void 0,D.current.order=h,P.onCollapse=u,P.onExpand=d,P.onResize=f,I.collapsedSize=n,I.collapsible=r,I.defaultSize=s,I.maxSize=a,I.minSize=l,(L.collapsedSize!==I.collapsedSize||L.collapsible!==I.collapsible||L.maxSize!==I.maxSize||L.minSize!==I.minSize)&&j(D.current,L)}),Nd(()=>{const P=D.current;return E(P),()=>{k(P)}},[h,M,E,k]),C.useImperativeHandle(o,()=>({collapse:()=>{x(D.current)},expand:P=>{y(D.current,P)},getId(){return M},getSize(){return v(D.current)},isCollapsed(){return S(D.current)},isExpanded(){return!S(D.current)},resize:P=>{_(D.current,P)}}),[x,y,v,S,M,_]);const R=w(D.current,s);return C.createElement(p,{...g,children:e,className:t,id:M,style:{...R,...m},[rr.groupId]:N,[rr.panel]:"",[rr.panelCollapsible]:r||void 0,[rr.panelId]:M,[rr.panelSize]:parseFloat(""+R.flexGrow).toFixed(1)})}const UX=C.forwardRef((e,t)=>C.createElement(HX,{...e,forwardedRef:t}));HX.displayName="Panel";UX.displayName="forwardRef(Panel)";let b_=null,gv=-1,ac=null;function d8e(e,t){if(t){const n=(t&KX)!==0,r=(t&ZX)!==0,s=(t&XX)!==0,o=(t&QX)!==0;if(n)return s?"se-resize":o?"ne-resize":"e-resize";if(r)return s?"sw-resize":o?"nw-resize":"w-resize";if(s)return"s-resize";if(o)return"n-resize"}switch(e){case"horizontal":return"ew-resize";case"intersection":return"move";case"vertical":return"ns-resize"}}function f8e(){ac!==null&&(document.head.removeChild(ac),b_=null,ac=null,gv=-1)}function a2(e,t){var n,r;const s=d8e(e,t);if(b_!==s){if(b_=s,ac===null&&(ac=document.createElement("style"),document.head.appendChild(ac)),gv>=0){var o;(o=ac.sheet)===null||o===void 0||o.removeRule(gv)}gv=(n=(r=ac.sheet)===null||r===void 0?void 0:r.insertRule(`*{cursor: ${s} !important;}`))!==null&&n!==void 0?n:-1}}function WX(e){return e.type==="keydown"}function qX(e){return e.type.startsWith("pointer")}function YX(e){return e.type.startsWith("mouse")}function mC(e){if(qX(e)){if(e.isPrimary)return{x:e.clientX,y:e.clientY}}else if(YX(e))return{x:e.clientX,y:e.clientY};return{x:1/0,y:1/0}}function h8e(){if(typeof matchMedia=="function")return matchMedia("(pointer:coarse)").matches?"coarse":"fine"}function m8e(e,t,n){return e.x<t.x+t.width&&e.x+e.width>t.x&&e.y<t.y+t.height&&e.y+e.height>t.y}function p8e(e,t){if(e===t)throw new Error("Cannot compare node with itself");const n={a:A$(e),b:A$(t)};let r;for(;n.a.at(-1)===n.b.at(-1);)e=n.a.pop(),t=n.b.pop(),r=e;Mt(r,"Stacking order can only be calculated for elements with a common ancestor");const s={a:I$(R$(n.a)),b:I$(R$(n.b))};if(s.a===s.b){const o=r.childNodes,i={a:n.a.at(-1),b:n.b.at(-1)};let a=o.length;for(;a--;){const l=o[a];if(l===i.a)return 1;if(l===i.b)return-1}}return Math.sign(s.a-s.b)}const g8e=/\b(?:position|zIndex|opacity|transform|webkitTransform|mixBlendMode|filter|webkitFilter|isolation)\b/;function b8e(e){var t;const n=getComputedStyle((t=GX(e))!==null&&t!==void 0?t:e).display;return n==="flex"||n==="inline-flex"}function x8e(e){const t=getComputedStyle(e);return!!(t.position==="fixed"||t.zIndex!=="auto"&&(t.position!=="static"||b8e(e))||+t.opacity<1||"transform"in t&&t.transform!=="none"||"webkitTransform"in t&&t.webkitTransform!=="none"||"mixBlendMode"in t&&t.mixBlendMode!=="normal"||"filter"in t&&t.filter!=="none"||"webkitFilter"in t&&t.webkitFilter!=="none"||"isolation"in t&&t.isolation==="isolate"||g8e.test(t.willChange)||t.webkitOverflowScrolling==="touch")}function R$(e){let t=e.length;for(;t--;){const n=e[t];if(Mt(n,"Missing node"),x8e(n))return n}return null}function I$(e){return e&&Number(getComputedStyle(e).zIndex)||0}function A$(e){const t=[];for(;e;)t.push(e),e=GX(e);return t}function GX(e){const{parentNode:t}=e;return t&&t instanceof ShadowRoot?t.host:t}const KX=1,ZX=2,XX=4,QX=8,y8e=h8e()==="coarse";let Mi=[],dh=!1,Hu=new Map,pC=new Map;const Tb=new Set;function v8e(e,t,n,r,s){var o;const{ownerDocument:i}=t,a={direction:n,element:t,hitAreaMargins:r,setResizeHandlerState:s},l=(o=Hu.get(i))!==null&&o!==void 0?o:0;return Hu.set(i,l+1),Tb.add(a),Gw(),function(){var d;pC.delete(e),Tb.delete(a);const f=(d=Hu.get(i))!==null&&d!==void 0?d:1;if(Hu.set(i,f-1),Gw(),f===1&&Hu.delete(i),Mi.includes(a)){const h=Mi.indexOf(a);h>=0&&Mi.splice(h,1),$I(),s("up",!0,null)}}}function w8e(e){const{target:t}=e,{x:n,y:r}=mC(e);dh=!0,FI({target:t,x:n,y:r}),Gw(),Mi.length>0&&(Kw("down",e),e.preventDefault(),JX(t)||e.stopImmediatePropagation())}function l2(e){const{x:t,y:n}=mC(e);if(dh&&e.buttons===0&&(dh=!1,Kw("up",e)),!dh){const{target:r}=e;FI({target:r,x:t,y:n})}Kw("move",e),$I(),Mi.length>0&&e.preventDefault()}function c2(e){const{target:t}=e,{x:n,y:r}=mC(e);pC.clear(),dh=!1,Mi.length>0&&(e.preventDefault(),JX(t)||e.stopImmediatePropagation()),Kw("up",e),FI({target:t,x:n,y:r}),$I(),Gw()}function JX(e){let t=e;for(;t;){if(t.hasAttribute(rr.resizeHandle))return!0;t=t.parentElement}return!1}function FI({target:e,x:t,y:n}){Mi.splice(0);let r=null;(e instanceof HTMLElement||e instanceof SVGElement)&&(r=e),Tb.forEach(s=>{const{element:o,hitAreaMargins:i}=s,a=o.getBoundingClientRect(),{bottom:l,left:u,right:d,top:f}=a,h=y8e?i.coarse:i.fine;if(t>=u-h&&t<=d+h&&n>=f-h&&n<=l+h){if(r!==null&&document.contains(r)&&o!==r&&!o.contains(r)&&!r.contains(o)&&p8e(r,o)>0){let p=r,g=!1;for(;p&&!p.contains(o);){if(m8e(p.getBoundingClientRect(),a)){g=!0;break}p=p.parentElement}if(g)return}Mi.push(s)}})}function u2(e,t){pC.set(e,t)}function $I(){let e=!1,t=!1;Mi.forEach(r=>{const{direction:s}=r;s==="horizontal"?e=!0:t=!0});let n=0;pC.forEach(r=>{n|=r}),e&&t?a2("intersection",n):e?a2("horizontal",n):t?a2("vertical",n):f8e()}let d2=new AbortController;function Gw(){d2.abort(),d2=new AbortController;const e={capture:!0,signal:d2.signal};Tb.size&&(dh?(Mi.length>0&&Hu.forEach((t,n)=>{const{body:r}=n;t>0&&(r.addEventListener("contextmenu",c2,e),r.addEventListener("pointerleave",l2,e),r.addEventListener("pointermove",l2,e))}),window.addEventListener("pointerup",c2,e),window.addEventListener("pointercancel",c2,e)):Hu.forEach((t,n)=>{const{body:r}=n;t>0&&(r.addEventListener("pointerdown",w8e,e),r.addEventListener("pointermove",l2,e))}))}function Kw(e,t){Tb.forEach(n=>{const{setResizeHandlerState:r}=n,s=Mi.includes(n);r(e,s,t)})}function S8e(){const[e,t]=C.useState(0);return C.useCallback(()=>t(n=>n+1),[])}function Mt(e,t){if(!e)throw console.error(t),Error(t)}function Gd(e,t,n=PI){return e.toFixed(n)===t.toFixed(n)?0:e>t?1:-1}function cl(e,t,n=PI){return Gd(e,t,n)===0}function yo(e,t,n){return Gd(e,t,n)===0}function C8e(e,t,n){if(e.length!==t.length)return!1;for(let r=0;r<e.length;r++){const s=e[r],o=t[r];if(!yo(s,o,n))return!1}return!0}function Zf({panelConstraints:e,panelIndex:t,size:n}){const r=e[t];Mt(r!=null,`Panel constraints not found for index ${t}`);let{collapsedSize:s=0,collapsible:o,maxSize:i=100,minSize:a=0}=r;if(Gd(n,a)<0)if(o){const l=(s+a)/2;Gd(n,l)<0?n=s:n=a}else n=a;return n=Math.min(i,n),n=parseFloat(n.toFixed(PI)),n}function og({delta:e,initialLayout:t,panelConstraints:n,pivotIndices:r,prevLayout:s,trigger:o}){if(yo(e,0))return t;const i=[...t],[a,l]=r;Mt(a!=null,"Invalid first pivot index"),Mt(l!=null,"Invalid second pivot index");let u=0;if(o==="keyboard"){{const f=e<0?l:a,h=n[f];Mt(h,`Panel constraints not found for index ${f}`);const{collapsedSize:m=0,collapsible:p,minSize:g=0}=h;if(p){const b=t[f];if(Mt(b!=null,`Previous layout not found for panel index ${f}`),yo(b,m)){const x=g-b;Gd(x,Math.abs(e))>0&&(e=e<0?0-x:x)}}}{const f=e<0?a:l,h=n[f];Mt(h,`No panel constraints found for index ${f}`);const{collapsedSize:m=0,collapsible:p,minSize:g=0}=h;if(p){const b=t[f];if(Mt(b!=null,`Previous layout not found for panel index ${f}`),yo(b,g)){const x=b-m;Gd(x,Math.abs(e))>0&&(e=e<0?0-x:x)}}}}{const f=e<0?1:-1;let h=e<0?l:a,m=0;for(;;){const g=t[h];Mt(g!=null,`Previous layout not found for panel index ${h}`);const x=Zf({panelConstraints:n,panelIndex:h,size:100})-g;if(m+=x,h+=f,h<0||h>=n.length)break}const p=Math.min(Math.abs(e),Math.abs(m));e=e<0?0-p:p}{let h=e<0?a:l;for(;h>=0&&h<n.length;){const m=Math.abs(e)-Math.abs(u),p=t[h];Mt(p!=null,`Previous layout not found for panel index ${h}`);const g=p-m,b=Zf({panelConstraints:n,panelIndex:h,size:g});if(!yo(p,b)&&(u+=p-b,i[h]=b,u.toPrecision(3).localeCompare(Math.abs(e).toPrecision(3),void 0,{numeric:!0})>=0))break;e<0?h--:h++}}if(C8e(s,i))return s;{const f=e<0?l:a,h=t[f];Mt(h!=null,`Previous layout not found for panel index ${f}`);const m=h+u,p=Zf({panelConstraints:n,panelIndex:f,size:m});if(i[f]=p,!yo(p,m)){let g=m-p,x=e<0?l:a;for(;x>=0&&x<n.length;){const y=i[x];Mt(y!=null,`Previous layout not found for panel index ${x}`);const v=y+g,w=Zf({panelConstraints:n,panelIndex:x,size:v});if(yo(y,w)||(g-=w-y,i[x]=w),yo(g,0))break;e>0?x--:x++}}}const d=i.reduce((f,h)=>h+f,0);return yo(d,100)?i:s}function N8e({layout:e,panelsArray:t,pivotIndices:n}){let r=0,s=100,o=0,i=0;const a=n[0];Mt(a!=null,"No pivot index found"),t.forEach((f,h)=>{const{constraints:m}=f,{maxSize:p=100,minSize:g=0}=m;h===a?(r=g,s=p):(o+=g,i+=p)});const l=Math.min(s,100-o),u=Math.max(r,100-i),d=e[a];return{valueMax:l,valueMin:u,valueNow:d}}function Rb(e,t=document){return Array.from(t.querySelectorAll(`[${rr.resizeHandleId}][data-panel-group-id="${e}"]`))}function eQ(e,t,n=document){const s=Rb(e,n).findIndex(o=>o.getAttribute(rr.resizeHandleId)===t);return s??null}function tQ(e,t,n){const r=eQ(e,t,n);return r!=null?[r,r+1]:[-1,-1]}function nQ(e,t=document){var n;if(t instanceof HTMLElement&&(t==null||(n=t.dataset)===null||n===void 0?void 0:n.panelGroupId)==e)return t;const r=t.querySelector(`[data-panel-group][data-panel-group-id="${e}"]`);return r||null}function gC(e,t=document){const n=t.querySelector(`[${rr.resizeHandleId}="${e}"]`);return n||null}function j8e(e,t,n,r=document){var s,o,i,a;const l=gC(t,r),u=Rb(e,r),d=l?u.indexOf(l):-1,f=(s=(o=n[d])===null||o===void 0?void 0:o.id)!==null&&s!==void 0?s:null,h=(i=(a=n[d+1])===null||a===void 0?void 0:a.id)!==null&&i!==void 0?i:null;return[f,h]}function k8e({committedValuesRef:e,eagerValuesRef:t,groupId:n,layout:r,panelDataArray:s,panelGroupElement:o,setLayout:i}){C.useRef({didWarnAboutMissingResizeHandle:!1}),Nd(()=>{if(!o)return;const a=Rb(n,o);for(let l=0;l<s.length-1;l++){const{valueMax:u,valueMin:d,valueNow:f}=N8e({layout:r,panelsArray:s,pivotIndices:[l,l+1]}),h=a[l];if(h!=null){const m=s[l];Mt(m,`No panel data found for index "${l}"`),h.setAttribute("aria-controls",m.id),h.setAttribute("aria-valuemax",""+Math.round(u)),h.setAttribute("aria-valuemin",""+Math.round(d)),h.setAttribute("aria-valuenow",f!=null?""+Math.round(f):"")}}return()=>{a.forEach((l,u)=>{l.removeAttribute("aria-controls"),l.removeAttribute("aria-valuemax"),l.removeAttribute("aria-valuemin"),l.removeAttribute("aria-valuenow")})}},[n,r,s,o]),C.useEffect(()=>{if(!o)return;const a=t.current;Mt(a,"Eager values not found");const{panelDataArray:l}=a,u=nQ(n,o);Mt(u!=null,`No group found for id "${n}"`);const d=Rb(n,o);Mt(d,`No resize handles found for group id "${n}"`);const f=d.map(h=>{const m=h.getAttribute(rr.resizeHandleId);Mt(m,"Resize handle element has no handle id attribute");const[p,g]=j8e(n,m,l,o);if(p==null||g==null)return()=>{};const b=x=>{if(!x.defaultPrevented)switch(x.key){case"Enter":{x.preventDefault();const y=l.findIndex(v=>v.id===p);if(y>=0){const v=l[y];Mt(v,`No panel data found for index ${y}`);const w=r[y],{collapsedSize:N=0,collapsible:S,minSize:j=0}=v.constraints;if(w!=null&&S){const E=og({delta:yo(w,N)?j-N:N-w,initialLayout:r,panelConstraints:l.map(_=>_.constraints),pivotIndices:tQ(n,m,o),prevLayout:r,trigger:"keyboard"});r!==E&&i(E)}}break}}};return h.addEventListener("keydown",b),()=>{h.removeEventListener("keydown",b)}});return()=>{f.forEach(h=>h())}},[o,e,t,n,r,s,i])}function P$(e,t){if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(e[n]!==t[n])return!1;return!0}function rQ(e,t){const n=e==="horizontal",{x:r,y:s}=mC(t);return n?r:s}function E8e(e,t,n,r,s){const o=n==="horizontal",i=gC(t,s);Mt(i,`No resize handle element found for id "${t}"`);const a=i.getAttribute(rr.groupId);Mt(a,"Resize handle element has no group id attribute");let{initialCursorPosition:l}=r;const u=rQ(n,e),d=nQ(a,s);Mt(d,`No group element found for id "${a}"`);const f=d.getBoundingClientRect(),h=o?f.width:f.height;return(u-l)/h*100}function _8e(e,t,n,r,s,o){if(WX(e)){const i=n==="horizontal";let a=0;e.shiftKey?a=100:s!=null?a=s:a=10;let l=0;switch(e.key){case"ArrowDown":l=i?0:a;break;case"ArrowLeft":l=i?-a:0;break;case"ArrowRight":l=i?a:0;break;case"ArrowUp":l=i?0:-a;break;case"End":l=100;break;case"Home":l=-100;break}return l}else return r==null?0:E8e(e,t,n,r,o)}function D8e({panelDataArray:e}){const t=Array(e.length),n=e.map(o=>o.constraints);let r=0,s=100;for(let o=0;o<e.length;o++){const i=n[o];Mt(i,`Panel constraints not found for index ${o}`);const{defaultSize:a}=i;a!=null&&(r++,t[o]=a,s-=a)}for(let o=0;o<e.length;o++){const i=n[o];Mt(i,`Panel constraints not found for index ${o}`);const{defaultSize:a}=i;if(a!=null)continue;const l=e.length-r,u=s/l;r++,t[o]=u,s-=u}return t}function Tf(e,t,n){t.forEach((r,s)=>{const o=e[s];Mt(o,`Panel data not found for index ${s}`);const{callbacks:i,constraints:a,id:l}=o,{collapsedSize:u=0,collapsible:d}=a,f=n[l];if(f==null||r!==f){n[l]=r;const{onCollapse:h,onExpand:m,onResize:p}=i;p&&p(r,f),d&&(h||m)&&(m&&(f==null||cl(f,u))&&!cl(r,u)&&m(),h&&(f==null||!cl(f,u))&&cl(r,u)&&h())}})}function O0(e,t){if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(e[n]!=t[n])return!1;return!0}function M8e({defaultSize:e,dragState:t,layout:n,panelData:r,panelIndex:s,precision:o=3}){const i=n[s];let a;return i==null?a=e!=null?e.toPrecision(o):"1":r.length===1?a="1":a=i.toPrecision(o),{flexBasis:0,flexGrow:a,flexShrink:1,overflow:"hidden",pointerEvents:t!==null?"none":void 0}}function T8e(e,t=10){let n=null;return(...s)=>{n!==null&&clearTimeout(n),n=setTimeout(()=>{e(...s)},t)}}function O$(e){try{if(typeof localStorage<"u")e.getItem=t=>localStorage.getItem(t),e.setItem=(t,n)=>{localStorage.setItem(t,n)};else throw new Error("localStorage not supported in this environment")}catch(t){console.error(t),e.getItem=()=>null,e.setItem=()=>{}}}function sQ(e){return`react-resizable-panels:${e}`}function oQ(e){return e.map(t=>{const{constraints:n,id:r,idIsFromProps:s,order:o}=t;return s?r:o?`${o}:${JSON.stringify(n)}`:JSON.stringify(n)}).sort((t,n)=>t.localeCompare(n)).join(",")}function iQ(e,t){try{const n=sQ(e),r=t.getItem(n);if(r){const s=JSON.parse(r);if(typeof s=="object"&&s!=null)return s}}catch{}return null}function R8e(e,t,n){var r,s;const o=(r=iQ(e,n))!==null&&r!==void 0?r:{},i=oQ(t);return(s=o[i])!==null&&s!==void 0?s:null}function I8e(e,t,n,r,s){var o;const i=sQ(e),a=oQ(t),l=(o=iQ(e,s))!==null&&o!==void 0?o:{};l[a]={expandToSizes:Object.fromEntries(n.entries()),layout:r};try{s.setItem(i,JSON.stringify(l))}catch(u){console.error(u)}}function F$({layout:e,panelConstraints:t}){const n=[...e],r=n.reduce((o,i)=>o+i,0);if(n.length!==t.length)throw Error(`Invalid ${t.length} panel layout: ${n.map(o=>`${o}%`).join(", ")}`);if(!yo(r,100)&&n.length>0)for(let o=0;o<t.length;o++){const i=n[o];Mt(i!=null,`No layout data found for index ${o}`);const a=100/r*i;n[o]=a}let s=0;for(let o=0;o<t.length;o++){const i=n[o];Mt(i!=null,`No layout data found for index ${o}`);const a=Zf({panelConstraints:t,panelIndex:o,size:i});i!=a&&(s+=i-a,n[o]=a)}if(!yo(s,0))for(let o=0;o<t.length;o++){const i=n[o];Mt(i!=null,`No layout data found for index ${o}`);const a=i+s,l=Zf({panelConstraints:t,panelIndex:o,size:a});if(i!==l&&(s-=l-i,n[o]=l,yo(s,0)))break}return n}const A8e=100,ig={getItem:e=>(O$(ig),ig.getItem(e)),setItem:(e,t)=>{O$(ig),ig.setItem(e,t)}},$$={};function aQ({autoSaveId:e=null,children:t,className:n="",direction:r,forwardedRef:s,id:o=null,onLayout:i=null,keyboardResizeBy:a=null,storage:l=ig,style:u,tagName:d="div",...f}){const h=OI(o),m=C.useRef(null),[p,g]=C.useState(null),[b,x]=C.useState([]),y=S8e(),v=C.useRef({}),w=C.useRef(new Map),N=C.useRef(0),S=C.useRef({autoSaveId:e,direction:r,dragState:p,id:h,keyboardResizeBy:a,onLayout:i,storage:l}),j=C.useRef({layout:b,panelDataArray:[],panelDataArrayChanged:!1});C.useRef({didLogIdAndOrderWarning:!1,didLogPanelConstraintsWarning:!1,prevPanelIds:[]}),C.useImperativeHandle(s,()=>({getId:()=>S.current.id,getLayout:()=>{const{layout:O}=j.current;return O},setLayout:O=>{const{onLayout:W}=S.current,{layout:B,panelDataArray:Y}=j.current,U=F$({layout:O,panelConstraints:Y.map(V=>V.constraints)});P$(B,U)||(x(U),j.current.layout=U,W&&W(U),Tf(Y,U,v.current))}}),[]),Nd(()=>{S.current.autoSaveId=e,S.current.direction=r,S.current.dragState=p,S.current.id=h,S.current.onLayout=i,S.current.storage=l}),k8e({committedValuesRef:S,eagerValuesRef:j,groupId:h,layout:b,panelDataArray:j.current.panelDataArray,setLayout:x,panelGroupElement:m.current}),C.useEffect(()=>{const{panelDataArray:O}=j.current;if(e){if(b.length===0||b.length!==O.length)return;let W=$$[e];W==null&&(W=T8e(I8e,A8e),$$[e]=W);const B=[...O],Y=new Map(w.current);W(e,B,Y,b,l)}},[e,b,l]),C.useEffect(()=>{});const E=C.useCallback(O=>{const{onLayout:W}=S.current,{layout:B,panelDataArray:Y}=j.current;if(O.constraints.collapsible){const U=Y.map(J=>J.constraints),{collapsedSize:V=0,panelSize:G,pivotIndices:K}=Du(Y,O,B);if(Mt(G!=null,`Panel size not found for panel "${O.id}"`),!cl(G,V)){w.current.set(O.id,G);const Q=Ff(Y,O)===Y.length-1?G-V:V-G,re=og({delta:Q,initialLayout:B,panelConstraints:U,pivotIndices:K,prevLayout:B,trigger:"imperative-api"});O0(B,re)||(x(re),j.current.layout=re,W&&W(re),Tf(Y,re,v.current))}}},[]),_=C.useCallback((O,W)=>{const{onLayout:B}=S.current,{layout:Y,panelDataArray:U}=j.current;if(O.constraints.collapsible){const V=U.map(de=>de.constraints),{collapsedSize:G=0,panelSize:K=0,minSize:J=0,pivotIndices:Q}=Du(U,O,Y),re=W??J;if(cl(K,G)){const de=w.current.get(O.id),fe=de!=null&&de>=re?de:re,je=Ff(U,O)===U.length-1?K-fe:fe-K,me=og({delta:je,initialLayout:Y,panelConstraints:V,pivotIndices:Q,prevLayout:Y,trigger:"imperative-api"});O0(Y,me)||(x(me),j.current.layout=me,B&&B(me),Tf(U,me,v.current))}}},[]),k=C.useCallback(O=>{const{layout:W,panelDataArray:B}=j.current,{panelSize:Y}=Du(B,O,W);return Mt(Y!=null,`Panel size not found for panel "${O.id}"`),Y},[]),M=C.useCallback((O,W)=>{const{panelDataArray:B}=j.current,Y=Ff(B,O);return M8e({defaultSize:W,dragState:p,layout:b,panelData:B,panelIndex:Y})},[p,b]),D=C.useCallback(O=>{const{layout:W,panelDataArray:B}=j.current,{collapsedSize:Y=0,collapsible:U,panelSize:V}=Du(B,O,W);return Mt(V!=null,`Panel size not found for panel "${O.id}"`),U===!0&&cl(V,Y)},[]),R=C.useCallback(O=>{const{layout:W,panelDataArray:B}=j.current,{collapsedSize:Y=0,collapsible:U,panelSize:V}=Du(B,O,W);return Mt(V!=null,`Panel size not found for panel "${O.id}"`),!U||Gd(V,Y)>0},[]),P=C.useCallback(O=>{const{panelDataArray:W}=j.current;W.push(O),W.sort((B,Y)=>{const U=B.order,V=Y.order;return U==null&&V==null?0:U==null?-1:V==null?1:U-V}),j.current.panelDataArrayChanged=!0,y()},[y]);Nd(()=>{if(j.current.panelDataArrayChanged){j.current.panelDataArrayChanged=!1;const{autoSaveId:O,onLayout:W,storage:B}=S.current,{layout:Y,panelDataArray:U}=j.current;let V=null;if(O){const K=R8e(O,U,B);K&&(w.current=new Map(Object.entries(K.expandToSizes)),V=K.layout)}V==null&&(V=D8e({panelDataArray:U}));const G=F$({layout:V,panelConstraints:U.map(K=>K.constraints)});P$(Y,G)||(x(G),j.current.layout=G,W&&W(G),Tf(U,G,v.current))}}),Nd(()=>{const O=j.current;return()=>{O.layout=[]}},[]);const I=C.useCallback(O=>{let W=!1;const B=m.current;return B&&window.getComputedStyle(B,null).getPropertyValue("direction")==="rtl"&&(W=!0),function(U){U.preventDefault();const V=m.current;if(!V)return()=>null;const{direction:G,dragState:K,id:J,keyboardResizeBy:Q,onLayout:re}=S.current,{layout:de,panelDataArray:fe}=j.current,{initialLayout:ue}=K??{},je=tQ(J,O,V);let me=_8e(U,O,G,K,Q,V);const ne=G==="horizontal";ne&&W&&(me=-me);const oe=fe.map(ae=>ae.constraints),pe=og({delta:me,initialLayout:ue??de,panelConstraints:oe,pivotIndices:je,prevLayout:de,trigger:WX(U)?"keyboard":"mouse-or-touch"}),De=!O0(de,pe);(qX(U)||YX(U))&&N.current!=me&&(N.current=me,!De&&me!==0?ne?u2(O,me<0?KX:ZX):u2(O,me<0?XX:QX):u2(O,0)),De&&(x(pe),j.current.layout=pe,re&&re(pe),Tf(fe,pe,v.current))}},[]),L=C.useCallback((O,W)=>{const{onLayout:B}=S.current,{layout:Y,panelDataArray:U}=j.current,V=U.map(de=>de.constraints),{panelSize:G,pivotIndices:K}=Du(U,O,Y);Mt(G!=null,`Panel size not found for panel "${O.id}"`);const Q=Ff(U,O)===U.length-1?G-W:W-G,re=og({delta:Q,initialLayout:Y,panelConstraints:V,pivotIndices:K,prevLayout:Y,trigger:"imperative-api"});O0(Y,re)||(x(re),j.current.layout=re,B&&B(re),Tf(U,re,v.current))},[]),F=C.useCallback((O,W)=>{const{layout:B,panelDataArray:Y}=j.current,{collapsedSize:U=0,collapsible:V}=W,{collapsedSize:G=0,collapsible:K,maxSize:J=100,minSize:Q=0}=O.constraints,{panelSize:re}=Du(Y,O,B);re!=null&&(V&&K&&cl(re,U)?cl(U,G)||L(O,G):re<Q?L(O,Q):re>J&&L(O,J))},[L]),H=C.useCallback((O,W)=>{const{direction:B}=S.current,{layout:Y}=j.current;if(!m.current)return;const U=gC(O,m.current);Mt(U,`Drag handle element not found for id "${O}"`);const V=rQ(B,W);g({dragHandleId:O,dragHandleRect:U.getBoundingClientRect(),initialCursorPosition:V,initialLayout:Y})},[]),$=C.useCallback(()=>{g(null)},[]),A=C.useCallback(O=>{const{panelDataArray:W}=j.current,B=Ff(W,O);B>=0&&(W.splice(B,1),delete v.current[O.id],j.current.panelDataArrayChanged=!0,y())},[y]),q=C.useMemo(()=>({collapsePanel:E,direction:r,dragState:p,expandPanel:_,getPanelSize:k,getPanelStyle:M,groupId:h,isPanelCollapsed:D,isPanelExpanded:R,reevaluatePanelConstraints:F,registerPanel:P,registerResizeHandle:I,resizePanel:L,startDragging:H,stopDragging:$,unregisterPanel:A,panelGroupElement:m.current}),[E,p,r,_,k,M,h,D,R,F,P,I,L,H,$,A]),z={display:"flex",flexDirection:r==="horizontal"?"row":"column",height:"100%",overflow:"hidden",width:"100%"};return C.createElement(hC.Provider,{value:q},C.createElement(d,{...f,children:t,className:n,id:o,ref:m,style:{...z,...u},[rr.group]:"",[rr.groupDirection]:r,[rr.groupId]:h}))}const lQ=C.forwardRef((e,t)=>C.createElement(aQ,{...e,forwardedRef:t}));aQ.displayName="PanelGroup";lQ.displayName="forwardRef(PanelGroup)";function Ff(e,t){return e.findIndex(n=>n===t||n.id===t.id)}function Du(e,t,n){const r=Ff(e,t),o=r===e.length-1?[r-1,r]:[r,r+1],i=n[r];return{...t.constraints,panelSize:i,pivotIndices:o}}function P8e({disabled:e,handleId:t,resizeHandler:n,panelGroupElement:r}){C.useEffect(()=>{if(e||n==null||r==null)return;const s=gC(t,r);if(s==null)return;const o=i=>{if(!i.defaultPrevented)switch(i.key){case"ArrowDown":case"ArrowLeft":case"ArrowRight":case"ArrowUp":case"End":case"Home":{i.preventDefault(),n(i);break}case"F6":{i.preventDefault();const a=s.getAttribute(rr.groupId);Mt(a,`No group element found for id "${a}"`);const l=Rb(a,r),u=eQ(a,t,r);Mt(u!==null,`No resize element found for id "${t}"`);const d=i.shiftKey?u>0?u-1:l.length-1:u+1<l.length?u+1:0;l[d].focus();break}}};return s.addEventListener("keydown",o),()=>{s.removeEventListener("keydown",o)}},[r,e,t,n])}function LI({children:e=null,className:t="",disabled:n=!1,hitAreaMargins:r,id:s,onBlur:o,onClick:i,onDragging:a,onFocus:l,onPointerDown:u,onPointerUp:d,style:f={},tabIndex:h=0,tagName:m="div",...p}){var g,b;const x=C.useRef(null),y=C.useRef({onClick:i,onDragging:a,onPointerDown:u,onPointerUp:d});C.useEffect(()=>{y.current.onClick=i,y.current.onDragging=a,y.current.onPointerDown=u,y.current.onPointerUp=d});const v=C.useContext(hC);if(v===null)throw Error("PanelResizeHandle components must be rendered within a PanelGroup container");const{direction:w,groupId:N,registerResizeHandle:S,startDragging:j,stopDragging:E,panelGroupElement:_}=v,k=OI(s),[M,D]=C.useState("inactive"),[R,P]=C.useState(!1),[I,L]=C.useState(null),F=C.useRef({state:M});Nd(()=>{F.current.state=M}),C.useEffect(()=>{if(n)L(null);else{const q=S(k);L(()=>q)}},[n,k,S]);const H=(g=r==null?void 0:r.coarse)!==null&&g!==void 0?g:15,$=(b=r==null?void 0:r.fine)!==null&&b!==void 0?b:5;C.useEffect(()=>{if(n||I==null)return;const q=x.current;Mt(q,"Element ref not attached");let z=!1;return v8e(k,q,w,{coarse:H,fine:$},(W,B,Y)=>{if(!B){D("inactive");return}switch(W){case"down":{D("drag"),z=!1,Mt(Y,'Expected event to be defined for "down" action'),j(k,Y);const{onDragging:U,onPointerDown:V}=y.current;U==null||U(!0),V==null||V();break}case"move":{const{state:U}=F.current;z=!0,U!=="drag"&&D("hover"),Mt(Y,'Expected event to be defined for "move" action'),I(Y);break}case"up":{D("hover"),E();const{onClick:U,onDragging:V,onPointerUp:G}=y.current;V==null||V(!1),G==null||G(),z||U==null||U();break}}})},[H,w,n,$,S,k,I,j,E]),P8e({disabled:n,handleId:k,resizeHandler:I,panelGroupElement:_});const A={touchAction:"none",userSelect:"none"};return C.createElement(m,{...p,children:e,className:t,id:s,onBlur:()=>{P(!1),o==null||o()},onFocus:()=>{P(!0),l==null||l()},ref:x,role:"separator",style:{...A,...f},tabIndex:h,[rr.groupDirection]:w,[rr.groupId]:N,[rr.resizeHandle]:"",[rr.resizeHandleActive]:M==="drag"?"pointer":R?"keyboard":void 0,[rr.resizeHandleEnabled]:!n,[rr.resizeHandleId]:k,[rr.resizeHandleState]:M})}LI.displayName="PanelResizeHandle";const cQ=({className:e,...t})=>c.jsx(lQ,{className:Z("flex h-full w-full data-[panel-group-direction=vertical]:flex-col",e),...t}),x_=UX,O8e=({withHandle:e,className:t,...n})=>c.jsx(LI,{className:Z("relative flex w-px items-center justify-center bg-border after:absolute after:inset-y-0 after:left-1/2 after:w-1 after:-translate-x-1/2 focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring focus-visible:ring-offset-1 data-[panel-group-direction=vertical]:h-px data-[panel-group-direction=vertical]:w-full data-[panel-group-direction=vertical]:after:left-0 data-[panel-group-direction=vertical]:after:h-1 data-[panel-group-direction=vertical]:after:w-full data-[panel-group-direction=vertical]:after:-translate-y-1/2 data-[panel-group-direction=vertical]:after:translate-x-0 [&[data-panel-group-direction=vertical]>div]:rotate-90",t),...n,children:e&&c.jsx("div",{className:"z-10 flex h-4 w-3 items-center justify-center rounded-sm border bg-border",children:c.jsx(PD,{className:"h-2.5 w-2.5"})})}),F8e=({withHandle:e,className:t,onTabClick:n,open:r,...s})=>c.jsx(LI,{className:Z("relative flex w-px items-start justify-end bg-border after:absolute after:inset-y-0 after:left-1/2 after:w-1 after:-translate-x-1/2 focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring focus-visible:ring-offset-1 data-[panel-group-direction=vertical]:h-px data-[panel-group-direction=vertical]:w-full data-[panel-group-direction=vertical]:after:left-0 data-[panel-group-direction=vertical]:after:h-1 data-[panel-group-direction=vertical]:after:w-full data-[panel-group-direction=vertical]:after:-translate-y-1/2 data-[panel-group-direction=vertical]:after:translate-x-0 [&[data-panel-group-direction=vertical]>div]:rotate-90",{"justify-start":r},t),...s,children:e&&!1});function $8e(e={}){const{initialPosition:t="bottom-right"}=e,[n,r]=C.useState(t),[s,o]=C.useState(!1),[i,a]=C.useState(null),l=C.useRef(null),u=C.useRef(!1),d=C.useRef(null);C.useEffect(()=>()=>{d.current&&(d.current(),d.current=null)},[]);const f=C.useCallback(p=>{const g="touches"in p?p.touches[0].clientX:p.clientX,b="touches"in p?p.touches[0].clientY:p.clientY;l.current={x:g,y:b},u.current=!1,a({x:g,y:b});const x=(j,E,_)=>{if(!l.current)return;const k=Math.abs(j-l.current.x),M=Math.abs(E-l.current.y);(k>10||M>10)&&(u.current?_.cancelable&&_.preventDefault():(_.cancelable&&_.preventDefault(),u.current=!0,o(!0))),a({x:j,y:E})},y={passive:!1},v=j=>{x(j.clientX,j.clientY,j)},w=j=>{if(j.touches.length===0)return;const E=j.touches[0];x(E.clientX,E.clientY,j)},N=()=>{document.removeEventListener("mousemove",v),document.removeEventListener("mouseup",S),document.removeEventListener("touchmove",w),document.removeEventListener("touchend",S),d.current=null},S=()=>{a(j=>{if(u.current&&j){const E=window.innerWidth,_=window.innerHeight,k=j.x<E/2,M=j.y<_/2;r(M&&k?"top-left":M&&!k?"top-right":!M&&k?"bottom-left":"bottom-right")}return null}),l.current=null,setTimeout(()=>{u.current=!1,o(!1)},100),N()};document.addEventListener("mousemove",v),document.addEventListener("mouseup",S),document.addEventListener("touchmove",w,y),document.addEventListener("touchend",S),d.current=N},[]),h=C.useCallback(()=>{if(s&&i)return{position:"fixed",left:0,top:0,right:"auto",bottom:"auto",transform:`translate(${i.x-24}px, ${i.y-24}px)`,transition:"none",willChange:"transform"}},[s,i]),m=C.useCallback(()=>({horizontal:n.includes("left")?"left-6":"right-6",vertical:n.includes("top")?"top-6":"bottom-6"}),[n]);return{position:n,isDragging:s,dragPosition:i,handleDragStart:f,isDraggingRef:u,getStyle:h,getPositionClasses:m}}function L8e({open:e,setOpen:t}){const n=X(o=>o.selectedSheetId),{deleteSheet:r}=Ot();function s(){n&&(r(n),t(!1))}return c.jsx(px,{open:e,onOpenChange:t,children:c.jsxs(ym,{children:[c.jsxs(vm,{children:[c.jsx(Sm,{children:"Delete Sheet"}),c.jsx(Cm,{children:"Are you sure you want to delete this sheet along with all its cards? This action cannot be undone."})]}),c.jsxs(wm,{children:[c.jsx(jm,{children:"Cancel"}),c.jsx(Nm,{className:"bg-destructive hover:bg-destructive/90",onClick:s,children:"Delete"})]})]})})}function z8e({children:e}){return c.jsx("pre",{className:"border-1 whitespace-pre-wrap rounded-md border border-muted p-3 text-xs",children:e})}function B8e(e,t){const n={};return(e[e.length-1]===""?[...e,""]:e).join((n.padRight?" ":"")+","+(n.padLeft===!1?"":" ")).trim()}const V8e=/^[$_\p{ID_Start}][$_\u{200C}\u{200D}\p{ID_Continue}]*$/u,H8e=/^[$_\p{ID_Start}][-$_\u{200C}\u{200D}\p{ID_Continue}]*$/u,U8e={};function L$(e,t){return(U8e.jsx?H8e:V8e).test(e)}const W8e=/[ \t\n\f\r]/g;function q8e(e){return typeof e=="object"?e.type==="text"?z$(e.value):!1:z$(e)}function z$(e){return e.replace(W8e,"")===""}class ay{constructor(t,n,r){this.normal=n,this.property=t,r&&(this.space=r)}}ay.prototype.normal={};ay.prototype.property={};ay.prototype.space=void 0;function uQ(e,t){const n={},r={};for(const s of e)Object.assign(n,s.property),Object.assign(r,s.normal);return new ay(n,r,t)}function y_(e){return e.toLowerCase()}class io{constructor(t,n){this.attribute=n,this.property=t}}io.prototype.attribute="";io.prototype.booleanish=!1;io.prototype.boolean=!1;io.prototype.commaOrSpaceSeparated=!1;io.prototype.commaSeparated=!1;io.prototype.defined=!1;io.prototype.mustUseProperty=!1;io.prototype.number=!1;io.prototype.overloadedBoolean=!1;io.prototype.property="";io.prototype.spaceSeparated=!1;io.prototype.space=void 0;let Y8e=0;const kt=mf(),yr=mf(),v_=mf(),Re=mf(),Rn=mf(),fh=mf(),mo=mf();function mf(){return 2**++Y8e}const w_=Object.freeze(Object.defineProperty({__proto__:null,boolean:kt,booleanish:yr,commaOrSpaceSeparated:mo,commaSeparated:fh,number:Re,overloadedBoolean:v_,spaceSeparated:Rn},Symbol.toStringTag,{value:"Module"})),f2=Object.keys(w_);class zI extends io{constructor(t,n,r,s){let o=-1;if(super(t,n),B$(this,"space",s),typeof r=="number")for(;++o<f2.length;){const i=f2[o];B$(this,f2[o],(r&w_[i])===w_[i])}}}zI.prototype.defined=!0;function B$(e,t,n){n&&(e[t]=n)}function cp(e){const t={},n={};for(const[r,s]of Object.entries(e.properties)){const o=new zI(r,e.transform(e.attributes||{},r),s,e.space);e.mustUseProperty&&e.mustUseProperty.includes(r)&&(o.mustUseProperty=!0),t[r]=o,n[y_(r)]=r,n[y_(o.attribute)]=r}return new ay(t,n,e.space)}const dQ=cp({properties:{ariaActiveDescendant:null,ariaAtomic:yr,ariaAutoComplete:null,ariaBusy:yr,ariaChecked:yr,ariaColCount:Re,ariaColIndex:Re,ariaColSpan:Re,ariaControls:Rn,ariaCurrent:null,ariaDescribedBy:Rn,ariaDetails:null,ariaDisabled:yr,ariaDropEffect:Rn,ariaErrorMessage:null,ariaExpanded:yr,ariaFlowTo:Rn,ariaGrabbed:yr,ariaHasPopup:null,ariaHidden:yr,ariaInvalid:null,ariaKeyShortcuts:null,ariaLabel:null,ariaLabelledBy:Rn,ariaLevel:Re,ariaLive:null,ariaModal:yr,ariaMultiLine:yr,ariaMultiSelectable:yr,ariaOrientation:null,ariaOwns:Rn,ariaPlaceholder:null,ariaPosInSet:Re,ariaPressed:yr,ariaReadOnly:yr,ariaRelevant:null,ariaRequired:yr,ariaRoleDescription:Rn,ariaRowCount:Re,ariaRowIndex:Re,ariaRowSpan:Re,ariaSelected:yr,ariaSetSize:Re,ariaSort:null,ariaValueMax:Re,ariaValueMin:Re,ariaValueNow:Re,ariaValueText:null,role:null},transform(e,t){return t==="role"?t:"aria-"+t.slice(4).toLowerCase()}});function fQ(e,t){return t in e?e[t]:t}function hQ(e,t){return fQ(e,t.toLowerCase())}const G8e=cp({attributes:{acceptcharset:"accept-charset",classname:"class",htmlfor:"for",httpequiv:"http-equiv"},mustUseProperty:["checked","multiple","muted","selected"],properties:{abbr:null,accept:fh,acceptCharset:Rn,accessKey:Rn,action:null,allow:null,allowFullScreen:kt,allowPaymentRequest:kt,allowUserMedia:kt,alt:null,as:null,async:kt,autoCapitalize:null,autoComplete:Rn,autoFocus:kt,autoPlay:kt,blocking:Rn,capture:null,charSet:null,checked:kt,cite:null,className:Rn,cols:Re,colSpan:null,content:null,contentEditable:yr,controls:kt,controlsList:Rn,coords:Re|fh,crossOrigin:null,data:null,dateTime:null,decoding:null,default:kt,defer:kt,dir:null,dirName:null,disabled:kt,download:v_,draggable:yr,encType:null,enterKeyHint:null,fetchPriority:null,form:null,formAction:null,formEncType:null,formMethod:null,formNoValidate:kt,formTarget:null,headers:Rn,height:Re,hidden:v_,high:Re,href:null,hrefLang:null,htmlFor:Rn,httpEquiv:Rn,id:null,imageSizes:null,imageSrcSet:null,inert:kt,inputMode:null,integrity:null,is:null,isMap:kt,itemId:null,itemProp:Rn,itemRef:Rn,itemScope:kt,itemType:Rn,kind:null,label:null,lang:null,language:null,list:null,loading:null,loop:kt,low:Re,manifest:null,max:null,maxLength:Re,media:null,method:null,min:null,minLength:Re,multiple:kt,muted:kt,name:null,nonce:null,noModule:kt,noValidate:kt,onAbort:null,onAfterPrint:null,onAuxClick:null,onBeforeMatch:null,onBeforePrint:null,onBeforeToggle:null,onBeforeUnload:null,onBlur:null,onCancel:null,onCanPlay:null,onCanPlayThrough:null,onChange:null,onClick:null,onClose:null,onContextLost:null,onContextMenu:null,onContextRestored:null,onCopy:null,onCueChange:null,onCut:null,onDblClick:null,onDrag:null,onDragEnd:null,onDragEnter:null,onDragExit:null,onDragLeave:null,onDragOver:null,onDragStart:null,onDrop:null,onDurationChange:null,onEmptied:null,onEnded:null,onError:null,onFocus:null,onFormData:null,onHashChange:null,onInput:null,onInvalid:null,onKeyDown:null,onKeyPress:null,onKeyUp:null,onLanguageChange:null,onLoad:null,onLoadedData:null,onLoadedMetadata:null,onLoadEnd:null,onLoadStart:null,onMessage:null,onMessageError:null,onMouseDown:null,onMouseEnter:null,onMouseLeave:null,onMouseMove:null,onMouseOut:null,onMouseOver:null,onMouseUp:null,onOffline:null,onOnline:null,onPageHide:null,onPageShow:null,onPaste:null,onPause:null,onPlay:null,onPlaying:null,onPopState:null,onProgress:null,onRateChange:null,onRejectionHandled:null,onReset:null,onResize:null,onScroll:null,onScrollEnd:null,onSecurityPolicyViolation:null,onSeeked:null,onSeeking:null,onSelect:null,onSlotChange:null,onStalled:null,onStorage:null,onSubmit:null,onSuspend:null,onTimeUpdate:null,onToggle:null,onUnhandledRejection:null,onUnload:null,onVolumeChange:null,onWaiting:null,onWheel:null,open:kt,optimum:Re,pattern:null,ping:Rn,placeholder:null,playsInline:kt,popover:null,popoverTarget:null,popoverTargetAction:null,poster:null,preload:null,readOnly:kt,referrerPolicy:null,rel:Rn,required:kt,reversed:kt,rows:Re,rowSpan:Re,sandbox:Rn,scope:null,scoped:kt,seamless:kt,selected:kt,shadowRootClonable:kt,shadowRootDelegatesFocus:kt,shadowRootMode:null,shape:null,size:Re,sizes:null,slot:null,span:Re,spellCheck:yr,src:null,srcDoc:null,srcLang:null,srcSet:null,start:Re,step:null,style:null,tabIndex:Re,target:null,title:null,translate:null,type:null,typeMustMatch:kt,useMap:null,value:yr,width:Re,wrap:null,writingSuggestions:null,align:null,aLink:null,archive:Rn,axis:null,background:null,bgColor:null,border:Re,borderColor:null,bottomMargin:Re,cellPadding:null,cellSpacing:null,char:null,charOff:null,classId:null,clear:null,code:null,codeBase:null,codeType:null,color:null,compact:kt,declare:kt,event:null,face:null,frame:null,frameBorder:null,hSpace:Re,leftMargin:Re,link:null,longDesc:null,lowSrc:null,marginHeight:Re,marginWidth:Re,noResize:kt,noHref:kt,noShade:kt,noWrap:kt,object:null,profile:null,prompt:null,rev:null,rightMargin:Re,rules:null,scheme:null,scrolling:yr,standby:null,summary:null,text:null,topMargin:Re,valueType:null,version:null,vAlign:null,vLink:null,vSpace:Re,allowTransparency:null,autoCorrect:null,autoSave:null,disablePictureInPicture:kt,disableRemotePlayback:kt,prefix:null,property:null,results:Re,security:null,unselectable:null},space:"html",transform:hQ}),K8e=cp({attributes:{accentHeight:"accent-height",alignmentBaseline:"alignment-baseline",arabicForm:"arabic-form",baselineShift:"baseline-shift",capHeight:"cap-height",className:"class",clipPath:"clip-path",clipRule:"clip-rule",colorInterpolation:"color-interpolation",colorInterpolationFilters:"color-interpolation-filters",colorProfile:"color-profile",colorRendering:"color-rendering",crossOrigin:"crossorigin",dataType:"datatype",dominantBaseline:"dominant-baseline",enableBackground:"enable-background",fillOpacity:"fill-opacity",fillRule:"fill-rule",floodColor:"flood-color",floodOpacity:"flood-opacity",fontFamily:"font-family",fontSize:"font-size",fontSizeAdjust:"font-size-adjust",fontStretch:"font-stretch",fontStyle:"font-style",fontVariant:"font-variant",fontWeight:"font-weight",glyphName:"glyph-name",glyphOrientationHorizontal:"glyph-orientation-horizontal",glyphOrientationVertical:"glyph-orientation-vertical",hrefLang:"hreflang",horizAdvX:"horiz-adv-x",horizOriginX:"horiz-origin-x",horizOriginY:"horiz-origin-y",imageRendering:"image-rendering",letterSpacing:"letter-spacing",lightingColor:"lighting-color",markerEnd:"marker-end",markerMid:"marker-mid",markerStart:"marker-start",navDown:"nav-down",navDownLeft:"nav-down-left",navDownRight:"nav-down-right",navLeft:"nav-left",navNext:"nav-next",navPrev:"nav-prev",navRight:"nav-right",navUp:"nav-up",navUpLeft:"nav-up-left",navUpRight:"nav-up-right",onAbort:"onabort",onActivate:"onactivate",onAfterPrint:"onafterprint",onBeforePrint:"onbeforeprint",onBegin:"onbegin",onCancel:"oncancel",onCanPlay:"oncanplay",onCanPlayThrough:"oncanplaythrough",onChange:"onchange",onClick:"onclick",onClose:"onclose",onCopy:"oncopy",onCueChange:"oncuechange",onCut:"oncut",onDblClick:"ondblclick",onDrag:"ondrag",onDragEnd:"ondragend",onDragEnter:"ondragenter",onDragExit:"ondragexit",onDragLeave:"ondragleave",onDragOver:"ondragover",onDragStart:"ondragstart",onDrop:"ondrop",onDurationChange:"ondurationchange",onEmptied:"onemptied",onEnd:"onend",onEnded:"onended",onError:"onerror",onFocus:"onfocus",onFocusIn:"onfocusin",onFocusOut:"onfocusout",onHashChange:"onhashchange",onInput:"oninput",onInvalid:"oninvalid",onKeyDown:"onkeydown",onKeyPress:"onkeypress",onKeyUp:"onkeyup",onLoad:"onload",onLoadedData:"onloadeddata",onLoadedMetadata:"onloadedmetadata",onLoadStart:"onloadstart",onMessage:"onmessage",onMouseDown:"onmousedown",onMouseEnter:"onmouseenter",onMouseLeave:"onmouseleave",onMouseMove:"onmousemove",onMouseOut:"onmouseout",onMouseOver:"onmouseover",onMouseUp:"onmouseup",onMouseWheel:"onmousewheel",onOffline:"onoffline",onOnline:"ononline",onPageHide:"onpagehide",onPageShow:"onpageshow",onPaste:"onpaste",onPause:"onpause",onPlay:"onplay",onPlaying:"onplaying",onPopState:"onpopstate",onProgress:"onprogress",onRateChange:"onratechange",onRepeat:"onrepeat",onReset:"onreset",onResize:"onresize",onScroll:"onscroll",onSeeked:"onseeked",onSeeking:"onseeking",onSelect:"onselect",onShow:"onshow",onStalled:"onstalled",onStorage:"onstorage",onSubmit:"onsubmit",onSuspend:"onsuspend",onTimeUpdate:"ontimeupdate",onToggle:"ontoggle",onUnload:"onunload",onVolumeChange:"onvolumechange",onWaiting:"onwaiting",onZoom:"onzoom",overlinePosition:"overline-position",overlineThickness:"overline-thickness",paintOrder:"paint-order",panose1:"panose-1",pointerEvents:"pointer-events",referrerPolicy:"referrerpolicy",renderingIntent:"rendering-intent",shapeRendering:"shape-rendering",stopColor:"stop-color",stopOpacity:"stop-opacity",strikethroughPosition:"strikethrough-position",strikethroughThickness:"strikethrough-thickness",strokeDashArray:"stroke-dasharray",strokeDashOffset:"stroke-dashoffset",strokeLineCap:"stroke-linecap",strokeLineJoin:"stroke-linejoin",strokeMiterLimit:"stroke-miterlimit",strokeOpacity:"stroke-opacity",strokeWidth:"stroke-width",tabIndex:"tabindex",textAnchor:"text-anchor",textDecoration:"text-decoration",textRendering:"text-rendering",transformOrigin:"transform-origin",typeOf:"typeof",underlinePosition:"underline-position",underlineThickness:"underline-thickness",unicodeBidi:"unicode-bidi",unicodeRange:"unicode-range",unitsPerEm:"units-per-em",vAlphabetic:"v-alphabetic",vHanging:"v-hanging",vIdeographic:"v-ideographic",vMathematical:"v-mathematical",vectorEffect:"vector-effect",vertAdvY:"vert-adv-y",vertOriginX:"vert-origin-x",vertOriginY:"vert-origin-y",wordSpacing:"word-spacing",writingMode:"writing-mode",xHeight:"x-height",playbackOrder:"playbackorder",timelineBegin:"timelinebegin"},properties:{about:mo,accentHeight:Re,accumulate:null,additive:null,alignmentBaseline:null,alphabetic:Re,amplitude:Re,arabicForm:null,ascent:Re,attributeName:null,attributeType:null,azimuth:Re,bandwidth:null,baselineShift:null,baseFrequency:null,baseProfile:null,bbox:null,begin:null,bias:Re,by:null,calcMode:null,capHeight:Re,className:Rn,clip:null,clipPath:null,clipPathUnits:null,clipRule:null,color:null,colorInterpolation:null,colorInterpolationFilters:null,colorProfile:null,colorRendering:null,content:null,contentScriptType:null,contentStyleType:null,crossOrigin:null,cursor:null,cx:null,cy:null,d:null,dataType:null,defaultAction:null,descent:Re,diffuseConstant:Re,direction:null,display:null,dur:null,divisor:Re,dominantBaseline:null,download:kt,dx:null,dy:null,edgeMode:null,editable:null,elevation:Re,enableBackground:null,end:null,event:null,exponent:Re,externalResourcesRequired:null,fill:null,fillOpacity:Re,fillRule:null,filter:null,filterRes:null,filterUnits:null,floodColor:null,floodOpacity:null,focusable:null,focusHighlight:null,fontFamily:null,fontSize:null,fontSizeAdjust:null,fontStretch:null,fontStyle:null,fontVariant:null,fontWeight:null,format:null,fr:null,from:null,fx:null,fy:null,g1:fh,g2:fh,glyphName:fh,glyphOrientationHorizontal:null,glyphOrientationVertical:null,glyphRef:null,gradientTransform:null,gradientUnits:null,handler:null,hanging:Re,hatchContentUnits:null,hatchUnits:null,height:null,href:null,hrefLang:null,horizAdvX:Re,horizOriginX:Re,horizOriginY:Re,id:null,ideographic:Re,imageRendering:null,initialVisibility:null,in:null,in2:null,intercept:Re,k:Re,k1:Re,k2:Re,k3:Re,k4:Re,kernelMatrix:mo,kernelUnitLength:null,keyPoints:null,keySplines:null,keyTimes:null,kerning:null,lang:null,lengthAdjust:null,letterSpacing:null,lightingColor:null,limitingConeAngle:Re,local:null,markerEnd:null,markerMid:null,markerStart:null,markerHeight:null,markerUnits:null,markerWidth:null,mask:null,maskContentUnits:null,maskUnits:null,mathematical:null,max:null,media:null,mediaCharacterEncoding:null,mediaContentEncodings:null,mediaSize:Re,mediaTime:null,method:null,min:null,mode:null,name:null,navDown:null,navDownLeft:null,navDownRight:null,navLeft:null,navNext:null,navPrev:null,navRight:null,navUp:null,navUpLeft:null,navUpRight:null,numOctaves:null,observer:null,offset:null,onAbort:null,onActivate:null,onAfterPrint:null,onBeforePrint:null,onBegin:null,onCancel:null,onCanPlay:null,onCanPlayThrough:null,onChange:null,onClick:null,onClose:null,onCopy:null,onCueChange:null,onCut:null,onDblClick:null,onDrag:null,onDragEnd:null,onDragEnter:null,onDragExit:null,onDragLeave:null,onDragOver:null,onDragStart:null,onDrop:null,onDurationChange:null,onEmptied:null,onEnd:null,onEnded:null,onError:null,onFocus:null,onFocusIn:null,onFocusOut:null,onHashChange:null,onInput:null,onInvalid:null,onKeyDown:null,onKeyPress:null,onKeyUp:null,onLoad:null,onLoadedData:null,onLoadedMetadata:null,onLoadStart:null,onMessage:null,onMouseDown:null,onMouseEnter:null,onMouseLeave:null,onMouseMove:null,onMouseOut:null,onMouseOver:null,onMouseUp:null,onMouseWheel:null,onOffline:null,onOnline:null,onPageHide:null,onPageShow:null,onPaste:null,onPause:null,onPlay:null,onPlaying:null,onPopState:null,onProgress:null,onRateChange:null,onRepeat:null,onReset:null,onResize:null,onScroll:null,onSeeked:null,onSeeking:null,onSelect:null,onShow:null,onStalled:null,onStorage:null,onSubmit:null,onSuspend:null,onTimeUpdate:null,onToggle:null,onUnload:null,onVolumeChange:null,onWaiting:null,onZoom:null,opacity:null,operator:null,order:null,orient:null,orientation:null,origin:null,overflow:null,overlay:null,overlinePosition:Re,overlineThickness:Re,paintOrder:null,panose1:null,path:null,pathLength:Re,patternContentUnits:null,patternTransform:null,patternUnits:null,phase:null,ping:Rn,pitch:null,playbackOrder:null,pointerEvents:null,points:null,pointsAtX:Re,pointsAtY:Re,pointsAtZ:Re,preserveAlpha:null,preserveAspectRatio:null,primitiveUnits:null,propagate:null,property:mo,r:null,radius:null,referrerPolicy:null,refX:null,refY:null,rel:mo,rev:mo,renderingIntent:null,repeatCount:null,repeatDur:null,requiredExtensions:mo,requiredFeatures:mo,requiredFonts:mo,requiredFormats:mo,resource:null,restart:null,result:null,rotate:null,rx:null,ry:null,scale:null,seed:null,shapeRendering:null,side:null,slope:null,snapshotTime:null,specularConstant:Re,specularExponent:Re,spreadMethod:null,spacing:null,startOffset:null,stdDeviation:null,stemh:null,stemv:null,stitchTiles:null,stopColor:null,stopOpacity:null,strikethroughPosition:Re,strikethroughThickness:Re,string:null,stroke:null,strokeDashArray:mo,strokeDashOffset:null,strokeLineCap:null,strokeLineJoin:null,strokeMiterLimit:Re,strokeOpacity:Re,strokeWidth:null,style:null,surfaceScale:Re,syncBehavior:null,syncBehaviorDefault:null,syncMaster:null,syncTolerance:null,syncToleranceDefault:null,systemLanguage:mo,tabIndex:Re,tableValues:null,target:null,targetX:Re,targetY:Re,textAnchor:null,textDecoration:null,textRendering:null,textLength:null,timelineBegin:null,title:null,transformBehavior:null,type:null,typeOf:mo,to:null,transform:null,transformOrigin:null,u1:null,u2:null,underlinePosition:Re,underlineThickness:Re,unicode:null,unicodeBidi:null,unicodeRange:null,unitsPerEm:Re,values:null,vAlphabetic:Re,vMathematical:Re,vectorEffect:null,vHanging:Re,vIdeographic:Re,version:null,vertAdvY:Re,vertOriginX:Re,vertOriginY:Re,viewBox:null,viewTarget:null,visibility:null,width:null,widths:null,wordSpacing:null,writingMode:null,x:null,x1:null,x2:null,xChannelSelector:null,xHeight:Re,y:null,y1:null,y2:null,yChannelSelector:null,z:null,zoomAndPan:null},space:"svg",transform:fQ}),mQ=cp({properties:{xLinkActuate:null,xLinkArcRole:null,xLinkHref:null,xLinkRole:null,xLinkShow:null,xLinkTitle:null,xLinkType:null},space:"xlink",transform(e,t){return"xlink:"+t.slice(5).toLowerCase()}}),pQ=cp({attributes:{xmlnsxlink:"xmlns:xlink"},properties:{xmlnsXLink:null,xmlns:null},space:"xmlns",transform:hQ}),gQ=cp({properties:{xmlBase:null,xmlLang:null,xmlSpace:null},space:"xml",transform(e,t){return"xml:"+t.slice(3).toLowerCase()}}),Z8e={classId:"classID",dataType:"datatype",itemId:"itemID",strokeDashArray:"strokeDasharray",strokeDashOffset:"strokeDashoffset",strokeLineCap:"strokeLinecap",strokeLineJoin:"strokeLinejoin",strokeMiterLimit:"strokeMiterlimit",typeOf:"typeof",xLinkActuate:"xlinkActuate",xLinkArcRole:"xlinkArcrole",xLinkHref:"xlinkHref",xLinkRole:"xlinkRole",xLinkShow:"xlinkShow",xLinkTitle:"xlinkTitle",xLinkType:"xlinkType",xmlnsXLink:"xmlnsXlink"},X8e=/[A-Z]/g,V$=/-[a-z]/g,Q8e=/^data[-\w.:]+$/i;function J8e(e,t){const n=y_(t);let r=t,s=io;if(n in e.normal)return e.property[e.normal[n]];if(n.length>4&&n.slice(0,4)==="data"&&Q8e.test(t)){if(t.charAt(4)==="-"){const o=t.slice(5).replace(V$,t9e);r="data"+o.charAt(0).toUpperCase()+o.slice(1)}else{const o=t.slice(4);if(!V$.test(o)){let i=o.replace(X8e,e9e);i.charAt(0)!=="-"&&(i="-"+i),t="data"+i}}s=zI}return new s(r,t)}function e9e(e){return"-"+e.toLowerCase()}function t9e(e){return e.charAt(1).toUpperCase()}const n9e=uQ([dQ,G8e,mQ,pQ,gQ],"html"),BI=uQ([dQ,K8e,mQ,pQ,gQ],"svg");function r9e(e){return e.join(" ").trim()}var VI={},H$=/\/\*[^*]*\*+([^/*][^*]*\*+)*\//g,s9e=/\n/g,o9e=/^\s*/,i9e=/^(\*?[-#/*\\\w]+(\[[0-9a-z_-]+\])?)\s*/,a9e=/^:\s*/,l9e=/^((?:'(?:\\'|.)*?'|"(?:\\"|.)*?"|\([^)]*?\)|[^};])+)/,c9e=/^[;\s]*/,u9e=/^\s+|\s+$/g,d9e=`
1012
+ `},HLe={onDragStart(e){let{active:t}=e;return"Picked up draggable item "+t.id+"."},onDragOver(e){let{active:t,over:n}=e;return n?"Draggable item "+t.id+" was moved over droppable area "+n.id+".":"Draggable item "+t.id+" is no longer over a droppable area."},onDragEnd(e){let{active:t,over:n}=e;return n?"Draggable item "+t.id+" was dropped over droppable area "+n.id:"Draggable item "+t.id+" was dropped."},onDragCancel(e){let{active:t}=e;return"Dragging was cancelled. Draggable item "+t.id+" was dropped."}};function ULe(e){let{announcements:t=HLe,container:n,hiddenTextDescribedById:r,screenReaderInstructions:s=VLe}=e;const{announce:o,announcement:i}=LLe(),a=Jx("DndLiveRegion"),[l,u]=C.useState(!1);if(C.useEffect(()=>{u(!0)},[]),zLe(C.useMemo(()=>({onDragStart(f){let{active:h}=f;o(t.onDragStart({active:h}))},onDragMove(f){let{active:h,over:m}=f;t.onDragMove&&o(t.onDragMove({active:h,over:m}))},onDragOver(f){let{active:h,over:m}=f;o(t.onDragOver({active:h,over:m}))},onDragEnd(f){let{active:h,over:m}=f;o(t.onDragEnd({active:h,over:m}))},onDragCancel(f){let{active:h,over:m}=f;o(t.onDragCancel({active:h,over:m}))}}),[o,t])),!l)return null;const d=C.createElement(C.Fragment,null,C.createElement(FLe,{id:r,value:s.draggable}),C.createElement($Le,{id:a,announcement:i}));return n?Ln.createPortal(d,n):d}var _r;(function(e){e.DragStart="dragStart",e.DragMove="dragMove",e.DragEnd="dragEnd",e.DragCancel="dragCancel",e.DragOver="dragOver",e.RegisterDroppable="registerDroppable",e.SetDroppableDisabled="setDroppableDisabled",e.UnregisterDroppable="unregisterDroppable"})(_r||(_r={}));function Ww(){}function tm(e,t){return C.useMemo(()=>({sensor:e,options:t??{}}),[e,t])}function lC(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];return C.useMemo(()=>[...t].filter(r=>r!=null),[...t])}const Vi=Object.freeze({x:0,y:0});function aX(e,t){return Math.sqrt(Math.pow(e.x-t.x,2)+Math.pow(e.y-t.y,2))}function WLe(e,t){const n=Uw(e);if(!n)return"0 0";const r={x:(n.x-t.left)/t.width*100,y:(n.y-t.top)/t.height*100};return r.x+"% "+r.y+"%"}function lX(e,t){let{data:{value:n}}=e,{data:{value:r}}=t;return n-r}function qLe(e,t){let{data:{value:n}}=e,{data:{value:r}}=t;return r-n}function b$(e){let{left:t,top:n,height:r,width:s}=e;return[{x:t,y:n},{x:t+s,y:n},{x:t,y:n+r},{x:t+s,y:n+r}]}function cX(e,t){if(!e||e.length===0)return null;const[n]=e;return n[t]}function x$(e,t,n){return t===void 0&&(t=e.left),n===void 0&&(n=e.top),{x:t+e.width*.5,y:n+e.height*.5}}const ey=e=>{let{collisionRect:t,droppableRects:n,droppableContainers:r}=e;const s=x$(t,t.left,t.top),o=[];for(const i of r){const{id:a}=i,l=n.get(a);if(l){const u=aX(x$(l),s);o.push({id:a,data:{droppableContainer:i,value:u}})}}return o.sort(lX)},YLe=e=>{let{collisionRect:t,droppableRects:n,droppableContainers:r}=e;const s=b$(t),o=[];for(const i of r){const{id:a}=i,l=n.get(a);if(l){const u=b$(l),d=s.reduce((h,m,p)=>h+aX(u[p],m),0),f=Number((d/4).toFixed(4));o.push({id:a,data:{droppableContainer:i,value:f}})}}return o.sort(lX)};function GLe(e,t){const n=Math.max(t.top,e.top),r=Math.max(t.left,e.left),s=Math.min(t.left+t.width,e.left+e.width),o=Math.min(t.top+t.height,e.top+e.height),i=s-r,a=o-n;if(r<s&&n<o){const l=t.width*t.height,u=e.width*e.height,d=i*a,f=d/(l+u-d);return Number(f.toFixed(4))}return 0}const KLe=e=>{let{collisionRect:t,droppableRects:n,droppableContainers:r}=e;const s=[];for(const o of r){const{id:i}=o,a=n.get(i);if(a){const l=GLe(a,t);l>0&&s.push({id:i,data:{droppableContainer:o,value:l}})}}return s.sort(qLe)};function ZLe(e,t,n){return{...e,scaleX:t&&n?t.width/n.width:1,scaleY:t&&n?t.height/n.height:1}}function uX(e,t){return e&&t?{x:e.left-t.left,y:e.top-t.top}:Vi}function XLe(e){return function(n){for(var r=arguments.length,s=new Array(r>1?r-1:0),o=1;o<r;o++)s[o-1]=arguments[o];return s.reduce((i,a)=>({...i,top:i.top+e*a.y,bottom:i.bottom+e*a.y,left:i.left+e*a.x,right:i.right+e*a.x}),{...n})}}const QLe=XLe(1);function dX(e){if(e.startsWith("matrix3d(")){const t=e.slice(9,-1).split(/, /);return{x:+t[12],y:+t[13],scaleX:+t[0],scaleY:+t[5]}}else if(e.startsWith("matrix(")){const t=e.slice(7,-1).split(/, /);return{x:+t[4],y:+t[5],scaleX:+t[0],scaleY:+t[3]}}return null}function JLe(e,t,n){const r=dX(t);if(!r)return e;const{scaleX:s,scaleY:o,x:i,y:a}=r,l=e.left-i-(1-s)*parseFloat(n),u=e.top-a-(1-o)*parseFloat(n.slice(n.indexOf(" ")+1)),d=s?e.width/s:e.width,f=o?e.height/o:e.height;return{width:d,height:f,top:u,right:l+d,bottom:u+f,left:l}}const e6e={ignoreTransform:!1};function ip(e,t){t===void 0&&(t=e6e);let n=e.getBoundingClientRect();if(t.ignoreTransform){const{transform:u,transformOrigin:d}=Vs(e).getComputedStyle(e);u&&(n=JLe(n,u,d))}const{top:r,left:s,width:o,height:i,bottom:a,right:l}=n;return{top:r,left:s,width:o,height:i,bottom:a,right:l}}function y$(e){return ip(e,{ignoreTransform:!0})}function t6e(e){const t=e.innerWidth,n=e.innerHeight;return{top:0,left:0,right:t,bottom:n,width:t,height:n}}function n6e(e,t){return t===void 0&&(t=Vs(e).getComputedStyle(e)),t.position==="fixed"}function r6e(e,t){t===void 0&&(t=Vs(e).getComputedStyle(e));const n=/(auto|scroll|overlay)/;return["overflow","overflowX","overflowY"].some(s=>{const o=t[s];return typeof o=="string"?n.test(o):!1})}function cC(e,t){const n=[];function r(s){if(t!=null&&n.length>=t||!s)return n;if(EI(s)&&s.scrollingElement!=null&&!n.includes(s.scrollingElement))return n.push(s.scrollingElement),n;if(!Xx(s)||sX(s)||n.includes(s))return n;const o=Vs(e).getComputedStyle(s);return s!==e&&r6e(s,o)&&n.push(s),n6e(s,o)?n:r(s.parentNode)}return e?r(e):n}function fX(e){const[t]=cC(e,1);return t??null}function s2(e){return!oC||!e?null:sp(e)?e:kI(e)?EI(e)||e===op(e).scrollingElement?window:Xx(e)?e:null:null}function hX(e){return sp(e)?e.scrollX:e.scrollLeft}function mX(e){return sp(e)?e.scrollY:e.scrollTop}function h_(e){return{x:hX(e),y:mX(e)}}var Or;(function(e){e[e.Forward=1]="Forward",e[e.Backward=-1]="Backward"})(Or||(Or={}));function pX(e){return!oC||!e?!1:e===document.scrollingElement}function gX(e){const t={x:0,y:0},n=pX(e)?{height:window.innerHeight,width:window.innerWidth}:{height:e.clientHeight,width:e.clientWidth},r={x:e.scrollWidth-n.width,y:e.scrollHeight-n.height},s=e.scrollTop<=t.y,o=e.scrollLeft<=t.x,i=e.scrollTop>=r.y,a=e.scrollLeft>=r.x;return{isTop:s,isLeft:o,isBottom:i,isRight:a,maxScroll:r,minScroll:t}}const s6e={x:.2,y:.2};function o6e(e,t,n,r,s){let{top:o,left:i,right:a,bottom:l}=n;r===void 0&&(r=10),s===void 0&&(s=s6e);const{isTop:u,isBottom:d,isLeft:f,isRight:h}=gX(e),m={x:0,y:0},p={x:0,y:0},g={height:t.height*s.y,width:t.width*s.x};return!u&&o<=t.top+g.height?(m.y=Or.Backward,p.y=r*Math.abs((t.top+g.height-o)/g.height)):!d&&l>=t.bottom-g.height&&(m.y=Or.Forward,p.y=r*Math.abs((t.bottom-g.height-l)/g.height)),!h&&a>=t.right-g.width?(m.x=Or.Forward,p.x=r*Math.abs((t.right-g.width-a)/g.width)):!f&&i<=t.left+g.width&&(m.x=Or.Backward,p.x=r*Math.abs((t.left+g.width-i)/g.width)),{direction:m,speed:p}}function i6e(e){if(e===document.scrollingElement){const{innerWidth:o,innerHeight:i}=window;return{top:0,left:0,right:o,bottom:i,width:o,height:i}}const{top:t,left:n,right:r,bottom:s}=e.getBoundingClientRect();return{top:t,left:n,right:r,bottom:s,width:e.clientWidth,height:e.clientHeight}}function bX(e){return e.reduce((t,n)=>uh(t,h_(n)),Vi)}function a6e(e){return e.reduce((t,n)=>t+hX(n),0)}function l6e(e){return e.reduce((t,n)=>t+mX(n),0)}function xX(e,t){if(t===void 0&&(t=ip),!e)return;const{top:n,left:r,bottom:s,right:o}=t(e);fX(e)&&(s<=0||o<=0||n>=window.innerHeight||r>=window.innerWidth)&&e.scrollIntoView({block:"center",inline:"center"})}const c6e=[["x",["left","right"],a6e],["y",["top","bottom"],l6e]];class _I{constructor(t,n){this.rect=void 0,this.width=void 0,this.height=void 0,this.top=void 0,this.bottom=void 0,this.right=void 0,this.left=void 0;const r=cC(n),s=bX(r);this.rect={...t},this.width=t.width,this.height=t.height;for(const[o,i,a]of c6e)for(const l of i)Object.defineProperty(this,l,{get:()=>{const u=a(r),d=s[o]-u;return this.rect[l]+d},enumerable:!0});Object.defineProperty(this,"rect",{enumerable:!1})}}class Mg{constructor(t){this.target=void 0,this.listeners=[],this.removeAll=()=>{this.listeners.forEach(n=>{var r;return(r=this.target)==null?void 0:r.removeEventListener(...n)})},this.target=t}add(t,n,r){var s;(s=this.target)==null||s.addEventListener(t,n,r),this.listeners.push([t,n,r])}}function u6e(e){const{EventTarget:t}=Vs(e);return e instanceof t?e:op(e)}function o2(e,t){const n=Math.abs(e.x),r=Math.abs(e.y);return typeof t=="number"?Math.sqrt(n**2+r**2)>t:"x"in t&&"y"in t?n>t.x&&r>t.y:"x"in t?n>t.x:"y"in t?r>t.y:!1}var Bo;(function(e){e.Click="click",e.DragStart="dragstart",e.Keydown="keydown",e.ContextMenu="contextmenu",e.Resize="resize",e.SelectionChange="selectionchange",e.VisibilityChange="visibilitychange"})(Bo||(Bo={}));function v$(e){e.preventDefault()}function d6e(e){e.stopPropagation()}var Wt;(function(e){e.Space="Space",e.Down="ArrowDown",e.Right="ArrowRight",e.Left="ArrowLeft",e.Up="ArrowUp",e.Esc="Escape",e.Enter="Enter",e.Tab="Tab"})(Wt||(Wt={}));const yX={start:[Wt.Space,Wt.Enter],cancel:[Wt.Esc],end:[Wt.Space,Wt.Enter,Wt.Tab]},f6e=(e,t)=>{let{currentCoordinates:n}=t;switch(e.code){case Wt.Right:return{...n,x:n.x+25};case Wt.Left:return{...n,x:n.x-25};case Wt.Down:return{...n,y:n.y+25};case Wt.Up:return{...n,y:n.y-25}}};class ty{constructor(t){this.props=void 0,this.autoScrollEnabled=!1,this.referenceCoordinates=void 0,this.listeners=void 0,this.windowListeners=void 0,this.props=t;const{event:{target:n}}=t;this.props=t,this.listeners=new Mg(op(n)),this.windowListeners=new Mg(Vs(n)),this.handleKeyDown=this.handleKeyDown.bind(this),this.handleCancel=this.handleCancel.bind(this),this.attach()}attach(){this.handleStart(),this.windowListeners.add(Bo.Resize,this.handleCancel),this.windowListeners.add(Bo.VisibilityChange,this.handleCancel),setTimeout(()=>this.listeners.add(Bo.Keydown,this.handleKeyDown))}handleStart(){const{activeNode:t,onStart:n}=this.props,r=t.node.current;r&&xX(r),n(Vi)}handleKeyDown(t){if(aC(t)){const{active:n,context:r,options:s}=this.props,{keyboardCodes:o=yX,coordinateGetter:i=f6e,scrollBehavior:a="smooth"}=s,{code:l}=t;if(o.end.includes(l)){this.handleEnd(t);return}if(o.cancel.includes(l)){this.handleCancel(t);return}const{collisionRect:u}=r.current,d=u?{x:u.left,y:u.top}:Vi;this.referenceCoordinates||(this.referenceCoordinates=d);const f=i(t,{active:n,context:r.current,currentCoordinates:d});if(f){const h=Db(f,d),m={x:0,y:0},{scrollableAncestors:p}=r.current;for(const g of p){const b=t.code,{isTop:x,isRight:y,isLeft:v,isBottom:w,maxScroll:N,minScroll:S}=gX(g),j=i6e(g),E={x:Math.min(b===Wt.Right?j.right-j.width/2:j.right,Math.max(b===Wt.Right?j.left:j.left+j.width/2,f.x)),y:Math.min(b===Wt.Down?j.bottom-j.height/2:j.bottom,Math.max(b===Wt.Down?j.top:j.top+j.height/2,f.y))},_=b===Wt.Right&&!y||b===Wt.Left&&!v,k=b===Wt.Down&&!w||b===Wt.Up&&!x;if(_&&E.x!==f.x){const M=g.scrollLeft+h.x,D=b===Wt.Right&&M<=N.x||b===Wt.Left&&M>=S.x;if(D&&!h.y){g.scrollTo({left:M,behavior:a});return}D?m.x=g.scrollLeft-M:m.x=b===Wt.Right?g.scrollLeft-N.x:g.scrollLeft-S.x,m.x&&g.scrollBy({left:-m.x,behavior:a});break}else if(k&&E.y!==f.y){const M=g.scrollTop+h.y,D=b===Wt.Down&&M<=N.y||b===Wt.Up&&M>=S.y;if(D&&!h.x){g.scrollTo({top:M,behavior:a});return}D?m.y=g.scrollTop-M:m.y=b===Wt.Down?g.scrollTop-N.y:g.scrollTop-S.y,m.y&&g.scrollBy({top:-m.y,behavior:a});break}}this.handleMove(t,uh(Db(f,this.referenceCoordinates),m))}}}handleMove(t,n){const{onMove:r}=this.props;t.preventDefault(),r(n)}handleEnd(t){const{onEnd:n}=this.props;t.preventDefault(),this.detach(),n()}handleCancel(t){const{onCancel:n}=this.props;t.preventDefault(),this.detach(),n()}detach(){this.listeners.removeAll(),this.windowListeners.removeAll()}}ty.activators=[{eventName:"onKeyDown",handler:(e,t,n)=>{let{keyboardCodes:r=yX,onActivation:s}=t,{active:o}=n;const{code:i}=e.nativeEvent;if(r.start.includes(i)){const a=o.activatorNode.current;return a&&e.target!==a?!1:(e.preventDefault(),s==null||s({event:e.nativeEvent}),!0)}return!1}}];function w$(e){return!!(e&&"distance"in e)}function S$(e){return!!(e&&"delay"in e)}class DI{constructor(t,n,r){var s;r===void 0&&(r=u6e(t.event.target)),this.props=void 0,this.events=void 0,this.autoScrollEnabled=!0,this.document=void 0,this.activated=!1,this.initialCoordinates=void 0,this.timeoutId=null,this.listeners=void 0,this.documentListeners=void 0,this.windowListeners=void 0,this.props=t,this.events=n;const{event:o}=t,{target:i}=o;this.props=t,this.events=n,this.document=op(i),this.documentListeners=new Mg(this.document),this.listeners=new Mg(r),this.windowListeners=new Mg(Vs(i)),this.initialCoordinates=(s=Uw(o))!=null?s:Vi,this.handleStart=this.handleStart.bind(this),this.handleMove=this.handleMove.bind(this),this.handleEnd=this.handleEnd.bind(this),this.handleCancel=this.handleCancel.bind(this),this.handleKeydown=this.handleKeydown.bind(this),this.removeTextSelection=this.removeTextSelection.bind(this),this.attach()}attach(){const{events:t,props:{options:{activationConstraint:n,bypassActivationConstraint:r}}}=this;if(this.listeners.add(t.move.name,this.handleMove,{passive:!1}),this.listeners.add(t.end.name,this.handleEnd),t.cancel&&this.listeners.add(t.cancel.name,this.handleCancel),this.windowListeners.add(Bo.Resize,this.handleCancel),this.windowListeners.add(Bo.DragStart,v$),this.windowListeners.add(Bo.VisibilityChange,this.handleCancel),this.windowListeners.add(Bo.ContextMenu,v$),this.documentListeners.add(Bo.Keydown,this.handleKeydown),n){if(r!=null&&r({event:this.props.event,activeNode:this.props.activeNode,options:this.props.options}))return this.handleStart();if(S$(n)){this.timeoutId=setTimeout(this.handleStart,n.delay),this.handlePending(n);return}if(w$(n)){this.handlePending(n);return}}this.handleStart()}detach(){this.listeners.removeAll(),this.windowListeners.removeAll(),setTimeout(this.documentListeners.removeAll,50),this.timeoutId!==null&&(clearTimeout(this.timeoutId),this.timeoutId=null)}handlePending(t,n){const{active:r,onPending:s}=this.props;s(r,t,this.initialCoordinates,n)}handleStart(){const{initialCoordinates:t}=this,{onStart:n}=this.props;t&&(this.activated=!0,this.documentListeners.add(Bo.Click,d6e,{capture:!0}),this.removeTextSelection(),this.documentListeners.add(Bo.SelectionChange,this.removeTextSelection),n(t))}handleMove(t){var n;const{activated:r,initialCoordinates:s,props:o}=this,{onMove:i,options:{activationConstraint:a}}=o;if(!s)return;const l=(n=Uw(t))!=null?n:Vi,u=Db(s,l);if(!r&&a){if(w$(a)){if(a.tolerance!=null&&o2(u,a.tolerance))return this.handleCancel();if(o2(u,a.distance))return this.handleStart()}if(S$(a)&&o2(u,a.tolerance))return this.handleCancel();this.handlePending(a,u);return}t.cancelable&&t.preventDefault(),i(l)}handleEnd(){const{onAbort:t,onEnd:n}=this.props;this.detach(),this.activated||t(this.props.active),n()}handleCancel(){const{onAbort:t,onCancel:n}=this.props;this.detach(),this.activated||t(this.props.active),n()}handleKeydown(t){t.code===Wt.Esc&&this.handleCancel()}removeTextSelection(){var t;(t=this.document.getSelection())==null||t.removeAllRanges()}}const h6e={cancel:{name:"pointercancel"},move:{name:"pointermove"},end:{name:"pointerup"}};class ap extends DI{constructor(t){const{event:n}=t,r=op(n.target);super(t,h6e,r)}}ap.activators=[{eventName:"onPointerDown",handler:(e,t)=>{let{nativeEvent:n}=e,{onActivation:r}=t;return!n.isPrimary||n.button!==0?!1:(r==null||r({event:n}),!0)}}];const m6e={move:{name:"mousemove"},end:{name:"mouseup"}};var m_;(function(e){e[e.RightClick=2]="RightClick"})(m_||(m_={}));class p6e extends DI{constructor(t){super(t,m6e,op(t.event.target))}}p6e.activators=[{eventName:"onMouseDown",handler:(e,t)=>{let{nativeEvent:n}=e,{onActivation:r}=t;return n.button===m_.RightClick?!1:(r==null||r({event:n}),!0)}}];const i2={cancel:{name:"touchcancel"},move:{name:"touchmove"},end:{name:"touchend"}};class g6e extends DI{constructor(t){super(t,i2)}static setup(){return window.addEventListener(i2.move.name,t,{capture:!1,passive:!1}),function(){window.removeEventListener(i2.move.name,t)};function t(){}}}g6e.activators=[{eventName:"onTouchStart",handler:(e,t)=>{let{nativeEvent:n}=e,{onActivation:r}=t;const{touches:s}=n;return s.length>1?!1:(r==null||r({event:n}),!0)}}];var Tg;(function(e){e[e.Pointer=0]="Pointer",e[e.DraggableRect=1]="DraggableRect"})(Tg||(Tg={}));var qw;(function(e){e[e.TreeOrder=0]="TreeOrder",e[e.ReversedTreeOrder=1]="ReversedTreeOrder"})(qw||(qw={}));function b6e(e){let{acceleration:t,activator:n=Tg.Pointer,canScroll:r,draggingRect:s,enabled:o,interval:i=5,order:a=qw.TreeOrder,pointerCoordinates:l,scrollableAncestors:u,scrollableAncestorRects:d,delta:f,threshold:h}=e;const m=y6e({delta:f,disabled:!o}),[p,g]=RLe(),b=C.useRef({x:0,y:0}),x=C.useRef({x:0,y:0}),y=C.useMemo(()=>{switch(n){case Tg.Pointer:return l?{top:l.y,bottom:l.y,left:l.x,right:l.x}:null;case Tg.DraggableRect:return s}},[n,s,l]),v=C.useRef(null),w=C.useCallback(()=>{const S=v.current;if(!S)return;const j=b.current.x*x.current.x,E=b.current.y*x.current.y;S.scrollBy(j,E)},[]),N=C.useMemo(()=>a===qw.TreeOrder?[...u].reverse():u,[a,u]);C.useEffect(()=>{if(!o||!u.length||!y){g();return}for(const S of N){if((r==null?void 0:r(S))===!1)continue;const j=u.indexOf(S),E=d[j];if(!E)continue;const{direction:_,speed:k}=o6e(S,E,y,t,h);for(const M of["x","y"])m[M][_[M]]||(k[M]=0,_[M]=0);if(k.x>0||k.y>0){g(),v.current=S,p(w,i),b.current=k,x.current=_;return}}b.current={x:0,y:0},x.current={x:0,y:0},g()},[t,w,r,g,o,i,JSON.stringify(y),JSON.stringify(m),p,u,N,d,JSON.stringify(h)])}const x6e={x:{[Or.Backward]:!1,[Or.Forward]:!1},y:{[Or.Backward]:!1,[Or.Forward]:!1}};function y6e(e){let{delta:t,disabled:n}=e;const r=Hw(t);return Qx(s=>{if(n||!r||!s)return x6e;const o={x:Math.sign(t.x-r.x),y:Math.sign(t.y-r.y)};return{x:{[Or.Backward]:s.x[Or.Backward]||o.x===-1,[Or.Forward]:s.x[Or.Forward]||o.x===1},y:{[Or.Backward]:s.y[Or.Backward]||o.y===-1,[Or.Forward]:s.y[Or.Forward]||o.y===1}}},[n,t,r])}function v6e(e,t){const n=t!=null?e.get(t):void 0,r=n?n.node.current:null;return Qx(s=>{var o;return t==null?null:(o=r??s)!=null?o:null},[r,t])}function w6e(e,t){return C.useMemo(()=>e.reduce((n,r)=>{const{sensor:s}=r,o=s.activators.map(i=>({eventName:i.eventName,handler:t(i.handler,r)}));return[...n,...o]},[]),[e,t])}var Mb;(function(e){e[e.Always=0]="Always",e[e.BeforeDragging=1]="BeforeDragging",e[e.WhileDragging=2]="WhileDragging"})(Mb||(Mb={}));var p_;(function(e){e.Optimized="optimized"})(p_||(p_={}));const C$=new Map;function S6e(e,t){let{dragging:n,dependencies:r,config:s}=t;const[o,i]=C.useState(null),{frequency:a,measure:l,strategy:u}=s,d=C.useRef(e),f=b(),h=_b(f),m=C.useCallback(function(x){x===void 0&&(x=[]),!h.current&&i(y=>y===null?x:y.concat(x.filter(v=>!y.includes(v))))},[h]),p=C.useRef(null),g=Qx(x=>{if(f&&!n)return C$;if(!x||x===C$||d.current!==e||o!=null){const y=new Map;for(let v of e){if(!v)continue;if(o&&o.length>0&&!o.includes(v.id)&&v.rect.current){y.set(v.id,v.rect.current);continue}const w=v.node.current,N=w?new _I(l(w),w):null;v.rect.current=N,N&&y.set(v.id,N)}return y}return x},[e,o,n,f,l]);return C.useEffect(()=>{d.current=e},[e]),C.useEffect(()=>{f||m()},[n,f]),C.useEffect(()=>{o&&o.length>0&&i(null)},[JSON.stringify(o)]),C.useEffect(()=>{f||typeof a!="number"||p.current!==null||(p.current=setTimeout(()=>{m(),p.current=null},a))},[a,f,m,...r]),{droppableRects:g,measureDroppableContainers:m,measuringScheduled:o!=null};function b(){switch(u){case Mb.Always:return!1;case Mb.BeforeDragging:return n;default:return!n}}}function MI(e,t){return Qx(n=>e?n||(typeof t=="function"?t(e):e):null,[t,e])}function C6e(e,t){return MI(e,t)}function N6e(e){let{callback:t,disabled:n}=e;const r=iC(t),s=C.useMemo(()=>{if(n||typeof window>"u"||typeof window.MutationObserver>"u")return;const{MutationObserver:o}=window;return new o(r)},[r,n]);return C.useEffect(()=>()=>s==null?void 0:s.disconnect(),[s]),s}function uC(e){let{callback:t,disabled:n}=e;const r=iC(t),s=C.useMemo(()=>{if(n||typeof window>"u"||typeof window.ResizeObserver>"u")return;const{ResizeObserver:o}=window;return new o(r)},[n]);return C.useEffect(()=>()=>s==null?void 0:s.disconnect(),[s]),s}function j6e(e){return new _I(ip(e),e)}function N$(e,t,n){t===void 0&&(t=j6e);const[r,s]=C.useState(null);function o(){s(l=>{if(!e)return null;if(e.isConnected===!1){var u;return(u=l??n)!=null?u:null}const d=t(e);return JSON.stringify(l)===JSON.stringify(d)?l:d})}const i=N6e({callback(l){if(e)for(const u of l){const{type:d,target:f}=u;if(d==="childList"&&f instanceof HTMLElement&&f.contains(e)){o();break}}}}),a=uC({callback:o});return Bi(()=>{o(),e?(a==null||a.observe(e),i==null||i.observe(document.body,{childList:!0,subtree:!0})):(a==null||a.disconnect(),i==null||i.disconnect())},[e]),r}function k6e(e){const t=MI(e);return uX(e,t)}const j$=[];function E6e(e){const t=C.useRef(e),n=Qx(r=>e?r&&r!==j$&&e&&t.current&&e.parentNode===t.current.parentNode?r:cC(e):j$,[e]);return C.useEffect(()=>{t.current=e},[e]),n}function _6e(e){const[t,n]=C.useState(null),r=C.useRef(e),s=C.useCallback(o=>{const i=s2(o.target);i&&n(a=>a?(a.set(i,h_(i)),new Map(a)):null)},[]);return C.useEffect(()=>{const o=r.current;if(e!==o){i(o);const a=e.map(l=>{const u=s2(l);return u?(u.addEventListener("scroll",s,{passive:!0}),[u,h_(u)]):null}).filter(l=>l!=null);n(a.length?new Map(a):null),r.current=e}return()=>{i(e),i(o)};function i(a){a.forEach(l=>{const u=s2(l);u==null||u.removeEventListener("scroll",s)})}},[s,e]),C.useMemo(()=>e.length?t?Array.from(t.values()).reduce((o,i)=>uh(o,i),Vi):bX(e):Vi,[e,t])}function k$(e,t){t===void 0&&(t=[]);const n=C.useRef(null);return C.useEffect(()=>{n.current=null},t),C.useEffect(()=>{const r=e!==Vi;r&&!n.current&&(n.current=e),!r&&n.current&&(n.current=null)},[e]),n.current?Db(e,n.current):Vi}function D6e(e){C.useEffect(()=>{if(!oC)return;const t=e.map(n=>{let{sensor:r}=n;return r.setup==null?void 0:r.setup()});return()=>{for(const n of t)n==null||n()}},e.map(t=>{let{sensor:n}=t;return n}))}function M6e(e,t){return C.useMemo(()=>e.reduce((n,r)=>{let{eventName:s,handler:o}=r;return n[s]=i=>{o(i,t)},n},{}),[e,t])}function vX(e){return C.useMemo(()=>e?t6e(e):null,[e])}const E$=[];function T6e(e,t){t===void 0&&(t=ip);const[n]=e,r=vX(n?Vs(n):null),[s,o]=C.useState(E$);function i(){o(()=>e.length?e.map(l=>pX(l)?r:new _I(t(l),l)):E$)}const a=uC({callback:i});return Bi(()=>{a==null||a.disconnect(),i(),e.forEach(l=>a==null?void 0:a.observe(l))},[e]),s}function wX(e){if(!e)return null;if(e.children.length>1)return e;const t=e.children[0];return Xx(t)?t:e}function R6e(e){let{measure:t}=e;const[n,r]=C.useState(null),s=C.useCallback(u=>{for(const{target:d}of u)if(Xx(d)){r(f=>{const h=t(d);return f?{...f,width:h.width,height:h.height}:h});break}},[t]),o=uC({callback:s}),i=C.useCallback(u=>{const d=wX(u);o==null||o.disconnect(),d&&(o==null||o.observe(d)),r(d?t(d):null)},[t,o]),[a,l]=Vw(i);return C.useMemo(()=>({nodeRef:a,rect:n,setRef:l}),[n,a,l])}const I6e=[{sensor:ap,options:{}},{sensor:ty,options:{}}],A6e={current:{}},pv={draggable:{measure:y$},droppable:{measure:y$,strategy:Mb.WhileDragging,frequency:p_.Optimized},dragOverlay:{measure:ip}};class Rg extends Map{get(t){var n;return t!=null&&(n=super.get(t))!=null?n:void 0}toArray(){return Array.from(this.values())}getEnabled(){return this.toArray().filter(t=>{let{disabled:n}=t;return!n})}getNodeFor(t){var n,r;return(n=(r=this.get(t))==null?void 0:r.node.current)!=null?n:void 0}}const P6e={activatorEvent:null,active:null,activeNode:null,activeNodeRect:null,collisions:null,containerNodeRect:null,draggableNodes:new Map,droppableRects:new Map,droppableContainers:new Rg,over:null,dragOverlay:{nodeRef:{current:null},rect:null,setRef:Ww},scrollableAncestors:[],scrollableAncestorRects:[],measuringConfiguration:pv,measureDroppableContainers:Ww,windowRect:null,measuringScheduled:!1},SX={activatorEvent:null,activators:[],active:null,activeNodeRect:null,ariaDescribedById:{draggable:""},dispatch:Ww,draggableNodes:new Map,over:null,measureDroppableContainers:Ww},ny=C.createContext(SX),CX=C.createContext(P6e);function O6e(){return{draggable:{active:null,initialCoordinates:{x:0,y:0},nodes:new Map,translate:{x:0,y:0}},droppable:{containers:new Rg}}}function F6e(e,t){switch(t.type){case _r.DragStart:return{...e,draggable:{...e.draggable,initialCoordinates:t.initialCoordinates,active:t.active}};case _r.DragMove:return e.draggable.active==null?e:{...e,draggable:{...e.draggable,translate:{x:t.coordinates.x-e.draggable.initialCoordinates.x,y:t.coordinates.y-e.draggable.initialCoordinates.y}}};case _r.DragEnd:case _r.DragCancel:return{...e,draggable:{...e.draggable,active:null,initialCoordinates:{x:0,y:0},translate:{x:0,y:0}}};case _r.RegisterDroppable:{const{element:n}=t,{id:r}=n,s=new Rg(e.droppable.containers);return s.set(r,n),{...e,droppable:{...e.droppable,containers:s}}}case _r.SetDroppableDisabled:{const{id:n,key:r,disabled:s}=t,o=e.droppable.containers.get(n);if(!o||r!==o.key)return e;const i=new Rg(e.droppable.containers);return i.set(n,{...o,disabled:s}),{...e,droppable:{...e.droppable,containers:i}}}case _r.UnregisterDroppable:{const{id:n,key:r}=t,s=e.droppable.containers.get(n);if(!s||r!==s.key)return e;const o=new Rg(e.droppable.containers);return o.delete(n),{...e,droppable:{...e.droppable,containers:o}}}default:return e}}function $6e(e){let{disabled:t}=e;const{active:n,activatorEvent:r,draggableNodes:s}=C.useContext(ny),o=Hw(r),i=Hw(n==null?void 0:n.id);return C.useEffect(()=>{if(!t&&!r&&o&&i!=null){if(!aC(o)||document.activeElement===o.target)return;const a=s.get(i);if(!a)return;const{activatorNode:l,node:u}=a;if(!l.current&&!u.current)return;requestAnimationFrame(()=>{for(const d of[l.current,u.current]){if(!d)continue;const f=PLe(d);if(f){f.focus();break}}})}},[r,t,s,i,o]),null}function NX(e,t){let{transform:n,...r}=t;return e!=null&&e.length?e.reduce((s,o)=>o({transform:s,...r}),n):n}function L6e(e){return C.useMemo(()=>({draggable:{...pv.draggable,...e==null?void 0:e.draggable},droppable:{...pv.droppable,...e==null?void 0:e.droppable},dragOverlay:{...pv.dragOverlay,...e==null?void 0:e.dragOverlay}}),[e==null?void 0:e.draggable,e==null?void 0:e.droppable,e==null?void 0:e.dragOverlay])}function z6e(e){let{activeNode:t,measure:n,initialRect:r,config:s=!0}=e;const o=C.useRef(!1),{x:i,y:a}=typeof s=="boolean"?{x:s,y:s}:s;Bi(()=>{if(!i&&!a||!t){o.current=!1;return}if(o.current||!r)return;const u=t==null?void 0:t.node.current;if(!u||u.isConnected===!1)return;const d=n(u),f=uX(d,r);if(i||(f.x=0),a||(f.y=0),o.current=!0,Math.abs(f.x)>0||Math.abs(f.y)>0){const h=fX(u);h&&h.scrollBy({top:f.y,left:f.x})}},[t,i,a,r,n])}const dC=C.createContext({...Vi,scaleX:1,scaleY:1});var rc;(function(e){e[e.Uninitialized=0]="Uninitialized",e[e.Initializing=1]="Initializing",e[e.Initialized=2]="Initialized"})(rc||(rc={}));const ry=C.memo(function(t){var n,r,s,o;let{id:i,accessibility:a,autoScroll:l=!0,children:u,sensors:d=I6e,collisionDetection:f=KLe,measuring:h,modifiers:m,...p}=t;const g=C.useReducer(F6e,void 0,O6e),[b,x]=g,[y,v]=BLe(),[w,N]=C.useState(rc.Uninitialized),S=w===rc.Initialized,{draggable:{active:j,nodes:E,translate:_},droppable:{containers:k}}=b,M=j!=null?E.get(j):null,D=C.useRef({initial:null,translated:null}),R=C.useMemo(()=>{var Le;return j!=null?{id:j,data:(Le=M==null?void 0:M.data)!=null?Le:A6e,rect:D}:null},[j,M]),P=C.useRef(null),[I,L]=C.useState(null),[F,H]=C.useState(null),$=_b(p,Object.values(p)),A=Jx("DndDescribedBy",i),q=C.useMemo(()=>k.getEnabled(),[k]),z=L6e(h),{droppableRects:O,measureDroppableContainers:W,measuringScheduled:B}=S6e(q,{dragging:S,dependencies:[_.x,_.y],config:z.droppable}),Y=v6e(E,j),U=C.useMemo(()=>F?Uw(F):null,[F]),V=Qe(),G=C6e(Y,z.draggable.measure);z6e({activeNode:j!=null?E.get(j):null,config:V.layoutShiftCompensation,initialRect:G,measure:z.draggable.measure});const K=N$(Y,z.draggable.measure,G),J=N$(Y?Y.parentElement:null),Q=C.useRef({activatorEvent:null,active:null,activeNode:Y,collisionRect:null,collisions:null,droppableRects:O,draggableNodes:E,draggingNode:null,draggingNodeRect:null,droppableContainers:k,over:null,scrollableAncestors:[],scrollAdjustedTranslate:null}),re=k.getNodeFor((n=Q.current.over)==null?void 0:n.id),de=R6e({measure:z.dragOverlay.measure}),fe=(r=de.nodeRef.current)!=null?r:Y,ue=S?(s=de.rect)!=null?s:K:null,je=!!(de.nodeRef.current&&de.rect),me=k6e(je?null:K),ne=vX(fe?Vs(fe):null),oe=E6e(S?re??Y:null),pe=T6e(oe),De=NX(m,{transform:{x:_.x-me.x,y:_.y-me.y,scaleX:1,scaleY:1},activatorEvent:F,active:R,activeNodeRect:K,containerNodeRect:J,draggingNodeRect:ue,over:Q.current.over,overlayNodeRect:de.rect,scrollableAncestors:oe,scrollableAncestorRects:pe,windowRect:ne}),ae=U?uh(U,_):null,Te=_6e(oe),Ue=k$(Te),ie=k$(Te,[K]),xe=uh(De,Ue),$e=ue?QLe(ue,De):null,he=R&&$e?f({active:R,collisionRect:$e,droppableRects:O,droppableContainers:q,pointerCoordinates:ae}):null,Ee=cX(he,"id"),[Ve,qe]=C.useState(null),Ae=je?De:uh(De,ie),xt=ZLe(Ae,(o=Ve==null?void 0:Ve.rect)!=null?o:null,K),Ce=C.useRef(null),mt=C.useCallback((Le,ve)=>{let{sensor:Be,options:we}=ve;if(P.current==null)return;const We=E.get(P.current);if(!We)return;const at=Le.nativeEvent,pn=new Be({active:P.current,activeNode:We,event:at,options:we,context:Q,onAbort(Ht){if(!E.get(Ht))return;const{onDragAbort:Vn}=$.current,gr={id:Ht};Vn==null||Vn(gr),y({type:"onDragAbort",event:gr})},onPending(Ht,Ir,Vn,gr){if(!E.get(Ht))return;const{onDragPending:Ao}=$.current,Zi={id:Ht,constraint:Ir,initialCoordinates:Vn,offset:gr};Ao==null||Ao(Zi),y({type:"onDragPending",event:Zi})},onStart(Ht){const Ir=P.current;if(Ir==null)return;const Vn=E.get(Ir);if(!Vn)return;const{onDragStart:gr}=$.current,xu={activatorEvent:at,active:{id:Ir,data:Vn.data,rect:D}};Ln.unstable_batchedUpdates(()=>{gr==null||gr(xu),N(rc.Initializing),x({type:_r.DragStart,initialCoordinates:Ht,active:Ir}),y({type:"onDragStart",event:xu}),L(Ce.current),H(at)})},onMove(Ht){x({type:_r.DragMove,coordinates:Ht})},onEnd:Vt(_r.DragEnd),onCancel:Vt(_r.DragCancel)});Ce.current=pn;function Vt(Ht){return async function(){const{active:Vn,collisions:gr,over:xu,scrollAdjustedTranslate:Ao}=Q.current;let Zi=null;if(Vn&&Ao){const{cancelDrop:yu}=$.current;Zi={activatorEvent:at,active:Vn,collisions:gr,delta:Ao,over:xu},Ht===_r.DragEnd&&typeof yu=="function"&&await Promise.resolve(yu(Zi))&&(Ht=_r.DragCancel)}P.current=null,Ln.unstable_batchedUpdates(()=>{x({type:Ht}),N(rc.Uninitialized),qe(null),L(null),H(null),Ce.current=null;const yu=Ht===_r.DragEnd?"onDragEnd":"onDragCancel";if(Zi){const hp=$.current[yu];hp==null||hp(Zi),y({type:yu,event:Zi})}})}}},[E]),_t=C.useCallback((Le,ve)=>(Be,we)=>{const We=Be.nativeEvent,at=E.get(we);if(P.current!==null||!at||We.dndKit||We.defaultPrevented)return;const pn={active:at};Le(Be,ve.options,pn)===!0&&(We.dndKit={capturedBy:ve.sensor},P.current=we,mt(Be,ve))},[E,mt]),He=w6e(d,_t);D6e(d),Bi(()=>{K&&w===rc.Initializing&&N(rc.Initialized)},[K,w]),C.useEffect(()=>{const{onDragMove:Le}=$.current,{active:ve,activatorEvent:Be,collisions:we,over:We}=Q.current;if(!ve||!Be)return;const at={active:ve,activatorEvent:Be,collisions:we,delta:{x:xe.x,y:xe.y},over:We};Ln.unstable_batchedUpdates(()=>{Le==null||Le(at),y({type:"onDragMove",event:at})})},[xe.x,xe.y]),C.useEffect(()=>{const{active:Le,activatorEvent:ve,collisions:Be,droppableContainers:we,scrollAdjustedTranslate:We}=Q.current;if(!Le||P.current==null||!ve||!We)return;const{onDragOver:at}=$.current,pn=we.get(Ee),Vt=pn&&pn.rect.current?{id:pn.id,rect:pn.rect.current,data:pn.data,disabled:pn.disabled}:null,Ht={active:Le,activatorEvent:ve,collisions:Be,delta:{x:We.x,y:We.y},over:Vt};Ln.unstable_batchedUpdates(()=>{qe(Vt),at==null||at(Ht),y({type:"onDragOver",event:Ht})})},[Ee]),Bi(()=>{Q.current={activatorEvent:F,active:R,activeNode:Y,collisionRect:$e,collisions:he,droppableRects:O,draggableNodes:E,draggingNode:fe,draggingNodeRect:ue,droppableContainers:k,over:Ve,scrollableAncestors:oe,scrollAdjustedTranslate:xe},D.current={initial:ue,translated:$e}},[R,Y,he,$e,E,fe,ue,O,k,Ve,oe,xe]),b6e({...V,delta:_,draggingRect:$e,pointerCoordinates:ae,scrollableAncestors:oe,scrollableAncestorRects:pe});const Jt=C.useMemo(()=>({active:R,activeNode:Y,activeNodeRect:K,activatorEvent:F,collisions:he,containerNodeRect:J,dragOverlay:de,draggableNodes:E,droppableContainers:k,droppableRects:O,over:Ve,measureDroppableContainers:W,scrollableAncestors:oe,scrollableAncestorRects:pe,measuringConfiguration:z,measuringScheduled:B,windowRect:ne}),[R,Y,K,F,he,J,de,E,k,O,Ve,W,oe,pe,z,B,ne]),Ke=C.useMemo(()=>({activatorEvent:F,activators:He,active:R,activeNodeRect:K,ariaDescribedById:{draggable:A},dispatch:x,draggableNodes:E,over:Ve,measureDroppableContainers:W}),[F,He,R,K,x,A,E,Ve,W]);return C.createElement(iX.Provider,{value:v},C.createElement(ny.Provider,{value:Ke},C.createElement(CX.Provider,{value:Jt},C.createElement(dC.Provider,{value:xt},u)),C.createElement($6e,{disabled:(a==null?void 0:a.restoreFocus)===!1})),C.createElement(ULe,{...a,hiddenTextDescribedById:A}));function Qe(){const Le=(I==null?void 0:I.autoScrollEnabled)===!1,ve=typeof l=="object"?l.enabled===!1:l===!1,Be=S&&!Le&&!ve;return typeof l=="object"?{...l,enabled:Be}:{enabled:Be}}}),B6e=C.createContext(null),_$="button",V6e="Draggable";function H6e(e){let{id:t,data:n,disabled:r=!1,attributes:s}=e;const o=Jx(V6e),{activators:i,activatorEvent:a,active:l,activeNodeRect:u,ariaDescribedById:d,draggableNodes:f,over:h}=C.useContext(ny),{role:m=_$,roleDescription:p="draggable",tabIndex:g=0}=s??{},b=(l==null?void 0:l.id)===t,x=C.useContext(b?dC:B6e),[y,v]=Vw(),[w,N]=Vw(),S=M6e(i,t),j=_b(n);Bi(()=>(f.set(t,{id:t,key:o,node:y,activatorNode:w,data:j}),()=>{const _=f.get(t);_&&_.key===o&&f.delete(t)}),[f,t]);const E=C.useMemo(()=>({role:m,tabIndex:g,"aria-disabled":r,"aria-pressed":b&&m===_$?!0:void 0,"aria-roledescription":p,"aria-describedby":d.draggable}),[r,m,g,b,p,d.draggable]);return{active:l,activatorEvent:a,activeNodeRect:u,attributes:E,isDragging:b,listeners:r?void 0:S,node:y,over:h,setNodeRef:v,setActivatorNodeRef:N,transform:x}}function jX(){return C.useContext(CX)}const U6e="Droppable",W6e={timeout:25};function kX(e){let{data:t,disabled:n=!1,id:r,resizeObserverConfig:s}=e;const o=Jx(U6e),{active:i,dispatch:a,over:l,measureDroppableContainers:u}=C.useContext(ny),d=C.useRef({disabled:n}),f=C.useRef(!1),h=C.useRef(null),m=C.useRef(null),{disabled:p,updateMeasurementsFor:g,timeout:b}={...W6e,...s},x=_b(g??r),y=C.useCallback(()=>{if(!f.current){f.current=!0;return}m.current!=null&&clearTimeout(m.current),m.current=setTimeout(()=>{u(Array.isArray(x.current)?x.current:[x.current]),m.current=null},b)},[b]),v=uC({callback:y,disabled:p||!i}),w=C.useCallback((E,_)=>{v&&(_&&(v.unobserve(_),f.current=!1),E&&v.observe(E))},[v]),[N,S]=Vw(w),j=_b(t);return C.useEffect(()=>{!v||!N.current||(v.disconnect(),f.current=!1,v.observe(N.current))},[N,v]),C.useEffect(()=>(a({type:_r.RegisterDroppable,element:{id:r,key:o,disabled:n,node:N,rect:h,data:j}}),()=>a({type:_r.UnregisterDroppable,key:o,id:r})),[r]),C.useEffect(()=>{n!==d.current.disabled&&(a({type:_r.SetDroppableDisabled,id:r,key:o,disabled:n}),d.current.disabled=n)},[r,o,n,a]),{active:i,rect:h,isOver:(l==null?void 0:l.id)===r,node:N,over:l,setNodeRef:S}}function q6e(e){let{animation:t,children:n}=e;const[r,s]=C.useState(null),[o,i]=C.useState(null),a=Hw(n);return!n&&!r&&a&&s(a),Bi(()=>{if(!o)return;const l=r==null?void 0:r.key,u=r==null?void 0:r.props.id;if(l==null||u==null){s(null);return}Promise.resolve(t(u,o)).then(()=>{s(null)})},[t,r,o]),C.createElement(C.Fragment,null,n,r?C.cloneElement(r,{ref:i}):null)}const Y6e={x:0,y:0,scaleX:1,scaleY:1};function G6e(e){let{children:t}=e;return C.createElement(ny.Provider,{value:SX},C.createElement(dC.Provider,{value:Y6e},t))}const K6e={position:"fixed",touchAction:"none"},Z6e=e=>aC(e)?"transform 250ms ease":void 0,X6e=C.forwardRef((e,t)=>{let{as:n,activatorEvent:r,adjustScale:s,children:o,className:i,rect:a,style:l,transform:u,transition:d=Z6e}=e;if(!a)return null;const f=s?u:{...u,scaleX:1,scaleY:1},h={...K6e,width:a.width,height:a.height,top:a.top,left:a.left,transform:ii.Transform.toString(f),transformOrigin:s&&r?WLe(r,a):void 0,transition:typeof d=="function"?d(r):d,...l};return C.createElement(n,{className:i,style:h,ref:t},o)}),Q6e=e=>t=>{let{active:n,dragOverlay:r}=t;const s={},{styles:o,className:i}=e;if(o!=null&&o.active)for(const[a,l]of Object.entries(o.active))l!==void 0&&(s[a]=n.node.style.getPropertyValue(a),n.node.style.setProperty(a,l));if(o!=null&&o.dragOverlay)for(const[a,l]of Object.entries(o.dragOverlay))l!==void 0&&r.node.style.setProperty(a,l);return i!=null&&i.active&&n.node.classList.add(i.active),i!=null&&i.dragOverlay&&r.node.classList.add(i.dragOverlay),function(){for(const[l,u]of Object.entries(s))n.node.style.setProperty(l,u);i!=null&&i.active&&n.node.classList.remove(i.active)}},J6e=e=>{let{transform:{initial:t,final:n}}=e;return[{transform:ii.Transform.toString(t)},{transform:ii.Transform.toString(n)}]},eze={duration:250,easing:"ease",keyframes:J6e,sideEffects:Q6e({styles:{active:{opacity:"0"}}})};function tze(e){let{config:t,draggableNodes:n,droppableContainers:r,measuringConfiguration:s}=e;return iC((o,i)=>{if(t===null)return;const a=n.get(o);if(!a)return;const l=a.node.current;if(!l)return;const u=wX(i);if(!u)return;const{transform:d}=Vs(i).getComputedStyle(i),f=dX(d);if(!f)return;const h=typeof t=="function"?t:nze(t);return xX(l,s.draggable.measure),h({active:{id:o,data:a.data,node:l,rect:s.draggable.measure(l)},draggableNodes:n,dragOverlay:{node:i,rect:s.dragOverlay.measure(u)},droppableContainers:r,measuringConfiguration:s,transform:f})})}function nze(e){const{duration:t,easing:n,sideEffects:r,keyframes:s}={...eze,...e};return o=>{let{active:i,dragOverlay:a,transform:l,...u}=o;if(!t)return;const d={x:a.rect.left-i.rect.left,y:a.rect.top-i.rect.top},f={scaleX:l.scaleX!==1?i.rect.width*l.scaleX/a.rect.width:1,scaleY:l.scaleY!==1?i.rect.height*l.scaleY/a.rect.height:1},h={x:l.x-d.x,y:l.y-d.y,...f},m=s({...u,active:i,dragOverlay:a,transform:{initial:l,final:h}}),[p]=m,g=m[m.length-1];if(JSON.stringify(p)===JSON.stringify(g))return;const b=r==null?void 0:r({active:i,dragOverlay:a,...u}),x=a.node.animate(m,{duration:t,easing:n,fill:"forwards"});return new Promise(y=>{x.onfinish=()=>{b==null||b(),y()}})}}let D$=0;function rze(e){return C.useMemo(()=>{if(e!=null)return D$++,D$},[e])}const EX=C.memo(e=>{let{adjustScale:t=!1,children:n,dropAnimation:r,style:s,transition:o,modifiers:i,wrapperElement:a="div",className:l,zIndex:u=999}=e;const{activatorEvent:d,active:f,activeNodeRect:h,containerNodeRect:m,draggableNodes:p,droppableContainers:g,dragOverlay:b,over:x,measuringConfiguration:y,scrollableAncestors:v,scrollableAncestorRects:w,windowRect:N}=jX(),S=C.useContext(dC),j=rze(f==null?void 0:f.id),E=NX(i,{activatorEvent:d,active:f,activeNodeRect:h,containerNodeRect:m,draggingNodeRect:b.rect,over:x,overlayNodeRect:b.rect,scrollableAncestors:v,scrollableAncestorRects:w,transform:S,windowRect:N}),_=MI(h),k=tze({config:r,draggableNodes:p,droppableContainers:g,measuringConfiguration:y}),M=_?b.setRef:void 0;return C.createElement(G6e,null,C.createElement(q6e,{animation:k},f&&j?C.createElement(X6e,{key:j,id:f.id,ref:M,as:a,activatorEvent:d,adjustScale:t,className:l,transition:o,rect:_,style:{zIndex:u,...s},transform:E},n):null))});function lp(e,t,n){const r=e.slice();return r.splice(n<0?r.length+n:n,0,r.splice(t,1)[0]),r}function sze(e,t){return e.reduce((n,r,s)=>{const o=t.get(r);return o&&(n[s]=o),n},Array(e.length))}function I0(e){return e!==null&&e>=0}function oze(e,t){if(e===t)return!0;if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(e[n]!==t[n])return!1;return!0}function ize(e){return typeof e=="boolean"?{draggable:e,droppable:e}:e}const A0={scaleX:1,scaleY:1},TI=e=>{var t;let{rects:n,activeNodeRect:r,activeIndex:s,overIndex:o,index:i}=e;const a=(t=n[s])!=null?t:r;if(!a)return null;const l=aze(n,i,s);if(i===s){const u=n[o];return u?{x:s<o?u.left+u.width-(a.left+a.width):u.left-a.left,y:0,...A0}:null}return i>s&&i<=o?{x:-a.width-l,y:0,...A0}:i<s&&i>=o?{x:a.width+l,y:0,...A0}:{x:0,y:0,...A0}};function aze(e,t,n){const r=e[t],s=e[t-1],o=e[t+1];return!r||!s&&!o?0:n<t?s?r.left-(s.left+s.width):o.left-(r.left+r.width):o?o.left-(r.left+r.width):r.left-(s.left+s.width)}const _X=e=>{let{rects:t,activeIndex:n,overIndex:r,index:s}=e;const o=lp(t,r,n),i=t[s],a=o[s];return!a||!i?null:{x:a.left-i.left,y:a.top-i.top,scaleX:a.width/i.width,scaleY:a.height/i.height}},P0={scaleX:1,scaleY:1},RI=e=>{var t;let{activeIndex:n,activeNodeRect:r,index:s,rects:o,overIndex:i}=e;const a=(t=o[n])!=null?t:r;if(!a)return null;if(s===n){const u=o[i];return u?{x:0,y:n<i?u.top+u.height-(a.top+a.height):u.top-a.top,...P0}:null}const l=lze(o,s,n);return s>n&&s<=i?{x:0,y:-a.height-l,...P0}:s<n&&s>=i?{x:0,y:a.height+l,...P0}:{x:0,y:0,...P0}};function lze(e,t,n){const r=e[t],s=e[t-1],o=e[t+1];return r?n<t?s?r.top-(s.top+s.height):o?o.top-(r.top+r.height):0:o?o.top-(r.top+r.height):s?r.top-(s.top+s.height):0:0}const DX="Sortable",MX=C.createContext({activeIndex:-1,containerId:DX,disableTransforms:!1,items:[],overIndex:-1,useDragOverlay:!1,sortedRects:[],strategy:_X,disabled:{draggable:!1,droppable:!1}});function sy(e){let{children:t,id:n,items:r,strategy:s=_X,disabled:o=!1}=e;const{active:i,dragOverlay:a,droppableRects:l,over:u,measureDroppableContainers:d}=jX(),f=Jx(DX,n),h=a.rect!==null,m=C.useMemo(()=>r.map(S=>typeof S=="object"&&"id"in S?S.id:S),[r]),p=i!=null,g=i?m.indexOf(i.id):-1,b=u?m.indexOf(u.id):-1,x=C.useRef(m),y=!oze(m,x.current),v=b!==-1&&g===-1||y,w=ize(o);Bi(()=>{y&&p&&d(m)},[y,m,p,d]),C.useEffect(()=>{x.current=m},[m]);const N=C.useMemo(()=>({activeIndex:g,containerId:f,disabled:w,disableTransforms:v,items:m,overIndex:b,useDragOverlay:h,sortedRects:sze(m,l),strategy:s}),[g,f,w.draggable,w.droppable,v,m,b,l,h,s]);return C.createElement(MX.Provider,{value:N},t)}const cze=e=>{let{id:t,items:n,activeIndex:r,overIndex:s}=e;return lp(n,r,s).indexOf(t)},uze=e=>{let{containerId:t,isSorting:n,wasDragging:r,index:s,items:o,newIndex:i,previousItems:a,previousContainerId:l,transition:u}=e;return!u||!r||a!==o&&s===i?!1:n?!0:i!==s&&t===l},dze={duration:200,easing:"ease"},TX="transform",fze=ii.Transition.toString({property:TX,duration:0,easing:"linear"}),hze={roleDescription:"sortable"};function mze(e){let{disabled:t,index:n,node:r,rect:s}=e;const[o,i]=C.useState(null),a=C.useRef(n);return Bi(()=>{if(!t&&n!==a.current&&r.current){const l=s.current;if(l){const u=ip(r.current,{ignoreTransform:!0}),d={x:l.left-u.left,y:l.top-u.top,scaleX:l.width/u.width,scaleY:l.height/u.height};(d.x||d.y)&&i(d)}}n!==a.current&&(a.current=n)},[t,n,r,s]),C.useEffect(()=>{o&&i(null)},[o]),o}function oy(e){let{animateLayoutChanges:t=uze,attributes:n,disabled:r,data:s,getNewIndex:o=cze,id:i,strategy:a,resizeObserverConfig:l,transition:u=dze}=e;const{items:d,containerId:f,activeIndex:h,disabled:m,disableTransforms:p,sortedRects:g,overIndex:b,useDragOverlay:x,strategy:y}=C.useContext(MX),v=pze(r,m),w=d.indexOf(i),N=C.useMemo(()=>({sortable:{containerId:f,index:w,items:d},...s}),[f,s,w,d]),S=C.useMemo(()=>d.slice(d.indexOf(i)),[d,i]),{rect:j,node:E,isOver:_,setNodeRef:k}=kX({id:i,data:N,disabled:v.droppable,resizeObserverConfig:{updateMeasurementsFor:S,...l}}),{active:M,activatorEvent:D,activeNodeRect:R,attributes:P,setNodeRef:I,listeners:L,isDragging:F,over:H,setActivatorNodeRef:$,transform:A}=H6e({id:i,data:N,attributes:{...hze,...n},disabled:v.draggable}),q=TLe(k,I),z=!!M,O=z&&!p&&I0(h)&&I0(b),W=!x&&F,B=W&&O?A:null,U=O?B??(a??y)({rects:g,activeNodeRect:R,activeIndex:h,overIndex:b,index:w}):null,V=I0(h)&&I0(b)?o({id:i,items:d,activeIndex:h,overIndex:b}):w,G=M==null?void 0:M.id,K=C.useRef({activeId:G,items:d,newIndex:V,containerId:f}),J=d!==K.current.items,Q=t({active:M,containerId:f,isDragging:F,isSorting:z,id:i,index:w,items:d,newIndex:K.current.newIndex,previousItems:K.current.items,previousContainerId:K.current.containerId,transition:u,wasDragging:K.current.activeId!=null}),re=mze({disabled:!Q,index:w,node:E,rect:j});return C.useEffect(()=>{z&&K.current.newIndex!==V&&(K.current.newIndex=V),f!==K.current.containerId&&(K.current.containerId=f),d!==K.current.items&&(K.current.items=d)},[z,V,f,d]),C.useEffect(()=>{if(G===K.current.activeId)return;if(G!=null&&K.current.activeId==null){K.current.activeId=G;return}const fe=setTimeout(()=>{K.current.activeId=G},50);return()=>clearTimeout(fe)},[G]),{active:M,activeIndex:h,attributes:P,data:N,rect:j,index:w,newIndex:V,items:d,isOver:_,isSorting:z,isDragging:F,listeners:L,node:E,overIndex:b,over:H,setNodeRef:q,setActivatorNodeRef:$,setDroppableNodeRef:k,setDraggableNodeRef:I,transform:re??U,transition:de()};function de(){if(re||J&&K.current.newIndex===w)return fze;if(!(W&&!aC(D)||!u)&&(z||Q))return ii.Transition.toString({...u,property:TX})}}function pze(e,t){var n,r;return typeof e=="boolean"?{draggable:e,droppable:!1}:{draggable:(n=e==null?void 0:e.draggable)!=null?n:t.draggable,droppable:(r=e==null?void 0:e.droppable)!=null?r:t.droppable}}function Yw(e){if(!e)return!1;const t=e.data.current;return!!(t&&"sortable"in t&&typeof t.sortable=="object"&&"containerId"in t.sortable&&"items"in t.sortable&&"index"in t.sortable)}const gze=[Wt.Down,Wt.Right,Wt.Up,Wt.Left],II=(e,t)=>{let{context:{active:n,collisionRect:r,droppableRects:s,droppableContainers:o,over:i,scrollableAncestors:a}}=t;if(gze.includes(e.code)){if(e.preventDefault(),!n||!r)return;const l=[];o.getEnabled().forEach(f=>{if(!f||f!=null&&f.disabled)return;const h=s.get(f.id);if(h)switch(e.code){case Wt.Down:r.top<h.top&&l.push(f);break;case Wt.Up:r.top>h.top&&l.push(f);break;case Wt.Left:r.left>h.left&&l.push(f);break;case Wt.Right:r.left<h.left&&l.push(f);break}});const u=YLe({collisionRect:r,droppableRects:s,droppableContainers:l});let d=cX(u,"id");if(d===(i==null?void 0:i.id)&&u.length>1&&(d=u[1].id),d!=null){const f=o.get(n.id),h=o.get(d),m=h?s.get(h.id):null,p=h==null?void 0:h.node.current;if(p&&m&&f&&h){const b=cC(p).some((S,j)=>a[j]!==S),x=RX(f,h),y=bze(f,h),v=b||!x?{x:0,y:0}:{x:y?r.width-m.width:0,y:y?r.height-m.height:0},w={x:m.left,y:m.top};return v.x&&v.y?w:Db(w,v)}}}};function RX(e,t){return!Yw(e)||!Yw(t)?!1:e.data.current.sortable.containerId===t.data.current.sortable.containerId}function bze(e,t){return!Yw(e)||!Yw(t)||!RX(e,t)?!1:e.data.current.sortable.index<t.data.current.sortable.index}function xze(e,t,n){const[r,s]=C.useState(null),[o,i]=C.useState(""),a=()=>{const p={id:`hierarchy_${Date.now()}`,label:o||"New Hierarchy",type:"static",steps:[],default:!1};t([...e,p]),i(""),s(p.id)},l=p=>{t(e.filter(g=>g.id!==p))},u=(p,g)=>{t(e.map(b=>b.id===p?{...b,...g}:b))};return{editingHierarchy:r,setEditingHierarchy:s,newHierarchyName:o,setNewHierarchyName:i,createNewHierarchy:a,deleteHierarchy:l,updateHierarchy:u,addStepToHierarchy:(p,g)=>{const b=n.find(v=>v.id===g);if(!b)return;const x={field:b,mode:"drillDown",label:`Drill to ${b.label}`,retainFilters:!0,preferredChartType:"bar"},y=e.find(v=>v.id===p);y&&u(p,{steps:[...y.steps,x]})},removeStepFromHierarchy:(p,g)=>{const b=e.find(x=>x.id===p);if(b){const x=[...b.steps];x.splice(g,1),u(p,{steps:x})}},updateStep:(p,g,b)=>{const x=e.find(y=>y.id===p);if(x){const y=x.steps.map((v,w)=>w===g?{...v,...b}:v);u(p,{steps:y})}},setDefaultHierarchy:p=>{t(e.map(g=>({...g,default:g.id===p})))}}}function yze({step:e,hierarchyId:t,stepIndex:n,onUpdateStep:r,open:s,onOpenChange:o,trigger:i}){return c.jsxs(Xr,{open:s,onOpenChange:o,children:[c.jsx(Qr,{asChild:!0,children:i}),c.jsx(Jr,{className:"z-50 w-80",align:"start",children:c.jsxs("div",{className:"space-y-3",children:[c.jsxs("div",{children:[c.jsx(ce,{className:"mb-1 block text-xs font-medium",children:"Chart Type"}),c.jsxs(nt,{value:e.preferredChartType||"bar",onValueChange:a=>{r(t,n,{preferredChartType:a})},children:[c.jsx(et,{className:"h-8",children:c.jsx(ot,{})}),c.jsxs(tt,{children:[c.jsx(be,{value:"bar",children:"Bar Chart"}),c.jsx(be,{value:"pie",children:"Pie Chart"}),c.jsx(be,{value:"line",children:"Line Chart"}),c.jsx(be,{value:"donut",children:"Donut Chart"}),c.jsx(be,{value:"table",children:"Table"}),c.jsx(be,{value:"metric",children:"Metric"})]})]})]}),c.jsxs("div",{children:[c.jsx(ce,{className:"mb-1 block text-xs font-medium",children:"Step Label"}),c.jsx(Nn,{value:e.label||"",onChange:a=>r(t,n,{label:a.target.value}),placeholder:"Custom drill label",className:"h-8"})]}),c.jsxs("div",{children:[c.jsx(ce,{className:"mb-1 block text-xs font-medium",children:"Breadcrumb Label Template"}),c.jsx(Nn,{value:e.breadcrumbLabelTemplate||"",onChange:a=>r(t,n,{breadcrumbLabelTemplate:a.target.value}),placeholder:"e.g., 'Region: {{value}}'",className:"h-8"})]}),c.jsx("div",{className:"flex items-center gap-4",children:c.jsxs("label",{className:"flex items-center gap-2 text-xs",children:[c.jsx("input",{type:"checkbox",checked:e.retainFilters!==!1,onChange:a=>r(t,n,{retainFilters:a.target.checked}),className:"rounded"}),"Retain filters when drilling"]})}),c.jsx("div",{className:"flex justify-end",children:c.jsx(se,{size:"sm",variant:"outline",onClick:()=>o(!1),children:"Done"})})]})})]})}function vze({field:e,step:t,stepIndex:n,hierarchyId:r,onUpdateStep:s,onRemoveStep:o}){const[i,a]=C.useState(!1),{attributes:l,listeners:u,setNodeRef:d,transform:f,transition:h,isDragging:m}=oy({id:`${r}-${e.id}-${n}`,disabled:!1}),p={transform:ii.Transform.toString(f),transition:h,opacity:m?.8:1,zIndex:m?1e3:1};return c.jsx("div",{ref:d,style:p,className:`relative ${i?"z-[9998]":""}`,...l,children:c.jsx(yze,{step:t,hierarchyId:r,stepIndex:n,onUpdateStep:s,open:i,onOpenChange:a,trigger:c.jsxs("div",{className:`flex cursor-pointer items-center gap-2 rounded-lg border bg-muted px-3 py-2 transition-colors hover:bg-muted/50 ${m?"shadow-lg ring-2 ring-primary":""}`,...u,onClick:g=>{g.stopPropagation(),a(b=>!b)},children:[c.jsxs("div",{className:"pointer-events-none flex items-center gap-2",children:[c.jsx("span",{className:"whitespace-nowrap text-sm font-medium",children:e.label}),t.preferredChartType&&t.preferredChartType!=="bar"&&c.jsx("span",{className:"whitespace-nowrap rounded bg-purple-100 px-1 py-0.5 text-xs text-purple-700 dark:bg-purple-900/50 dark:text-purple-300",children:t.preferredChartType}),t.linkedInsightId&&c.jsx("span",{className:"whitespace-nowrap rounded bg-green-100 px-1 py-0.5 text-xs text-green-700 dark:bg-green-900/50 dark:text-green-300",children:"📊"})]}),c.jsx("button",{className:"pointer-events-auto ml-1 text-xs text-muted-foreground hover:text-red-800 dark:hover:text-red-400",onClick:g=>{g.stopPropagation(),o(r,n)},children:c.jsx(yt,{className:"h-3 w-3"})})]})})})}function wze(e){return{sensors:lC(tm(ap,{activationConstraint:{distance:5}}),tm(ty,{coordinateGetter:II})),handleStepDragEnd:(r,s)=>{const{active:o,over:i}=r;if(!i||o.id===i.id)return;const a=o.id.replace(`${s.id}-`,""),l=i.id.replace(`${s.id}-`,""),u=s.steps.findIndex(f=>f.field.id===a),d=s.steps.findIndex(f=>f.field.id===l);if(u!==-1&&d!==-1&&u!==d){const f=lp(s.steps,u,d);e(s.id,{steps:f})}}}}function Sze({hierarchy:e,onUpdateStep:t,onRemoveStep:n,onUpdateHierarchy:r}){const{sensors:s}=wze(r),[o,i]=C.useState(null),a=e.steps.filter(h=>h&&h.field&&h.field.id),u=a.map(h=>h.field).map((h,m)=>`${e.id}-${h.id}-${m}`),d=h=>{const m=h.active.id,p=Number.parseInt(m.split("-").pop()||"0"),g=a[p],b=g==null?void 0:g.field;i(b||null)},f=h=>{i(null);const{active:m,over:p}=h;if(!p||m.id===p.id)return;const g=Number.parseInt(m.id.split("-").pop()||"0"),b=Number.parseInt(p.id.split("-").pop()||"0");if(g!==b&&g<a.length&&b<a.length){const x=[...e.steps],[y]=x.splice(g,1);x.splice(b,0,y),r(e.id,{steps:x})}};return a.length===0?c.jsx("div",{className:"steps-container",onPointerDown:h=>h.stopPropagation(),children:c.jsx("div",{className:"rounded-lg border bg-muted/50 p-2 text-sm text-muted-foreground",children:"No drill steps configured. Add steps to create a drill hierarchy."})}):c.jsx("div",{className:"steps-container",onPointerDown:h=>h.stopPropagation(),children:c.jsxs(ry,{sensors:s,collisionDetection:ey,onDragStart:d,onDragEnd:f,children:[c.jsx(sy,{items:u,strategy:TI,children:c.jsx("div",{className:"flex flex-wrap items-center gap-2",style:{minHeight:"40px"},children:a.map((h,m)=>{if(!h||!h.field||!h.field.id)return null;const p=[];m>0&&p.push(c.jsx(Lr,{className:"pointer-events-none h-4 w-4 text-gray-400"},`arrow-${m}`));const g=m===0,b=m===a.length-1;return p.push(c.jsx(vze,{field:h.field,step:h,stepIndex:m,hierarchyId:e.id,onUpdateStep:t,onRemoveStep:n,isFirstField:g,isLastField:b},`field-${h.field.id}-${m}`)),p})})}),typeof window<"u"&&Ln.createPortal(c.jsx(EX,{className:"semaphor-scope",style:{zIndex:9999},children:o?c.jsx("div",{className:"flex items-center gap-2 rounded-lg border-2 border-blue-300 bg-blue-200 p-2 shadow-lg dark:border-blue-600 dark:bg-blue-900/70",children:c.jsx("span",{className:"whitespace-nowrap text-sm font-medium",children:o.label})}):null}),document.body)]})})}function Cze({hierarchy:e,sampleFieldReferences:t,onUpdateHierarchy:n,onDeleteHierarchy:r,onUpdateStep:s,onRemoveStep:o,onAddStep:i}){const[a,l]=C.useState(!1),{attributes:u,listeners:d,setNodeRef:f,transform:h,transition:m}=oy({id:e.id,disabled:!1}),p={transform:ii.Transform.toString(h),transition:m},g=e.steps.filter(b=>b.field).map(b=>b.field.id);return c.jsxs("div",{ref:f,style:p,className:"hierarchy-container relative rounded-lg border bg-background p-3 transition-shadow hover:shadow-md",children:[c.jsxs("div",{className:"mb-3 flex cursor-move items-center justify-between",...u,...d,children:[c.jsx("div",{className:"flex items-center gap-2",children:c.jsx("div",{onPointerDown:b=>b.stopPropagation(),onClick:b=>b.stopPropagation(),onKeyDown:b=>b.stopPropagation(),children:c.jsx(ei,{value:e.label||"",onSave:b=>{n(e.id,{label:b})},placeholder:"Hierarchy Name",displayClassName:"font-medium",inputClassName:"font-medium"})})}),c.jsx("div",{className:"flex items-center gap-1",children:c.jsx(se,{size:"sm",variant:"ghost",onClick:b=>{b.stopPropagation(),r(e.id)},onPointerDown:b=>b.stopPropagation(),children:c.jsx(Fl,{className:"h-3 w-3"})})})]}),c.jsx(Sze,{hierarchy:e,onUpdateStep:s,onRemoveStep:o,onUpdateHierarchy:n}),c.jsx("div",{className:"mt-3 border-t pt-3","data-hierarchy-editing":!0,children:a?c.jsxs(Lm,{className:"rounded-lg border",children:[c.jsx(Tx,{placeholder:"Search fields..."}),c.jsxs(zm,{children:[c.jsx(Bm,{children:"No field found."}),c.jsx(Vm,{children:t.filter(b=>!g.includes(b.id)).map(b=>c.jsx(Hm,{value:b.label,onSelect:()=>{i(e.id,b.id),l(!1)},children:b.label},b.id))})]})]}):c.jsxs(se,{type:"button",variant:"outline",size:"sm",onClick:b=>{b.preventDefault(),b.stopPropagation(),l(!0)},children:[c.jsx(Sr,{className:"mr-2 h-4 w-4"}),"Add Step"]})})]})}function Nze({open:e,onOpenChange:t,drillHierarchies:n,onUpdateHierarchies:r,availableFields:s}){const[o,i]=C.useState(n);C.useEffect(()=>{e&&i(n)},[e,n]);const a=C.useMemo(()=>s.filter(y=>Tr(y.dataType)==="string"),[s]),l=lC(tm(ap),tm(ty,{coordinateGetter:II})),{createNewHierarchy:u,deleteHierarchy:d,updateHierarchy:f,addStepToHierarchy:h,removeStepFromHierarchy:m,updateStep:p,setDefaultHierarchy:g}=xze(o,i,a),b=y=>{const{active:v,over:w}=y;if(v.id!==(w==null?void 0:w.id)){const N=o.findIndex(j=>j.id===v.id),S=o.findIndex(j=>j.id===(w==null?void 0:w.id));i(lp(o,N,S))}},x=y=>{y||r(o),t(y)};return c.jsx(ns,{modal:!0,open:e,onOpenChange:x,children:c.jsx(Vr,{className:"flex max-h-[85vh] max-w-3xl flex-col overflow-hidden p-0",onInteractOutside:y=>y.preventDefault(),onEscapeKeyDown:y=>y.preventDefault(),children:c.jsx(um,{trapped:!1,children:c.jsxs("div",{className:"flex max-h-[85vh] max-w-3xl flex-col overflow-hidden",children:[c.jsxs(Hr,{className:"border-b px-6 pb-4 pt-6",children:[c.jsx(Ur,{children:"Manage Drill Hierarchies"}),c.jsx(ys,{children:"Create multiple drill paths for different analysis scenarios. Define step-by-step navigation through your dimensions."})]}),c.jsx(Ls,{className:"flex-1 px-6",children:c.jsxs("div",{className:"space-y-4 py-4",children:[o.length>0&&c.jsx("div",{className:"flex justify-end",children:c.jsxs(se,{type:"button",size:"sm",onClick:y=>{y.preventDefault(),y.stopPropagation(),u()},children:[c.jsx(Sr,{className:"mr-1 h-4 w-4"}),"Add Hierarchy"]})}),o.length>0?c.jsx(ry,{sensors:l,collisionDetection:ey,onDragEnd:b,children:c.jsx(sy,{items:o.map(y=>y.id),strategy:RI,children:c.jsx("div",{className:"space-y-4",children:o.map(y=>c.jsx(Cze,{hierarchy:y,sampleFieldReferences:a,onUpdateHierarchy:f,onDeleteHierarchy:d,onSetDefaultHierarchy:g,onUpdateStep:p,onRemoveStep:m,onAddStep:h},y.id))})})}):c.jsxs("div",{className:"rounded-lg border border-dashed p-8 text-center",children:[c.jsx("p",{className:"mb-2 text-sm text-muted-foreground",children:"No hierarchies configured yet"}),c.jsx("p",{className:"mb-4 text-xs text-muted-foreground",children:"Create your first hierarchy to enable drill-down interactions"}),c.jsxs(se,{type:"button",size:"sm",variant:"outline",onClick:y=>{y.preventDefault(),y.stopPropagation(),u()},children:[c.jsx(Sr,{className:"mr-2 h-4 w-4"}),"Create First Hierarchy"]})]})]})}),c.jsx("div",{className:"flex justify-end gap-2 border-t px-6 py-4",children:c.jsx(se,{variant:"outline",onClick:()=>x(!1),children:"Done"})})]})})})})}function IX(e){switch(e){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..."}]}}function jze({interaction:e,onUpdate:t,card:n,availableFields:r,onUpdateHierarchies:s,onManageHierarchies:o}){var M;const[i,a]=C.useState(!1),[l,u]=C.useState(!1),[d,f]=C.useState(null),[h,m]=C.useState(!1),[p,g]=C.useState({}),b=C.useMemo(()=>{var D;return((D=n.interactionConfig)==null?void 0:D.drillHierarchies)||[]},[(M=n.interactionConfig)==null?void 0:M.drillHierarchies]),x=C.useMemo(()=>{var I,L;const D=[],R=e.trigger;if(!R)return D;let P;if(R.type==="attribute"){const F=r.find($=>$.id===R.field.id);F&&(F.dataType==="date"||F.dataType==="timestamp")&&(P=F)}else if(R.type==="metric"){const F=(L=(I=n.config)==null?void 0:I.groupByColumns)==null?void 0:L.find(H=>H.dataType==="date"||H.dataType==="timestamp");F&&(P=F)}if(P&&pse(P,b)){const F=mse(P);D.push(F)}return D},[r,b,e.trigger,n.config]),y=C.useMemo(()=>[...b,...x],[b,x]),v=y.find(D=>D.id===e.hierarchyId);T.useEffect(()=>{i&&v&&v.type==="date"?f(v.id):i||f(null)},[i,v]);const w=D=>{if(x.some(P=>P.id===D)&&s){const P=x.find(I=>I.id===D);P&&s([...b,P])}t({...e,hierarchyId:D}),a(!1)},N=()=>{a(!1),u(!0),o&&o()},S=D=>{s&&s(D)},j=D=>D.steps.map(P=>P.field.label||P.field.name).join(" → "),E=D=>D&&D.charAt(0).toUpperCase()+D.slice(1),_=(D,R,P)=>{const I=[...D.steps];I[R]={...I[R],field:{...I[R].field,dateFormat:P,customFormat:P==="custom"?p[R]||"":void 0}};const L={...D,steps:I};if(s){const F=b.findIndex(H=>H.id===D.id);if(F>=0){const H=[...b];H[F]=L,s(H)}else s([...b,L])}},k=(D,R,P)=>{g(F=>({...F,[R]:P}));const I=[...D.steps];I[R]={...I[R],field:{...I[R].field,dateFormat:"custom",customFormat:P}};const L={...D,steps:I};if(s){const F=b.findIndex(H=>H.id===D.id);if(F>=0){const H=[...b];H[F]=L,s(H)}else s([...b,L])}};return c.jsxs("div",{className:"space-y-4",children:[c.jsxs("div",{className:"space-y-2",children:[c.jsx(ce,{className:"text-sm font-medium",children:"Choose hierarchy"}),c.jsx("p",{className:"mb-2 text-xs text-muted-foreground",children:"Select which hierarchy to drill through when this interaction triggers"}),y.length>0?c.jsxs(c.Fragment,{children:[c.jsxs(Xr,{open:i,onOpenChange:a,children:[c.jsx(Qr,{asChild:!0,children:c.jsxs(se,{variant:"outline",role:"combobox",className:"w-full justify-between",children:[c.jsx("div",{className:"flex flex-1 flex-col items-start text-left",children:v?c.jsxs(c.Fragment,{children:[c.jsx("div",{className:"flex items-center gap-2",children:c.jsx("span",{className:"font-medium",children:v.label||"Unnamed Hierarchy"})}),c.jsx("span",{className:"text-xs text-muted-foreground",children:j(v)})]}):c.jsx("span",{className:"text-muted-foreground",children:"Select hierarchy..."})}),c.jsxs("div",{className:"flex items-center gap-2",children:[v&&v.type==="date"&&c.jsx(se,{variant:"ghost",size:"sm",className:"h-6 w-6 p-0",onClick:D=>{D.stopPropagation(),m(!h)},children:c.jsx(cm,{className:"h-3 w-3"})}),c.jsx(Lr,{className:"h-4 w-4 shrink-0 opacity-50"})]})]})}),c.jsxs(Jr,{className:"w-[500px] p-0",align:"start",children:[c.jsxs("div",{className:"flex items-center justify-between border-b p-3",children:[c.jsx("span",{className:"text-sm font-medium",children:"Select Hierarchy"}),c.jsxs(se,{variant:"ghost",size:"sm",onClick:N,children:[c.jsx(Sr,{className:"mr-1.5 h-3.5 w-3.5"}),"Create new"]})]}),c.jsxs("div",{className:"p-2",children:[x.length>0&&c.jsxs(c.Fragment,{children:[c.jsx("div",{className:"px-3 py-2",children:c.jsx("span",{className:"text-xs font-medium text-muted-foreground",children:"AUTO-GENERATED"})}),x.map(D=>c.jsx("div",{className:`cursor-pointer rounded-md p-3 hover:bg-muted ${e.hierarchyId===D.id?"bg-muted":""}`,onClick:()=>w(D.id),children:c.jsxs("div",{className:"space-y-1",children:[c.jsx("div",{className:"flex items-center gap-2",children:c.jsx("span",{className:"text-sm font-medium",children:D.label||"Unnamed Hierarchy"})}),c.jsx("div",{className:"text-xs text-muted-foreground",children:j(D)})]})},D.id))]}),b.length>0&&c.jsxs(c.Fragment,{children:[x.length>0&&c.jsx("div",{className:"my-2 border-t"}),b.map(D=>c.jsx("div",{className:`cursor-pointer rounded-md p-3 hover:bg-muted ${e.hierarchyId===D.id?"bg-muted":""}`,onClick:()=>w(D.id),children:c.jsxs("div",{className:"space-y-1",children:[c.jsx("div",{className:"flex items-center gap-2",children:c.jsx("span",{className:"text-sm font-medium",children:D.label||"Unnamed Hierarchy"})}),c.jsx("div",{className:"text-xs text-muted-foreground",children:j(D)})]})},D.id))]})]})]})]}),v&&v.type==="date"&&h&&c.jsxs("div",{className:"mt-3 space-y-3 rounded-md border border-border p-3",children:[c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsx(ce,{className:"text-sm font-medium",children:"Customize Date Formats"}),c.jsx(se,{variant:"ghost",size:"sm",className:"h-6 text-xs",onClick:()=>m(!1),children:"Close"})]}),v.steps.map((D,R)=>{var F;const P=D.field.granularity;if(!P)return null;const I=IX(P),L=D.field.dateFormat||((F=I[0])==null?void 0:F.value);return c.jsxs("div",{className:"space-y-1",children:[c.jsx(ce,{className:"text-xs font-medium text-muted-foreground",children:D.field.label||E(P)}),c.jsxs(nt,{value:L,onValueChange:H=>{_(v,R,H)},children:[c.jsx(et,{className:"h-8 text-xs",children:c.jsx(ot,{})}),c.jsx(tt,{children:I.map(H=>c.jsx(be,{value:H.value,className:"text-xs",children:H.label},H.value))})]}),L==="custom"&&c.jsxs("div",{className:"mt-2 space-y-1",children:[c.jsx(Nn,{placeholder:"Enter custom format (e.g., YYYY-MM-DD)",value:D.field.customFormat||p[R]||"",onChange:H=>{k(v,R,H.target.value)},className:"h-8 text-xs"}),c.jsx("p",{className:"text-[10px] text-muted-foreground",children:"Common tokens: YYYY (year), MM (month), DD (day), HH (hour), mm (minute)"})]})]},R)})]})]}):c.jsxs("div",{className:"rounded-md border border-dashed p-6 text-center",children:[c.jsx("p",{className:"mb-2 text-sm text-muted-foreground",children:"No hierarchies configured"}),c.jsx("p",{className:"mb-4 text-xs text-muted-foreground",children:"Create a hierarchy to define your drill path"}),c.jsxs(se,{variant:"outline",size:"sm",onClick:N,children:[c.jsx(Sr,{className:"mr-2 h-4 w-4"}),"Create hierarchy"]})]})]}),c.jsx(Nze,{open:l,onOpenChange:u,drillHierarchies:b,onUpdateHierarchies:S,availableFields:r})]})}function kze({fields:e,selectedFieldIds:t,onSelectionChange:n,searchPlaceholder:r="Search fields...",className:s=""}){const[o,i]=C.useState(""),a=e.filter(d=>d.label.toLowerCase().includes(o.toLowerCase())||d.qualifiedEntityName&&d.qualifiedEntityName.toLowerCase().includes(o.toLowerCase())),l=()=>{const d=[...new Set([...t,...a.map(f=>f.id)])];n(d)},u=()=>{const d=a.map(f=>f.id);n(t.filter(f=>!d.includes(f)))};return c.jsxs("div",{className:`space-y-2 ${s}`,children:[c.jsxs("div",{className:"mb-3 flex items-center gap-2",children:[c.jsx(Nn,{placeholder:r,value:o,onChange:d=>i(d.target.value),className:"flex-1"}),c.jsxs("span",{className:"text-xs text-muted-foreground",children:[a.length," fields"]})]}),c.jsxs("div",{className:"mb-2 flex items-center gap-2",children:[c.jsx(se,{size:"sm",variant:"outline",onClick:l,children:"Select All"}),c.jsx(se,{size:"sm",variant:"outline",onClick:u,children:"Deselect All"}),c.jsxs("span",{className:"text-xs text-muted-foreground",children:[t.length," selected"]})]}),c.jsx("div",{className:"grid max-h-32 grid-cols-2 gap-2 overflow-y-auto rounded border p-2",children:a.map(d=>c.jsxs("label",{className:"flex cursor-pointer items-center gap-2 rounded p-2 text-xs hover:bg-muted/50",children:[c.jsx(Qt,{checked:t.includes(d.id),onCheckedChange:f=>{n(f?[...t,d.id]:t.filter(h=>h!==d.id))}}),c.jsx("span",{className:"font-medium",children:d.label})]},d.id))}),o&&a.length===0&&c.jsxs("div",{className:"py-4 text-center text-sm text-muted-foreground",children:['No fields found matching "',o,'"']})]})}const Eze=e=>["string","boolean"].includes(Tr(e.dataType));function _ze({interaction:e,availableFields:t,onUpdate:n}){var i;const r=t.filter(Eze),s=((i=e.availableFields)==null?void 0:i.map(a=>a.id))||[],o=a=>{const l=r.filter(u=>a.includes(u.id));n({...e,availableFields:l})};return c.jsx("div",{className:"space-y-4",children:c.jsxs("div",{className:"space-y-2",children:[c.jsx(ce,{children:"Available dimensions"}),c.jsx("p",{className:"text-sm text-muted-foreground",children:"Choose which fields users can explore dynamically"}),c.jsx(kze,{fields:r,selectedFieldIds:s,onSelectionChange:o,searchPlaceholder:"Search fields..."}),s.length===0&&c.jsx("p",{className:"text-xs text-amber-600",children:"⚠️ Please select at least one field"})]})})}function Dze({value:e,onChange:t}){const[n,r]=C.useState(!1),[s,o]=C.useState(""),[i,a]=C.useState("all"),{currentUser:l}=oo(),{data:u,isLoading:d}=bM(Pt.DASHBOARD,s),f=(u==null?void 0:u.dashboards)||[],h=f.filter(g=>i==="me"?g.ownership.createdBy.userId===(l==null?void 0:l.id):!0),m=f.find(g=>g.id===e),p=g=>{t(g.id,g.title),r(!1),o("")};return c.jsxs(Xr,{open:n,onOpenChange:r,children:[c.jsx(Qr,{asChild:!0,children:c.jsx(se,{variant:"outline",className:Z("w-full justify-start text-left font-normal",!e&&"text-muted-foreground"),children:m?c.jsx("span",{className:"truncate",children:m.title}):"Choose dashboard..."})}),c.jsx(Jr,{className:"w-[500px] p-0",align:"start",children:c.jsxs(Bs,{value:i,onValueChange:g=>a(g),children:[c.jsx("div",{className:"p-3 border-b",children:c.jsxs("div",{className:"relative",children:[c.jsx(Ui,{className:"absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground"}),c.jsx(Nn,{placeholder:"Search all dashboards...",value:s,onChange:g=>o(g.target.value),className:"pl-9"})]})}),c.jsxs(vs,{className:"w-full justify-start rounded-none border-b bg-transparent p-0",children:[c.jsx(Gt,{value:"me",className:"rounded-none border-b-2 border-transparent data-[state=active]:border-primary data-[state=active]:bg-transparent",children:"created by me"}),c.jsx(Gt,{value:"all",className:"rounded-none border-b-2 border-transparent data-[state=active]:border-primary data-[state=active]:bg-transparent",children:"all"})]}),c.jsx(sr,{value:i,className:"mt-0",children:c.jsx(Ls,{className:"h-[300px]",children:d?c.jsx("div",{className:"p-8 text-center text-sm text-muted-foreground",children:"Loading dashboards..."}):h.length===0?c.jsx("div",{className:"p-8 text-center text-sm text-muted-foreground",children:s?`No dashboards found matching "${s}"`:i==="me"?"No dashboards created by you":"No dashboards available"}):c.jsx("div",{className:"p-2",children:h.map(g=>c.jsxs("button",{onClick:()=>p(g),className:Z("w-full flex items-start gap-3 p-3 rounded-md hover:bg-muted/50 transition-colors text-left",e===g.id&&"bg-muted"),children:[c.jsx(v8,{className:"h-5 w-5 mt-0.5 text-muted-foreground flex-shrink-0"}),c.jsxs("div",{className:"flex-1 min-w-0",children:[c.jsx("div",{className:"font-medium text-sm truncate",children:g.title}),c.jsx("div",{className:"text-xs text-muted-foreground mt-0.5",children:Mze(g.createdAt)})]})]},g.id))})})})]})})]})}function Mze(e){const t=new Date(e),n=new Date;if(t.getDate()===n.getDate()&&t.getMonth()===n.getMonth()&&t.getFullYear()===n.getFullYear()){const i=t.getHours(),a=t.getMinutes(),l=i>=12?"PM":"AM",u=i%12||12,d=a.toString().padStart(2,"0");return`TODAY AT ${u}:${d} ${l}`}const s=t.toLocaleString("en-US",{month:"short"}).toUpperCase(),o=t.getDate();return`${s} ${o}`}function Tze({interaction:e,onUpdate:t}){return c.jsxs("div",{className:"space-y-4",children:[c.jsxs("div",{className:"space-y-2",children:[c.jsx(ce,{className:"text-sm font-medium",children:"Target dashboard"}),c.jsx("p",{className:"text-xs text-muted-foreground mb-2",children:"Select which dashboard to navigate to when this interaction triggers"}),c.jsx(Dze,{value:e.targetDashboardId,onChange:(n,r)=>{const s={...e,targetDashboardId:n};!e.label&&r&&(s.label=r),t(s)}})]}),c.jsxs("div",{className:"space-y-2",children:[c.jsx(ce,{className:"text-sm font-medium",children:"Propagate Filters"}),c.jsx("p",{className:"text-xs text-muted-foreground mb-2",children:"Choose what filters to pass to the target dashboard"}),c.jsxs(nt,{value:e.contextMode||"full",onValueChange:n=>t({...e,contextMode:n}),children:[c.jsx(et,{children:c.jsxs(ot,{placeholder:"Choose context mode...",children:[e.contextMode==="interactionFilters"&&"Interaction Filters",(e.contextMode==="full"||!e.contextMode)&&"All Filters",e.contextMode==="none"&&"None"]})}),c.jsxs(tt,{children:[c.jsx(be,{value:"interactionFilters",children:c.jsxs("div",{className:"flex flex-col items-start gap-1 py-1",children:[c.jsx("span",{className:"font-medium",children:"Interaction Filters"}),c.jsx("span",{className:"text-xs text-muted-foreground",children:"Pass only the clicked element as a filter"})]})}),c.jsx(be,{value:"full",children:c.jsxs("div",{className:"flex flex-col items-start gap-1 py-1",children:[c.jsx("span",{className:"font-medium",children:"All Filters"}),c.jsx("span",{className:"text-xs text-muted-foreground",children:"Pass current dashboard filters + clicked element"})]})}),c.jsx(be,{value:"none",children:c.jsxs("div",{className:"flex flex-col items-start gap-1 py-1",children:[c.jsx("span",{className:"font-medium",children:"None"}),c.jsx("span",{className:"text-xs text-muted-foreground",children:"Navigate without passing any filters"})]})})]})]})]}),!e.targetDashboardId&&c.jsx("div",{className:"rounded-md bg-amber-50 dark:bg-amber-900/20 border border-amber-200 dark:border-amber-800 p-3",children:c.jsx("p",{className:"text-xs text-amber-800 dark:text-amber-200",children:"⚠ Please select a target dashboard to complete this configuration"})}),e.targetDashboardId&&c.jsx("div",{className:"rounded-md bg-green-50 dark:bg-green-900/20 border border-green-200 dark:border-green-800 p-3",children:c.jsx("p",{className:"text-xs text-green-800 dark:text-green-200",children:"✓ Dashboard drill-through configured successfully"})}),c.jsxs("div",{className:"space-y-2",children:[c.jsx(ce,{className:"text-sm font-medium",children:"Menu label"}),c.jsx(Nn,{value:e.label||"",onChange:n=>t({...e,label:n.target.value}),placeholder:hf(e.mode)}),c.jsx("p",{className:"text-xs text-muted-foreground",children:"How this interaction appears when multiple actions are available"})]})]})}function Rze({value:e,onChange:t}){const[n,r]=C.useState(!1),[s,o]=C.useState(""),[i,a]=C.useState("all"),{currentUser:l}=oo(),{data:u,isLoading:d}=bM(Pt.VISUAL,s),f=(u==null?void 0:u.visuals)||[],h=f.filter(g=>i==="me"?g.ownership.createdBy.userId===(l==null?void 0:l.id):!0),m=f.find(g=>g.id===e),p=g=>{t(g.id,g.title),r(!1),o("")};return c.jsxs(Xr,{open:n,onOpenChange:r,children:[c.jsx(Qr,{asChild:!0,children:c.jsx(se,{variant:"outline",className:Z("w-full justify-start text-left font-normal",!e&&"text-muted-foreground"),children:m?c.jsx("span",{className:"truncate",children:m.title}):"Choose insight..."})}),c.jsx(Jr,{className:"w-[500px] p-0",align:"start",children:c.jsxs(Bs,{value:i,onValueChange:g=>a(g),children:[c.jsx("div",{className:"p-3 border-b",children:c.jsxs("div",{className:"relative",children:[c.jsx(Ui,{className:"absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground"}),c.jsx(Nn,{placeholder:"Search all insights...",value:s,onChange:g=>o(g.target.value),className:"pl-9"})]})}),c.jsxs(vs,{className:"w-full justify-start rounded-none border-b bg-transparent p-0",children:[c.jsx(Gt,{value:"me",className:"rounded-none border-b-2 border-transparent data-[state=active]:border-primary data-[state=active]:bg-transparent",children:"created by me"}),c.jsx(Gt,{value:"all",className:"rounded-none border-b-2 border-transparent data-[state=active]:border-primary data-[state=active]:bg-transparent",children:"all"})]}),c.jsx(sr,{value:i,className:"mt-0",children:c.jsx(Ls,{className:"h-[300px]",children:d?c.jsx("div",{className:"p-8 text-center text-sm text-muted-foreground",children:"Loading insights..."}):h.length===0?c.jsx("div",{className:"p-8 text-center text-sm text-muted-foreground",children:s?`No insights found matching "${s}"`:i==="me"?"No insights created by you":"No insights available"}):c.jsx("div",{className:"p-2",children:h.map(g=>c.jsxs("button",{onClick:()=>p(g),className:Z("w-full flex items-start gap-3 p-3 rounded-md hover:bg-muted/50 transition-colors text-left",e===g.id&&"bg-muted"),children:[c.jsx(im,{className:"h-5 w-5 mt-0.5 text-muted-foreground flex-shrink-0"}),c.jsxs("div",{className:"flex-1 min-w-0",children:[c.jsx("div",{className:"font-medium text-sm truncate",children:g.title}),c.jsx("div",{className:"text-xs text-muted-foreground mt-0.5",children:Ize(g.createdAt)})]})]},g.id))})})})]})})]})}function Ize(e){const t=new Date(e),n=new Date;if(t.getDate()===n.getDate()&&t.getMonth()===n.getMonth()&&t.getFullYear()===n.getFullYear()){const i=t.getHours(),a=t.getMinutes(),l=i>=12?"PM":"AM",u=i%12||12,d=a.toString().padStart(2,"0");return`TODAY AT ${u}:${d} ${l}`}const s=t.toLocaleString("en-US",{month:"short"}).toUpperCase(),o=t.getDate();return`${s} ${o}`}function Aze({interaction:e,onUpdate:t}){return c.jsxs("div",{className:"space-y-4",children:[c.jsxs("div",{className:"space-y-2",children:[c.jsx(ce,{className:"text-sm font-medium",children:"Target insight"}),c.jsx("p",{className:"text-xs text-muted-foreground mb-2",children:"Select the saved insight to navigate to"}),c.jsx(Rze,{value:e.targetInsightId,onChange:(n,r)=>{const s={...e,targetInsightId:n};!e.label&&r&&(s.label=r),t(s)}})]}),c.jsxs("div",{className:"space-y-2",children:[c.jsx(ce,{className:"text-sm font-medium",children:"Propagate Filters"}),c.jsx("p",{className:"text-xs text-muted-foreground mb-2",children:"Choose what filters to pass to the insight"}),c.jsxs(nt,{value:e.contextMode||"full",onValueChange:n=>t({...e,contextMode:n}),children:[c.jsx(et,{children:c.jsxs(ot,{placeholder:"Choose context mode...",children:[e.contextMode==="interactionFilters"&&"Interaction Filters",(e.contextMode==="full"||!e.contextMode)&&"All Filters",e.contextMode==="none"&&"None"]})}),c.jsxs(tt,{children:[c.jsx(be,{value:"interactionFilters",children:c.jsxs("div",{className:"flex flex-col items-start gap-1 py-1",children:[c.jsx("span",{className:"font-medium",children:"Interaction Filters"}),c.jsx("span",{className:"text-xs text-muted-foreground",children:"Pass only the clicked element as a filter"})]})}),c.jsx(be,{value:"full",children:c.jsxs("div",{className:"flex flex-col items-start gap-1 py-1",children:[c.jsx("span",{className:"font-medium",children:"All Filters"}),c.jsx("span",{className:"text-xs text-muted-foreground",children:"Pass all current filters and selections"})]})}),c.jsx(be,{value:"none",children:c.jsxs("div",{className:"flex flex-col items-start gap-1 py-1",children:[c.jsx("span",{className:"font-medium",children:"None"}),c.jsx("span",{className:"text-xs text-muted-foreground",children:"Open insight without any filters"})]})})]})]})]}),c.jsxs("div",{className:"space-y-2",children:[c.jsx(ce,{className:"text-sm font-medium",children:"Display mode"}),c.jsx("p",{className:"text-xs text-muted-foreground mb-2",children:"Choose how the insight should be displayed"}),c.jsxs(nt,{value:e.displayMode||"modal",onValueChange:n=>t({...e,displayMode:n}),children:[c.jsx(et,{children:c.jsx(ot,{placeholder:"Choose display mode..."})}),c.jsxs(tt,{children:[c.jsx(be,{value:"modal",children:c.jsx("div",{className:"flex items-center gap-2",children:c.jsx("span",{children:"Open in modal"})})}),c.jsx(be,{value:"replace-card",children:c.jsx("div",{className:"flex items-center gap-2",children:c.jsx("span",{children:"Replace the card"})})})]})]})]}),!e.targetInsightId&&c.jsx("div",{className:"rounded-md bg-amber-50 dark:bg-amber-900/20 border border-amber-200 dark:border-amber-800 p-3",children:c.jsx("p",{className:"text-xs text-amber-800 dark:text-amber-200",children:"⚠ Please enter a target insight ID to complete this configuration"})}),e.targetInsightId&&c.jsx("div",{className:"rounded-md bg-green-50 dark:bg-green-900/20 border border-green-200 dark:border-green-800 p-3",children:c.jsx("p",{className:"text-xs text-green-800 dark:text-green-200",children:"✓ Insight drill-through configured successfully"})}),c.jsxs("div",{className:"space-y-2",children:[c.jsx(ce,{className:"text-sm font-medium",children:"Menu label"}),c.jsx(Nn,{value:e.label||"",onChange:n=>t({...e,label:n.target.value}),placeholder:hf(e.mode)}),c.jsx("p",{className:"text-xs text-muted-foreground",children:"How this interaction appears when multiple actions are available"})]})]})}function Pze(e){return e.filter(t=>t.role==="groupby"||t.role==="pivotby").map(t=>({id:t.name,label:t.label||t.name,category:"attribute",field:t}))}function Oze(){return[{id:"card_id",label:"Card ID",category:"identifier"},{id:"frame_id",label:"Frame ID",category:"identifier"},{id:"sheet_id",label:"Sheet ID",category:"identifier"}]}function Fze(e,t){const n=`{{${t}}}`;return e.includes(n)}function $ze(e,t){return t.filter(n=>Fze(e,n.id))}function Lze(e,t,n){const r=`{{${t}}}`,s=e.slice(0,n)+r+e.slice(n),o=n+r.length;return{newTemplate:s,newCursorPosition:o}}function zze(e,t){let n=e;return t.forEach(r=>{const s=`{{${r.id}}}`;let o;if(r.category==="identifier")o=`${r.id.toUpperCase()}-abc123`;else{const i=r.label.toLowerCase();i.includes("name")?o="Example Name":i.includes("region")||i.includes("location")?o="California":i.includes("id")?o="ID-12345":i.includes("category")?o="Category A":o="Sample Value"}n=n.replace(new RegExp(s,"g"),o)}),n}const AX=T.forwardRef(({className:e,...t},n)=>c.jsx("textarea",{className:Z("flex min-h-[80px] w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background placeholder:text-muted-foreground disabled:cursor-not-allowed disabled:opacity-50","focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-inset focus-visible:ring-ring focus-visible:ring-offset-0",e),ref:n,...t}));AX.displayName="Textarea";function Bze({open:e,onOpenChange:t,interaction:n,availableFields:r,onSave:s}){const[o,i]=C.useState(n.urlTemplate||""),[a,l]=C.useState(0),[u,d]=C.useState(n.encodeParameters!==!1),[f,h]=C.useState(n.label||""),m=C.useRef(null);C.useEffect(()=>{e&&(i(n.urlTemplate||""),d(n.encodeParameters!==!1),h(n.label||""),l(0))},[e,n.urlTemplate,n.encodeParameters,n.label]);const p=Pze(r),g=Oze(),b=[...p,...g],x=$ze(o,b),y=vse(o),v=o&&y.valid?zze(o,x):"",w=k=>{i(k.target.value),l(k.target.selectionStart)},N=k=>{const M=k.target;l(M.selectionStart)},S=k=>{const M=k.target;l(M.selectionStart)},j=k=>{const{newTemplate:M,newCursorPosition:D}=Lze(o,k.id,a);i(M),l(D),m.current&&(m.current.focus(),setTimeout(()=>{m.current&&m.current.setSelectionRange(D,D)},0))},E=()=>{y.valid&&(s({...n,urlTemplate:o,parameters:x,encodeParameters:u,label:f}),t(!1))},_=()=>{t(!1)};return c.jsx(ns,{open:e,onOpenChange:t,children:c.jsxs(Vr,{className:"max-h-[90vh] max-w-5xl overflow-y-auto",onOpenAutoFocus:k=>{k.preventDefault(),setTimeout(()=>{var M;(M=m.current)==null||M.focus()},0)},children:[c.jsxs(Hr,{children:[c.jsx(Ur,{children:"Configure Drill to URL"}),c.jsx(ys,{children:"Build a custom URL with dynamic parameters that will open when users click on chart elements."})]}),c.jsxs("div",{className:"flex flex-col gap-6 py-4",children:[c.jsxs("div",{className:"grid grid-cols-2 gap-6",children:[c.jsxs("div",{className:"flex flex-col gap-4",children:[c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsx(ce,{htmlFor:"url-template",children:"URL"}),c.jsx(_n,{children:c.jsxs(Zt,{children:[c.jsx(Xt,{asChild:!0,children:c.jsx(Wn,{className:"h-4 w-4 text-muted-foreground"})}),c.jsx(en,{children:c.jsx("p",{className:"max-w-xs text-xs",children:"Enter your URL and click parameters from the right panel to insert them. Parameters will be replaced with actual values when the URL is opened."})})]})})]}),c.jsx(AX,{ref:m,id:"url-template",value:o,onChange:w,onClick:N,onKeyUp:S,placeholder:"https://example.com/product/{{product_id}}?region={{region}}",className:"min-h-[200px] font-mono text-sm"}),!y.valid&&o&&c.jsx("div",{className:"rounded-lg border border-destructive bg-destructive/10 p-3",children:c.jsx("div",{className:"text-sm text-destructive",children:y.errors.map((k,M)=>c.jsx("div",{children:k},M))})}),v&&c.jsxs("div",{className:"space-y-2",children:[c.jsx(ce,{className:"text-xs text-muted-foreground",children:"Preview:"}),c.jsx("div",{className:"rounded-md bg-muted p-3",children:c.jsx("p",{className:"break-all font-mono text-xs",children:v})})]})]}),c.jsxs("div",{className:"flex flex-col gap-4",children:[c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsx(ce,{children:"Parameters"}),c.jsx(_n,{children:c.jsxs(Zt,{children:[c.jsx(Xt,{asChild:!0,children:c.jsx(Wn,{className:"h-4 w-4 text-muted-foreground"})}),c.jsx(en,{children:c.jsx("p",{className:"max-w-xs text-xs",children:"Click any parameter to insert it into your URL at the cursor position. Attributes come from your chart data, Identifiers are system values."})})]})})]}),c.jsxs("div",{className:"flex flex-col gap-6 rounded-lg border p-4",children:[c.jsxs("div",{className:"space-y-3",children:[c.jsx("div",{className:"text-xs font-medium uppercase tracking-wide text-muted-foreground",children:"Attributes"}),c.jsxs("div",{className:"space-y-1",children:[p.map(k=>c.jsx(M$,{parameter:k,isUsed:x.some(M=>M.id===k.id),onClick:()=>j(k)},k.id)),p.length===0&&c.jsx("p",{className:"text-sm text-muted-foreground",children:"No attributes available"})]})]}),c.jsxs("div",{className:"space-y-3",children:[c.jsx("div",{className:"text-xs font-medium uppercase tracking-wide text-muted-foreground",children:"Identifiers"}),c.jsx("div",{className:"space-y-1",children:g.map(k=>c.jsx(M$,{parameter:k,isUsed:x.some(M=>M.id===k.id),onClick:()=>j(k)},k.id))})]})]})]})]}),c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsx(Qt,{id:"encode-params",checked:u,onCheckedChange:k=>d(k===!0)}),c.jsx(ce,{htmlFor:"encode-params",className:"cursor-pointer text-sm font-normal",children:"URL encode parameters"}),c.jsx(_n,{children:c.jsxs(Zt,{children:[c.jsx(Xt,{asChild:!0,children:c.jsx(Wn,{className:"h-4 w-4 text-muted-foreground"})}),c.jsx(en,{children:c.jsx("p",{className:"max-w-xs text-xs",children:"Recommended. Encodes special characters in parameter values to ensure valid URLs (e.g., spaces become %20)."})})]})})]}),c.jsxs("div",{className:"space-y-2",children:[c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsx(ce,{className:"text-sm font-medium",children:"Menu label"}),c.jsx(_n,{children:c.jsxs(Zt,{children:[c.jsx(Xt,{asChild:!0,children:c.jsx(Wn,{className:"h-4 w-4 text-muted-foreground"})}),c.jsx(en,{children:c.jsx("p",{className:"max-w-xs text-xs",children:"How this interaction appears when multiple actions are available"})})]})})]}),c.jsx(Nn,{value:f,onChange:k=>h(k.target.value),placeholder:hf("drillToURL")})]}),c.jsxs("div",{className:"flex items-start gap-2 rounded-lg border bg-muted/50 p-3",children:[c.jsx(Wn,{className:"mt-0.5 h-4 w-4 text-muted-foreground"}),c.jsx("p",{className:"text-xs text-muted-foreground",children:"URLs will always open in a new browser tab when clicked."})]})]}),c.jsxs(xs,{children:[c.jsx(se,{variant:"outline",onClick:_,children:"Cancel"}),c.jsx(se,{onClick:E,disabled:!y.valid,children:"Save"})]})]})})}function M$({parameter:e,isUsed:t,onClick:n}){var o,i;const r=e.category==="attribute"?"🏷️":"#",s=((o=e.field)==null?void 0:o.qualifiedFieldName)||((i=e.field)==null?void 0:i.name);return c.jsxs(se,{type:"button",variant:"ghost",className:"h-auto w-full justify-start gap-2 px-3 py-2 font-normal hover:bg-accent",onClick:n,children:[c.jsx("span",{className:"text-base",children:r}),c.jsxs("div",{className:"flex flex-1 flex-col items-start gap-0.5",children:[c.jsx("span",{className:"text-sm",children:e.label}),s&&c.jsx("span",{className:"text-xs text-muted-foreground",children:s})]}),t&&c.jsx(Fe,{variant:"secondary",className:"ml-auto gap-1",children:c.jsx(Mr,{className:"h-3 w-3"})})]})}function Vze({interaction:e,availableFields:t,onUpdate:n}){const[r,s]=C.useState(!1),o=!!e.urlTemplate;return c.jsxs("div",{className:"flex flex-col gap-4",children:[o?c.jsxs("div",{className:"flex flex-col gap-3 rounded-lg border p-4",children:[c.jsxs("div",{className:"flex items-start justify-between gap-4",children:[c.jsxs("div",{className:"flex-1 space-y-2",children:[c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsx(Kg,{className:"h-4 w-4 text-muted-foreground"}),c.jsx("span",{className:"text-sm font-medium",children:"URL Template"})]}),c.jsx("div",{className:"rounded-md bg-muted p-3",children:c.jsx("p",{className:"break-all font-mono text-xs",children:e.urlTemplate})})]}),c.jsxs(se,{variant:"outline",size:"sm",onClick:()=>s(!0),children:[c.jsx(T1,{className:"mr-2 h-4 w-4"}),"Edit"]})]}),e.parameters&&e.parameters.length>0&&c.jsxs("div",{className:"text-xs text-muted-foreground",children:[e.parameters.length," parameter",e.parameters.length!==1?"s":""," configured"]}),c.jsxs("div",{className:"text-xs text-muted-foreground",children:["URL encoding:"," ",e.encodeParameters!==!1?"enabled":"disabled"]})]}):c.jsxs("div",{className:"flex flex-col items-center gap-3 rounded-lg border border-dashed p-8",children:[c.jsx(Kg,{className:"h-8 w-8 text-muted-foreground"}),c.jsx("p",{className:"text-sm text-muted-foreground",children:"No URL configured"}),c.jsx(se,{variant:"outline",size:"sm",onClick:()=>s(!0),children:"Add Custom URL"})]}),c.jsx(Bze,{open:r,onOpenChange:s,interaction:e,availableFields:t,onSave:n})]})}var fC="Switch",[Hze]=kr(fC),[Uze,Wze]=Hze(fC),PX=T.forwardRef((e,t)=>{const{__scopeSwitch:n,name:r,checked:s,defaultChecked:o,required:i,disabled:a,value:l="on",onCheckedChange:u,form:d,...f}=e,[h,m]=T.useState(null),p=rt(t,v=>m(v)),g=T.useRef(!1),b=h?d||!!h.closest("form"):!0,[x,y]=Br({prop:s,defaultProp:o??!1,onChange:u,caller:fC});return c.jsxs(Uze,{scope:n,checked:x,disabled:a,children:[c.jsx(ze.button,{type:"button",role:"switch","aria-checked":x,"aria-required":i,"data-state":LX(x),"data-disabled":a?"":void 0,disabled:a,value:l,...f,ref:p,onClick:ke(e.onClick,v=>{y(w=>!w),b&&(g.current=v.isPropagationStopped(),g.current||v.stopPropagation())})}),b&&c.jsx($X,{control:h,bubbles:!g.current,name:r,value:l,checked:x,required:i,disabled:a,form:d,style:{transform:"translateX(-100%)"}})]})});PX.displayName=fC;var OX="SwitchThumb",FX=T.forwardRef((e,t)=>{const{__scopeSwitch:n,...r}=e,s=Wze(OX,n);return c.jsx(ze.span,{"data-state":LX(s.checked),"data-disabled":s.disabled?"":void 0,...r,ref:t})});FX.displayName=OX;var qze="SwitchBubbleInput",$X=T.forwardRef(({__scopeSwitch:e,control:t,checked:n,bubbles:r=!0,...s},o)=>{const i=T.useRef(null),a=rt(i,o),l=gx(n),u=ix(t);return T.useEffect(()=>{const d=i.current;if(!d)return;const f=window.HTMLInputElement.prototype,m=Object.getOwnPropertyDescriptor(f,"checked").set;if(l!==n&&m){const p=new Event("click",{bubbles:r});m.call(d,n),d.dispatchEvent(p)}},[l,n,r]),c.jsx("input",{type:"checkbox","aria-hidden":!0,defaultChecked:n,...s,tabIndex:-1,ref:a,style:{...s.style,...u,position:"absolute",pointerEvents:"none",opacity:0,margin:0}})});$X.displayName=qze;function LX(e){return e?"checked":"unchecked"}var iy=PX,AI=FX;const g_=T.forwardRef(({className:e,...t},n)=>c.jsx(iy,{className:Z("peer inline-flex h-6 w-11 shrink-0 cursor-pointer items-center rounded-full border-2 border-transparent transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background disabled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:bg-primary data-[state=unchecked]:bg-input",e),...t,ref:n,children:c.jsx(AI,{className:Z("pointer-events-none block h-5 w-5 rounded-full bg-background shadow-lg ring-0 transition-transform data-[state=checked]:translate-x-5 data-[state=unchecked]:translate-x-0")})}));g_.displayName=iy.displayName;function Yze({interaction:e,onUpdate:t}){return c.jsxs("div",{className:"space-y-4",children:[c.jsxs("div",{className:"space-y-2",children:[c.jsx(ce,{className:"text-sm font-medium",children:"Fetch mode"}),c.jsx("p",{className:"text-xs text-muted-foreground mb-2",children:"Choose when to load the detailed data"}),c.jsxs(nt,{value:e.fetchMode||"lazy",onValueChange:n=>t({...e,fetchMode:n}),children:[c.jsx(et,{children:c.jsx(ot,{placeholder:"Choose fetch mode..."})}),c.jsxs(tt,{children:[c.jsx(be,{value:"lazy",children:c.jsxs("div",{className:"flex flex-col items-start gap-1 py-1",children:[c.jsx("span",{className:"font-medium",children:"Lazy loading"}),c.jsx("span",{className:"text-xs text-muted-foreground",children:"Fetch data only when user clicks"})]})}),c.jsx(be,{value:"preloaded",children:c.jsxs("div",{className:"flex flex-col items-start gap-1 py-1",children:[c.jsx("span",{className:"font-medium",children:"Preloaded"}),c.jsx("span",{className:"text-xs text-muted-foreground",children:"Fetch all data when dashboard loads"})]})})]})]}),c.jsxs("div",{className:"rounded-md bg-blue-50 dark:bg-blue-900/20 border border-blue-200 dark:border-blue-800 p-3 flex gap-2",children:[c.jsx(Wn,{className:"h-4 w-4 text-blue-600 dark:text-blue-400 mt-0.5 flex-shrink-0"}),c.jsx("div",{className:"text-xs text-blue-800 dark:text-blue-200",children:e.fetchMode==="lazy"?c.jsxs(c.Fragment,{children:[c.jsx("div",{className:"font-medium",children:"Lazy loading"}),c.jsx("div",{className:"mt-1",children:"Data is fetched on-demand when the user clicks. Best for large datasets or when detailed data isn't always needed."})]}):c.jsxs(c.Fragment,{children:[c.jsx("div",{className:"font-medium",children:"Preloaded"}),c.jsx("div",{className:"mt-1",children:"Data is fetched when the dashboard loads. Best for small datasets or when instant drill-down is required."})]})})]})]}),c.jsxs("div",{className:"space-y-2",children:[c.jsx(ce,{className:"text-sm font-medium",children:"Record limit"}),c.jsx("p",{className:"text-xs text-muted-foreground mb-2",children:"Maximum number of detailed records to show (0 for unlimited)"}),c.jsx(Nn,{type:"number",min:"0",placeholder:"100",value:e.inlineLimit??100,onChange:n=>{const r=parseInt(n.target.value)||0;t({...e,inlineLimit:r})}})]}),c.jsxs("div",{className:"space-y-2",children:[c.jsx(ce,{className:"text-sm font-medium",children:"Display mode"}),c.jsx("p",{className:"text-xs text-muted-foreground mb-2",children:"How to display the detailed records"}),c.jsxs(nt,{value:e.displayMode||"table",onValueChange:n=>t({...e,displayMode:n}),children:[c.jsx(et,{children:c.jsx(ot,{placeholder:"Choose display mode..."})}),c.jsxs(tt,{children:[c.jsx(be,{value:"table",children:c.jsx("div",{className:"flex items-center gap-2",children:c.jsx("span",{children:"Table view"})})}),c.jsx(be,{value:"list",children:c.jsx("div",{className:"flex items-center gap-2",children:c.jsx("span",{children:"List view"})})}),c.jsx(be,{value:"cards",children:c.jsx("div",{className:"flex items-center gap-2",children:c.jsx("span",{children:"Card view"})})})]})]})]}),c.jsxs("div",{className:"flex items-center justify-between rounded-md border p-3 bg-background",children:[c.jsxs("div",{className:"space-y-0.5",children:[c.jsx(ce,{className:"text-sm font-medium",children:"Show in modal"}),c.jsx("p",{className:"text-xs text-muted-foreground",children:"Display detailed records in a modal overlay"})]}),c.jsx(g_,{checked:e.showInModal??!1,onCheckedChange:n=>t({...e,showInModal:n})})]}),c.jsxs("div",{className:"flex items-center justify-between rounded-md border p-3 bg-background",children:[c.jsxs("div",{className:"space-y-0.5",children:[c.jsx(ce,{className:"text-sm font-medium",children:"Allow export"}),c.jsx("p",{className:"text-xs text-muted-foreground",children:"Enable users to export the detailed records"})]}),c.jsx(g_,{checked:e.allowExport??!0,onCheckedChange:n=>t({...e,allowExport:n})})]}),c.jsxs("div",{className:"rounded-md bg-green-50 dark:bg-green-900/20 border border-green-200 dark:border-green-800 p-3",children:[c.jsx("div",{className:"text-xs text-green-800 dark:text-green-200",children:"✓ Inline drill configured successfully"}),c.jsxs("div",{className:"mt-2 space-y-1 text-xs text-green-700 dark:text-green-300",children:[c.jsxs("div",{children:["Mode: ",e.fetchMode==="lazy"?"Lazy loading":"Preloaded"]}),c.jsxs("div",{children:["Limit: ",e.inlineLimit===0?"Unlimited":`${e.inlineLimit} records`]}),c.jsxs("div",{children:["Display: ",e.displayMode==="table"?"Table view":e.displayMode==="list"?"List view":"Card view"]})]})]}),c.jsxs("div",{className:"space-y-2",children:[c.jsx(ce,{className:"text-sm font-medium",children:"Menu label"}),c.jsx(Nn,{value:e.label||"",onChange:n=>t({...e,label:n.target.value}),placeholder:hf(e.mode)}),c.jsx("p",{className:"text-xs text-muted-foreground",children:"How this interaction appears when multiple actions are available"})]})]})}function Gze({interaction:e,metrics:t,attributes:n,availableFields:r,card:s,onUpdateHierarchies:o,onUpdate:i,onRemove:a}){const l=e.trigger!==void 0,u=e.mode!==void 0,d=l&&u,[f,h]=C.useState(!d),m=()=>{var x;if(!l)return"Configure interaction";const g=`When ${((x=e.trigger)==null?void 0:x.field.label)||"..."}`;if(!u)return`${g} → Choose action`;const b=e.label||hf(e.mode);return`${g} → ${b}`},p=u?Bw(e.mode):null;return c.jsxs(Do,{className:"relative p-0",children:[c.jsx(se,{variant:"ghost",size:"sm",className:"absolute right-2 top-2 z-10 h-8 w-8 p-0",onClick:a,"aria-label":"Remove interaction",children:c.jsx(yt,{className:"h-3 w-3"})}),c.jsxs(Js,{open:f,onOpenChange:h,children:[c.jsx(eo,{asChild:!0,children:c.jsxs(se,{variant:"ghost",className:"h-auto w-full justify-between p-4 pr-12 hover:bg-muted/50",children:[c.jsxs("div",{className:"flex items-center gap-3",children:[p&&c.jsx(p,{className:"h-4 w-4 flex-shrink-0"}),c.jsx("span",{className:"text-left text-sm font-medium",children:m()})]}),f?c.jsx(FD,{className:"h-3 w-3 flex-shrink-0"}):c.jsx(M1,{className:"h-3 w-3 flex-shrink-0"})]})}),c.jsx(to,{children:c.jsxs("div",{className:"space-y-6 border-t p-6",children:[c.jsx("div",{className:"space-y-3",children:l?c.jsxs("div",{className:"space-y-2",children:[c.jsxs("div",{className:"text-sm font-medium",children:["When I click on"," ",c.jsx("span",{className:"text-muted-foreground",children:"(value of)"})]}),e.trigger&&c.jsxs("div",{className:"inline-flex cursor-pointer items-center gap-2 rounded-md border bg-background px-3 py-2 hover:bg-muted/50",onClick:()=>{i({...e,trigger:void 0})},children:[Eb(e.trigger.field.dataType),c.jsx("span",{className:"text-sm font-medium",children:e.trigger.field.label})]})]}):c.jsxs(c.Fragment,{children:[c.jsx("div",{className:"text-sm font-medium",children:"When I click on"}),c.jsx(_Le,{value:e.trigger,onChange:g=>{i({...e,trigger:g})},metrics:t,attributes:n})]})}),l&&c.jsx(c.Fragment,{children:c.jsxs("div",{className:"space-y-3",children:[c.jsx("div",{className:"text-sm font-medium",children:"I want to"}),c.jsx(DLe,{value:e.mode,onChange:g=>{if(!e.trigger){console.error("Trigger must be defined before selecting action");return}const b={mode:g,trigger:e.trigger};switch(g){case"clickFilter":i({...b,mode:"clickFilter",filterFields:[]});break;case"drillDown":i({...b,mode:"drillDown",filterFields:[]});break;case"dynamicDrill":i({...b,mode:"dynamicDrill",availableFields:[]});break;case"drillThrough":i({...b,mode:"drillThrough",filterFields:[],targetDashboardId:""});break;case"drillToDetail":i({...b,mode:"drillToDetail",filterFields:[]});break;case"drillToURL":i({...b,mode:"drillToURL",filterFields:[],urlTemplate:"",parameters:[],encodeParameters:!0});break;case"inlineDrill":i({...b,mode:"inlineDrill",filterFields:[]});break}}})]})}),l&&u&&c.jsxs(c.Fragment,{children:[c.jsx(As,{}),c.jsx(Kze,{interaction:e,metrics:t,attributes:n,availableFields:r,card:s,onUpdateHierarchies:o,onUpdate:i})]})]})})]})]})}function Kze({interaction:e,metrics:t,attributes:n,availableFields:r,card:s,onUpdateHierarchies:o,onUpdate:i}){switch(e.mode){case"clickFilter":return c.jsx(MLe,{interaction:e,onUpdate:a=>i(a)});case"drillDown":return c.jsx(jze,{interaction:e,onUpdate:a=>i(a),card:s,availableFields:r,onUpdateHierarchies:o});case"dynamicDrill":return c.jsx(_ze,{interaction:e,onUpdate:a=>i(a),availableFields:r});case"drillThrough":return c.jsx(Tze,{interaction:e,onUpdate:a=>i(a)});case"drillToDetail":return c.jsx(Aze,{interaction:e,onUpdate:a=>i(a)});case"drillToURL":return c.jsx(Vze,{interaction:e,availableFields:[...t,...n],onUpdate:a=>i(a)});case"inlineDrill":return c.jsx(Yze,{interaction:e,onUpdate:a=>i(a)});default:return c.jsx("div",{className:"text-sm text-muted-foreground",children:"Unknown interaction type"})}}function Zze({interactions:e,metrics:t,attributes:n,availableFields:r,card:s,onUpdateHierarchies:o,onChange:i}){const[a,l]=C.useState(null),u=()=>{const h={};i([...e,h]),l(e.length)},d=(h,m)=>{const p=[...e];p[h]=m,i(p)},f=h=>{const m=e.filter((p,g)=>g!==h);i(m),a===h&&l(null)};return c.jsxs("div",{className:"space-y-4",children:[e.length>0?c.jsx("div",{className:"space-y-3",children:e.map((h,m)=>c.jsx(Gze,{interaction:h,metrics:t,attributes:n,availableFields:r,card:s,onUpdateHierarchies:o,onUpdate:p=>d(m,p),onRemove:()=>f(m)},m))}):c.jsx("div",{className:"border rounded-lg p-8 text-center bg-muted/30",children:c.jsxs("div",{className:"space-y-2",children:[c.jsx("div",{className:"text-sm font-medium",children:"No interactions configured"}),c.jsx("div",{className:"text-xs text-muted-foreground",children:'Click "Add Interaction" to create your first interaction'}),c.jsx("div",{className:"pt-2",children:c.jsxs(se,{onClick:u,size:"sm",variant:"outline",children:[c.jsx(Sr,{className:"mr-2 h-4 w-4"}),"Add First Interaction"]})})]})}),e.length>0&&c.jsx("div",{className:"flex justify-start pt-2",children:c.jsxs(se,{onClick:u,size:"sm",variant:"outline",children:[c.jsx(Sr,{className:"mr-2 h-4 w-4"}),"Add Interaction"]})})]})}function Xze(){var L,F,H;const{open:e,frameId:t,cardId:n,closePopover:r,anchorPosition:s}=fR(),o=Npe(),i=jpe(),{updateCurrentDashboardCard:a}=Ot(),{setCard:l}=Qn(),u=X($=>$.dashboard),d=((L=u==null?void 0:u.sheets)==null?void 0:L.flatMap($=>$.frames||[]).find($=>($==null?void 0:$.id)===t))||null,f=d&&n?d.cards.find($=>$.id===n):null;C.useEffect(()=>{e&&f&&l(f)},[e,f,l]);const{columns:h}=pT(),{metricFields:m,groupByFields:p,pivotByFields:g}=Rz();[...p,...g];const b=h,x=m,y=[...p,...g],v=((F=o.interactionConfig)==null?void 0:F.drillHierarchies)||[],w=((H=o.interactionConfig)==null?void 0:H.allowedDrillTargets)||[],[N,S]=C.useState(v),[j,E]=C.useState(w||[]),[_,k]=C.useState(null),[M,D]=C.useState(()=>Si(o.interactionConfig));C.useRef(null),C.useEffect(()=>{var $,A;e&&(S((($=o.interactionConfig)==null?void 0:$.drillHierarchies)||[]),E(((A=o.interactionConfig)==null?void 0:A.allowedDrillTargets)||[]),k(null),D(Si(o.interactionConfig)))},[e,o.interactionConfig]);const R=()=>{i.updateDrillHierarchies(N),i.updateAllowedDrillTargets(j);const $={...o,interactionConfig:{...o.interactionConfig,drillHierarchies:N,allowedDrillTargets:j,interactions:M}};a($),l($),r()},P=()=>{k(null),r()};if(!e||!t||!n||!f||!s)return null;const I={position:"fixed",left:`${s.left}px`,top:`${s.top}px`,width:`${s.width}px`,height:`${s.height}px`};return c.jsxs(Xr,{modal:!1,open:e,onOpenChange:$=>!$&&r(),children:[c.jsx(Qr,{asChild:!0,children:c.jsx("div",{style:I,className:"pointer-events-none invisible","aria-hidden":"true"})}),c.jsxs(Jr,{onEscapeKeyDown:$=>$.preventDefault(),className:"mt-5 flex max-h-[70vh] w-[600px] max-w-4xl flex-col overflow-hidden p-0",align:"start",side:"right",sideOffset:20,children:[c.jsx(MNe,{className:"fill-border",width:12,height:8}),c.jsxs("div",{className:"flex flex-col border-b px-6 py-4",children:[c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsx("h2",{className:"text-lg font-semibold",children:"Configure Interactions"}),M.length>0&&c.jsx(Fe,{variant:"default",className:"h-5 min-w-5 rounded-full px-1.5 text-xs",children:M.length})]}),c.jsxs("p",{className:"text-sm text-muted-foreground",children:["Set up drill behaviors for"," ",(f==null?void 0:f.title)||(o==null?void 0:o.title)||"this chart"]})]}),c.jsx("div",{className:"min-h-0 flex-1 overflow-y-auto",children:c.jsx("div",{className:"space-y-6 p-6",children:c.jsx("div",{children:c.jsx("div",{className:"grid grid-cols-1 gap-4",children:c.jsx(Zze,{interactions:M,metrics:x,attributes:y,availableFields:b,card:{...o,interactionConfig:{...o.interactionConfig,drillHierarchies:N}},onUpdateHierarchies:S,onChange:D})})})})}),c.jsxs("div",{className:"flex justify-end gap-2 border-t px-6 py-4",children:[c.jsx(se,{variant:"outline",onClick:P,children:"Cancel"}),c.jsx(se,{onClick:R,children:"Save Changes"})]})]})]})}function Qze(e){return Tr(e.dataType)==="date"?220:e.uiType==="tabs"?200:e.uiType==="radio"?180:160}const Jze=100,e8e=400;function t8e({filter:e,isEditing:t=!1,dragListeners:n}){const{removeFilterValues:r,updateFilter:s,removeFilter:o}=Ot(),i=e.showLabel??!0,a=e.toolbarWidth??Qze(e),[l,u]=C.useState(!1),[d,f]=C.useState(a),h=C.useRef(null),m=C.useRef(d);C.useEffect(()=>{m.current=d},[d]),C.useEffect(()=>{l||f(a)},[a,l]);const p=C.useCallback(g=>{g.preventDefault(),g.stopPropagation();const b=g.clientX,x=m.current,y=w=>{const N=w.clientX-b,S=Math.max(Jze,Math.min(e8e,x+N));f(S),m.current=S},v=()=>{document.removeEventListener("mousemove",y),document.removeEventListener("mouseup",v),u(!1);const w=m.current;w!==a&&s({...e,toolbarWidth:w})};u(!0),document.addEventListener("mousemove",y),document.addEventListener("mouseup",v)},[a,e,s]);return c.jsxs("div",{ref:h,style:{width:d},className:Z("group relative flex shrink-0 flex-col gap-1 rounded-md p-2",l&&"select-none"),children:[(t||i)&&c.jsxs("div",{className:"flex items-center justify-between gap-1",children:[c.jsxs("div",{className:Z("flex min-w-0 flex-1 items-center gap-1",t&&n&&"cursor-grab active:cursor-grabbing"),...t?n:{},children:[t&&c.jsx(PD,{className:"size-3 shrink-0 text-muted-foreground/50"}),i&&c.jsx(ce,{className:"truncate text-xs font-medium text-muted-foreground",children:e.title||e.column})]}),c.jsxs("div",{className:"flex shrink-0 items-center gap-1",children:[t&&c.jsx(NI,{filter:e,isEditing:t,trigger:c.jsx("button",{className:"text-muted-foreground hover:text-foreground","aria-label":"Filter settings",children:c.jsx(Nl,{className:"size-3"})})}),t&&c.jsx("button",{onClick:()=>{r(e.id),o(e.id)},className:"text-muted-foreground hover:text-foreground","aria-label":"Remove filter",children:c.jsx(yt,{className:"size-3"})})]})]}),c.jsx("div",{className:"min-h-[32px]",children:c.jsx(rp,{filter:e})}),t&&c.jsx("div",{onMouseDown:p,className:Z("absolute bottom-0 right-0 top-0 w-2 cursor-ew-resize","hover:bg-muted-foreground/20",l&&"bg-primary/20"),"aria-label":"Resize filter"})]})}function n8e({filter:e,isEditing:t=!1,disabled:n=!1}){const{attributes:r,listeners:s,setNodeRef:o,transform:i,transition:a,isDragging:l}=oy({id:e.id,disabled:n||!t}),u={transform:ii.Translate.toString(i),transition:a,opacity:l?.5:1,zIndex:l?10:void 0};return c.jsx("div",{ref:o,style:u,...r,children:c.jsx(t8e,{filter:e,isEditing:t,dragListeners:t?s:void 0})})}function zX({open:e,onOpenChange:t}){const[n,r]=C.useState(!1),[s,o]=C.useState(!1),[i,a]=C.useState({sheetSelection:"current",protectPdf:!1,password:""}),l=X(b=>{var x;return(x=b.dashboard)==null?void 0:x.sheets}),u=X(b=>b.selectedSheetId),{authToken:d,tokenProps:f}=Ge(),h=l==null?void 0:l.find(b=>b.id===u),m=((l==null?void 0:l.length)||0)>1,p=()=>{a({sheetSelection:"current",protectPdf:!1,password:""}),r(!1),t(!1)};async function g(){if(i.protectPdf&&!i.password){Oe.error("Please enter a password to protect the PDF");return}o(!0);const b=i.sheetSelection==="all"?"Generating PDF for all sheets... This may take a while.":i.protectPdf?"Generating protected PDF... may take up to 60 seconds":"Generating PDF... may take up to 60 seconds",x=Oe.loading(b);try{const y=VY();await kY(f.apiServiceUrl,d,i.protectPdf?i.password:void 0,i.sheetSelection,y),Oe.dismiss(x);const v=i.sheetSelection==="all"?"All sheets PDF downloaded successfully!":i.protectPdf?"Protected PDF downloaded successfully!":"PDF downloaded successfully!";Oe.success(v,{duration:2e3}),p()}catch(y){Oe.dismiss(x),Oe.error("Failed to download PDF",{description:"Please try again or contact support.",richColors:!0}),console.error("PDF download error:",y)}finally{o(!1)}}return c.jsx(ns,{open:e,onOpenChange:b=>{if(!b){p();return}t(!0)},children:c.jsxs(Vr,{className:"sm:max-w-[425px]",children:[c.jsxs(Hr,{children:[c.jsx(Ur,{children:"Export Dashboard"}),c.jsx(ys,{children:"Export your dashboard as a PDF document."})]}),c.jsxs("div",{className:"space-y-4 py-4",children:[m&&c.jsxs(c.Fragment,{children:[c.jsxs("div",{className:"space-y-3",children:[c.jsx(ce,{children:"Export Scope"}),c.jsxs(jo,{value:i.sheetSelection,onValueChange:b=>a({...i,sheetSelection:b}),children:[c.jsxs("div",{className:"flex items-center space-x-2",children:[c.jsx(In,{value:"current",id:"scope-current"}),c.jsxs(ce,{htmlFor:"scope-current",className:"cursor-pointer font-normal",children:["This sheet (",(h==null?void 0:h.title)||"Current",")"]})]}),c.jsxs("div",{className:"flex items-center space-x-2",children:[c.jsx(In,{value:"all",id:"scope-all"}),c.jsxs(ce,{htmlFor:"scope-all",className:"cursor-pointer font-normal",children:["All sheets (",l==null?void 0:l.length," sheets)"]})]})]})]}),c.jsx(As,{})]}),c.jsxs("div",{className:"space-y-3",children:[c.jsxs("div",{className:"flex items-center space-x-2",children:[c.jsx(Qt,{id:"protect-pdf",checked:i.protectPdf,onCheckedChange:b=>{a({...i,protectPdf:b,password:b?i.password:""}),b||r(!1)}}),c.jsxs(ce,{htmlFor:"protect-pdf",className:"flex cursor-pointer items-center text-sm font-normal",children:[c.jsx(C8,{className:"mr-2 h-3.5 w-3.5"}),"Password protect PDF"]})]}),i.protectPdf&&c.jsxs("div",{className:"ml-6 space-y-2",children:[c.jsx(ce,{htmlFor:"pdf-password",className:"text-sm",children:"Password"}),c.jsxs("div",{className:"relative",children:[c.jsx(Nn,{id:"pdf-password",type:n?"text":"password",value:i.password,onChange:b=>a({...i,password:b.target.value}),placeholder:"Enter password",className:"pr-10",onKeyDown:b=>{b.key==="Enter"&&i.password&&g()}}),c.jsx(se,{type:"button",variant:"ghost",size:"sm",className:"absolute right-0 top-0 h-full px-3 py-2 hover:bg-transparent",onClick:()=>r(!n),children:n?c.jsx(k1,{className:"h-4 w-4 text-muted-foreground"}):c.jsx($c,{className:"h-4 w-4 text-muted-foreground"})})]}),c.jsx("p",{className:"text-xs text-muted-foreground",children:"Recipients will need this password to open the PDF"})]})]})]}),c.jsxs(xs,{children:[c.jsx(se,{variant:"outline",onClick:p,disabled:s,children:"Cancel"}),c.jsx(se,{onClick:g,disabled:s,children:s?c.jsxs(c.Fragment,{children:[c.jsx(an,{className:"mr-2 h-4 w-4 animate-spin"}),"Exporting..."]}):c.jsxs(c.Fragment,{children:[c.jsx(am,{className:"mr-2 h-4 w-4"}),"Export"]})})]})]})})}function BX({iconClassName:e}){const[t,n]=C.useState(!1),r=X(s=>s.isDownloadingPdf);return c.jsxs(c.Fragment,{children:[c.jsx(se,{variant:"ghost",size:"sm",className:"h-7 p-2",disabled:r,onClick:()=>n(!0),children:c.jsx(am,{className:Z("size-4",e)})}),c.jsx(zX,{open:t,onOpenChange:n})]})}function r8e(e,t){return e.displayMode&&e.displayMode!=="inherit"?e.displayMode:(t==null?void 0:t.displayMode)||"canvas"}function s8e(){var f;const e=X(h=>h.selectedSheetId),t=X(h=>h.dashboard.filters),n=X(h=>h.dashboard.filterLayout),r=X(h=>h.isDashboardEditing),{reorderFilters:s}=Ot(),o=lC(tm(ap,{activationConstraint:{distance:5}})),i=(f=Bl(t,e))==null?void 0:f.filter(h=>!h.hide&&h.location!=="frame"),a=i==null?void 0:i.filter(h=>r8e(h,n)==="toolbar");function l(h){const{active:m,over:p}=h;if(!p||m.id===p.id||!t)return;const g=t.findIndex(x=>x.id===m.id),b=t.findIndex(x=>x.id===p.id);if(g!==-1&&b!==-1){const x=lp(t.map(y=>y.id),g,b);s(x)}}if(!(a!=null&&a.length))return null;const u=(n==null?void 0:n.toolbarWrap)??!1,d=(n==null?void 0:n.showDownloadButton)??!1;return c.jsx(ry,{sensors:o,collisionDetection:ey,onDragEnd:l,children:c.jsx(sy,{items:a.map(h=>h.id),strategy:TI,children:c.jsxs("div",{className:Z("flex items-center border-b bg-background px-1",u?"flex-wrap":"w-0 min-w-full overflow-x-auto"),role:"toolbar","aria-label":"Dashboard filters",children:[a.map(h=>c.jsx(n8e,{filter:h,isEditing:r},h.id)),d&&c.jsx("div",{className:"ml-auto",children:c.jsx(BX,{})})]})})})}const o8e=w4.WidthProvider(w4.Responsive);function i8e(e,t){return e.displayMode&&e.displayMode!=="inherit"?e.displayMode:(t==null?void 0:t.displayMode)||"canvas"}function a8e(){const{open:e}=fR();return e?c.jsx(Xze,{}):null}function l8e({sheet:e}){var v,w;const t=X(N=>N.isDashboardEditing),n=X(N=>N.currentBreakpoint),r=X(N=>N.themeStyle),s=C.useRef(0),o=X(N=>N.selectedSheetId),i=e.layouts,a=X(N=>N.dashboard.filters),l=X(N=>N.dashboard.filterLayout),u=e.frames,{setSheetLayouts:d,setCurrentBreakpoint:f}=X(N=>N.actions);C.useEffect(()=>{document.documentElement.style.setProperty("--placeholder-border-radius",`${r==null?void 0:r.cardBorderRadius}px`)},[r==null?void 0:r.cardBorderRadius]);function h(N){f(N)}function m(N,S){o===e.id&&d(o,S)}if(!o)return null;const p=(N,S)=>c.jsx(VX,{className:"after:content-none",ref:S,handleAxis:N}),g=N=>N&&(N==null?void 0:N.h)===1&&(N==null?void 0:N.w)===1?{...N,h:8,minH:7,w:7}:null;function b(){var j;const N=(j=Bl(a,o))==null?void 0:j.filter(E=>!E.hide),S=N==null?void 0:N.filter(E=>i8e(E,l)==="canvas");return S==null?void 0:S.map(E=>{var M;const _=(M=i==null?void 0:i[n])==null?void 0:M.find(D=>D.i===E.id);if(E.location==="frame")return null;const k=g(_);return c.jsxs("div",{style:{borderRadius:r==null?void 0:r.cardBorderRadius},className:Z("z-50 flex flex-col rounded-md border bg-background px-3 py-2"),...k?{"data-grid":k}:{},children:[c.jsx(jI,{filter:E}),c.jsx(rp,{filter:E})]},E.id)})}function x(){return u==null?void 0:u.map(N=>c.jsx("div",{role:"dashboard-frame-container",className:Z("group isolate overflow-hidden",r==null?void 0:r.dashboardCardContainer),children:c.jsx(Ua,{FallbackComponent:({error:S,resetErrorBoundary:j})=>c.jsx(C3e,{error:S,resetErrorBoundary:j,frame:N}),children:c.jsx(fLe,{frame:N})})},N.id))}const y=((v=r==null?void 0:r.gridLayout)==null?void 0:v.margin)||[10,10];return!u||u.length===0?c.jsx(ELe,{sheetId:e.id}):c.jsxs(e_e,{children:[c.jsx(s8e,{}),c.jsxs(o8e,{margin:y,isDraggable:t,resizeHandles:t?["s","w","e","n","sw","nw","se","ne"]:[],className:Z((w=r==null?void 0:r.gridLayout)==null?void 0:w.className),layouts:i,cols:{lg:48,md:36,sm:24,xs:12,xxs:6},rowHeight:1,onBreakpointChange:h,onLayoutChange:m,onResize:(N,S,j,E,_,k)=>{const M=Date.now();M-s.current>100&&(k.scrollIntoView({behavior:"auto",block:"nearest"}),s.current=M)},onResizeStop:(N,S,j,E,_,k)=>{k.scrollIntoView({behavior:"smooth",block:"nearest"})},resizeHandle:p,children:[b(),x()]}),c.jsx(a8e,{})]})}const VX=C.forwardRef(({className:e,handleAxis:t,...n},r)=>{const s=X(o=>o.themeStyle);return s!=null&&s.cardBorderRadius,c.jsx("div",{ref:r,className:Z(`react-resizable-handle z-20 react-resizable-handle-${t} absolute border-foreground/40`,{"z-30 h-4 w-4":["sw","nw","se","ne"].includes(t),"bottom-0 left-0 cursor-sw-resize":t==="sw","left-0 top-0 cursor-nw-resize":t==="nw","bottom-0 right-0 cursor-se-resize":t==="se","right-0 top-0 cursor-ne-resize":t==="ne","!bottom-0 !left-0 !right-0 !h-2 !w-full cursor-ns-resize":t==="s","!left-0 !right-0 !top-0 !h-2 !w-full cursor-ns-resize":t==="n","!bottom-0 !right-0 !top-0 !h-full !w-2 cursor-ew-resize":t==="e","!bottom-0 !left-0 !top-0 !h-full !w-2 cursor-ew-resize":t==="w"},e),...n})});VX.displayName="ResizeHandle";const hC=C.createContext(null);hC.displayName="PanelGroupContext";const rr={group:"data-panel-group",groupDirection:"data-panel-group-direction",groupId:"data-panel-group-id",panel:"data-panel",panelCollapsible:"data-panel-collapsible",panelId:"data-panel-id",panelSize:"data-panel-size",resizeHandle:"data-resize-handle",resizeHandleActive:"data-resize-handle-active",resizeHandleEnabled:"data-panel-resize-handle-enabled",resizeHandleId:"data-panel-resize-handle-id",resizeHandleState:"data-resize-handle-state"},PI=10,Nd=C.useLayoutEffect,T$=T.useId,c8e=typeof T$=="function"?T$:()=>null;let u8e=0;function OI(e=null){const t=c8e(),n=C.useRef(e||t||null);return n.current===null&&(n.current=""+u8e++),e??n.current}function HX({children:e,className:t="",collapsedSize:n,collapsible:r,defaultSize:s,forwardedRef:o,id:i,maxSize:a,minSize:l,onCollapse:u,onExpand:d,onResize:f,order:h,style:m,tagName:p="div",...g}){const b=C.useContext(hC);if(b===null)throw Error("Panel components must be rendered within a PanelGroup container");const{collapsePanel:x,expandPanel:y,getPanelSize:v,getPanelStyle:w,groupId:N,isPanelCollapsed:S,reevaluatePanelConstraints:j,registerPanel:E,resizePanel:_,unregisterPanel:k}=b,M=OI(i),D=C.useRef({callbacks:{onCollapse:u,onExpand:d,onResize:f},constraints:{collapsedSize:n,collapsible:r,defaultSize:s,maxSize:a,minSize:l},id:M,idIsFromProps:i!==void 0,order:h});C.useRef({didLogMissingDefaultSizeWarning:!1}),Nd(()=>{const{callbacks:P,constraints:I}=D.current,L={...I};D.current.id=M,D.current.idIsFromProps=i!==void 0,D.current.order=h,P.onCollapse=u,P.onExpand=d,P.onResize=f,I.collapsedSize=n,I.collapsible=r,I.defaultSize=s,I.maxSize=a,I.minSize=l,(L.collapsedSize!==I.collapsedSize||L.collapsible!==I.collapsible||L.maxSize!==I.maxSize||L.minSize!==I.minSize)&&j(D.current,L)}),Nd(()=>{const P=D.current;return E(P),()=>{k(P)}},[h,M,E,k]),C.useImperativeHandle(o,()=>({collapse:()=>{x(D.current)},expand:P=>{y(D.current,P)},getId(){return M},getSize(){return v(D.current)},isCollapsed(){return S(D.current)},isExpanded(){return!S(D.current)},resize:P=>{_(D.current,P)}}),[x,y,v,S,M,_]);const R=w(D.current,s);return C.createElement(p,{...g,children:e,className:t,id:M,style:{...R,...m},[rr.groupId]:N,[rr.panel]:"",[rr.panelCollapsible]:r||void 0,[rr.panelId]:M,[rr.panelSize]:parseFloat(""+R.flexGrow).toFixed(1)})}const UX=C.forwardRef((e,t)=>C.createElement(HX,{...e,forwardedRef:t}));HX.displayName="Panel";UX.displayName="forwardRef(Panel)";let b_=null,gv=-1,ac=null;function d8e(e,t){if(t){const n=(t&KX)!==0,r=(t&ZX)!==0,s=(t&XX)!==0,o=(t&QX)!==0;if(n)return s?"se-resize":o?"ne-resize":"e-resize";if(r)return s?"sw-resize":o?"nw-resize":"w-resize";if(s)return"s-resize";if(o)return"n-resize"}switch(e){case"horizontal":return"ew-resize";case"intersection":return"move";case"vertical":return"ns-resize"}}function f8e(){ac!==null&&(document.head.removeChild(ac),b_=null,ac=null,gv=-1)}function a2(e,t){var n,r;const s=d8e(e,t);if(b_!==s){if(b_=s,ac===null&&(ac=document.createElement("style"),document.head.appendChild(ac)),gv>=0){var o;(o=ac.sheet)===null||o===void 0||o.removeRule(gv)}gv=(n=(r=ac.sheet)===null||r===void 0?void 0:r.insertRule(`*{cursor: ${s} !important;}`))!==null&&n!==void 0?n:-1}}function WX(e){return e.type==="keydown"}function qX(e){return e.type.startsWith("pointer")}function YX(e){return e.type.startsWith("mouse")}function mC(e){if(qX(e)){if(e.isPrimary)return{x:e.clientX,y:e.clientY}}else if(YX(e))return{x:e.clientX,y:e.clientY};return{x:1/0,y:1/0}}function h8e(){if(typeof matchMedia=="function")return matchMedia("(pointer:coarse)").matches?"coarse":"fine"}function m8e(e,t,n){return e.x<t.x+t.width&&e.x+e.width>t.x&&e.y<t.y+t.height&&e.y+e.height>t.y}function p8e(e,t){if(e===t)throw new Error("Cannot compare node with itself");const n={a:A$(e),b:A$(t)};let r;for(;n.a.at(-1)===n.b.at(-1);)e=n.a.pop(),t=n.b.pop(),r=e;Mt(r,"Stacking order can only be calculated for elements with a common ancestor");const s={a:I$(R$(n.a)),b:I$(R$(n.b))};if(s.a===s.b){const o=r.childNodes,i={a:n.a.at(-1),b:n.b.at(-1)};let a=o.length;for(;a--;){const l=o[a];if(l===i.a)return 1;if(l===i.b)return-1}}return Math.sign(s.a-s.b)}const g8e=/\b(?:position|zIndex|opacity|transform|webkitTransform|mixBlendMode|filter|webkitFilter|isolation)\b/;function b8e(e){var t;const n=getComputedStyle((t=GX(e))!==null&&t!==void 0?t:e).display;return n==="flex"||n==="inline-flex"}function x8e(e){const t=getComputedStyle(e);return!!(t.position==="fixed"||t.zIndex!=="auto"&&(t.position!=="static"||b8e(e))||+t.opacity<1||"transform"in t&&t.transform!=="none"||"webkitTransform"in t&&t.webkitTransform!=="none"||"mixBlendMode"in t&&t.mixBlendMode!=="normal"||"filter"in t&&t.filter!=="none"||"webkitFilter"in t&&t.webkitFilter!=="none"||"isolation"in t&&t.isolation==="isolate"||g8e.test(t.willChange)||t.webkitOverflowScrolling==="touch")}function R$(e){let t=e.length;for(;t--;){const n=e[t];if(Mt(n,"Missing node"),x8e(n))return n}return null}function I$(e){return e&&Number(getComputedStyle(e).zIndex)||0}function A$(e){const t=[];for(;e;)t.push(e),e=GX(e);return t}function GX(e){const{parentNode:t}=e;return t&&t instanceof ShadowRoot?t.host:t}const KX=1,ZX=2,XX=4,QX=8,y8e=h8e()==="coarse";let Mi=[],dh=!1,Hu=new Map,pC=new Map;const Tb=new Set;function v8e(e,t,n,r,s){var o;const{ownerDocument:i}=t,a={direction:n,element:t,hitAreaMargins:r,setResizeHandlerState:s},l=(o=Hu.get(i))!==null&&o!==void 0?o:0;return Hu.set(i,l+1),Tb.add(a),Gw(),function(){var d;pC.delete(e),Tb.delete(a);const f=(d=Hu.get(i))!==null&&d!==void 0?d:1;if(Hu.set(i,f-1),Gw(),f===1&&Hu.delete(i),Mi.includes(a)){const h=Mi.indexOf(a);h>=0&&Mi.splice(h,1),$I(),s("up",!0,null)}}}function w8e(e){const{target:t}=e,{x:n,y:r}=mC(e);dh=!0,FI({target:t,x:n,y:r}),Gw(),Mi.length>0&&(Kw("down",e),e.preventDefault(),JX(t)||e.stopImmediatePropagation())}function l2(e){const{x:t,y:n}=mC(e);if(dh&&e.buttons===0&&(dh=!1,Kw("up",e)),!dh){const{target:r}=e;FI({target:r,x:t,y:n})}Kw("move",e),$I(),Mi.length>0&&e.preventDefault()}function c2(e){const{target:t}=e,{x:n,y:r}=mC(e);pC.clear(),dh=!1,Mi.length>0&&(e.preventDefault(),JX(t)||e.stopImmediatePropagation()),Kw("up",e),FI({target:t,x:n,y:r}),$I(),Gw()}function JX(e){let t=e;for(;t;){if(t.hasAttribute(rr.resizeHandle))return!0;t=t.parentElement}return!1}function FI({target:e,x:t,y:n}){Mi.splice(0);let r=null;(e instanceof HTMLElement||e instanceof SVGElement)&&(r=e),Tb.forEach(s=>{const{element:o,hitAreaMargins:i}=s,a=o.getBoundingClientRect(),{bottom:l,left:u,right:d,top:f}=a,h=y8e?i.coarse:i.fine;if(t>=u-h&&t<=d+h&&n>=f-h&&n<=l+h){if(r!==null&&document.contains(r)&&o!==r&&!o.contains(r)&&!r.contains(o)&&p8e(r,o)>0){let p=r,g=!1;for(;p&&!p.contains(o);){if(m8e(p.getBoundingClientRect(),a)){g=!0;break}p=p.parentElement}if(g)return}Mi.push(s)}})}function u2(e,t){pC.set(e,t)}function $I(){let e=!1,t=!1;Mi.forEach(r=>{const{direction:s}=r;s==="horizontal"?e=!0:t=!0});let n=0;pC.forEach(r=>{n|=r}),e&&t?a2("intersection",n):e?a2("horizontal",n):t?a2("vertical",n):f8e()}let d2=new AbortController;function Gw(){d2.abort(),d2=new AbortController;const e={capture:!0,signal:d2.signal};Tb.size&&(dh?(Mi.length>0&&Hu.forEach((t,n)=>{const{body:r}=n;t>0&&(r.addEventListener("contextmenu",c2,e),r.addEventListener("pointerleave",l2,e),r.addEventListener("pointermove",l2,e))}),window.addEventListener("pointerup",c2,e),window.addEventListener("pointercancel",c2,e)):Hu.forEach((t,n)=>{const{body:r}=n;t>0&&(r.addEventListener("pointerdown",w8e,e),r.addEventListener("pointermove",l2,e))}))}function Kw(e,t){Tb.forEach(n=>{const{setResizeHandlerState:r}=n,s=Mi.includes(n);r(e,s,t)})}function S8e(){const[e,t]=C.useState(0);return C.useCallback(()=>t(n=>n+1),[])}function Mt(e,t){if(!e)throw console.error(t),Error(t)}function Gd(e,t,n=PI){return e.toFixed(n)===t.toFixed(n)?0:e>t?1:-1}function cl(e,t,n=PI){return Gd(e,t,n)===0}function yo(e,t,n){return Gd(e,t,n)===0}function C8e(e,t,n){if(e.length!==t.length)return!1;for(let r=0;r<e.length;r++){const s=e[r],o=t[r];if(!yo(s,o,n))return!1}return!0}function Zf({panelConstraints:e,panelIndex:t,size:n}){const r=e[t];Mt(r!=null,`Panel constraints not found for index ${t}`);let{collapsedSize:s=0,collapsible:o,maxSize:i=100,minSize:a=0}=r;if(Gd(n,a)<0)if(o){const l=(s+a)/2;Gd(n,l)<0?n=s:n=a}else n=a;return n=Math.min(i,n),n=parseFloat(n.toFixed(PI)),n}function og({delta:e,initialLayout:t,panelConstraints:n,pivotIndices:r,prevLayout:s,trigger:o}){if(yo(e,0))return t;const i=[...t],[a,l]=r;Mt(a!=null,"Invalid first pivot index"),Mt(l!=null,"Invalid second pivot index");let u=0;if(o==="keyboard"){{const f=e<0?l:a,h=n[f];Mt(h,`Panel constraints not found for index ${f}`);const{collapsedSize:m=0,collapsible:p,minSize:g=0}=h;if(p){const b=t[f];if(Mt(b!=null,`Previous layout not found for panel index ${f}`),yo(b,m)){const x=g-b;Gd(x,Math.abs(e))>0&&(e=e<0?0-x:x)}}}{const f=e<0?a:l,h=n[f];Mt(h,`No panel constraints found for index ${f}`);const{collapsedSize:m=0,collapsible:p,minSize:g=0}=h;if(p){const b=t[f];if(Mt(b!=null,`Previous layout not found for panel index ${f}`),yo(b,g)){const x=b-m;Gd(x,Math.abs(e))>0&&(e=e<0?0-x:x)}}}}{const f=e<0?1:-1;let h=e<0?l:a,m=0;for(;;){const g=t[h];Mt(g!=null,`Previous layout not found for panel index ${h}`);const x=Zf({panelConstraints:n,panelIndex:h,size:100})-g;if(m+=x,h+=f,h<0||h>=n.length)break}const p=Math.min(Math.abs(e),Math.abs(m));e=e<0?0-p:p}{let h=e<0?a:l;for(;h>=0&&h<n.length;){const m=Math.abs(e)-Math.abs(u),p=t[h];Mt(p!=null,`Previous layout not found for panel index ${h}`);const g=p-m,b=Zf({panelConstraints:n,panelIndex:h,size:g});if(!yo(p,b)&&(u+=p-b,i[h]=b,u.toPrecision(3).localeCompare(Math.abs(e).toPrecision(3),void 0,{numeric:!0})>=0))break;e<0?h--:h++}}if(C8e(s,i))return s;{const f=e<0?l:a,h=t[f];Mt(h!=null,`Previous layout not found for panel index ${f}`);const m=h+u,p=Zf({panelConstraints:n,panelIndex:f,size:m});if(i[f]=p,!yo(p,m)){let g=m-p,x=e<0?l:a;for(;x>=0&&x<n.length;){const y=i[x];Mt(y!=null,`Previous layout not found for panel index ${x}`);const v=y+g,w=Zf({panelConstraints:n,panelIndex:x,size:v});if(yo(y,w)||(g-=w-y,i[x]=w),yo(g,0))break;e>0?x--:x++}}}const d=i.reduce((f,h)=>h+f,0);return yo(d,100)?i:s}function N8e({layout:e,panelsArray:t,pivotIndices:n}){let r=0,s=100,o=0,i=0;const a=n[0];Mt(a!=null,"No pivot index found"),t.forEach((f,h)=>{const{constraints:m}=f,{maxSize:p=100,minSize:g=0}=m;h===a?(r=g,s=p):(o+=g,i+=p)});const l=Math.min(s,100-o),u=Math.max(r,100-i),d=e[a];return{valueMax:l,valueMin:u,valueNow:d}}function Rb(e,t=document){return Array.from(t.querySelectorAll(`[${rr.resizeHandleId}][data-panel-group-id="${e}"]`))}function eQ(e,t,n=document){const s=Rb(e,n).findIndex(o=>o.getAttribute(rr.resizeHandleId)===t);return s??null}function tQ(e,t,n){const r=eQ(e,t,n);return r!=null?[r,r+1]:[-1,-1]}function nQ(e,t=document){var n;if(t instanceof HTMLElement&&(t==null||(n=t.dataset)===null||n===void 0?void 0:n.panelGroupId)==e)return t;const r=t.querySelector(`[data-panel-group][data-panel-group-id="${e}"]`);return r||null}function gC(e,t=document){const n=t.querySelector(`[${rr.resizeHandleId}="${e}"]`);return n||null}function j8e(e,t,n,r=document){var s,o,i,a;const l=gC(t,r),u=Rb(e,r),d=l?u.indexOf(l):-1,f=(s=(o=n[d])===null||o===void 0?void 0:o.id)!==null&&s!==void 0?s:null,h=(i=(a=n[d+1])===null||a===void 0?void 0:a.id)!==null&&i!==void 0?i:null;return[f,h]}function k8e({committedValuesRef:e,eagerValuesRef:t,groupId:n,layout:r,panelDataArray:s,panelGroupElement:o,setLayout:i}){C.useRef({didWarnAboutMissingResizeHandle:!1}),Nd(()=>{if(!o)return;const a=Rb(n,o);for(let l=0;l<s.length-1;l++){const{valueMax:u,valueMin:d,valueNow:f}=N8e({layout:r,panelsArray:s,pivotIndices:[l,l+1]}),h=a[l];if(h!=null){const m=s[l];Mt(m,`No panel data found for index "${l}"`),h.setAttribute("aria-controls",m.id),h.setAttribute("aria-valuemax",""+Math.round(u)),h.setAttribute("aria-valuemin",""+Math.round(d)),h.setAttribute("aria-valuenow",f!=null?""+Math.round(f):"")}}return()=>{a.forEach((l,u)=>{l.removeAttribute("aria-controls"),l.removeAttribute("aria-valuemax"),l.removeAttribute("aria-valuemin"),l.removeAttribute("aria-valuenow")})}},[n,r,s,o]),C.useEffect(()=>{if(!o)return;const a=t.current;Mt(a,"Eager values not found");const{panelDataArray:l}=a,u=nQ(n,o);Mt(u!=null,`No group found for id "${n}"`);const d=Rb(n,o);Mt(d,`No resize handles found for group id "${n}"`);const f=d.map(h=>{const m=h.getAttribute(rr.resizeHandleId);Mt(m,"Resize handle element has no handle id attribute");const[p,g]=j8e(n,m,l,o);if(p==null||g==null)return()=>{};const b=x=>{if(!x.defaultPrevented)switch(x.key){case"Enter":{x.preventDefault();const y=l.findIndex(v=>v.id===p);if(y>=0){const v=l[y];Mt(v,`No panel data found for index ${y}`);const w=r[y],{collapsedSize:N=0,collapsible:S,minSize:j=0}=v.constraints;if(w!=null&&S){const E=og({delta:yo(w,N)?j-N:N-w,initialLayout:r,panelConstraints:l.map(_=>_.constraints),pivotIndices:tQ(n,m,o),prevLayout:r,trigger:"keyboard"});r!==E&&i(E)}}break}}};return h.addEventListener("keydown",b),()=>{h.removeEventListener("keydown",b)}});return()=>{f.forEach(h=>h())}},[o,e,t,n,r,s,i])}function P$(e,t){if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(e[n]!==t[n])return!1;return!0}function rQ(e,t){const n=e==="horizontal",{x:r,y:s}=mC(t);return n?r:s}function E8e(e,t,n,r,s){const o=n==="horizontal",i=gC(t,s);Mt(i,`No resize handle element found for id "${t}"`);const a=i.getAttribute(rr.groupId);Mt(a,"Resize handle element has no group id attribute");let{initialCursorPosition:l}=r;const u=rQ(n,e),d=nQ(a,s);Mt(d,`No group element found for id "${a}"`);const f=d.getBoundingClientRect(),h=o?f.width:f.height;return(u-l)/h*100}function _8e(e,t,n,r,s,o){if(WX(e)){const i=n==="horizontal";let a=0;e.shiftKey?a=100:s!=null?a=s:a=10;let l=0;switch(e.key){case"ArrowDown":l=i?0:a;break;case"ArrowLeft":l=i?-a:0;break;case"ArrowRight":l=i?a:0;break;case"ArrowUp":l=i?0:-a;break;case"End":l=100;break;case"Home":l=-100;break}return l}else return r==null?0:E8e(e,t,n,r,o)}function D8e({panelDataArray:e}){const t=Array(e.length),n=e.map(o=>o.constraints);let r=0,s=100;for(let o=0;o<e.length;o++){const i=n[o];Mt(i,`Panel constraints not found for index ${o}`);const{defaultSize:a}=i;a!=null&&(r++,t[o]=a,s-=a)}for(let o=0;o<e.length;o++){const i=n[o];Mt(i,`Panel constraints not found for index ${o}`);const{defaultSize:a}=i;if(a!=null)continue;const l=e.length-r,u=s/l;r++,t[o]=u,s-=u}return t}function Tf(e,t,n){t.forEach((r,s)=>{const o=e[s];Mt(o,`Panel data not found for index ${s}`);const{callbacks:i,constraints:a,id:l}=o,{collapsedSize:u=0,collapsible:d}=a,f=n[l];if(f==null||r!==f){n[l]=r;const{onCollapse:h,onExpand:m,onResize:p}=i;p&&p(r,f),d&&(h||m)&&(m&&(f==null||cl(f,u))&&!cl(r,u)&&m(),h&&(f==null||!cl(f,u))&&cl(r,u)&&h())}})}function O0(e,t){if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(e[n]!=t[n])return!1;return!0}function M8e({defaultSize:e,dragState:t,layout:n,panelData:r,panelIndex:s,precision:o=3}){const i=n[s];let a;return i==null?a=e!=null?e.toPrecision(o):"1":r.length===1?a="1":a=i.toPrecision(o),{flexBasis:0,flexGrow:a,flexShrink:1,overflow:"hidden",pointerEvents:t!==null?"none":void 0}}function T8e(e,t=10){let n=null;return(...s)=>{n!==null&&clearTimeout(n),n=setTimeout(()=>{e(...s)},t)}}function O$(e){try{if(typeof localStorage<"u")e.getItem=t=>localStorage.getItem(t),e.setItem=(t,n)=>{localStorage.setItem(t,n)};else throw new Error("localStorage not supported in this environment")}catch(t){console.error(t),e.getItem=()=>null,e.setItem=()=>{}}}function sQ(e){return`react-resizable-panels:${e}`}function oQ(e){return e.map(t=>{const{constraints:n,id:r,idIsFromProps:s,order:o}=t;return s?r:o?`${o}:${JSON.stringify(n)}`:JSON.stringify(n)}).sort((t,n)=>t.localeCompare(n)).join(",")}function iQ(e,t){try{const n=sQ(e),r=t.getItem(n);if(r){const s=JSON.parse(r);if(typeof s=="object"&&s!=null)return s}}catch{}return null}function R8e(e,t,n){var r,s;const o=(r=iQ(e,n))!==null&&r!==void 0?r:{},i=oQ(t);return(s=o[i])!==null&&s!==void 0?s:null}function I8e(e,t,n,r,s){var o;const i=sQ(e),a=oQ(t),l=(o=iQ(e,s))!==null&&o!==void 0?o:{};l[a]={expandToSizes:Object.fromEntries(n.entries()),layout:r};try{s.setItem(i,JSON.stringify(l))}catch(u){console.error(u)}}function F$({layout:e,panelConstraints:t}){const n=[...e],r=n.reduce((o,i)=>o+i,0);if(n.length!==t.length)throw Error(`Invalid ${t.length} panel layout: ${n.map(o=>`${o}%`).join(", ")}`);if(!yo(r,100)&&n.length>0)for(let o=0;o<t.length;o++){const i=n[o];Mt(i!=null,`No layout data found for index ${o}`);const a=100/r*i;n[o]=a}let s=0;for(let o=0;o<t.length;o++){const i=n[o];Mt(i!=null,`No layout data found for index ${o}`);const a=Zf({panelConstraints:t,panelIndex:o,size:i});i!=a&&(s+=i-a,n[o]=a)}if(!yo(s,0))for(let o=0;o<t.length;o++){const i=n[o];Mt(i!=null,`No layout data found for index ${o}`);const a=i+s,l=Zf({panelConstraints:t,panelIndex:o,size:a});if(i!==l&&(s-=l-i,n[o]=l,yo(s,0)))break}return n}const A8e=100,ig={getItem:e=>(O$(ig),ig.getItem(e)),setItem:(e,t)=>{O$(ig),ig.setItem(e,t)}},$$={};function aQ({autoSaveId:e=null,children:t,className:n="",direction:r,forwardedRef:s,id:o=null,onLayout:i=null,keyboardResizeBy:a=null,storage:l=ig,style:u,tagName:d="div",...f}){const h=OI(o),m=C.useRef(null),[p,g]=C.useState(null),[b,x]=C.useState([]),y=S8e(),v=C.useRef({}),w=C.useRef(new Map),N=C.useRef(0),S=C.useRef({autoSaveId:e,direction:r,dragState:p,id:h,keyboardResizeBy:a,onLayout:i,storage:l}),j=C.useRef({layout:b,panelDataArray:[],panelDataArrayChanged:!1});C.useRef({didLogIdAndOrderWarning:!1,didLogPanelConstraintsWarning:!1,prevPanelIds:[]}),C.useImperativeHandle(s,()=>({getId:()=>S.current.id,getLayout:()=>{const{layout:O}=j.current;return O},setLayout:O=>{const{onLayout:W}=S.current,{layout:B,panelDataArray:Y}=j.current,U=F$({layout:O,panelConstraints:Y.map(V=>V.constraints)});P$(B,U)||(x(U),j.current.layout=U,W&&W(U),Tf(Y,U,v.current))}}),[]),Nd(()=>{S.current.autoSaveId=e,S.current.direction=r,S.current.dragState=p,S.current.id=h,S.current.onLayout=i,S.current.storage=l}),k8e({committedValuesRef:S,eagerValuesRef:j,groupId:h,layout:b,panelDataArray:j.current.panelDataArray,setLayout:x,panelGroupElement:m.current}),C.useEffect(()=>{const{panelDataArray:O}=j.current;if(e){if(b.length===0||b.length!==O.length)return;let W=$$[e];W==null&&(W=T8e(I8e,A8e),$$[e]=W);const B=[...O],Y=new Map(w.current);W(e,B,Y,b,l)}},[e,b,l]),C.useEffect(()=>{});const E=C.useCallback(O=>{const{onLayout:W}=S.current,{layout:B,panelDataArray:Y}=j.current;if(O.constraints.collapsible){const U=Y.map(J=>J.constraints),{collapsedSize:V=0,panelSize:G,pivotIndices:K}=Du(Y,O,B);if(Mt(G!=null,`Panel size not found for panel "${O.id}"`),!cl(G,V)){w.current.set(O.id,G);const Q=Ff(Y,O)===Y.length-1?G-V:V-G,re=og({delta:Q,initialLayout:B,panelConstraints:U,pivotIndices:K,prevLayout:B,trigger:"imperative-api"});O0(B,re)||(x(re),j.current.layout=re,W&&W(re),Tf(Y,re,v.current))}}},[]),_=C.useCallback((O,W)=>{const{onLayout:B}=S.current,{layout:Y,panelDataArray:U}=j.current;if(O.constraints.collapsible){const V=U.map(de=>de.constraints),{collapsedSize:G=0,panelSize:K=0,minSize:J=0,pivotIndices:Q}=Du(U,O,Y),re=W??J;if(cl(K,G)){const de=w.current.get(O.id),fe=de!=null&&de>=re?de:re,je=Ff(U,O)===U.length-1?K-fe:fe-K,me=og({delta:je,initialLayout:Y,panelConstraints:V,pivotIndices:Q,prevLayout:Y,trigger:"imperative-api"});O0(Y,me)||(x(me),j.current.layout=me,B&&B(me),Tf(U,me,v.current))}}},[]),k=C.useCallback(O=>{const{layout:W,panelDataArray:B}=j.current,{panelSize:Y}=Du(B,O,W);return Mt(Y!=null,`Panel size not found for panel "${O.id}"`),Y},[]),M=C.useCallback((O,W)=>{const{panelDataArray:B}=j.current,Y=Ff(B,O);return M8e({defaultSize:W,dragState:p,layout:b,panelData:B,panelIndex:Y})},[p,b]),D=C.useCallback(O=>{const{layout:W,panelDataArray:B}=j.current,{collapsedSize:Y=0,collapsible:U,panelSize:V}=Du(B,O,W);return Mt(V!=null,`Panel size not found for panel "${O.id}"`),U===!0&&cl(V,Y)},[]),R=C.useCallback(O=>{const{layout:W,panelDataArray:B}=j.current,{collapsedSize:Y=0,collapsible:U,panelSize:V}=Du(B,O,W);return Mt(V!=null,`Panel size not found for panel "${O.id}"`),!U||Gd(V,Y)>0},[]),P=C.useCallback(O=>{const{panelDataArray:W}=j.current;W.push(O),W.sort((B,Y)=>{const U=B.order,V=Y.order;return U==null&&V==null?0:U==null?-1:V==null?1:U-V}),j.current.panelDataArrayChanged=!0,y()},[y]);Nd(()=>{if(j.current.panelDataArrayChanged){j.current.panelDataArrayChanged=!1;const{autoSaveId:O,onLayout:W,storage:B}=S.current,{layout:Y,panelDataArray:U}=j.current;let V=null;if(O){const K=R8e(O,U,B);K&&(w.current=new Map(Object.entries(K.expandToSizes)),V=K.layout)}V==null&&(V=D8e({panelDataArray:U}));const G=F$({layout:V,panelConstraints:U.map(K=>K.constraints)});P$(Y,G)||(x(G),j.current.layout=G,W&&W(G),Tf(U,G,v.current))}}),Nd(()=>{const O=j.current;return()=>{O.layout=[]}},[]);const I=C.useCallback(O=>{let W=!1;const B=m.current;return B&&window.getComputedStyle(B,null).getPropertyValue("direction")==="rtl"&&(W=!0),function(U){U.preventDefault();const V=m.current;if(!V)return()=>null;const{direction:G,dragState:K,id:J,keyboardResizeBy:Q,onLayout:re}=S.current,{layout:de,panelDataArray:fe}=j.current,{initialLayout:ue}=K??{},je=tQ(J,O,V);let me=_8e(U,O,G,K,Q,V);const ne=G==="horizontal";ne&&W&&(me=-me);const oe=fe.map(ae=>ae.constraints),pe=og({delta:me,initialLayout:ue??de,panelConstraints:oe,pivotIndices:je,prevLayout:de,trigger:WX(U)?"keyboard":"mouse-or-touch"}),De=!O0(de,pe);(qX(U)||YX(U))&&N.current!=me&&(N.current=me,!De&&me!==0?ne?u2(O,me<0?KX:ZX):u2(O,me<0?XX:QX):u2(O,0)),De&&(x(pe),j.current.layout=pe,re&&re(pe),Tf(fe,pe,v.current))}},[]),L=C.useCallback((O,W)=>{const{onLayout:B}=S.current,{layout:Y,panelDataArray:U}=j.current,V=U.map(de=>de.constraints),{panelSize:G,pivotIndices:K}=Du(U,O,Y);Mt(G!=null,`Panel size not found for panel "${O.id}"`);const Q=Ff(U,O)===U.length-1?G-W:W-G,re=og({delta:Q,initialLayout:Y,panelConstraints:V,pivotIndices:K,prevLayout:Y,trigger:"imperative-api"});O0(Y,re)||(x(re),j.current.layout=re,B&&B(re),Tf(U,re,v.current))},[]),F=C.useCallback((O,W)=>{const{layout:B,panelDataArray:Y}=j.current,{collapsedSize:U=0,collapsible:V}=W,{collapsedSize:G=0,collapsible:K,maxSize:J=100,minSize:Q=0}=O.constraints,{panelSize:re}=Du(Y,O,B);re!=null&&(V&&K&&cl(re,U)?cl(U,G)||L(O,G):re<Q?L(O,Q):re>J&&L(O,J))},[L]),H=C.useCallback((O,W)=>{const{direction:B}=S.current,{layout:Y}=j.current;if(!m.current)return;const U=gC(O,m.current);Mt(U,`Drag handle element not found for id "${O}"`);const V=rQ(B,W);g({dragHandleId:O,dragHandleRect:U.getBoundingClientRect(),initialCursorPosition:V,initialLayout:Y})},[]),$=C.useCallback(()=>{g(null)},[]),A=C.useCallback(O=>{const{panelDataArray:W}=j.current,B=Ff(W,O);B>=0&&(W.splice(B,1),delete v.current[O.id],j.current.panelDataArrayChanged=!0,y())},[y]),q=C.useMemo(()=>({collapsePanel:E,direction:r,dragState:p,expandPanel:_,getPanelSize:k,getPanelStyle:M,groupId:h,isPanelCollapsed:D,isPanelExpanded:R,reevaluatePanelConstraints:F,registerPanel:P,registerResizeHandle:I,resizePanel:L,startDragging:H,stopDragging:$,unregisterPanel:A,panelGroupElement:m.current}),[E,p,r,_,k,M,h,D,R,F,P,I,L,H,$,A]),z={display:"flex",flexDirection:r==="horizontal"?"row":"column",height:"100%",overflow:"hidden",width:"100%"};return C.createElement(hC.Provider,{value:q},C.createElement(d,{...f,children:t,className:n,id:o,ref:m,style:{...z,...u},[rr.group]:"",[rr.groupDirection]:r,[rr.groupId]:h}))}const lQ=C.forwardRef((e,t)=>C.createElement(aQ,{...e,forwardedRef:t}));aQ.displayName="PanelGroup";lQ.displayName="forwardRef(PanelGroup)";function Ff(e,t){return e.findIndex(n=>n===t||n.id===t.id)}function Du(e,t,n){const r=Ff(e,t),o=r===e.length-1?[r-1,r]:[r,r+1],i=n[r];return{...t.constraints,panelSize:i,pivotIndices:o}}function P8e({disabled:e,handleId:t,resizeHandler:n,panelGroupElement:r}){C.useEffect(()=>{if(e||n==null||r==null)return;const s=gC(t,r);if(s==null)return;const o=i=>{if(!i.defaultPrevented)switch(i.key){case"ArrowDown":case"ArrowLeft":case"ArrowRight":case"ArrowUp":case"End":case"Home":{i.preventDefault(),n(i);break}case"F6":{i.preventDefault();const a=s.getAttribute(rr.groupId);Mt(a,`No group element found for id "${a}"`);const l=Rb(a,r),u=eQ(a,t,r);Mt(u!==null,`No resize element found for id "${t}"`);const d=i.shiftKey?u>0?u-1:l.length-1:u+1<l.length?u+1:0;l[d].focus();break}}};return s.addEventListener("keydown",o),()=>{s.removeEventListener("keydown",o)}},[r,e,t,n])}function LI({children:e=null,className:t="",disabled:n=!1,hitAreaMargins:r,id:s,onBlur:o,onClick:i,onDragging:a,onFocus:l,onPointerDown:u,onPointerUp:d,style:f={},tabIndex:h=0,tagName:m="div",...p}){var g,b;const x=C.useRef(null),y=C.useRef({onClick:i,onDragging:a,onPointerDown:u,onPointerUp:d});C.useEffect(()=>{y.current.onClick=i,y.current.onDragging=a,y.current.onPointerDown=u,y.current.onPointerUp=d});const v=C.useContext(hC);if(v===null)throw Error("PanelResizeHandle components must be rendered within a PanelGroup container");const{direction:w,groupId:N,registerResizeHandle:S,startDragging:j,stopDragging:E,panelGroupElement:_}=v,k=OI(s),[M,D]=C.useState("inactive"),[R,P]=C.useState(!1),[I,L]=C.useState(null),F=C.useRef({state:M});Nd(()=>{F.current.state=M}),C.useEffect(()=>{if(n)L(null);else{const q=S(k);L(()=>q)}},[n,k,S]);const H=(g=r==null?void 0:r.coarse)!==null&&g!==void 0?g:15,$=(b=r==null?void 0:r.fine)!==null&&b!==void 0?b:5;C.useEffect(()=>{if(n||I==null)return;const q=x.current;Mt(q,"Element ref not attached");let z=!1;return v8e(k,q,w,{coarse:H,fine:$},(W,B,Y)=>{if(!B){D("inactive");return}switch(W){case"down":{D("drag"),z=!1,Mt(Y,'Expected event to be defined for "down" action'),j(k,Y);const{onDragging:U,onPointerDown:V}=y.current;U==null||U(!0),V==null||V();break}case"move":{const{state:U}=F.current;z=!0,U!=="drag"&&D("hover"),Mt(Y,'Expected event to be defined for "move" action'),I(Y);break}case"up":{D("hover"),E();const{onClick:U,onDragging:V,onPointerUp:G}=y.current;V==null||V(!1),G==null||G(),z||U==null||U();break}}})},[H,w,n,$,S,k,I,j,E]),P8e({disabled:n,handleId:k,resizeHandler:I,panelGroupElement:_});const A={touchAction:"none",userSelect:"none"};return C.createElement(m,{...p,children:e,className:t,id:s,onBlur:()=>{P(!1),o==null||o()},onFocus:()=>{P(!0),l==null||l()},ref:x,role:"separator",style:{...A,...f},tabIndex:h,[rr.groupDirection]:w,[rr.groupId]:N,[rr.resizeHandle]:"",[rr.resizeHandleActive]:M==="drag"?"pointer":R?"keyboard":void 0,[rr.resizeHandleEnabled]:!n,[rr.resizeHandleId]:k,[rr.resizeHandleState]:M})}LI.displayName="PanelResizeHandle";const cQ=({className:e,...t})=>c.jsx(lQ,{className:Z("flex h-full w-full data-[panel-group-direction=vertical]:flex-col",e),...t}),x_=UX,O8e=({withHandle:e,className:t,...n})=>c.jsx(LI,{className:Z("relative flex w-px items-center justify-center bg-border after:absolute after:inset-y-0 after:left-1/2 after:w-1 after:-translate-x-1/2 focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring focus-visible:ring-offset-1 data-[panel-group-direction=vertical]:h-px data-[panel-group-direction=vertical]:w-full data-[panel-group-direction=vertical]:after:left-0 data-[panel-group-direction=vertical]:after:h-1 data-[panel-group-direction=vertical]:after:w-full data-[panel-group-direction=vertical]:after:-translate-y-1/2 data-[panel-group-direction=vertical]:after:translate-x-0 [&[data-panel-group-direction=vertical]>div]:rotate-90",t),...n,children:e&&c.jsx("div",{className:"z-10 flex h-4 w-3 items-center justify-center rounded-sm border bg-border",children:c.jsx(PD,{className:"h-2.5 w-2.5"})})}),F8e=({withHandle:e,className:t,onTabClick:n,open:r,...s})=>c.jsx(LI,{className:Z("relative flex w-px items-start justify-end bg-border after:absolute after:inset-y-0 after:left-1/2 after:w-1 after:-translate-x-1/2 focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring focus-visible:ring-offset-1 data-[panel-group-direction=vertical]:h-px data-[panel-group-direction=vertical]:w-full data-[panel-group-direction=vertical]:after:left-0 data-[panel-group-direction=vertical]:after:h-1 data-[panel-group-direction=vertical]:after:w-full data-[panel-group-direction=vertical]:after:-translate-y-1/2 data-[panel-group-direction=vertical]:after:translate-x-0 [&[data-panel-group-direction=vertical]>div]:rotate-90",{"justify-start":r},t),...s,children:e&&!1});function $8e(e={}){const{initialPosition:t="bottom-right"}=e,[n,r]=C.useState(t),[s,o]=C.useState(!1),[i,a]=C.useState(null),l=C.useRef(null),u=C.useRef(!1),d=C.useRef(null);C.useEffect(()=>()=>{d.current&&(d.current(),d.current=null)},[]);const f=C.useCallback(p=>{const g="touches"in p?p.touches[0].clientX:p.clientX,b="touches"in p?p.touches[0].clientY:p.clientY;l.current={x:g,y:b},u.current=!1,a({x:g,y:b});const x=(j,E,_)=>{if(!l.current)return;const k=Math.abs(j-l.current.x),M=Math.abs(E-l.current.y);(k>10||M>10)&&(u.current?_.cancelable&&_.preventDefault():(_.cancelable&&_.preventDefault(),u.current=!0,o(!0))),a({x:j,y:E})},y={passive:!1},v=j=>{x(j.clientX,j.clientY,j)},w=j=>{if(j.touches.length===0)return;const E=j.touches[0];x(E.clientX,E.clientY,j)},N=()=>{document.removeEventListener("mousemove",v),document.removeEventListener("mouseup",S),document.removeEventListener("touchmove",w),document.removeEventListener("touchend",S),d.current=null},S=()=>{a(j=>{if(u.current&&j){const E=window.innerWidth,_=window.innerHeight,k=j.x<E/2,M=j.y<_/2;r(M&&k?"top-left":M&&!k?"top-right":!M&&k?"bottom-left":"bottom-right")}return null}),l.current=null,setTimeout(()=>{u.current=!1,o(!1)},100),N()};document.addEventListener("mousemove",v),document.addEventListener("mouseup",S),document.addEventListener("touchmove",w,y),document.addEventListener("touchend",S),d.current=N},[]),h=C.useCallback(()=>{if(s&&i)return{position:"fixed",left:0,top:0,right:"auto",bottom:"auto",transform:`translate(${i.x-24}px, ${i.y-24}px)`,transition:"none",willChange:"transform"}},[s,i]),m=C.useCallback(()=>({horizontal:n.includes("left")?"left-6":"right-6",vertical:n.includes("top")?"top-6":"bottom-6"}),[n]);return{position:n,isDragging:s,dragPosition:i,handleDragStart:f,isDraggingRef:u,getStyle:h,getPositionClasses:m}}function L8e({open:e,setOpen:t}){const n=X(o=>o.selectedSheetId),{deleteSheet:r}=Ot();function s(){n&&(r(n),t(!1))}return c.jsx(px,{open:e,onOpenChange:t,children:c.jsxs(ym,{children:[c.jsxs(vm,{children:[c.jsx(Sm,{children:"Delete Sheet"}),c.jsx(Cm,{children:"Are you sure you want to delete this sheet along with all its cards? This action cannot be undone."})]}),c.jsxs(wm,{children:[c.jsx(jm,{children:"Cancel"}),c.jsx(Nm,{className:"bg-destructive hover:bg-destructive/90",onClick:s,children:"Delete"})]})]})})}function z8e({children:e}){return c.jsx("pre",{className:"border-1 whitespace-pre-wrap rounded-md border border-muted p-3 text-xs",children:e})}function B8e(e,t){const n={};return(e[e.length-1]===""?[...e,""]:e).join((n.padRight?" ":"")+","+(n.padLeft===!1?"":" ")).trim()}const V8e=/^[$_\p{ID_Start}][$_\u{200C}\u{200D}\p{ID_Continue}]*$/u,H8e=/^[$_\p{ID_Start}][-$_\u{200C}\u{200D}\p{ID_Continue}]*$/u,U8e={};function L$(e,t){return(U8e.jsx?H8e:V8e).test(e)}const W8e=/[ \t\n\f\r]/g;function q8e(e){return typeof e=="object"?e.type==="text"?z$(e.value):!1:z$(e)}function z$(e){return e.replace(W8e,"")===""}class ay{constructor(t,n,r){this.normal=n,this.property=t,r&&(this.space=r)}}ay.prototype.normal={};ay.prototype.property={};ay.prototype.space=void 0;function uQ(e,t){const n={},r={};for(const s of e)Object.assign(n,s.property),Object.assign(r,s.normal);return new ay(n,r,t)}function y_(e){return e.toLowerCase()}class io{constructor(t,n){this.attribute=n,this.property=t}}io.prototype.attribute="";io.prototype.booleanish=!1;io.prototype.boolean=!1;io.prototype.commaOrSpaceSeparated=!1;io.prototype.commaSeparated=!1;io.prototype.defined=!1;io.prototype.mustUseProperty=!1;io.prototype.number=!1;io.prototype.overloadedBoolean=!1;io.prototype.property="";io.prototype.spaceSeparated=!1;io.prototype.space=void 0;let Y8e=0;const kt=mf(),yr=mf(),v_=mf(),Re=mf(),Rn=mf(),fh=mf(),mo=mf();function mf(){return 2**++Y8e}const w_=Object.freeze(Object.defineProperty({__proto__:null,boolean:kt,booleanish:yr,commaOrSpaceSeparated:mo,commaSeparated:fh,number:Re,overloadedBoolean:v_,spaceSeparated:Rn},Symbol.toStringTag,{value:"Module"})),f2=Object.keys(w_);class zI extends io{constructor(t,n,r,s){let o=-1;if(super(t,n),B$(this,"space",s),typeof r=="number")for(;++o<f2.length;){const i=f2[o];B$(this,f2[o],(r&w_[i])===w_[i])}}}zI.prototype.defined=!0;function B$(e,t,n){n&&(e[t]=n)}function cp(e){const t={},n={};for(const[r,s]of Object.entries(e.properties)){const o=new zI(r,e.transform(e.attributes||{},r),s,e.space);e.mustUseProperty&&e.mustUseProperty.includes(r)&&(o.mustUseProperty=!0),t[r]=o,n[y_(r)]=r,n[y_(o.attribute)]=r}return new ay(t,n,e.space)}const dQ=cp({properties:{ariaActiveDescendant:null,ariaAtomic:yr,ariaAutoComplete:null,ariaBusy:yr,ariaChecked:yr,ariaColCount:Re,ariaColIndex:Re,ariaColSpan:Re,ariaControls:Rn,ariaCurrent:null,ariaDescribedBy:Rn,ariaDetails:null,ariaDisabled:yr,ariaDropEffect:Rn,ariaErrorMessage:null,ariaExpanded:yr,ariaFlowTo:Rn,ariaGrabbed:yr,ariaHasPopup:null,ariaHidden:yr,ariaInvalid:null,ariaKeyShortcuts:null,ariaLabel:null,ariaLabelledBy:Rn,ariaLevel:Re,ariaLive:null,ariaModal:yr,ariaMultiLine:yr,ariaMultiSelectable:yr,ariaOrientation:null,ariaOwns:Rn,ariaPlaceholder:null,ariaPosInSet:Re,ariaPressed:yr,ariaReadOnly:yr,ariaRelevant:null,ariaRequired:yr,ariaRoleDescription:Rn,ariaRowCount:Re,ariaRowIndex:Re,ariaRowSpan:Re,ariaSelected:yr,ariaSetSize:Re,ariaSort:null,ariaValueMax:Re,ariaValueMin:Re,ariaValueNow:Re,ariaValueText:null,role:null},transform(e,t){return t==="role"?t:"aria-"+t.slice(4).toLowerCase()}});function fQ(e,t){return t in e?e[t]:t}function hQ(e,t){return fQ(e,t.toLowerCase())}const G8e=cp({attributes:{acceptcharset:"accept-charset",classname:"class",htmlfor:"for",httpequiv:"http-equiv"},mustUseProperty:["checked","multiple","muted","selected"],properties:{abbr:null,accept:fh,acceptCharset:Rn,accessKey:Rn,action:null,allow:null,allowFullScreen:kt,allowPaymentRequest:kt,allowUserMedia:kt,alt:null,as:null,async:kt,autoCapitalize:null,autoComplete:Rn,autoFocus:kt,autoPlay:kt,blocking:Rn,capture:null,charSet:null,checked:kt,cite:null,className:Rn,cols:Re,colSpan:null,content:null,contentEditable:yr,controls:kt,controlsList:Rn,coords:Re|fh,crossOrigin:null,data:null,dateTime:null,decoding:null,default:kt,defer:kt,dir:null,dirName:null,disabled:kt,download:v_,draggable:yr,encType:null,enterKeyHint:null,fetchPriority:null,form:null,formAction:null,formEncType:null,formMethod:null,formNoValidate:kt,formTarget:null,headers:Rn,height:Re,hidden:v_,high:Re,href:null,hrefLang:null,htmlFor:Rn,httpEquiv:Rn,id:null,imageSizes:null,imageSrcSet:null,inert:kt,inputMode:null,integrity:null,is:null,isMap:kt,itemId:null,itemProp:Rn,itemRef:Rn,itemScope:kt,itemType:Rn,kind:null,label:null,lang:null,language:null,list:null,loading:null,loop:kt,low:Re,manifest:null,max:null,maxLength:Re,media:null,method:null,min:null,minLength:Re,multiple:kt,muted:kt,name:null,nonce:null,noModule:kt,noValidate:kt,onAbort:null,onAfterPrint:null,onAuxClick:null,onBeforeMatch:null,onBeforePrint:null,onBeforeToggle:null,onBeforeUnload:null,onBlur:null,onCancel:null,onCanPlay:null,onCanPlayThrough:null,onChange:null,onClick:null,onClose:null,onContextLost:null,onContextMenu:null,onContextRestored:null,onCopy:null,onCueChange:null,onCut:null,onDblClick:null,onDrag:null,onDragEnd:null,onDragEnter:null,onDragExit:null,onDragLeave:null,onDragOver:null,onDragStart:null,onDrop:null,onDurationChange:null,onEmptied:null,onEnded:null,onError:null,onFocus:null,onFormData:null,onHashChange:null,onInput:null,onInvalid:null,onKeyDown:null,onKeyPress:null,onKeyUp:null,onLanguageChange:null,onLoad:null,onLoadedData:null,onLoadedMetadata:null,onLoadEnd:null,onLoadStart:null,onMessage:null,onMessageError:null,onMouseDown:null,onMouseEnter:null,onMouseLeave:null,onMouseMove:null,onMouseOut:null,onMouseOver:null,onMouseUp:null,onOffline:null,onOnline:null,onPageHide:null,onPageShow:null,onPaste:null,onPause:null,onPlay:null,onPlaying:null,onPopState:null,onProgress:null,onRateChange:null,onRejectionHandled:null,onReset:null,onResize:null,onScroll:null,onScrollEnd:null,onSecurityPolicyViolation:null,onSeeked:null,onSeeking:null,onSelect:null,onSlotChange:null,onStalled:null,onStorage:null,onSubmit:null,onSuspend:null,onTimeUpdate:null,onToggle:null,onUnhandledRejection:null,onUnload:null,onVolumeChange:null,onWaiting:null,onWheel:null,open:kt,optimum:Re,pattern:null,ping:Rn,placeholder:null,playsInline:kt,popover:null,popoverTarget:null,popoverTargetAction:null,poster:null,preload:null,readOnly:kt,referrerPolicy:null,rel:Rn,required:kt,reversed:kt,rows:Re,rowSpan:Re,sandbox:Rn,scope:null,scoped:kt,seamless:kt,selected:kt,shadowRootClonable:kt,shadowRootDelegatesFocus:kt,shadowRootMode:null,shape:null,size:Re,sizes:null,slot:null,span:Re,spellCheck:yr,src:null,srcDoc:null,srcLang:null,srcSet:null,start:Re,step:null,style:null,tabIndex:Re,target:null,title:null,translate:null,type:null,typeMustMatch:kt,useMap:null,value:yr,width:Re,wrap:null,writingSuggestions:null,align:null,aLink:null,archive:Rn,axis:null,background:null,bgColor:null,border:Re,borderColor:null,bottomMargin:Re,cellPadding:null,cellSpacing:null,char:null,charOff:null,classId:null,clear:null,code:null,codeBase:null,codeType:null,color:null,compact:kt,declare:kt,event:null,face:null,frame:null,frameBorder:null,hSpace:Re,leftMargin:Re,link:null,longDesc:null,lowSrc:null,marginHeight:Re,marginWidth:Re,noResize:kt,noHref:kt,noShade:kt,noWrap:kt,object:null,profile:null,prompt:null,rev:null,rightMargin:Re,rules:null,scheme:null,scrolling:yr,standby:null,summary:null,text:null,topMargin:Re,valueType:null,version:null,vAlign:null,vLink:null,vSpace:Re,allowTransparency:null,autoCorrect:null,autoSave:null,disablePictureInPicture:kt,disableRemotePlayback:kt,prefix:null,property:null,results:Re,security:null,unselectable:null},space:"html",transform:hQ}),K8e=cp({attributes:{accentHeight:"accent-height",alignmentBaseline:"alignment-baseline",arabicForm:"arabic-form",baselineShift:"baseline-shift",capHeight:"cap-height",className:"class",clipPath:"clip-path",clipRule:"clip-rule",colorInterpolation:"color-interpolation",colorInterpolationFilters:"color-interpolation-filters",colorProfile:"color-profile",colorRendering:"color-rendering",crossOrigin:"crossorigin",dataType:"datatype",dominantBaseline:"dominant-baseline",enableBackground:"enable-background",fillOpacity:"fill-opacity",fillRule:"fill-rule",floodColor:"flood-color",floodOpacity:"flood-opacity",fontFamily:"font-family",fontSize:"font-size",fontSizeAdjust:"font-size-adjust",fontStretch:"font-stretch",fontStyle:"font-style",fontVariant:"font-variant",fontWeight:"font-weight",glyphName:"glyph-name",glyphOrientationHorizontal:"glyph-orientation-horizontal",glyphOrientationVertical:"glyph-orientation-vertical",hrefLang:"hreflang",horizAdvX:"horiz-adv-x",horizOriginX:"horiz-origin-x",horizOriginY:"horiz-origin-y",imageRendering:"image-rendering",letterSpacing:"letter-spacing",lightingColor:"lighting-color",markerEnd:"marker-end",markerMid:"marker-mid",markerStart:"marker-start",navDown:"nav-down",navDownLeft:"nav-down-left",navDownRight:"nav-down-right",navLeft:"nav-left",navNext:"nav-next",navPrev:"nav-prev",navRight:"nav-right",navUp:"nav-up",navUpLeft:"nav-up-left",navUpRight:"nav-up-right",onAbort:"onabort",onActivate:"onactivate",onAfterPrint:"onafterprint",onBeforePrint:"onbeforeprint",onBegin:"onbegin",onCancel:"oncancel",onCanPlay:"oncanplay",onCanPlayThrough:"oncanplaythrough",onChange:"onchange",onClick:"onclick",onClose:"onclose",onCopy:"oncopy",onCueChange:"oncuechange",onCut:"oncut",onDblClick:"ondblclick",onDrag:"ondrag",onDragEnd:"ondragend",onDragEnter:"ondragenter",onDragExit:"ondragexit",onDragLeave:"ondragleave",onDragOver:"ondragover",onDragStart:"ondragstart",onDrop:"ondrop",onDurationChange:"ondurationchange",onEmptied:"onemptied",onEnd:"onend",onEnded:"onended",onError:"onerror",onFocus:"onfocus",onFocusIn:"onfocusin",onFocusOut:"onfocusout",onHashChange:"onhashchange",onInput:"oninput",onInvalid:"oninvalid",onKeyDown:"onkeydown",onKeyPress:"onkeypress",onKeyUp:"onkeyup",onLoad:"onload",onLoadedData:"onloadeddata",onLoadedMetadata:"onloadedmetadata",onLoadStart:"onloadstart",onMessage:"onmessage",onMouseDown:"onmousedown",onMouseEnter:"onmouseenter",onMouseLeave:"onmouseleave",onMouseMove:"onmousemove",onMouseOut:"onmouseout",onMouseOver:"onmouseover",onMouseUp:"onmouseup",onMouseWheel:"onmousewheel",onOffline:"onoffline",onOnline:"ononline",onPageHide:"onpagehide",onPageShow:"onpageshow",onPaste:"onpaste",onPause:"onpause",onPlay:"onplay",onPlaying:"onplaying",onPopState:"onpopstate",onProgress:"onprogress",onRateChange:"onratechange",onRepeat:"onrepeat",onReset:"onreset",onResize:"onresize",onScroll:"onscroll",onSeeked:"onseeked",onSeeking:"onseeking",onSelect:"onselect",onShow:"onshow",onStalled:"onstalled",onStorage:"onstorage",onSubmit:"onsubmit",onSuspend:"onsuspend",onTimeUpdate:"ontimeupdate",onToggle:"ontoggle",onUnload:"onunload",onVolumeChange:"onvolumechange",onWaiting:"onwaiting",onZoom:"onzoom",overlinePosition:"overline-position",overlineThickness:"overline-thickness",paintOrder:"paint-order",panose1:"panose-1",pointerEvents:"pointer-events",referrerPolicy:"referrerpolicy",renderingIntent:"rendering-intent",shapeRendering:"shape-rendering",stopColor:"stop-color",stopOpacity:"stop-opacity",strikethroughPosition:"strikethrough-position",strikethroughThickness:"strikethrough-thickness",strokeDashArray:"stroke-dasharray",strokeDashOffset:"stroke-dashoffset",strokeLineCap:"stroke-linecap",strokeLineJoin:"stroke-linejoin",strokeMiterLimit:"stroke-miterlimit",strokeOpacity:"stroke-opacity",strokeWidth:"stroke-width",tabIndex:"tabindex",textAnchor:"text-anchor",textDecoration:"text-decoration",textRendering:"text-rendering",transformOrigin:"transform-origin",typeOf:"typeof",underlinePosition:"underline-position",underlineThickness:"underline-thickness",unicodeBidi:"unicode-bidi",unicodeRange:"unicode-range",unitsPerEm:"units-per-em",vAlphabetic:"v-alphabetic",vHanging:"v-hanging",vIdeographic:"v-ideographic",vMathematical:"v-mathematical",vectorEffect:"vector-effect",vertAdvY:"vert-adv-y",vertOriginX:"vert-origin-x",vertOriginY:"vert-origin-y",wordSpacing:"word-spacing",writingMode:"writing-mode",xHeight:"x-height",playbackOrder:"playbackorder",timelineBegin:"timelinebegin"},properties:{about:mo,accentHeight:Re,accumulate:null,additive:null,alignmentBaseline:null,alphabetic:Re,amplitude:Re,arabicForm:null,ascent:Re,attributeName:null,attributeType:null,azimuth:Re,bandwidth:null,baselineShift:null,baseFrequency:null,baseProfile:null,bbox:null,begin:null,bias:Re,by:null,calcMode:null,capHeight:Re,className:Rn,clip:null,clipPath:null,clipPathUnits:null,clipRule:null,color:null,colorInterpolation:null,colorInterpolationFilters:null,colorProfile:null,colorRendering:null,content:null,contentScriptType:null,contentStyleType:null,crossOrigin:null,cursor:null,cx:null,cy:null,d:null,dataType:null,defaultAction:null,descent:Re,diffuseConstant:Re,direction:null,display:null,dur:null,divisor:Re,dominantBaseline:null,download:kt,dx:null,dy:null,edgeMode:null,editable:null,elevation:Re,enableBackground:null,end:null,event:null,exponent:Re,externalResourcesRequired:null,fill:null,fillOpacity:Re,fillRule:null,filter:null,filterRes:null,filterUnits:null,floodColor:null,floodOpacity:null,focusable:null,focusHighlight:null,fontFamily:null,fontSize:null,fontSizeAdjust:null,fontStretch:null,fontStyle:null,fontVariant:null,fontWeight:null,format:null,fr:null,from:null,fx:null,fy:null,g1:fh,g2:fh,glyphName:fh,glyphOrientationHorizontal:null,glyphOrientationVertical:null,glyphRef:null,gradientTransform:null,gradientUnits:null,handler:null,hanging:Re,hatchContentUnits:null,hatchUnits:null,height:null,href:null,hrefLang:null,horizAdvX:Re,horizOriginX:Re,horizOriginY:Re,id:null,ideographic:Re,imageRendering:null,initialVisibility:null,in:null,in2:null,intercept:Re,k:Re,k1:Re,k2:Re,k3:Re,k4:Re,kernelMatrix:mo,kernelUnitLength:null,keyPoints:null,keySplines:null,keyTimes:null,kerning:null,lang:null,lengthAdjust:null,letterSpacing:null,lightingColor:null,limitingConeAngle:Re,local:null,markerEnd:null,markerMid:null,markerStart:null,markerHeight:null,markerUnits:null,markerWidth:null,mask:null,maskContentUnits:null,maskUnits:null,mathematical:null,max:null,media:null,mediaCharacterEncoding:null,mediaContentEncodings:null,mediaSize:Re,mediaTime:null,method:null,min:null,mode:null,name:null,navDown:null,navDownLeft:null,navDownRight:null,navLeft:null,navNext:null,navPrev:null,navRight:null,navUp:null,navUpLeft:null,navUpRight:null,numOctaves:null,observer:null,offset:null,onAbort:null,onActivate:null,onAfterPrint:null,onBeforePrint:null,onBegin:null,onCancel:null,onCanPlay:null,onCanPlayThrough:null,onChange:null,onClick:null,onClose:null,onCopy:null,onCueChange:null,onCut:null,onDblClick:null,onDrag:null,onDragEnd:null,onDragEnter:null,onDragExit:null,onDragLeave:null,onDragOver:null,onDragStart:null,onDrop:null,onDurationChange:null,onEmptied:null,onEnd:null,onEnded:null,onError:null,onFocus:null,onFocusIn:null,onFocusOut:null,onHashChange:null,onInput:null,onInvalid:null,onKeyDown:null,onKeyPress:null,onKeyUp:null,onLoad:null,onLoadedData:null,onLoadedMetadata:null,onLoadStart:null,onMessage:null,onMouseDown:null,onMouseEnter:null,onMouseLeave:null,onMouseMove:null,onMouseOut:null,onMouseOver:null,onMouseUp:null,onMouseWheel:null,onOffline:null,onOnline:null,onPageHide:null,onPageShow:null,onPaste:null,onPause:null,onPlay:null,onPlaying:null,onPopState:null,onProgress:null,onRateChange:null,onRepeat:null,onReset:null,onResize:null,onScroll:null,onSeeked:null,onSeeking:null,onSelect:null,onShow:null,onStalled:null,onStorage:null,onSubmit:null,onSuspend:null,onTimeUpdate:null,onToggle:null,onUnload:null,onVolumeChange:null,onWaiting:null,onZoom:null,opacity:null,operator:null,order:null,orient:null,orientation:null,origin:null,overflow:null,overlay:null,overlinePosition:Re,overlineThickness:Re,paintOrder:null,panose1:null,path:null,pathLength:Re,patternContentUnits:null,patternTransform:null,patternUnits:null,phase:null,ping:Rn,pitch:null,playbackOrder:null,pointerEvents:null,points:null,pointsAtX:Re,pointsAtY:Re,pointsAtZ:Re,preserveAlpha:null,preserveAspectRatio:null,primitiveUnits:null,propagate:null,property:mo,r:null,radius:null,referrerPolicy:null,refX:null,refY:null,rel:mo,rev:mo,renderingIntent:null,repeatCount:null,repeatDur:null,requiredExtensions:mo,requiredFeatures:mo,requiredFonts:mo,requiredFormats:mo,resource:null,restart:null,result:null,rotate:null,rx:null,ry:null,scale:null,seed:null,shapeRendering:null,side:null,slope:null,snapshotTime:null,specularConstant:Re,specularExponent:Re,spreadMethod:null,spacing:null,startOffset:null,stdDeviation:null,stemh:null,stemv:null,stitchTiles:null,stopColor:null,stopOpacity:null,strikethroughPosition:Re,strikethroughThickness:Re,string:null,stroke:null,strokeDashArray:mo,strokeDashOffset:null,strokeLineCap:null,strokeLineJoin:null,strokeMiterLimit:Re,strokeOpacity:Re,strokeWidth:null,style:null,surfaceScale:Re,syncBehavior:null,syncBehaviorDefault:null,syncMaster:null,syncTolerance:null,syncToleranceDefault:null,systemLanguage:mo,tabIndex:Re,tableValues:null,target:null,targetX:Re,targetY:Re,textAnchor:null,textDecoration:null,textRendering:null,textLength:null,timelineBegin:null,title:null,transformBehavior:null,type:null,typeOf:mo,to:null,transform:null,transformOrigin:null,u1:null,u2:null,underlinePosition:Re,underlineThickness:Re,unicode:null,unicodeBidi:null,unicodeRange:null,unitsPerEm:Re,values:null,vAlphabetic:Re,vMathematical:Re,vectorEffect:null,vHanging:Re,vIdeographic:Re,version:null,vertAdvY:Re,vertOriginX:Re,vertOriginY:Re,viewBox:null,viewTarget:null,visibility:null,width:null,widths:null,wordSpacing:null,writingMode:null,x:null,x1:null,x2:null,xChannelSelector:null,xHeight:Re,y:null,y1:null,y2:null,yChannelSelector:null,z:null,zoomAndPan:null},space:"svg",transform:fQ}),mQ=cp({properties:{xLinkActuate:null,xLinkArcRole:null,xLinkHref:null,xLinkRole:null,xLinkShow:null,xLinkTitle:null,xLinkType:null},space:"xlink",transform(e,t){return"xlink:"+t.slice(5).toLowerCase()}}),pQ=cp({attributes:{xmlnsxlink:"xmlns:xlink"},properties:{xmlnsXLink:null,xmlns:null},space:"xmlns",transform:hQ}),gQ=cp({properties:{xmlBase:null,xmlLang:null,xmlSpace:null},space:"xml",transform(e,t){return"xml:"+t.slice(3).toLowerCase()}}),Z8e={classId:"classID",dataType:"datatype",itemId:"itemID",strokeDashArray:"strokeDasharray",strokeDashOffset:"strokeDashoffset",strokeLineCap:"strokeLinecap",strokeLineJoin:"strokeLinejoin",strokeMiterLimit:"strokeMiterlimit",typeOf:"typeof",xLinkActuate:"xlinkActuate",xLinkArcRole:"xlinkArcrole",xLinkHref:"xlinkHref",xLinkRole:"xlinkRole",xLinkShow:"xlinkShow",xLinkTitle:"xlinkTitle",xLinkType:"xlinkType",xmlnsXLink:"xmlnsXlink"},X8e=/[A-Z]/g,V$=/-[a-z]/g,Q8e=/^data[-\w.:]+$/i;function J8e(e,t){const n=y_(t);let r=t,s=io;if(n in e.normal)return e.property[e.normal[n]];if(n.length>4&&n.slice(0,4)==="data"&&Q8e.test(t)){if(t.charAt(4)==="-"){const o=t.slice(5).replace(V$,t9e);r="data"+o.charAt(0).toUpperCase()+o.slice(1)}else{const o=t.slice(4);if(!V$.test(o)){let i=o.replace(X8e,e9e);i.charAt(0)!=="-"&&(i="-"+i),t="data"+i}}s=zI}return new s(r,t)}function e9e(e){return"-"+e.toLowerCase()}function t9e(e){return e.charAt(1).toUpperCase()}const n9e=uQ([dQ,G8e,mQ,pQ,gQ],"html"),BI=uQ([dQ,K8e,mQ,pQ,gQ],"svg");function r9e(e){return e.join(" ").trim()}var VI={},H$=/\/\*[^*]*\*+([^/*][^*]*\*+)*\//g,s9e=/\n/g,o9e=/^\s*/,i9e=/^(\*?[-#/*\\\w]+(\[[0-9a-z_-]+\])?)\s*/,a9e=/^:\s*/,l9e=/^((?:'(?:\\'|.)*?'|"(?:\\"|.)*?"|\([^)]*?\)|[^};])+)/,c9e=/^[;\s]*/,u9e=/^\s+|\s+$/g,d9e=`
1013
1013
  `,U$="/",W$="*",Uu="",f9e="comment",h9e="declaration";function m9e(e,t){if(typeof e!="string")throw new TypeError("First argument must be a string");if(!e)return[];t=t||{};var n=1,r=1;function s(p){var g=p.match(s9e);g&&(n+=g.length);var b=p.lastIndexOf(d9e);r=~b?p.length-b:r+p.length}function o(){var p={line:n,column:r};return function(g){return g.position=new i(p),u(),g}}function i(p){this.start=p,this.end={line:n,column:r},this.source=t.source}i.prototype.content=e;function a(p){var g=new Error(t.source+":"+n+":"+r+": "+p);if(g.reason=p,g.filename=t.source,g.line=n,g.column=r,g.source=e,!t.silent)throw g}function l(p){var g=p.exec(e);if(g){var b=g[0];return s(b),e=e.slice(b.length),g}}function u(){l(o9e)}function d(p){var g;for(p=p||[];g=f();)g!==!1&&p.push(g);return p}function f(){var p=o();if(!(U$!=e.charAt(0)||W$!=e.charAt(1))){for(var g=2;Uu!=e.charAt(g)&&(W$!=e.charAt(g)||U$!=e.charAt(g+1));)++g;if(g+=2,Uu===e.charAt(g-1))return a("End of comment missing");var b=e.slice(2,g-2);return r+=2,s(b),e=e.slice(g),r+=2,p({type:f9e,comment:b})}}function h(){var p=o(),g=l(i9e);if(g){if(f(),!l(a9e))return a("property missing ':'");var b=l(l9e),x=p({type:h9e,property:q$(g[0].replace(H$,Uu)),value:b?q$(b[0].replace(H$,Uu)):Uu});return l(c9e),x}}function m(){var p=[];d(p);for(var g;g=h();)g!==!1&&(p.push(g),d(p));return p}return u(),m()}function q$(e){return e?e.replace(u9e,Uu):Uu}var p9e=m9e,g9e=ul&&ul.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(VI,"__esModule",{value:!0});VI.default=x9e;const b9e=g9e(p9e);function x9e(e,t){let n=null;if(!e||typeof e!="string")return n;const r=(0,b9e.default)(e),s=typeof t=="function";return r.forEach(o=>{if(o.type!=="declaration")return;const{property:i,value:a}=o;s?t(i,a,o):a&&(n=n||{},n[i]=a)}),n}var bC={};Object.defineProperty(bC,"__esModule",{value:!0});bC.camelCase=void 0;var y9e=/^--[a-zA-Z0-9_-]+$/,v9e=/-([a-z])/g,w9e=/^[^-]+$/,S9e=/^-(webkit|moz|ms|o|khtml)-/,C9e=/^-(ms)-/,N9e=function(e){return!e||w9e.test(e)||y9e.test(e)},j9e=function(e,t){return t.toUpperCase()},Y$=function(e,t){return"".concat(t,"-")},k9e=function(e,t){return t===void 0&&(t={}),N9e(e)?e:(e=e.toLowerCase(),t.reactCompat?e=e.replace(C9e,Y$):e=e.replace(S9e,Y$),e.replace(v9e,j9e))};bC.camelCase=k9e;var E9e=ul&&ul.__importDefault||function(e){return e&&e.__esModule?e:{default:e}},_9e=E9e(VI),D9e=bC;function S_(e,t){var n={};return!e||typeof e!="string"||(0,_9e.default)(e,function(r,s){r&&s&&(n[(0,D9e.camelCase)(r,t)]=s)}),n}S_.default=S_;var M9e=S_;const T9e=Jc(M9e),bQ=xQ("end"),HI=xQ("start");function xQ(e){return t;function t(n){const r=n&&n.position&&n.position[e]||{};if(typeof r.line=="number"&&r.line>0&&typeof r.column=="number"&&r.column>0)return{line:r.line,column:r.column,offset:typeof r.offset=="number"&&r.offset>-1?r.offset:void 0}}}function R9e(e){const t=HI(e),n=bQ(e);if(t&&n)return{start:t,end:n}}function Ig(e){return!e||typeof e!="object"?"":"position"in e||"type"in e?G$(e.position):"start"in e||"end"in e?G$(e):"line"in e||"column"in e?C_(e):""}function C_(e){return K$(e&&e.line)+":"+K$(e&&e.column)}function G$(e){return C_(e&&e.start)+"-"+C_(e&&e.end)}function K$(e){return e&&typeof e=="number"?e:1}class Cs extends Error{constructor(t,n,r){super(),typeof n=="string"&&(r=n,n=void 0);let s="",o={},i=!1;if(n&&("line"in n&&"column"in n?o={place:n}:"start"in n&&"end"in n?o={place:n}:"type"in n?o={ancestors:[n],place:n.position}:o={...n}),typeof t=="string"?s=t:!o.cause&&t&&(i=!0,s=t.message,o.cause=t),!o.ruleId&&!o.source&&typeof r=="string"){const l=r.indexOf(":");l===-1?o.ruleId=r:(o.source=r.slice(0,l),o.ruleId=r.slice(l+1))}if(!o.place&&o.ancestors&&o.ancestors){const l=o.ancestors[o.ancestors.length-1];l&&(o.place=l.position)}const a=o.place&&"start"in o.place?o.place.start:o.place;this.ancestors=o.ancestors||void 0,this.cause=o.cause||void 0,this.column=a?a.column:void 0,this.fatal=void 0,this.file="",this.message=s,this.line=a?a.line:void 0,this.name=Ig(o.place)||"1:1",this.place=o.place||void 0,this.reason=this.message,this.ruleId=o.ruleId||void 0,this.source=o.source||void 0,this.stack=i&&o.cause&&typeof o.cause.stack=="string"?o.cause.stack:"",this.actual=void 0,this.expected=void 0,this.note=void 0,this.url=void 0}}Cs.prototype.file="";Cs.prototype.name="";Cs.prototype.reason="";Cs.prototype.message="";Cs.prototype.stack="";Cs.prototype.column=void 0;Cs.prototype.line=void 0;Cs.prototype.ancestors=void 0;Cs.prototype.cause=void 0;Cs.prototype.fatal=void 0;Cs.prototype.place=void 0;Cs.prototype.ruleId=void 0;Cs.prototype.source=void 0;const UI={}.hasOwnProperty,I9e=new Map,A9e=/[A-Z]/g,P9e=new Set(["table","tbody","thead","tfoot","tr"]),O9e=new Set(["td","th"]),yQ="https://github.com/syntax-tree/hast-util-to-jsx-runtime";function F9e(e,t){if(!t||t.Fragment===void 0)throw new TypeError("Expected `Fragment` in options");const n=t.filePath||void 0;let r;if(t.development){if(typeof t.jsxDEV!="function")throw new TypeError("Expected `jsxDEV` in options when `development: true`");r=W9e(n,t.jsxDEV)}else{if(typeof t.jsx!="function")throw new TypeError("Expected `jsx` in production options");if(typeof t.jsxs!="function")throw new TypeError("Expected `jsxs` in production options");r=U9e(n,t.jsx,t.jsxs)}const s={Fragment:t.Fragment,ancestors:[],components:t.components||{},create:r,elementAttributeNameCase:t.elementAttributeNameCase||"react",evaluater:t.createEvaluater?t.createEvaluater():void 0,filePath:n,ignoreInvalidStyle:t.ignoreInvalidStyle||!1,passKeys:t.passKeys!==!1,passNode:t.passNode||!1,schema:t.space==="svg"?BI:n9e,stylePropertyNameCase:t.stylePropertyNameCase||"dom",tableCellAlignToStyle:t.tableCellAlignToStyle!==!1},o=vQ(s,e,void 0);return o&&typeof o!="string"?o:s.create(e,s.Fragment,{children:o||void 0},void 0)}function vQ(e,t,n){if(t.type==="element")return $9e(e,t,n);if(t.type==="mdxFlowExpression"||t.type==="mdxTextExpression")return L9e(e,t);if(t.type==="mdxJsxFlowElement"||t.type==="mdxJsxTextElement")return B9e(e,t,n);if(t.type==="mdxjsEsm")return z9e(e,t);if(t.type==="root")return V9e(e,t,n);if(t.type==="text")return H9e(e,t)}function $9e(e,t,n){const r=e.schema;let s=r;t.tagName.toLowerCase()==="svg"&&r.space==="html"&&(s=BI,e.schema=s),e.ancestors.push(t);const o=SQ(e,t.tagName,!1),i=q9e(e,t);let a=qI(e,t);return P9e.has(t.tagName)&&(a=a.filter(function(l){return typeof l=="string"?!q8e(l):!0})),wQ(e,i,o,t),WI(i,a),e.ancestors.pop(),e.schema=r,e.create(t,o,i,n)}function L9e(e,t){if(t.data&&t.data.estree&&e.evaluater){const r=t.data.estree.body[0];return r.type,e.evaluater.evaluateExpression(r.expression)}Ib(e,t.position)}function z9e(e,t){if(t.data&&t.data.estree&&e.evaluater)return e.evaluater.evaluateProgram(t.data.estree);Ib(e,t.position)}function B9e(e,t,n){const r=e.schema;let s=r;t.name==="svg"&&r.space==="html"&&(s=BI,e.schema=s),e.ancestors.push(t);const o=t.name===null?e.Fragment:SQ(e,t.name,!0),i=Y9e(e,t),a=qI(e,t);return wQ(e,i,o,t),WI(i,a),e.ancestors.pop(),e.schema=r,e.create(t,o,i,n)}function V9e(e,t,n){const r={};return WI(r,qI(e,t)),e.create(t,e.Fragment,r,n)}function H9e(e,t){return t.value}function wQ(e,t,n,r){typeof n!="string"&&n!==e.Fragment&&e.passNode&&(t.node=r)}function WI(e,t){if(t.length>0){const n=t.length>1?t:t[0];n&&(e.children=n)}}function U9e(e,t,n){return r;function r(s,o,i,a){const u=Array.isArray(i.children)?n:t;return a?u(o,i,a):u(o,i)}}function W9e(e,t){return n;function n(r,s,o,i){const a=Array.isArray(o.children),l=HI(r);return t(s,o,i,a,{columnNumber:l?l.column-1:void 0,fileName:e,lineNumber:l?l.line:void 0},void 0)}}function q9e(e,t){const n={};let r,s;for(s in t.properties)if(s!=="children"&&UI.call(t.properties,s)){const o=G9e(e,s,t.properties[s]);if(o){const[i,a]=o;e.tableCellAlignToStyle&&i==="align"&&typeof a=="string"&&O9e.has(t.tagName)?r=a:n[i]=a}}if(r){const o=n.style||(n.style={});o[e.stylePropertyNameCase==="css"?"text-align":"textAlign"]=r}return n}function Y9e(e,t){const n={};for(const r of t.attributes)if(r.type==="mdxJsxExpressionAttribute")if(r.data&&r.data.estree&&e.evaluater){const o=r.data.estree.body[0];o.type;const i=o.expression;i.type;const a=i.properties[0];a.type,Object.assign(n,e.evaluater.evaluateExpression(a.argument))}else Ib(e,t.position);else{const s=r.name;let o;if(r.value&&typeof r.value=="object")if(r.value.data&&r.value.data.estree&&e.evaluater){const a=r.value.data.estree.body[0];a.type,o=e.evaluater.evaluateExpression(a.expression)}else Ib(e,t.position);else o=r.value===null?!0:r.value;n[s]=o}return n}function qI(e,t){const n=[];let r=-1;const s=e.passKeys?new Map:I9e;for(;++r<t.children.length;){const o=t.children[r];let i;if(e.passKeys){const l=o.type==="element"?o.tagName:o.type==="mdxJsxFlowElement"||o.type==="mdxJsxTextElement"?o.name:void 0;if(l){const u=s.get(l)||0;i=l+"-"+u,s.set(l,u+1)}}const a=vQ(e,o,i);a!==void 0&&n.push(a)}return n}function G9e(e,t,n){const r=J8e(e.schema,t);if(!(n==null||typeof n=="number"&&Number.isNaN(n))){if(Array.isArray(n)&&(n=r.commaSeparated?B8e(n):r9e(n)),r.property==="style"){let s=typeof n=="object"?n:K9e(e,String(n));return e.stylePropertyNameCase==="css"&&(s=Z9e(s)),["style",s]}return[e.elementAttributeNameCase==="react"&&r.space?Z8e[r.property]||r.property:r.attribute,n]}}function K9e(e,t){try{return T9e(t,{reactCompat:!0})}catch(n){if(e.ignoreInvalidStyle)return{};const r=n,s=new Cs("Cannot parse `style` attribute",{ancestors:e.ancestors,cause:r,ruleId:"style",source:"hast-util-to-jsx-runtime"});throw s.file=e.filePath||void 0,s.url=yQ+"#cannot-parse-style-attribute",s}}function SQ(e,t,n){let r;if(!n)r={type:"Literal",value:t};else if(t.includes(".")){const s=t.split(".");let o=-1,i;for(;++o<s.length;){const a=L$(s[o])?{type:"Identifier",name:s[o]}:{type:"Literal",value:s[o]};i=i?{type:"MemberExpression",object:i,property:a,computed:!!(o&&a.type==="Literal"),optional:!1}:a}r=i}else r=L$(t)&&!/^[a-z]/.test(t)?{type:"Identifier",name:t}:{type:"Literal",value:t};if(r.type==="Literal"){const s=r.value;return UI.call(e.components,s)?e.components[s]:s}if(e.evaluater)return e.evaluater.evaluateExpression(r);Ib(e)}function Ib(e,t){const n=new Cs("Cannot handle MDX estrees without `createEvaluater`",{ancestors:e.ancestors,place:t,ruleId:"mdx-estree",source:"hast-util-to-jsx-runtime"});throw n.file=e.filePath||void 0,n.url=yQ+"#cannot-handle-mdx-estrees-without-createevaluater",n}function Z9e(e){const t={};let n;for(n in e)UI.call(e,n)&&(t[X9e(n)]=e[n]);return t}function X9e(e){let t=e.replace(A9e,Q9e);return t.slice(0,3)==="ms-"&&(t="-"+t),t}function Q9e(e){return"-"+e.toLowerCase()}const h2={action:["form"],cite:["blockquote","del","ins","q"],data:["object"],formAction:["button","input"],href:["a","area","base","link"],icon:["menuitem"],itemId:null,manifest:["html"],ping:["a","area"],poster:["video"],src:["audio","embed","iframe","img","input","script","source","track","video"]},J9e={};function YI(e,t){const n=J9e,r=typeof n.includeImageAlt=="boolean"?n.includeImageAlt:!0,s=typeof n.includeHtml=="boolean"?n.includeHtml:!0;return CQ(e,r,s)}function CQ(e,t,n){if(e7e(e)){if("value"in e)return e.type==="html"&&!n?"":e.value;if(t&&"alt"in e&&e.alt)return e.alt;if("children"in e)return Z$(e.children,t,n)}return Array.isArray(e)?Z$(e,t,n):""}function Z$(e,t,n){const r=[];let s=-1;for(;++s<e.length;)r[s]=CQ(e[s],t,n);return r.join("")}function e7e(e){return!!(e&&typeof e=="object")}const X$=document.createElement("i");function GI(e){const t="&"+e+";";X$.innerHTML=t;const n=X$.textContent;return n.charCodeAt(n.length-1)===59&&e!=="semi"||n===t?!1:n}function Eo(e,t,n,r){const s=e.length;let o=0,i;if(t<0?t=-t>s?0:s+t:t=t>s?s:t,n=n>0?n:0,r.length<1e4)i=Array.from(r),i.unshift(t,n),e.splice(...i);else for(n&&e.splice(t,n);o<r.length;)i=r.slice(o,o+1e4),i.unshift(t,0),e.splice(...i),o+=1e4,t+=1e4}function Ho(e,t){return e.length>0?(Eo(e,e.length,0,t),e):t}const Q$={}.hasOwnProperty;function NQ(e){const t={};let n=-1;for(;++n<e.length;)t7e(t,e[n]);return t}function t7e(e,t){let n;for(n in t){const s=(Q$.call(e,n)?e[n]:void 0)||(e[n]={}),o=t[n];let i;if(o)for(i in o){Q$.call(s,i)||(s[i]=[]);const a=o[i];n7e(s[i],Array.isArray(a)?a:a?[a]:[])}}}function n7e(e,t){let n=-1;const r=[];for(;++n<t.length;)(t[n].add==="after"?e:r).push(t[n]);Eo(e,0,0,r)}function jQ(e,t){const n=Number.parseInt(e,t);return n<9||n===11||n>13&&n<32||n>126&&n<160||n>55295&&n<57344||n>64975&&n<65008||(n&65535)===65535||(n&65535)===65534||n>1114111?"�":String.fromCodePoint(n)}function Ti(e){return e.replace(/[\t\n\r ]+/g," ").replace(/^ | $/g,"").toLowerCase().toUpperCase()}const Is=bu(/[A-Za-z]/),ps=bu(/[\dA-Za-z]/),r7e=bu(/[#-'*+\--9=?A-Z^-~]/);function Zw(e){return e!==null&&(e<32||e===127)}const N_=bu(/\d/),s7e=bu(/[\dA-Fa-f]/),o7e=bu(/[!-/:-@[-`{-~]/);function it(e){return e!==null&&e<-2}function Mn(e){return e!==null&&(e<0||e===32)}function zt(e){return e===-2||e===-1||e===32}const xC=bu(new RegExp("\\p{P}|\\p{S}","u")),Kd=bu(/\s/);function bu(e){return t;function t(n){return n!==null&&n>-1&&e.test(String.fromCharCode(n))}}function up(e){const t=[];let n=-1,r=0,s=0;for(;++n<e.length;){const o=e.charCodeAt(n);let i="";if(o===37&&ps(e.charCodeAt(n+1))&&ps(e.charCodeAt(n+2)))s=2;else if(o<128)/[!#$&-;=?-Z_a-z~]/.test(String.fromCharCode(o))||(i=String.fromCharCode(o));else if(o>55295&&o<57344){const a=e.charCodeAt(n+1);o<56320&&a>56319&&a<57344?(i=String.fromCharCode(o,a),s=1):i="�"}else i=String.fromCharCode(o);i&&(t.push(e.slice(r,n),encodeURIComponent(i)),r=n+s+1,i=""),s&&(n+=s,s=0)}return t.join("")+e.slice(r)}function Kt(e,t,n,r){const s=r?r-1:Number.POSITIVE_INFINITY;let o=0;return i;function i(l){return zt(l)?(e.enter(n),a(l)):t(l)}function a(l){return zt(l)&&o++<s?(e.consume(l),a):(e.exit(n),t(l))}}const i7e={tokenize:a7e};function a7e(e){const t=e.attempt(this.parser.constructs.contentInitial,r,s);let n;return t;function r(a){if(a===null){e.consume(a);return}return e.enter("lineEnding"),e.consume(a),e.exit("lineEnding"),Kt(e,t,"linePrefix")}function s(a){return e.enter("paragraph"),o(a)}function o(a){const l=e.enter("chunkText",{contentType:"text",previous:n});return n&&(n.next=l),n=l,i(a)}function i(a){if(a===null){e.exit("chunkText"),e.exit("paragraph"),e.consume(a);return}return it(a)?(e.consume(a),e.exit("chunkText"),o):(e.consume(a),i)}}const l7e={tokenize:c7e},J$={tokenize:u7e};function c7e(e){const t=this,n=[];let r=0,s,o,i;return a;function a(v){if(r<n.length){const w=n[r];return t.containerState=w[1],e.attempt(w[0].continuation,l,u)(v)}return u(v)}function l(v){if(r++,t.containerState._closeFlow){t.containerState._closeFlow=void 0,s&&y();const w=t.events.length;let N=w,S;for(;N--;)if(t.events[N][0]==="exit"&&t.events[N][1].type==="chunkFlow"){S=t.events[N][1].end;break}x(r);let j=w;for(;j<t.events.length;)t.events[j][1].end={...S},j++;return Eo(t.events,N+1,0,t.events.slice(w)),t.events.length=j,u(v)}return a(v)}function u(v){if(r===n.length){if(!s)return h(v);if(s.currentConstruct&&s.currentConstruct.concrete)return p(v);t.interrupt=!!(s.currentConstruct&&!s._gfmTableDynamicInterruptHack)}return t.containerState={},e.check(J$,d,f)(v)}function d(v){return s&&y(),x(r),h(v)}function f(v){return t.parser.lazy[t.now().line]=r!==n.length,i=t.now().offset,p(v)}function h(v){return t.containerState={},e.attempt(J$,m,p)(v)}function m(v){return r++,n.push([t.currentConstruct,t.containerState]),h(v)}function p(v){if(v===null){s&&y(),x(0),e.consume(v);return}return s=s||t.parser.flow(t.now()),e.enter("chunkFlow",{_tokenizer:s,contentType:"flow",previous:o}),g(v)}function g(v){if(v===null){b(e.exit("chunkFlow"),!0),x(0),e.consume(v);return}return it(v)?(e.consume(v),b(e.exit("chunkFlow")),r=0,t.interrupt=void 0,a):(e.consume(v),g)}function b(v,w){const N=t.sliceStream(v);if(w&&N.push(null),v.previous=o,o&&(o.next=v),o=v,s.defineSkip(v.start),s.write(N),t.parser.lazy[v.start.line]){let S=s.events.length;for(;S--;)if(s.events[S][1].start.offset<i&&(!s.events[S][1].end||s.events[S][1].end.offset>i))return;const j=t.events.length;let E=j,_,k;for(;E--;)if(t.events[E][0]==="exit"&&t.events[E][1].type==="chunkFlow"){if(_){k=t.events[E][1].end;break}_=!0}for(x(r),S=j;S<t.events.length;)t.events[S][1].end={...k},S++;Eo(t.events,E+1,0,t.events.slice(j)),t.events.length=S}}function x(v){let w=n.length;for(;w-- >v;){const N=n[w];t.containerState=N[1],N[0].exit.call(t,e)}n.length=v}function y(){s.write([null]),o=void 0,s=void 0,t.containerState._closeFlow=void 0}}function u7e(e,t,n){return Kt(e,e.attempt(this.parser.constructs.document,t,n),"linePrefix",this.parser.constructs.disable.null.includes("codeIndented")?void 0:4)}function nm(e){if(e===null||Mn(e)||Kd(e))return 1;if(xC(e))return 2}function yC(e,t,n){const r=[];let s=-1;for(;++s<e.length;){const o=e[s].resolveAll;o&&!r.includes(o)&&(t=o(t,n),r.push(o))}return t}const j_={name:"attention",resolveAll:d7e,tokenize:f7e};function d7e(e,t){let n=-1,r,s,o,i,a,l,u,d;for(;++n<e.length;)if(e[n][0]==="enter"&&e[n][1].type==="attentionSequence"&&e[n][1]._close){for(r=n;r--;)if(e[r][0]==="exit"&&e[r][1].type==="attentionSequence"&&e[r][1]._open&&t.sliceSerialize(e[r][1]).charCodeAt(0)===t.sliceSerialize(e[n][1]).charCodeAt(0)){if((e[r][1]._close||e[n][1]._open)&&(e[n][1].end.offset-e[n][1].start.offset)%3&&!((e[r][1].end.offset-e[r][1].start.offset+e[n][1].end.offset-e[n][1].start.offset)%3))continue;l=e[r][1].end.offset-e[r][1].start.offset>1&&e[n][1].end.offset-e[n][1].start.offset>1?2:1;const f={...e[r][1].end},h={...e[n][1].start};eL(f,-l),eL(h,l),i={type:l>1?"strongSequence":"emphasisSequence",start:f,end:{...e[r][1].end}},a={type:l>1?"strongSequence":"emphasisSequence",start:{...e[n][1].start},end:h},o={type:l>1?"strongText":"emphasisText",start:{...e[r][1].end},end:{...e[n][1].start}},s={type:l>1?"strong":"emphasis",start:{...i.start},end:{...a.end}},e[r][1].end={...i.start},e[n][1].start={...a.end},u=[],e[r][1].end.offset-e[r][1].start.offset&&(u=Ho(u,[["enter",e[r][1],t],["exit",e[r][1],t]])),u=Ho(u,[["enter",s,t],["enter",i,t],["exit",i,t],["enter",o,t]]),u=Ho(u,yC(t.parser.constructs.insideSpan.null,e.slice(r+1,n),t)),u=Ho(u,[["exit",o,t],["enter",a,t],["exit",a,t],["exit",s,t]]),e[n][1].end.offset-e[n][1].start.offset?(d=2,u=Ho(u,[["enter",e[n][1],t],["exit",e[n][1],t]])):d=0,Eo(e,r-1,n-r+3,u),n=r+u.length-d-2;break}}for(n=-1;++n<e.length;)e[n][1].type==="attentionSequence"&&(e[n][1].type="data");return e}function f7e(e,t){const n=this.parser.constructs.attentionMarkers.null,r=this.previous,s=nm(r);let o;return i;function i(l){return o=l,e.enter("attentionSequence"),a(l)}function a(l){if(l===o)return e.consume(l),a;const u=e.exit("attentionSequence"),d=nm(l),f=!d||d===2&&s||n.includes(l),h=!s||s===2&&d||n.includes(r);return u._open=!!(o===42?f:f&&(s||!h)),u._close=!!(o===42?h:h&&(d||!f)),t(l)}}function eL(e,t){e.column+=t,e.offset+=t,e._bufferIndex+=t}const h7e={name:"autolink",tokenize:m7e};function m7e(e,t,n){let r=0;return s;function s(m){return e.enter("autolink"),e.enter("autolinkMarker"),e.consume(m),e.exit("autolinkMarker"),e.enter("autolinkProtocol"),o}function o(m){return Is(m)?(e.consume(m),i):m===64?n(m):u(m)}function i(m){return m===43||m===45||m===46||ps(m)?(r=1,a(m)):u(m)}function a(m){return m===58?(e.consume(m),r=0,l):(m===43||m===45||m===46||ps(m))&&r++<32?(e.consume(m),a):(r=0,u(m))}function l(m){return m===62?(e.exit("autolinkProtocol"),e.enter("autolinkMarker"),e.consume(m),e.exit("autolinkMarker"),e.exit("autolink"),t):m===null||m===32||m===60||Zw(m)?n(m):(e.consume(m),l)}function u(m){return m===64?(e.consume(m),d):r7e(m)?(e.consume(m),u):n(m)}function d(m){return ps(m)?f(m):n(m)}function f(m){return m===46?(e.consume(m),r=0,d):m===62?(e.exit("autolinkProtocol").type="autolinkEmail",e.enter("autolinkMarker"),e.consume(m),e.exit("autolinkMarker"),e.exit("autolink"),t):h(m)}function h(m){if((m===45||ps(m))&&r++<63){const p=m===45?h:f;return e.consume(m),p}return n(m)}}const ly={partial:!0,tokenize:p7e};function p7e(e,t,n){return r;function r(o){return zt(o)?Kt(e,s,"linePrefix")(o):s(o)}function s(o){return o===null||it(o)?t(o):n(o)}}const kQ={continuation:{tokenize:b7e},exit:x7e,name:"blockQuote",tokenize:g7e};function g7e(e,t,n){const r=this;return s;function s(i){if(i===62){const a=r.containerState;return a.open||(e.enter("blockQuote",{_container:!0}),a.open=!0),e.enter("blockQuotePrefix"),e.enter("blockQuoteMarker"),e.consume(i),e.exit("blockQuoteMarker"),o}return n(i)}function o(i){return zt(i)?(e.enter("blockQuotePrefixWhitespace"),e.consume(i),e.exit("blockQuotePrefixWhitespace"),e.exit("blockQuotePrefix"),t):(e.exit("blockQuotePrefix"),t(i))}}function b7e(e,t,n){const r=this;return s;function s(i){return zt(i)?Kt(e,o,"linePrefix",r.parser.constructs.disable.null.includes("codeIndented")?void 0:4)(i):o(i)}function o(i){return e.attempt(kQ,t,n)(i)}}function x7e(e){e.exit("blockQuote")}const EQ={name:"characterEscape",tokenize:y7e};function y7e(e,t,n){return r;function r(o){return e.enter("characterEscape"),e.enter("escapeMarker"),e.consume(o),e.exit("escapeMarker"),s}function s(o){return o7e(o)?(e.enter("characterEscapeValue"),e.consume(o),e.exit("characterEscapeValue"),e.exit("characterEscape"),t):n(o)}}const _Q={name:"characterReference",tokenize:v7e};function v7e(e,t,n){const r=this;let s=0,o,i;return a;function a(f){return e.enter("characterReference"),e.enter("characterReferenceMarker"),e.consume(f),e.exit("characterReferenceMarker"),l}function l(f){return f===35?(e.enter("characterReferenceMarkerNumeric"),e.consume(f),e.exit("characterReferenceMarkerNumeric"),u):(e.enter("characterReferenceValue"),o=31,i=ps,d(f))}function u(f){return f===88||f===120?(e.enter("characterReferenceMarkerHexadecimal"),e.consume(f),e.exit("characterReferenceMarkerHexadecimal"),e.enter("characterReferenceValue"),o=6,i=s7e,d):(e.enter("characterReferenceValue"),o=7,i=N_,d(f))}function d(f){if(f===59&&s){const h=e.exit("characterReferenceValue");return i===ps&&!GI(r.sliceSerialize(h))?n(f):(e.enter("characterReferenceMarker"),e.consume(f),e.exit("characterReferenceMarker"),e.exit("characterReference"),t)}return i(f)&&s++<o?(e.consume(f),d):n(f)}}const tL={partial:!0,tokenize:S7e},nL={concrete:!0,name:"codeFenced",tokenize:w7e};function w7e(e,t,n){const r=this,s={partial:!0,tokenize:N};let o=0,i=0,a;return l;function l(S){return u(S)}function u(S){const j=r.events[r.events.length-1];return o=j&&j[1].type==="linePrefix"?j[2].sliceSerialize(j[1],!0).length:0,a=S,e.enter("codeFenced"),e.enter("codeFencedFence"),e.enter("codeFencedFenceSequence"),d(S)}function d(S){return S===a?(i++,e.consume(S),d):i<3?n(S):(e.exit("codeFencedFenceSequence"),zt(S)?Kt(e,f,"whitespace")(S):f(S))}function f(S){return S===null||it(S)?(e.exit("codeFencedFence"),r.interrupt?t(S):e.check(tL,g,w)(S)):(e.enter("codeFencedFenceInfo"),e.enter("chunkString",{contentType:"string"}),h(S))}function h(S){return S===null||it(S)?(e.exit("chunkString"),e.exit("codeFencedFenceInfo"),f(S)):zt(S)?(e.exit("chunkString"),e.exit("codeFencedFenceInfo"),Kt(e,m,"whitespace")(S)):S===96&&S===a?n(S):(e.consume(S),h)}function m(S){return S===null||it(S)?f(S):(e.enter("codeFencedFenceMeta"),e.enter("chunkString",{contentType:"string"}),p(S))}function p(S){return S===null||it(S)?(e.exit("chunkString"),e.exit("codeFencedFenceMeta"),f(S)):S===96&&S===a?n(S):(e.consume(S),p)}function g(S){return e.attempt(s,w,b)(S)}function b(S){return e.enter("lineEnding"),e.consume(S),e.exit("lineEnding"),x}function x(S){return o>0&&zt(S)?Kt(e,y,"linePrefix",o+1)(S):y(S)}function y(S){return S===null||it(S)?e.check(tL,g,w)(S):(e.enter("codeFlowValue"),v(S))}function v(S){return S===null||it(S)?(e.exit("codeFlowValue"),y(S)):(e.consume(S),v)}function w(S){return e.exit("codeFenced"),t(S)}function N(S,j,E){let _=0;return k;function k(I){return S.enter("lineEnding"),S.consume(I),S.exit("lineEnding"),M}function M(I){return S.enter("codeFencedFence"),zt(I)?Kt(S,D,"linePrefix",r.parser.constructs.disable.null.includes("codeIndented")?void 0:4)(I):D(I)}function D(I){return I===a?(S.enter("codeFencedFenceSequence"),R(I)):E(I)}function R(I){return I===a?(_++,S.consume(I),R):_>=i?(S.exit("codeFencedFenceSequence"),zt(I)?Kt(S,P,"whitespace")(I):P(I)):E(I)}function P(I){return I===null||it(I)?(S.exit("codeFencedFence"),j(I)):E(I)}}}function S7e(e,t,n){const r=this;return s;function s(i){return i===null?n(i):(e.enter("lineEnding"),e.consume(i),e.exit("lineEnding"),o)}function o(i){return r.parser.lazy[r.now().line]?n(i):t(i)}}const m2={name:"codeIndented",tokenize:N7e},C7e={partial:!0,tokenize:j7e};function N7e(e,t,n){const r=this;return s;function s(u){return e.enter("codeIndented"),Kt(e,o,"linePrefix",5)(u)}function o(u){const d=r.events[r.events.length-1];return d&&d[1].type==="linePrefix"&&d[2].sliceSerialize(d[1],!0).length>=4?i(u):n(u)}function i(u){return u===null?l(u):it(u)?e.attempt(C7e,i,l)(u):(e.enter("codeFlowValue"),a(u))}function a(u){return u===null||it(u)?(e.exit("codeFlowValue"),i(u)):(e.consume(u),a)}function l(u){return e.exit("codeIndented"),t(u)}}function j7e(e,t,n){const r=this;return s;function s(i){return r.parser.lazy[r.now().line]?n(i):it(i)?(e.enter("lineEnding"),e.consume(i),e.exit("lineEnding"),s):Kt(e,o,"linePrefix",5)(i)}function o(i){const a=r.events[r.events.length-1];return a&&a[1].type==="linePrefix"&&a[2].sliceSerialize(a[1],!0).length>=4?t(i):it(i)?s(i):n(i)}}const k7e={name:"codeText",previous:_7e,resolve:E7e,tokenize:D7e};function E7e(e){let t=e.length-4,n=3,r,s;if((e[n][1].type==="lineEnding"||e[n][1].type==="space")&&(e[t][1].type==="lineEnding"||e[t][1].type==="space")){for(r=n;++r<t;)if(e[r][1].type==="codeTextData"){e[n][1].type="codeTextPadding",e[t][1].type="codeTextPadding",n+=2,t-=2;break}}for(r=n-1,t++;++r<=t;)s===void 0?r!==t&&e[r][1].type!=="lineEnding"&&(s=r):(r===t||e[r][1].type==="lineEnding")&&(e[s][1].type="codeTextData",r!==s+2&&(e[s][1].end=e[r-1][1].end,e.splice(s+2,r-s-2),t-=r-s-2,r=s+2),s=void 0);return e}function _7e(e){return e!==96||this.events[this.events.length-1][1].type==="characterEscape"}function D7e(e,t,n){let r=0,s,o;return i;function i(f){return e.enter("codeText"),e.enter("codeTextSequence"),a(f)}function a(f){return f===96?(e.consume(f),r++,a):(e.exit("codeTextSequence"),l(f))}function l(f){return f===null?n(f):f===32?(e.enter("space"),e.consume(f),e.exit("space"),l):f===96?(o=e.enter("codeTextSequence"),s=0,d(f)):it(f)?(e.enter("lineEnding"),e.consume(f),e.exit("lineEnding"),l):(e.enter("codeTextData"),u(f))}function u(f){return f===null||f===32||f===96||it(f)?(e.exit("codeTextData"),l(f)):(e.consume(f),u)}function d(f){return f===96?(e.consume(f),s++,d):s===r?(e.exit("codeTextSequence"),e.exit("codeText"),t(f)):(o.type="codeTextData",u(f))}}class M7e{constructor(t){this.left=t?[...t]:[],this.right=[]}get(t){if(t<0||t>=this.left.length+this.right.length)throw new RangeError("Cannot access index `"+t+"` in a splice buffer of size `"+(this.left.length+this.right.length)+"`");return t<this.left.length?this.left[t]:this.right[this.right.length-t+this.left.length-1]}get length(){return this.left.length+this.right.length}shift(){return this.setCursor(0),this.right.pop()}slice(t,n){const r=n??Number.POSITIVE_INFINITY;return r<this.left.length?this.left.slice(t,r):t>this.left.length?this.right.slice(this.right.length-r+this.left.length,this.right.length-t+this.left.length).reverse():this.left.slice(t).concat(this.right.slice(this.right.length-r+this.left.length).reverse())}splice(t,n,r){const s=n||0;this.setCursor(Math.trunc(t));const o=this.right.splice(this.right.length-s,Number.POSITIVE_INFINITY);return r&&Pp(this.left,r),o.reverse()}pop(){return this.setCursor(Number.POSITIVE_INFINITY),this.left.pop()}push(t){this.setCursor(Number.POSITIVE_INFINITY),this.left.push(t)}pushMany(t){this.setCursor(Number.POSITIVE_INFINITY),Pp(this.left,t)}unshift(t){this.setCursor(0),this.right.push(t)}unshiftMany(t){this.setCursor(0),Pp(this.right,t.reverse())}setCursor(t){if(!(t===this.left.length||t>this.left.length&&this.right.length===0||t<0&&this.left.length===0))if(t<this.left.length){const n=this.left.splice(t,Number.POSITIVE_INFINITY);Pp(this.right,n.reverse())}else{const n=this.right.splice(this.left.length+this.right.length-t,Number.POSITIVE_INFINITY);Pp(this.left,n.reverse())}}}function Pp(e,t){let n=0;if(t.length<1e4)e.push(...t);else for(;n<t.length;)e.push(...t.slice(n,n+1e4)),n+=1e4}function DQ(e){const t={};let n=-1,r,s,o,i,a,l,u;const d=new M7e(e);for(;++n<d.length;){for(;n in t;)n=t[n];if(r=d.get(n),n&&r[1].type==="chunkFlow"&&d.get(n-1)[1].type==="listItemPrefix"&&(l=r[1]._tokenizer.events,o=0,o<l.length&&l[o][1].type==="lineEndingBlank"&&(o+=2),o<l.length&&l[o][1].type==="content"))for(;++o<l.length&&l[o][1].type!=="content";)l[o][1].type==="chunkText"&&(l[o][1]._isInFirstContentOfListItem=!0,o++);if(r[0]==="enter")r[1].contentType&&(Object.assign(t,T7e(d,n)),n=t[n],u=!0);else if(r[1]._container){for(o=n,s=void 0;o--;)if(i=d.get(o),i[1].type==="lineEnding"||i[1].type==="lineEndingBlank")i[0]==="enter"&&(s&&(d.get(s)[1].type="lineEndingBlank"),i[1].type="lineEnding",s=o);else if(!(i[1].type==="linePrefix"||i[1].type==="listItemIndent"))break;s&&(r[1].end={...d.get(s)[1].start},a=d.slice(s,n),a.unshift(r),d.splice(s,n-s+1,a))}}return Eo(e,0,Number.POSITIVE_INFINITY,d.slice(0)),!u}function T7e(e,t){const n=e.get(t)[1],r=e.get(t)[2];let s=t-1;const o=[];let i=n._tokenizer;i||(i=r.parser[n.contentType](n.start),n._contentTypeTextTrailing&&(i._contentTypeTextTrailing=!0));const a=i.events,l=[],u={};let d,f,h=-1,m=n,p=0,g=0;const b=[g];for(;m;){for(;e.get(++s)[1]!==m;);o.push(s),m._tokenizer||(d=r.sliceStream(m),m.next||d.push(null),f&&i.defineSkip(m.start),m._isInFirstContentOfListItem&&(i._gfmTasklistFirstContentOfListItem=!0),i.write(d),m._isInFirstContentOfListItem&&(i._gfmTasklistFirstContentOfListItem=void 0)),f=m,m=m.next}for(m=n;++h<a.length;)a[h][0]==="exit"&&a[h-1][0]==="enter"&&a[h][1].type===a[h-1][1].type&&a[h][1].start.line!==a[h][1].end.line&&(g=h+1,b.push(g),m._tokenizer=void 0,m.previous=void 0,m=m.next);for(i.events=[],m?(m._tokenizer=void 0,m.previous=void 0):b.pop(),h=b.length;h--;){const x=a.slice(b[h],b[h+1]),y=o.pop();l.push([y,y+x.length-1]),e.splice(y,2,x)}for(l.reverse(),h=-1;++h<l.length;)u[p+l[h][0]]=p+l[h][1],p+=l[h][1]-l[h][0]-1;return u}const R7e={resolve:A7e,tokenize:P7e},I7e={partial:!0,tokenize:O7e};function A7e(e){return DQ(e),e}function P7e(e,t){let n;return r;function r(a){return e.enter("content"),n=e.enter("chunkContent",{contentType:"content"}),s(a)}function s(a){return a===null?o(a):it(a)?e.check(I7e,i,o)(a):(e.consume(a),s)}function o(a){return e.exit("chunkContent"),e.exit("content"),t(a)}function i(a){return e.consume(a),e.exit("chunkContent"),n.next=e.enter("chunkContent",{contentType:"content",previous:n}),n=n.next,s}}function O7e(e,t,n){const r=this;return s;function s(i){return e.exit("chunkContent"),e.enter("lineEnding"),e.consume(i),e.exit("lineEnding"),Kt(e,o,"linePrefix")}function o(i){if(i===null||it(i))return n(i);const a=r.events[r.events.length-1];return!r.parser.constructs.disable.null.includes("codeIndented")&&a&&a[1].type==="linePrefix"&&a[2].sliceSerialize(a[1],!0).length>=4?t(i):e.interrupt(r.parser.constructs.flow,n,t)(i)}}function MQ(e,t,n,r,s,o,i,a,l){const u=l||Number.POSITIVE_INFINITY;let d=0;return f;function f(x){return x===60?(e.enter(r),e.enter(s),e.enter(o),e.consume(x),e.exit(o),h):x===null||x===32||x===41||Zw(x)?n(x):(e.enter(r),e.enter(i),e.enter(a),e.enter("chunkString",{contentType:"string"}),g(x))}function h(x){return x===62?(e.enter(o),e.consume(x),e.exit(o),e.exit(s),e.exit(r),t):(e.enter(a),e.enter("chunkString",{contentType:"string"}),m(x))}function m(x){return x===62?(e.exit("chunkString"),e.exit(a),h(x)):x===null||x===60||it(x)?n(x):(e.consume(x),x===92?p:m)}function p(x){return x===60||x===62||x===92?(e.consume(x),m):m(x)}function g(x){return!d&&(x===null||x===41||Mn(x))?(e.exit("chunkString"),e.exit(a),e.exit(i),e.exit(r),t(x)):d<u&&x===40?(e.consume(x),d++,g):x===41?(e.consume(x),d--,g):x===null||x===32||x===40||Zw(x)?n(x):(e.consume(x),x===92?b:g)}function b(x){return x===40||x===41||x===92?(e.consume(x),g):g(x)}}function TQ(e,t,n,r,s,o){const i=this;let a=0,l;return u;function u(m){return e.enter(r),e.enter(s),e.consume(m),e.exit(s),e.enter(o),d}function d(m){return a>999||m===null||m===91||m===93&&!l||m===94&&!a&&"_hiddenFootnoteSupport"in i.parser.constructs?n(m):m===93?(e.exit(o),e.enter(s),e.consume(m),e.exit(s),e.exit(r),t):it(m)?(e.enter("lineEnding"),e.consume(m),e.exit("lineEnding"),d):(e.enter("chunkString",{contentType:"string"}),f(m))}function f(m){return m===null||m===91||m===93||it(m)||a++>999?(e.exit("chunkString"),d(m)):(e.consume(m),l||(l=!zt(m)),m===92?h:f)}function h(m){return m===91||m===92||m===93?(e.consume(m),a++,f):f(m)}}function RQ(e,t,n,r,s,o){let i;return a;function a(h){return h===34||h===39||h===40?(e.enter(r),e.enter(s),e.consume(h),e.exit(s),i=h===40?41:h,l):n(h)}function l(h){return h===i?(e.enter(s),e.consume(h),e.exit(s),e.exit(r),t):(e.enter(o),u(h))}function u(h){return h===i?(e.exit(o),l(i)):h===null?n(h):it(h)?(e.enter("lineEnding"),e.consume(h),e.exit("lineEnding"),Kt(e,u,"linePrefix")):(e.enter("chunkString",{contentType:"string"}),d(h))}function d(h){return h===i||h===null||it(h)?(e.exit("chunkString"),u(h)):(e.consume(h),h===92?f:d)}function f(h){return h===i||h===92?(e.consume(h),d):d(h)}}function Ag(e,t){let n;return r;function r(s){return it(s)?(e.enter("lineEnding"),e.consume(s),e.exit("lineEnding"),n=!0,r):zt(s)?Kt(e,r,n?"linePrefix":"lineSuffix")(s):t(s)}}const F7e={name:"definition",tokenize:L7e},$7e={partial:!0,tokenize:z7e};function L7e(e,t,n){const r=this;let s;return o;function o(m){return e.enter("definition"),i(m)}function i(m){return TQ.call(r,e,a,n,"definitionLabel","definitionLabelMarker","definitionLabelString")(m)}function a(m){return s=Ti(r.sliceSerialize(r.events[r.events.length-1][1]).slice(1,-1)),m===58?(e.enter("definitionMarker"),e.consume(m),e.exit("definitionMarker"),l):n(m)}function l(m){return Mn(m)?Ag(e,u)(m):u(m)}function u(m){return MQ(e,d,n,"definitionDestination","definitionDestinationLiteral","definitionDestinationLiteralMarker","definitionDestinationRaw","definitionDestinationString")(m)}function d(m){return e.attempt($7e,f,f)(m)}function f(m){return zt(m)?Kt(e,h,"whitespace")(m):h(m)}function h(m){return m===null||it(m)?(e.exit("definition"),r.parser.defined.push(s),t(m)):n(m)}}function z7e(e,t,n){return r;function r(a){return Mn(a)?Ag(e,s)(a):n(a)}function s(a){return RQ(e,o,n,"definitionTitle","definitionTitleMarker","definitionTitleString")(a)}function o(a){return zt(a)?Kt(e,i,"whitespace")(a):i(a)}function i(a){return a===null||it(a)?t(a):n(a)}}const B7e={name:"hardBreakEscape",tokenize:V7e};function V7e(e,t,n){return r;function r(o){return e.enter("hardBreakEscape"),e.consume(o),s}function s(o){return it(o)?(e.exit("hardBreakEscape"),t(o)):n(o)}}const H7e={name:"headingAtx",resolve:U7e,tokenize:W7e};function U7e(e,t){let n=e.length-2,r=3,s,o;return e[r][1].type==="whitespace"&&(r+=2),n-2>r&&e[n][1].type==="whitespace"&&(n-=2),e[n][1].type==="atxHeadingSequence"&&(r===n-1||n-4>r&&e[n-2][1].type==="whitespace")&&(n-=r+1===n?2:4),n>r&&(s={type:"atxHeadingText",start:e[r][1].start,end:e[n][1].end},o={type:"chunkText",start:e[r][1].start,end:e[n][1].end,contentType:"text"},Eo(e,r,n-r+1,[["enter",s,t],["enter",o,t],["exit",o,t],["exit",s,t]])),e}function W7e(e,t,n){let r=0;return s;function s(d){return e.enter("atxHeading"),o(d)}function o(d){return e.enter("atxHeadingSequence"),i(d)}function i(d){return d===35&&r++<6?(e.consume(d),i):d===null||Mn(d)?(e.exit("atxHeadingSequence"),a(d)):n(d)}function a(d){return d===35?(e.enter("atxHeadingSequence"),l(d)):d===null||it(d)?(e.exit("atxHeading"),t(d)):zt(d)?Kt(e,a,"whitespace")(d):(e.enter("atxHeadingText"),u(d))}function l(d){return d===35?(e.consume(d),l):(e.exit("atxHeadingSequence"),a(d))}function u(d){return d===null||d===35||Mn(d)?(e.exit("atxHeadingText"),a(d)):(e.consume(d),u)}}const q7e=["address","article","aside","base","basefont","blockquote","body","caption","center","col","colgroup","dd","details","dialog","dir","div","dl","dt","fieldset","figcaption","figure","footer","form","frame","frameset","h1","h2","h3","h4","h5","h6","head","header","hr","html","iframe","legend","li","link","main","menu","menuitem","nav","noframes","ol","optgroup","option","p","param","search","section","summary","table","tbody","td","tfoot","th","thead","title","tr","track","ul"],rL=["pre","script","style","textarea"],Y7e={concrete:!0,name:"htmlFlow",resolveTo:Z7e,tokenize:X7e},G7e={partial:!0,tokenize:J7e},K7e={partial:!0,tokenize:Q7e};function Z7e(e){let t=e.length;for(;t--&&!(e[t][0]==="enter"&&e[t][1].type==="htmlFlow"););return t>1&&e[t-2][1].type==="linePrefix"&&(e[t][1].start=e[t-2][1].start,e[t+1][1].start=e[t-2][1].start,e.splice(t-2,2)),e}function X7e(e,t,n){const r=this;let s,o,i,a,l;return u;function u(O){return d(O)}function d(O){return e.enter("htmlFlow"),e.enter("htmlFlowData"),e.consume(O),f}function f(O){return O===33?(e.consume(O),h):O===47?(e.consume(O),o=!0,g):O===63?(e.consume(O),s=3,r.interrupt?t:A):Is(O)?(e.consume(O),i=String.fromCharCode(O),b):n(O)}function h(O){return O===45?(e.consume(O),s=2,m):O===91?(e.consume(O),s=5,a=0,p):Is(O)?(e.consume(O),s=4,r.interrupt?t:A):n(O)}function m(O){return O===45?(e.consume(O),r.interrupt?t:A):n(O)}function p(O){const W="CDATA[";return O===W.charCodeAt(a++)?(e.consume(O),a===W.length?r.interrupt?t:D:p):n(O)}function g(O){return Is(O)?(e.consume(O),i=String.fromCharCode(O),b):n(O)}function b(O){if(O===null||O===47||O===62||Mn(O)){const W=O===47,B=i.toLowerCase();return!W&&!o&&rL.includes(B)?(s=1,r.interrupt?t(O):D(O)):q7e.includes(i.toLowerCase())?(s=6,W?(e.consume(O),x):r.interrupt?t(O):D(O)):(s=7,r.interrupt&&!r.parser.lazy[r.now().line]?n(O):o?y(O):v(O))}return O===45||ps(O)?(e.consume(O),i+=String.fromCharCode(O),b):n(O)}function x(O){return O===62?(e.consume(O),r.interrupt?t:D):n(O)}function y(O){return zt(O)?(e.consume(O),y):k(O)}function v(O){return O===47?(e.consume(O),k):O===58||O===95||Is(O)?(e.consume(O),w):zt(O)?(e.consume(O),v):k(O)}function w(O){return O===45||O===46||O===58||O===95||ps(O)?(e.consume(O),w):N(O)}function N(O){return O===61?(e.consume(O),S):zt(O)?(e.consume(O),N):v(O)}function S(O){return O===null||O===60||O===61||O===62||O===96?n(O):O===34||O===39?(e.consume(O),l=O,j):zt(O)?(e.consume(O),S):E(O)}function j(O){return O===l?(e.consume(O),l=null,_):O===null||it(O)?n(O):(e.consume(O),j)}function E(O){return O===null||O===34||O===39||O===47||O===60||O===61||O===62||O===96||Mn(O)?N(O):(e.consume(O),E)}function _(O){return O===47||O===62||zt(O)?v(O):n(O)}function k(O){return O===62?(e.consume(O),M):n(O)}function M(O){return O===null||it(O)?D(O):zt(O)?(e.consume(O),M):n(O)}function D(O){return O===45&&s===2?(e.consume(O),L):O===60&&s===1?(e.consume(O),F):O===62&&s===4?(e.consume(O),q):O===63&&s===3?(e.consume(O),A):O===93&&s===5?(e.consume(O),$):it(O)&&(s===6||s===7)?(e.exit("htmlFlowData"),e.check(G7e,z,R)(O)):O===null||it(O)?(e.exit("htmlFlowData"),R(O)):(e.consume(O),D)}function R(O){return e.check(K7e,P,z)(O)}function P(O){return e.enter("lineEnding"),e.consume(O),e.exit("lineEnding"),I}function I(O){return O===null||it(O)?R(O):(e.enter("htmlFlowData"),D(O))}function L(O){return O===45?(e.consume(O),A):D(O)}function F(O){return O===47?(e.consume(O),i="",H):D(O)}function H(O){if(O===62){const W=i.toLowerCase();return rL.includes(W)?(e.consume(O),q):D(O)}return Is(O)&&i.length<8?(e.consume(O),i+=String.fromCharCode(O),H):D(O)}function $(O){return O===93?(e.consume(O),A):D(O)}function A(O){return O===62?(e.consume(O),q):O===45&&s===2?(e.consume(O),A):D(O)}function q(O){return O===null||it(O)?(e.exit("htmlFlowData"),z(O)):(e.consume(O),q)}function z(O){return e.exit("htmlFlow"),t(O)}}function Q7e(e,t,n){const r=this;return s;function s(i){return it(i)?(e.enter("lineEnding"),e.consume(i),e.exit("lineEnding"),o):n(i)}function o(i){return r.parser.lazy[r.now().line]?n(i):t(i)}}function J7e(e,t,n){return r;function r(s){return e.enter("lineEnding"),e.consume(s),e.exit("lineEnding"),e.attempt(ly,t,n)}}const eBe={name:"htmlText",tokenize:tBe};function tBe(e,t,n){const r=this;let s,o,i;return a;function a(A){return e.enter("htmlText"),e.enter("htmlTextData"),e.consume(A),l}function l(A){return A===33?(e.consume(A),u):A===47?(e.consume(A),N):A===63?(e.consume(A),v):Is(A)?(e.consume(A),E):n(A)}function u(A){return A===45?(e.consume(A),d):A===91?(e.consume(A),o=0,p):Is(A)?(e.consume(A),y):n(A)}function d(A){return A===45?(e.consume(A),m):n(A)}function f(A){return A===null?n(A):A===45?(e.consume(A),h):it(A)?(i=f,F(A)):(e.consume(A),f)}function h(A){return A===45?(e.consume(A),m):f(A)}function m(A){return A===62?L(A):A===45?h(A):f(A)}function p(A){const q="CDATA[";return A===q.charCodeAt(o++)?(e.consume(A),o===q.length?g:p):n(A)}function g(A){return A===null?n(A):A===93?(e.consume(A),b):it(A)?(i=g,F(A)):(e.consume(A),g)}function b(A){return A===93?(e.consume(A),x):g(A)}function x(A){return A===62?L(A):A===93?(e.consume(A),x):g(A)}function y(A){return A===null||A===62?L(A):it(A)?(i=y,F(A)):(e.consume(A),y)}function v(A){return A===null?n(A):A===63?(e.consume(A),w):it(A)?(i=v,F(A)):(e.consume(A),v)}function w(A){return A===62?L(A):v(A)}function N(A){return Is(A)?(e.consume(A),S):n(A)}function S(A){return A===45||ps(A)?(e.consume(A),S):j(A)}function j(A){return it(A)?(i=j,F(A)):zt(A)?(e.consume(A),j):L(A)}function E(A){return A===45||ps(A)?(e.consume(A),E):A===47||A===62||Mn(A)?_(A):n(A)}function _(A){return A===47?(e.consume(A),L):A===58||A===95||Is(A)?(e.consume(A),k):it(A)?(i=_,F(A)):zt(A)?(e.consume(A),_):L(A)}function k(A){return A===45||A===46||A===58||A===95||ps(A)?(e.consume(A),k):M(A)}function M(A){return A===61?(e.consume(A),D):it(A)?(i=M,F(A)):zt(A)?(e.consume(A),M):_(A)}function D(A){return A===null||A===60||A===61||A===62||A===96?n(A):A===34||A===39?(e.consume(A),s=A,R):it(A)?(i=D,F(A)):zt(A)?(e.consume(A),D):(e.consume(A),P)}function R(A){return A===s?(e.consume(A),s=void 0,I):A===null?n(A):it(A)?(i=R,F(A)):(e.consume(A),R)}function P(A){return A===null||A===34||A===39||A===60||A===61||A===96?n(A):A===47||A===62||Mn(A)?_(A):(e.consume(A),P)}function I(A){return A===47||A===62||Mn(A)?_(A):n(A)}function L(A){return A===62?(e.consume(A),e.exit("htmlTextData"),e.exit("htmlText"),t):n(A)}function F(A){return e.exit("htmlTextData"),e.enter("lineEnding"),e.consume(A),e.exit("lineEnding"),H}function H(A){return zt(A)?Kt(e,$,"linePrefix",r.parser.constructs.disable.null.includes("codeIndented")?void 0:4)(A):$(A)}function $(A){return e.enter("htmlTextData"),i(A)}}const KI={name:"labelEnd",resolveAll:oBe,resolveTo:iBe,tokenize:aBe},nBe={tokenize:lBe},rBe={tokenize:cBe},sBe={tokenize:uBe};function oBe(e){let t=-1;const n=[];for(;++t<e.length;){const r=e[t][1];if(n.push(e[t]),r.type==="labelImage"||r.type==="labelLink"||r.type==="labelEnd"){const s=r.type==="labelImage"?4:2;r.type="data",t+=s}}return e.length!==n.length&&Eo(e,0,e.length,n),e}function iBe(e,t){let n=e.length,r=0,s,o,i,a;for(;n--;)if(s=e[n][1],o){if(s.type==="link"||s.type==="labelLink"&&s._inactive)break;e[n][0]==="enter"&&s.type==="labelLink"&&(s._inactive=!0)}else if(i){if(e[n][0]==="enter"&&(s.type==="labelImage"||s.type==="labelLink")&&!s._balanced&&(o=n,s.type!=="labelLink")){r=2;break}}else s.type==="labelEnd"&&(i=n);const l={type:e[o][1].type==="labelLink"?"link":"image",start:{...e[o][1].start},end:{...e[e.length-1][1].end}},u={type:"label",start:{...e[o][1].start},end:{...e[i][1].end}},d={type:"labelText",start:{...e[o+r+2][1].end},end:{...e[i-2][1].start}};return a=[["enter",l,t],["enter",u,t]],a=Ho(a,e.slice(o+1,o+r+3)),a=Ho(a,[["enter",d,t]]),a=Ho(a,yC(t.parser.constructs.insideSpan.null,e.slice(o+r+4,i-3),t)),a=Ho(a,[["exit",d,t],e[i-2],e[i-1],["exit",u,t]]),a=Ho(a,e.slice(i+1)),a=Ho(a,[["exit",l,t]]),Eo(e,o,e.length,a),e}function aBe(e,t,n){const r=this;let s=r.events.length,o,i;for(;s--;)if((r.events[s][1].type==="labelImage"||r.events[s][1].type==="labelLink")&&!r.events[s][1]._balanced){o=r.events[s][1];break}return a;function a(h){return o?o._inactive?f(h):(i=r.parser.defined.includes(Ti(r.sliceSerialize({start:o.end,end:r.now()}))),e.enter("labelEnd"),e.enter("labelMarker"),e.consume(h),e.exit("labelMarker"),e.exit("labelEnd"),l):n(h)}function l(h){return h===40?e.attempt(nBe,d,i?d:f)(h):h===91?e.attempt(rBe,d,i?u:f)(h):i?d(h):f(h)}function u(h){return e.attempt(sBe,d,f)(h)}function d(h){return t(h)}function f(h){return o._balanced=!0,n(h)}}function lBe(e,t,n){return r;function r(f){return e.enter("resource"),e.enter("resourceMarker"),e.consume(f),e.exit("resourceMarker"),s}function s(f){return Mn(f)?Ag(e,o)(f):o(f)}function o(f){return f===41?d(f):MQ(e,i,a,"resourceDestination","resourceDestinationLiteral","resourceDestinationLiteralMarker","resourceDestinationRaw","resourceDestinationString",32)(f)}function i(f){return Mn(f)?Ag(e,l)(f):d(f)}function a(f){return n(f)}function l(f){return f===34||f===39||f===40?RQ(e,u,n,"resourceTitle","resourceTitleMarker","resourceTitleString")(f):d(f)}function u(f){return Mn(f)?Ag(e,d)(f):d(f)}function d(f){return f===41?(e.enter("resourceMarker"),e.consume(f),e.exit("resourceMarker"),e.exit("resource"),t):n(f)}}function cBe(e,t,n){const r=this;return s;function s(a){return TQ.call(r,e,o,i,"reference","referenceMarker","referenceString")(a)}function o(a){return r.parser.defined.includes(Ti(r.sliceSerialize(r.events[r.events.length-1][1]).slice(1,-1)))?t(a):n(a)}function i(a){return n(a)}}function uBe(e,t,n){return r;function r(o){return e.enter("reference"),e.enter("referenceMarker"),e.consume(o),e.exit("referenceMarker"),s}function s(o){return o===93?(e.enter("referenceMarker"),e.consume(o),e.exit("referenceMarker"),e.exit("reference"),t):n(o)}}const dBe={name:"labelStartImage",resolveAll:KI.resolveAll,tokenize:fBe};function fBe(e,t,n){const r=this;return s;function s(a){return e.enter("labelImage"),e.enter("labelImageMarker"),e.consume(a),e.exit("labelImageMarker"),o}function o(a){return a===91?(e.enter("labelMarker"),e.consume(a),e.exit("labelMarker"),e.exit("labelImage"),i):n(a)}function i(a){return a===94&&"_hiddenFootnoteSupport"in r.parser.constructs?n(a):t(a)}}const hBe={name:"labelStartLink",resolveAll:KI.resolveAll,tokenize:mBe};function mBe(e,t,n){const r=this;return s;function s(i){return e.enter("labelLink"),e.enter("labelMarker"),e.consume(i),e.exit("labelMarker"),e.exit("labelLink"),o}function o(i){return i===94&&"_hiddenFootnoteSupport"in r.parser.constructs?n(i):t(i)}}const p2={name:"lineEnding",tokenize:pBe};function pBe(e,t){return n;function n(r){return e.enter("lineEnding"),e.consume(r),e.exit("lineEnding"),Kt(e,t,"linePrefix")}}const bv={name:"thematicBreak",tokenize:gBe};function gBe(e,t,n){let r=0,s;return o;function o(u){return e.enter("thematicBreak"),i(u)}function i(u){return s=u,a(u)}function a(u){return u===s?(e.enter("thematicBreakSequence"),l(u)):r>=3&&(u===null||it(u))?(e.exit("thematicBreak"),t(u)):n(u)}function l(u){return u===s?(e.consume(u),r++,l):(e.exit("thematicBreakSequence"),zt(u)?Kt(e,a,"whitespace")(u):a(u))}}const Ws={continuation:{tokenize:vBe},exit:SBe,name:"list",tokenize:yBe},bBe={partial:!0,tokenize:CBe},xBe={partial:!0,tokenize:wBe};function yBe(e,t,n){const r=this,s=r.events[r.events.length-1];let o=s&&s[1].type==="linePrefix"?s[2].sliceSerialize(s[1],!0).length:0,i=0;return a;function a(m){const p=r.containerState.type||(m===42||m===43||m===45?"listUnordered":"listOrdered");if(p==="listUnordered"?!r.containerState.marker||m===r.containerState.marker:N_(m)){if(r.containerState.type||(r.containerState.type=p,e.enter(p,{_container:!0})),p==="listUnordered")return e.enter("listItemPrefix"),m===42||m===45?e.check(bv,n,u)(m):u(m);if(!r.interrupt||m===49)return e.enter("listItemPrefix"),e.enter("listItemValue"),l(m)}return n(m)}function l(m){return N_(m)&&++i<10?(e.consume(m),l):(!r.interrupt||i<2)&&(r.containerState.marker?m===r.containerState.marker:m===41||m===46)?(e.exit("listItemValue"),u(m)):n(m)}function u(m){return e.enter("listItemMarker"),e.consume(m),e.exit("listItemMarker"),r.containerState.marker=r.containerState.marker||m,e.check(ly,r.interrupt?n:d,e.attempt(bBe,h,f))}function d(m){return r.containerState.initialBlankLine=!0,o++,h(m)}function f(m){return zt(m)?(e.enter("listItemPrefixWhitespace"),e.consume(m),e.exit("listItemPrefixWhitespace"),h):n(m)}function h(m){return r.containerState.size=o+r.sliceSerialize(e.exit("listItemPrefix"),!0).length,t(m)}}function vBe(e,t,n){const r=this;return r.containerState._closeFlow=void 0,e.check(ly,s,o);function s(a){return r.containerState.furtherBlankLines=r.containerState.furtherBlankLines||r.containerState.initialBlankLine,Kt(e,t,"listItemIndent",r.containerState.size+1)(a)}function o(a){return r.containerState.furtherBlankLines||!zt(a)?(r.containerState.furtherBlankLines=void 0,r.containerState.initialBlankLine=void 0,i(a)):(r.containerState.furtherBlankLines=void 0,r.containerState.initialBlankLine=void 0,e.attempt(xBe,t,i)(a))}function i(a){return r.containerState._closeFlow=!0,r.interrupt=void 0,Kt(e,e.attempt(Ws,t,n),"linePrefix",r.parser.constructs.disable.null.includes("codeIndented")?void 0:4)(a)}}function wBe(e,t,n){const r=this;return Kt(e,s,"listItemIndent",r.containerState.size+1);function s(o){const i=r.events[r.events.length-1];return i&&i[1].type==="listItemIndent"&&i[2].sliceSerialize(i[1],!0).length===r.containerState.size?t(o):n(o)}}function SBe(e){e.exit(this.containerState.type)}function CBe(e,t,n){const r=this;return Kt(e,s,"listItemPrefixWhitespace",r.parser.constructs.disable.null.includes("codeIndented")?void 0:5);function s(o){const i=r.events[r.events.length-1];return!zt(o)&&i&&i[1].type==="listItemPrefixWhitespace"?t(o):n(o)}}const sL={name:"setextUnderline",resolveTo:NBe,tokenize:jBe};function NBe(e,t){let n=e.length,r,s,o;for(;n--;)if(e[n][0]==="enter"){if(e[n][1].type==="content"){r=n;break}e[n][1].type==="paragraph"&&(s=n)}else e[n][1].type==="content"&&e.splice(n,1),!o&&e[n][1].type==="definition"&&(o=n);const i={type:"setextHeading",start:{...e[r][1].start},end:{...e[e.length-1][1].end}};return e[s][1].type="setextHeadingText",o?(e.splice(s,0,["enter",i,t]),e.splice(o+1,0,["exit",e[r][1],t]),e[r][1].end={...e[o][1].end}):e[r][1]=i,e.push(["exit",i,t]),e}function jBe(e,t,n){const r=this;let s;return o;function o(u){let d=r.events.length,f;for(;d--;)if(r.events[d][1].type!=="lineEnding"&&r.events[d][1].type!=="linePrefix"&&r.events[d][1].type!=="content"){f=r.events[d][1].type==="paragraph";break}return!r.parser.lazy[r.now().line]&&(r.interrupt||f)?(e.enter("setextHeadingLine"),s=u,i(u)):n(u)}function i(u){return e.enter("setextHeadingLineSequence"),a(u)}function a(u){return u===s?(e.consume(u),a):(e.exit("setextHeadingLineSequence"),zt(u)?Kt(e,l,"lineSuffix")(u):l(u))}function l(u){return u===null||it(u)?(e.exit("setextHeadingLine"),t(u)):n(u)}}const kBe={tokenize:EBe};function EBe(e){const t=this,n=e.attempt(ly,r,e.attempt(this.parser.constructs.flowInitial,s,Kt(e,e.attempt(this.parser.constructs.flow,s,e.attempt(R7e,s)),"linePrefix")));return n;function r(o){if(o===null){e.consume(o);return}return e.enter("lineEndingBlank"),e.consume(o),e.exit("lineEndingBlank"),t.currentConstruct=void 0,n}function s(o){if(o===null){e.consume(o);return}return e.enter("lineEnding"),e.consume(o),e.exit("lineEnding"),t.currentConstruct=void 0,n}}const _Be={resolveAll:AQ()},DBe=IQ("string"),MBe=IQ("text");function IQ(e){return{resolveAll:AQ(e==="text"?TBe:void 0),tokenize:t};function t(n){const r=this,s=this.parser.constructs[e],o=n.attempt(s,i,a);return i;function i(d){return u(d)?o(d):a(d)}function a(d){if(d===null){n.consume(d);return}return n.enter("data"),n.consume(d),l}function l(d){return u(d)?(n.exit("data"),o(d)):(n.consume(d),l)}function u(d){if(d===null)return!0;const f=s[d];let h=-1;if(f)for(;++h<f.length;){const m=f[h];if(!m.previous||m.previous.call(r,r.previous))return!0}return!1}}}function AQ(e){return t;function t(n,r){let s=-1,o;for(;++s<=n.length;)o===void 0?n[s]&&n[s][1].type==="data"&&(o=s,s++):(!n[s]||n[s][1].type!=="data")&&(s!==o+2&&(n[o][1].end=n[s-1][1].end,n.splice(o+2,s-o-2),s=o+2),o=void 0);return e?e(n,r):n}}function TBe(e,t){let n=0;for(;++n<=e.length;)if((n===e.length||e[n][1].type==="lineEnding")&&e[n-1][1].type==="data"){const r=e[n-1][1],s=t.sliceStream(r);let o=s.length,i=-1,a=0,l;for(;o--;){const u=s[o];if(typeof u=="string"){for(i=u.length;u.charCodeAt(i-1)===32;)a++,i--;if(i)break;i=-1}else if(u===-2)l=!0,a++;else if(u!==-1){o++;break}}if(t._contentTypeTextTrailing&&n===e.length&&(a=0),a){const u={type:n===e.length||l||a<2?"lineSuffix":"hardBreakTrailing",start:{_bufferIndex:o?i:r.start._bufferIndex+i,_index:r.start._index+o,line:r.end.line,column:r.end.column-a,offset:r.end.offset-a},end:{...r.end}};r.end={...u.start},r.start.offset===r.end.offset?Object.assign(r,u):(e.splice(n,0,["enter",u,t],["exit",u,t]),n+=2)}n++}return e}const RBe={42:Ws,43:Ws,45:Ws,48:Ws,49:Ws,50:Ws,51:Ws,52:Ws,53:Ws,54:Ws,55:Ws,56:Ws,57:Ws,62:kQ},IBe={91:F7e},ABe={[-2]:m2,[-1]:m2,32:m2},PBe={35:H7e,42:bv,45:[sL,bv],60:Y7e,61:sL,95:bv,96:nL,126:nL},OBe={38:_Q,92:EQ},FBe={[-5]:p2,[-4]:p2,[-3]:p2,33:dBe,38:_Q,42:j_,60:[h7e,eBe],91:hBe,92:[B7e,EQ],93:KI,95:j_,96:k7e},$Be={null:[j_,_Be]},LBe={null:[42,95]},zBe={null:[]},BBe=Object.freeze(Object.defineProperty({__proto__:null,attentionMarkers:LBe,contentInitial:IBe,disable:zBe,document:RBe,flow:PBe,flowInitial:ABe,insideSpan:$Be,string:OBe,text:FBe},Symbol.toStringTag,{value:"Module"}));function VBe(e,t,n){let r={_bufferIndex:-1,_index:0,line:n&&n.line||1,column:n&&n.column||1,offset:n&&n.offset||0};const s={},o=[];let i=[],a=[];const l={attempt:j(N),check:j(S),consume:y,enter:v,exit:w,interrupt:j(S,{interrupt:!0})},u={code:null,containerState:{},defineSkip:g,events:[],now:p,parser:e,previous:null,sliceSerialize:h,sliceStream:m,write:f};let d=t.tokenize.call(u,l);return t.resolveAll&&o.push(t),u;function f(M){return i=Ho(i,M),b(),i[i.length-1]!==null?[]:(E(t,0),u.events=yC(o,u.events,u),u.events)}function h(M,D){return UBe(m(M),D)}function m(M){return HBe(i,M)}function p(){const{_bufferIndex:M,_index:D,line:R,column:P,offset:I}=r;return{_bufferIndex:M,_index:D,line:R,column:P,offset:I}}function g(M){s[M.line]=M.column,k()}function b(){let M;for(;r._index<i.length;){const D=i[r._index];if(typeof D=="string")for(M=r._index,r._bufferIndex<0&&(r._bufferIndex=0);r._index===M&&r._bufferIndex<D.length;)x(D.charCodeAt(r._bufferIndex));else x(D)}}function x(M){d=d(M)}function y(M){it(M)?(r.line++,r.column=1,r.offset+=M===-3?2:1,k()):M!==-1&&(r.column++,r.offset++),r._bufferIndex<0?r._index++:(r._bufferIndex++,r._bufferIndex===i[r._index].length&&(r._bufferIndex=-1,r._index++)),u.previous=M}function v(M,D){const R=D||{};return R.type=M,R.start=p(),u.events.push(["enter",R,u]),a.push(R),R}function w(M){const D=a.pop();return D.end=p(),u.events.push(["exit",D,u]),D}function N(M,D){E(M,D.from)}function S(M,D){D.restore()}function j(M,D){return R;function R(P,I,L){let F,H,$,A;return Array.isArray(P)?z(P):"tokenize"in P?z([P]):q(P);function q(Y){return U;function U(V){const G=V!==null&&Y[V],K=V!==null&&Y.null,J=[...Array.isArray(G)?G:G?[G]:[],...Array.isArray(K)?K:K?[K]:[]];return z(J)(V)}}function z(Y){return F=Y,H=0,Y.length===0?L:O(Y[H])}function O(Y){return U;function U(V){return A=_(),$=Y,Y.partial||(u.currentConstruct=Y),Y.name&&u.parser.constructs.disable.null.includes(Y.name)?B():Y.tokenize.call(D?Object.assign(Object.create(u),D):u,l,W,B)(V)}}function W(Y){return M($,A),I}function B(Y){return A.restore(),++H<F.length?O(F[H]):L}}}function E(M,D){M.resolveAll&&!o.includes(M)&&o.push(M),M.resolve&&Eo(u.events,D,u.events.length-D,M.resolve(u.events.slice(D),u)),M.resolveTo&&(u.events=M.resolveTo(u.events,u))}function _(){const M=p(),D=u.previous,R=u.currentConstruct,P=u.events.length,I=Array.from(a);return{from:P,restore:L};function L(){r=M,u.previous=D,u.currentConstruct=R,u.events.length=P,a=I,k()}}function k(){r.line in s&&r.column<2&&(r.column=s[r.line],r.offset+=s[r.line]-1)}}function HBe(e,t){const n=t.start._index,r=t.start._bufferIndex,s=t.end._index,o=t.end._bufferIndex;let i;if(n===s)i=[e[n].slice(r,o)];else{if(i=e.slice(n,s),r>-1){const a=i[0];typeof a=="string"?i[0]=a.slice(r):i.shift()}o>0&&i.push(e[s].slice(0,o))}return i}function UBe(e,t){let n=-1;const r=[];let s;for(;++n<e.length;){const o=e[n];let i;if(typeof o=="string")i=o;else switch(o){case-5:{i="\r";break}case-4:{i=`
1014
1014
  `;break}case-3:{i=`\r
1015
1015
  `;break}case-2:{i=t?" ":" ";break}case-1:{if(!t&&s)continue;i=" ";break}default:i=String.fromCharCode(o)}s=o===-2,r.push(i)}return r.join("")}function WBe(e){const r={constructs:NQ([BBe,...(e||{}).extensions||[]]),content:s(i7e),defined:[],document:s(l7e),flow:s(kBe),lazy:{},string:s(DBe),text:s(MBe)};return r;function s(o){return i;function i(a){return VBe(r,o,a)}}}function qBe(e){for(;!DQ(e););return e}const oL=/[\0\t\n\r]/g;function YBe(){let e=1,t="",n=!0,r;return s;function s(o,i,a){const l=[];let u,d,f,h,m;for(o=t+(typeof o=="string"?o.toString():new TextDecoder(i||void 0).decode(o)),f=0,t="",n&&(o.charCodeAt(0)===65279&&f++,n=void 0);f<o.length;){if(oL.lastIndex=f,u=oL.exec(o),h=u&&u.index!==void 0?u.index:o.length,m=o.charCodeAt(h),!u){t=o.slice(f);break}if(m===10&&f===h&&r)l.push(-3),r=void 0;else switch(r&&(l.push(-5),r=void 0),f<h&&(l.push(o.slice(f,h)),e+=h-f),m){case 0:{l.push(65533),e++;break}case 9:{for(d=Math.ceil(e/4)*4,l.push(-2);e++<d;)l.push(-1);break}case 10:{l.push(-4),e=1;break}default:r=!0,e=1}f=h+1}return a&&(r&&l.push(-5),t&&l.push(t),l.push(null)),l}}const GBe=/\\([!-/:-@[-`{-~])|&(#(?:\d{1,7}|x[\da-f]{1,6})|[\da-z]{1,31});/gi;function KBe(e){return e.replace(GBe,ZBe)}function ZBe(e,t,n){if(t)return t;if(n.charCodeAt(0)===35){const s=n.charCodeAt(1),o=s===120||s===88;return jQ(n.slice(o?2:1),o?16:10)}return GI(n)||e}const PQ={}.hasOwnProperty;function XBe(e,t,n){return typeof t!="string"&&(n=t,t=void 0),QBe(n)(qBe(WBe(n).document().write(YBe()(e,t,!0))))}function QBe(e){const t={transforms:[],canContainEols:["emphasis","fragment","heading","paragraph","strong"],enter:{autolink:o(ne),autolinkProtocol:_,autolinkEmail:_,atxHeading:o(fe),blockQuote:o(K),characterEscape:_,characterReference:_,codeFenced:o(J),codeFencedFenceInfo:i,codeFencedFenceMeta:i,codeIndented:o(J,i),codeText:o(Q,i),codeTextData:_,data:_,codeFlowValue:_,definition:o(re),definitionDestinationString:i,definitionLabelString:i,definitionTitleString:i,emphasis:o(de),hardBreakEscape:o(ue),hardBreakTrailing:o(ue),htmlFlow:o(je,i),htmlFlowData:_,htmlText:o(je,i),htmlTextData:_,image:o(me),label:i,link:o(ne),listItem:o(pe),listItemValue:h,listOrdered:o(oe,f),listUnordered:o(oe),paragraph:o(De),reference:O,referenceString:i,resourceDestinationString:i,resourceTitleString:i,setextHeading:o(fe),strong:o(ae),thematicBreak:o(Ue)},exit:{atxHeading:l(),atxHeadingSequence:N,autolink:l(),autolinkEmail:G,autolinkProtocol:V,blockQuote:l(),characterEscapeValue:k,characterReferenceMarkerHexadecimal:B,characterReferenceMarkerNumeric:B,characterReferenceValue:Y,characterReference:U,codeFenced:l(b),codeFencedFence:g,codeFencedFenceInfo:m,codeFencedFenceMeta:p,codeFlowValue:k,codeIndented:l(x),codeText:l(I),codeTextData:k,data:k,definition:l(),definitionDestinationString:w,definitionLabelString:y,definitionTitleString:v,emphasis:l(),hardBreakEscape:l(D),hardBreakTrailing:l(D),htmlFlow:l(R),htmlFlowData:k,htmlText:l(P),htmlTextData:k,image:l(F),label:$,labelText:H,lineEnding:M,link:l(L),listItem:l(),listOrdered:l(),listUnordered:l(),paragraph:l(),referenceString:W,resourceDestinationString:A,resourceTitleString:q,resource:z,setextHeading:l(E),setextHeadingLineSequence:j,setextHeadingText:S,strong:l(),thematicBreak:l()}};OQ(t,(e||{}).mdastExtensions||[]);const n={};return r;function r(ie){let xe={type:"root",children:[]};const $e={stack:[xe],tokenStack:[],config:t,enter:a,exit:u,buffer:i,resume:d,data:n},he=[];let Ee=-1;for(;++Ee<ie.length;)if(ie[Ee][1].type==="listOrdered"||ie[Ee][1].type==="listUnordered")if(ie[Ee][0]==="enter")he.push(Ee);else{const Ve=he.pop();Ee=s(ie,Ve,Ee)}for(Ee=-1;++Ee<ie.length;){const Ve=t[ie[Ee][0]];PQ.call(Ve,ie[Ee][1].type)&&Ve[ie[Ee][1].type].call(Object.assign({sliceSerialize:ie[Ee][2].sliceSerialize},$e),ie[Ee][1])}if($e.tokenStack.length>0){const Ve=$e.tokenStack[$e.tokenStack.length-1];(Ve[1]||iL).call($e,void 0,Ve[0])}for(xe.position={start:Jl(ie.length>0?ie[0][1].start:{line:1,column:1,offset:0}),end:Jl(ie.length>0?ie[ie.length-2][1].end:{line:1,column:1,offset:0})},Ee=-1;++Ee<t.transforms.length;)xe=t.transforms[Ee](xe)||xe;return xe}function s(ie,xe,$e){let he=xe-1,Ee=-1,Ve=!1,qe,Ae,xt,Ce;for(;++he<=$e;){const mt=ie[he];switch(mt[1].type){case"listUnordered":case"listOrdered":case"blockQuote":{mt[0]==="enter"?Ee++:Ee--,Ce=void 0;break}case"lineEndingBlank":{mt[0]==="enter"&&(qe&&!Ce&&!Ee&&!xt&&(xt=he),Ce=void 0);break}case"linePrefix":case"listItemValue":case"listItemMarker":case"listItemPrefix":case"listItemPrefixWhitespace":break;default:Ce=void 0}if(!Ee&&mt[0]==="enter"&&mt[1].type==="listItemPrefix"||Ee===-1&&mt[0]==="exit"&&(mt[1].type==="listUnordered"||mt[1].type==="listOrdered")){if(qe){let _t=he;for(Ae=void 0;_t--;){const He=ie[_t];if(He[1].type==="lineEnding"||He[1].type==="lineEndingBlank"){if(He[0]==="exit")continue;Ae&&(ie[Ae][1].type="lineEndingBlank",Ve=!0),He[1].type="lineEnding",Ae=_t}else if(!(He[1].type==="linePrefix"||He[1].type==="blockQuotePrefix"||He[1].type==="blockQuotePrefixWhitespace"||He[1].type==="blockQuoteMarker"||He[1].type==="listItemIndent"))break}xt&&(!Ae||xt<Ae)&&(qe._spread=!0),qe.end=Object.assign({},Ae?ie[Ae][1].start:mt[1].end),ie.splice(Ae||he,0,["exit",qe,mt[2]]),he++,$e++}if(mt[1].type==="listItemPrefix"){const _t={type:"listItem",_spread:!1,start:Object.assign({},mt[1].start),end:void 0};qe=_t,ie.splice(he,0,["enter",_t,mt[2]]),he++,$e++,xt=void 0,Ce=!0}}}return ie[xe][1]._spread=Ve,$e}function o(ie,xe){return $e;function $e(he){a.call(this,ie(he),he),xe&&xe.call(this,he)}}function i(){this.stack.push({type:"fragment",children:[]})}function a(ie,xe,$e){this.stack[this.stack.length-1].children.push(ie),this.stack.push(ie),this.tokenStack.push([xe,$e||void 0]),ie.position={start:Jl(xe.start),end:void 0}}function l(ie){return xe;function xe($e){ie&&ie.call(this,$e),u.call(this,$e)}}function u(ie,xe){const $e=this.stack.pop(),he=this.tokenStack.pop();if(he)he[0].type!==ie.type&&(xe?xe.call(this,ie,he[0]):(he[1]||iL).call(this,ie,he[0]));else throw new Error("Cannot close `"+ie.type+"` ("+Ig({start:ie.start,end:ie.end})+"): it’s not open");$e.position.end=Jl(ie.end)}function d(){return YI(this.stack.pop())}function f(){this.data.expectingFirstListItemValue=!0}function h(ie){if(this.data.expectingFirstListItemValue){const xe=this.stack[this.stack.length-2];xe.start=Number.parseInt(this.sliceSerialize(ie),10),this.data.expectingFirstListItemValue=void 0}}function m(){const ie=this.resume(),xe=this.stack[this.stack.length-1];xe.lang=ie}function p(){const ie=this.resume(),xe=this.stack[this.stack.length-1];xe.meta=ie}function g(){this.data.flowCodeInside||(this.buffer(),this.data.flowCodeInside=!0)}function b(){const ie=this.resume(),xe=this.stack[this.stack.length-1];xe.value=ie.replace(/^(\r?\n|\r)|(\r?\n|\r)$/g,""),this.data.flowCodeInside=void 0}function x(){const ie=this.resume(),xe=this.stack[this.stack.length-1];xe.value=ie.replace(/(\r?\n|\r)$/g,"")}function y(ie){const xe=this.resume(),$e=this.stack[this.stack.length-1];$e.label=xe,$e.identifier=Ti(this.sliceSerialize(ie)).toLowerCase()}function v(){const ie=this.resume(),xe=this.stack[this.stack.length-1];xe.title=ie}function w(){const ie=this.resume(),xe=this.stack[this.stack.length-1];xe.url=ie}function N(ie){const xe=this.stack[this.stack.length-1];if(!xe.depth){const $e=this.sliceSerialize(ie).length;xe.depth=$e}}function S(){this.data.setextHeadingSlurpLineEnding=!0}function j(ie){const xe=this.stack[this.stack.length-1];xe.depth=this.sliceSerialize(ie).codePointAt(0)===61?1:2}function E(){this.data.setextHeadingSlurpLineEnding=void 0}function _(ie){const $e=this.stack[this.stack.length-1].children;let he=$e[$e.length-1];(!he||he.type!=="text")&&(he=Te(),he.position={start:Jl(ie.start),end:void 0},$e.push(he)),this.stack.push(he)}function k(ie){const xe=this.stack.pop();xe.value+=this.sliceSerialize(ie),xe.position.end=Jl(ie.end)}function M(ie){const xe=this.stack[this.stack.length-1];if(this.data.atHardBreak){const $e=xe.children[xe.children.length-1];$e.position.end=Jl(ie.end),this.data.atHardBreak=void 0;return}!this.data.setextHeadingSlurpLineEnding&&t.canContainEols.includes(xe.type)&&(_.call(this,ie),k.call(this,ie))}function D(){this.data.atHardBreak=!0}function R(){const ie=this.resume(),xe=this.stack[this.stack.length-1];xe.value=ie}function P(){const ie=this.resume(),xe=this.stack[this.stack.length-1];xe.value=ie}function I(){const ie=this.resume(),xe=this.stack[this.stack.length-1];xe.value=ie}function L(){const ie=this.stack[this.stack.length-1];if(this.data.inReference){const xe=this.data.referenceType||"shortcut";ie.type+="Reference",ie.referenceType=xe,delete ie.url,delete ie.title}else delete ie.identifier,delete ie.label;this.data.referenceType=void 0}function F(){const ie=this.stack[this.stack.length-1];if(this.data.inReference){const xe=this.data.referenceType||"shortcut";ie.type+="Reference",ie.referenceType=xe,delete ie.url,delete ie.title}else delete ie.identifier,delete ie.label;this.data.referenceType=void 0}function H(ie){const xe=this.sliceSerialize(ie),$e=this.stack[this.stack.length-2];$e.label=KBe(xe),$e.identifier=Ti(xe).toLowerCase()}function $(){const ie=this.stack[this.stack.length-1],xe=this.resume(),$e=this.stack[this.stack.length-1];if(this.data.inReference=!0,$e.type==="link"){const he=ie.children;$e.children=he}else $e.alt=xe}function A(){const ie=this.resume(),xe=this.stack[this.stack.length-1];xe.url=ie}function q(){const ie=this.resume(),xe=this.stack[this.stack.length-1];xe.title=ie}function z(){this.data.inReference=void 0}function O(){this.data.referenceType="collapsed"}function W(ie){const xe=this.resume(),$e=this.stack[this.stack.length-1];$e.label=xe,$e.identifier=Ti(this.sliceSerialize(ie)).toLowerCase(),this.data.referenceType="full"}function B(ie){this.data.characterReferenceType=ie.type}function Y(ie){const xe=this.sliceSerialize(ie),$e=this.data.characterReferenceType;let he;$e?(he=jQ(xe,$e==="characterReferenceMarkerNumeric"?10:16),this.data.characterReferenceType=void 0):he=GI(xe);const Ee=this.stack[this.stack.length-1];Ee.value+=he}function U(ie){const xe=this.stack.pop();xe.position.end=Jl(ie.end)}function V(ie){k.call(this,ie);const xe=this.stack[this.stack.length-1];xe.url=this.sliceSerialize(ie)}function G(ie){k.call(this,ie);const xe=this.stack[this.stack.length-1];xe.url="mailto:"+this.sliceSerialize(ie)}function K(){return{type:"blockquote",children:[]}}function J(){return{type:"code",lang:null,meta:null,value:""}}function Q(){return{type:"inlineCode",value:""}}function re(){return{type:"definition",identifier:"",label:null,title:null,url:""}}function de(){return{type:"emphasis",children:[]}}function fe(){return{type:"heading",depth:0,children:[]}}function ue(){return{type:"break"}}function je(){return{type:"html",value:""}}function me(){return{type:"image",title:null,url:"",alt:null}}function ne(){return{type:"link",title:null,url:"",children:[]}}function oe(ie){return{type:"list",ordered:ie.type==="listOrdered",start:null,spread:ie._spread,children:[]}}function pe(ie){return{type:"listItem",spread:ie._spread,checked:null,children:[]}}function De(){return{type:"paragraph",children:[]}}function ae(){return{type:"strong",children:[]}}function Te(){return{type:"text",value:""}}function Ue(){return{type:"thematicBreak"}}}function Jl(e){return{line:e.line,column:e.column,offset:e.offset}}function OQ(e,t){let n=-1;for(;++n<t.length;){const r=t[n];Array.isArray(r)?OQ(e,r):JBe(e,r)}}function JBe(e,t){let n;for(n in t)if(PQ.call(t,n))switch(n){case"canContainEols":{const r=t[n];r&&e[n].push(...r);break}case"transforms":{const r=t[n];r&&e[n].push(...r);break}case"enter":case"exit":{const r=t[n];r&&Object.assign(e[n],r);break}}}function iL(e,t){throw e?new Error("Cannot close `"+e.type+"` ("+Ig({start:e.start,end:e.end})+"): a different token (`"+t.type+"`, "+Ig({start:t.start,end:t.end})+") is open"):new Error("Cannot close document, a token (`"+t.type+"`, "+Ig({start:t.start,end:t.end})+") is still open")}function eVe(e){const t=this;t.parser=n;function n(r){return XBe(r,{...t.data("settings"),...e,extensions:t.data("micromarkExtensions")||[],mdastExtensions:t.data("fromMarkdownExtensions")||[]})}}function tVe(e,t){const n={type:"element",tagName:"blockquote",properties:{},children:e.wrap(e.all(t),!0)};return e.patch(t,n),e.applyData(t,n)}function nVe(e,t){const n={type:"element",tagName:"br",properties:{},children:[]};return e.patch(t,n),[e.applyData(t,n),{type:"text",value:`
@@ -1095,7 +1095,7 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
1095
1095
 
1096
1096
  `)},flush(e){e.enqueue(`data: [DONE]
1097
1097
 
1098
- `)}})}});var IQe=kXe(()=>Cee(ai([Kn({type:Tt("text-start"),id:st(),providerMetadata:ur.optional()}),Kn({type:Tt("text-delta"),id:st(),delta:st(),providerMetadata:ur.optional()}),Kn({type:Tt("text-end"),id:st(),providerMetadata:ur.optional()}),Kn({type:Tt("error"),errorText:st()}),Kn({type:Tt("tool-input-start"),toolCallId:st(),toolName:st(),providerExecuted:qs().optional(),dynamic:qs().optional()}),Kn({type:Tt("tool-input-delta"),toolCallId:st(),inputTextDelta:st()}),Kn({type:Tt("tool-input-available"),toolCallId:st(),toolName:st(),input:sa(),providerExecuted:qs().optional(),providerMetadata:ur.optional(),dynamic:qs().optional()}),Kn({type:Tt("tool-input-error"),toolCallId:st(),toolName:st(),input:sa(),providerExecuted:qs().optional(),providerMetadata:ur.optional(),dynamic:qs().optional(),errorText:st()}),Kn({type:Tt("tool-output-available"),toolCallId:st(),output:sa(),providerExecuted:qs().optional(),dynamic:qs().optional(),preliminary:qs().optional()}),Kn({type:Tt("tool-output-error"),toolCallId:st(),errorText:st(),providerExecuted:qs().optional(),dynamic:qs().optional()}),Kn({type:Tt("reasoning-start"),id:st(),providerMetadata:ur.optional()}),Kn({type:Tt("reasoning-delta"),id:st(),delta:st(),providerMetadata:ur.optional()}),Kn({type:Tt("reasoning-end"),id:st(),providerMetadata:ur.optional()}),Kn({type:Tt("source-url"),sourceId:st(),url:st(),title:st().optional(),providerMetadata:ur.optional()}),Kn({type:Tt("source-document"),sourceId:st(),mediaType:st(),title:st(),filename:st().optional(),providerMetadata:ur.optional()}),Kn({type:Tt("file"),url:st(),mediaType:st(),providerMetadata:ur.optional()}),Kn({type:xee(e=>typeof e=="string"&&e.startsWith("data-"),{message:'Type must start with "data-"'}),id:st().optional(),data:sa(),transient:qs().optional()}),Kn({type:Tt("start-step")}),Kn({type:Tt("finish-step")}),Kn({type:Tt("start"),messageId:st().optional(),messageMetadata:sa().optional()}),Kn({type:Tt("finish"),finishReason:pee(["stop","length","content-filter","tool-calls","error","other","unknown"]).optional(),messageMetadata:sa().optional()}),Kn({type:Tt("abort")}),Kn({type:Tt("message-metadata"),messageMetadata:sa()})])));function AQe(e){return e.type.startsWith("data-")}function Tee(e,t){if(e===void 0&&t===void 0)return;if(e===void 0)return t;if(t===void 0)return e;const n={...e};for(const r in t)if(Object.prototype.hasOwnProperty.call(t,r)){const s=t[r];if(s===void 0)continue;const o=r in e?e[r]:void 0,i=s!==null&&typeof s=="object"&&!Array.isArray(s)&&!(s instanceof Date)&&!(s instanceof RegExp),a=o!=null&&typeof o=="object"&&!Array.isArray(o)&&!(o instanceof Date)&&!(o instanceof RegExp);i&&a?n[r]=Tee(o,s):n[r]=s}return n}function PQe(e){const t=["ROOT"];let n=-1,r=null;function s(l,u,d){switch(l){case'"':{n=u,t.pop(),t.push(d),t.push("INSIDE_STRING");break}case"f":case"t":case"n":{n=u,r=u,t.pop(),t.push(d),t.push("INSIDE_LITERAL");break}case"-":{t.pop(),t.push(d),t.push("INSIDE_NUMBER");break}case"0":case"1":case"2":case"3":case"4":case"5":case"6":case"7":case"8":case"9":{n=u,t.pop(),t.push(d),t.push("INSIDE_NUMBER");break}case"{":{n=u,t.pop(),t.push(d),t.push("INSIDE_OBJECT_START");break}case"[":{n=u,t.pop(),t.push(d),t.push("INSIDE_ARRAY_START");break}}}function o(l,u){switch(l){case",":{t.pop(),t.push("INSIDE_OBJECT_AFTER_COMMA");break}case"}":{n=u,t.pop();break}}}function i(l,u){switch(l){case",":{t.pop(),t.push("INSIDE_ARRAY_AFTER_COMMA");break}case"]":{n=u,t.pop();break}}}for(let l=0;l<e.length;l++){const u=e[l];switch(t[t.length-1]){case"ROOT":s(u,l,"FINISH");break;case"INSIDE_OBJECT_START":{switch(u){case'"':{t.pop(),t.push("INSIDE_OBJECT_KEY");break}case"}":{n=l,t.pop();break}}break}case"INSIDE_OBJECT_AFTER_COMMA":{switch(u){case'"':{t.pop(),t.push("INSIDE_OBJECT_KEY");break}}break}case"INSIDE_OBJECT_KEY":{switch(u){case'"':{t.pop(),t.push("INSIDE_OBJECT_AFTER_KEY");break}}break}case"INSIDE_OBJECT_AFTER_KEY":{switch(u){case":":{t.pop(),t.push("INSIDE_OBJECT_BEFORE_VALUE");break}}break}case"INSIDE_OBJECT_BEFORE_VALUE":{s(u,l,"INSIDE_OBJECT_AFTER_VALUE");break}case"INSIDE_OBJECT_AFTER_VALUE":{o(u,l);break}case"INSIDE_STRING":{switch(u){case'"':{t.pop(),n=l;break}case"\\":{t.push("INSIDE_STRING_ESCAPE");break}default:n=l}break}case"INSIDE_ARRAY_START":{switch(u){case"]":{n=l,t.pop();break}default:{n=l,s(u,l,"INSIDE_ARRAY_AFTER_VALUE");break}}break}case"INSIDE_ARRAY_AFTER_VALUE":{switch(u){case",":{t.pop(),t.push("INSIDE_ARRAY_AFTER_COMMA");break}case"]":{n=l,t.pop();break}default:{n=l;break}}break}case"INSIDE_ARRAY_AFTER_COMMA":{s(u,l,"INSIDE_ARRAY_AFTER_VALUE");break}case"INSIDE_STRING_ESCAPE":{t.pop(),n=l;break}case"INSIDE_NUMBER":{switch(u){case"0":case"1":case"2":case"3":case"4":case"5":case"6":case"7":case"8":case"9":{n=l;break}case"e":case"E":case"-":case".":break;case",":{t.pop(),t[t.length-1]==="INSIDE_ARRAY_AFTER_VALUE"&&i(u,l),t[t.length-1]==="INSIDE_OBJECT_AFTER_VALUE"&&o(u,l);break}case"}":{t.pop(),t[t.length-1]==="INSIDE_OBJECT_AFTER_VALUE"&&o(u,l);break}case"]":{t.pop(),t[t.length-1]==="INSIDE_ARRAY_AFTER_VALUE"&&i(u,l);break}default:{t.pop();break}}break}case"INSIDE_LITERAL":{const f=e.substring(r,l+1);!"false".startsWith(f)&&!"true".startsWith(f)&&!"null".startsWith(f)?(t.pop(),t[t.length-1]==="INSIDE_OBJECT_AFTER_VALUE"?o(u,l):t[t.length-1]==="INSIDE_ARRAY_AFTER_VALUE"&&i(u,l)):n=l;break}}}let a=e.slice(0,n+1);for(let l=t.length-1;l>=0;l--)switch(t[l]){case"INSIDE_STRING":{a+='"';break}case"INSIDE_OBJECT_KEY":case"INSIDE_OBJECT_AFTER_KEY":case"INSIDE_OBJECT_AFTER_COMMA":case"INSIDE_OBJECT_START":case"INSIDE_OBJECT_BEFORE_VALUE":case"INSIDE_OBJECT_AFTER_VALUE":{a+="}";break}case"INSIDE_ARRAY_START":case"INSIDE_ARRAY_AFTER_COMMA":case"INSIDE_ARRAY_AFTER_VALUE":{a+="]";break}case"INSIDE_LITERAL":{const d=e.substring(r,e.length);"true".startsWith(d)?a+="true".slice(d.length):"false".startsWith(d)?a+="false".slice(d.length):"null".startsWith(d)&&(a+="null".slice(d.length))}}return a}async function Ree(e){if(e===void 0)return{value:void 0,state:"undefined-input"};let t=await a1({text:e});return t.success?{value:t.value,state:"successful-parse"}:(t=await a1({text:PQe(e)}),t.success?{value:t.value,state:"repaired-parse"}:{value:void 0,state:"failed-parse"})}function yv(e){return e.type.startsWith("tool-")}function OQe(e){return e.type==="dynamic-tool"}function L_(e){return yv(e)||OQe(e)}function y6(e){return e.type.split("-").slice(1).join("-")}function FQe({lastMessage:e,messageId:t}){return{message:(e==null?void 0:e.role)==="assistant"?e:{id:t,metadata:void 0,role:"assistant",parts:[]},activeTextParts:{},activeReasoningParts:{},partialToolCalls:{}}}function $Qe({stream:e,messageMetadataSchema:t,dataPartSchemas:n,runUpdateMessageJob:r,onError:s,onToolCall:o,onData:i}){return e.pipeThrough(new TransformStream({async transform(a,l){await r(async({state:u,write:d})=>{var f,h,m,p;function g(w){const S=u.message.parts.filter(yv).find(j=>j.toolCallId===w);if(S==null)throw new Error("tool-output-error must be preceded by a tool-input-available");return S}function b(w){const S=u.message.parts.filter(j=>j.type==="dynamic-tool").find(j=>j.toolCallId===w);if(S==null)throw new Error("tool-output-error must be preceded by a tool-input-available");return S}function x(w){var N;const S=u.message.parts.find(_=>yv(_)&&_.toolCallId===w.toolCallId),j=w,E=S;S!=null?(S.state=w.state,E.input=j.input,E.output=j.output,E.errorText=j.errorText,E.rawInput=j.rawInput,E.preliminary=j.preliminary,E.providerExecuted=(N=j.providerExecuted)!=null?N:S.providerExecuted,j.providerMetadata!=null&&S.state==="input-available"&&(S.callProviderMetadata=j.providerMetadata)):u.message.parts.push({type:`tool-${w.toolName}`,toolCallId:w.toolCallId,state:w.state,input:j.input,output:j.output,rawInput:j.rawInput,errorText:j.errorText,providerExecuted:j.providerExecuted,preliminary:j.preliminary,...j.providerMetadata!=null?{callProviderMetadata:j.providerMetadata}:{}})}function y(w){var N,S;const j=u.message.parts.find(k=>k.type==="dynamic-tool"&&k.toolCallId===w.toolCallId),E=w,_=j;j!=null?(j.state=w.state,_.toolName=w.toolName,_.input=E.input,_.output=E.output,_.errorText=E.errorText,_.rawInput=(N=E.rawInput)!=null?N:_.rawInput,_.preliminary=E.preliminary,_.providerExecuted=(S=E.providerExecuted)!=null?S:j.providerExecuted,E.providerMetadata!=null&&j.state==="input-available"&&(j.callProviderMetadata=E.providerMetadata)):u.message.parts.push({type:"dynamic-tool",toolName:w.toolName,toolCallId:w.toolCallId,state:w.state,input:E.input,output:E.output,errorText:E.errorText,preliminary:E.preliminary,providerExecuted:E.providerExecuted,...E.providerMetadata!=null?{callProviderMetadata:E.providerMetadata}:{}})}async function v(w){if(w!=null){const N=u.message.metadata!=null?Tee(u.message.metadata,w):w;t!=null&&await m6({value:N,schema:t}),u.message.metadata=N}}switch(a.type){case"text-start":{const w={type:"text",text:"",providerMetadata:a.providerMetadata,state:"streaming"};u.activeTextParts[a.id]=w,u.message.parts.push(w),d();break}case"text-delta":{const w=u.activeTextParts[a.id];w.text+=a.delta,w.providerMetadata=(f=a.providerMetadata)!=null?f:w.providerMetadata,d();break}case"text-end":{const w=u.activeTextParts[a.id];w.state="done",w.providerMetadata=(h=a.providerMetadata)!=null?h:w.providerMetadata,delete u.activeTextParts[a.id],d();break}case"reasoning-start":{const w={type:"reasoning",text:"",providerMetadata:a.providerMetadata,state:"streaming"};u.activeReasoningParts[a.id]=w,u.message.parts.push(w),d();break}case"reasoning-delta":{const w=u.activeReasoningParts[a.id];w.text+=a.delta,w.providerMetadata=(m=a.providerMetadata)!=null?m:w.providerMetadata,d();break}case"reasoning-end":{const w=u.activeReasoningParts[a.id];w.providerMetadata=(p=a.providerMetadata)!=null?p:w.providerMetadata,w.state="done",delete u.activeReasoningParts[a.id],d();break}case"file":{u.message.parts.push({type:"file",mediaType:a.mediaType,url:a.url}),d();break}case"source-url":{u.message.parts.push({type:"source-url",sourceId:a.sourceId,url:a.url,title:a.title,providerMetadata:a.providerMetadata}),d();break}case"source-document":{u.message.parts.push({type:"source-document",sourceId:a.sourceId,mediaType:a.mediaType,title:a.title,filename:a.filename,providerMetadata:a.providerMetadata}),d();break}case"tool-input-start":{const w=u.message.parts.filter(yv);u.partialToolCalls[a.toolCallId]={text:"",toolName:a.toolName,index:w.length,dynamic:a.dynamic},a.dynamic?y({toolCallId:a.toolCallId,toolName:a.toolName,state:"input-streaming",input:void 0,providerExecuted:a.providerExecuted}):x({toolCallId:a.toolCallId,toolName:a.toolName,state:"input-streaming",input:void 0,providerExecuted:a.providerExecuted}),d();break}case"tool-input-delta":{const w=u.partialToolCalls[a.toolCallId];w.text+=a.inputTextDelta;const{value:N}=await Ree(w.text);w.dynamic?y({toolCallId:a.toolCallId,toolName:w.toolName,state:"input-streaming",input:N}):x({toolCallId:a.toolCallId,toolName:w.toolName,state:"input-streaming",input:N}),d();break}case"tool-input-available":{a.dynamic?y({toolCallId:a.toolCallId,toolName:a.toolName,state:"input-available",input:a.input,providerExecuted:a.providerExecuted,providerMetadata:a.providerMetadata}):x({toolCallId:a.toolCallId,toolName:a.toolName,state:"input-available",input:a.input,providerExecuted:a.providerExecuted,providerMetadata:a.providerMetadata}),d(),o&&!a.providerExecuted&&await o({toolCall:a});break}case"tool-input-error":{a.dynamic?y({toolCallId:a.toolCallId,toolName:a.toolName,state:"output-error",input:a.input,errorText:a.errorText,providerExecuted:a.providerExecuted,providerMetadata:a.providerMetadata}):x({toolCallId:a.toolCallId,toolName:a.toolName,state:"output-error",input:void 0,rawInput:a.input,errorText:a.errorText,providerExecuted:a.providerExecuted,providerMetadata:a.providerMetadata}),d();break}case"tool-output-available":{if(a.dynamic){const w=b(a.toolCallId);y({toolCallId:a.toolCallId,toolName:w.toolName,state:"output-available",input:w.input,output:a.output,preliminary:a.preliminary})}else{const w=g(a.toolCallId);x({toolCallId:a.toolCallId,toolName:y6(w),state:"output-available",input:w.input,output:a.output,providerExecuted:a.providerExecuted,preliminary:a.preliminary})}d();break}case"tool-output-error":{if(a.dynamic){const w=b(a.toolCallId);y({toolCallId:a.toolCallId,toolName:w.toolName,state:"output-error",input:w.input,errorText:a.errorText,providerExecuted:a.providerExecuted})}else{const w=g(a.toolCallId);x({toolCallId:a.toolCallId,toolName:y6(w),state:"output-error",input:w.input,rawInput:w.rawInput,errorText:a.errorText,providerExecuted:a.providerExecuted})}d();break}case"start-step":{u.message.parts.push({type:"step-start"});break}case"finish-step":{u.activeTextParts={},u.activeReasoningParts={};break}case"start":{a.messageId!=null&&(u.message.id=a.messageId),await v(a.messageMetadata),(a.messageId!=null||a.messageMetadata!=null)&&d();break}case"finish":{a.finishReason!=null&&(u.finishReason=a.finishReason),await v(a.messageMetadata),a.messageMetadata!=null&&d();break}case"message-metadata":{await v(a.messageMetadata),a.messageMetadata!=null&&d();break}case"error":{s==null||s(new Error(a.errorText));break}default:if(AQe(a)){(n==null?void 0:n[a.type])!=null&&await m6({value:a.data,schema:n[a.type]});const w=a;if(w.transient){i==null||i(w);break}const N=w.id!=null?u.message.parts.find(S=>w.type===S.type&&w.id===S.id):void 0;N!=null?N.data=w.data:u.message.parts.push(w),i==null||i(w),d()}}l.enqueue(a)})}}))}async function LQe({stream:e,onError:t}){const n=e.getReader();try{for(;;){const{done:r}=await n.read();if(r)break}}catch(r){t==null||t(r)}finally{n.releaseLock()}}fy({prefix:"aitxt",size:24});fy({prefix:"aiobj",size:24});var zQe=class{constructor(){this.queue=[],this.isProcessing=!1}async processQueue(){if(!this.isProcessing){for(this.isProcessing=!0;this.queue.length>0;)await this.queue[0](),this.queue.shift();this.isProcessing=!1}}async run(e){return new Promise((t,n)=>{this.queue.push(async()=>{try{await e(),t()}catch(r){n(r)}}),this.processQueue()})}};fy({prefix:"aiobj",size:24});var BQe={};CQe(BQe,{object:()=>HQe,text:()=>VQe});var VQe=()=>({type:"text",responseFormat:{type:"text"},async parsePartial({text:e}){return{partial:e}},async parseOutput({text:e}){return e}}),HQe=({schema:e})=>{const t=wQe(e);return{type:"object",responseFormat:{type:"json",schema:t.jsonSchema},async parsePartial({text:n}){const r=await Ree(n);switch(r.state){case"failed-parse":case"undefined-input":return;case"repaired-parse":case"successful-parse":return{partial:r.value};default:{const s=r.state;throw new Error(`Unsupported parse state: ${s}`)}}},async parseOutput({text:n},r){const s=await a1({text:n});if(!s.success)throw new b6({message:"No object generated: could not parse the response.",cause:s.error,text:n,response:r.response,usage:r.usage,finishReason:r.finishReason});const o=await pA({value:s.value,schema:t});if(!o.success)throw new b6({message:"No object generated: response did not match schema.",cause:o.error,text:n,response:r.response,usage:r.usage,finishReason:r.finishReason});return o.value}}};async function UQe(e){if(e==null)return[];if(!globalThis.FileList||!(e instanceof globalThis.FileList))throw new Error("FileList is not supported in the current environment");return Promise.all(Array.from(e).map(async t=>{const{name:n,type:r}=t,s=await new Promise((o,i)=>{const a=new FileReader;a.onload=l=>{var u;o((u=l.target)==null?void 0:u.result)},a.onerror=l=>i(l),a.readAsDataURL(t)});return{type:"file",mediaType:r,filename:n,url:s}}))}var WQe=class{constructor({api:e="/api/chat",credentials:t,headers:n,body:r,fetch:s,prepareSendMessagesRequest:o,prepareReconnectToStreamRequest:i}){this.api=e,this.credentials=t,this.headers=n,this.body=r,this.fetch=s,this.prepareSendMessagesRequest=o,this.prepareReconnectToStreamRequest=i}async sendMessages({abortSignal:e,...t}){var n,r,s,o,i;const a=await If(this.body),l=await If(this.headers),u=await If(this.credentials),d={...$u(l),...$u(t.headers)},f=await((n=this.prepareSendMessagesRequest)==null?void 0:n.call(this,{api:this.api,id:t.chatId,messages:t.messages,body:{...a,...t.body},headers:d,credentials:u,requestMetadata:t.metadata,trigger:t.trigger,messageId:t.messageId})),h=(r=f==null?void 0:f.api)!=null?r:this.api,m=(f==null?void 0:f.headers)!==void 0?$u(f.headers):d,p=(f==null?void 0:f.body)!==void 0?f.body:{...a,...t.body,id:t.chatId,messages:t.messages,trigger:t.trigger,messageId:t.messageId},g=(s=f==null?void 0:f.credentials)!=null?s:u,x=await((o=this.fetch)!=null?o:globalThis.fetch)(h,{method:"POST",headers:f6({"Content-Type":"application/json",...m},`ai-sdk/${x6}`,d6()),body:JSON.stringify(p),credentials:g,signal:e});if(!x.ok)throw new Error((i=await x.text())!=null?i:"Failed to fetch the chat response.");if(!x.body)throw new Error("The response body is empty.");return this.processResponseStream(x.body)}async reconnectToStream(e){var t,n,r,s,o;const i=await If(this.body),a=await If(this.headers),l=await If(this.credentials),u={...$u(a),...$u(e.headers)},d=await((t=this.prepareReconnectToStreamRequest)==null?void 0:t.call(this,{api:this.api,id:e.chatId,body:{...i,...e.body},headers:u,credentials:l,requestMetadata:e.metadata})),f=(n=d==null?void 0:d.api)!=null?n:`${this.api}/${e.chatId}/stream`,h=(d==null?void 0:d.headers)!==void 0?$u(d.headers):u,m=(r=d==null?void 0:d.credentials)!=null?r:l,g=await((s=this.fetch)!=null?s:globalThis.fetch)(f,{method:"GET",headers:f6(h,`ai-sdk/${x6}`,d6()),credentials:m});if(g.status===204)return null;if(!g.ok)throw new Error((o=await g.text())!=null?o:"Failed to fetch the chat response.");if(!g.body)throw new Error("The response body is empty.");return this.processResponseStream(g.body)}},bA=class extends WQe{constructor(e={}){super(e)}processResponseStream(e){return DXe({stream:e,schema:IQe}).pipeThrough(new TransformStream({async transform(t,n){if(!t.success)throw t.error;n.enqueue(t.value)}}))}},qQe=class{constructor({generateId:e=yXe,id:t=e(),transport:n=new bA,messageMetadataSchema:r,dataPartSchemas:s,state:o,onError:i,onToolCall:a,onFinish:l,onData:u,sendAutomaticallyWhen:d}){this.activeResponse=void 0,this.jobExecutor=new zQe,this.sendMessage=async(f,h)=>{var m,p,g,b;if(f==null){await this.makeRequest({trigger:"submit-message",messageId:(m=this.lastMessage)==null?void 0:m.id,...h});return}let x;if("text"in f||"files"in f?x={parts:[...Array.isArray(f.files)?f.files:await UQe(f.files),..."text"in f&&f.text!=null?[{type:"text",text:f.text}]:[]]}:x=f,f.messageId!=null){const y=this.state.messages.findIndex(v=>v.id===f.messageId);if(y===-1)throw new Error(`message with id ${f.messageId} not found`);if(this.state.messages[y].role!=="user")throw new Error(`message with id ${f.messageId} is not a user message`);this.state.messages=this.state.messages.slice(0,y+1),this.state.replaceMessage(y,{...x,id:f.messageId,role:(p=x.role)!=null?p:"user",metadata:f.metadata})}else this.state.pushMessage({...x,id:(g=x.id)!=null?g:this.generateId(),role:(b=x.role)!=null?b:"user",metadata:f.metadata});await this.makeRequest({trigger:"submit-message",messageId:f.messageId,...h})},this.regenerate=async({messageId:f,...h}={})=>{const m=f==null?this.state.messages.length-1:this.state.messages.findIndex(p=>p.id===f);if(m===-1)throw new Error(`message ${f} not found`);this.state.messages=this.state.messages.slice(0,this.messages[m].role==="assistant"?m:m+1),await this.makeRequest({trigger:"regenerate-message",messageId:f,...h})},this.resumeStream=async(f={})=>{await this.makeRequest({trigger:"resume-stream",...f})},this.clearError=()=>{this.status==="error"&&(this.state.error=void 0,this.setStatus({status:"ready"}))},this.addToolOutput=async({state:f="output-available",tool:h,toolCallId:m,output:p,errorText:g})=>this.jobExecutor.run(async()=>{var b,x;const y=this.state.messages,v=y[y.length-1];this.state.replaceMessage(y.length-1,{...v,parts:v.parts.map(w=>L_(w)&&w.toolCallId===m?{...w,state:f,output:p,errorText:g}:w)}),this.activeResponse&&(this.activeResponse.state.message.parts=this.activeResponse.state.message.parts.map(w=>L_(w)&&w.toolCallId===m?{...w,state:f,output:p,errorText:g}:w)),this.status!=="streaming"&&this.status!=="submitted"&&((b=this.sendAutomaticallyWhen)!=null&&b.call(this,{messages:this.state.messages}))&&this.makeRequest({trigger:"submit-message",messageId:(x=this.lastMessage)==null?void 0:x.id})}),this.addToolResult=this.addToolOutput,this.stop=async()=>{var f;this.status!=="streaming"&&this.status!=="submitted"||(f=this.activeResponse)!=null&&f.abortController&&this.activeResponse.abortController.abort()},this.id=t,this.transport=n,this.generateId=e,this.messageMetadataSchema=r,this.dataPartSchemas=s,this.state=o,this.onError=i,this.onToolCall=a,this.onFinish=l,this.onData=u,this.sendAutomaticallyWhen=d}get status(){return this.state.status}setStatus({status:e,error:t}){this.status!==e&&(this.state.status=e,this.state.error=t)}get error(){return this.state.error}get messages(){return this.state.messages}get lastMessage(){return this.state.messages[this.state.messages.length-1]}set messages(e){this.state.messages=e}async makeRequest({trigger:e,metadata:t,headers:n,body:r,messageId:s}){var o,i,a,l;this.setStatus({status:"submitted",error:void 0});const u=this.lastMessage;let d=!1,f=!1,h=!1;try{const m={state:FQe({lastMessage:this.state.snapshot(u),messageId:this.generateId()}),abortController:new AbortController};m.abortController.signal.addEventListener("abort",()=>{d=!0}),this.activeResponse=m;let p;if(e==="resume-stream"){const b=await this.transport.reconnectToStream({chatId:this.id,metadata:t,headers:n,body:r});if(b==null){this.setStatus({status:"ready"});return}p=b}else p=await this.transport.sendMessages({chatId:this.id,messages:this.state.messages,abortSignal:m.abortController.signal,metadata:t,headers:n,body:r,trigger:e,messageId:s});const g=b=>this.jobExecutor.run(()=>b({state:m.state,write:()=>{var x;this.setStatus({status:"streaming"}),m.state.message.id===((x=this.lastMessage)==null?void 0:x.id)?this.state.replaceMessage(this.state.messages.length-1,m.state.message):this.state.pushMessage(m.state.message)}}));await LQe({stream:$Qe({stream:p,onToolCall:this.onToolCall,onData:this.onData,messageMetadataSchema:this.messageMetadataSchema,dataPartSchemas:this.dataPartSchemas,runUpdateMessageJob:g,onError:b=>{throw b}}),onError:b=>{throw b}}),this.setStatus({status:"ready"})}catch(m){if(d||m.name==="AbortError")return d=!0,this.setStatus({status:"ready"}),null;h=!0,m instanceof TypeError&&(m.message.toLowerCase().includes("fetch")||m.message.toLowerCase().includes("network"))&&(f=!0),this.onError&&m instanceof Error&&this.onError(m),this.setStatus({status:"error",error:m})}finally{try{(i=this.onFinish)==null||i.call(this,{message:this.activeResponse.state.message,messages:this.state.messages,isAbort:d,isDisconnect:f,isError:h,finishReason:(o=this.activeResponse)==null?void 0:o.state.finishReason})}catch(m){console.error(m)}this.activeResponse=void 0}(a=this.sendAutomaticallyWhen)!=null&&a.call(this,{messages:this.state.messages})&&!h&&await this.makeRequest({trigger:"submit-message",messageId:(l=this.lastMessage)==null?void 0:l.id,metadata:t,headers:n,body:r})}};function YQe({messages:e}){const t=e[e.length-1];if(!t||t.role!=="assistant")return!1;const n=t.parts.reduce((s,o,i)=>o.type==="step-start"?i:s,-1),r=t.parts.slice(n+1).filter(L_).filter(s=>!s.providerExecuted);return r.length>0&&r.every(s=>s.state==="output-available"||s.state==="output-error")}function GQe(e,t){if(typeof e!="function")throw new TypeError(`Expected the first argument to be a \`function\`, got \`${typeof e}\`.`);let n,r=0;return function(...o){clearTimeout(n);const i=Date.now(),a=i-r,l=t-a;l<=0?(r=i,e.apply(this,o)):n=setTimeout(()=>{r=Date.now(),e.apply(this,o)},l)}}var KQe=GQe;const ZQe=Jc(KQe);var Iee=(e,t,n)=>{if(!t.has(e))throw TypeError("Cannot "+n)},Fn=(e,t,n)=>(Iee(e,t,"read from private field"),n?n.call(e):t.get(e)),Ji=(e,t,n)=>{if(t.has(e))throw TypeError("Cannot add the same private member more than once");t instanceof WeakSet?t.add(e):t.set(e,n)},nc=(e,t,n,r)=>(Iee(e,t,"write to private field"),t.set(e,n),n);function XQe(e,t){return t!=null?ZQe(e,t):e}var Fo,vv,wv,lg,cg,ug,Lf,z_,B_,QQe=class{constructor(e=[]){Ji(this,Fo,void 0),Ji(this,vv,"ready"),Ji(this,wv,void 0),Ji(this,lg,new Set),Ji(this,cg,new Set),Ji(this,ug,new Set),this.pushMessage=t=>{nc(this,Fo,Fn(this,Fo).concat(t)),Fn(this,Lf).call(this)},this.popMessage=()=>{nc(this,Fo,Fn(this,Fo).slice(0,-1)),Fn(this,Lf).call(this)},this.replaceMessage=(t,n)=>{nc(this,Fo,[...Fn(this,Fo).slice(0,t),this.snapshot(n),...Fn(this,Fo).slice(t+1)]),Fn(this,Lf).call(this)},this.snapshot=t=>structuredClone(t),this["~registerMessagesCallback"]=(t,n)=>{const r=n?XQe(t,n):t;return Fn(this,lg).add(r),()=>{Fn(this,lg).delete(r)}},this["~registerStatusCallback"]=t=>(Fn(this,cg).add(t),()=>{Fn(this,cg).delete(t)}),this["~registerErrorCallback"]=t=>(Fn(this,ug).add(t),()=>{Fn(this,ug).delete(t)}),Ji(this,Lf,()=>{Fn(this,lg).forEach(t=>t())}),Ji(this,z_,()=>{Fn(this,cg).forEach(t=>t())}),Ji(this,B_,()=>{Fn(this,ug).forEach(t=>t())}),nc(this,Fo,e)}get status(){return Fn(this,vv)}set status(e){nc(this,vv,e),Fn(this,z_).call(this)}get error(){return Fn(this,wv)}set error(e){nc(this,wv,e),Fn(this,B_).call(this)}get messages(){return Fn(this,Fo)}set messages(e){nc(this,Fo,[...e]),Fn(this,Lf).call(this)}};Fo=new WeakMap;vv=new WeakMap;wv=new WeakMap;lg=new WeakMap;cg=new WeakMap;ug=new WeakMap;Lf=new WeakMap;z_=new WeakMap;B_=new WeakMap;var zf,v6=class extends qQe{constructor({messages:e,...t}){const n=new QQe(e);super({...t,state:n}),Ji(this,zf,void 0),this["~registerMessagesCallback"]=(r,s)=>Fn(this,zf)["~registerMessagesCallback"](r,s),this["~registerStatusCallback"]=r=>Fn(this,zf)["~registerStatusCallback"](r),this["~registerErrorCallback"]=r=>Fn(this,zf)["~registerErrorCallback"](r),nc(this,zf,n)}};zf=new WeakMap;function Aee({experimental_throttle:e,resume:t=!1,...n}={}){const r=C.useRef("chat"in n?n.chat:new v6(n));("chat"in n&&n.chat!==r.current||"id"in n&&r.current.id!==n.id)&&(r.current="chat"in n?n.chat:new v6(n));const o="id"in n?n.id:null,i=C.useCallback(f=>r.current["~registerMessagesCallback"](f,e),[e,o]),a=C.useSyncExternalStore(i,()=>r.current.messages,()=>r.current.messages),l=C.useSyncExternalStore(r.current["~registerStatusCallback"],()=>r.current.status,()=>r.current.status),u=C.useSyncExternalStore(r.current["~registerErrorCallback"],()=>r.current.error,()=>r.current.error),d=C.useCallback(f=>{typeof f=="function"&&(f=f(r.current.messages)),r.current.messages=f},[r]);return C.useEffect(()=>{t&&r.current.resumeStream()},[t,r]),{id:r.current.id,messages:a,setMessages:d,sendMessage:r.current.sendMessage,regenerate:r.current.regenerate,clearError:r.current.clearError,stop:r.current.stop,error:u,resumeStream:r.current.resumeStream,status:l,addToolResult:r.current.addToolOutput,addToolOutput:r.current.addToolOutput}}function JQe(e,t){return e.some(n=>n.tableName&&n.tableName===t.tableName||n.datamodelName&&n.datamodelName===t.datamodelName)}function eJe(e){return e.filter((n,r,s)=>r===s.findIndex(o=>o.tableName===n.tableName&&o.datamodelName===n.datamodelName))}function tJe(e,t){return e.filter(n=>!(n.connectionId===t.connectionId&&n.tableName===t.tableName&&n.datamodelName===t.datamodelName))}function nJe(e){return e.toLowerCase()==="clickhouse"?"{database_name}.{table_name}":e.toLowerCase()==="postgres"?"{schema_name}.{table_name}":"{table_name}"}function Pee(e){return e.map(r=>{const s=r.connectionType==="API"||r.connectionType==="S3"||r.connectionType==="S3Tables"?"DuckDb":r.connectionType;return r.datamodelName?{...r,databaseName:"",schemaName:"",tableName:"",connectionType:s,tableReferenceFormat:"dm.{table_name}"}:{...r,connectionType:s,tableReferenceFormat:nJe(s)}}).filter(r=>r.datamodelName?r.connectionId&&r.datamodelName&&r.connectionType:r.connectionId&&r.tableName&&r.connectionType)}function Oee(e){var n,r;if(!e)return"";let t="";try{const s=JSON.parse((e==null?void 0:e.message)||"{}");t=((r=(n=s==null?void 0:s.error)==null?void 0:n.lastError)==null?void 0:r.message)||(s==null?void 0:s.error)||e.message}catch{t=e.message}return t}function rJe(){var b;const{authToken:e,tokenProps:t}=Ge(),n=X(x=>x.dashboard.aiScopeTables),r=(b=C1().data)==null?void 0:b.assistantProfileId,{sendMessage:s,messages:o,setMessages:i,regenerate:a,status:l,addToolResult:u,error:d,stop:f,clearError:h}=Aee({transport:new bA({api:`${t.apiServiceUrl}/v1/assistant`,headers:()=>({Authorization:`Bearer ${e==null?void 0:e.accessToken}`}),body:()=>{const x=qi.getState();return{assistantId:"dashboard-assistant",assistantProfileId:r,aiContext:x.currentAIContext,reasoningEffort:x.reasoningEffort,showReasoning:x.showReasoning}},credentials:"omit",prepareSendMessagesRequest:({messages:x,body:y})=>({body:{...y,messages:Iq(x)}})}),onToolCall:m,sendAutomaticallyWhen:YQe,onFinish({isAbort:x,isDisconnect:y,isError:v}){console.log(x?"[Dashboard Assistant] Stream aborted by user":y?"[Dashboard Assistant] Stream disconnected (network error)":v?"[Dashboard Assistant] Stream error occurred":"[Dashboard Assistant] Stream completed successfully")},onError(x){var y;if(x.name==="AbortError"||(y=x.message)!=null&&y.includes("aborted")){console.log("[Dashboard Assistant] Stream aborted (expected)");return}console.error("[Dashboard Assistant] Stream error:",x)}});async function m({toolCall:x}){if(x.toolName==="getCurrentTableScope"&&u({tool:x.toolName,toolCallId:x.toolCallId,output:{tables:Pee(n||[])}}),x.toolName==="getDashboardContext"){const y=X.getState().dashboard;u({tool:x.toolName,toolCallId:x.toolCallId,output:{dashboardContext:y}})}}const p=!["ready","error"].includes(l),g=Oee(d);return{sendMessage:s,regenerate:a,isLoading:p,messages:o,setMessages:i,status:l,stop:f,errorMessage:g,clearError:h}}function Fee(){var u;const{authToken:e,tokenProps:t}=Ge(),n=(u=C1().data)==null?void 0:u.assistantProfileId;function r(){return!(!n||!(e!=null&&e.accessToken))}const{data:s,isLoading:o,isFetching:i,isError:a}=hn({queryKey:["assistant-profile",n],queryFn:()=>qn(`${t.apiServiceUrl}/v1/assistant/${n}`,(e==null?void 0:e.accessToken)||""),enabled:r()});return{assistantProfile:s==null?void 0:s.assistantProfile,isLoading:o,isFetching:i,isError:a}}function $ee({seedQuestions:e,handleSeedQuestionClick:t}){return e.length===0?null:c.jsxs("div",{className:"overflow-x-auto rounded-md border bg-muted/40 p-4",children:[c.jsxs("div",{className:"mb-3 flex items-center",children:[c.jsx(p8,{className:"mr-2 h-4 w-4 text-muted-foreground"}),c.jsx("h3",{className:"font-medium",children:"Example Questions"})]}),c.jsx("div",{className:"flex flex-wrap gap-2",children:e.map((n,r)=>c.jsx(se,{variant:"outline",size:"sm",onClick:()=>t(n),className:"text-sm",children:n},r))})]})}function l1(e,t={}){const{size:n="h-4 w-4"}=t,r=n;switch(e){case"table":return c.jsx(HD,{className:r});case"view":return c.jsx($c,{className:r});case"materialized view":return c.jsx(rle,{className:r});case"model":return c.jsx(D1,{className:r});case"file":return c.jsx(Fi,{className:r});case"dataset":return c.jsx(Cl,{className:r});case"upload":return c.jsx(YD,{className:r});case"url":return c.jsx(w8,{className:r});default:return c.jsx(E1,{className:r})}}const Lee=T.forwardRef(({className:e,...t},n)=>c.jsxs("div",{className:"flex items-center px-3","cmdk-input-wrapper":"",children:[c.jsx(Ui,{className:"mr-2 h-4 w-4 shrink-0 opacity-50"}),c.jsx(Ss.Input,{ref:n,className:Z("flex h-11 w-full rounded-md bg-transparent py-3 text-sm outline-none placeholder:text-muted-foreground disabled:cursor-not-allowed disabled:opacity-50",e),...t})]}));Lee.displayName=Ss.Input.displayName;const U0=e=>e.label||(e==null?void 0:e.name),w6=e=>"description"in e?e.description:`${e.type} from ${e.database||"database"}`;function sJe({isOpen:e,onSelect:t,onDeselect:n,onClose:r,availableEntities:s,selectedEntities:o,onTabComplete:i,onSelectAll:a,onRemoveAll:l,onAddContext:u}){const{tokenProps:d}=Ge(),f=(d==null?void 0:d.type)==="dashboard",[h,m]=C.useState(""),[p,g]=C.useState(""),b=s.filter(S=>{if(!h)return!0;const j=U0(S).toLowerCase(),E=w6(S).toLowerCase(),_=h.toLowerCase();return j.includes(_)||E.includes(_)});C.useEffect(()=>{e||(m(""),g(""))},[e]),C.useEffect(()=>{b.length>0&&!p&&g(U0(b[0]))},[b,p]);const x=()=>{if(!p)return;const S=b.find(j=>U0(j)===p);S&&(o.some(E=>"id"in S&&"id"in E?S.id===E.id:S.name===E.name&&S.connectionId===E.connectionId)||t(S),i(S),r())},y=S=>{(S.key==="Tab"||S.key==="Enter")&&(S.preventDefault(),x())};if(!e)return null;const v=S=>o.some(j=>"id"in S&&"id"in j?S.id===j.id:S.name===j.name&&S.connectionId===j.connectionId),w=o.length===s.length,N=o.length>0;return c.jsx(c.Fragment,{children:c.jsxs(Lm,{shouldFilter:!1,value:p,onValueChange:g,onKeyDown:y,children:[s.length>0&&c.jsxs("div",{className:"flex items-center justify-between border-b pr-3",children:[c.jsx(Lee,{placeholder:"Search entities...",value:h,onValueChange:m,className:"flex-1 border-0",autoFocus:!0}),!f&&c.jsxs(se,{onClick:S=>{S.preventDefault(),S.stopPropagation(),u==null||u()},onMouseDown:S=>{S.preventDefault(),S.stopPropagation()},variant:"outline",size:"sm",className:"h-7 shrink-0",children:[c.jsx(Sr,{className:"mr-1 h-4 w-4"}),"Add"]})]}),s.length>0&&c.jsxs("div",{className:"flex items-center justify-between border-b px-3 py-2 text-sm",children:[c.jsxs("div",{className:"text-muted-foreground",children:[o.length," ",o.length===1?"entity":"entities"," selected"]}),c.jsxs("div",{className:"flex items-center gap-1",children:[c.jsx(se,{onClick:S=>{S.preventDefault(),S.stopPropagation(),a==null||a()},onMouseDown:S=>{S.preventDefault(),S.stopPropagation()},disabled:w,variant:"ghost",size:"sm",className:"h-6 px-2 text-xs",children:"Select All"}),N&&c.jsxs(se,{onClick:S=>{S.preventDefault(),S.stopPropagation(),l==null||l()},onMouseDown:S=>{S.preventDefault(),S.stopPropagation()},variant:"ghost",size:"sm",className:"h-6 gap-1 px-2 text-xs",children:[c.jsx(yt,{className:"h-3.5 w-3.5"}),"Clear"]})]})]}),c.jsxs(zm,{className:"min-h-60",children:[c.jsx(Bm,{children:c.jsxs("div",{className:"flex flex-col items-center justify-center py-4",children:[c.jsx("p",{className:"mb-3 text-sm text-muted-foreground",children:"No entities found."}),!f&&c.jsxs(se,{onClick:S=>{S.preventDefault(),S.stopPropagation(),u==null||u()},onMouseDown:S=>{S.preventDefault(),S.stopPropagation()},size:"sm",variant:"outline",className:"flex items-center gap-2",children:[c.jsx(Sr,{className:"h-4 w-4"}),"Add Datasets"]})]})}),c.jsx(Vm,{children:b.map((S,j)=>{const E=v(S),_="id"in S?S.id:`${S.connectionId}-${S.name}`,k=U0(S);return c.jsxs(Hm,{value:k,onSelect:()=>{E?n==null||n(S):t(S)},onMouseDown:M=>{M.preventDefault(),M.stopPropagation()},className:Z("flex cursor-pointer items-start gap-2 p-2 hover:bg-gray-100"),children:[c.jsx("div",{className:"mt-0.5 flex h-5 w-5 shrink-0 items-center justify-center",children:l1(S.type)}),c.jsxs("div",{className:"min-w-0 flex-1",children:[c.jsx("div",{className:"truncate font-medium",children:k}),c.jsx("div",{className:"truncate text-xs text-muted-foreground",children:w6(S)})]}),E&&c.jsx("div",{className:"ml-1 flex h-5 w-5 shrink-0 items-center justify-center rounded-full bg-foreground/80",children:c.jsx(Mr,{className:"h-3 w-3 text-background"})})]},_)})})]})]})})}const V_=e=>e.name||e.name,oJe=e=>{const t=V_(e),n="description"in e?e.description:"",r=e.database||"",s=e.schema||"";return c.jsxs("div",{className:"space-y-1",children:[c.jsx("div",{className:"font-medium",children:t}),n&&c.jsx("div",{className:"text-sm text-muted-foreground",children:n}),c.jsxs("div",{className:"text-xs text-muted-foreground",children:["Type: ",e.type,r&&` • Database: ${r}`,s&&` • Schema: ${s}`]})]})};function iJe({entities:e,availableEntities:t,onRemoveEntity:n,onRemoveEntities:r}){const[s,o]=C.useState(!1),i=e.length>0;e.length,t.length,e.length<t.length;const a=e.length>=3?e.slice(0,2):e,l=e.length>=3?e.slice(2):[],u=l.length>0;return c.jsx(_n,{children:c.jsx("div",{className:"space-y-2",children:i&&c.jsxs("div",{className:"flex flex-wrap gap-1",children:[a.map((d,f)=>{const h="id"in d?d.id:`${d.connectionId}-${d.name}`;return c.jsxs(Zt,{children:[c.jsx(Xt,{asChild:!0,children:c.jsxs(Fe,{variant:"secondary",className:"group relative cursor-pointer gap-2 transition-colors hover:border-red-200 hover:bg-red-50 dark:hover:border-red-800 dark:hover:bg-red-950",children:[l1(d.type,{size:"h-3 w-3"}),c.jsx("span",{className:"max-w-24 truncate text-xs",children:V_(d)}),c.jsx("button",{className:"rounded-full p-0.5 transition-opacity hover:bg-red-100 group-hover:opacity-100",onClick:()=>n(d),children:c.jsx(yt,{className:"h-3 w-3"})})]})}),c.jsx(en,{side:"top",className:"max-w-xs",children:oJe(d)})]},h)}),u&&c.jsxs(Zt,{open:s,onOpenChange:o,children:[c.jsx(Xt,{asChild:!0,children:c.jsxs(Fe,{variant:"secondary",className:"flex cursor-pointer items-center gap-1 transition-colors hover:bg-secondary/80",onClick:()=>o(!0),children:[c.jsx(sle,{className:"h-3 w-3"}),c.jsxs("span",{className:"text-xs",children:[l.length," more"]}),c.jsx("button",{className:"rounded-full p-0.5 transition-opacity hover:bg-red-100 group-hover:opacity-100",onClick:()=>r(l),children:c.jsx(yt,{className:"h-3 w-3"})})]})}),c.jsx(en,{side:"top",className:"max-h-60 max-w-xs overflow-y-auto p-2",children:c.jsxs("div",{className:"space-y-2",children:[c.jsx("div",{className:"text-sm font-medium",children:"Additional Datasets"}),c.jsx("div",{className:"space-y-2",children:l.map(d=>{const f="id"in d?d.id:`${d.connectionId}-${d.name}`;return c.jsxs("div",{className:"group flex items-center justify-between gap-2",children:[c.jsxs("div",{className:"flex items-start gap-2",children:[c.jsx("div",{className:"flex h-5 w-5 shrink-0 items-center justify-center",children:l1(d.type,{size:"h-3 w-3"})}),c.jsxs("div",{className:"min-w-0 flex-1",children:[c.jsx("div",{className:"truncate text-sm font-medium",children:V_(d)}),c.jsxs("div",{className:"truncate text-xs text-muted-foreground",children:[d.type," ",d.database?`• ${d.database}`:""]})]})]}),c.jsx(se,{variant:"ghost",size:"sm",className:"h-6 w-6 p-0 opacity-0 group-hover:opacity-100",onClick:()=>{n(d),l.length===1&&o(!1)},children:c.jsx(yt,{className:"h-3 w-3"})})]},f)})})]})})]})]})})})}function zee(e){return e.type==="dataset"&&e.label||e.name}function aJe(e){const t=[];return t.push({label:"Type",value:e.type}),t.push({label:"Name",value:e.name}),e.connectionType&&t.push({label:"Connection",value:e.connectionType}),e.database&&t.push({label:"Database",value:e.database}),e.schema&&t.push({label:"Schema",value:e.schema}),e.type==="dataset"&&e.label&&t.push({label:"Label",value:e.label}),e.type==="dataset"&&e.description&&t.push({label:"Description",value:e.description}),e.type==="model"&&e.label&&t.push({label:"Label",value:e.label}),e.type==="model"&&e.description&&t.push({label:"Description",value:e.description}),t}function lJe({selectedEntities:e,onDeselectEntity:t}){return e.length===0?null:c.jsxs("div",{className:"mb-4 space-y-2",children:[c.jsxs(ce,{className:"mb-2 text-xs font-medium text-muted-foreground",children:["Selected Entities (",e.length,")"]}),c.jsx("div",{className:"max-h-32 overflow-y-auto rounded-md border border-border/50 p-2",children:c.jsx("div",{className:"flex flex-wrap gap-1",children:e.map((n,r)=>c.jsxs(Fe,{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:[c.jsxs("span",{className:"mr-1 text-gray-500",children:["[",n.type,"]"]}),zee(n),c.jsx("button",{onClick:s=>{s.stopPropagation(),t(n)},className:"absolute right-1 top-1/2 -translate-y-1/2 rounded-full p-0.5 opacity-0 transition-opacity hover:bg-red-100 group-hover:opacity-100",children:c.jsx(yt,{className:"h-2.5 w-2.5 text-red-500"})})]},`${n.type}-${n.name}-${r}`))})})]})}function cJe(e){const{tokenProps:t}=Ge(),n=X(l=>l.authToken)||e;_e(l=>l.selectedConnectionId),_e(l=>{var u,d;return(d=(u=l==null?void 0:l.card)==null?void 0:u.dataSource)==null?void 0:d.connectionId});const{refetch:r,isPending:s,data:o,isLoading:i,isError:a}=hn({queryKey:["semantic-domains"],queryFn:()=>qn(`${t.apiServiceUrl}/v1/domains`,(n==null?void 0:n.accessToken)||""),enabled:!!(n!=null&&n.accessToken)});return{isPending:s,error:a,semanticDomainsData:o,semanticDomains:(o==null?void 0:o.domains)||[],isSemanticDomainsLoading:i,isSemanticDomainsError:a,refetchSemanticDomains:r}}function uJe(e,t){const{tokenProps:n}=Ge(),r=X(u=>u.authToken)||t,{refetch:s,isPending:o,data:i,isLoading:a,isError:l}=hn({queryKey:["datasets",e],queryFn:()=>qn(`${n.apiServiceUrl}/v1/datasets`,(r==null?void 0:r.accessToken)||"",{domainId:e}),enabled:!!(r!=null&&r.accessToken)&&!!e});return{isPending:o,error:l,datasets:(i==null?void 0:i.datasets)||[],isDatasetsLoading:a,isDatasetsError:l,refetchDatasets:s}}function dJe(e){var g,b;const{tokenProps:t}=Ge(),n=X(x=>x.authToken)||e,{connections:r}=$a(e),s=_e(x=>{var y,v;return(v=(y=x==null?void 0:x.card)==null?void 0:y.dataSource)==null?void 0:v.connectionId}),o=r==null?void 0:r.find(x=>x.id===s),i=o==null?void 0:o.type,a=o==null?void 0:o.capabilities,l=((g=a==null?void 0:a.labels)==null?void 0:g.database)||"Database";function u(x){return s&&x?!(x==="API"||x==="S3"):!1}const{data:d,isPending:f,error:h,refetch:m}=hn({queryKey:["databases",s],queryFn:()=>qn(`${t.apiServiceUrl}/v1/databases`,(n==null?void 0:n.accessToken)||"",{connection_id:s}),enabled:u(i)}),p=(b=d==null?void 0:d.databases)==null?void 0:b.map(x=>({id:x.database_name,name:x.database_name}));return{isPending:f,error:h,databases:p||[],refetch:m,label:l}}function fJe(e){var g;const{tokenProps:t}=Ge(),n=X(b=>b.authToken)||e,{connections:r}=$a(e),s=_e(b=>{var x,y;return(y=(x=b==null?void 0:b.card)==null?void 0:x.dataSource)==null?void 0:y.connectionId}),o=_e(b=>{var x,y,v;return(v=(y=(x=b==null?void 0:b.card)==null?void 0:x.dataSource)==null?void 0:y.dbSelection)==null?void 0:v.database}),i=r==null?void 0:r.find(b=>b.id===s),a=i==null?void 0:i.capabilities,l=((g=a==null?void 0:a.labels)==null?void 0:g.schema)||"Schema";function u(){return!(!s||(i==null?void 0:i.type)==="API"||(i==null?void 0:i.type)==="S3"||!o||!(a!=null&&a.path.includes("schema")))}const{data:d,isPending:f,error:h,refetch:m}=hn({queryKey:["schemas",s,o],queryFn:()=>qn(`${t.apiServiceUrl}/v1/schemas`,(n==null?void 0:n.accessToken)||"",{connection_id:s,database_name:o}),enabled:u()}),p=d==null?void 0:d.schemas.map(b=>({id:b.schema_name,name:b.schema_name}));return{isPending:f,error:h,schemas:p||[],refetch:m,label:l}}function Bee(e){const{tokenProps:t}=Ge(),n=X(h=>h.authToken)||e,{connections:r}=$a(e),s=_e(h=>{var m,p;return(p=(m=h==null?void 0:h.card)==null?void 0:m.dataSource)==null?void 0:p.connectionId}),o=r.find(h=>h.id===s);function i(){return!(!(n!=null&&n.accessToken)||!s)}const{data:a,isPending:l,error:u,refetch:d}=hn({queryKey:["dataModels",s],queryFn:()=>qn(`${t.apiServiceUrl}/v1/datamodels`,(n==null?void 0:n.accessToken)||"",{connection_id:s}),enabled:i()}),f=a==null?void 0:a.datamodels.map(h=>({id:h.id,name:h.name,label:h.label,description:h.description,connectionId:s,dialect:h.dialect,connectionType:o==null?void 0:o.type,type:"model",database:h.database,schema:h.schema}));return{isPending:l,error:u,dataModels:f||[],refetch:d}}function hJe(){var N,S,j;const e=_e(E=>E.card.dataSource);_e(E=>E.actions.updateDirectSource);const t=_e(E=>E.actions.updateDataSource),[n,r]=C.useState(""),{selectedConnection:s,error:o}=$a(),{databases:i,isPending:a,error:l,label:u}=dJe(),{schemas:d,isPending:f,error:h,label:m}=fJe(),{error:p}=Bee(),g=s==null?void 0:s.capabilities.path.includes("schema"),b=s==null?void 0:s.capabilities.path.includes("database"),x=u==null?void 0:u.toLowerCase(),y=m==null?void 0:m.toLowerCase(),v=E=>{e&&t({...e,dbSelection:{database:E,schema:"",entityType:"table"},selectedEntities:(e==null?void 0:e.selectedEntities)||[]})},w=E=>{var k;if(!((k=e==null?void 0:e.dbSelection)!=null&&k.database))return;const _=e.dbSelection||{database:"",schema:"",entityType:"table"};t({...e,dbSelection:{..._,schema:E},selectedEntities:(e==null?void 0:e.selectedEntities)||[]})};return c.jsxs(c.Fragment,{children:[(o||l||h||p)&&c.jsxs("div",{className:"rounded-md border border-red-200 bg-red-50 p-3",children:[c.jsx("div",{className:"flex items-center",children:c.jsxs("div",{className:"text-sm text-red-800",children:[c.jsx("strong",{children:"Error loading data:"}),c.jsxs("ul",{className:"mt-1 list-inside list-disc",children:[o&&c.jsxs("li",{children:["Connections: ",o]}),l&&c.jsxs("li",{children:[u,": ",l.message]}),h&&c.jsxs("li",{children:[m,": ",h.message]}),p&&c.jsxs("li",{children:["Data Models: ",p.message]})]})]})}),c.jsx(se,{variant:"outline",size:"sm",className:"mt-2",onClick:()=>window.location.reload(),children:"Retry"})]}),c.jsxs("div",{className:"space-y-4",children:[b&&c.jsxs("div",{className:"space-y-2",children:[c.jsx(ce,{className:"text-sm font-medium",children:u}),c.jsxs(nt,{value:((N=e==null?void 0:e.dbSelection)==null?void 0:N.database)||"",onValueChange:v,disabled:a,children:[c.jsx(et,{className:"w-full",children:c.jsxs("div",{className:"flex items-center gap-2",children:[a&&c.jsx(an,{className:"h-4 w-4 animate-spin"}),c.jsx(ot,{placeholder:l?`Error loading ${x}`:a?`Loading ${x}...`:`Select ${x}...`})]})}),c.jsx(tt,{children:i.map(E=>c.jsx(be,{className:"hover:bg-muted",value:E.id,children:E.name},E.id))})]})]}),((S=e==null?void 0:e.dbSelection)==null?void 0:S.database)&&g&&c.jsxs("div",{className:"space-y-2",children:[c.jsx(ce,{className:"text-sm font-medium",children:m}),c.jsxs(nt,{value:((j=e==null?void 0:e.dbSelection)==null?void 0:j.schema)||"",onValueChange:w,disabled:f,children:[c.jsx(et,{className:"w-full",children:c.jsxs("div",{className:"flex items-center gap-2",children:[f&&c.jsx(an,{className:"h-4 w-4 animate-spin"}),c.jsx(ot,{placeholder:h?`Error loading ${y}`:f?`Loading ${y}...`:`Select ${y}...`})]})}),c.jsx(tt,{children:d.map(E=>c.jsx(be,{className:"hover:bg-muted",value:E.id,children:E.name},E.id))})]})]})]})]})}function mJe(){const e=_e(l=>l.card.dataSource),t=_e(l=>l.actions.updateDataSource),[n,r]=C.useState(!1),s=l=>{if(!l||(e==null?void 0:e.mode)!=="upload")return;const u=Array.from(l).map(f=>({id:`file-${Date.now()}-${Math.random()}`,name:f.name,type:"upload",connectionId:"default",connectionType:"none",label:f.name,description:`Uploaded ${new Date().toLocaleString()}`,originalName:f.name,file:f})),d=(e==null?void 0:e.selectedEntities)||[];t({...e,selectedEntities:[...d,...u]})},o=l=>{if(!e)return;const u=(e.selectedEntities||[]).filter(d=>d.id!==l);t({...e,selectedEntities:u})},i=l=>{if(l===0)return"0 Bytes";const u=1024,d=["Bytes","KB","MB","GB"],f=Math.floor(Math.log(l)/Math.log(u));return Number.parseFloat((l/Math.pow(u,f)).toFixed(2))+" "+d[f]},a=(e==null?void 0:e.selectedEntities)||[];return c.jsxs("div",{className:"space-y-4",children:[c.jsxs("div",{className:"space-y-2",children:[c.jsx(ce,{className:"text-sm font-medium",children:"Upload Files"}),c.jsxs("div",{className:`rounded-lg border-2 border-dashed p-6 text-center transition-colors ${n?"border-blue-400 bg-blue-50":"border-gray-300 hover:border-gray-400"}`,onDragOver:l=>{l.preventDefault(),r(!0)},onDragLeave:()=>r(!1),onDrop:l=>{l.preventDefault(),r(!1),s(l.dataTransfer.files)},children:[c.jsx(YD,{className:"mx-auto mb-2 h-8 w-8 text-gray-400"}),c.jsx("p",{className:"mb-2 text-sm text-gray-600",children:"Drag and drop files here, or click to select"}),c.jsx("input",{type:"file",multiple:!0,className:"hidden",id:"file-upload",onChange:l=>s(l.target.files),accept:".csv,.json,.xlsx,.xls"}),c.jsx(se,{variant:"outline",size:"sm",onClick:()=>{var l;return(l=document.getElementById("file-upload"))==null?void 0:l.click()},children:"Select Files"}),c.jsx("p",{className:"mt-2 text-xs text-gray-500",children:"Supports CSV, JSON, Excel files"})]})]}),a.length>0&&c.jsxs("div",{className:"space-y-2",children:[c.jsxs(ce,{className:"text-xs text-gray-600",children:["Uploaded Files (",a.length,")"]}),c.jsx("div",{className:"max-h-40 space-y-1 overflow-y-auto",children:a.map(l=>c.jsxs("div",{className:"flex items-center justify-between rounded border bg-gray-50 p-2",children:[c.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[c.jsx(Fi,{className:"h-4 w-4 flex-shrink-0 text-gray-500"}),c.jsxs("div",{className:"min-w-0",children:[c.jsx("p",{className:"truncate text-sm text-gray-700",children:l.originalName}),c.jsx("p",{className:"text-xs text-gray-500",children:l.file?i(l.file.size):""})]})]}),c.jsx(se,{variant:"ghost",size:"sm",className:"h-6 w-6 flex-shrink-0 p-0",onClick:()=>o(l.id),children:c.jsx(yt,{className:"h-3 w-3"})})]},l.id))})]})]})}function pJe(){const e=_e(f=>f.card.dataSource),t=_e(f=>f.actions.updateDataSource),[n,r]=C.useState(""),[s,o]=C.useState(""),[i,a]=C.useState("api"),l=()=>{if(!n.trim()||!s.trim()||!e)return;const f={id:`url-${Date.now()}-${Math.random()}`,name:n.trim(),type:"url",connectionId:"default",connectionType:"none",label:n.trim(),description:`URL source of type ${i}`,url:s.trim(),sourceType:i,originalName:n.trim()},h=(e==null?void 0:e.selectedEntities)||[];t({...e,selectedEntities:[...h,f]}),r(""),o(""),a("api")},u=f=>{if(!e)return;const h=(e.selectedEntities||[]).filter(m=>m.id!==f);t({...e,selectedEntities:h})},d=(e==null?void 0:e.selectedEntities)||[];return c.jsxs("div",{className:"space-y-4",children:[c.jsxs("div",{className:"space-y-2",children:[c.jsx(ce,{className:"text-sm font-medium text-gray-700",children:"URL Sources"}),c.jsxs("div",{className:"space-y-3 rounded-lg border bg-gray-50 p-3",children:[c.jsxs("div",{className:"space-y-2",children:[c.jsx(ce,{className:"text-xs text-gray-600",children:"Source Name"}),c.jsx(Nn,{placeholder:"e.g., Sales API, Customer Data",value:n,onChange:f=>r(f.target.value),className:"h-8 text-sm"})]}),c.jsxs("div",{className:"space-y-2",children:[c.jsx(ce,{className:"text-xs text-gray-600",children:"URL"}),c.jsx(Nn,{placeholder:"https://api.example.com/data",value:s,onChange:f=>o(f.target.value),className:"h-8 text-sm"})]}),c.jsxs("div",{className:"space-y-2",children:[c.jsx(ce,{className:"text-xs text-gray-600",children:"Type"}),c.jsxs("select",{value:i,onChange:f=>a(f.target.value),className:"h-8 w-full rounded-md border border-gray-300 px-2 text-sm",children:[c.jsx("option",{value:"api",children:"API Endpoint"}),c.jsx("option",{value:"csv",children:"CSV File"}),c.jsx("option",{value:"json",children:"JSON File"})]})]}),c.jsxs(se,{onClick:l,disabled:!n.trim()||!s.trim(),size:"sm",className:"w-full",children:[c.jsx(Sr,{className:"mr-1 h-3 w-3"}),"Add Source"]})]})]}),d.length>0&&c.jsxs("div",{className:"space-y-2",children:[c.jsxs(ce,{className:"text-xs text-gray-600",children:["Added Sources (",d.length,")"]}),c.jsx("div",{className:"max-h-40 space-y-1 overflow-y-auto",children:d.map(f=>c.jsxs("div",{className:"flex items-center justify-between rounded border bg-gray-50 p-2",children:[c.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[c.jsx(E1,{className:"h-4 w-4 flex-shrink-0 text-gray-500"}),c.jsxs("div",{className:"min-w-0",children:[c.jsx("p",{className:"truncate text-sm text-gray-700",children:f.name}),c.jsx("p",{className:"truncate text-xs text-gray-500",children:f.url})]})]}),c.jsx(se,{variant:"ghost",size:"sm",className:"h-6 w-6 flex-shrink-0 p-0",onClick:()=>u(f.id),children:c.jsx(yt,{className:"h-3 w-3"})})]},f.id))})]})]})}function gJe(e,t){var y,v;const{tokenProps:n}=Ge(),r=X(w=>w.authToken)||t,{connections:s}=$a(t),o=_e(w=>{var N,S;return(S=(N=w==null?void 0:w.card)==null?void 0:N.dataSource)==null?void 0:S.connectionId}),i=_e(w=>{var N,S,j;return(j=(S=(N=w==null?void 0:w.card)==null?void 0:N.dataSource)==null?void 0:S.dbSelection)==null?void 0:j.database}),a=_e(w=>{var N,S,j;return(j=(S=(N=w==null?void 0:w.card)==null?void 0:N.dataSource)==null?void 0:S.dbSelection)==null?void 0:j.schema}),l=s==null?void 0:s.find(w=>w.id===o),u=l==null?void 0:l.capabilities,d=((y=u==null?void 0:u.labels)==null?void 0:y.schema)||"Schema";function f(){return o?(l==null?void 0:l.type)==="API"||(l==null?void 0:l.type)==="S3"?!0:!(!i||u!=null&&u.path.includes("schema")&&!a):!1}const{data:h,isPending:m,isLoading:p,error:g,refetch:b}=hn({queryKey:[e,o,i,a],queryFn:()=>qn(`${n.apiServiceUrl}/v1/${e}s`,(r==null?void 0:r.accessToken)||"",{connection_id:o,database_name:i,schema_name:a}),enabled:f()}),x=(v=h==null?void 0:h[`${e}s`])==null?void 0:v.map(w=>{var N;return{connectionId:l==null?void 0:l.id,connectionType:l==null?void 0:l.type,dialect:l==null?void 0:l.dialect,type:e,dbObjectType:(N=w==null?void 0:w.table_type)==null?void 0:N.toLowerCase(),id:w[`${e}_name`],database:i,schema:a,name:w[`${e}_name`]}});return{isPending:m,isLoading:p,error:g,entities:x||[],refetch:b,label:d}}function c1({title:e,message:t}){return c.jsx("div",{className:"rounded-xl border border-destructive/40 bg-destructive/10 p-4 text-destructive shadow-sm",children:c.jsxs("div",{className:"flex items-start gap-4",children:[c.jsx(Fc,{className:"h-6 w-6 flex-shrink-0"}),c.jsxs("div",{className:"flex-1",children:[c.jsx("h4",{className:"text-base font-semibold",children:e}),t&&c.jsx("p",{className:"mt-1 text-sm text-destructive/90",children:t})]})]})})}function bJe({dataSource:e,onSelectionChange:t,selectedEntities:n,onRegisterSelectAll:r}){const{connections:s,isPending:o}=$a(),[i,a]=C.useState(""),[l,u]=C.useState(""),[d,f]=C.useState("tables"),{updateDataSource:h,setSelectedConnectionId:m}=Qn(),{entities:p,isLoading:g,error:b}=gJe("table"),{dataModels:x,isPending:y,error:v}=Bee(),w=k=>{const M=s.find(R=>R.id===k);if(!M)return;const D=M.type==="upload"?"upload":M.type==="url"?"url":"database";h({...e,connectionId:k,connectionType:M.type,mode:D,dbSelection:{database:"",schema:"",entityType:"table"}}),m(k)},N=k=>{var P,I;const M=n||[],D=M.some(L=>L.name===k.name&&L.type===k.type);let R;if(D)R=M.filter(L=>!(L.name===k.name&&L.type===k.type));else{const L={connectionId:e.connectionId,connectionType:e.connectionType,type:k.type,dbObjectType:k.dbObjectType,database:((P=e.dbSelection)==null?void 0:P.database)||"",schema:((I=e.dbSelection)==null?void 0:I.schema)||"",name:k.name,dialect:k.dialect};R=[...M,L]}t==null||t(R)},S=k=>{const M=n||[],D=M.some(P=>P.type==="model"&&P.name===k.name);let R;D?R=M.filter(P=>!(P.type==="model"&&P.name===k.name)):R=[...M,k],t==null||t(R)},j=p.filter(k=>k.name.toLowerCase().includes(i.toLowerCase())),E=x.filter(k=>k.name.toLowerCase().includes(l.toLowerCase())),_=C.useCallback(()=>{if(!t)return;const k=n||[];let M=[...k];if(d==="tables"){const R=j.filter(P=>!k.some(I=>I.name===P.name&&I.type==="table")).map(P=>{var I,L;return{connectionId:e.connectionId,connectionType:e.connectionType,type:"table",dbObjectType:P.dbObjectType,database:((I=e.dbSelection)==null?void 0:I.database)||"",schema:((L=e.dbSelection)==null?void 0:L.schema)||"",name:P.name,dialect:P.dialect}});M=[...k,...R]}else if(d==="datamodels"){const D=E.filter(R=>!k.some(P=>P.name===R.name&&P.type==="model"));M=[...k,...D]}t(M)},[d,j,E,n,e,t]);return C.useEffect(()=>{r&&r(_)},[r,_]),c.jsxs("div",{className:"space-y-4",children:[c.jsxs("div",{className:"space-y-2",children:[c.jsx(ce,{className:"font-medium= text-sm",children:"Connection"}),c.jsxs(nt,{value:(e==null?void 0:e.connectionId)||"",onValueChange:w,disabled:o,children:[c.jsx(et,{className:"w-full",children:c.jsx(ot,{placeholder:o?"Loading connections...":"Select connection..."})}),c.jsx(tt,{children:s.map(k=>c.jsx(be,{className:"hover:bg-muted",value:k.id,children:c.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[c.jsx(Cl,{className:"h-4 w-4 flex-shrink-0"}),c.jsx("span",{className:"truncate",children:k.name}),c.jsx(Fe,{variant:"secondary",className:"flex-shrink-0 text-xs",children:k.type})]})},k.id))})]})]}),(e==null?void 0:e.connectionId)&&c.jsxs(c.Fragment,{children:[e.connectionType==="upload"&&c.jsx(mJe,{}),e.connectionType==="url"&&c.jsx(pJe,{}),e.connectionType!=="upload"&&e.connectionType!=="url"&&c.jsxs(c.Fragment,{children:[c.jsx(hJe,{}),c.jsx("div",{className:"space-y-4",children:c.jsx("div",{className:"space-y-2",children:c.jsxs(Bs,{defaultValue:"tables",value:d,onValueChange:k=>f(k),className:"w-full",children:[c.jsxs(vs,{className:"grid w-full grid-cols-2",children:[c.jsxs(Gt,{value:"tables",children:["Tables & Views (",j.length,")"]}),c.jsxs(Gt,{value:"datamodels",children:["Data Models (",E.length,")"]})]}),c.jsxs(sr,{value:"tables",className:"space-y-2",children:[c.jsx(xn,{placeholder:"Search tables and views...",value:i,onChange:k=>a(k.target.value),className:"h-8 text-sm",disabled:g}),c.jsx("div",{className:"max-h-40 space-y-1 overflow-y-auto",children:g?c.jsx("div",{className:"py-4 text-center text-sm",children:"Loading tables..."}):b?c.jsx(c1,{title:"Error loading tables",message:b.message||"Failed to load tables. Please try again.",onRetry:()=>window.location.reload()}):j.length===0?c.jsx("div",{className:"py-4 text-center text-sm",children:"No tables or views found"}):j.map(k=>{const M=n.some(D=>D.name===k.name&&D.type==="table");return c.jsxs("div",{className:"group flex cursor-pointer items-center space-x-2 rounded p-2 hover:bg-muted",onClick:()=>N(k),children:[c.jsx(Qt,{id:`table-${k.name}`,checked:M,onCheckedChange:()=>N(k),onClick:D=>D.stopPropagation(),disabled:g}),c.jsxs(ce,{className:"flex flex-1 cursor-pointer items-center gap-2",children:[k.name,k.dbObjectType==="view"&&c.jsx(Fe,{variant:"secondary",className:"text-xs group-hover:border-border",children:"View"}),k.dbObjectType==="materialized view"&&c.jsx(Fe,{variant:"secondary",className:"text-xs group-hover:border-border",children:"Materialized View"})]})]},k.name)})})]}),c.jsxs(sr,{value:"datamodels",className:"space-y-2",children:[c.jsx(xn,{placeholder:"Search data models...",value:l,onChange:k=>u(k.target.value),className:"h-8 text-sm",disabled:y}),c.jsx("div",{className:"max-h-40 space-y-1 overflow-y-auto",children:y?c.jsx("div",{className:"py-4 text-center text-sm",children:"Loading data models..."}):v?c.jsx(c1,{title:"Error loading data models",message:v.message||"Failed to load data models. Please try again.",onRetry:()=>window.location.reload()}):E.length===0?c.jsx("div",{className:"py-4 text-center text-sm",children:"No data models found"}):E.map(k=>{const M=n.some(D=>D.name===k.name&&D.type==="model");return c.jsxs("div",{className:"flex cursor-pointer items-start space-x-2 rounded p-2 hover:bg-muted",onClick:()=>S(k),children:[c.jsx(Qt,{id:`dataModel-${k.name}`,checked:M,onCheckedChange:()=>S(k),onClick:D=>D.stopPropagation(),disabled:y}),c.jsxs("div",{className:"flex flex-1 cursor-pointer flex-col gap-1",children:[c.jsx(ce,{className:"cursor-pointer",children:k.name}),c.jsx("span",{className:"text-xs text-muted-foreground",children:k.description})]})]},k.name)})})]})]})})})]})]})]})}function xJe({dataSource:e,onDataSourceUpdate:t,onSelectionChange:n,selectedEntities:r,allowedDomainIds:s=[],isRestricted:o=!1,autoSelectedDomainId:i,onRegisterSelectAll:a}){var N;const[l,u]=C.useState(""),d=C.useCallback(S=>{const j={...e,connectionId:e.connectionId||"none",connectionType:e.connectionType||"none",mode:"semanticDomain",semanticDomainId:S};t({...j})},[e,t]);C.useEffect(()=>{i&&!(e!=null&&e.semanticDomainId)&&d(i)},[i,e==null?void 0:e.semanticDomainId,d]);const{semanticDomains:f,isPending:h,error:m}=cJe(),p=o?f.filter(S=>s.includes(S.id)):f,{datasets:g,isPending:b,error:x}=uJe(e==null?void 0:e.semanticDomainId),y=S=>{const j=r||[],E=j.some(k=>k.id===S.id&&k.type==="dataset");let _;if(E)_=j.filter(k=>!(k.id===S.id&&k.type==="dataset"));else{const k={id:S.id,datasetType:S.type,name:S.name||S.table,label:S.label,domainId:S.domainId,description:S.description,database:S.database,schema:S.schema,type:"dataset",connectionId:S.connectionId,connectionType:S.connectionType,dialect:S.dialect,datamodelId:S.datamodelId,sql:S.sql};_=[...j,k]}n==null||n(_)},v=g.filter(S=>S.name.toLowerCase().includes(l.toLowerCase())),w=C.useCallback(()=>{if(!n||!(e!=null&&e.semanticDomainId))return;const S=r||[],E=v.filter(k=>!S.some(M=>M.id===k.id&&M.type==="dataset")).map(k=>({id:k.id,datasetType:k.type,name:k.name||k.table,label:k.label,domainId:k.domainId,description:k.description,database:k.database,schema:k.schema,type:"dataset",connectionId:k.connectionId,connectionType:k.connectionType,dialect:k.dialect,datamodelId:k.datamodelId,sql:k.sql})),_=[...S,...E];n(_)},[v,r,e==null?void 0:e.semanticDomainId,n]);return C.useEffect(()=>{a&&a(w)},[a,w]),c.jsxs("div",{className:"space-y-4",children:[c.jsxs("div",{className:"space-y-2",children:[c.jsx(ce,{className:"text-sm font-medium",children:"Semantic Domain"}),c.jsxs(nt,{value:(e==null?void 0:e.semanticDomainId)||"",onValueChange:d,disabled:h||o&&!!i,children:[c.jsx(et,{className:"w-full",children:c.jsx(ot,{placeholder:h?"Loading semantic domains...":o&&i?"Loading domain...":"Select semantic domain...",children:((N=p.find(S=>S.id===(e==null?void 0:e.semanticDomainId)))==null?void 0:N.label)||"Select semantic domain"})}),c.jsx(tt,{children:p.map(S=>c.jsx(be,{className:"hover:bg-muted",value:S.id,children:c.jsxs("div",{className:"flex flex-col items-start",children:[c.jsx("span",{className:"font-medium",children:S.label}),c.jsx("span",{className:"text-xs",children:S.description})]})},S.id))})]}),m&&c.jsx(c1,{title:"Error loading semantic models",message:m.message})]}),(e==null?void 0:e.semanticDomainId)&&c.jsxs("div",{className:"space-y-2",children:[c.jsx(ce,{className:"text-sm font-medium text-gray-700",children:"Datasets"}),c.jsxs("div",{className:"space-y-2",children:[c.jsx(xn,{placeholder:"Search datasets...",value:l,onChange:S=>u(S.target.value),className:"h-8 text-sm",disabled:b}),c.jsx("div",{className:"max-h-40 space-y-1 overflow-y-auto",children:b?c.jsx("div",{className:"py-4 text-center text-sm text-gray-500",children:"Loading datasets..."}):x?c.jsx(c1,{title:"Error loading datasets",message:x.message||"Failed to load datasets. Please try again.",onRetry:()=>window.location.reload()}):v.length===0?c.jsx("div",{className:"py-4 text-center text-sm text-gray-500",children:l?"No datasets match your search":"No datasets available"}):v.map(S=>{const j=r.some(E=>E.id===S.id&&E.type==="dataset");return c.jsxs("div",{className:"flex cursor-pointer items-start space-x-2 rounded p-2 hover:bg-gray-50",onClick:()=>y(S),children:[c.jsx(Qt,{id:`dataset-${S.id}`,checked:j,onCheckedChange:()=>y(S),onClick:E=>E.stopPropagation(),disabled:b}),c.jsxs("div",{className:"flex flex-1 flex-col gap-1",children:[c.jsx(ce,{className:"cursor-pointer font-medium",children:S.label||S.name}),c.jsx("span",{className:"text-xs text-gray-500",children:S.description})]})]},S.label||S.name)})})]})]})]})}function xA({open:e,onOpenChange:t,dataSource:n,dialogMode:r,incomingSelectedEntities:s}){const{tokenProps:o}=Ge(),{allowedSemanticDomains:i}=o,[a,l]=C.useState([]),{updateDataSource:u}=Qn(),d=X(M=>M.isVisualEditing),f=X(M=>M.dashboard.aiContext),{setAiContext:h}=Ot(),m=C.useRef(null),[p,g]=C.useState(!1),b=i&&i.length>0,x=!b,y=b&&i.length===1?i[0]:void 0,v=C.useCallback(M=>{const D=M;u({...n,connectionId:(n==null?void 0:n.connectionId)||"",connectionType:(n==null?void 0:n.connectionType)||"",mode:D,selectedEntities:(n==null?void 0:n.selectedEntities)||[],...D!=="semanticDomain"&&{semanticDomainId:void 0}})},[n,u]),w=C.useCallback(M=>{u({...n,...M})},[n,u]);C.useEffect(()=>{b&&n.mode!=="semanticDomain"&&v("semanticDomain")},[b,n.mode,v]),C.useEffect(()=>{y&&!n.semanticDomainId&&w({semanticDomainId:y})},[y,n.semanticDomainId,w]),C.useEffect(()=>{e?l(s||[]):(m.current=null,g(!1))},[e,n==null?void 0:n.selectedEntities,r,u,s,n]);const N=M=>{const D=a.filter(R=>!(R.name===M.name&&R.type===M.type));l(D)},S=()=>{l([])},j=C.useCallback(M=>{l(M)},[]),E=C.useCallback(()=>{m.current&&m.current()},[]),_=C.useCallback(M=>{m.current=M,g(!0)},[]);function k(){var M,D;if(r==="aiContext")d&&u(n),h({...f,selectedEntities:a}),t(!1);else if(r==="dataSource"){if(n.mode==="semanticDomain"){const R=(M=a==null?void 0:a[0])==null?void 0:M.connectionId,P=(D=a==null?void 0:a[0])==null?void 0:D.connectionType;u({...n,connectionId:R,connectionType:P,selectedEntities:a})}else u({...n,selectedEntities:a});t(!1)}}return c.jsx(ns,{open:e,onOpenChange:t,children:c.jsx(Vr,{className:"flex max-w-2xl flex-col",children:c.jsxs("div",{children:[c.jsxs(Hr,{className:"flex-shrink-0",children:[c.jsx(Ur,{children:r==="aiContext"?"Data Context":"Select Data Source"}),c.jsx(ys,{children:r==="aiContext"?"Set the overall data scope for the dashboard":"Select data sets to analyze"})]}),c.jsx("div",{className:"flex-1 grow overflow-y-auto py-4",children:c.jsxs("div",{className:"space-y-4",children:[x&&c.jsx("div",{className:"space-y-2",children:c.jsx(Bs,{defaultValue:(n==null?void 0:n.mode)||"database",value:(n==null?void 0:n.mode)||"database",onValueChange:v,className:"w-full",children:c.jsxs(vs,{className:"grid w-full grid-cols-2",children:[c.jsx(Gt,{value:"database",children:"Direct Source"}),c.jsx(Gt,{value:"semanticDomain",children:"Semantic Domain"})]})})}),(n==null?void 0:n.mode)==="semanticDomain"&&c.jsx(xJe,{dataSource:n,onDataSourceUpdate:w,selectedEntities:a,onSelectionChange:j,allowedDomainIds:i||[],isRestricted:b,autoSelectedDomainId:y,onRegisterSelectAll:_}),(n==null?void 0:n.mode)==="database"&&x&&c.jsx(bJe,{dataSource:n,onDataSourceUpdate:w,selectedEntities:a,onSelectionChange:j,onRegisterSelectAll:_})]})}),c.jsx(lJe,{selectedEntities:a,onDeselectEntity:N}),c.jsx(xs,{className:"flex-shrink-0",children:c.jsx("div",{className:"flex w-full justify-between",children:c.jsxs("div",{className:"flex grow justify-end gap-2",children:[c.jsx(se,{variant:"outline",onClick:E,disabled:!p,children:"Select All"}),c.jsx(se,{variant:"outline",onClick:S,disabled:a.length===0,children:"Clear All"}),c.jsxs(se,{variant:"outline",onClick:()=>t(!1),children:[c.jsx(yt,{className:"mr-2 h-4 w-4"}),"Close"]}),c.jsxs(se,{onClick:k,children:[c.jsx(Mr,{className:"mr-2 h-4 w-4"}),"Accept"]})]})})})]})})})}function yJe({onFilesSelected:e,disabled:t=!1,currentFileCount:n=0,className:r}){const s=C.useRef(null),o=async a=>{const l=Array.from(a.target.files||[]);if(l.length===0)return;const u=tl-n;if(l.length>u){Oe.error(`You can only attach ${tl} files per message. You have ${u} slot(s) remaining.`);return}const{valid:d,errors:f}=jJ(l);if(f.forEach(({file:h,error:m})=>{Oe.error(`${h.name}: ${m}`)}),d.length>0)try{const h=await Promise.all(d.map(m=>aA(m)));e(h)}catch(h){console.error("Failed to process files:",h),Oe.error("Failed to process one or more files")}s.current&&(s.current.value="")},i=()=>{var a;(a=s.current)==null||a.click()};return c.jsxs(c.Fragment,{children:[c.jsx("input",{ref:s,type:"file",multiple:!0,accept:".png,.jpg,.jpeg,.gif,.webp,.pdf,.txt,.md,.csv,.json,.xml,.js,.jsx,.ts,.tsx,.py,.sql",onChange:o,className:"hidden",disabled:t||n>=tl}),c.jsx(se,{variant:"secondary",size:"sm",className:`h-7 px-2 ${r}`,onClick:i,disabled:t||n>=tl,title:n>=tl?`Maximum ${tl} files allowed`:"Attach files",children:c.jsx($D,{className:"h-4 w-4 text-muted-foreground"})})]})}function vJe({children:e,onFilesDropped:t,disabled:n=!1,currentFileCount:r=0,className:s}){const[o,i]=C.useState(!1),a=C.useCallback(f=>{f.preventDefault(),f.stopPropagation(),n||i(!0)},[n]),l=C.useCallback(f=>{f.preventDefault(),f.stopPropagation();const h=f.currentTarget.getBoundingClientRect(),m=f.clientX,p=f.clientY;(m<h.left||m>=h.right||p<h.top||p>=h.bottom)&&i(!1)},[]),u=C.useCallback(f=>{f.preventDefault(),f.stopPropagation()},[]),d=C.useCallback(async f=>{if(f.preventDefault(),f.stopPropagation(),i(!1),n)return;const h=Array.from(f.dataTransfer.files);if(h.length===0)return;const m=tl-r;if(h.length>m){Oe.error(`You can only attach ${tl} files per message. You have ${m} slot(s) remaining.`);return}const{valid:p,errors:g}=jJ(h);if(g.forEach(({file:b,error:x})=>{Oe.error(`${b.name}: ${x}`)}),p.length>0)try{const b=await Promise.all(p.map(x=>aA(x)));t(b),Oe.success(`${b.length} file(s) attached successfully`)}catch(b){console.error("Failed to process files:",b),Oe.error("Failed to process one or more files")}},[n,r,t]);return c.jsxs("div",{className:Z("relative",s),onDragEnter:a,onDragLeave:l,onDragOver:u,onDrop:d,children:[e,o&&!n&&c.jsx("div",{className:"pointer-events-none absolute inset-0 z-50 flex items-center justify-center rounded-lg border-2 border-dashed border-primary bg-primary/5 backdrop-blur-sm",children:c.jsxs("div",{className:"flex flex-col items-center gap-2",children:[c.jsx(YD,{className:"h-8 w-8 text-primary"}),c.jsx("p",{className:"text-sm font-medium text-primary",children:"Drop files here to upload"}),c.jsxs("p",{className:"text-xs text-muted-foreground",children:[tl-r," slot(s) available"]})]})})]})}const yA=C.forwardRef(({input:e,setInput:t,handleInputChange:n,handleSubmit:r,isLoading:s,stop:o,onFocus:i,status:a,assistantType:l},u)=>{const[d,f]=C.useState(!1),[h,m]=C.useState(!1),[p,g]=C.useState(!1),b=C.useRef(null),x=Wm();x2e(),b2e();const{setCurrentAIContext:y,updateSelectedEntities:v,setReasoningEffort:w,setShowReasoning:N}=_S(),{queueMessage:S}=qm(),{addFileAttachment:j,removeFileAttachment:E,clearFileAttachments:_,getFileAttachments:k}=BT(),M=zT(l),D=_e(V=>V.card.dataSource),R=X(V=>V.dashboard.aiContext),P=X(V=>{var G;return(G=V.dashboard.aiContext)==null?void 0:G.selectedEntities});C.useEffect(()=>{u&&"current"in u&&(u.current=b.current)},[u]);const I=C.useCallback(()=>{const V=b.current;if(V){if(!e||e.length===0){V.style.height="10px";return}V.style.height="auto";const G=Math.min(Math.max(V.scrollHeight,10),200);V.style.height=`${G}px`}},[e]);C.useEffect(()=>{I()},[I]),C.useEffect(()=>{const V=setTimeout(()=>{I()},0);return()=>clearTimeout(V)},[I]);const L=()=>{const V=e.trim();!V&&M.length===0||(a!=="ready"?(S(l,V,M),t(""),_(l)):r({preventDefault:()=>{}}))},F=V=>{V.key==="Enter"&&!V.shiftKey&&(V.preventDefault(),L()),V.key==="@"&&(U(),f(!0))},H=C.useCallback(V=>{const G=Uqe(V.nativeEvent);G.length>0&&(V.preventDefault(),G.forEach(async K=>{const J=await aA(K);j(l,J)}))},[j,l]),$=C.useCallback(V=>{V.forEach(G=>{j(l,G)})},[j,l]),A=C.useCallback(V=>{V.forEach(G=>{j(l,G)})},[j,l]),q=C.useCallback(V=>{E(l,V)},[E,l]),z=V=>{if(x.selectedEntities.some(K=>K.id&&K.id===V.id||K.name===V.name)){const K=x.selectedEntities.filter(J=>!(J.id&&J.id===V.id||J.name===V.name));y({selectedEntities:K})}else{const K=[...x.selectedEntities,V];y({selectedEntities:K})}},O=V=>{z(V)},W=V=>{var J;if(!x.selectedEntities.some(Q=>Q.id&&Q.id===V.id||Q.name===V.name)){const Q=[...x.selectedEntities,V];y({selectedEntities:Q})}const K="label"in V?V.label:V.name;t(e+`@${K} `),f(!1),(J=b.current)==null||J.focus()},B=V=>{const G=x.selectedEntities.filter(Q=>!(Q.id&&Q.id===V.id||Q.name===V.name));y({selectedEntities:G});const J=`@${"label"in V?V.label:V.name}`;e.includes(J)&&t(e.replace(J,"").trim())},Y=V=>{const G=new Set(V.map(Q=>Q.id||Q.name)),K=x.selectedEntities.filter(Q=>!G.has(Q.id||Q.name));y({selectedEntities:K});let J=e;V.forEach(Q=>{const de=`@${"label"in Q?Q.label:Q.name}`;J=J.replace(de,"").trim()}),t(J)},U=C.useCallback(()=>{x.selectedEntities.length===0&&y({selectedEntities:(R==null?void 0:R.selectedEntities)||[]})},[x.selectedEntities.length,R==null?void 0:R.selectedEntities,y]);return c.jsxs(vJe,{onFilesDropped:$,currentFileCount:M.length,disabled:s,className:"space-y-4",children:[c.jsx(iJe,{entities:x.selectedEntities,availableEntities:P||[],onRemoveEntity:B,onRemoveEntities:Y}),M.length>0&&c.jsx(Wqe,{files:M,onRemove:q,showRemove:!s,className:"mb-2"}),c.jsxs("div",{className:"rounded-lg border border-border bg-background shadow-sm focus-within:ring-1 focus-within:ring-foreground/40",children:[c.jsx("textarea",{ref:b,value:e,onChange:n,onKeyDown:F,onPaste:H,onFocus:()=>{I(),i==null||i()},placeholder:"Ask a question...",className:"max-h-[200px] min-h-[40px] w-full resize-none overflow-y-auto border-0 bg-transparent px-3 py-2 text-sm text-foreground placeholder:text-muted-foreground/50 focus:outline-none focus:ring-0",style:{height:"40px",lineHeight:"1.5"}}),c.jsxs("div",{className:"flex items-center justify-between border-foreground/10 px-3 py-2",children:[c.jsxs("div",{className:"flex items-center gap-2",children:[l==="dashboard"&&c.jsxs(Xr,{open:d,onOpenChange:V=>{V&&U(),f(V)},children:[c.jsx(Qr,{asChild:!0,children:c.jsx(se,{variant:"secondary",size:"sm",className:"h-7 px-2",title:"Add entity",children:c.jsx(Xae,{className:"h-4 w-4 text-muted-foreground"})})}),c.jsx(Jr,{className:"w-80 p-0",align:"start",side:"top",sideOffset:8,onOpenAutoFocus:V=>V.preventDefault(),children:c.jsx(sJe,{isOpen:!0,onSelect:z,onDeselect:O,onClose:()=>{var V;f(!1),(V=b.current)==null||V.focus()},availableEntities:P||[],selectedEntities:x.selectedEntities,onTabComplete:W,onSelectAll:()=>{P&&y({selectedEntities:P})},onRemoveAll:()=>{y({selectedEntities:[]})},onAddContext:()=>{f(!1),m(!0)}})})]}),c.jsx(yJe,{onFilesSelected:A,disabled:s,currentFileCount:M.length})]}),c.jsxs("div",{className:"flex items-center gap-2",children:[s&&c.jsx(se,{className:"rounded-full",size:"sm",onClick:o,children:c.jsx(mle,{className:"size-3.5 bg-background"})}),!s&&c.jsx(se,{disabled:!e.trim()&&M.length===0,size:"sm",variant:a!=="ready"?"secondary":"default",onClick:L,title:a!=="ready"?"Message will be queued":void 0,children:c.jsx(_8,{className:"size-4"})})]})]})]}),c.jsx(xA,{incomingSelectedEntities:x.selectedEntities,open:h,onOpenChange:m,dataSource:D||kC,dialogMode:"aiContext"})]})});yA.displayName="ChatInputWithContext";function Vee({assistantType:e,className:t}){const n=Aq(e),{removeFromQueue:r}=qm();return n.length===0?null:c.jsxs("div",{className:Z("space-y-2",t),children:[c.jsxs("div",{className:"flex items-center gap-1 text-xs text-muted-foreground",children:[c.jsx(Tl,{className:"h-3 w-3"}),c.jsxs("span",{children:["Pending messages (",n.length,")"]})]}),c.jsx("div",{className:"space-y-2",children:n.map(s=>c.jsx("div",{className:"group relative rounded-lg border border-dashed border-muted-foreground/30 bg-muted/30 px-3 py-2 text-sm animate-in fade-in-0 slide-in-from-bottom-1",children:c.jsxs("div",{className:"flex items-start justify-between gap-2",children:[c.jsx("div",{className:"flex-1 space-y-1",children:c.jsx("p",{className:"break-words text-foreground/70",children:s.text})}),c.jsx(se,{variant:"ghost",size:"sm",className:"h-6 w-6 p-0 opacity-0 transition-opacity group-hover:opacity-100",onClick:()=>r(e,s.id),title:"Remove from queue",children:c.jsx(yt,{className:"h-3 w-3"})})]})},s.id))})]})}function Hee({assistantType:e,status:t,isLoading:n,sendMessage:r}){const s=Aq(e),{dequeueMessage:o}=qm();C.useEffect(()=>{if(t!=="ready"||n||!(s&&s.length>0))return;const a=o(e);a&&r({role:"user",parts:[{type:"text",text:a.text}]})},[t,n,s,o,r,e])}function Uee(e,t={}){const{threshold:n=50,behavior:r="smooth",forceScrollOnStream:s=!0,isStreaming:o=!1}=t,i=C.useRef(null),[a,l]=C.useState(!0),[u,d]=C.useState(!0),[f,h]=C.useState(!1),[m,p]=C.useState(0),g=C.useRef(0),b=C.useRef(!1),x=C.useRef(0),y=C.useRef(a),v=C.useRef(void 0),w=C.useRef({key:null,count:0,length:0}),N=C.useCallback(()=>{const _=i.current;return _?_.scrollHeight-_.scrollTop-_.clientHeight:0},[]),S=C.useCallback((_={})=>{if(!i.current)return;const{force:M=!1,instant:D=!1}=_;if(!M&&!y.current||!a&&!M)return;const R=D||r==="auto"||r==="instant"?"auto":r;v.current&&cancelAnimationFrame(v.current),b.current=!0,v.current=requestAnimationFrame(()=>{if(!M&&!y.current){b.current=!1,v.current=void 0;return}const P=i.current;if(!P){b.current=!1,v.current=void 0;return}const I=P.scrollHeight;R==="smooth"&&"scrollTo"in P?P.scrollTo({top:I,behavior:R}):P.scrollTop=I,g.current=P.scrollTop,d(!0),l(!0),y.current=!0,h(!1),p(0),b.current=!1,v.current=void 0})},[r,a]),j=C.useCallback(()=>{const _=i.current;if(!_)return;const k=g.current,M=_.scrollTop,D=M-k;if(g.current=M,D<-1){v.current&&(cancelAnimationFrame(v.current),v.current=void 0),b.current=!1,y.current=!1,l(!1),d(!1);return}if(b.current)return;const R=N()<=n;d(R),l(R),y.current=R,R&&(h(!1),p(0))},[N,n]),E=C.useCallback(()=>{p(0),h(!1)},[]);return C.useEffect(()=>{y.current=a},[a]),C.useEffect(()=>{const _=i.current;if(!_||!e||e.length===0){h(!1),p(0),w.current={key:null,count:0,length:0},g.current=_?_.scrollTop:0,x.current=_?_.scrollHeight:0;return}g.current=_.scrollTop,x.current=_.scrollHeight;const k=w.current,M=e[e.length-1],D=(M==null?void 0:M.id)??(M==null?void 0:M.messageId)??(M==null?void 0:M.createdAt)??(M==null?void 0:M.timestamp)??e.length,R=Array.isArray(M==null?void 0:M.parts)?M.parts.reduce(($,A)=>A?typeof A=="string"?$+A.length:typeof A.text=="string"?$+A.text.length:typeof A.content=="string"?$+A.content.length:typeof A.value=="string"?$+A.value.length:$:$,0):typeof(M==null?void 0:M.content)=="string"?M.content.length:typeof(M==null?void 0:M.text)=="string"?M.text.length:0,P=e.length>k.count,I=D!==k.key,L=R>k.length,F=s&&(M==null?void 0:M.role)==="assistant"&&!P&&(I||L),H=o||F;if(w.current={key:D,count:e.length,length:R},a&&(P||I||L||H)){S({force:!1,instant:H});return}if(!a&&P){const $=e.length-k.count;$>0&&(h(!0),p(A=>A+$))}else!a&&L&&(h(!0),p($=>$>0?$:1))},[e,S,a,s,o]),C.useEffect(()=>{S({instant:!0})},[S]),C.useEffect(()=>{if(typeof ResizeObserver>"u")return;const _=i.current;if(!_)return;x.current=_.scrollHeight;const k=new ResizeObserver(()=>{const M=i.current;if(!M)return;const D=x.current,R=M.scrollHeight;x.current=R,!b.current&&y.current&&R>D&&S({force:!1,instant:!0})});return k.observe(_),()=>{k.disconnect()}},[S]),C.useEffect(()=>()=>{v.current&&cancelAnimationFrame(v.current)},[]),{scrollRef:i,isAutoScrollEnabled:a,isAtBottom:u,hasNewMessages:f,newMessageCount:m,scrollToBottom:S,handleScroll:j,resetNewMessageCount:E}}function Wee(e,t={}){const{maxVisibleMessages:n=50,initialLoadCount:r=20,loadMoreCount:s=10}=t,[o,i]=C.useState(r),a=C.useMemo(()=>{if(e.length<=o)return e;const h=Math.max(0,e.length-o);return e.slice(h)},[e,o]),l=e.length>o,u=o>=e.length,d=C.useCallback(()=>{i(h=>Math.min(h+s,n))},[s,n]),f=C.useCallback(()=>{i(r)},[r]);return C.useEffect(()=>{u&&e.length>o&&o<n&&i(Math.min(e.length,n))},[e.length,o,u,n]),{visibleMessages:a,hasMoreMessages:l,totalMessageCount:e.length,loadMoreMessages:d,resetMessageWindow:f,isShowingAll:u}}function qee(e){var n;if(!e||e.length===0)return{hasActiveTools:!1};const t=e[e.length-1];if(!(t!=null&&t.parts))return{hasActiveTools:!1};for(const r of t.parts){if(r.type==="reasoning"&&"state"in r&&r.state==="streaming")return{hasActiveTools:!0,activeToolText:r.text||"Reasoning...",toolType:"reasoning"};if(((n=r.type)!=null&&n.startsWith("tool-")||r.type==="dynamic-tool")&&"state"in r&&["input-streaming","input-available"].includes(r.state)){const s=r,o=s.state;return{hasActiveTools:!0,activeToolText:kJ(s.type,o),toolType:s.type}}}return{hasActiveTools:!1}}const wJe=[{title:"Show top 3 insights",subtitle:"from this dataset"},{title:"Create a bar chart for",subtitle:"sales by product category"}];function SJe({open:e,setOpen:t,isFullscreen:n,onFullscreenChange:r,fullscreenContainer:s}){const[o,i]=C.useState(!1),[a,l]=C.useState(rD),[u,d]=C.useState(!1),[f,h]=C.useState(!1),[m,p]=C.useState(!1),g=n??m,{isLocalDev:b,isConsoleMode:x}=xm(),y=C.useRef(null);X(He=>He.dashboard.aiScopeTables),X(He=>He.isDashboardEditing);const v=X(He=>He.selectedSheetId),{setDataSource:w}=Qn(),{addFrame:N,setSelectedFrameId:S,setIsDashboardEditing:j}=Ot(),E=Wm(),{setCurrentAIContext:_,updateSelectedEntities:k,setReasoningEffort:M,setShowReasoning:D}=_S(),{clearQueue:R}=qm(),{clearFileAttachments:P,getFileAttachments:I}=BT(),L=zT("dashboard"),F=X(He=>He.dashboard.aiContext),H=_e(He=>He.card.dataSource),{assistantProfile:$}=Fee(),A=X(He=>He.handleOpenAssistantProfile),{sendMessage:q,isLoading:z,messages:O,setMessages:W,status:B,stop:Y,errorMessage:U,clearError:V}=rJe(),G=C.useCallback(He=>{r==null||r(He),n===void 0&&p(He)},[n,r]),K=C.useCallback(()=>{G(!g)},[g,G]);C.useEffect(()=>{if(!g)return;function He(Jt){Jt.key==="Escape"&&G(!1)}return window.addEventListener("keydown",He),()=>{window.removeEventListener("keydown",He)}},[g,G]);const[J,Q]=C.useState(""),re=He=>{Q(He.target.value)};function de({sql:He,cardTitle:Jt,connectionId:Ke,cardType:Qe,python:Le,cardConfig:ve,dataSource:Be,customVisualPreferences:we}){if(!v)return;const We={id:vr(),title:Jt||"Title",preferences:{onClickFilter:[{columnIndex:0,expression:""}],chartOptions:{indexAxis:Qe==="horizontalBar"?"y":"x"}},type:Qe,sql:He,python:Le,dataSource:Be,config:ve,connectionId:Ke,customCardPreferences:we?{url:we.url,componentName:we.componentName,pluginChartType:we.pluginChartType,settings:we.settings,type:"component"}:void 0},at={id:vr(),cards:[We],activeCardId:We.id};j(!0),N(v,at,"end"),S(at.id)}const fe=He=>{He.preventDefault();const Jt=J.trim();if(!Jt&&L.length===0)return;const Ke=[];Jt&&Ke.push({type:"text",text:Jt}),L.forEach(Qe=>{Qe.data&&Ke.push({type:"file",mediaType:Qe.type,filename:Qe.name,url:`data:${Qe.type};base64,${Qe.data}`})}),q({role:"user",parts:Ke}),Q(""),P("dashboard"),ie({force:!0})};C.useEffect(()=>{var He;e&&((He=y.current)==null||He.focus())},[e]),Hee({assistantType:"dashboard",status:B,isLoading:z,sendMessage:q});const{hasActiveTools:ue}=qee(O),{visibleMessages:je,hasMoreMessages:me,totalMessageCount:ne,loadMoreMessages:oe,resetMessageWindow:pe}=Wee(O,{maxVisibleMessages:15,initialLoadCount:10,loadMoreCount:5}),{scrollRef:De,isAtBottom:ae,hasNewMessages:Te,newMessageCount:Ue,scrollToBottom:ie,handleScroll:xe,resetNewMessageCount:$e}=Uee(je,{threshold:50,behavior:"smooth",isStreaming:z});function he(He){Ae();const Jt={role:"user",parts:[{type:"text",text:He.title+" "+He.subtitle}]};q(Jt)}function Ee(He){Ae(),q({role:"user",parts:[{type:"text",text:He}]})}function Ve(He){Ae(),q({role:"user",parts:[{type:"text",text:He}]}),ie({force:!0})}const qe=C.useCallback(async()=>{const He=JSON.stringify(O??[],null,2);try{if(typeof navigator>"u"||!navigator.clipboard)throw new Error("Clipboard API unavailable");await navigator.clipboard.writeText(He),Oe.success("Conversation copied")}catch(Jt){console.error("Failed to copy conversation",Jt),Oe.error("Unable to copy conversation")}},[O]);function Ae(){E.selectedEntities.length===0&&_({selectedEntities:(F==null?void 0:F.selectedEntities)||[]})}const xt=(J==null?void 0:J.length)===0&&(O==null?void 0:O.filter(He=>He.role==="user").length)===0;function Ce(){return c.jsx("div",{"data-role":"header",children:c.jsx("div",{className:"text-lg font-semibold",children:"Assistant"})})}function mt(){return c.jsxs(gm,{children:[c.jsx(bm,{asChild:!0,children:c.jsx(Ec,{className:"h-7 p-2 text-muted-foreground hover:text-foreground",children:c.jsx(lm,{className:"size-3.5"})})}),c.jsxs(rf,{align:"end",children:[c.jsx(sh,{children:"Options"}),c.jsx(Ad,{}),c.jsx(fg,{checked:o,onCheckedChange:i,children:"Token Usage"}),c.jsx(fg,{checked:a,onCheckedChange:l,children:"Tool Invocations"}),c.jsx(fg,{checked:u,onCheckedChange:d,children:"System Message"})]})]})}const _t=c.jsxs("div",{"data-role":"dashboard-assistant",className:Z("flex h-full grow flex-col justify-between break-words px-6 py-4",g&&"rounded-2xl border border-border/60 bg-background px-8 pb-6 pt-6 shadow-xl"),children:[c.jsxs("div",{"data-role":"header-section",className:"flex items-start justify-between gap-2",children:[Ce(),A&&c.jsx(se,{variant:"outline",size:"sm",className:"h-7 p-2",onClick:A,children:($==null?void 0:$.name)||"Default Profile"}),c.jsxs("div",{"data-role":"header-actions",className:"flex items-center",children:[x&&mt(),a&&c.jsx(se,{variant:"ghost",size:"sm",className:"ml-2 h-7 px-2 text-muted-foreground hover:text-foreground",onClick:qe,children:"Copy Conversation"}),c.jsx(Ec,{className:"h-7 p-2 text-muted-foreground hover:text-foreground",tooltip:g?"Exit Fullscreen":"Expand",onClick:K,children:g?c.jsx(FD,{className:"size-4"}):c.jsx(M1,{className:"size-4"})}),c.jsx(Ec,{className:"h-7 p-2 text-muted-foreground hover:text-foreground",tooltip:"New Chat",onClick:()=>{W([]),R("dashboard"),V(),pe()},children:c.jsx(T1,{className:"size-4"})}),c.jsx(Ec,{className:"h-7 p-2 text-muted-foreground hover:text-foreground",onClick:()=>{t(!1)},children:c.jsx(yt,{className:"size-4"})})]})]}),c.jsxs(Vl,{"data-role":"dashboard-assistant-scroll-area",ref:De,className:"mt-4 flex flex-1 basis-0 flex-col flex-wrap justify-end pr-2",onScroll:xe,children:[c.jsxs("div",{className:"space-y-3 pb-4",children:[me&&c.jsx("div",{className:"flex justify-center py-2",children:c.jsxs(se,{variant:"outline",size:"sm",onClick:oe,className:"text-xs",children:["Load ",Math.min(5,ne-je.length)," ","more messages (",ne-je.length," ","hidden)"]})}),c.jsx(_J,{showTools:a,showSystemMessage:u,messages:je,onAddToDashboard:de,onQuickReply:Ve,disableQuickReplies:z}),!ue&&c.jsx(EJ,{status:B,errorMessage:U})]}),c.jsx(si,{orientation:"horizontal"})]}),e&&!ae&&c.jsx("div",{className:"absolute bottom-24 right-8 z-10",children:c.jsxs(se,{onClick:()=>{ie({force:!0}),$e()},size:"sm",variant:"secondary",className:"rounded-full shadow-lg","aria-label":"Scroll to bottom",children:[c.jsx(hr,{className:"h-4 w-4"}),Te&&Ue>0&&c.jsx("span",{className:"ml-1.5 flex h-5 w-5 items-center justify-center rounded-full bg-primary text-xs text-primary-foreground",children:Ue>9?"9+":Ue})]})}),c.jsxs("div",{className:"space-y-3",children:[!$&&xt&&c.jsx(DJ,{onClick:he,placeholders:wJe}),c.jsx("div",{children:xt&&$&&c.jsx($ee,{seedQuestions:$.seedQuestions||[],handleSeedQuestionClick:Ee})}),c.jsx(Vee,{assistantType:"dashboard",className:"mb-3"}),c.jsx(yA,{ref:y,setInput:Q,stop:Y,input:J,handleInputChange:re,handleSubmit:He=>{Ae(),fe(He),ie({force:!0})},isLoading:z,status:B,assistantType:"dashboard",onFocus:()=>{}})]}),c.jsx(xA,{incomingSelectedEntities:(F==null?void 0:F.selectedEntities)||[],open:f,onOpenChange:h,dataSource:H||kC,dialogMode:"aiContext"})]});return g&&s?Ln.createPortal(c.jsx("div",{className:"pointer-events-auto absolute inset-0 z-50 flex bg-background px-6 pb-6 pt-[calc(var(--app-header-height,15px)+1rem)]",children:c.jsx("div",{className:"flex h-full w-full",children:_t})}),s):_t}function CJe(e){const t=e.current,{getSelectedFrame:n,addFrame:r,setSelectedFrameId:s}=Ot(),o=X(d=>d.dashboard.sheets),a=X(d=>d.selectedSheetId)??(o==null?void 0:o[0].id),l=X(d=>d.isDashboardEditing),u=X(d=>d.isVisualEditing);C.useEffect(()=>{if(!l||u)return;async function d(m){const p=m.ctrlKey||m.metaKey;p&&m.key==="c"?(await f(),Oe.success("Card copied to clipboard"),m.preventDefault()):p&&m.key==="v"&&(await h(),m.preventDefault())}async function f(){try{const m=n();m&&await navigator.clipboard.writeText(JSON.stringify(m))}catch(m){console.error("Failed to copy text:",m)}}async function h(){if(!a)return null;try{const m=await navigator.clipboard.readText();try{const p=JSON.parse(m);if(p!=null&&p.id){const g=dI(p),b=g.cards.findIndex(x=>x.id===g.activeCardId);b!==-1&&(g.cards[b].title=`${g.cards[b].title} (Copy)`),r(a,g),s(g.id),Oe.success("Card pasted from clipboard")}}catch(p){console.error("Failed to parse clipboard contents: ",p)}return m}catch(m){return console.error("Failed to paste text:",m),null}}return t==null||t.addEventListener("keydown",d),()=>t==null?void 0:t.removeEventListener("keydown",d)},[r,n,s,a,l,u,t])}function NJe(e,t){switch(e.interactionMode){case"drillToDetail":jJe(e,t);break;case"drillThrough":kJe(e,t);break;case"drillToURL":EJe(e);break;case"inlineDrill":console.warn("Inline drill execution not yet implemented");break;case"clickFilter":case"drillDown":case"dynamicDrill":break;default:console.warn("Unknown interaction mode:",e.interactionMode)}}function jJe(e,t){var l;const{targetInsightId:n,contextMode:r,displayMode:s,filterGroups:o}=e;if(!n){console.warn("drillToDetail event missing targetInsightId");return}const i=r||"full";let a=[];switch(i){case"interactionFilters":a=o.flatMap(u=>u.filters);break;case"full":{const u=((l=t.getCurrentFilters)==null?void 0:l.call(t))||[],d=o.flatMap(f=>f.filters);a=[...u,...d];break}case"none":default:a=[];break}s==="replace-card"?t.replaceCardContent({cardId:e.sourceCardId,insightId:n,filters:a,contextMode:r}):t.openInsightModal({insightId:n,filters:a,contextMode:r})}function kJe(e,t){var u,d;const{targetDashboardId:n,contextMode:r="interactionFilters",filterGroups:s,sourceCardId:o}=e;if(!n){console.warn("[DrillThrough] Event missing targetDashboardId. This interaction needs to be reconfigured with a target dashboard.",e);return}const i=s.flatMap(f=>f.filters),a=((u=t.getCurrentDashboardId)==null?void 0:u.call(t))||"",l=(d=t.getCurrentDashboardTitle)==null?void 0:d.call(t);t.setGlobalDrillContext&&t.setGlobalDrillContext({filters:i,contextMode:r,sourceDashboardId:a,sourceDashboardTitle:l,targetDashboardId:n}),t.setPendingDrillThrough&&t.setPendingDrillThrough({targetDashboardId:n,sourceDashboardId:a,sourceDashboardTitle:l,filters:i,contextMode:r})}function EJe(e){const{url:t}=e;if(!t){console.warn("drillToURL event missing url");return}try{new URL(t)}catch(n){console.error("Invalid URL:",t,n);return}window.open(t,"_blank","noopener,noreferrer")}function _Je({open:e,onOpenChange:t,insightId:n,filters:r,filterDefinitions:s,contextMode:o,cardTitle:i,cardDescription:a}){return c.jsx(ns,{open:e,onOpenChange:t,children:c.jsxs(Vr,{className:"max-h-[90vh] max-w-[90vw] p-6",children:[c.jsxs(Hr,{children:[c.jsx(Ur,{children:i||"Insight Detail"}),c.jsx(ys,{children:a||"View detailed insight data with applied filters"})]}),c.jsx(GZ,{filters:r,filterDefinitions:s,contextMode:o}),c.jsx("div",{className:"h-[400px] flex-1 overflow-auto",children:n?c.jsx(QZ,{insightId:n,filters:r,contextMode:o}):c.jsx("div",{className:"flex items-center justify-center p-12 text-muted-foreground",children:"No insight selected"})})]})})}function DJe(){const e=It(w=>w.interactionStates),t=It(w=>w.setInteractionState),n=It(w=>w.clearLastInteractionEvent),r=It(w=>w.replaceCardWithInsight),s=It(w=>w.setPendingDrillThrough),o=It(w=>w.pendingDrillThrough),i=It(w=>w.clearPendingDrillThrough),{setSelectedSheetId:a,navigateWithDrill:l}=Ot(),{selectDashboard:u}=tx(),d=X(w=>w.dashboard),f=X(w=>w.filterValues),{data:h,isLoading:m}=H7((o==null?void 0:o.targetDashboardId)||"",{enabled:!!(o!=null&&o.targetDashboardId)}),[p,g]=C.useState({open:!1,insightId:""}),b=JZ(p.insightId,{enabled:p.open&&!!p.insightId}),x=C.useRef(new Set),y=C.useMemo(()=>({setSelectedSheetId:a,openInsightModal:({insightId:w,filters:N,contextMode:S})=>{g({open:!0,insightId:w,filters:N,filterDefinitions:(d==null?void 0:d.filters)||[],contextMode:S})},replaceCardContent:({cardId:w,insightId:N,filters:S,contextMode:j})=>{r(w,N,S,j)},getCurrentFilters:()=>f||[],navigateWithDrill:l,getCurrentDashboardId:()=>(d==null?void 0:d.id)||"",getCurrentDashboardTitle:()=>d==null?void 0:d.title,setPendingDrillThrough:s,setGlobalDrillContext:({filters:w,contextMode:N,sourceDashboardId:S,sourceDashboardTitle:j,targetDashboardId:E})=>{const k={sourceCardId:ga,interactionMode:"clickFilter",filterGroups:[{filters:w}]},M={...Wo(),appliedClickFilters:[k],contextMode:N,sourceDashboardId:S,sourceDashboardTitle:j,targetDashboardId:E};t(ga,M)}}),[a,r,f,l,d,s,t]);C.useEffect(()=>{Object.entries(e).forEach(([w,N])=>{if(N!=null&&N.lastInteractionEvent){const S=N.lastInteractionEvent,j=`${w}-${S.interactionMode}-${S.sourceCardId}-${Date.now()}`;if(x.current.has(j))return;x.current.add(j);try{NJe(S,y)}catch(E){console.error("Error executing interaction event:",E)}finally{n(w),setTimeout(()=>{x.current.delete(j)},5e3)}}})},[e,n,y]),C.useEffect(()=>{if(!(!o||!h||m))try{u(h),l(o.targetDashboardId,o.sourceDashboardId,o.sourceDashboardTitle,o.filters,o.contextMode),i()}catch(w){console.error("[DrillThrough] Error during automatic navigation:",w),i()}},[o,h,m,u,l,i]);const v=()=>{g({open:!1,insightId:""})};return c.jsxs(c.Fragment,{children:[c.jsx(_Je,{open:p.open,onOpenChange:v,insightId:p.insightId,filters:p.filters,filterDefinitions:p.filterDefinitions,contextMode:p.contextMode,cardTitle:b.title,cardDescription:b.description}),o&&m&&c.jsx("div",{className:"fixed inset-0 z-[51] flex items-center justify-center bg-background/80 backdrop-blur-sm",children:c.jsxs("div",{className:"flex flex-col items-center gap-3 rounded-lg border bg-background p-6 shadow-lg",children:[c.jsx(an,{className:"h-8 w-8 animate-spin text-primary"}),c.jsx("div",{className:"text-sm text-muted-foreground",children:"Loading dashboard..."})]})})]})}function MJe(e){return e.length===0?"":e.map(t=>{const n=t.field.label||t.field.name,r=t.operator,s=TJe(t.value);return r==="="?`${n} = ${s}`:`${n} ${r} ${s}`}).join(", ")}function TJe(e){return e==null?"null":Array.isArray(e)?e.join(", "):typeof e=="object"&&e.toString?e.toString():String(e)}function RJe(e){return e?`Back to ${e}`:"Back"}function IJe(){var x,y,v,w,N;const e=It(S=>S.interactionStates[ga]),t=X(S=>S.actions.goBackFromDrill),n=X(S=>S.actions.clearDrillContext),{selectDashboard:r}=tx(),[s,o]=C.useState({x:16,y:16}),[i,a]=C.useState(!1),l=C.useRef({x:0,y:0});C.useEffect(()=>{if(!i)return;const S=E=>{o({x:E.clientX-l.current.x,y:E.clientY-l.current.y})},j=()=>{a(!1)};return document.addEventListener("mousemove",S),document.addEventListener("mouseup",j),()=>{document.removeEventListener("mousemove",S),document.removeEventListener("mouseup",j)}},[i]);const u=e==null?void 0:e.sourceDashboardId,d=e==null?void 0:e.sourceDashboardTitle,f=((w=(v=(y=(x=e==null?void 0:e.appliedClickFilters)==null?void 0:x[0])==null?void 0:y.filterGroups)==null?void 0:v[0])==null?void 0:w.filters)||[],h=u?{id:u,title:d||"Previous Dashboard",description:"",isPrivate:!1,isPublic:!1,version:"",createdBy:null,createdByTenantUser:"",tenantId:"",projectId:"",createdAt:"",updatedAt:"",lastModified:"",lastModifiedBy:"",createdByUser:null,createdByTenantUserRel:{name:"",email:""},permissions:{canEdit:!0,canShare:!0,canDelete:!0},ownership:{status:"private",isOwner:!0,sharedCount:0,createdBy:{type:"user",userId:"",name:"",email:""}}}:null;if(!e||!((N=e.appliedClickFilters)!=null&&N.length))return null;const m=()=>{if(!h){console.warn("[DrillBack] No source dashboard in context");return}try{t(),r(h)}catch(S){console.error("[DrillBack] Error during back navigation:",S)}},p=()=>{n()},g=S=>{S.target.closest("button")||(a(!0),l.current={x:S.clientX-s.x,y:S.clientY-s.y})};MJe(f);const b=RJe(d);return c.jsx("div",{className:"fixed z-50 max-w-md",style:{left:0,top:0,transform:`translate(${s.x}px, ${s.y}px)`,transition:i?"none":void 0},children:c.jsxs("div",{className:"select-none rounded-lg border bg-background/95 p-3 shadow-lg backdrop-blur-sm",onMouseDown:g,style:{cursor:i?"grabbing":"grab"},children:[c.jsxs("div",{className:"mb-3 flex items-start justify-between gap-2",children:[c.jsxs("div",{className:"flex flex-col gap-2",children:[c.jsx("span",{className:"text-xs font-medium text-muted-foreground",children:"Viewing:"}),c.jsx("div",{className:"flex flex-wrap gap-2",children:f.map((S,j)=>{const E=S.field.label||S.field.name,_=String(S.value);return c.jsxs(Fe,{variant:"secondary",className:"pointer-events-none text-xs",children:[E," = ",_]},j)})})]}),c.jsx(se,{variant:"ghost",size:"sm",onClick:p,className:"h-6 w-6 cursor-pointer p-0",title:"Clear drill context",children:c.jsx(yt,{className:"h-3 w-3"})})]}),c.jsx("div",{className:"flex items-center gap-2 border-t pt-2",children:c.jsxs(se,{variant:"secondary",size:"sm",onClick:m,disabled:!h,className:"w-full cursor-pointer",children:[c.jsx(l8,{className:"mr-2 h-4 w-4"}),b]})})]})})}function Yee(){var me;const{showAssistant:e,tokenProps:t}=Ge(),{preferences:n,isConsoleMode:r}=xm(),s=((me=n==null?void 0:n.cardDisplay)==null?void 0:me.mode)==="print",o=C.useRef(null),i=C.useRef(null),[a,l]=C.useState(!1),{handleDragStart:u,isDraggingRef:d,getStyle:f,getPositionClasses:h}=$8e({initialPosition:"bottom-right"}),m=vd(ne=>ne.setFullscreen),p=vd(ne=>ne.setPanelOpen),g=vd(ne=>ne.setContainer),b=Mq("dashboard"),x=Tq(),y=Rq("dashboard"),v=b.isOpen,w=x==="dashboard",N=X(ne=>ne.isVisualEditing),S=X(ne=>ne.themeStyle),j=X(ne=>{var oe;return(oe=ne.dashboard)==null?void 0:oe.sheets}),E=X(ne=>ne.showFilters),_=X(ne=>ne.isDashboardEditing),k=X(ne=>ne.selectedSheetId),M=X(ne=>{var oe;return(oe=ne.dashboard)==null?void 0:oe.id}),D=X(ne=>ne.isDashboardPanelOpen),R=X(ne=>ne.actions.setIsDashboardPanelOpen),{getDefaultSheetId:P,setDefaultSheetId:I,clearDefaultSheetId:L}=r8(M),[F,H]=C.useState(null);W1(Pt.DASHBOARD);const{setSelectedSheetId:$,setSheetTitle:A,addSheet:q,setSheets:z}=Ot();CJe(i);const{setActiveAssistantType:O}=_S();C.useEffect(()=>{if(M){const ne=P();H(ne)}},[M,P]),C.useEffect(()=>{v?O("dashboard"):x==="dashboard"&&m(null)},[v,O,x,m]),C.useEffect(()=>{var ne;v||(ne=o.current)==null||ne.resize(0)},[v]);function W(ne){var oe,pe;ne?((oe=o.current)==null||oe.resize(40),p("dashboard",!0),O("dashboard")):(p("dashboard",!1),m(null),(pe=o.current)==null||pe.resize(0),O(null))}function B(){const ne={id:vr(),title:"New Sheet"};q(ne),$(ne.id)}function Y(ne,oe){if(!M)return;F===ne?(L(),H(null),Oe.success("Default sheet cleared")):(I(ne),H(ne),Oe.success(`"${oe}" set as default sheet`))}function U(ne){var oe;ne<1?(p("dashboard",!1),m(null),O(null),(oe=o.current)==null||oe.resize(0)):(v||p("dashboard",!0),O("dashboard"))}function V(){return(S==null?void 0:S.canvasTheme)==="muted"||!(S!=null&&S.canvasTheme)?"hsl(var(--semaphor-muted))":(S==null?void 0:S.canvasTheme)==="clear"?"":S==null?void 0:S.canvasTheme}const G=(ne,oe)=>{ne.dataTransfer.setData("tabIndex",oe.toString())},K=ne=>{ne.preventDefault()},J=(ne,oe)=>{const pe=ne.dataTransfer.getData("tabIndex");if(pe===oe.toString())return;const De=Array.from(j||[]),[ae]=De.splice(parseInt(pe),1);De.splice(oe,0,ae),z(De)},Q=t.orgUserId||t.tenantId&&t.endUserId&&t.endUserEmail,re=e===!0&&!s&&!v&&!N&&!E;function de(){var ne,oe;if(j&&j.length>1||_)return c.jsxs(vs,{role:"tab-list",className:"flex h-11 items-center justify-start gap-2 rounded-none border-b border-b-muted bg-transparent px-2.5 py-3",children:[r&&Q&&c.jsx(se,{variant:"outline","aria-label":"Manage Dashboards and Visuals",onClick:()=>{R(!D)},className:"h-8 p-2",children:D?c.jsx(h8,{className:"h-4 w-4"}):c.jsx(m8,{className:"h-4 w-4"})}),j==null?void 0:j.map((pe,De)=>{const ae=k===pe.id,Te=F===pe.id;return c.jsxs(Gt,{draggable:!0,onDragStart:Ue=>G(Ue,De),onDragOver:K,onDrop:Ue=>J(Ue,De),style:{borderRadius:S==null?void 0:S.controlInputRadius},onClick:()=>$(pe.id),className:"flex items-center gap-1 rounded-none border px-2 py-1",value:pe.id,children:[c.jsx(jb,{enabled:_&&ae,text:pe.title,onSave:Ue=>A(pe.id,Ue),children:pe.title},pe.id),!_&&ae&&c.jsx("div",{title:Te?"Clear default sheet":"Set as default sheet",children:c.jsx(VD,{className:Z("ml-1 size-3 cursor-pointer transition-all",Te?"fill-yellow-500 text-yellow-500":"text-muted-foreground hover:text-foreground"),onClick:Ue=>{Ue.stopPropagation(),Y(pe.id,pe.title||"Sheet")}})}),_&&ae&&j.length>1&&c.jsx(yt,{className:"ml-1 size-3",onClick:()=>l(!0)})]},pe.id)}),_&&c.jsx("div",{style:{borderRadius:(oe=(ne=S==null?void 0:S.chart)==null?void 0:ne.options)==null?void 0:oe.borderRadius},className:"flex h-7 items-center justify-center border-none bg-muted p-2 hover:cursor-pointer dark:border-l-background",onClick:B,children:c.jsx(Sr,{className:"size-3"})})]})}function fe(){return c.jsx("div",{ref:i,style:{},className:"grow",children:j==null?void 0:j.map(ne=>c.jsx(sr,{style:{backgroundColor:V()},className:Z("mt-0",{}),value:ne.id,children:c.jsx(l8e,{sheet:ne})},ne.id))})}function ue(){var ne;return c.jsxs(Bs,{"data-role":"dashboard-tabs-container",className:Z("relative flex h-full flex-col",S==null?void 0:S.dashboardTabsContainer),onValueChange:oe=>{$(oe)},value:k||((ne=j==null?void 0:j[0])==null?void 0:ne.id),children:[de(),c.jsx(Vl,{"data-role":"dashboard-tabs-content",className:"flex-1 grow basis-0 overflow-y-auto",children:fe()}),c.jsx(L8e,{open:a,setOpen:l})]})}const je=C.useCallback(ne=>{g("dashboard",ne)},[g]);return j?c.jsxs(c.Fragment,{children:[c.jsx(DJe,{}),c.jsx(IJe,{}),c.jsxs("div",{className:"relative flex-1 basis-0 overflow-hidden",children:[c.jsxs(cQ,{className:Z("flex-1 basis-0 overflow-y-auto transition-opacity",w&&"pointer-events-none opacity-0"),direction:"horizontal",children:[c.jsx(x_,{children:ue()}),e===!0&&c.jsxs(c.Fragment,{children:[c.jsx(F8e,{open:v,onTabClick:W,withHandle:!0,disabled:!v}),c.jsx(x_,{className:"flex grow","data-role":"dashboard-assistant-panel",onResize:U,defaultSize:v?40:0,ref:o,children:c.jsx("div",{className:"grow overflow-y-auto",children:c.jsx(SJe,{open:v,setOpen:W,isFullscreen:w,onFullscreenChange:ne=>m(ne?"dashboard":null),fullscreenContainer:y})})})]})]}),c.jsx("div",{ref:je,className:Z("absolute inset-0",!w&&"pointer-events-none")}),re&&c.jsx("div",{className:Z("absolute z-50 transition-all duration-300 ease-in-out",h().horizontal,h().vertical),style:f(),children:c.jsx(se,{size:"sm",variant:"outline",className:"h-12 w-12 cursor-grab rounded-full border-border bg-background p-0 shadow-lg hover:bg-muted active:cursor-grabbing",onClick:()=>{d.current||W(!0)},onMouseDown:u,onTouchStart:u,title:"Open Assistant (drag to move)",children:c.jsx(BD,{className:"h-5 w-5"})})})]})]}):null}function vA({children:e}){return c.jsx(Fa,{style:{height:"100%",width:"100%"},children:c.jsx(dae,{defaultTheme:"system",storageKey:"vite-ui-theme",children:c.jsx(_n,{delayDuration:0,children:e})})})}function Gee({children:e,preferences:t}){const{currentUser:n}=oo(),r=C.useMemo(()=>{var s,o;return{preferences:t||{},isLocalDev:((s=t==null?void 0:t.uiMode)==null?void 0:s.developer)||!1,isConsoleMode:((o=t==null?void 0:t.uiMode)==null?void 0:o.console)||!1}},[t]);return c.jsx(v7.Provider,{value:r,children:c.jsx(wI,{displayPreferences:t==null?void 0:t.cardDisplay,currentUser:n,children:e})})}function AJe(e=2e3,t=500){const n=zae(),[r,s]=C.useState(!1),[o,i]=C.useState(!1),a=C.useRef(null);return C.useEffect(()=>{const l=setTimeout(()=>s(!0),e);return()=>clearTimeout(l)},[e]),C.useEffect(()=>{if(r){if(n>0){i(!1),a.current&&(clearTimeout(a.current),a.current=null);return}return a.current&&clearTimeout(a.current),a.current=setTimeout(()=>{i(!0)},t),()=>{a.current&&clearTimeout(a.current)}}},[r,n,t]),o}function wA({delayMs:e=2e3,quietMs:t=500,componentType:n,componentId:r}){const s=AJe(e,t);return C.useEffect(()=>(s&&(window.__SEMAPHOR_READY__={ready:!0,type:n,componentId:r||null,timestamp:Date.now()}),()=>{window.__SEMAPHOR_READY__={ready:!1,type:n,componentId:r||null,timestamp:Date.now()}}),[s,n,r]),c.jsx("div",{id:"idle-check","aria-hidden":"true",style:{position:"absolute",width:1,height:1,padding:0,margin:-1,overflow:"hidden",clip:"rect(0, 0, 0, 0)",whiteSpace:"nowrap",border:0},children:s?"ready":""})}function Kee(e){if(typeof window>"u")return null;const{preferences:t}=e;return c.jsx(Ua,{FallbackComponent:eC,children:c.jsxs(jD,{dashboardProps:e,children:[c.jsx(wA,{componentType:"dashboard",componentId:e.id}),c.jsx(vA,{children:c.jsx(Gee,{preferences:t,children:c.jsx("main",{className:"flex h-full flex-col",children:c.jsx(VT,{...e,type:"dashboard",children:c.jsx(Yee,{})})})})})]})})}function SA(e){const{tokenProps:t,authToken:n}=Ge(),r=t==null?void 0:t.apiServiceUrl;return hn({queryKey:["joinability-map",e],queryFn:async()=>{if(!e||!(n!=null&&n.accessToken))return null;const s=`${r}/v1/domains/${e}/joinability`;return qn(s,n.accessToken)},enabled:!!e&&!!(n!=null&&n.accessToken)&&!!r,staleTime:5*60*1e3,gcTime:10*60*1e3,retry:2,retryDelay:s=>Math.min(1e3*2**s,3e4)})}function Zee(e,t,n){if(t==="source")return{isValid:!0};const r=Tr(e.dataType);if(n==="kpi"){if(t==="groupBy"&&r!=="date")return{isValid:!1,reason:"KPI Trend By only accepts date fields"};if(t==="metrics"&&r==="date")return{isValid:!1,reason:"KPI metrics cannot be date fields"}}return{isValid:!0}}function Xee(e,t,n,r,s){if(e!=="kpi"||s.length<3)return;const o=(t==null?void 0:t.groupByColumns)&&t.groupByColumns.length>0,i=(t==null?void 0:t.comparisonType)==="none";!o&&i||n(r,{groupByColumns:[],comparisonType:"none"})}const Qee=e=>{var R;const t=(R=e==null?void 0:e.dataSource)==null?void 0:R.semanticDomainId,{data:n}=SA(t),{updateCardConfig:r,updateGroupByColumn:s,updateMetricColumn:o,updatePivotByColumn:i,updateSortByColumn:a,removeGroupByColumn:l,removeMetricColumn:u,removePivotByColumn:d,removeSortByColumn:f}=Qn(),h=_e(P=>P.card.type),m=e==null?void 0:e.id,p=C.useCallback(P=>{if(!(e!=null&&e.config))return[];switch(P){case"groupBy":return(e.config.groupByColumns||[]).map(I=>({id:I.id,name:I.name,dataType:I.dataType,label:I.label!==void 0?I.label:I.name,qualifiedEntityName:I.qualifiedEntityName,entityId:I.entityId,entityName:I.entityName,entityType:I.entityType,dateFormat:I.dateFormat,customFormat:I.customFormat,granularity:I.granularity}));case"metrics":return e.config.metricColumns||[];case"pivotBy":return(e.config.pivotByColumns||[]).map(I=>({id:I.id,name:I.name,dataType:I.dataType,label:I.label!==void 0?I.label:I.name,qualifiedEntityName:I.qualifiedEntityName,entityId:I.entityId,entityName:I.entityName,entityType:I.entityType}));case"sortBy":return(e.config.sortByColumns||[]).map(I=>({id:I.id,name:I.name,dataType:I.dataType,label:I.label!==void 0?I.label:I.name,qualifiedEntityName:I.qualifiedEntityName,entityId:I.entityId,entityName:I.entityName,entityType:I.entityType,direction:I.direction}));case"source":return[];default:return[]}},[e]),g=C.useCallback((P,I)=>{if(m)switch(P){case"groupBy":{r(m,{groupByColumns:I});break}case"metrics":{r(m,{metricColumns:I});break}case"pivotBy":{r(m,{pivotByColumns:I});break}case"sortBy":{r(m,{sortByColumns:I});break}}},[m,r]),b=C.useCallback((P,I,L)=>{if(!m)return;const H=p(P)[I];if(H)switch(P){case"groupBy":s(m,H.id,{label:L});break;case"metrics":o(m,H.id,{label:L});break;case"pivotBy":i(m,H.id,{label:L});break;case"sortBy":a(m,H.id,{label:L});break}},[m,p,s,o,i,a]),x=C.useCallback((P,I)=>{if(!m)return;const F=p("metrics")[P];F&&o(m,F.id,{aggregate:I,label:OU(F.name,I)})},[m,p,o]),y=C.useCallback((P,I,L)=>{if(!m)return;const H=p("groupBy")[P];if(!H)return;const $={dateFormat:I};I==="custom"&&L?$.customFormat=L:$.customFormat=void 0,s(m,H.id,$)},[m,p,s]),v=C.useCallback((P,I)=>{if(!m)return;const F=p("groupBy")[P];F&&s(m,F.id,{granularity:I})},[m,p,s]),w=C.useCallback((P,I)=>{if(!m)return;const F=p("metrics")[P];F&&o(m,F.id,{aliasTemplate:I})},[m,p,o]),N=C.useCallback((P,I)=>{if(console.log("handleValueAliasesChange",P,I),!m)return;console.log("handleValueAliasesChange",P,I);const F=p("metrics")[P];F&&(console.log("handleValueAliasesChange",I),o(m,F.id,{valueAliases:I}))},[m,p,o]),S=C.useCallback(P=>{if(!m)return;if(p("metrics").length===0){Oe.error("Add Metric First",{description:"Please add a metric field before selecting a comparison type",position:"top-center",duration:3e3});return}r(m,{comparisonType:P})},[m,r,p]),j=C.useCallback(P=>{m&&r(m,{showTrendline:P})},[m,r]),E=C.useCallback(P=>{m&&r(m,{trendlineWindow:P})},[m,r]),_=C.useCallback(P=>{m&&r(m,{trendlineGranularity:P})},[m,r]),k=C.useCallback(P=>{m&&r(m,{targetValue:P})},[m,r]),M=C.useCallback(P=>{var q;if(!m)return;const I=[...p("groupBy"),...p("pivotBy"),...p("metrics"),...p("sortBy")],L=sNe(P,I,{joinPlan:(q=e==null?void 0:e.config)==null?void 0:q.joinPlan,joinabilityMap:n==null?void 0:n.joinabilityMap,semanticDomainId:t});if(!L.isValid){L.showError&&IU();return}const F=aNe(P,I,h);if(!F){Oe.error("Invalid Field",{description:"This field cannot be added to any container",position:"top-center",duration:3e3});return}const H=Zee(P,F,h);if(!H.isValid){Oe.error("Invalid Field Type",{description:H.reason,position:"top-center",duration:3e3});return}const $=p(F);if(AU(P,$))return;const A=FU(P,F,$);if(A){const z=[...$,A];g(F,z),F==="metrics"&&Xee(h,e==null?void 0:e.config,r,m,z)}},[m,e==null?void 0:e.config,p,g,t,n,h,r]),D=C.useCallback((P,I)=>{if(!m)return;const F=p(P)[I];if(F){if(P!=="sortBy"){const H=p("sortBy"),$=H.filter(A=>!(A.name===F.name&&A.qualifiedEntityName===F.qualifiedEntityName));$.length!==H.length&&r(m,{sortByColumns:$})}switch(P){case"groupBy":l(m,F.id);break;case"metrics":u(m,F.id);break;case"pivotBy":d(m,F.id);break;case"sortBy":f(m,F.id);break}}},[m,p,l,u,d,f,r]);return{getFieldsForContainer:p,setFieldsForContainer:g,updateLabel:b,handleAggregationChange:x,handleDateFormatChange:y,handleGranularityChange:v,handleAliasTemplateChange:w,handleValueAliasesChange:N,removeField:D,handleFieldClick:M,handleKpiComparisonTypeChange:S,handleKpiShowTrendlineChange:j,handleKpiTrendlineWindowChange:E,handleKpiTrendlineGranularityChange:_,handleKpiTargetValueChange:k,cardType:h}};function hy(e,t){var Ee,Ve,qe,Ae,xt;const{tokenProps:n}=Ge(),r=zs(),s=Ge().authToken||e,o=_e(Ce=>Ce.selectedConnectionId),i=_e(Ce=>Ce.card),{queryKey:a}=_pe(i),l=_e(Ce=>Ce.selectedDatamodelId),u=_e(Ce=>Ce.isDevMode),d=_e(Ce=>Ce.selectedDatabaseName),f=_e(Ce=>Ce.selectedSchemaName),h=_e(Ce=>Ce.selectedTableName),m=_e(Ce=>Ce.actions.setSelectedConnectionId),p=_e(Ce=>Ce.actions.setSelectedDatamodelId),g=_e(Ce=>Ce.actions.setSelectedDatabaseName),b=_e(Ce=>Ce.actions.setSelectedSchemaName),x=_e(Ce=>Ce.actions.setSelectedTableName);_e(Ce=>Ce.actions.setCardSql);const{setQueryConfig:y}=Qn();function v(Ce){var _t;return o&&Ce==="API"?!1:o&&Ce==="S3"?!0:!(!o||!d||d==="NA"||((_t=_==null?void 0:_.capabilities)==null?void 0:_t.path.includes("schema"))&&!f)}function w(Ce){return o&&Ce?!(Ce==="API"||Ce==="S3"):!1}const{refetchConnections:N,connectionsData:S,isConnectionsLoading:j,isConnectionsError:E,selectedConnection:_}=$a(e),{refetch:k,data:M,isLoading:D,isError:R}=hn({queryKey:["models",o],queryFn:()=>qn(`${n.apiServiceUrl}/v1/datamodels`,(s==null?void 0:s.accessToken)||"",{connection_id:o}),enabled:!!(s!=null&&s.accessToken)&&!!o}),P=_==null?void 0:_.type,I=(_==null?void 0:_.type)==="API"||(_==null?void 0:_.type)==="S3",{data:L,isLoading:F,isFetching:H,isError:$,refetch:A}=hn({queryKey:["databases",o],queryFn:()=>qn(`${n.apiServiceUrl}/v1/databases`,(s==null?void 0:s.accessToken)||"",{connection_id:o}),enabled:w(P)}),{data:q,isLoading:z,isFetching:O,isError:W,refetch:B}=hn({queryKey:["schemas",o,d],queryFn:()=>qn(`${n.apiServiceUrl}/v1/schemas`,(s==null?void 0:s.accessToken)||"",{connection_id:o,database_name:d}),enabled:!!o&&!!d&&!I&&d!=="NA"}),{data:Y,isLoading:U,isFetching:V,isError:G,refetch:K}=hn({queryKey:["tables",o,d,f],queryFn:()=>qn(`${n.apiServiceUrl}/v1/tables`,(s==null?void 0:s.accessToken)||"",{connection_id:o,database_name:d,schema_name:f}),enabled:v(P)}),{columns:J,isColumnsLoading:Q,isColumnsFetching:re,isColumnsError:de,refetchColumns:fe}=$U(e);C.useEffect(()=>{(P==="S3"||P==="API")&&(g(""),b(""),p(""),P==="API"&&x("api"))},[P,x,g,b,p]);const ue=(_==null?void 0:_.type)==="API"?(Ee=_==null?void 0:_.type)==null?void 0:Ee.toLowerCase():h||"",je=I?"":f||"";function me(Ce){x(Ce),y(void 0),u||(r.setQueryData(a,null),r.removeQueries({queryKey:a,exact:!0}))}function ne(Ce){b(Ce),x("")}function oe(Ce){g(Ce==="none"?"":Ce),b(""),x(""),Ce!=="none"&&Ce!==""&&p("")}function pe(Ce){m(Ce)}function De(Ce){p(Ce==="none"?"":Ce),Ce!=="none"&&Ce!==""&&g("")}L&&((Ve=L==null?void 0:L.databases)==null?void 0:Ve.length)>0,q&&((qe=q==null?void 0:q.schemas)==null?void 0:qe.length)>0;const ae=S==null?void 0:S.connections.map(Ce=>({id:Ce.id,name:Ce.name,type:Ce.type})),Te=(Ae=M==null?void 0:M.datamodels)==null?void 0:Ae.map(Ce=>({id:Ce.id,name:Ce.name})),Ue=L==null?void 0:L.databases.map(Ce=>({id:Ce.database_name,name:Ce.database_name})),ie=q==null?void 0:q.schemas.map(Ce=>({id:Ce.schema_name,name:Ce.schema_name})),xe=Y==null?void 0:Y.tables.map(Ce=>({id:Ce.table_name,name:Ce.table_name})),$e=(xt=M==null?void 0:M.datamodels.find(Ce=>Ce.id===l))==null?void 0:xt.name,he=kv({schemaName:je,tableName:ue,modelName:$e,connectionType:P,databaseName:d||""});return{connectionItems:ae,selectedConnectionId:o,selectedConnection:_,isConnectionsLoading:j,isConnectionsError:E,modelItems:Te,selectedDatamodelId:l,selectedDatamodelName:$e,isModelsLoading:D,isModelsError:R,selectedDatabaseName:d,databaseItems:Ue,isDatabasesLoadingOrFetching:F||H,isDatabaseError:$,schemaItems:ie,selectedSchemaName:f,isSchemaLoadingOrFetching:z||O,isSchemaError:W,tableItems:xe,selectedTableName:h,isTableLoadingOrFetching:U||V,isTableError:G,columns:J,isColumnsLoadingOrFetching:Q||re,isColumnsError:de,isNonDbConnection:I,connectionType:P,tableName:ue,formattedTableName:he,schemaName:je,refetchConnections:N,refetchModels:k,refetchDatabases:A,refetchSchemas:B,refetchTables:K,refetchColumns:fe,handleConnectionChange:pe,handleDatamodelChange:De,handleDatabaseChange:oe,handleSchemaChange:ne,handleTableChange:me}}function W0(e){return`${e}-${vr()}`}function S6(e,t){const n=ni(e.replace(/_/g," "));switch(t){case"SUM":return`Sum of ${n}`;case"COUNT":return`Count of ${n}`;case"DISTINCT":return`Unique ${n}`;case"AVG":return`Average of ${n}`;case"MIN":return`Min of ${n}`;case"MAX":return`Max of ${n}`;default:return n}}function PJe(e,t){const n=ni(e.replace(/_/g," "));switch(t){case"day":return`Date of ${n}`;case"week":return`Week of ${n}`;case"month":return`Month of ${n}`;case"year":return`Year of ${n}`;default:return n}}function CA(e){if(!e||!e.selectedEntities||e.selectedEntities.length===0)return{tableName:void 0,schemaName:void 0,databaseName:void 0,connectionId:e==null?void 0:e.connectionId,connectionType:e==null?void 0:e.connectionType};const t=e.selectedEntities[0];return{tableName:t==null?void 0:t.name,schemaName:t==null?void 0:t.schema,databaseName:t==null?void 0:t.database,connectionId:e.connectionId,connectionType:e.connectionType}}function Jee(e){if(!e||!e.selectedEntities||e.selectedEntities.length===0)return!1;const t=e.selectedEntities[0];return!!(t!=null&&t.name)}function ete(){const e=_e(S=>S.sqlGen),t=_e(S=>S.isDevMode),n=_e(S=>S.card.dataSource),r=_e(S=>{var j,E;return(E=(j=S.card)==null?void 0:j.queryConfig)==null?void 0:E.metricColumns}),{tableName:s,schemaName:o,databaseName:i}=CA(n),a=Jee(n),l=_e(S=>S.selectedDatamodelId),{addColumnToMetricColumns:u,addColumnToGroupBy:d,setCardSql:f,setRunSql:h,setSqlGen:m,setIsShowingVisual:p}=Qn(),{connectionType:g,modelItems:b,selectedDatamodelName:x}=hy(),y=S=>({column_name:S.name,data_type:S.dataType,label:S.label,description:S.description});return{handleDevModeFieldClick:S=>{var E;if(!t)return;const j=y(S);if(t&&a&&s){const _=cD(j,e);m(_);const k=(E=b==null?void 0:b.find(D=>D.id===l))==null?void 0:E.name,M=lD(_,Ci(o||""),Ci(s),k||"",g,i||"");M&&(f(M),h(!0))}else if(!t){if(Qb(j.data_type))if(r&&r.length>0){const _={...j,role:"groupby",id:W0(j.column_name),name:j.column_name,type:j.data_type};d(_)}else{const _={...j,role:"metric",id:W0(j.column_name),name:j.column_name,label:S6(j.column_name,"COUNT"),type:j.data_type,aggregate:"COUNT"};u(_)}if(Ii(j.data_type)){const _={...j,role:"groupby",id:W0(j.column_name),name:j.column_name,type:j.data_type,label:PJe(j.column_name,"month"),granularity:"month"};d(_)}if(Ri(j.data_type)){const _={...j,role:"metric",id:W0(j.column_name),name:j.column_name,label:S6(j.column_name,"SUM"),type:j.data_type,aggregate:"SUM"};u(_)}}},handleShowSample:()=>{if(!a||!s){console.warn("Cannot generate SQL: missing table metadata");return}const S=kv({schemaName:o||"",tableName:s,modelName:x,connectionType:g,databaseName:i||""});p(!1);const j=g==="MSSQL"?`SELECT top 10 * FROM ${S}`:`SELECT * FROM ${S} LIMIT 10`;f(j),h(!0)},handleShowCount:()=>{if(!a||!s){console.warn("Cannot generate SQL: missing table metadata");return}const S=kv({schemaName:o||"",tableName:s,modelName:x,connectionType:g,databaseName:i||""});f(`SELECT COUNT(*) as count FROM ${S}`),h(!0)},isNumberField:S=>Ri(S.dataType)}}function OJe({columnName:e,database:t,schemaName:n,tableName:r,connectionType:s,datamodelId:o,modelName:i,field:a}){const l=Ci(e),u=Ci(t||""),d=Ci(n||""),f=Ci(r);let h=x1({schemaName:d,tableName:f,connectionType:s,databaseName:u}),m=`${h}.${l}`;return o&&o!=="none"&&i&&(m=`${Vg}.${i}.${l}`,h=`${Vg}.${i}`),a!=null&&a.qualifiedFieldName&&(m=a.qualifiedFieldName,h=a.qualifiedFieldName.split(".").slice(0,-1).join(".")),{qualifiedColumnName:m,qualifiedTableName:h,formattedColumnName:l,formattedTableName:f,formattedDatabase:u,formattedSchemaName:d}}function tte(){const e=_e(p=>p.selectedConnectionId),t=_e(p=>p.selectedDatamodelId),n=_e(p=>p.selectedDatabaseName),r=_e(p=>p.selectedSchemaName),s=_e(p=>p.selectedTableName),o=X(p=>p.dashboard.filters)||[],i=X(p=>p.selectedSheetId),a=X(p=>p.actions.addFilter),l=X(p=>p.actions.removeFilter),{removeFilterValues:u}=Ot(),{modelItems:d,tableName:f,connectionType:h}=hy();function m(p,g="sheet",b){var E;const x=(E=d==null?void 0:d.find(_=>_.id===t))==null?void 0:E.name,{qualifiedColumnName:y,qualifiedTableName:v,formattedColumnName:w,formattedTableName:N,formattedDatabase:S}=OJe({columnName:p.column_name,database:n,schemaName:r,tableName:f,connectionType:h,datamodelId:t,modelName:x,field:b});let j;if(g==="sheet"&&i?j=a_e(o,y,N,n||"",S,i):j=o==null?void 0:o.find(_=>_.column===y&&_.table===N&&(_.database===S||_.database===n)),j)u(j.id),l(j.id);else{const _=vr(),k=g==="sheet"&&i?[i]:void 0;return f==="api"&&e?(a({location:g,id:_,column:y,title:p.label||p.column_name,dataType:p.data_type,table:"api",database:"",connectionId:e,operation:"in",applyToSheetIds:k,sql:KE(p.data_type,v,w)}),_):(a({id:_,location:g,column:y,title:p.label||p.column_name,dataType:p.data_type,table:s||"",database:n||"",connectionId:e||"",operation:"in",applyToSheetIds:k,sql:KE(p.data_type,v,(b==null?void 0:b.qualifiedFieldName)||w)}),_)}}return{assignFilter:m}}function FJe({column:e}){const[t,n]=C.useState(!1),r=_e(x=>x.card.dataSource),{tableName:s,schemaName:o,databaseName:i}=CA(r),a=_e(x=>x.selectedDatamodelId),l=_e(x=>x.sqlGen),{modelItems:u,connectionType:d}=hy(),f=_e(x=>x.actions.setSqlGen),h=_e(x=>x.actions.setCardSql),m=_e(x=>x.actions.setRunSql),p=Jee(r);function g(x,y){var S;if(!p||!s){console.warn("Cannot generate SQL: missing table metadata");return}const v=cD(x,l,y),w=(S=u==null?void 0:u.find(j=>j.id===a))==null?void 0:S.name;f(v);const N=lD(v,Ci(o||""),Ci(s),w||"",d,i||"");N&&(h(N),m(!0)),n(!1)}function b(){return c.jsxs("ul",{className:"text-xs",children:[c.jsx("li",{onClick:()=>g(e,"COUNT"),className:"cursor-pointer p-1 px-3 transition-colors hover:bg-muted",children:"Count"}),c.jsx("li",{onClick:()=>g(e,"AVG"),className:"cursor-pointer p-1 px-3 transition-colors hover:bg-muted",children:"Avg"}),c.jsx("li",{onClick:()=>g(e,"SUM"),className:"cursor-pointer p-1 px-3 transition-colors hover:bg-muted",children:"Sum"}),c.jsx("li",{onClick:()=>g(e,"MAX"),className:"cursor-pointer p-1 px-3 transition-colors hover:bg-muted",children:"Max"}),c.jsx("li",{onClick:()=>g(e,"MIN"),className:"cursor-pointer p-1 px-3 transition-colors hover:bg-muted",children:"Min"})]})}return p?c.jsxs(km,{openDelay:0,open:t,onOpenChange:n,children:[c.jsx(Em,{asChild:!0,children:c.jsx(lm,{className:"invisible size-3.5 cursor-pointer text-foreground/40 group-hover/container:visible"})}),c.jsx(of,{align:"center",className:"w-20 rounded-md p-0 shadow-none",children:b()})]}):null}function $Je({field:e,fieldState:t}){return c.jsxs("div",{className:"w-64 bg-background p-0",children:[c.jsxs("div",{className:"mb-2 flex items-start justify-between gap-2",children:[c.jsx("h3",{className:"text-sm font-medium text-foreground",children:e.label||e.name}),c.jsx("span",{className:"rounded bg-muted px-2 py-0.5 font-mono text-xs text-muted-foreground",children:e.dataType})]}),e.description&&c.jsx("p",{className:"mb-3 text-xs text-muted-foreground",children:e.description}),t&&t.tooltip&&c.jsx("div",{className:"mb-2 rounded bg-muted/50 p-2",children:c.jsx("p",{className:"text-xs text-muted-foreground",children:t.tooltip})}),c.jsx("div",{className:"overflow-x-auto border-t border-border pb-2 pt-2",children:c.jsx("span",{className:"font-mono text-xs text-muted-foreground",children:e.name})})]})}function LJe({field:e,context:t="editor",fieldState:n,onFieldSelect:r,inlineFilters:s}){const o=_e(Y=>Y.isDevMode),i=t==="filter"||t==="inline-filter",a=o||i||(n==null?void 0:n.state)==="unreachable"&&!i,l=X(Y=>Y.dashboard.filters),u=X(Y=>Y.selectedSheetId),d=X(Y=>Y.actions.removeFilter),{removeFilterValues:f}=Ot(),{assignFilter:h}=tte(),m=t==="filter"?Bl(l,u):l,p=t==="filter"?m==null?void 0:m.find(Y=>{var U;return Y.title===e.name||((U=Y.column)==null?void 0:U.includes(e.name))}):void 0,g=!!p,b=t==="inline-filter"&&(s==null?void 0:s.some(Y=>Y.column===e.qualifiedFieldName||Y.column===e.name)),x=g||b,y=p&&i?l==null?void 0:l.find(Y=>Y.id===p.id):void 0,v=y&&(y.applyToSheetIds&&y.applyToSheetIds.length>1||y.excludeSheetIds&&y.excludeSheetIds.length>0||!y.applyToSheetIds&&!y.excludeSheetIds&&!y.sheetId);i&&x&&console.log("[SourceField Debug]",{fieldName:e.name,hasActiveFilter:x,activeFilterOnSheet:p?{id:p.id,title:p.title,column:p.column,applyToSheetIds:p.applyToSheetIds,excludeSheetIds:p.excludeSheetIds}:null,activeFilterForField:y?{id:y.id,title:y.title,column:y.column,applyToSheetIds:y.applyToSheetIds,excludeSheetIds:y.excludeSheetIds}:null,isMultiSheetFilter:v,selectedSheetId:u});const[w,N]=C.useState(!1),[S,j]=C.useState(null),{attributes:E,listeners:_,setNodeRef:k,transform:M,transition:D,isDragging:R}=oy({id:e.id,disabled:a}),[P,I]=C.useState(!1),L=_e(Y=>Y.card),{handleFieldClick:F}=Qee(L),{handleDevModeFieldClick:H,isNumberField:$}=ete(),A=()=>{y&&(console.log("[SourceField] Removing multi-sheet filter:",y.id),f(y.id),d(y.id)),j(null),N(!1)},q=()=>{if(t==="inline-filter"&&r){r(e);return}if(t==="filter"){const Y={column_name:e.name,data_type:e.dataType,label:e.label,description:e.description,qualifiedFieldName:e.qualifiedFieldName};x&&v?(j({column:Y,field:e}),N(!0)):h(Y,"sheet",e)}else o?H(e):F(e)},z={column_name:e.name,data_type:e.dataType,label:e.label,description:e.description},O={transform:ii.Transform.toString(M),transition:D},B=(()=>{if(!n||i)return{};const U={base:{hoverBorderColor:"hover:border-blue-500/40",hoverBgColor:"hover:bg-blue-50/50 dark:hover:bg-blue-950/20"},draggable:{hoverBorderColor:"hover:border-green-500/40",hoverBgColor:"hover:bg-green-50/30 dark:hover:bg-green-950/20"},indirect:{hoverBorderColor:"hover:border-yellow-500/40",hoverBgColor:"hover:bg-yellow-50/30 dark:hover:bg-yellow-950/20"},unreachable:{borderColor:"border-gray-300/40 dark:border-gray-700/40",bgColor:"bg-gray-50/30 dark:bg-gray-900/20",hoverBgColor:"hover:bg-gray-100/30 dark:hover:bg-gray-800/20",opacity:"opacity-50",cursor:"cursor-not-allowed"}}[n.state]||{};return n.isSelected&&{base:{borderColor:"border-blue-300/30 dark:border-blue-700/30",bgColor:"bg-blue-50/20 dark:bg-blue-950/10",...U},draggable:{borderColor:"border-green-300/30 dark:border-green-700/30",bgColor:"bg-green-50/20 dark:bg-green-950/10",...U},indirect:{borderColor:"border-yellow-300/30 dark:border-yellow-700/30",bgColor:"bg-yellow-50/20 dark:bg-yellow-950/10",...U}}[n.state]||U})();return c.jsxs("div",{ref:k,style:O,...a?{}:E,...a?{}:_,className:Z("group/container max-w-[265px] overflow-hidden rounded-lg transition-all",R&&"scale-95 opacity-50",!R&&"border",B.borderColor||"border-transparent",B.bgColor||"",B.hoverBorderColor,B.hoverBgColor||"hover:bg-muted",B.opacity,B.cursor,g&&"border-accent-foreground/20 bg-accent",b&&"border-primary/20 bg-primary/10",{"cursor-pointer":o||i,"cursor-grab active:cursor-grabbing":!a&&!o&&!i}),title:n==null?void 0:n.tooltip,children:[c.jsxs("div",{className:"flex min-w-0 items-center gap-3 p-2",onClick:q,children:[Eb(e.dataType),c.jsx(_n,{children:c.jsxs(Zt,{children:[c.jsx(Xt,{asChild:!0,children:c.jsx("div",{className:"min-w-0 flex-1 overflow-hidden",children:c.jsx("span",{className:`block text-sm text-foreground/80 hover:text-foreground dark:text-muted-foreground ${P?"whitespace-normal break-words":"truncate"}`,children:e.label||e.name})})}),c.jsx(en,{side:"bottom",align:"start",className:"ml-5 max-w-xs px-4 pb-2 pt-4",children:c.jsx($Je,{field:e,fieldState:n})})]})}),o&&!i&&$(e)&&c.jsx("div",{onClick:Y=>Y.stopPropagation(),children:c.jsx(FJe,{column:z})})]}),P&&c.jsx("div",{className:"text-muted-foreground-700 px-2 pb-3 text-sm",children:c.jsx(Do,{className:"",children:c.jsxs(Oi,{className:"space-y-2 p-3",children:[c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsx(M8,{className:"h-4 w-4 text-muted-foreground"}),c.jsx("span",{className:"break-all",children:e.label||e.name})]}),c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsx(yle,{className:"h-4 w-4 text-muted-foreground"}),c.jsx("span",{className:"break-all",children:e.name})]}),c.jsx(Fe,{variant:"outline",className:"mt-2 text-xs",children:e.dataType})]})})}),c.jsx(px,{open:w,onOpenChange:N,children:c.jsxs(ym,{children:[c.jsxs(vm,{children:[c.jsx(Sm,{children:"Remove Filter from Multiple Sheets?"}),c.jsx(Cm,{children:"This filter is currently applied to multiple sheets. Removing it will affect all sheets where it's applied."})]}),c.jsxs(wm,{children:[c.jsx(jm,{children:"Cancel"}),c.jsx(Nm,{onClick:A,children:"Remove Filter"})]})]})})]})}const zJe="SEMAPHOR_CALCULATED_FIELD",BJe=["MM-DD-YYYY","YYYY-MM-DD","MM/DD/YYYY","DD/MM/YYYY","MMMM DD, YYYY","MMM DD, YYYY","DD MMM YYYY","Week of MMM DD, YYYY","Week of MMMM DD, YYYY","YYYY-WW","MMM YYYY","MMMM YYYY","YYYY-MM","MM/YYYY","YYYY MMM","Q1 YYYY","YYYY Q1","1st Quarter YYYY","YYYY-Q1","Quarter 1, YYYY","YYYY","YY","custom"];function nte(e){return!!e.expression}function VJe(e){return!!e.expression}function HJe(e){return!!e.expression}var rte=(e=>(e.SUBTOTAL="__SUBTOTAL__",e.TOTAL="__TOTAL__",e.ALL="__ALL__",e))(rte||{}),Ki="Accordion",UJe=["Home","End","ArrowDown","ArrowUp","ArrowLeft","ArrowRight"],[NA,WJe,qJe]=sx(Ki),[MC]=kr(Ki,[qJe,bW]),jA=bW(),ste=C.forwardRef((e,t)=>{const{type:n,...r}=e,s=r,o=r;return c.jsx(NA.Provider,{scope:e.__scopeAccordion,children:n==="multiple"?c.jsx(ZJe,{...o,ref:t}):c.jsx(KJe,{...s,ref:t})})});ste.displayName=Ki;var[ote,YJe]=MC(Ki),[ite,GJe]=MC(Ki,{collapsible:!1}),KJe=C.forwardRef((e,t)=>{const{value:n,defaultValue:r,onValueChange:s=()=>{},collapsible:o=!1,...i}=e,[a,l]=Br({prop:n,defaultProp:r??"",onChange:s,caller:Ki});return c.jsx(ote,{scope:e.__scopeAccordion,value:C.useMemo(()=>a?[a]:[],[a]),onItemOpen:l,onItemClose:C.useCallback(()=>o&&l(""),[o,l]),children:c.jsx(ite,{scope:e.__scopeAccordion,collapsible:o,children:c.jsx(ate,{...i,ref:t})})})}),ZJe=C.forwardRef((e,t)=>{const{value:n,defaultValue:r,onValueChange:s=()=>{},...o}=e,[i,a]=Br({prop:n,defaultProp:r??[],onChange:s,caller:Ki}),l=C.useCallback(d=>a((f=[])=>[...f,d]),[a]),u=C.useCallback(d=>a((f=[])=>f.filter(h=>h!==d)),[a]);return c.jsx(ote,{scope:e.__scopeAccordion,value:i,onItemOpen:l,onItemClose:u,children:c.jsx(ite,{scope:e.__scopeAccordion,collapsible:!0,children:c.jsx(ate,{...o,ref:t})})})}),[XJe,TC]=MC(Ki),ate=C.forwardRef((e,t)=>{const{__scopeAccordion:n,disabled:r,dir:s,orientation:o="vertical",...i}=e,a=C.useRef(null),l=rt(a,t),u=WJe(n),f=eu(s)==="ltr",h=ke(e.onKeyDown,m=>{var E;if(!UJe.includes(m.key))return;const p=m.target,g=u().filter(_=>{var k;return!((k=_.ref.current)!=null&&k.disabled)}),b=g.findIndex(_=>_.ref.current===p),x=g.length;if(b===-1)return;m.preventDefault();let y=b;const v=0,w=x-1,N=()=>{y=b+1,y>w&&(y=v)},S=()=>{y=b-1,y<v&&(y=w)};switch(m.key){case"Home":y=v;break;case"End":y=w;break;case"ArrowRight":o==="horizontal"&&(f?N():S());break;case"ArrowDown":o==="vertical"&&N();break;case"ArrowLeft":o==="horizontal"&&(f?S():N());break;case"ArrowUp":o==="vertical"&&S();break}const j=y%x;(E=g[j].ref.current)==null||E.focus()});return c.jsx(XJe,{scope:n,disabled:r,direction:s,orientation:o,children:c.jsx(NA.Slot,{scope:n,children:c.jsx(ze.div,{...i,"data-orientation":o,ref:l,onKeyDown:r?void 0:h})})})}),u1="AccordionItem",[QJe,kA]=MC(u1),lte=C.forwardRef((e,t)=>{const{__scopeAccordion:n,value:r,...s}=e,o=TC(u1,n),i=YJe(u1,n),a=jA(n),l=ar(),u=r&&i.value.includes(r)||!1,d=o.disabled||e.disabled;return c.jsx(QJe,{scope:n,open:u,disabled:d,triggerId:l,children:c.jsx(vW,{"data-orientation":o.orientation,"data-state":mte(u),...a,...s,ref:t,disabled:d,open:u,onOpenChange:f=>{f?i.onItemOpen(r):i.onItemClose(r)}})})});lte.displayName=u1;var cte="AccordionHeader",ute=C.forwardRef((e,t)=>{const{__scopeAccordion:n,...r}=e,s=TC(Ki,n),o=kA(cte,n);return c.jsx(ze.h3,{"data-orientation":s.orientation,"data-state":mte(o.open),"data-disabled":o.disabled?"":void 0,...r,ref:t})});ute.displayName=cte;var H_="AccordionTrigger",dte=C.forwardRef((e,t)=>{const{__scopeAccordion:n,...r}=e,s=TC(Ki,n),o=kA(H_,n),i=GJe(H_,n),a=jA(n);return c.jsx(NA.ItemSlot,{scope:n,children:c.jsx(cje,{"aria-disabled":o.open&&!i.collapsible||void 0,"data-orientation":s.orientation,id:o.triggerId,...a,...r,ref:t})})});dte.displayName=H_;var fte="AccordionContent",hte=C.forwardRef((e,t)=>{const{__scopeAccordion:n,...r}=e,s=TC(Ki,n),o=kA(fte,n),i=jA(n);return c.jsx(uje,{role:"region","aria-labelledby":o.triggerId,"data-orientation":s.orientation,...i,...r,ref:t,style:{"--radix-accordion-content-height":"var(--radix-collapsible-content-height)","--radix-accordion-content-width":"var(--radix-collapsible-content-width)",...e.style}})});hte.displayName=fte;function mte(e){return e?"open":"closed"}var JJe=ste,eet=lte,tet=ute,pte=dte,gte=hte;const bte=JJe,EA=T.forwardRef(({className:e,...t},n)=>c.jsx(eet,{ref:n,className:Z("border-b",e),...t}));EA.displayName="AccordionItem";const _A=T.forwardRef(({className:e,children:t,...n},r)=>c.jsx(tet,{className:"flex",children:c.jsxs(pte,{ref:r,className:Z("flex flex-1 items-center justify-between py-4 font-medium transition-all hover:underline [&[data-state=open]>svg]:rotate-180",e),...n,children:[t,c.jsx(hr,{className:"h-4 w-4 shrink-0 transition-transform duration-200"})]})}));_A.displayName=pte.displayName;const DA=T.forwardRef(({className:e,children:t,...n},r)=>c.jsx(gte,{ref:r,className:"overflow-hidden text-sm transition-all data-[state=closed]:animate-accordion-up data-[state=open]:animate-accordion-down",...n,children:c.jsx("div",{className:Z("pb-4 pt-0",e),children:t})}));DA.displayName=gte.displayName;function xte({context:e="editor",onFieldSelect:t,inlineFilters:n}={}){var I,L,F,H;const[r,s]=C.useState(""),[o,i]=C.useState("all");_e($=>$.isDevMode);const a=_e($=>$.card.dataSource),l=_e($=>$.card.config),u=_e($=>$.card),{autoJoinMetadata:d}=_a(u),{columns:f=[],columnGroups:h=[],isLoading:m,error:p}=pT(),g=(a==null?void 0:a.mode)==="semanticDomain"?a.semanticDomainId:void 0,{data:b}=SA(g),x=[...(l==null?void 0:l.groupByColumns)||[],...(l==null?void 0:l.metricColumns)||[]];(L=(I=l==null?void 0:l.joinPlan)==null?void 0:I.baseEntity)==null||L.name,(H=(F=d==null?void 0:d.resolvedJoinPlan)==null?void 0:F.baseEntity)==null||H.name,ete();const y=f.filter($=>$.name.toLowerCase().includes(r.toLowerCase())||$.dataType.toLowerCase().includes(r.toLowerCase())||$.label&&$.label.toLowerCase().includes(r.toLowerCase())||$.qualifiedEntityName&&$.qualifiedEntityName.toLowerCase().includes(r.toLowerCase())),v=$=>{if($.role==="metric"&&nte($)||$.role==="groupby"&&$.expression)return"calculated";if($.dataType==="number"||$.dataType==="integer"||$.dataType==="float"||$.dataType==="decimal"||$.dataType==="currency")return"metrics";const A=Tr($.dataType);return["date","string","boolean"].includes(A)?"dimensions":A==="number"?"metrics":"dimensions"},N=(o==="all"?y:y.filter($=>v($)===o)).reduce(($,A)=>{const q=A.qualifiedEntityName||"Other Fields";return $[q]||($[q]={label:xD(A.entityName),fields:[]}),$[q].fields.push(A),$},{}),j=Object.keys(N),E=y.filter($=>v($)==="dimensions").length,_=y.filter($=>v($)==="metrics").length,k=y.filter($=>v($)==="calculated").length,M=y.length>0&&e!=="inline-filter",D=e==="inline-filter"?"w-full":"w-[290px]";if(m)return c.jsx("div",{className:Z("flex h-full flex-col items-center justify-center py-8",D),children:c.jsx(Gc,{size:"md",color:"muted","aria-label":"Loading data"})});if(p)return c.jsxs("div",{className:Z("flex h-full flex-col items-center justify-center py-8",D),children:[c.jsx(Cl,{className:"mb-4 h-12 w-12 text-red-300"}),c.jsx("p",{className:"mb-2 text-sm text-red-500",children:"Error loading fields"}),c.jsx("p",{className:"px-4 text-center text-xs text-red-400",children:p.message||"Failed to load column data"})]});if(!a||!a.selectedEntities||a.selectedEntities.length===0)return c.jsxs("div",{className:Z("flex flex-col items-center justify-center py-8 text-center",D),children:[c.jsx(Cl,{className:"mb-4 h-12 w-12 text-gray-300"}),c.jsx("p",{className:"mb-2 text-sm text-gray-500",children:"No data source selected"}),c.jsx("p",{className:"px-4 text-xs text-gray-400",children:e==="filter"||e==="inline-filter"?"Configure a data source for this card to see available fields":"Select a table, view, or dataset from the data source panel to see available fields"})]});const R=e==="inline-filter"?"px-3 pb-3":"px-6 pb-6",P=e==="inline-filter"?"overflow-hidden":"";return c.jsxs("div",{className:Z("mt-2 flex h-full w-full grow flex-col gap-2",R,P),children:[c.jsxs("div",{className:"mt-1 flex-shrink-0 space-y-2",children:[f.length>0&&c.jsxs("div",{className:"relative",children:[c.jsx(Ui,{className:"absolute left-3 top-1/2 size-3.5 -translate-y-1/2 transform text-muted-foreground"}),c.jsx(xn,{className:"pl-10 pr-10",type:"text",placeholder:"Search fields...",value:r,onChange:$=>s($.target.value)}),r&&c.jsx("button",{className:"absolute right-3 top-1/2 -translate-y-1/2 transform text-muted-foreground hover:text-foreground",onClick:()=>s(""),type:"button",children:c.jsx(yt,{className:"size-3.5"})})]}),M&&c.jsx(Bs,{defaultValue:"all",value:o,onValueChange:$=>i($),className:"mb-4",children:c.jsxs(vs,{className:"grid h-9 w-full grid-cols-4",children:[c.jsxs(Gt,{value:"all",className:"text-xs",children:["All",c.jsx("span",{className:"ml-2 text-xs font-semibold",children:y.length})]}),c.jsxs(Gt,{value:"dimensions",className:"text-xs",children:[c.jsx(D1,{className:"size-4 shrink-0"}),c.jsx("span",{className:"ml-2 text-xs font-semibold",children:E})]}),c.jsxs(Gt,{value:"metrics",className:"text-xs",children:[c.jsx(im,{className:"size-4 shrink-0"}),c.jsx("span",{className:"ml-2 text-xs font-semibold",children:_})]}),c.jsxs(Gt,{value:"calculated",className:"text-xs",children:[c.jsx(kD,{className:"size-4 shrink-0"}),c.jsx("span",{className:"ml-2 text-xs font-semibold",children:k})]})]})})]}),c.jsxs(Vl,{className:"min-h-0 overflow-auto",children:[c.jsx(bte,{type:"multiple",defaultValue:j,className:"space-y-2",children:Object.entries(N).map(([$,A])=>{const q=h.find(z=>z.entityName===$)||{entityName:$,label:A.label};return c.jsxs(EA,{value:$,className:"border-none",children:[c.jsx(_A,{className:"group rounded-md px-2.5 py-2 text-muted-foreground hover:bg-muted hover:no-underline",children:c.jsxs("div",{title:q.label||q.entityName,className:"flex items-center gap-2",children:[c.jsx("span",{className:"max-w-[190px] truncate text-ellipsis whitespace-nowrap text-sm font-medium text-primary",children:q.label||q.entityName}),c.jsx(Fe,{variant:"secondary",className:"rounded-full text-xs text-muted-foreground group-hover:bg-background",children:A.fields.length})]})}),c.jsx(DA,{className:"pb-2",children:c.jsx("div",{className:"space-y-1",children:A.fields.map(z=>{const O=gT(z,{joinabilityMap:(b==null?void 0:b.joinabilityMap)||null,selectedFields:x,cardConfig:l,autoJoinMetadata:d});return c.jsx(LJe,{field:z,context:e,fieldState:O,onFieldSelect:t,inlineFilters:e==="inline-filter"?n:void 0},z.id)})})})]},$)})}),Object.keys(N).length===0&&f.length===0&&c.jsxs("div",{className:"py-8 text-center text-sm text-gray-500",children:[c.jsx("p",{children:"No fields found for selected data source"}),c.jsx("p",{className:"mt-1 text-xs text-gray-400",children:e==="filter"?"The selected data source has no available fields":"Try selecting different data sources"})]}),Object.keys(N).length===0&&f.length>0&&c.jsx("div",{className:"py-4 text-center text-sm text-gray-500",children:"No fields found for this category"}),c.jsx(si,{orientation:"horizontal"}),c.jsx(si,{orientation:"vertical"})]})]})}function yte({context:e="editor"}={}){return c.jsxs("div",{"data-content":"fields-section",className:"flex h-full grow flex-col items-center overflow-hidden",children:[" ",c.jsx(xte,{context:e})," "]})}function vte(){const e=_e(i=>i.card.dataSource),{setSelectedConnectionId:t,setSelectedDatabaseName:n,setSelectedSchemaName:r,setSelectedTableName:s,setSelectedDatamodelId:o}=Qn();C.useEffect(()=>{var m;if(!e)return;const{tableName:i,schemaName:a,databaseName:l,connectionId:u}=CA(e),d=(m=e.selectedEntities)==null?void 0:m[0],h=(d==null?void 0:d.type)==="model"&&"id"in d?d.id:"";t(u||""),n(l||""),r(a||""),s(i||""),o(h)},[e,t,n,r,s,o])}function net(){vte();const e=X(l=>l.selectedSheetId),t=X(l=>l.selectedFrameId),n=X(l=>l.dashboard),r=X(l=>l.actions.getSelectedFrame),{setSelectedFrameId:s}=Ot(),{setCard:o}=Qn(),i=_e(l=>l.card.dataSource);return C.useEffect(()=>{var u,d;let l=r();if(!l){const f=(u=n==null?void 0:n.sheets)==null?void 0:u.find(m=>m.id===e),h=(d=f==null?void 0:f.frames)==null?void 0:d[0];h&&(s(h.id),l=h)}if(l){const f=l.cards.find(h=>h.id===l.activeCardId);f&&o(f)}},[r,e,t,n,s,o]),{hasEntities:!!(i!=null&&i.selectedEntities&&i.selectedEntities.length>0)}}function ret(){const e=X(o=>o.dashboard.filterLayout),{setFilterLayout:t}=Ot(),n=(e==null?void 0:e.displayMode)||"canvas",r=(e==null?void 0:e.toolbarWrap)??!1,s=(e==null?void 0:e.showDownloadButton)??!1;return c.jsxs(Xr,{children:[c.jsx(Qr,{asChild:!0,children:c.jsx(se,{variant:"ghost",size:"sm",className:"h-7 w-7 p-0","aria-label":"Filter display settings",children:c.jsx(Nl,{className:"h-4 w-4"})})}),c.jsx(Jr,{className:"w-[280px]",align:"end",children:c.jsxs("div",{className:"space-y-4",children:[c.jsxs("div",{children:[c.jsx("h4",{className:"mb-3 text-sm font-medium",children:"Filter Display"}),c.jsxs(jo,{value:n,onValueChange:o=>t({displayMode:o}),className:"space-y-2",children:[c.jsxs("div",{className:"flex items-start space-x-3",children:[c.jsx(In,{value:"canvas",id:"canvas",className:"mt-0.5"}),c.jsxs("div",{className:"grid gap-0.5",children:[c.jsx(ce,{htmlFor:"canvas",className:"cursor-pointer font-normal",children:"Canvas Cards"}),c.jsx("p",{className:"text-xs text-muted-foreground",children:"Filters as draggable, resizable cards on the dashboard"})]})]}),c.jsxs("div",{className:"flex items-start space-x-3",children:[c.jsx(In,{value:"toolbar",id:"toolbar",className:"mt-0.5"}),c.jsxs("div",{className:"grid gap-0.5",children:[c.jsx(ce,{htmlFor:"toolbar",className:"cursor-pointer font-normal",children:"Toolbar"}),c.jsx("p",{className:"text-xs text-muted-foreground",children:"Compact horizontal toolbar below dashboard controls"})]})]})]})]}),n==="toolbar"&&c.jsxs(c.Fragment,{children:[c.jsxs("div",{className:"flex items-center space-x-2 border-t pt-4",children:[c.jsx(Qt,{id:"wrap",checked:r,onCheckedChange:o=>t({toolbarWrap:o===!0})}),c.jsx(ce,{htmlFor:"wrap",className:"cursor-pointer text-sm font-normal",children:"Wrap filters to multiple lines"})]}),c.jsxs("div",{className:"flex items-center space-x-2 pt-2",children:[c.jsx(Qt,{id:"download",checked:s,onCheckedChange:o=>t({showDownloadButton:o===!0})}),c.jsx(ce,{htmlFor:"download",className:"cursor-pointer text-sm font-normal",children:"Show download button"})]})]}),c.jsx("p",{className:"border-t pt-3 text-xs text-muted-foreground",children:"Individual filters can override this setting in their configuration."})]})})]})}function set(){const e=X(n=>n.actions.setShowFilters),{hasEntities:t}=net();return c.jsxs("section",{className:"relative flex min-w-[320px] grow flex-col overflow-hidden border-l",children:[c.jsxs("div",{className:"mt-4 flex items-center justify-between gap-2 px-4",children:[c.jsx(ce,{className:"px-2 text-base",children:"Dashboard Filters"}),c.jsxs("div",{className:"flex items-center gap-1",children:[c.jsx(ret,{}),c.jsx(se,{onClick:()=>e(!1),className:"h-7 w-7 p-0",variant:"ghost",children:c.jsx(tX,{})})]})]}),!t&&c.jsxs("div",{className:"flex h-full flex-col items-center justify-center px-6 py-12 text-center",children:[c.jsx(Cl,{className:"mb-4 h-12 w-12 text-muted-foreground/50"}),c.jsx("h3",{className:"mb-2 text-sm font-medium text-foreground",children:"No fields configured"}),c.jsx("p",{className:"text-xs text-muted-foreground",children:"Please configure a data source for this card to enable filtering"})]}),t&&c.jsx("div",{className:"flex grow overflow-y-auto",children:c.jsx(ry,{collisionDetection:ey,children:c.jsx(sy,{items:[],strategy:RI,children:c.jsx(yte,{context:"filter"})})})})]})}function oet(){const e=X(r=>r.dashboard.filters),t=X(r=>r.theme),n=e==null?void 0:e.filter(r=>r.hide);return n!=null&&n.length?c.jsx("div",{className:Z("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)]":t==="light","bg-[repeating-linear-gradient(45deg,_#18171d_0_3px,_#272729_3px_6px)]":t==="dark"}),children:n==null?void 0:n.map(r=>c.jsxs("div",{className:"flex min-w-[250px] max-w-fit flex-col gap-1 p-2",children:[c.jsx(jI,{filter:r}),c.jsx(rp,{filter:r})]},r.id))}):null}function iet(){const e=X(r=>r.showFilters),t=X(r=>r.isVisualEditing),n=X(r=>r.isDashboardEditing);return c.jsxs("div",{role:"dashboard-plus-main",className:Z("",{"max-h-0 overflow-hidden":t,"flex grow overflow-hidden":!t}),children:[c.jsxs("section",{className:"flex grow flex-col overflow-y-auto",children:[n&&c.jsx(oet,{}),c.jsx(Yee,{})]}),e&&c.jsx("div",{role:"filter-aside-container",className:"flex overflow-hidden",children:c.jsx(set,{})})]})}const aet=C.lazy(()=>Promise.resolve().then(()=>require("./dashboard-controls-BdFhbpoS.js"))),cet=C.lazy(()=>Promise.resolve().then(()=>require("./edit-dashboard-visual-BEAKONcQ.js"))),uet=C.lazy(()=>Promise.resolve().then(()=>require("./dashboard-json-ClK3yCs7.js"))),det=C.lazy(()=>Promise.resolve().then(()=>require("./resource-management-panel-Cs7tkTxZ.js")).then(e=>({default:e.ResourceManagementPanel})));function fet({showControls:e=!1,showFooter:t=!0,...n}){const r=X(l=>l.isDashboardPanelOpen),s=X(l=>l.isVisualEditing),o=X(l=>l.showDashboardJSON),i=X(l=>l.actions.setIsDashboardPanelOpen),{preferences:a}=n;return c.jsx(Ua,{FallbackComponent:eC,children:c.jsxs(jD,{dashboardProps:n,children:[c.jsx(mhe,{}),c.jsx(wA,{componentType:"surfboard",componentId:n.id}),c.jsx(vA,{children:c.jsxs(Gee,{preferences:a,children:[o&&c.jsx(C.Suspense,{fallback:null,children:c.jsx(uet,{})}),c.jsxs("main",{className:"relative flex h-full w-full flex-col overflow-hidden",children:[e&&c.jsx(C.Suspense,{fallback:null,children:c.jsx(aet,{})}),c.jsxs("div",{className:"flex grow overflow-hidden",children:[r&&c.jsx(C.Suspense,{fallback:null,children:c.jsx(det,{isOpen:r,onClose:()=>i(!1),variant:"inline"})}),c.jsx("div",{className:"flex min-w-0 flex-1",children:c.jsxs(VT,{...n,type:"dashboard",children:[s&&c.jsx(C.Suspense,{fallback:null,children:c.jsx(cet,{})}),c.jsx(iet,{})]})})]})]})]})})]})})}var het=Object.defineProperty,met=(e,t,n)=>t in e?het(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,q0=(e,t,n)=>met(e,typeof t!="symbol"?t+"":t,n);const pet={stringify:e=>e?"true":"false",parse:e=>/^[ty1-9]/i.test(e)},get={stringify:e=>e.name,parse:(e,t,n)=>{const r=(()=>{if(typeof window<"u"&&e in window)return window[e];if(typeof global<"u"&&e in global)return global[e]})();return typeof r=="function"?r.bind(n):void 0}},bet={stringify:e=>JSON.stringify(e),parse:e=>JSON.parse(e)};function xet(e){return e.replace(/([a-z0-9])([A-Z])/g,(t,n,r)=>`${n}-${r.toLowerCase()}`)}function wte(e){return e.replace(/[-:]([a-z])/g,(t,n)=>`${n.toUpperCase()}`)}const yet={stringify:e=>e.name,parse:(e,t,n)=>{const r=(()=>{const s=wte(t);if(typeof n<"u"&&s in n.container)return n.container[s]})();return typeof r=="function"?r.bind(n):void 0}},vet={stringify:e=>`${e}`,parse:e=>parseFloat(e)},wet={stringify:e=>e,parse:e=>e},I2={string:wet,number:vet,boolean:pet,function:get,method:yet,json:bet},$p=Symbol.for("r2wc.render"),Y0=Symbol.for("r2wc.connected"),Tu=Symbol.for("r2wc.context"),fo=Symbol.for("r2wc.props");function Cet(e,t,n){var r,s,o;t.props||(t.props=e.propTypes?Object.keys(e.propTypes):[]),t.events||(t.events=[]);const i=Array.isArray(t.props)?t.props.slice():Object.keys(t.props),a=Array.isArray(t.events)?t.events.slice():Object.keys(t.events),l={},u={},d={},f={};for(const m of i){l[m]=Array.isArray(t.props)?"string":t.props[m];const p=xet(m);d[m]=p,f[p]=m}for(const m of a)u[m]=Array.isArray(t.events)?{}:t.events[m];class h extends HTMLElement{constructor(){super(),q0(this,o,!0),q0(this,s),q0(this,r,{}),q0(this,"container"),t.shadow?this.container=this.attachShadow({mode:t.shadow}):this.container=this,this[fo].container=this.container;for(const p of i){const g=d[p],b=this.getAttribute(g),x=l[p],y=x?I2[x]:null;if(x==="method"){const v=wte(g);Object.defineProperty(this[fo].container,v,{enumerable:!0,configurable:!0,get(){return this[fo][v]},set(w){this[fo][v]=w,this[$p]()}}),this[fo][p]=y.parse(b,g,this)}y!=null&&y.parse&&b&&(this[fo][p]=y.parse(b,g,this))}for(const p of a)this[fo][p]=g=>{const b=p.replace(/^on/,"").toLowerCase();this.dispatchEvent(new CustomEvent(b,{detail:g,...u[p]}))}}static get observedAttributes(){return Object.keys(f)}connectedCallback(){this[Y0]=!0,this[$p]()}disconnectedCallback(){this[Y0]=!1,this[Tu]&&n.unmount(this[Tu]),delete this[Tu]}attributeChangedCallback(p,g,b){const x=f[p],y=l[x],v=y?I2[y]:null;x in l&&v!=null&&v.parse&&b&&(this[fo][x]=v.parse(b,p,this),this[$p]())}[(o=Y0,s=Tu,r=fo,$p)](){this[Y0]&&(this[Tu]?n.update(this[Tu],this[fo]):this[Tu]=n.mount(this.container,e,this[fo]))}}for(const m of i){const p=d[m],g=l[m];Object.defineProperty(h.prototype,m,{enumerable:!0,configurable:!0,get(){return this[fo][m]},set(b){this[fo][m]=b;const x=g?I2[g]:null;if(x!=null&&x.stringify){const y=x.stringify(b,p,this);this.getAttribute(p)!==y&&this.setAttribute(p,y)}else this[$p]()}})}return h}function Net(e,t,n){const r=Vne.createRoot(e),s=C.createElement(t,n);return r.render(s),{root:r,ReactComponent:t}}function jet({root:e,ReactComponent:t},n){const r=C.createElement(t,n);e.render(r)}function ket({root:e}){e.unmount()}function Eet(e,t={}){return Cet(e,t,{mount:Net,update:jet,unmount:ket})}const _et={id:"string",version:"string",authToken:"json",placeholders:"json",defaultFilterValues:"json",currentTheme:"string",customCards:"json",customStyle:"json",onChartElementClicked:"function",onFilterValuesChange:"function",onEvent:"function",onSave:"function",LoadingComponent:"function",ErrorComponent:"function",showAssistant:"boolean",selectedSheetId:"string",eventHandlers:"json",preferences:"json"},Det=Eet(Kee,{props:_et});function C6(e,t){(t==null||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n<t;n++)r[n]=e[n];return r}function Met(e){if(Array.isArray(e))return e}function Tet(e,t,n){return(t=$et(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function Ret(e,t){var n=e==null?null:typeof Symbol<"u"&&e[Symbol.iterator]||e["@@iterator"];if(n!=null){var r,s,o,i,a=[],l=!0,u=!1;try{if(o=(n=n.call(e)).next,t!==0)for(;!(l=(r=o.call(n)).done)&&(a.push(r.value),a.length!==t);l=!0);}catch(d){u=!0,s=d}finally{try{if(!l&&n.return!=null&&(i=n.return(),Object(i)!==i))return}finally{if(u)throw s}}return a}}function Iet(){throw new TypeError(`Invalid attempt to destructure non-iterable instance.
1098
+ `)}})}});var IQe=kXe(()=>Cee(ai([Kn({type:Tt("text-start"),id:st(),providerMetadata:ur.optional()}),Kn({type:Tt("text-delta"),id:st(),delta:st(),providerMetadata:ur.optional()}),Kn({type:Tt("text-end"),id:st(),providerMetadata:ur.optional()}),Kn({type:Tt("error"),errorText:st()}),Kn({type:Tt("tool-input-start"),toolCallId:st(),toolName:st(),providerExecuted:qs().optional(),dynamic:qs().optional()}),Kn({type:Tt("tool-input-delta"),toolCallId:st(),inputTextDelta:st()}),Kn({type:Tt("tool-input-available"),toolCallId:st(),toolName:st(),input:sa(),providerExecuted:qs().optional(),providerMetadata:ur.optional(),dynamic:qs().optional()}),Kn({type:Tt("tool-input-error"),toolCallId:st(),toolName:st(),input:sa(),providerExecuted:qs().optional(),providerMetadata:ur.optional(),dynamic:qs().optional(),errorText:st()}),Kn({type:Tt("tool-output-available"),toolCallId:st(),output:sa(),providerExecuted:qs().optional(),dynamic:qs().optional(),preliminary:qs().optional()}),Kn({type:Tt("tool-output-error"),toolCallId:st(),errorText:st(),providerExecuted:qs().optional(),dynamic:qs().optional()}),Kn({type:Tt("reasoning-start"),id:st(),providerMetadata:ur.optional()}),Kn({type:Tt("reasoning-delta"),id:st(),delta:st(),providerMetadata:ur.optional()}),Kn({type:Tt("reasoning-end"),id:st(),providerMetadata:ur.optional()}),Kn({type:Tt("source-url"),sourceId:st(),url:st(),title:st().optional(),providerMetadata:ur.optional()}),Kn({type:Tt("source-document"),sourceId:st(),mediaType:st(),title:st(),filename:st().optional(),providerMetadata:ur.optional()}),Kn({type:Tt("file"),url:st(),mediaType:st(),providerMetadata:ur.optional()}),Kn({type:xee(e=>typeof e=="string"&&e.startsWith("data-"),{message:'Type must start with "data-"'}),id:st().optional(),data:sa(),transient:qs().optional()}),Kn({type:Tt("start-step")}),Kn({type:Tt("finish-step")}),Kn({type:Tt("start"),messageId:st().optional(),messageMetadata:sa().optional()}),Kn({type:Tt("finish"),finishReason:pee(["stop","length","content-filter","tool-calls","error","other","unknown"]).optional(),messageMetadata:sa().optional()}),Kn({type:Tt("abort")}),Kn({type:Tt("message-metadata"),messageMetadata:sa()})])));function AQe(e){return e.type.startsWith("data-")}function Tee(e,t){if(e===void 0&&t===void 0)return;if(e===void 0)return t;if(t===void 0)return e;const n={...e};for(const r in t)if(Object.prototype.hasOwnProperty.call(t,r)){const s=t[r];if(s===void 0)continue;const o=r in e?e[r]:void 0,i=s!==null&&typeof s=="object"&&!Array.isArray(s)&&!(s instanceof Date)&&!(s instanceof RegExp),a=o!=null&&typeof o=="object"&&!Array.isArray(o)&&!(o instanceof Date)&&!(o instanceof RegExp);i&&a?n[r]=Tee(o,s):n[r]=s}return n}function PQe(e){const t=["ROOT"];let n=-1,r=null;function s(l,u,d){switch(l){case'"':{n=u,t.pop(),t.push(d),t.push("INSIDE_STRING");break}case"f":case"t":case"n":{n=u,r=u,t.pop(),t.push(d),t.push("INSIDE_LITERAL");break}case"-":{t.pop(),t.push(d),t.push("INSIDE_NUMBER");break}case"0":case"1":case"2":case"3":case"4":case"5":case"6":case"7":case"8":case"9":{n=u,t.pop(),t.push(d),t.push("INSIDE_NUMBER");break}case"{":{n=u,t.pop(),t.push(d),t.push("INSIDE_OBJECT_START");break}case"[":{n=u,t.pop(),t.push(d),t.push("INSIDE_ARRAY_START");break}}}function o(l,u){switch(l){case",":{t.pop(),t.push("INSIDE_OBJECT_AFTER_COMMA");break}case"}":{n=u,t.pop();break}}}function i(l,u){switch(l){case",":{t.pop(),t.push("INSIDE_ARRAY_AFTER_COMMA");break}case"]":{n=u,t.pop();break}}}for(let l=0;l<e.length;l++){const u=e[l];switch(t[t.length-1]){case"ROOT":s(u,l,"FINISH");break;case"INSIDE_OBJECT_START":{switch(u){case'"':{t.pop(),t.push("INSIDE_OBJECT_KEY");break}case"}":{n=l,t.pop();break}}break}case"INSIDE_OBJECT_AFTER_COMMA":{switch(u){case'"':{t.pop(),t.push("INSIDE_OBJECT_KEY");break}}break}case"INSIDE_OBJECT_KEY":{switch(u){case'"':{t.pop(),t.push("INSIDE_OBJECT_AFTER_KEY");break}}break}case"INSIDE_OBJECT_AFTER_KEY":{switch(u){case":":{t.pop(),t.push("INSIDE_OBJECT_BEFORE_VALUE");break}}break}case"INSIDE_OBJECT_BEFORE_VALUE":{s(u,l,"INSIDE_OBJECT_AFTER_VALUE");break}case"INSIDE_OBJECT_AFTER_VALUE":{o(u,l);break}case"INSIDE_STRING":{switch(u){case'"':{t.pop(),n=l;break}case"\\":{t.push("INSIDE_STRING_ESCAPE");break}default:n=l}break}case"INSIDE_ARRAY_START":{switch(u){case"]":{n=l,t.pop();break}default:{n=l,s(u,l,"INSIDE_ARRAY_AFTER_VALUE");break}}break}case"INSIDE_ARRAY_AFTER_VALUE":{switch(u){case",":{t.pop(),t.push("INSIDE_ARRAY_AFTER_COMMA");break}case"]":{n=l,t.pop();break}default:{n=l;break}}break}case"INSIDE_ARRAY_AFTER_COMMA":{s(u,l,"INSIDE_ARRAY_AFTER_VALUE");break}case"INSIDE_STRING_ESCAPE":{t.pop(),n=l;break}case"INSIDE_NUMBER":{switch(u){case"0":case"1":case"2":case"3":case"4":case"5":case"6":case"7":case"8":case"9":{n=l;break}case"e":case"E":case"-":case".":break;case",":{t.pop(),t[t.length-1]==="INSIDE_ARRAY_AFTER_VALUE"&&i(u,l),t[t.length-1]==="INSIDE_OBJECT_AFTER_VALUE"&&o(u,l);break}case"}":{t.pop(),t[t.length-1]==="INSIDE_OBJECT_AFTER_VALUE"&&o(u,l);break}case"]":{t.pop(),t[t.length-1]==="INSIDE_ARRAY_AFTER_VALUE"&&i(u,l);break}default:{t.pop();break}}break}case"INSIDE_LITERAL":{const f=e.substring(r,l+1);!"false".startsWith(f)&&!"true".startsWith(f)&&!"null".startsWith(f)?(t.pop(),t[t.length-1]==="INSIDE_OBJECT_AFTER_VALUE"?o(u,l):t[t.length-1]==="INSIDE_ARRAY_AFTER_VALUE"&&i(u,l)):n=l;break}}}let a=e.slice(0,n+1);for(let l=t.length-1;l>=0;l--)switch(t[l]){case"INSIDE_STRING":{a+='"';break}case"INSIDE_OBJECT_KEY":case"INSIDE_OBJECT_AFTER_KEY":case"INSIDE_OBJECT_AFTER_COMMA":case"INSIDE_OBJECT_START":case"INSIDE_OBJECT_BEFORE_VALUE":case"INSIDE_OBJECT_AFTER_VALUE":{a+="}";break}case"INSIDE_ARRAY_START":case"INSIDE_ARRAY_AFTER_COMMA":case"INSIDE_ARRAY_AFTER_VALUE":{a+="]";break}case"INSIDE_LITERAL":{const d=e.substring(r,e.length);"true".startsWith(d)?a+="true".slice(d.length):"false".startsWith(d)?a+="false".slice(d.length):"null".startsWith(d)&&(a+="null".slice(d.length))}}return a}async function Ree(e){if(e===void 0)return{value:void 0,state:"undefined-input"};let t=await a1({text:e});return t.success?{value:t.value,state:"successful-parse"}:(t=await a1({text:PQe(e)}),t.success?{value:t.value,state:"repaired-parse"}:{value:void 0,state:"failed-parse"})}function yv(e){return e.type.startsWith("tool-")}function OQe(e){return e.type==="dynamic-tool"}function L_(e){return yv(e)||OQe(e)}function y6(e){return e.type.split("-").slice(1).join("-")}function FQe({lastMessage:e,messageId:t}){return{message:(e==null?void 0:e.role)==="assistant"?e:{id:t,metadata:void 0,role:"assistant",parts:[]},activeTextParts:{},activeReasoningParts:{},partialToolCalls:{}}}function $Qe({stream:e,messageMetadataSchema:t,dataPartSchemas:n,runUpdateMessageJob:r,onError:s,onToolCall:o,onData:i}){return e.pipeThrough(new TransformStream({async transform(a,l){await r(async({state:u,write:d})=>{var f,h,m,p;function g(w){const S=u.message.parts.filter(yv).find(j=>j.toolCallId===w);if(S==null)throw new Error("tool-output-error must be preceded by a tool-input-available");return S}function b(w){const S=u.message.parts.filter(j=>j.type==="dynamic-tool").find(j=>j.toolCallId===w);if(S==null)throw new Error("tool-output-error must be preceded by a tool-input-available");return S}function x(w){var N;const S=u.message.parts.find(_=>yv(_)&&_.toolCallId===w.toolCallId),j=w,E=S;S!=null?(S.state=w.state,E.input=j.input,E.output=j.output,E.errorText=j.errorText,E.rawInput=j.rawInput,E.preliminary=j.preliminary,E.providerExecuted=(N=j.providerExecuted)!=null?N:S.providerExecuted,j.providerMetadata!=null&&S.state==="input-available"&&(S.callProviderMetadata=j.providerMetadata)):u.message.parts.push({type:`tool-${w.toolName}`,toolCallId:w.toolCallId,state:w.state,input:j.input,output:j.output,rawInput:j.rawInput,errorText:j.errorText,providerExecuted:j.providerExecuted,preliminary:j.preliminary,...j.providerMetadata!=null?{callProviderMetadata:j.providerMetadata}:{}})}function y(w){var N,S;const j=u.message.parts.find(k=>k.type==="dynamic-tool"&&k.toolCallId===w.toolCallId),E=w,_=j;j!=null?(j.state=w.state,_.toolName=w.toolName,_.input=E.input,_.output=E.output,_.errorText=E.errorText,_.rawInput=(N=E.rawInput)!=null?N:_.rawInput,_.preliminary=E.preliminary,_.providerExecuted=(S=E.providerExecuted)!=null?S:j.providerExecuted,E.providerMetadata!=null&&j.state==="input-available"&&(j.callProviderMetadata=E.providerMetadata)):u.message.parts.push({type:"dynamic-tool",toolName:w.toolName,toolCallId:w.toolCallId,state:w.state,input:E.input,output:E.output,errorText:E.errorText,preliminary:E.preliminary,providerExecuted:E.providerExecuted,...E.providerMetadata!=null?{callProviderMetadata:E.providerMetadata}:{}})}async function v(w){if(w!=null){const N=u.message.metadata!=null?Tee(u.message.metadata,w):w;t!=null&&await m6({value:N,schema:t}),u.message.metadata=N}}switch(a.type){case"text-start":{const w={type:"text",text:"",providerMetadata:a.providerMetadata,state:"streaming"};u.activeTextParts[a.id]=w,u.message.parts.push(w),d();break}case"text-delta":{const w=u.activeTextParts[a.id];w.text+=a.delta,w.providerMetadata=(f=a.providerMetadata)!=null?f:w.providerMetadata,d();break}case"text-end":{const w=u.activeTextParts[a.id];w.state="done",w.providerMetadata=(h=a.providerMetadata)!=null?h:w.providerMetadata,delete u.activeTextParts[a.id],d();break}case"reasoning-start":{const w={type:"reasoning",text:"",providerMetadata:a.providerMetadata,state:"streaming"};u.activeReasoningParts[a.id]=w,u.message.parts.push(w),d();break}case"reasoning-delta":{const w=u.activeReasoningParts[a.id];w.text+=a.delta,w.providerMetadata=(m=a.providerMetadata)!=null?m:w.providerMetadata,d();break}case"reasoning-end":{const w=u.activeReasoningParts[a.id];w.providerMetadata=(p=a.providerMetadata)!=null?p:w.providerMetadata,w.state="done",delete u.activeReasoningParts[a.id],d();break}case"file":{u.message.parts.push({type:"file",mediaType:a.mediaType,url:a.url}),d();break}case"source-url":{u.message.parts.push({type:"source-url",sourceId:a.sourceId,url:a.url,title:a.title,providerMetadata:a.providerMetadata}),d();break}case"source-document":{u.message.parts.push({type:"source-document",sourceId:a.sourceId,mediaType:a.mediaType,title:a.title,filename:a.filename,providerMetadata:a.providerMetadata}),d();break}case"tool-input-start":{const w=u.message.parts.filter(yv);u.partialToolCalls[a.toolCallId]={text:"",toolName:a.toolName,index:w.length,dynamic:a.dynamic},a.dynamic?y({toolCallId:a.toolCallId,toolName:a.toolName,state:"input-streaming",input:void 0,providerExecuted:a.providerExecuted}):x({toolCallId:a.toolCallId,toolName:a.toolName,state:"input-streaming",input:void 0,providerExecuted:a.providerExecuted}),d();break}case"tool-input-delta":{const w=u.partialToolCalls[a.toolCallId];w.text+=a.inputTextDelta;const{value:N}=await Ree(w.text);w.dynamic?y({toolCallId:a.toolCallId,toolName:w.toolName,state:"input-streaming",input:N}):x({toolCallId:a.toolCallId,toolName:w.toolName,state:"input-streaming",input:N}),d();break}case"tool-input-available":{a.dynamic?y({toolCallId:a.toolCallId,toolName:a.toolName,state:"input-available",input:a.input,providerExecuted:a.providerExecuted,providerMetadata:a.providerMetadata}):x({toolCallId:a.toolCallId,toolName:a.toolName,state:"input-available",input:a.input,providerExecuted:a.providerExecuted,providerMetadata:a.providerMetadata}),d(),o&&!a.providerExecuted&&await o({toolCall:a});break}case"tool-input-error":{a.dynamic?y({toolCallId:a.toolCallId,toolName:a.toolName,state:"output-error",input:a.input,errorText:a.errorText,providerExecuted:a.providerExecuted,providerMetadata:a.providerMetadata}):x({toolCallId:a.toolCallId,toolName:a.toolName,state:"output-error",input:void 0,rawInput:a.input,errorText:a.errorText,providerExecuted:a.providerExecuted,providerMetadata:a.providerMetadata}),d();break}case"tool-output-available":{if(a.dynamic){const w=b(a.toolCallId);y({toolCallId:a.toolCallId,toolName:w.toolName,state:"output-available",input:w.input,output:a.output,preliminary:a.preliminary})}else{const w=g(a.toolCallId);x({toolCallId:a.toolCallId,toolName:y6(w),state:"output-available",input:w.input,output:a.output,providerExecuted:a.providerExecuted,preliminary:a.preliminary})}d();break}case"tool-output-error":{if(a.dynamic){const w=b(a.toolCallId);y({toolCallId:a.toolCallId,toolName:w.toolName,state:"output-error",input:w.input,errorText:a.errorText,providerExecuted:a.providerExecuted})}else{const w=g(a.toolCallId);x({toolCallId:a.toolCallId,toolName:y6(w),state:"output-error",input:w.input,rawInput:w.rawInput,errorText:a.errorText,providerExecuted:a.providerExecuted})}d();break}case"start-step":{u.message.parts.push({type:"step-start"});break}case"finish-step":{u.activeTextParts={},u.activeReasoningParts={};break}case"start":{a.messageId!=null&&(u.message.id=a.messageId),await v(a.messageMetadata),(a.messageId!=null||a.messageMetadata!=null)&&d();break}case"finish":{a.finishReason!=null&&(u.finishReason=a.finishReason),await v(a.messageMetadata),a.messageMetadata!=null&&d();break}case"message-metadata":{await v(a.messageMetadata),a.messageMetadata!=null&&d();break}case"error":{s==null||s(new Error(a.errorText));break}default:if(AQe(a)){(n==null?void 0:n[a.type])!=null&&await m6({value:a.data,schema:n[a.type]});const w=a;if(w.transient){i==null||i(w);break}const N=w.id!=null?u.message.parts.find(S=>w.type===S.type&&w.id===S.id):void 0;N!=null?N.data=w.data:u.message.parts.push(w),i==null||i(w),d()}}l.enqueue(a)})}}))}async function LQe({stream:e,onError:t}){const n=e.getReader();try{for(;;){const{done:r}=await n.read();if(r)break}}catch(r){t==null||t(r)}finally{n.releaseLock()}}fy({prefix:"aitxt",size:24});fy({prefix:"aiobj",size:24});var zQe=class{constructor(){this.queue=[],this.isProcessing=!1}async processQueue(){if(!this.isProcessing){for(this.isProcessing=!0;this.queue.length>0;)await this.queue[0](),this.queue.shift();this.isProcessing=!1}}async run(e){return new Promise((t,n)=>{this.queue.push(async()=>{try{await e(),t()}catch(r){n(r)}}),this.processQueue()})}};fy({prefix:"aiobj",size:24});var BQe={};CQe(BQe,{object:()=>HQe,text:()=>VQe});var VQe=()=>({type:"text",responseFormat:{type:"text"},async parsePartial({text:e}){return{partial:e}},async parseOutput({text:e}){return e}}),HQe=({schema:e})=>{const t=wQe(e);return{type:"object",responseFormat:{type:"json",schema:t.jsonSchema},async parsePartial({text:n}){const r=await Ree(n);switch(r.state){case"failed-parse":case"undefined-input":return;case"repaired-parse":case"successful-parse":return{partial:r.value};default:{const s=r.state;throw new Error(`Unsupported parse state: ${s}`)}}},async parseOutput({text:n},r){const s=await a1({text:n});if(!s.success)throw new b6({message:"No object generated: could not parse the response.",cause:s.error,text:n,response:r.response,usage:r.usage,finishReason:r.finishReason});const o=await pA({value:s.value,schema:t});if(!o.success)throw new b6({message:"No object generated: response did not match schema.",cause:o.error,text:n,response:r.response,usage:r.usage,finishReason:r.finishReason});return o.value}}};async function UQe(e){if(e==null)return[];if(!globalThis.FileList||!(e instanceof globalThis.FileList))throw new Error("FileList is not supported in the current environment");return Promise.all(Array.from(e).map(async t=>{const{name:n,type:r}=t,s=await new Promise((o,i)=>{const a=new FileReader;a.onload=l=>{var u;o((u=l.target)==null?void 0:u.result)},a.onerror=l=>i(l),a.readAsDataURL(t)});return{type:"file",mediaType:r,filename:n,url:s}}))}var WQe=class{constructor({api:e="/api/chat",credentials:t,headers:n,body:r,fetch:s,prepareSendMessagesRequest:o,prepareReconnectToStreamRequest:i}){this.api=e,this.credentials=t,this.headers=n,this.body=r,this.fetch=s,this.prepareSendMessagesRequest=o,this.prepareReconnectToStreamRequest=i}async sendMessages({abortSignal:e,...t}){var n,r,s,o,i;const a=await If(this.body),l=await If(this.headers),u=await If(this.credentials),d={...$u(l),...$u(t.headers)},f=await((n=this.prepareSendMessagesRequest)==null?void 0:n.call(this,{api:this.api,id:t.chatId,messages:t.messages,body:{...a,...t.body},headers:d,credentials:u,requestMetadata:t.metadata,trigger:t.trigger,messageId:t.messageId})),h=(r=f==null?void 0:f.api)!=null?r:this.api,m=(f==null?void 0:f.headers)!==void 0?$u(f.headers):d,p=(f==null?void 0:f.body)!==void 0?f.body:{...a,...t.body,id:t.chatId,messages:t.messages,trigger:t.trigger,messageId:t.messageId},g=(s=f==null?void 0:f.credentials)!=null?s:u,x=await((o=this.fetch)!=null?o:globalThis.fetch)(h,{method:"POST",headers:f6({"Content-Type":"application/json",...m},`ai-sdk/${x6}`,d6()),body:JSON.stringify(p),credentials:g,signal:e});if(!x.ok)throw new Error((i=await x.text())!=null?i:"Failed to fetch the chat response.");if(!x.body)throw new Error("The response body is empty.");return this.processResponseStream(x.body)}async reconnectToStream(e){var t,n,r,s,o;const i=await If(this.body),a=await If(this.headers),l=await If(this.credentials),u={...$u(a),...$u(e.headers)},d=await((t=this.prepareReconnectToStreamRequest)==null?void 0:t.call(this,{api:this.api,id:e.chatId,body:{...i,...e.body},headers:u,credentials:l,requestMetadata:e.metadata})),f=(n=d==null?void 0:d.api)!=null?n:`${this.api}/${e.chatId}/stream`,h=(d==null?void 0:d.headers)!==void 0?$u(d.headers):u,m=(r=d==null?void 0:d.credentials)!=null?r:l,g=await((s=this.fetch)!=null?s:globalThis.fetch)(f,{method:"GET",headers:f6(h,`ai-sdk/${x6}`,d6()),credentials:m});if(g.status===204)return null;if(!g.ok)throw new Error((o=await g.text())!=null?o:"Failed to fetch the chat response.");if(!g.body)throw new Error("The response body is empty.");return this.processResponseStream(g.body)}},bA=class extends WQe{constructor(e={}){super(e)}processResponseStream(e){return DXe({stream:e,schema:IQe}).pipeThrough(new TransformStream({async transform(t,n){if(!t.success)throw t.error;n.enqueue(t.value)}}))}},qQe=class{constructor({generateId:e=yXe,id:t=e(),transport:n=new bA,messageMetadataSchema:r,dataPartSchemas:s,state:o,onError:i,onToolCall:a,onFinish:l,onData:u,sendAutomaticallyWhen:d}){this.activeResponse=void 0,this.jobExecutor=new zQe,this.sendMessage=async(f,h)=>{var m,p,g,b;if(f==null){await this.makeRequest({trigger:"submit-message",messageId:(m=this.lastMessage)==null?void 0:m.id,...h});return}let x;if("text"in f||"files"in f?x={parts:[...Array.isArray(f.files)?f.files:await UQe(f.files),..."text"in f&&f.text!=null?[{type:"text",text:f.text}]:[]]}:x=f,f.messageId!=null){const y=this.state.messages.findIndex(v=>v.id===f.messageId);if(y===-1)throw new Error(`message with id ${f.messageId} not found`);if(this.state.messages[y].role!=="user")throw new Error(`message with id ${f.messageId} is not a user message`);this.state.messages=this.state.messages.slice(0,y+1),this.state.replaceMessage(y,{...x,id:f.messageId,role:(p=x.role)!=null?p:"user",metadata:f.metadata})}else this.state.pushMessage({...x,id:(g=x.id)!=null?g:this.generateId(),role:(b=x.role)!=null?b:"user",metadata:f.metadata});await this.makeRequest({trigger:"submit-message",messageId:f.messageId,...h})},this.regenerate=async({messageId:f,...h}={})=>{const m=f==null?this.state.messages.length-1:this.state.messages.findIndex(p=>p.id===f);if(m===-1)throw new Error(`message ${f} not found`);this.state.messages=this.state.messages.slice(0,this.messages[m].role==="assistant"?m:m+1),await this.makeRequest({trigger:"regenerate-message",messageId:f,...h})},this.resumeStream=async(f={})=>{await this.makeRequest({trigger:"resume-stream",...f})},this.clearError=()=>{this.status==="error"&&(this.state.error=void 0,this.setStatus({status:"ready"}))},this.addToolOutput=async({state:f="output-available",tool:h,toolCallId:m,output:p,errorText:g})=>this.jobExecutor.run(async()=>{var b,x;const y=this.state.messages,v=y[y.length-1];this.state.replaceMessage(y.length-1,{...v,parts:v.parts.map(w=>L_(w)&&w.toolCallId===m?{...w,state:f,output:p,errorText:g}:w)}),this.activeResponse&&(this.activeResponse.state.message.parts=this.activeResponse.state.message.parts.map(w=>L_(w)&&w.toolCallId===m?{...w,state:f,output:p,errorText:g}:w)),this.status!=="streaming"&&this.status!=="submitted"&&((b=this.sendAutomaticallyWhen)!=null&&b.call(this,{messages:this.state.messages}))&&this.makeRequest({trigger:"submit-message",messageId:(x=this.lastMessage)==null?void 0:x.id})}),this.addToolResult=this.addToolOutput,this.stop=async()=>{var f;this.status!=="streaming"&&this.status!=="submitted"||(f=this.activeResponse)!=null&&f.abortController&&this.activeResponse.abortController.abort()},this.id=t,this.transport=n,this.generateId=e,this.messageMetadataSchema=r,this.dataPartSchemas=s,this.state=o,this.onError=i,this.onToolCall=a,this.onFinish=l,this.onData=u,this.sendAutomaticallyWhen=d}get status(){return this.state.status}setStatus({status:e,error:t}){this.status!==e&&(this.state.status=e,this.state.error=t)}get error(){return this.state.error}get messages(){return this.state.messages}get lastMessage(){return this.state.messages[this.state.messages.length-1]}set messages(e){this.state.messages=e}async makeRequest({trigger:e,metadata:t,headers:n,body:r,messageId:s}){var o,i,a,l;this.setStatus({status:"submitted",error:void 0});const u=this.lastMessage;let d=!1,f=!1,h=!1;try{const m={state:FQe({lastMessage:this.state.snapshot(u),messageId:this.generateId()}),abortController:new AbortController};m.abortController.signal.addEventListener("abort",()=>{d=!0}),this.activeResponse=m;let p;if(e==="resume-stream"){const b=await this.transport.reconnectToStream({chatId:this.id,metadata:t,headers:n,body:r});if(b==null){this.setStatus({status:"ready"});return}p=b}else p=await this.transport.sendMessages({chatId:this.id,messages:this.state.messages,abortSignal:m.abortController.signal,metadata:t,headers:n,body:r,trigger:e,messageId:s});const g=b=>this.jobExecutor.run(()=>b({state:m.state,write:()=>{var x;this.setStatus({status:"streaming"}),m.state.message.id===((x=this.lastMessage)==null?void 0:x.id)?this.state.replaceMessage(this.state.messages.length-1,m.state.message):this.state.pushMessage(m.state.message)}}));await LQe({stream:$Qe({stream:p,onToolCall:this.onToolCall,onData:this.onData,messageMetadataSchema:this.messageMetadataSchema,dataPartSchemas:this.dataPartSchemas,runUpdateMessageJob:g,onError:b=>{throw b}}),onError:b=>{throw b}}),this.setStatus({status:"ready"})}catch(m){if(d||m.name==="AbortError")return d=!0,this.setStatus({status:"ready"}),null;h=!0,m instanceof TypeError&&(m.message.toLowerCase().includes("fetch")||m.message.toLowerCase().includes("network"))&&(f=!0),this.onError&&m instanceof Error&&this.onError(m),this.setStatus({status:"error",error:m})}finally{try{(i=this.onFinish)==null||i.call(this,{message:this.activeResponse.state.message,messages:this.state.messages,isAbort:d,isDisconnect:f,isError:h,finishReason:(o=this.activeResponse)==null?void 0:o.state.finishReason})}catch(m){console.error(m)}this.activeResponse=void 0}(a=this.sendAutomaticallyWhen)!=null&&a.call(this,{messages:this.state.messages})&&!h&&await this.makeRequest({trigger:"submit-message",messageId:(l=this.lastMessage)==null?void 0:l.id,metadata:t,headers:n,body:r})}};function YQe({messages:e}){const t=e[e.length-1];if(!t||t.role!=="assistant")return!1;const n=t.parts.reduce((s,o,i)=>o.type==="step-start"?i:s,-1),r=t.parts.slice(n+1).filter(L_).filter(s=>!s.providerExecuted);return r.length>0&&r.every(s=>s.state==="output-available"||s.state==="output-error")}function GQe(e,t){if(typeof e!="function")throw new TypeError(`Expected the first argument to be a \`function\`, got \`${typeof e}\`.`);let n,r=0;return function(...o){clearTimeout(n);const i=Date.now(),a=i-r,l=t-a;l<=0?(r=i,e.apply(this,o)):n=setTimeout(()=>{r=Date.now(),e.apply(this,o)},l)}}var KQe=GQe;const ZQe=Jc(KQe);var Iee=(e,t,n)=>{if(!t.has(e))throw TypeError("Cannot "+n)},Fn=(e,t,n)=>(Iee(e,t,"read from private field"),n?n.call(e):t.get(e)),Ji=(e,t,n)=>{if(t.has(e))throw TypeError("Cannot add the same private member more than once");t instanceof WeakSet?t.add(e):t.set(e,n)},nc=(e,t,n,r)=>(Iee(e,t,"write to private field"),t.set(e,n),n);function XQe(e,t){return t!=null?ZQe(e,t):e}var Fo,vv,wv,lg,cg,ug,Lf,z_,B_,QQe=class{constructor(e=[]){Ji(this,Fo,void 0),Ji(this,vv,"ready"),Ji(this,wv,void 0),Ji(this,lg,new Set),Ji(this,cg,new Set),Ji(this,ug,new Set),this.pushMessage=t=>{nc(this,Fo,Fn(this,Fo).concat(t)),Fn(this,Lf).call(this)},this.popMessage=()=>{nc(this,Fo,Fn(this,Fo).slice(0,-1)),Fn(this,Lf).call(this)},this.replaceMessage=(t,n)=>{nc(this,Fo,[...Fn(this,Fo).slice(0,t),this.snapshot(n),...Fn(this,Fo).slice(t+1)]),Fn(this,Lf).call(this)},this.snapshot=t=>structuredClone(t),this["~registerMessagesCallback"]=(t,n)=>{const r=n?XQe(t,n):t;return Fn(this,lg).add(r),()=>{Fn(this,lg).delete(r)}},this["~registerStatusCallback"]=t=>(Fn(this,cg).add(t),()=>{Fn(this,cg).delete(t)}),this["~registerErrorCallback"]=t=>(Fn(this,ug).add(t),()=>{Fn(this,ug).delete(t)}),Ji(this,Lf,()=>{Fn(this,lg).forEach(t=>t())}),Ji(this,z_,()=>{Fn(this,cg).forEach(t=>t())}),Ji(this,B_,()=>{Fn(this,ug).forEach(t=>t())}),nc(this,Fo,e)}get status(){return Fn(this,vv)}set status(e){nc(this,vv,e),Fn(this,z_).call(this)}get error(){return Fn(this,wv)}set error(e){nc(this,wv,e),Fn(this,B_).call(this)}get messages(){return Fn(this,Fo)}set messages(e){nc(this,Fo,[...e]),Fn(this,Lf).call(this)}};Fo=new WeakMap;vv=new WeakMap;wv=new WeakMap;lg=new WeakMap;cg=new WeakMap;ug=new WeakMap;Lf=new WeakMap;z_=new WeakMap;B_=new WeakMap;var zf,v6=class extends qQe{constructor({messages:e,...t}){const n=new QQe(e);super({...t,state:n}),Ji(this,zf,void 0),this["~registerMessagesCallback"]=(r,s)=>Fn(this,zf)["~registerMessagesCallback"](r,s),this["~registerStatusCallback"]=r=>Fn(this,zf)["~registerStatusCallback"](r),this["~registerErrorCallback"]=r=>Fn(this,zf)["~registerErrorCallback"](r),nc(this,zf,n)}};zf=new WeakMap;function Aee({experimental_throttle:e,resume:t=!1,...n}={}){const r=C.useRef("chat"in n?n.chat:new v6(n));("chat"in n&&n.chat!==r.current||"id"in n&&r.current.id!==n.id)&&(r.current="chat"in n?n.chat:new v6(n));const o="id"in n?n.id:null,i=C.useCallback(f=>r.current["~registerMessagesCallback"](f,e),[e,o]),a=C.useSyncExternalStore(i,()=>r.current.messages,()=>r.current.messages),l=C.useSyncExternalStore(r.current["~registerStatusCallback"],()=>r.current.status,()=>r.current.status),u=C.useSyncExternalStore(r.current["~registerErrorCallback"],()=>r.current.error,()=>r.current.error),d=C.useCallback(f=>{typeof f=="function"&&(f=f(r.current.messages)),r.current.messages=f},[r]);return C.useEffect(()=>{t&&r.current.resumeStream()},[t,r]),{id:r.current.id,messages:a,setMessages:d,sendMessage:r.current.sendMessage,regenerate:r.current.regenerate,clearError:r.current.clearError,stop:r.current.stop,error:u,resumeStream:r.current.resumeStream,status:l,addToolResult:r.current.addToolOutput,addToolOutput:r.current.addToolOutput}}function JQe(e,t){return e.some(n=>n.tableName&&n.tableName===t.tableName||n.datamodelName&&n.datamodelName===t.datamodelName)}function eJe(e){return e.filter((n,r,s)=>r===s.findIndex(o=>o.tableName===n.tableName&&o.datamodelName===n.datamodelName))}function tJe(e,t){return e.filter(n=>!(n.connectionId===t.connectionId&&n.tableName===t.tableName&&n.datamodelName===t.datamodelName))}function nJe(e){return e.toLowerCase()==="clickhouse"?"{database_name}.{table_name}":e.toLowerCase()==="postgres"?"{schema_name}.{table_name}":"{table_name}"}function Pee(e){return e.map(r=>{const s=r.connectionType==="API"||r.connectionType==="S3"||r.connectionType==="S3Tables"?"DuckDb":r.connectionType;return r.datamodelName?{...r,databaseName:"",schemaName:"",tableName:"",connectionType:s,tableReferenceFormat:"dm.{table_name}"}:{...r,connectionType:s,tableReferenceFormat:nJe(s)}}).filter(r=>r.datamodelName?r.connectionId&&r.datamodelName&&r.connectionType:r.connectionId&&r.tableName&&r.connectionType)}function Oee(e){var n,r;if(!e)return"";let t="";try{const s=JSON.parse((e==null?void 0:e.message)||"{}");t=((r=(n=s==null?void 0:s.error)==null?void 0:n.lastError)==null?void 0:r.message)||(s==null?void 0:s.error)||e.message}catch{t=e.message}return t}function rJe(){var b;const{authToken:e,tokenProps:t}=Ge(),n=X(x=>x.dashboard.aiScopeTables),r=(b=C1().data)==null?void 0:b.assistantProfileId,{sendMessage:s,messages:o,setMessages:i,regenerate:a,status:l,addToolResult:u,error:d,stop:f,clearError:h}=Aee({transport:new bA({api:`${t.apiServiceUrl}/v1/assistant`,headers:()=>({Authorization:`Bearer ${e==null?void 0:e.accessToken}`}),body:()=>{const x=qi.getState();return{assistantId:"dashboard-assistant",assistantProfileId:r,aiContext:x.currentAIContext,reasoningEffort:x.reasoningEffort,showReasoning:x.showReasoning}},credentials:"omit",prepareSendMessagesRequest:({messages:x,body:y})=>({body:{...y,messages:Iq(x)}})}),onToolCall:m,sendAutomaticallyWhen:YQe,onFinish({isAbort:x,isDisconnect:y,isError:v}){console.log(x?"[Dashboard Assistant] Stream aborted by user":y?"[Dashboard Assistant] Stream disconnected (network error)":v?"[Dashboard Assistant] Stream error occurred":"[Dashboard Assistant] Stream completed successfully")},onError(x){var y;if(x.name==="AbortError"||(y=x.message)!=null&&y.includes("aborted")){console.log("[Dashboard Assistant] Stream aborted (expected)");return}console.error("[Dashboard Assistant] Stream error:",x)}});async function m({toolCall:x}){if(x.toolName==="getCurrentTableScope"&&u({tool:x.toolName,toolCallId:x.toolCallId,output:{tables:Pee(n||[])}}),x.toolName==="getDashboardContext"){const y=X.getState().dashboard;u({tool:x.toolName,toolCallId:x.toolCallId,output:{dashboardContext:y}})}}const p=!["ready","error"].includes(l),g=Oee(d);return{sendMessage:s,regenerate:a,isLoading:p,messages:o,setMessages:i,status:l,stop:f,errorMessage:g,clearError:h}}function Fee(){var u;const{authToken:e,tokenProps:t}=Ge(),n=(u=C1().data)==null?void 0:u.assistantProfileId;function r(){return!(!n||!(e!=null&&e.accessToken))}const{data:s,isLoading:o,isFetching:i,isError:a}=hn({queryKey:["assistant-profile",n],queryFn:()=>qn(`${t.apiServiceUrl}/v1/assistant/${n}`,(e==null?void 0:e.accessToken)||""),enabled:r()});return{assistantProfile:s==null?void 0:s.assistantProfile,isLoading:o,isFetching:i,isError:a}}function $ee({seedQuestions:e,handleSeedQuestionClick:t}){return e.length===0?null:c.jsxs("div",{className:"overflow-x-auto rounded-md border bg-muted/40 p-4",children:[c.jsxs("div",{className:"mb-3 flex items-center",children:[c.jsx(p8,{className:"mr-2 h-4 w-4 text-muted-foreground"}),c.jsx("h3",{className:"font-medium",children:"Example Questions"})]}),c.jsx("div",{className:"flex flex-wrap gap-2",children:e.map((n,r)=>c.jsx(se,{variant:"outline",size:"sm",onClick:()=>t(n),className:"text-sm",children:n},r))})]})}function l1(e,t={}){const{size:n="h-4 w-4"}=t,r=n;switch(e){case"table":return c.jsx(HD,{className:r});case"view":return c.jsx($c,{className:r});case"materialized view":return c.jsx(rle,{className:r});case"model":return c.jsx(D1,{className:r});case"file":return c.jsx(Fi,{className:r});case"dataset":return c.jsx(Cl,{className:r});case"upload":return c.jsx(YD,{className:r});case"url":return c.jsx(w8,{className:r});default:return c.jsx(E1,{className:r})}}const Lee=T.forwardRef(({className:e,...t},n)=>c.jsxs("div",{className:"flex items-center px-3","cmdk-input-wrapper":"",children:[c.jsx(Ui,{className:"mr-2 h-4 w-4 shrink-0 opacity-50"}),c.jsx(Ss.Input,{ref:n,className:Z("flex h-11 w-full rounded-md bg-transparent py-3 text-sm outline-none placeholder:text-muted-foreground disabled:cursor-not-allowed disabled:opacity-50",e),...t})]}));Lee.displayName=Ss.Input.displayName;const U0=e=>e.label||(e==null?void 0:e.name),w6=e=>"description"in e?e.description:`${e.type} from ${e.database||"database"}`;function sJe({isOpen:e,onSelect:t,onDeselect:n,onClose:r,availableEntities:s,selectedEntities:o,onTabComplete:i,onSelectAll:a,onRemoveAll:l,onAddContext:u}){const{tokenProps:d}=Ge(),f=(d==null?void 0:d.type)==="dashboard",[h,m]=C.useState(""),[p,g]=C.useState(""),b=s.filter(S=>{if(!h)return!0;const j=U0(S).toLowerCase(),E=w6(S).toLowerCase(),_=h.toLowerCase();return j.includes(_)||E.includes(_)});C.useEffect(()=>{e||(m(""),g(""))},[e]),C.useEffect(()=>{b.length>0&&!p&&g(U0(b[0]))},[b,p]);const x=()=>{if(!p)return;const S=b.find(j=>U0(j)===p);S&&(o.some(E=>"id"in S&&"id"in E?S.id===E.id:S.name===E.name&&S.connectionId===E.connectionId)||t(S),i(S),r())},y=S=>{(S.key==="Tab"||S.key==="Enter")&&(S.preventDefault(),x())};if(!e)return null;const v=S=>o.some(j=>"id"in S&&"id"in j?S.id===j.id:S.name===j.name&&S.connectionId===j.connectionId),w=o.length===s.length,N=o.length>0;return c.jsx(c.Fragment,{children:c.jsxs(Lm,{shouldFilter:!1,value:p,onValueChange:g,onKeyDown:y,children:[s.length>0&&c.jsxs("div",{className:"flex items-center justify-between border-b pr-3",children:[c.jsx(Lee,{placeholder:"Search entities...",value:h,onValueChange:m,className:"flex-1 border-0",autoFocus:!0}),!f&&c.jsxs(se,{onClick:S=>{S.preventDefault(),S.stopPropagation(),u==null||u()},onMouseDown:S=>{S.preventDefault(),S.stopPropagation()},variant:"outline",size:"sm",className:"h-7 shrink-0",children:[c.jsx(Sr,{className:"mr-1 h-4 w-4"}),"Add"]})]}),s.length>0&&c.jsxs("div",{className:"flex items-center justify-between border-b px-3 py-2 text-sm",children:[c.jsxs("div",{className:"text-muted-foreground",children:[o.length," ",o.length===1?"entity":"entities"," selected"]}),c.jsxs("div",{className:"flex items-center gap-1",children:[c.jsx(se,{onClick:S=>{S.preventDefault(),S.stopPropagation(),a==null||a()},onMouseDown:S=>{S.preventDefault(),S.stopPropagation()},disabled:w,variant:"ghost",size:"sm",className:"h-6 px-2 text-xs",children:"Select All"}),N&&c.jsxs(se,{onClick:S=>{S.preventDefault(),S.stopPropagation(),l==null||l()},onMouseDown:S=>{S.preventDefault(),S.stopPropagation()},variant:"ghost",size:"sm",className:"h-6 gap-1 px-2 text-xs",children:[c.jsx(yt,{className:"h-3.5 w-3.5"}),"Clear"]})]})]}),c.jsxs(zm,{className:"min-h-60",children:[c.jsx(Bm,{children:c.jsxs("div",{className:"flex flex-col items-center justify-center py-4",children:[c.jsx("p",{className:"mb-3 text-sm text-muted-foreground",children:"No entities found."}),!f&&c.jsxs(se,{onClick:S=>{S.preventDefault(),S.stopPropagation(),u==null||u()},onMouseDown:S=>{S.preventDefault(),S.stopPropagation()},size:"sm",variant:"outline",className:"flex items-center gap-2",children:[c.jsx(Sr,{className:"h-4 w-4"}),"Add Datasets"]})]})}),c.jsx(Vm,{children:b.map((S,j)=>{const E=v(S),_="id"in S?S.id:`${S.connectionId}-${S.name}`,k=U0(S);return c.jsxs(Hm,{value:k,onSelect:()=>{E?n==null||n(S):t(S)},onMouseDown:M=>{M.preventDefault(),M.stopPropagation()},className:Z("flex cursor-pointer items-start gap-2 p-2 hover:bg-gray-100"),children:[c.jsx("div",{className:"mt-0.5 flex h-5 w-5 shrink-0 items-center justify-center",children:l1(S.type)}),c.jsxs("div",{className:"min-w-0 flex-1",children:[c.jsx("div",{className:"truncate font-medium",children:k}),c.jsx("div",{className:"truncate text-xs text-muted-foreground",children:w6(S)})]}),E&&c.jsx("div",{className:"ml-1 flex h-5 w-5 shrink-0 items-center justify-center rounded-full bg-foreground/80",children:c.jsx(Mr,{className:"h-3 w-3 text-background"})})]},_)})})]})]})})}const V_=e=>e.name||e.name,oJe=e=>{const t=V_(e),n="description"in e?e.description:"",r=e.database||"",s=e.schema||"";return c.jsxs("div",{className:"space-y-1",children:[c.jsx("div",{className:"font-medium",children:t}),n&&c.jsx("div",{className:"text-sm text-muted-foreground",children:n}),c.jsxs("div",{className:"text-xs text-muted-foreground",children:["Type: ",e.type,r&&` • Database: ${r}`,s&&` • Schema: ${s}`]})]})};function iJe({entities:e,availableEntities:t,onRemoveEntity:n,onRemoveEntities:r}){const[s,o]=C.useState(!1),i=e.length>0;e.length,t.length,e.length<t.length;const a=e.length>=3?e.slice(0,2):e,l=e.length>=3?e.slice(2):[],u=l.length>0;return c.jsx(_n,{children:c.jsx("div",{className:"space-y-2",children:i&&c.jsxs("div",{className:"flex flex-wrap gap-1",children:[a.map((d,f)=>{const h="id"in d?d.id:`${d.connectionId}-${d.name}`;return c.jsxs(Zt,{children:[c.jsx(Xt,{asChild:!0,children:c.jsxs(Fe,{variant:"secondary",className:"group relative cursor-pointer gap-2 transition-colors hover:border-red-200 hover:bg-red-50 dark:hover:border-red-800 dark:hover:bg-red-950",children:[l1(d.type,{size:"h-3 w-3"}),c.jsx("span",{className:"max-w-24 truncate text-xs",children:V_(d)}),c.jsx("button",{className:"rounded-full p-0.5 transition-opacity hover:bg-red-100 group-hover:opacity-100",onClick:()=>n(d),children:c.jsx(yt,{className:"h-3 w-3"})})]})}),c.jsx(en,{side:"top",className:"max-w-xs",children:oJe(d)})]},h)}),u&&c.jsxs(Zt,{open:s,onOpenChange:o,children:[c.jsx(Xt,{asChild:!0,children:c.jsxs(Fe,{variant:"secondary",className:"flex cursor-pointer items-center gap-1 transition-colors hover:bg-secondary/80",onClick:()=>o(!0),children:[c.jsx(sle,{className:"h-3 w-3"}),c.jsxs("span",{className:"text-xs",children:[l.length," more"]}),c.jsx("button",{className:"rounded-full p-0.5 transition-opacity hover:bg-red-100 group-hover:opacity-100",onClick:()=>r(l),children:c.jsx(yt,{className:"h-3 w-3"})})]})}),c.jsx(en,{side:"top",className:"max-h-60 max-w-xs overflow-y-auto p-2",children:c.jsxs("div",{className:"space-y-2",children:[c.jsx("div",{className:"text-sm font-medium",children:"Additional Datasets"}),c.jsx("div",{className:"space-y-2",children:l.map(d=>{const f="id"in d?d.id:`${d.connectionId}-${d.name}`;return c.jsxs("div",{className:"group flex items-center justify-between gap-2",children:[c.jsxs("div",{className:"flex items-start gap-2",children:[c.jsx("div",{className:"flex h-5 w-5 shrink-0 items-center justify-center",children:l1(d.type,{size:"h-3 w-3"})}),c.jsxs("div",{className:"min-w-0 flex-1",children:[c.jsx("div",{className:"truncate text-sm font-medium",children:V_(d)}),c.jsxs("div",{className:"truncate text-xs text-muted-foreground",children:[d.type," ",d.database?`• ${d.database}`:""]})]})]}),c.jsx(se,{variant:"ghost",size:"sm",className:"h-6 w-6 p-0 opacity-0 group-hover:opacity-100",onClick:()=>{n(d),l.length===1&&o(!1)},children:c.jsx(yt,{className:"h-3 w-3"})})]},f)})})]})})]})]})})})}function zee(e){return e.type==="dataset"&&e.label||e.name}function aJe(e){const t=[];return t.push({label:"Type",value:e.type}),t.push({label:"Name",value:e.name}),e.connectionType&&t.push({label:"Connection",value:e.connectionType}),e.database&&t.push({label:"Database",value:e.database}),e.schema&&t.push({label:"Schema",value:e.schema}),e.type==="dataset"&&e.label&&t.push({label:"Label",value:e.label}),e.type==="dataset"&&e.description&&t.push({label:"Description",value:e.description}),e.type==="model"&&e.label&&t.push({label:"Label",value:e.label}),e.type==="model"&&e.description&&t.push({label:"Description",value:e.description}),t}function lJe({selectedEntities:e,onDeselectEntity:t}){return e.length===0?null:c.jsxs("div",{className:"mb-4 space-y-2",children:[c.jsxs(ce,{className:"mb-2 text-xs font-medium text-muted-foreground",children:["Selected Entities (",e.length,")"]}),c.jsx("div",{className:"max-h-32 overflow-y-auto rounded-md border border-border/50 p-2",children:c.jsx("div",{className:"flex flex-wrap gap-1",children:e.map((n,r)=>c.jsxs(Fe,{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:[c.jsxs("span",{className:"mr-1 text-gray-500",children:["[",n.type,"]"]}),zee(n),c.jsx("button",{onClick:s=>{s.stopPropagation(),t(n)},className:"absolute right-1 top-1/2 -translate-y-1/2 rounded-full p-0.5 opacity-0 transition-opacity hover:bg-red-100 group-hover:opacity-100",children:c.jsx(yt,{className:"h-2.5 w-2.5 text-red-500"})})]},`${n.type}-${n.name}-${r}`))})})]})}function cJe(e){const{tokenProps:t}=Ge(),n=X(l=>l.authToken)||e;_e(l=>l.selectedConnectionId),_e(l=>{var u,d;return(d=(u=l==null?void 0:l.card)==null?void 0:u.dataSource)==null?void 0:d.connectionId});const{refetch:r,isPending:s,data:o,isLoading:i,isError:a}=hn({queryKey:["semantic-domains"],queryFn:()=>qn(`${t.apiServiceUrl}/v1/domains`,(n==null?void 0:n.accessToken)||""),enabled:!!(n!=null&&n.accessToken)});return{isPending:s,error:a,semanticDomainsData:o,semanticDomains:(o==null?void 0:o.domains)||[],isSemanticDomainsLoading:i,isSemanticDomainsError:a,refetchSemanticDomains:r}}function uJe(e,t){const{tokenProps:n}=Ge(),r=X(u=>u.authToken)||t,{refetch:s,isPending:o,data:i,isLoading:a,isError:l}=hn({queryKey:["datasets",e],queryFn:()=>qn(`${n.apiServiceUrl}/v1/datasets`,(r==null?void 0:r.accessToken)||"",{domainId:e}),enabled:!!(r!=null&&r.accessToken)&&!!e});return{isPending:o,error:l,datasets:(i==null?void 0:i.datasets)||[],isDatasetsLoading:a,isDatasetsError:l,refetchDatasets:s}}function dJe(e){var g,b;const{tokenProps:t}=Ge(),n=X(x=>x.authToken)||e,{connections:r}=$a(e),s=_e(x=>{var y,v;return(v=(y=x==null?void 0:x.card)==null?void 0:y.dataSource)==null?void 0:v.connectionId}),o=r==null?void 0:r.find(x=>x.id===s),i=o==null?void 0:o.type,a=o==null?void 0:o.capabilities,l=((g=a==null?void 0:a.labels)==null?void 0:g.database)||"Database";function u(x){return s&&x?!(x==="API"||x==="S3"):!1}const{data:d,isPending:f,error:h,refetch:m}=hn({queryKey:["databases",s],queryFn:()=>qn(`${t.apiServiceUrl}/v1/databases`,(n==null?void 0:n.accessToken)||"",{connection_id:s}),enabled:u(i)}),p=(b=d==null?void 0:d.databases)==null?void 0:b.map(x=>({id:x.database_name,name:x.database_name}));return{isPending:f,error:h,databases:p||[],refetch:m,label:l}}function fJe(e){var g;const{tokenProps:t}=Ge(),n=X(b=>b.authToken)||e,{connections:r}=$a(e),s=_e(b=>{var x,y;return(y=(x=b==null?void 0:b.card)==null?void 0:x.dataSource)==null?void 0:y.connectionId}),o=_e(b=>{var x,y,v;return(v=(y=(x=b==null?void 0:b.card)==null?void 0:x.dataSource)==null?void 0:y.dbSelection)==null?void 0:v.database}),i=r==null?void 0:r.find(b=>b.id===s),a=i==null?void 0:i.capabilities,l=((g=a==null?void 0:a.labels)==null?void 0:g.schema)||"Schema";function u(){return!(!s||(i==null?void 0:i.type)==="API"||(i==null?void 0:i.type)==="S3"||!o||!(a!=null&&a.path.includes("schema")))}const{data:d,isPending:f,error:h,refetch:m}=hn({queryKey:["schemas",s,o],queryFn:()=>qn(`${t.apiServiceUrl}/v1/schemas`,(n==null?void 0:n.accessToken)||"",{connection_id:s,database_name:o}),enabled:u()}),p=d==null?void 0:d.schemas.map(b=>({id:b.schema_name,name:b.schema_name}));return{isPending:f,error:h,schemas:p||[],refetch:m,label:l}}function Bee(e){const{tokenProps:t}=Ge(),n=X(h=>h.authToken)||e,{connections:r}=$a(e),s=_e(h=>{var m,p;return(p=(m=h==null?void 0:h.card)==null?void 0:m.dataSource)==null?void 0:p.connectionId}),o=r.find(h=>h.id===s);function i(){return!(!(n!=null&&n.accessToken)||!s)}const{data:a,isPending:l,error:u,refetch:d}=hn({queryKey:["dataModels",s],queryFn:()=>qn(`${t.apiServiceUrl}/v1/datamodels`,(n==null?void 0:n.accessToken)||"",{connection_id:s}),enabled:i()}),f=a==null?void 0:a.datamodels.map(h=>({id:h.id,name:h.name,label:h.label,description:h.description,connectionId:s,dialect:h.dialect,connectionType:o==null?void 0:o.type,type:"model",database:h.database,schema:h.schema}));return{isPending:l,error:u,dataModels:f||[],refetch:d}}function hJe(){var N,S,j;const e=_e(E=>E.card.dataSource);_e(E=>E.actions.updateDirectSource);const t=_e(E=>E.actions.updateDataSource),[n,r]=C.useState(""),{selectedConnection:s,error:o}=$a(),{databases:i,isPending:a,error:l,label:u}=dJe(),{schemas:d,isPending:f,error:h,label:m}=fJe(),{error:p}=Bee(),g=s==null?void 0:s.capabilities.path.includes("schema"),b=s==null?void 0:s.capabilities.path.includes("database"),x=u==null?void 0:u.toLowerCase(),y=m==null?void 0:m.toLowerCase(),v=E=>{e&&t({...e,dbSelection:{database:E,schema:"",entityType:"table"},selectedEntities:(e==null?void 0:e.selectedEntities)||[]})},w=E=>{var k;if(!((k=e==null?void 0:e.dbSelection)!=null&&k.database))return;const _=e.dbSelection||{database:"",schema:"",entityType:"table"};t({...e,dbSelection:{..._,schema:E},selectedEntities:(e==null?void 0:e.selectedEntities)||[]})};return c.jsxs(c.Fragment,{children:[(o||l||h||p)&&c.jsxs("div",{className:"rounded-md border border-red-200 bg-red-50 p-3",children:[c.jsx("div",{className:"flex items-center",children:c.jsxs("div",{className:"text-sm text-red-800",children:[c.jsx("strong",{children:"Error loading data:"}),c.jsxs("ul",{className:"mt-1 list-inside list-disc",children:[o&&c.jsxs("li",{children:["Connections: ",o]}),l&&c.jsxs("li",{children:[u,": ",l.message]}),h&&c.jsxs("li",{children:[m,": ",h.message]}),p&&c.jsxs("li",{children:["Data Models: ",p.message]})]})]})}),c.jsx(se,{variant:"outline",size:"sm",className:"mt-2",onClick:()=>window.location.reload(),children:"Retry"})]}),c.jsxs("div",{className:"space-y-4",children:[b&&c.jsxs("div",{className:"space-y-2",children:[c.jsx(ce,{className:"text-sm font-medium",children:u}),c.jsxs(nt,{value:((N=e==null?void 0:e.dbSelection)==null?void 0:N.database)||"",onValueChange:v,disabled:a,children:[c.jsx(et,{className:"w-full",children:c.jsxs("div",{className:"flex items-center gap-2",children:[a&&c.jsx(an,{className:"h-4 w-4 animate-spin"}),c.jsx(ot,{placeholder:l?`Error loading ${x}`:a?`Loading ${x}...`:`Select ${x}...`})]})}),c.jsx(tt,{children:i.map(E=>c.jsx(be,{className:"hover:bg-muted",value:E.id,children:E.name},E.id))})]})]}),((S=e==null?void 0:e.dbSelection)==null?void 0:S.database)&&g&&c.jsxs("div",{className:"space-y-2",children:[c.jsx(ce,{className:"text-sm font-medium",children:m}),c.jsxs(nt,{value:((j=e==null?void 0:e.dbSelection)==null?void 0:j.schema)||"",onValueChange:w,disabled:f,children:[c.jsx(et,{className:"w-full",children:c.jsxs("div",{className:"flex items-center gap-2",children:[f&&c.jsx(an,{className:"h-4 w-4 animate-spin"}),c.jsx(ot,{placeholder:h?`Error loading ${y}`:f?`Loading ${y}...`:`Select ${y}...`})]})}),c.jsx(tt,{children:d.map(E=>c.jsx(be,{className:"hover:bg-muted",value:E.id,children:E.name},E.id))})]})]})]})]})}function mJe(){const e=_e(l=>l.card.dataSource),t=_e(l=>l.actions.updateDataSource),[n,r]=C.useState(!1),s=l=>{if(!l||(e==null?void 0:e.mode)!=="upload")return;const u=Array.from(l).map(f=>({id:`file-${Date.now()}-${Math.random()}`,name:f.name,type:"upload",connectionId:"default",connectionType:"none",label:f.name,description:`Uploaded ${new Date().toLocaleString()}`,originalName:f.name,file:f})),d=(e==null?void 0:e.selectedEntities)||[];t({...e,selectedEntities:[...d,...u]})},o=l=>{if(!e)return;const u=(e.selectedEntities||[]).filter(d=>d.id!==l);t({...e,selectedEntities:u})},i=l=>{if(l===0)return"0 Bytes";const u=1024,d=["Bytes","KB","MB","GB"],f=Math.floor(Math.log(l)/Math.log(u));return Number.parseFloat((l/Math.pow(u,f)).toFixed(2))+" "+d[f]},a=(e==null?void 0:e.selectedEntities)||[];return c.jsxs("div",{className:"space-y-4",children:[c.jsxs("div",{className:"space-y-2",children:[c.jsx(ce,{className:"text-sm font-medium",children:"Upload Files"}),c.jsxs("div",{className:`rounded-lg border-2 border-dashed p-6 text-center transition-colors ${n?"border-blue-400 bg-blue-50":"border-gray-300 hover:border-gray-400"}`,onDragOver:l=>{l.preventDefault(),r(!0)},onDragLeave:()=>r(!1),onDrop:l=>{l.preventDefault(),r(!1),s(l.dataTransfer.files)},children:[c.jsx(YD,{className:"mx-auto mb-2 h-8 w-8 text-gray-400"}),c.jsx("p",{className:"mb-2 text-sm text-gray-600",children:"Drag and drop files here, or click to select"}),c.jsx("input",{type:"file",multiple:!0,className:"hidden",id:"file-upload",onChange:l=>s(l.target.files),accept:".csv,.json,.xlsx,.xls"}),c.jsx(se,{variant:"outline",size:"sm",onClick:()=>{var l;return(l=document.getElementById("file-upload"))==null?void 0:l.click()},children:"Select Files"}),c.jsx("p",{className:"mt-2 text-xs text-gray-500",children:"Supports CSV, JSON, Excel files"})]})]}),a.length>0&&c.jsxs("div",{className:"space-y-2",children:[c.jsxs(ce,{className:"text-xs text-gray-600",children:["Uploaded Files (",a.length,")"]}),c.jsx("div",{className:"max-h-40 space-y-1 overflow-y-auto",children:a.map(l=>c.jsxs("div",{className:"flex items-center justify-between rounded border bg-gray-50 p-2",children:[c.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[c.jsx(Fi,{className:"h-4 w-4 flex-shrink-0 text-gray-500"}),c.jsxs("div",{className:"min-w-0",children:[c.jsx("p",{className:"truncate text-sm text-gray-700",children:l.originalName}),c.jsx("p",{className:"text-xs text-gray-500",children:l.file?i(l.file.size):""})]})]}),c.jsx(se,{variant:"ghost",size:"sm",className:"h-6 w-6 flex-shrink-0 p-0",onClick:()=>o(l.id),children:c.jsx(yt,{className:"h-3 w-3"})})]},l.id))})]})]})}function pJe(){const e=_e(f=>f.card.dataSource),t=_e(f=>f.actions.updateDataSource),[n,r]=C.useState(""),[s,o]=C.useState(""),[i,a]=C.useState("api"),l=()=>{if(!n.trim()||!s.trim()||!e)return;const f={id:`url-${Date.now()}-${Math.random()}`,name:n.trim(),type:"url",connectionId:"default",connectionType:"none",label:n.trim(),description:`URL source of type ${i}`,url:s.trim(),sourceType:i,originalName:n.trim()},h=(e==null?void 0:e.selectedEntities)||[];t({...e,selectedEntities:[...h,f]}),r(""),o(""),a("api")},u=f=>{if(!e)return;const h=(e.selectedEntities||[]).filter(m=>m.id!==f);t({...e,selectedEntities:h})},d=(e==null?void 0:e.selectedEntities)||[];return c.jsxs("div",{className:"space-y-4",children:[c.jsxs("div",{className:"space-y-2",children:[c.jsx(ce,{className:"text-sm font-medium text-gray-700",children:"URL Sources"}),c.jsxs("div",{className:"space-y-3 rounded-lg border bg-gray-50 p-3",children:[c.jsxs("div",{className:"space-y-2",children:[c.jsx(ce,{className:"text-xs text-gray-600",children:"Source Name"}),c.jsx(Nn,{placeholder:"e.g., Sales API, Customer Data",value:n,onChange:f=>r(f.target.value),className:"h-8 text-sm"})]}),c.jsxs("div",{className:"space-y-2",children:[c.jsx(ce,{className:"text-xs text-gray-600",children:"URL"}),c.jsx(Nn,{placeholder:"https://api.example.com/data",value:s,onChange:f=>o(f.target.value),className:"h-8 text-sm"})]}),c.jsxs("div",{className:"space-y-2",children:[c.jsx(ce,{className:"text-xs text-gray-600",children:"Type"}),c.jsxs("select",{value:i,onChange:f=>a(f.target.value),className:"h-8 w-full rounded-md border border-gray-300 px-2 text-sm",children:[c.jsx("option",{value:"api",children:"API Endpoint"}),c.jsx("option",{value:"csv",children:"CSV File"}),c.jsx("option",{value:"json",children:"JSON File"})]})]}),c.jsxs(se,{onClick:l,disabled:!n.trim()||!s.trim(),size:"sm",className:"w-full",children:[c.jsx(Sr,{className:"mr-1 h-3 w-3"}),"Add Source"]})]})]}),d.length>0&&c.jsxs("div",{className:"space-y-2",children:[c.jsxs(ce,{className:"text-xs text-gray-600",children:["Added Sources (",d.length,")"]}),c.jsx("div",{className:"max-h-40 space-y-1 overflow-y-auto",children:d.map(f=>c.jsxs("div",{className:"flex items-center justify-between rounded border bg-gray-50 p-2",children:[c.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[c.jsx(E1,{className:"h-4 w-4 flex-shrink-0 text-gray-500"}),c.jsxs("div",{className:"min-w-0",children:[c.jsx("p",{className:"truncate text-sm text-gray-700",children:f.name}),c.jsx("p",{className:"truncate text-xs text-gray-500",children:f.url})]})]}),c.jsx(se,{variant:"ghost",size:"sm",className:"h-6 w-6 flex-shrink-0 p-0",onClick:()=>u(f.id),children:c.jsx(yt,{className:"h-3 w-3"})})]},f.id))})]})]})}function gJe(e,t){var y,v;const{tokenProps:n}=Ge(),r=X(w=>w.authToken)||t,{connections:s}=$a(t),o=_e(w=>{var N,S;return(S=(N=w==null?void 0:w.card)==null?void 0:N.dataSource)==null?void 0:S.connectionId}),i=_e(w=>{var N,S,j;return(j=(S=(N=w==null?void 0:w.card)==null?void 0:N.dataSource)==null?void 0:S.dbSelection)==null?void 0:j.database}),a=_e(w=>{var N,S,j;return(j=(S=(N=w==null?void 0:w.card)==null?void 0:N.dataSource)==null?void 0:S.dbSelection)==null?void 0:j.schema}),l=s==null?void 0:s.find(w=>w.id===o),u=l==null?void 0:l.capabilities,d=((y=u==null?void 0:u.labels)==null?void 0:y.schema)||"Schema";function f(){return o?(l==null?void 0:l.type)==="API"||(l==null?void 0:l.type)==="S3"?!0:!(!i||u!=null&&u.path.includes("schema")&&!a):!1}const{data:h,isPending:m,isLoading:p,error:g,refetch:b}=hn({queryKey:[e,o,i,a],queryFn:()=>qn(`${n.apiServiceUrl}/v1/${e}s`,(r==null?void 0:r.accessToken)||"",{connection_id:o,database_name:i,schema_name:a}),enabled:f()}),x=(v=h==null?void 0:h[`${e}s`])==null?void 0:v.map(w=>{var N;return{connectionId:l==null?void 0:l.id,connectionType:l==null?void 0:l.type,dialect:l==null?void 0:l.dialect,type:e,dbObjectType:(N=w==null?void 0:w.table_type)==null?void 0:N.toLowerCase(),id:w[`${e}_name`],database:i,schema:a,name:w[`${e}_name`]}});return{isPending:m,isLoading:p,error:g,entities:x||[],refetch:b,label:d}}function c1({title:e,message:t}){return c.jsx("div",{className:"rounded-xl border border-destructive/40 bg-destructive/10 p-4 text-destructive shadow-sm",children:c.jsxs("div",{className:"flex items-start gap-4",children:[c.jsx(Fc,{className:"h-6 w-6 flex-shrink-0"}),c.jsxs("div",{className:"flex-1",children:[c.jsx("h4",{className:"text-base font-semibold",children:e}),t&&c.jsx("p",{className:"mt-1 text-sm text-destructive/90",children:t})]})]})})}function bJe({dataSource:e,onSelectionChange:t,selectedEntities:n,onRegisterSelectAll:r}){const{connections:s,isPending:o}=$a(),[i,a]=C.useState(""),[l,u]=C.useState(""),[d,f]=C.useState("tables"),{updateDataSource:h,setSelectedConnectionId:m}=Qn(),{entities:p,isLoading:g,error:b}=gJe("table"),{dataModels:x,isPending:y,error:v}=Bee(),w=k=>{const M=s.find(R=>R.id===k);if(!M)return;const D=M.type==="upload"?"upload":M.type==="url"?"url":"database";h({...e,connectionId:k,connectionType:M.type,mode:D,dbSelection:{database:"",schema:"",entityType:"table"}}),m(k)},N=k=>{var P,I;const M=n||[],D=M.some(L=>L.name===k.name&&L.type===k.type);let R;if(D)R=M.filter(L=>!(L.name===k.name&&L.type===k.type));else{const L={connectionId:e.connectionId,connectionType:e.connectionType,type:k.type,dbObjectType:k.dbObjectType,database:((P=e.dbSelection)==null?void 0:P.database)||"",schema:((I=e.dbSelection)==null?void 0:I.schema)||"",name:k.name,dialect:k.dialect};R=[...M,L]}t==null||t(R)},S=k=>{const M=n||[],D=M.some(P=>P.type==="model"&&P.name===k.name);let R;D?R=M.filter(P=>!(P.type==="model"&&P.name===k.name)):R=[...M,k],t==null||t(R)},j=p.filter(k=>k.name.toLowerCase().includes(i.toLowerCase())),E=x.filter(k=>k.name.toLowerCase().includes(l.toLowerCase())),_=C.useCallback(()=>{if(!t)return;const k=n||[];let M=[...k];if(d==="tables"){const R=j.filter(P=>!k.some(I=>I.name===P.name&&I.type==="table")).map(P=>{var I,L;return{connectionId:e.connectionId,connectionType:e.connectionType,type:"table",dbObjectType:P.dbObjectType,database:((I=e.dbSelection)==null?void 0:I.database)||"",schema:((L=e.dbSelection)==null?void 0:L.schema)||"",name:P.name,dialect:P.dialect}});M=[...k,...R]}else if(d==="datamodels"){const D=E.filter(R=>!k.some(P=>P.name===R.name&&P.type==="model"));M=[...k,...D]}t(M)},[d,j,E,n,e,t]);return C.useEffect(()=>{r&&r(_)},[r,_]),c.jsxs("div",{className:"space-y-4",children:[c.jsxs("div",{className:"space-y-2",children:[c.jsx(ce,{className:"font-medium= text-sm",children:"Connection"}),c.jsxs(nt,{value:(e==null?void 0:e.connectionId)||"",onValueChange:w,disabled:o,children:[c.jsx(et,{className:"w-full",children:c.jsx(ot,{placeholder:o?"Loading connections...":"Select connection..."})}),c.jsx(tt,{children:s.map(k=>c.jsx(be,{className:"hover:bg-muted",value:k.id,children:c.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[c.jsx(Cl,{className:"h-4 w-4 flex-shrink-0"}),c.jsx("span",{className:"truncate",children:k.name}),c.jsx(Fe,{variant:"secondary",className:"flex-shrink-0 text-xs",children:k.type})]})},k.id))})]})]}),(e==null?void 0:e.connectionId)&&c.jsxs(c.Fragment,{children:[e.connectionType==="upload"&&c.jsx(mJe,{}),e.connectionType==="url"&&c.jsx(pJe,{}),e.connectionType!=="upload"&&e.connectionType!=="url"&&c.jsxs(c.Fragment,{children:[c.jsx(hJe,{}),c.jsx("div",{className:"space-y-4",children:c.jsx("div",{className:"space-y-2",children:c.jsxs(Bs,{defaultValue:"tables",value:d,onValueChange:k=>f(k),className:"w-full",children:[c.jsxs(vs,{className:"grid w-full grid-cols-2",children:[c.jsxs(Gt,{value:"tables",children:["Tables & Views (",j.length,")"]}),c.jsxs(Gt,{value:"datamodels",children:["Data Models (",E.length,")"]})]}),c.jsxs(sr,{value:"tables",className:"space-y-2",children:[c.jsx(xn,{placeholder:"Search tables and views...",value:i,onChange:k=>a(k.target.value),className:"h-8 text-sm",disabled:g}),c.jsx("div",{className:"max-h-40 space-y-1 overflow-y-auto",children:g?c.jsx("div",{className:"py-4 text-center text-sm",children:"Loading tables..."}):b?c.jsx(c1,{title:"Error loading tables",message:b.message||"Failed to load tables. Please try again.",onRetry:()=>window.location.reload()}):j.length===0?c.jsx("div",{className:"py-4 text-center text-sm",children:"No tables or views found"}):j.map(k=>{const M=n.some(D=>D.name===k.name&&D.type==="table");return c.jsxs("div",{className:"group flex cursor-pointer items-center space-x-2 rounded p-2 hover:bg-muted",onClick:()=>N(k),children:[c.jsx(Qt,{id:`table-${k.name}`,checked:M,onCheckedChange:()=>N(k),onClick:D=>D.stopPropagation(),disabled:g}),c.jsxs(ce,{className:"flex flex-1 cursor-pointer items-center gap-2",children:[k.name,k.dbObjectType==="view"&&c.jsx(Fe,{variant:"secondary",className:"text-xs group-hover:border-border",children:"View"}),k.dbObjectType==="materialized view"&&c.jsx(Fe,{variant:"secondary",className:"text-xs group-hover:border-border",children:"Materialized View"})]})]},k.name)})})]}),c.jsxs(sr,{value:"datamodels",className:"space-y-2",children:[c.jsx(xn,{placeholder:"Search data models...",value:l,onChange:k=>u(k.target.value),className:"h-8 text-sm",disabled:y}),c.jsx("div",{className:"max-h-40 space-y-1 overflow-y-auto",children:y?c.jsx("div",{className:"py-4 text-center text-sm",children:"Loading data models..."}):v?c.jsx(c1,{title:"Error loading data models",message:v.message||"Failed to load data models. Please try again.",onRetry:()=>window.location.reload()}):E.length===0?c.jsx("div",{className:"py-4 text-center text-sm",children:"No data models found"}):E.map(k=>{const M=n.some(D=>D.name===k.name&&D.type==="model");return c.jsxs("div",{className:"flex cursor-pointer items-start space-x-2 rounded p-2 hover:bg-muted",onClick:()=>S(k),children:[c.jsx(Qt,{id:`dataModel-${k.name}`,checked:M,onCheckedChange:()=>S(k),onClick:D=>D.stopPropagation(),disabled:y}),c.jsxs("div",{className:"flex flex-1 cursor-pointer flex-col gap-1",children:[c.jsx(ce,{className:"cursor-pointer",children:k.name}),c.jsx("span",{className:"text-xs text-muted-foreground",children:k.description})]})]},k.name)})})]})]})})})]})]})]})}function xJe({dataSource:e,onDataSourceUpdate:t,onSelectionChange:n,selectedEntities:r,allowedDomainIds:s=[],isRestricted:o=!1,autoSelectedDomainId:i,onRegisterSelectAll:a}){var N;const[l,u]=C.useState(""),d=C.useCallback(S=>{const j={...e,connectionId:e.connectionId||"none",connectionType:e.connectionType||"none",mode:"semanticDomain",semanticDomainId:S};t({...j})},[e,t]);C.useEffect(()=>{i&&!(e!=null&&e.semanticDomainId)&&d(i)},[i,e==null?void 0:e.semanticDomainId,d]);const{semanticDomains:f,isPending:h,error:m}=cJe(),p=o?f.filter(S=>s.includes(S.id)):f,{datasets:g,isPending:b,error:x}=uJe(e==null?void 0:e.semanticDomainId),y=S=>{const j=r||[],E=j.some(k=>k.id===S.id&&k.type==="dataset");let _;if(E)_=j.filter(k=>!(k.id===S.id&&k.type==="dataset"));else{const k={id:S.id,datasetType:S.type,name:S.name||S.table,label:S.label,domainId:S.domainId,description:S.description,database:S.database,schema:S.schema,type:"dataset",connectionId:S.connectionId,connectionType:S.connectionType,dialect:S.dialect,datamodelId:S.datamodelId,sql:S.sql};_=[...j,k]}n==null||n(_)},v=g.filter(S=>S.name.toLowerCase().includes(l.toLowerCase())),w=C.useCallback(()=>{if(!n||!(e!=null&&e.semanticDomainId))return;const S=r||[],E=v.filter(k=>!S.some(M=>M.id===k.id&&M.type==="dataset")).map(k=>({id:k.id,datasetType:k.type,name:k.name||k.table,label:k.label,domainId:k.domainId,description:k.description,database:k.database,schema:k.schema,type:"dataset",connectionId:k.connectionId,connectionType:k.connectionType,dialect:k.dialect,datamodelId:k.datamodelId,sql:k.sql})),_=[...S,...E];n(_)},[v,r,e==null?void 0:e.semanticDomainId,n]);return C.useEffect(()=>{a&&a(w)},[a,w]),c.jsxs("div",{className:"space-y-4",children:[c.jsxs("div",{className:"space-y-2",children:[c.jsx(ce,{className:"text-sm font-medium",children:"Semantic Domain"}),c.jsxs(nt,{value:(e==null?void 0:e.semanticDomainId)||"",onValueChange:d,disabled:h||o&&!!i,children:[c.jsx(et,{className:"w-full",children:c.jsx(ot,{placeholder:h?"Loading semantic domains...":o&&i?"Loading domain...":"Select semantic domain...",children:((N=p.find(S=>S.id===(e==null?void 0:e.semanticDomainId)))==null?void 0:N.label)||"Select semantic domain"})}),c.jsx(tt,{children:p.map(S=>c.jsx(be,{className:"hover:bg-muted",value:S.id,children:c.jsxs("div",{className:"flex flex-col items-start",children:[c.jsx("span",{className:"font-medium",children:S.label}),c.jsx("span",{className:"text-xs",children:S.description})]})},S.id))})]}),m&&c.jsx(c1,{title:"Error loading semantic models",message:m.message})]}),(e==null?void 0:e.semanticDomainId)&&c.jsxs("div",{className:"space-y-2",children:[c.jsx(ce,{className:"text-sm font-medium text-gray-700",children:"Datasets"}),c.jsxs("div",{className:"space-y-2",children:[c.jsx(xn,{placeholder:"Search datasets...",value:l,onChange:S=>u(S.target.value),className:"h-8 text-sm",disabled:b}),c.jsx("div",{className:"max-h-40 space-y-1 overflow-y-auto",children:b?c.jsx("div",{className:"py-4 text-center text-sm text-gray-500",children:"Loading datasets..."}):x?c.jsx(c1,{title:"Error loading datasets",message:x.message||"Failed to load datasets. Please try again.",onRetry:()=>window.location.reload()}):v.length===0?c.jsx("div",{className:"py-4 text-center text-sm text-gray-500",children:l?"No datasets match your search":"No datasets available"}):v.map(S=>{const j=r.some(E=>E.id===S.id&&E.type==="dataset");return c.jsxs("div",{className:"flex cursor-pointer items-start space-x-2 rounded p-2 hover:bg-gray-50",onClick:()=>y(S),children:[c.jsx(Qt,{id:`dataset-${S.id}`,checked:j,onCheckedChange:()=>y(S),onClick:E=>E.stopPropagation(),disabled:b}),c.jsxs("div",{className:"flex flex-1 flex-col gap-1",children:[c.jsx(ce,{className:"cursor-pointer font-medium",children:S.label||S.name}),c.jsx("span",{className:"text-xs text-gray-500",children:S.description})]})]},S.label||S.name)})})]})]})]})}function xA({open:e,onOpenChange:t,dataSource:n,dialogMode:r,incomingSelectedEntities:s}){const{tokenProps:o}=Ge(),{allowedSemanticDomains:i}=o,[a,l]=C.useState([]),{updateDataSource:u}=Qn(),d=X(M=>M.isVisualEditing),f=X(M=>M.dashboard.aiContext),{setAiContext:h}=Ot(),m=C.useRef(null),[p,g]=C.useState(!1),b=i&&i.length>0,x=!b,y=b&&i.length===1?i[0]:void 0,v=C.useCallback(M=>{const D=M;u({...n,connectionId:(n==null?void 0:n.connectionId)||"",connectionType:(n==null?void 0:n.connectionType)||"",mode:D,selectedEntities:(n==null?void 0:n.selectedEntities)||[],...D!=="semanticDomain"&&{semanticDomainId:void 0}})},[n,u]),w=C.useCallback(M=>{u({...n,...M})},[n,u]);C.useEffect(()=>{b&&n.mode!=="semanticDomain"&&v("semanticDomain")},[b,n.mode,v]),C.useEffect(()=>{y&&!n.semanticDomainId&&w({semanticDomainId:y})},[y,n.semanticDomainId,w]),C.useEffect(()=>{e?l(s||[]):(m.current=null,g(!1))},[e,n==null?void 0:n.selectedEntities,r,u,s,n]);const N=M=>{const D=a.filter(R=>!(R.name===M.name&&R.type===M.type));l(D)},S=()=>{l([])},j=C.useCallback(M=>{l(M)},[]),E=C.useCallback(()=>{m.current&&m.current()},[]),_=C.useCallback(M=>{m.current=M,g(!0)},[]);function k(){var M,D;if(r==="aiContext")d&&u(n),h({...f,selectedEntities:a}),t(!1);else if(r==="dataSource"){if(n.mode==="semanticDomain"){const R=(M=a==null?void 0:a[0])==null?void 0:M.connectionId,P=(D=a==null?void 0:a[0])==null?void 0:D.connectionType;u({...n,connectionId:R,connectionType:P,selectedEntities:a})}else u({...n,selectedEntities:a});t(!1)}}return c.jsx(ns,{open:e,onOpenChange:t,children:c.jsx(Vr,{className:"flex max-w-2xl flex-col",children:c.jsxs("div",{children:[c.jsxs(Hr,{className:"flex-shrink-0",children:[c.jsx(Ur,{children:r==="aiContext"?"Data Context":"Select Data Source"}),c.jsx(ys,{children:r==="aiContext"?"Set the overall data scope for the dashboard":"Select data sets to analyze"})]}),c.jsx("div",{className:"flex-1 grow overflow-y-auto py-4",children:c.jsxs("div",{className:"space-y-4",children:[x&&c.jsx("div",{className:"space-y-2",children:c.jsx(Bs,{defaultValue:(n==null?void 0:n.mode)||"database",value:(n==null?void 0:n.mode)||"database",onValueChange:v,className:"w-full",children:c.jsxs(vs,{className:"grid w-full grid-cols-2",children:[c.jsx(Gt,{value:"database",children:"Direct Source"}),c.jsx(Gt,{value:"semanticDomain",children:"Semantic Domain"})]})})}),(n==null?void 0:n.mode)==="semanticDomain"&&c.jsx(xJe,{dataSource:n,onDataSourceUpdate:w,selectedEntities:a,onSelectionChange:j,allowedDomainIds:i||[],isRestricted:b,autoSelectedDomainId:y,onRegisterSelectAll:_}),(n==null?void 0:n.mode)==="database"&&x&&c.jsx(bJe,{dataSource:n,onDataSourceUpdate:w,selectedEntities:a,onSelectionChange:j,onRegisterSelectAll:_})]})}),c.jsx(lJe,{selectedEntities:a,onDeselectEntity:N}),c.jsx(xs,{className:"flex-shrink-0",children:c.jsx("div",{className:"flex w-full justify-between",children:c.jsxs("div",{className:"flex grow justify-end gap-2",children:[c.jsx(se,{variant:"outline",onClick:E,disabled:!p,children:"Select All"}),c.jsx(se,{variant:"outline",onClick:S,disabled:a.length===0,children:"Clear All"}),c.jsxs(se,{variant:"outline",onClick:()=>t(!1),children:[c.jsx(yt,{className:"mr-2 h-4 w-4"}),"Close"]}),c.jsxs(se,{onClick:k,children:[c.jsx(Mr,{className:"mr-2 h-4 w-4"}),"Accept"]})]})})})]})})})}function yJe({onFilesSelected:e,disabled:t=!1,currentFileCount:n=0,className:r}){const s=C.useRef(null),o=async a=>{const l=Array.from(a.target.files||[]);if(l.length===0)return;const u=tl-n;if(l.length>u){Oe.error(`You can only attach ${tl} files per message. You have ${u} slot(s) remaining.`);return}const{valid:d,errors:f}=jJ(l);if(f.forEach(({file:h,error:m})=>{Oe.error(`${h.name}: ${m}`)}),d.length>0)try{const h=await Promise.all(d.map(m=>aA(m)));e(h)}catch(h){console.error("Failed to process files:",h),Oe.error("Failed to process one or more files")}s.current&&(s.current.value="")},i=()=>{var a;(a=s.current)==null||a.click()};return c.jsxs(c.Fragment,{children:[c.jsx("input",{ref:s,type:"file",multiple:!0,accept:".png,.jpg,.jpeg,.gif,.webp,.pdf,.txt,.md,.csv,.json,.xml,.js,.jsx,.ts,.tsx,.py,.sql",onChange:o,className:"hidden",disabled:t||n>=tl}),c.jsx(se,{variant:"secondary",size:"sm",className:`h-7 px-2 ${r}`,onClick:i,disabled:t||n>=tl,title:n>=tl?`Maximum ${tl} files allowed`:"Attach files",children:c.jsx($D,{className:"h-4 w-4 text-muted-foreground"})})]})}function vJe({children:e,onFilesDropped:t,disabled:n=!1,currentFileCount:r=0,className:s}){const[o,i]=C.useState(!1),a=C.useCallback(f=>{f.preventDefault(),f.stopPropagation(),n||i(!0)},[n]),l=C.useCallback(f=>{f.preventDefault(),f.stopPropagation();const h=f.currentTarget.getBoundingClientRect(),m=f.clientX,p=f.clientY;(m<h.left||m>=h.right||p<h.top||p>=h.bottom)&&i(!1)},[]),u=C.useCallback(f=>{f.preventDefault(),f.stopPropagation()},[]),d=C.useCallback(async f=>{if(f.preventDefault(),f.stopPropagation(),i(!1),n)return;const h=Array.from(f.dataTransfer.files);if(h.length===0)return;const m=tl-r;if(h.length>m){Oe.error(`You can only attach ${tl} files per message. You have ${m} slot(s) remaining.`);return}const{valid:p,errors:g}=jJ(h);if(g.forEach(({file:b,error:x})=>{Oe.error(`${b.name}: ${x}`)}),p.length>0)try{const b=await Promise.all(p.map(x=>aA(x)));t(b),Oe.success(`${b.length} file(s) attached successfully`)}catch(b){console.error("Failed to process files:",b),Oe.error("Failed to process one or more files")}},[n,r,t]);return c.jsxs("div",{className:Z("relative",s),onDragEnter:a,onDragLeave:l,onDragOver:u,onDrop:d,children:[e,o&&!n&&c.jsx("div",{className:"pointer-events-none absolute inset-0 z-50 flex items-center justify-center rounded-lg border-2 border-dashed border-primary bg-primary/5 backdrop-blur-sm",children:c.jsxs("div",{className:"flex flex-col items-center gap-2",children:[c.jsx(YD,{className:"h-8 w-8 text-primary"}),c.jsx("p",{className:"text-sm font-medium text-primary",children:"Drop files here to upload"}),c.jsxs("p",{className:"text-xs text-muted-foreground",children:[tl-r," slot(s) available"]})]})})]})}const yA=C.forwardRef(({input:e,setInput:t,handleInputChange:n,handleSubmit:r,isLoading:s,stop:o,onFocus:i,status:a,assistantType:l},u)=>{const[d,f]=C.useState(!1),[h,m]=C.useState(!1),[p,g]=C.useState(!1),b=C.useRef(null),x=Wm();x2e(),b2e();const{setCurrentAIContext:y,updateSelectedEntities:v,setReasoningEffort:w,setShowReasoning:N}=_S(),{queueMessage:S}=qm(),{addFileAttachment:j,removeFileAttachment:E,clearFileAttachments:_,getFileAttachments:k}=BT(),M=zT(l),D=_e(V=>V.card.dataSource),R=X(V=>V.dashboard.aiContext),P=X(V=>{var G;return(G=V.dashboard.aiContext)==null?void 0:G.selectedEntities});C.useEffect(()=>{u&&"current"in u&&(u.current=b.current)},[u]);const I=C.useCallback(()=>{const V=b.current;if(V){if(!e||e.length===0){V.style.height="10px";return}V.style.height="auto";const G=Math.min(Math.max(V.scrollHeight,10),200);V.style.height=`${G}px`}},[e]);C.useEffect(()=>{I()},[I]),C.useEffect(()=>{const V=setTimeout(()=>{I()},0);return()=>clearTimeout(V)},[I]);const L=()=>{const V=e.trim();!V&&M.length===0||(a!=="ready"?(S(l,V,M),t(""),_(l)):r({preventDefault:()=>{}}))},F=V=>{V.key==="Enter"&&!V.shiftKey&&(V.preventDefault(),L()),V.key==="@"&&(U(),f(!0))},H=C.useCallback(V=>{const G=Uqe(V.nativeEvent);G.length>0&&(V.preventDefault(),G.forEach(async K=>{const J=await aA(K);j(l,J)}))},[j,l]),$=C.useCallback(V=>{V.forEach(G=>{j(l,G)})},[j,l]),A=C.useCallback(V=>{V.forEach(G=>{j(l,G)})},[j,l]),q=C.useCallback(V=>{E(l,V)},[E,l]),z=V=>{if(x.selectedEntities.some(K=>K.id&&K.id===V.id||K.name===V.name)){const K=x.selectedEntities.filter(J=>!(J.id&&J.id===V.id||J.name===V.name));y({selectedEntities:K})}else{const K=[...x.selectedEntities,V];y({selectedEntities:K})}},O=V=>{z(V)},W=V=>{var J;if(!x.selectedEntities.some(Q=>Q.id&&Q.id===V.id||Q.name===V.name)){const Q=[...x.selectedEntities,V];y({selectedEntities:Q})}const K="label"in V?V.label:V.name;t(e+`@${K} `),f(!1),(J=b.current)==null||J.focus()},B=V=>{const G=x.selectedEntities.filter(Q=>!(Q.id&&Q.id===V.id||Q.name===V.name));y({selectedEntities:G});const J=`@${"label"in V?V.label:V.name}`;e.includes(J)&&t(e.replace(J,"").trim())},Y=V=>{const G=new Set(V.map(Q=>Q.id||Q.name)),K=x.selectedEntities.filter(Q=>!G.has(Q.id||Q.name));y({selectedEntities:K});let J=e;V.forEach(Q=>{const de=`@${"label"in Q?Q.label:Q.name}`;J=J.replace(de,"").trim()}),t(J)},U=C.useCallback(()=>{x.selectedEntities.length===0&&y({selectedEntities:(R==null?void 0:R.selectedEntities)||[]})},[x.selectedEntities.length,R==null?void 0:R.selectedEntities,y]);return c.jsxs(vJe,{onFilesDropped:$,currentFileCount:M.length,disabled:s,className:"space-y-4",children:[c.jsx(iJe,{entities:x.selectedEntities,availableEntities:P||[],onRemoveEntity:B,onRemoveEntities:Y}),M.length>0&&c.jsx(Wqe,{files:M,onRemove:q,showRemove:!s,className:"mb-2"}),c.jsxs("div",{className:"rounded-lg border border-border bg-background shadow-sm focus-within:ring-1 focus-within:ring-foreground/40",children:[c.jsx("textarea",{ref:b,value:e,onChange:n,onKeyDown:F,onPaste:H,onFocus:()=>{I(),i==null||i()},placeholder:"Ask a question...",className:"max-h-[200px] min-h-[40px] w-full resize-none overflow-y-auto border-0 bg-transparent px-3 py-2 text-sm text-foreground placeholder:text-muted-foreground/50 focus:outline-none focus:ring-0",style:{height:"40px",lineHeight:"1.5"}}),c.jsxs("div",{className:"flex items-center justify-between border-foreground/10 px-3 py-2",children:[c.jsxs("div",{className:"flex items-center gap-2",children:[l==="dashboard"&&c.jsxs(Xr,{open:d,onOpenChange:V=>{V&&U(),f(V)},children:[c.jsx(Qr,{asChild:!0,children:c.jsx(se,{variant:"secondary",size:"sm",className:"h-7 px-2",title:"Add entity",children:c.jsx(Xae,{className:"h-4 w-4 text-muted-foreground"})})}),c.jsx(Jr,{className:"w-80 p-0",align:"start",side:"top",sideOffset:8,onOpenAutoFocus:V=>V.preventDefault(),children:c.jsx(sJe,{isOpen:!0,onSelect:z,onDeselect:O,onClose:()=>{var V;f(!1),(V=b.current)==null||V.focus()},availableEntities:P||[],selectedEntities:x.selectedEntities,onTabComplete:W,onSelectAll:()=>{P&&y({selectedEntities:P})},onRemoveAll:()=>{y({selectedEntities:[]})},onAddContext:()=>{f(!1),m(!0)}})})]}),c.jsx(yJe,{onFilesSelected:A,disabled:s,currentFileCount:M.length})]}),c.jsxs("div",{className:"flex items-center gap-2",children:[s&&c.jsx(se,{className:"rounded-full",size:"sm",onClick:o,children:c.jsx(mle,{className:"size-3.5 bg-background"})}),!s&&c.jsx(se,{disabled:!e.trim()&&M.length===0,size:"sm",variant:a!=="ready"?"secondary":"default",onClick:L,title:a!=="ready"?"Message will be queued":void 0,children:c.jsx(_8,{className:"size-4"})})]})]})]}),c.jsx(xA,{incomingSelectedEntities:x.selectedEntities,open:h,onOpenChange:m,dataSource:D||kC,dialogMode:"aiContext"})]})});yA.displayName="ChatInputWithContext";function Vee({assistantType:e,className:t}){const n=Aq(e),{removeFromQueue:r}=qm();return n.length===0?null:c.jsxs("div",{className:Z("space-y-2",t),children:[c.jsxs("div",{className:"flex items-center gap-1 text-xs text-muted-foreground",children:[c.jsx(Tl,{className:"h-3 w-3"}),c.jsxs("span",{children:["Pending messages (",n.length,")"]})]}),c.jsx("div",{className:"space-y-2",children:n.map(s=>c.jsx("div",{className:"group relative rounded-lg border border-dashed border-muted-foreground/30 bg-muted/30 px-3 py-2 text-sm animate-in fade-in-0 slide-in-from-bottom-1",children:c.jsxs("div",{className:"flex items-start justify-between gap-2",children:[c.jsx("div",{className:"flex-1 space-y-1",children:c.jsx("p",{className:"break-words text-foreground/70",children:s.text})}),c.jsx(se,{variant:"ghost",size:"sm",className:"h-6 w-6 p-0 opacity-0 transition-opacity group-hover:opacity-100",onClick:()=>r(e,s.id),title:"Remove from queue",children:c.jsx(yt,{className:"h-3 w-3"})})]})},s.id))})]})}function Hee({assistantType:e,status:t,isLoading:n,sendMessage:r}){const s=Aq(e),{dequeueMessage:o}=qm();C.useEffect(()=>{if(t!=="ready"||n||!(s&&s.length>0))return;const a=o(e);a&&r({role:"user",parts:[{type:"text",text:a.text}]})},[t,n,s,o,r,e])}function Uee(e,t={}){const{threshold:n=50,behavior:r="smooth",forceScrollOnStream:s=!0,isStreaming:o=!1}=t,i=C.useRef(null),[a,l]=C.useState(!0),[u,d]=C.useState(!0),[f,h]=C.useState(!1),[m,p]=C.useState(0),g=C.useRef(0),b=C.useRef(!1),x=C.useRef(0),y=C.useRef(a),v=C.useRef(void 0),w=C.useRef({key:null,count:0,length:0}),N=C.useCallback(()=>{const _=i.current;return _?_.scrollHeight-_.scrollTop-_.clientHeight:0},[]),S=C.useCallback((_={})=>{if(!i.current)return;const{force:M=!1,instant:D=!1}=_;if(!M&&!y.current||!a&&!M)return;const R=D||r==="auto"||r==="instant"?"auto":r;v.current&&cancelAnimationFrame(v.current),b.current=!0,v.current=requestAnimationFrame(()=>{if(!M&&!y.current){b.current=!1,v.current=void 0;return}const P=i.current;if(!P){b.current=!1,v.current=void 0;return}const I=P.scrollHeight;R==="smooth"&&"scrollTo"in P?P.scrollTo({top:I,behavior:R}):P.scrollTop=I,g.current=P.scrollTop,d(!0),l(!0),y.current=!0,h(!1),p(0),b.current=!1,v.current=void 0})},[r,a]),j=C.useCallback(()=>{const _=i.current;if(!_)return;const k=g.current,M=_.scrollTop,D=M-k;if(g.current=M,D<-1){v.current&&(cancelAnimationFrame(v.current),v.current=void 0),b.current=!1,y.current=!1,l(!1),d(!1);return}if(b.current)return;const R=N()<=n;d(R),l(R),y.current=R,R&&(h(!1),p(0))},[N,n]),E=C.useCallback(()=>{p(0),h(!1)},[]);return C.useEffect(()=>{y.current=a},[a]),C.useEffect(()=>{const _=i.current;if(!_||!e||e.length===0){h(!1),p(0),w.current={key:null,count:0,length:0},g.current=_?_.scrollTop:0,x.current=_?_.scrollHeight:0;return}g.current=_.scrollTop,x.current=_.scrollHeight;const k=w.current,M=e[e.length-1],D=(M==null?void 0:M.id)??(M==null?void 0:M.messageId)??(M==null?void 0:M.createdAt)??(M==null?void 0:M.timestamp)??e.length,R=Array.isArray(M==null?void 0:M.parts)?M.parts.reduce(($,A)=>A?typeof A=="string"?$+A.length:typeof A.text=="string"?$+A.text.length:typeof A.content=="string"?$+A.content.length:typeof A.value=="string"?$+A.value.length:$:$,0):typeof(M==null?void 0:M.content)=="string"?M.content.length:typeof(M==null?void 0:M.text)=="string"?M.text.length:0,P=e.length>k.count,I=D!==k.key,L=R>k.length,F=s&&(M==null?void 0:M.role)==="assistant"&&!P&&(I||L),H=o||F;if(w.current={key:D,count:e.length,length:R},a&&(P||I||L||H)){S({force:!1,instant:H});return}if(!a&&P){const $=e.length-k.count;$>0&&(h(!0),p(A=>A+$))}else!a&&L&&(h(!0),p($=>$>0?$:1))},[e,S,a,s,o]),C.useEffect(()=>{S({instant:!0})},[S]),C.useEffect(()=>{if(typeof ResizeObserver>"u")return;const _=i.current;if(!_)return;x.current=_.scrollHeight;const k=new ResizeObserver(()=>{const M=i.current;if(!M)return;const D=x.current,R=M.scrollHeight;x.current=R,!b.current&&y.current&&R>D&&S({force:!1,instant:!0})});return k.observe(_),()=>{k.disconnect()}},[S]),C.useEffect(()=>()=>{v.current&&cancelAnimationFrame(v.current)},[]),{scrollRef:i,isAutoScrollEnabled:a,isAtBottom:u,hasNewMessages:f,newMessageCount:m,scrollToBottom:S,handleScroll:j,resetNewMessageCount:E}}function Wee(e,t={}){const{maxVisibleMessages:n=50,initialLoadCount:r=20,loadMoreCount:s=10}=t,[o,i]=C.useState(r),a=C.useMemo(()=>{if(e.length<=o)return e;const h=Math.max(0,e.length-o);return e.slice(h)},[e,o]),l=e.length>o,u=o>=e.length,d=C.useCallback(()=>{i(h=>Math.min(h+s,n))},[s,n]),f=C.useCallback(()=>{i(r)},[r]);return C.useEffect(()=>{u&&e.length>o&&o<n&&i(Math.min(e.length,n))},[e.length,o,u,n]),{visibleMessages:a,hasMoreMessages:l,totalMessageCount:e.length,loadMoreMessages:d,resetMessageWindow:f,isShowingAll:u}}function qee(e){var n;if(!e||e.length===0)return{hasActiveTools:!1};const t=e[e.length-1];if(!(t!=null&&t.parts))return{hasActiveTools:!1};for(const r of t.parts){if(r.type==="reasoning"&&"state"in r&&r.state==="streaming")return{hasActiveTools:!0,activeToolText:r.text||"Reasoning...",toolType:"reasoning"};if(((n=r.type)!=null&&n.startsWith("tool-")||r.type==="dynamic-tool")&&"state"in r&&["input-streaming","input-available"].includes(r.state)){const s=r,o=s.state;return{hasActiveTools:!0,activeToolText:kJ(s.type,o),toolType:s.type}}}return{hasActiveTools:!1}}const wJe=[{title:"Show top 3 insights",subtitle:"from this dataset"},{title:"Create a bar chart for",subtitle:"sales by product category"}];function SJe({open:e,setOpen:t,isFullscreen:n,onFullscreenChange:r,fullscreenContainer:s}){const[o,i]=C.useState(!1),[a,l]=C.useState(rD),[u,d]=C.useState(!1),[f,h]=C.useState(!1),[m,p]=C.useState(!1),g=n??m,{isLocalDev:b,isConsoleMode:x}=xm(),y=C.useRef(null);X(He=>He.dashboard.aiScopeTables),X(He=>He.isDashboardEditing);const v=X(He=>He.selectedSheetId),{setDataSource:w}=Qn(),{addFrame:N,setSelectedFrameId:S,setIsDashboardEditing:j}=Ot(),E=Wm(),{setCurrentAIContext:_,updateSelectedEntities:k,setReasoningEffort:M,setShowReasoning:D}=_S(),{clearQueue:R}=qm(),{clearFileAttachments:P,getFileAttachments:I}=BT(),L=zT("dashboard"),F=X(He=>He.dashboard.aiContext),H=_e(He=>He.card.dataSource),{assistantProfile:$}=Fee(),A=X(He=>He.handleOpenAssistantProfile),{sendMessage:q,isLoading:z,messages:O,setMessages:W,status:B,stop:Y,errorMessage:U,clearError:V}=rJe(),G=C.useCallback(He=>{r==null||r(He),n===void 0&&p(He)},[n,r]),K=C.useCallback(()=>{G(!g)},[g,G]);C.useEffect(()=>{if(!g)return;function He(Jt){Jt.key==="Escape"&&G(!1)}return window.addEventListener("keydown",He),()=>{window.removeEventListener("keydown",He)}},[g,G]);const[J,Q]=C.useState(""),re=He=>{Q(He.target.value)};function de({sql:He,cardTitle:Jt,connectionId:Ke,cardType:Qe,python:Le,cardConfig:ve,dataSource:Be,customVisualPreferences:we}){if(!v)return;const We={id:vr(),title:Jt||"Title",preferences:{onClickFilter:[{columnIndex:0,expression:""}],chartOptions:{indexAxis:Qe==="horizontalBar"?"y":"x"}},type:Qe,sql:He,python:Le,dataSource:Be,config:ve,connectionId:Ke,customCardPreferences:we?{url:we.url,componentName:we.componentName,pluginChartType:we.pluginChartType,settings:we.settings,type:"component"}:void 0},at={id:vr(),cards:[We],activeCardId:We.id};j(!0),N(v,at,"end"),S(at.id)}const fe=He=>{He.preventDefault();const Jt=J.trim();if(!Jt&&L.length===0)return;const Ke=[];Jt&&Ke.push({type:"text",text:Jt}),L.forEach(Qe=>{Qe.data&&Ke.push({type:"file",mediaType:Qe.type,filename:Qe.name,url:`data:${Qe.type};base64,${Qe.data}`})}),q({role:"user",parts:Ke}),Q(""),P("dashboard"),ie({force:!0})};C.useEffect(()=>{var He;e&&((He=y.current)==null||He.focus())},[e]),Hee({assistantType:"dashboard",status:B,isLoading:z,sendMessage:q});const{hasActiveTools:ue}=qee(O),{visibleMessages:je,hasMoreMessages:me,totalMessageCount:ne,loadMoreMessages:oe,resetMessageWindow:pe}=Wee(O,{maxVisibleMessages:15,initialLoadCount:10,loadMoreCount:5}),{scrollRef:De,isAtBottom:ae,hasNewMessages:Te,newMessageCount:Ue,scrollToBottom:ie,handleScroll:xe,resetNewMessageCount:$e}=Uee(je,{threshold:50,behavior:"smooth",isStreaming:z});function he(He){Ae();const Jt={role:"user",parts:[{type:"text",text:He.title+" "+He.subtitle}]};q(Jt)}function Ee(He){Ae(),q({role:"user",parts:[{type:"text",text:He}]})}function Ve(He){Ae(),q({role:"user",parts:[{type:"text",text:He}]}),ie({force:!0})}const qe=C.useCallback(async()=>{const He=JSON.stringify(O??[],null,2);try{if(typeof navigator>"u"||!navigator.clipboard)throw new Error("Clipboard API unavailable");await navigator.clipboard.writeText(He),Oe.success("Conversation copied")}catch(Jt){console.error("Failed to copy conversation",Jt),Oe.error("Unable to copy conversation")}},[O]);function Ae(){E.selectedEntities.length===0&&_({selectedEntities:(F==null?void 0:F.selectedEntities)||[]})}const xt=(J==null?void 0:J.length)===0&&(O==null?void 0:O.filter(He=>He.role==="user").length)===0;function Ce(){return c.jsx("div",{"data-role":"header",children:c.jsx("div",{className:"text-lg font-semibold",children:"Assistant"})})}function mt(){return c.jsxs(gm,{children:[c.jsx(bm,{asChild:!0,children:c.jsx(Ec,{className:"h-7 p-2 text-muted-foreground hover:text-foreground",children:c.jsx(lm,{className:"size-3.5"})})}),c.jsxs(rf,{align:"end",children:[c.jsx(sh,{children:"Options"}),c.jsx(Ad,{}),c.jsx(fg,{checked:o,onCheckedChange:i,children:"Token Usage"}),c.jsx(fg,{checked:a,onCheckedChange:l,children:"Tool Invocations"}),c.jsx(fg,{checked:u,onCheckedChange:d,children:"System Message"})]})]})}const _t=c.jsxs("div",{"data-role":"dashboard-assistant",className:Z("flex h-full grow flex-col justify-between break-words px-6 py-4",g&&"rounded-2xl border border-border/60 bg-background px-8 pb-6 pt-6 shadow-xl"),children:[c.jsxs("div",{"data-role":"header-section",className:"flex items-start justify-between gap-2",children:[Ce(),A&&c.jsx(se,{variant:"outline",size:"sm",className:"h-7 p-2",onClick:A,children:($==null?void 0:$.name)||"Default Profile"}),c.jsxs("div",{"data-role":"header-actions",className:"flex items-center",children:[x&&mt(),a&&c.jsx(se,{variant:"ghost",size:"sm",className:"ml-2 h-7 px-2 text-muted-foreground hover:text-foreground",onClick:qe,children:"Copy Conversation"}),c.jsx(Ec,{className:"h-7 p-2 text-muted-foreground hover:text-foreground",tooltip:g?"Exit Fullscreen":"Expand",onClick:K,children:g?c.jsx(FD,{className:"size-4"}):c.jsx(M1,{className:"size-4"})}),c.jsx(Ec,{className:"h-7 p-2 text-muted-foreground hover:text-foreground",tooltip:"New Chat",onClick:()=>{W([]),R("dashboard"),V(),pe()},children:c.jsx(T1,{className:"size-4"})}),c.jsx(Ec,{className:"h-7 p-2 text-muted-foreground hover:text-foreground",onClick:()=>{t(!1)},children:c.jsx(yt,{className:"size-4"})})]})]}),c.jsxs(Vl,{"data-role":"dashboard-assistant-scroll-area",ref:De,className:"mt-4 flex flex-1 basis-0 flex-col flex-wrap justify-end pr-2",onScroll:xe,children:[c.jsxs("div",{className:"space-y-3 pb-4",children:[me&&c.jsx("div",{className:"flex justify-center py-2",children:c.jsxs(se,{variant:"outline",size:"sm",onClick:oe,className:"text-xs",children:["Load ",Math.min(5,ne-je.length)," ","more messages (",ne-je.length," ","hidden)"]})}),c.jsx(_J,{showTools:a,showSystemMessage:u,messages:je,onAddToDashboard:de,onQuickReply:Ve,disableQuickReplies:z}),!ue&&c.jsx(EJ,{status:B,errorMessage:U})]}),c.jsx(si,{orientation:"horizontal"})]}),e&&!ae&&c.jsx("div",{className:"absolute bottom-24 right-8 z-10",children:c.jsxs(se,{onClick:()=>{ie({force:!0}),$e()},size:"sm",variant:"secondary",className:"rounded-full shadow-lg","aria-label":"Scroll to bottom",children:[c.jsx(hr,{className:"h-4 w-4"}),Te&&Ue>0&&c.jsx("span",{className:"ml-1.5 flex h-5 w-5 items-center justify-center rounded-full bg-primary text-xs text-primary-foreground",children:Ue>9?"9+":Ue})]})}),c.jsxs("div",{className:"space-y-3",children:[!$&&xt&&c.jsx(DJ,{onClick:he,placeholders:wJe}),c.jsx("div",{children:xt&&$&&c.jsx($ee,{seedQuestions:$.seedQuestions||[],handleSeedQuestionClick:Ee})}),c.jsx(Vee,{assistantType:"dashboard",className:"mb-3"}),c.jsx(yA,{ref:y,setInput:Q,stop:Y,input:J,handleInputChange:re,handleSubmit:He=>{Ae(),fe(He),ie({force:!0})},isLoading:z,status:B,assistantType:"dashboard",onFocus:()=>{}})]}),c.jsx(xA,{incomingSelectedEntities:(F==null?void 0:F.selectedEntities)||[],open:f,onOpenChange:h,dataSource:H||kC,dialogMode:"aiContext"})]});return g&&s?Ln.createPortal(c.jsx("div",{className:"pointer-events-auto absolute inset-0 z-50 flex bg-background px-6 pb-6 pt-[calc(var(--app-header-height,15px)+1rem)]",children:c.jsx("div",{className:"flex h-full w-full",children:_t})}),s):_t}function CJe(e){const t=e.current,{getSelectedFrame:n,addFrame:r,setSelectedFrameId:s}=Ot(),o=X(d=>d.dashboard.sheets),a=X(d=>d.selectedSheetId)??(o==null?void 0:o[0].id),l=X(d=>d.isDashboardEditing),u=X(d=>d.isVisualEditing);C.useEffect(()=>{if(!l||u)return;async function d(m){const p=m.ctrlKey||m.metaKey;p&&m.key==="c"?(await f(),Oe.success("Card copied to clipboard"),m.preventDefault()):p&&m.key==="v"&&(await h(),m.preventDefault())}async function f(){try{const m=n();m&&await navigator.clipboard.writeText(JSON.stringify(m))}catch(m){console.error("Failed to copy text:",m)}}async function h(){if(!a)return null;try{const m=await navigator.clipboard.readText();try{const p=JSON.parse(m);if(p!=null&&p.id){const g=dI(p),b=g.cards.findIndex(x=>x.id===g.activeCardId);b!==-1&&(g.cards[b].title=`${g.cards[b].title} (Copy)`),r(a,g),s(g.id),Oe.success("Card pasted from clipboard")}}catch(p){console.error("Failed to parse clipboard contents: ",p)}return m}catch(m){return console.error("Failed to paste text:",m),null}}return t==null||t.addEventListener("keydown",d),()=>t==null?void 0:t.removeEventListener("keydown",d)},[r,n,s,a,l,u,t])}function NJe(e,t){switch(e.interactionMode){case"drillToDetail":jJe(e,t);break;case"drillThrough":kJe(e,t);break;case"drillToURL":EJe(e);break;case"inlineDrill":console.warn("Inline drill execution not yet implemented");break;case"clickFilter":case"drillDown":case"dynamicDrill":break;default:console.warn("Unknown interaction mode:",e.interactionMode)}}function jJe(e,t){var l;const{targetInsightId:n,contextMode:r,displayMode:s,filterGroups:o}=e;if(!n){console.warn("drillToDetail event missing targetInsightId");return}const i=r||"full";let a=[];switch(i){case"interactionFilters":a=o.flatMap(u=>u.filters);break;case"full":{const u=((l=t.getCurrentFilters)==null?void 0:l.call(t))||[],d=o.flatMap(f=>f.filters);a=[...u,...d];break}case"none":default:a=[];break}s==="replace-card"?t.replaceCardContent({cardId:e.sourceCardId,insightId:n,filters:a,contextMode:r}):t.openInsightModal({insightId:n,filters:a,contextMode:r})}function kJe(e,t){var u,d;const{targetDashboardId:n,contextMode:r="interactionFilters",filterGroups:s,sourceCardId:o}=e;if(!n){console.warn("[DrillThrough] Event missing targetDashboardId. This interaction needs to be reconfigured with a target dashboard.",e);return}const i=s.flatMap(f=>f.filters),a=((u=t.getCurrentDashboardId)==null?void 0:u.call(t))||"",l=(d=t.getCurrentDashboardTitle)==null?void 0:d.call(t);t.setGlobalDrillContext&&t.setGlobalDrillContext({filters:i,contextMode:r,sourceDashboardId:a,sourceDashboardTitle:l,targetDashboardId:n}),t.setPendingDrillThrough&&t.setPendingDrillThrough({targetDashboardId:n,sourceDashboardId:a,sourceDashboardTitle:l,filters:i,contextMode:r})}function EJe(e){const{url:t}=e;if(!t){console.warn("drillToURL event missing url");return}try{new URL(t)}catch(n){console.error("Invalid URL:",t,n);return}window.open(t,"_blank","noopener,noreferrer")}function _Je({open:e,onOpenChange:t,insightId:n,filters:r,filterDefinitions:s,contextMode:o,cardTitle:i,cardDescription:a}){return c.jsx(ns,{open:e,onOpenChange:t,children:c.jsxs(Vr,{className:"max-h-[90vh] max-w-[90vw] p-6",children:[c.jsxs(Hr,{children:[c.jsx(Ur,{children:i||"Insight Detail"}),c.jsx(ys,{children:a||"View detailed insight data with applied filters"})]}),c.jsx(GZ,{filters:r,filterDefinitions:s,contextMode:o}),c.jsx("div",{className:"h-[400px] flex-1 overflow-auto",children:n?c.jsx(QZ,{insightId:n,filters:r,contextMode:o}):c.jsx("div",{className:"flex items-center justify-center p-12 text-muted-foreground",children:"No insight selected"})})]})})}function DJe(){const e=It(w=>w.interactionStates),t=It(w=>w.setInteractionState),n=It(w=>w.clearLastInteractionEvent),r=It(w=>w.replaceCardWithInsight),s=It(w=>w.setPendingDrillThrough),o=It(w=>w.pendingDrillThrough),i=It(w=>w.clearPendingDrillThrough),{setSelectedSheetId:a,navigateWithDrill:l}=Ot(),{selectDashboard:u}=tx(),d=X(w=>w.dashboard),f=X(w=>w.filterValues),{data:h,isLoading:m}=H7((o==null?void 0:o.targetDashboardId)||"",{enabled:!!(o!=null&&o.targetDashboardId)}),[p,g]=C.useState({open:!1,insightId:""}),b=JZ(p.insightId,{enabled:p.open&&!!p.insightId}),x=C.useRef(new Set),y=C.useMemo(()=>({setSelectedSheetId:a,openInsightModal:({insightId:w,filters:N,contextMode:S})=>{g({open:!0,insightId:w,filters:N,filterDefinitions:(d==null?void 0:d.filters)||[],contextMode:S})},replaceCardContent:({cardId:w,insightId:N,filters:S,contextMode:j})=>{r(w,N,S,j)},getCurrentFilters:()=>f||[],navigateWithDrill:l,getCurrentDashboardId:()=>(d==null?void 0:d.id)||"",getCurrentDashboardTitle:()=>d==null?void 0:d.title,setPendingDrillThrough:s,setGlobalDrillContext:({filters:w,contextMode:N,sourceDashboardId:S,sourceDashboardTitle:j,targetDashboardId:E})=>{const k={sourceCardId:ga,interactionMode:"clickFilter",filterGroups:[{filters:w}]},M={...Wo(),appliedClickFilters:[k],contextMode:N,sourceDashboardId:S,sourceDashboardTitle:j,targetDashboardId:E};t(ga,M)}}),[a,r,f,l,d,s,t]);C.useEffect(()=>{Object.entries(e).forEach(([w,N])=>{if(N!=null&&N.lastInteractionEvent){const S=N.lastInteractionEvent,j=`${w}-${S.interactionMode}-${S.sourceCardId}-${Date.now()}`;if(x.current.has(j))return;x.current.add(j);try{NJe(S,y)}catch(E){console.error("Error executing interaction event:",E)}finally{n(w),setTimeout(()=>{x.current.delete(j)},5e3)}}})},[e,n,y]),C.useEffect(()=>{if(!(!o||!h||m))try{u(h),l(o.targetDashboardId,o.sourceDashboardId,o.sourceDashboardTitle,o.filters,o.contextMode),i()}catch(w){console.error("[DrillThrough] Error during automatic navigation:",w),i()}},[o,h,m,u,l,i]);const v=()=>{g({open:!1,insightId:""})};return c.jsxs(c.Fragment,{children:[c.jsx(_Je,{open:p.open,onOpenChange:v,insightId:p.insightId,filters:p.filters,filterDefinitions:p.filterDefinitions,contextMode:p.contextMode,cardTitle:b.title,cardDescription:b.description}),o&&m&&c.jsx("div",{className:"fixed inset-0 z-[51] flex items-center justify-center bg-background/80 backdrop-blur-sm",children:c.jsxs("div",{className:"flex flex-col items-center gap-3 rounded-lg border bg-background p-6 shadow-lg",children:[c.jsx(an,{className:"h-8 w-8 animate-spin text-primary"}),c.jsx("div",{className:"text-sm text-muted-foreground",children:"Loading dashboard..."})]})})]})}function MJe(e){return e.length===0?"":e.map(t=>{const n=t.field.label||t.field.name,r=t.operator,s=TJe(t.value);return r==="="?`${n} = ${s}`:`${n} ${r} ${s}`}).join(", ")}function TJe(e){return e==null?"null":Array.isArray(e)?e.join(", "):typeof e=="object"&&e.toString?e.toString():String(e)}function RJe(e){return e?`Back to ${e}`:"Back"}function IJe(){var x,y,v,w,N;const e=It(S=>S.interactionStates[ga]),t=X(S=>S.actions.goBackFromDrill),n=X(S=>S.actions.clearDrillContext),{selectDashboard:r}=tx(),[s,o]=C.useState({x:16,y:16}),[i,a]=C.useState(!1),l=C.useRef({x:0,y:0});C.useEffect(()=>{if(!i)return;const S=E=>{o({x:E.clientX-l.current.x,y:E.clientY-l.current.y})},j=()=>{a(!1)};return document.addEventListener("mousemove",S),document.addEventListener("mouseup",j),()=>{document.removeEventListener("mousemove",S),document.removeEventListener("mouseup",j)}},[i]);const u=e==null?void 0:e.sourceDashboardId,d=e==null?void 0:e.sourceDashboardTitle,f=((w=(v=(y=(x=e==null?void 0:e.appliedClickFilters)==null?void 0:x[0])==null?void 0:y.filterGroups)==null?void 0:v[0])==null?void 0:w.filters)||[],h=u?{id:u,title:d||"Previous Dashboard",description:"",isPrivate:!1,isPublic:!1,version:"",createdBy:null,createdByTenantUser:"",tenantId:"",projectId:"",createdAt:"",updatedAt:"",lastModified:"",lastModifiedBy:"",createdByUser:null,createdByTenantUserRel:{name:"",email:""},permissions:{canEdit:!0,canShare:!0,canDelete:!0},ownership:{status:"private",isOwner:!0,sharedCount:0,createdBy:{type:"user",userId:"",name:"",email:""}}}:null;if(!e||!((N=e.appliedClickFilters)!=null&&N.length))return null;const m=()=>{if(!h){console.warn("[DrillBack] No source dashboard in context");return}try{t(),r(h)}catch(S){console.error("[DrillBack] Error during back navigation:",S)}},p=()=>{n()},g=S=>{S.target.closest("button")||(a(!0),l.current={x:S.clientX-s.x,y:S.clientY-s.y})};MJe(f);const b=RJe(d);return c.jsx("div",{className:"fixed z-50 max-w-md",style:{left:0,top:0,transform:`translate(${s.x}px, ${s.y}px)`,transition:i?"none":void 0},children:c.jsxs("div",{className:"select-none rounded-lg border bg-background/95 p-3 shadow-lg backdrop-blur-sm",onMouseDown:g,style:{cursor:i?"grabbing":"grab"},children:[c.jsxs("div",{className:"mb-3 flex items-start justify-between gap-2",children:[c.jsxs("div",{className:"flex flex-col gap-2",children:[c.jsx("span",{className:"text-xs font-medium text-muted-foreground",children:"Viewing:"}),c.jsx("div",{className:"flex flex-wrap gap-2",children:f.map((S,j)=>{const E=S.field.label||S.field.name,_=String(S.value);return c.jsxs(Fe,{variant:"secondary",className:"pointer-events-none text-xs",children:[E," = ",_]},j)})})]}),c.jsx(se,{variant:"ghost",size:"sm",onClick:p,className:"h-6 w-6 cursor-pointer p-0",title:"Clear drill context",children:c.jsx(yt,{className:"h-3 w-3"})})]}),c.jsx("div",{className:"flex items-center gap-2 border-t pt-2",children:c.jsxs(se,{variant:"secondary",size:"sm",onClick:m,disabled:!h,className:"w-full cursor-pointer",children:[c.jsx(l8,{className:"mr-2 h-4 w-4"}),b]})})]})})}function Yee(){var me;const{showAssistant:e,tokenProps:t}=Ge(),{preferences:n,isConsoleMode:r}=xm(),s=((me=n==null?void 0:n.cardDisplay)==null?void 0:me.mode)==="print",o=C.useRef(null),i=C.useRef(null),[a,l]=C.useState(!1),{handleDragStart:u,isDraggingRef:d,getStyle:f,getPositionClasses:h}=$8e({initialPosition:"bottom-right"}),m=vd(ne=>ne.setFullscreen),p=vd(ne=>ne.setPanelOpen),g=vd(ne=>ne.setContainer),b=Mq("dashboard"),x=Tq(),y=Rq("dashboard"),v=b.isOpen,w=x==="dashboard",N=X(ne=>ne.isVisualEditing),S=X(ne=>ne.themeStyle),j=X(ne=>{var oe;return(oe=ne.dashboard)==null?void 0:oe.sheets}),E=X(ne=>ne.showFilters),_=X(ne=>ne.isDashboardEditing),k=X(ne=>ne.selectedSheetId),M=X(ne=>{var oe;return(oe=ne.dashboard)==null?void 0:oe.id}),D=X(ne=>ne.isDashboardPanelOpen),R=X(ne=>ne.actions.setIsDashboardPanelOpen),{getDefaultSheetId:P,setDefaultSheetId:I,clearDefaultSheetId:L}=r8(M),[F,H]=C.useState(null);W1(Pt.DASHBOARD);const{setSelectedSheetId:$,setSheetTitle:A,addSheet:q,setSheets:z}=Ot();CJe(i);const{setActiveAssistantType:O}=_S();C.useEffect(()=>{if(M){const ne=P();H(ne)}},[M,P]),C.useEffect(()=>{v?O("dashboard"):x==="dashboard"&&m(null)},[v,O,x,m]),C.useEffect(()=>{var ne;v||(ne=o.current)==null||ne.resize(0)},[v]);function W(ne){var oe,pe;ne?((oe=o.current)==null||oe.resize(40),p("dashboard",!0),O("dashboard")):(p("dashboard",!1),m(null),(pe=o.current)==null||pe.resize(0),O(null))}function B(){const ne={id:vr(),title:"New Sheet"};q(ne),$(ne.id)}function Y(ne,oe){if(!M)return;F===ne?(L(),H(null),Oe.success("Default sheet cleared")):(I(ne),H(ne),Oe.success(`"${oe}" set as default sheet`))}function U(ne){var oe;ne<1?(p("dashboard",!1),m(null),O(null),(oe=o.current)==null||oe.resize(0)):(v||p("dashboard",!0),O("dashboard"))}function V(){return(S==null?void 0:S.canvasTheme)==="muted"||!(S!=null&&S.canvasTheme)?"hsl(var(--semaphor-muted))":(S==null?void 0:S.canvasTheme)==="clear"?"":S==null?void 0:S.canvasTheme}const G=(ne,oe)=>{ne.dataTransfer.setData("tabIndex",oe.toString())},K=ne=>{ne.preventDefault()},J=(ne,oe)=>{const pe=ne.dataTransfer.getData("tabIndex");if(pe===oe.toString())return;const De=Array.from(j||[]),[ae]=De.splice(parseInt(pe),1);De.splice(oe,0,ae),z(De)},Q=t.orgUserId||t.tenantId&&t.endUserId&&t.endUserEmail,re=e===!0&&!s&&!v&&!N&&!E;function de(){var ne,oe;if(j&&j.length>1||_)return c.jsxs(vs,{role:"tab-list",className:"flex h-12 w-0 min-w-full items-center justify-start gap-2 overflow-x-auto rounded-none border-b border-b-muted bg-transparent px-3",children:[r&&Q&&c.jsx(se,{style:{borderRadius:S==null?void 0:S.controlInputRadius},variant:"outline","aria-label":"Manage Dashboards and Visuals",onClick:()=>{R(!D)},className:"h-8 shrink-0 p-2",children:D?c.jsx(h8,{className:"h-4 w-4"}):c.jsx(m8,{className:"h-4 w-4"})}),j==null?void 0:j.map((pe,De)=>{const ae=k===pe.id,Te=F===pe.id;return c.jsxs(Gt,{draggable:!0,onDragStart:Ue=>G(Ue,De),onDragOver:K,onDrop:Ue=>J(Ue,De),style:{borderRadius:S==null?void 0:S.controlInputRadius},onClick:()=>$(pe.id),className:"flex shrink-0 items-center gap-1 border px-2 py-1",value:pe.id,children:[c.jsx(jb,{enabled:_&&ae,text:pe.title,onSave:Ue=>A(pe.id,Ue),children:pe.title},pe.id),!_&&ae&&c.jsx("div",{title:Te?"Clear default sheet":"Set as default sheet",children:c.jsx(VD,{className:Z("ml-1 size-3 cursor-pointer transition-all",Te?"fill-yellow-500 text-yellow-500":"text-muted-foreground hover:text-foreground"),onClick:Ue=>{Ue.stopPropagation(),Y(pe.id,pe.title||"Sheet")}})}),_&&ae&&j.length>1&&c.jsx(yt,{className:"ml-1 size-3",onClick:()=>l(!0)})]},pe.id)}),_&&c.jsx("div",{style:{borderRadius:(oe=(ne=S==null?void 0:S.chart)==null?void 0:ne.options)==null?void 0:oe.borderRadius},className:"flex h-7 shrink-0 items-center justify-center border-none bg-muted p-2 hover:cursor-pointer dark:border-l-background",onClick:B,children:c.jsx(Sr,{className:"size-3"})})]})}function fe(){return c.jsx("div",{ref:i,style:{},className:"grow",children:j==null?void 0:j.map(ne=>c.jsx(sr,{style:{backgroundColor:V()},className:Z("mt-0",{}),value:ne.id,children:c.jsx(l8e,{sheet:ne})},ne.id))})}function ue(){var ne;return c.jsxs(Bs,{"data-role":"dashboard-tabs-container",className:Z("relative flex h-full flex-col",S==null?void 0:S.dashboardTabsContainer),onValueChange:oe=>{$(oe)},value:k||((ne=j==null?void 0:j[0])==null?void 0:ne.id),children:[de(),c.jsx(Vl,{"data-role":"dashboard-tabs-content",className:"flex-1 grow basis-0 overflow-y-auto",children:fe()}),c.jsx(L8e,{open:a,setOpen:l})]})}const je=C.useCallback(ne=>{g("dashboard",ne)},[g]);return j?c.jsxs(c.Fragment,{children:[c.jsx(DJe,{}),c.jsx(IJe,{}),c.jsxs("div",{className:"relative flex-1 basis-0 overflow-hidden",children:[c.jsxs(cQ,{className:Z("flex-1 basis-0 overflow-y-auto transition-opacity",w&&"pointer-events-none opacity-0"),direction:"horizontal",children:[c.jsx(x_,{children:ue()}),e===!0&&c.jsxs(c.Fragment,{children:[c.jsx(F8e,{open:v,onTabClick:W,withHandle:!0,disabled:!v}),c.jsx(x_,{className:"flex grow","data-role":"dashboard-assistant-panel",onResize:U,defaultSize:v?40:0,ref:o,children:c.jsx("div",{className:"grow overflow-y-auto",children:c.jsx(SJe,{open:v,setOpen:W,isFullscreen:w,onFullscreenChange:ne=>m(ne?"dashboard":null),fullscreenContainer:y})})})]})]}),c.jsx("div",{ref:je,className:Z("absolute inset-0",!w&&"pointer-events-none")}),re&&c.jsx("div",{className:Z("absolute z-50 transition-all duration-300 ease-in-out",h().horizontal,h().vertical),style:f(),children:c.jsx(se,{size:"sm",variant:"outline",className:"h-12 w-12 cursor-grab rounded-full border-border bg-background p-0 shadow-lg hover:bg-muted active:cursor-grabbing",onClick:()=>{d.current||W(!0)},onMouseDown:u,onTouchStart:u,title:"Open Assistant (drag to move)",children:c.jsx(BD,{className:"h-5 w-5"})})})]})]}):null}function vA({children:e}){return c.jsx(Fa,{style:{height:"100%",width:"100%"},children:c.jsx(dae,{defaultTheme:"system",storageKey:"vite-ui-theme",children:c.jsx(_n,{delayDuration:0,children:e})})})}function Gee({children:e,preferences:t}){const{currentUser:n}=oo(),r=C.useMemo(()=>{var s,o;return{preferences:t||{},isLocalDev:((s=t==null?void 0:t.uiMode)==null?void 0:s.developer)||!1,isConsoleMode:((o=t==null?void 0:t.uiMode)==null?void 0:o.console)||!1}},[t]);return c.jsx(v7.Provider,{value:r,children:c.jsx(wI,{displayPreferences:t==null?void 0:t.cardDisplay,currentUser:n,children:e})})}function AJe(e=2e3,t=500){const n=zae(),[r,s]=C.useState(!1),[o,i]=C.useState(!1),a=C.useRef(null);return C.useEffect(()=>{const l=setTimeout(()=>s(!0),e);return()=>clearTimeout(l)},[e]),C.useEffect(()=>{if(r){if(n>0){i(!1),a.current&&(clearTimeout(a.current),a.current=null);return}return a.current&&clearTimeout(a.current),a.current=setTimeout(()=>{i(!0)},t),()=>{a.current&&clearTimeout(a.current)}}},[r,n,t]),o}function wA({delayMs:e=2e3,quietMs:t=500,componentType:n,componentId:r}){const s=AJe(e,t);return C.useEffect(()=>(s&&(window.__SEMAPHOR_READY__={ready:!0,type:n,componentId:r||null,timestamp:Date.now()}),()=>{window.__SEMAPHOR_READY__={ready:!1,type:n,componentId:r||null,timestamp:Date.now()}}),[s,n,r]),c.jsx("div",{id:"idle-check","aria-hidden":"true",style:{position:"absolute",width:1,height:1,padding:0,margin:-1,overflow:"hidden",clip:"rect(0, 0, 0, 0)",whiteSpace:"nowrap",border:0},children:s?"ready":""})}function Kee(e){if(typeof window>"u")return null;const{preferences:t}=e;return c.jsx(Ua,{FallbackComponent:eC,children:c.jsxs(jD,{dashboardProps:e,children:[c.jsx(wA,{componentType:"dashboard",componentId:e.id}),c.jsx(vA,{children:c.jsx(Gee,{preferences:t,children:c.jsx("main",{className:"flex h-full flex-col",children:c.jsx(VT,{...e,type:"dashboard",children:c.jsx(Yee,{})})})})})]})})}function SA(e){const{tokenProps:t,authToken:n}=Ge(),r=t==null?void 0:t.apiServiceUrl;return hn({queryKey:["joinability-map",e],queryFn:async()=>{if(!e||!(n!=null&&n.accessToken))return null;const s=`${r}/v1/domains/${e}/joinability`;return qn(s,n.accessToken)},enabled:!!e&&!!(n!=null&&n.accessToken)&&!!r,staleTime:5*60*1e3,gcTime:10*60*1e3,retry:2,retryDelay:s=>Math.min(1e3*2**s,3e4)})}function Zee(e,t,n){if(t==="source")return{isValid:!0};const r=Tr(e.dataType);if(n==="kpi"){if(t==="groupBy"&&r!=="date")return{isValid:!1,reason:"KPI Trend By only accepts date fields"};if(t==="metrics"&&r==="date")return{isValid:!1,reason:"KPI metrics cannot be date fields"}}return{isValid:!0}}function Xee(e,t,n,r,s){if(e!=="kpi"||s.length<3)return;const o=(t==null?void 0:t.groupByColumns)&&t.groupByColumns.length>0,i=(t==null?void 0:t.comparisonType)==="none";!o&&i||n(r,{groupByColumns:[],comparisonType:"none"})}const Qee=e=>{var R;const t=(R=e==null?void 0:e.dataSource)==null?void 0:R.semanticDomainId,{data:n}=SA(t),{updateCardConfig:r,updateGroupByColumn:s,updateMetricColumn:o,updatePivotByColumn:i,updateSortByColumn:a,removeGroupByColumn:l,removeMetricColumn:u,removePivotByColumn:d,removeSortByColumn:f}=Qn(),h=_e(P=>P.card.type),m=e==null?void 0:e.id,p=C.useCallback(P=>{if(!(e!=null&&e.config))return[];switch(P){case"groupBy":return(e.config.groupByColumns||[]).map(I=>({id:I.id,name:I.name,dataType:I.dataType,label:I.label!==void 0?I.label:I.name,qualifiedEntityName:I.qualifiedEntityName,entityId:I.entityId,entityName:I.entityName,entityType:I.entityType,dateFormat:I.dateFormat,customFormat:I.customFormat,granularity:I.granularity}));case"metrics":return e.config.metricColumns||[];case"pivotBy":return(e.config.pivotByColumns||[]).map(I=>({id:I.id,name:I.name,dataType:I.dataType,label:I.label!==void 0?I.label:I.name,qualifiedEntityName:I.qualifiedEntityName,entityId:I.entityId,entityName:I.entityName,entityType:I.entityType}));case"sortBy":return(e.config.sortByColumns||[]).map(I=>({id:I.id,name:I.name,dataType:I.dataType,label:I.label!==void 0?I.label:I.name,qualifiedEntityName:I.qualifiedEntityName,entityId:I.entityId,entityName:I.entityName,entityType:I.entityType,direction:I.direction}));case"source":return[];default:return[]}},[e]),g=C.useCallback((P,I)=>{if(m)switch(P){case"groupBy":{r(m,{groupByColumns:I});break}case"metrics":{r(m,{metricColumns:I});break}case"pivotBy":{r(m,{pivotByColumns:I});break}case"sortBy":{r(m,{sortByColumns:I});break}}},[m,r]),b=C.useCallback((P,I,L)=>{if(!m)return;const H=p(P)[I];if(H)switch(P){case"groupBy":s(m,H.id,{label:L});break;case"metrics":o(m,H.id,{label:L});break;case"pivotBy":i(m,H.id,{label:L});break;case"sortBy":a(m,H.id,{label:L});break}},[m,p,s,o,i,a]),x=C.useCallback((P,I)=>{if(!m)return;const F=p("metrics")[P];F&&o(m,F.id,{aggregate:I,label:OU(F.name,I)})},[m,p,o]),y=C.useCallback((P,I,L)=>{if(!m)return;const H=p("groupBy")[P];if(!H)return;const $={dateFormat:I};I==="custom"&&L?$.customFormat=L:$.customFormat=void 0,s(m,H.id,$)},[m,p,s]),v=C.useCallback((P,I)=>{if(!m)return;const F=p("groupBy")[P];F&&s(m,F.id,{granularity:I})},[m,p,s]),w=C.useCallback((P,I)=>{if(!m)return;const F=p("metrics")[P];F&&o(m,F.id,{aliasTemplate:I})},[m,p,o]),N=C.useCallback((P,I)=>{if(console.log("handleValueAliasesChange",P,I),!m)return;console.log("handleValueAliasesChange",P,I);const F=p("metrics")[P];F&&(console.log("handleValueAliasesChange",I),o(m,F.id,{valueAliases:I}))},[m,p,o]),S=C.useCallback(P=>{if(!m)return;if(p("metrics").length===0){Oe.error("Add Metric First",{description:"Please add a metric field before selecting a comparison type",position:"top-center",duration:3e3});return}r(m,{comparisonType:P})},[m,r,p]),j=C.useCallback(P=>{m&&r(m,{showTrendline:P})},[m,r]),E=C.useCallback(P=>{m&&r(m,{trendlineWindow:P})},[m,r]),_=C.useCallback(P=>{m&&r(m,{trendlineGranularity:P})},[m,r]),k=C.useCallback(P=>{m&&r(m,{targetValue:P})},[m,r]),M=C.useCallback(P=>{var q;if(!m)return;const I=[...p("groupBy"),...p("pivotBy"),...p("metrics"),...p("sortBy")],L=sNe(P,I,{joinPlan:(q=e==null?void 0:e.config)==null?void 0:q.joinPlan,joinabilityMap:n==null?void 0:n.joinabilityMap,semanticDomainId:t});if(!L.isValid){L.showError&&IU();return}const F=aNe(P,I,h);if(!F){Oe.error("Invalid Field",{description:"This field cannot be added to any container",position:"top-center",duration:3e3});return}const H=Zee(P,F,h);if(!H.isValid){Oe.error("Invalid Field Type",{description:H.reason,position:"top-center",duration:3e3});return}const $=p(F);if(AU(P,$))return;const A=FU(P,F,$);if(A){const z=[...$,A];g(F,z),F==="metrics"&&Xee(h,e==null?void 0:e.config,r,m,z)}},[m,e==null?void 0:e.config,p,g,t,n,h,r]),D=C.useCallback((P,I)=>{if(!m)return;const F=p(P)[I];if(F){if(P!=="sortBy"){const H=p("sortBy"),$=H.filter(A=>!(A.name===F.name&&A.qualifiedEntityName===F.qualifiedEntityName));$.length!==H.length&&r(m,{sortByColumns:$})}switch(P){case"groupBy":l(m,F.id);break;case"metrics":u(m,F.id);break;case"pivotBy":d(m,F.id);break;case"sortBy":f(m,F.id);break}}},[m,p,l,u,d,f,r]);return{getFieldsForContainer:p,setFieldsForContainer:g,updateLabel:b,handleAggregationChange:x,handleDateFormatChange:y,handleGranularityChange:v,handleAliasTemplateChange:w,handleValueAliasesChange:N,removeField:D,handleFieldClick:M,handleKpiComparisonTypeChange:S,handleKpiShowTrendlineChange:j,handleKpiTrendlineWindowChange:E,handleKpiTrendlineGranularityChange:_,handleKpiTargetValueChange:k,cardType:h}};function hy(e,t){var Ee,Ve,qe,Ae,xt;const{tokenProps:n}=Ge(),r=zs(),s=Ge().authToken||e,o=_e(Ce=>Ce.selectedConnectionId),i=_e(Ce=>Ce.card),{queryKey:a}=_pe(i),l=_e(Ce=>Ce.selectedDatamodelId),u=_e(Ce=>Ce.isDevMode),d=_e(Ce=>Ce.selectedDatabaseName),f=_e(Ce=>Ce.selectedSchemaName),h=_e(Ce=>Ce.selectedTableName),m=_e(Ce=>Ce.actions.setSelectedConnectionId),p=_e(Ce=>Ce.actions.setSelectedDatamodelId),g=_e(Ce=>Ce.actions.setSelectedDatabaseName),b=_e(Ce=>Ce.actions.setSelectedSchemaName),x=_e(Ce=>Ce.actions.setSelectedTableName);_e(Ce=>Ce.actions.setCardSql);const{setQueryConfig:y}=Qn();function v(Ce){var _t;return o&&Ce==="API"?!1:o&&Ce==="S3"?!0:!(!o||!d||d==="NA"||((_t=_==null?void 0:_.capabilities)==null?void 0:_t.path.includes("schema"))&&!f)}function w(Ce){return o&&Ce?!(Ce==="API"||Ce==="S3"):!1}const{refetchConnections:N,connectionsData:S,isConnectionsLoading:j,isConnectionsError:E,selectedConnection:_}=$a(e),{refetch:k,data:M,isLoading:D,isError:R}=hn({queryKey:["models",o],queryFn:()=>qn(`${n.apiServiceUrl}/v1/datamodels`,(s==null?void 0:s.accessToken)||"",{connection_id:o}),enabled:!!(s!=null&&s.accessToken)&&!!o}),P=_==null?void 0:_.type,I=(_==null?void 0:_.type)==="API"||(_==null?void 0:_.type)==="S3",{data:L,isLoading:F,isFetching:H,isError:$,refetch:A}=hn({queryKey:["databases",o],queryFn:()=>qn(`${n.apiServiceUrl}/v1/databases`,(s==null?void 0:s.accessToken)||"",{connection_id:o}),enabled:w(P)}),{data:q,isLoading:z,isFetching:O,isError:W,refetch:B}=hn({queryKey:["schemas",o,d],queryFn:()=>qn(`${n.apiServiceUrl}/v1/schemas`,(s==null?void 0:s.accessToken)||"",{connection_id:o,database_name:d}),enabled:!!o&&!!d&&!I&&d!=="NA"}),{data:Y,isLoading:U,isFetching:V,isError:G,refetch:K}=hn({queryKey:["tables",o,d,f],queryFn:()=>qn(`${n.apiServiceUrl}/v1/tables`,(s==null?void 0:s.accessToken)||"",{connection_id:o,database_name:d,schema_name:f}),enabled:v(P)}),{columns:J,isColumnsLoading:Q,isColumnsFetching:re,isColumnsError:de,refetchColumns:fe}=$U(e);C.useEffect(()=>{(P==="S3"||P==="API")&&(g(""),b(""),p(""),P==="API"&&x("api"))},[P,x,g,b,p]);const ue=(_==null?void 0:_.type)==="API"?(Ee=_==null?void 0:_.type)==null?void 0:Ee.toLowerCase():h||"",je=I?"":f||"";function me(Ce){x(Ce),y(void 0),u||(r.setQueryData(a,null),r.removeQueries({queryKey:a,exact:!0}))}function ne(Ce){b(Ce),x("")}function oe(Ce){g(Ce==="none"?"":Ce),b(""),x(""),Ce!=="none"&&Ce!==""&&p("")}function pe(Ce){m(Ce)}function De(Ce){p(Ce==="none"?"":Ce),Ce!=="none"&&Ce!==""&&g("")}L&&((Ve=L==null?void 0:L.databases)==null?void 0:Ve.length)>0,q&&((qe=q==null?void 0:q.schemas)==null?void 0:qe.length)>0;const ae=S==null?void 0:S.connections.map(Ce=>({id:Ce.id,name:Ce.name,type:Ce.type})),Te=(Ae=M==null?void 0:M.datamodels)==null?void 0:Ae.map(Ce=>({id:Ce.id,name:Ce.name})),Ue=L==null?void 0:L.databases.map(Ce=>({id:Ce.database_name,name:Ce.database_name})),ie=q==null?void 0:q.schemas.map(Ce=>({id:Ce.schema_name,name:Ce.schema_name})),xe=Y==null?void 0:Y.tables.map(Ce=>({id:Ce.table_name,name:Ce.table_name})),$e=(xt=M==null?void 0:M.datamodels.find(Ce=>Ce.id===l))==null?void 0:xt.name,he=kv({schemaName:je,tableName:ue,modelName:$e,connectionType:P,databaseName:d||""});return{connectionItems:ae,selectedConnectionId:o,selectedConnection:_,isConnectionsLoading:j,isConnectionsError:E,modelItems:Te,selectedDatamodelId:l,selectedDatamodelName:$e,isModelsLoading:D,isModelsError:R,selectedDatabaseName:d,databaseItems:Ue,isDatabasesLoadingOrFetching:F||H,isDatabaseError:$,schemaItems:ie,selectedSchemaName:f,isSchemaLoadingOrFetching:z||O,isSchemaError:W,tableItems:xe,selectedTableName:h,isTableLoadingOrFetching:U||V,isTableError:G,columns:J,isColumnsLoadingOrFetching:Q||re,isColumnsError:de,isNonDbConnection:I,connectionType:P,tableName:ue,formattedTableName:he,schemaName:je,refetchConnections:N,refetchModels:k,refetchDatabases:A,refetchSchemas:B,refetchTables:K,refetchColumns:fe,handleConnectionChange:pe,handleDatamodelChange:De,handleDatabaseChange:oe,handleSchemaChange:ne,handleTableChange:me}}function W0(e){return`${e}-${vr()}`}function S6(e,t){const n=ni(e.replace(/_/g," "));switch(t){case"SUM":return`Sum of ${n}`;case"COUNT":return`Count of ${n}`;case"DISTINCT":return`Unique ${n}`;case"AVG":return`Average of ${n}`;case"MIN":return`Min of ${n}`;case"MAX":return`Max of ${n}`;default:return n}}function PJe(e,t){const n=ni(e.replace(/_/g," "));switch(t){case"day":return`Date of ${n}`;case"week":return`Week of ${n}`;case"month":return`Month of ${n}`;case"year":return`Year of ${n}`;default:return n}}function CA(e){if(!e||!e.selectedEntities||e.selectedEntities.length===0)return{tableName:void 0,schemaName:void 0,databaseName:void 0,connectionId:e==null?void 0:e.connectionId,connectionType:e==null?void 0:e.connectionType};const t=e.selectedEntities[0];return{tableName:t==null?void 0:t.name,schemaName:t==null?void 0:t.schema,databaseName:t==null?void 0:t.database,connectionId:e.connectionId,connectionType:e.connectionType}}function Jee(e){if(!e||!e.selectedEntities||e.selectedEntities.length===0)return!1;const t=e.selectedEntities[0];return!!(t!=null&&t.name)}function ete(){const e=_e(S=>S.sqlGen),t=_e(S=>S.isDevMode),n=_e(S=>S.card.dataSource),r=_e(S=>{var j,E;return(E=(j=S.card)==null?void 0:j.queryConfig)==null?void 0:E.metricColumns}),{tableName:s,schemaName:o,databaseName:i}=CA(n),a=Jee(n),l=_e(S=>S.selectedDatamodelId),{addColumnToMetricColumns:u,addColumnToGroupBy:d,setCardSql:f,setRunSql:h,setSqlGen:m,setIsShowingVisual:p}=Qn(),{connectionType:g,modelItems:b,selectedDatamodelName:x}=hy(),y=S=>({column_name:S.name,data_type:S.dataType,label:S.label,description:S.description});return{handleDevModeFieldClick:S=>{var E;if(!t)return;const j=y(S);if(t&&a&&s){const _=cD(j,e);m(_);const k=(E=b==null?void 0:b.find(D=>D.id===l))==null?void 0:E.name,M=lD(_,Ci(o||""),Ci(s),k||"",g,i||"");M&&(f(M),h(!0))}else if(!t){if(Qb(j.data_type))if(r&&r.length>0){const _={...j,role:"groupby",id:W0(j.column_name),name:j.column_name,type:j.data_type};d(_)}else{const _={...j,role:"metric",id:W0(j.column_name),name:j.column_name,label:S6(j.column_name,"COUNT"),type:j.data_type,aggregate:"COUNT"};u(_)}if(Ii(j.data_type)){const _={...j,role:"groupby",id:W0(j.column_name),name:j.column_name,type:j.data_type,label:PJe(j.column_name,"month"),granularity:"month"};d(_)}if(Ri(j.data_type)){const _={...j,role:"metric",id:W0(j.column_name),name:j.column_name,label:S6(j.column_name,"SUM"),type:j.data_type,aggregate:"SUM"};u(_)}}},handleShowSample:()=>{if(!a||!s){console.warn("Cannot generate SQL: missing table metadata");return}const S=kv({schemaName:o||"",tableName:s,modelName:x,connectionType:g,databaseName:i||""});p(!1);const j=g==="MSSQL"?`SELECT top 10 * FROM ${S}`:`SELECT * FROM ${S} LIMIT 10`;f(j),h(!0)},handleShowCount:()=>{if(!a||!s){console.warn("Cannot generate SQL: missing table metadata");return}const S=kv({schemaName:o||"",tableName:s,modelName:x,connectionType:g,databaseName:i||""});f(`SELECT COUNT(*) as count FROM ${S}`),h(!0)},isNumberField:S=>Ri(S.dataType)}}function OJe({columnName:e,database:t,schemaName:n,tableName:r,connectionType:s,datamodelId:o,modelName:i,field:a}){const l=Ci(e),u=Ci(t||""),d=Ci(n||""),f=Ci(r);let h=x1({schemaName:d,tableName:f,connectionType:s,databaseName:u}),m=`${h}.${l}`;return o&&o!=="none"&&i&&(m=`${Vg}.${i}.${l}`,h=`${Vg}.${i}`),a!=null&&a.qualifiedFieldName&&(m=a.qualifiedFieldName,h=a.qualifiedFieldName.split(".").slice(0,-1).join(".")),{qualifiedColumnName:m,qualifiedTableName:h,formattedColumnName:l,formattedTableName:f,formattedDatabase:u,formattedSchemaName:d}}function tte(){const e=_e(p=>p.selectedConnectionId),t=_e(p=>p.selectedDatamodelId),n=_e(p=>p.selectedDatabaseName),r=_e(p=>p.selectedSchemaName),s=_e(p=>p.selectedTableName),o=X(p=>p.dashboard.filters)||[],i=X(p=>p.selectedSheetId),a=X(p=>p.actions.addFilter),l=X(p=>p.actions.removeFilter),{removeFilterValues:u}=Ot(),{modelItems:d,tableName:f,connectionType:h}=hy();function m(p,g="sheet",b){var E;const x=(E=d==null?void 0:d.find(_=>_.id===t))==null?void 0:E.name,{qualifiedColumnName:y,qualifiedTableName:v,formattedColumnName:w,formattedTableName:N,formattedDatabase:S}=OJe({columnName:p.column_name,database:n,schemaName:r,tableName:f,connectionType:h,datamodelId:t,modelName:x,field:b});let j;if(g==="sheet"&&i?j=a_e(o,y,N,n||"",S,i):j=o==null?void 0:o.find(_=>_.column===y&&_.table===N&&(_.database===S||_.database===n)),j)u(j.id),l(j.id);else{const _=vr(),k=g==="sheet"&&i?[i]:void 0;return f==="api"&&e?(a({location:g,id:_,column:y,title:p.label||p.column_name,dataType:p.data_type,table:"api",database:"",connectionId:e,operation:"in",applyToSheetIds:k,sql:KE(p.data_type,v,w)}),_):(a({id:_,location:g,column:y,title:p.label||p.column_name,dataType:p.data_type,table:s||"",database:n||"",connectionId:e||"",operation:"in",applyToSheetIds:k,sql:KE(p.data_type,v,(b==null?void 0:b.qualifiedFieldName)||w)}),_)}}return{assignFilter:m}}function FJe({column:e}){const[t,n]=C.useState(!1),r=_e(x=>x.card.dataSource),{tableName:s,schemaName:o,databaseName:i}=CA(r),a=_e(x=>x.selectedDatamodelId),l=_e(x=>x.sqlGen),{modelItems:u,connectionType:d}=hy(),f=_e(x=>x.actions.setSqlGen),h=_e(x=>x.actions.setCardSql),m=_e(x=>x.actions.setRunSql),p=Jee(r);function g(x,y){var S;if(!p||!s){console.warn("Cannot generate SQL: missing table metadata");return}const v=cD(x,l,y),w=(S=u==null?void 0:u.find(j=>j.id===a))==null?void 0:S.name;f(v);const N=lD(v,Ci(o||""),Ci(s),w||"",d,i||"");N&&(h(N),m(!0)),n(!1)}function b(){return c.jsxs("ul",{className:"text-xs",children:[c.jsx("li",{onClick:()=>g(e,"COUNT"),className:"cursor-pointer p-1 px-3 transition-colors hover:bg-muted",children:"Count"}),c.jsx("li",{onClick:()=>g(e,"AVG"),className:"cursor-pointer p-1 px-3 transition-colors hover:bg-muted",children:"Avg"}),c.jsx("li",{onClick:()=>g(e,"SUM"),className:"cursor-pointer p-1 px-3 transition-colors hover:bg-muted",children:"Sum"}),c.jsx("li",{onClick:()=>g(e,"MAX"),className:"cursor-pointer p-1 px-3 transition-colors hover:bg-muted",children:"Max"}),c.jsx("li",{onClick:()=>g(e,"MIN"),className:"cursor-pointer p-1 px-3 transition-colors hover:bg-muted",children:"Min"})]})}return p?c.jsxs(km,{openDelay:0,open:t,onOpenChange:n,children:[c.jsx(Em,{asChild:!0,children:c.jsx(lm,{className:"invisible size-3.5 cursor-pointer text-foreground/40 group-hover/container:visible"})}),c.jsx(of,{align:"center",className:"w-20 rounded-md p-0 shadow-none",children:b()})]}):null}function $Je({field:e,fieldState:t}){return c.jsxs("div",{className:"w-64 bg-background p-0",children:[c.jsxs("div",{className:"mb-2 flex items-start justify-between gap-2",children:[c.jsx("h3",{className:"text-sm font-medium text-foreground",children:e.label||e.name}),c.jsx("span",{className:"rounded bg-muted px-2 py-0.5 font-mono text-xs text-muted-foreground",children:e.dataType})]}),e.description&&c.jsx("p",{className:"mb-3 text-xs text-muted-foreground",children:e.description}),t&&t.tooltip&&c.jsx("div",{className:"mb-2 rounded bg-muted/50 p-2",children:c.jsx("p",{className:"text-xs text-muted-foreground",children:t.tooltip})}),c.jsx("div",{className:"overflow-x-auto border-t border-border pb-2 pt-2",children:c.jsx("span",{className:"font-mono text-xs text-muted-foreground",children:e.name})})]})}function LJe({field:e,context:t="editor",fieldState:n,onFieldSelect:r,inlineFilters:s}){const o=_e(Y=>Y.isDevMode),i=t==="filter"||t==="inline-filter",a=o||i||(n==null?void 0:n.state)==="unreachable"&&!i,l=X(Y=>Y.dashboard.filters),u=X(Y=>Y.selectedSheetId),d=X(Y=>Y.actions.removeFilter),{removeFilterValues:f}=Ot(),{assignFilter:h}=tte(),m=t==="filter"?Bl(l,u):l,p=t==="filter"?m==null?void 0:m.find(Y=>{var U;return Y.title===e.name||((U=Y.column)==null?void 0:U.includes(e.name))}):void 0,g=!!p,b=t==="inline-filter"&&(s==null?void 0:s.some(Y=>Y.column===e.qualifiedFieldName||Y.column===e.name)),x=g||b,y=p&&i?l==null?void 0:l.find(Y=>Y.id===p.id):void 0,v=y&&(y.applyToSheetIds&&y.applyToSheetIds.length>1||y.excludeSheetIds&&y.excludeSheetIds.length>0||!y.applyToSheetIds&&!y.excludeSheetIds&&!y.sheetId);i&&x&&console.log("[SourceField Debug]",{fieldName:e.name,hasActiveFilter:x,activeFilterOnSheet:p?{id:p.id,title:p.title,column:p.column,applyToSheetIds:p.applyToSheetIds,excludeSheetIds:p.excludeSheetIds}:null,activeFilterForField:y?{id:y.id,title:y.title,column:y.column,applyToSheetIds:y.applyToSheetIds,excludeSheetIds:y.excludeSheetIds}:null,isMultiSheetFilter:v,selectedSheetId:u});const[w,N]=C.useState(!1),[S,j]=C.useState(null),{attributes:E,listeners:_,setNodeRef:k,transform:M,transition:D,isDragging:R}=oy({id:e.id,disabled:a}),[P,I]=C.useState(!1),L=_e(Y=>Y.card),{handleFieldClick:F}=Qee(L),{handleDevModeFieldClick:H,isNumberField:$}=ete(),A=()=>{y&&(console.log("[SourceField] Removing multi-sheet filter:",y.id),f(y.id),d(y.id)),j(null),N(!1)},q=()=>{if(t==="inline-filter"&&r){r(e);return}if(t==="filter"){const Y={column_name:e.name,data_type:e.dataType,label:e.label,description:e.description,qualifiedFieldName:e.qualifiedFieldName};x&&v?(j({column:Y,field:e}),N(!0)):h(Y,"sheet",e)}else o?H(e):F(e)},z={column_name:e.name,data_type:e.dataType,label:e.label,description:e.description},O={transform:ii.Transform.toString(M),transition:D},B=(()=>{if(!n||i)return{};const U={base:{hoverBorderColor:"hover:border-blue-500/40",hoverBgColor:"hover:bg-blue-50/50 dark:hover:bg-blue-950/20"},draggable:{hoverBorderColor:"hover:border-green-500/40",hoverBgColor:"hover:bg-green-50/30 dark:hover:bg-green-950/20"},indirect:{hoverBorderColor:"hover:border-yellow-500/40",hoverBgColor:"hover:bg-yellow-50/30 dark:hover:bg-yellow-950/20"},unreachable:{borderColor:"border-gray-300/40 dark:border-gray-700/40",bgColor:"bg-gray-50/30 dark:bg-gray-900/20",hoverBgColor:"hover:bg-gray-100/30 dark:hover:bg-gray-800/20",opacity:"opacity-50",cursor:"cursor-not-allowed"}}[n.state]||{};return n.isSelected&&{base:{borderColor:"border-blue-300/30 dark:border-blue-700/30",bgColor:"bg-blue-50/20 dark:bg-blue-950/10",...U},draggable:{borderColor:"border-green-300/30 dark:border-green-700/30",bgColor:"bg-green-50/20 dark:bg-green-950/10",...U},indirect:{borderColor:"border-yellow-300/30 dark:border-yellow-700/30",bgColor:"bg-yellow-50/20 dark:bg-yellow-950/10",...U}}[n.state]||U})();return c.jsxs("div",{ref:k,style:O,...a?{}:E,...a?{}:_,className:Z("group/container max-w-[265px] overflow-hidden rounded-lg transition-all",R&&"scale-95 opacity-50",!R&&"border",B.borderColor||"border-transparent",B.bgColor||"",B.hoverBorderColor,B.hoverBgColor||"hover:bg-muted",B.opacity,B.cursor,g&&"border-accent-foreground/20 bg-accent",b&&"border-primary/20 bg-primary/10",{"cursor-pointer":o||i,"cursor-grab active:cursor-grabbing":!a&&!o&&!i}),title:n==null?void 0:n.tooltip,children:[c.jsxs("div",{className:"flex min-w-0 items-center gap-3 p-2",onClick:q,children:[Eb(e.dataType),c.jsx(_n,{children:c.jsxs(Zt,{children:[c.jsx(Xt,{asChild:!0,children:c.jsx("div",{className:"min-w-0 flex-1 overflow-hidden",children:c.jsx("span",{className:`block text-sm text-foreground/80 hover:text-foreground dark:text-muted-foreground ${P?"whitespace-normal break-words":"truncate"}`,children:e.label||e.name})})}),c.jsx(en,{side:"bottom",align:"start",className:"ml-5 max-w-xs px-4 pb-2 pt-4",children:c.jsx($Je,{field:e,fieldState:n})})]})}),o&&!i&&$(e)&&c.jsx("div",{onClick:Y=>Y.stopPropagation(),children:c.jsx(FJe,{column:z})})]}),P&&c.jsx("div",{className:"text-muted-foreground-700 px-2 pb-3 text-sm",children:c.jsx(Do,{className:"",children:c.jsxs(Oi,{className:"space-y-2 p-3",children:[c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsx(M8,{className:"h-4 w-4 text-muted-foreground"}),c.jsx("span",{className:"break-all",children:e.label||e.name})]}),c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsx(yle,{className:"h-4 w-4 text-muted-foreground"}),c.jsx("span",{className:"break-all",children:e.name})]}),c.jsx(Fe,{variant:"outline",className:"mt-2 text-xs",children:e.dataType})]})})}),c.jsx(px,{open:w,onOpenChange:N,children:c.jsxs(ym,{children:[c.jsxs(vm,{children:[c.jsx(Sm,{children:"Remove Filter from Multiple Sheets?"}),c.jsx(Cm,{children:"This filter is currently applied to multiple sheets. Removing it will affect all sheets where it's applied."})]}),c.jsxs(wm,{children:[c.jsx(jm,{children:"Cancel"}),c.jsx(Nm,{onClick:A,children:"Remove Filter"})]})]})})]})}const zJe="SEMAPHOR_CALCULATED_FIELD",BJe=["MM-DD-YYYY","YYYY-MM-DD","MM/DD/YYYY","DD/MM/YYYY","MMMM DD, YYYY","MMM DD, YYYY","DD MMM YYYY","Week of MMM DD, YYYY","Week of MMMM DD, YYYY","YYYY-WW","MMM YYYY","MMMM YYYY","YYYY-MM","MM/YYYY","YYYY MMM","Q1 YYYY","YYYY Q1","1st Quarter YYYY","YYYY-Q1","Quarter 1, YYYY","YYYY","YY","custom"];function nte(e){return!!e.expression}function VJe(e){return!!e.expression}function HJe(e){return!!e.expression}var rte=(e=>(e.SUBTOTAL="__SUBTOTAL__",e.TOTAL="__TOTAL__",e.ALL="__ALL__",e))(rte||{}),Ki="Accordion",UJe=["Home","End","ArrowDown","ArrowUp","ArrowLeft","ArrowRight"],[NA,WJe,qJe]=sx(Ki),[MC]=kr(Ki,[qJe,bW]),jA=bW(),ste=C.forwardRef((e,t)=>{const{type:n,...r}=e,s=r,o=r;return c.jsx(NA.Provider,{scope:e.__scopeAccordion,children:n==="multiple"?c.jsx(ZJe,{...o,ref:t}):c.jsx(KJe,{...s,ref:t})})});ste.displayName=Ki;var[ote,YJe]=MC(Ki),[ite,GJe]=MC(Ki,{collapsible:!1}),KJe=C.forwardRef((e,t)=>{const{value:n,defaultValue:r,onValueChange:s=()=>{},collapsible:o=!1,...i}=e,[a,l]=Br({prop:n,defaultProp:r??"",onChange:s,caller:Ki});return c.jsx(ote,{scope:e.__scopeAccordion,value:C.useMemo(()=>a?[a]:[],[a]),onItemOpen:l,onItemClose:C.useCallback(()=>o&&l(""),[o,l]),children:c.jsx(ite,{scope:e.__scopeAccordion,collapsible:o,children:c.jsx(ate,{...i,ref:t})})})}),ZJe=C.forwardRef((e,t)=>{const{value:n,defaultValue:r,onValueChange:s=()=>{},...o}=e,[i,a]=Br({prop:n,defaultProp:r??[],onChange:s,caller:Ki}),l=C.useCallback(d=>a((f=[])=>[...f,d]),[a]),u=C.useCallback(d=>a((f=[])=>f.filter(h=>h!==d)),[a]);return c.jsx(ote,{scope:e.__scopeAccordion,value:i,onItemOpen:l,onItemClose:u,children:c.jsx(ite,{scope:e.__scopeAccordion,collapsible:!0,children:c.jsx(ate,{...o,ref:t})})})}),[XJe,TC]=MC(Ki),ate=C.forwardRef((e,t)=>{const{__scopeAccordion:n,disabled:r,dir:s,orientation:o="vertical",...i}=e,a=C.useRef(null),l=rt(a,t),u=WJe(n),f=eu(s)==="ltr",h=ke(e.onKeyDown,m=>{var E;if(!UJe.includes(m.key))return;const p=m.target,g=u().filter(_=>{var k;return!((k=_.ref.current)!=null&&k.disabled)}),b=g.findIndex(_=>_.ref.current===p),x=g.length;if(b===-1)return;m.preventDefault();let y=b;const v=0,w=x-1,N=()=>{y=b+1,y>w&&(y=v)},S=()=>{y=b-1,y<v&&(y=w)};switch(m.key){case"Home":y=v;break;case"End":y=w;break;case"ArrowRight":o==="horizontal"&&(f?N():S());break;case"ArrowDown":o==="vertical"&&N();break;case"ArrowLeft":o==="horizontal"&&(f?S():N());break;case"ArrowUp":o==="vertical"&&S();break}const j=y%x;(E=g[j].ref.current)==null||E.focus()});return c.jsx(XJe,{scope:n,disabled:r,direction:s,orientation:o,children:c.jsx(NA.Slot,{scope:n,children:c.jsx(ze.div,{...i,"data-orientation":o,ref:l,onKeyDown:r?void 0:h})})})}),u1="AccordionItem",[QJe,kA]=MC(u1),lte=C.forwardRef((e,t)=>{const{__scopeAccordion:n,value:r,...s}=e,o=TC(u1,n),i=YJe(u1,n),a=jA(n),l=ar(),u=r&&i.value.includes(r)||!1,d=o.disabled||e.disabled;return c.jsx(QJe,{scope:n,open:u,disabled:d,triggerId:l,children:c.jsx(vW,{"data-orientation":o.orientation,"data-state":mte(u),...a,...s,ref:t,disabled:d,open:u,onOpenChange:f=>{f?i.onItemOpen(r):i.onItemClose(r)}})})});lte.displayName=u1;var cte="AccordionHeader",ute=C.forwardRef((e,t)=>{const{__scopeAccordion:n,...r}=e,s=TC(Ki,n),o=kA(cte,n);return c.jsx(ze.h3,{"data-orientation":s.orientation,"data-state":mte(o.open),"data-disabled":o.disabled?"":void 0,...r,ref:t})});ute.displayName=cte;var H_="AccordionTrigger",dte=C.forwardRef((e,t)=>{const{__scopeAccordion:n,...r}=e,s=TC(Ki,n),o=kA(H_,n),i=GJe(H_,n),a=jA(n);return c.jsx(NA.ItemSlot,{scope:n,children:c.jsx(cje,{"aria-disabled":o.open&&!i.collapsible||void 0,"data-orientation":s.orientation,id:o.triggerId,...a,...r,ref:t})})});dte.displayName=H_;var fte="AccordionContent",hte=C.forwardRef((e,t)=>{const{__scopeAccordion:n,...r}=e,s=TC(Ki,n),o=kA(fte,n),i=jA(n);return c.jsx(uje,{role:"region","aria-labelledby":o.triggerId,"data-orientation":s.orientation,...i,...r,ref:t,style:{"--radix-accordion-content-height":"var(--radix-collapsible-content-height)","--radix-accordion-content-width":"var(--radix-collapsible-content-width)",...e.style}})});hte.displayName=fte;function mte(e){return e?"open":"closed"}var JJe=ste,eet=lte,tet=ute,pte=dte,gte=hte;const bte=JJe,EA=T.forwardRef(({className:e,...t},n)=>c.jsx(eet,{ref:n,className:Z("border-b",e),...t}));EA.displayName="AccordionItem";const _A=T.forwardRef(({className:e,children:t,...n},r)=>c.jsx(tet,{className:"flex",children:c.jsxs(pte,{ref:r,className:Z("flex flex-1 items-center justify-between py-4 font-medium transition-all hover:underline [&[data-state=open]>svg]:rotate-180",e),...n,children:[t,c.jsx(hr,{className:"h-4 w-4 shrink-0 transition-transform duration-200"})]})}));_A.displayName=pte.displayName;const DA=T.forwardRef(({className:e,children:t,...n},r)=>c.jsx(gte,{ref:r,className:"overflow-hidden text-sm transition-all data-[state=closed]:animate-accordion-up data-[state=open]:animate-accordion-down",...n,children:c.jsx("div",{className:Z("pb-4 pt-0",e),children:t})}));DA.displayName=gte.displayName;function xte({context:e="editor",onFieldSelect:t,inlineFilters:n}={}){var I,L,F,H;const[r,s]=C.useState(""),[o,i]=C.useState("all");_e($=>$.isDevMode);const a=_e($=>$.card.dataSource),l=_e($=>$.card.config),u=_e($=>$.card),{autoJoinMetadata:d}=_a(u),{columns:f=[],columnGroups:h=[],isLoading:m,error:p}=pT(),g=(a==null?void 0:a.mode)==="semanticDomain"?a.semanticDomainId:void 0,{data:b}=SA(g),x=[...(l==null?void 0:l.groupByColumns)||[],...(l==null?void 0:l.metricColumns)||[]];(L=(I=l==null?void 0:l.joinPlan)==null?void 0:I.baseEntity)==null||L.name,(H=(F=d==null?void 0:d.resolvedJoinPlan)==null?void 0:F.baseEntity)==null||H.name,ete();const y=f.filter($=>$.name.toLowerCase().includes(r.toLowerCase())||$.dataType.toLowerCase().includes(r.toLowerCase())||$.label&&$.label.toLowerCase().includes(r.toLowerCase())||$.qualifiedEntityName&&$.qualifiedEntityName.toLowerCase().includes(r.toLowerCase())),v=$=>{if($.role==="metric"&&nte($)||$.role==="groupby"&&$.expression)return"calculated";if($.dataType==="number"||$.dataType==="integer"||$.dataType==="float"||$.dataType==="decimal"||$.dataType==="currency")return"metrics";const A=Tr($.dataType);return["date","string","boolean"].includes(A)?"dimensions":A==="number"?"metrics":"dimensions"},N=(o==="all"?y:y.filter($=>v($)===o)).reduce(($,A)=>{const q=A.qualifiedEntityName||"Other Fields";return $[q]||($[q]={label:xD(A.entityName),fields:[]}),$[q].fields.push(A),$},{}),j=Object.keys(N),E=y.filter($=>v($)==="dimensions").length,_=y.filter($=>v($)==="metrics").length,k=y.filter($=>v($)==="calculated").length,M=y.length>0&&e!=="inline-filter",D=e==="inline-filter"?"w-full":"w-[290px]";if(m)return c.jsx("div",{className:Z("flex h-full flex-col items-center justify-center py-8",D),children:c.jsx(Gc,{size:"md",color:"muted","aria-label":"Loading data"})});if(p)return c.jsxs("div",{className:Z("flex h-full flex-col items-center justify-center py-8",D),children:[c.jsx(Cl,{className:"mb-4 h-12 w-12 text-red-300"}),c.jsx("p",{className:"mb-2 text-sm text-red-500",children:"Error loading fields"}),c.jsx("p",{className:"px-4 text-center text-xs text-red-400",children:p.message||"Failed to load column data"})]});if(!a||!a.selectedEntities||a.selectedEntities.length===0)return c.jsxs("div",{className:Z("flex flex-col items-center justify-center py-8 text-center",D),children:[c.jsx(Cl,{className:"mb-4 h-12 w-12 text-gray-300"}),c.jsx("p",{className:"mb-2 text-sm text-gray-500",children:"No data source selected"}),c.jsx("p",{className:"px-4 text-xs text-gray-400",children:e==="filter"||e==="inline-filter"?"Configure a data source for this card to see available fields":"Select a table, view, or dataset from the data source panel to see available fields"})]});const R=e==="inline-filter"?"px-3 pb-3":"px-6 pb-6",P=e==="inline-filter"?"overflow-hidden":"";return c.jsxs("div",{className:Z("mt-2 flex h-full w-full grow flex-col gap-2",R,P),children:[c.jsxs("div",{className:"mt-1 flex-shrink-0 space-y-2",children:[f.length>0&&c.jsxs("div",{className:"relative",children:[c.jsx(Ui,{className:"absolute left-3 top-1/2 size-3.5 -translate-y-1/2 transform text-muted-foreground"}),c.jsx(xn,{className:"pl-10 pr-10",type:"text",placeholder:"Search fields...",value:r,onChange:$=>s($.target.value)}),r&&c.jsx("button",{className:"absolute right-3 top-1/2 -translate-y-1/2 transform text-muted-foreground hover:text-foreground",onClick:()=>s(""),type:"button",children:c.jsx(yt,{className:"size-3.5"})})]}),M&&c.jsx(Bs,{defaultValue:"all",value:o,onValueChange:$=>i($),className:"mb-4",children:c.jsxs(vs,{className:"grid h-9 w-full grid-cols-4",children:[c.jsxs(Gt,{value:"all",className:"text-xs",children:["All",c.jsx("span",{className:"ml-2 text-xs font-semibold",children:y.length})]}),c.jsxs(Gt,{value:"dimensions",className:"text-xs",children:[c.jsx(D1,{className:"size-4 shrink-0"}),c.jsx("span",{className:"ml-2 text-xs font-semibold",children:E})]}),c.jsxs(Gt,{value:"metrics",className:"text-xs",children:[c.jsx(im,{className:"size-4 shrink-0"}),c.jsx("span",{className:"ml-2 text-xs font-semibold",children:_})]}),c.jsxs(Gt,{value:"calculated",className:"text-xs",children:[c.jsx(kD,{className:"size-4 shrink-0"}),c.jsx("span",{className:"ml-2 text-xs font-semibold",children:k})]})]})})]}),c.jsxs(Vl,{className:"min-h-0 overflow-auto",children:[c.jsx(bte,{type:"multiple",defaultValue:j,className:"space-y-2",children:Object.entries(N).map(([$,A])=>{const q=h.find(z=>z.entityName===$)||{entityName:$,label:A.label};return c.jsxs(EA,{value:$,className:"border-none",children:[c.jsx(_A,{className:"group rounded-md px-2.5 py-2 text-muted-foreground hover:bg-muted hover:no-underline",children:c.jsxs("div",{title:q.label||q.entityName,className:"flex items-center gap-2",children:[c.jsx("span",{className:"max-w-[190px] truncate text-ellipsis whitespace-nowrap text-sm font-medium text-primary",children:q.label||q.entityName}),c.jsx(Fe,{variant:"secondary",className:"rounded-full text-xs text-muted-foreground group-hover:bg-background",children:A.fields.length})]})}),c.jsx(DA,{className:"pb-2",children:c.jsx("div",{className:"space-y-1",children:A.fields.map(z=>{const O=gT(z,{joinabilityMap:(b==null?void 0:b.joinabilityMap)||null,selectedFields:x,cardConfig:l,autoJoinMetadata:d});return c.jsx(LJe,{field:z,context:e,fieldState:O,onFieldSelect:t,inlineFilters:e==="inline-filter"?n:void 0},z.id)})})})]},$)})}),Object.keys(N).length===0&&f.length===0&&c.jsxs("div",{className:"py-8 text-center text-sm text-gray-500",children:[c.jsx("p",{children:"No fields found for selected data source"}),c.jsx("p",{className:"mt-1 text-xs text-gray-400",children:e==="filter"?"The selected data source has no available fields":"Try selecting different data sources"})]}),Object.keys(N).length===0&&f.length>0&&c.jsx("div",{className:"py-4 text-center text-sm text-gray-500",children:"No fields found for this category"}),c.jsx(si,{orientation:"horizontal"}),c.jsx(si,{orientation:"vertical"})]})]})}function yte({context:e="editor"}={}){return c.jsxs("div",{"data-content":"fields-section",className:"flex h-full grow flex-col items-center overflow-hidden",children:[" ",c.jsx(xte,{context:e})," "]})}function vte(){const e=_e(i=>i.card.dataSource),{setSelectedConnectionId:t,setSelectedDatabaseName:n,setSelectedSchemaName:r,setSelectedTableName:s,setSelectedDatamodelId:o}=Qn();C.useEffect(()=>{var m;if(!e)return;const{tableName:i,schemaName:a,databaseName:l,connectionId:u}=CA(e),d=(m=e.selectedEntities)==null?void 0:m[0],h=(d==null?void 0:d.type)==="model"&&"id"in d?d.id:"";t(u||""),n(l||""),r(a||""),s(i||""),o(h)},[e,t,n,r,s,o])}function net(){vte();const e=X(l=>l.selectedSheetId),t=X(l=>l.selectedFrameId),n=X(l=>l.dashboard),r=X(l=>l.actions.getSelectedFrame),{setSelectedFrameId:s}=Ot(),{setCard:o}=Qn(),i=_e(l=>l.card.dataSource);return C.useEffect(()=>{var u,d;let l=r();if(!l){const f=(u=n==null?void 0:n.sheets)==null?void 0:u.find(m=>m.id===e),h=(d=f==null?void 0:f.frames)==null?void 0:d[0];h&&(s(h.id),l=h)}if(l){const f=l.cards.find(h=>h.id===l.activeCardId);f&&o(f)}},[r,e,t,n,s,o]),{hasEntities:!!(i!=null&&i.selectedEntities&&i.selectedEntities.length>0)}}function ret(){const e=X(o=>o.dashboard.filterLayout),{setFilterLayout:t}=Ot(),n=(e==null?void 0:e.displayMode)||"canvas",r=(e==null?void 0:e.toolbarWrap)??!1,s=(e==null?void 0:e.showDownloadButton)??!1;return c.jsxs(Xr,{children:[c.jsx(Qr,{asChild:!0,children:c.jsx(se,{variant:"ghost",size:"sm",className:"h-7 w-7 p-0","aria-label":"Filter display settings",children:c.jsx(Nl,{className:"h-4 w-4"})})}),c.jsx(Jr,{className:"w-[280px]",align:"end",children:c.jsxs("div",{className:"space-y-4",children:[c.jsxs("div",{children:[c.jsx("h4",{className:"mb-3 text-sm font-medium",children:"Filter Display"}),c.jsxs(jo,{value:n,onValueChange:o=>t({displayMode:o}),className:"space-y-2",children:[c.jsxs("div",{className:"flex items-start space-x-3",children:[c.jsx(In,{value:"canvas",id:"canvas",className:"mt-0.5"}),c.jsxs("div",{className:"grid gap-0.5",children:[c.jsx(ce,{htmlFor:"canvas",className:"cursor-pointer font-normal",children:"Canvas Cards"}),c.jsx("p",{className:"text-xs text-muted-foreground",children:"Filters as draggable, resizable cards on the dashboard"})]})]}),c.jsxs("div",{className:"flex items-start space-x-3",children:[c.jsx(In,{value:"toolbar",id:"toolbar",className:"mt-0.5"}),c.jsxs("div",{className:"grid gap-0.5",children:[c.jsx(ce,{htmlFor:"toolbar",className:"cursor-pointer font-normal",children:"Toolbar"}),c.jsx("p",{className:"text-xs text-muted-foreground",children:"Compact horizontal toolbar below dashboard controls"})]})]})]})]}),n==="toolbar"&&c.jsxs(c.Fragment,{children:[c.jsxs("div",{className:"flex items-center space-x-2 border-t pt-4",children:[c.jsx(Qt,{id:"wrap",checked:r,onCheckedChange:o=>t({toolbarWrap:o===!0})}),c.jsx(ce,{htmlFor:"wrap",className:"cursor-pointer text-sm font-normal",children:"Wrap filters to multiple lines"})]}),c.jsxs("div",{className:"flex items-center space-x-2 pt-2",children:[c.jsx(Qt,{id:"download",checked:s,onCheckedChange:o=>t({showDownloadButton:o===!0})}),c.jsx(ce,{htmlFor:"download",className:"cursor-pointer text-sm font-normal",children:"Show download button"})]})]}),c.jsx("p",{className:"border-t pt-3 text-xs text-muted-foreground",children:"Individual filters can override this setting in their configuration."})]})})]})}function set(){const e=X(n=>n.actions.setShowFilters),{hasEntities:t}=net();return c.jsxs("section",{className:"relative flex min-w-[320px] grow flex-col overflow-hidden border-l",children:[c.jsxs("div",{className:"mt-4 flex items-center justify-between gap-2 px-4",children:[c.jsx(ce,{className:"px-2 text-base",children:"Dashboard Filters"}),c.jsxs("div",{className:"flex items-center gap-1",children:[c.jsx(ret,{}),c.jsx(se,{onClick:()=>e(!1),className:"h-7 w-7 p-0",variant:"ghost",children:c.jsx(tX,{})})]})]}),!t&&c.jsxs("div",{className:"flex h-full flex-col items-center justify-center px-6 py-12 text-center",children:[c.jsx(Cl,{className:"mb-4 h-12 w-12 text-muted-foreground/50"}),c.jsx("h3",{className:"mb-2 text-sm font-medium text-foreground",children:"No fields configured"}),c.jsx("p",{className:"text-xs text-muted-foreground",children:"Please configure a data source for this card to enable filtering"})]}),t&&c.jsx("div",{className:"flex grow overflow-y-auto",children:c.jsx(ry,{collisionDetection:ey,children:c.jsx(sy,{items:[],strategy:RI,children:c.jsx(yte,{context:"filter"})})})})]})}function oet(){const e=X(r=>r.dashboard.filters),t=X(r=>r.theme),n=e==null?void 0:e.filter(r=>r.hide);return n!=null&&n.length?c.jsx("div",{className:Z("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)]":t==="light","bg-[repeating-linear-gradient(45deg,_#18171d_0_3px,_#272729_3px_6px)]":t==="dark"}),children:n==null?void 0:n.map(r=>c.jsxs("div",{className:"flex min-w-[250px] max-w-fit flex-col gap-1 p-2",children:[c.jsx(jI,{filter:r}),c.jsx(rp,{filter:r})]},r.id))}):null}function iet(){const e=X(r=>r.showFilters),t=X(r=>r.isVisualEditing),n=X(r=>r.isDashboardEditing);return c.jsxs("div",{role:"dashboard-plus-main",className:Z("",{"max-h-0 overflow-hidden":t,"flex grow overflow-hidden":!t}),children:[c.jsxs("section",{className:"flex grow flex-col overflow-y-auto",children:[n&&c.jsx(oet,{}),c.jsx(Yee,{})]}),e&&c.jsx("div",{role:"filter-aside-container",className:"flex overflow-hidden",children:c.jsx(set,{})})]})}const aet=C.lazy(()=>Promise.resolve().then(()=>require("./dashboard-controls-BF1ISsg_.js"))),cet=C.lazy(()=>Promise.resolve().then(()=>require("./edit-dashboard-visual-DPKlhiyI.js"))),uet=C.lazy(()=>Promise.resolve().then(()=>require("./dashboard-json-CMYMYz8t.js"))),det=C.lazy(()=>Promise.resolve().then(()=>require("./resource-management-panel-CnlQHXZ9.js")).then(e=>({default:e.ResourceManagementPanel})));function fet({showControls:e=!1,showFooter:t=!0,...n}){const r=X(l=>l.isDashboardPanelOpen),s=X(l=>l.isVisualEditing),o=X(l=>l.showDashboardJSON),i=X(l=>l.actions.setIsDashboardPanelOpen),{preferences:a}=n;return c.jsx(Ua,{FallbackComponent:eC,children:c.jsxs(jD,{dashboardProps:n,children:[c.jsx(mhe,{}),c.jsx(wA,{componentType:"surfboard",componentId:n.id}),c.jsx(vA,{children:c.jsxs(Gee,{preferences:a,children:[o&&c.jsx(C.Suspense,{fallback:null,children:c.jsx(uet,{})}),c.jsxs("main",{className:"relative flex h-full w-full flex-col overflow-hidden",children:[e&&c.jsx(C.Suspense,{fallback:null,children:c.jsx(aet,{})}),c.jsxs("div",{className:"flex grow overflow-hidden",children:[r&&c.jsx(C.Suspense,{fallback:null,children:c.jsx(det,{isOpen:r,onClose:()=>i(!1),variant:"inline"})}),c.jsx("div",{className:"flex min-w-0 flex-1",children:c.jsxs(VT,{...n,type:"dashboard",children:[s&&c.jsx(C.Suspense,{fallback:null,children:c.jsx(cet,{})}),c.jsx(iet,{})]})})]})]})]})})]})})}var het=Object.defineProperty,met=(e,t,n)=>t in e?het(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,q0=(e,t,n)=>met(e,typeof t!="symbol"?t+"":t,n);const pet={stringify:e=>e?"true":"false",parse:e=>/^[ty1-9]/i.test(e)},get={stringify:e=>e.name,parse:(e,t,n)=>{const r=(()=>{if(typeof window<"u"&&e in window)return window[e];if(typeof global<"u"&&e in global)return global[e]})();return typeof r=="function"?r.bind(n):void 0}},bet={stringify:e=>JSON.stringify(e),parse:e=>JSON.parse(e)};function xet(e){return e.replace(/([a-z0-9])([A-Z])/g,(t,n,r)=>`${n}-${r.toLowerCase()}`)}function wte(e){return e.replace(/[-:]([a-z])/g,(t,n)=>`${n.toUpperCase()}`)}const yet={stringify:e=>e.name,parse:(e,t,n)=>{const r=(()=>{const s=wte(t);if(typeof n<"u"&&s in n.container)return n.container[s]})();return typeof r=="function"?r.bind(n):void 0}},vet={stringify:e=>`${e}`,parse:e=>parseFloat(e)},wet={stringify:e=>e,parse:e=>e},I2={string:wet,number:vet,boolean:pet,function:get,method:yet,json:bet},$p=Symbol.for("r2wc.render"),Y0=Symbol.for("r2wc.connected"),Tu=Symbol.for("r2wc.context"),fo=Symbol.for("r2wc.props");function Cet(e,t,n){var r,s,o;t.props||(t.props=e.propTypes?Object.keys(e.propTypes):[]),t.events||(t.events=[]);const i=Array.isArray(t.props)?t.props.slice():Object.keys(t.props),a=Array.isArray(t.events)?t.events.slice():Object.keys(t.events),l={},u={},d={},f={};for(const m of i){l[m]=Array.isArray(t.props)?"string":t.props[m];const p=xet(m);d[m]=p,f[p]=m}for(const m of a)u[m]=Array.isArray(t.events)?{}:t.events[m];class h extends HTMLElement{constructor(){super(),q0(this,o,!0),q0(this,s),q0(this,r,{}),q0(this,"container"),t.shadow?this.container=this.attachShadow({mode:t.shadow}):this.container=this,this[fo].container=this.container;for(const p of i){const g=d[p],b=this.getAttribute(g),x=l[p],y=x?I2[x]:null;if(x==="method"){const v=wte(g);Object.defineProperty(this[fo].container,v,{enumerable:!0,configurable:!0,get(){return this[fo][v]},set(w){this[fo][v]=w,this[$p]()}}),this[fo][p]=y.parse(b,g,this)}y!=null&&y.parse&&b&&(this[fo][p]=y.parse(b,g,this))}for(const p of a)this[fo][p]=g=>{const b=p.replace(/^on/,"").toLowerCase();this.dispatchEvent(new CustomEvent(b,{detail:g,...u[p]}))}}static get observedAttributes(){return Object.keys(f)}connectedCallback(){this[Y0]=!0,this[$p]()}disconnectedCallback(){this[Y0]=!1,this[Tu]&&n.unmount(this[Tu]),delete this[Tu]}attributeChangedCallback(p,g,b){const x=f[p],y=l[x],v=y?I2[y]:null;x in l&&v!=null&&v.parse&&b&&(this[fo][x]=v.parse(b,p,this),this[$p]())}[(o=Y0,s=Tu,r=fo,$p)](){this[Y0]&&(this[Tu]?n.update(this[Tu],this[fo]):this[Tu]=n.mount(this.container,e,this[fo]))}}for(const m of i){const p=d[m],g=l[m];Object.defineProperty(h.prototype,m,{enumerable:!0,configurable:!0,get(){return this[fo][m]},set(b){this[fo][m]=b;const x=g?I2[g]:null;if(x!=null&&x.stringify){const y=x.stringify(b,p,this);this.getAttribute(p)!==y&&this.setAttribute(p,y)}else this[$p]()}})}return h}function Net(e,t,n){const r=Vne.createRoot(e),s=C.createElement(t,n);return r.render(s),{root:r,ReactComponent:t}}function jet({root:e,ReactComponent:t},n){const r=C.createElement(t,n);e.render(r)}function ket({root:e}){e.unmount()}function Eet(e,t={}){return Cet(e,t,{mount:Net,update:jet,unmount:ket})}const _et={id:"string",version:"string",authToken:"json",placeholders:"json",defaultFilterValues:"json",currentTheme:"string",customCards:"json",customStyle:"json",onChartElementClicked:"function",onFilterValuesChange:"function",onEvent:"function",onSave:"function",LoadingComponent:"function",ErrorComponent:"function",showAssistant:"boolean",selectedSheetId:"string",eventHandlers:"json",preferences:"json"},Det=Eet(Kee,{props:_et});function C6(e,t){(t==null||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n<t;n++)r[n]=e[n];return r}function Met(e){if(Array.isArray(e))return e}function Tet(e,t,n){return(t=$et(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function Ret(e,t){var n=e==null?null:typeof Symbol<"u"&&e[Symbol.iterator]||e["@@iterator"];if(n!=null){var r,s,o,i,a=[],l=!0,u=!1;try{if(o=(n=n.call(e)).next,t!==0)for(;!(l=(r=o.call(n)).done)&&(a.push(r.value),a.length!==t);l=!0);}catch(d){u=!0,s=d}finally{try{if(!l&&n.return!=null&&(i=n.return(),Object(i)!==i))return}finally{if(u)throw s}}return a}}function Iet(){throw new TypeError(`Invalid attempt to destructure non-iterable instance.
1099
1099
  In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}function N6(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter(function(s){return Object.getOwnPropertyDescriptor(e,s).enumerable})),n.push.apply(n,r)}return n}function j6(e){for(var t=1;t<arguments.length;t++){var n=arguments[t]!=null?arguments[t]:{};t%2?N6(Object(n),!0).forEach(function(r){Tet(e,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):N6(Object(n)).forEach(function(r){Object.defineProperty(e,r,Object.getOwnPropertyDescriptor(n,r))})}return e}function Aet(e,t){if(e==null)return{};var n,r,s=Pet(e,t);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);for(r=0;r<o.length;r++)n=o[r],t.indexOf(n)===-1&&{}.propertyIsEnumerable.call(e,n)&&(s[n]=e[n])}return s}function Pet(e,t){if(e==null)return{};var n={};for(var r in e)if({}.hasOwnProperty.call(e,r)){if(t.indexOf(r)!==-1)continue;n[r]=e[r]}return n}function Oet(e,t){return Met(e)||Ret(e,t)||Let(e,t)||Iet()}function Fet(e,t){if(typeof e!="object"||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t);if(typeof r!="object")return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return(t==="string"?String:Number)(e)}function $et(e){var t=Fet(e,"string");return typeof t=="symbol"?t:t+""}function Let(e,t){if(e){if(typeof e=="string")return C6(e,t);var n={}.toString.call(e).slice(8,-1);return n==="Object"&&e.constructor&&(n=e.constructor.name),n==="Map"||n==="Set"?Array.from(e):n==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?C6(e,t):void 0}}function zet(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function k6(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter(function(s){return Object.getOwnPropertyDescriptor(e,s).enumerable})),n.push.apply(n,r)}return n}function E6(e){for(var t=1;t<arguments.length;t++){var n=arguments[t]!=null?arguments[t]:{};t%2?k6(Object(n),!0).forEach(function(r){zet(e,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):k6(Object(n)).forEach(function(r){Object.defineProperty(e,r,Object.getOwnPropertyDescriptor(n,r))})}return e}function Bet(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];return function(r){return t.reduceRight(function(s,o){return o(s)},r)}}function dg(e){return function t(){for(var n=this,r=arguments.length,s=new Array(r),o=0;o<r;o++)s[o]=arguments[o];return s.length>=e.length?e.apply(this,s):function(){for(var i=arguments.length,a=new Array(i),l=0;l<i;l++)a[l]=arguments[l];return t.apply(n,[].concat(s,a))}}}function d1(e){return{}.toString.call(e).includes("Object")}function Vet(e){return!Object.keys(e).length}function zb(e){return typeof e=="function"}function Het(e,t){return Object.prototype.hasOwnProperty.call(e,t)}function Uet(e,t){return d1(t)||Oc("changeType"),Object.keys(t).some(function(n){return!Het(e,n)})&&Oc("changeField"),t}function Wet(e){zb(e)||Oc("selectorType")}function qet(e){zb(e)||d1(e)||Oc("handlerType"),d1(e)&&Object.values(e).some(function(t){return!zb(t)})&&Oc("handlersType")}function Yet(e){e||Oc("initialIsRequired"),d1(e)||Oc("initialType"),Vet(e)&&Oc("initialContent")}function Get(e,t){throw new Error(e[t]||e.default)}var Ket={initialIsRequired:"initial state is required",initialType:"initial state should be an object",initialContent:"initial state shouldn't be an empty object",handlerType:"handler should be an object or a function",handlersType:"all handlers should be a functions",selectorType:"selector should be a function",changeType:"provided value of changes should be an object",changeField:'it seams you want to change a field in the state which is not specified in the "initial" state',default:"an unknown error accured in `state-local` package"},Oc=dg(Get)(Ket),G0={changes:Uet,selector:Wet,handler:qet,initial:Yet};function Zet(e){var t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};G0.initial(e),G0.handler(t);var n={current:e},r=dg(Jet)(n,t),s=dg(Qet)(n),o=dg(G0.changes)(e),i=dg(Xet)(n);function a(){var u=arguments.length>0&&arguments[0]!==void 0?arguments[0]:function(d){return d};return G0.selector(u),u(n.current)}function l(u){Bet(r,s,o,i)(u)}return[a,l]}function Xet(e,t){return zb(t)?t(e.current):t}function Qet(e,t){return e.current=E6(E6({},e.current),t),t}function Jet(e,t,n){return zb(t)?t(e.current):Object.keys(n).forEach(function(r){var s;return(s=t[r])===null||s===void 0?void 0:s.call(t,e.current[r])}),n}var ett={create:Zet},ttt={paths:{vs:"https://cdn.jsdelivr.net/npm/monaco-editor@0.55.1/min/vs"}};function ntt(e){return function t(){for(var n=this,r=arguments.length,s=new Array(r),o=0;o<r;o++)s[o]=arguments[o];return s.length>=e.length?e.apply(this,s):function(){for(var i=arguments.length,a=new Array(i),l=0;l<i;l++)a[l]=arguments[l];return t.apply(n,[].concat(s,a))}}}function rtt(e){return{}.toString.call(e).includes("Object")}function stt(e){return e||_6("configIsRequired"),rtt(e)||_6("configType"),e.urls?(ott(),{paths:{vs:e.urls.monacoBase}}):e}function ott(){console.warn(Ste.deprecation)}function itt(e,t){throw new Error(e[t]||e.default)}var Ste={configIsRequired:"the configuration object is required",configType:"the configuration object should be an object",default:"an unknown error accured in `@monaco-editor/loader` package",deprecation:`Deprecation warning!
1100
1100
  You are using deprecated way of configuration.
1101
1101