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

@section('content')
    <h3 class="page-title">@lang('quickadmin.course-of-construction.title')</h3>

    <div class="panel panel-default course-of-construction">
        <div class="panel-heading header-block">
            <div class="col-xs-12 col-lg-4">
                <div class="row">
                    @can('planning_create')
                        <a href="{{ route('admin.course_of_constructions.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">
                    <form action="{{ route('admin.course_of_constructions.index') }}" method="GET">
                        <div class="row">
                            <div class="input-group">
                                {!! Form::select('residental_complex_id', $residential_complexes, $residental_complex_id, ['class' => 'form-control select2']) !!}
                                {{--<input type="text" name="search" class="form-control" placeholder="Search"--}}
                                {{--id="txtSearch"/>--}}
                                <div class="input-group-btn">
                                    <button class="btn btn-primary" type="submit">
                                        <span class="glyphicon glyphicon-search"></span>
                                    </button>
                                </div>
                            </div>
                        </div>
                    </form>
                </div>
            @endif
            <div class="col-xs-12 col-lg-4">
                <div class="row">
                    @can('planning_delete')
                        <ul class="list-inline">
                            <li><a href="{{ route('admin.course_of_constructions.index') }}"
                                   style="{{ request('show_deleted') == 1 ? '' : 'font-weight: 700' }}">@lang('quickadmin.qa_all')</a>
                            </li>
                            |
                            <li><a href="{{ route('admin.course_of_constructions.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($course_of_constructions) > 0 ? 'datatable' : '' }} @can('course_of_construction_delete') @if ( request('show_deleted') != 1 ) dt-select @endif @endcan">
                <thead>
                <tr>
                    @can('course_of_construction_delete')
                        @if ( request('show_deleted') != 1 )
                            <th style="text-align:center;"><input type="checkbox" id="select-all"/></th>@endif
                    @endcan

                    <th>@lang('quickadmin.course-of-construction.fields.images')</th>
                    <th>@lang('quickadmin.course-of-construction.fields.youtube-link')</th>
                    <th>@lang('quickadmin.course-of-construction.fields.report-date')</th>
                    {{--<th>@lang('quickadmin.course-of-construction.fields.description')</th>--}}
                    <th>@lang('quickadmin.course-of-construction.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($course_of_constructions) > 0)
                    @foreach ($course_of_constructions as $course_of_construction)

                        <tr data-entry-id="{{ $course_of_construction->id }}">
                            @can('course_of_construction_delete')
                                @if ( request('show_deleted') != 1 )
                                    <td></td>@endif
                            @endcan

                            <td field-key='images'> @foreach($course_of_construction->getMedia('images') as $media)
                                        <a href="{{ $media->getUrl() }}" target="_blank">{{ $media->name }}
                                            ({{ $media->size }} bytes)</a>
                                @endforeach</td>
                            <td field-key='youtube_link'>@if($course_of_construction->youtube_link)<a
                                        href="{{ $course_of_construction->youtube_link }}" target="_blank">Переглянути
                                    відео</a>@endif</td>
                            <td field-key='report_date'>{{ $course_of_construction->report_date }}</td>
                            {{--<td field-key='description'>{{ $course_of_construction->description }}</td>--}}
                            <td field-key='residental_complex'>{{ $course_of_construction->residental_complex->name ?? '' }}</td>
                            @if( request('show_deleted') == 1 )
                                <td class="action">
                                    @can('course_of_construction_delete')
                                        {!! Form::open(array(
        'style' => 'display: inline-block;',
        'method' => 'POST',
        'onsubmit' => "return confirm('".trans("quickadmin.qa_are_you_sure")."');",
        'route' => ['admin.course_of_constructions.restore', $course_of_construction->id])) !!}
                                        {!! Form::submit(trans('quickadmin.qa_restore'), array('class' => 'btn btn-xs btn-success')) !!}
                                        {!! Form::close() !!}
                                    @endcan
                                    @can('course_of_construction_delete')
                                        {!! Form::open(array(
        'style' => 'display: inline-block;',
        'method' => 'DELETE',
        'onsubmit' => "return confirm('".trans("quickadmin.qa_are_you_sure")."');",
        'route' => ['admin.course_of_constructions.perma_del', $course_of_construction->id])) !!}
                                        {!! Form::submit(trans('quickadmin.qa_permadel'), array('class' => 'btn btn-xs btn-danger')) !!}
                                        {!! Form::close() !!}
                                    @endcan
                                </td>
                            @else
                                <td class="action">
                                    @can('course_of_construction_view')
                                        <a href="{{ route('admin.course_of_constructions.show',[$course_of_construction->id]) }}"
                                           class="btn btn-xs btn-primary">@lang('quickadmin.qa_view')</a>
                                    @endcan
                                    @can('course_of_construction_edit')
                                        <a href="{{ route('admin.course_of_constructions.edit',[$course_of_construction->id]) }}"
                                           class="btn btn-xs btn-info">@lang('quickadmin.qa_edit')</a>
                                    @endcan
                                    @can('course_of_construction_delete')
                                        {!! Form::open(array(
                                                                                'style' => 'display: inline-block;',
                                                                                'method' => 'DELETE',
                                                                                'onsubmit' => "return confirm('".trans("quickadmin.qa_are_you_sure")."');",
                                                                                'route' => ['admin.course_of_constructions.destroy', $course_of_construction->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="10">@lang('quickadmin.qa_no_entries_in_table')</td>
                    </tr>
                @endif
                </tbody>
            </table>
            @if ( !isset($residental_complex_id) && request('show_deleted') != 1)
                {{ $course_of_constructions->links() }}
            @endif
        </div>
    </div>
@stop

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

    </script>
@endsection