<template>
  <div id="inventorySearch">
    <div class="field has-addons">
      <div class="control is-expanded">
        <input
          class="input is-primary is-medium"
          type="text"
          placeholder="Find something in particular..."
          v-model.trim="term"
          @input="updateSearch"
          autofocus
        />
      </div>
      <div class="control">
        <div class="select is-primary is-medium">
          <select>
            <option>Sort by Age (Oldest to Newest)</option>
            <option>Sort by Name</option>
            <option>Sort by Price (Low to High)</option>
            <option>Sort by Price (High to Low)</option>
          </select>
        </div>
      </div>
    </div>
    <content class="has-text-centered" v-if="noResults">
      <p>We couldn't find anything like that...</p>
    </content>
  </div>
</template>

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