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 FormControlDate = /*@__PURE__*/ proxyCustomElement(class FormControlDate 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.maxDate = this.currentDate;
        this.handleFormControlInput = (event) => {
            const dateValue = event.target.value;
            this.inputHandler(this.name, dateValue);
            this.formControlInput.emit({ name: this.name, value: dateValue });
        };
    }
    handleDefaultValueChange(newValue) {
        this.updateInput(newValue);
    }
    get currentDate() {
        if (!this.showTime) {
            return new Date().toISOString().split('T')[0];
        }
        else {
            return new Date().toISOString().slice(0, 16);
        }
    }
    componentDidLoad() {
        this.updateInput(this.defaultValue);
    }
    updateInput(value) {
        this.dateInput.value = value;
    }
    get part() {
        let part = input;
        if (this.errorText) {
            part = inputInvalid;
        }
        if (this.disabled) {
            part = inputDisabled;
        }
        if (this.isFocused) {
            part = inputFocused;
        }
        return part;
    }
    render() {
        return (h(Host, { key: 'a7bf2b14b5b1d29ea4ae370c440d9fbeac550ca4' }, h("div", { key: 'bdb2162f367f5fdec34fae2d8732d084958246da', class: "form-group d-flex flex-column" }, h("div", { key: 'eb9483d77d8f1d1effd3278b83e4540b6017ee4c', class: "d-flex gap-2" }, h("label", { key: '2947a82052e88c4bb44d9d32e409d7a39baf157f', part: label, class: "form-label", htmlFor: this.name }, this.label), h("form-control-tooltip", { key: 'edfbc6ddb02cb5d70abd0867f8da8bab860ba598', helpText: this.helpText })), h("input", { key: '2a2d8d464e330ae2ba56f76dadede59c180cdcb6', type: this.showTime ? 'datetime-local' : 'date', ref: el => (this.dateInput = 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-control is-invalid' : 'form-control', disabled: this.disabled, max: this.maxDate }), h(FormControlErrorText, { key: '8837370dd05097b6d43489855ac87eff8270ae25', errorText: this.errorText, name: this.name }))));
    }
    static get watchers() { return {
        "defaultValue": ["handleDefaultValueChange"]
    }; }
}, [256, "form-control-date", {
        "name": [1],
        "label": [1],
        "inputHandler": [16],
        "defaultValue": [1, "default-value"],
        "helpText": [1, "help-text"],
        "errorText": [1, "error-text"],
        "disabled": [4],
        "showTime": [4, "show-time"],
        "maxDate": [1, "max-date"],
        "isFocused": [32]
    }, undefined, {
        "defaultValue": ["handleDefaultValueChange"]
    }]);
function defineCustomElement() {
    if (typeof customElements === "undefined") {
        return;
    }
    const components = ["form-control-date", "custom-popper", "form-control-tooltip"];
    components.forEach(tagName => { switch (tagName) {
        case "form-control-date":
            if (!customElements.get(tagName)) {
                customElements.define(tagName, FormControlDate);
            }
            break;
        case "custom-popper":
            if (!customElements.get(tagName)) {
                defineCustomElement$2();
            }
            break;
        case "form-control-tooltip":
            if (!customElements.get(tagName)) {
                defineCustomElement$1();
            }
            break;
    } });
}
defineCustomElement();

export { FormControlDate as F, defineCustomElement as d };
