<!--
   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>
  <div :class="{ 'dd-list': true, show: show }">
    <button class="btn btn-outline-primary" :class="small ? 'btn-sm' : ''" @click="doShow">
      <slot name="icon"></slot>
      <slot name="label"></slot>
      <FontAwesomeIcon :icon="arrowIcon" />
    </button>
    <div class="dd-click-detect" @click="doHide"></div>
    <div class="dd-details">
      <slot></slot>
    </div>
  </div>
</template>
<script>
import { FontAwesomeIcon } from '@fortawesome/vue-fontawesome'
import { faCaretSquareDown, faCaretSquareUp } from '@fortawesome/free-solid-svg-icons'
import { mapState } from 'vuex'

export default {
  name: 'FilterButton',
  components: { FontAwesomeIcon },
  props: {
    show: Boolean,
    small: Boolean
  },
  computed: {
    arrowIcon() {
      return this.show ? faCaretSquareUp : faCaretSquareDown
    }
  },
  methods: {
    doShow () {
      this.$emit('show')
    },
    doHide () {
      this.$emit('hide')
    }
  }
}
</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;
  z-index: 100;
}
.dd-click-detect {
  display: none;
}
.dd-list.show > .dd-click-detect {
  display: block;
  position: fixed;
  top: 0;
  left: 0;
  height: 100%;
  width: 100vw;
  z-index: 99;
}
</style>
