@extends('doctor.layouts.app')
@section('title','السجل الطبي')
@section('page-title','تفاصيل الزيارة')

@section('content')
<div class="row justify-content-center">
<div class="col-lg-9">

<div class="d-flex align-items-center justify-content-between mb-3">
    <a href="{{ route('doctor.archive.patient',$record->patient_id) }}" class="btn btn-outline-secondary btn-sm">
        <i class="bi bi-arrow-right me-1"></i>ملف {{ $record->patient->user->name }}
    </a>
    <span class="text-muted small">{{ $record->visit_date->format('Y/m/d') }}</span>
</div>

{{-- المؤشرات الحيوية --}}
@if($record->blood_pressure || $record->temperature || $record->pulse || $record->oxygen_saturation)
<div class="card mb-3">
    <div class="card-header"><i class="bi bi-activity me-2 text-danger"></i>المؤشرات الحيوية</div>
    <div class="card-body">
        <div class="row g-3 text-center">
            @if($record->blood_pressure)
            <div class="col-6 col-md-3">
                <div class="stat-icon mx-auto mb-1" style="background:#fee2e2;color:#dc2626;width:44px;height:44px;border-radius:10px;display:flex;align-items:center;justify-content:center"><i class="bi bi-heart-pulse"></i></div>
                <div class="fw-bold">{{ $record->blood_pressure }}</div><div class="text-muted small">الضغط</div>
            </div>
            @endif
            @if($record->temperature)
            <div class="col-6 col-md-3">
                <div class="stat-icon mx-auto mb-1" style="background:#fef3c7;color:#d97706;width:44px;height:44px;border-radius:10px;display:flex;align-items:center;justify-content:center"><i class="bi bi-thermometer-half"></i></div>
                <div class="fw-bold">{{ $record->temperature }}°</div><div class="text-muted small">الحرارة</div>
            </div>
            @endif
            @if($record->pulse)
            <div class="col-6 col-md-3">
                <div class="stat-icon mx-auto mb-1" style="background:#ede9fe;color:#7c3aed;width:44px;height:44px;border-radius:10px;display:flex;align-items:center;justify-content:center"><i class="bi bi-activity"></i></div>
                <div class="fw-bold">{{ $record->pulse }}</div><div class="text-muted small">النبض</div>
            </div>
            @endif
            @if($record->oxygen_saturation)
            <div class="col-6 col-md-3">
                <div class="stat-icon mx-auto mb-1" style="background:#dbeafe;color:#1d4ed8;width:44px;height:44px;border-radius:10px;display:flex;align-items:center;justify-content:center"><i class="bi bi-lungs"></i></div>
                <div class="fw-bold">{{ $record->oxygen_saturation }}%</div><div class="text-muted small">O₂</div>
            </div>
            @endif
        </div>
    </div>
</div>
@endif

{{-- التشخيص --}}
<div class="card mb-3">
    <div class="card-header"><i class="bi bi-clipboard2-pulse me-2 text-primary"></i>التشخيص والفحص</div>
    <div class="card-body">
        @if($record->chief_complaint)
        <div class="mb-3">
            <div class="text-muted small mb-1">الشكوى الرئيسية</div>
            <div>{{ $record->chief_complaint }}</div>
        </div>
        @endif
        @if($record->symptoms)
        <div class="mb-3">
            <div class="text-muted small mb-1">الأعراض</div>
            <div>{{ $record->symptoms }}</div>
        </div>
        @endif
        <div class="mb-3">
            <div class="text-muted small mb-1">التشخيص</div>
            <div class="fw-semibold fs-6">{{ $record->diagnosis }}</div>
        </div>
        @if($record->examination_notes)
        <div>
            <div class="text-muted small mb-1">ملاحظات الفحص</div>
            <div>{{ $record->examination_notes }}</div>
        </div>
        @endif
    </div>
</div>

{{-- الوصفة الطبية --}}
@if($record->prescriptions && count($record->prescriptions))
<div class="card mb-3">
    <div class="card-header"><i class="bi bi-capsule me-2 text-success"></i>الوصفة الطبية</div>
    <div class="table-responsive">
        <table class="table tbl mb-0">
            <thead><tr><th>الدواء</th><th>الجرعة</th><th>عدد المرات</th><th>المدة</th></tr></thead>
            <tbody>
                @foreach($record->prescriptions as $med)
                @if(!empty($med['medicine']))
                <tr>
                    <td class="fw-semibold">{{ $med['medicine'] }}</td>
                    <td>{{ $med['dose'] ?? '—' }}</td>
                    <td>{{ $med['times'] ?? '—' }}</td>
                    <td>{{ $med['duration'] ?? '—' }}</td>
                </tr>
                @endif
                @endforeach
            </tbody>
        </table>
    </div>
</div>
@endif

{{-- التعليمات والمتابعة --}}
@if($record->instructions || $record->next_visit_date)
<div class="card">
    <div class="card-body">
        @if($record->instructions)
        <div class="mb-3">
            <div class="text-muted small mb-1"><i class="bi bi-info-circle me-1"></i>تعليمات للمريض</div>
            <div>{{ $record->instructions }}</div>
        </div>
        @endif
        @if($record->next_visit_date)
        <div class="{{ $record->next_visit_date->isPast() ? 'text-danger' : 'text-success' }}">
            <i class="bi bi-calendar-check me-1"></i>
            موعد المتابعة: <strong>{{ $record->next_visit_date->format('Y/m/d') }}</strong>
        </div>
        @endif
    </div>
</div>
@endif

</div>
</div>
@endsection
