<template>
  <div class="right_top">
    <div class="right_top-title flex">
      <div class="flex items-center">
        <img src="@/assets/img/home/title_arrow.png" alt="">
        高频事件前50条
      </div>
    </div>
    <div class="scroll" v-loading="loading">
      <vue3-seamless-scroll :list="list" hover :singleHeight="100" v-if="list.length">
        <div class="scroll-item" v-for="(item,index) in list" :key="item.id">
          <span class="scroll-item-empty">{{ index }}</span>
          <span class="scroll-item-area">{{ item.areaName }}</span>
          <TextTooltip :content="item.title" className="scroll-item-title"></TextTooltip>
          <el-tooltip placement="top">
            <template #content> {{ item.title }}</template>
            <span class="scroll-item-hotspot">{{ item.hotspotName }}</span>
          </el-tooltip>
          <span class="scroll-item-num"> <CountUp :endVal="item.sumCount " :duration="2"/>次</span>
        </div>
      </vue3-seamless-scroll>
      <template v-else>
        <EmptyCom></EmptyCom>
      </template>
    </div>
  </div>
</template>
<script setup lang="ts">
import {onMounted, ref, watch, defineAsyncComponent} from "vue";
import {Vue3SeamlessScroll} from "vue3-seamless-scroll";
import CountUp from "@/components/count-up";
import {highFrequency} from "@/api/home";
import dayjs from "dayjs";
import EmptyCom from "@/components/empty-com";

const TextTooltip = defineAsyncComponent(() => import('@/components/TextTooltip/index.vue'));

const props = defineProps({
  dateArray: {
    type: Array,
    default: () => []
  }
})
const date = ref([]);
watch(() => props.dateArray, (val: any) => {
  date.value = val;
}, {immediate: true})

watch(() => props.dateArray, (val: any) => {
  getData();
})

const list = ref<any>([]);
const loading = ref(false);
const getData = async () => {
  loading.value = true;
  try {
    const {result} = await highFrequency({
      StartDate: dayjs(date.value[0]).format('YYYY-MM-DD'),
      EndDate: dayjs(date.value[1]).format('YYYY-MM-DD')
    });
    list.value = result;
    // list.value = [...result,...result,...result,...result,...result];
    loading.value = false;
  } catch (e) {
    console.log(e);
    loading.value = false;
  }
}
onMounted(() => {
  getData();
})
</script>
<style scoped lang="scss">
.right_top {
  padding: 0 30px;
  font-size: 15px;

  &-title {
    font-size: 20px;
    color: #fff;
    justify-content: space-between;
    align-items: center;
    line-height: initial;
  }


  .scroll {
    height: 280px;
    overflow: hidden;
    margin-top: 10px;

    &-item {
      width: 100%;
      display: flex;
      justify-content: space-between;
      align-items: center;
      color: #D2D4D5;
      height: 30px;
      line-height: 25px;
      margin-bottom: 10px;
      border-left: transparent;

      &-empty {
        display: inline-block;
        width: 5px;
        color: transparent;
      }

      &-area {
        display: inline-block;
        background-color: #69BBF6;
        padding: 0 6px;
        color: #333;
        border-radius: 4px;
        white-space: nowrap;
        width: 75px;
        overflow: hidden;
        text-overflow: ellipsis;
        text-align: center;
      }

      &-title {
        width: 50%;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
        margin-left: 10px;
        line-height: initial;
      }

      &-hotspot {
        width: 30%;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
        flex: 1;
      }
    }
  }
}

.count-up-wrap {
  display: inline-block;
}
</style>
<style lang="scss">
.scroll-item-title {
  width: 50%;
  margin-left: 10px;
  line-height: initial;
}

.scroll-item-hotspot {
  width: 30%;
  flex: 1;
}
</style>