"use client" import type { Job } from "@/lib/types"; import { Card, CardContent, CardFooter, CardHeader, } from "@/components/ui/card"; import { Button } from "@/components/ui/button"; import { Badge } from "@/components/ui/badge"; import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar"; import { MapPin, Briefcase, DollarSign, Clock, Building2, Heart, } from "lucide-react"; import Link from "next/link"; import { motion } from "framer-motion"; import { useState } from "react"; import { useNotify } from "@/contexts/notification-context"; import { useTranslation } from "@/lib/i18n"; interface JobCardProps { job: Job; } export function JobCard({ job }: JobCardProps) { const { t } = useTranslation(); const [isFavorited, setIsFavorited] = useState(false); const notify = useNotify(); const formatTimeAgo = (dateString: string) => { const date = new Date(dateString); const now = new Date(); const diffInMs = now.getTime() - date.getTime(); const diffInDays = Math.floor(diffInMs / (1000 * 60 * 60 * 24)); if (diffInDays === 0) return t('jobs.posted.today'); if (diffInDays === 1) return t('jobs.posted.yesterday'); if (diffInDays < 7) return t('jobs.posted.daysAgo', { count: diffInDays }); if (diffInDays < 30) return t('jobs.posted.weeksAgo', { count: Math.floor(diffInDays / 7) }); return t('jobs.posted.monthsAgo', { count: Math.floor(diffInDays / 30) }); }; const getTypeLabel = (type: string) => { return t(`jobs.types.${type}`) !== `jobs.types.${type}` ? t(`jobs.types.${type}`) : type; }; const getTypeBadgeVariant = (type: string) => { switch (type) { case "full-time": return "default"; case "part-time": return "secondary"; case "contract": return "outline"; case "remote": return "default"; default: return "outline"; } }; const getCompanyInitials = (company: string) => { return company .split(" ") .map((word) => word[0]) .join("") .toUpperCase() .slice(0, 2); }; const handleFavorite = () => { setIsFavorited(!isFavorited); if (!isFavorited) { notify.info( t('jobs.favorites.added.title'), t('jobs.favorites.added.desc', { title: job.title }), { actionUrl: "/dashboard/favorites", actionLabel: t('jobs.favorites.action'), } ); } }; return (
{getCompanyInitials(job.company)}

{job.title}

{job.company}
{/* Job Meta Information */} {/* Job Meta Information */}
{job.location}
{getTypeLabel(job.type)}
{job.salary && ( {job.salary} )}
{/* Job Description Preview */}

{job.description}

{/* Skills/Requirements Preview */} {job.requirements && job.requirements.length > 0 && (
{job.requirements.slice(0, 3).map((requirement, index) => ( {requirement} ))} {job.requirements.length > 3 && ( {t('jobs.requirements.more', { count: job.requirements.length - 3 })} )}
)} {/* Time Posted */}
{formatTimeAgo(job.postedAt)}
); }