import { Play, Share2 } from "lucide-react"; import { type Video } from "@shared/schema"; import { Button } from "@/components/ui/button"; interface VideoCardProps { video: Video; onClick: (video: Video) => void; } function formatDuration(seconds: number): string { const minutes = Math.floor(seconds / 60); const remainingSeconds = seconds % 60; return `${minutes}:${remainingSeconds.toString().padStart(2, '0')}`; } function formatViews(views: number): string { if (views >= 1000000) { return `${(views / 1000000).toFixed(1)}M views`; } else if (views >= 1000) { return `${(views / 1000).toFixed(1)}K views`; } return `${views} views`; } function formatDate(date: Date | string): string { const now = new Date(); const createdDate = typeof date === 'string' ? new Date(date) : date; if (!createdDate || isNaN(createdDate.getTime())) { return "Unknown"; } const diffTime = Math.abs(now.getTime() - createdDate.getTime()); const diffDays = Math.floor(diffTime / (1000 * 60 * 60 * 24)); if (diffDays === 0) return "Today"; if (diffDays === 1) return "1 day ago"; if (diffDays < 7) return `${diffDays} days ago`; if (diffDays < 30) return `${Math.floor(diffDays / 7)} week${Math.floor(diffDays / 7) > 1 ? 's' : ''} ago`; return `${Math.floor(diffDays / 30)} month${Math.floor(diffDays / 30) > 1 ? 's' : ''} ago`; } export default function VideoCard({ video, onClick }: VideoCardProps) { const handleShare = async (e: React.MouseEvent) => { e.stopPropagation(); // Prevent video modal from opening const shareUrl = `${window.location.origin}/?video=${video.id}`; const shareData = { title: video.title, text: `Check out this video: ${video.title}`, url: shareUrl, }; try { if (navigator.share) { // Use native share API if available (mobile devices) await navigator.share(shareData); } else { // Fallback: copy to clipboard await navigator.clipboard.writeText(shareUrl); alert('Video link copied to clipboard!'); } } catch (err) { console.error('Error sharing:', err); } }; return (
onClick(video)} data-testid={`card-video-${video.id}`} >
{video.title}
{formatDuration(video.duration)}
{/* Share button */}

{video.title}

{formatViews(video.views)} {formatDate(video.createdAt)}
); }