import { useSidebar } from '@/composables/use-sidebar'
import { useAuthStore } from '@/stores/auth'

import type { SidebarData, User } from '../types'

export function useSidebarData() {
  const { navData } = useSidebar()
  const authStore = useAuthStore()

  // 从 auth store 获取用户信息，转换为 sidebar User 类型
  const user = computed<User>(() => {
    const adminInfo = authStore.adminInfo
    return {
      name: adminInfo?.nickname || adminInfo?.username || 'Admin',
      email: adminInfo?.username || '',
      avatar: adminInfo?.avatar || '/avatars/admin.jpg',
    }
  })

  const sidebarData = computed<SidebarData>(() => ({
    user: user.value,
    navMain: navData.value!,
  }))

  return {
    sidebarData,
  }
}
