<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 ref="scrollRef" 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, defineProps, ref } from 'vue';
  import _ from 'lodash';
  import { useAutoScroll } from '/@/hooks/core/useAutoScroll';

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

  const scrollRef = ref(null);
  if (props.autoScroll) {
    useAutoScroll(scrollRef);
  }

  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';
  @import '@/design/theme.less';

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

  @{theme-green} {
    .table__content {
      --image-content-label: url(/@/assets/images/themify/green/company/content-label.png);
      --image-content-text: url('/@/assets/images/themify/green/company/content-text.png');
      --image-list-head: url('/@/assets/images/themify/green/home-container/configurable/firehome/list-head.png');
    }
  }
  @{theme-deepblue} {
    .table__content {
      --image-content-label: url(/@/assets/images/themify/deepblue/company/content-label.png);
      --image-content-text: url('/@/assets/images/themify/deepblue/company/content-text.png');
      --image-list-head: url('/@/assets/images/themify/deepblue/home-container/configurable/firehome/list-head.png');
    }
  }

  .table__content {
    --image-content-label: url(/@/assets/images/company/content-label.png);
    --image-content-text: url('/@/assets/images/company/content-text.png');
    --image-list-head: url('/@/assets/images/home-container/configurable/firehome/list-head.png');
    --image-content-label-d: url(/@/assets/images/home-container/configurable/minehome/content-label.png);
    --image-content-body-d: url('/@/assets/images/home-container/configurable/minehome/content-body.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_label_A {
      background-image: var(--image-content-label);
      background-size: 100% 100%;
      background-repeat: no-repeat;
      color: #31b9ef;
    }
    .table__content_label_B {
      background-image: linear-gradient(to top, #04698c, #04698c00);
      background-size: 100% 100%;
      background-repeat: no-repeat;
      color: #31b9ef;
    }
    .table__content_label_C {
      background-position: center 100%;
      background-size: 100% 25px;
      background-repeat: no-repeat;
      background-image: var(--image-content-text);
      height: 40px;

      .label-t {
        background-repeat: no-repeat;
        background-size: 80% auto;
        background-position: center;
        background-image: var(--image-list-head);
      }
    }

    .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_list_A {
      .table__content_list_row {
        background-size: 100% auto;
        background-repeat: no-repeat;
        background-position: center bottom;
        background-image: var(--image-content-text);
      }
    }
    .table__content_list_C {
      .table__content_list_row {
        min-height: 50px;
        background-size: 100% auto;
        background-repeat: no-repeat;
        background-position: center bottom;
        background-image: var(--image-content-text);
      }
    }

    .table__content_label_D {
      width: calc(100% - 10px);
      background-image: var(--image-content-label-d);
      background-size: 100% 100%;
      background-repeat: no-repeat;
      color: #fff;
    }
    .table__content_list_D {
      width: calc(100% - 10px);
      background-image: var(--image-content-body-d);
      background-size: 100% 100%;
      padding: 5px;
      .table__content_list_row {
        height: 20%;
        margin: 0;
      }
      /* 奇数行背景颜色 */
      .table__content_list_row:nth-child(odd) {
        background: #061b24;
      }

      /* 偶数行背景颜色 */
      .table__content_list_row:nth-child(even) {
        background: #092b3a;
      }
    }
  }
</style>
