import { useState } from 'react'; import { IndJob } from '@/lib/types'; import { formatISK } from '@/utils/priceUtils'; import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card'; import { Popover, PopoverContent, PopoverTrigger } from '@/components/ui/popover'; import { useNavigate } from 'react-router-dom'; import { ChevronDown, ChevronUp } from 'lucide-react'; import { getStatusBackgroundColor } from '@/utils/jobStatusUtils'; interface RecapPopoverProps { title: string; jobs: IndJob[]; children: React.ReactNode; calculateJobValue: (job: IndJob) => number; } const RecapPopover: React.FC = ({ title, jobs, children, calculateJobValue }) => { const navigate = useNavigate(); const [sortDescending, setSortDescending] = useState(true); const jobContributions = jobs .map(job => ({ job, value: calculateJobValue(job) })) .filter(({ value }) => value !== 0) .sort((a, b) => sortDescending ? Math.abs(b.value) - Math.abs(a.value) : Math.abs(a.value) - Math.abs(b.value)); const handleJobClick = (jobId: string) => { navigate(`/${jobId}`); }; const toggleSort = (e: React.MouseEvent) => { e.stopPropagation(); setSortDescending(!sortDescending); }; const handleItemClick = (e: React.MouseEvent, jobId: string) => { // Check if the clicked element or its parent has data-no-navigate const target = e.target as HTMLElement; const hasNoNavigate = target.closest('[data-no-navigate]'); if (!hasNoNavigate) { handleJobClick(jobId); } }; return ( {children} {title} {jobContributions.length === 0 ? (

No contributions to display

) : ( jobContributions.map(({ job, value }) => (
handleItemClick(e, job.id)} className={`flex justify-between items-center p-2 rounded hover:bg-gray-700/50 cursor-pointer transition-colors border-l-2 border-l-gray-600 ${getStatusBackgroundColor(job.status)}`} >
{job.outputItem}
ID: {job.id}
= 0 ? 'text-green-400' : 'text-red-400'}`}> {formatISK(value)}
)) )}
); }; export default RecapPopover;