2026-05-07 03:40:29 +03:30
|
|
|
'use client';
|
|
|
|
|
|
2026-06-20 14:51:43 +03:30
|
|
|
import { useTranslations } from 'next-intl';
|
2026-05-07 03:40:29 +03:30
|
|
|
import { FileText } from 'lucide-react';
|
|
|
|
|
import type { PastTreatment } from '@/types/treatment';
|
2026-05-19 23:43:43 +03:30
|
|
|
import { CaseSentLabel } from '@/components/ui/treatment/CaseSentLabel';
|
2026-05-07 03:40:29 +03:30
|
|
|
|
2026-06-20 14:51:43 +03:30
|
|
|
const TREATMENT_TYPE_KEYS = {
|
|
|
|
|
consultation: 'typeConsultation',
|
|
|
|
|
filling: 'typeFilling',
|
|
|
|
|
endo: 'typeEndo',
|
|
|
|
|
visit: 'typeVisit',
|
|
|
|
|
hygiene: 'typeHygiene',
|
|
|
|
|
} as const;
|
|
|
|
|
|
2026-05-07 03:40:29 +03:30
|
|
|
interface PastTreatmentsPanelProps {
|
|
|
|
|
items: PastTreatment[];
|
|
|
|
|
loading?: boolean;
|
2026-05-19 23:43:43 +03:30
|
|
|
onReviewTreatment?: (treatment: PastTreatment) => void;
|
2026-05-07 03:40:29 +03:30
|
|
|
}
|
|
|
|
|
|
2026-05-07 14:20:50 +03:30
|
|
|
export function PastTreatmentsPanel({
|
|
|
|
|
items,
|
|
|
|
|
loading,
|
2026-05-19 23:43:43 +03:30
|
|
|
onReviewTreatment,
|
2026-05-07 14:20:50 +03:30
|
|
|
}: PastTreatmentsPanelProps) {
|
2026-06-20 14:51:43 +03:30
|
|
|
const t = useTranslations('treatment');
|
|
|
|
|
const tCommon = useTranslations('common');
|
|
|
|
|
|
2026-05-07 03:40:29 +03:30
|
|
|
return (
|
|
|
|
|
<div className="surface-card p-4 space-y-3">
|
|
|
|
|
<div>
|
2026-06-20 14:51:43 +03:30
|
|
|
<h3 className="text-sm font-semibold text-text-primary">{t('historyTitle')}</h3>
|
2026-05-19 23:43:43 +03:30
|
|
|
<p className="text-[11px] text-text-muted mt-0.5">
|
2026-06-20 14:51:43 +03:30
|
|
|
{t('historySubtitle')}
|
2026-05-07 03:40:29 +03:30
|
|
|
</p>
|
|
|
|
|
</div>
|
|
|
|
|
|
2026-06-20 14:51:43 +03:30
|
|
|
{loading && <p className="text-sm text-text-muted">{t('loadingHistory')}</p>}
|
2026-05-07 03:40:29 +03:30
|
|
|
|
|
|
|
|
{!loading && items.length === 0 && (
|
2026-06-20 14:51:43 +03:30
|
|
|
<p className="text-sm text-text-muted">{t('historyEmpty')}</p>
|
2026-05-07 03:40:29 +03:30
|
|
|
)}
|
|
|
|
|
|
2026-05-19 23:43:43 +03:30
|
|
|
<div className="space-y-3 max-h-[min(420px,50vh)] overflow-y-auto pr-1">
|
2026-06-20 14:51:43 +03:30
|
|
|
{items.map((treatment) => (
|
2026-05-07 03:40:29 +03:30
|
|
|
<article
|
2026-06-20 14:51:43 +03:30
|
|
|
key={treatment.id}
|
2026-05-19 23:43:43 +03:30
|
|
|
className="border border-border/70 rounded-[var(--radius-md)] p-2.5 bg-background-secondary/40 space-y-2"
|
2026-05-07 03:40:29 +03:30
|
|
|
>
|
|
|
|
|
<div className="flex items-start justify-between gap-2">
|
2026-05-19 23:43:43 +03:30
|
|
|
<div className="min-w-0">
|
2026-06-20 14:51:43 +03:30
|
|
|
<p className="text-sm font-medium text-text-primary truncate">{treatment.title}</p>
|
|
|
|
|
<p className="text-[11px] text-text-secondary capitalize mt-0.5">
|
|
|
|
|
{t('statusLabel')} {treatment.status}
|
|
|
|
|
</p>
|
2026-05-19 23:43:43 +03:30
|
|
|
</div>
|
|
|
|
|
<time
|
|
|
|
|
className="text-[11px] text-text-muted tabular-nums shrink-0"
|
2026-06-20 14:51:43 +03:30
|
|
|
dateTime={treatment.treatmentAt}
|
2026-05-19 23:43:43 +03:30
|
|
|
>
|
2026-06-20 14:51:43 +03:30
|
|
|
{new Date(treatment.treatmentAt).toLocaleDateString()}
|
2026-05-07 03:40:29 +03:30
|
|
|
</time>
|
|
|
|
|
</div>
|
|
|
|
|
|
2026-05-19 23:43:43 +03:30
|
|
|
<div className="space-y-1.5">
|
2026-06-28 15:34:56 +03:30
|
|
|
{treatment.details.map((c, idx) => {
|
2026-05-19 23:43:43 +03:30
|
|
|
const attachments = c.attachmentMetas ?? [];
|
2026-06-20 14:51:43 +03:30
|
|
|
const typeKey = TREATMENT_TYPE_KEYS[c.treatmentType as keyof typeof TREATMENT_TYPE_KEYS];
|
|
|
|
|
const typeLabel = typeKey ? t(typeKey) : c.treatmentType;
|
2026-05-19 23:43:43 +03:30
|
|
|
return (
|
|
|
|
|
<div
|
|
|
|
|
key={c.id}
|
|
|
|
|
className="border border-border/60 rounded-[var(--radius-sm)] px-2.5 py-2 bg-background-secondary/30 space-y-1"
|
|
|
|
|
>
|
|
|
|
|
<div className="flex items-center justify-between gap-2">
|
|
|
|
|
<p className="text-xs font-medium text-text-primary capitalize">
|
2026-06-20 14:51:43 +03:30
|
|
|
{t('historyCaseLabel', { n: idx + 1, type: typeLabel })}
|
2026-05-19 23:43:43 +03:30
|
|
|
</p>
|
|
|
|
|
{c.sentAt && (
|
|
|
|
|
<CaseSentLabel
|
|
|
|
|
treatmentCase={c}
|
|
|
|
|
className="text-[10px] text-text-muted shrink-0 text-right"
|
|
|
|
|
/>
|
|
|
|
|
)}
|
|
|
|
|
</div>
|
|
|
|
|
<p className="text-[11px] text-text-secondary">
|
2026-06-20 14:51:43 +03:30
|
|
|
{t('teethLabel')} {c.teeth.length ? [...c.teeth].sort().join(', ') : t('teethNone')}
|
2026-05-19 23:43:43 +03:30
|
|
|
</p>
|
|
|
|
|
{c.notes?.trim() && (
|
|
|
|
|
<p className="text-[11px] text-text-muted line-clamp-2">{c.notes}</p>
|
|
|
|
|
)}
|
|
|
|
|
<div>
|
|
|
|
|
<p className="text-[10px] uppercase tracking-wide text-text-muted mb-1">
|
2026-06-20 14:51:43 +03:30
|
|
|
{t('attachments')}
|
2026-05-19 23:43:43 +03:30
|
|
|
</p>
|
|
|
|
|
{attachments.length === 0 ? (
|
2026-06-20 14:51:43 +03:30
|
|
|
<p className="text-[11px] text-text-muted">{tCommon('none')}</p>
|
2026-05-19 23:43:43 +03:30
|
|
|
) : (
|
|
|
|
|
<ul className="space-y-0.5">
|
|
|
|
|
{attachments.map((doc) => (
|
|
|
|
|
<li
|
|
|
|
|
key={doc.id}
|
|
|
|
|
className="flex items-center gap-1.5 text-[11px] text-text-secondary"
|
|
|
|
|
>
|
|
|
|
|
<FileText className="w-3 h-3 shrink-0 icon-flat" aria-hidden />
|
|
|
|
|
<span className="truncate">{doc.fileName}</span>
|
|
|
|
|
<span className="text-text-muted tabular-nums shrink-0">
|
|
|
|
|
{(doc.sizeBytes / 1024).toFixed(1)} KB
|
|
|
|
|
</span>
|
|
|
|
|
</li>
|
|
|
|
|
))}
|
|
|
|
|
</ul>
|
|
|
|
|
)}
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
})}
|
|
|
|
|
</div>
|
2026-05-07 03:40:29 +03:30
|
|
|
|
2026-05-19 23:43:43 +03:30
|
|
|
{onReviewTreatment && (
|
|
|
|
|
<div className="pt-1 flex justify-end">
|
2026-05-07 14:20:50 +03:30
|
|
|
<button
|
|
|
|
|
type="button"
|
2026-06-20 14:51:43 +03:30
|
|
|
onClick={() => onReviewTreatment(treatment)}
|
2026-05-07 14:20:50 +03:30
|
|
|
className="text-xs text-primary hover:underline focus:outline-none focus-visible:ring-2 focus-visible:ring-primary/35 rounded-[var(--radius-sm)] px-1"
|
|
|
|
|
>
|
2026-06-20 14:51:43 +03:30
|
|
|
{t('reviewDetails')}
|
2026-05-07 14:20:50 +03:30
|
|
|
</button>
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
2026-05-07 03:40:29 +03:30
|
|
|
</article>
|
|
|
|
|
))}
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|