<script setup>
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 props = defineProps({
  show: {
    type: Boolean,
    default: false,
  },
  onClose: {
    type: Function,
    default: () => {},
  },
  arrows: {
    type: Array,
    default: () => [],
  },
});
</script>

<template>
  <view class="container" :style="{ display: show ? 'flex' : 'none' }">
    <AppBackground :type="1" />
    <view class="header">
      <view>
        <Avatar :src="user.avatar" frame :size="50" />
        <view>
          <text>{{ 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" :showLatestArrow="false" />
    </view>
    <view class="desc">
      <text>{{ arrows.length }}</text>
      <text>支箭，共</text>
      <text>{{ arrows.reduce((a, b) => a + b.ring, 0) }}</text>
      <text>环</text>
    </view>
    <ScorePanel
      :rowCount="arrows.length === 12 ? 6 : 9"
      :total="arrows.length"
      :scores="arrows.map((a) => a.ring)"
      :margin="arrows.length === 12 ? 4 : 1"
      :fontSize="arrows.length === 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;
}
.header > view:first-child > view:last-child > text:last-child {
  font-size: 10px;
  color: #fff9;
  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>
