@if($m_data_error)
    <div class="row">
        <div class="col-sm-12">
            <div class="alert alert-danger">
                <ul>
                    <li>{{ $m_data_error }}</li>
                </ul>
            </div>
        </div>
    </div>
@endif


<div class="card mb-4">
    <h5 class="card-header">
        <div class="row">
            <div class="col-md-12">
                {{ __('White-Label') }}
            </div>
           
        </div>
    </h5>
    <div class="card-body">
        {!! Form::open(['action' => route('admin_lead_update')."?show=".$show, 'class' => 'form-horizontal', 'id'=>'white-label-form']) !!}
        <input type="hidden" name="user_id" value="{{$user->id}}">
        <div class="form-row">
            <div class="form-group col-md-12">
                <label class="form-label" for="whitelabel_products">Produkte für White-Label hinzufügen</label>
                <select class="selectpicker" name="whitelabel_products[]" id="whitelabel_products" data-style="btn-light" data-live-search="true" multiple>
                    {!!  HTMLHelper::getProductsWhiteLabelOptions([], $user->whitelabel_products()->pluck('product_id')->toArray(), 1) !!}
                </select>
                <p class="badge">Hier werden alle Produkte angzeigt, die unter Produkte als White-Label markiert sind.</p>
                <div>
                <button type="submit"  name="action" value="add_whitelabel_products" class="btn btn-sm btn-submit">Produkte hinzufügen</button>&nbsp;
                </div>
            </div>
        </div>        
        @foreach($user->whitelabel_products as $wlp)
        @if($wlp->product)
        <div class="card shadow-none bg-transparent mb-2 p-4" style="border-color:rgba(24, 28, 33, 0.2) !important">
        <div class="form-row">
            <div class="col-md-12">
                <div class="float-right">
                    <a href="{{ route('admin_lead_remove', ['remove_whitelabel_product', $user->id, $wlp->id]) }}?show={{ $show }}" class="btn btn-sm btn-danger mt-2 mb-2" onclick="return confirm('Produkt wirklich entfernen?');">Produkt entfernen</a>
                </div>
                <h4>{{ $wlp->product->getWhiteLableName() }}</h4>
               
            </div>


            @foreach($wlp->whitelabel_images as $wlp_image)
            <div class="col-md-12">
                <hr>   
            </div>
            <div class="col-md-3 col-lg-2">
                  <img class="img-fluid" alt="" style="max-height: 200px" src="{{ route('product_image', [$wlp_image->slug]) }}">
            </div>
            <div class="col-md-9 col-lg-10">
                <label class="form-label" for="image_wl_attributes_{{ $wlp_image->id }}">für {{ __('Varianten') }}</label>
                <select class="selectpicker" name="image_wl_attributes[{{ $wlp_image->id }}][]" id="image_wl_attributes_{{ $wlp_image->id }}" data-style="btn-light" data-live-search="true" multiple>
                    {!!  HTMLHelper::getProductAttributesOptions($wlp->product->attribute_variants, $wlp_image->attributes, false, 1) !!}
                </select>
                <a href="{{ route('admin_lead_remove', ['remove_whitelabel_label', $user->id, $wlp->id, $wlp_image->id]) }}?show={{ $show }}" class="btn btn-sm btn-danger mt-2 mb-2" onclick="return confirm('Etikett wirklich löschen?');">Etikett löschen</a>
            </div>
            @endforeach

            <div class="form-group col-md-12">
                <hr>
                <button type="button" class="btn btn-sm btn-primary" data-toggle="modal" data-target="#modals-upload-white-label"
                        data-id="{{ $wlp->id }}">{{__('White Label VP Etikett hochladen')}}</button>
            </div>
        </div>
        </div>
        @endif

        @endforeach
        <div class="form-group">
            <button type="submit" name="action" value="update_whitelabel_products" class=" float-right btn btn-sm btn-submit">{{ __('save') }}</button>&nbsp; 
        </div>

        {!! Form::close() !!}
    </div>
</div>


<!-- Modal template -->
<div class="modal fade" id="modals-upload-white-label">
    <div class="modal-dialog">
        <div class="modal-content">
            @csrf
            <input type="hidden" name="id">
            <input type="hidden" name="action" value="upload-white-label">

            <style>
                /* Dropzone */
                .dropzone {
                    min-height: 230px;
                    border: 2px dashed rgba(0, 0, 0, 0.3);
                    background: white;
                    border-radius: 6px;
                }
                .dropzone .dz-message {
                    font-size: 28px;
        
                }
        
            </style>

            <div class="modal-header">
                <h5 class="modal-title">Upload Etikett White-Label Produkt</h5>
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">×</button>
            </div>
            <div class="modal-body">
       
                <div class="card-body">
                    <form method="POST" action="{{ route('admin_lead_update') }}?show={{ $show }}" accept-charset="UTF-8" class="avatar" enctype="multipart/form-data">
                        @csrf
                        <input type="hidden" name="id" value="">
                        <input type="hidden" name="user_id" value="{{$user->id}}">
                        <input type="hidden" name="upload_type" value="uwllogo">
                        <input type="hidden" name="action" value="upload_white_label_image">


                        <div class="slim_holder text-center">
                            <div class="slim" style="margin:20px auto;"
                                data-label='<span class="text-green">Foto-Upload</span><br>(Datei suchen oder Drag & Drop)'
                                data-fetcher="fetch.php"
                                data-size="600,600"
                                data-min-size="200,200"
                                data-max-file-size="10"
                                data-status-image-too-small="Bild zu klein<br>min. $0 Pixel"
                                data-status-file-type="Ungültige Datei<br>bitte nur: $0"
                                data-status-file-size="Die Datei ist zu groß<br>max. $0 MB"
                                data-button-confirm-label="bestätigen"
                                data-button-cancel-label="abbrechen"
                                data-button-confirm-title="bestätigen"
                                data-button-cancel-title="abbrechen"
                                data-button-rotate-title="drehen"
                                data-ratio="1:1">
                                <input type="file" name="images[]" required />
                            </div>
                            <br>
                            <button class="btn btn-primary" type="submit">Bild speichern</button>
                        </div>
                    </form>
                </div>
            
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">{{__('close')}}</button>
            </div>
        </div>
    </div>
</div>

<script>
    $( document ).ready(function() {
        $('#modals-upload-white-label').on('show.bs.modal', function (event) {
            var button = $(event.relatedTarget);
            $(this).find(".modal-content input[name='id']").val(button.data('id'));
        });
     
    });
</script>

