export function resolveMediaUrl(path?: string | null): string | null {
  if (!path) {
    return null
  }

  if (/^https?:\/\//i.test(path)) {
    return path
  }

  const base = process.env.NEXT_PUBLIC_API_BASE_URL || process.env.API_BASE_URL || ''
  if (!base) {
    return path
  }

  const normalisedBase = base.endsWith('/') ? base.slice(0, -1) : base
  const normalisedPath = path.startsWith('/') ? path : `/${path}`

  return `${normalisedBase}${normalisedPath}`
}
