'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 FormControlDate = 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.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 = parts.input;
        if (this.errorText) {
            part = parts.inputInvalid;
        }
        if (this.disabled) {
            part = parts.inputDisabled;
        }
        if (this.isFocused) {
            part = parts.inputFocused;
        }
        return part;
    }
    render() {
        return (index.h(index.Host, { key: 'a7bf2b14b5b1d29ea4ae370c440d9fbeac550ca4' }, index.h("div", { key: 'bdb2162f367f5fdec34fae2d8732d084958246da', class: "form-group d-flex flex-column" }, index.h("div", { key: 'eb9483d77d8f1d1effd3278b83e4540b6017ee4c', class: "d-flex gap-2" }, index.h("label", { key: '2947a82052e88c4bb44d9d32e409d7a39baf157f', part: parts.label, class: "form-label", htmlFor: this.name }, this.label), index.h("form-control-tooltip", { key: 'edfbc6ddb02cb5d70abd0867f8da8bab860ba598', helpText: this.helpText })), index.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 }), index.h(formControlErrorText.FormControlErrorText, { key: '8837370dd05097b6d43489855ac87eff8270ae25', errorText: this.errorText, name: this.name }))));
    }
    static get watchers() { return {
        "defaultValue": ["handleDefaultValueChange"]
    }; }
};

exports.form_control_date = FormControlDate;
