<script setup lang="ts">
import Layout from "@/layout/index.vue"
import { useUserStore } from "@/pinia/stores/user"
import { useDark } from "@@/composables/useDark"
import { useWxStore } from "@/pinia/stores/wx"

// const userStore = useUserStore()
const wxStore = useWxStore()
const route = useRoute()

const { isDark, initDark } = useDark()

const isLoading = false;
// const isLoading = computed(() => userStore.token && !userStore.username)

// watch(
//   () => userStore.token,
//   (newVal) => {
//     newVal && userStore.getInfo()
//   },
//   {
//     immediate: true
//   }
// )

initDark()
onMounted(() => {
  const urlParams = new URLSearchParams(window.location.search);
  console.log('urlParams', urlParams);
  const code = urlParams.get('code') || undefined;
  const state = urlParams.get('state') || undefined;
  if (code || state) {
    wxStore.handleWxCallback({ code, state })
  }
})
</script>

<template>
  <van-config-provider :theme="isDark ? 'dark' : 'light'" un-h-full>
    <van-loading v-if="isLoading" un-h-full un-flex-center>
      加载中...
    </van-loading>
    <Layout v-else />
  </van-config-provider>
</template>
