import roma from "@/assets/product-roma.jpg";
import beefsteak from "@/assets/product-beefsteak.jpg";
import cherry from "@/assets/product-cherry.jpg";
import heirloom from "@/assets/product-heirloom.jpg";

const productImageMap: Record<string, string> = {
  "roma-musanze": roma,
  "beefsteak-huye": beefsteak,
  "cherry-rwamagana": cherry,
  "heirloom-nyamagabe": heirloom,
};

function isValidUrl(value: string) {
  try {
    new URL(value);
    return true;
  } catch {
    return false;
  }
}

export function resolveProductImage(image: string | null | undefined) {
  if (!image) return "";
  if (productImageMap[image]) return productImageMap[image];
  if (isValidUrl(image) || image.startsWith("/uploads") || image.startsWith("http")) return image;
  return "";
}
