/*!
 * KoliBri - The accessible HTML-Standard
 */
"use strict";const index=require("./index-7215e5f8.js"),controller=require("./controller-3ebac0f5.js"),fillKeyOptionMap=(t,e,o="")=>{e.forEach(((e,i)=>{const n=`${o}-${i}`;"object"==typeof e&&null!==e&&"string"==typeof e.label&&e.label.length>0&&(Array.isArray(e.options)?fillKeyOptionMap(t,e.options,n):t.set(n,e))}))};class InputCheckboxRadioController extends controller.InputController{constructor(t,e,o){super(t,e,o),this.component=t}validateRequired(t){index.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.isValueInOptions=(t,e)=>void 0!==e.find((e=>e.value===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(),fillKeyOptionMap(this.keyOptionMap,o);const t=e.has("_value")?e.get("_value"):this.component.state._value;!1===this.isValueInOptions(t,o)&&(e.set("_value",o[0].value),this.onStateChange())}},this.component=t}validateOrientation(t){index.watchValidator(this.component,"_orientation",(t=>"string"==typeof t&&index.orientationOptions.includes(t)),new Set([`Orientation {${index.orientationOptions.join(", ")}`]),t,{defaultValue:"vertical"})}validateOptions(t){index.validateOptions(this.component,t,{hooks:{afterPatch:this.afterPatchOptions,beforePatch:this.beforePatchOptions}})}validateValue(t){t=index.mapString2Unknown(t),t=Array.isArray(t)?t[0]:t,index.setState(this.component,"_value",t,{afterPatch:this.afterPatchOptions,beforePatch:this.beforePatchOptions})}componentWillLoad(t){super.componentWillLoad(),this.onStateChange=()=>{if("function"==typeof t){const e=setTimeout((()=>{clearTimeout(e),t(index.STATE_CHANGE_EVENT)}))}},this.validateOrientation(this.component._orientation),this.validateOptions(this.component._options),this.validateValue(this.component._value)}}exports.InputCheckboxRadioController=InputCheckboxRadioController,exports.InputRadioController=InputRadioController,exports.fillKeyOptionMap=fillKeyOptionMap;