<!--
 * @Author: changjun
 * @FilePath: /qingdao-safety-product/src/views/threatIntelligenceManagement/components/TableProgressBar.vue
 * @Date: 2022-08-04 10:31:43
 * @Description: 
 * @LastEditTime: 2023-09-01 17:06:58
 * @LastEditors: 曹文丽
-->
<script setup lang="ts">
import { computed } from 'vue'
interface ProgressBarProps {
  percentage: number,
  color?: string,
  progressWidth?: string,
}
const { percentage = 0, color = '#F84A51', progressWidth = '100%' } = defineProps<ProgressBarProps>()


const getWrapProgressBarStyle = computed(() => {
  return {
    borderColor: color,
    width: progressWidth,
  }
})

const getCss = computed(() => {
  return {
    background: color
  }
})

const beforeEnter = (el) => {
  el.style.width = 0
}
const enter = (el) => {
  el.style.width = `${percentage}%`
  el.style.transition = `width 1s linear`
}

</script>

<template>
  <div class="progress-bar" :style="getWrapProgressBarStyle">
    <div class="background-bar"></div>
    <transition appear @before-appear="beforeEnter" @after-appear="enter">
      <div class="tracker-bar" :style="getCss"></div>
    </transition>
  </div>
</template>

<style scoped lang="scss">
.progress-bar {
  border: 1px solid transparent;
  height: 8px;
  padding: 1px;
  border-radius: 4px;
  box-sizing: border-box;

  .background-bar {
    background: #fff;
    width: 100%;
    height: 4px;
    border-radius: 4px;
  }

  .tracker-bar {
    background: transparent;
    height: 4px;
    width: 0;
    transition: width 0.5s linear;
    margin-top: -4px;
    border-radius: 4px;
  }
}
</style>
