<template>
  <div class="emergency-supplies-container">
    <div class="container-title">
      <span class="line"></span>
      <span class="title">应急物资</span>
    </div>
    <div class="supply-counts">
      <div>
        <span>共计物资品类</span>
        <span class="supply-count">{{ categoryCount }}</span>
      </div>
      <div>
        <span>共计物资数量</span>
        <span class="supply-count">{{ quantityCount }}</span>
      </div>
    </div>
    <div class="supply-list">
      <div class="supply-item" v-for="(item, index) in supplyCategories" :key="index">
        <span class="supply-item-name">{{ item.suppliesTypeName }}</span>
        <div class="supply-item-info">
          <span>物资品类</span>
          <span class="category-count">{{ item.categoryCount }}</span>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
  import { onMounted, ref } from 'vue';
  import { SuppliesCategory, getOverviewSupplyCount } from '@/api/emergency-overview';

  const categoryCount = ref<number>(0);
  const quantityCount = ref<number>(0);

  const supplyCategories = ref<SuppliesCategory[]>([]);

  onMounted(async () => {
    const res = await getOverviewSupplyCount();
    categoryCount.value = res.categoryTotalCount;
    quantityCount.value = res.suppliesTotalCount;
    supplyCategories.value = res.suppliesCategoryList;
  });
</script>

<style scoped lang="scss">
  .container-title {
    height: 24px;
    display: flex;
    align-items: center;
    font-weight: 500;
    font-size: 16px;
    color: #000000;

    .line {
      width: 3px;
      height: 16px;
      background: #1777ff;
      margin-right: 10px;
    }

    .title {
      margin-right: 12px;
    }
  }

  .emergency-supplies-container {
    padding: 10px 0;

    .supply-counts {
      display: flex;
      justify-content: space-around;
      align-items: center;
      margin: 20px 7px 10px 7px;
      padding: 12px 0px;
      background: #e7f1ff;
      border-radius: 8px;
      font-weight: 400;
      font-size: 16px;
      color: rgba(0, 0, 0, 0.65);

      .supply-count {
        color: #1777ff;
        margin-left: 4px;
      }
    }

    .supply-list {
      width: 100%;
      height: calc(100% - 102px);
      padding: 0 10px;
      display: grid;
      grid-template-columns: repeat(2, 1fr);
      grid-gap: 10px;

      .supply-item {
        background: linear-gradient(90deg, #dbfaff 0%, #f5faff 100%);
        border-radius: 8px;
        padding: 10px 16px;

        .supply-item-name {
          font-weight: 500;
          font-size: 16px;
          color: #333333;
          white-space: nowrap;
          overflow: hidden;
          text-overflow: ellipsis;
        }

        .supply-item-info {
          margin-top: 8px;
          font-weight: 400;
          font-size: 16px;
          color: #666666;
          white-space: nowrap;
          overflow: hidden;
          text-overflow: ellipsis;
        }

        .category-count {
          margin-left: 5px;
          font-weight: 500;
          font-size: 18px;
          color: #333333;
        }
      }
    }
  }
</style>
