import { Link } from "wouter"; import { WorkWithAuthor } from "@/lib/types"; import { Heart } from "lucide-react"; import { Button } from "@/components/ui/button"; import { Badge } from "@/components/ui/badge"; import { LanguageTag } from "@/components/common/LanguageTag"; import { useState } from "react"; import { apiRequest } from "@/lib/queryClient"; import { useToast } from "@/hooks/use-toast"; interface WorkCardProps { work: WorkWithAuthor; compact?: boolean; grid?: boolean; } export function WorkCard({ work, compact = false, grid = false }: WorkCardProps) { const [likeCount, setLikeCount] = useState(work.likes || 0); const [isLiked, setIsLiked] = useState(false); const { toast } = useToast(); const handleLike = async (e: React.MouseEvent) => { e.preventDefault(); e.stopPropagation(); try { if (!isLiked) { await apiRequest('POST', '/api/likes', { userId: 1, // For demo, we'll use hardcoded user ID entityType: 'work', entityId: work.id }); setLikeCount(likeCount + 1); setIsLiked(true); } else { // In a real app, we would delete the specific like setLikeCount(likeCount - 1); setIsLiked(false); } } catch (error) { toast({ title: "Error", description: "Could not like this work. Please try again.", variant: "destructive" }); } }; if (grid) { return (

{work.title}

{work.author?.name || 'Unknown Author'}

{work.tags && work.tags.length > 0 ? ( work.tags.slice(0, 3).map((tag) => ( {tag.name} )) ) : ( General )}

{work.description}

{/* Assuming translations count would be available */} {Math.floor(Math.random() * 10) + 1} translations
); } return (

{work.title}

{work.type === 'poem' ? 'Poem' : work.type === 'story' ? 'Short story' : work.type === 'novel' ? 'Novel' : work.type === 'play' ? 'Play' : work.type === 'essay' ? 'Essay' : 'Work'}, {work.year}
{!compact && (

{work.description}

)}
{work.tags && work.tags.length > 0 ? ( work.tags.map((tag) => ( {tag.name} )) ) : ( General )}
{/* Assuming translations count would be available */} {Math.floor(Math.random() * 10) + 1} translations
); }