import*as t from"react";import{r as e}from"../../../react-dom/index.js";import r from"../../../react-fast-compare/index.js";import{fromEntries as n,useIsomorphicLayoutEffect as s}from"./utils.js";import{createPopper as o}from"../../../@popperjs/core/lib/popper.js";var a=[],u=function(u,i,p){void 0===p&&(p={});var c=t.useRef(null),l={onFirstUpdate:p.onFirstUpdate,placement:p.placement||"bottom",strategy:p.strategy||"absolute",modifiers:p.modifiers||a},m=t.useState({styles:{popper:{position:l.strategy,left:"0",top:"0"},arrow:{position:"absolute"}},attributes:{}}),f=m[0],d=m[1],y=t.useMemo((function(){return{name:"updateState",enabled:!0,phase:"write",fn:function(t){var r=t.state,s=Object.keys(r.elements);e.flushSync((function(){d({styles:n(s.map((function(t){return[t,r.styles[t]||{}]}))),attributes:n(s.map((function(t){return[t,r.attributes[t]]})))})}))},requires:["computeStyles"]}}),[]),b=t.useMemo((function(){var t={onFirstUpdate:l.onFirstUpdate,placement:l.placement,strategy:l.strategy,modifiers:[].concat(l.modifiers,[y,{name:"applyStyles",enabled:!1}])};return r(c.current,t)?c.current||t:(c.current=t,t)}),[l.onFirstUpdate,l.placement,l.strategy,l.modifiers,y]),U=t.useRef();return s((function(){U.current&&U.current.setOptions(b)}),[b]),s((function(){if(null!=u&&null!=i){var t=(p.createPopper||o)(u,i,b);return U.current=t,function(){t.destroy(),U.current=null}}}),[u,i,p.createPopper]),{state:U.current?U.current.state:null,styles:f.styles,attributes:f.attributes,update:U.current?U.current.update:null,forceUpdate:U.current?U.current.forceUpdate:null}};export{u as usePopper};
//# sourceMappingURL=usePopper.js.map
