/*!
 * KoliBri - The accessible HTML-Standard
 */
import { validateOptions, validatePlaceholder, validateRequired, watchBoolean, watchNumber, watchValidator } from "../../schema";
import { InputIconController } from "../@deprecated/input/controller-icon";
import { fillKeyOptionMap } from "../input-radio/controller";
export class SingleSelectController extends InputIconController {
    constructor(component, name, host) {
        super(component, name, host);
        this.keyOptionMap = new Map();
        this.afterPatchOptions = (value, _state, _component, key) => {
            if (key === '_value') {
                this.setFormAssociatedValue(value);
            }
        };
        this.beforePatchOptions = (_value, nextState) => {
            const options = nextState.has('_options') ? nextState.get('_options') : this.component.state._options;
            if (Array.isArray(options) && options.length > 0) {
                this.keyOptionMap.clear();
                fillKeyOptionMap(this.keyOptionMap, options);
            }
        };
        this.component = component;
    }
    validateOptions(value) {
        validateOptions(this.component, value, {
            hooks: {
                afterPatch: this.afterPatchOptions,
                beforePatch: this.beforePatchOptions,
            },
        });
    }
    validateRequired(value) {
        validateRequired(this.component, value);
    }
    validateValue(value) {
        watchValidator(this.component, '_value', (v) => v !== undefined, new Set([`StencilUnknown`]), value);
    }
    validatePlaceholder(value) {
        validatePlaceholder(this.component, value);
    }
    validateHasClearButton(value) {
        watchBoolean(this.component, '_hasClearButton', value);
    }
    validateRows(value) {
        watchNumber(this.component, '_rows', value);
    }
    componentWillLoad() {
        super.componentWillLoad();
        this.validateOptions(this.component._options);
        this.validateRequired(this.component._required);
        this.validateValue(this.component._value);
        this.validatePlaceholder(this.component._placeholder);
        this.validateHasClearButton(this.component._hasClearButton);
        this.validateRows(this.component._rows);
    }
}
//# sourceMappingURL=controller.js.map
