<template>
  <div>
    <v-toolbar>
      <v-spacer />
      <v-toolbar-items>
        <v-autocomplete
          outlined
          return-object
          v-model="user"
          style="margin-top: 3px"
          placeholder="Suche Person"
          :items="allUsers"
          item-text="fullName"
          prepend-inner-icon="search"
          full-width
        />
        <v-btn text @click="addUser">Hinzufügen</v-btn>
      </v-toolbar-items>
    </v-toolbar>
  </div>
</template>

<script>
import { mapGetters, mapActions } from 'vuex'

export default {
  name: 'SearchBar',
  props: {},
  data() {
    return {
      user: null
    }
  },
  created() {
    this.getAllUsers()
  },
  methods: {
    ...mapActions({
      getAllUsers: 'barUsers/getAllUsers',
      addCreditList: 'barUsers/addCreditList'
    }),
    addUser() {
      this.addCreditList(this.user)
      this.user = null
    }
  },
  computed: {
    ...mapGetters({ allUsers: 'barUsers/allUsers' })
  }
}
</script>

<style scoped>
</style>
