import{jsx as o,Fragment as X,jsxs as C}from"react/jsx-runtime";import g from"./button.js";import"./checkbox.js";import"./dropdown-selector.js";import"./radio.js";import"./segmented-control.js";import"./switch.js";import"./text.js";import{useToggleState as oe}from"../../hooks/useToggleState.js";import{cx as te}from"@styled/css";import{Center as re,Box as Y}from"@styled/jsx";import{vstack as ne}from"@styled/patterns";import{token as ie}from"@styled/tokens";import{createSlot as v,createHost as le}from"create-slots";import{Children as ce,cloneElement as se,useMemo as pe,useRef as z,useCallback as A,useEffect as ae}from"react";import{useOverlayTrigger as de,usePopover as me,mergeProps as B,Overlay as ge}from"react-aria";const D="bottom left",H=8,ue="hover",E=v(({children:t})=>o(X,{children:t})),j=v(({children:t,...c})=>{const{onPress:i,...s}=c;return o(re,{children:ce.map(t,l=>se(l,s))})}),w=v(t=>o(g.LeadingIcon,{...t})),K=v(t=>o(g.TrailingIcon,{...t})),M=({children:t,...c})=>le(t,i=>{var s;const{isOpen:l,defaultOpen:W,onOpenChange:_,trigger:O=ue,iconSize:h,onPress:fe,...I}=c,{isSelected:q,setSelected:x}=oe({isOpen:l,defaultSelected:W,onChange:_,...c}),b=l!==void 0?l:q,r=24,n=pe(()=>({isOpen:b,open:()=>{x(!0)},close:()=>{x(!1)},setOpen(e){x(e)},toggle(){}}),[b]),S=i.getProps(E),p=z(null),{triggerProps:L,overlayProps:G}=de({type:"dialog"},n,p),a=z(null),{popoverProps:J,underlayProps:Z}=me({placement:c.placement||D,offset:H,popoverRef:a,triggerRef:p,...S},n),u=B(S,J);!((s=u?.style)===null||s===void 0)&&s.zIndex&&(u.style.zIndex=ie("zIndex.max"));const k=A(()=>{n.open()},[n]),y=A(e=>{var P,T;const d=(P=p.current)===null||P===void 0?void 0:P.getBoundingClientRect(),m=(T=a.current)===null||T===void 0?void 0:T.getBoundingClientRect();if(d&&m){const V=e.clientX>=d.left-r&&e.clientX<=d.right+r&&e.clientY>=d.top-r&&e.clientY<=d.bottom+r,ee=e.clientX>=m.left-r&&e.clientX<=m.right+r&&e.clientY>=m.top-r&&e.clientY<=m.bottom+r;!V&&!ee&&n.close()}},[n]),$=()=>{if(a.current){const e=a.current.querySelectorAll('a, button, input, select, textarea, [tabindex]:not([tabindex="-1"])');e.length>0&&e[0].focus()}},Q=e=>{e.key==="Enter"&&(e.preventDefault(),l?n.close():(n.open(),setTimeout($,0)))};ae(()=>(document.addEventListener("mousemove",y),()=>{document.removeEventListener("mousemove",y)}),[y]);const f=i.get(j),R=i.getProps(w),F=i.getProps(K),N=h?{height:h,width:h}:{};return C(X,{children:[f?o(Y,{display:"inline-block",ref:p,...I,children:f&&{...f,props:{...f.props,...L}}}):o(Y,{display:"inline-block",ref:p,children:C(g,{...B(L,I),onKeyDown:Q,onHover:()=>O==="hover"&&k(),onPress:()=>O==="click"&&k(),children:[R&&o(g.LeadingIcon,{...R,...N}),F&&o(g.TrailingIcon,{...F,...N})]})}),b&&C(ge,{...G,children:[o("div",{...Z,className:"underlay"}),o("div",{ref:a,...u,className:te(ne({bg:"surface.secondary",p:3,gap:0,color:"text.secondary",borderWidth:1,borderColor:"neutral.secondary",borderRadius:"xl",boxShadow:"0px 4px 20px 0px rgba(0, 0, 0, 0.10)",maxW:52,alignItems:"start"}),u.className),children:i.get(E)})]})]})}),U=Object.assign(M,{Trigger:j,LeadingIcon:w,TrailingIcon:K,Content:E});export{H as DEFAULT_OFFSET,D as DEFAULT_PLACEMENT,U as Popover,M as PopoverHost,U as default};
//# sourceMappingURL=popover.js.map
