const API_BASE_URL = import.meta.env.VITE_API_BASE_URL || 'http://localhost:8080/api'
const BASE_URL = API_BASE_URL.replace('/api', '')

export function getImageUrl(path: string): string {
  if (!path) return ''
  if (path.startsWith('http://') || path.startsWith('https://')) {
    return path
  }
  if (path.startsWith('/')) {
    return BASE_URL + path
  }
  return BASE_URL + '/' + path
}

export function getFirstImage(images: string): string {
  if (!images) return ''
  const arr = images.split(',').map((s: string) => s.trim()).filter(Boolean)
  const first = arr[0] || ''
  return getImageUrl(first)
}
