@inject('request', 'Illuminate\Http\Request')
@extends('layouts.app')

@section('content')
    <h3 class="page-title">@lang('quickadmin.document-type.title')</h3>
    <div class="panel panel-default">
        <div class="panel-heading header-block">
            <div class="col-xs-12 col-lg-4">
                <div class="row">
                    @can('document_type_create')
                        <a href="{{ route('admin.document_types.create') }}"
                           class="btn btn-success">@lang('quickadmin.qa_add_new')</a>
                    @endcan
                </div>
            </div>

            @if(request('show_deleted') != 1)
                <div class="col-xs-12 col-lg-4">
                    @include('partials.main-search', [
                        'route' => route('admin.document_types.index'),
                        'search_id' => $search_id,
                        'listForSelect' => $documentTypesFilter
                    ])
                </div>
            @endif
            <div class="col-xs-12 col-lg-4">
                <div class="row">
                    @can('document_type_delete')
                        <ul class="list-inline">
                            <li><a href="{{ route('admin.document_types.index') }}"
                                   style="{{ request('show_deleted') == 1 ? '' : 'font-weight: 700' }}">@lang('quickadmin.qa_all')</a>
                            </li>
                            |
                            <li><a href="{{ route('admin.document_types.index') }}?show_deleted=1"
                                   style="{{ request('show_deleted') == 1 ? 'font-weight: 700' : '' }}">@lang('quickadmin.qa_trash')</a>
                            </li>
                        </ul>
                    @endcan
                </div>
            </div>
        </div>


        <div class="panel-body table-responsive">
            <table class="table table-bordered table-striped {{ count($document_types) > 0 ? 'datatable' : '' }} @can('document_type_delete') @if ( request('show_deleted') != 1 ) dt-select @endif @endcan">
                <thead>
                <tr>
                    @can('document_type_delete')
                        @if ( request('show_deleted') != 1 )
                            <th style="text-align:center;"><input type="checkbox" id="select-all"/></th>@endif
                    @endcan

                    <th>@lang('quickadmin.document-type.fields.name')</th>
                    @if( request('show_deleted') == 1 )
                        <th>&nbsp;</th>
                    @else
                        <th>&nbsp;</th>
                    @endif
                </tr>
                </thead>

                <tbody>
                @if (count($document_types) > 0)
                    @foreach ($document_types as $document_type)
                        <tr data-entry-id="{{ $document_type->id }}">
                            @can('document_type_delete')
                                @if ( request('show_deleted') != 1 )
                                    <td></td>@endif
                            @endcan

                            <td field-key='name'>{{ $document_type->name }}</td>
                            @if( request('show_deleted') == 1 )
                                <td class="action">
                                    @can('document_type_delete')
                                        {!! Form::open(array(
        'style' => 'display: inline-block;',
        'method' => 'POST',
        'onsubmit' => "return confirm('".trans("quickadmin.qa_are_you_sure")."');",
        'route' => ['admin.document_types.restore', $document_type->id])) !!}
                                        {!! Form::submit(trans('quickadmin.qa_restore'), array('class' => 'btn btn-xs btn-success')) !!}
                                        {!! Form::close() !!}
                                    @endcan
                                    @can('document_type_delete')
                                        {!! Form::open(array(
        'style' => 'display: inline-block;',
        'method' => 'DELETE',
        'onsubmit' => "return confirm('".trans("quickadmin.qa_are_you_sure")."');",
        'route' => ['admin.document_types.perma_del', $document_type->id])) !!}
                                        {!! Form::submit(trans('quickadmin.qa_permadel'), array('class' => 'btn btn-xs btn-danger')) !!}
                                        {!! Form::close() !!}
                                    @endcan
                                </td>
                            @else
                                <td class="action">
                                    {{--@can('document_type_view')--}}
                                        {{--<a href="{{ route('admin.document_types.show',[$document_type->id]) }}"--}}
                                           {{--class="btn btn-xs btn-primary">@lang('quickadmin.qa_view')</a>--}}
                                    {{--@endcan--}}
                                    @can('document_type_edit')
                                        <a href="{{ route('admin.document_types.edit',[$document_type->id]) }}"
                                           class="btn btn-xs btn-info">@lang('quickadmin.qa_edit')</a>
                                    @endcan
                                    @can('document_type_delete')
                                        {!! Form::open(array(
                                            'style' => 'display: inline-block;',
                                            'method' => 'DELETE',
                                            'onsubmit' => "return confirm('".trans("quickadmin.qa_are_you_sure")."');",
                                            'route' => ['admin.document_types.destroy', $document_type->id])) !!}
                                        {!! Form::submit(trans('quickadmin.qa_delete'), array('class' => 'btn btn-xs btn-danger')) !!}
                                        {!! Form::close() !!}
                                    @endcan
                                </td>
                            @endif
                        </tr>
                    @endforeach
                @else
                    <tr>
                        <td colspan="6">@lang('quickadmin.qa_no_entries_in_table')</td>
                    </tr>
                @endif
                </tbody>
            </table>
            @if ( !isset($search_id) && request('show_deleted') != 1)
                {{ $document_types->links() }}
            @endif
        </div>
    </div>
@stop

@section('javascript')
    <script>
        @can('document_type_delete')
                @if ( request('show_deleted') != 1 ) window.route_mass_crud_entries_destroy = '{{ route('admin.document_types.mass_destroy') }}'; @endif
        @endcan

    </script>
@endsection