"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var _=require("react"),g=require("react-dom"),M=require("@popperjs/core"),R=require("../../../../_virtual/index.js"),p=require("./utils.js");function O(r){if(r&&r.__esModule)return r;var n=Object.create(null);return r&&Object.keys(r).forEach(function(u){if(u!=="default"){var e=Object.getOwnPropertyDescriptor(r,u);Object.defineProperty(n,u,e.get?e:{enumerable:!0,get:function(){return r[u]}})}}),n.default=r,Object.freeze(n)}var i=O(_),S=O(g),j=[],U=function(n,u,e){e===void 0&&(e={});var f=i.useRef(null),a={onFirstUpdate:e.onFirstUpdate,placement:e.placement||"bottom",strategy:e.strategy||"absolute",modifiers:e.modifiers||j},v=i.useState({styles:{popper:{position:a.strategy,left:"0",top:"0"},arrow:{position:"absolute"}},attributes:{}}),y=v[0],P=v[1],m=i.useMemo(function(){return{name:"updateState",enabled:!0,phase:"write",fn:function(o){var d=o.state,b=Object.keys(d.elements);S.flushSync(function(){P({styles:p.fromEntries(b.map(function(c){return[c,d.styles[c]||{}]})),attributes:p.fromEntries(b.map(function(c){return[c,d.attributes[c]]}))})})},requires:["computeStyles"]}},[]),l=i.useMemo(function(){var s={onFirstUpdate:a.onFirstUpdate,placement:a.placement,strategy:a.strategy,modifiers:[].concat(a.modifiers,[m,{name:"applyStyles",enabled:!1}])};return R.default(f.current,s)?f.current||s:(f.current=s,s)},[a.onFirstUpdate,a.placement,a.strategy,a.modifiers,m]),t=i.useRef();return p.useIsomorphicLayoutEffect(function(){t.current&&t.current.setOptions(l)},[l]),p.useIsomorphicLayoutEffect(function(){if(!(n==null||u==null)){var s=e.createPopper||M.createPopper,o=s(n,u,l);return t.current=o,function(){o.destroy(),t.current=null}}},[n,u,e.createPopper]),{state:t.current?t.current.state:null,styles:y.styles,attributes:y.attributes,update:t.current?t.current.update:null,forceUpdate:t.current?t.current.forceUpdate:null}};exports.usePopper=U;
