<template>
    <label>
        <span :style="{ width: width + 'em' }">{{ $t(labelTr) }}</span>
        <input type="date" v-model="internalValue" :placeholder="$t(labelTr)" :title="$t(tooltipTr)"
            :disabled="disabled" @change="updateValue($event.target.value)" />
    </label>
</template>

<script>
import { mapGetters } from 'vuex';

export default {
    name: "DateInputWidget",
    props: {
        labelTr: {
            type: String,
            required: true,
        },
        value: {
            type: String,
            required: false,
        },
        tooltipTr: {
            type: String,
            required: true,
        },
        width: {
            type: Number,
            required: false,
            default: 10
        },
        disabled: {
            type: Boolean,
            required: false,
            default: false
        }
    },
    data() {
        return {
            internalValue: this.value
        }
    },
    watch: {
        value(newValue) {
            this.internalValue = newValue;
        }
    },
    computed: {
        ...mapGetters(['language']),
    },
    methods: {
        updateValue(value) {
            this.internalValue = value;
            this.$emit("input", value);
        }
    }
};
</script>

<style scoped>
label {
    display: block;
}

label>span {
    display: inline-block;
}

input {
    margin-left: 0.5em;
}
</style>
