<?php

use yii\helpers\Url;

use common\modules\testings\widgets\NotCloseTabsWidget;
use common\modules\testings\models\Question;

?>

<?php
	$questions = [];
	$count = 0;
	foreach ($model->questions as $question) 
	{
		$count++;

		$pictures = [];
		foreach ($question->question->files as $file) 
		{
			$pictures[] = $file->url;
		}

		$answers = [];
		// если ответ вводит сам пользователь, нельзя отправлять ответ - поскольку в нём указан верный ответ.

		foreach ($question->question->answers as $answer) 
		{
			if ($question->question->type <> Question::USER_ANSWER) 
			{
				$answers[] = $answer->text;
			} 
			else 
			{
				$answers[] = 'тут должен быть ответ';
			}
		}

		$questions[$count] = [
			'id' => $question->question->id,
			'text' => $question->question->text,
			'type' => $question->question->type,
			'pictures' => $pictures,
			'answers' => $answers,
			'userAnswer' => '',
			'time' => 0,
			'theme' => $question->question->theme->name,
		];

	}
?>


<script type="text/javascript">
	$(function(){

		countDown.init({
			continue: <?=($model->start_date?'true':'false')?>,
			startDate: '<?=date("d F Y H:i:s", strtotime($model->start_date))?>',
			startDateTime: <?=strtotime($model->start_date)?>,
			minutes: <?=$model->test->minutes;?>,
			time: <?=time()?>
		});

		tester.init({
			global_id: <?=$current_answer?>,
			one_option: <?=Question::ONE_OPTION?>,
			few_options: <?=Question::FEW_OPTIONS?>,
			user_answer: <?=Question::USER_ANSWER?>,
			delimiter: '<?=Question::DELIMITER?>',
			questions_count: <?=count($questions)?>,
			questions: <?=\yii\helpers\Json::encode($questions)?>,
			answerUrl: '<?=Url::to(["/testing/set-answer/".$model->id])?>',
			finishUrl: '<?=Url::to(["/testing/finish-test/".$model->id])?>',
			passUrl: '<?=Url::to(["/testing/pass/".$model->id])?>'
		});

		$('#answerBox').on('change','*',tester.answersChangeStatus);
	});
</script>

<section class="top_line_testing">
    <div class="container">
        <div class="row">
            <div class="col-md-12 col-xs-12 col-sm-12">
                <strong>Тест: </strong>
                <p><?=$model->test->name?> | <span id="questionThemeBox"></span></p>
            </div>
        </div>
    </div>
</section>
<section class="testing_block">
    <div class="container">

    	<?= NotCloseTabsWidget::widget() ?>

    	<br>

        <div class="row">
            <div class="col-md-1 col-xs-1 col-sm-2">
                 <span class="testing_num questionNumber"></span>
             </div>
             <div class="col-md-11 col-xs-11 col-sm-10">
                 <h1 class="testing_block_title" id="questionTextBox"></h1>
             </div>
        </div>
        <div class="row">
            <div class="col-md-4 col-xs-4 col-sm-12">
            	<div class="number_questions_img_box" id="questionPictureBox"></div>
            </div>
        </div>
        <div class="row">
            <div class="col-md-12 col-xs-12 col-sm-12">
                <form class="testing_form">
                	<div class="questions" id="answerBox"></div>
                	<div class="answer" id="sendInfoBox"></div>
                    <button id="clickNext" class="testing_form_btn" onClick="tester.nextQuestion(); return false;">Подтвердить ответ</button>
                </form>
            </div>
        </div>
        <div class="row col-md-12 col-xs-12 col-sm-12">
			<h4 class="testing_info_foot" id="messageStep50"></h4>
			<h4 class="testing_info_foot" id="messageStep75"></h4>
			<h4 class="testing_info_foot" id="messageStep100"></h4>
		</div>
    </div>
</section>
<section class="testing_foot">
    <div class="container">
        <div class="row">
            <div class="test_ft clearfix">
            <div class="col-md-6 col-xs-8 col-sm-12">
                <div class="testing_votes">Вопрос <strong class="questionNumber">1</strong> из <strong><?=count($questions)?></strong></div>
                <div class="testing_progress"><div class="testing_progress_proc" id="progressbar" style="width:0%;"></div></div>
            </div>
            <div class="col-md-6 col-xs-4 col-sm-12">
                <div class="testing_time">До конца осталось: <span id="countdown_timer"></span></div>
            </div>
            </div>
        </div>
    </div>
</section>

<?php echo $this->render('@app/views/layouts/footer-testing'); ?>