import{r as t,c as s,h as i,g as a}from"./p-dfbe004d.js";const r=class{constructor(i){t(this,i),this.scTabHide=s(this,"scTabHide",7),this.scTabShow=s(this,"scTabShow",7),this.tabs=[],this.panels=[]}componentDidLoad(){this.syncTabsAndPanels(),this.setAriaLabels(),this.setActiveTab(this.getActiveTab()||this.tabs[0],{emitEvents:!1}),this.mutationObserver=new MutationObserver((()=>{this.syncTabsAndPanels()})),this.mutationObserver.observe(this.el,{attributes:!0,childList:!0,subtree:!0})}disconnectedCallback(){this.mutationObserver.disconnect()}syncTabsAndPanels(){this.tabs=this.getAllTabs(),this.panels=this.getAllPanels()}setAriaLabels(){this.tabs.map((t=>{const s=this.panels.find((s=>s.name===t.panel));s&&(t.setAttribute("aria-controls",s.getAttribute("id")),s.setAttribute("aria-labelledby",t.getAttribute("id")))}))}handleClick(t){const s=t.target.closest("sc-tab");(null==s?void 0:s.closest("sc-tab-group"))===this.el&&s&&this.setActiveTab(s,{scrollBehavior:"smooth"})}handleKeyDown(t){const s=t.target.closest("sc-tab");if((null==s?void 0:s.closest("sc-tab-group"))!==this.el)return!0;if(["Enter"," "].includes(t.key)&&s&&this.setActiveTab(s,{scrollBehavior:"smooth"}),["ArrowUp","ArrowDown","Home","End"].includes(t.key)){const s=document.activeElement;if(s&&"sc-tab"===s.tagName.toLowerCase()){let i=this.tabs.indexOf(s);"Home"===t.key?i=0:"End"===t.key?i=this.tabs.length-1:"ArrowUp"===t.key?i=Math.max(0,i-1):"ArrowDown"===t.key&&(i=Math.min(this.tabs.length-1,i+1)),this.tabs[i].triggerFocus({preventScroll:!0}),t.preventDefault()}}}setActiveTab(t,s){if(s=Object.assign({emitEvents:!0,scrollBehavior:"auto"},s),t&&t!==this.activeTab&&!t.disabled){const i=this.activeTab;this.activeTab=t,this.tabs.map((t=>t.active=t===this.activeTab)),this.panels.map((t=>t.active=t.name===this.activeTab.panel)),s.emitEvents&&(i&&this.scTabHide.emit(i.panel),this.scTabShow.emit(this.activeTab.panel))}}getActiveTab(){return this.getAllTabs().find((t=>t.active))}getAllChildren(){const t=this.el.shadowRoot.querySelectorAll("slot"),s=["sc-tab","sc-tab-panel"];return Array.from(t).map((t=>{var s;return null===(s=null==t?void 0:t.assignedElements)||void 0===s?void 0:s.call(t,{flatten:!0})})).flat().reduce(((t,s)=>{var i;return t.concat(s,[...(null===(i=null==s?void 0:s.querySelectorAll)||void 0===i?void 0:i.call(s,"*"))||[]])}),[]).filter((t=>{var i,a;return s.includes(null===(a=null===(i=null==t?void 0:t.tagName)||void 0===i?void 0:i.toLowerCase)||void 0===a?void 0:a.call(i))}))}getAllTabs(t=!1){return this.getAllChildren().filter((s=>t?"sc-tab"===s.tagName.toLowerCase():"sc-tab"===s.tagName.toLowerCase()&&!s.disabled))}getAllPanels(){return this.getAllChildren().filter((t=>"sc-tab-panel"===t.tagName.toLowerCase()))}render(){return i("div",{part:"base",class:{"tab-group":!0},onClick:t=>this.handleClick(t),onKeyDown:t=>this.handleKeyDown(t)},i("div",{class:"tab-group__nav-container",part:"nav"},i("div",{class:"tab-group__nav"},i("div",{part:"tabs",class:"tab-group__tabs",role:"tablist"},i("slot",{onSlotchange:()=>this.syncTabsAndPanels(),name:"nav"})))),i("div",{part:"body",class:"tab-group__body"},i("slot",{onSlotchange:()=>this.syncTabsAndPanels()})))}get el(){return a(this)}};r.style=":host{display:block;--sc-tabs-min-width:225px}.tab-group{display:flex;flex-wrap:wrap;position:relative;border:solid 1px transparent;border-radius:0;flex-direction:row}@media screen and (min-width: 750px){.tab-group{flex-wrap:nowrap}}.tab-group__tabs{display:flex;flex-wrap:wrap;flex:0 0 auto;flex-direction:column;margin-bottom:var(--sc-spacing-xx-large)}.tab-group__nav-container{order:1;flex:1 0 100%}@media screen and (min-width: 750px){.tab-group__nav-container{min-width:var(--sc-tabs-min-width);flex:0 1 auto}}.tab-group__body{flex:1 1 auto;order:2}@media screen and (min-width: 750px){.tab-group__body{padding:0 var(--sc-spacing-xx-large)}}::slotted(sc-tab){margin-bottom:var(--sc-spacing-xx-small)}";export{r as sc_tab_group}