<template>
  <div class="table__content">
    <div class="table__content_label" :class="`table__content_label_${type}`">
      <div class="label-t" v-for="(item, index) in columns" :key="`svvhbcth-${index}`" :style="{ flexBasis }">{{ item.name }}</div>
    </div>
    <div class="table__content_list" :class="`table__content_list_${type}`">
      <div class="table__content_list_row" v-for="(item, index) in data" :key="`svvhbct-${index}`">
        <div v-for="(t, i) in columns" :key="`svvhbctr-${i}`" :style="{ flexBasis }" :class="`table__content__list_item_${type}`">
          <slot :name="t.prop" :scope="item">
            <span>{{ get(item, t.prop) }}</span>
          </slot>
        </div>
      </div>
    </div>
  </div>
</template>
<script lang="ts" setup>
  import { computed } from 'vue';
  import _ from 'lodash';

  let props = withDefaults(
    defineProps<{
      /** B | C */
      type: string;
      /** 列表表头配置，每个prop都有其对应的slot来提供定制化功能 */
      columns: { prop: string; name: string }[];
      data: any[];
      defaultValue?: string;
    }>(),
    {
      type: 'B',
      autoScroll: false,
      columns: () => [],
      data: () => [],
      defaultValue: '-',
    }
  );

  const flexBasis = computed(() => {
    return Math.fround(100 / props.columns.length) + '%';
  });

  function get(o, p) {
    const d = _.get(o, p);
    return _.isNil(d) ? props.defaultValue : d === '' ? props.defaultValue : d;
  }
</script>
<style lang="less" scoped>
  @import '/@/design/theme.less';

  @font-face {
    font-family: 'douyuFont';
    src: url('/@/assets/font/douyuFont.otf');
  }

  .table__content {
    --image-content-label-A: url('/@/assets/images/sealedGoaf/configurable/table/table-label-A.png');

    height: 100%;
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 5px 0;

    .table__content_label {
      width: 400px;
      height: 32px;
      display: flex;
      justify-content: space-around;
      align-items: center;
      .label-t {
        text-align: center;
        font-size: 14px;
      }
    }

    .table__content_list {
      height: calc(100% - 32px);
      width: 400px;
      display: flex;
      flex-direction: column;
      padding: 5px 0;
      box-sizing: border-box;
      overflow-y: auto;
      .table__content_list_row {
        width: 100%;
        display: flex;
        justify-content: space-around;
        align-items: center;
        color: #fff;
        margin-bottom: 5px;
        span {
          display: inline-block;
          text-align: center;
        }
      }
    }

    .table__content_label_A {
      background-image: var(--image-content-label-A);
      background-size: 100% 100%;
      background-repeat: no-repeat;
      color: #000000;
      width: 100%;
      padding-left: 10px;
    }

    .table__content_list_A {
      width: 100%;
      padding-left: 10px;
      font-weight: bold;
      font-size: 24px;
    }
    /* 第一个子元素：黑色 */
    .table__content_list_row .table__content__list_item_A:nth-child(1) {
      font-size: 12px;
      text-align: left;
      color: #000000;
    }

    /* 第二个子元素：蓝色 */
    .table__content_list_row .table__content__list_item_A:nth-child(2) {
      color: #1890ff;
    }

    /* 第三个子元素：黄色 */
    .table__content_list_row .table__content__list_item_A:nth-child(3) {
      color: #ffc107;
    }

    /* 第四个子元素：橙色 */
    .table__content_list_row .table__content__list_item_A:nth-child(4) {
      color: #ff7a45;
    }

    /* 第五个子元素：红色 */
    .table__content_list_row .table__content__list_item_A:nth-child(5) {
      color: #ff4d4f;
    }
  }
</style>
