import*as e from"react";import{useFloating as t,offset as r,shift as o,flip as i,size as a,arrow as n,hide as s,limitShift as d}from"../../../@floating-ui/react-dom/dist/floating-ui.react-dom.js";import{Root as l}from"../../react-arrow/dist/index.js";import{useComposedRefs as p}from"../../react-compose-refs/dist/index.js";import{createContextScope as c}from"../../react-context/dist/index.js";import{Primitive as f}from"../../react-primitive/dist/index.js";import{useCallbackRef as m}from"../../react-use-callback-ref/dist/index.js";import{useLayoutEffect as h}from"../../react-use-layout-effect/dist/index.js";import{useSize as g}from"../../react-use-size/dist/index.js";import{jsx as u}from"react/jsx-runtime";import{autoUpdate as x}from"../../../@floating-ui/react-dom/node_modules/@floating-ui/dom/dist/floating-ui.dom.js";var y="Popper",[w,v]=c(y),[b,P]=w(y),A=t=>{const{__scopePopper:r,children:o}=t,[i,a]=e.useState(null);return u(b,{scope:r,anchor:i,onAnchorChange:a,children:o})};A.displayName=y;var j="PopperAnchor",S=e.forwardRef(((t,r)=>{const{__scopePopper:o,virtualRef:i,...a}=t,n=P(j,o),s=e.useRef(null),d=p(r,s);return e.useEffect((()=>{n.onAnchorChange(i?.current||s.current)})),i?null:u(f.div,{...a,ref:d})}));S.displayName=j;var $="PopperContent",[_,O]=w($),C=e.forwardRef(((l,c)=>{const{__scopePopper:y,side:w="bottom",sideOffset:v=0,align:b="center",alignOffset:A=0,arrowPadding:j=0,avoidCollisions:S=!0,collisionBoundary:O=[],collisionPadding:C=0,sticky:H="partial",hideWhenDetached:R=!1,updatePositionStrategy:W="optimized",onPlaced:N,...X}=l,k=P($,y),[D,B]=e.useState(null),F=p(c,(e=>B(e))),[I,L]=e.useState(null),M=g(I),q=M?.width??0,G=M?.height??0,J=w+("center"!==b?"-"+b:""),K="number"==typeof C?C:{top:0,right:0,bottom:0,left:0,...C},Q=Array.isArray(O)?O:[O],T=Q.length>0,U={padding:K,boundary:Q.filter(Y),altBoundary:T},{refs:V,floatingStyles:Z,placement:ee,isPositioned:te,middlewareData:re}=t({strategy:"fixed",placement:J,whileElementsMounted:(...e)=>x(...e,{animationFrame:"always"===W}),elements:{reference:k.anchor},middleware:[r({mainAxis:v+G,alignmentAxis:A}),S&&o({mainAxis:!0,crossAxis:!1,limiter:"partial"===H?d():void 0,...U}),S&&i({...U}),a({...U,apply:({elements:e,rects:t,availableWidth:r,availableHeight:o})=>{const{width:i,height:a}=t.reference,n=e.floating.style;n.setProperty("--radix-popper-available-width",`${r}px`),n.setProperty("--radix-popper-available-height",`${o}px`),n.setProperty("--radix-popper-anchor-width",`${i}px`),n.setProperty("--radix-popper-anchor-height",`${a}px`)}}),I&&n({element:I,padding:j}),z({arrowWidth:q,arrowHeight:G}),R&&s({strategy:"referenceHidden",...U})]}),[oe,ie]=E(ee),ae=m(N);h((()=>{te&&ae?.()}),[te,ae]);const ne=re.arrow?.x,se=re.arrow?.y,de=0!==re.arrow?.centerOffset,[le,pe]=e.useState();return h((()=>{D&&pe(window.getComputedStyle(D).zIndex)}),[D]),u("div",{ref:V.setFloating,"data-radix-popper-content-wrapper":"",style:{...Z,transform:te?Z.transform:"translate(0, -200%)",minWidth:"max-content",zIndex:le,"--radix-popper-transform-origin":[re.transformOrigin?.x,re.transformOrigin?.y].join(" "),...re.hide?.referenceHidden&&{visibility:"hidden",pointerEvents:"none"}},dir:l.dir,children:u(_,{scope:y,placedSide:oe,onArrowChange:L,arrowX:ne,arrowY:se,shouldHideArrow:de,children:u(f.div,{"data-side":oe,"data-align":ie,...X,ref:F,style:{...X.style,animation:te?void 0:"none"}})})})}));C.displayName=$;var H="PopperArrow",R={top:"bottom",right:"left",bottom:"top",left:"right"},W=e.forwardRef((function(e,t){const{__scopePopper:r,...o}=e,i=O(H,r),a=R[i.placedSide];return u("span",{ref:i.onArrowChange,style:{position:"absolute",left:i.arrowX,top:i.arrowY,[a]:0,transformOrigin:{top:"",right:"0 0",bottom:"center 0",left:"100% 0"}[i.placedSide],transform:{top:"translateY(100%)",right:"translateY(50%) rotate(90deg) translateX(-50%)",bottom:"rotate(180deg)",left:"translateY(50%) rotate(-90deg) translateX(50%)"}[i.placedSide],visibility:i.shouldHideArrow?"hidden":void 0},children:u(l,{...o,ref:t,style:{...o.style,display:"block"}})})}));function Y(e){return null!==e}W.displayName=H;var z=e=>({name:"transformOrigin",options:e,fn(t){const{placement:r,rects:o,middlewareData:i}=t,a=0!==i.arrow?.centerOffset,n=a?0:e.arrowWidth,s=a?0:e.arrowHeight,[d,l]=E(r),p={start:"0%",center:"50%",end:"100%"}[l],c=(i.arrow?.x??0)+n/2,f=(i.arrow?.y??0)+s/2;let m="",h="";return"bottom"===d?(m=a?p:`${c}px`,h=-s+"px"):"top"===d?(m=a?p:`${c}px`,h=`${o.floating.height+s}px`):"right"===d?(m=-s+"px",h=a?p:`${f}px`):"left"===d&&(m=`${o.floating.width+s}px`,h=a?p:`${f}px`),{data:{x:m,y:h}}}});function E(e){const[t,r="center"]=e.split("-");return[t,r]}var N=A,X=S,k=C,D=W;export{X as Anchor,D as Arrow,k as Content,A as Popper,S as PopperAnchor,W as PopperArrow,C as PopperContent,N as Root,v as createPopperScope};
//# sourceMappingURL=index.js.map
