import { Lang } from "@/constants/languages"

import { resolve as resolveEntry } from "@/utils/entry"
import { findLang } from "@/utils/languages"
import { removeTrailingSlash } from "@/utils/url"

export const getUidAndContentTypeByPath = async (pathname: string) => {
  const lang = findLang(pathname)

  const pathWithoutTrailingSlash = removeTrailingSlash(pathname)

  const contentTypePathName = pathWithoutTrailingSlash.replace(`/${lang}`, "")

  const { contentType, uid } = await resolveEntry(
    contentTypePathName,
    lang ?? Lang.en
  )

  return { contentType, uid }
}
