<template>
  <div class="nav">
    <div class="nav-bar flex-ct">
      <h-img type="local" width=".8rem" src="base/fanhui.png" @click="goBack" />
      <div class="right flex-sb">
        <div class="tips flex-st">
          <div>
            Receba R$
            <span style="color: #f9eb2d; font-weight: bold">
              {{ formatDigit(taskNum) }}
            </span>
            de graça
          </div>
          <h-img
            width=".55rem"
            style="margin-left: 0.2rem"
            src="turntable/wenhao.png"
            @click="visible = !visible"
          />
        </div>
        <div class="member flex-ct">
          <h-img width=".5rem" src="turntable/wd.png" />
          <span>
            R$
            {{
              formatDigit(Math.trunc(Number(userStore.userInfo.coins / 10000)))
            }}
          </span>
        </div>
      </div>
    </div>
  </div>
  <h-center-popup v-model="visible" title="Regulation" contentBgcolor="#004f43">
    <rules />
  </h-center-popup>
</template>

<script setup lang="ts">
import { ref } from "vue";
import { formatDigit } from "@/utils";
import { useRouter } from "vue-router";
import Rules from "../rules/index.vue";
import { useUserStore } from "@/stores/modules/user";

const userStore = useUserStore();

const router = useRouter();
const visible = ref(false);

const props = defineProps({
  back: { type: Function, default: () => {}, required: false },
  taskNum: { type: Number, default: 100, required: true },
});

const goBack = () => {
  if (typeof props.back == "function") {
    props.back();
    return;
  }
  router.back();
};
</script>

<style lang="scss" scoped>
@import "./index.scss";
</style>
