/*!
 * KoliBri - The accessible HTML-Standard
 */
import { isString, setState, validateChecked, validateIndeterminate, validateLabelAlign, validateVariantInputCheckbox, watchValidator } from "../../schema";
import { InputCheckboxRadioController } from "../input-radio/controller";
export class InputCheckboxController extends InputCheckboxRadioController {
    constructor(component, name, host) {
        super(component, name, host);
        this.setFormAssociatedCheckboxValue = (value) => {
            if (this.component._checked) {
                this.setFormAssociatedValue(value);
            }
            else {
                this.setFormAssociatedValue(null);
            }
        };
        this.component = component;
    }
    validateChecked(value) {
        validateChecked(this.component, value);
        this.setFormAssociatedCheckboxValue(this.component.state._value);
    }
    validateIcons(value) {
        watchValidator(this.component, '_icons', (value) => {
            const v = value;
            return typeof v === 'object' && v !== null && (isString(v.checked, 1) || isString(v.indeterminate, 1) || isString(v.unchecked, 1));
        }, new Set(['InputCheckboxIcons']), value, {
            hooks: {
                beforePatch: (nextValue, nextState, component) => {
                    nextState.set('_icons', Object.assign(Object.assign({}, component.state._icons), nextValue));
                },
            },
        });
    }
    validateIndeterminate(value) {
        validateIndeterminate(this.component, value);
    }
    validateLabelAlign(value) {
        validateLabelAlign(this.component, value);
    }
    validateValue(value) {
        setState(this.component, '_value', value);
        this.setFormAssociatedCheckboxValue(this.component.state._value);
    }
    validateVariant(value) {
        validateVariantInputCheckbox(this.component, value);
    }
    componentWillLoad() {
        super.componentWillLoad();
        this.validateChecked(this.component._checked);
        this.validateIcons(this.component._icons);
        this.validateIndeterminate(this.component._indeterminate);
        this.validateValue(this.component._value);
        this.validateVariant(this.component._variant);
        this.validateLabelAlign(this.component._labelAlign);
    }
}
//# sourceMappingURL=controller.js.map
