import { headers } from "next/headers"

import { getLang } from "@/i18n/serverContext"

export async function appendSlugToPathname(slug?: string) {
  const headersList = await headers()
  const pathname = headersList.get("x-pathname")
  const lang = await getLang()

  if (!pathname || !slug) {
    return null
  }

  return `/${lang}${pathname}/${slug}`
}
