/**
 * Resolves an image source to a full URL.
 * - If src starts with "http" or "https", returns it as-is.
 * - Otherwise, prepends the API base URL from environment variables.
 * - If src is null/undefined, returns the placeholder.
 */
export const PLACEHOLDER_IMAGE =
  "https://static.wixstatic.com/media/703249_3a76a53b765e46d4b3a5e4c3ec6ddd7e~mv2.png/v1/fill/w_800,h_800,al_c,q_90/placeholder.png";

export function resolveImage(src: string | null | undefined): string {
  if (!src) return PLACEHOLDER_IMAGE;
  if (src.startsWith("http://") || src.startsWith("https://") || src.startsWith("//")) {
    return src;
  }
  const base = process.env.NEXT_PUBLIC_API_BASE_URL || "";
  return `${base}${src.startsWith("/") ? "" : "/"}${src}`;
}
