@component('panel.layouts.component', ['title' => 'ویرایش محصول '])
    @slot('style')
        <style>
.hide-element{
    display: flex;}
        </style>
    @endslot
    @slot('subject')
        <h1><i class="fa fa-users"></i>ویرایش محصولات </h1>
        <p>ویرایش محصول در فروشگاه.</p>
    @endslot
    @slot('breadcrumb')
        <li class="breadcrumb-item">محصولات</li>
    @endslot
    @slot('content')
        <div class="auth-background h-auto py-5">
            <div class="container py-5">
                @component('product::components.message')
                @endcomponent
                @if(session()->has('image_deleted'))
                    <div class="alert alert-dismissible alert-success">
                        <button class="close" type="button" data-dismiss="alert">×</button>
                        {{session('image_deleted')}}
                    </div>
                @endif
                <div class="row align-items-center">
                    <div class="col-lg-12 col-md-12 mx-auto">
                        <div class="card">
                            <div class="card-header"><strong>{{ __('ویرایش محصول ') }}</strong></div>
                            <div class="card-body mx-lg-5 px-lg-3">
                                <form method="POST" action="{{ route('products.update',$product->id) }}"
                                      enctype="multipart/form-data">
                                    @csrf
                                    @if ($product)
                                        @method('PUT')
                                    @endif
                                    <div class="form-group">
                                        <label for="title">{{ __('product.title') }}</label>
                                        <i class="required"> *</i>
                                        <input id="title" type="text"
                                               class="form-control @error('title') is-invalid @enderror"
                                               name="title"
                                               value="{{$product->title}}" autocomplete="title" autofocus>
                                        @error('title')
                                        <span class="invalid-feedback" role="alert">
                                            <strong>{{ $message }}</strong>
                                        </span>
                                        @enderror
                                    </div>
                                    <div class="form-row ">
                                        <div class="form-group col-lg-4">
                                            <label for="slug">  {{ __('product.slug') }}</label>
                                            <input id="slug" type="text"
                                                   class="form-control @error('slug') is-invalid @enderror"
                                                   name="slug" value="{{$product->slug}}"
                                                   autocomplete="slug" autofocus>
                                            @error('slug')
                                            <span class="invalid-feedback" role="alert">
                                                <strong>{{ $message }}</strong>
                                            </span>
                                            @enderror
                                        </div>
                                        <div class="form-group col-lg-4">
                                            <label for="sku">  {{ __('product.sku') }}</label>
                                            <input id="sku" type="text"
                                                   class="form-control @error('sku') is-invalid @enderror"
                                                   name="sku" value="{{$product->sku}}"
                                                   autocomplete="sku" autofocus>
                                            @error('sku')
                                            <span class="invalid-feedback" role="alert">
                                                <strong>{{ $message }}</strong>
                                            </span>
                                            @enderror
                                        </div>
                                        <div class="form-group col-lg-4">
                                            <label for="type">{{ __('product.type') }}</label>
                                            <select id="type" type="text"
                                                    class="form-control @error('type') is-invalid @enderror"
                                                    name="type"
                                                    autocomplete="type">
                                                <option value="0" @if($product->type==='ساده') selected='selected' @endif>
                                                    ساده
                                                </option>
                                                <option value="1" @if($product->type==='متغیر') selected='selected' @endif>
                                                    متغیر
                                                </option>
                                                <option value="2" @if($product->type==='باندل') selected='selected' @endif>
                                                    باندل
                                                </option>
                                            </select>
                                            @error('type')
                                                <span class="invalid-feedback" role="alert">
                                                    <strong>{{ $message }}</strong>
                                                </span>
                                            @enderror
                                        </div>
                                    </div>
                                    <div class="form-row ">
                                        <div class="form-group col-lg-4">
                                            <label for="price">  {{ __('product.price') }}</label>
                                            <i class="required"> *</i>
                                            <input id="price" type="text"
                                                   class="form-control price @error('price') is-invalid @enderror"
                                                   name="price"
                                                   value="{{$product->price}}" autocomplete="price" autofocus>
                                            @error('price')
                                                <span class="invalid-feedback" role="alert">
                                                    <strong>{{ $message }}</strong>
                                                </span>
                                            @enderror
                                        </div>
                                        <div class="form-group col-lg-4">
                                            <label for="sale_price">{{ __('product.sale_price') }}</label>
                                            <input id="sale_price" type="text"
                                                   class="form-control price @error('sale_price') is-invalid @enderror"
                                                   name="sale_price"
                                                   value="{{$product->sale_price}}" autocomplete="sale_price">
                                            @error('sale_price')
                                                <span class="invalid-feedback" role="alert">
                                                    <strong>{{ $message }}</strong>
                                                </span>
                                            @enderror
                                        </div>
                                        <div class="form-group col-lg-4">
                                            <label for="status">{{ __('product.status') }}</label>
                                            <i class="required">&nbsp; *</i>
                                            <select id="status" type="text"
                                                    class="form-control @error('status') is-invalid @enderror"
                                                    name="status"
                                                    value="{{$product->status}}" required autocomplete="status">
                                                <option value="0">ناموجود</option>
                                                <option value="1" @if ($product->status === 'موجود')  selected='selected'@endif>موجود</option>
                                            </select>
                                            @error('status')
                                                <span class="invalid-feedback" role="alert">
                                                    <strong>{{ $message }}</strong>
                                                </span>
                                            @enderror
                                        </div>
                                    </div>
                                    <div class="form-group col-lg-4">
                                        <label for="ReleaseStatus">{{ __('product.ReleaseStatus') }}</label>
                                        <i class="required">  *</i>
                                        <select id="ReleaseStatus" type="text"
                                                class="form-control @error('ReleaseStatus') is-invalid @enderror"
                                                name="ReleaseStatus"
                                                autocomplete="ReleaseStatus">
                                            <option value="draft" @if($product->ReleaseStatus==='پیشنویس') selected='selected' @endif>
                                                پیشنویس
                                            </option>
                                            <option value="pending" @if($product->ReleaseStatus==='در انتظار انتشار') selected='selected' @endif>
                                              در انتظار انتشار
                                            </option>
                                            <option value="published" @if($product->ReleaseStatus==='منتشر شده') selected='selected' @endif>
                                                منتشر شده
                                            </option>
                                        </select>
                                        @error('ReleaseStatus')
                                        <span class="invalid-feedback" role="alert">
                                                    <strong>{{ $message }}</strong>
                                                </span>
                                        @enderror
                                    </div>
                                    <div class="form-group">
                                        <label for="discription">{{ __('product.discription') }}</label>
                                        <i class="required">&nbsp; *</i>
                                        <textarea id="editor" type="text"
                                                  class="form-control @error('discription') is-invalid @enderror"
                                                  name="discription"
                                                  autocomplete="discription">{{$product->discription}}</textarea>
                                        @error('discription')
                                            <span class="invalid-feedback" role="alert">
                                                <strong>{{ $message }}</strong>
                                            </span>
                                        @enderror
                                    </div>

                                    <div class="form-group">
                                        <label for="categories[]">{{ __('product.categories') }}</label>
                                        <i class="required">&nbsp; *</i>

                                        <select id="categories" type="text"
                                                class="form-control select2 @error('categories[]') is-invalid @enderror"
                                                name="categories[]"
                                                autocomplete="categories[]" multiple>

                                                {!! category_select_options( $categories,  $product->categories->pluck('id')->toArray() ) !!}
                                        </select>
                                        @error('status')
                                        <span class="invalid-feedback" role="alert">
                                                <strong>{{ $message }}</strong>
                                            </span>
                                        @enderror
                                    </div>

                                    <div class="form-group col-md-8">
                                        @component('product::components.featuredImage')
                                            @slot('ImageSrc')
                                                {{\Illuminate\Support\Facades\Storage::disk('product')->url($product->featured_image->path)}}
                                            @endslot
                                            @slot('featureDescription')
                                                    {{$product->featured_image->descriptionImg}}
                                                @endslot
                                                @slot('featureCaption')
                                                    {{$product->featured_image->caption}}
                                                @endslot
                                        @endcomponent
                                    </div>

                                    <div class="row">

                                        <div class="form-row ">
                                            <div class="upload-widget test ">

                                                <div class="select">
                                                    <label for="title">
                                                        {{ __('product.gallery_image') }}
                                                    </label>
                                                    <span class="btn btn-primary btn-file">
                                                <input class="files" type="file" name="gallery_image[]" value="{{old('gallery_image[]')}}" multiple>
                                                    {{ __('product.gallery_images') }}
                                                </span>

                                                    <output class="list row " >

                                                            @foreach($product->gallery_images as $upload_photo)
                                                                <div class="b">
                                                                <div class=" DeleteImages">
                                                                    <a class="btn btn-danger  position-absolute  "
                                                                       href="{{route('uploads.destroyFile', $upload_photo->id)}}">
                                                                        <i class="icon fa fa-close"></i>
                                                                    </a>
                                                                    <img id="holder" class="img-thumbnail"
                                                                         src="{{ \Illuminate\Support\Facades\Storage::disk('product')->url($upload_photo->path) }}"
                                                                         alt=""
                                                                         style="width: 200px; height: 150px;" >
                                                                    <span class="form-input py-3 md-form" style="display: block;">
                                                                            <label for="description">توضیحات: </label>
                                                                           <input type="text" class="form-control" value="{{$upload_photo->descriptionImg}}" name="descriptionGallery[]">
                                                                            <label for="caption">عنوان: </label>
                                                                           <input type="text" class="form-control" value="{{$upload_photo->caption}}" name="captionGallery[]">
                                                                    </span>
                                                                </div>

                                                                </div>
                                                            @endforeach

                                                    </output>
                                                </div>
                                                <div class="dropZone col-3">
                                                </div>
                                            </div>
                                        </div>
                                    </div>

                                    <div class="form-group mb-0">
                                        <div class="">
                                            <button type="submit" class="btn btn-primary">
                                                {{ __('ویرایش محصول') }}
                                            </button>
                                            <a href={{ route('products.index') }} type="button"
                                               class="btn btn-warning"> انصراف</a>
                                        </div>
                                    </div>
                                </form>
                            </div>
                            <div class="card-footer">
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    @endslot
    @slot('script')
    @endslot
@endcomponent








