<template>
  <view class="app-container pb-16">
    <SalesHome v-if="role === 'sales'" />
    <DispatchHome v-else-if="role === 'dispatch'" />
    <ConstructionHome v-else />
    <!-- #ifdef H5 || APP-PLUS -->
    <AppTabBar />
    <!-- #endif -->
  </view>
</template>

<script setup lang="ts">
import { onShow } from '@dcloudio/uni-app'
import { computed } from 'vue'
import { useAuthStore } from '@/stores/auth'
import { safeHideTabBar } from '@/utils'
import SalesHome from '@/components/home/SalesHome.vue'
import DispatchHome from '@/components/home/DispatchHome.vue'
import ConstructionHome from '@/components/home/ConstructionHome.vue'
// #ifdef H5 || APP-PLUS
import AppTabBar from '@/components/common/AppTabBar.vue'
// #endif

const authStore = useAuthStore()
const role = computed(() => authStore.userRole || 'sales')

onShow(() => {
  // #ifdef H5 || APP-PLUS
  safeHideTabBar({ animation: false, repeat: 10 })
  // #endif
  // #ifdef MP-WEIXIN
  const pages = getCurrentPages()
  const page = pages[pages.length - 1] as any
  page?.getTabBar?.()?.setSelected?.(0)
  // #endif
})
</script>
