import { useState, useEffect } from 'react'; import Link from 'next/link'; import Head from 'next/head'; interface Listing { id: string; title: string; description: string; price: number; currency: string; quantity: number; category: string; status: string; sellerName?: string; location?: { city?: string; region?: string }; tags: string[]; viewCount: number; createdAt: string; } interface MarketplaceStats { totalListings: number; activeListings: number; totalSales: number; topCategories: { category: string; count: number }[]; } const categoryLabels: Record = { seeds: 'Seeds', seedlings: 'Seedlings', mature_plants: 'Mature Plants', cuttings: 'Cuttings', produce: 'Produce', supplies: 'Supplies', }; const categoryIcons: Record = { seeds: '🌰', seedlings: '🌱', mature_plants: '🪴', cuttings: '✂️', produce: '🥬', supplies: '🧰', }; export default function MarketplacePage() { const [featured, setFeatured] = useState([]); const [recent, setRecent] = useState([]); const [stats, setStats] = useState(null); const [popularTags, setPopularTags] = useState<{ tag: string; count: number }[]>([]); const [loading, setLoading] = useState(true); const [searchQuery, setSearchQuery] = useState(''); useEffect(() => { fetchMarketplaceData(); }, []); const fetchMarketplaceData = async () => { try { const response = await fetch('/api/marketplace/featured'); const data = await response.json(); if (!response.ok) { throw new Error(data.error || 'Failed to fetch marketplace data'); } setFeatured(data.featured || []); setRecent(data.recent || []); setStats(data.stats || null); setPopularTags(data.popularTags || []); } catch (error) { console.error('Error fetching marketplace data:', error); } finally { setLoading(false); } }; const handleSearch = (e: React.FormEvent) => { e.preventDefault(); if (searchQuery.trim()) { window.location.href = `/marketplace/listings?q=${encodeURIComponent(searchQuery)}`; } }; return (
Plant Marketplace - LocalGreenChain {/* Header */}
{/* Hero Section */}

Plant Marketplace

Buy and sell plants, seeds, and produce from local growers

{/* Search Bar */}
setSearchQuery(e.target.value)} placeholder="Search for plants, seeds, produce..." className="flex-1 px-6 py-4 rounded-lg text-gray-900 text-lg focus:ring-2 focus:ring-green-300 focus:outline-none" />
{/* Stats */} {stats && (
{stats.activeListings}
Active Listings
{stats.totalSales}
Completed Sales
)}
{/* Main Content */}
{loading ? (

Loading marketplace...

) : ( <> {/* Categories */}

Browse Categories

{/* Featured Listings */} {featured.length > 0 && (

Featured Listings

View all
{featured.map((listing) => ( ))}
)} {/* Recent Listings */} {recent.length > 0 && (

Recently Added

View all
{recent.slice(0, 6).map((listing) => ( ))}
)} {/* Popular Tags */} {popularTags.length > 0 && (

Popular Tags

{popularTags.map(({ tag, count }) => ( {tag} ({count}) ))}
)} {/* CTA Section */}

Ready to Start Selling?

List your plants, seeds, or produce and connect with local buyers.

Create Your First Listing
)}
); } function ListingCard({ listing }: { listing: Listing }) { return (
{categoryIcons[listing.category] || '🌿'}

{listing.title}

${listing.price.toFixed(2)}

{listing.description}

{categoryLabels[listing.category]} {listing.quantity} available
{listing.sellerName && (
by {listing.sellerName}
)} {listing.tags.length > 0 && (
{listing.tags.slice(0, 3).map((tag) => ( {tag} ))}
)}
); }