@extends('layouts.app')

@section('title', __('labCore::lang.lab_core') . ' — ' . $session->sample_no)

@section('content')
<section class="content-header">
    <h1><i class="fas fa-vials"></i> {{ __('labCore::lang.lab_core') }} <small>Session {{ $session->sample_no }}</small></h1>
</section>

<section class="content">
    @include('labCore::partials._nav')

    <div class="row">
        <div class="col-md-4">
            <div class="box box-solid">
                <div class="box-header with-border"><h3 class="box-title">Sample</h3></div>
                <div class="box-body">
                    <table class="table table-condensed">
                        <tr><th>Sample No</th><td>{{ $session->sample_no }}</td></tr>
                        <tr><th>Patient</th><td>{{ $session->patient_name ?: '—' }}</td></tr>
                        <tr><th>Patient ID</th><td>{{ $session->patient_id ?: '—' }}</td></tr>
                        <tr><th>Species</th><td>{{ $session->species ?: '—' }}</td></tr>
                        <tr><th>Sex</th><td>{{ $session->sex ?: '—' }}</td></tr>
                        <tr><th>Age</th><td>{{ $session->age ?? '—' }}</td></tr>
                        <tr><th>Vendor</th><td>{{ ucfirst($session->vendor) }}</td></tr>
                        <tr><th>Device</th><td>{{ $session->device?->name ?? '—' }}</td></tr>
                        <tr><th>Date</th><td>{{ optional($session->test_date)->format('Y-m-d') }} {{ $session->test_time }}</td></tr>
                        <tr><th>Source</th><td>{{ $session->source }}</td></tr>
                        <tr><th>UUID</th><td><small><code>{{ $session->uuid }}</code></small></td></tr>
                    </table>
                </div>
            </div>
        </div>

        <div class="col-md-8">
            <div class="box box-solid">
                <div class="box-header with-border">
                    <h3 class="box-title">Results ({{ $session->results->count() }})</h3>
                </div>
                <div class="box-body no-padding">
                    <table class="table table-striped">
                        <thead>
                            <tr><th>Analyte</th><th>Result</th><th>Unit</th><th>Reference</th><th>Flag</th></tr>
                        </thead>
                        <tbody>
                        @forelse($session->results as $r)
                            <tr class="{{ $r->is_abnormal ? 'danger' : '' }}">
                                <td><strong>{{ $r->analyte_name ?: $r->analyte_code }}</strong>
                                    @if($r->analyte_name)<br><small class="text-muted">{{ $r->analyte_code }}</small>@endif
                                </td>
                                <td>{{ $r->equality !== '=' ? $r->equality : '' }}{{ $r->value }}</td>
                                <td>{{ $r->unit }}</td>
                                <td>{{ $r->ref_lower !== null || $r->ref_upper !== null ? $r->ref_lower . ' – ' . $r->ref_upper : '—' }}</td>
                                <td>
                                    @if($r->is_abnormal)
                                        <span class="label label-danger">{{ $r->raw_flag ?: 'Abnormal' }}</span>
                                    @else
                                        <span class="label label-success">Normal</span>
                                    @endif
                                </td>
                            </tr>
                        @empty
                            <tr><td colspan="5" class="text-muted">No results.</td></tr>
                        @endforelse
                        </tbody>
                    </table>
                </div>
                <div class="box-footer">
                    <a href="{{ route('lab.results.index') }}" class="btn btn-default">Back</a>
                    @can('lab.manage_results')
                        <form method="POST" action="{{ route('lab.results.destroy', $session->id) }}" style="display:inline;float:right;" onsubmit="return confirm('Delete this session and its results?');">
                            @csrf @method('DELETE')
                            <button class="btn btn-danger"><i class="fa fa-trash"></i> Delete Session</button>
                        </form>
                    @endcan
                </div>
            </div>
        </div>
    </div>
</section>
@endsection
