<template>
  <div class="cus-tab" :class="`cus-tab-${type}`">
    <template v-for="item in tabs">
      <div class="cus-tab-item __hover" :class="{active: item.value === param}" @click="$emit('update:param', item.value)">{{item.name}}</div>
    </template>
    <div class="cus-tab-slot">
      <slot/>
    </div>
  </div>
</template>

<script lang="ts">
import {
  defineComponent,
  computed,
  onMounted,
  ref,
  reactive,
  watch,
  getCurrentInstance,
  ComponentInternalInstance,
  toRefs,
  nextTick
} from 'vue'
import {useStore} from 'vuex'
import {useRouter, useRoute} from 'vue-router'

export default defineComponent({
  name: 'CusTab',
  components: {},
  props: {
    tabs: {
      required: true
    },
    param: {
      required: true
    },
    type: {default: 'type1', validator(val: string) {
      return ['type1', 'type2'].includes(val)
    }},
  },
  setup(props, {emit}) {
    const store = useStore();
    const router = useRouter();
    const route = useRoute();
    const that = (getCurrentInstance() as ComponentInternalInstance).appContext.config.globalProperties
    const state = reactive({})
    return {
      ...toRefs(state)
    }
  },
})
</script>

<style scoped lang="scss">
  .cus-tab {
    height: 40px;
    width: 100%;
    border-bottom: 1px solid #DCDFE5;;
    display: flex;
    align-items: center;
    box-sizing: border-box;
    .cus-tab-item {
      height: 100%;
      display: flex;
      align-items: center;
      justify-content: center;
      position: relative;
      font-size: 14px;
      font-family: PingFang SC-Regular, PingFang SC;
      font-weight: 400;
      color: #606266;
      margin-right: 16px;
      &:last-child {
        margin-right: 0;
      }
      &.active {
        &:after {
          content: '';
          position: absolute;
          bottom: 0;
        }
      }
    }
    &.cus-tab-type1 {
      .cus-tab-item {
        padding: 0 4px;
        &.active {
          color: #0062E9;
          &:after {
            width: 100%;
            height: 2px;
            bottom: -1px;
            background-color: #0062E9;
          }
        }
      }
    }
    &.cus-tab-type2 {
      .cus-tab-item {
        padding: 0 4px;
        min-width: 77px;
        margin-right: 6px;
        &.active {
          font-weight: 500;
          color: #0062E9;
          &:after {
            width: 100%;
            height: 5px;
            bottom: -3px;
            background-image: url("@/assets/images/cus/cus-tab_type2-active.png");
            background-repeat: no-repeat;
            background-size: 100% 100%;
          }
        }
      }
    }
    .cus-tab-slot {
      margin-left: auto;
    }
  }
</style>
