'use client';
import { useTranslations } from 'next-intl';
import { FileText } from 'lucide-react';
import type { PastTreatment } from '@/types/treatment';
import { CaseSentLabel } from '@/components/ui/treatment/CaseSentLabel';
const TREATMENT_TYPE_KEYS = {
consultation: 'typeConsultation',
filling: 'typeFilling',
endo: 'typeEndo',
visit: 'typeVisit',
hygiene: 'typeHygiene',
} as const;
interface PastTreatmentsPanelProps {
items: PastTreatment[];
loading?: boolean;
onReviewTreatment?: (treatment: PastTreatment) => void;
}
export function PastTreatmentsPanel({
items,
loading,
onReviewTreatment,
}: PastTreatmentsPanelProps) {
const t = useTranslations('treatment');
const tCommon = useTranslations('common');
return (
{t('historyTitle')}
{t('historySubtitle')}
{loading &&
{t('loadingHistory')}
}
{!loading && items.length === 0 && (
{t('historyEmpty')}
)}
{items.map((treatment) => (
{treatment.title}
{t('statusLabel')} {treatment.status}
{treatment.details.map((c, idx) => {
const attachments = c.attachmentMetas ?? [];
const typeKey = TREATMENT_TYPE_KEYS[c.treatmentType as keyof typeof TREATMENT_TYPE_KEYS];
const typeLabel = typeKey ? t(typeKey) : c.treatmentType;
return (
{t('historyCaseLabel', { n: idx + 1, type: typeLabel })}
{c.sentAt && (
)}
{t('teethLabel')} {c.teeth.length ? [...c.teeth].sort().join(', ') : t('teethNone')}
{c.notes?.trim() && (
{c.notes}
)}
{t('attachments')}
{attachments.length === 0 ? (
{tCommon('none')}
) : (
{attachments.map((doc) => (
-
{doc.fileName}
{(doc.sizeBytes / 1024).toFixed(1)} KB
))}
)}
);
})}
{onReviewTreatment && (
)}
))}
);
}