<?php
use yii\helpers\Html;
use yii\widgets\ActiveForm;
use kartik\datetime\DateTimePicker;
use app\widgets\CropperjsWidget;

$form = ActiveForm::begin([
    'id' => 'inquirer-form',
    'options' => ['class' => 'form-horizontal', 'enctype' => 'multipart/form-data']]);

?>
<input type="hidden" name="inquirer[id]" value="<?=$model->id?>">

<div class="container-fluid">
<div class="row">
	<div class="col">
<?
echo $form->field($model, 'text')->textInput([
                    'maxlength' => true,
                    'class' => 'form-control js-word-count-input',
					'placeholder' => 'Вопрос',
//					'id' => 'js-news-content'
                ])->label('Вопрос');
?>
<div class="card">
<div class="card-header">
<h3 class="card-title">Варианты ответов</h3>
</div>
<div class="card-body">
<?
$answers = $model->getAnswers();
foreach($answers as $item){
?>
<div class="info-box answer">
<span class="info-box-icon bg-info"><i class="far fa-thumbs-up"></i><br><span class="info-box-number-cnt"><?=$item->count?></span></span>
<div class="info-box-content">
<div class="input-group">
	<input type="text" class="form-control" value="<?=$item->text?>" name="Inquirer[text_answer][<?=$item->id?>]">
		<div class="input-group-append">
			<span class="btn btn-dark btn-flat"  onclick="remove(this)"><b>-</b></span>
		</div>
</div>
</div>
</div>
<?
}
?>

</div>

<div class="card-footer">
<div class="card-tools">
<button type="button" class="btn btn-outline-primary" onclick="addanswer()"><b>+</b></button>
</div>
</div>

</div>
<div class="form-group form-check">
<?

                //($model->show == 'Y')?true:false,
echo $form->field($model, 'show')->checkbox([
                    'class' => 'form-check-input',
					'label' => 'Включить голосование',
					'uncheck' => 'N',
					'value' => 'Y',
					'checked' => ($model->show == 'Y')?true:false
                ]);
echo $form->field($model, 'active')->checkbox([
                    'class' => 'form-check-input',
					'label' => 'Показывать',
					'uncheck' => 'N',
					'value' => 'Y',
					'checked' => ($model->active == 'Y')?true:false
                ]);

?>
</div>
<div class="form-group">
<?
	echo Html::submitButton('Сохранить', ['class' => 'btn btn-success']);
?>
</div>
</div>
</div>
</div>
<script id="template-answer" type="text/template">
<div class="info-box answer">
<span class="info-box-icon bg-info"><i class="far fa-thumbs-up"></i></span>
<div class="info-box-content">
<div class="input-group">
	<input type="text" class="form-control" value="" name="Inquirer[text_new][]">
		<div class="input-group-append">
			<span class="btn btn-dark btn-flat" onclick="remove(this)"><b>-</b></span>
		</div>
</div>
</div>
</div>
</script>
<script>
	function addanswer(){
		el = document.getElementById('template-answer').innerHTML,
		$(el).appendTo($('.card-body'));
	}
	function remove(el){
		$(el).parent().closest('.answer').remove();
	}
</script>
<style>
.info-box-number-cnt{
	position: absolute;
	bottom: 6px;
	font-size: 17px;
}
</style>
<?
ActiveForm::end();
