{{-- resources/views/doctor/archive/index.blade.php --}}
@extends('doctor.layouts.app')
@section('title','الأرشيف الطبي')
@section('page-title','الأرشيف الطبي')

@section('content')
<div class="card mb-3">
    <div class="card-body py-2">
        <form method="GET" class="d-flex gap-2">
            <div class="input-group input-group-sm">
                <span class="input-group-text"><i class="bi bi-search"></i></span>
                <input type="text" name="search" value="{{ request('search') }}"
                       class="form-control" placeholder="بحث بالاسم أو الهاتف...">
            </div>
            <button class="btn btn-sm btn-primary px-3">بحث</button>
        </form>
    </div>
</div>

<div class="row g-3">
    @forelse($patients as $patient)
    <div class="col-md-4 col-lg-3">
        <a href="{{ route('doctor.archive.patient',$patient->id) }}" class="text-decoration-none">
            <div class="card h-100 hover-card" style="transition:box-shadow .2s" onmouseover="this.style.boxShadow='0 4px 16px rgba(0,0,0,.12)'" onmouseout="this.style.boxShadow=''">
                <div class="card-body text-center py-4">
                    <div style="width:52px;height:52px;background:{{ $patient->gender==='female'?'#ec4899':'#1d4ed8' }};border-radius:50%;display:flex;align-items:center;justify-content:center;font-size:1.3rem;color:#fff;margin:0 auto .8rem">
                        <i class="bi bi-person-fill"></i>
                    </div>
                    <div class="fw-semibold">{{ $patient->user->name }}</div>
                    <div class="text-muted small">{{ $patient->user->phone }}</div>
                    @if($patient->blood_type)
                        <span class="badge bg-danger mt-1">{{ $patient->blood_type }}</span>
                    @endif
                    @if($patient->chronic_diseases)
                        <div class="mt-1"><span class="badge bg-warning text-dark small">{{ Str::limit($patient->chronic_diseases,25) }}</span></div>
                    @endif
                    <div class="text-muted small mt-2">
                        @if($patient->medicalRecords->first())
                            آخر زيارة: {{ $patient->medicalRecords->first()->visit_date->format('Y/m/d') }}
                        @endif
                    </div>
                </div>
            </div>
        </a>
    </div>
    @empty
    <div class="col-12">
        <div class="card text-center py-5 text-muted">
            <i class="bi bi-archive fs-2 d-block mb-2"></i>
            لا توجد سجلات طبية بعد
        </div>
    </div>
    @endforelse
</div>

@if($patients->hasPages())
<div class="mt-3 d-flex justify-content-center">
    {{ $patients->withQueryString()->links('pagination::bootstrap-5') }}
</div>
@endif
@endsection
