import { r as registerInstance, c as createEvent, h, H as Host } from './index-CV0Pyo1O.js';
import { F as inputCheckboxInvalid, G as inputCheckboxCheckedFocused, H as inputCheckboxFocused, I as inputCheckboxChecked, J as inputCheckbox, x as label } from './parts-CPKMvyV_.js';
import { F as FormControlHelpText } from './form-control-help-text-DGMpMuAm.js';
import { F as FormControlErrorText } from './form-control-error-text-Di9QePY5.js';
import './event-types-CZfYo5-1.js';

const FormControlCheckbox = class {
    constructor(hostRef) {
        registerInstance(this, hostRef);
        this.formControlInput = createEvent(this, "formControlInput", 7);
        this.formControlBlur = createEvent(this, "formControlBlur", 7);
        this.isFocused = false;
        this.errorText = '';
        this.inputHandler = () => { };
        this.disabled = false;
        this.handleFormControlInput = (event) => {
            event.preventDefault();
            const target = event.target;
            const name = target.getAttribute('name');
            this.inputHandler(name, target.checked);
            this.formControlInput.emit({ name, value: target.value });
        };
        this.updateInput = (newValue) => {
            this.checkboxElement.checked = newValue;
        };
    }
    get part() {
        if (this.errorText) {
            return inputCheckboxInvalid;
        }
        if (this.isFocused && this.checked) {
            return inputCheckboxCheckedFocused;
        }
        if (this.isFocused) {
            return inputCheckboxFocused;
        }
        if (this.checked) {
            return inputCheckboxChecked;
        }
        return inputCheckbox;
    }
    render() {
        return (h(Host, { key: 'dc2fdbd7fd92a0205b15e4b302458d8f0d775b35' }, h("div", { key: 'f32f7d5cb559282cece071f3623bdab80998bc04', class: 'form-group d-flex flex-column' }, h("div", { key: '5481439484b97ad733a0051f1722a5c3ed45778d', class: "form-check" }, h("input", { key: '9e96a563e5b0b1a9589dff7eb4f3eb3038d4918b', ref: el => (this.checkboxElement = el), type: "checkbox", id: this.name, name: this.name, onFocus: () => this.isFocused = true, onBlur: () => {
                this.isFocused = false;
                this.formControlBlur.emit();
            }, onInput: this.handleFormControlInput, part: this.part, class: this.errorText ? 'form-check-input is-invalid' : 'form-check-input', disabled: this.disabled, checked: this.checked }), h("label", { key: '11a27a415d7741d8a29dde8d1fd029c2e143f235', class: "form-check-label", htmlFor: this.name, part: label }, this.label)), h(FormControlHelpText, { key: '3e0ef15182200a48d3cf3142c3511a0ad8095db3', helpText: this.helpText, name: this.name }), h(FormControlErrorText, { key: 'e85175ea76f6073d7ee813a3f2d8eaecc044601a', errorText: this.errorText, name: this.name }))));
    }
};

export { FormControlCheckbox as form_control_checkbox };
