<template>
  <div ref="banner" style="position: relative;" v-if="showBanner && show">
    <el-carousel indicator-position="outside" :height="height" arrow="never">
      <el-carousel-item v-for="(item, index) in options" :key="index"  class="banner-item">
        <router-link :to="'/activity/actDetail/' + item.act_type + '/' + item.contentId" v-slot="{ navigate }" v-if="(item.act_type==1 || item.act_type==2) && item.contentId" >
          <div class="item" :style="{'background-image':'url('+item.img_url+')'}" @click="navigate" ></div>
        </router-link>
        <router-link to="/shop" v-slot="{ navigate }" v-if="item.act_type==3" >
          <div class="item" :style="{'background-image':'url('+item.img_url+')'}" @click="navigate" ></div>
        </router-link>
        <div class="item" v-else :style="{'background-image':'url('+item.img_url+')'}" @click="navigate" ></div>
      </el-carousel-item>
    </el-carousel>
    <div class="banner-close" @click="close" >
        <el-icon color="rgba(196, 196, 196, 1)" ><Close /></el-icon>
    </div>
  </div>
</template>

<script setup>
import { onMounted, ref } from 'vue'
const banner = ref(null)
const height = ref('auto')
onMounted(() => {
    if (banner.value) {
        height.value = (banner.value.offsetWidth / 800 * 67) + 'px' 
    }
})

const emit = defineEmits(['close'])

const showBanner = ref(true)

const props = defineProps({
  options: {
    type: Array,
    default: []
  },
  show: {
    type: Boolean,
    default: true
  }
});

function close() {
    showBanner.value = false
    emit('close')
}

</script>

<style lang="scss" scoped>
.banner-item {
    width: 100%;

    .item {
        width: 100%;
        padding-top: 8.333%;
        background-size: 100%;
        background-repeat: no-repeat;
    }
}

:deep(.el-carousel__indicator--horizontal) {
  padding: 6px var(--el-carousel-indicator-padding-horizontal);
}

:deep(.el-carousel__button) {
    width: 6px;
    height: 6px;
    border-radius: 50%;
}

.banner-close {
    cursor: pointer;
    position: absolute;
    top: 10px;
    right: 13px;
    width: 20px;
    height: 20px;
    display: flex;
    justify-content: center;
    align-items: center;
}
</style>
