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

@section('content')
    <h3 class="page-title">@lang('quickadmin.qa_list') житлових комплексів</h3>
    <div class="panel panel-default">
        <div class="panel-heading header-block">
            @include('partials.rc-filter', [
                'page' => 'residential_complex',
                 'url_index' => route('admin.residential_complexes.index'),
                 'url_create' => route('admin.residential_complexes.create')
                 ])
        </div>

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

                    <th rowspan="2">@lang('quickadmin.residential-complex.fields.name')</th>
                    <th rowspan="2">@lang('quickadmin.residential-complex.fields.code')</th>
                    <th rowspan="2">@lang('quickadmin.residential-complex.fields.enabled')</th>
                    <th rowspan="2">@lang('quickadmin.residential-complex.fields.developer')</th>

                    <th colspan="2" id="priority-border">@lang('quickadmin.developer.fields.page-priority')</th>

                    <th rowspan="2">@lang('quickadmin.residential-complex.fields.min-price')</th>
                    <th rowspan="2">@lang('quickadmin.residential-complex.fields.city')</th>
                    <th rowspan="2">@lang('quickadmin.residential-complex.fields.district')</th>
                    <th rowspan="2">@lang('quickadmin.residential-complex.fields.street-name')</th>
                    <th rowspan="2">@lang('quickadmin.residential-complex.fields.stage-of-construction')</th>
                    @if( request('show_deleted') == 1 )
                        <th rowspan="2">@lang('quickadmin.qa_action')</th>
                    @else
                        <th rowspan="2">@lang('quickadmin.qa_action')</th>
                    @endif
                </tr>
                <tr>
                    <th>@lang('quickadmin.residential-complex.fields.main-page-priority_index')</th>
                    <th>@lang('quickadmin.residential-complex.fields.res-com-page-priority_index')</th>
                </tr>
                </thead>

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

                            <td field-key='name'>{{ $residential_complex->name }}</td>
                            <td field-key='code'>{{ $residential_complex->code }}</td>
                            <td field-key='enabled'>{{ Form::checkbox("enabled", 1, $residential_complex->enabled == 1 ? true : false, ["disabled"]) }}</td>
                            <td field-key='developer'>{{ $residential_complex->developer->name ?? '' }}</td>
                            <td field-key='main_page_priority'>{{ $residential_complex->main_page_priority }}</td>
                            <td field-key='res_com_page_priority'>{{ $residential_complex->res_com_page_priority }}</td>
                            <td field-key='min_price'>{{ $residential_complex->min_price }}</td>
                            <td field-key='city'>{{ $residential_complex->city->name ?? '' }}</td>
                            <td field-key='district'>{{ $residential_complex->district->name ?? '' }}</td>
                            <td field-key='street_name'>{{ $residential_complex->street_name->name ?? '' }}</td>
                            <td field-key='stage_of_construction'>{{ $residential_complex->stageOfConstruction->name ?? '' }}</td>
                            @if( request('show_deleted') == 1 )
                                <td class="action">
                                    @can('residential_complex_delete')
                                        {!! Form::open(array(
        'style' => 'display: inline-block;',
        'method' => 'POST',
        'onsubmit' => "return confirm('".trans("quickadmin.qa_are_you_sure")."');",
        'route' => ['admin.residential_complexes.restore', $residential_complex->id])) !!}
                                        {!! Form::submit(trans('quickadmin.qa_restore'), array('class' => 'btn btn-xs btn-success')) !!}
                                        {!! Form::close() !!}
                                    @endcan
                                    @can('residential_complex_delete')
                                        {!! Form::open(array(
        'style' => 'display: inline-block;',
        'method' => 'DELETE',
        'onsubmit' => "return confirm('".trans("quickadmin.qa_are_you_sure")."');",
        'route' => ['admin.residential_complexes.perma_del', $residential_complex->id])) !!}
                                        {!! Form::submit(trans('quickadmin.qa_permadel'), array('class' => 'btn btn-xs btn-danger')) !!}
                                        {!! Form::close() !!}
                                    @endcan
                                </td>
                            @else
                                <td class="action">
                                    @can('residential_complex_view')
                                        <a href="{{ route('admin.residential_complexes.show',[$residential_complex->id]) }}"
                                           class="btn btn-xs btn-primary">@lang('quickadmin.qa_view')</a>
                                    @endcan
                                    @can('residential_complex_edit')
                                        <a href="{{ route('admin.residential_complexes.edit',[$residential_complex->id]) }}"
                                           class="btn btn-xs btn-info">@lang('quickadmin.qa_edit')</a>
                                    @endcan
                                    @can('residential_complex_delete')
                                        {!! Form::open(array(
                                                                                'style' => 'display: inline-block;',
                                                                                'method' => 'DELETE',
                                                                                'onsubmit' => "return confirm('".trans("quickadmin.qa_are_you_sure")."');",
                                                                                'route' => ['admin.residential_complexes.destroy', $residential_complex->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="41">@lang('quickadmin.qa_no_entries_in_table')</td>
                    </tr>
                @endif
                </tbody>
            </table>
            @if ( !isset($residental_complex_id) && request('show_deleted') != 1)
                {{ $residential_complexes->links() }}
            @endif
        </div>
    </div>
@stop

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