import{p as t,H as e,c as i,h as s,d as n,t as c}from"./p-Bpcl2TqF.js";import{i as h,d as r,t as o}from"./p-94ZtGp9D.js";const d=()=>`.ifx-content-switcher{background-color:#FFFFFF;border:1px solid #BFBBBB;border-radius:9999px;height:36px;width:fit-content;box-sizing:border-box;display:flex;flex-direction:row;align-items:center}.ifx-content-switcher ::slotted(ifx-content-switcher-item){position:relative}.ifx-content-switcher ::slotted(ifx-content-switcher-item:first-child){left:-1px;margin-right:-1px}.ifx-content-switcher ::slotted(ifx-content-switcher-item:last-child){right:-1px;margin-left:-1px}.ifx-content-switcher ::slotted(.ifx-content-switcher-divider){width:1px;height:20px;background-color:#8D8786;margin:0px 1px;visibility:visible}.ifx-content-switcher ::slotted(.ifx-content-switcher-divider.hidden){visibility:hidden}`;const l=t(class t extends e{constructor(t){super();if(t!==false){this.__registerHost()}this.__attachShadow();this.ifxChange=i(this,"ifxChange",7)}get el(){return this}items;activeIndex=-1;hoverIndex=-1;focusIndex=-1;dividers=[];ifxChange;eventHandlers=new Map;componentWillLoad(){this.items=Array.from(this.el.children);this.initializeDividers();this.addEventListeners();this.ensureSingleSelectedItem()}async componentDidLoad(){if(!h(this.el)){const t=r();o("ifx-content-switcher",await t)}}disconnectedCallback(){this.removeEventListeners()}initializeDividers(){this.items.forEach(((t,e)=>{if(e<this.items.length-1){const e=document.createElement("div");e.classList.add("ifx-content-switcher-divider");t.after(e);this.dividers.push(e)}}))}addEventListeners(){this.items.forEach(((t,e)=>{const i={click:()=>this.selectItem(e),mouseenter:()=>this.handleHover(e,true),mouseleave:()=>this.handleHover(e,false),focus:()=>this.handleFocus(e,true),blur:()=>this.handleFocus(e,false)};Object.keys(i).forEach((e=>{t.addEventListener(e,i[e])}));this.eventHandlers.set(t,i)}))}removeEventListeners(){this.eventHandlers.forEach(((t,e)=>{Object.keys(t).forEach((i=>{e.removeEventListener(i,t[i])}))}));this.eventHandlers.clear()}ensureSingleSelectedItem(){this.items.forEach(((t,e)=>{const i=t.getAttribute("selected")==="true"||t.selected;if(i){if(this.activeIndex<0){this.selectItem(e)}else{t.removeAttribute("selected");t.selected=false}}}))}handleHover(t,e){this.hoverIndex=e?t:-1;this.updateDividersOfItem(t)}handleFocus(t,e){this.focusIndex=e?t:-1;this.updateDividersOfItem(t)}updateDividersOfItem(t){if(t<this.items.length-1){this.updateDividerVisibility(t)}if(t>0){this.updateDividerVisibility(t-1)}}updateDividerVisibility(t){const e=new Set([this.activeIndex,this.activeIndex-1,this.hoverIndex,this.hoverIndex-1,this.focusIndex,this.focusIndex-1]);this.setDividerVisibility(t,e.has(t))}setDividerVisibility(t,e){if(this.dividers[t]){this.dividers[t].classList.toggle("hidden",e)}}selectItem(t){if(t===this.activeIndex)return;const e=this.activeIndex;if(e>=0){this.items[e].removeAttribute("selected")}this.activeIndex=t;this.items[t].setAttribute("selected","true");this.ifxChange.emit({oldValue:this.getValueOfItem(e),newValue:this.getValueOfItem(t)});this.updateDividersOfItem(e);this.updateDividersOfItem(t)}getValueOfItem(t){if(this.items[t]==null)return t.toLocaleString();return this.items[t].getAttribute("value")||t.toLocaleString()}render(){return s(n,{key:"b63709af07098f40de2a88c93c1b3880dca5008f"},s("div",{key:"c6ce025d029bcf39bcd5db66fe1cb467e2f9f989",class:"ifx-content-switcher",role:"group"},s("slot",{key:"e7ec91f4b27c4feb3724639f2cc9ba4561edd2ca"})))}static get style(){return d()}},[769,"ifx-content-switcher",{items:[32],activeIndex:[32],hoverIndex:[32],focusIndex:[32],dividers:[32]}]);function f(){if(typeof customElements==="undefined"){return}const t=["ifx-content-switcher"];t.forEach((t=>{switch(t){case"ifx-content-switcher":if(!customElements.get(c(t))){customElements.define(c(t),l)}break}}))}const a=l;const x=f;export{a as IfxContentSwitcher,x as defineCustomElement};
//# sourceMappingURL=ifx-content-switcher.js.map