/*!
 * KoliBri - The accessible HTML-Standard
 */
import{W as t,w as s,X as i,Y as e,Z as a,m as o,$ as h}from"./index-c3ae175d.js";import{I as n}from"./controller-a5087ab9.js";const r=(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)?r(t,e.options,a):t.set(a,e))}))};class l extends n{constructor(t,e,o){super(t,e,o),this.component=t}validateRequired(e){t(this.component,e)}componentWillLoad(){super.componentWillLoad(),this.validateRequired(this.component._required)}}class c extends l{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(),r(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){s(this.component,"_orientation",(t=>"string"==typeof t&&i.includes(t)),new Set([`Orientation {${i.join(", ")}`]),t,{defaultValue:"vertical"})}validateOptions(t){e(this.component,t,{hooks:{afterPatch:this.afterPatchOptions,beforePatch:this.beforePatchOptions}})}validateValue(t){t=a(t),t=Array.isArray(t)?t[0]:t,o(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(h)}))}},this.validateOrientation(this.component._orientation),this.validateOptions(this.component._options),this.validateValue(this.component._value)}}export{l as I,c as a,r as f};