import{r as s,j as t,a as b}from"./sikshya-admin-sikshya-react-E_TY_un4.js";import{N as v}from"./sikshya-admin.js";function w(a){return"href"in a}function E({items:a,ariaLabel:h}){const[n,l]=s.useState(!1),[u,f]=s.useState(null),d=s.useRef(null),m=s.useRef(null);if(s.useLayoutEffect(()=>{if(!n||!d.current){f(null);return}const e=()=>{const r=d.current;if(!r)return;const o=r.getBoundingClientRect();f({top:o.bottom+4,right:window.innerWidth-o.right})};e();const i=window.requestAnimationFrame(e);return window.addEventListener("resize",e),window.addEventListener("scroll",e,!0),()=>{window.cancelAnimationFrame(i),window.removeEventListener("resize",e),window.removeEventListener("scroll",e,!0)}},[n,a.length]),s.useEffect(()=>{if(!n)return;const e=r=>{var c,p;const o=r.target;o instanceof Node&&((c=d.current)!=null&&c.contains(o)||(p=m.current)!=null&&p.contains(o)||l(!1))},i=r=>{r.key==="Escape"&&l(!1)};return document.addEventListener("mousedown",e),document.addEventListener("touchstart",e,{passive:!0}),document.addEventListener("keydown",i),()=>{document.removeEventListener("mousedown",e),document.removeEventListener("touchstart",e),document.removeEventListener("keydown",i)}},[n]),a.length===0)return null;const x=n&&u?t.jsx("div",{ref:m,role:"menu",style:{position:"fixed",top:u.top,right:u.right,zIndex:100050},className:"min-w-[12rem] rounded-xl border border-slate-200 bg-white py-1 shadow-lg ring-1 ring-black/5 dark:border-slate-700 dark:bg-slate-900 dark:ring-white/10",children:a.map(e=>w(e)?t.jsx("a",{role:"menuitem",href:e.href,...e.external?{target:"_blank",rel:"noopener noreferrer"}:{},className:"block px-3 py-2 text-sm text-slate-700 no-underline hover:bg-slate-50 dark:text-slate-200 dark:hover:bg-slate-800",onClick:()=>l(!1),children:e.label},e.key):t.jsx("button",{type:"button",role:"menuitem",disabled:!!e.disabled,className:`block w-full px-3 py-2 text-left text-sm ${e.disabled?"cursor-not-allowed text-slate-400 dark:text-slate-500":`hover:bg-slate-50 dark:hover:bg-slate-800 ${e.danger?"text-red-600 dark:text-red-400":"text-slate-700 dark:text-slate-200"}`}`,onClick:()=>{e.disabled||(l(!1),e.onClick())},children:e.label},e.key))}):null;return t.jsxs(t.Fragment,{children:[t.jsx("div",{ref:d,className:"relative inline-block text-left",children:t.jsx("button",{type:"button","aria-expanded":n,"aria-haspopup":"menu","aria-label":h,onClick:()=>l(e=>!e),className:"inline-flex rounded-md p-1 text-slate-400 hover:bg-slate-200/70 hover:text-slate-700 dark:hover:bg-slate-700/60 dark:hover:text-slate-200",children:t.jsx(v,{name:"dotsVertical",className:"h-4 w-4"})})}),typeof document<"u"&&x?b.createPortal(x,document.body):null]})}export{E as R};
