import { proxyCustomElement, HTMLElement, createEvent, h, Host } from '@stencil/core/internal/client';
import { v as inputInvalidAndFocused, b as inputInvalid, d as inputFocused, c as inputDisabled, e as input, l as label } from './parts.js';
import { d as defineCustomElement$1 } from './form-control-help-text3.js';

const FormControlTextarea = /*@__PURE__*/ proxyCustomElement(class FormControlTextarea 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.helpText = '';
        this.errorText = '';
        this.inputHandler = () => { };
        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('textarea');
            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.errorText) {
            return inputInvalid;
        }
        if (this.isFocused) {
            return inputFocused;
        }
        if (this.disabled) {
            return inputDisabled;
        }
        return input;
    }
    render() {
        return (h(Host, { key: 'f6c4833f4a582e5b310b89356716acce6ef24f8f' }, h("div", { key: 'dc576c3df86ede178fef9dd2975ea2307fd1bd5f', class: "form-group d-flex flex-column" }, h("label", { key: '4217d6bbe9fb6331c2ab5e9d043659079a7af1dc', part: label, class: "form-label", htmlFor: this.name }, this.label), h("textarea", { key: '42ab7f076431ee0a1e744eb648de1590e39554f7', 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', disabled: this.disabled }), h("form-control-help-text", { key: 'a1d8a2b674e5faf81c778a07ca270094f77e7281', helpText: this.helpText, name: this.name }), h("form-control-error-text", { key: 'a47839b4edc4007b6c9dfc1b6689dd1e1750cc60', errorText: this.errorText, name: this.name }))));
    }
    get el() { return this; }
    static get watchers() { return {
        "defaultValue": ["handleDefaultValueChange"]
    }; }
}, [256, "form-control-textarea", {
        "label": [1],
        "name": [8],
        "helpText": [1, "help-text"],
        "errorText": [1, "error-text"],
        "defaultValue": [1, "default-value"],
        "maxLength": [2, "max-length"],
        "inputHandler": [16],
        "keyDownHandler": [16],
        "disabled": [4],
        "isFocused": [32]
    }, undefined, {
        "defaultValue": ["handleDefaultValueChange"]
    }]);
function defineCustomElement() {
    if (typeof customElements === "undefined") {
        return;
    }
    const components = ["form-control-textarea", "form-control-help-text"];
    components.forEach(tagName => { switch (tagName) {
        case "form-control-textarea":
            if (!customElements.get(tagName)) {
                customElements.define(tagName, FormControlTextarea);
            }
            break;
        case "form-control-help-text":
            if (!customElements.get(tagName)) {
                defineCustomElement$1();
            }
            break;
    } });
}
defineCustomElement();

export { FormControlTextarea as F, defineCustomElement as d };
