<template>
  <ModuleCard title="养老机构五项服务状况" size="large">
    <div class="elderly-institution-service">
      <div class="institution-grid">
        <div v-for="(institution, index) in institutions" :key="index" class="institution-item">
          <div class="institution-icon" :class="getIconClass(institution.problemCount)">
            <i class="iconfont icon-yanglaoyuan"></i>
            <!-- <div class="problem-count">{{ institution.problemCount }}</div> -->
          </div>
          <div class="institution-name">{{ institution.name }}</div>
        </div>
      </div>
    </div>
  </ModuleCard>
</template>

<script setup lang="ts">
import { computed } from 'vue'
import ModuleCard from './ModuleCard.vue'
import { institutionServiceData } from '../data/institutionService'

const institutions = computed(() => institutionServiceData.institutions)

const getIconClass = (problemCount: number) => {
  if (problemCount === 0) {
    return 'status-good'
  } else if (problemCount < 5) {
    return 'status-warning'
  } else {
    return 'status-danger'
  }
}
</script>

<style lang="scss" scoped>
$green: #07ada0;
$orange: #d49a3d;
$red: #d45656;

:deep(.module-content) {
  padding: 40px 0 36px;
}

.elderly-institution-service {
  width: 100%;
  height: 100%;
  padding: 0 20px;
  box-sizing: border-box;
  overflow-y: auto;
  margin-right: 10px;

  // 自定义滚动条
  &::-webkit-scrollbar {
    width: 8px;
  }

  &::-webkit-scrollbar-track {
    background: rgba(0, 255, 230, 0.1);
    border-radius: 4px;
  }

  &::-webkit-scrollbar-thumb {
    background: rgba(0, 255, 230, 0.5);
    border-radius: 4px;
  }

  &::-webkit-scrollbar-thumb:hover {
    background: rgba(0, 255, 230, 0.8);
  }

  .institution-grid {
    display: grid;
    grid-template-columns: repeat(9, 1fr);
    gap: 26px 20px;

    .institution-item {
      display: flex;
      flex-direction: column;
      align-items: center;

      .institution-icon {
        position: relative;
        width: 80px;
        height: 80px;
        display: flex;
        align-items: center;
        justify-content: center;
        border-radius: 8px;
        margin-bottom: 10px;

        .iconfont {
          font-size: 60px;
        }

        .problem-count {
          position: absolute;
          bottom: -5px;
          right: -5px;
          width: 24px;
          height: 24px;
          background: rgba(0, 0, 0, 0.7);
          color: white;
          border-radius: 50%;
          display: flex;
          align-items: center;
          justify-content: center;
          font-size: 12px;
          font-weight: bold;
        }

        &.status-good {
          background: rgba(7, 173, 160, 0.1);
          border: 2px solid $green;

          .iconfont {
            color: $green;
          }
        }

        &.status-warning {
          background: rgba(212, 154, 61, 0.1);
          border: 2px solid $orange;

          .iconfont {
            color: $orange;
          }
        }

        &.status-danger {
          background: rgba(212, 86, 86, 0.1);
          border: 2px solid $red;

          .iconfont {
            color: $red;
          }
        }
      }

      .institution-name {
        font-size: 16px;
        color: #00ffe6;
        text-align: center;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        max-width: 192px;
      }
    }
  }
}
</style>
