<?php

use yii\helpers\Html;
use yii\grid\GridView;

/* @var $this yii\web\View */
/* @var $searchModel backend\models\EventSearch */
/* @var $dataProvider yii\data\ActiveDataProvider */

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

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

    <p>
        <?= Html::a(Yii::t('event', 'Create Event'), ['create'], ['class' => 'btn btn-success']) ?>
    </p>

    <?= GridView::widget([
        'dataProvider' => $dataProvider,
        'columns' => [
            [
                'attribute' => 'event_id',
                'label' => \Yii::t('event', 'ID')
            ],
            [
                'attribute' => 'event_type_name',
                'label' => \Yii::t('event', 'Id Event Type')
            ],
            [
                'attribute' => 'event_start',
                'label' => \Yii::t('event', 'Start'),
                'format' => 'datetime'
            ],
            [
                'attribute' => 'event_end',
                'label' => \Yii::t('event', 'End'),
                'format' => 'time'
            ],
            [
                'attribute' => 'event_seat_count',
                'label' => \Yii::t('event', 'Seat Count')
            ],
            [
                'attribute' => 'registration_count',
                'label' => \Yii::t('event', 'Registration Count')
            ],
            [
                'attribute' => 'room_name',
                'label' => \Yii::t('event', 'Room Name')
            ],
            [
                'attribute' => 'trainer_name',
                'label' => \Yii::t('event', 'Trainer Name')
            ],
            [
                'attribute' => 'event_created_at',
                'label' => \Yii::t('event', 'Created At'),
                'format' => 'datetime'
            ],
            [
                'attribute' => 'event_updated_at',
                'label' => \Yii::t('event', 'Updated At'),
                'format' => 'datetime'
            ],
            [
                'attribute' => 'event_deleted_at',
                'label' => \Yii::t('event', 'Deleted At'),
                'format' => 'datetime'
            ],
            [
                'class' => 'yii\grid\ActionColumn',
                'template' => '{view} {update}   {reserve-card}',
                'urlCreator' => function ($action, $model, $key, $index) {
                    $params = ['id' => $model['event_id']];
                    $params[0] = "event" . '/' . $action;
                    return \yii\helpers\Url::toRoute($params);
                },
                'buttons' => [
                    'view' => function ($url, $model, $key) {
                        $options = [
                            'title' => Yii::t('yii', 'View'),
                            'aria-label' => Yii::t('yii', 'View'),
                            'data-pjax' => '0',
                        ];
                        return Html::a('<span class="glyphicon glyphicon-eye-open"></span>', $url, $options);
                    },
                    'update' => function ($url, $model, $key) {
                        $options = [
                            'title' => Yii::t('yii', 'Update'),
                            'aria-label' => Yii::t('yii', 'Update'),
                            'data-pjax' => '0',
                        ];
                        return Html::a('<span class="glyphicon glyphicon-pencil"></span>', $url, $options);
                    },
                    'delete' => function ($url, $model, $key) {
                        $options = [
                            'title' => Yii::t('yii', 'Delete'),
                            'aria-label' => Yii::t('yii', 'Delete'),
                            'data-confirm' => Yii::t('yii', 'Are you sure you want to delete this item?'),
                            'data-method' => 'post',
                            'data-pjax' => '0',
                        ];
                        return Html::a('<span class="glyphicon glyphicon-trash"></span>', $url, $options);
                    },
                    'reserve-card' => function ($url, $model, $key) {
                        $options = [
                            'title' => Yii::t('yii', 'Register'),
                            'aria-label' => Yii::t('yii', 'Register'),
                            'data-pjax' => '0',
                        ];
                        return Html::a('<span class="glyphicon glyphicon-user"></span>', $url, $options);
                    }
                ]

            ],
        ],
    ]); ?>

</div>
