<!--
Champs de saisie de bloc texte

@see https://vuetifyjs.com/en/components/textareas/
-->

<template>
  <v-textarea
      outlined
      :value="data"
      :label="$t(label_field)"
      :rules="rules"
      :disabled="readonly"
      :error="error || violations"
      :error-messages="errorMessage"
      @change="onChange($event)"
    />
</template>

<script lang="ts">
import { defineComponent } from '@nuxtjs/composition-api'
import {$useError} from "~/composables/form/useError";

export default defineComponent({
  props: {
    label: {
      type: String,
      required: false,
      default: null
    },
    field: {
      type: String,
      required: false,
      default: null
    },
    data: {
      type: [String, Number],
      required: false,
      default: null
    },
    readonly: {
      type: Boolean,
      required: false
    },
    rules: {
      type: Array,
      required: false,
      default: () => []
    },
    error: {
      type: Boolean,
      required: false
    },
    errorMessage: {
      type: String,
      required: false,
      default: null
    }
  },
  setup (props, {emit}) {
    const {error: violations, onChange} = $useError(props.field, emit)

    return {
      label_field: props.label ?? props.field,
      violations,
      onChange
    }
  }
})
</script>

<style>
  input:read-only{
    color: #666 !important;
  }
</style>
