<template>
  <div class="card bg-white flex text-center w-full overflow-hidden">
    <div class="w-1/4 mt-10" v-for="(item, index) in list" :key="index">
      <div class="text-text-color">{{ item.name }}</div>
      <div
        ref="father"
        class="mt-4 text-title-color text-xl font-bold overflow-hidden overflow-ellipsis whitespace-nowrap"
      >
        <span v-if="index < 2" ref="a">
          {{ item.value | filterAmount }} YCC
        </span>
        <span v-else-if="index == 2" ref="b">
          {{ item.value | filterMoney }} {{ $t('lang.price.dollar') }}
        </span>
        <span v-else ref="c">
          {{ item.value }}
        </span>
      </div>
    </div>
  </div>
</template>

<script lang="ts">
import Vue, { PropType } from 'vue'
export default Vue.extend({
  props: {
    list: Array as PropType<{ name: string; value: string | number }[]>,
  },
  mounted() {
    this.setFontSize()
  },
  methods: {
    setFontSize() {
      const father = this.$refs.father as HTMLElement[]
      const a = this.$refs.a as HTMLElement[]
      const b = this.$refs.b as HTMLElement
      const c = this.$refs.c as HTMLElement
      ;[...a, b, c].forEach((el: HTMLElement) => {
        console.log(el.offsetWidth, father[0].offsetWidth)
        if (el.offsetWidth >= father[0].offsetWidth) {
          el.style.fontSize = '14px'
        }
      })
    },
  },
  watch: {
    list(newV) {
      this.setFontSize()
    },
  },
})
</script>

<style scoped>
.card {
  height: 140px;
  border-radius: 4px;
}
</style>
