'use strict';

var index = require('./index-p7cvUYAE.js');
var parts = require('./parts-BXshb_S-.js');
var formControlHelpText = require('./form-control-help-text-BdbTxD5g.js');
var formControlErrorText = require('./form-control-error-text-BO58Y6zF.js');
require('./event-types-YOY5TKUN.js');

const FormControlCheckbox = class {
    constructor(hostRef) {
        index.registerInstance(this, hostRef);
        this.formControlInput = index.createEvent(this, "formControlInput", 7);
        this.formControlBlur = index.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 parts.inputCheckboxInvalid;
        }
        if (this.isFocused && this.checked) {
            return parts.inputCheckboxCheckedFocused;
        }
        if (this.isFocused) {
            return parts.inputCheckboxFocused;
        }
        if (this.checked) {
            return parts.inputCheckboxChecked;
        }
        return parts.inputCheckbox;
    }
    render() {
        return (index.h(index.Host, { key: 'dc2fdbd7fd92a0205b15e4b302458d8f0d775b35' }, index.h("div", { key: 'f32f7d5cb559282cece071f3623bdab80998bc04', class: 'form-group d-flex flex-column' }, index.h("div", { key: '5481439484b97ad733a0051f1722a5c3ed45778d', class: "form-check" }, index.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 }), index.h("label", { key: '11a27a415d7741d8a29dde8d1fd029c2e143f235', class: "form-check-label", htmlFor: this.name, part: parts.label }, this.label)), index.h(formControlHelpText.FormControlHelpText, { key: '3e0ef15182200a48d3cf3142c3511a0ad8095db3', helpText: this.helpText, name: this.name }), index.h(formControlErrorText.FormControlErrorText, { key: 'e85175ea76f6073d7ee813a3f2d8eaecc044601a', errorText: this.errorText, name: this.name }))));
    }
};

exports.form_control_checkbox = FormControlCheckbox;
