@extends('vetPortal::layouts.portal')
@section('title', $pet->petname)

@section('content')
@php
    $stClass = [
        'pending' => 'vp-b-blue', 'confirmed' => 'vp-b-blue', 'waiting' => 'vp-b-amber',
        'in_progress' => 'vp-b-amber', 'completed' => 'vp-b-green',
        'cancelled' => 'vp-b-red', 'no_show' => 'vp-b-red',
    ];
@endphp

<a href="{{ route('vp.portal.pets') }}" style="font-size:12px;">&larr; {{ __('vetPortal::lang.my_pets') }}</a>
<div class="vp-page-title" style="margin-top:6px;"><i class="fas fa-paw"></i> {{ $pet->petname }}</div>

{{-- Profile --}}
<div class="vp-card">
    <div class="vp-card-h"><i class="fas fa-id-card"></i> Profile</div>
    <div class="vp-card-b">
        <div class="vp-grid" style="grid-template-columns:repeat(auto-fill,minmax(140px,1fr));">
            <div><div class="l" style="font-size:11px;color:#94a3b8;">Species</div><div>{{ ucfirst($pet->species ?? '—') }}</div></div>
            <div><div class="l" style="font-size:11px;color:#94a3b8;">Breed</div><div>{{ $pet->breed ?: '—' }}</div></div>
            <div><div class="l" style="font-size:11px;color:#94a3b8;">Gender</div><div>{{ ucfirst($pet->gender ?? '—') }}</div></div>
            <div><div class="l" style="font-size:11px;color:#94a3b8;">Age</div><div>{{ $pet->dob ? \Carbon\Carbon::parse($pet->dob)->age . ' yr' : '—' }}</div></div>
            <div><div class="l" style="font-size:11px;color:#94a3b8;">Colour</div><div>{{ $pet->color ?: '—' }}</div></div>
            <div><div class="l" style="font-size:11px;color:#94a3b8;">Microchip</div><div>{{ $pet->microchip_no ?: '—' }}</div></div>
        </div>
    </div>
</div>

{{-- Vaccinations --}}
<div class="vp-card">
    <div class="vp-card-h"><i class="fas fa-syringe"></i> {{ __('vetPortal::lang.vaccinations') }}</div>
    <div class="vp-card-b" style="padding:0;">
        @if($pet->vaccinations->isEmpty())
            <div class="vp-empty">No vaccinations recorded.</div>
        @else
            <table class="vp-table">
                <thead><tr><th>Vaccine</th><th>Given</th><th>Next Due</th></tr></thead>
                <tbody>
                @foreach($pet->vaccinations as $v)
                    @php
                        $due = $v->next_due_date ? \Carbon\Carbon::parse($v->next_due_date) : null;
                        $overdue = $due && $due->isPast();
                    @endphp
                    <tr>
                        <td>{{ optional($v->vaccineType)->name ?? 'Vaccine' }}</td>
                        <td>{{ $v->administered_date ? \Carbon\Carbon::parse($v->administered_date)->format('d M Y') : '—' }}</td>
                        <td>
                            @if($due)
                                <span class="vp-badge {{ $overdue ? 'vp-b-red' : 'vp-b-green' }}">
                                    {{ $due->format('d M Y') }}
                                </span>
                            @else — @endif
                        </td>
                    </tr>
                @endforeach
                </tbody>
            </table>
        @endif
    </div>
</div>

{{-- Prescriptions --}}
<div class="vp-card">
    <div class="vp-card-h"><i class="fas fa-prescription-bottle-alt"></i> {{ __('vetPortal::lang.prescriptions') }}</div>
    <div class="vp-card-b" style="padding:0;">
        @if($pet->prescriptions->isEmpty())
            <div class="vp-empty">No prescriptions recorded.</div>
        @else
            <table class="vp-table">
                <thead><tr><th>Ref</th><th>Date</th><th>Doctor</th><th>Diagnosis</th></tr></thead>
                <tbody>
                @foreach($pet->prescriptions as $p)
                    <tr>
                        <td>{{ $p->ref_no ?? ('#' . $p->id) }}</td>
                        <td>{{ $p->prescribed_date ? \Carbon\Carbon::parse($p->prescribed_date)->format('d M Y') : '—' }}</td>
                        <td>{{ optional($p->doctor)->name ?? '—' }}</td>
                        <td>{{ \Illuminate\Support\Str::limit($p->diagnosis, 50) ?: '—' }}</td>
                    </tr>
                @endforeach
                </tbody>
            </table>
        @endif
    </div>
</div>

{{-- Conditions --}}
<div class="vp-card">
    <div class="vp-card-h"><i class="fas fa-heartbeat"></i> {{ __('vetPortal::lang.conditions') }}</div>
    <div class="vp-card-b">
        @if($pet->conditions->isEmpty())
            <div class="vp-empty">No medical conditions on file.</div>
        @else
            @foreach($pet->conditions as $c)
                <span class="vp-badge vp-b-gray" style="margin:2px;">
                    {{ optional($c->condition)->name ?? 'Condition' }}
                    @if($c->status) · {{ ucfirst($c->status) }} @endif
                </span>
            @endforeach
        @endif
    </div>
</div>

{{-- Appointments --}}
<div class="vp-card">
    <div class="vp-card-h"><i class="fas fa-calendar"></i> {{ __('vetPortal::lang.appointments') }}</div>
    <div class="vp-card-b" style="padding:0;">
        @if($pet->appointments->isEmpty())
            <div class="vp-empty">No appointments recorded.</div>
        @else
            <table class="vp-table">
                <thead><tr><th>Date</th><th>Doctor</th><th>Type</th><th>Status</th></tr></thead>
                <tbody>
                @foreach($pet->appointments->take(20) as $a)
                    <tr>
                        <td>{{ \Carbon\Carbon::parse($a->appointment_date)->format('d M Y') }}</td>
                        <td>{{ optional($a->doctor)->name ?? '—' }}</td>
                        <td>{{ ucfirst(str_replace('_', ' ', $a->type ?? '—')) }}</td>
                        <td><span class="vp-badge {{ $stClass[$a->status] ?? 'vp-b-gray' }}">{{ ucfirst(str_replace('_', ' ', $a->status)) }}</span></td>
                    </tr>
                @endforeach
                </tbody>
            </table>
        @endif
    </div>
</div>
@endsection
