import { ArticleTypeEnum } from '@/constants'
import { useUserStore } from '@/stores/user'
import { storeToRefs } from 'pinia'

export function useNavigation() {
  const router = useRouter()
  const userStore = useUserStore()
  const { userInfo } = storeToRefs(userStore)

  // 根据文章类型跳到对应的文章详情页面
  const jumpToArticleDetailPage = ({ type, id }: { type: ArticleTypeEnum; id: number }) => {
    if (type === ArticleTypeEnum.VIDEO) {
      router.push(`/videoDetail/${id}`)
    } else if (type === ArticleTypeEnum.QUESTION) {
      router.push(`/questionDetail/${id}`)
    } else {
      router.push(`/articleDetail/${id}`)
    }
  }

  // 点击头像跳转用户首页 【实践 专访 问吧】 是 1 实名 其他是 0 匿名
  const jumpToUserHomePage = ({ userId, type }: { userId: string; type: ArticleTypeEnum }) => {
    const isSelf = userInfo.value.userId === userId
    if (isSelf) {
      router.push(`/userPage/selfPublish`)
    } else {
      let isReal = 0
      if (
        type === ArticleTypeEnum.PRACTICE ||
        type === ArticleTypeEnum.INTERVIEW ||
        type === ArticleTypeEnum.QUESTION
      ) {
        isReal = 1
      }
      router.push(`/otherUserPage/${userId}/${isReal}`)
    }
  }

  return {
    router,
    jumpToArticleDetailPage,
    jumpToUserHomePage,
  }
}
