import{r as t,c as a,h as s,a as i}from"./p-e97fde0a.js";const e=":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)}";const o=e;const r=class{constructor(s){t(this,s);this.scTabHide=a(this,"scTabHide",7);this.scTabShow=a(this,"scTabShow",7);this.tabs=[];this.panels=[];this.activeTab=undefined}componentDidLoad(){this.syncTabsAndPanels();this.setAriaLabels();this.setActiveTab(this.getActiveTab()||this.tabs[0],{emitEvents:false});this.mutationObserver=new MutationObserver((()=>{this.syncTabsAndPanels()}));this.mutationObserver.observe(this.el,{attributes:true,childList:true,subtree:true})}disconnectedCallback(){this.mutationObserver.disconnect()}syncTabsAndPanels(){this.tabs=this.getAllTabs();this.panels=this.getAllPanels()}setAriaLabels(){this.tabs.map((t=>{const a=this.panels.find((a=>a.name===t.panel));if(a){t.setAttribute("aria-controls",a.getAttribute("id"));a.setAttribute("aria-labelledby",t.getAttribute("id"))}}))}handleClick(t){const a=t.target;const s=a.closest("sc-tab");const i=s===null||s===void 0?void 0:s.closest("sc-tab-group");if(i!==this.el){return}if(s){this.setActiveTab(s,{scrollBehavior:"smooth"})}}handleKeyDown(t){const a=t.target;const s=a.closest("sc-tab");const i=s===null||s===void 0?void 0:s.closest("sc-tab-group");if(i!==this.el){return true}if(["Enter"," "].includes(t.key)){if(s){this.setActiveTab(s,{scrollBehavior:"smooth"})}}if(["ArrowUp","ArrowDown","Home","End"].includes(t.key)){const a=document.activeElement;if(a&&a.tagName.toLowerCase()==="sc-tab"){let s=this.tabs.indexOf(a);if(t.key==="Home"){s=0}else if(t.key==="End"){s=this.tabs.length-1}else if(t.key==="ArrowUp"){s=Math.max(0,s-1)}else if(t.key==="ArrowDown"){s=Math.min(this.tabs.length-1,s+1)}this.tabs[s].triggerFocus({preventScroll:true});t.preventDefault()}}}setActiveTab(t,a){a=Object.assign({emitEvents:true,scrollBehavior:"auto"},a);if(t&&t!==this.activeTab&&!t.disabled){const s=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));if(a.emitEvents){if(s){this.scTabHide.emit(s.panel)}this.scTabShow.emit(this.activeTab.panel)}}}getActiveTab(){const t=this.getAllTabs();return t.find((t=>t.active))}getAllChildren(){const t=this.el.shadowRoot.querySelectorAll("slot");const a=["sc-tab","sc-tab-panel"];const s=Array.from(t).map((t=>{var a;return(a=t===null||t===void 0?void 0:t.assignedElements)===null||a===void 0?void 0:a.call(t,{flatten:true})})).flat();return s.reduce(((t,a)=>{var s;return t.concat(a,[...((s=a===null||a===void 0?void 0:a.querySelectorAll)===null||s===void 0?void 0:s.call(a,"*"))||[]])}),[]).filter((t=>{var s,i;return a.includes((i=(s=t===null||t===void 0?void 0:t.tagName)===null||s===void 0?void 0:s.toLowerCase)===null||i===void 0?void 0:i.call(s))}))}getAllTabs(t=false){return this.getAllChildren().filter((a=>t?a.tagName.toLowerCase()==="sc-tab":a.tagName.toLowerCase()==="sc-tab"&&!a.disabled))}getAllPanels(){return this.getAllChildren().filter((t=>t.tagName.toLowerCase()==="sc-tab-panel"))}render(){return s("div",{key:"681adf1d4ec8da0f95b3334367a949666d68ee28",part:"base",class:{"tab-group":true},onClick:t=>this.handleClick(t),onKeyDown:t=>this.handleKeyDown(t)},s("div",{key:"3c8a28a3a551dd41b8feca9c9f2acc24db3d76fc",class:"tab-group__nav-container",part:"nav"},s("div",{key:"cef03177f5593be915af72efb3abc45ab6739006",class:"tab-group__nav"},s("div",{key:"58b0f5577b50d62a64d3a1dd325bbc23ac24efda",part:"tabs",class:"tab-group__tabs",role:"tablist"},s("slot",{key:"0f3e2d1d0a3123da46b81346367e97d895e8a688",onSlotchange:()=>this.syncTabsAndPanels(),name:"nav"})))),s("div",{key:"c674a6777f898a479c2d304d68f6bb39c5796839",part:"body",class:"tab-group__body"},s("slot",{key:"0be0d84afd46ea6eb280dfd841a618fa7aefd245",onSlotchange:()=>this.syncTabsAndPanels()})))}get el(){return i(this)}};r.style=o;export{r as sc_tab_group};
//# sourceMappingURL=p-cab11d42.entry.js.map