<script setup>
import { ref } from 'vue';
import { useGameStore } from '@/stores/game';
import navBar from '@/components/navBar.vue';
import success from '@/components/success.vue';

const gameStore = useGameStore();

const ASSETS = Object.freeze({
  completionPopup: 'https://userone-oss-cdn.angelgroup.com.cn/static/2026-01-23/d204d71cf2a54b18a6404e6132618cd6%E5%AE%8C%E6%88%90%E5%BC%B9%E7%AA%97.webp',
});

const showCompletionModal = ref(false);
const showSuccess1 = ref(false);
const showSuccess2 = ref(false);

const handleFinish = () => {
  showCompletionModal.value = true;
};

const closeCompletionModal = () => {
  showCompletionModal.value = false;
  showSuccess1.value = true;
};

const handleSuccess1Confirm = () => {
  showSuccess1.value = false;
  showSuccess2.value = true;
};

const handleSuccess2Confirm = () => {
  showSuccess2.value = false;
  gameStore.setFourthLevelStatus(true);
  uni.reLaunch({ url: '/pages/start/index' });
};
</script>

<template>
    <navBar />
    <view class="next" @click="handleFinish">完成</view>

    <!-- 完成弹窗 - 全屏覆盖 -->
    <view class="completion-modal" v-if="showCompletionModal" @click="closeCompletionModal">
      <image
        class="modal-image"
        :src="ASSETS.completionPopup"
        mode="scaleToFill"
      />
    </view>

    <!-- 第一个徽章 -->
    <success
      :show="showSuccess1"
      :badge-index="4"
      title="精准控水达人"
      sub-title="已完成第四关卡"
      @close="showSuccess1 = false"
      @confirm="handleSuccess1Confirm"
    />

    <!-- 第二个徽章 -->
    <success
      :show="showSuccess2"
      :badge-index="5"
      title="水质专家"
      sub-title="已完成全部关卡"
      @close="showSuccess2 = false"
      @confirm="handleSuccess2Confirm"
    />
</template>

<style scoped lang="scss">
.next {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 40rpx;
  color: #333;
}

.completion-modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(0, 0, 0, 0.7);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 1000;

  .modal-image {
    width: 100%;
    height: 100%;
  }
}
</style>