"use client"; import Image from "next/image"; import { Button, Card, CardHeader, CardBody, CardFooter } from "@heroui/react"; import { buttonStyles } from "@/lib/buttonStyles"; import { useApp } from "@/contexts/AppContext"; const COLOR_KEYS = ["orange", "green", "blue", "purple", "red", "teal", "indigo", "rose", "amber", "cyan"] as const; type ColorKey = typeof COLOR_KEYS[number]; const COLOR_MAP: Record = { orange: { bg: "bg-orange-50", text: "text-orange-600", border: "border-orange-300", gradient: "from-orange-500/5 via-orange-300/3 to-white/0" }, green: { bg: "bg-green-50", text: "text-green-600", border: "border-green-300", gradient: "from-green-500/5 via-green-300/3 to-white/0" }, blue: { bg: "bg-blue-50", text: "text-blue-600", border: "border-blue-300", gradient: "from-blue-500/5 via-blue-300/3 to-white/0" }, purple: { bg: "bg-purple-50", text: "text-purple-600", border: "border-purple-300", gradient: "from-purple-500/5 via-purple-300/3 to-white/0" }, red: { bg: "bg-red-50", text: "text-red-600", border: "border-red-300", gradient: "from-red-500/5 via-red-300/3 to-white/0" }, teal: { bg: "bg-teal-50", text: "text-teal-600", border: "border-teal-300", gradient: "from-teal-500/5 via-teal-300/3 to-white/0" }, indigo: { bg: "bg-indigo-50", text: "text-indigo-600", border: "border-indigo-300", gradient: "from-indigo-500/5 via-indigo-300/3 to-white/0" }, rose: { bg: "bg-rose-50", text: "text-rose-600", border: "border-rose-300", gradient: "from-rose-500/5 via-rose-300/3 to-white/0" }, amber: { bg: "bg-amber-50", text: "text-amber-600", border: "border-amber-300", gradient: "from-amber-500/5 via-amber-300/3 to-white/0" }, cyan: { bg: "bg-cyan-50", text: "text-cyan-600", border: "border-cyan-300", gradient: "from-cyan-500/5 via-cyan-300/3 to-white/0" }, }; function resolveColor(categoryColor: string, productId: number) { if ((COLOR_KEYS as readonly string[]).includes(categoryColor)) { return COLOR_MAP[categoryColor as ColorKey]; } return COLOR_MAP[COLOR_KEYS[productId % COLOR_KEYS.length]]; } interface ProductCardProps { productId: number; name: string; category: string; categoryColor: string; iconUrl: string; yieldAPY: string; poolCap: string; maturity: string; risk: string; riskLevel: 1 | 2 | 3; lockUp: string; circulatingSupply: string; poolCapacityPercent: number; status?: 'active' | 'full' | 'ended'; onInvest?: () => void; } export default function ProductCard({ productId, name, category, categoryColor, iconUrl, yieldAPY, poolCap, maturity, risk, riskLevel, lockUp, circulatingSupply, poolCapacityPercent, status, onInvest, }: ProductCardProps) { const getRiskBars = () => { const bars = [ { height: "h-[5px]", active: riskLevel >= 1 }, { height: "h-[7px]", active: riskLevel >= 2 }, { height: "h-[11px]", active: riskLevel >= 3 }, ]; const activeColor = riskLevel === 1 ? "bg-green-500" : riskLevel === 2 ? "bg-amber-400" : "bg-red-500"; return bars.map((bar, index) => (
)); }; const colors = resolveColor(categoryColor, productId); const { t } = useApp(); const statusCfg = status ? status === 'ended' ? { label: t("product.statusEnded"), dot: "bg-gray-400", bg: "bg-gray-100", border: "border-gray-300", text: "text-gray-500" } : status === 'full' ? { label: t("product.statusFull"), dot: "bg-orange-500", bg: "bg-orange-50", border: "border-orange-200", text: "text-orange-600" } : { label: t("product.statusActive"), dot: "bg-green-500", bg: "bg-green-50", border: "border-green-200", text: "text-green-600" } : null; return ( {/* Product Header */}
{/* Icon Container */}
{name}
{/* Title, Category, Status */}

{name}

{statusCfg && (
{statusCfg.label}
)}
{/* Category badge: white bg + colored border, always visible against gradient */}
{category}
{/* Yield APY & Pool Cap */}
{t("productPage.yieldAPY")} {yieldAPY}
{t("productPage.poolCap")} {poolCap}
{/* Details Section */}
{/* Maturity & Risk */}
{t("productPage.maturity")} {maturity || "--"}
{t("productPage.risk")}
{risk || "--"}
{getRiskBars()}
{/* Lock-Up & Circulating Supply */}
{t("productPage.lockUp")} {lockUp || "--"}
{t("productPage.circulatingSupply")} {circulatingSupply || "--"}
{/* Pool Capacity & Invest Button */}
{t("productPage.poolCapacity")} {poolCapacityPercent.toFixed(4)}% {t("productPage.filled")}
); }