128 lines
5.3 KiB
TypeScript
128 lines
5.3 KiB
TypeScript
import * as React from "react"
|
||
import { CakeIcon, CopyIcon, IdCardIcon, PhoneIcon, StethoscopeIcon } from "lucide-react"
|
||
|
||
import { cn } from "../lib/utils"
|
||
import { copyToClipboard } from "../lib/clipboard"
|
||
import { pluralYears } from "../lib/format"
|
||
import { ContentTabs, type ContentTabItem } from "./content-tabs"
|
||
import { GenderMark, PatientAvatar, type AvatarPerson } from "./patient-avatar"
|
||
|
||
export interface PatientPanelPerson extends AvatarPerson {
|
||
readonly middleName?: string
|
||
readonly birthDate: string
|
||
readonly age: number
|
||
readonly phone?: string
|
||
readonly cardNumber?: string
|
||
readonly snils?: string
|
||
readonly doctor?: string
|
||
}
|
||
|
||
/**
|
||
* Шапка пациента: аватар, ФИО, пол, дата рождения, контакты, действия справа
|
||
* и (необязательно) вкладки разделов карточки под ней. Лёгкая заливка — в цвет пола.
|
||
* birthIcon заменяет значок-торт перед датой рождения (например, интерактивным).
|
||
*/
|
||
export function PatientPanel<T extends string>({
|
||
person: p,
|
||
actions,
|
||
birthIcon,
|
||
tabs,
|
||
activeTab,
|
||
onTabChange,
|
||
className,
|
||
}: {
|
||
person: PatientPanelPerson
|
||
actions?: React.ReactNode
|
||
birthIcon?: React.ReactNode
|
||
tabs?: readonly ContentTabItem<T>[]
|
||
activeTab?: T
|
||
onTabChange?: (tab: T) => void
|
||
className?: string
|
||
}) {
|
||
const female = p.gender === "female"
|
||
const fullName = [p.lastName, p.firstName, p.middleName].filter(Boolean).join(" ")
|
||
|
||
return (
|
||
<div className={cn("shrink-0", className)}>
|
||
<header className="relative overflow-hidden border-b">
|
||
<div
|
||
className={cn(
|
||
"pointer-events-none absolute inset-0 opacity-[0.09]",
|
||
female
|
||
? "bg-[radial-gradient(ellipse_at_top_left,var(--female)_0%,transparent_55%)]"
|
||
: "bg-[radial-gradient(ellipse_at_top_left,var(--male)_0%,transparent_55%)]",
|
||
)}
|
||
/>
|
||
|
||
<div className="relative flex flex-wrap items-center gap-x-3 gap-y-2 px-5 py-2.5">
|
||
<PatientAvatar patient={p} ring className="size-9" />
|
||
|
||
<div className="min-w-0 flex-1 leading-tight">
|
||
<div className="flex flex-wrap items-baseline gap-x-2">
|
||
<h1 className="text-base font-semibold tracking-tight">
|
||
<button
|
||
type="button"
|
||
title="Скопировать ФИО"
|
||
onClick={() => copyToClipboard(fullName, "ФИО скопировано")}
|
||
className="group inline-flex items-baseline gap-1.5 rounded-sm text-left hover:text-primary focus-visible:ring-[3px] focus-visible:ring-ring/50 focus-visible:outline-none"
|
||
>
|
||
{fullName}
|
||
<CopyIcon className="size-3 self-center text-muted-foreground opacity-0 transition group-hover:opacity-100" />
|
||
</button>
|
||
</h1>
|
||
<GenderMark gender={p.gender} className="text-sm" />
|
||
<span className="inline-flex items-center gap-1 self-center text-sm text-muted-foreground tabular">
|
||
{birthIcon ?? <CakeIcon className="size-3.5" />}
|
||
{p.birthDate} · <span className="text-foreground">{pluralYears(p.age)}</span>
|
||
</span>
|
||
</div>
|
||
|
||
<div className="mt-0.5 flex flex-wrap items-center gap-x-4 text-[13px] text-muted-foreground">
|
||
{p.phone && (
|
||
<a href={`tel:${p.phone}`} className="inline-flex items-center gap-1.5 text-primary hover:underline">
|
||
<PhoneIcon className="size-3.5" />
|
||
{p.phone}
|
||
</a>
|
||
)}
|
||
{p.cardNumber && (
|
||
<button
|
||
type="button"
|
||
onClick={() => copyToClipboard(p.cardNumber!, "Номер карты скопирован")}
|
||
className="group inline-flex items-center gap-1.5 hover:text-foreground"
|
||
>
|
||
<IdCardIcon className="size-3.5" />
|
||
<span className="font-mono text-foreground">{p.cardNumber}</span>
|
||
<CopyIcon className="size-3 opacity-0 transition group-hover:opacity-100" />
|
||
</button>
|
||
)}
|
||
{p.snils && (
|
||
<button
|
||
type="button"
|
||
onClick={() => copyToClipboard(p.snils!, "СНИЛС скопирован")}
|
||
className="group inline-flex items-center gap-1.5 hover:text-foreground"
|
||
>
|
||
СНИЛС
|
||
<span className="font-mono text-foreground">{p.snils}</span>
|
||
<CopyIcon className="size-3 opacity-0 transition group-hover:opacity-100" />
|
||
</button>
|
||
)}
|
||
{p.doctor && (
|
||
<span className="inline-flex items-center gap-1.5">
|
||
<StethoscopeIcon className="size-3.5" />
|
||
<span className="text-foreground">{p.doctor}</span>
|
||
</span>
|
||
)}
|
||
</div>
|
||
</div>
|
||
|
||
{actions && <div className="flex items-center gap-2">{actions}</div>}
|
||
</div>
|
||
</header>
|
||
|
||
{tabs && activeTab !== undefined && onTabChange && (
|
||
<ContentTabs tabs={tabs} value={activeTab} onValueChange={onTabChange} />
|
||
)}
|
||
</div>
|
||
)
|
||
}
|