/*!
 * KoliBri - The accessible HTML-Standard
 */
import{I as InputController}from"./getRenderStates.js";import{a as a11yHint,j as watchJsonArrayString,c as watchBoolean,w as watchValidator,y as mapString2Unknown,s as setState}from"./prop.validators.js";import{b as hasEnoughReadableChars,c as containsOnlyNumbers}from"./label.js";const validateInputSelectOptions=t=>{if("object"==typeof t&&null!==t){if("string"==typeof t.label&&t.label.length>0)return t.disabled=!0===t.disabled,t.label=`${t.label}`.trim(),!1===hasEnoughReadableChars(t.label,3)&&!1===containsOnlyNumbers(t.label)&&a11yHint(`A differing Aria-Label (${t.label}) is not accessible. A differing Aria-Label should consist of at least three readable characters.`),!Array.isArray(t.options)||void 0===t.options.find((t=>!1===validateInputSelectOptions(t)));if("number"==typeof t.label)return!0}return!1},validateOptions=(t,e,o={})=>{watchJsonArrayString(t,"_options",(t=>"object"==typeof t&&null!==t&&"string"==typeof t.label&&t.label.length>0),e,void 0,o)},validateOptionsWithOptgroup=(t,e,o={})=>{watchJsonArrayString(t,"_options",validateInputSelectOptions,e,void 0,o)},validateRequired=(t,e)=>{watchBoolean(t,"_required",e)},orientationOptions=["horizontal","vertical"],fillKeyOptionMap=(t,e,o="")=>{e.forEach(((e,a)=>{const i=`${o}-${a}`;"object"==typeof e&&null!==e&&"string"==typeof e.label&&e.label.length>0&&(Array.isArray(e.options)?fillKeyOptionMap(t,e.options,i):t.set(i,e))}))};class InputCheckboxRadioController extends InputController{constructor(t,e,o){super(t,e,o),this.component=t}validateRequired(t){validateRequired(this.component,t)}componentWillLoad(){super.componentWillLoad(),this.validateRequired(this.component._required)}}class InputRadioController extends InputCheckboxRadioController{constructor(t,e,o){super(t,e,o),this.keyOptionMap=new Map,this.getOptionByKey=t=>this.keyOptionMap.get(t),this.afterPatchOptions=(t,e,o,a)=>{"_value"===a&&this.setFormAssociatedValue(t)},this.beforePatchOptions=(t,e)=>{const o=e.has("_options")?e.get("_options"):this.component.state._options;Array.isArray(o)&&o.length>0&&(this.keyOptionMap.clear(),fillKeyOptionMap(this.keyOptionMap,o))},this.component=t}validateOrientation(t){watchValidator(this.component,"_orientation",(t=>"string"==typeof t&&orientationOptions.includes(t)),new Set([`Orientation {${orientationOptions.join(", ")}`]),t,{defaultValue:"vertical"})}validateOptions(t){validateOptions(this.component,t,{hooks:{afterPatch:this.afterPatchOptions,beforePatch:this.beforePatchOptions}})}validateValue(t){t=mapString2Unknown(t),t=Array.isArray(t)?t[0]:t,setState(this.component,"_value",t,{afterPatch:this.afterPatchOptions,beforePatch:this.beforePatchOptions})}componentWillLoad(){super.componentWillLoad(),this.validateOrientation(this.component._orientation),this.validateOptions(this.component._options),this.validateValue(this.component._value)}}export{InputCheckboxRadioController as I,InputRadioController as a,validateOptions as b,fillKeyOptionMap as f,validateOptionsWithOptgroup as v};