<?php

use yii\helpers\Html;
use yii\grid\GridView;
use app\models\Auctions;

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

$this->title = Yii::t('app', 'Torgi ID');
$this->params['breadcrumbs'][] = $this->title;
?>

<div class="panel panel-primary">
    <div class="panel-heading"><span class="glyphicon glyphicon-stats"></span><strong> <?= Html::encode($this->title) ?></strong></div>
    <div class="panel-body">

        <div class="auctions-index">

            <?php // echo $this->render('_search', ['model' => $searchModel]); ?>

            <p>
                <?= $this->render('_alert.php') ?>
                <?php
                if(Yii::$app->user->can('admin'))
                {
                    $actions = '{view} {delete} {publishing}';
                    //echo Html::a(Yii::t('app', 'Create Auctions'), ['create'], ['class' => 'btn btn-success']);
                }
                elseif(Yii::$app->user->can('member'))
                {
                    $actions = '{view} {bid} {publishing}';
                }
                elseif(Yii::$app->user->can('org'))
                {
                    $actions = '{view} {bid} {publishing}';
                }
                else
                {
                    $actions = '{view}';
                }
                ?>

            </p>

            <?= GridView::widget([
                'dataProvider' => $dataProvider,
                'filterModel' => $searchModel,
                'columns' => [
                    [
                        'class' => 'yii\grid\SerialColumn',
                        'contentOptions' => ['width' => '70px'],
                    ],

                    //'name',
                    //'userName',
                    [
                        'attribute' => 'lot_num',
                        'header'    =>  Yii::t('app','LotNumber ID'),
                    ],
                    [
                        'attribute' => 'lot',
                        'value' => 'lot.name'
                    ],
                    'date_start:datetime',
                    'bidding_date:datetime',


                    [
                        'attribute'=>'status',
                        //'header' => Yii::t('app', 'Status ID'),
                        'value' => function($model){
                            if ($model->status==0)
                            {
                                //return Yii::t('app', 'Waiting ID');
                                return Yii::t('app', 'pMakeBidding ID');
                            }
                            if ($model->status==1)
                            {
                                //return Yii::t('app', 'Success ID');
                                return Yii::t('app', 'pWaitAuction ID');
                            }
                            if ($model->status==2)
                            {
                                //return Yii::t('app', 'Rejected ID');
                                return Yii::t('app', 'pMakeAuction ID');
                            }
                            if ($model->status==3)
                            {
                                //return Yii::t('app', 'Rejected ID');
                                return Yii::t('app', 'pMakeFinal ID');
                            }
                             if ($model->status==4)
                            {
                                //return Yii::t('app', 'Rejected ID');
                                return Yii::t('app', 'pEndTorg ID');
                            }
                        },
                        'format' => 'raw',
                    ],


                    [
                            'header' => Yii::t('app', 'StartPrice ID'),
                            'value' => 'lot.start_price',
                    ],
                    // 'last_price',
                    // 'last_user',
                    // 'last_date',

                    //['class' => 'yii\grid\ActionColumn'],
                    [
                        'class' => 'yii\grid\ActionColumn',
                        'template' => $actions,
                        'buttons' => [
                            'view' => function ($url,$model,$key) {
                                return Html::a('', $url,['title'=>Yii::t('app','GoAuction ID'),'class' => 'glyphicon glyphicon-log-in']);
                            },
                            'bid' => function ($url,$model,$key) {
                                return Html::a('', '/lots/view?id='.$model->lot_id,['title'=>Yii::t('app','CreateBid ID'),'class' => 'glyphicon glyphicon-th-list']);
                            },
                            'publishing' => function ($url, $model, $key)
                            {
                                return Html::a('', '/publishing/view?id='.$model->id,['title' => Yii::t('app', 'PublishingLot ID'), 'class' => 'glyphicon glyphicon-eye-open']);
                            }

                        ],
                    ],
                ],
            ]); ?>

        </div>
    </div>
</div>
