import { FeatureTag } from "@/app/utils/svgs/featureTag"; import { getFullImageUrl } from "@/app/utils/functions"; import Image from "next/image"; import Link from "next/link"; import React, { useState } from "react"; import PrimaryButton from "./primaryButton"; import { ArrowIcon } from "@/app/utils/svgs/arrowIcon"; interface ListCardProps { id: string; name: string; image: string; // may be empty href: string; price: number; category_id: string; category: string; discount?: number | null; isFeatured?: boolean; onSale: boolean; skus: Array; } const ListCard = ({ id, name, image, href, price, category, discount, isFeatured = false, onSale, skus, }: ListCardProps) => { const [loaded, setLoaded] = useState(false); const hasDiscount = discount != null && discount > 0; const priceValue = hasDiscount ? price + discount : price; const fallbackImage = "/images/Hero.png"; // 👈 fallback if no image // Ensure image URL has full S3 path if it's relative const fullImageUrl = getFullImageUrl(image) || fallbackImage; return (
{/* Featured badge */} {isFeatured && ( {FeatureTag} )} {/* On sale pill */} {onSale && ( )}
{/* Skeleton always shown until image finishes */} {!loaded && (
)} {name} setLoaded(true)} onError={() => setLoaded(true)} />

{category}

{name}

{skus && skus.length && (

PART #: {skus[0] || "N/A"}

)}
); }; export default ListCard;