import{s as e}from"./chunk-Bj-mKKzh.js";import{n as t,t as n}from"./jsx-runtime-CiQ1k8xo.js";import{t as r}from"./clsx-BcPLHiun.js";import{t as i}from"./react-dom-CvzHKZGB.js";import{lt as a}from"./vscode-api-DjORcpSo.js";var o=a(),s=e(t(),1),c=e(i(),1),l=n(),u=360,d=12,f=8;function p(e){let t=(0,o.c)(29),{anchorRef:n,composerController:i,isActive:a,mentionUiState:u,placement:d,portalRoot:f,zIndexClassName:p,children:g}=e,_=f===void 0?`dialog`:f,v=p===void 0?`z-[60]`:p,y;t[0]===a?y=t[1]:(y=e=>!a||typeof window>`u`?m:(window.addEventListener(`resize`,e),window.addEventListener(`scroll`,e,!0),()=>{window.removeEventListener(`resize`,e),window.removeEventListener(`scroll`,e,!0)}),t[0]=a,t[1]=y);let b=y,x;t[2]!==n||t[3]!==i||t[4]!==u||t[5]!==d||t[6]!==_?(x=()=>{let e=h({anchorRef:n,composerController:i,mentionUiState:u,placement:d,portalRoot:_});return e==null?null:`${e.fixedPosition}:${e.left}:${e.top}:${e.width}:${d}`},t[2]=n,t[3]=i,t[4]=u,t[5]=d,t[6]=_,t[7]=x):x=t[7];let S=(0,s.useSyncExternalStore)(b,x),C;bb0:{if(S==null){C=null;break bb0}let e;t[8]!==n||t[9]!==i||t[10]!==u||t[11]!==d||t[12]!==_?(e=h({anchorRef:n,composerController:i,mentionUiState:u,placement:d,portalRoot:_}),t[8]=n,t[9]=i,t[10]=u,t[11]=d,t[12]=_,t[13]=e):e=t[13],C=e}let w=C;if(!a||w==null)return null;let T=w.fixedPosition?`fixed`:`absolute`,E=w.renderAbove&&`-translate-y-full`,D;t[14]!==T||t[15]!==E||t[16]!==v?(D=r(v,T,E),t[14]=T,t[15]=E,t[16]=v,t[17]=D):D=t[17];let O;t[18]!==w.left||t[19]!==w.top||t[20]!==w.width?(O={left:w.left,top:w.top,width:w.width},t[18]=w.left,t[19]=w.top,t[20]=w.width,t[21]=O):O=t[21];let k;t[22]!==g||t[23]!==D||t[24]!==O?(k=(0,l.jsx)(`div`,{className:D,style:O,children:g}),t[22]=g,t[23]=D,t[24]=O,t[25]=k):k=t[25];let A;return t[26]!==w.portalContainer||t[27]!==k?(A=(0,c.createPortal)(k,w.portalContainer),t[26]=w.portalContainer,t[27]=k,t[28]=A):A=t[28],A}function m(){}function h({anchorRef:e,composerController:t,mentionUiState:n,placement:r,portalRoot:i}){if(typeof document>`u`)return null;let a=g({composerController:t,mentionUiState:n,placement:r,portalRoot:i});if(a!=null)return a;let o=e.current;if(o==null)return null;let s=_({anchorElement:o,portalRoot:i}),c=o.getBoundingClientRect(),l=s===document.body?{left:0,top:0}:s.getBoundingClientRect();return{portalContainer:s,left:c.left-l.left,top:(r===`top`?c.top-8:c.bottom+8)-l.top,width:c.width,fixedPosition:s===document.body,renderAbove:r===`top`}}function g({composerController:e,mentionUiState:t,placement:n,portalRoot:r}){let i=t?.anchorPos;if(e==null||i==null)return null;let a=e.view.dom,o=_({anchorElement:a,portalRoot:r}),s=o===document.body?{left:0,top:0,width:window.innerWidth}:o.getBoundingClientRect(),c=e.view.coordsAtPos(i),l=Math.max(s.width-d*2,0),p=Math.min(u,l);return{portalContainer:o,left:v(c.left-s.left,d,s.width-p-d),top:(n===`top`?c.top-f:c.bottom+f)-s.top,width:p,fixedPosition:o===document.body,renderAbove:n===`top`}}function _({anchorElement:e,portalRoot:t}){return t===`body`?document.body:e.closest(`.codex-dialog`)??document.body}function v(e,t,n){return n<t?t:Math.min(Math.max(e,t),n)}export{p as t};
//# sourceMappingURL=anchored-autocomplete-overlay-BGVmgt5z.js.map