import{p as t,H as e,c as i,h as s,d as n,t as h}from"./p-CHfEnK-2.js";import{i as c,d as r,t as o}from"./p-94ZtGp9D.js";const d=t(class extends e{constructor(t){super(),!1!==t&&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(!c(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,!0),mouseleave:()=>this.handleHover(e,!1),focus:()=>this.handleFocus(e,!0),blur:()=>this.handleFocus(e,!1)};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)=>{("true"===t.getAttribute("selected")||t.selected)&&(this.activeIndex<0?this.selectItem(e):(t.removeAttribute("selected"),t.selected=!1))}))}handleHover(t,e){this.hoverIndex=e?t:-1,this.updateDividersOfItem(t)}handleFocus(t,e){this.focusIndex=e?t:-1,this.updateDividersOfItem(t)}updateDividersOfItem(t){t<this.items.length-1&&this.updateDividerVisibility(t),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){this.dividers[t]&&this.dividers[t].classList.toggle("hidden",e)}selectItem(t){if(t===this.activeIndex)return;const e=this.activeIndex;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){return null==this.items[t]?t.toLocaleString():this.items[t].getAttribute("value")||t.toLocaleString()}render(){return s(n,{key:"b0dd6f378d746ae3ac71be0a8fe1e58cf39a7407"},s("div",{key:"df5fc484b090e510e430065a6bb15fa0351d6e59",class:"ifx-content-switcher",role:"group"},s("slot",{key:"a90f9153551e045becf99c51774fcfee525f825b"})))}static get style(){return".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}"}},[769,"ifx-content-switcher",{items:[32],activeIndex:[32],hoverIndex:[32],focusIndex:[32],dividers:[32]}]),l=d,a=function(){"undefined"!=typeof customElements&&["ifx-content-switcher"].forEach((t=>{"ifx-content-switcher"===t&&(customElements.get(h(t))||customElements.define(h(t),d))}))};export{l as IfxContentSwitcher,a as defineCustomElement}