<template>
  <div class="anchorGraph-component">
    <img src="@/assets/images/head/anchorTitle.png" alt="" class="header-title" />

    <CommunityNode
      v-if="currentComponent == 'CommunityNode'"
      @click:anchorNode="handleClickAnchor"
    ></CommunityNode>

    <DetailNode
      v-else
      :communityNode="currentSelectedCommunityNode"
      @click:openDialog="handleClickOpenDialog"
      @click:goback="handleClickGoBack"
    ></DetailNode>

    <div class="statistics-container" v-show="currentComponent == 'CommunityNode'">
      <div class="statistics-item" v-for="item in statisticsList" :key="item.id">
        <img :src="item.icon" alt="" class="statistics-item-icon" />
        <div class="statistics-item-name">{{ item.name }}:&nbsp;</div>
        <div class="statistics-item-number">{{ item.number }}</div>
      </div>
    </div>
  </div>
</template>

<script setup>
import { defineProps, ref, defineEmits, watch, onMounted } from "vue"
import CommunityNode from "./communityNode.vue"
import DetailNode from "./detailNode.vue"
import { useKeyNodeRecognitionStore } from "@/store/keyNodeRecognition/index"
import { storeToRefs } from "pinia"

const keyNodeStore = useKeyNodeRecognitionStore()
const { riskEventIndex } = storeToRefs(keyNodeStore)
const props = defineProps({
  statisticsList: {
    type: Array,
    default: () => []
  }
})
const statisticsList = ref(props.statisticsList)
watch(riskEventIndex, (newIndex) => {
  if (newIndex == 6) {
    return
  }
  const tooltipList = keyNodeStore.tooltipList

  const highRiskCount = tooltipList[newIndex].filter((item) => item.riskType == "高风险").length
  keyNodeStore.statisticsList[5].number = highRiskCount
  keyNodeStore.statisticsList[4].number = tooltipList[newIndex].length
})
const emit = defineEmits(["click:openAnchorDialog"])

const currentComponent = ref("CommunityNode")
const currentSelectedCommunityNode = ref(null)

const handleClickAnchor = (communityNode) => {
  currentComponent.value = "detailNode"
  currentSelectedCommunityNode.value = communityNode
}
const handleClickGoBack = (currentComponentName) => {
  currentComponent.value = currentComponentName
}
const handleClickOpenDialog = (anchorNode) => {
  if (anchorNode) {
    emit("click:openAnchorDialog", { anchorDialog: true, currentSelectAnchorNode: anchorNode })
  }
}
onMounted(() => {
  keyNodeStore.initStatisticsList()
})
</script>

<style scoped lang="less">
:deep(.custom-dialog) {
  width: 640px;
  border-width: 0px, 0px, 0px, 0px;
  border-style: solid;
  border-image-source: linear-gradient(180deg, #3aa1f8 0%, rgba(58, 161, 248, 0.2) 100%);
  background-color: rgba(6, 45, 90, 1);
  border: 1px solid #1a8bff;
  border-radius: 2px;
  padding: 0 0;
  z-index: 1;
}

:deep(.custom-dialog) .dialog-content .content {
  color: rgba(255, 255, 255, 0.8);
  font-family: "PingFang SC";
  font-size: 16px;
  font-style: normal;
  font-weight: 400;
  opacity: 0.7;
}

.anchorGraph-component {
  width: 100%;
  height: 100%;
  position: relative;
  backdrop-filter: blur(5px);
  top: 0;
  .header-title {
    margin: 0 auto;
  }

  .statistics-container {
    height: 42px;
    width: 97%;
    border-radius: 4px;
    border: 1px solid #3aa1f8;
    background: linear-gradient(270deg, rgba(0, 82, 125, 0.48) 0%, rgba(0, 200, 255, 0.23) 100%);
    backdrop-filter: blur(3px);
    display: flex;
    justify-content: space-around;
    align-items: center;
    position: absolute;
    bottom: 13px;
    left: 10px;
    .statistics-item {
      display: flex;
      height: 100%;
      justify-content: center;
      align-items: center;
      color: #fff;
      .statistics-item-icon {
        margin-right: 5px;
        margin-top: 2px;
      }
      .statistics-item-name {
        color: #fff;
        font-family: OPPOSans;
        font-size: 14px;
        font-style: normal;
        font-weight: 400;
        line-height: normal;
      }
      .statistics-item-number {
        color: #fff;
        font-family: D-DIN;
        font-size: 17px;
        font-style: normal;
        font-weight: 700;
      }
    }
  }
}
</style>
