@extends('layouts.yellow')
@section('content')
<style>
    .recurring-appointments-container {
        padding: 1.5rem;
    }
    
    .page-header {
        background: linear-gradient(135deg, #4A90E2 0%, #2A4E6D 100%);
        border-radius: 12px;
        padding: 1.5rem;
        margin-bottom: 1.5rem;
        color: white;
        box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
    }
    
    .page-header h2 {
        margin: 0;
        font-weight: 600;
    }
    
    .data-card {
        background: white;
        border-radius: 12px;
        overflow: hidden;
        box-shadow: 0 4px 15px rgba(0, 0, 0, 0.05);
    }
    
    .table-header {
        background-color: #f8fafc;
        font-weight: 600;
        color: #4a5568;
    }
    
    .empty-state {
        padding: 3rem 2rem;
        text-align: center;
    }
    
    .empty-state i {
        font-size: 3.5rem;
        color: #a0aec0;
        margin-bottom: 1rem;
    }
    
    .empty-state p {
        color: #718096;
        font-size: 1.1rem;
        margin-bottom: 1.5rem;
    }
    
    .badge-scheduled {
        background-color: rgba(74, 144, 226, 0.15);
        color: #4A90E2;
        font-weight: 500;
        padding: 0.35rem 0.75rem;
        border-radius: 50px;
    }
    
    .badge-success {
        background-color: rgba(46, 182, 125, 0.15);
        color: #2eb67d;
    }
    
    .badge-warning {
        background-color: rgba(255, 193, 7, 0.15);
        color: #ffc107;
    }
    
    .badge-danger {
        background-color: rgba(227, 52, 47, 0.15);
        color: #e3342f;
    }
    
    .btn-action {
        width: 32px;
        height: 32px;
        padding: 0;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        border-radius: 8px;
        margin-right: 0.25rem;
        transition: all 0.2s;
    }
    
    .btn-action:hover {
        transform: translateY(-2px);
        box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
    }
    
    .btn-info {
        background-color: rgba(74, 144, 226, 0.1);
        color: #4A90E2;
        border: none;
    }
    
    .btn-info:hover {
        background-color: #4A90E2;
        color: white;
    }
    
    .btn-primary {
        background-color: rgba(49, 130, 206, 0.1);
        color: #3182ce;
        border: none;
    }
    
    .btn-primary:hover {
        background-color: #3182ce;
        color: white;
    }
    
    .btn-danger {
        background-color: rgba(227, 52, 47, 0.1);
        color: #e3342f;
        border: none;
    }
    
    .btn-danger:hover {
        background-color: #e3342f;
        color: white;
    }
    
    .table-hover tbody tr {
        transition: all 0.2s;
    }
    
    .table-hover tbody tr:hover {
        background-color: rgba(74, 144, 226, 0.05);
    }
    
    .patient-name {
        font-weight: 600;
        color: #2d3748;
    }
    
    .appointment-time {
        display: block;
        font-weight: 600;
        color: #4A90E2;
        margin-bottom: 0.35rem;
    }
    
    .time-remaining {
        font-size: 0.8rem;
    }
    
    .text-primary-custom {
        color: #4A90E2;
    }
    
    .alert-custom {
        border-left: 4px solid;
        padding: 1rem 1.25rem;
        border-radius: 8px;
    }
    
    .alert-success-custom {
        background-color: rgba(46, 182, 125, 0.1);
        border-left-color: #2eb67d;
        color: #2eb67d;
    }
    
    .pagination {
        margin-top: 1.5rem;
    }
    
    .new-appointment-btn {
        background: linear-gradient(135deg, #4A90E2 0%, #3B6EA5 100%);
        color: white;
        border: none;
        padding: 0.5rem 1.25rem;
        border-radius: 8px;
        font-weight: 500;
        transition: all 0.3s;
    }
    
    .new-appointment-btn:hover {
        transform: translateY(-2px);
        box-shadow: 0 4px 12px rgba(74, 144, 226, 0.2);
        color: white;
    }
</style>

<div class="container-fluid recurring-appointments-container">
    <div class="row">
        <div class="col-12">
            <div class="page-header d-flex justify-content-between align-items-center">
                <div class="d-flex align-items-center">
                    <i class="bi bi-calendar-check me-3 fs-3"></i>
                    <h2>
                        @if(isset($patient_id) && $recurringAppointments->isNotEmpty())
                            {{ __('recurring-appointments.titleView') }}: {{ $recurringAppointments->first()->patient->firstname }} {{ $recurringAppointments->first()->patient->lastname }}
                        @else
                            {{ __('recurring-appointments.titleView') }}
                        @endif
                    </h2>
                </div>
                <div>
                    @if(isset($patient_id))
                        <a href="{{ url()->previous() }}" class="btn btn-secondary me-2">
                            <i class="bi bi-arrow-left me-1"></i> {{ __('recurring-appointments.back') }}
                        </a>
                    @endif
                    
                    <a href="{{ route('recurring-appointments.create', ['appointment_id' => session('last_appointment_id')]) }}" 
                       class="btn new-appointment-btn" {{ session('last_appointment_id') ? '' : 'disabled' }}>
                        <i class="bi bi-plus-circle me-2"></i>
                        {{ __('recurring-appointments.create') }}
                    </a>
                </div>
            </div>
        </div>
    </div>

    @if(session('success'))
    <div class="row mb-3">
        <div class="col-12">
            <div class="alert alert-custom alert-success-custom alert-dismissible fade show">
                <div class="d-flex align-items-center">
                    <i class="bi bi-check-circle me-2 fs-4"></i>
                    <div>{{ session('success') }}</div>
                </div>
                <button type="button" class="btn-close" data-bs-dismiss="alert"></button>
            </div>
        </div>
    </div>
    @endif

    @if(session('error'))
    <div class="row mb-3">
        <div class="col-12">
            <div class="alert alert-custom alert-danger-custom alert-dismissible fade show">
                <div class="d-flex align-items-center">
                    <i class="bi bi-exclamation-triangle me-2 fs-4"></i>
                    <div>{{ session('error') }}</div>
                </div>
                <button type="button" class="btn-close" data-bs-dismiss="alert"></button>
            </div>
        </div>
    </div>
    @endif

    <div class="row">
        <div class="col-12">
            <div class="data-card">
                <div class="table-responsive">
                    <table class="table table-hover mb-0">
                        <thead class="table-header">
                            <tr>
                                <th class="px-4 py-3">
                                    <div class="d-flex align-items-center">
                                        <i class="bi bi-person me-2 text-primary-custom"></i>
                                        {{ __('recurring-appointments.patient') }}
                                    </div>
                                </th>
                                <th class="px-4 py-3">
                                    <div class="d-flex align-items-center">
                                        <i class="bi bi-person-badge me-2 text-primary-custom"></i>
                                        {{ __('recurring-appointments.doctor') }}
                                    </div>
                                </th>
                                <th class="px-4 py-3">
                                    <div class="d-flex align-items-center">
                                        <i class="bi bi-clipboard-plus me-2 text-primary-custom"></i>
                                        {{ __('recurring-appointments.especiality') }}
                                    </div>
                                </th>
                                <th class="px-4 py-3">
                                    <div class="d-flex align-items-center">
                                        <i class="bi bi-calendar-event me-2 text-primary-custom"></i>
                                        {{ __('recurring-appointments.nextAppointment') }}
                                    </div>
                                </th>
                                <th class="px-4 py-3">
                                    <div class="d-flex align-items-center">
                                        <i class="bi bi-calendar-range me-2 text-primary-custom"></i>
                                        {{ __('recurring-appointments.daysInterval') }}
                                    </div>
                                </th>
                                <th class="px-4 py-3">
                                    <div class="d-flex align-items-center">
                                        <i class="bi bi-bell me-2 text-primary-custom"></i>
                                        {{ __('recurring-appointments.reminderDays') }}
                                    </div>
                                </th>
                                <th class="px-4 py-3">
                                    <div class="d-flex align-items-center">
                                        <i class="bi bi-calendar-check me-2 text-primary-custom"></i>
                                        {{ __('recurring-appointments.autoSchedule') }}
                                    </div>
                                </th>
                                <th class="px-4 py-3">
                                    <div class="d-flex align-items-center">
                                        <i class="bi bi-gear me-2 text-primary-custom"></i>
                                        {{ __('recurring-appointments.actions') }}
                                    </div>
                                </th>
                            </tr>
                        </thead>
                        <tbody>
                            @forelse($recurringAppointments as $recurring)
                            @php
                                $daysUntil = \Carbon\Carbon::now()->startOfDay()->diffInDays(\Carbon\Carbon::parse($recurring->next_appointment_date)->startOfDay(), false);
                                $isPast = \Carbon\Carbon::parse($recurring->next_appointment_date)->isPast();
                                $isClose = $daysUntil <= $recurring->reminder_days && !$isPast;
                            @endphp
                            <tr>
                                <td class="px-4 py-3">
                                    <span class="patient-name">
                                        {{ $recurring->patient->firstname }} {{ $recurring->patient->lastname }}
                                    </span>
                                </td>
                                <td class="px-4 py-3">
                                    {{ $recurring->doctor->name }}
                                </td>
                                <td class="px-4 py-3">
                                    {{ $recurring->especialityRelation->name }}
                                </td>
                                <td class="px-4 py-3">
                                    <span class="appointment-time">
                                        {{ \Carbon\Carbon::parse($recurring->next_appointment_date)->format('d/m/Y') }}
                                    </span>
                                    <span class="badge {{ $isPast ? 'badge-danger' : ($isClose ? 'badge-warning' : 'badge-scheduled') }} time-remaining">
                                        <i class="bi {{ $isPast ? 'bi-exclamation-circle' : 'bi-clock' }} me-1"></i>
                                        {{ \Carbon\Carbon::parse($recurring->next_appointment_date)->diffForHumans() }}
                                    </span>
                                </td>
                                <td class="px-4 py-3">
                                    <span class="badge badge-scheduled">
                                        {{ $recurring->days_interval }} {{ __('recurring-appointments.days') }}
                                    </span>
                                </td>
                                <td class="px-4 py-3">
                                    <span class="badge badge-scheduled">
                                        {{ $recurring->reminder_days }} {{ __('recurring-appointments.days') }}
                                    </span>
                                </td>
                                <td class="px-4 py-3">
                                    <span class="badge {{ $recurring->auto_schedule ? 'badge-success' : 'badge-secondary' }}">
                                        <i class="bi {{ $recurring->auto_schedule ? 'bi-check-circle' : 'bi-x-circle' }} me-1"></i>
                                        {{ $recurring->auto_schedule ? __('recurring-appointments.yes') : __('recurring-appointments.no') }}
                                    </span>
                                </td>
                                <td class="px-4 py-3">
                                    <div class="d-flex">
                                        <a href="{{ route('recurring-appointments.show', $recurring->id) }}" class="btn btn-action btn-info">
                                            <i class="bi bi-eye"></i>
                                        </a>
                                        <a href="{{ route('recurring-appointments.edit', $recurring->id) }}" class="btn btn-action btn-primary">
                                            <i class="bi bi-pencil"></i>
                                        </a>
                                        <form action="{{ route('recurring-appointments.cancel', $recurring->id) }}" method="POST" class="d-inline" onsubmit="return confirm('{{ __('recurring-appointments.confirmCancel') }}');">
                                            @csrf
                                            @method('DELETE')
                                            <button type="submit" class="btn btn-action btn-danger">
                                                <i class="bi bi-x-circle"></i>
                                            </button>
                                        </form>
                                    </div>
                                </td>
                            </tr>
                            @empty
                            <tr>
                                <td colspan="8">
                                    <div class="empty-state">
                                        <i class="bi bi-calendar-x mb-3"></i>
                                        <p>{{ __('recurring-appointments.noRecurringAppointments') }}</p>
                                        <a href="{{ route('/admin/view-appointments') }}" class="btn new-appointment-btn">
                                            <i class="bi bi-calendar-plus me-2"></i>
                                            {{ __('view-appointments.create') }}
                                        </a>
                                    </div>
                                </td>
                            </tr>
                            @endforelse
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
    </div>
</div>
@endsection 