import React from 'react'; import { useTranslation } from 'react-i18next'; import { ClockIcon } from '@heroicons/react/24/outline'; import TaskDeferUntilSection from '../TaskForm/TaskDeferUntilSection'; import { Task } from '../../../entities/Task'; interface TaskDeferUntilCardProps { task: Task; isEditing: boolean; editedDeferUntil: string; onChangeDateTime: (value: string) => void; onStartEdit: () => void; onSave: () => void; onCancel: () => void; } const TaskDeferUntilCard: React.FC = ({ task, isEditing, editedDeferUntil, onChangeDateTime, onStartEdit, onSave, onCancel, }) => { const { t, i18n } = useTranslation(); const getDeferUntilDisplay = (deferUntil: string) => { const date = new Date(deferUntil); if (Number.isNaN(date.getTime())) return null; const formattedDateTime = date.toLocaleString(i18n.language, { day: '2-digit', month: '2-digit', year: 'numeric', hour: '2-digit', minute: '2-digit', }); const now = new Date(); const diffMs = date.getTime() - now.getTime(); const diffMins = Math.round(diffMs / (1000 * 60)); const diffHours = Math.round(diffMs / (1000 * 60 * 60)); const diffDays = Math.round(diffMs / (1000 * 60 * 60 * 24)); let relativeText = ''; if (diffMins < 0) { if (diffDays < -1) { relativeText = t('task.daysAgo', '{{count}} days ago', { count: Math.abs(diffDays), }); } else if (diffHours < -1) { relativeText = t('task.hoursAgo', '{{count}} hours ago', { count: Math.abs(diffHours), }); } else { relativeText = t('task.minutesAgo', '{{count}} minutes ago', { count: Math.abs(diffMins), }); } } else if (diffMins < 60) { relativeText = t('task.inMinutes', 'in {{count}} minutes', { count: diffMins, }); } else if (diffHours < 24) { relativeText = t('task.inHours', 'in {{count}} hours', { count: diffHours, }); } else { relativeText = t('task.inDays', 'in {{count}} days', { count: diffDays, }); } return { formattedDateTime, relativeText, isPast: diffMs < 0 }; }; return (

{t('task.deferUntil', 'Defer Until')}

{isEditing ? (
) : ( )}
); }; export default TaskDeferUntilCard;