import{P as p}from"./index-1.0.74-DtMr5-xA.js";import{r as f,d as U}from"./redux-1.0.74-D8bIc6ki.js";function h(n){if(typeof window>"u")return n;const t=f.useRef(null);return f.useLayoutEffect(()=>{t.current=n}),f.useCallback((...r)=>{var s;(s=t.current)===null||s===void 0||s.call(t,...r)},[])}const R={};function A(n,t){R[n]||(R[n]=!0,console.error("[material-ui-popup-state] WARNING",t))}const q={isOpen:!1,setAnchorElUsed:!1,anchorEl:void 0,anchorPosition:void 0,hovered:!1,focused:!1,_openEventType:null,_childPopupState:null,_deferNextOpen:!1,_deferNextClose:!1},x=U,L="useId"in x?()=>x.useId():()=>{};function M({parentPopupState:n,popupId:t=L(),variant:r,disableAutoFocus:s}){const c=f.useRef(!0);f.useEffect(()=>(c.current=!0,()=>{c.current=!1}),[]);const[l,a]=f.useState(q),i=f.useCallback(o=>{c.current&&a(o)},[]),y=f.useCallback(o=>i(e=>({...e,setAnchorElUsed:!0,anchorEl:o??void 0})),[]),S=h(o=>(l.isOpen?g(o):b(o),l)),b=h(o=>{const e=o instanceof Element?void 0:o,u=o instanceof Element?o:(o==null?void 0:o.currentTarget)instanceof Element?o.currentTarget:void 0;if((e==null?void 0:e.type)==="touchstart"){i(d=>({...d,_deferNextOpen:!0}));return}const C=e==null?void 0:e.clientX,T=e==null?void 0:e.clientY,B=typeof C=="number"&&typeof T=="number"?{left:C,top:T}:void 0,N=d=>{if(!o&&!d.setAnchorElUsed&&r!=="dialog"&&A("missingEventOrAnchorEl","eventOrAnchorEl should be defined if setAnchorEl is not used"),n){if(!n.isOpen)return d;setTimeout(()=>n._setChildPopupState(E))}const P={...d,isOpen:!0,anchorPosition:B,hovered:(e==null?void 0:e.type)==="mouseover"||d.hovered,focused:(e==null?void 0:e.type)==="focus"||d.focused,_openEventType:e==null?void 0:e.type};return d.setAnchorElUsed||(e!=null&&e.currentTarget?P.anchorEl=e==null?void 0:e.currentTarget:u&&(P.anchorEl=u)),P};i(d=>d._deferNextOpen?(setTimeout(()=>i(N),0),{...d,_deferNextOpen:!1}):N(d))}),m=o=>{const{_childPopupState:e}=o;return setTimeout(()=>{e==null||e.close(),n==null||n._setChildPopupState(null)}),{...o,isOpen:!1,hovered:!1,focused:!1}},g=h(o=>{const e=o instanceof Element?void 0:o;if((e==null?void 0:e.type)==="touchstart"){i(u=>({...u,_deferNextClose:!0}));return}i(u=>u._deferNextClose?(setTimeout(()=>i(m),0),{...u,_deferNextClose:!1}):m(u))}),I=f.useCallback((o,e)=>{o?b(e):g(e)},[]),k=h(o=>{const{relatedTarget:e}=o;i(u=>u.hovered&&!(e instanceof Element&&_(e,E))?u.focused?{...u,hovered:!1}:m(u):u)}),w=h(o=>{if(!o)return;const{relatedTarget:e}=o;i(u=>u.focused&&!(e instanceof Element&&_(e,E))?u.hovered?{...u,focused:!1}:m(u):u)}),F=f.useCallback(o=>i(e=>({...e,_childPopupState:o})),[]),E={...l,setAnchorEl:y,popupId:t??void 0,variant:r,open:b,close:g,toggle:S,setOpen:I,onBlur:w,onMouseLeave:k,disableAutoFocus:s??!!(l.hovered||l.focused),_setChildPopupState:F};return E}function O({isOpen:n,popupId:t,variant:r}){return{...r==="popover"?{"aria-haspopup":!0,"aria-controls":n?t:void 0}:r==="popper"?{"aria-describedby":n?t:void 0}:void 0}}function G(n){return{...O(n),onClick:n.open,onTouchStart:n.open}}function $({isOpen:n,anchorEl:t,anchorPosition:r,close:s,popupId:c,onMouseLeave:l,disableAutoFocus:a,_openEventType:i}){return{id:c,anchorEl:t,anchorPosition:r,anchorReference:i==="contextmenu"?"anchorPosition":"anchorEl",open:n,onClose:s,onMouseLeave:l,...a&&{disableAutoFocus:!0,disableEnforceFocus:!0,disableRestoreFocus:!0}}}function W(n,{popupId:t}){if(!t)return null;const r=typeof n.getRootNode=="function"?n.getRootNode():document;return typeof r.getElementById=="function"?r.getElementById(t):null}function _(n,t){const{anchorEl:r,_childPopupState:s}=t;return v(r,n)||v(W(n,t),n)||s!=null&&_(n,s)}function v(n,t){if(!n)return!1;for(;t;){if(t===n)return!0;t=t.parentElement}return!1}function X({children:n,popupId:t,variant:r,parentPopupState:s,disableAutoFocus:c}){const l=M({popupId:t,variant:r,parentPopupState:s,disableAutoFocus:c}),a=n(l);return a??null}X.propTypes={children:p.func.isRequired,popupId:p.string,variant:p.oneOf(["popover","popper"]).isRequired,parentPopupState:p.object,disableAutoFocus:p.bool};export{X as P,$ as a,G as b};
