'use strict';

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

const FormControlSelect = 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.handleFormControlInput = (event) => {
            const target = event.target;
            const name = target.getAttribute('name');
            this.inputHandler(name, target.value);
            this.formControlInput.emit(target.value);
        };
        this.updateInput = (newValue) => {
            this.selectElement.value = newValue;
        };
    }
    handleDefaultValueChange(newValue) {
        this.updateInput(newValue);
    }
    componentDidLoad() {
        this.updateInput(this.defaultValue);
    }
    get part() {
        let part = parts.input;
        if (this.errorText) {
            part = parts.inputInvalid;
        }
        if (this.disabled) {
            part = parts.inputDisabled;
        }
        if (this.isFocused) {
            part = parts.inputFocused;
        }
        return part;
    }
    render() {
        var _a;
        return (index.h(index.Host, { key: 'bf6556107b1f272aa6bc4f89cb0f2a889f8b9d1d' }, index.h("div", { key: 'be1644d78987676c9af452831e25c3effc31a67c', class: "form-group d-flex flex-column" }, index.h("div", { key: '62eaea4bdbee959d6e785c00c4f41f642c0a16af', class: "d-flex align-items-start gap-2" }, index.h("label", { key: '641ada798c78ca0c649ec76029c157069636838b', part: parts.label, class: "form-label", htmlFor: this.name }, this.label), index.h("form-control-tooltip", { key: '3a04fe21799a54e402e8afead34b60898c804af4', helpText: this.helpText })), index.h("select", { key: '54188864be36aed540647275cd84eae738eb633f', ref: el => (this.selectElement = el), 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-select is-invalid' : 'form-select', disabled: this.disabled }, (_a = this.options) === null || _a === void 0 ? void 0 : _a.map(option => (index.h("option", { value: option.value }, option.label)))), index.h(formControlErrorText.FormControlErrorText, { key: '387753bf79494f44a91858175af74d48a9e9c051', errorText: this.errorText, name: this.name }))));
    }
    static get watchers() { return {
        "defaultValue": ["handleDefaultValueChange"]
    }; }
};

const FormControlText = 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.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 parts.inputInvalid;
        }
        if (this.disabled) {
            return parts.inputDisabled;
        }
        if (this.isFocused) {
            return parts.inputFocused;
        }
        return parts.input;
    }
    render() {
        return (index.h(index.Host, { key: '5732a2a92dd945b8520e277bf10e22ea296b0949' }, index.h("div", { key: '9f58456015584c0cd945686e8bc7d629f46a39a2', class: "form-group d-flex flex-column" }, index.h("div", { key: '1dccca5e3f97a41e895e7572f24f0e21d2b912c1', class: "d-flex align-items-start gap-2" }, index.h("label", { key: '54d52a444a22f460579911ecf869633b041bcab9', part: parts.label, class: "form-label", htmlFor: this.name }, this.label), index.h("form-control-tooltip", { key: '65f9c29cb659be24d88697c72dac422c70431209', helpText: this.helpText })), index.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 }), index.h(formControlErrorText.FormControlErrorText, { key: 'f7bf2c8f5f1c30cfdc4e6c2927434a50f7f58add', errorText: this.errorText, name: this.name }))));
    }
    get el() { return index.getElement(this); }
    static get watchers() { return {
        "defaultValue": ["handleDefaultValueChange"]
    }; }
};

exports.form_control_select = FormControlSelect;
exports.form_control_text = FormControlText;
