import{r as o,c as i,h as r,g as t}from"./p-b891c2f1.js";import{F as s}from"./p-8fc67a82.js";let a=0;const e=class{constructor(r){o(this,r),this.scBlur=i(this,"scBlur",7),this.scChange=i(this,"scChange",7),this.scFocus=i(this,"scFocus",7),this.inputId="radio-"+ ++a,this.labelId=`radio-label-${a}`,this.hasFocus=!1,this.disabled=!1,this.checked=!1,this.required=!1,this.invalid=!1}async ceClick(){this.input.click()}async reportValidity(){return this.invalid=!this.input.checkValidity(),this.input.reportValidity()}handleCheckedChange(){this.checked&&this.getSiblingRadios().map((o=>o.checked=!1)),this.input.checked=this.checked,this.scChange.emit()}handleClick(){this.checked=!0}handleBlur(){this.hasFocus=!1,this.scBlur.emit()}handleFocus(){this.hasFocus=!0,this.scFocus.emit()}setCustomValidity(o){this.input.setCustomValidity(o),this.invalid=!this.input.checkValidity()}getAllRadios(){const o=this.el.closest("sc-radio-group");return o?[...o.querySelectorAll("sc-radio")].filter((o=>o.name===this.name)):[]}getSiblingRadios(){return this.getAllRadios().filter((o=>o!==this.el))}handleKeyDown(o){if(["ArrowUp","ArrowDown","ArrowLeft","ArrowRight"].includes(o.key)){const i=this.getAllRadios().filter((o=>!o.disabled)),r=["ArrowUp","ArrowLeft"].includes(o.key)?-1:1;let t=i.indexOf(this.el)+r;t<0&&(t=i.length-1),t>i.length-1&&(t=0),this.getAllRadios().map((o=>o.checked=!1)),i[t].focus(),i[t].checked=!0,o.preventDefault()}}handleMouseDown(o){o.preventDefault(),this.input.focus()}componentDidLoad(){this.formController=new s(this.el,{value:o=>o.checked?o.value:void 0}).addFormData()}disconnectedCallback(){var o;null===(o=this.formController)||void 0===o||o.removeFormData()}render(){return r("label",{part:"base",class:{radio:!0,"radio--checked":this.checked,"radio--disabled":this.disabled,"radio--focused":this.hasFocus},htmlFor:this.inputId,onKeyDown:o=>this.handleKeyDown(o),onMouseDown:o=>this.handleMouseDown(o)},r("span",{part:"control",class:"radio__control"},r("span",{part:"checked-icon",class:"radio__icon"},r("svg",{viewBox:"0 0 16 16"},r("g",{stroke:"none","stroke-width":"1",fill:"none","fill-rule":"evenodd"},r("g",{fill:"currentColor"},r("circle",{cx:"8",cy:"8",r:"3.42857143"}))))),r("input",{id:this.inputId,ref:o=>this.input=o,type:"radio",name:this.name,value:this.value,checked:this.checked,disabled:this.disabled,required:this.required,"aria-checked":this.checked?"true":"false","aria-disabled":this.disabled?"true":"false","aria-labelledby":this.labelId,onClick:()=>this.handleClick(),onBlur:()=>this.handleBlur(),onFocus:()=>this.handleFocus()})),r("span",{part:"label",id:this.labelId,class:"radio__label"},r("slot",null)))}get el(){return t(this)}static get watchers(){return{checked:["handleCheckedChange"]}}};e.style=":host{display:inline-block}.radio{display:inline-flex;align-items:center;font-family:var(--sc-input-font-family);font-size:var(--sc-input-font-size-medium);font-weight:var(--sc-input-font-weight);color:var(--sc-input-color);vertical-align:middle;cursor:pointer}.radio__icon{display:inline-flex;width:var(--sc-radio-size);height:var(--sc-radio-size)}.radio__icon svg{width:100%;height:100%}.radio__control{flex:0 0 auto;position:relative;display:inline-flex;align-items:center;justify-content:center;width:var(--sc-radio-size);height:var(--sc-radio-size);border:solid var(--sc-input-border-width) var(--sc-input-border-color);border-radius:50%;background-color:var(--sc-input-background-color);color:transparent;transition:var(--sc-transition-fast) border-color, var(--sc-transition-fast) opacity, var(--sc-transition-fast) background-color, var(--sc-transition-fast) color, var(--sc-transition-fast) box-shadow}.radio__control input[type=radio]{position:absolute;opacity:0;padding:0;margin:0;pointer-events:none}.radio:not(.radio--checked):not(.radio--disabled) .radio__control:hover{border-color:var(--sc-input-border-color-hover);background-color:var(--sc-input-background-color-hover)}.radio.radio--focused:not(.radio--checked):not(.radio--disabled) .radio__control{border-color:var(--sc-input-border-color-focus);background-color:var(--sc-input-background-color-focus);box-shadow:0 0 0 var(--sc-focus-ring-width) var(--sc-focus-ring-color-primary)}.radio--checked .radio__control{color:var(--sc-color-white);border-color:var(--sc-color-primary-500);background-color:var(--sc-color-primary-500)}.radio.radio--checked:not(.radio--disabled) .radio__control:hover{opacity:0.8}.radio.radio--checked:not(.radio--disabled).radio--focused .radio__control{border-color:var(--sc-color-white);background-color:var(--sc-color-primary-500);box-shadow:0 0 0 var(--sc-focus-ring-width) var(--sc-focus-ring-color-primary)}.radio--disabled{opacity:0.5;cursor:not-allowed}.radio:not(.radio--checked) svg circle{opacity:0}.radio__label{line-height:var(--sc-radio-size);margin-left:0.5em;user-select:none}";export{e as sc_radio}