<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>Blood Bank summary · {{ $patient->fullName() }}</title>
    <style>
        body { font-family: system-ui, sans-serif; color: #0f172a; margin: 2rem; }
        h1 { font-size: 1.25rem; margin: 0 0 .25rem; }
        h2 { font-size: .95rem; margin: 1.25rem 0 .5rem; border-bottom: 1px solid #e2e8f0; padding-bottom: .25rem; }
        .meta { color: #64748b; font-size: .875rem; }
        dl { display: grid; grid-template-columns: 10rem 1fr; gap: .35rem .75rem; font-size: .875rem; }
        dt { color: #64748b; }
        dd { margin: 0; font-weight: 500; }
        @media print { .no-print { display: none; } }
    </style>
</head>
<body>
    <p class="no-print"><a href="{{ route('care.specialty.workspace', ['module' => 'blood_bank', 'visit' => $visit]) }}">Back</a></p>

    <h1>{{ $patient->fullName() }}</h1>
    <p class="meta">
        {{ $patient->patient_number }}
        · Visit #{{ $visit->id }}
        · Stage {{ $visit->specialty_stage ?? '—' }}
        · {{ $visit->checked_in_at?->format('d M Y H:i') ?? '—' }}
    </p>

    <h2>Blood request</h2>
    @if ($bloodRequest)
        <dl>
            <dt>Product</dt><dd>{{ $bloodRequest->payload['product'] ?? '—' }}</dd>
            <dt>Units requested</dt><dd>{{ $bloodRequest->payload['units'] ?? '—' }}</dd>
            <dt>Urgency</dt><dd>{{ $bloodRequest->payload['urgency'] ?? '—' }}</dd>
            <dt>Blood group</dt><dd>{{ $bloodRequest->payload['patient_blood_group'] ?? '—' }}</dd>
            <dt>Indication</dt><dd>{{ $bloodRequest->payload['indication'] ?? '—' }}</dd>
            <dt>Cross-match</dt><dd>{{ $bloodRequest->payload['crossmatch_status'] ?? '—' }}</dd>
            <dt>Issued units</dt><dd>{{ $bloodRequest->payload['issued_units'] ?? '—' }}</dd>
            <dt>Notes</dt><dd>{{ $bloodRequest->payload['notes'] ?? '—' }}</dd>
        </dl>
    @else
        <p class="meta">No blood request recorded.</p>
    @endif

    <h2>Issue</h2>
    @if ($issueNote)
        <dl>
            <dt>Product</dt><dd>{{ $issueNote->payload['product'] ?? '—' }}</dd>
            <dt>Units issued</dt><dd>{{ $issueNote->payload['units_issued'] ?? '—' }}</dd>
            <dt>Bag numbers</dt><dd>{{ $issueNote->payload['bag_numbers'] ?? '—' }}</dd>
            <dt>Issued to</dt><dd>{{ $issueNote->payload['issued_to'] ?? '—' }}</dd>
            <dt>Issued at</dt><dd>{{ $issueNote->payload['issued_at'] ?? '—' }}</dd>
            <dt>Notes</dt><dd>{{ $issueNote->payload['notes'] ?? '—' }}</dd>
        </dl>
    @else
        <p class="meta">No issue recorded.</p>
    @endif

    <h2>Transfusion</h2>
    @if ($transfusionNote)
        <dl>
            <dt>Started</dt><dd>{{ $transfusionNote->payload['started_at'] ?? '—' }}</dd>
            <dt>Units transfused</dt><dd>{{ $transfusionNote->payload['units_transfused'] ?? '—' }}</dd>
            <dt>Reaction</dt><dd>{{ $transfusionNote->payload['reaction'] ?? '—' }}</dd>
            <dt>Outcome</dt><dd>{{ $transfusionNote->payload['outcome'] ?? '—' }}</dd>
            <dt>Notes</dt><dd>{{ $transfusionNote->payload['notes'] ?? '—' }}</dd>
        </dl>
    @else
        <p class="meta">No transfusion record.</p>
    @endif

    @if ($visit->bill)
        <h2>Billing ({{ $visit->bill->invoice_number }})</h2>
        <dl>
            @foreach ($visit->bill->lineItems as $line)
                <dt>{{ $line->description }}</dt>
                <dd>{{ number_format($line->total_minor / 100, 2) }}</dd>
            @endforeach
        </dl>
    @endif

    <script>window.print();</script>
</body>
</html>
