<template>
  <div class="pop-up-select">
    <span>{{ title }} <el-icon><ElIconArrowUpBold/></el-icon></span>
    <!--  事件遮罩  -->
    <div
      class="event-mask"
      @click="active = !active"
      v-on:[mouseover]="active = true"
      @mouseout="active = false"
    />
    <ul
      :class="{ active: active, leave: !active }"
      @mouseover="active = true"
      @mouseout="active = false"
    >
      <li v-for="option in data" :key="option.title">
        <nuxt-link target="_blank" :to="option.value">{{ option.title }}</nuxt-link>
      </li>
    </ul>
  </div>
</template>

<script>
export default {
  name: 'PopUpSelect',
  props: {
    title: String,
    data: {
      default: () => {
        return []
      }
    }
  },
  computed: {
    mouseover () {
      return this.$device.isMobile ? '' : 'mouseover'
    }
  },
  data () {
    return {
      active: false
    }
  }
}
</script>

<style scoped lang="scss">
@import "@/assets/style/variables";

.pop-up-select {
  position: relative;
  height: 40px;
  background-color: #FFFFFF;
  border: 1px solid #e4e7ed;
  display: flex;
  align-items: center;
  .event-mask {
    width: 100%;
    height: 100%;
    position: absolute;
    top: 0;
    left: 0;
  }
  &>span {
    width: 100%;
    padding: 5px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    white-space: nowrap;
    .el-icon {
      color: #aaa;
      font-size: 18px;
      line-height: 18px;
      margin-top: 2px;
    }
  }
  ul {
    width: 100%;
    position: absolute;
    bottom: 30px;
    left: -1px;
    background-color: #FFFFFF;
    overflow: hidden;
    border: 1px solid #e4e7ed;
    border-bottom: 0;
    z-index: 9;
    height: 0;
    &.active {
      height: auto;
      animation: pop-up linear 0.5s 1;
      animation-fill-mode: forwards;
    }
    &.leave {
      display: none;
    }
    li {
      &:hover {
        background-color: rgb(216.8, 235.6, 255);
      }
      a {
        position: relative;
        display: flex;
        padding: 10px 10px 10px 25px;
        color: var(--font-color);
      }
      &:last-of-type {
        margin-bottom: 10px;
      }
    }
  }
}
@keyframes pop-up {
  0% {
    max-height: 0;
  }
  100% {
    max-height: 300px;
  }
}

@media (max-width: $--mobile-max-width) {
  .pop-up-select {
    span {
      padding: 5px 10px;
    }
  }
}
</style>
