'use client'; import { Collection } from '../../types/api'; import { getImageUrl } from '../../lib/api'; import Link from 'next/link'; interface CollectionCardProps { collection: Collection; viewMode: 'grid' | 'list'; onUpdate?: () => void; } export default function CollectionCard({ collection, viewMode, onUpdate }: CollectionCardProps) { const formatReadingTime = (minutes: number): string => { if (minutes < 60) { return `${minutes}m`; } const hours = Math.floor(minutes / 60); const remainingMinutes = minutes % 60; return remainingMinutes > 0 ? `${hours}h ${remainingMinutes}m` : `${hours}h`; }; const renderRatingStars = (rating?: number) => { if (!rating) return null; return (
{[1, 2, 3, 4, 5].map((star) => ( ))}
); }; if (viewMode === 'grid') { return (
{/* Cover Image or Placeholder */}
{collection.coverImagePath ? ( {`${collection.name} ) : (
{collection.storyCount}
{collection.storyCount === 1 ? 'story' : 'stories'}
)} {collection.isArchived && (
Archived
)}
{/* Collection Info */}

{collection.name}

{collection.description && (

{collection.description}

)}
{collection.storyCount} stories {collection.estimatedReadingTime ? formatReadingTime(collection.estimatedReadingTime) : '—'}
{collection.rating && (
{renderRatingStars(collection.rating)}
)} {/* Tags */} {collection.tags && collection.tags.length > 0 && (
{collection.tags.slice(0, 3).map((tag) => ( {tag.name} ))} {collection.tags.length > 3 && ( +{collection.tags.length - 3} more )}
)}
); } // List view return (
{/* Cover Image */}
{collection.coverImagePath ? ( {`${collection.name} ) : (
{collection.storyCount}
)}
{/* Collection Details */}

{collection.name} {collection.isArchived && ( Archived )}

{collection.description && (

{collection.description}

)}
{collection.storyCount} stories {collection.estimatedReadingTime ? formatReadingTime(collection.estimatedReadingTime) : '—'} reading {collection.averageStoryRating && collection.averageStoryRating > 0 && ( ★ {collection.averageStoryRating.toFixed(1)} avg )}
{/* Tags */} {collection.tags && collection.tags.length > 0 && (
{collection.tags.slice(0, 5).map((tag) => ( {tag.name} ))} {collection.tags.length > 5 && ( +{collection.tags.length - 5} more )}
)}
{collection.rating && (
{renderRatingStars(collection.rating)}
)}
); }