import Image from "next/image"; import { acceptOffer } from "@/lib/actions/offers"; import { Badge } from "@/components/ui/badge"; import { Button } from "@/components/ui/button"; import { Card, CardContent } from "@/components/ui/card"; type Offer = { id: string; title: string; description: string; price: number; status: string; merchant_id: string; profiles: { full_name: string | null } | { full_name: string | null }[] | null; offer_images: { storage_path: string; position: number }[] | null; }; const STATUS_LABEL: Record = { pending: "En attente", accepted: "Acceptée", rejected: "Refusée", withdrawn: "Retirée", }; export function OfferList({ offers, needId, needStatus, isOwner, getImageUrl, }: { offers: Offer[]; needId: string; needStatus: string; isOwner: boolean; getImageUrl: (path: string) => string; }) { if (offers.length === 0) { return (

Aucune offre reçue pour le moment.

); } return (
{offers.map((offer) => { const merchant = Array.isArray(offer.profiles) ? offer.profiles[0] : offer.profiles; const images = [...(offer.offer_images ?? [])].sort( (a, b) => a.position - b.position ); return (
{merchant?.full_name ?? "Commerçant"} {STATUS_LABEL[offer.status] ?? offer.status}

{offer.title}

{offer.description}

{offer.price} €

{images.length > 0 && (
{images.map((img) => (
{offer.title}
))}
)} {isOwner && needStatus === "open" && offer.status === "pending" && (
)}
); })}
); }