import{__decorate as i}from"tslib";import{html as s}from"lit";import{property as t,state as e,customElement as a}from"lit/decorators.js";import{s as h}from"./nile-radio.css.esm.js";import{classMap as l}from"lit/directives/class-map.js";import{w as r}from"../internal/watch.esm.js";import{N as o}from"../internal/nile-element.esm.js";import"../internal/accessibility/a11y.state.enum.esm.js";import"../internal/accessibility/a11y.property.enum.esm.js";import"../internal/accessibility/role.enum.esm.js";let n=class extends o{constructor(){super(...arguments),this.checked=!1,this.hasFocus=!1,this.value="",this.size="medium",this.disabled=!1,this.islabelborder=!1,this.allowUncheck=!1}connectedCallback(){super.connectedCallback(),this.handleBlur=this.handleBlur.bind(this),this.handleClick=this.handleClick.bind(this),this.handleFocus=this.handleFocus.bind(this),this.setInitialAttributes(),this.addEventListeners(),this.emit("nile-init")}disconnectedCallback(){this.removeEventListeners(),this.emit("nile-destroy")}addEventListeners(){this.addEventListener("blur",this.handleBlur),this.addEventListener("click",this.handleClick),this.addEventListener("focus",this.handleFocus)}removeEventListeners(){this.removeEventListener("blur",this.handleBlur),this.removeEventListener("click",this.handleClick),this.removeEventListener("focus",this.handleFocus)}handleBlur(){this.hasFocus=!1,this.emit("nile-blur")}handleClick(){this.allowUncheck&&!this.disabled?this.checked=!this.checked:this.disabled||(this.checked=!0)}handleFocus(){this.hasFocus=!0,this.emit("nile-focus")}setInitialAttributes(){this.setAttribute("role","radio"),this.setAttribute("tabindex","-1"),this.setAttribute("aria-disabled",this.disabled?"true":"false")}handleCheckedChange(){this.setAttribute("aria-checked",this.checked?"true":"false"),this.disabled?this.setAttribute("tabindex","-1"):this.setAttribute("tabindex",this.checked?"0":"-1")}handleDisabledChange(){this.setAttribute("aria-disabled",this.disabled?"true":"false"),this.disabled?(this.setAttribute("tabindex","-1"),this.matches(":focus")&&this.blur()):this.setAttribute("tabindex",this.checked?"0":"-1")}render(){return s`
      <span
        part="base"
        class=${l({radio:!0,"radio--checked":this.checked,"radio--disabled":this.disabled,"radio--focused":this.hasFocus,"radio--medium":"medium"===this.size,radio__label_border:this.islabelborder})}
      >
        <span part="${"control"+(this.checked?" control--checked":"")}" class="radio__control">
          ${this.checked?s` <span class="radio__checked-icon"></span> `:""}
        </span>

        <slot part="label" class="radio__label"></slot>
      </span>
    `}};n.styles=h,i([t({type:Boolean})],n.prototype,"checked",void 0),i([e()],n.prototype,"hasFocus",void 0),i([t()],n.prototype,"value",void 0),i([t({reflect:!0})],n.prototype,"size",void 0),i([t({type:Boolean,reflect:!0})],n.prototype,"disabled",void 0),i([t({type:Boolean,reflect:!0})],n.prototype,"islabelborder",void 0),i([t({type:Boolean,reflect:!0})],n.prototype,"allowUncheck",void 0),i([r("checked")],n.prototype,"handleCheckedChange",null),i([r("disabled",{waitUntilFirstUpdate:!0})],n.prototype,"handleDisabledChange",null),n=i([a("nile-radio")],n);export{n as N};
