'use client'; import { MessageSquare } from 'lucide-react'; import { useTranslations } from 'next-intl'; import { Badge } from '@/components/ui/shared/Badge'; import { FORM_SELECT_CLASS } from '@/components/shared/formSelectStyles'; import { LabCaseCommentsPanel } from '@/components/ui/lab/LabCaseCommentsPanel'; import { labTaskStatusSelectStyle, labTaskStatusVariant, } from '@/components/lab/labTaskStatusDisplay'; import { formatToothList, prosthesisTypeBadgeStyleFromCatalog, } from '@/components/treatment/prosthesisTypeDisplay'; import { tasksApi } from '@/lib/api/tasks'; import type { LabTaskListItem, LabTaskStatus } from '@/types/cases'; import type { ProsthesisCatalogEntry } from '@/types/treatment-catalog'; interface TaskRowProps { task: LabTaskListItem; locale: string; flatMode: boolean; canEdit: boolean; statusOptions: { value: LabTaskStatus; label: string }[]; updatingTaskId: string | null; commentsOpen: boolean; prosthesisCatalog: readonly ProsthesisCatalogEntry[]; onStatusUpdate: (taskId: string, status: LabTaskStatus) => void; onToggleComments: (taskId: string) => void; onCommentError: (message: string) => void; } function formatPatientName(patient: { firstName: string; lastName: string }) { return `${patient.firstName} ${patient.lastName}`.trim(); } export function TaskRow({ task, locale, flatMode, canEdit, statusOptions, updatingTaskId, commentsOpen, prosthesisCatalog, onStatusUpdate, onToggleComments, onCommentError, }: TaskRowProps) { const t = useTranslations('tasks'); const taskDate = new Intl.DateTimeFormat(locale, { year: 'numeric', month: 'short', day: 'numeric', }).format(new Date(task.createdAt)); return (
  • {task.stepOrder}. {task.stepLabel}

    {flatMode && task.isImportant ? ( {t('importantBadge')} ) : null}
    {flatMode ? (

    {t('fromClinic', { name: task.clinic.name })} · {formatPatientName(task.patient)}{' '} · {t('teethLabel', { teeth: formatToothList(task.teeth) })}

    ) : null}

    {t('taskDate', { date: taskDate })} {task.lastStatusChangedBy ? ( <> · {t('lastUpdatedBy', { name: task.lastStatusChangedBy.name })} ) : null}

    {canEdit ? ( ) : ( {statusOptions.find((opt) => opt.value === task.status)?.label ?? task.status} )}
    {canEdit ? ( ) : null} {flatMode ? ( {task.prosthesisTypeLabel} ) : null}
    {commentsOpen && canEdit ? (
    { const r = await tasksApi.listComments(task.labCaseId); return r.data; }} onPost={async (body, visibleToClinic) => { const r = await tasksApi.addComment(task.labCaseId, { body, visibleToClinic, }); return r.data; }} onToggleVisibility={async (commentId, visible) => { const r = await tasksApi.setCommentVisibility(commentId, visible); return r.data; }} onError={onCommentError} />
    ) : null}
  • ); }