<template>
  <div class="go-device-status">
    <div class="header">
      <div class="title">
        <svg-icon icon-class="rocket" class="title-icon" :style="{ color: option.iconColor }"></svg-icon>
        <span :style="{ color: option.titleColor, fontSize: option.titleSize + 'px' }">{{ option.title }}</span>
      </div>
    </div>
    <div class="status-section">
      <div class="online-rate">
        <div class="rate-circle">
          <span class="rate-text">{{ option.onlineRate }}%</span>
        </div>
        <span class="rate-label">设备在线率</span>
      </div>
      <div class="progress-bar">
        <div class="progress" :style="{ width: option.onlineRate + '%' }"></div>
      </div>
      <div class="device-count">
        <span>{{ option.onlineDevice }}</span> / <span>{{ option.totalDevice }}</span>
      </div>
    </div>
    <div class="table-header" :style="{ backgroundColor: option.headerBackgroundColor, height: option.headerHeight + 'px' }">
      <div v-for="header in option.header" :key="header" class="header-item" :style="{ color: option.headerTextColor, fontSize: option.fontSize + 'px' }">
        {{ header }}
      </div>
    </div>
    <div class="table-body">
      <div v-for="(item, index) in option.dataset" :key="index" class="table-row" :style="{ backgroundColor: option.itemBackgroundColor, height: option.itemHeight + 'px' }">
        <div class="row-item" :style="{ color: option.textColor, fontSize: option.fontSize + 'px' }">{{ item.enterprise }}</div>
        <div class="row-item" :style="{ color: option.textColor, fontSize: option.fontSize + 'px' }">{{ item.deviceType }}</div>
        <div class="row-item" :style="{ color: option.textColor, fontSize: option.fontSize + 'px' }">{{ item.deviceName }}</div>
        <div class="row-item time" :style="{ color: option.timeColor, fontSize: option.fontSize + 'px' }">{{ item.time }}</div>
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
import { PropType, computed } from 'vue'
import { option as configOption } from './config'

const props = defineProps({
  chartConfig: {
    type: Object as PropType<{ option: typeof configOption }>,
    required: true
  }
})

const option = computed(() => props.chartConfig.option)
</script>

<style lang="scss" scoped>
.go-device-status {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  background-color: #0F233E;
  color: #ffffff;
  padding: 10px;
  box-sizing: border-box;

  .header {
    display: flex;
    align-items: center;
    margin-bottom: 10px;
    .title {
      display: flex;
      align-items: center;
      .title-icon {
        font-size: 24px;
        margin-right: 10px;
      }
    }
  }

  .status-section {
    display: flex;
    align-items: center;
    margin-bottom: 10px;
    .online-rate {
      display: flex;
      align-items: center;
      .rate-circle {
        width: 50px;
        height: 50px;
        border: 2px solid #00E5FF;
        border-radius: 50%;
        display: flex;
        justify-content: center;
        align-items: center;
        margin-right: 10px;
        .rate-text {
          color: #00E5FF;
          font-size: 16px;
        }
      }
      .rate-label {
        font-size: 14px;
      }
    }
    .progress-bar {
      flex: 1;
      height: 10px;
      background-color: #1A385A;
      border-radius: 5px;
      margin: 0 10px;
      overflow: hidden;
      .progress {
        height: 100%;
        background-color: #00E5FF;
      }
    }
    .device-count {
      font-size: 14px;
    }
  }

  .table-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 10px;
    .header-item {
      flex: 1;
      text-align: center;
    }
  }

  .table-body {
    flex: 1;
    overflow-y: auto;
    .table-row {
      display: flex;
      justify-content: space-between;
      align-items: center;
      padding: 0 10px;
      border-bottom: 1px solid #1A385A;
      .row-item {
        flex: 1;
        text-align: center;
        &.time {
          color: #FF4D4F;
        }
      }
    }
  }
}
</style>