'use client'; import { useState } from 'react'; import { Input } from '@/components/ui'; import { Textarea } from '@/components/ui'; import { Button } from '@/components/ui'; import { Badge } from '@/components/ui'; import type { KeyResult, KeyResultStatus } from '@/lib/types'; import { KEY_RESULT_STATUS_LABELS } from '@/lib/types'; // Helper function for Key Result status colors function getKeyResultStatusColor(status: KeyResultStatus): { bg: string; color: string } { switch (status) { case 'NOT_STARTED': return { bg: 'color-mix(in srgb, #6b7280 15%, transparent)', // gray-500 color: '#6b7280', }; case 'IN_PROGRESS': return { bg: 'color-mix(in srgb, #3b82f6 15%, transparent)', // blue-500 color: '#3b82f6', }; case 'COMPLETED': return { bg: 'color-mix(in srgb, #10b981 15%, transparent)', // green-500 color: '#10b981', }; case 'AT_RISK': return { bg: 'color-mix(in srgb, #f59e0b 15%, transparent)', // amber-500 (orange/yellow) color: '#f59e0b', }; default: return { bg: 'color-mix(in srgb, #6b7280 15%, transparent)', color: '#6b7280', }; } } interface KeyResultItemProps { keyResult: KeyResult; okrId: string; canEdit: boolean; onUpdate?: () => void; } export function KeyResultItem({ keyResult, okrId, canEdit, onUpdate }: KeyResultItemProps) { const [currentValue, setCurrentValue] = useState(keyResult.currentValue); const [notes, setNotes] = useState(keyResult.notes || ''); const [updating, setUpdating] = useState(false); const [isEditing, setIsEditing] = useState(false); const progress = keyResult.targetValue > 0 ? (currentValue / keyResult.targetValue) * 100 : 0; const progressColor = progress >= 100 ? 'var(--success)' : progress >= 50 ? 'var(--accent)' : 'var(--destructive)'; const handleUpdate = async () => { setUpdating(true); try { const response = await fetch(`/api/okrs/${okrId}/key-results/${keyResult.id}`, { method: 'PATCH', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ currentValue: Number(currentValue), notes: notes || null, }), }); if (!response.ok) { const error = await response.json(); alert(error.error || 'Erreur lors de la mise à jour'); return; } setIsEditing(false); onUpdate?.(); } catch (error) { console.error('Error updating key result:', error); alert('Erreur lors de la mise à jour'); } finally { setUpdating(false); } }; return (