/*!
 * KoliBri - The accessible HTML-Standard
 */
"use strict";var common=require("./common-Cd2qH809.js"),label=require("./label-Nicf9N_T.js"),required=require("./required-CXU7vdyH.js"),orientation=require("./orientation-BGODo_Ua.js"),FormFieldStateWrapper=require("./FormFieldStateWrapper-BeAW0hiT.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===label.hasEnoughReadableChars(t.label,3)&&!1===label.containsOnlyNumbers(t.label)&&common.a11yHint(`A differing Aria-Label (${t.label}) is inaccessible. 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={})=>{common.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={})=>{common.watchJsonArrayString(t,"_options",validateInputSelectOptions,e,void 0,o)},fillKeyOptionMap=(t,e,o="")=>{e.forEach((e,i)=>{const a=`${o}-${i}`;"object"==typeof e&&null!==e&&"string"==typeof e.label&&e.label.length>0&&(Array.isArray(e.options)?fillKeyOptionMap(t,e.options,a):t.set(a,e))})};class InputCheckboxRadioController extends FormFieldStateWrapper.InputController{constructor(t,e,o){super(t,e,o),this.component=t}validateRequired(t){required.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,i)=>{"_value"===i&&this.setFormAssociatedValue(t)},this.beforePatchOptions=(t,e)=>{const o=e.has("_options")?e.get("_options"):this.component.state._options;if(Array.isArray(o)&&o.length>0){this.keyOptionMap.clear();const t=o.map(t=>{var e;return"object"==typeof t&&null!==t&&"string"==typeof t.label?Object.assign(Object.assign({},t),{value:null!==(e=t.value)&&void 0!==e?e:t.label}):t});fillKeyOptionMap(this.keyOptionMap,t)}},this.component=t}validateOrientation(t){orientation.validateOrientation(this.component,t,"vertical")}validateOptions(t){validateOptions(this.component,t,{hooks:{afterPatch:this.afterPatchOptions,beforePatch:this.beforePatchOptions}})}validateValue(t){t=Array.isArray(t)?t[0]:t,common.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;