@extends('layouts.layout-2')

@section('content')

    <h4 class="font-weight-bold py-3 mb-1">
        {{ __('Feedback') }}
    </h4>

    <div class="card">
        <div class="card-datatable table-responsive py-2">
            <div class="mr-4 mb-2 text-right">
                <a href="{{ route('cms_feedback_detail', ['new']) }}" class="btn btn-sm btn-primary">Neuen Feedback anlegen</a>
            </div>
            <table class="datatables-feedbacks table table-striped table-bordered">
                <thead>
                <tr>
                    <th style="max-width: 60px;">&nbsp;</th>
                    <th>{{__('Name')}}</th>
                    <th>{{__('Parent')}}</th>
                    <th>{{__('Date')}}</th>
                    <th>{{__('sichtbar')}}</th>
                    <th>#</th>
                </tr>
                </thead>
                <tbody>
                @foreach($feedbacks as $value)
                    <tr>
                        <td>
                            <a href="{{ route('cms_feedback_detail', [$value->id]) }}" class="btn icon-btn btn-sm btn-primary">
                                <span class="far fa-edit"></span>
                            </a>
                        </td>
                        <td><a href="{{ route('cms_feedback_detail', [$value->id]) }}">{{ $value->title }}</a></td>
                        <td>@if($value->parent) {{ $value->parent->title }} @else - Main No-Parent - @endif</td>
                        <td data-sort="{{ $value->getDateRow() }}">{{ $value->date }}</td>

                        <td data-sort="{{ $value->status }}">
                            @if($value->status)
                                <span class="badge badge-pill badge-success"><i class="far fa-check"></i></span>
                            @else
                                <span class="badge badge-pill badge-danger"><i class="far fa-times"></i></span>
                            @endif
                        </td>
                        <td>
                            @if($value->parent)
                            <a class="text-danger" href="{{ route('cms_feedback_delete', [$value->id]) }}"  onclick="return confirm('{{__('Wirklich löschen?')}}');"><i class="far fa-trash-alt"></i></a>
                            @else
                                -
                            @endif
                        </td>
                    </tr>
                @endforeach
                </tbody>
            </table>
            <div class="mt-4 col">
                <a href="{{ route('cms_feedback_detail', ['new']) }}" class="btn btn-sm btn-primary">Neues Feedback anlegen</a>
            </div>
        </div>
        <script>
            $( document ).ready(function() {
                $('.datatables-feedbacks').dataTable({
                    "bLengthChange": false,
                    "iDisplayLength": 50,
                    "language": {
                        "url": "/js/German.json"
                    },
                    initComplete: function () {
                        this.api().columns(2).every( function () {
                            var column = this;
                            var title = $(column.header()).html();
                            var select = $('<select class="selectpicker"><option value="">'+title+'</option></select>')
                                .appendTo( $(column.header()).empty() )
                                .on( 'change', function () {
                                    var val = $.fn.dataTable.util.escapeRegex(
                                        $(this).val()
                                    );

                                    column
                                        .search( val ? '^'+val+'$' : '', true, false )
                                        .draw();
                                } );

                            column.data().unique().sort().each( function ( d, j ) {
                                if(d !== ""){
                                    select.append( '<option value="'+d+'">'+d+'</option>' );
                                }
                            } );


                        } );
                        $('.selectpicker').selectpicker();
                    }
                });


            });

        </script>
    </div>



@endsection