<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>ED 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' => 'emergency', '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>Triage</h2>
    @if ($triage)
        <dl>
            <dt>Acuity</dt><dd>{{ $triage->payload['acuity'] ?? '—' }}</dd>
            <dt>Chief complaint</dt><dd>{{ $triage->payload['chief_complaint'] ?? '—' }}</dd>
            <dt>Mode of arrival</dt><dd>{{ $triage->payload['mode_of_arrival'] ?? '—' }}</dd>
            <dt>ABC</dt>
            <dd>
                A {{ ($triage->payload['airway_ok'] ?? true) ? 'OK' : 'Compromised' }}
                · B {{ ($triage->payload['breathing_ok'] ?? true) ? 'OK' : 'Compromised' }}
                · C {{ ($triage->payload['circulation_ok'] ?? true) ? 'OK' : 'Compromised' }}
            </dd>
            <dt>GCS / Pain</dt><dd>{{ $triage->payload['gcs'] ?? '—' }} / {{ $triage->payload['pain_score'] ?? '—' }}</dd>
            <dt>Notes</dt><dd>{{ $triage->payload['notes'] ?? '—' }}</dd>
        </dl>
    @else
        <p class="meta">No triage recorded.</p>
    @endif

    <h2>Latest vitals</h2>
    @if ($latestVitals)
        <dl>
            <dt>BP</dt><dd>{{ $latestVitals->bp_systolic ?? '—' }}/{{ $latestVitals->bp_diastolic ?? '—' }}</dd>
            <dt>Pulse</dt><dd>{{ $latestVitals->pulse ?? '—' }}</dd>
            <dt>SpO₂</dt><dd>{{ $latestVitals->spo2 ?? '—' }}%</dd>
            <dt>Temp</dt><dd>{{ $latestVitals->temperature ?? '—' }}</dd>
            <dt>RR</dt><dd>{{ $latestVitals->respiratory_rate ?? '—' }}</dd>
            <dt>Recorded</dt><dd>{{ $latestVitals->recorded_at?->format('d M Y H:i') }}</dd>
        </dl>
    @else
        <p class="meta">No vitals recorded.</p>
    @endif

    <h2>Clinical note</h2>
    @if ($clinicalNote)
        <dl>
            <dt>History</dt><dd>{{ $clinicalNote->payload['history'] ?? '—' }}</dd>
            <dt>Examination</dt><dd>{{ $clinicalNote->payload['examination'] ?? '—' }}</dd>
            <dt>Diagnosis</dt><dd>{{ $clinicalNote->payload['working_diagnosis'] ?? '—' }}</dd>
            <dt>Plan</dt><dd>{{ $clinicalNote->payload['plan'] ?? '—' }}</dd>
        </dl>
    @else
        <p class="meta">No clinical note.</p>
    @endif

    <h2>Disposition</h2>
    @if ($disposition)
        <dl>
            <dt>Disposition</dt><dd>{{ $disposition->payload['disposition'] ?? '—' }}</dd>
            <dt>Condition</dt><dd>{{ $disposition->payload['condition'] ?? '—' }}</dd>
            <dt>Destination</dt><dd>{{ $disposition->payload['destination'] ?? '—' }}</dd>
            <dt>Diagnosis</dt><dd>{{ $disposition->payload['diagnosis'] ?? '—' }}</dd>
            <dt>Advice</dt><dd>{{ $disposition->payload['advice'] ?? '—' }}</dd>
        </dl>
    @else
        <p class="meta">No disposition recorded.</p>
    @endif

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