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