<!--
 * @Author: changjun
 * @FilePath: /yuan-qingdao-zld-browser/src/components/ProgressBar/ProgressBar.vue
 * @Date: 2022-07-08 08:52:06
 * @Description: 进度条组件
 * @LastEditTime: 2023-03-28 17:34:31
 * @LastEditors: 李佐宁
-->
<script setup lang="ts">
import { getThemeColor } from "@/components/chart/options/theme";
interface ProgressBarProps {
  percentage: number;
  color?: string;
  backgroundColor?: string;
}

let colors = getThemeColor().progressColor || "#0095FF";
const {
  percentage = 0,
  color,
  backgroundColor = "rgba(255,255,255,0.15)",
} = defineProps<ProgressBarProps>();
colors = color || colors;
const getCss = computed(() => {
  return {
    background: unref(colors),
  };
});

const getBackgroundBarCss = computed(() => {
  return {
    background: unref(backgroundColor),
  };
});

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

<template>
  <div class="progress-bar">
    <div
      class="background-bar"
      :style="getBackgroundBarCss"
    ></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 {
  width: 100%;

  .background-bar {
    width: 100%;
    height: 6px;
  }

  .tracker-bar {
    background: transparent;
    height: 6px;
    width: 0;
    transition: width 0.5s linear;
    margin-top: -6px;
    // transform: skewX(30deg);
    min-width: 3px;
    // border-radius: 4px;
  }
}
</style>
