@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"
            >Products
            </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 -->
            <div class="mb-4">
                <a href="{{ route('admin.create-product') }}" class="block max-w-xs p-6 mx-auto space-y-3 bg-blue-600 shadow-lg group bg-whitering-1 ring-gray-900/5 hover:bg-sky-500 hover:ring-sky-500">
                    <div class="flex items-center space-x-3">
                    <svg xmlns="http://www.w3.org/2000/svg" class="w-5 h-5 text-white dark:text-gray-300" viewBox="0 0 20 20" fill="currentColor">
                    <path fill-rule="evenodd" d="M10 3a1 1 0 011 1v5h5a1 1 0 110 2h-5v5a1 1 0 11-2 0v-5H4a1 1 0 110-2h5V4a1 1 0 011-1z" clip-rule="evenodd" />
                    </svg>
                    <h3 class="font-semibold text-white dark:text-gray-300">New Product</h3>
                </div>
                <small class="text-gray-900">Create a new Product.</small>
                </a>
            </div>

          <div class="flex items-center mb-4">
            <div class="block w-full mr-4">
              <form method="get" action="{{ route('admin.products') }}">
                @csrf
                <small class="text-gray-700 dark:text-gray-200">Search Product Name</small>
                <div class="flex items-center">              
                <input type="text" name="name" 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>  

            <form method="get" class="w-full" action="{{ route('admin.products') }}">
                <div class="flex items-center mb-4">
                  @csrf
                  <div class="mr-3">
                      <small class="text-gray-700 dark:text-gray-200">Min Price</small>
                      <div class="flex items-center">              
                      <input type="number" name="min" step="any" 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">  
                    </div>
                  </div>

                  <div class="">
                      <small class="text-gray-700 dark:text-gray-200">Max Price</small>
                        <div class="flex items-center">              
                        <input type="number" name="max" step="any" 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">  
                      </div>
                  </div>  
              <button type="submit" class="d-none"></button>
            </form>
          </div>


            <h4
              class="flex mb-4 text-lg font-semibold text-gray-600 dark:text-gray-300"
            >
              All Available Products <svg xmlns="http://www.w3.org/2000/svg" class="w-5 h-5 mt-1 ml-2 mr-3" viewBox="0 0 20 20" fill="currentColor">
                <path fill-rule="evenodd" d="M10 2a4 4 0 00-4 4v1H5a1 1 0 00-.994.89l-1 9A1 1 0 004 18h12a1 1 0 
                00.994-1.11l-1-9A1 1 0 0015 7h-1V6a4 4 0 00-4-4zm2 5V6a2 2 0 10-4 0v1h4zm-6 3a1 1 0 112 0 1 1 0 01-2 
                0zm7-1a1 1 0 100 2 1 1 0 000-2z" clip-rule="evenodd" />
              </svg>
              Total ({{ $products->total() }})
            </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">Product Name</th>
                      <th class="px-4 py-3">Stock Status</th>
                      <th class="px-4 py-3">Rating</th>
                      <th class="px-4 py-3">Produt Value</th>
                      <th class="px-4 py-3">Market</th>
                      <th class="px-4 py-3">Sell Margin</th>
                      <th class="px-4 py-3">Bid Margin</th>
                      <th class="px-6 py-3 ml-16">Actions</th>
                    </tr>
                  </thead>
                  <tbody
                    class="bg-white divide-y dark:divide-gray-700 dark:bg-gray-800"
                  >
                  @forelse($products as $product)
                    <tr class="text-gray-700 dark:text-gray-400">
                      <td class="px-4 py-3">
                        <div class="flex items-center text-sm">
                          <img class="mr-3" src="{{ asset('storage/products/'.$product->image1) }}" style="height: 40px;"/>
                          <div>
                            <p class="font-semibold" title="{{ $product->name }}">{{ mb_strimwidth($product->name, 0, 40, '...') }}</p>                      
                          </div>
                        </div>
                      </td>
                      <td class="px-4 py-3 text-sm">
                      {{ $product->status == 1 ? 'In Stock' : 'Out OF Stock' }}
                      </td>
                      <td class="px-4 py-3 text-sm">
                      {{ number_format($product->rating, 1) }}
                      </td>
                      <td class="px-4 py-3 text-sm">
                            ${{ number_format($product->value, 2) }}
                      </td>
                      <td class="px-4 py-3 text-sm">
                        {{ ucfirst($product->market?->name) }}
                      </td>
                      <td class="px-4 py-3 text-sm">
                        {{ ucfirst($product->market?->sell_margin) }}
                      </td>
                      <td class="px-4 py-3 text-sm">
                        {{ ucfirst($product->market?->bid_margin) }}
                      </td>
                      <td class="px-4 py-3">
                        <div class="flex items-center space-x-6 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.edit-product', $product->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>
                          <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.create-bid', $product->id) }}"
                          >
                            <svg class="w-5 h-5"  width="24" height="24" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" 
                              fill="none" stroke-linecap="round" stroke-linejoin="round">  <path stroke="none" d="M0 0h24v24H0z"/>  
                              <circle cx="9" cy="19" r="2" />  <circle cx="17" cy="19" r="2" />  
                              <path d="M3 3h2l2 12a3 3 0 0 0 3 2h7a3 3 0 0 0 3 -2l1 -7h-15.2" />
                            </svg>
                          </a>
                          <form method="post" id="{{'form-delete-'.$product->id}}" action="{{route('admin.product-destroy', $product->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 the {{ $product->name }} product?');"
                          >
                            <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 text-white lead">No Created Products.</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($products->currentPage() != 1)
                <span><a class="p-3 mb-3" href="{{ $products->url(1) }}">«&nbsp;</a></span>
                <span><a class="p-3 mt-4" href="{{ $products->previousPageUrl() }}"><&nbsp;</a></span>
                  @for($i=1; $i<=$products->lastPage(); $i++) 
                    @if($i== $products->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="{{ $products->url($i) }}">{{ $i }}&nbsp;</a></span>
                     @endif
                  @endfor
                  @if($products->currentPage() != $products->lastPage())
                <span><a class="p-3 mt-4" href="{{ $products->nextPageUrl() }}">>&nbsp;</a></span>
                <span><a class="p-3 mt-4" href="{{ $products->url($products->lastPage()) }}">»</a></span>
               @endif
               @else
               <span><a class="p-3 mb-3" href="{{ $products->url(1) }}">1</a></span>
               <span><a class="p-3 mt-4" href="{{ $products->nextPageUrl() }}">>&nbsp;</a></span>
               <span><a class="p-3 mt-4" href="{{ $products->url($products->lastPage()) }}">»</a></span>
               @endif
               
              </div>
              <div>
                  <small class="text-gray-500 dark:text-gray-400">Showing {{ $products->firstItem() }}–{{ $products->lastItem() }} of {{ $products->total() }} results</small>
              </div>
            </div>
            </div>
          </div>
        </main>





@endsection