import React, { useState } from 'react'; import { useTranslation } from 'react-i18next'; import { ExternalLink, Edit2, RefreshCw, Trash2, AlertTriangle, Clock, Tag, History } from 'lucide-react'; import { Card, CardContent, CardFooter, CardHeader } from '@/components/ui/card'; import { Button } from '@/components/ui/button'; import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '@/components/ui/select'; import { Dialog, DialogContent, DialogHeader, DialogTitle, DialogFooter } from '@/components/ui/dialog'; import { Input } from '@/components/ui/input'; import { Label } from '@/components/ui/label'; import { Marquee } from '@/components/ui/marquee'; import { cn } from '@/lib/utils'; export function ItemCard({ item, onEdit, onDelete, onCheck, onZoom, onCategoryUpdate, categories, onViewHistory }) { const { t } = useTranslation(); const [showCategorySelect, setShowCategorySelect] = useState(false); const [showNewCategoryDialog, setShowNewCategoryDialog] = useState(false); const [newCategoryName, setNewCategoryName] = useState(''); const getStockStatus = (inStock) => { if (inStock === true) return { label: t('dashboard.inStock'), color: 'bg-green-500/90 text-white border-green-400/50' }; if (inStock === false) return { label: t('dashboard.outOfStock'), color: 'bg-red-500/90 text-white border-red-400/50' }; return { label: t('dashboard.stockUnknown'), color: 'bg-zinc-500/90 text-white border-zinc-400/50' }; }; const stockStatus = getStockStatus(item.in_stock); return (
onZoom(item.screenshot_url)}> {item.screenshot_url ? ( <> {`Screenshot { e.target.style.display = 'none' }} />
) : (
Pas de capture
)} {/* Stock Confidence Bar */} {(item.in_stock_confidence !== null && item.in_stock_confidence !== undefined) && (
0.8 ? 'bg-emerald-500' : item.in_stock_confidence > 0.5 ? 'bg-yellow-500' : 'bg-red-500' )} style={{ width: `${item.in_stock_confidence * 100}%` }} title={`Stock Confidence: ${Math.round(item.in_stock_confidence * 100)}%`} />
)} {/* Stock Badge */}
{stockStatus.label}
{new URL(item.url).hostname.replace('www.', '')}
{t('dashboard.currentPrice')} {item.target_price && ( {t('dashboard.targetPrice')}: {item.target_price}€ )}
{item.current_price ? `${item.current_price}€` : '---'}
{/* Price Confidence Bar */} {(item.current_price_confidence !== null && item.current_price_confidence !== undefined) && (
0.8 ? 'bg-primary' : item.current_price_confidence > 0.5 ? 'bg-primary/70' : 'bg-primary/40' )} style={{ width: `${item.current_price_confidence * 100}%` }} />
{t('dashboard.confidence')} (prix): {Math.round(item.current_price_confidence * 100)}%
)}
{/* Tags */} {item.tags && (
{item.tags.split(',').map(tag => ( {tag.trim()} ))}
)} {/* Category */}
{item.category ? ( {item.category} ) : null} {onCategoryUpdate && ( )}
{/* New Category Dialog */} Nouvelle catégorie
setNewCategoryName(e.target.value)} placeholder="ex: Électronique" onKeyDown={(e) => { if (e.key === 'Enter' && newCategoryName.trim()) { onCategoryUpdate(item.id, newCategoryName.trim()); setNewCategoryName(''); setShowNewCategoryDialog(false); } }} />
{/* Description */} {item.description && (

{item.description}

)}
{item.last_checked ? new Date(item.last_checked).toLocaleString('fr-FR') : t('dashboard.never')}
{item.last_error && (
{t('common.error')}
)}
{onViewHistory && ( )}
); }