<template>
  <router-view />
</template>

<script setup>
import useSettingsStore from '@/store/modules/settings'
import usePermissionStore from '@/store/modules/permission'
import { handleThemeStyle } from '@/utils/theme'
import { useRoute } from 'vue-router'

const route = useRoute()
const permissionStore = usePermissionStore()

onMounted(() => {
  nextTick(() => {
    // 初始化主题样式
    handleThemeStyle(useSettingsStore().theme)
    
    // 根据当前路径设置正确的Tab
    const path = route.path
    if (path.startsWith('/platform')) {
      permissionStore.setCurrentTab('platform')
    } else if (path.startsWith('/car')) {
      permissionStore.setCurrentTab('car')
    } else if (path.startsWith('/system')) {
      permissionStore.setCurrentTab('system')
    } else if (path.startsWith('/road')) {
      permissionStore.setCurrentTab('road')
    } else if (path === '/' || path === '/index') {
      // 根源路径默认设为platform
      permissionStore.setCurrentTab('platform')
    }
  })
})
</script>