/*!
 * KoliBri - The accessible HTML-Standard
 */
"use strict";const controller=require("./controller-ef1a645a.js"),prop_validators=require("./prop.validators-37d21dea.js"),label=require("./label-d84e4f92.js"),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===label.hasEnoughReadableChars(t.label,3)&&!1===label.containsOnlyNumbers(t.label)&&prop_validators.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,o,e={})=>{prop_validators.watchJsonArrayString(t,"_options",(t=>"object"==typeof t&&null!==t&&"string"==typeof t.label&&t.label.length>0),o,void 0,e)},validateOptionsWithOptgroup=(t,o,e={})=>{prop_validators.watchJsonArrayString(t,"_options",validateInputSelectOptions,o,void 0,e)},validateRequired=(t,o)=>{prop_validators.watchBoolean(t,"_required",o)},orientationOptions=["horizontal","vertical"],fillKeyOptionMap=(t,o,e="")=>{o.forEach(((o,i)=>{const a=`${e}-${i}`;"object"==typeof o&&null!==o&&"string"==typeof o.label&&o.label.length>0&&(Array.isArray(o.options)?fillKeyOptionMap(t,o.options,a):t.set(a,o))}))};class InputCheckboxRadioController extends controller.InputController{constructor(t,o,e){super(t,o,e),this.component=t}validateRequired(t){validateRequired(this.component,t)}componentWillLoad(){super.componentWillLoad(),this.validateRequired(this.component._required)}}class InputRadioController extends InputCheckboxRadioController{constructor(t,o,e){super(t,o,e),this.keyOptionMap=new Map,this.getOptionByKey=t=>this.keyOptionMap.get(t),this.afterPatchOptions=(t,o,e,i)=>{"_value"===i&&this.setFormAssociatedValue(t)},this.beforePatchOptions=(t,o)=>{const e=o.has("_options")?o.get("_options"):this.component.state._options;Array.isArray(e)&&e.length>0&&(this.keyOptionMap.clear(),fillKeyOptionMap(this.keyOptionMap,e))},this.component=t}validateOrientation(t){prop_validators.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=prop_validators.mapString2Unknown(t),t=Array.isArray(t)?t[0]:t,prop_validators.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)}}exports.InputCheckboxRadioController=InputCheckboxRadioController,exports.InputRadioController=InputRadioController,exports.fillKeyOptionMap=fillKeyOptionMap,exports.validateOptions=validateOptions,exports.validateOptionsWithOptgroup=validateOptionsWithOptgroup;