import { API_URL } from '../services/api';

/**
 * Get the full URL for an image, handling both absolute and relative URLs
 */
export const getImageUrl = (imageUrl: string | undefined | null): string | undefined => {
  if (!imageUrl) return undefined;
  
  // If already an absolute URL, return as-is
  if (imageUrl.startsWith('http://') || imageUrl.startsWith('https://')) {
    return imageUrl;
  }
  
  // Otherwise, prepend the backend base URL
  const backendUrl = API_URL.replace('/api/v1', '');
  const path = imageUrl.startsWith('/') ? imageUrl : `/${imageUrl}`;
  return `${backendUrl}${path}`;
};
