<!--
   Copyright 2019 Brigham Young University

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
-->
<template>
  <button class="btn btn-outline-primary" @click="clearAll">
    <FontAwesomeIcon :icon="eyeIcon" />
    <span>Clear Filters</span>
  </button>
</template>
<script>
import { FontAwesomeIcon } from '@fortawesome/vue-fontawesome'
import { faEye } from '@fortawesome/free-solid-svg-icons'
import { mapState, mapMutations, mapActions } from 'vuex'

export default {
  name: 'FilterButton',
  components: { FontAwesomeIcon },
  computed: {
    ...mapState({
      filters: s => s.packetList.filters
    }),
    eyeIcon() {
      return faEye
    }
  },
  methods: {
    ...mapMutations(['clearPacketListFilter']),
    ...mapActions(['fetchPacketList']),
    clearAll () {
      this.clearPacketListFilter({ all: true })
      this.fetchPacketList({force: true})
    }
  }
}
</script>
<style scoped>
.dd-list {
  position: relative;
}
.dd-details {
  position: absolute;
  display: none;
}
.dd-list.show > .dd-details {
  display: grid;
  grid-template-columns: 1fr;
  grid-auto-rows: auto;
  grid-gap: 0.5rem;
  background-color: white;
  border: thin solid var(--gray-dark, #333);
  cursor: pointer;
}
</style>
