<script setup>
import { computed } from "vue";
import AppBackground from "@/components/AppBackground.vue";
import Avatar from "@/components/Avatar.vue";
import BowTarget from "@/components/BowTarget.vue";
import ScorePanel from "@/components/ScorePanel.vue";
import useStore from "@/store";
import { storeToRefs } from "pinia";
const store = useStore();
const { user } = storeToRefs(store);

const isSVip = computed(() => user.value.sVip === true);
const isVip = computed(() => user.value.vip === true && user.value.sVip !== true);

const props = defineProps({
  show: {
    type: Boolean,
    default: false,
  },
  onClose: {
    type: Function,
    default: () => {},
  },
  arrows: {
    type: Array,
    default: () => [],
  },
  total: {
    type: Number,
    default: 0,
  },
});
</script>

<template>
  <view class="container" :style="{ display: show ? 'flex' : 'none' }">
    <AppBackground :type="1" />
    <view class="header">
      <view>
        <Avatar :src="user.avatar" :rankLvl="user.rankLvl" :size="45" />
        <view>
          <view
            v-if="isVip || isSVip"
            :class="[
              'bow-data-user-name',
              'member-nickname',
              isVip ? 'member-nickname--vip' : '',
              isSVip ? 'member-nickname--svip' : '',
            ]"
          >
            <text class="member-nickname__text">{{ user.nickName }}</text>
            <text v-if="isSVip" class="member-nickname__shine">
              {{ user.nickName }}
            </text>
          </view>
          <text v-else>{{ user.nickName }}</text>
          <text>{{ user.lvlName }}</text>
        </view>
      </view>
      <view @click="onClose">
        <image src="../static/close-white.png" mode="widthFix" />
      </view>
    </view>
    <view :style="{ width: '100%', marginBottom: '20px' }">
      <BowTarget :scores="arrows" :isSvip="isSVip" />
    </view>
    <view class="desc">
      <text>{{ arrows.length }}</text>
      <text>支箭，共</text>
      <text>{{ arrows.reduce((a, b) => a + (b.ring || 0), 0) }}</text>
      <text>环</text>
    </view>
    <ScorePanel
      :completeEffect="false"
      :rowCount="total === 12 ? 6 : 9"
      :total="total"
      :arrows="arrows"
      :margin="total === 12 ? 4 : 1"
      :fontSize="total === 12 ? 25 : 22"
    />
  </view>
</template>

<style scoped>
.container {
  width: 100vw;
  height: 100vh;
  position: fixed;
  top: 0;
  left: 0;
  background-color: #232323;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  z-index: 10;
}
.header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: calc(100% - 20px);
  padding: 10px;
}
.header > view:first-child {
  display: flex;
  align-items: center;
  margin-left: 10px;
}
.header > view:first-child > view:last-child {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  margin-left: 10px;
  color: #fff;
}
.bow-data-user-name {
  max-width: 300rpx;
}
.bow-data-user-name .member-nickname__text,
.bow-data-user-name .member-nickname__shine {
  max-width: 300rpx;
}
.header > view:first-child > view:last-child > text:last-child {
  font-size: 10px;
  background-color: #5f51ff;
  padding: 2px 5px;
  border-radius: 10px;
  margin-top: 5px;
}
.header > view:last-child > image {
  width: 40px;
}
.desc {
  color: #fff;
  margin-bottom: 40px;
}
.desc > text:nth-child(2),
.desc > text:nth-child(4) {
  color: #fed847;
}
</style>
