@extends('backend.layouts.app')
@section('title')
    {{ __('Booking Details') }}
@endsection
@section('content')
    <div class="main-content">
        <div class="page-title">
            <div class="container-fluid">
                <div class="row">
                    <div class="col">
                        <div class="title-content">
                            <h2 class="title">{{ __('Booking Details') }}</h2>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <div class="container-fluid">
            <div class="row">
                <div class="col-xl-6">
                    <div class="site-card">
                        <div class="site-card-header">
                            <h4 class="title-small">{{ __('Booking Information') }}</h4>
                        </div>
                        <div class="site-card-body">
                            <div class="profile-text-data">
                                <div class="attribute">{{ __('Space') }}</div>
                                <div class="value">{{ $booking->space->title ?? 'N/A' }}</div>
                            </div>
                            <div class="profile-text-data">
                                <div class="attribute">{{ __('Location') }}</div>
                                <div class="value">{{ $booking->space->location->name ?? 'N/A' }}</div>
                            </div>
                            <div class="profile-text-data">
                                <div class="attribute">{{ __('Booking ID') }}</div>
                                <div class="value">{{ $booking->booking_id }}</div>
                            </div>
                            <div class="profile-text-data">
                                <div class="attribute">{{ __('Total Amount') }}</div>
                                <div class="value">
                                    <div class="site-badge success">{{ $currencySymbol . $booking->total_amount }}</div>
                                </div>
                            </div>
                            <div class="profile-text-data">
                                <div class="attribute">{{ __('Booking From') }}</div>
                                <div class="value">
                                    {{ $booking->booking_from->format('d M Y h:i A') }}
                                </div>
                            </div>
                            <div class="profile-text-data">
                                <div class="attribute">{{ __('Booking To') }}</div>
                                <div class="value">
                                    {{ $booking->booking_to->format('d M Y h:i A') }}
                                </div>
                            </div>
                            <div class="profile-text-data">
                                <div class="attribute">{{ __('Stock') }}</div>
                                <div class="value">
                                    {{ $booking->stock }}
                                </div>
                            </div>
                            <div class="profile-text-data">
                                <div class="attribute">{{ __('Selected Facilities') }}</div>
                                <div class="value">
                                    {{ $facilities }}
                                </div>
                            </div>
                            <div class="profile-text-data">
                                <div class="attribute">{{ __('Gateway') }}</div>
                                <div class="value">
                                    {{ $booking->gateway->name ?? 'N/A' }}
                                </div>
                            </div>
                            <div class="profile-text-data">
                                <div class="attribute">{{ __('Payment Status') }}</div>
                                <div class="value">
                                    <div @class([
                                        'site-badge',
                                        'success' => $booking->is_paid,
                                        'danger' => !$booking->is_paid,
                                    ])>
                                        {{ $booking->is_paid ? __('Paid') : __('Unpaid') }}
                                    </div>
                                </div>
                            </div>
                            <div class="profile-text-data">
                                <div class="attribute">{{ __('Status') }}</div>
                                <div class="value">
                                    @switch($booking->status->value)
                                        @case('pending')
                                            <div class="site-badge pending">{{ __('Pending') }}</div>
                                        @break

                                        @case('booked')
                                            <div class="site-badge success">{{ __('Booked') }}</div>
                                        @break

                                        @case('cancelled')
                                            <div class="site-badge danger">{{ __('Cancelled') }}</div>
                                        @break
                                        @case('completed')
                                            <div class="site-badge primary">{{ __('Completed') }}</div>
                                        @break
                                    @endswitch
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="col-xl-6">
                    <div class="site-card">
                        <div class="site-card-header">
                            <h4 class="title-small">{{ __('Billing Information') }}</h4>
                        </div>
                        <div class="site-card-body">
                            @foreach ($booking->billing_details as $key => $value)
                                <li class="profile-text-data">
                                    <div class="attribute"> {{ ucwords(str_replace('_', ' ', $key)) }}</div>
                                    <div class="value">
                                        <strong>{{ $value }}</strong>
                                    </div>
                                </li>
                            @endforeach
                        </div>
                    </div>
                </div>
                @can('booking-action')
                    <div class="col-xl-12">
                        <div class="site-card">
                            <div class="site-card-header">
                                <h4 class="title-small">{{ __('Booking Action') }}</h4>
                            </div>
                            <div class="site-card-body">
                                <form action="{{ route('admin.bookings.action', $booking->id) }}" method="post">
                                    @csrf
                                    <div class="row">
                                        <div class="col-xl-6">
                                            <div class="site-input-groups">
                                                <label class="box-input-label" for="">
                                                    {{ __('Payment Status:') }}
                                                </label>
                                                <select name="payment_status" class="form-select" id="">
                                                    <option value="1" @selected($booking->is_paid)>{{ __('Paid') }}
                                                    </option>
                                                    <option value="0" @selected(!$booking->is_paid)>{{ __('Unpaid') }}
                                                    </option>
                                                </select>
                                            </div>
                                        </div>
                                        <div class="col-xl-6">
                                            @php
                                                $reflectionClass = new ReflectionClass(\App\Enums\BookingStatus::class);
                                                $statuses = $reflectionClass->getConstants();
                                            @endphp
                                            <div class="site-input-groups">
                                                <label class="box-input-label" for="">
                                                    {{ __('Status:') }}
                                                </label>
                                                <select name="status" class="form-select" id="">
                                                    @foreach ($statuses as $key => $value)
                                                        <option value="{{ $value }}" @selected($booking->status->value === $value->value)>
                                                            {{ $key }}</option>
                                                    @endforeach
                                                </select>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="action-btns">
                                        <button type="submit" class="site-btn-sm primary-btn me-2">
                                            <i data-lucide="refresh-ccw"></i>
                                            {{ __('Update') }}
                                        </button>
                                    </div>
                                </form>
                            </div>
                        </div>
                    </div>
                @endcan
            </div>
        </div>
    </div>
@endsection
