<!--
Case à cocher

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

<template>
  <v-container
    class="px-0"
    fluid
  >
    <v-checkbox
      v-model="data"
      :value="data"
      :label="$t(label_field)"
      :disabled="readonly"
      :error="error"
      @change="onChange($event)"
    />
  </v-container>
</template>

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

export default defineComponent({
  props: {
    field: {
      type: String,
      required: false,
      default: null
    },
    label: {
      type: String,
      required: false,
      default: null
    },
    data: {
      type: Boolean,
      required: false
    },
    readonly: {
      type: Boolean,
      required: false
    }
  },
  setup (props, {emit}) {
    const {store} = useContext()
    const {error, onChange} = useError(props.field, emit, store)

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

<style scoped>
</style>
