<?php

use yii\helpers\Html;
use yii\widgets\ActiveForm;

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

<div class="option-values-form">
	
    <?php $form = ActiveForm::begin(); ?>

    <?= $form->field($model, 'option_key')->textInput(['maxlength' => true]) ?>
	
	<div class="optionvalues-option_value_text-active">
	<?= $form->field($model, 'option_value_text', ['enableClientValidation' => false])->label($model->getAttributeLabel('option_key').' | <span class="glyphicon glyphicon-globe add-langs"></span>')->textInput() ?>

    <?= $form->field($model, 'option_language_id')->dropDownList($model->getDropDownArray()) ?>
    </div>

    <?= $form->field($model, 'option_value_parent')->dropDownList($model->getUserOptionsArray()) ?>

    <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>
<div class="reserved_inputs">
    <div class="lang-inputs form-group optionvalues-option_value_text-lang">
    	<label for="OptionValues[option_value_text][0]" class="col-xs-12 optionvalues-option_value_text" data-group="optionvalues-option_value_text"><?php echo $model->getAttributeLabel('option_key'); ?> | <span class="glyphicon glyphicon-globe remove-langs"></span></label>
    	<?php foreach($model->getLanguagesCodes() as $lang) {
    	   ?>
    	   <div class="col-xs-1 text-right"><span><?=$lang['lang_code']?></span></div>
    	   <div class="col-xs-11"><input type="text" id="optionvalues-<?=$lang['lang_code']?>-option_value_text" class="form-control" name="OptionValues[option_value_text][<?=$lang['language_id']?>]" /></div>
    	   <?php
    	}?>
    	<div class="clearfix"></div>
    </div>
</div>
<script>
	$(function() {
		$(document).on('click', '.add-langs', function() {
			var group = $(this).parent().attr('for');
			$(this).parent().parent().appendTo('.reserved_inputs');
			$('.field-optionvalues-option_language_id').appendTo('.reserved_inputs');
			$('.'+group+'-lang').appendTo('.'+group+'-active');
		});
		$(document).on('click', '.remove-langs', function() {
			var group = $(this).parent().data('group');
			$(this).parent().parent().appendTo('.reserved_inputs');
			console.log('field-'+group);
			$('.reserved_inputs .field-'+group).appendTo('.'+group+'-active');
			$('.field-optionvalues-option_language_id').appendTo('.'+group+'-active');
		});
	});
</script>