@extends('layouts.agent_layout')

@section('content')



<main class="h-full pb-16 overflow-y-auto">
          <div class="container grid px-6 mx-auto">
            <h2
              class="my-6 text-2xl font-semibold text-gray-700 dark:text-gray-200"
            >
            <span class="text-blue-500">List</span> of all Users
            </h2>
             <!-- CTA -->
             <a
              class="flex items-center justify-between p-4 mb-8 text-sm font-semibold bg-blue-600 shadow-md focus:outline-none focus:shadow-outline-green"
              href="{{ url('/') }}" style="color: #fff;"
            >
              <div class="flex items-center">
                <svg
                  class="w-5 h-5 mr-2"
                  fill="currentColor"
                  viewBox="0 0 20 20"
                >
                  <path
                    d="M9.049 2.927c.3-.921 1.603-.921 1.902 0l1.07 3.292a1 1 0 00.95.69h3.462c.969 0 1.371 1.24.588 1.81l-2.8 2.034a1 1 0 00-.364 1.118l1.07 3.292c.3.921-.755 1.688-1.54 1.118l-2.8-2.034a1 1 0 00-1.175 0l-2.8 2.034c-.784.57-1.838-.197-1.539-1.118l1.07-3.292a1 1 0 00-.364-1.118L2.98 8.72c-.783-.57-.38-1.81.588-1.81h3.461a1 1 0 00.951-.69l1.07-3.292z"
                  ></path>
                </svg>
                <span>Go to main website</span>
              </div>
              <span>View &RightArrow;</span>
            </a>



                <!-- Filter input -->
          <div class="flex items-center mb-4">
            <div class="block w-full mr-4">
              <form method="get" action="{{ route('admin.agent.users') }}">
                @csrf
                <small class="text-gray-700 dark:text-gray-200">Sort By Store Name</small>
                <div class="flex items-center">              
                <input type="text" name="username" class="block w-full mt-1 text-sm dark:text-gray-300 dark:border-gray-600 dark:bg-gray-700 form-select focus:border-green-400 focus:outline-none focus:shadow-outline-green dark:focus:shadow-outline-gray">  

                <button type="submit" class="d-none"></button>
                 </form>
               </div>
              </div>

              
              <div class="block w-full mr-4">
              <form method="get" action="{{ route('admin.agent.users') }}">
                @csrf
                <small class="text-gray-700 dark:text-gray-200">Sort By Email</small>
                <div class="flex items-center">              
                <input type="text" name="email" class="block w-full mt-1 text-sm dark:text-gray-300 dark:border-gray-600 dark:bg-gray-700 form-select focus:border-green-400 focus:outline-none focus:shadow-outline-green dark:focus:shadow-outline-gray">  

                <button type="submit" class="d-none"></button>
                 </form>
               </div>
              </div>
            </div>

            

            <!-- With actions -->
            <h4
              class="mb-4 text-lg font-semibold text-gray-600 dark:text-gray-300"
            >
            @if(!empty($title))
            {{ $title }}<br>
            <form method="get" action="{{ route('admin.agent.users') }}">
              <input type="hidden" name="all"/>
              <button class="text-sm text-green-600 cursor-pointer font-semi-bold dark:text-green-400" href="#">
                &LeftArrow;  Back to All 
              </button>
            </form>
            @else
              List of Registered Users
            @endif
            </h4>
            <x-alert/><br>
            <div class="w-full overflow-hidden rounded-lg shadow-xs">
              <div class="w-full overflow-x-auto">
                <table class="w-full whitespace-no-wrap">
                  <thead>
                    <tr
                      class="text-xs font-semibold tracking-wide text-left text-gray-500 uppercase border-b dark:border-gray-700 bg-gray-50 dark:text-gray-400 dark:bg-gray-800"
                    >
                      <th class="px-4 py-3">User</th>
                      <th class="px-4 py-3">Available Balance</th>
                      <th class="px-4 py-3">User Status</th>
                      <th class="px-4 py-3">Registration Date</th>
                    </tr>
                  </thead>
                  <tbody
                    class="bg-white divide-y dark:divide-gray-700 dark:bg-gray-800"
                  >
                  @forelse($users as $user)
                    <tr class="text-gray-700 dark:text-gray-400">
                      <td class="px-4 py-3">
                        <div class="flex items-center text-sm">
                          <!-- Avatar with inset shadow -->
                          <div
                            class="relative w-8 h-8 mr-3 rounded-full md:block"
                          >
                            <img
                              class="object-cover w-full h-full rounded-full"
                              @if($user->avatar == null)
                              src="{{ asset('images/toy-avatar.png') }}"
                              @else
                              src="{{ asset('storage/images/'.$user->avatar) }}"
                              @endif
                              alt=""
                              loading="lazy"
                            />
                            <div
                              class="absolute inset-0 rounded-full shadow-inner"
                              aria-hidden="true"
                            ></div>
                          </div>
                          <div><a href="{{ route('admin.agent.user_info', $user->id) }}">
                            <p class="font-semibold">{{ $user->first_name . ' ' . $user->last_name }}</p>
                            <p class="text-xs text-gray-600 dark:text-gray-400">
                              {{ $user->email }} - [{{ $user->username }}]
                            </p>
                           </a>
                          </div>
                        </div>
                      </td>
                      <td class="px-4 py-3 text-sm">
                        USDT {{ number_format($user->balance, 2) }}
                      </td>
                      <td class="px-4 py-3 text-xs">
                      @if($user->activated == 1)
                        <span
                          class="px-2 py-1 font-semibold leading-tight text-green-700 bg-green-100 rounded-full dark:bg-green-700 dark:text-green-100"
                        >
                          
                            Active
                          
                        </span>
                        @else
                        <span
                          class="px-2 py-1 font-semibold leading-tight text-red-700 bg-red-100 rounded-full dark:bg-red-700 dark:text-red-100"
                        >
                            In-Active
                        </span>
                       @endif
                      </td>
                      <td class="px-4 py-3 text-sm">
                        {{ date('M j Y', strtotime($user->created_at)) }}
                      </td>
                    </tr>
                    @empty
                  <div class="mx-auto my-3">
                        <p class="text-center text-white lead">No Registered Users!!</p>
                  </div>
                  <br><br><br>
                  @endforelse
                  
                  </tbody>
                </table>
              </div>
              <div
                class="px-4 py-3 text-xs font-semibold text-gray-500 uppercase dark:border-gray-700 bg-gray-50 dark:text-gray-400 dark:bg-gray-800" style="padding-top:50px !important;padding-bottom:20px !important;"
              >
                  
              @if($users->currentPage() != 1)
                <span><a class="p-3 mb-3" href="{{ $users->url(1) }}">«&nbsp;</a></span>
                <span><a class="p-3 mt-4" href="{{ $users->previousPageUrl() }}"><&nbsp;</a></span>
                  @for($i=1; $i<=$users->lastPage(); $i++) 
                    @if($i== $users->currentPage()) 
                        <span><a class="p-1 mt-4 text-center pranala" style="background-color: #e4ab0d; color: #fff;border-radius:50%;"><b>{{ $i }}</b>&nbsp;</a></span>
                     @else
                        <span class="mt-12"><a class="p-3" href="{{ $users->url($i) }}">{{ $i }}&nbsp;</a></span>
                     @endif
                  @endfor
                  @if($users->currentPage() != $users->lastPage())
                <span><a class="p-3 mt-4" href="{{ $users->nextPageUrl() }}">>&nbsp;</a></span>
                <span><a class="p-3 mt-4" href="{{ $users->url($users->lastPage()) }}">»</a></span>
               @endif
               @else
               <span><a class="p-3 mb-3" href="{{ $users->url(1) }}">1</a></span>
               <span><a class="p-3 mt-4" href="{{ $users->nextPageUrl() }}">>&nbsp;</a></span>
               <span><a class="p-3 mt-4" href="{{ $users->url($users->lastPage()) }}">»</a></span>
               @endif
               
              </div>
              <div>
                  <small class="text-gray-500 dark:text-gray-400">Showing {{ $users->firstItem() }}–{{ $users->lastItem() }} of {{ $users->total() }} results</small>
              </div>
            </div>
          </div>
        </main>







       <script>

              // If admin clicks on the ban btn, call the ban function 
              $(document).on('click', '#banned', function() {
                  
                  // Get the user id
                  var user_id = $('#banned').data('user_id');
                  //let user_name = $('.ban').data('user_name');
                  console.log(user_id);
                  // Call the ban function
                  //ban(user_id, user_name);
              });

        
            </script>


@endsection