import { useState, useEffect } from 'react'; import { useRouter } from 'next/router'; import Layout from '../../components/Layout'; export default function CollectionView() { const router = useRouter(); const { id } = router.query; // Mock user data for now const user = { email: 'me@randallstillwell.com', role: 'user' }; const [collection, setCollection] = useState(null); const [cards, setCards] = useState([]); const [loading, setLoading] = useState(true); const [isFavorited, setIsFavorited] = useState(false); const [showShareModal, setShowShareModal] = useState(false); const [copySuccess, setCopySuccess] = useState(false); // Filter states const [searchQuery, setSearchQuery] = useState(''); const [selectedRarity, setSelectedRarity] = useState('all'); const [selectedType, setSelectedType] = useState('all'); const [sortBy, setSortBy] = useState('name'); const [viewMode, setViewMode] = useState('grid'); // grid or list // Mock collection data const mockCollection = { id: 1, name: "King PikaRomulus", description: "A competitive Pokemon deck focused on Pikachu and powerful electric types", creator: "Emberwing", format: "Standard", cost: "$1,430", cardCount: 60, createdAt: "2023-04-12", lastUpdated: "2 months ago", isPublic: true, isOfficial: false, tags: ["competitive", "electric", "pikachu", "standard"], tcg: "Pokemon", playGuide: "How to play King PikaRomulus", views: 2847, favorites: 156, copies: 89 }; // Mock cards data const mockCards = [ { id: 1, name: "Pikachu VMAX", set: "Vivid Voltage", rarity: "Rainbow Rare", type: "Electric", cost: 45.99, quantity: 1, image: "https://images.pokemontcg.io/swsh4/188_hires.png" }, { id: 2, name: "Professor's Research", set: "Champion's Path", rarity: "Uncommon", type: "Trainer", cost: 2.50, quantity: 4, image: "https://images.pokemontcg.io/swsh35/62_hires.png" }, { id: 3, name: "Quick Ball", set: "Sword & Shield", rarity: "Uncommon", type: "Trainer", cost: 1.25, quantity: 4, image: "https://images.pokemontcg.io/swsh1/179_hires.png" }, { id: 4, name: "Lightning Energy", set: "Basic Energy", rarity: "Common", type: "Energy", cost: 0.10, quantity: 12, image: "https://images.pokemontcg.io/base1/100_hires.png" }, { id: 5, name: "Zapdos V", set: "Chilling Reign", rarity: "Ultra Rare", type: "Electric", cost: 8.75, quantity: 2, image: "https://images.pokemontcg.io/swsh6/166_hires.png" }, { id: 6, name: "Ultra Ball", set: "Plasma Freeze", rarity: "Uncommon", type: "Trainer", cost: 3.20, quantity: 3, image: "https://images.pokemontcg.io/pl9/122_hires.png" } ]; useEffect(() => { if (id) { // Simulate API call setTimeout(() => { setCollection(mockCollection); setCards(mockCards); setLoading(false); }, 500); } }, [id]); const handleCopyLink = async () => { try { await navigator.clipboard.writeText(window.location.href); setCopySuccess(true); setTimeout(() => setCopySuccess(false), 2000); } catch (err) { console.error('Failed to copy link:', err); } }; const handleFavorite = () => { setIsFavorited(!isFavorited); // Here you would typically make an API call }; const handleSaveCopy = () => { // Logic to save a copy to user's collections console.log('Saving copy of collection'); }; const filteredCards = cards.filter(card => { const matchesSearch = card.name.toLowerCase().includes(searchQuery.toLowerCase()); const matchesRarity = selectedRarity === 'all' || card.rarity === selectedRarity; const matchesType = selectedType === 'all' || card.type === selectedType; return matchesSearch && matchesRarity && matchesType; }); const sortedCards = [...filteredCards].sort((a, b) => { switch (sortBy) { case 'name': return a.name.localeCompare(b.name); case 'cost': return b.cost - a.cost; case 'rarity': return a.rarity.localeCompare(b.rarity); case 'type': return a.type.localeCompare(b.type); default: return 0; } }); const totalValue = cards.reduce((sum, card) => sum + (card.cost * card.quantity), 0); const totalCards = cards.reduce((sum, card) => sum + card.quantity, 0); if (loading) { return (
); } if (!collection) { return (

Collection not found

); } return ( {/* Hero Section with Collection Info */}
👑

{collection.name}

👤
Crafted by {collection.creator}
Format: {collection.format} Cost: {collection.cost} Appears in: {collection.playGuide} +4 more
Created {collection.createdAt} Last updated {collection.lastUpdated}
{/* Action Buttons */}
{/* Stats and Filters */}
{/* Collection Stats */}
{totalCards}
Total Cards
${totalValue.toFixed(2)}
Total Value
{collection.views}
Views
{collection.favorites}
Favorites
{/* Filters */}
setSearchQuery(e.target.value)} />
{/* Cards Display */}

Cards ({sortedCards.length})

{viewMode === 'grid' ? (
{sortedCards.map(card => (
router.push(`/card/${card.id}`)} >
{card.name} { e.target.src = 'https://via.placeholder.com/250x350/6366f1/ffffff?text=No+Image'; }} /> {card.quantity > 1 && (
{card.quantity}x
)}
{card.name}
${card.cost}
))}
) : (
{sortedCards.map(card => (
router.push(`/card/${card.id}`)} > {card.name} { e.target.src = 'https://via.placeholder.com/64x88/6366f1/ffffff?text=No+Image'; }} />

{card.name}

{card.set} • {card.rarity} • {card.type}
${card.cost}
Qty: {card.quantity}
))}
)} {sortedCards.length === 0 && (
🔍

No cards found

Try adjusting your search or filter criteria

)}
{/* Share Modal */} {showShareModal && (

Share Collection

)}
); }