@extends('medportal::me.layout')
@section('body')
<div class="mp-card">
    <h3>{{ $patient->patient_name ?: __('medportal::lang.me_title') }}</h3>
    <div class="mp-body">
        <p>
            <a class="mp-btn" href="{{ route('mportal.me.records') }}">@lang('medportal::lang.my_records')</a>
        </p>
    </div>
</div>

<div class="mp-card">
    <h3>@lang('medportal::lang.released_records')</h3>
    <div class="mp-body">
        <table>
            @foreach($visibility as $type => $vis)
                <tr>
                    <td>@lang('medportal::lang.type_' . $type)</td>
                    <td>
                        @if($vis)
                            <span class="mp-badge">@lang('medportal::lang.released')</span>
                        @else
                            <span class="mp-badge off">@lang('medportal::lang.not_released_yet')</span>
                        @endif
                    </td>
                </tr>
            @endforeach
        </table>
    </div>
</div>

<div class="mp-card">
    <h3>@lang('medportal::lang.my_appointments')</h3>
    <div class="mp-body">
        @if($appointments->isEmpty())
            <p class="mp-muted">—</p>
        @else
        <table>
            <tr><th>@lang('medportal::lang.date')</th><th>@lang('medportal::lang.status')</th></tr>
            @foreach($appointments as $a)
                <tr>
                    <td>{{ $a->appointment_date }} {{ $a->appointment_time ?? '' }}</td>
                    <td>{{ $a->status ?? '' }}</td>
                </tr>
            @endforeach
        </table>
        @endif
    </div>
</div>

<div class="mp-card">
    <h3>@lang('medportal::lang.my_messages') ({{ $unread }} @lang('medportal::lang.unread'))</h3>
    <div class="mp-body">
        @if($threads->isEmpty())
            <p class="mp-muted">—</p>
        @else
        <table>
            @foreach($threads as $t)
                <tr>
                    <td>{{ \Illuminate\Support\Str::limit($t->body, 70) }}</td>
                    <td class="mp-muted">{{ optional($t->created_at)->format('Y-m-d') }}</td>
                </tr>
            @endforeach
        </table>
        @endif
    </div>
</div>

<div class="mp-card">
    <h3>@lang('medportal::lang.my_health')</h3>
    <div class="mp-body">
        <form method="POST" action="{{ route('mportal.me.health') }}" style="margin-bottom:12px;">
            {{ csrf_field() }}
            <select name="metric" required>
                <option value="weight">@lang('medportal::lang.metric_weight')</option>
                <option value="blood_pressure">@lang('medportal::lang.metric_blood_pressure')</option>
                <option value="blood_glucose">@lang('medportal::lang.metric_blood_glucose')</option>
                <option value="temperature">@lang('medportal::lang.metric_temperature')</option>
                <option value="mood">@lang('medportal::lang.metric_mood')</option>
                <option value="steps">@lang('medportal::lang.metric_steps')</option>
            </select>
            <input type="number" step="any" name="value_num" placeholder="value">
            <input type="text" name="value_text" placeholder="e.g. 120/80">
            <button class="mp-btn" type="submit">@lang('medportal::lang.log_a_reading')</button>
        </form>
        @if($healthLogs->isEmpty())
            <p class="mp-muted">@lang('medportal::lang.no_readings')</p>
        @else
        <table>
            <tr><th>@lang('medportal::lang.metric')</th><th>@lang('medportal::lang.value')</th><th>@lang('medportal::lang.logged_at')</th></tr>
            @foreach($healthLogs as $l)
                <tr>
                    <td>@lang('medportal::lang.metric_' . $l->metric)</td>
                    <td>{{ $l->value_text ?? $l->value_num }}</td>
                    <td class="mp-muted">{{ optional($l->logged_at)->format('Y-m-d H:i') }}</td>
                </tr>
            @endforeach
        </table>
        @endif
    </div>
</div>
@endsection
