<script setup lang="ts">
import type { selectType } from '../interface'
const props = withDefaults(
  defineProps<{
    dataList: selectType[]
  }>(),
  {
    dataList: () => [{ label: '', value: '' }],
  },
)

const emits = defineEmits(['change'])
const OSS_URL = import.meta.env.VITE_OSS_URL
const activeTap = ref()
watch(
  () => props.dataList,
  nv => {
    // 默认激活列表中第一项
    activeTap.value = props.dataList[0]
  },
  {
    deep: true,
    immediate: true,
  },
)

function handleSelect(item: any) {
  if (activeTap.value.label === item.label) return
  activeTap.value = item
  emits('change', item)
}
</script>
<template>
  <div class="aside-list">
    <div
      v-for="(item, index) in dataList"
      :key="index"
      :class="{ 'data-item': true, active: activeTap.label === item.label }"
      :style="{
        'background-image':
          activeTap.label === item.label ? `url('${OSS_URL}/icon/leaf_icon.svg')` : 'none',
      }"
      @click="handleSelect(item)"
      v-html="item.label"
    ></div>
  </div>
</template>

<style lang="scss" scoped>
.aside-list {
  .data-item {
    min-height: 6vh;
    width: 162px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: $font-text;
    font-size: 2.67vh;
    line-height: 4vh;
    color: white;
    text-align: center;
    padding: 1vh;
    position: relative;
    margin-bottom: 2.83vh;
    cursor: pointer;
    &:not(:first-child)::after {
      position: absolute;
      left: 50%;
      transform: translate(-50%);
      top: -1.42vh;
      content: '';
      width: 88px;
      height: 0.17vh;
      background-color: rgba(255, 255, 255, 0.65);
    }
    &:last-child {
      margin-bottom: 0;
    }
  }
  .active {
    background-color: #000000a6;
    background-position: -10px;
    border-radius: 0.67vh 0 0 0.67vh;
    &::before {
      content: '';
      width: 8px;
      height: 100%;
      position: absolute;
      background-color: #a2fb6e;
      right: 0;
      top: 0;
      border-radius: 0.33vh 0 0 0.33vh;
    }
  }
}
</style>
