export function replaceUrlPart(currentPath: string, newPart: string): string {
  const pathSegments = currentPath.split("/").filter((segment) => segment)

  const newPathSegments = newPart
    .replace(/\/$/, "")
    .split("/")
    .filter((segment) => segment)

  const isFullPathReplacement = newPathSegments.length > 1

  if (isFullPathReplacement) {
    return `/${newPathSegments.join("/")}`
  }

  const updatedPathSegments = pathSegments.slice(1)
  const updatedPath = `/${newPathSegments.concat(updatedPathSegments).join("/")}`

  return updatedPath
}
