@extends('layouts.admin_layout')

@section('content')



<main class="h-full pb-16 overflow-y-auto">
        <div class="container grid px-6 mx-auto">
        <br><br>
        <h2
            class="flex my-6 text-2xl font-semibold text-gray-700 dark:text-gray-200"
        >
             <a href="{{ route('admin.products') }}">
                <svg xmlns="http://www.w3.org/2000/svg" class="w-6 h-6" fill="none" viewBox="0 0 24 24" stroke="currentColor">
                   <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15 19l-7-7 7-7" />
                </svg>
             </a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Edit Product
            </h2>
            <!-- CTA -->
            <a
              class="flex items-center justify-between p-4 mb-8 text-sm font-semibold bg-blue-600 rounded-lg shadow-md focus:outline-none focus:shadow-outline-green"
              href="{{ route('admin.products') }}" 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 website</span>
              </div>
              <span>View &RightArrow;</span>
            </a>

            <!-- General elements -->
            <h4
              class="mb-4 text-lg font-semibold text-gray-600 dark:text-gray-300"
            >
             Edit Product
            </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.update-product', $product->id) }}" class="mt-4" enctype="multipart/form-data">
            @csrf

            <div class="flex items-center mb-4">
              <label class="block w-full mb-5 mr-3 text-sm">
                <span class="font-semibold text-gray-700 dark:text-gray-400">Product Name</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="name" required type="text"
                value="{{ $product->name }}"/>
              </label>

            <label class="block w-full mb-5 text-sm">
                <span class="font-semibold text-gray-700 dark:text-gray-400">Market</span>
                <select
                  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="market_id" required
                >
                    <option value="{{ $product->market?->id }}">{{ ucfirst($product->market?->name.' '.'('.$product->market?->type.')') }}</option>
                @foreach($markets as $market)
                    <option value="{{ $market?->id }}">{{ ucfirst($market?->name.' '.'('.$market?->type.')') }}</option>
                @endforeach
                </select>
              </label>
            </div>

            <div class="flex items-center mb-4">
              <label class="block w-full mb-5 mr-3 text-sm">
                <span class="font-semibold text-gray-700 dark:text-gray-400">Status</span>
                <select
                  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="status" required
                >
                    <option value="{{ $product->status }}">{{ $product->status == 1 ? 'In Stock' : 'Out OF Stock' }}</option>
                    <option value="1">In Stock</option>
                    <option value="2">Out OF Stock</option>
                </select>
              </label>

              <label class="block w-full mb-5 text-sm">
                <span class="font-semibold text-gray-700 dark:text-gray-400">Category</span>
                <select
                  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="category" required
                >
                    <option value="{{ $product->category }}">{{ $product->category }}</option>
                    <option value="Beauty & personal care">Beauty & personal care</option>
                    <option value="Accessories">Accessories</option>
                    <option value="Home appliances and utensils">Home appliances and utensils</option>
                    <option value="Sports and outdoor">Sports and outdoor</option>
                    <option value="Toys and games">Toys and games</option>
                    <option value="Groceries">Groceries</option>
                    <option value="Gadgets and electronics">Gadgets and electronics</option>
                    <option value="Video games">Video games</option>
                    <option value="Lawn and garden">Lawn and garden</option>
                    <option value="Automotive kits">Automotive kits</option>
                    <option value="Books">Books</option>
                    <option value="Jewelry">Jewelry</option>
                    <option value="Babies">Babies</option>
                    <option value="General furnitures">General furnitures</option>
                    <option value="Instruments">Instruments</option>
                    <option value="Industrial">Industrial</option>
                </select>
              </label>
            </div>

            <div class="flex items-center mb-4">
              <label class="block w-full mb-5 text-sm">
                <span class="font-semibold text-gray-700 dark:text-gray-400">Rating</span>
                <select
                  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="rating" step="any"
                >
                    <option value="{{ $product->rating }}">{{ number_format($product->rating, 1) }} star</option>
                    <option value="1">1.0 star</option>
                    <option value="1.5">1.5 stars</option>
                    <option value="2">2.0 stars</option>
                    <option value="2.5">2.5 stars</option>
                    <option value="3">3.0 stars</option>
                    <option value="3.5">3.5 stars</option>
                    <option value="4">4.0 stars</option>
                    <option value="4.5">4.5 stars</option>
                    <option value="5">5.0 stars</option>
                </select>
              </label>
            </div>

            <div class="flex items-center mb-4">
              <label class="block w-full mb-5 mr-3 text-sm">
                <span class="font-semibold text-gray-700 dark:text-gray-400">Value ($)</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="value" type="number" step=".01"
                  value="{{ $product->value }}"/>
              </label>
              
              <label class="block w-full mb-5 mr-3 text-sm">
                <span class="font-semibold text-gray-700 dark:text-gray-400">Old Value ($)</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="old_value" type="number" step=".01"
                  value="{{ $product->old_value }}"/>
              </label>
            </div>


            <div class="flex items-center mb-4">
              <label class="block w-full mb-5 mr-3 text-sm">
                <span class="font-semibold text-gray-700 dark:text-gray-400">Product Description</span>
                <textarea
                  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="description"
                >{{ $product->description }}</textarea>
              </label>
            </div>
            
            
            <div class="flex items-center mb-4">
              <label class="block w-full mb-5 text-sm">
              <span class="font-semibold text-gray-700 dark:text-gray-400">Product Image 1</span>
              <small class="text-gray-700 dark:text-gray-400">This will be the image that will display on image cards</small>
                @if($product->image1 != null)
                    <img src="{{ asset('storage/products/'.$product->image1) }}" style="height: 60px;"/>
                @else
                    <p class="font-bold text-gray-700 dark:text-gray-400">No Image</p>
                @endif
              <input type="file" class="@error('image1') focus:border-red-400 focus:outline-none focus:shadow-outline-red @enderror 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" 
               id="image1" name="image1">
              @error('image1')
              <span class="text-xs text-red-600 dark:text-red-400">
                  {{ $message }}
                </span>
              @enderror
              </label>
            </div>

            <div class="flex items-center mb-4">
              <label class="block w-full mb-5 text-sm">
              <span class="font-semibold text-gray-700 dark:text-gray-400">Product Image 2</span>
                @if($product->image2 != null)
                    <img src="{{ asset('storage/products/'.$product->image2) }}" style="height: 60px;"/>
                @else
                    <p class="font-bold text-gray-700 dark:text-gray-400">No Image</p>
                @endif
              <input type="file" class="@error('image2') focus:border-red-400 focus:outline-none focus:shadow-outline-red @enderror 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" 
               id="image2" name="image2">
              @error('image2')
              <span class="text-xs text-red-600 dark:text-red-400">
                  {{ $message }}
                </span>
              @enderror
              </label>
            </div>

            <div class="flex items-center mb-4">
              <label class="block w-full mb-5 text-sm">
              <span class="font-semibold text-gray-700 dark:text-gray-400">Product Image 3</span>
                @if($product->image3 != null)
                    <img src="{{ asset('storage/products/'.$product->image3) }}" style="height: 60px;"/>
                @else
                    <p class="font-bold text-gray-700 dark:text-gray-400">No Image</p>
                @endif
              <input type="file" class="@error('image3') focus:border-red-400 focus:outline-none focus:shadow-outline-red @enderror 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" 
               id="image3" name="image3">
              @error('image3')
              <span class="text-xs text-red-600 dark:text-red-400">
                  {{ $message }}
                </span>
              @enderror
              </label>
            </div>


              <div class="mx-auto">
              <button
                  class="px-5 py-3 font-medium leading-5 text-white transition-colors duration-150 bg-blue-600 border border-transparent rounded-lg hover:bg-green-700 focus:outline-none focus:shadow-outline-green"
                  type="submit" style="color: #fff;"
                >
                  Update Product
                </button>
              </div>
            </form>

        </div>
      </div>                      
    </div>
</main>



@endsection