import{bd as L,u as y,r as o,j as l}from"./index-gnHkq9KV.js";var C=L();function D({items:a,id:g}){const{t:h}=y(),[n,s]=o.useState(!1),[x,E]=o.useState(!1),[p,v]=o.useState({top:0,left:0,minWidth:150}),f=o.useRef(null),w=o.useRef(null),c=o.useCallback(()=>{const e=f.current;if(!e)return;const t=e.getBoundingClientRect(),r=Math.max(a.length*36+12,80),d=window.innerHeight-t.bottom,u=d<r&&t.top>d,i=Math.max(t.width,150),b=Math.max(8,Math.min(t.right-i,window.innerWidth-i-8)),M=u?Math.max(8,t.top-r-4):Math.min(window.innerHeight-r-8,t.bottom+4);E(u),v({top:M,left:b,minWidth:i})},[a.length]),k=o.useCallback(e=>{if(e.stopPropagation(),!n){c(),s(!0);return}s(!1)},[n,c]);return o.useLayoutEffect(()=>{n&&c()},[n,c]),o.useEffect(()=>{if(!n)return;const e=t=>{var m,i;const r=t.target,d=(m=f.current)==null?void 0:m.contains(r),u=(i=w.current)==null?void 0:i.contains(r);!d&&!u&&s(!1)};return document.addEventListener("click",e,!0),()=>document.removeEventListener("click",e,!0)},[n]),o.useEffect(()=>{if(!n)return;const e=t=>{t.key==="Escape"&&s(!1)};return document.addEventListener("keydown",e),()=>document.removeEventListener("keydown",e)},[n]),o.useEffect(()=>{if(!n)return;const e=()=>s(!1);return window.addEventListener("resize",e),window.addEventListener("scroll",e,!0),()=>{window.removeEventListener("resize",e),window.removeEventListener("scroll",e,!0)}},[n]),a.length===0?null:l.jsxs("div",{className:"action-menu-wrap",ref:f,"data-menu-id":g,children:[l.jsx("button",{className:"action-menu-btn",onClick:k,title:h("Actions"),children:"⋮"}),n&&C.createPortal(l.jsx("div",{ref:w,className:`action-menu-dropdown action-menu-dropdown-fixed${x?" drop-up":""}`,style:{top:`${p.top}px`,left:`${p.left}px`,minWidth:`${p.minWidth}px`},onClick:e=>e.stopPropagation(),onMouseDown:e=>e.stopPropagation(),children:a.map((e,t)=>l.jsx("button",{className:`action-menu-item${e.danger?" danger":""}`,disabled:e.disabled,onMouseDown:r=>r.stopPropagation(),onClick:r=>{r.stopPropagation(),s(!1),e.onClick()},children:h(e.label)},t))}),document.body)]})}export{D as A,C as r};
