function encodeSegment(value) {
  return encodeURIComponent(String(value || '').trim())
}

export function homePath(query = '') {
  const normalized = String(query || '').trim()
  return normalized ? `/?q=${encodeURIComponent(normalized)}` : '/'
}

export function loginPath(redirect = '') {
  const normalized = String(redirect || '').trim()
  return normalized ? `/login?redirect=${encodeURIComponent(normalized)}` : '/login'
}

export function topicPath(topicId) {
  return `/topics/${encodeSegment(topicId)}`
}

export function editorNewPath(topicId) {
  return `/editor/${encodeSegment(topicId)}/new`
}

export function editorPath(topicId, tierListId, { preview = false } = {}) {
  const base = `/editor/${encodeSegment(topicId)}/${encodeSegment(tierListId)}`
  return preview ? `${base}?preview=1` : base
}

export function shareEditorPath(topicId, tierListId) {
  return `/share/editor/${encodeSegment(topicId)}/${encodeSegment(tierListId)}`
}

export function mePath() {
  return '/me'
}

export function favoritesPath() {
  return '/favorites'
}

export function followingFeedPath() {
  return '/following'
}

export function profilePath() {
  return '/profile'
}

export function userProfilePath(userId) {
  return `/users/${encodeSegment(userId)}`
}
