import*as e from"react";import{composeEventHandlers as o}from"../../primitive/dist/index.js";import{useComposedRefs as r}from"../../react-compose-refs/dist/index.js";import{createContextScope as t}from"../../react-context/dist/index.js";import{DismissableLayer as n}from"../../react-dismissable-layer/dist/index.js";import{useFocusGuards as i}from"../../react-focus-guards/dist/index.js";import{FocusScope as s}from"../../react-focus-scope/dist/index.js";import{createPopperScope as a,Anchor as c,Content as p,Arrow as d}from"../../react-popper/dist/index.js";import{Portal as u}from"../../react-portal/dist/index.js";import{Presence as l}from"../../react-presence/dist/index.js";import{Primitive as f}from"../../react-primitive/dist/index.js";import{Slot as v}from"../../react-slot/dist/index.js";import{hideOthers as m}from"../../../aria-hidden/dist/es2015/index.js";import h from"../../../react-remove-scroll/dist/es2015/Combination.js";import{jsx as P}from"react/jsx-runtime";var g="Popover",[x,C]=t(g,[a]),w=a(),[O,_]=x(g),F="PopoverAnchor",R=e.forwardRef(((o,r)=>{const{__scopePopover:t,...n}=o,i=_(F,t),s=w(t),{onCustomAnchorAdd:a,onCustomAnchorRemove:p}=i;return e.useEffect((()=>(a(),()=>p())),[a,p]),P(c,{...s,...n,ref:r})}));R.displayName=F;var b="PopoverTrigger",y=e.forwardRef(((e,t)=>{const{__scopePopover:n,...i}=e,s=_(b,n),a=w(n),p=r(t,s.triggerRef),d=P(f.button,{type:"button","aria-haspopup":"dialog","aria-expanded":s.open,"aria-controls":s.contentId,"data-state":q(s.open),...i,ref:p,onClick:o(e.onClick,s.onOpenToggle)});return s.hasCustomAnchor?d:P(c,{asChild:!0,...a,children:d})}));y.displayName=b;var j="PopoverPortal",[A,D]=x(j,{forceMount:void 0}),E=e=>{const{__scopePopover:o,forceMount:r,children:t,container:n}=e,i=_(j,o);return P(A,{scope:o,forceMount:r,children:P(l,{present:r||i.open,children:P(u,{asChild:!0,container:n,children:t})})})};E.displayName=j;var k="PopoverContent",I=e.forwardRef(((e,o)=>{const r=D(k,e.__scopePopover),{forceMount:t=r.forceMount,...n}=e,i=_(k,e.__scopePopover);return P(l,{present:t||i.open,children:i.modal?P(M,{...n,ref:o}):P(N,{...n,ref:o})})}));I.displayName=k;var M=e.forwardRef(((t,n)=>{const i=_(k,t.__scopePopover),s=e.useRef(null),a=r(n,s),c=e.useRef(!1);return e.useEffect((()=>{const e=s.current;if(e)return m(e)}),[]),P(h,{as:v,allowPinchZoom:!0,children:P(K,{...t,ref:a,trapFocus:i.open,disableOutsidePointerEvents:!0,onCloseAutoFocus:o(t.onCloseAutoFocus,(e=>{e.preventDefault(),c.current||i.triggerRef.current?.focus()})),onPointerDownOutside:o(t.onPointerDownOutside,(e=>{const o=e.detail.originalEvent,r=0===o.button&&!0===o.ctrlKey,t=2===o.button||r;c.current=t}),{checkForDefaultPrevented:!1}),onFocusOutside:o(t.onFocusOutside,(e=>e.preventDefault()),{checkForDefaultPrevented:!1})})})})),N=e.forwardRef(((o,r)=>{const t=_(k,o.__scopePopover),n=e.useRef(!1),i=e.useRef(!1);return P(K,{...o,ref:r,trapFocus:!1,disableOutsidePointerEvents:!1,onCloseAutoFocus:e=>{o.onCloseAutoFocus?.(e),e.defaultPrevented||(n.current||t.triggerRef.current?.focus(),e.preventDefault()),n.current=!1,i.current=!1},onInteractOutside:e=>{o.onInteractOutside?.(e),e.defaultPrevented||(n.current=!0,"pointerdown"===e.detail.originalEvent.type&&(i.current=!0));const r=e.target,s=t.triggerRef.current?.contains(r);s&&e.preventDefault(),"focusin"===e.detail.originalEvent.type&&i.current&&e.preventDefault()}})})),K=e.forwardRef(((e,o)=>{const{__scopePopover:r,trapFocus:t,onOpenAutoFocus:a,onCloseAutoFocus:c,disableOutsidePointerEvents:d,onEscapeKeyDown:u,onPointerDownOutside:l,onFocusOutside:f,onInteractOutside:v,...m}=e,h=_(k,r),g=w(r);return i(),P(s,{asChild:!0,loop:!0,trapped:t,onMountAutoFocus:a,onUnmountAutoFocus:c,children:P(n,{asChild:!0,disableOutsidePointerEvents:d,onInteractOutside:v,onEscapeKeyDown:u,onPointerDownOutside:l,onFocusOutside:f,onDismiss:()=>h.onOpenChange(!1),children:P(p,{"data-state":q(h.open),role:"dialog",id:h.contentId,...g,...m,ref:o,style:{...m.style,"--radix-popover-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-popover-content-available-width":"var(--radix-popper-available-width)","--radix-popover-content-available-height":"var(--radix-popper-available-height)","--radix-popover-trigger-width":"var(--radix-popper-anchor-width)","--radix-popover-trigger-height":"var(--radix-popper-anchor-height)"}})})})})),T="PopoverClose",U=e.forwardRef(((e,r)=>{const{__scopePopover:t,...n}=e,i=_(T,t);return P(f.button,{type:"button",...n,ref:r,onClick:o(e.onClick,(()=>i.onOpenChange(!1)))})}));U.displayName=T;var Z=e.forwardRef(((e,o)=>{const{__scopePopover:r,...t}=e,n=w(r);return P(d,{...n,...t,ref:o})}));function q(e){return e?"open":"closed"}Z.displayName="PopoverArrow";var z=y,B=E,G=I;export{G as Content,R as PopoverAnchor,Z as PopoverArrow,U as PopoverClose,I as PopoverContent,E as PopoverPortal,y as PopoverTrigger,B as Portal,z as Trigger,C as createPopoverScope};
//# sourceMappingURL=index.js.map
