
<script setup lang="ts">
import { ref } from 'vue'
import { useConfigStore } from '@/stores/config'
const props = defineProps({
  href: String,
  icon: String,
  hovericon: String,
  code: String,
})
const useConfig = useConfigStore();
const isMobile = useConfig.isMobile
const show = ref(false)
function open  () {
  show.value = true
}
function hide () {
  show.value = false
}
function change () {
  show.value = !show.value
}
</script>
<template>
  <div>
    <a
      :class="isMobile ? 'mobile' : 'pc'"
      class="popup"
      :href="href"
      @mouseover="isMobile || open()"
      @mouseout="isMobile || hide()"
      @click="isMobile && change()"
      target="_blank"
    >
      <img :src="icon" v-show="!hovericon || !show">
      <img :src="hovericon" v-show="hovericon && show">
      <div v-if="code" v-show="show">
        <img :src="code">
      </div>
    </a>
  </div>
</template>

<style scoped>
.popup {
  display: inline-block;
  width: 30px;
  height: 30px;
  margin-right: 12px;
}

.popup > img {
  width: 100%;
  height: 100%;
}

.popup.pc {
  position: relative;
}

.popup.pc div {
  width: 142px;
  position: absolute;
  left: 50%;
  top: -12px;
  transform: translateX(-50%) translateY(-100%);
}

.popup.pc div img {
  width: 100%;
  height: 100%;
}

.popup.mobile div {
  position: fixed;
  left: 0;
  top: 66px;
  padding-bottom: 66px;
  box-sizing: border-box;
  width: 100%;
  height: 100%;
  z-index: 99;
  background-color: rgba(0, 0, 0, 0.5);
}

.popup.mobile div img {
  width: 50%;
  left: 50%;
  position: absolute;
  top: 50%;
  transform: translateX(-50%) translateY(-50%);
  margin-top: -66px;
}

</style>
