import{r as t,c as i,a as e,h as s,d as h}from"./p-wX3eJOEL.js";import{i as n}from"./p-CtINY9El.js";import{d as r,t as c}from"./p-DNHOWgWh.js";const o=class{constructor(e){t(this,e),this.ifxChange=i(this,"ifxChange",7)}get el(){return e(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(!n(this.el)){const t=r();c("ifx-content-switcher",await t)}}disconnectedCallback(){this.removeEventListeners()}initializeDividers(){this.items.forEach(((t,i)=>{if(i<this.items.length-1){const i=document.createElement("div");i.classList.add("ifx-content-switcher-divider"),t.after(i),this.dividers.push(i)}}))}addEventListeners(){this.items.forEach(((t,i)=>{const e={click:()=>this.selectItem(i),mouseenter:()=>this.handleHover(i,!0),mouseleave:()=>this.handleHover(i,!1),focus:()=>this.handleFocus(i,!0),blur:()=>this.handleFocus(i,!1)};Object.keys(e).forEach((i=>{t.addEventListener(i,e[i])})),this.eventHandlers.set(t,e)}))}removeEventListeners(){this.eventHandlers.forEach(((t,i)=>{Object.keys(t).forEach((e=>{i.removeEventListener(e,t[e])}))})),this.eventHandlers.clear()}ensureSingleSelectedItem(){this.items.forEach(((t,i)=>{("true"===t.getAttribute("selected")||t.selected)&&(this.activeIndex<0?this.selectItem(i):(t.removeAttribute("selected"),t.selected=!1))}))}handleHover(t,i){this.hoverIndex=i?t:-1,this.updateDividersOfItem(t)}handleFocus(t,i){this.focusIndex=i?t:-1,this.updateDividersOfItem(t)}updateDividersOfItem(t){t<this.items.length-1&&this.updateDividerVisibility(t),t>0&&this.updateDividerVisibility(t-1)}updateDividerVisibility(t){const i=new Set([this.activeIndex,this.activeIndex-1,this.hoverIndex,this.hoverIndex-1,this.focusIndex,this.focusIndex-1]);this.setDividerVisibility(t,i.has(t))}setDividerVisibility(t,i){this.dividers[t]&&this.dividers[t].classList.toggle("hidden",i)}selectItem(t){if(t===this.activeIndex)return;const i=this.activeIndex;i>=0&&this.items[i].removeAttribute("selected"),this.activeIndex=t,this.items[t].setAttribute("selected","true"),this.ifxChange.emit({oldValue:this.getValueOfItem(i),newValue:this.getValueOfItem(t)}),this.updateDividersOfItem(i),this.updateDividersOfItem(t)}getValueOfItem(t){return null==this.items[t]?t.toLocaleString():this.items[t].getAttribute("value")||t.toLocaleString()}render(){return s(h,{key:"b0dd6f378d746ae3ac71be0a8fe1e58cf39a7407"},s("div",{key:"df5fc484b090e510e430065a6bb15fa0351d6e59",class:"ifx-content-switcher",role:"group"},s("slot",{key:"a90f9153551e045becf99c51774fcfee525f825b"})))}};o.style=".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}";export{o as ifx_content_switcher}