<template>
  <div class="lc-progress"
       :style="runWayStyle"
       :accessible="true"
       :aria-label="`进度为百分之${value}`">
    <div class="progress" :style="progressStyle"></div>
  </div>
</template>

<style scoped>
  .lc-progress {
    position: relative;
    border-width: 1px;
    border-style: solid;
    border-radius: 8px;
  }

  .progress {
    position: absolute;
    top: -0.5px;
    border-radius: 8px;
  }
</style>

<script>
  export default {
    props: {
      barColor: {
        type: String,
        default: '#44B825'
      },
      bgColor: {
        type: String,
        default: '#fbfbfb'
      },
      borderColor: {
        type: String,
        default: '#f9f9f9'
      },
      barWidth: {
        type: Number,
        default: 580
      },
      barHeight: {
        type: Number,
        default: 16
      },
      value: {
        type: Number,
        default: 0
      }
    },
    computed: {
      runWayStyle () {
        const { barWidth, barHeight, bgColor, borderColor} = this;
        return {
          width: barWidth + 'px',
          height: barHeight + 'px',
          borderColor: borderColor,
          backgroundColor: bgColor
        }
      },
      progressStyle () {
        const { value, barWidth, barHeight, barColor } = this;
        const newValue = value < 0 ? 0 : (value > 100 ? 100 : value);
        return {
          backgroundColor: barColor,
          height: barHeight + 'px',
          width: newValue / 100 * barWidth + 'px'
        }
      }
    }
  }
</script>
