<?php

use yii\helpers\Html;
use yii\grid\GridView;
use kartik\select2\Select2;
use app\models\Publishing;
use yii\widgets\ListView;
use yii\widgets\ActiveForm;
use yii\helpers\ArrayHelper;

/* @var $this yii\web\View */
/* @var $searchModel app\models\PublishingSearch */
/* @var $dataProvider yii\data\ActiveDataProvider */

$this->title = Yii::t('app', 'Publishing ID');
$this->params['breadcrumbs'][] = $this->title;
$this->registerJs(<<<JS
    $('#index-form *').on('change', function(){
       $('#index-form').submit();
    });
JS
);


?>
<div class="container">

    <section class="publications">
        <div class="container">
            <div class="row">
                <div class="col-12 publications-search">

                    <?php $form = ActiveForm::begin([
                        'method' => 'get',
                        'action' => ['/publishing'],
                        'id' => 'index-form'
                    ])?>

                    <div class="input-group mb-2">
                        <?= Html::activeInput('text', $searchModel, 'main_search',
                            ['class' => 'form-control', 'placeholder'=>'Назва або ідентифікатор аукціону'])?>
                        <?= Html::submitButton(Html::img('/images/icon-search.png'), ['class' => 'btn btn-primary'])?>
                    </div>
                    <input class="link-secondary p-0" data-toggle="collapse" data-target="#expandedSearch" type="button" value="Розширений пошук">
                    <img src="/images/icon-plus.png" alt="">
                    <div class="collapse <?= $searchModel->isClear() ? '' : 'show'?>" id="expandedSearch">
                        <div class="row ">

                            <div class="form-group col-md-6 col-lg-3 mb-0">
                                <label for="search-filter-admin">Організатор торгів</label>
                                <?= Html::activeInput('text', $searchModel, 'org_name',
                                    ['class' => 'form-control', 'placeholder'=>'Організатор', 'id' =>'search-filter-region'])?>
                            </div>

                            <div class="form-group col-md-6 col-lg-3 mb-0">
                                <label for="search-filter-id">Категорія</label>
                                <?=Html::activeDropDownList($searchModel, 'category',
                                    ArrayHelper::merge(['' => Yii::t('app','Choose')], ArrayHelper::map(\app\models\Category::find()->all(), 'id', 'name')),
                                    [
                                        'class' => 'form-control',
                                        'id' => 'search-filter-category'
                                    ]) ?>
                            </div>

                            <div class="form-group col-md-6 col-lg-3 mb-0">
                                <label for="search-filter-status">Стан торгів</label>
                                <?=Html::activeDropDownList($searchModel, 'status',
                                    [
                                        '' => Yii::t('app','Choose'),
                                        '0' => Yii::t('app','pMakeBidding ID'),
                                        '1' => Yii::t('app','pWaitAuction ID'),
                                        '2' => Yii::t('app','pMakeAuction ID'),
                                        '3' => Yii::t('app','pMakeFinal ID'),
                                        '4' =>  Yii::t('app','pEndTorg ID')
                                    ],
                                    [
                                        'class' => 'form-control',
                                        'id' => 'search-filter-status'
                                    ]) ?>
                            </div>
                            <div class="form-group col-md-6 col-lg-3 mb-0">
                                <label for="search-filter-type">Тип аукціону</label>
                                <?=Html::activeDropDownList($searchModel, 'type',
                                    [
                                        '' => Yii::t('app','Choose'),
                                        '1' => 'Аукціон на підвищення',
                                        '2' => 'Голландський аукціон'
                                    ],
                                    [
                                        'class' => 'form-control',
                                        'id' => 'search-filter-type'
                                    ]) ?>
                            </div>
                        </div>

                        <div class="row no-gutters">
                            <div class="col mt-3">
                                <a class="link-secondary" href="/publishing" id="reset-btn" name="search-clear">Очистити фільтр</a>
                            </div>
                        </div>
                    </div>
                    <?php ActiveForm::end();?>
                </div>

                <!-- start items -->
            </div>
            <section class="content bordered">
                <?= ListView::widget([
                    'dataProvider'=>$dataProvider ,
                    'itemView' => '_forms/_auctions',
                    'layout' => "{items}",
                ]) ?>
            </section>
            <?= \yii\widgets\LinkPager::widget([
                'pagination'=>$dataProvider->pagination,
                'prevPageLabel' => '&larr;',
                'nextPageLabel' => '&rarr;',
                'options' => [
                    'class' => 'pagination justify-content-center',
                ],

                // Customzing CSS class for pager link
                'linkOptions' => ['class' => 'page-link'],
                'activePageCssClass' => 'page-item active',
                'disabledPageCssClass' => 'hidden page-item',

            ]); ?>
        </div>
    </section>
</div>