@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"
            >
              Mailing System
            </h2>
            <hr class="mb-6">
             <!-- CTA -->
             
             
             
             <!-- Form -->
             <!-- General elements -->
            <h4
              class="mb-4 flex text-lg font-semibold text-gray-600 dark:text-gray-300"
            >
              Email Content <svg xmlns="http://www.w3.org/2000/svg" class="h-6 w-6" fill="none" viewBox="0 0 24 24" stroke="currentColor">
                  <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M3 8l7.89 5.26a2 2 0 002.22 0L21 8M5 19h14a2 2 0 002-2V7a2 2 0 00-2-2H5a2 2 0 00-2 2v10a2 2 0 002 2z" />
                </svg>
            </h4>
            <div
              class="px-4 py-3 mb-8 bg-white rounded-lg shadow-md dark:bg-gray-800"
            >
            <x-alert/>
            <form method="post" action="{{ route('admin.mailing') }}" class="mt-4" enctype="multipart/form-data">
            @csrf


            <div class="flex items-center mb-4">
              <label class="block w-full mr-3 text-sm mb-5">
                <span class="text-gray-700 dark:text-gray-400 font-semibold">Mail Subject</span>
                <input
                  class="
                  block w-full mt-1 text-sm dark:border-gray-600 dark:bg-gray-700 focus:border-green-400 
                  focus:outline-none focus:shadow-outline-green dark:text-gray-300 dark:focus:shadow-outline-gray 
                  form-input"
                   name="subject" type="text"
                />
              </label>

              
              <label class="block w-full text-sm mb-5">
                <span class="text-gray-700 dark:text-gray-400 font-semibold">Scope (will appear here by itself based on filter)</span>
                <input
                  class=" 
                  block w-full mt-1 text-sm dark:border-gray-600 dark:bg-gray-700 focus:border-green-400 focus:outline-none 
                  focus:shadow-outline-green dark:text-gray-300 dark:focus:shadow-outline-gray form-input"
                   name="scope" disabled value="{{ $title }}" 
                />
              </label>
            </div>
            
            @foreach($users as $user)
            <input type="hidden" name="users[]" value="{{ $user->email }}"/>
            @endforeach

            <div class="md:flex items-center mb-4">
            <label class="block w-full mt-4 text-sm">
                <span class="text-gray-700 dark:text-gray-400 font-semibold">Message</span>
                <textarea
                  class="
                  block w-full mt-1 text-sm dark:text-gray-300 dark:border-gray-600 dark:bg-gray-700 form-textarea 
                  focus:border-green-400 focus:outline-none focus:shadow-outline-green dark:focus:shadow-outline-gray"
                  rows="4" name="message"
                ></textarea>
              </label>
            </div>



              <div class="mx-auto">
              <button
                  class="flex items-center px-5 py-3 font-medium leading-5 text-white transition-colors duration-150 border border-transparent rounded-lg active:bg-green-500 hover:bg-green-700 focus:outline-none focus:shadow-outline-green"
                  type="submit" style="background-color: #e4ab0d; color: #fff;"
                >
                  Send <svg xmlns="http://www.w3.org/2000/svg" class="ml-4 h-5 w-5" viewBox="0 0 20 20" fill="currentColor">
                      <path fill-rule="evenodd" d="M10 18a8 8 0 100-16 8 8 0 000 16zm3.707-9.293a1 1 0 00-1.414-1.414L9 10.586 7.707 9.293a1 1 0 00-1.414 1.414l2 2a1 1 0 001.414 0l4-4z" clip-rule="evenodd" />
                    </svg>
                </button>
              </div>
            </form>

        </div>
             <!-- Form end -->
             
             



                <!-- Filter input -->
                <div class="flex items-center mb-4">
              <div class="block w-full mr-4">
              <form id="filter-form" method="get" action="{{ route('admin.mails.show') }}">
                @csrf
                <small class="text-gray-700 dark:text-gray-200">Sort Users</small>
                <div class="flex items-center">              
                <select
                  name="user" 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"
                  onchange="this.form.submit();">                
                    @if($users == null || $title == 'All')
                    <option class="active">All</option>
                    <option>Investors</option>
                    <option>Non-Investors</option>
                    @else
                    <option class="active">{{ $title }}</option>
                    <option>All</option>
                    <option>Investors</option>
                    <option>Non-Investors</option>
                    @endif
                </select>
                 </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.users.show') }}">
              <input type="hidden" name="all"/>
              <button class="font-semi-bold text-green-600 dark:text-green-400 text-sm cursor-pointer" href="#">
                &LeftArrow;  Back to All 
              </button>
            </form>
            @else
              List of Registered Users
            @endif
            </h4>
            <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">Customer</th>
                      <th class="px-4 py-3">Available Earnings</th>
                      <th class="px-4 py-3">User Status</th>
                      <th class="px-4 py-3">Registration 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($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 hidden w-8 h-8 mr-3 rounded-full md:block"
                          >
                            <img
                              class="object-cover w-full h-full rounded-full"
                              src="{{ asset('public/assets/img/user_avatar.png') }}"
                              alt=""
                              loading="lazy"
                            />
                            <div
                              class="absolute inset-0 rounded-full shadow-inner"
                              aria-hidden="true"
                            ></div>
                          </div>
                          <div><a href="{{ route('admin.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 }}
                            </p>
                           </a>
                          </div>
                        </div>
                      </td>
                      <td class="px-4 py-3 text-sm">
                        &#8358;{{ number_format($user->balance) }}
                      </td>
                      <td class="px-4 py-3 text-xs">
                      @if($user->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"
                        >
                          
                            Active
                          
                        </span>
                        @elseif($user->status == 0)
                        <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"
                        >
                            Banned
                        </span>
                       @endif
                      </td>
                      <td class="px-4 py-3 text-sm">
                        {{ date('M j Y', strtotime($user->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.user.edit', $user->id) }}"
                          >
                            <svg
                              class="w-5 h-5"
                              aria-hidden="true"
                              fill="currentColor"
                              viewBox="0 0 20 20"
                            >
                              <path
                                d="M13.586 3.586a2 2 0 112.828 2.828l-.793.793-2.828-2.828.793-.793zM11.379 5.793L3 14.172V17h2.828l8.38-8.379-2.83-2.828z"
                              ></path>
                            </svg>
                          </a>


                          @if($user->status == 1)
                          <form action="{{ route('admin.ban', $user->id) }}" method="post">
                           @csrf
                          <button
                            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="Ban"
                          >
                            Ban
                          </button>
                         </form>
                          @elseif($user->status == 0)
                          <form action="{{ route('admin.unban', $user->id) }}" method="post">
                           @csrf
                          <button
                            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="Ban"
                          >
                            UnBan
                          </button>
                          </form>
                          @endif

                          <form method="post" id="{{'form-delete-'.$user->id}}" action="{{route('admin.user.destroy', $user->id)}}" >
                            @csrf
                            @method('delete')
                          <button 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"
                           type="submit" onclick="return confirm('Dear Admin, Are you sure you want to delete {{ $user->first_name }}?');"
                          >
                            <svg
                              class="w-5 h-5"
                              aria-hidden="true"
                              fill="currentColor"
                              viewBox="0 0 20 20"
                            >
                              <path
                                fill-rule="evenodd"
                                d="M9 2a1 1 0 00-.894.553L7.382 4H4a1 1 0 000 2v10a2 2 0 002 2h8a2 2 0 002-2V6a1 1 0 100-2h-3.382l-.724-1.447A1 1 0 0011 2H9zM7 8a1 1 0 012 0v6a1 1 0 11-2 0V8zm5-1a1 1 0 00-1 1v6a1 1 0 102 0V8a1 1 0 00-1-1z"
                                clip-rule="evenodd"
                              ></path>
                            </svg>
                          </button>
                        </form>
                        </div>
                      </td>
                    </tr>
                    @empty
                  <div class="mx-auto my-3">
                        <p class="text-center lead text-white">No Registered Users!!</p>
                  </div>
                  <br><br><br>
                  @endforelse
                  
                  </tbody>
                </table>
              </div>
           
          </div>
        </main>








   
                




@endsection