<template>
  <div ref="circleWrapperRef" class="circle-wrapper">
    <a-progress
      type="circle"
      :width="width"
      :stroke-color="strokeColor"
      :percent="value"
    />
    <p v-if="name">{{ name }}</p>
  </div>
</template>

<script lang="ts">
import { computed, defineComponent, PropType, ref } from 'vue'

export default defineComponent({
  name: 'Circle',
  props: {
    color: {
      type: [String, Array] as PropType<string | string[]>,
      default: ['#0094FF', '#1DF9FF'],
    },
    value: {
      type: Number as PropType<number>,
      default: 0,
    },
    name: {
      type: String as PropType<string>,
      default: '',
    },
  },
  setup(props) {
    const circleWrapperRef = ref<HTMLElement | null>(null)
    const strokeColor = computed(() => {
      if (Array.isArray(props.color)) {
        return {
          '0%': props.color[0],
          '100%': props.color[1],
        }
      }
      return props.color
    })
    const width = computed(() => {
      if (circleWrapperRef.value) {
        console.log('width', circleWrapperRef.value.clientWidth)

        return circleWrapperRef.value.clientWidth / 1.8
      }
      return 0
    })
    return {
      circleWrapperRef,
      strokeColor,
      width,
    }
  },
})
</script>

<style lang="stylus" scoped>
@import '../../components/MyComponent/main.styl'
.circle-wrapper
  width 100%
  height 100%
  $center()
  flex-direction column
  >p
    margin-top .1rem
    font-size .12rem
    font-weight bold
</style>
