@extends('frontend::layouts.user')
@section('title')
    {{ __('My Bookings') }}
@endsection
@section('content')
    <div class="td-dashboard-content-box-profile">
        <div class="td-dashboard-content-box-profile-title">
            <h3>{{ __('My Bookings') }}</h3>
        </div>
        <div class="td-dashboard-content-box-bookings-table">
            <div class="table-responsive">
                <table class="table align-middle custom-table-width">
                    <thead>
                        <tr>
                            <th scope="col" class="text-start">{{ __('Image') }}</th>
                            <th scope="col" class="text-start">{{ __('Space Type') }}</th>
                            <th scope="col" class="text-center">{{ __('Location') }}</th>
                            <th scope="col" class="text-center">{{ __('Booking From') }}</th>
                            <th scope="col" class="text-center">{{ __('Booking To') }}</th>
                            <th scope="col" class="text-center">{{ __('Amount') }}</th>
                            <th scope="col" class="text-center">{{ __('Payment Status') }}</th>
                            <th scope="col" class="text-center">{{ __('Status') }}</th>
                            <th scope="col" class="text-center">{{ __('Action') }}</th>
                        </tr>
                    </thead>
                    <tbody>
                        @foreach ($bookings as $booking)
                            <tr>
                                <td class="text-start">
                                    <img src="{{ asset($booking->space->banner_image) }}" alt="">
                                </td>
                                <td class="text-center">{{ $booking->space?->type?->name }}</td>
                                <td class="text-center">{{ $booking->space?->location?->name }}</td>
                                <td class="text-center">{{ $booking->booking_from->format('d M Y h:i A') }}</td>
                                <td class="text-center">{{ $booking->booking_to->format('d M Y h:i A') }}</td>
                                <td class="amount text-center">
                                    {{ setting('currency_symbol') }}{{ $booking->total_amount }}</td>
                                <td class="status text-end">
                                    <button
                                        @class([
                                            'success' => $booking->is_paid,
                                            'ongoing' => !$booking->is_paid,
                                        ])>{{ $booking->is_paid ? __('Paid') : __('Unpaid') }}</button>
                                </td>
                                <td class="status text-end">
                                    <button @class([
                                        'success' => in_array($booking->status, [App\Enums\BookingStatus::Booked, App\Enums\BookingStatus::Completed]),
                                        'ongoing' => !in_array($booking->status, [App\Enums\BookingStatus::Booked, App\Enums\BookingStatus::Completed]),
                                    ])>{{ ucfirst($booking->status->value) }}</button>
                                </td>
                                <td class="status text-end">
                                    <div class="action-btns">
                                        @if (!$booking->is_paid && $booking->status !== App\Enums\BookingStatus::Cancelled)
                                            <a href="{{ route('user.booking.booked', $booking->booking_id) }}" target="_blank"
                                                class="print-btn" aria-label="{{ __('Pay Now') }}" data-bs-toggle="tooltip"
                                                data-bs-placement="top" data-bs-original-title="{{ __('Pay Now') }}">
                                                <i class="fa-solid fa-paper-plane"></i>
                                            </a>
                                        @endif
                                        <a href="{{ route('user.booking.invoice', $booking->booking_id) }}"
                                            class="print-btn" aria-label="{{ __('Download Invoice') }}"
                                            data-bs-toggle="tooltip" data-bs-placement="top"
                                            data-bs-original-title="{{ __('Download Invoice') }}">
                                            <i class="fa-solid fa-print"></i>
                                        </a>
                                    </div>
                                </td>
                            </tr>
                        @endforeach
                    </tbody>
                </table>
            </div>
            {{ $bookings->links('frontend::include.__pagination') }}
        </div>
    </div>
@endsection
