@extends('layouts.master')

@section('title') @lang('translation.Customers') @endsection

@section('css')
    <!-- DataTables -->
    <link href="{{ URL::asset('/assets/libs/datatables/datatables.min.css') }}" rel="stylesheet" type="text/css" />
@endsection
@section('content')

    @component('components.breadcrumb')
        @slot('li_1') Ecommerce @endslot
        @slot('title') Customers @endslot
    @endcomponent

    <div class="row">
        <div class="col-12">
            <div class="card">
                <div class="card-body">
                    <div class="row mb-2">
                        <div class="col-sm-4">
                            <div class="search-box me-2 mb-2 d-inline-block">
                            </div>
                        </div>
                        <div class="col-sm-8">
                            <div class="text-sm-end">
                                @if(Route::current()->getName() == 'admin.customers')
                                <a href="{{ route('add_customer_form')}}" class="btn btn-success btn-rounded waves-effect waves-light mb-2 me-2"><i class="mdi mdi-plus me-1"></i> New Customers</a>
                                @elseif(Route::current()->getName() == 'admin.angels')
                                <a href="{{ route('add_customer_form')}}" class="btn btn-success btn-rounded waves-effect waves-light mb-2 me-2"><i class="mdi mdi-plus me-1"></i> New Angels</a>
                                @endif
                            </div>
                        </div><!-- end col-->
                    </div>

                    <?php $i = 0 ?>
                    <div class="table-responsive">
                        <table id="datatable-buttons" class="table align-middle table-nowrap">
                            <thead>
                                <tr>
                                    <th>#</th>
                                    <th>Username</th>
                                    <th> Email</th>
                                    <th> Phone Number</th>
                                    <th>Wallet Balance</th>
                                    <th>Status</th>
                                    <th>Action</th>
                                </tr>
                            </thead>
                            <tbody>
                            @if($users)
                                @foreach ($users as $user)
                                    <tr>
                                        <td>{{ ++$i }}</td>
                                        <td>{{ $user->name }}</td>
                                        <td>{{ $user->email }}</td>
                                        <td>{{ $user->UserData ? $user->UserData->phone_number : ''}}</td>
                                        <td>{{ $user->UserData ? $user->UserData->wallet_amount : ''}}</td>
                                        <td>{{ $user->status }}</td>
                                        <td>
                                            <div class="dropdown">
                                                <a href="#" class="dropdown-toggle card-drop" data-bs-toggle="dropdown"
                                                    aria-expanded="false">
                                                    <i class="mdi mdi-dots-horizontal font-size-18"></i>
                                                </a>
                                                <ul class="dropdown-menu dropdown-menu-end">
                                                    <li><a href="{{ route('edit_customer', ['id' => $user->id]) }}" class="dropdown-item"><i
                                                                class="mdi mdi-pencil font-size-16 text-success me-1"></i>
                                                            Edit</a></li>
                                                    <li><a href="{{ route('user.destroy', ['user' => $user->id] ) }}" class="dropdown-item"><i
                                                                class="mdi mdi-trash-can font-size-16 text-danger me-1"></i>
                                                            Delete</a></li>
                                                    <li><a href="{{ route('user.show', ['user' => $user->id]) }}" class="dropdown-item"><i
                                                                class="mdi mdi-eye font-size-16 text-danger me-1"></i>
                                                            View</a></li>
                                                </ul>
                                            </div>
                                        </td>
                                    </tr>
                                @endforeach
                            @endif
                            </tbody>
                        </table>
                    </div>
                    
                </div>
            </div>
        </div>
    </div>
    <!-- end row -->
@endsection
@section('script')
    <!-- Required datatable js -->
    <script src="{{ URL::asset('/assets/libs/datatables/datatables.min.js') }}"></script>
    <script src="{{ URL::asset('/assets/libs/jszip/jszip.min.js') }}"></script>
    <script src="{{ URL::asset('/assets/libs/pdfmake/pdfmake.min.js') }}"></script>
    <!-- Datatable init js -->
    <script src="{{ URL::asset('/assets/js/pages/datatables.init.js') }}"></script>
@endsection
