@extends('layouts.app')

@section('title', 'Beach Reservations')

@section('content')
<div class="content-wrapper">
    <div class="content-header">
        <div class="container-fluid">
            <div class="row mb-2">
                <div class="col-sm-6">
                    <h1 class="m-0">Beach Reservations</h1>
                </div>
                {{-- <div class="col-sm-6">
                    <div class="float-sm-right">
                        <a href="{{ route('beach-reservations.create') }}" class="btn btn-primary">
                            <i class="fas fa-plus"></i> New Reservation
                        </a>
                    </div>
                </div> --}}
            </div>
        </div>
    </div>

    <section class="content">
        <div class="container-fluid">
            <div class="card">
                <div class="card-header">
                    <h3 class="card-title">All Beach Reservations</h3>
                </div>
                <div class="card-body">
                    <form action="{{ route('beach-reservations.index') }}" method="GET" class="mb-4">
                        <div class="row">
                            <div class="col-md-3">
                                <div class="form-group">
                                    <div class="input-group">
                                        <input type="text" name="search" class="form-control" placeholder="Search by full name..." value="{{ request('search') }}">
                                        <div class="input-group-append">
                                            <button type="submit" class="btn btn-primary">
                                                <i class="fas fa-search"></i>
                                            </button>
                                            @if(request('search'))
                                                <a href="{{ route('beach-reservations.index', array_merge(request()->except('search'), ['search' => ''])) }}" class="btn btn-danger">
                                                    <i class="fas fa-times"></i>
                                                </a>
                                            @endif
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <div class="col-md-3">
                                <div class="form-group">
                                    <select name="status" class="form-control" onchange="this.form.submit()">
                                        <option value="">All Statuses</option>
                                        <option value="pending" {{ request('status') == 'pending' ? 'selected' : '' }}>Pending</option>
                                        <option value="approved" {{ request('status') == 'approved' ? 'selected' : '' }}>Approved</option>
                                        <option value="rejected" {{ request('status') == 'rejected' ? 'selected' : '' }}>Rejected</option>
                                    </select>
                                </div>
                            </div>
                            <div class="col-md-3">
                                <div class="form-group">
                                    <input type="date" name="date_from" class="form-control" placeholder="Date From" value="{{ request('date_from') }}" onchange="this.form.submit()">
                                </div>
                            </div>
                            <div class="col-md-3">
                                <div class="form-group">
                                    <input type="date" name="date_to" class="form-control" placeholder="Date To" value="{{ request('date_to') }}" onchange="this.form.submit()">
                                </div>
                            </div>
                        </div>
                    </form>

                    <div class="table-responsive">
                        <table class="table table-bordered table-striped">
                            <thead>
                                <tr>
                                    <th>ID</th>
                                    <th>Customer</th>
                                    <th>Reservation Date</th>
                                    <th>Persons</th>
                                    <th>Instagram</th>
                                    <th>Status</th>
                                    <th>Created</th>
                                    <th>Actions</th>
                                </tr>
                            </thead>
                            <tbody>
                                @forelse($reservations as $reservation)
                                    <tr>
                                        <td>{{ $reservation->id }}</td>
                                        <td>
                                            <div>
                                                <strong>{{ $reservation->full_name }}</strong>
                                                <br>
                                                <small class="text-muted">{{ $reservation->user->email }}</small>
                                            </div>
                                        </td>
                                        <td>{{ $reservation->formatted_date }}</td>
                                        <td>
                                            <span class="badge bg-info text-white">{{ $reservation->number_of_persons }}</span>
                                        </td>
                                        <td>
                                            <a href="{{ $reservation->instagram_link }}" target="_blank" class="text-primary">
                                                <i class="fab fa-instagram"></i> View Profile
                                            </a>
                                        </td>
                                        <td>
                                            @php
                                                $statusColors = [
                                                    'pending' => ['bg' => 'bg-warning', 'text' => 'text-dark'],
                                                    'approved' => ['bg' => 'bg-success', 'text' => 'text-white'],
                                                    'rejected' => ['bg' => 'bg-danger', 'text' => 'text-white']
                                                ];
                                                $status = $reservation->status;
                                                $colors = $statusColors[$status];
                                            @endphp
                                            <span class="badge {{ $colors['bg'] }} {{ $colors['text'] }} p-2">
                                                {{ ucfirst($status) }}
                                            </span>
                                        </td>
                                        <td>{{ $reservation->created_at->format('M d, Y H:i') }}</td>
                                        <td>
                                            <div class="btn-group" role="group">
                                                <a href="{{ route('beach-reservations.show', $reservation) }}" class="btn btn-sm btn-info" title="View Details">
                                                    <i class="fas fa-eye"></i>
                                                </a>
                                                @if($reservation->isPending())
                                                    <form method="POST" action="{{ route('beach-reservations.approve', $reservation) }}" class="d-inline">
                                                        @csrf
                                                        <button type="submit" class="btn btn-sm btn-success" title="Approve" onclick="return confirm('Are you sure you want to approve this reservation?')">
                                                            <i class="fas fa-check"></i>
                                                        </button>
                                                    </form>
                                                    <form method="POST" action="{{ route('beach-reservations.reject', $reservation) }}" class="d-inline">
                                                        @csrf
                                                        <button type="submit" class="btn btn-sm btn-danger" title="Reject" onclick="return confirm('Are you sure you want to reject this reservation?')">
                                                            <i class="fas fa-times"></i>
                                                        </button>
                                                    </form>
                                                @endif
                                            </div>
                                        </td>
                                    </tr>
                                @empty
                                    <tr>
                                        <td colspan="8" class="text-center">No beach reservations found</td>
                                    </tr>
                                @endforelse
                            </tbody>
                        </table>
                    </div>
                </div>
                <div class="card-footer">
                    {{ $reservations->appends(request()->query())->links() }}
                </div>
            </div>
        </div>
    </section>
</div>

<style>
.badge {
    font-size: 0.9em;
    font-weight: 500;
    padding: 0.5em 1em;
}
.badge.bg-warning {
    background-color: #ffc107 !important;
}
.badge.bg-info {
    background-color: #17a2b8 !important;
}
.badge.bg-success {
    background-color: #28a745 !important;
}
.badge.bg-danger {
    background-color: #dc3545 !important;
}
.btn-group .btn {
    margin-right: 2px;
}
.btn-group .btn:last-child {
    margin-right: 0;
}
</style>
@endsection 