<script setup>
import { topThreeColors } from "@/constants";
defineProps({
  avatar: {
    type: String,
    default: "",
  },
  name: {
    type: String,
    default: "",
  },
  scores: {
    type: Array,
    default: () => [],
  },
  rank: {
    type: Number,
    default: 0,
  },
  totalScore: {
    type: Number,
    default: 0,
  },
  totalRing: {
    type: Number,
    default: 0,
  },
});
const rowCount = new Array(6).fill(0);
</script>

<template>
  <view class="container">
    <view>
      <image
        v-if="rank === 1"
        src="../static/champ1.png"
        mode="widthFix"
        class="avatar-rank"
      />
      <image
        v-if="rank === 2"
        src="../static/champ2.png"
        mode="widthFix"
        class="avatar-rank"
      />
      <image
        v-if="rank === 3"
        src="../static/champ3.png"
        mode="widthFix"
        class="avatar-rank"
      />
      <view v-if="rank > 3" class="rank-view">{{ rank }}</view>
      <image
        :src="avatar"
        mode="widthFix"
        :style="{ borderColor: topThreeColors[rank - 1] || '#fff' }"
      />
    </view>
    <view>
      <view>
        <view v-for="(_, index) in rowCount" :key="index">
          <text>{{ scores[index] ? `${scores[index].ring}环` : "-" }}</text>
        </view>
      </view>
      <view>
        <view v-for="(_, index) in rowCount" :key="index">
          <text>{{
            scores[index + 6] ? `${scores[index + 6].ring}环` : "-"
          }}</text>
        </view>
      </view>
    </view>
    <view>
      <text>{{ totalRing }}环</text>
      <text>积分{{ totalScore }}</text>
    </view>
  </view>
</template>

<style scoped>
.container {
  width: calc(100% - 65px);
  display: flex;
  align-items: center;
  border: 1px solid #fff3;
  margin: 10px 0;
  margin-left: 30px;
  border-radius: 15px;
  padding: 10px;
  color: #fff9;
  font-size: 28rpx;
  position: relative;
}
.container > view:first-child {
  position: absolute;
  width: 30px;
  height: 30px;
  top: 30%;
  left: -17px;
}
.container > view:first-child > image:last-child {
  width: 30px;
  max-height: 30px;
  min-height: 30px;
  border-radius: 50%;
  border: 1px solid #fff;
}
.avatar-rank,
.rank-view {
  position: absolute;
  width: 16px;
  height: 17px;
  top: -9px;
  right: 5px;
}
.rank-view {
  background-color: #6d6d6d;
  text-align: center;
  line-height: 15px;
  font-size: 10px;
  border-radius: 50%;
  color: #fff;
}
.container > view:nth-child(2) {
  display: flex;
  flex-direction: column;
  margin-left: 15px;
  border-right: 1px solid #fff3;
  padding-right: 10px;
}
.container > view:nth-child(2) > view {
  display: flex;
}
.container > view:nth-child(2) > view text {
  width: 36px;
  text-align: center;
  display: block;
}
.container > view:nth-child(2) > view:first-child {
  border-bottom: 1px solid #fff3;
  padding-bottom: 10px;
}
.container > view:nth-child(2) > view:last-child {
  padding-top: 10px;
}
.container > view:nth-child(3) {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding-left: 10px;
  width: 100%;
}
.container > view:nth-child(3) > text {
  text-align: center;
  margin: 5px 0;
}
</style>
