"use client"; import React from "react"; import type { Citation } from "@duoc-thu/shared-types"; import { BookOpen, FileText, ChevronRight, AlertTriangle, ExternalLink } from "lucide-react"; import { cn } from "./lib/utils"; interface CitationCardProps { citation: Citation; index: number; isActive?: boolean; onSelect?: () => void; className?: string; } // Matches the real 19-field section_key enum the corpus is chunked on // (apps/ai-service/rag/understanding.py SECTION_KEY_HINTS) — the previous // map here used guessed keys (lieu_dung, tac_dung_phu, duoc_ly, qua_lieu, // bao_quan) that never matched a real chunk, so every citation silently // fell back to the raw slug instead of a readable label. const SECTION_LABELS: Record = { ten_chung_quoc_te: "Tên chung quốc tế", ten_thuong_mai: "Tên thương mại", ma_atc: "Mã ATC", loai_thuoc: "Phân loại thuốc", dang_thuoc_va_ham_luong: "Dạng thuốc & Hàm lượng", duoc_ly_va_co_che_tac_dung: "Dược lý & Cơ chế tác dụng", chi_dinh: "Chỉ định", chong_chi_dinh: "Chống chỉ định", than_trong: "Thận trọng", thoi_ky_mang_thai: "Thời kỳ mang thai", thoi_ky_cho_con_bu: "Thời kỳ cho con bú", tac_dung_khong_mong_muon: "Tác dụng không mong muốn (ADR)", huong_dan_xu_tri_adr: "Hướng dẫn xử trí ADR", lieu_luong_va_cach_dung: "Liều lượng & Cách dùng", tuong_tac_thuoc: "Tương tác thuốc", qua_lieu_va_xu_tri: "Quá liều & Xử trí", do_on_dinh_va_bao_quan: "Độ ổn định & Bảo quản", tuong_ky: "Tương kỵ", thong_tin_quy_che: "Thông tin quy chế", }; export function citationSectionLabel(sectionType: string): string { return SECTION_LABELS[sectionType] ?? (sectionType.replace(/_/g, " ") || "Chuyên luận"); } export function CitationCard({ citation, index, isActive = false, onSelect, className, }: CitationCardProps) { const sectionLabel = citationSectionLabel(citation.sectionType); const pageRangeText = citation.sourcePageRange ? `Trang ${citation.sourcePageRange[0]}${ citation.sourcePageRange[1] && citation.sourcePageRange[1] !== citation.sourcePageRange[0] ? `–${citation.sourcePageRange[1]}` : "" }` : "Dược thư 2018"; return (
{ if (e.key === "Enter" || e.key === " ") { e.preventDefault(); onSelect?.(); } }} className={cn( "group relative flex flex-col gap-2 rounded-2xl border p-3.5 transition-all cursor-pointer select-none", isActive ? "bg-accent-soft/30 border-border-accent shadow-elevated glass-beam-glow ring-2 ring-accent-primary/20" : "bg-surface border-border-subtle hover:border-border-active hover:bg-surface-elevated shadow-sm", className )} > {/* Header */}
{index}

{citation.drugName || "Chuyên luận Dược thư"}

{pageRangeText}
{/* Section Badge */}
{sectionLabel}
{/* Snippet / Source Excerpt - the exact retrieved chunk text, verbatim */} {citation.snippet && (
{citation.snippet}
)} {/* Quarantine notice - only rendered when the source pipeline actually flagged this chunk (table/formula lifted out of prose), never a generic boilerplate line for an ordinary citation. */} {citation.isQuarantined && (

{citation.quarantineNotice}

{citation.sourceCropUrl ? ( {`Ảnh ) : ( e.stopPropagation()} className="inline-flex items-center gap-1 rounded-lg bg-surface px-2 py-1 font-semibold text-accent-primary hover:underline" > Mở trang PDF gốc để đối chiếu )}
)}
Xem trích dẫn đầy đủ
); }