<!--
 * @Author: wjc
 * @Date: 2025-04-09 10:19:11
 * @LastEditors: wjc
 * @LastEditTime: 2026-01-22 14:20:25
 * @Description: 
-->
<template>
  <page-meta>
    <!-- 微信小程序非自定义组件不支持 v-bind(2025-1-16)，兼容处理 -->
    <!-- <navigation-bar v-bind="originNavBarStyle" /> -->
    <navigation-bar
      :front-color="originNavBarStyle.frontColor as any"
      :background-color="originNavBarStyle.backgroundColor as any"
      :animation="originNavBarStyle.animation"
    />
  </page-meta>
  <nut-config-provider
    :theme="theme"
    class="bg-bg-page h-full"
    id="__uni-starter-styles__"
    :class="[userStore.theme]"
    :style="userStore.themeVars"
  >
    <slot></slot>
  </nut-config-provider>
</template>

<script setup lang="ts">
  import { useUserStore } from '@/stores/modules/userStore'
  import { onLaunch, onShow } from '@dcloudio/uni-app'

  defineOptions({
    name: 'MConfigProvider',
    options: {
      virtualHost: true,
    },
  })

  const userStore = useUserStore()
  const theme = computed(() => userStore.theme)

  const setBarStyle = () => {
    if (userStore.theme === 'dark') {
      const styles: UniApp.SetNavigationbarColorOptions = {
        frontColor: '#ffffff',
        backgroundColor: '#1a1a1a',
        animation: {
          duration: 0,
          timingFunc: 'easeIn',
        },
      }
      uni.setNavigationBarColor(styles)
      return styles
    } else {
      const styles: UniApp.SetNavigationbarColorOptions = {
        frontColor: '#000000',
        backgroundColor: '#f8f8f8',
        animation: {
          duration: 0,
          timingFunc: 'easeIn',
        },
      }
      uni.setNavigationBarColor(styles)
      return styles
    }
  }

  const originNavBarStyle = computed(setBarStyle)

  onLaunch(() => {
    setBarStyle()
    // uni.hideTabBar()
  })
  onShow(() => {
    setBarStyle()
    // uni.hideTabBar()
  })
</script>
