@extends('layouts.layout-2')

@section('content')
    <h4 class="font-weight-bold py-3 mb-1">
        Vorlagen
    </h4>
    <div class="nav-tabs-top mb-4">
        <ul class="nav nav-tabs">
            <li class="nav-item">
                <a class="nav-link @if(!$step) active show @endif" data-toggle="tab" href="#navs-top-drafts">Übersicht</a>
            </li>
            <li class="nav-item">
                <a class="nav-link @if($step === 'type') active show @endif" data-toggle="tab" href="#navs-top-draft_types">Typen</a>
            </li>
        </ul>

        <div class="tab-content">
            <div class="tab-pane fade @if(!$step) active show @endif" id="navs-top-drafts">
                <div class="card">
                    <div class="card-datatable table-responsive">
                        <table class="datatables-drafts table table-striped table-bordered">
                            <thead>
                            <tr>
                                <th style="max-width: 60px;">&nbsp;</th>
                                <th>{{__('Name')}}</th>
                                <th>{{__('sichtbar')}}</th>
                                <th></th>
                            </tr>
                            </thead>
                            <tbody>
                            @foreach($drafts as $value)
                                <tr>
                                    <td>
                                        <a href="{{ route('draft_detail', [$value->id]) }}" class="btn icon-btn btn-sm btn-primary">
                                            <span class="fa fa-edit"></span>
                                        </a>
                                    </td>
                                    <td><a href="{{ route('draft_detail', [$value->id]) }}">{{ $value->name }}</a></td>

                                    <td data-sort="{{ $value->active }}">
                                        @if($value->active)
                                            <span class="badge badge-pill badge-success"><i class="fa fa-check"></i></span>
                                        @else
                                            <span class="badge badge-pill badge-danger"><i class="fa fa-times"></i></span>
                                        @endif
                                    </td>
                                    <td><a class="text-danger" href="{{ route('draft_delete', [$value->id]) }}"  onclick="return confirm('{{__('Wirklich löschen?')}}');"><i class="fa fa-trash-alt"></i></a></td>

                                </tr>
                            @endforeach
                            </tbody>
                        </table>
                        <div class="mt-4 col">
                            <a href="{{ route('draft_detail', ['new']) }}" class="btn btn-sm btn-primary">Neue Vorlage anlegen</a>
                            <a href="{{ route('draft_load_old') }}" class="btn btn-sm btn-default float-right">aus alter Vorlage laden</a><br>
                            <a href="{{ route('draft_load_new') }}" class="btn btn-sm btn-default float-right mt-2">aus Vorlage duplizieren</a>
                        </div>
                    </div>
                    <script>
                        $( document ).ready(function() {
                            $('.datatables-drafts').dataTable({
                                "bLengthChange": false,
                                "iDisplayLength": 50,

                                "language": {
                                    "url": "/js/German.json"
                                }
                            });
                        });
                    </script>
                 </div>
            </div>

            <div class="tab-pane fade @if($step === 'type') active show @endif" id="navs-top-draft_types">
                <div class="card">
                    <div class="card-datatable table-responsive">
                        <table class="datatables-types table table-striped table-bordered">
                            <thead>
                            <tr>
                                <th style="max-width: 60px;">&nbsp;</th>
                                <th style="width: 2%;">{{__('POS')}}</th>
                                <th>{{__('Name')}}</th>
                                <th>{{__('Farbe')}}</th>
                                <th>{{__('sichtbar')}}</th>
                                <th></th>
                            </tr>
                            </thead>
                            <tbody>
                            @foreach($draft_types as $value)
                                <tr>
                                    <td>
                                        <button type="button" class="btn icon-btn btn-sm btn-primary" data-toggle="modal" data-target="#modals-type"
                                                data-id="{{ $value->id }}"
                                                data-name="{{ $value->name }}"
                                                data-color="{{ $value->color }}"
                                                data-active="{{ $value->active }}"
                                                data-pos="{{ $value->pos }}">
                                            <span class="fa fa-edit"></span>
                                        </button>
                                    </td>
                                    <td>{{ $value->pos   }}</td>

                                    <td>{{ $value->name   }}</td>
                                    <td>@if($value->color)
                                            <div style="display:inline-block; width: 20px; height: 20px; border: 1px solid #888a85; background-color: {{$value->color}}"></div>
                                            {{ $value->color }}
                                        @else
                                            <div style="display:inline-block; width: 20px; height: 20px; border: 1px solid #888a85; background-color: #fff"></div>
                                        @endif
                                    </td>
                                    <td data-sort="{{ $value->active }}">
                                        @if($value->active)
                                            <span class="badge badge-pill badge-success"><i class="fa fa-check"></i></span>
                                        @else
                                            <span class="badge badge-pill badge-danger"><i class="fa fa-times"></i></span>
                                        @endif
                                    </td>
                                    <td><a class="text-danger" href="{{ route('draft_type_delete', [$value->id]) }}"  onclick="return confirm('{{__('Wirklich löschen?')}}');"><i class="fa fa-trash-alt"></i></a></td>

                                </tr>
                            @endforeach
                            </tbody>
                        </table>
                        <div class="mt-4 ml-3 text-left">
                            <button type="button" class="btn btn-sm btn-primary" data-toggle="modal" data-target="#modals-type"
                                    data-id="new"
                                    data-name=""
                                    data-active="1"
                                    data-pos="0"
                            >Neuen Typ anlegen</button>
                        </div>
                    </div>

                    <!-- Modal template -->
                    <div class="modal fade" id="modals-type">
                        <div class="modal-dialog">
                            <form class="modal-content" action="{{ route('draft_type_update') }}" method="post">
                                @csrf
                                <input type="hidden" class="form-control" name="id">

                                <div class="modal-header">
                                    <h5 class="modal-title">Vorlagen-Typ <span class="font-weight-light">anlegen/bearbeiten</span></h5>
                                    <button type="button" class="close" data-dismiss="modal" aria-label="Close">×</button>
                                </div>
                                <div class="modal-body">
                                    <div class="form-row">
                                        <div class="form-group col">
                                            <label for="name" class="form-label">Name*</label>
                                            <input type="text" class="form-control" name="name" placeholder="{{__('Description')}}" required>
                                        </div>
                                    </div>
                                    <div class="form-row">
                                        <div class="form-group col">
                                            <label for="pos" class="form-label">POS*</label>
                                            <input type="text" class="form-control" name="pos" placeholder="{{__('Position')}}" required>
                                        </div>
                                    </div>

                                    <div class="form-row">
                                        <div class="form-group col">
                                            <label for="name" class="form-label">Farbe*</label>
                                            <input type="text" name="color" id="minicolors-hue" class="form-control" value="#fff">
                                        </div>
                                    </div>

                                    <div class="form-group">
                                        <label class="custom-control custom-checkbox m-0">
                                            <input type="checkbox" class="custom-control-input" name="active" checked>
                                            <span class="custom-control-label">{{__('sichtbar')}}</span>
                                        </label>
                                    </div>
                                </div>
                                <div class="modal-footer">
                                    <button type="button" class="btn btn-default" data-dismiss="modal">{{__('close')}}</button>
                                    <button type="submit" class="btn btn-primary">{{__('save')}}</button>
                                </div>
                            </form>

                        </div>
                    </div>
                    <script>
                        $( document ).ready(function() {

                            $('#minicolors-hue').minicolors({
                                control:  'hue',
                                position: 'bottom ' + 'left',
                            });

                            $('#modals-type').on('show.bs.modal', function (event) {
                                var button = $(event.relatedTarget);
                                $(this).find(".modal-content input[name='id']").val(button.data('id'));
                                $(this).find(".modal-body input[name='name']").val(button.data('name'));
                                $(this).find(".modal-body input[name='pos']").val(button.data('pos'));
                                color = '#fff';
                                if(button.data('color') != ""){
                                    color = button.data('color');
                                }
                                $('#minicolors-hue').minicolors('value', color);

                               // $('.selectpicker').selectpicker('refresh');
                                $(this).find(".modal-body input[name='active']").prop( "checked", button.data('active'));
                            });

                            $('.datatables-types').dataTable({
                                "bLengthChange": false,
                                "iDisplayLength": 50,
                                "order": [[ 1, "desc" ]],
                                "language": {
                                    "url": "/js/German.json"
                                }
                            });
                        });
                    </script>
                </div>
            </div>

        </div>
    </div>


@endsection