"use client"; import { useRef } from "react"; import Image from "next/image"; import { Printer, Plus } from "lucide-react"; import { Button } from "@/components/ui/button"; import { useT } from "@/i18n/context"; import type { PredictResponse } from "@/lib/api"; export type FormSnapshot = { patient_id?: string; age: number; sex: "M" | "F"; max_hr: number; fasting_bs: "0" | "1"; exercise_angina: "Y" | "N"; chest_pain_type: "ASY" | "ATA" | "NAP" | "TA"; st_slope: "Up" | "Flat" | "Down"; resting_bp?: number; cholesterol?: number; resting_ecg?: "Normal" | "ST" | "LVH"; oldpeak?: number; }; export function Ticket({ response, snapshot, onNew, }: { response: PredictResponse; snapshot: FormSnapshot; onNew: () => void; }) { const { dict } = useT(); const ticketRef = useRef(null); const ts = new Date(response.timestamp); const date = ts.toLocaleDateString(); const time = ts.toLocaleTimeString(); const isHigh = response.classification === "HIGH"; return (
BeatSense
{dict.app.name}
{dict.ticket.facility}
{dict.ticket.code} {response.patient_id} {dict.ticket.date} {date} {dict.ticket.time} {time} {dict.ticket.clinician} {dict.header.user}
{dict.ticket.vitals}
{snapshot.resting_bp ? ( ) : null} {snapshot.cholesterol ? ( ) : null}
{dict.ticket.result}
{response.probability.toFixed(1)}%
{dict.ticket.riskScore} ยท {dict.ticket.threshold}: {response.threshold}%
{isHigh ? dict.ticket.highRisk : dict.ticket.lowRisk}
{dict.ticket.recommendation}

{isHigh ? dict.ticket.recHigh : dict.ticket.recLow}

{dict.ticket.footer}
); } function Row({ label, value }: { label: string; value: string }) { return (
{label} {value}
); } function Divider() { return (
); } function ProbabilityBar({ value, threshold, }: { value: number; threshold: number; }) { return (
= threshold ? "var(--destructive)" : "var(--success)", }} />
0% {threshold}% 100%
); } function Barcode({ value }: { value: string }) { const bars = Array.from(value).flatMap((c, i) => { const code = c.charCodeAt(0) + i; return [ { w: (code % 4) + 1, gap: 1 }, { w: ((code >> 2) % 3) + 1, gap: 2 }, ]; }); return (
{bars.map((b, i) => (
))}
{value}
); }