<template>
  <div class="go-alarm-list">
    <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="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.event }}</div>
        <div class="row-item" :style="{ color: option.textColor, fontSize: option.fontSize + 'px' }">{{ item.time }}</div>
        <div class="row-item" :style="{ color: option.textColor, fontSize: option.fontSize + 'px' }">{{ item.enterprise }}</div>
        <div class="row-item" :style="{ color: getStatusColor(item.status), fontSize: option.fontSize + 'px' }">{{ item.status }}</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)

const getStatusColor = (status: string) => {
  return props.chartConfig.option.statusColors[status] || '#ffffff'
}
</script>

<style lang="scss" scoped>
.go-alarm-list {
  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;
      }
    }
  }

  .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;
      }
    }
  }
}
</style>
