@extends('layouts.app')

@section('title', __('clinic.visits'))
@section('heading', __('clinic.visits'))

@section('content')
    <div class="card mb-1">
        <form method="GET" action="{{ route('visits.index') }}" class="form-grid" style="--grid-cols: 3; gap: 0.75rem; align-items: flex-end;">
            <div class="form-group mb-0">
                <label for="q">{{ __('clinic.search') }}</label>
                <input id="q" class="form-control" name="q" value="{{ request('q') }}" placeholder="{{ __('clinic.search_placeholder') }}">
            </div>

            <div class="form-group mb-0">
                <label for="status">{{ __('clinic.visit_status') }}</label>
                <select id="status" class="form-control" name="status">
                    <option value="">{{ __('clinic.view_all') }}</option>
                    <option value="waiting" {{ request('status') === 'waiting' ? 'selected' : '' }}>{{ __('clinic.waiting') }}</option>
                    <option value="in_progress" {{ request('status') === 'in_progress' ? 'selected' : '' }}>{{ __('clinic.in_progress') }}</option>
                    <option value="completed" {{ request('status') === 'completed' ? 'selected' : '' }}>{{ __('clinic.completed') }}</option>
                    <option value="cancelled" {{ request('status') === 'cancelled' ? 'selected' : '' }}>{{ __('clinic.cancelled') }}</option>
                </select>
            </div>

            <div class="flex gap">
                <button type="submit" class="btn btn-primary btn-sm" style="flex: 1;">{{ __('clinic.filter') }}</button>
                <a href="{{ route('visits.index') }}" class="btn btn-ghost btn-sm">✕</a>
            </div>
        </form>
    </div>

    <div class="flex-between mb-1" style="display:flex; justify-content:flex-end;">
        <a href="{{ route('visits.create') }}" class="btn btn-primary btn-sm">➕ {{ __('clinic.new_visit') }}</a>
    </div>

    <div class="table-wrap">
        <table class="data-table">
            <thead>
                <tr>
                    <th>{{ __('clinic.visit_date') }}</th>
                    <th>{{ __('clinic.patients') }}</th>
                    <th>{{ __('clinic.chief_complaint') }}</th>
                    <th>👨‍⚕️ {{ __('clinic.filter_by_doctor') }}</th>
                    <th>{{ __('clinic.status') }}</th>
                    <th></th>
                </tr>
            </thead>
            <tbody>
                @forelse ($visits as $v)
                    <tr>
                        <td><strong>{{ $v->visit_date->format('Y-m-d H:i') }}</strong></td>
                        <td><a href="{{ route('patients.show', $v->patient) }}">{{ $v->patient->full_name }}</a></td>
                        <td><a href="{{ route('visits.show', $v) }}">{{ $v->chief_complaint }}</a></td>
                        <td>{{ $v->doctor->name ?? '—' }}</td>
                        <td>
                            <span class="pill @if($v->status === 'completed') pill-success @elseif($v->status === 'waiting') pill-muted @else pill-danger @endif">
                                {{ __('clinic.' . $v->status) }}
                            </span>
                        </td>
                        <td>
                            <a href="{{ route('visits.show', $v) }}" class="btn btn-ghost btn-sm">Open</a>
                        </td>
                    </tr>
                @empty
                    <tr>
                        <td colspan="6" style="text-align: center;">{{ __('clinic.no_records') }}</td>
                    </tr>
                @endforelse
            </tbody>
        </table>
    </div>

    @include('partials.pagination', ['paginator' => $visits])
@endsection
