<script setup lang="ts">
import { onLaunch } from '@dcloudio/uni-app'
import { useAuthStore } from './store/auth'
import { configTheme } from './components/theme/ThemeDefine';
import { LogUtils } from '@imengyu/imengyu-utils';
import { useCommonCategoryGlobalLoader } from './pages/article/data/CommonCategoryGlobalLoader';
import { useAppConfiguration } from './api/system/useAppConfiguration';

const TAG = 'App';
const authStore = useAuthStore();
const { loadCommonCategory } = useCommonCategoryGlobalLoader();
const { loadAppConfiguration } = useAppConfiguration();

function loadFontFace() {
  uni.loadFontFace({
    global: true,
    family: "SongtiSCBlack",
    source: 'url("https://mncdn.wenlvti.net/assets/fonts/STSongti-SC-Black.woff")',
  });
  uni.loadFontFace({
    global: true,
    family: "HUNdin1451",
    source: 'url("https://mncdn.wenlvti.net/app_static/minnan/fonts/HUN-din1451.woff")',
  });
}

onLaunch(async () => {
  LogUtils.printLog(TAG, 'info', 'App Launch');

  //加载配置
  await loadAppConfiguration();

  //加载字体
  loadFontFace();

  //加载登录状态
  await authStore.loadLoginState();

  //加载系统分类
  await loadCommonCategory();
})

configTheme(false, (theme, darkTheme) => {
  theme.colorConfigs.default.primary = '#d9492e';
  theme.colorConfigs.pressed.primary = '#882d1d';
  theme.colorConfigs.background.primary = '#ffcfc6';
  theme.colorConfigs.background.warning = '#f5ebe0';
  theme.colorConfigs.background.page = '#f6f2e7';
  return [theme, darkTheme];
});
</script>

<style lang="scss">
@use "@/common/scss/fonts.scss" as *;
@use "@/common/scss/common.scss" as *;
@use "@/common/scss/global/base.scss" as *;
@use "@/components/index.scss" as *;

page {
  background-color: #f6f2e7;
  overflow-x: hidden;
}
</style>

