<template>
  <NConfigProvider
    :locale="zhCN"
    :theme="getDarkTheme"
    :theme-overrides="getThemeOverrides"
    :date-locale="dateZhCN"
  >
    <AppProvider>
      <RouterView />
      <RouterError />
    </AppProvider>
  </NConfigProvider>
</template>

<script lang="ts" setup>
import { computed, onMounted, onUnmounted } from "vue";
import { zhCN, dateZhCN, darkTheme, useDialog } from "naive-ui";

import { AppProvider } from "@/components/Application";
import { RouterError } from "@/components/RouterError";
import { useRoute, useRouter } from "vue-router";
import { useDesignSettingStore } from "@/store/modules/designSetting";
import { lighten } from "@/utils/index";

const route = useRoute();

const designStore = useDesignSettingStore();

/**
 * @type import('naive-ui').GlobalThemeOverrides
 */
const getThemeOverrides = computed(() => {
  const appTheme = designStore.appTheme;
  const lightenStr = lighten(designStore.appTheme, 6);
  return {
    common: {
      primaryColor: appTheme,
      primaryColorHover: lightenStr,
      primaryColorPressed: lightenStr,
    },
    LoadingBar: {
      colorLoading: appTheme,
    },
  };
});

const getDarkTheme = computed(() => (designStore.darkTheme ? darkTheme : undefined));

let timer: string | number | NodeJS.Timeout | undefined;

onMounted(() => {});

onUnmounted(() => {});
</script>

<style lang="less">
@import "styles/index.less";
</style>
