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

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

    <div class="panel panel-default promotion">
        <div class="panel-heading header-block">
            <div class="col-xs-12 col-lg-4">
                <div class="row">
                    @can('planning_create')
                        <a href="{{ route('admin.promotions.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.promotions.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.promotions.index') }}"
                                   style="{{ request('show_deleted') == 1 ? '' : 'font-weight: 700' }}">@lang('quickadmin.qa_all')</a>
                            </li>
                            |
                            <li><a href="{{ route('admin.promotions.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($promotions) > 0 ? 'datatable' : '' }} @can('promotion_delete') @if ( request('show_deleted') != 1 ) dt-select @endif @endcan">
                <thead>
                <tr>
                    @can('promotion_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.promotion.fields.plajka')</th>
                    <th rowspan="2">@lang('quickadmin.promotion.fields.color-picker')</th>
                    <th rowspan="2">@lang('quickadmin.promotion.fields.header')</th>
                    <th rowspan="2">@lang('quickadmin.promotion.fields.sub-header')</th>
                    <th colspan="2" id="priority-border">@lang('quickadmin.developer.fields.page-priority')</th>
                    <th class="image" rowspan="2">@lang('quickadmin.promotion.fields.image')</th>
                    <th rowspan="2">@lang('quickadmin.promotion.fields.residental-complex')</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.promotion.fields.promotion-priority-index')</th>
                </tr>

                </thead>

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

                            <td field-key='plajka'>{{ $promotion->plajka }}</td>
                            <td field-key='color_picker'>{{ $promotion->color_picker }}</td>
                            <td field-key='header'>{{ $promotion->header }}</td>
                            <td field-key='sub_header'>{{ $promotion->sub_header }}</td>
                            <td field-key='main_page_priority'>{{ $promotion->main_page_priority }}</td>
                            <td field-key='promotion_page_priority'>{{ $promotion->promotion_page_priority }}</td>

                            <td class="image" field-key='image'>@if($promotion->image)<a
                                        href="{{ asset(env('UPLOAD_PATH').'/promotion/' . $promotion->image) }}"
                                        target="_blank"><img
                                            src="{{ asset(env('UPLOAD_PATH').'/thumb/' . $promotion->image) }}"/></a>@endif
                            </td>
                            <td field-key='residental_complex'>{{ $promotion->residental_complex->name ?? '' }}</td>
                            @if( request('show_deleted') == 1 )
                                <td class="action">
                                    @can('promotion_delete')
                                        {!! Form::open(array(
        'style' => 'display: inline-block;',
        'method' => 'POST',
        'onsubmit' => "return confirm('".trans("quickadmin.qa_are_you_sure")."');",
        'route' => ['admin.promotions.restore', $promotion->id])) !!}
                                        {!! Form::submit(trans('quickadmin.qa_restore'), array('class' => 'btn btn-xs btn-success')) !!}
                                        {!! Form::close() !!}
                                    @endcan
                                    @can('promotion_delete')
                                        {!! Form::open(array(
        'style' => 'display: inline-block;',
        'method' => 'DELETE',
        'onsubmit' => "return confirm('".trans("quickadmin.qa_are_you_sure")."');",
        'route' => ['admin.promotions.perma_del', $promotion->id])) !!}
                                        {!! Form::submit(trans('quickadmin.qa_permadel'), array('class' => 'btn btn-xs btn-danger')) !!}
                                        {!! Form::close() !!}
                                    @endcan
                                </td>
                            @else
                                <td class="action">
                                    @can('promotion_view')
                                        <a href="{{ route('admin.promotions.show',[$promotion->id]) }}"
                                           class="btn btn-xs btn-primary">@lang('quickadmin.qa_view')</a>
                                    @endcan
                                    @can('promotion_edit')
                                        <a href="{{ route('admin.promotions.edit',[$promotion->id]) }}"
                                           class="btn btn-xs btn-info">@lang('quickadmin.qa_edit')</a>
                                    @endcan
                                    @can('promotion_delete')
                                        {!! Form::open(array(
                                                                                'style' => 'display: inline-block;',
                                                                                'method' => 'DELETE',
                                                                                'onsubmit' => "return confirm('".trans("quickadmin.qa_are_you_sure")."');",
                                                                                'route' => ['admin.promotions.destroy', $promotion->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)
                {{ $promotions->links() }}
            @endif
        </div>
    </div>
@stop

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

    </script>
@endsection
