import { proxyCustomElement, HTMLElement, createEvent, h, Host } from '@stencil/core/internal/client';
import { G as inputCheckboxInvalid, H as inputCheckboxCheckedFocused, I as inputCheckboxFocused, J as inputCheckboxChecked, K as inputCheckbox, l as label } from './parts.js';
import { F as FormControlHelpText } from './form-control-help-text2.js';
import { F as FormControlErrorText } from './form-control-error-text.js';
import './justifi-details2.js';
import './event-types.js';
import './justifi-radio-list-item2.js';

const FormControlCheckbox = /*@__PURE__*/ proxyCustomElement(class FormControlCheckbox extends HTMLElement {
    constructor(registerHost) {
        super();
        if (registerHost !== false) {
            this.__registerHost();
        }
        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 }))));
    }
}, [256, "form-control-checkbox", {
        "label": [1],
        "name": [8],
        "helpText": [1, "help-text"],
        "errorText": [1, "error-text"],
        "checked": [4],
        "inputHandler": [16],
        "disabled": [4],
        "isFocused": [32]
    }]);
function defineCustomElement() {
    if (typeof customElements === "undefined") {
        return;
    }
    const components = ["form-control-checkbox"];
    components.forEach(tagName => { switch (tagName) {
        case "form-control-checkbox":
            if (!customElements.get(tagName)) {
                customElements.define(tagName, FormControlCheckbox);
            }
            break;
    } });
}
defineCustomElement();

export { FormControlCheckbox as F, defineCustomElement as d };
