"use client"; import { useMemo, useState } from "react"; import type { Asset, LockerStorage, MarketListing, MarketNegotiation } from "@/payload-types"; import { Input } from "@/components/ui/input"; import { Label } from "@/components/ui/label"; import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue, } from "@/components/ui/select"; import { RARITY_LABELS } from "@/lib/market"; import { ListingCard } from "@/components/frontend/market/ListingCard"; import { CreateListingDialog } from "@/components/frontend/market/CreateListingDialog"; import { NegotiationPanel } from "@/components/frontend/market/NegotiationPanel"; import { SearchIcon } from "lucide-react"; const ASSET_TYPE_OPTIONS: { value: string; label: string }[] = [ { value: "weapon", label: "Weapon" }, { value: "magazine", label: "Magazine" }, { value: "optic", label: "Optic" }, { value: "muzzle", label: "Muzzle" }, { value: "bipod", label: "Bipod" }, { value: "uniform", label: "Uniform" }, { value: "vest", label: "Vest" }, { value: "backpack", label: "Backpack" }, { value: "helmet", label: "Helmet" }, { value: "facewear", label: "Facewear" }, { value: "nvg", label: "NVG" }, { value: "radio", label: "Radio" }, { value: "medical", label: "Medical" }, { value: "tool", label: "Tool" }, { value: "explosive", label: "Explosive" }, { value: "skin", label: "Skin" }, { value: "miscellaneous", label: "Miscellaneous" }, ]; const RARITY_OPTIONS = Object.entries(RARITY_LABELS); function assetName(listing: MarketListing): string { const asset = listing.asset as Asset; return typeof asset === "object" && asset ? asset.name.toLowerCase() : ""; } function assetTypeOf(listing: MarketListing): string | null { const asset = listing.asset as Asset; return typeof asset === "object" && asset ? asset.assetType : null; } function rarityOf(listing: MarketListing): string | null { const asset = listing.asset as Asset; return typeof asset === "object" && asset ? (asset.marketTrading?.Rarity ?? null) : null; } interface MarketViewProps { listings: MarketListing[]; myListings: MarketListing[]; negotiations: MarketNegotiation[]; locker: LockerStorage | null; currentUserId: number; currencyLabel: string | null; isManager: boolean; } export function MarketView({ listings, myListings, negotiations, locker, currentUserId, currencyLabel, isManager, }: MarketViewProps) { const [search, setSearch] = useState(""); const [rarity, setRarity] = useState("all"); const [assetType, setAssetType] = useState("all"); const filtered = useMemo(() => { const q = search.trim().toLowerCase(); const myIds = new Set(myListings.map((l) => l.id)); return listings.filter((listing) => { if (myIds.has(listing.id)) return false; if (rarity !== "all" && rarityOf(listing) !== rarity) return false; if (assetType !== "all" && assetTypeOf(listing) !== assetType) return false; if (q && !assetName(listing).includes(q)) return false; return true; }); }, [listings, myListings, search, rarity, assetType]); return (
setSearch(e.target.value)} />

For sale

{filtered.length} listing{filtered.length !== 1 ? "s" : ""}
{filtered.length === 0 ? (

No listings match. Try clearing the filters.

) : (
{filtered.map((listing) => ( ))}
)}
{myListings.length > 0 && (

My listings

{myListings.length} active
{myListings.map((listing) => ( ))}
)}
); }