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