<?php
use yii\helpers\Html;
use yii\widgets\ActiveForm;
use yii\data\SqlDataProvider;

use kartik\widgets\DatePicker;
use app\base\Common;
use app\models\Registration;

$RModel = new Registration;
$RModel->q12rep['pos'] = 'Positives';

$rngtype = ['3' => 'ARV Refill', '1' => 'CD4', '2' => 'Motivational'];
// $rngtype = ['1' => 'CD4', '2' => 'Motivational'];

$this->title = Yii::t('app', Common::getMenuname());
$this->params['breadcrumbs'][] = $this->title;

// if(empty($model->frmdate))
//     $model->frmdate = date('d-m-Y');
// if(empty($model->todate))
//     $model->todate = date('d-m-Y');

$JS = "
    $('#hivstatusreport-reptype').change(function(){
        $('div.help-block').html('');
        $('div.form-group').removeClass('has-success').removeClass('has-error');
        if($(this).val() == 1 || $(this).val() == 9 || $(this).val() == 'pos') {
            $('div.form-group.field-hivstatusreport-rngtype').show();
        } else {
            $('div.form-group.field-hivstatusreport-rngtype').hide();
            $('#hivstatusreport-rngtype').val('');
        }
    });
    $('#hivstatusreport-reptype').trigger('change');
";

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

<div class="attandance-form">
    <h1><?= Html::encode($this->title) ?></h1>
    <div class="panel panel-default">
        <div class="panel-body">
            <div class="row">
                <div class="col-lg-12">
                    <?php
                        $form = ActiveForm::begin(['enableAjaxValidation' => false, 'action' => ['index'], 'method' => 'get', '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>',
                        ];
                    ?>
                    <?= $form->field($model, 'reptype', $template)->dropDownList($RModel->q12rep, ['prompt' => $model->getAttributeLabel("reptype")]) ?>
                    <?= $form->field($model, 'frmdate', $template)->widget(DatePicker::classname(), ['options' => ['placeholder' => $model->getAttributeLabel("frmdate")], 'pluginOptions' => ['autoclose' => true, 'startDate' => '01-01-1900', 'endDate' => '+1y', 'format' => strtolower(Yii::$app->formatter->dateFormat)]]) ?>
                    <?= $form->field($model, 'todate', $template)->widget(DatePicker::classname(), ['options' => ['placeholder' => $model->getAttributeLabel("todate")], 'pluginOptions' => ['autoclose' => true, 'startDate' => '01-01-1900', 'endDate' => '+1y', 'format' => strtolower(Yii::$app->formatter->dateFormat)]]) ?>
                    <?= $form->field($model, 'rngtype', $template)->dropDownList($rngtype, ['prompt' => $model->getAttributeLabel("rngtype")]) ?>
					<div class="form-group">
                        <div class="col-sm-5">
                            <?= Html::label('* Please select the Date range for which Clients are due for a particular service') ?>
                        </div>
					</div>
                    <div class="form-group">
                        <div class="col-sm-offset-5 col-sm-7">
                            <?= Html::submitButton(Yii::t('app', 'Go'), ['class' =>'btn btn-success']) ?>
                        </div>
                    </div>
                    <?php ActiveForm::end(); ?>
                    <?php if(isset($dataProvider)) : ?>
                         <?php if($model->reptype != '1' && $model->reptype != '9' && $model->reptype != 'pos') : ?>
                              <?= $this->render('hivneg', ['dataProvider' => $dataProvider, 'layouttitle' => '', 'allfields' => '']); ?>
                         <?php else: ?>
                              <?= $this->render('hivpos', ['dataProvider' => $dataProvider, 'layouttitle' => '', 'allfields' => '']); ?>
                         <?php endif; ?>
                    <?php endif; ?>
                </div>
                <!-- /.col-lg-6 (nested) -->
            </div>
            <!-- /.row (nested) -->
        </div>
        <!-- /.panel-body -->
    </div>
    <!-- /.panel -->
</div>