@extends('layouts.app')

@section('content')
    <div class="container-fluid p-4">
        <div class="card shadow-sm p-3">
            <h4 class="fw-bold" style="color: #063986;">Data Booking</h4>
            <div class="d-flex justify-content-between align-items-center mb-3">
                <a href="{{ route('admin.createbooking') }}" class="btn text-white"
                    style="background: linear-gradient(135deg, #8AC0DF, #48499B); border: none;">
                    <i class="bi bi-plus-circle"></i> Tambah Booking
                </a>

                <form method="GET" action="{{ route('admin.booking') }}" class="d-flex">
                    <input type="text" name="search" class="form-control form-control-sm me-2"
                        placeholder="Cari booking..." value="{{ request()->search }}" style="max-width: 200px;">
                    <button type="submit" class="btn btn-outline-secondary btn-sm">Cari</button>
                </form>
            </div>

            <div class="table-responsive">
                <table class="table table-bordered text-center">
                    <thead class="table-primary">
                        <tr>
                            <th>No</th>
                            <th>Nama Customer</th>
                            <th>Nomor Kamar</th>
                            <th>Tanggal Booking</th>
                            <th>Tanggal Check-in</th>
                            <th>Tanggal Check-out</th>
                            <th>Status Booking</th>
                            <th>Aksi</th>
                        </tr>
                    </thead>
                    <tbody>
                        @foreach($bookings as $index => $booking)
                            <tr>
                                <td>{{ $index + 1 }}</td>
                                <td>{{ $booking->user->name }}</td>
                                <td>{{ $booking->room->room_number }}</td>
                                <td>{{ \Carbon\Carbon::parse($booking->tanggal_booking)->format('d-m-Y') }}</td>
                                <td>{{ \Carbon\Carbon::parse($booking->tanggal_checkin)->format('d-m-Y') }}</td>
                                <td>{{ \Carbon\Carbon::parse($booking->tanggal_checkout)->format('d-m-Y') }}</td>
                                <td>{{ ucfirst($booking->status_booking) }}</td>
                                <td>
                                    <a href="{{ route('admin.editbooking', ['id_booking' => $booking->id_booking]) }}" class="text-warning">
                                        <i class="bi bi-pencil-square"></i>
                                    </a>
                                    <a href="{{ route('admin.deletebooking', ['id_booking' => $booking->id_booking]) }}" class="text-danger" 
                                        onclick="return confirm('Apakah Anda yakin ingin menghapus booking ini?');">
                                        <i class="bi bi-trash-fill"></i>
                                    </a>

                                    @if ($booking->status_booking === 'Dikonfirmasi')
                                        <a href="{{ route('admin.bookingselesai', $booking->id_booking) }}" class="btn btn-success btn-sm mt-1">
                                            Tandai Selesai
                                        </a>
                                    @endif
                                </td>
                            </tr>
                        @endforeach
                    </tbody>
                    
                </table>
            </div>
        </div>
    </div>
@endsection
