@extends('vetPortal::layouts.portal')
@section('title', __('vetPortal::lang.appointments'))

@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',
    ];
    $row = function ($a) use ($stClass) {
        return '<tr>'
            . '<td>' . \Carbon\Carbon::parse($a->appointment_date)->format('d M Y')
            . ' <span style="color:#94a3b8;">' . \Carbon\Carbon::parse($a->appointment_time)->format('H:i') . '</span></td>'
            . '<td>' . e(optional($a->pet)->petname ?? '—') . '</td>'
            . '<td>' . e(optional($a->doctor)->name ?? '—') . '</td>'
            . '<td>' . e(ucfirst(str_replace('_', ' ', $a->type ?? '—'))) . '</td>'
            . '<td><span class="vp-badge ' . ($stClass[$a->status] ?? 'vp-b-gray') . '">'
            . e(ucfirst(str_replace('_', ' ', $a->status))) . '</span></td>'
            . '</tr>';
    };
@endphp

<div class="vp-page-title"><i class="fas fa-calendar"></i> {{ __('vetPortal::lang.appointments') }}</div>

<div class="vp-card">
    <div class="vp-card-h"><i class="fas fa-clock" style="color:#2563eb;"></i> {{ __('vetPortal::lang.upcoming') }}</div>
    <div class="vp-card-b" style="padding:0;">
        @if($upcoming->isEmpty())
            <div class="vp-empty">No upcoming appointments.</div>
        @else
            <table class="vp-table">
                <thead><tr><th>Date</th><th>Pet</th><th>Doctor</th><th>Type</th><th>Status</th></tr></thead>
                <tbody>@foreach($upcoming as $a){!! $row($a) !!}@endforeach</tbody>
            </table>
        @endif
    </div>
</div>

<div class="vp-card">
    <div class="vp-card-h"><i class="fas fa-history" style="color:#64748b;"></i> {{ __('vetPortal::lang.past') }}</div>
    <div class="vp-card-b" style="padding:0;">
        @if($past->isEmpty())
            <div class="vp-empty">No past appointments.</div>
        @else
            <table class="vp-table">
                <thead><tr><th>Date</th><th>Pet</th><th>Doctor</th><th>Type</th><th>Status</th></tr></thead>
                <tbody>@foreach($past as $a){!! $row($a) !!}@endforeach</tbody>
            </table>
        @endif
    </div>
</div>

@if(optional($portalSettings)->whatsapp_number)
    <a href="https://wa.me/{{ preg_replace('/[^0-9]/', '', $portalSettings->whatsapp_number) }}?text={{ urlencode('Hello, I would like to ask about an appointment.') }}"
       target="_blank" class="vp-btn vp-btn-wa">
        <i class="fab fa-whatsapp"></i> {{ __('vetPortal::lang.contact_clinic') }}
    </a>
@endif
@endsection
