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

@section('content')
    <h3 class="page-title"> @lang('quickadmin.qa_list') документів</h3>

    <div class="panel panel-default documents">
        <div class="panel-heading header-block">
            @include('partials.rc-filter', [
                'page' => 'document',
                 'url_index' => route('admin.documents.index'),
                 'url_create' => route('admin.documents.create')
                 ])
        </div>
        
        <div class="panel-body table-responsive">
            <table class="table table-bordered table-striped {{ count($documents) > 0 ? 'datatable' : '' }} @can('document_delete') @if ( request('show_deleted') != 1 ) dt-select @endif @endcan">
                <thead>
                <tr>
                    @can('document_delete')
                        @if ( request('show_deleted') != 1 )
                            <th style="text-align:center;"><input type="checkbox" id="select-all"/></th>@endif
                    @endcan

                    <th>@lang('quickadmin.document.fields.name')</th>
                    {{--<th>@lang('quickadmin.document.fields.description')</th>--}}
                    {{--<th>@lang('quickadmin.document.fields.icon')</th>--}}
                    <th>@lang('quickadmin.document.fields.file')</th>
                    <th>@lang('quickadmin.document.fields.link')</th>
                    <th>@lang('quickadmin.document.fields.document-type')</th>
                    <th>@lang('quickadmin.document.fields.residental-complex')</th>
                    @if( request('show_deleted') == 1 )
                        <th>@lang('quickadmin.qa_action')</th>
                    @else
                        <th>@lang('quickadmin.qa_action')</th>
                    @endif
                </tr>
                </thead>

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

                            <td field-key='name'>{{ $document->name }}</td>
                            {{--<td field-key='description'>{{ $document->description }}</td>--}}
                            {{--<td field-key='icon'>@if($document->icon)<a href="{{ asset(env('UPLOAD_PATH').'/' . $document->icon) }}" target="_blank"><img src="{{ asset(env('UPLOAD_PATH').'/thumb/' . $document->icon) }}"/></a>@endif</td>--}}
                            <td field-key='file'>@if($document->file)<a
                                        href="{{ asset(env('UPLOAD_PATH').'/' . $document->file) }}" target="_blank">Завантажити
                                    документ</a>@endif</td>
                            <td field-key='link'>@if($document->link)<a href="{{ $document->link }}" target="_blank">Відкрити
                                    документ</a>@endif </td>
                            <td field-key='document_type'>{{ $document->document_type->name ?? '' }}</td>
                            <td field-key='residental_complex'>{{ $document->residental_complex->name ?? '' }}</td>
                            @if( request('show_deleted') == 1 )
                                <td class="action">
                                    @can('document_delete')
                                        {!! Form::open(array(
        'style' => 'display: inline-block;',
        'method' => 'POST',
        'onsubmit' => "return confirm('".trans("quickadmin.qa_are_you_sure")."');",
        'route' => ['admin.documents.restore', $document->id])) !!}
                                        {!! Form::submit(trans('quickadmin.qa_restore'), array('class' => 'btn btn-xs btn-success')) !!}
                                        {!! Form::close() !!}
                                    @endcan
                                    @can('document_delete')
                                        {!! Form::open(array(
        'style' => 'display: inline-block;',
        'method' => 'DELETE',
        'onsubmit' => "return confirm('".trans("quickadmin.qa_are_you_sure")."');",
        'route' => ['admin.documents.perma_del', $document->id])) !!}
                                        {!! Form::submit(trans('quickadmin.qa_permadel'), array('class' => 'btn btn-xs btn-danger')) !!}
                                        {!! Form::close() !!}
                                    @endcan
                                </td>
                            @else
                                <td class="action">
                                    {{--@can('document_view')--}}
                                        {{--<a href="{{ route('admin.documents.show',[$document->id]) }}"--}}
                                           {{--class="btn btn-xs btn-primary">@lang('quickadmin.qa_view')</a>--}}
                                    {{--@endcan--}}
                                    @can('document_edit')
                                        <a href="{{ route('admin.documents.edit',[$document->id]) }}"
                                           class="btn btn-xs btn-info">@lang('quickadmin.qa_edit')</a>
                                    @endcan
                                    @can('document_delete')
                                        {!! Form::open(array(
                                                                                'style' => 'display: inline-block;',
                                                                                'method' => 'DELETE',
                                                                                'onsubmit' => "return confirm('".trans("quickadmin.qa_are_you_sure")."');",
                                                                                'route' => ['admin.documents.destroy', $document->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="12">@lang('quickadmin.qa_no_entries_in_table')</td>
                    </tr>
                @endif
                </tbody>
            </table>
            @if ( !isset($residental_complex_id) && request('show_deleted') != 1)
                {{ $documents->links() }}
            @endif
        </div>
    </div>
@stop

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

    </script>
@endsection