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

@section('content')
    <h3 class="page-title">@lang('quickadmin.qa_list') секцій</h3>

    <div class="panel panel-default section">
        <div class="panel-heading header-block">
            <div class="col-xs-12 col-lg-4">
                <div class="row">
                    @can('planning_create')
                        <a href="{{ route('admin.sections.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.sections.index') }}" method="GET">
                        <div class="row">
                            <div class="input-group">
                                {!! Form::select('residental_complex_id', $residential_complexes, $residental_complex_id, ['class' => 'form-control select2']) !!}
                                <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.sections.index') }}"--}}
                                   {{--style="{{ request('show_deleted') == 1 ? '' : 'font-weight: 700' }}">@lang('quickadmin.qa_all')</a>--}}
                            {{--</li>--}}
                            {{--|--}}
                            {{--<li><a href="{{ route('admin.sections.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($sections) > 0 ? 'datatable' : '' }} @can('section_delete') @if ( request('show_deleted') != 1 ) dt-select @endif @endcan">
                <thead>
                <tr>
                    @can('section_delete')
                        @if ( request('show_deleted') != 1 )
                            <th style="text-align:center;"><input type="checkbox" id="select-all"/></th>@endif
                    @endcan

                    <th>@lang('quickadmin.section.fields.name')</th>
                    {{--<th>@lang('quickadmin.section.fields.building_number')</th>--}}
                    {{--<th>@lang('quickadmin.section.fields.number')</th>--}}
                    <th>@lang('quickadmin.planning.fields.count_of_floor')</th>
                    {{--<th>@lang('quickadmin.section.fields.section-type')</th>--}}
                    <th>@lang('quickadmin.section.fields.stage-of-construction')</th>
                    <th>@lang('quickadmin.section.fields.date-start-building')</th>
                    <th>@lang('quickadmin.section.fields.date-finish-buildiing')</th>
                    <th>@lang('quickadmin.section.fields.is_pricing')</th>
                    <th>@lang('quickadmin.section.fields.is_planning')</th>
                    <th>@lang('quickadmin.section.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($sections) > 0)
                    @foreach ($sections as $section)
                        <tr data-entry-id="{{ $section->id }}">
                            @can('section_delete')
                                @if ( request('show_deleted') != 1 )
                                    <td></td>@endif
                            @endcan
                            <td field-key='name'>{{ $section->name }}</td>
                            {{--<td field-key='name'>{{ $section->building_number }}</td>--}}
                            {{--<td field-key='number'>{{ $section->number }}</td>--}}
                            <td field-key='name'>{{ $section->count_of_floor }}</td>
                            {{--<td field-key='section_type'>{{ $section->section_type->type ?? '' }}</td>--}}
                            <td field-key='stage_of_construction'>{{ $section->stage_of_construction->name ?? '' }}</td>
                            <td field-key='date_start_building'>{{ $section->date_start_building }}</td>
                            <td field-key='date_finish_buildiing'>{{ $section->date_finish_buildiing }}</td>
                            <td field-key='is_pricing'>{{ Form::checkbox("is_pricing", 1, $section->is_pricing == 1 ? true : false, ["disabled"]) }}</td>
                            <td field-key='is_planning'>{{ Form::checkbox("is_planning", 1, $section->is_planning == 1 ? true : false, ["disabled"]) }}</td>
                            <td field-key='residental_complex'>{{ $section->residental_complex->name ?? '' }}</td>
                            @if( request('show_deleted') == 1 )
                                <td class="action">
                                    @can('section_delete')
                                        {!! Form::open(array(
        'style' => 'display: inline-block;',
        'method' => 'POST',
        'onsubmit' => "return confirm('".trans("quickadmin.qa_are_you_sure")."');",
        'route' => ['admin.sections.restore', $section->id])) !!}
                                        {!! Form::submit(trans('quickadmin.qa_restore'), array('class' => 'btn btn-xs btn-success')) !!}
                                        {!! Form::close() !!}
                                    @endcan
                                    @can('section_delete')
                                        {!! Form::open(array(
        'style' => 'display: inline-block;',
        'method' => 'DELETE',
        'onsubmit' => "return confirm('".trans("quickadmin.qa_are_you_sure")."');",
        'route' => ['admin.sections.perma_del', $section->id])) !!}
                                        {!! Form::submit(trans('quickadmin.qa_permadel'), array('class' => 'btn btn-xs btn-danger')) !!}
                                        {!! Form::close() !!}
                                    @endcan
                                </td>
                            @else
                                <td class="action">
                                    @can('section_view')
                                        <a href="{{ route('admin.sections.show',[$section->id]) }}"
                                           class="btn btn-xs btn-primary">@lang('quickadmin.qa_view')</a>
                                    @endcan
                                    @can('section_edit')
                                        <a href="{{ route('admin.sections.edit',[$section->id]) }}"
                                           class="btn btn-xs btn-info">@lang('quickadmin.qa_edit')</a>
                                    @endcan
                                    @can('section_delete')
                                        {!! Form::open(array(
                                                                                'style' => 'display: inline-block;',
                                                                                'method' => 'DELETE',
                                                                                'onsubmit' => "return confirm('".trans("quickadmin.qa_are_you_sure")."');",
                                                                                'route' => ['admin.sections.destroy', $section->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="13">@lang('quickadmin.qa_no_entries_in_table')</td>
                    </tr>
                @endif
                </tbody>
            </table>
            @if ( !isset($residental_complex_id) && request('show_deleted') != 1)
                {{ $sections->links() }}
            @endif
        </div>
    </div>
@stop

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