import{d as ce,Y as d,b as q,Z as ve,$ as fe,ae as de,o as i,c as h,a as me,r as w,g as O,h as he,w as W,e as E,b6 as pe,F as Q,p as ge,l as ye,N as we,i as $,t as C,j as be,bv as ke,aK as Me,aw as Z,Q as _e}from"./C6MRUCyE.js";import{e as G,o as Re}from"./CKE40ChC.js";const Ee={"data-pyro-telepopover-wrapper":"",class:"relative"},$e=["aria-expanded"],Ce={key:0,class:"h-px w-full bg-button-bg"},Le=["aria-selected","onClick","onFocus","onMouseover"],Be=["href","aria-selected","onClick","onFocus","onMouseover"],De={key:3},We=ce({__name:"TeleportOverflowMenu",props:{options:{},hoverable:{type:Boolean,default:!1}},emits:["select"],setup(J,{emit:ee}){function b(e){return e.divider}const k=J,te=ee,v=d(!1),a=d(-1),f=d(null),m=d(null),z=d(!1),L=d(""),p=d(null),r=d([]),oe=G(m),ae=G(f),le=q(()=>oe.value||ae.value),B=d({top:"0px",left:"0px"}),c=q(()=>k.options.filter(e=>e.shown!==!1)),I=()=>{if(!m.value||!f.value)return{top:"0px",left:"0px"};const e=m.value.getBoundingClientRect(),n=f.value.getBoundingClientRect(),s=n.width,o=n.height,t=8;let l,u;return e.bottom+o+t<=window.innerHeight?l=e.bottom+t:e.top-o-t>=0?l=e.top-o-t:l=Math.max(t,window.innerHeight-o-t),e.left+s+t<=window.innerWidth?u=e.left:e.right-s-t>=0?u=e.right-s:u=Math.max(t,window.innerWidth-s-t),{top:`${l}px`,left:`${u}px`}},ne=e=>{e.stopPropagation(),k.hoverable||(v.value?g():D())},D=()=>{v.value=!0,ue(),Z(()=>{B.value=I(),document.addEventListener("mousemove",T),ie()})},g=()=>{v.value=!1,a.value=-1,A(),document.removeEventListener("mousemove",T)},x=e=>{te("select",e),typeof e.action=="function"&&e.action(),g()},se=e=>{e.preventDefault(),z.value=!0},re=()=>{k.hoverable&&D()},H=()=>{k.hoverable&&setTimeout(()=>{le.value||g()},250)},T=e=>{var o,t;if(!v.value||!z.value||!((o=f.value)==null?void 0:o.getBoundingClientRect()))return;const s=(t=f.value)==null?void 0:t.querySelectorAll('[role="menuitem"]');if(s)for(let l=0;l=u.left&&e.clientX<=u.right&&e.clientY>=u.top&&e.clientY<=u.bottom){a.value=l;break}}},S=(e,n)=>{a.value=n,x(e)},F=e=>{var n,s;a.value=e,(s=(n=r.value[a.value]).focus)==null||s.call(n)},ue=()=>{const e=window.innerWidth-document.documentElement.clientWidth;e>0?document.body.style.paddingRight=`${e}px`:document.body.style.paddingRight="",document.body.style.overflow="hidden"},A=()=>{document.body.style.paddingRight="",document.body.style.overflow=""},ie=()=>{var e,n;r.value.length>0&&((n=(e=r.value[0]).focus)==null||n.call(e))},M=e=>{var n,s,o,t,l,u,N,j,R,V,K,Y,P,U;if(!v.value){(e.key==="Enter"||e.key===" ")&&(e.preventDefault(),D());return}switch(e.key){case"ArrowDown":e.preventDefault(),a.value=(a.value+1)%c.value.length,(s=(n=r.value[a.value]).focus)==null||s.call(n);break;case"ArrowUp":e.preventDefault(),a.value=(a.value-1+c.value.length)%c.value.length,(t=(o=r.value[a.value]).focus)==null||t.call(o);break;case"Home":e.preventDefault(),r.value.length>0&&(a.value=0,(u=(l=r.value[a.value]).focus)==null||u.call(l));break;case"End":e.preventDefault(),r.value.length>0&&(a.value=c.value.length-1,(j=(N=r.value[a.value]).focus)==null||j.call(N));break;case"Enter":case" ":if(e.preventDefault(),a.value>=0){const y=c.value[a.value];if(b(y))break;x(y)}break;case"Escape":e.preventDefault(),g(),(V=(R=m.value)==null?void 0:R.focus)==null||V.call(R);break;case"Tab":e.preventDefault(),r.value.length>0&&(e.shiftKey?a.value=(a.value-1+c.value.length)%c.value.length:a.value=(a.value+1)%c.value.length,(Y=(K=r.value[a.value]).focus)==null||Y.call(K));break;default:if(e.key.length===1){L.value+=e.key.toLowerCase();const y=c.value.findIndex(X=>!b(X)&&X.id.toLowerCase().startsWith(L.value));y!==-1&&(a.value=y,(U=(P=r.value[a.value]).focus)==null||U.call(P)),p.value&&clearTimeout(p.value),p.value=setTimeout(()=>{L.value=""},1e3)}break}},_=((e,n)=>{let s;return function(...o){s||(e(...o),s=!0,setTimeout(()=>s=!1,n))}})(()=>{v.value&&(B.value=I())},100);return ve(()=>{var e;(e=m.value)==null||e.addEventListener("keydown",M),window.addEventListener("resize",_),window.addEventListener("scroll",_)}),fe(()=>{var e;(e=m.value)==null||e.removeEventListener("keydown",M),window.removeEventListener("resize",_),window.removeEventListener("scroll",_),document.removeEventListener("mousemove",T),p.value&&clearTimeout(p.value),A()}),de(v,e=>{var n;e?Z(()=>{var s;(s=f.value)==null||s.addEventListener("keydown",M)}):(n=f.value)==null||n.removeEventListener("keydown",M)}),Re(f,e=>{var n;(n=m.value)!=null&&n.contains(e.target)||g()}),(e,n)=>{const s=_e;return i(),h("div",Ee,[me("button",{ref_key:"triggerRef",ref:m,class:"teleport-overflow-menu-trigger","aria-expanded":v.value,"aria-haspopup":!0,onMousedown:se,onMouseenter:re,onMouseleave:H,onClick:ne},[w(e.$slots,"default")],40,$e),(i(),O(Me,{to:"#teleports"},[he(ke,{"enter-active-class":"transition duration-125 ease-out","enter-from-class":"transform scale-75 opacity-0","enter-to-class":"transform scale-100 opacity-100","leave-active-class":"transition duration-125 ease-in","leave-from-class":"transform scale-100 opacity-100","leave-to-class":"transform scale-75 opacity-0"},{default:W(()=>[v.value?(i(),h("div",{key:0,ref_key:"menuRef",ref:f,"data-pyro-telepopover-root":"",class:"experimental-styles-within fixed isolate z-[9999] flex w-fit flex-col gap-2 overflow-hidden rounded-2xl border-[1px] border-solid border-divider bg-bg-raised p-2 shadow-lg",style:E(B.value),role:"menu",tabindex:"-1",onMousedown:n[0]||(n[0]=pe(()=>{},["stop"])),onMouseleave:H},[(i(!0),h(Q,null,ge(c.value,(o,t)=>(i(),h(Q,{key:b(o)?`divider-${t}`:o.id},[b(o)?(i(),h("div",Ce)):(i(),O(ye(we),{key:1,type:"transparent",role:"menuitem",color:o.color},{default:W(()=>[typeof o.action=="function"?(i(),h("button",{key:0,ref_for:!0,ref:l=>{l&&(r.value[t]=l)},class:"w-full !justify-start !whitespace-nowrap focus-visible:!outline-none","aria-selected":t===a.value,style:E(t===a.value?{background:"var(--color-button-bg)"}:{}),onClick:l=>S(o,t),onFocus:l=>a.value=t,onMouseover:l=>F(t)},[w(e.$slots,o.id,{},()=>[$(C(o.id),1)])],44,Le)):typeof o.action=="string"&&o.action.startsWith("/")?(i(),O(s,{key:1,ref_for:!0,ref:l=>{l&&(r.value[t]=l)},to:o.action,class:"w-full !justify-start !whitespace-nowrap focus-visible:!outline-none","aria-selected":t===a.value,style:E(t===a.value?{background:"var(--color-button-bg)"}:{}),onClick:l=>S(o,t),onFocus:l=>a.value=t,onMouseover:l=>F(t)},{default:W(()=>[w(e.$slots,o.id,{},()=>[$(C(o.id),1)])]),_:2},1032,["to","aria-selected","style","onClick","onFocus","onMouseover"])):typeof o.action=="string"&&!o.action.startsWith("http")?(i(),h("a",{key:2,ref_for:!0,ref:l=>{l&&(r.value[t]=l)},href:o.action,target:"_blank",class:"w-full !justify-start !whitespace-nowrap focus-visible:!outline-none","aria-selected":t===a.value,style:E(t===a.value?{background:"var(--color-button-bg)"}:{}),onClick:l=>S(o,t),onFocus:l=>a.value=t,onMouseover:l=>F(t)},[w(e.$slots,o.id,{},()=>[$(C(o.id),1)])],44,Be)):(i(),h("span",De,[w(e.$slots,o.id,{},()=>[$(C(o.id),1)])]))]),_:2},1032,["color"]))],64))),128))],36)):be("",!0)]),_:3})]))])}}});export{We as _};