<template>
  <div class="ui-chart-rank-bar">
    <div class="ui-chart-rank-bar__main">
      <div class="ui-chart-rank-bar__progress" :style="{width: percent + '%', 'background-color': color}"></div>
    </div>
    <div class="ui-chart-rank-bar__value">{{ value }}{{ unit }}</div>
  </div>
</template>
<script>
export default {
  name: 'UiChartRankItemBar',
  props: {
    value: {
      type: Number,
      default: 0
    },
    total: {
      type: Number,
      default: 0
    },
    unit: {
      type: String
    },
    color: {
      type: String,
      default: '#0088FF'
    }
  },
  computed: {
    percent() {
      if (!this.total) {
        return 0
      }
      return Math.min((this.value / this.total), 1) * 100
    }
  }
}
</script>
<style lang="less">
.ui-chart-rank-bar{
  display: flex;
  flex-direction: row;
  align-items: center;
  height: 24px;
  line-height: 24px;
}
.ui-chart-rank-bar__main{
  height: 16px;
  border-radius: 8px;
  background-color: #F7F8FB;
  flex: 1;
  min-width: 0;
  margin-right: 6px;
}
.ui-chart-rank-bar__value{
  min-width: 42px;
  text-align: right;
}
.ui-chart-rank-bar__progress{
  height: 100%;
  background-color: #0088FF;
  border-radius: 8px;
}
</style>
