<?php

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

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

$Surveys = Common::getSurvey();
$Locations = Common::getLocations();
$PIDs = Common::getCounselorServicePIDs("hivcaretest");
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("hivcaretest", 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)."'});
	
	$('#hivcounseling-hiv_counseling_part_id').on('select2:select', function (evt) {
		var pid = $(this)[0].value;		
		if(pid != '') {
			var link = $('#pid-info').data('link') + pid;			
			$.ajax({
				type: 'post',
				url: 'hivcont',
				data: 'pid='+$(this)[0].value,
				success: function(response) {
                    			
					if(response.hiv_continuum_q8 != null) {
						
						$('#hivcounseling-hiv_counseling_q2').val(response.hiv_continuum_q8);
						
						
					} else {
						$('#hivcontinuum-hiv_counseling_q2').val('');						
						
					}
					
				}
			});
		}
	});
	
	$('#hivcounseling-hiv_counseling_part_id').on('select2:select', function (evt) {
		var pid = $(this)[0].value;
		if(pid != '') {
			var link = $('#pid-list').data('link') + pid;
			$('#pid-list').attr('link', link);
			$('#pid_list').load(link);
			var link = $('#pid-info').data('link') + pid;
			$('#pid-info').removeClass('hidden');
			$('#pid-info').attr('link', link);			
		}
	});

	$('#hivcounseling-hiv_counseling_part_id').on('select2:unselect', function (evt) {
		$('#pid_list').html('');		
	});

";

$this->registerJs($JS);


?>

<div class="hivcounseling-form">
	<div class="panel panel-default">
		<div class="panel-heading">
			
		</div>
		<div class="panel-body">
			<div class="row">
				<div class="col-lg-12">
					<?php
					    $ajaxdata['hiv_counseling_part_id'] = '';
						// $form = ActiveForm::begin(['enableAjaxValidation' => true,'options' => ['class' => 'form-horizontal']]);
						$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>',
						];
						$template_icon = [
							'labelOptions' => ['class' => 'form-label'],
							'template' => '<div class="col-sm-5">{label}{hint}</div><div class="col-sm-4">{input}{error}</div><a id = "pid-info" class="btn btn-warning hidden" href="#" link="'.Url::toRoute(['/hivcounseling', 'ajaxload' => true, 'HivcounselingSearch' => $ajaxdata]).'" header="List" data-link="'.Url::toRoute(['/hivcounseling', 'ajaxload' => true, 'HivcounselingSearch' => $ajaxdata]).'" data-toggle="modal" data-target="#modal-popup">'.FA::icon('info-circle').'</a>',
						]; 
						
						$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}'
						];
					?>
					<?= Common::generateControl($form, $model, $template, 'hiv_counseling_survey', $Surveys, 'survey', 'getCounselorServicePIDs', 'hivcaretest') ?>
					<?= Common::generateControl($form, $model, $template, 'hiv_counseling_loc', $Locations, 'location', '', [Html::getInputId($model, 'hiv_counseling_survey')]) ?>
					<?= Common::generateControl($form, $model, $template_icon, 'hiv_counseling_part_id', $PIDs, 'pid', '', [Html::getInputId($model, 'hiv_counseling_survey'), Html::getInputId($model, 'hiv_counseling_loc')]) ?>
					
					<?= $form->field($model, 'hiv_counseling_q1', $template)->dropDownList($model->q1, ['prompt' => 'Select']) ?>
					<?= $form->field($model, 'hiv_counseling_q2', $template)->textInput(['maxlength' => true])->hint("<strong>INTERVIEWER INSTRUCTION :</strong> This comes from the Client's Self Reported ART adherence (from 0% to 100%) at the most recent cohort study visit <br> <strong> Note: </strong> This will be missing for clients who are not enrolled in the cohort.") ?>
					<?= $form->field($model, 'hiv_counseling_q3', $template)->textarea(['maxlength' => true,'rows' => '4'])->hint("<strong>INTERVIEWER INSTRUCTION :</strong> For ART clients, this is adherence to medications; For pre ART clients, this is adherence to clinic appointments.") ?>
					<?= $form->field($model, 'hiv_counseling_q4', $template)->textarea(['maxlength' => true,'rows' => '4']) ?>
					<?= $form->field($model, 'hiv_counseling_q5', $template)->textarea(['maxlength' => true,'rows' => '4']) ?>
					<?= $form->field($model, 'hiv_counseling_q6', $template)->textarea(['maxlength' => true,'rows' => '4']) ?>
					<?= $form->field($model, 'hiv_counseling_q7', $template)->dropDownList($model->q7, ['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>