import { eventCardImage } from "@/features/events/eventCardFields";
import type { OpportunityItem } from "./commonProfileTypes";

/**
 * The picture of one card in a profile's opportunities / events tab.
 *
 * An event shows its own card artwork (`cover_image`); the gallery
 * (`event_images`) holds documentation photos only, so the first photo is a card
 * only for a legacy event that has no artwork at all (card/gallery decision,
 * 10 Nov 2026). An opportunity shows its first announcement image.
 */
export function listingImage(item: OpportunityItem, isEvent: boolean): string | null {
  return isEvent ? eventCardImage(item) : item.opportunity_images?.[0]?.image ?? null;
}
