@extends('layouts.app')
@section('title', __('medportal::lang.patient_portal'))
@section('content')
<section class="content-header">
    <h1>@lang('medportal::lang.patient_portal')</h1>
    <p>@lang('medportal::lang.dashboard_help')</p>
</section>
<section class="content">
    @if(! $hasClinic)
        @component('components.widget', ['class' => 'box-warning'])
            <p class="text-muted">@lang('medportal::lang.clinic_missing')</p>
        @endcomponent
    @endif

    <div class="row">
        <div class="col-md-3 col-sm-6">
            <div class="info-box bg-aqua">
                <span class="info-box-icon"><i class="fa fas fa-user-injured"></i></span>
                <div class="info-box-content">
                    <span class="info-box-text">@lang('medportal::lang.portal_patients')</span>
                    <span class="info-box-number">{{ $portalPatients }}</span>
                </div>
            </div>
        </div>
        <div class="col-md-3 col-sm-6">
            <div class="info-box bg-green">
                <span class="info-box-icon"><i class="fa fas fa-users"></i></span>
                <div class="info-box-content">
                    <span class="info-box-text">@lang('medportal::lang.linked_dependents')</span>
                    <span class="info-box-number">{{ $dependents }}</span>
                </div>
            </div>
        </div>
        <div class="col-md-3 col-sm-6">
            <div class="info-box bg-yellow">
                <span class="info-box-icon"><i class="fa fas fa-lock"></i></span>
                <div class="info-box-content">
                    <span class="info-box-text">@lang('medportal::lang.pending_releases')</span>
                    <span class="info-box-number">{{ $pendingReleases }}</span>
                </div>
            </div>
        </div>
        <div class="col-md-3 col-sm-6">
            <div class="info-box bg-red">
                <span class="info-box-icon"><i class="fa fas fa-envelope"></i></span>
                <div class="info-box-content">
                    <span class="info-box-text">@lang('medportal::lang.unread_messages')</span>
                    <span class="info-box-number">{{ $unreadThreads }}</span>
                </div>
            </div>
        </div>
    </div>

    @component('components.widget', ['class' => 'box-primary', 'title' => __('medportal::lang.recent_questionnaires')])
        <p class="text-muted">{{ __('medportal::lang.flag_hint', ['threshold' => $flagThreshold]) }}</p>
        <div class="table-responsive">
            <table class="table table-bordered table-striped">
                <thead><tr>
                    <th>@lang('medportal::lang.patient')</th>
                    <th>@lang('medportal::lang.questionnaire')</th>
                    <th>@lang('medportal::lang.score')</th>
                    <th>@lang('medportal::lang.severity')</th>
                    <th>@lang('medportal::lang.completed_at')</th>
                </tr></thead>
                <tbody>
                @forelse($recentResponses as $r)
                    @php $flagged = $questionnaireSvc->isFlagged($r); @endphp
                    <tr @if($flagged) class="danger" @endif>
                        <td>{{ $patientNames[$r->patient_id] ?? ('Patient #' . $r->patient_id) }}</td>
                        <td>{{ optional($r->questionnaire)->title ?? '—' }}</td>
                        <td>
                            {{ $r->score ?? '—' }}
                            @if($flagged)<span class="label label-danger">@lang('medportal::lang.flagged')</span>@endif
                        </td>
                        <td>{{ $r->severity ? __('medportal::lang.sev_' . $r->severity) : '—' }}</td>
                        <td>{{ optional($r->completed_at)->format('Y-m-d H:i') ?? '—' }}</td>
                    </tr>
                @empty
                    <tr><td colspan="5" class="text-center text-muted">@lang('medportal::lang.no_responses')</td></tr>
                @endforelse
                </tbody>
            </table>
        </div>
    @endcomponent
</section>
@endsection
