<!-- <x-owner-layout> -->
    @section('page_css')
        <link rel="stylesheet" type="text/css"
            href="{{ asset('app-assets/vendors/css/tables/datatable/datatables.min.css') }}">
        <link rel="stylesheet" type="text/css"
            href="{{ asset('app-assets/vendors/css/tables/datatable/extensions/dataTables.checkboxes.css') }}">
        <link rel="stylesheet" type="text/css" href="{{ asset('app-assets/css/pages/data-list-view.css') }}">
        <link href="{{ asset('app-assets/css/bootstrap-datepicker.min.css') }}" rel="stylesheet">
        <style>
            .datepicker {
                z-index: 1000 !important;
            }
        </style>

        <div class="app-content content">
            <div class="content-overlay"></div>
            <div class="header-navbar-shadow"></div>
            <div class="content-wrapper">
                <div class="content-header row">
                    <div class="content-header-left col-md-8 col-12 mb-2">
                        <div class="row breadcrumbs-top">
                            <div class="col-12">
                                <h2 class="content-header-title float-left mb-0">Wash Report</h2>
                                <div class="breadcrumb-wrapper">
                                    <ol class="breadcrumb">
                                        <li class="breadcrumb-item"><a href="{{ $home_url }}">Home</a></li>
                                        <li class="breadcrumb-item active">Wash Report</li>
                                    </ol>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="content-header-right text-md-right col-md-4 col-12">
                        <div class="form-group breadcrum-right">
                            <div class="buttons-section">
                                @include('owner.washreport.partials._action_buttons')
                            </div>

                        </div>
                    </div>

                </div>
                <div class="content-body">
                    <section id="data-list-view" class="data-list-view-header">
                        @if (Session::has('msg'))
                        <div class="alert {{ Session::get('msg_class') }}" role="alert">
                            <p class="mb-0">
                                {{ Session::get('msg') }}
                            </p>
                        </div>
                        @endif
                        <!-- filters start -->
                        <div class="card">
                        <div class="card-header">
                            <!-- <h4 class="card-title">Car Registration No.</h4> -->
                            <a class="heading-elements-toggle"><i class="fa fa-ellipsis-v font-medium-3"></i></a>
                            <div class="heading-elements">
                                <ul class="list-inline mb-0">
                                    <li><a data-action="collapse"><i class="feather icon-chevron-down"></i></a></li>
                                    <!-- <li><a data-action=""><i class="feather icon-rotate-cw users-data-filter"></i></a> -->
                                    </li>
                                    <li><a data-action="close"><i class="feather icon-x"></i></a></li>
                                </ul>
                            </div>
                        </div>
                        <div class="card-content collapse show">
                            <div class="card-body">
                                <div class="users-list-filter">
                                    <form method="GET" action="{{ route('owner.cor.list') }}">
                                    <div class="row">
                                        <div class="col-md-4">
                                            <div class="form-group row">
                                                <!-- <div class="col-md-5">
                                                    <span>Car Registration No.</span>
                                                </div> -->
                                                <div class="col-md-12">
                                                    <input type="text" class="form-control" id="car_registration_no" name="car_registration_no" placeholder="Car Registration No." value="@if(request()->get('car_registration_no')) {{request()->get('car_registration_no')}} @endif">
                                                </div>
                                            </div>
                                        </div>
                                        <div class="col-md-4">
                                            <div class="form-group row">
                                                <!-- <div class="col-md-5">
                                                    <span>Car Registration No.</span>
                                                </div> -->
                                                <div class="col-md-12">
                                                    <div class="input-group date" data-provide="datepicker" data-date-format="yyyy/mm/dd">
                                                        <input type="text" id="start_date" class="form-control rounded" name="start_date" placeholder="Start Date" value="@if(request()->get('start_date')) {{ date('Y/m/d', strtotime(request()->get('start_date'))) }} @endif"  autocomplete="off">
                                                        <div class="input-group-addon">
                                                            <span class="glyphicon glyphicon-th"></span>
                                                        </div>
                                                    </div>
                                                </div>
                                            </div>
                                        </div>
                                        <div class="col-md-4">
                                            <div class="form-group row">
                                                <!-- <div class="col-md-5">
                                                    <span>Car Registration No.</span>
                                                </div> -->
                                                <div class="col-md-12">
                                                    <div class="input-group date" data-provide="datepicker" data-date-format="yyyy/mm/dd">
                                                        <input type="text" id="end_date" class="form-control rounded" name="end_date" placeholder="End Date" value="@if(request()->get('end_date')) {{ date('Y/m/d', strtotime(request()->get('end_date'))) }} @endif"  autocomplete="off">
                                                        <div class="input-group-addon">
                                                            <span class="glyphicon glyphicon-th"></span>
                                                        </div>
                                                    </div>
                                                </div>
                                            </div>
                                        </div>
                                        
                                        <div class="col-md-2 col-6 text-center">
                                            <button type="submit" class="btn btn-primary waves-effect waves-light">Search</button>
                                        </div>
                                        <div class="col-md-2 col-6 text-center">
                                            <a class="btn btn-outline-warning waves-effect waves-light" href="{{ route('owner.cor.list') }}">Clear</a>
                                        </div>
                                    </div>
                                    </form>
                                </div>
                            </div>
                        </div>
                    </div>
                        <!-- filters end -->

                        <!-- DataTable starts -->
                        <div class="table-responsive">
                            <a id="delete_wash" class="btn btn-danger ag-grid-export-btn waves-effect waves-light delete_wash">Delete</a>
                            <?php $i = 1; ?>
                            @if (isset($records) && !empty($records) && count($records))
                                <table class="table" style="white-space: nowrap;">
                                    <thead>
                                        <tr>
                                            <th>Sl No.</th>
                                            <!-- <th>CWO Name</th> -->
                                            <th>Client Name</th>
                                            <!-- <th>Client Email </th> -->
                                            <th>Client Phone</th>
                                            <th>Car Reg. No.</th>
                                            <th>Car Make/Model</th>
                                            <th>Vehicle Color</th>
                                            <th>Body Type</th>
                                            <th>Car Wash Type</th>
                                            <th>Amount(R)</th>
                                            <th>Discount</th>
                                            <th>Cleaners</th>
                                            <th>Date Washed</th>
                                            <th>In-Queue Time</th>
                                            <th>In Wash Bay Time</th>
                                            <th>Finishing Bay Time</th>
                                            <th>Completed Time</th>
                                            <th>Time In Queue</th>
                                            <th>Time In Washbay</th>
                                            <th>Time In Finishing Bay</th>
                                            <th>Total Wash Time</th>
                                            <th>Total Time @Carwash</th>
                                            <th>Car Wash Status</th>
                                            <th>Payment Status</th>
                                            <th>Payment Type</th>
                                            <th>Free Wash</th>
                                            <th>Keys Collected</th>
                                            <th>Action</th>
                                        </tr>
                                    </thead>
                                    <tbody>
                                        @foreach ($records as $index => $singleData)
                                            <tr style="background-color:#ffffff;">
                                                <!-- <td>{{$index + $records->firstItem()}}</td> -->
                                                <td>
                                                    <!-- {{$singleData['wash_count']}} -->
                                                    <div class="vs-checkbox-con vs-checkbox-primary">
                                                        <input type="checkbox" class="delete_ids" value="{{$singleData['id']}}" name="delete_ids[]">
                                                        <span class="vs-checkbox">
                                                            <span class="vs-checkbox--check">
                                                                <i class="vs-icon feather icon-check"></i>
                                                            </span>
                                                        </span>
                                                        <span class="">{{$singleData['wash_count']}}</span>
                                                    </div>
                                                </td>
                                                <!-- <td>{{$singleData['cwo_company']}}</td> -->
                                                <td>
                                                    @if($singleData['driver_name'] !='')
                                                    {{$singleData['driver_name']}}
                                                    @else
                                                    {{$singleData['co_fname']}} {{$singleData['co_lname']}}
                                                    @endif
                                                </td>
                                                <!-- <td>
                                                      @if($singleData['driver_email'] != '')
                                                      ({{ $singleData['driver_email']}})
                                                      @else
                                                      ({{ $singleData['email']}})
                                                      @endif
                                                </td> -->
                                                <td>
                                                    @if($singleData['driver_phone'] != '')
                                                        +{{$singleData['driver_isd_code']}}{{$singleData['driver_phone']}}
                                                    @else
                                                        @if($singleData['co_phone'] != '')
                                                        +{{$singleData['isd_code']}}{{$singleData['co_phone']}}
                                                        @endif
                                                    @endif
                                                </td>
                                                <td>{{$singleData['car_registration_no']}}</td>
                                                <td>{{$singleData['make']}}</td>
                                                <td>{{$singleData['vehicle_color']}}</td>
                                                <td>{{$singleData['body_type']}}</td>
                                                <td>
                                                    {{ getWashTypes($singleData['id']) }}<br>
                                                    @if($singleData['wash_type_id'] > 0)
                                                    {{ getSingleWashTypeName($singleData['wash_type_id']) }}<br>
                                                    @endif
                                                    {{ getExtra($singleData['id']) }}
                                                </td>
                                                <td>
                                                    {{$singleData['symbol']}}{{$singleData['total_amount']}}
                                                </td>
                                                <td>
                                                    {{$singleData['discount']}}%
                                                </td>
                                                <td>
                                                    {{ getCleaners($singleData['id']) }}
                                                </td>
                                                <td>
                                                    @if($singleData['date_washed'] != '')
                                                    <!-- {{date("d-m-Y", strtotime($singleData['created_at']))}} -->
                                                    {{date("Y/m/d", strtotime($singleData['date_washed']))}}
                                                    @endif
                                                </td>
                                                <td>
                                                    @if($singleData['created_at'] != '')
                                                    {{date("H:i", strtotime($singleData['created_at']))}}
                                                    @endif
                                                </td>
                                                <td>
                                                    @if($singleData['wash_in'] != '')
                                                    {{date("H:i", strtotime($singleData['wash_in']))}}
                                                    @endif
                                                </td>
                                                <td>
                                                    @if($singleData['wash_out'] != '')
                                                    {{date("H:i", strtotime($singleData['wash_out']))}}
                                                    @endif
                                                </td>
                                                <td>
                                                    @if($singleData['time_washed'] != '')
                                                    {{date("H:i", strtotime($singleData['time_washed']))}}
                                                    @endif
                                                </td>
                                                <td>
                                                    @if($singleData['wash_in'] != '')
                                                    {{getDateDiffBay($singleData['created_at'], $singleData['wash_in'])}}
                                                    @else
                                                    @endif
                                                </td>
                                                <td>
                                                    @if($singleData['wash_in'] != '' && $singleData['wash_out'] != '')
                                                        {{getDateDiffBay($singleData['wash_in'], $singleData['wash_out'])}}
                                                        @else
                                                    @endif
                                                </td>
                                                <td>
                                                    @if($singleData['wash_out'] != '' && $singleData['time_washed'] != '')
                                                        {{getDateDiffBay($singleData['wash_out'], $singleData['updated_at'])}}
                                                        @else
                                                    @endif
                                                </td>
                                                <td>
                                                    @if($singleData['wash_in'] != '' && $singleData['time_washed'] != '')
                                                        {{getDateDiffBay($singleData['wash_in'], $singleData['updated_at'])}}
                                                        @else
                                                    @endif
                                                </td>
                                                <td>
                                                    @if($singleData['time_washed'] != '')
                                                        {{getDateDiffBay($singleData['created_at'], $singleData['updated_at'])}}
                                                        @else
                                                    @endif
                                                </td>
                                                <td>
                                                    @if($singleData['status'] == 0)
                                                        In Queue
                                                    @endif
                                                    @if($singleData['status'] == 1)
                                                        In Wash Bay
                                                    @endif
                                                    @if($singleData['status'] == 2)
                                                        Finishing Bay
                                                    @endif
                                                    @if($singleData['status'] == 3)
                                                        Completed
                                                    @endif
                                                    @if($singleData['status'] == 4)
                                                        Cancelled
                                                    @endif
                                                    @if($singleData['status'] == 5)
                                                        Keys Collected
                                                    @endif
                                                </td>
                                                <td>
                                                    @if($singleData['payment_status'] == 1)
                                                        Paid
                                                    @else
                                                        Not Paid
                                                    @endif
                                                </td>
                                                <td>{{$singleData['payment_details']}} </td>
                                                <td>
                                                    @if($singleData['is_free_wash'] == 1 ) 
                                                        Yes
                                                    @else
                                                        No     
                                                    @endif
                                                </td>
                                                <td>
                                                    @if($singleData['keys_collected'] != '')
                                                    {{date("Y-m-d H:i", strtotime($singleData['keys_collected']))}}
                                                    @endif
                                                </td>
                                                <td>
                                                    @if(Auth::user()->is_admin == 1)
                                                        <a title="Edit Car Wash" href="{{ route('owner.cor.edit', array('id' => $singleData['id'])) }}"><i class="feather icon-edit"></i></a>
                                                    @endif
                                                    <a href="{{ route('owner.cor.print', array('id' => $singleData['id'])) }}" target="_blank"><i class="feather icon-printer"></i></a>
                                                    @if(Auth::user()->is_admin == 1)
                                                        <a title="Delete Car Wash" onclick="return confirm('Are you sure, you want to delete this car wash record? Once deleted this record will not be recovered.');" href="{{ route('owner.cor.delete', array('id' => $singleData['id'])) }}" style="color: red;"><i class="feather icon-trash"></i></a>
                                                    @endif
                                                </td>
                                            </tr>
                                        @endforeach
                                    </tbody>
                                    <!-- <tfoot>
                                            <tr>
                                                <th>Sl No.</th>
                                                <th>CWO Name</th>
                                                <th>Client Name</th>
                                                <th>Client Email</th>
                                                <th>Client Phone</th>
                                                <th>Car Registration No.</th>
                                                <th>Body Type</th>
                                                <th>Car Wash Type</th>
                                                <th>Amount</th>
                                                <th>Date Washed</th>
                                                <th>Time Washed</th>
                                                <th>Car Wash Status</th>
                                                <th>Payment Status</th>
                                                <th>Payment Type</th>
                                            </tr>
                                        </tfoot> -->

                                </table>
                            @endif
                        </div>
                        <!-- DataTable ends -->

                        <div class="row">
                            <div class="col-12 col-sm-12">
                                <div class="float-right">
                                    <!-- @if (isset($records) && count($records))
    {{ $records->links('pagination::bootstrap-4') }}
    @endif -->
                                    @if (isset($records) && count($records))
                                        {{ $records->appends($_GET)->links('pagination::bootstrap-4') }}
                                    @endif
                                </div>
                            </div>
                        </div>


                    </section>

                </div>
            </div>
        </div>
    @section('page_scripts')
        <script src="{{ asset('app-assets/vendors/js/extensions/dropzone.min.js') }}"></script>
        <script src="{{ asset('app-assets/vendors/js/tables/datatable/pdfmake.min.js') }}"></script>
        <script src="{{ asset('app-assets/vendors/js/tables/datatable/vfs_fonts.js') }}"></script>
        <script src="{{ asset('app-assets/vendors/js/tables/datatable/datatables.min.js') }}"></script>
        <script src="{{ asset('app-assets/vendors/js/tables/datatable/datatables.buttons.min.js') }}"></script>
        {{-- <script src="{{ asset('app-assets/vendors/js/tables/datatable/buttons.html5.min.js')}}"></script> --}}
        <script src="{{ asset('app-assets/vendors/js/tables/datatable/buttons.print.min.js') }}"></script>
        <script src="{{ asset('app-assets/vendors/js/tables/datatable/buttons.bootstrap.min.js') }}"></script>
        <script src="{{ asset('app-assets/vendors/js/tables/datatable/datatables.bootstrap4.min.js') }}"></script>
        <script src="{{ asset('app-assets/vendors/js/tables/datatable/dataTables.select.min.js') }}"></script>
        <script src="{{ asset('app-assets/vendors/js/tables/datatable/datatables.checkboxes.min.js') }}"></script>
        <script src="{{ asset('app-assets/js/scripts/ui/data-list-view.js') }}"></script>
        <script src="{{ asset('app-assets/js/bootstrap-datepicker.min.js') }}"></script>
        <script type="text/javascript">
        document.getElementById('start_date').addEventListener('keypress', (e) => {
          e.preventDefault();
        });
        document.getElementById('end_date').addEventListener('keypress', (e) => {
          e.preventDefault();
        });

        $(document).on('click', '#delete_wash', function(){ 
            var checkedVals = $('.delete_ids:checkbox:checked').map(function() {
                return this.value;
            }).get();
            var delete_ids = checkedVals.join(",");
            // alert(delete_ids);
            if(delete_ids == '') {
                alert('Please select at least one wash');
            } else {
                // alert(delete_ids);
                let _url = "{{ route('owner.cor.multidelete') }}";
                let data = {
                    'delete_ids': delete_ids
                };
                $.ajax({
                    url: _url,
                    type: 'POST',
                    headers: {
                        'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                    },
                    data: data,
                    success: function(response) {
                        if (response.status == 1) {
                            // toastr.success(response.message, 'Deleted!');
                            alert(response.message, 'Deleted!');
                            window.location.reload();
                        } else {
                            toastr.error('Something went wrong.', 'Failed!');

                        }
                    }

                });
            }
        });
    </script>

    @endsection

</x-owner-layout>
