/**
 * Convert S3 URL to proxy URL through backend API
 * This is needed because S3 bucket might not have public read access
 */
export function getProxyImageUrl(url: string | null | undefined): string {
  if (!url) {
    return '/assets/demo_images/8f017153a7b4a239a4f0691234ef97dd55092282.jpg';
  }

  // If it's already a local URL or data URL, return as-is
  if (url.startsWith('/') || url.startsWith('data:')) {
    return url;
  }

  // If it's an S3/external URL, proxy through backend
  if (url.startsWith('http')) {
    const apiUrl = process.env.NEXT_PUBLIC_API_URL || 'http://localhost:3001/api/v1';
    return `${apiUrl}/upload/image?url=${encodeURIComponent(url)}`;
  }

  return url;
}
