import Link from "next/link"; import type { MarketListing, MarketNegotiation } from "@/payload-types"; import { ChevronRightIcon, HandshakeIcon } from "lucide-react"; import type { CurrencyConfig } from "@/lib/banking/format"; import { CurrencyAmount } from "@/components/frontend/banking/CurrencyAmount"; import { TacticalFrame } from "./tactical"; interface OpenNegotiationsProps { readonly negotiations: MarketNegotiation[]; readonly currentUserId: number; readonly currencyConfig: CurrencyConfig; } function listingOf(negotiation: MarketNegotiation): MarketListing | null { return typeof negotiation.listing === "object" && negotiation.listing ? (negotiation.listing as MarketListing) : null; } function assetNameOf(listing: MarketListing | null): string { const asset = listing?.asset; return typeof asset === "object" && asset ? asset.name : "Unknown item"; } function buyerIdOf(negotiation: MarketNegotiation): number | null { return typeof negotiation.buyer === "object" && negotiation.buyer ? negotiation.buyer.id : negotiation.buyer; } export function OpenNegotiations({ negotiations, currentUserId, currencyConfig, }: OpenNegotiationsProps) { // Deliberately hidden when there is nothing on the table (same convention as // NegotiationPanel on the market page). if (negotiations.length === 0) return null; const fmt = (n: number) => ; return (

Negotiations

{negotiations.length} open
Market
{negotiations.map((negotiation) => { const listing = listingOf(negotiation); const role = buyerIdOf(negotiation) === currentUserId ? "buyer" : "seller"; const theirProposal = (role === "buyer" && negotiation.proposedBy === "seller") || (role === "seller" && negotiation.proposedBy === "buyer"); const quantity = negotiation.quantity ?? listing?.quantity ?? 1; return (
{assetNameOf(listing)} {role === "buyer" ? "Buying" : "Selling"}
{fmt(negotiation.amount ?? 0)} each · {quantity}× ·{" "} {theirProposal ? "their offer" : "your offer"}
); })}
); }