<?php

use yii\helpers\Html;
use yii\helpers\Url;
use yii\helpers\ArrayHelper;
use yii\widgets\ActiveForm;
use backend\models\Departments;
use backend\models\User;
use mihaildev\ckeditor\CKEditor;
use pavlinter\multifields\MultiFields;

/* @var $this yii\web\View */
/* @var $model backend\models\Team */
/* @var $form yii\widgets\ActiveForm */
?>

<div class="team-form">

    <?php $form = ActiveForm::begin(['options' => ['enctype' => 'multipart/form-data', 'id' => 'team-form']]); ?>

	<?= $form->errorSummary([$model,reset($skills)],['class' => 'alert alert-danger']); ?>

	<?= $form->field($model, 'department_id')->dropDownList(
		ArrayHelper::map(
			Departments::find()->all(),
			'id',
			'title'
		)
	) ?>

    <?= $form->field($model, 'user_id')->dropDownList(
	    ArrayHelper::map(
		    User::find()->all(),
		    'id',
		    'username'
	    ), ['prompt' => Yii::t('yii', '(not set)')]
    ) ?>

    <?= $form->field($model, 'name')->textInput(['maxlength' => true]) ?>

    <?= $form->field($model, 'name2')->textInput(['maxlength' => true]) ?>

    <?= $form->field($model, 'email')->textInput(['maxlength' => true]) ?>

    <?= $form->field($model, 'job')->textInput(['maxlength' => true]) ?>

    <?= $form->field($model, 'zodiac')->dropDownList([ 'aries' => 'Aries', 'taurus' => 'Taurus', 'gemini' => 'Gemini', 'cancer' => 'Cancer', 'leo' => 'Leo', 'virgo' => 'Virgo', 'libra' => 'Libra', 'scorpio' => 'Scorpio', 'sagittarius' => 'Sagittarius', 'capricorn' => 'Capricorn', 'aquarius' => 'Aquarius', 'pisces' => 'Pisces'], ['prompt' => '']) ?>

    <?= $form->field($model, 'iq')->textInput() ?>

    <?= $form->field($model, 'soc_vk')->textInput(['maxlength' => true]) ?>

    <?= $form->field($model, 'soc_fb')->textInput(['maxlength' => true]) ?>

    <?= $form->field($model, 'soc_tw')->textInput(['maxlength' => true]) ?>

    <?= $form->field($model, 'soc_li')->textInput(['maxlength' => true]) ?>

    <?= $form->field($model, 'interests_caption')->widget(CKEditor::className(),[
	    'editorOptions' => [
		    'preset' => 'basic',
		    'inline' => false,
	    ],
    ]);
    ?>

	<fieldset>
		<legend><?= Yii::t('app', 'Skils')?></legend>
    <?= $form->field($model, 'skils_caption')->widget(CKEditor::className(),[
	    'editorOptions' => [
		    'preset' => 'basic',
		    'inline' => false,
	    ],
    ]);
    ?>
		<div class="form-group">
			<?= MultiFields::widget([
				'models' => $skills,
				'form' => $form,
				'attributes' => [
					[
						'attribute' => 'title',
						'options'=> [],
						'field' => function ($activeField, $skills, $parentClass, $closeButtonClass) {
							return $activeField->textInput($skills);
						},
					],
					[
						'attribute' => 'value',
						'options'=> [],
						'field' => function ($activeField, $skills, $parentClass, $closeButtonClass) {
							return $activeField->textInput($skills);
						},
					],
				],
				//default
				'parentClassPrefix' => '-mf-row',
				'closeButtonClass' => 'mf-btn-close pull-right',
				'clientOptions' => [
					'btn' => '.cloneBtn',
					'appendTo' => '',
					'confirmMessage' => Yii::t('yii' , 'Are you sure you want to delete this item?'),
					'deleteRouter' => Url::to('deleteskill'),
				],
				'template' => function($parentOptions, $closeButtonClass, $templateFields){ //default
					$closeBtn = Html::tag('a', '&times;', ['class' => $closeButtonClass, 'href' => 'javascript:void(0)']);
					return Html::tag('div', $closeBtn . $templateFields, $parentOptions);
				},
			]);?>

			<?= \yii\bootstrap\Button::widget([
				'label' => 'Add skill',
				'options' => [
					'class' => 'cloneBtn'
				]
			]);?>
		</div>
	</fieldset>

	<fieldset>
		<legend><?= Yii::t('app', 'Books')?></legend>
		<?= $form->field($model, 'films_caption')->widget(CKEditor::className(),[
			'editorOptions' => [
				'preset' => 'basic',
				'inline' => false,
			],
		]);
		?>
		<div class="form-group">
			<?= MultiFields::widget([
				'models' => $books,
				'form' => $form,
				'attributes' => [
					[
						'attribute' => 'title',
						'options'=> [],
						'field' => function ($activeField, $books, $parentClass, $closeButtonClass) {
							return $activeField->textInput($books);
						},
					],
					[
						'attribute' => 'cover',
						'options'=> [],
						'field' => function ($activeField, $books, $parentClass, $closeButtonClass) {
							return $activeField->fileInput();
						},
					],
				],
				//default
				'parentClassPrefix' => '-mf-row',
				'closeButtonClass' => 'mf-btn-close pull-right',
				'clientOptions' => [
					'btn' => '.cloneBtn',
					'appendTo' => '',
					'confirmMessage' => Yii::t('yii' , 'Are you sure you want to delete this item?'),
					'deleteRouter' => Url::to('deletebook'),
				],
				'template' => function($parentOptions, $closeButtonClass, $templateFields){ //default
					$closeBtn = Html::tag('a', '&times;', ['class' => $closeButtonClass, 'href' => 'javascript:void(0)']);
					return Html::tag('div', $closeBtn . $templateFields, $parentOptions);
				},
			]);?>

			<?= \yii\bootstrap\Button::widget([
				'label' => 'Add book',
				'options' => [
					'class' => 'cloneBtn'
				]
			]);?>
		</div>
	</fieldset>

    <?= $form->field($model, 'description')->widget(CKEditor::className(),[
	    'editorOptions' => [
		    'preset' => 'basic',
		    'inline' => false,
	    ],
    ]);
    ?>

	<?= $form->field($model, 'file')->fileInput() ?>
	<?php if (!empty($model->photo)) :?>
		<?= Html::img('/files/'. $model->photo, ['style' => 'max-width: 150px; max-height: 200px'])?>
		<br><br>
	<?php endif?>

	<?= $form->field($model, 'file2')->fileInput() ?>
	<?php if (!empty($model->photo_big)) :?>
		<?= Html::img('/files/'. $model->photo_big, ['style' => 'max-width: 150px; max-height: 200px'])?>
		<br><br>
	<?php endif?>

	<?= $form->field($model, 'visible')->dropDownList([1=>Yii::t('app', 'Active'),0=>Yii::t('app', 'Hidden')]) ?>

    <div class="form-group">
        <?= Html::submitButton($model->isNewRecord ? Yii::t('app', 'Create') : Yii::t('app', 'Update'), ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?>
    </div>

    <?php ActiveForm::end(); ?>

</div>
