<template>
  <div class="xl:w-screen-xl m-auto py-4 my-20">
    <el-page-header :icon="ArrowLeft" @back="goBack">
      <template #content>
        <span class="text-large font-600 mr-3"> 实名认证 </span>
      </template>
      <div class="login-layout m-auto mt-10 sm:w-screen-xl w-full">
        <div class="m-auto flex sm:flex-row flex-col sm:px-0 px-3 ">
          <!-- 用户菜单 -->
          <UserMenu :activeIndex="activeIndex" @done="reload"/>
          <div class="flash bg-white rounded-lg w-full">
            <div class="sm:w-screen-md w-full sm:px-4 sm:py-2">
              <Auth @done="reload"/>
            </div>
          </div>
        </div>
      </div>
    </el-page-header>
  </div>
</template>
<script setup lang="ts">
import { ArrowLeft,View,Search } from '@element-plus/icons-vue'
import {useConfigInfo, useWebsite} from "~/composables/configState";
import {ref} from 'vue'
import {useServerRequest} from "~/composables/useServerRequest";
import type {ApiResult} from "~/api";
import UserMenu from "./components/UserMenu.vue";
import Auth from './components/Auth.vue';
import type {ShopMerchantApply} from "~/api/shop/shopMerchantApply/model";

// 配置信息
const runtimeConfig = useRuntimeConfig();
const route = useRoute();
const router = useRouter();
const activeIndex = ref('');
const website = useWebsite()
const config = useConfigInfo();
const merchantApply = ref<ShopMerchantApply>();

const reload = async () => {
  // 未登录状态(是否强制登录)
  const token = localStorage.getItem('token');
  if (!token || token == '') {
    navigateTo('/passport/login');
    return false;
  }
  const {data: response} = await useServerRequest<ApiResult<ShopMerchantApply>>('/shop/shop-merchant-apply/getByUserId', {baseURL: runtimeConfig.public.apiServer})
  if (response.value?.data) {
    merchantApply.value = response.value.data;
  }
  if(config.value){
    useHead({
      title: `实名认证 - ${config.value?.siteName}`,
      meta: [{name: website.value.keywords, content: website.value.comments}]
    });
  }
}


const goBack = () => {
  router.back(); // 返回上一页
}

watch(
    () => route.path,
    (path) => {
      activeIndex.value = path;
      reload();
    },
    {immediate: true}
);
</script>
