<?php

use yii\helpers\Html;
use yii\grid\GridView;
use yii\helpers\Url;
use yii\widgets\ActiveForm;
use yii\helpers\ArrayHelper;

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

$this->title = Yii::t('app', 'YouLots ID');
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="lots-index">

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

            <ul class="nav nav-tabs">
                <!-- <li role="presentation">
                    <?= Html::a(\Yii::t('app', 'Template ID'), ['auclots/index'], ['class' => 'presentation active']) ?>
                </li> -->
                <li role="presentation"  class="active">
                    <?= Html::a(\Yii::t('app', 'Lots ID'), ['/lots/index'], ['class' => 'presentation active']) ?>
                </li>
            </ul>

            <?php // echo $this->render('_search', ['model' => $searchModel]);
            /*
            if ($model->status==1) {
                return Html::a(Yii::t('app', 'Waiting ID'), ['id' => Yii::$app->user->identity->id], ['class' => 'btn btn-xs btn-warning btn-block']);
            }
            if ($model->status==2) {
                return Html::a(Yii::t('app', 'Success ID'), ['id' => Yii::$app->user->identity->id], ['class' => 'btn btn-xs btn-success btn-block']);
            }
            else {
                return Html::a(Yii::t('app', 'Rejected ID'), ['id' => Yii::$app->user->identity->id], ['class' => 'btn btn-xs btn-danger btn-block']);
            }*/
            ?>
        <br>
            <p>
                <?= Html::a(Yii::t('app', 'CreateLot ID'), ['create'], ['class' => 'btn btn-success']) ?>
            </p>

            <?= $this->render('_alert.php') ?>


            <?php
            if(Yii::$app->user->can('admin') || (Yii::$app->user->can('org')))
            {
                $actions = '{clone} {view} {update} {delete}';
            }
            else
            {
                $actions = '{view} {update} {delete}';
            }

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

                    //'id',
                    //'user_id',
                    'aukname',
                    //'num',
                    'name',
                    //'description',
                    'start_price',
                    //'step',
                    // 'docs_id',
                    // 'address',
                    //'delivery_time:datetime',
                    // 'delivery_term',
                    // 'requires',
                    //'payment_term',
                    // 'payment_order',
                    // 'category_id',
                    // 'member_require',
                    // 'member_docs',
                    // 'requisites_id',
                    // 'notes',
                    // 'dogovor_id',
                    //'date',
                    //'auction_date',
                    'date:datetime',
                    /*[
                        'attribute'=>'date',
                        'format'=>'datetime', // ��������� ������������ - date:datetime:time
                        'headerOptions' => ['width' => '120'],
                    ],*/
                    [
                        'attribute'=>'status',
                        //'header' => Yii::t('app', 'Status ID'),
                        'value' => function($model){
                            if ($model->status==1)
                            {
                                //return Yii::t('app', 'Waiting ID');
                                return Html::a(Yii::t('app', 'Waiting ID'), ['#'], ['class' => 'label label-warning']);
                            }
                            if ($model->status==2)
                            {
                                //return Yii::t('app', 'Success ID');
                                return Html::a(Yii::t('app', 'Success ID'), ['#'], ['class' => 'label label-success']);
                            }
                            if ($model->status==3)
                            {
                                //return Yii::t('app', 'Rejected ID');
                                return Html::a(Yii::t('app', 'Rejected ID'), ['#'], ['class' => 'label label-danger']);
                            }
                            if ($model->status==4)
                            {
                                //return Yii::t('app', 'Rejected ID');
                                return Html::a(Yii::t('app', 'Agree by organizer'), ['#'], ['class' => 'label label-info']);
                            }
                        },
                        'format' => 'raw',
                    ],

                    ['class' => 'yii\grid\ActionColumn',
                        'template' => $actions,
                        'buttons' => [
                            /*'auction' => function ($url,$model,$key) {
                                return Html::a('', $url,['class' => 'glyphicon glyphicon-plus']);
                            },*/
                            'clone' => function ($url,$model,$key) {
                                return Html::a('', $url,['class' => 'glyphicon glyphicon-duplicate','title' => 'Клонувати']);
                            },
                            'delete' => function($url, $model){
                                return Html::a('<span class="glyphicon glyphicon-trash"></span>', ['delete', 'id' => $model->id], [
                                    'data' => [
                                        'confirm' => $model->auction
                                            ? 'Видаляючи цей лот, ви видалите і опублікований аукціон. Ви впевнені?'
                                            : 'Ви впевнені, що хочете видалити лот',
                                        'method' => 'post',
                                    ],
                                ]);
                            }
                        ],

                    ],
                ],
            ]); ?>

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