@extends('backend.layouts.master')

@section('main-content')

<div class="card">
    <h5 class="card-header">Edit Product</h5>
    <div class="card-body">
      <form method="post" action="{{route('product.update',$product->id)}}">
        @csrf 
        @method('PATCH')
        <div class="form-group">
          <label for="inputTitle" class="col-form-label">Title <span class="text-danger">*</span></label>
          <input id="inputTitle" type="text" name="title" placeholder="Enter title"  value="{{$product->title}}" class="form-control" required>
          @error('title')
          <span class="text-danger">{{$message}}</span>
          @enderror
        </div>

        <div class="form-group">
          <label for="collection">Collection <span class="text-danger">*</span></label>
          <select name="collection" class="form-control selectpicker"  data-live-search="true" required>
              <option value="">--Select any collection--</option>
              @foreach($collections as $collection)
              <option value="{{$collection->id}}" {{ $product->collection == $collection->id ? 'selected' : '' }} >{{$collection->title}}</option>
              @endforeach
          </select>
          @error('collection')
          <span class="text-danger">{{$message}}</span>
          @enderror
        </div>

        <div class="form-group">
          <label for="type">Type <span class="text-danger">*</span></label>
          <select name="type" class="form-control selectpicker"  data-live-search="true" required>
              <option value="">--Select any type--</option>
              <option value="personal" {{ $product->type == 'personal' ? 'selected' : '' }} >Personal</option>
              <option value="company" {{ $product->type == 'company' ? 'selected' : '' }} >Company</option>
          </select>
          @error('type')
          <span class="text-danger">{{$message}}</span>
          @enderror
        </div>

        <div class="form-group">
          <label for="summary" class="col-form-label">Summary <span class="text-danger">*</span></label>
          <textarea class="form-control" id="summary" name="summary">{{$product->summary}}</textarea>
          @error('summary')
          <span class="text-danger">{{$message}}</span>
          @enderror
        </div>

        <div class="form-group">
          <label for="description" class="col-form-label">Description</label>
          <textarea class="form-control" id="description" name="description">{{$product->description}}</textarea>
          @error('description')
          <span class="text-danger">{{$message}}</span>
          @enderror
        </div>

        <div class="form-group">
          <label for="color">Colors <span class="text-danger">*</span></label>
          <select name="color[]" class="form-control selectpicker" multiple data-live-search="true" required>
            @foreach($colors as $key => $color)
              @if ( in_array($color->id,$productColor) )
                <option value="{{$color->id}}" selected>{{$color->title}}</option>
              @else
                <option value="{{$color->id}}">{{$color->title}}</option>
              @endif
            @endforeach
          </select>
        </div>
        <div>
        @error('color')
          <span class="text-danger">{{$message}}</span>
        @enderror
        </div>

        <div class="form-group">
          <label for="size">Size <span class="text-danger">*</span></label>
          <select name="size[]" class="form-control selectpicker"  multiple data-live-search="true" required>
              @foreach($sizes as $key => $size)
                @if ( in_array($size->id,$productSize) )
                  <option value="{{$size->id}}" selected>{{$size->title}}</option>
                @else
                  <option value="{{$size->id}}" >{{$size->title}}</option>
                @endif
              @endforeach
          </select>
        </div>
        <div>
        @error('size')
          <span class="text-danger">{{$message}}</span>
        @enderror
        </div>

        <div class="form-group">
          <label for="model">Model <span class="text-danger">*</span></label>
          <input id="model" type="text" name="model" placeholder="Enter model"  value="{{$product->model}}" class="form-control" required>
          @error('model')
          <span class="text-danger">{{$message}}</span>
          @enderror
        </div>

        <div class="form-group">
          <label for="stock">Quantity <span class="text-danger">*</span></label>
          <input id="quantity" type="number" name="stock" min="0" placeholder="Enter quantity"  value="{{$product->stock}}" class="form-control" required>
          @error('stock')
          <span class="text-danger">{{$message}}</span>
          @enderror
        </div>
        <div class="form-group">
          <label for="inputPhoto" class="col-form-label">Photo <span class="text-danger">*</span></label>
          <div class="input-group">
              <span class="input-group-btn">
                  <a id="lfm" data-input="thumbnail" data-preview="holder" class="btn btn-primary text-white">
                  <i class="fas fa-image"></i> Choose
                  </a>
              </span>
          <input id="thumbnail" class="form-control" type="text" name="photo" value="{{$product->photo}}" required>
        </div>
        <div id="holder" style="margin-top:15px;max-height:100px;">
          @if (count(explode(',',$product->photo)) > 1 )
          @foreach (explode(',',$product->photo) as $photo)
          <img src="{{$photo}}" width="120px" height="80px">
          @endforeach
          @else
          <img src="{{$product->photo}}" width="120px" height="80px">
          @endif
        </div>
          @error('photo')
          <span class="text-danger">{{$message}}</span>
          @enderror
        </div>

        <div class="form-group">
          <label for="inputVideo" class="col-form-label">Video</label>
          <div class="input-group">
              <span class="input-group-btn">
                  <a id="lfm2" data-input="thumbnail2" data-preview="holder2" class="btn btn-primary text-white">
                  <i class="fas fa-image"></i> Choose
                  </a>
              </span>
          <input id="thumbnail2" class="form-control" type="text" name="video" value="{{$product->video}}" >
        </div>
        <div id="holder2" style="margin-top:15px;max-height:150px;">
          @if (!empty($product->video) && count(explode(',',$product->video)) > 1 )
          @foreach (explode(',',$product->video) as $video)
          <video width="200" height="100" controls>
            <source src="{{ $video }}" type="video/mp4">
            <source src="{{ $video }}" type="video/ogg">
            Your browser does not support the video tag.
          </video>
          @endforeach
          @else
          <video width="200" height="100" controls>
            <source src="{{ $product->video }}" type="video/mp4">
            <source src="{{ $product->video }}" type="video/ogg">
            Your browser does not support the video tag.
          </video>
          @endif
        </div>
          @error('video')
          <span class="text-danger">{{$message}}</span>
          @enderror
        </div>
        
        <div class="form-group">
          <label for="status" class="col-form-label">Status <span class="text-danger">*</span></label>
          <select name="status" class="form-control">
            <option value="active" {{(($product->status=='active')? 'selected' : '')}}>Active</option>
            <option value="inactive" {{(($product->status=='inactive')? 'selected' : '')}}>Inactive</option>
        </select>
          @error('status')
          <span class="text-danger">{{$message}}</span>
          @enderror
        </div>
        <div class="form-group mb-3">
           <button class="btn btn-success" type="submit">Update</button>
        </div>
      </form>
    </div>
</div>

@endsection

@push('styles')
<link rel="stylesheet" href="{{asset('backend/summernote/summernote.min.css')}}">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-select/1.13.1/css/bootstrap-select.css" />

@endpush
@push('scripts')
<script src="/vendor/laravel-filemanager/js/stand-alone-button.js"></script>
<script src="{{asset('backend/summernote/summernote.min.js')}}"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-select/1.13.1/js/bootstrap-select.min.js"></script>

<script>
    $('#lfm').filemanager('image');

    $('#lfm2').filemanager('files');

    $(document).ready(function() {
    $('#summary').summernote({
      placeholder: "Write short description.....",
        tabsize: 2,
        height: 150
    });
    });
    $(document).ready(function() {
      $('#description').summernote({
        placeholder: "Write detail Description.....",
          tabsize: 2,
          height: 150
      });
    });
</script>

@endpush