"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var c=require("react"),i=require("../utils/index.js");function l(r){const t=c.useRef(null),n=c.useRef(null),s=e=>{var o,a;const u=document.activeElement===n.current,f=document.activeElement===t.current;e.key==="Tab"&&(u&&!e.shiftKey&&(e.preventDefault(),(o=t.current)==null||o.focus()),f&&e.shiftKey&&(e.preventDefault(),(a=n.current)==null||a.focus()))};c.useEffect(()=>{const e=i.getFocusableElements(r.current);t.current=e[0],n.current=e[e.length-1],t.current&&t.current.focus()},[r.current]),c.useEffect(()=>{var e;return(e=r.current)==null||e.addEventListener("keydown",s),()=>{var u;(u=r.current)==null||u.removeEventListener("keydown",s)}},[s])}exports.useTrappedFocus=l;
