"use client"; import { useState } from "react"; import { FileText, Plus, X, Trash2, ChevronDown, Search, Shield, Download, } from "lucide-react"; import { todayISO, type HealthRecord, type RecordType } from "@/lib/health-store"; import { t, type SupportedLanguage } from "@/lib/i18n"; const RECORD_TYPES: Record = { "lab-report": { label: "Lab Report", emoji: "๐Ÿงช" }, "clinical-note": { label: "Clinical Note", emoji: "๐Ÿ“‹" }, prescription: { label: "Prescription", emoji: "๐Ÿ’Š" }, certificate: { label: "Certificate", emoji: "๐Ÿ“„" }, imaging: { label: "Imaging / X-Ray", emoji: "๐Ÿ”ฌ" }, other: { label: "Other", emoji: "๐Ÿ“Œ" }, }; interface RecordsViewProps { records: HealthRecord[]; onAdd: (rec: Omit) => void; onEdit: (id: string, patch: Partial) => void; onDelete: (id: string) => void; onExport: () => void; language: SupportedLanguage; } export function RecordsView({ records, onAdd, onDelete, onExport, language, }: RecordsViewProps) { const [showForm, setShowForm] = useState(false); const [title, setTitle] = useState(""); const [type, setType] = useState("lab-report"); const [date, setDate] = useState(todayISO()); const [notes, setNotes] = useState(""); const [tags, setTags] = useState(""); const [search, setSearch] = useState(""); const handleSubmit = () => { if (!title.trim()) return; onAdd({ title: title.trim(), type, date, notes: notes.trim() || undefined, tags: tags .split(",") .map((t) => t.trim()) .filter(Boolean), }); setTitle(""); setNotes(""); setTags(""); setShowForm(false); }; const filtered = search ? records.filter( (r) => r.title.toLowerCase().includes(search.toLowerCase()) || r.notes?.toLowerCase().includes(search.toLowerCase()) || r.tags?.some((tag) => tag.toLowerCase().includes(search.toLowerCase())), ) : records; const sorted = [...filtered].sort((a, b) => b.date.localeCompare(a.date)); return (

{t("rec_title", language)}

{t("rec_subtitle", language)}

{/* Search */}
setSearch(e.target.value)} placeholder={t("rec_search", language)} className="w-full bg-surface-1 border border-line/60 text-ink-base rounded-xl pl-10 pr-4 py-2.5 text-sm focus:outline-none focus:ring-2 focus:ring-brand-500/30" />
{/* Add form */} {showForm && (

{t("rec_new", language)}

setTitle(e.target.value)} placeholder="e.g. Blood work results โ€” March 2026" className="w-full bg-surface-2 border border-line/60 text-ink-base rounded-xl px-3 py-2.5 text-sm focus:outline-none focus:ring-2 focus:ring-brand-500/30" />
setDate(e.target.value)} className="w-full bg-surface-2 border border-line/60 text-ink-base rounded-xl px-3 py-2.5 text-sm focus:outline-none focus:ring-2 focus:ring-brand-500/30" />