<template>
  <TechCard>
    <div class="card-header">
      <div class="title">今日跌倒与告警</div>
    </div>
    <BaseChart :option="chartOption" :height="180" />
  </TechCard>
</template>

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

defineOptions({ name: 'AlertFallCompareCard' })

interface Props {
  fallCount: number
  alertCount: number
}

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

const chartOption = computed(() => ({
  tooltip: {
    trigger: 'item',
    axisPointer: { type: 'shadow' },
    formatter: '{b}: {c} 次',
  },
  grid: {
    left: 40,
    right: 20,
    top: 20,
    bottom: 40,
  },
  xAxis: {
    type: 'category',
    data: ['跌倒', '告警'],
    axisLabel: { color: '#9cc5e0' },
    axisTick: { show: false },
    axisLine: { show: false },
  },
  yAxis: {
    type: 'value',
    axisLabel: { color: '#9cc5e0' },
    splitLine: { show: false },
  },
  series: [
    {
      type: 'bar',
      data: [props.fallCount, props.alertCount],
      barWidth: 40,
      itemStyle: {
        color: (params: { dataIndex: number }) => ['#ff4d6d', '#f39c12'][params.dataIndex],
      },
      label: {
        show: true,
        position: 'top',
        color: '#fff',
        fontSize: 14,
      },
    },
  ],
}))
</script>

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

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