<?php

use yii\helpers\Html;
use yii\helpers\Url;
use kartik\export\ExportMenu;
use yii\grid\GridView;
use yii\bootstrap\Modal;

$this->title = Yii::t('app', 'Trainees Report');

$columns = [
    [
        'attribute' => 'serial_number',
        'headerOptions' => ['style' => 'width: 10%;']
    ],
    [
        'attribute' => 'full_name',
        'headerOptions' => ['style' => 'width: 15%;'],
    ],
    [
        'attribute' => 'mother_name',
        'headerOptions' => ['style' => 'width: 15%;'],
    ],
    [
        'attribute' => 'university_name',
        'headerOptions' => ['style' => 'width: 15%;'],
    ],
    [
        'attribute' => 'faculty',
        'headerOptions' => ['style' => 'width: 15%;'],
    ],
    [
        'attribute' => 'training_request_status',
        'label' => Yii::t('app', 'Training Request Status'),
        'headerOptions' => ['style' => 'width: 15%;'],
        'filter' => [
            'Pending'       => Yii::t('app', 'Pending'),
            'Approved'      => Yii::t('app', 'Approved'),
            'Rejected'      => Yii::t('app', 'Rejected'),
            'Interview'     => Yii::t('app', 'Interview'),
            'Finish'        => Yii::t('app', 'Finish'),
            'Reactivated'   => Yii::t('app', 'Reactivated'),
        ],
        'value' => function($model){
            return Yii::t('app', $model->training_request_status);
        }
    ],
    [
        'attribute' => 'create_date',
        'headerOptions' => ['style' => 'width: 15%;'],
    ],
];

?>

<div class="trainees-report">

    <h1><?= $this->title ?></h1>

    <?= Html::a(Yii::t('app', 'Advanced Search'), 
        ['#'], 
        [
            'class' => 'btn btn-purple btn-expanded advanced-search-btn',
            'value' => Url::to(['advanced-search', 'from_date' => isset($_GET['from_date']) ? $_GET['from_date'] : null, 'to_date' => isset($_GET['to_date']) ? $_GET['to_date'] : null]),
            'title' => Yii::t('app', 'Advanced Search')
        ]) ?>
    
    <?= ExportMenu::widget([
        'dataProvider' => $dataProvider,
        'showConfirmAlert' => false,
        'showColumnSelector' => false,
        'asDropdown' => false,
        'filename' => 'Training-Requests-Report',
        'exportConfig' => [
            ExportMenu::FORMAT_CSV => [
                'label' => Yii::t('app', 'Export'),
                'icon' => false,
                'options' => [
                    'title' => Yii::t('app', 'Export'), 
                    'class' => 'btn btn-primary btn-expanded btn-export',
                ]
            ],
            ExportMenu::FORMAT_HTML     => false,
            ExportMenu::FORMAT_EXCEL    => false,
            ExportMenu::FORMAT_TEXT     => false,
            ExportMenu::FORMAT_PDF      => false,
            ExportMenu::FORMAT_EXCEL_X  => false,
        ],
        'columns' => $columns
    ]); ?>
    
    <br><br>
    <?php if(Yii::$app->session->hasFlash('wrong_selected_dates')): ?>
        <div class="alert alert-danger">
            <a href="#" class="close" data-dismiss="alert" aria-label="close">×</a>
            <?= Yii::$app->session->getFlash('wrong_selected_dates') ?>
        </div>
    <?php endif; ?>

    <?= GridView::widget([
        'dataProvider' => $dataProvider,
        'filterModel' => $searchModel,
        'columns' => $columns
    ]); ?>

</div>

<?php 
    Modal::begin([
        'header' => '<h3>' . \Yii::t('app', 'Advanced Search') . '</h3>',
        'id' => 'advanced-search-modal',
        'size' => 'modal-md'
    ]);

    echo '<div id="advanced-search-modal-content"></div>';

    Modal::end();
?>