import { proxyCustomElement, HTMLElement, createEvent, h, Host } from '@stencil/core/internal/client';
import { e as input, l as label, b as inputInvalid, c as inputDisabled, d as inputFocused } 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 FormControlSelect = /*@__PURE__*/ proxyCustomElement(class FormControlSelect 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(target.value);
        };
        this.updateInput = (newValue) => {
            this.selectElement.value = newValue;
        };
    }
    handleDefaultValueChange(newValue) {
        this.updateInput(newValue);
    }
    componentDidLoad() {
        this.updateInput(this.defaultValue);
    }
    get part() {
        let part = input;
        if (this.errorText) {
            part = inputInvalid;
        }
        if (this.disabled) {
            part = inputDisabled;
        }
        if (this.isFocused) {
            part = inputFocused;
        }
        return part;
    }
    render() {
        var _a;
        return (h(Host, { key: 'bf6556107b1f272aa6bc4f89cb0f2a889f8b9d1d' }, h("div", { key: 'be1644d78987676c9af452831e25c3effc31a67c', class: "form-group d-flex flex-column" }, h("div", { key: '62eaea4bdbee959d6e785c00c4f41f642c0a16af', class: "d-flex align-items-start gap-2" }, h("label", { key: '641ada798c78ca0c649ec76029c157069636838b', part: label, class: "form-label", htmlFor: this.name }, this.label), h("form-control-tooltip", { key: '3a04fe21799a54e402e8afead34b60898c804af4', helpText: this.helpText })), 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 => (h("option", { value: option.value }, option.label)))), h(FormControlErrorText, { key: '387753bf79494f44a91858175af74d48a9e9c051', errorText: this.errorText, name: this.name }))));
    }
    static get watchers() { return {
        "defaultValue": ["handleDefaultValueChange"]
    }; }
}, [256, "form-control-select", {
        "name": [8],
        "label": [1],
        "options": [16],
        "inputHandler": [16],
        "defaultValue": [1, "default-value"],
        "helpText": [1, "help-text"],
        "errorText": [1, "error-text"],
        "disabled": [4],
        "isFocused": [32]
    }, undefined, {
        "defaultValue": ["handleDefaultValueChange"]
    }]);
function defineCustomElement() {
    if (typeof customElements === "undefined") {
        return;
    }
    const components = ["form-control-select", "custom-popper", "form-control-tooltip"];
    components.forEach(tagName => { switch (tagName) {
        case "form-control-select":
            if (!customElements.get(tagName)) {
                customElements.define(tagName, FormControlSelect);
            }
            break;
        case "custom-popper":
            if (!customElements.get(tagName)) {
                defineCustomElement$2();
            }
            break;
        case "form-control-tooltip":
            if (!customElements.get(tagName)) {
                defineCustomElement$1();
            }
            break;
    } });
}
defineCustomElement();

export { FormControlSelect as F, defineCustomElement as d };
