<?php

use yii\helpers\Html;
use yii\helpers\Url;
use yii\grid\GridView;
use yii\bootstrap\Modal;

?>

<div class="pending-training-requests-index">

    <?= GridView::widget([
        'dataProvider' => $dataProvider,
        'columns' => [
            [
                'attribute' => 'serial_number',
                'headerOptions' => ['style' => 'width: 10%;'],
                'value' => function($model){
                    return $model->trainingRequest->serial_number;
                }
            ],
            [
                'attribute' => 'trainee_full_name',
                'headerOptions' => ['style' => 'width: 20%;'],
                'value' => function($model){
                    return $model->trainingRequest->full_name;
                }
            ],
            [
                'attribute' => 'trainee_mother_name',
                'headerOptions' => ['style' => 'width: 20%;'],
                'value' => function($model){
                    return $model->trainingRequest->mother_name;
                }
            ],
            [
                'attribute' => 'date',
                'label' => Yii::t('app', 'Time'),
                'headerOptions' => ['style' => 'width: 20%;'],
                'value' => function($model){
                    return date('G:i', strtotime($model->date));
                }
            ],
            [
                'attribute' => 'create_date',
                'headerOptions' => ['style' => 'width: 20%;'],
                'value' => function($model){
                    return $model->trainingRequest->create_date;
                }
            ],
            [
                'class' => 'yii\grid\ActionColumn',
                'headerOptions' => ['style' => 'width: 10%;'],
                'template' => '{view} {reject} {approve}',
                'buttons' => [
                    'view' => function($url, $model){
                        return Html::a('<span class="glyphicon glyphicon-eye-open"></span>', 
                            ['/training-requests/view', 'id' => $model->trainingRequest->id],
                            ['title' => Yii::t('app', 'View Training Request')]);
                    },
                    'reject' => function($url, $model){
                        return Html::a('<span class="glyphicon glyphicon-remove"></span>', 
                            ['#'],
                            [
                                'value' => Url::to(['/training-requests/reject-training', 'id' => $model->trainingRequest->id, 'url' => 'Dashboard']),
                                'title' => Yii::t('app', 'Reject'),
                                'class' => 'reject-training-request-btn'
                            ]);
                    },
                    'approve' => function($url, $model){
                        return Html::a('<span class="glyphicon glyphicon-ok"></span>', 
                            ['/trainings/create', 'training_request_id' => $model->trainingRequest->id],
                            ['title' => Yii::t('app', 'Approve')]);
                    },
                ]
            ],
        ],
    ]); ?>
</div>

<?php 
    Modal::begin([
        'header' => '<h3>' . \Yii::t('app', 'Reject Training Request') . '</h3>',
        'id' => 'reject-training-request-modal',
        'size' => 'modal-md'
    ]);

    echo '<div id="reject-training-request-modal-content"></div>';

    Modal::end();
?>