<template>
    <v-textarea
        ref="Control"
        auto-grow
        no-resize
        rows="3"
        :hide-details="control.hideDetails"
        :dense="control.dense"
        :outlined="control.outlined"
        :maxlength="control.maxlength"
        :clearable="control.clearable"
        :persistent-hint="control.persistentHint"
        :hint="control.hint"
        :error-messages="localeErrors"
        
        v-model="localValue"

        @focus="$emit('focus')"
        @blur="$emit('blur')"
    >
        <template #label v-if="control.label">
            <cs-label 
                :control="control"
            />
        </template>
    </v-textarea>
</template>

<script>
    export default {

        props: {
            control: {required: true},

            value: {required: true},

            errors: {default: null},
        },

        computed: {
            localValue: {
                get: function() {
                    return this.value;
                },

                set: function(value) {
                    return this.$emit('input', value);
                }
            },

            localeErrors() {
                return _.map(this.errors, error => this.__(error))
            }
        },

        methods: {
            Focus() {
                setTimeout( () => {
                    this.$refs.Control.focus();
                }, 1)
            }
        },

        components: {
            CsLabel: require('./../labels/CsLabel').default,
        },

        name: 'CsEditBox',
    }
</script>