<?php

use yii\helpers\Html;
use yii\helpers\Url;
use yii\widgets\DetailView;
use yii\bootstrap\Modal;

$this->title = Yii::t('app', 'Training Request') . ' ' . $model->serial_number;

if(Yii::$app->user->identity->role->item_name != 'User'){
    $this->params['breadcrumbs'][] = ['label' => Yii::t('app', 'Training Requests'), 'url' => ['index']];
}

$this->params['breadcrumbs'][] = $this->title;

?>

<div class="training-request-view">

    <h1><?= Html::encode($this->title) ?></h1>
    <?php if(Yii::$app->session->hasFlash('request_rejected')): ?>
        <div class="alert alert-success">
            <a href="#" class="close" data-dismiss="alert" aria-label="close">×</a>
            <?= Yii::$app->session->getFlash('request_rejected') ?>
        </div>
    <?php endif; ?>

    <?php if(Yii::$app->session->hasFlash('request_reactivated')): ?>
        <div class="alert alert-success">
            <a href="#" class="close" data-dismiss="alert" aria-label="close">×</a>
            <?= Yii::$app->session->getFlash('request_reactivated') ?>
        </div>
    <?php endif; ?>
    
    <p>
        <?php 
            if(Yii::$app->user->identity->role->item_name == 'Admin'){
                switch($model->training_request_status){
                    case 'Pending':
                        echo Html::a(Yii::t('app', 'Make Interview'), 
                            ['/interviews/create', 'training_request_id' => $model->id],
                            ['class' => 'btn btn-success btn-expanded']);
                        echo ' ';
                        echo Html::a(Yii::t('app', 'Reject'), 
                            ['#'],
                            [
                                'class' => 'btn btn-black btn-expanded reject-training-request-btn',
                                'value' => Url::to(['reject-training', 'id' => $model->id, 'url' => 'View']),
                            ]);
                    break;
                    case 'Interview':
                        echo Html::a(Yii::t('app', 'Approve'), 
                            ['/trainings/create', 'training_request_id' => $model->id],
                            ['class' => 'btn btn-success btn-expanded']);
                        echo ' ';
                        echo Html::a(Yii::t('app', 'Reject'), 
                            ['#'],
                            [
                                'class' => 'btn btn-black btn-expanded reject-training-request-btn',
                                'value' => Url::to(['reject-training', 'id' => $model->id, 'url' => 'View']),
                            ]);
                    break;
                    case 'Approved':
                        echo Html::a(Yii::t('app', 'Reject'), 
                            ['#'],
                            [
                                'class' => 'btn btn-black btn-expanded reject-training-request-btn',
                                'value' => Url::to(['reject-training', 'id' => $model->id, 'url' => 'View']),
                            ]);
                    break;
                    case 'Rejected':
                        echo Html::a(Yii::t('app', 'Reactivate'), 
                            ['reactivate-request', 'id' => $model->id],
                            [
                                'class' => 'btn btn-info btn-expanded',
                                'data' => ['confirm' => Yii::t('app', 'Are you sure you want to reactivate this request?')]
                            ]);
                    break;
                    case 'Reactivated':
                        echo Html::a(Yii::t('app', 'Make Interview'), 
                            ['/interviews/create', 'training_request_id' => $model->id],
                            ['class' => 'btn btn-success btn-expanded']);
                    break;
                    case 'Finish':
                        echo Html::a(Yii::t('app', 'Print Certificate'), 
                            ['print-certificate', 'id' => $model->id],
                            ['class' => 'btn btn-success btn-expanded']);
                    break;
                }
            }
        ?>
    </p>

    <table class="table table-bordered">
        <tr>
            <th class="grey-color width25"><?= Yii::t('app', 'Full Name') ?></th>
            <td class="width25"><?= $model->full_name ?></td>

            <th class="grey-color width25"><?= Yii::t('app', 'Full Name English') ?></th>
            <td class="width25"><?= $model->full_name_english ?></td>
        </tr>

        <tr>
            <th class="grey-color width25"><?= Yii::t('app', 'Mother Name') ?></th>
            <td class="width25"><?= $model->mother_name ?></td>

            <th class="grey-color width25"><?= Yii::t('app', 'Gender') ?></th>
            <td class="width25"><?= Yii::t('app', $model->gender) ?></td>
        </tr>

        <tr>
            <th class="grey-color width25"><?= Yii::t('app', 'Residence Place') ?></th>
            <td class="width25"><?= $model->residence_place ?></td>
            
            <th class="grey-color width25"><?= Yii::t('app', 'Phone') ?></th>
            <td class="width25"><?= $model->phone ?></td>
        </tr>

        <tr>
            <th class="grey-color width25"><?= Yii::t('app', 'Mobile') ?></th>
            <td class="width25"><?= $model->mobile ?></td>
            
            <th class="grey-color width25"><?= Yii::t('app', 'Alternative Phone Number') ?></th>
            <td class="width25"><?= $model->alternative_phone_number ?></td>
        </tr>

        <tr>
            <th class="grey-color width25"><?= Yii::t('app', 'Educational Degree') ?></th>
            <td class="width25"><?= $model->educational_degree ?></td>
            
            <th class="grey-color width25"><?= Yii::t('app', 'University Name') ?></th>
            <td class="width25"><?= $model->university_name ?></td>
        </tr>

        <tr>
            <th class="grey-color width25"><?= Yii::t('app', 'Faculty') ?></th>
            <td class="width25"><?= $model->faculty ?></td>
            
            <th class="grey-color width25"><?= Yii::t('app', 'Year Of Study') ?></th>
            <td class="width25"><?= Yii::t('app', $model->year_of_study) ?></td>
        </tr>

        <tr>
            <th class="grey-color width25"><?= Yii::t('app', 'Create Date') ?></th>
            <td class="width25"><?= $model->create_date ?></td>

            <th class="grey-color width25"><?= Yii::t('app', 'Serial Number') ?></th>
            <td class="width25"><?= $model->serial_number ?></td>
        </tr>

        <tr>
            <th colspan="2" class="grey-color width50"><?= Yii::t('app', 'Training Request Status') ?></th>
            <td colspan="2" class="width50"><?= Yii::t('app', $model->training_request_status) ?></td>
        </tr>
    </table>

    <table class="table table-bordered">
        <tr>
            <th colspan="3" class="grey-color"><?= Yii::t('app', 'Attached Files') ?></th>
        </tr>
        <tr>
            <th class="width33"><?= Yii::t('app', 'University Training Request') ?></th>
            <th class="width33"><?= Yii::t('app', 'Personal Photo') ?></th>
            <th class="width33"><?= Yii::t('app', 'Identity') ?></th>
        </tr>
        <tr>
            <td class="width33"><?= Html::img("@web/{$model->university_training_request}", ['width' => '50px', 'height' => '50px;', 'id' => 'university-image', 'class' => 'request-image']); ?></td>
            <td class="width33"><?= Html::img("@web/{$model->personal_photo}", ['width' => '50px', 'height' => '50px;', 'id' => 'personal-image', 'class' => 'request-image']); ?></td>
            <td class="width33"><?= Html::img("@web/{$model->identity}", ['width' => '50px', 'height' => '50px;', 'id' => 'identity-image', 'class' => 'request-image']); ?></td>
        </tr>
    </table>
</div>

<?php if($interviews && Yii::$app->user->identity->role->item_name != 'User'): ?>
    <hr>
    <h1><?= Yii::t('app', 'Interviews') ?></h1>
    
    <?= $this->render('/interviews/trainee-interviews', [
        'training_request_model' => $model,
        'interviews' => $interviews
    ]); ?>
<?php endif; ?>


<?php if($trainings && Yii::$app->user->identity->role->item_name != 'User'): ?>
    <hr>
    <h1><?= Yii::t('app', 'Trainings') ?></h1>
    
    <?= $this->render('/trainings/trainee-trainings', [
        'model' => $model,
        'trainings' => $trainings
    ]); ?>
<?php endif; ?>


<?php if($rejections): ?>
    <hr>
    <h1><?= Yii::t('app', 'Rejections History') ?></h1>
    
    <?= $this->render('trainee-rejections-history', [
        'model' => $model,
        'rejections' => $rejections
    ]); ?>
<?php endif; ?>

<?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();
?>

<div class="image-modal" id="university-image-modal">
    <span class="close-image-modal" id="close-university-modal">&times;</span>
    <img class="image-modal-content" id="university-image-large">
</div>

<div class="image-modal" id="personal-image-modal">
    <span class="close-image-modal" id="close-personal-modal">&times;</span>
    <img class="image-modal-content" id="personal-image-large">
</div>

<div class="image-modal" id="identity-image-modal">
    <span class="close-image-modal" id="close-identity-modal">&times;</span>
    <img class="image-modal-content" id="identity-image-large">
</div>

<script>

    var modalUniversity = document.getElementById("university-image-modal");
    var modalPersonal   = document.getElementById("personal-image-modal");
    var modalIdentity   = document.getElementById("identity-image-modal");

    var imgUniversity = document.getElementById("university-image");
    var modalImgUniversity = document.getElementById("university-image-large");
    imgUniversity.onclick = function(){
        modalUniversity.style.display = "block";
        modalImgUniversity.src = this.src;
    }

    var imgPersonal = document.getElementById("personal-image");
    var modalImgPersonal = document.getElementById("personal-image-large");
    imgPersonal.onclick = function(){
        modalPersonal.style.display = "block";
        modalImgPersonal.src = this.src;
    }

    var imgIdentity = document.getElementById("identity-image");
    var modalImgIdentity = document.getElementById("identity-image-large");
    imgIdentity.onclick = function(){
        modalIdentity.style.display = "block";
        modalImgIdentity.src = this.src;
    }

    var spanUniversity = document.getElementById("close-university-modal");
    var spanPersonal   = document.getElementById("close-personal-modal");
    var spanIdentity   = document.getElementById("close-identity-modal");

    spanUniversity.onclick = function() {
        modalUniversity.style.display = "none";
    }

    spanPersonal.onclick = function() {
        modalPersonal.style.display = "none";
    }

    spanIdentity.onclick = function() {
        modalIdentity.style.display = "none";
    }

</script>