import{r as t,h as s,H as e,g as i}from"./p-76ab1744.js";const a=class{constructor(s){t(this,s),this.dataTrackingId="telia-focus-trap",this.focusableSelectors=["a[href]","audio[controls]","video[controls]","[contenteditable]",'[tabindex="0"]:not([disabled])',"button:not([disabled])","iframe","input:not([disabled]):not([type='hidden'])","select:not([disabled])","summary","textarea:not([disabled])"].join(", "),this.handleKeyDown=t=>{const s=t.path||t.composedPath&&t.composedPath(),e=this.getCurrentIndex(s[0]);"Tab"===t.key&&(e!==this.focusableEls.length-1||t.shiftKey||(t.preventDefault(),this.focusableEls[0].focus()),0===e&&t.shiftKey&&(t.preventDefault(),this.focusableEls[this.focusableEls.length-1].focus()))}}componentDidLoad(){document.addEventListener("keydown",this.handleKeyDown),this.findFocusableElements()}disconnectedCallback(){document.removeEventListener("keydown",this.handleKeyDown)}findFocusableElements(){let t=[];Array.from(this.element.querySelectorAll("*")).forEach((s=>{this.traverseFocusable(s,t)})),this.focusableEls=t}traverseFocusable(t,s){t.matches(this.focusableSelectors)?s.push(t):t.shadowRoot&&Array.from(t.shadowRoot.querySelectorAll(this.focusableSelectors)).forEach((t=>{this.traverseFocusable(t,s)}))}getCurrentIndex(t){let s;return this.focusableEls.map(((e,i)=>{e===t&&(s=i)})),s}render(){return s(e,{"data-testid":this.dataTestid},s("slot",null),s("telia-vst",{dataTrackingId:this.dataTrackingId}))}get element(){return i(this)}};export{a as telia_focus_trap}