import*as t from"lit";import*as e from"lit/decorators.js";var s,i,r={2890(t,e,s){s.d(e,{e:()=>i});var i,r=s(2900),o=s(7704),n=s(4084),d=s(2927),l=s(8899),a=s(2670),c=function(t,e,s,i){var r,o=arguments.length,n=o<3?e:null===i?i=Object.getOwnPropertyDescriptor(e,s):i;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)n=Reflect.decorate(t,e,s,i);else for(var d=t.length-1;d>=0;d--)(r=t[d])&&(n=(o<3?r(n):o>3?r(e,s,n):r(e,s))||n);return o>3&&n&&Object.defineProperty(e,s,n),n};!function(t){let e=class extends((0,o.TS)((0,o.yC)(d.LitElement))){constructor(){super(...arguments),this.active=0,this.tabIndex=0,this.newMomentum=!1,this._disabled=!1}get disabled(){return this._disabled}set disabled(t){const e=this._disabled;this._disabled=t,this.setAttribute("aria-disabled",`${t}`),this.tabIndex=t?-1:0,this.requestUpdate("disabled",e)}get slotElement(){return this.buttonSlot}static get styles(){return[n.A,a.A]}firstUpdated(t){super.firstUpdated(t),this.setAttribute("role","group")}setButtonTabIndex(){this.slotted.forEach(t=>t.tabIndex=-1)}updated(t){super.updated(t),t.has("slotted")&&(this.setButtonTabIndex(),this.setFirstActive())}get selectedBtnValue(){return this.slotted[this.active].value}notifySelectedChange(){this.dispatchEvent(new CustomEvent("button-group-change",{detail:{selected:this.selectedBtnValue},bubbles:!0,composed:!0})),this.dispatchEvent(new CustomEvent("focus-visible",{composed:!0,bubbles:!0}))}setSelected(t){var e,s;const i=this.findSelectedBtnIndex();-1!==i&&i!==t&&(null===(e=this.slotted[i])||void 0===e||e.toggleAttribute("selected",!1)),null===(s=this.slotted[t])||void 0===s||s.toggleAttribute("selected",!0)}setFirstActive(){-1===this.findSelectedBtnIndex()&&this.setSelected(this.active)}findBtnIndex(t){const e=t.composedPath();return this.slotted.findIndex(t=>e.includes(t))}findSelectedBtnIndex(){return this.slotted.findIndex(t=>t.hasAttribute("selected"))}isBtnDisabled(t){return this.slotted[t].disabled}connectedCallback(){super.connectedCallback(),this.addEventListener("keydown",this.handleKeyDown),this.addEventListener("click",this.handleClick)}disconnectedCallback(){super.disconnectedCallback(),this.removeEventListener("keydown",this.handleKeyDown),this.removeEventListener("click",this.handleClick)}switchBtnOnArrowPress(t,e=1){const s=this.getAvailableSelectedIndex(t,e);-1!==s&&(this.active=s,this.setSelected(s),this.notifySelectedChange())}getAvailableSelectedIndex(t,e=1){const s=this.slotted.length;for(let i=0,r=t;i<s;i+=1,r+=e){r<0?r=s-1:r>=s&&(r=0);const t=this.slotted[r];if(this.isFocusable(t))return r}return-1}isFocusable(t){return!t.hasAttribute("disabled")&&!t.hasAttribute("hidden")}handleClick(t){const e=this.findBtnIndex(t);-1!==e&&(this.isBtnDisabled(e)||(this.active=e,this.setSelected(e),this.notifySelectedChange()))}handleKeyDown(t){const{code:e}=t;switch(e){case r.Uz.Enter:case r.Uz.Space:this.isBtnDisabled(this.active)||(this.setSelected(this.active),this.notifySelectedChange());break;case r.Uz.ArrowLeft:0===this.active?this.switchBtnOnArrowPress(this.slotted.length-1,-1):this.switchBtnOnArrowPress(this.active-1,-1);break;case r.Uz.ArrowRight:this.active===this.slotted.length-1?this.switchBtnOnArrowPress(0):this.switchBtnOnArrowPress(this.active+1)}}render(){return d.html`
        <div role="group" class="md-button-group" part="button-group">
          <slot name="button"></slot>
        </div>
      `}};c([(0,l.property)({type:Number,reflect:!0})],e.prototype,"active",void 0),c([(0,l.property)({type:Number,reflect:!0})],e.prototype,"tabIndex",void 0),c([(0,l.property)({type:Boolean,reflect:!0})],e.prototype,"newMomentum",void 0),c([(0,l.query)("slot[name='button']")],e.prototype,"buttonSlot",void 0),c([(0,l.property)({type:Boolean,reflect:!0})],e.prototype,"disabled",null),e=c([(0,o.wW)("md-button-group")],e),t.ELEMENT=e}(i||(i={}))},2927(e,s,i){var r,o;e.exports=(r={LitElement:()=>t.LitElement,css:()=>t.css,html:()=>t.html},o={},i.d(o,r),o)},7704(t,e,s){s.d(e,{TS:()=>r.T,wW:()=>o.w,yC:()=>i.y}),s(2364);var i=s(3203),r=(s(9938),s(5201),s(4781),s(608)),o=s(9609)},8899(t,s,i){var r,o;t.exports=(r={property:()=>e.property,query:()=>e.query},o={},i.d(o,r),o)}},o={};function n(t){var e=o[t];if(void 0!==e)return e.exports;var s=o[t]={exports:{}};return r[t](s,s.exports,n),s.exports}n.m=r,s=[],n.O=(t,e,i,r)=>{if(!e){var o=1/0;for(c=0;c<s.length;c++){for(var[e,i,r]=s[c],d=!0,l=0;l<e.length;l++)(!1&r||o>=r)&&Object.keys(n.O).every(t=>n.O[t](e[l]))?e.splice(l--,1):(d=!1,r<o&&(o=r));if(d){s.splice(c--,1);var a=i();void 0!==a&&(t=a)}}return t}r=r||0;for(var c=s.length;c>0&&s[c-1][2]>r;c--)s[c]=s[c-1];s[c]=[e,i,r]},n.d=(t,e)=>{for(var s in e)n.o(e,s)&&!n.o(t,s)&&Object.defineProperty(t,s,{enumerable:!0,get:e[s]})},n.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e);export{n as __webpack_require__};i={561:0,2942:0,5310:0,5323:0,7704:0,8180:0},n.C=t=>{var e,s,{__webpack_esm_ids__:r,__webpack_esm_modules__:o,__webpack_esm_runtime__:d}=t,l=0;for(e in o)n.o(o,e)&&(n.m[e]=o[e]);for(d&&d(n);l<r.length;l++)s=r[l],n.o(i,s)&&i[s]&&i[s][0](),i[r[l]]=0;n.O()},n.O.j=t=>0===i[t];import*as d from"../9609.js";n.C(d);import*as l from"../4084.js";n.C(l);import*as a from"../2364.js";n.C(a);import*as c from"../9938.js";n.C(c);import*as h from"../4781.js";n.C(h);import*as p from"../5201.js";n.C(p);import*as u from"../5584.js";n.C(u);import*as b from"../2900.js";n.C(b);import*as v from"../608.js";n.C(v);import*as f from"../2670.js";n.C(f);var m=n.O(void 0,[9609,4084,2364,9938,4781,5201,5584,2900,608,2670],()=>n(2890));const y=(m=n.O(m)).e;export{y as ButtonGroup};