import{c as e,i as t}from"./preload-helper-B45gAKPr.js";import{pn as n}from"./iframe-NOj5DEP4.js";function r(e){if(typeof document>`u`)return null;let t=document.getElementById(e);if(t instanceof HTMLElement)return t;let n=document.createElement(`div`);return n.id=e,document.body.append(n),n}function i(e,t){(0,s.useEffect)(()=>{let n=n=>{if(Array.isArray(e)){let r=!0;for(let t of e)t.current&&t.current.contains(n.target)&&(r=!1);r&&t()}else e.current&&!e.current.contains(n.target)&&t()};return document.addEventListener(`mousedown`,n),()=>document.removeEventListener(`mousedown`,n)},[e,t])}function a({active:e,onDismiss:t,enabled:n=!0,documentTarget:r,containerRef:i}){let a=(0,s.useEffectEvent)(()=>t());(0,s.useEffect)(()=>{if(!e||!n)return;let t=r??(typeof document>`u`?null:document);if(!t)return;let o=e=>{if(e.key!==`Escape`)return;let n=t.activeElement,r=i?.current;r&&n instanceof Node&&n!==r&&!r.contains(n)||(e.preventDefault(),a())};return t.addEventListener(`keydown`,o,!0),()=>t.removeEventListener(`keydown`,o,!0)},[e,n,r,i])}function o({active:e,trapFocus:t=!1,restoreFocus:n=!0,initialFocus:r=`auto`,restoreFocusTarget:i,containerRef:a}){let o=(0,s.useRef)(null),l=a??o,u=(0,s.useRef)(null),d=(0,s.useEffectEvent)(e=>Array.from(e.querySelectorAll(c)).filter(e=>!e.hasAttribute(`aria-hidden`))),f=(0,s.useEffectEvent)(e=>{if(r===`container`)return e;if(typeof r==`function`)return r(e)??e;let t=d(e);return t.find(e=>e.hasAttribute(`autofocus`)||e.hasAttribute(`autoFocus`))??t[0]??e}),p=(0,s.useEffectEvent)(()=>i?.()??u.current);return(0,s.useEffect)(()=>{if(!e)return;u.current=document.activeElement instanceof HTMLElement?document.activeElement:null;let r=null,i=0,a=()=>{if(r=l.current,!r){i=window.requestAnimationFrame(a);return}let e=f(r);e instanceof HTMLElement&&e.isConnected&&e.focus(),t&&r.addEventListener(`keydown`,o)},o=e=>{if(!t||e.key!==`Tab`||!r)return;let n=d(r);if(n.length===0){e.preventDefault(),r.focus();return}let i=n[0],a=n[n.length-1],o=document.activeElement;if(e.shiftKey){(o===i||o===r)&&(e.preventDefault(),a.focus());return}o===a&&(e.preventDefault(),i.focus())};return a(),()=>{if(window.cancelAnimationFrame(i),t&&r&&r.removeEventListener(`keydown`,o),!n)return;let e=p();e?.isConnected&&e.focus()}},[e,t,n,l]),l}var s,c,l=t((()=>{s=e(n(),1),c=`button:not([disabled]), [href], input:not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex="-1"]):not([disabled])`}));function u({hookName:e,providerName:t,contextName:n}){let r=n?` "${n}"`:``;return[`Хук ${e} должен использоваться внутри ${t}.`,`Контекст${r} равен null, поэтому, вероятно, дерево компонентов не обёрнуто в ${t}.`,`Убедитесь, что ${t} расположен выше компонента, который вызывает ${e}.`].join(` `)}function d({hookName:e,providerName:t,contextName:n}){return Error(u({hookName:e,providerName:t,contextName:n}))}var f=t((()=>{}));export{l as a,a as i,d as n,i as o,r,o as s,f as t};