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