<?php

use app\base\Common;
use yii\web\View;
use yii\helpers\Html;
use yii\widgets\ActiveForm;
use kartik\select2\Select2;

/* @var $this yii\web\View */
/* @var $model app\models\Hcvtesting */
/* @var $form yii\widgets\ActiveForm */

$Surveys = Common::getSurvey();
$Locations = Common::getLocations();
$PIDs = Common::getCounselorServicePIDs("hcvtest");
if(Yii::$app->params['SURVEY'] != '') {
	$Locations = Common::getSurlocations(Yii::$app->params['SURVEY']);
}
if(Yii::$app->params['SURVEY'] != '' && Yii::$app->params['LOCATION'] != '') {
	$Locations = Common::getSurlocations(Yii::$app->params['SURVEY']);
	$PIDs = Common::getCounselorServicePIDs("hcvtest", Yii::$app->params['SURVEY'], Yii::$app->params['LOCATION']);
}

$JS = "
	$('.datepicker').datepicker({autoclose: true, startDate: '01-01-1900', endDate: '0', format: '".strtolower(Yii::$app->formatter->dateFormat)."'});

	$('#hcvtesting-hcv_test_q3').change(function(){
		// $('div.form-group').show();
		$('div.help-block').html('');
		$('div.form-group').removeClass('has-success').removeClass('has-error');
		if($(this).val() != 0) {
			$('div.form-group.field-hcvtesting-hcv_test_q4, div.form-group.field-hcvtesting-hcv_test_q5').addClass('required').show();
		} else {
			$('div.form-group.field-hcvtesting-hcv_test_q4, div.form-group.field-hcvtesting-hcv_test_q5,div.form-group.field-hcvtesting-hcv_test_q6').removeClass('required').hide();
			
			$('#hcvtesting-hcv_test_q4, #hcvtesting-hcv_test_q5, #hcvtesting-hcv_test_q6').val('');
		}
	});

	$('#hcvtesting-hcv_test_q5').change(function(){
		// $('div.form-group').show();
		$('div.help-block').html('');
		$('div.form-group').removeClass('has-success').removeClass('has-error');
		if($(this).val() == 1) {
			$('div.form-group.field-hcvtesting-hcv_test_q6').addClass('required').show();
		} else {
			$('div.form-group.field-hcvtesting-hcv_test_q6').removeClass('required').hide();
			
			$('#hcvtesting-hcv_test_q6').val('');
		}
	});

	$('#hcvtesting-hcv_test_q6').change(function(){
		if($(this).val() == 1) {
			showmsg('No HCV Ab test needed');
		}
	});
	$('#hcvtesting-hcv_test_q3, #hcvtesting-hcv_test_q5').trigger('change');
";

$this->registerJs($JS);
?>

<div class="hcvtesting-form">
	<div class="panel panel-default">
		<div class="panel-heading">
			
		</div>
		<div class="panel-body">
			<div class="row">
				<div class="col-lg-12">
					<?php
						$form = ActiveForm::begin(['options' => ['class' => 'form-horizontal']]);
						$template = [
							'labelOptions' => ['class' => 'form-label'],
							'template' => '<div class="col-sm-5">{label}{hint}</div><div class="col-sm-4">{input}{error}</div>',
						];
						$chklist_template = [
							'labelOptions' => ['class' => 'form-label'],
							'template' => '<div class="col-sm-5">{label}{hint}</div><div class="col-sm-4 checkbox-list">{input}{error}</div>',
						];
						$htemplate = [
							'options' => ['tag' => false],
							'template' => '{input}'
						];
						$fmt = str_replace("dd", "d", strtolower(Yii::$app->formatter->dateFormat));
						$fmt = str_replace("mm", "m", $fmt);
						$fmt = str_replace("yyyy", "Y", $fmt);
					?>
					<?= Common::generateControl($form, $model, $template, 'hcv_test_survey', $Surveys, 'survey', 'getCounselorServicePIDs', 'hcvtest') ?>
					<?= Common::generateControl($form, $model, $template, 'hcv_test_loc', $Locations, 'location', '', [Html::getInputId($model, 'hcv_test_survey')]) ?>
					<?= Common::generateControl($form, $model, $template, 'hcv_test_part_id', $PIDs, 'pid', '', [Html::getInputId($model, 'hcv_test_survey'), Html::getInputId($model, 'hcv_test_loc')]) ?>				
										
					<?php if($model->isNewRecord) : ?>					
					 <?= $form->field($model, 'hcv_test_q1', $template)->textInput(['class' => 'form-control datepicker', 'value' => app\base\Converter::toDisplay(date($fmt))]) ?>
					<?php else: ?>	
					 <?= $form->field($model, 'hcv_test_q1', $template)->textInput(['class' => 'form-control datepicker', 'value' => $model->hcv_test_q1,'disabled' => true]) ?>
					<?php endif; ?>	
					
					<?= $form->field($model, 'hcv_test_q2', $chklist_template)->checkboxList($model->q2) ?>
					<?= $form->field($model, 'hcv_test_q3', $template)->textInput(['maxlength' => true, 'data-min' => 0, 'data-max' => 10, 'data-msg' => 'Please double-check that this answer is correct']) ?>
					<?= $form->field($model, 'hcv_test_q4', $template)->textInput(['class' => 'form-control datepicker'])->hint("<strong>INTERVIEWER INSTRUCTIONS:</strong> If client does not know exact date, try and narrow it down to month and year. If client can only narrow it down to a month, select the 15th day in that month. If client can only narrow down to a year, select 1 July of that year.") ?>
					<?= $form->field($model, 'hcv_test_q5', $template)->dropDownList($model->q5, ['prompt'=>'Select']); ?>
					<?= $form->field($model, 'hcv_test_q6', $template)->dropDownList($model->yes_no, ['prompt'=>'Select']); ?>
					<?= $form->field($model, 'hcv_test_q7', $template)->dropDownList($model->yes_no, ['prompt'=>'Select']); ?>
					<?= $form->field($model, 'status', $htemplate)->hiddenInput(['value' => 1])->label() ?>
					<?= $form->field($model, $model->isNewRecord ? 'create_user' : 'update_user', $htemplate)->hiddenInput(['value' => yii::$app->user->identity->id])->label("") ?>
					<div class="form-group">
						<div class="col-sm-offset-5 col-sm-7">
							<?= Html::submitButton($model->isNewRecord ? Yii::t('app', 'Create') : Yii::t('app', 'Update'), ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?>
							<?= Html::a('Cancel', ['/'.Yii::$app->controller->id], ['class' => 'btn btn-default']) ?>
						</div>
					</div>
					<?php ActiveForm::end(); ?>
				</div>
				<!-- /.col-lg-6 (nested) -->
			</div>
			<!-- /.row (nested) -->
		</div>
		<!-- /.panel-body -->
	</div>
	<!-- /.panel -->
</div>