import{r as t,c as s,h as e,H as i,g as n}from"./p-add854e8.js";const l=class{constructor(e){t(this,e),this.ruxSelected=s(this,"ruxselected",7),this._panels=[],this._tabs=[],this.small=void 0}handleTabselected(t){const s=t.target,e=Array.from(this.el.children);if(s.selected&&e.includes(s)){const t=this._panels.find((t=>t.getAttribute("aria-labelledby")===s.getAttribute("id")));this._panels.forEach((t=>t.classList.add("hidden"))),null==t||t.classList.remove("hidden")}this._checkSelected()}handleListen(t){t.target.getAttribute("aria-labelledby")===this.el.id&&this._registerPanels(t)}handleSmallChange(){this._tabs.forEach(this.small?t=>t.setAttribute("small",""):t=>{t.hasAttribute("small")&&t.removeAttribute("small")})}onKeydown(t){var s;const e=this._tabs.filter((t=>!t.disabled));if(t.target&&e.includes(t.target)){const i=e.findIndex((s=>s===t.target));let n;["ArrowDown","ArrowRight"].includes(t.code)&&(n=i===e.length-1?e[0]:e[i+1]),["ArrowUp","ArrowLeft"].includes(t.code)&&(n=0===i?e[e.length-1]:e[i-1]),n&&e.includes(n)&&(null===(s=n.shadowRoot)||void 0===s?void 0:s.querySelector(".rux-tab")).focus()}}connectedCallback(){this._addTabs()}componentWillUpdate(){this._checkSelected()}_addTabs(){var t;this._tabs=Array.from(null===(t=this.el)||void 0===t?void 0:t.querySelectorAll("rux-tab"))}_checkSelected(){const t=this._tabs[0].shadowRoot.querySelector('[part="container"]');t&&(t.tabIndex=!this._tabs.find((t=>t.selected))||this._tabs[0].hasAttribute("selected")?0:-1)}_registerPanels(t){this._panels=[],t.detail.forEach((t=>{this._panels.push(t)})),this._addTabs();const s=this._tabs.find((t=>t.selected))||this._tabs[0];this._setTab(s)}_onPress(t){"Enter"===t.key&&this._onClick(t)}_onClick(t){const s=t.target.closest("rux-tab");null!==s&&(this.ruxSelected.emit(s),null===s.getAttribute("disabled")&&this._setTab(s))}_reset(){this._tabs.forEach((t=>{t.parentElement===this.el&&(t.selected=!1)})),this._panels.forEach((t=>{var s;(null===(s=t.parentElement)||void 0===s?void 0:s.getAttribute("aria-labelledby"))===this.el.id&&t.classList.add("hidden")}))}_setTab(t){this._reset();const s=this._panels.find((s=>s.getAttribute("aria-labelledby")===t.getAttribute("id")));t&&(t.selected=!0),s&&s.classList.remove("hidden")}render(){return e(i,{onClick:t=>this._onClick(t),onKeyPress:t=>this._onPress(t),role:"tablist"},e("slot",{onSlotchange:this._addTabs.bind(this)}))}get el(){return n(this)}static get watchers(){return{small:["handleSmallChange"]}}};l.style=":host{box-sizing:border-box;display:flex;justify-content:flex-start;height:100%;width:auto;margin:0;padding:0;-moz-user-select:none;-khtml-user-select:none;-webkit-user-select:none;-ms-user-select:none;user-select:none}:host(:not(:focus-within)){contain:content;}:host([hidden]){display:none}";export{l as rux_tabs}