import{u as j,c as _,d as G,e as J,f as K,g as Q,h as V,i as X,j as Y,k as $,o as B,l as b,m as ee,_ as C,n as re,p as te,q as ne,r as ae,s as ue}from"./CQYcUog4.js";import{r as u}from"./entries/entry-server-routing.Jj-lWLtL.js";var h=function(o){for(var t=o.activeElement;t!=null&&t.shadowRoot;)t=t.shadowRoot.activeElement;return t},Z=function(o){var t=o.target;return t&&t.shadowRoot&&(t=o.composedPath()[0]),t};function I(o){var t=u.useRef(function(){throw new Error("Cannot call an event handler while rendering")});return j(function(){t.current=o},[o]),_(function(){return function(){for(var s=[],n=0;n<arguments.length;n++)s[n]=arguments[n];var l=t.current;return l.apply(void 0,s)}})}var oe=function(o){var t=u.useRef(o);t.current=o,u.useEffect(function(){return function(){var s;(s=t.current)===null||s===void 0||s.call(t)}},[])},se="FocusTrapZone",ie={disabled:!1,disableFirstFocus:!1,forceFocusInsideTrap:!0,isClickableOutsideFocusTrap:!1,"data-tabster":'{"uncontrolled": {"completely": true}}'},ce=function(o,t,s){u.useImperativeHandle(o,function(){return{get previouslyFocusedElement(){return t},focus:s}},[s,t])},p=u.forwardRef(function(o,t){var s,n=u.useRef(null),l=u.useRef(null),d=u.useRef(null),N=G(n,t),c=J(),T=K(),y=Q(),O=(s=V(!1))!==null&&s!==void 0?s:!0,a=X(ie,o),i=_({hasFocus:!1,focusStackId:Y("ftz-",a.id)}),H=a.children,L=a.componentRef,f=a.disabled,M=a.disableFirstFocus,m=a.forceFocusInsideTrap,q=a.focusPreviouslyFocusedInnerElement,g=a.firstFocusableSelector,E=a.firstFocusableTarget,S=a.disableRestoreFocus,z=S===void 0?a.ignoreExternalFocusing:S,k=a.isClickableOutsideFocusTrap,w=a.enableAriaHiddenSiblings,P={"aria-hidden":!0,style:{pointerEvents:"none",position:"fixed"},tabIndex:f?-1:0,"data-is-visible":!0,"data-is-focus-trap-zone-bumper":!0},R=u.useCallback(function(e){e!==l.current&&e!==d.current&&$(e)},[]),F=I(function(){if(n.current){var e=i.previouslyFocusedElementInTrapZone;if(q&&e&&b(n.current,e)){R(e);return}var r=null;if(typeof E=="string")r=n.current.querySelector(E);else if(E)r=E(n.current);else if(g){var v=typeof g=="string"?g:g();r=n.current.querySelector("."+v)}r||(r=ne(n.current,n.current.firstChild,!1,!1,!1,!0,void 0,void 0,void 0,y)),r&&R(r)}}),x=function(e){if(!(f||!n.current)){var r=e===i.hasFocus?ae(n.current,d.current,!0,!1,y):ue(n.current,l.current,!0,!1,y);r&&(r===l.current||r===d.current?F():r.focus())}},D=function(e){var r;(r=a.onBlurCapture)===null||r===void 0||r.call(a,e);var v=e.relatedTarget;e.relatedTarget===null&&(v=h(c)),b(n.current,v)||(i.hasFocus=!1)},U=function(e){var r;(r=a.onFocusCapture)===null||r===void 0||r.call(a,e),e.target===l.current?x(!0):e.target===d.current&&x(!1),i.hasFocus=!0,e.target!==e.currentTarget&&!(e.target===l.current||e.target===d.current)&&(i.previouslyFocusedElementInTrapZone=Z(e.nativeEvent))},W=I(function(e){if(p.focusStack=p.focusStack.filter(function(v){return i.focusStackId!==v}),!!c){var r=c.activeElement;!z&&typeof(e==null?void 0:e.focus)=="function"&&(b(n.current,r)||r===c.body||r.shadowRoot)&&R(e)}}),A=I(function(e){if(!f&&i.focusStackId===p.focusStack.slice(-1)[0]){var r=Z(e);r&&!b(n.current,r)&&(c&&h(c)===c.body?setTimeout(function(){c&&h(c)===c.body&&(F(),i.hasFocus=!0)},0):(F(),i.hasFocus=!0),e.preventDefault(),e.stopPropagation())}});return u.useEffect(function(){var e=[];return m&&e.push(B(T,"focus",A,!0)),k||e.push(B(T,"click",A,!0)),function(){e.forEach(function(r){return r()})}},[m,k,T]),u.useEffect(function(){if(!(f||!O&&!m||!n.current)){p.focusStack.push(i.focusStackId);var e=a.elementToFocusOnDismiss||h(c);return!M&&!b(n.current,e)&&F(),function(){return W(e)}}},[m,f]),u.useEffect(function(){if(!f&&w){var e=ee(n.current);return e}},[f,w,n]),oe(function(){delete i.previouslyFocusedElementInTrapZone}),ce(L,i.previouslyFocusedElementInTrapZone,F),u.createElement("div",C({"aria-labelledby":a.ariaLabelledBy},re(a,te),{ref:N,onFocusCapture:U,onBlurCapture:D}),u.createElement("div",C({},P,{ref:l})),H,u.createElement("div",C({},P,{ref:d})))});p.displayName=se;p.focusStack=[];export{p as F,oe as u};
//# sourceMappingURL=DxmafSWm.js.map
