import{r as t,c as i,h as s,g as e}from"./p-21516f8c.js";import{s as n}from"./p-6fdf5ce4.js";const h=":host{--lu-tabs-min-width:0;display:flex;width:100%;min-width:0;min-width:var(--lu-tabs-min-width)}.inner-container{margin-left:auto;margin-right:auto;display:flex;position:relative;flex-flow:row;width:var(--lu-tabs-max-inner-width, 100%);height:100%;white-space:nowrap}.box.expand{transition-duration:0.15s;transition-timing-function:cubic-bezier(0.4, 0, 1, 1)}.box.contract{transition-duration:0.18s;transition-timing-function:cubic-bezier(0, 0, 0.2, 1)}.box.align-bottom{bottom:0}.box.hidden{display:none}.box{left:0;right:0;position:absolute;bottom:0;height:3px;-webkit-transform:scale(0);-webkit-transform:translateZ(0);transform:scale(0);-webkit-transform-origin:left center;transform-origin:left center;transition-property:-webkit-transform;transition-property:transform;background-color:var(--lu-tabs-selection-bar-color, #256EC1)}";const r=class{constructor(s){t(this,s);this.luTabsUpdated=i(this,"luTabsUpdated",7);this.luTabFocused=i(this,"luTabFocused",3);this.luTabBlurred=i(this,"luTabBlurred",3);this.tabsId=`lu-rg-${a++}`;this.tabs=[];this.tabIncrement=1;this.noSlide=true;this.onBarTransitionEnd=()=>{if(!this.noSlide){let t=this.selectionBar.classList;if(t.contains("expand")){t.remove("expand");t.add("contract");this.positionBar(this.pos.width,this.pos.left)}else if(t.contains("contract")){t.remove("contract")}}}}connectedCallback(){this.currentNodes=this.getNodes()}componentDidLoad(){n(25).then((()=>this.tabs.forEach((t=>{if(t.active){this.updateItYo(t)}}))));if(this.selectionBar){this.selectionBar.addEventListener("webkitTransitionEnd",this.onBarTransitionEnd)}}disconnectedCallback(){if(this.selectionBar){this.selectionBar.removeEventListener("webkitTransitionEnd",this.onBarTransitionEnd)}}onTabDidLoad(t){const i=t.target;i.noSlide=this.noSlide;if(!i.name){i.name=this.tabsId+"-tab-"+this.tabIncrement;this.tabIncrement++}if(i.active){this.value=i.name}this.tabs.push(i)}onTabDidDisconnect(t){const i=this.tabs.indexOf(t.target);if(i>-1){this.tabs.splice(i,1)}}onTabSelect(t){const i=t.target;if(i){this.updateItYo(i)}}handleKeyDown(t){let i=false;this.focusedNode=this.currentNodes.find((t=>getComputedStyle(t.shadowRoot.querySelector(".focus-box")).display==="block"));switch(t.key){case"ArrowRight":this.focusedNode.nextElementSibling?this.focusedNode.nextElementSibling.focus():this.currentNodes[0].focus();i=true;break;case"ArrowLeft":this.focusedNode.previousElementSibling?this.focusedNode.previousElementSibling.focus():this.currentNodes[this.currentNodes.length-1].focus();i=true;break;case"Home":this.currentNodes[0].focus();i=true;break;case"End":this.currentNodes[this.currentNodes.length-1].focus();i=true;break}if(i){t.preventDefault()}}onFocus(){this.luTabFocused.emit()}onBlur(){if(document.activeElement.nodeName!=="LU-TAB"){this.luTabBlurred.emit()}}async elementResized(){if(this.value&&!this.noSlide){this.tabChanged(this.tabs.filter((t=>t.name===this.value))[0],null)}return true}updateItYo(t){let i=null;let s;this.currentOrderedTabsArray=this.getNodes();this.value=t.name;this.currentOrderedTabsArray.forEach((e=>{if(e!==t&&e.active===true){e.active=false;i=e}if(e===t){s=e}}));if(!this.noSlide){this.tabChanged(s,i)}this.luTabsUpdated.emit({value:this.value})}tabChanged(t,i){if(!t){this.selectionBar.classList.remove("expand");this.selectionBar.classList.remove("contract");this.positionBar(0,0);return}let s=this.tabsContent.getBoundingClientRect();let e=s.width;let n=t.getBoundingClientRect();let h=n.left-s.left;this.pos={width:this.calcPercent(n.width,e),left:this.calcPercent(h,e)};if(this.noSlide||i==null){this.selectionBar.classList.remove("expand");this.selectionBar.classList.remove("contract");this.positionBar(this.pos.width,this.pos.left);return}let r=i.getBoundingClientRect();let a=this.tabs.indexOf(i);let o=this.tabs.indexOf(t);let l=5;this.selectionBar.classList.add("expand");let c=a<o;if(c){this.positionBar(this.calcPercent(n.left+n.width-r.left,e)-l,this.left)}else{this.positionBar(this.calcPercent(r.left+r.width-n.left,e)-l,this.calcPercent(h,e)+l)}}positionBar(t,i){t=t||0;i=i||0;this.width=t;this.left=i;this.selectionBar.style.webkitTransform="translateX("+i+"%) scaleX("+t/100+")";this.selectionBar.style.transform="translateX("+i+"%) scaleX("+t/100+")"}getNodes(){let t=Array.from(this.tabsElement.children);if(t[0]&&t[0].tagName.toLowerCase()==="div"){t=Array.from(Array.from(this.tabsElement.children)[0].children).filter((t=>t.tagName.toLowerCase()==="lu-tab"))}return t}calcPercent(t,i){return 100*t/i}render(){return s("div",{"aria-label":this.label,class:"inner-container",ref:t=>this.tabsContent=t,role:"tablist"},s("slot",null),this.noSlide?null:s("div",{class:"box align-bottom",onTransitionEnd:this.onBarTransitionEnd,ref:t=>this.selectionBar=t}))}get tabsElement(){return e(this)}};let a=0;r.style=h;export{r as lu_tabs};
//# sourceMappingURL=p-127dc8b9.entry.js.map