@extends('layouts.admin_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 Grant Applications
            </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>    

            <!-- With actions -->
            <h4
              class="mb-4 text-lg font-semibold text-gray-600 dark:text-gray-300"
            >
              Grant Applications ({{ count($grants) }})
            </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">Grant Status</th>
                      <th class="px-4 py-3">Application Date</th>
                      <th class="px-4 py-3">Actions</th>
                    </tr>
                  </thead>
                  <tbody
                    class="bg-white divide-y dark:divide-gray-700 dark:bg-gray-800"
                  >
                  @forelse($grants as $grant)
                    <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"
                              src="{{ asset('images/toy-avatar.png') }}"
                              alt=""
                              loading="lazy"
                            />
                            <div
                              class="absolute inset-0 rounded-full shadow-inner"
                              aria-hidden="true"
                            ></div>
                          </div>
                          <div><a href="{{ route('admin.grant-details', $grant->id) }}">
                            <p class="font-semibold">{{ $grant->user?->first_name . ' ' . $grant->user?->last_name }}</p>
                            <p class="text-xs text-gray-600 dark:text-gray-400">
                              {{ $grant->user?->email }} - [{{ $grant->user?->username }}]
                            </p>
                           </a>
                          </div>
                        </div>
                      </td>
                      <td class="px-4 py-3 text-xs">
                        @if($grant->status == 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"
                        >
                            Seen
                        </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"
                        >
                            Pending
                        </span>
                        @endif
                      </td>
                      <td class="px-4 py-3 text-sm">
                        {{ date('M j Y', strtotime($grant->created_at)) }}
                      </td>
                      <td class="px-4 py-3">
                        <div class="flex items-center space-x-4 text-sm">
                          <a
                            class="flex items-center justify-between px-2 py-2 text-sm font-medium leading-5 text-green-600 rounded-lg dark:text-gray-400 focus:outline-none focus:shadow-outline-gray"
                            aria-label="Edit" href="{{ route('admin.grant-details', $grant->id) }}"
                          >
                        <svg class="w-5 h-5"  fill="none" 
                            viewBox="0 0 24 24" stroke="currentColor">
                            <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15 12a3 3 0 11-6 0 3 3 0 016 0z"/>
                            <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M2.458 12C3.732 7.943 7.523 5 12 5c4.478 0 8.268 2.943 9.542 7-1.274 4.057-5.064 7-9.542 7-4.477 0-8.268-2.943-9.542-7z"/>
                        </svg>
                          </a>
                        </div>
                      </td>
                    </tr>
                    @empty
                  <div class="mx-auto my-3">
                        <p class="text-center text-white lead">No Grant Applications!!</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($grants->currentPage() != 1)
                <span><a class="p-3 mb-3" href="{{ $grants->url(1) }}">«&nbsp;</a></span>
                <span><a class="p-3 mt-4" href="{{ $grants->previousPageUrl() }}"><&nbsp;</a></span>
                  @for($i=1; $i<=$grants->lastPage(); $i++) 
                    @if($i== $grants->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="{{ $grants->url($i) }}">{{ $i }}&nbsp;</a></span>
                     @endif
                  @endfor
                  @if($grants->currentPage() != $grants->lastPage())
                <span><a class="p-3 mt-4" href="{{ $grants->nextPageUrl() }}">>&nbsp;</a></span>
                <span><a class="p-3 mt-4" href="{{ $grants->url($grants->lastPage()) }}">»</a></span>
               @endif
               @else
               <span><a class="p-3 mb-3" href="{{ $grants->url(1) }}">1</a></span>
               <span><a class="p-3 mt-4" href="{{ $grants->nextPageUrl() }}">>&nbsp;</a></span>
               <span><a class="p-3 mt-4" href="{{ $grants->url($grants->lastPage()) }}">»</a></span>
               @endif
               
              </div>
              <div>
                  <small class="text-gray-500 dark:text-gray-400">Showing {{ $grants->firstItem() }}–{{ $grants->lastItem() }} of {{ $grants->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