<template>
  <div class="l-progress">
    <span class="l-progress-label">{{ label }}</span>
    <div class="l-progress-bar-container">
      <div 
        class="l-progress-bar" 
        :style="{ width: percentage + '%' }"
      ></div>
    </div>
    <span class="l-progress-value">{{ percentage }}%</span>
  </div>
</template>

<script setup lang="ts">
import { computed } from 'vue'

// 定义组件props
interface Props {
  label: string
  num: number
  count: number
}

const props = withDefaults(defineProps<Props>(), {
  label: '',
  num: 0,
  count: 0
})

// 计算占比百分比
const percentage = computed(() => {
  if (props.count === 0) return 0
  return Math.min(100, Math.max(0, (props.num / props.count) * 100))
})
</script>

<style scoped lang="scss">
.l-progress {
  display: flex;
  align-items: center;
  width: 100%;
  
  .l-progress-label {
    font-size: 14px;
    color: #121212;
    white-space: nowrap;
    margin-right: 12px;
    display: inline-block;
    width: 80px;
    text-align: right;
  }
  
  .l-progress-bar-container {
    flex: 1;
    height: 10px;
    background-color: #e4e7ed;
    border-radius: 5px;
    overflow: hidden;
    margin-right: 12px;
    
    .l-progress-bar {
      height: 100%;
      background: linear-gradient(90deg, #409eff, #66b1ff);
      border-radius: 5px;
      transition: width 0.3s ease;
    }
  }
  
  .l-progress-value {
    font-size: 14px;
    color: #121212;
    font-weight: 500;
    white-space: nowrap;
  }
}
</style>