<template>

  <div class="card">

    <template v-if="cardLoading">
      <a-spin class="card-loading" :spinning="cardLoading"></a-spin>
    </template>

    <template v-else>

      <!-- 卡片头部 -->
      <div class="card-header" v-if="slots.header">
        <slot name="header"></slot>
      </div>

      <!--卡片内容-->
      <div class="card-body">
        <a-tabs v-model:activeKey="tabActiveKey" v-if="props.isShowTab" @change="tabChange">
          <a-tab-pane
            :key="tabItem.key"
            :tab="tabItem.name" v-for="tabItem in props.tabList">
          </a-tab-pane>
          <template #leftExtra>
            <slot name="leftExtra" v-if="slots.leftExtra"></slot>
          </template>
          <template #rightExtra>
            <slot name="rightExtra" v-if="slots.rightExtra"></slot>
          </template>
        </a-tabs>
        <slot name="body" v-if="slots.body"></slot>
      </div>

    </template>

  </div>

</template>

<script setup>
import {useSlots, ref, onUpdated} from "vue";

const slots = useSlots();

const props = defineProps({
  // tab栏默认选中
  activeKey: {
    type: String,
    default: ''
  },
  // 是否显示tab栏
  isShowTab: {
    type: Boolean,
    default: false,
  },
  // tab栏列表
  tabList: {
    type: Array,
    default: () => {
      return []
    }
  },
  loading: {
    type: Boolean,
    default: false
  }
})

const emits = defineEmits(['tabChange']);

const tabActiveKey = ref(props.activeKey);

const cardLoading = ref(props.loading);

// tab切换
const tabChange = (key) => {
  emits('tabChange', key);
}

onUpdated(() => {
  tabActiveKey.value = props.activeKey
})


</script>

<style scoped lang="less">
.card {
  display: flex;
  flex-direction: column;
  width: 100%;
  height: 100%;
  margin: 0;
  border-radius: 12px;
  box-sizing: border-box;
  overflow-y: auto;
  overflow-x: hidden;
  background-image: linear-gradient(180deg, rgba(255, 255, 255, 0.72) 1%, rgba(255, 255, 255, 0.86) 74%);
  backdrop-filter: blur(0px);
  box-shadow: 0 2px 10px 0 rgba(224, 223, 227, .48);
  color: #383838;
}

.card-header {
  padding-left: 18px;
  padding-right: 18px;
  padding-top: 14px;
  padding-bottom: 10px;
}

.card-body {
  width: 100%;
  height: 100%;
  overflow: hidden;
}

.card-loading {
  position: absolute;
  top: 50%;
  left: 50%;
}

:deep(.ant-tabs-ink-bar) {
  display: none;
}

:deep(.ant-tabs-tab-active) {
  position: relative;
  &::after {
    position: absolute;
    bottom: 0;
    left: 50%;
    content: '';
    background-image: linear-gradient(216deg, #5CB431 0%, #0091DA 79%);
    border-radius: 2px;
    height: 4px !important;
    width: 52px !important;
    margin-left: -26px;
  }
}

</style>
