/**
 * 用来构造分享的参数, 比如分享，海报等等
 */

import { useRef, useMemo } from 'react'
import { ROLE_CODE } from '@/constants/user'

export default function useParams({id, buildingId, person, from}) {
  // 判断当前人员是否置业顾问
  const consultant = person.personType === ROLE_CODE.CONSULTANT ? { id: person.personId } : {}

  const paramsRef = useRef()
  paramsRef.current = useMemo(() => {
    return [
      id ? `id=${id}` : undefined, // 非详情页, 比如首页分享的时候, 没有 id
      `from=${from}`,
      `recommender=${person.personId}`,
      buildingId ? `buildingId=${buildingId}` : undefined,
      consultant.id ? `consultant=${consultant.id}` : undefined,
    ].filter(Boolean).join('&')
  }, [id, buildingId, from, person.personId, consultant.id])

  return paramsRef
}
