import { proxyCustomElement, HTMLElement, createEvent, h, Host } from '@stencil/core/internal/client';
import { v as inputInvalidAndFocused, d as inputFocused, b as inputInvalid, e as input, 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 FormControlNumber = /*@__PURE__*/ proxyCustomElement(class FormControlNumber 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.disabled = false;
        this.handleFormControlInput = (event) => {
            const target = event.target;
            const name = target.getAttribute('name');
            this.inputHandler(name, target.value);
            this.formControlInput.emit({ name, value: target.value });
        };
        this.updateInput = (newValue) => {
            const inputElement = this.el.querySelector('input');
            if (inputElement) {
                inputElement.value = newValue || '';
            }
        };
    }
    handleDefaultValueChange(newValue) {
        this.updateInput(newValue);
    }
    componentDidLoad() {
        this.updateInput(this.defaultValue);
    }
    get part() {
        if (this.isFocused && this.errorText) {
            return inputInvalidAndFocused;
        }
        if (this.isFocused) {
            return inputFocused;
        }
        if (this.errorText) {
            return inputInvalid;
        }
        return input;
    }
    render() {
        return (h(Host, { key: 'a47de1fbb4fbd97b47c4dc934d58a628c65f1dbf' }, h("div", { key: 'bbd063c3f0c68bdad5f1849fed8ac318ebb423ef', class: 'form-group d-flex flex-column' }, h("label", { key: '796cb0253dc523ceb21464f3ce528509abffecfa', part: label, class: "form-label", htmlFor: this.name }, this.label), h("input", { key: '8ceaf162d7db2c639b679a431dea7b962593eb09', 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-control is-invalid' : 'form-control', type: "number", disabled: this.disabled }), h(FormControlHelpText, { key: '6935e075c057a55f0af02051eb97310b187ae807', helpText: this.helpText, name: this.name }), h(FormControlErrorText, { key: '019b48db586768219622e657e121772e4f0203c5', errorText: this.errorText, name: this.name }))));
    }
    get el() { return this; }
    static get watchers() { return {
        "defaultValue": ["handleDefaultValueChange"]
    }; }
}, [256, "form-control-number", {
        "label": [1],
        "name": [8],
        "helpText": [1, "help-text"],
        "errorText": [1, "error-text"],
        "defaultValue": [1, "default-value"],
        "inputHandler": [16],
        "disabled": [4],
        "isFocused": [32]
    }, undefined, {
        "defaultValue": ["handleDefaultValueChange"]
    }]);
function defineCustomElement() {
    if (typeof customElements === "undefined") {
        return;
    }
    const components = ["form-control-number"];
    components.forEach(tagName => { switch (tagName) {
        case "form-control-number":
            if (!customElements.get(tagName)) {
                customElements.define(tagName, FormControlNumber);
            }
            break;
    } });
}
defineCustomElement();

export { FormControlNumber as F, defineCustomElement as d };
