<template>
  <TechCard>
    <div class="card-header">
      <div class="title">长者活跃度</div>
    </div>
    <BaseChart :option="chartOption" />
    <div class="footer">
      <div class="label">当前活跃度</div>
      <div class="count">{{ rate }}%</div>
    </div>
  </TechCard>
</template>

<script lang="ts" setup>
import { computed } from 'vue'
import TechCard from '../TechCard/index.vue'

defineOptions({ name: 'ElderActivityCard' })

type Props = {
  activityRate: number | null
}

const props = withDefaults(defineProps<Props>(), {
  activityRate: 0,
})

const rate = computed(() => Number(props.activityRate && props.activityRate.toFixed(2)))

const chartOption = computed(() => ({
  tooltip: {
    trigger: 'item',
    appendToBody: true,
    formatter: '{b}: {c}%',
  },
  series: [
    {
      type: 'pie',
      radius: ['0%', '75%'],
      center: ['50%', '50%'],
      data: [
        {
          value: rate.value,
          name: '活跃',
          itemStyle: { color: '#00f0ff' },
        },
        {
          value: Number((100 - rate.value).toFixed(2)),
          name: '非活跃',
          itemStyle: { color: '#2c5364' },
        },
      ],
      label: { show: false },
      labelLine: { show: false },
    },
  ],
}))
</script>

<style lang="less" scoped>
.card-header {
  text-align: center;

  .title {
    font-size: 16px;
    font-weight: bold;
    color: #00f0ff;
  }
}

.footer {
  display: flex;
  justify-content: center;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  font-size: 14px;
  color: #9cc5e0;
  margin-top: 12px;

  .count {
    font-weight: bold;
    color: #00f0ff;
    font-size: 16px;
  }
}
</style>
