import { proxyCustomElement, HTMLElement, createEvent, h, Host } from '@stencil/core/internal/client';
import { b as inputInvalid, c as inputDisabled, d as inputFocused, e as input, l as label } from './parts.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';
import { d as defineCustomElement$2 } from './custom-popper2.js';
import { d as defineCustomElement$1 } from './form-control-tooltip2.js';

const FormControlText = /*@__PURE__*/ proxyCustomElement(class FormControlText 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.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.errorText) {
            return inputInvalid;
        }
        if (this.disabled) {
            return inputDisabled;
        }
        if (this.isFocused) {
            return inputFocused;
        }
        return input;
    }
    render() {
        return (h(Host, { key: '5732a2a92dd945b8520e277bf10e22ea296b0949' }, h("div", { key: '9f58456015584c0cd945686e8bc7d629f46a39a2', class: "form-group d-flex flex-column" }, h("div", { key: '1dccca5e3f97a41e895e7572f24f0e21d2b912c1', class: "d-flex align-items-start gap-2" }, h("label", { key: '54d52a444a22f460579911ecf869633b041bcab9', part: label, class: "form-label", htmlFor: this.name }, this.label), h("form-control-tooltip", { key: '65f9c29cb659be24d88697c72dac422c70431209', helpText: this.helpText })), h("input", { key: 'ba4b46b0e3e66112ed90e64425de6fd9c97559d2', id: this.name, name: this.name, onFocus: () => this.isFocused = true, onBlur: () => {
                this.isFocused = false;
                this.formControlBlur.emit();
            }, onInput: this.handleFormControlInput, onKeyDown: this.keyDownHandler, onPaste: this.keyDownHandler, maxLength: this.maxLength, part: this.part, class: this.errorText ? "form-control is-invalid" : "form-control", type: "text", disabled: this.disabled }), h(FormControlErrorText, { key: 'f7bf2c8f5f1c30cfdc4e6c2927434a50f7f58add', errorText: this.errorText, name: this.name }))));
    }
    get el() { return this; }
    static get watchers() { return {
        "defaultValue": ["handleDefaultValueChange"]
    }; }
}, [256, "form-control-text", {
        "name": [8],
        "label": [1],
        "inputHandler": [16],
        "defaultValue": [1, "default-value"],
        "helpText": [1, "help-text"],
        "errorText": [1, "error-text"],
        "maxLength": [2, "max-length"],
        "keyDownHandler": [16],
        "disabled": [4],
        "isFocused": [32]
    }, undefined, {
        "defaultValue": ["handleDefaultValueChange"]
    }]);
function defineCustomElement() {
    if (typeof customElements === "undefined") {
        return;
    }
    const components = ["form-control-text", "custom-popper", "form-control-tooltip"];
    components.forEach(tagName => { switch (tagName) {
        case "form-control-text":
            if (!customElements.get(tagName)) {
                customElements.define(tagName, FormControlText);
            }
            break;
        case "custom-popper":
            if (!customElements.get(tagName)) {
                defineCustomElement$2();
            }
            break;
        case "form-control-tooltip":
            if (!customElements.get(tagName)) {
                defineCustomElement$1();
            }
            break;
    } });
}
defineCustomElement();

export { FormControlText as F, defineCustomElement as d };
