<template>
  <div id="inventoryFilter">
    <section class="section">
      <div class="container">
        <input
          class="input is-primary is-medium"
          type="text"
          placeholder="Find something in particular..."
          v-model.trim="term"
          @input="updateFilter"
          autofocus
        />
      </div>
      <content class="has-text-centered" v-if="noResults">
        <p>We couldn't find anything like that...</p>
      </content>
    </section>
  </div>
</template>

<script>
export default {
  name: "InventoryFilter",
  data() {
    return {
      term: ""
    };
  },
  computed: {
    noResults() {
      return !this.$store.getters.inventory.length;
    }
  },
  methods: {
    updateFilter() {
      this.$store.commit("filterTerm", this.term);
    }
  }
};
</script>
