@extends('layouts.app')
@section('page-title')
    {{ __('Rental Agreement') }}
@endsection
@section('breadcrumb')
<li class="breadcrumb-item"><a href="{{ route('dashboard') }}">{{ __('Dashboard') }}</a></li>
<li class="breadcrumb-item" aria-current="page">{{ __('Rental Agreement') }}</li>
@endsection
@section('card-action-btn')
    @if (Gate::check('manage rental agreement'))
        <a class="btn btn-secondary  customModal" href="#" data-size="lg"
            data-url="{{ route('rental-agreement.create') }}" data-title="{{ __('Create Rental Agreement') }}"> <i
                class="ti ti-circle-plus align-text-bottom"></i>
            {{ __('Create Agreement') }}
        </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>{{ __('Rental Agreement List') }}</h5>
                        </div>
                        <div class="col-auto">
                            @if (Gate::check('manage rental agreement'))
                                <a class="btn btn-secondary  customModal" href="#" data-size="lg"
                                    data-url="{{ route('rental-agreement.create') }}" data-title="{{ __('Create Rental Agreement') }}"> <i
                                        class="ti ti-circle-plus align-text-bottom"></i>
                                    {{ __('Create Agreement') }}
                                </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>{{ __('Date') }}</th>
                                <th>{{ __('Rental Start Date') }}</th>
                                <th>{{ __('Rental End Date') }}</th>
                                <th>{{ __('Rental Duration') }}</th>
                                <th>{{ __('Status') }}</th>
                                @if (Gate::check('edit rental agreement') ||
                                        Gate::check('delete rental agreement') ||
                                        Gate::check('show rental agreement'))
                                    <th>{{ __('Action') }}</th>
                                @endif
                            </tr>
                        </thead>
                        <tbody>
                            @foreach ($agreements as $agreement)
                                <tr>
                                    <td>{{ rentalAgreementPrefix() . $agreement->agreement_id }} </td>
                                    <td>{{ !empty($agreement->drivers) ? $agreement->drivers->name : '-' }}</td>
                                    <td>{{ !empty($agreement->vehicles) ? $agreement->vehicles->name . ' - ' . $agreement->vehicles->license_plate : '-' }}
                                    </td>
                                    <td>{{ dateFormat($agreement->date) }} </td>
                                    <td>{{ dateFormat($agreement->rental_start_date) }} </td>
                                    <td>{{ dateFormat($agreement->rental_end_date) }} </td>
                                    <td>{{ $agreement->rental_duration . ' ' . __('Days') }} </td>
                                    <td>
                                        @if ($agreement->status == 'draft')
                                            <span
                                                class="badge bg-light-info">{{ \App\Models\RentalAgreement::$status[$agreement->status] }}</span>
                                        @elseif($agreement->status == 'pending')
                                            <span
                                                class="badge bg-light-warning">{{ \App\Models\RentalAgreement::$status[$agreement->status] }}</span>
                                        @elseif($agreement->status == 'confirmed' || $agreement->status == 'active')
                                            <span
                                                class="badge bg-light-success">{{ \App\Models\RentalAgreement::$status[$agreement->status] }}</span>
                                        @else
                                            <span
                                                class="badge bg-light-danger">{{ \App\Models\RentalAgreement::$status[$agreement->status] }}</span>
                                        @endif
                                    </td>
                                    @if (Gate::check('edit rental agreement') ||
                                            Gate::check('delete rental agreement') ||
                                            Gate::check('show rental agreement'))
                                        <td>
                                            <div class="cart-action">
                                                {!! Form::open(['method' => 'DELETE', 'route' => ['rental-agreement.destroy', $agreement->id]]) !!}
                                                @can('show rental agreement')
                                                    <a class="avtar avtar-xs btn-link-warning text-warning"
                                                        data-bs-toggle="tooltip" data-bs-original-title="{{ __('Details') }}"
                                                        href="{{ route('rental-agreement.show', \Illuminate\Support\Facades\Crypt::encrypt($agreement->id)) }}">
                                                        <i data-feather="eye"></i></a>
                                                @endcan
                                                @can('edit rental agreement')
                                                    <a class="avtar avtar-xs btn-link-secondary text-secondary customModal"
                                                        data-bs-toggle="tooltip" data-bs-original-title="{{ __('Edit') }}"
                                                        href="#" data-size="lg"
                                                        data-url="{{ route('rental-agreement.edit', $agreement->id) }}"
                                                        data-title="{{ __('Edit Rental Agreement') }}"> <i
                                                            data-feather="edit"></i></a>
                                                @endcan
                                                @can('delete rental agreement')
                                                    <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
