import React from 'react'; import { Link } from 'react-router-dom'; import { Item } from '../types'; import { getImageUrl } from '../services/uploadService'; interface ItemCardProps { item: Item; variant?: 'compact' | 'standard'; } const ItemCard: React.FC = ({ item, variant = 'standard' }) => { const isCompact = variant === 'compact'; const getPriceDisplay = () => { // Collect all available pricing tiers const pricingTiers: string[] = []; if (item.pricePerHour && Number(item.pricePerHour) > 0) { pricingTiers.push(`$${Math.floor(Number(item.pricePerHour))}/hr`); } if (item.pricePerDay && Number(item.pricePerDay) > 0) { pricingTiers.push(`$${Math.floor(Number(item.pricePerDay))}/day`); } if (item.pricePerWeek && Number(item.pricePerWeek) > 0) { pricingTiers.push(`$${Math.floor(Number(item.pricePerWeek))}/wk`); } if (item.pricePerMonth && Number(item.pricePerMonth) > 0) { pricingTiers.push(`$${Math.floor(Number(item.pricePerMonth))}/mo`); } if (pricingTiers.length === 0) { return "Free to Borrow"; } // Display up to 2 pricing tiers separated by bullet point return pricingTiers.slice(0, 2).join(" • "); }; const getLocationDisplay = () => { return item.city && item.state ? `${item.city}, ${item.state}` : ''; }; return (
{item.imageFilenames && item.imageFilenames[0] ? ( {item.name} { // Fallback to original for images uploaded before resizing was added const target = e.currentTarget; if (!target.dataset.fallback) { target.dataset.fallback = 'true'; target.src = getImageUrl(item.imageFilenames[0], 'original'); } }} style={{ height: isCompact ? '150px' : '200px', objectFit: 'contain', backgroundColor: '#f8f9fa' }} /> ) : (
)}
{isCompact ? (
{item.name}
) : (
{item.name}
)}
{getPriceDisplay()}
{getLocationDisplay()}
); }; export default ItemCard;