@extends('layouts.yellow')

@section('content')
<div class="container">
    <div class="row justify-content-center">
        <div class="col-md-12">
            <div class="card">
                <div class="card-header d-flex justify-content-between align-items-center">
                    <h5 class="mb-0">{{ __('doctor-schedules.schedules') }}</h5>
                    <a href="{{ route('doctor-schedules.create') }}" class="btn btn-primary btn-sm">
                        <i class="fas fa-plus"></i> {{ __('common.add_new') }}
                    </a>
                </div>

                <div class="card-body">
                    @if (session('success'))
                        <div class="alert alert-success alert-dismissible fade show" role="alert">
                            {{ session('success') }}
                            <button type="button" class="close" data-dismiss="alert" aria-label="Close">
                                <span aria-hidden="true">&times;</span>
                            </button>
                        </div>
                    @endif

                    @if (session('error'))
                        <div class="alert alert-danger alert-dismissible fade show" role="alert">
                            {{ session('error') }}
                            <button type="button" class="close" data-dismiss="alert" aria-label="Close">
                                <span aria-hidden="true">&times;</span>
                            </button>
                        </div>
                    @endif

                    @if(count($schedules) > 0)
                        <div class="table-responsive">
                            <table class="table table-hover">
                                <thead>
                                    <tr>
                                        <th>{{ __('doctor-schedules.doctor') }}</th>
                                        <th>{{ __('doctor-schedules.day_of_week') }}</th>
                                        <th>{{ __('doctor-schedules.start_time') }}</th>
                                        <th>{{ __('doctor-schedules.end_time') }}</th>
                                        <th>{{ __('common.status') }}</th>
                                        <th class="text-center">{{ __('common.actions') }}</th>
                                    </tr>
                                </thead>
                                <tbody>
                                    @foreach ($schedules as $schedule)
                                        <tr>
                                            <td>{{ $schedule->doctor->name }} {{ $schedule->doctor->lastname }}</td>
                                            <td>
                                                @switch($schedule->day_of_week)
                                                    @case(0)
                                                        {{ __('doctor-schedules.sunday') }}
                                                        @break
                                                    @case(1)
                                                        {{ __('doctor-schedules.monday') }}
                                                        @break
                                                    @case(2)
                                                        {{ __('doctor-schedules.tuesday') }}
                                                        @break
                                                    @case(3)
                                                        {{ __('doctor-schedules.wednesday') }}
                                                        @break
                                                    @case(4)
                                                        {{ __('doctor-schedules.thursday') }}
                                                        @break
                                                    @case(5)
                                                        {{ __('doctor-schedules.friday') }}
                                                        @break
                                                    @case(6)
                                                        {{ __('doctor-schedules.saturday') }}
                                                        @break
                                                @endswitch
                                            </td>
                                            <td>{{ $schedule->start_time }}</td>
                                            <td>{{ $schedule->end_time }}</td>
                                            <td>
                                                @if($schedule->is_active)
                                                    <span class="badge badge-success">{{ __('common.active') }}</span>
                                                @else
                                                    <span class="badge badge-danger">{{ __('common.inactive') }}</span>
                                                @endif
                                            </td>
                                            <td class="text-center">
                                                <div class="btn-group">
                                                    <a href="{{ route('doctor-schedules.show', $schedule->id) }}" class="btn btn-info btn-sm">
                                                        <i class="fas fa-eye"></i>
                                                    </a>
                                                    <a href="{{ route('doctor-schedules.edit', $schedule->id) }}" class="btn btn-primary btn-sm">
                                                        <i class="fas fa-edit"></i>
                                                    </a>
                                                    <button type="button" class="btn btn-danger btn-sm" 
                                                            onclick="confirmDelete('{{ $schedule->id }}')">
                                                        <i class="fas fa-trash"></i>
                                                    </button>
                                                </div>
                                                <form id="delete-form-{{ $schedule->id }}" 
                                                      action="{{ route('doctor-schedules.destroy', $schedule->id) }}" 
                                                      method="POST" style="display: none;">
                                                    @csrf
                                                    @method('DELETE')
                                                </form>
                                            </td>
                                        </tr>
                                    @endforeach
                                </tbody>
                            </table>
                        </div>
                        
                        <div class="d-flex justify-content-center mt-4">
                            {{ $schedules->links() }}
                        </div>
                    @else
                        <div class="alert alert-info text-center">
                            <i class="fas fa-info-circle mr-2"></i> {{ __('common.no_records_found') }}
                        </div>
                    @endif
                </div>
            </div>
        </div>
    </div>
</div>

@endsection

@section('scripts')
<script>
    function confirmDelete(id) {
        if (confirm("{{ __('common.confirm_delete') }}")) {
            document.getElementById('delete-form-' + id).submit();
        }
    }
</script>
@endsection 