@extends('backend.layouts.app')

@section('title', app_name() . ' | ' .'Background image management')

@section('content')
    <div class="card">
        <div class="card-body">
            <div class="row">
                <div class="col">

                </div>

                <div class="col">
                    <div class="btn-toolbar float-right" role="toolbar"
                         aria-label="@lang('labels.general.toolbar_btn_groups')">
                        <button data-toggle="modal" data-target="#new_background_modal"
                                class="btn btn-success ml-1" data-toggle="tooltip"
                                title="@lang('labels.general.create_new')"><i class="fas fa-plus-circle"></i></button>

                    </div>
                </div><!--col-->
            </div><!--row-->

            <div class="row mt-4">
                <div class="col">
                    <div class="table-responsive">
                        <table class="table">
                            <thead>
                            <tr>
                                <th>Thumbnail</th>
                                <th>Owner</th>
                                <th>Public</th>
                                <th></th>

                            </tr>
                            </thead>
                            <tbody>
                            @foreach($images as $background)
                                <tr>
                                    <td>
                                        <img
                                            src="{{$background->path()}}"
                                            style="width: 100px; height: auto">
                                    </td>


                                    <td>{{$background->owner->first_name}} {{$background->owner->last_name}}</td>

                                    <td>
                                        <div class="btn-group" role="group"
                                             aria-label="@lang('labels.backend.access.users.user_actions')">
                                            <a href="{{ route('admin.backgrounds.show', $background) }}"
                                               data-toggle="tooltip"
                                               data-placement="top" title="@lang('buttons.general.crud.view')"
                                               class="btn btn-info">
                                                <i class="fas fa-eye"></i>
                                            </a>

                                            <a href="{{ route('admin.backgrounds.edit', $background) }}"
                                               data-toggle="tooltip"
                                               data-placement="top" title="@lang('buttons.general.crud.edit')"
                                               class="btn btn-primary">
                                                <i class="fas fa-edit"></i>
                                            </a>
                                            <a href="#" data-toggle="tooltip" data-placement="top"
                                               title="@lang('buttons.general.crud.delete')" class="btn btn-danger">
                                                <i class="fas fa-times"></i>
                                            </a>
                                        </div>
                                    </td>

                                </tr>
                            @endforeach
                            </tbody>
                        </table>
                    </div>
                </div><!--col-->
            </div><!--row-->
            <div class="row">
                <div class="col-7">

                </div><!--col-->

                <div class="col-5">

                </div><!--col-->
            </div><!--row-->
        </div><!--card-body-->
    </div><!--card-->
@endsection
@section('dialogs')

    <div id="new_background_modal" class="modal fade left">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <h4 class="modal-title">Add background</h4>
                    <button type="button" class="close" data-dismiss="modal"><i class="fa fa-times" aria-hidden="true"
                                                                                style="color: red"></i>
                    </button>
                </div>
                <div class="modal-body">
                    @include('backend.backgrounds.form.newbackground')
                </div>
            </div>
        </div>
    </div>

@endsection
@push('after-scripts')

    <script src="{{ asset('js/dropzone.min.js') }}"></script>
    <script>
        // the user uploaded image upload functionality
        Dropzone.options.newImageDropzone = {
            // autoProcessQueue: false,
            params: {
                '_token': "{{ csrf_token() }}"
            },
            maxFiles: 1,
            acceptedFiles: "image/*",
            init: function (e) {
                console.log(e)
                this.on("addedfile", function (file) {
                    let reader = new FileReader();
                    console.log(file);
                    //alert("Added file."); });
                });
                // clean up and append new file entry to selector
                this.on("success", function (file) {
                    this.removeFile(file);
                    console.log('success!');
                    console.log(JSON.parse(file.xhr.response).location);
                    location.reload();
                })
                $('#add_image_btn').on("click", function () {
                    console.log('Processing...')
                    //  myDropzone.processQueue(); // Tell Dropzone to process all queued files.
                });

            }
        };
        $(document).ready(function () {

        })
    </script>
@endpush

@push('after-styles')
    <link href="{{ asset('css/dropzone.min.css') }}" rel="stylesheet">
    <style>
        .dropzone {
            border: 2px dashed #0087F7;
            border-radius: 5px;
            background: white;
            box-sizing: border-box;
        }

        .dropzone .dz-message {
            text-align: center;
            margin: 2em 0;
            font-weight: 400;
            cursor: pointer;
        }

        .dropzone .dz-message .dz-button {
            background: none;
            color: inherit;
            border: none;
            padding: 0;
            font: inherit;
            cursor: pointer;
            outline: inherit;
        }
    </style>
@endpush
