@extends('layouts.app')
@section('page-title')
    {{ __('Booking') }}
@endsection
@section('breadcrumb')
    <li class="breadcrumb-item"><a href="{{ route('dashboard') }}">{{ __('Dashboard') }}</a></li>
    <li class="breadcrumb-item" aria-current="page">{{ __('Booking') }}</li>
@endsection
@section('card-action-btn')
    @if (Gate::check('manage vehicle'))
        <a class="btn btn-secondary btn-sm ml-20" href="{{ route('booking.create') }}"> <i class="ti-plus mr-5"></i>
            {{ __('Create Booking') }}
        </a>
    @endif
@endsection
@section('content')
    <div class="row">
        <div class="col-12">
            <div class="card table-card">
                <div class="card-header">
                    <div class="row align-items-center g-2">
                        <div class="col">
                            <h5>{{ __('Booking List') }}</h5>
                        </div>
                        <div class="col-auto">
                            @if (Gate::check('manage vehicle'))
                                <a class="btn btn-secondary" href="{{ route('booking.create') }}">  <i class="ti ti-circle-plus align-text-bottom"></i>
                                    {{ __('Create Booking') }}
                                </a>
                            @endif
                        </div>
                    </div>
                </div>
                <div class="card-body pt-0">
                    <div class="dt-responsive table-responsive">
                        <table class="table table-hover advance-datatable">
                            <thead>
                                <tr>
                                    <th>{{ __('ID') }}</th>
                                    <th>{{ __('Driver') }}</th>
                                    <th>{{ __('Vehicle') }}</th>
                                    <th>{{ __('Duration') }}</th>
                                    <th>{{ __('Status') }}</th>
                                    <th>{{ __('Payment Status') }}</th>
                                    @if (Gate::check('edit booking') || Gate::check('delete booking') || Gate::check('show booking'))
                                        <th>{{ __('Action') }}</th>
                                    @endif
                                </tr>
                            </thead>
                            <tbody>
                                @foreach ($bookings as $booking)
                                    <tr>
                                        <td>{{ bookingPrefix() . $booking->booking_id }} </td>
                                        <td>{{ !empty($booking->drivers) ? $booking->drivers->name : '-' }} </td>
                                        <td>{{ !empty($booking->vehicleDetails()) ? $booking->vehicleDetails()->name : '-' }}
                                        </td>
                                        <td>
                                            {{ dateFormat($booking->start_date) . ' / ' . timeFormat($booking->start_time) }}
                                            <br>
                                            {{ dateFormat($booking->end_date) . ' / ' . timeFormat($booking->end_time) }}
                                        </td>
                                        <td>
                                            @if ($booking->status == 'yet_to_start')
                                                <span
                                                    class="badge bg-light-primary">{{ \App\Models\Booking::$status[$booking->status] }}</span>
                                            @elseif($booking->status == 'completed')
                                                <span
                                                    class="badge bg-light-success">{{ \App\Models\Booking::$status[$booking->status] }}</span>
                                            @elseif($booking->status == 'on_going')
                                                <span
                                                    class="badge bg-light-warning">{{ \App\Models\Booking::$status[$booking->status] }}</span>
                                            @elseif($booking->status == 'cancelled')
                                                <span
                                                    class="badge bg-light-danger">{{ \App\Models\Booking::$status[$booking->status] }}</span>
                                            @endif
                                        </td>
                                        <td>
                                            @if ($booking->payment_status == 'paid')
                                                <span
                                                    class="badge bg-light-success">{{ \App\Models\Booking::$paymentStatus[$booking->payment_status] }}</span>
                                            @elseif($booking->payment_status == 'unpaid')
                                                <span
                                                    class="badge bg-light-danger">{{ \App\Models\Booking::$paymentStatus[$booking->payment_status] }}</span>
                                            @elseif($booking->payment_status == 'partial_paid')
                                                <span
                                                    class="badge bg-light-warning">{{ \App\Models\Booking::$paymentStatus[$booking->payment_status] }}</span>
                                            @endif
                                        </td>
                                        @if (Gate::check('edit booking') || Gate::check('delete booking') || Gate::check('show booking'))
                                            <td>
                                                <div class="cart-action">
                                                    {!! Form::open(['method' => 'DELETE', 'route' => ['booking.destroy', $booking->id]]) !!}
                                                    @can('show booking')
                                                        <a class="avtar avtar-xs btn-link-warning text-warning" data-bs-toggle="tooltip"
                                                            data-bs-original-title="{{ __('Details') }}"
                                                            href="{{ route('booking.show', \Illuminate\Support\Facades\Crypt::encrypt($booking->id)) }}">
                                                            <i data-feather="eye"></i></a>
                                                    @endcan
                                                    @can('edit booking')
                                                        <a class="avtar avtar-xs btn-link-secondary text-secondary" data-bs-toggle="tooltip"
                                                            data-bs-original-title="{{ __('Edit') }}"
                                                            href="{{ route('booking.edit', \Illuminate\Support\Facades\Crypt::encrypt($booking->id)) }}">
                                                            <i data-feather="edit"></i></a>
                                                    @endcan
                                                    @can('delete booking')
                                                        <a class=" avtar avtar-xs btn-link-danger text-danger confirm_dialog" data-bs-toggle="tooltip"
                                                            data-bs-original-title="{{ __('Detete') }}" href="#"> <i
                                                                data-feather="trash-2"></i></a>
                                                    @endcan
                                                    {!! Form::close() !!}
                                                </div>

                                            </td>
                                        @endif
                                    </tr>
                                @endforeach

                            </tbody>
                        </table>
                    </div>
                </div>
            </div>
        </div>
    </div>
@endsection
