<?php

use yii\helpers\ArrayHelper;
use common\components\artboxtree\ArtboxTreeHelper;
use yii\helpers\Html;
use yii\widgets\ActiveForm;
use common\modules\rubrication\models\TaxGroup;
use common\modules\rubrication\models\TaxOption;
use common\modules\rubrication\helpers\RubricationHelper;

/* @var $this yii\web\View */
/* @var $model common\modules\rubrication\models\TaxOption */
/* @var $form yii\widgets\ActiveForm */
?>

<div class="tax-option-form">

    <?php $form = ActiveForm::begin(['options' => ['enctype' => 'multipart/form-data']]); ?>
    <?php if (empty($group->tax_group_id)) :?>
        <?= $form->field($model, 'tax_group_id')->dropDownList(
            ArrayHelper::map(TaxOption::find()->all(), 'tax_group_id', 'name'),
            [
                'prompt' => Yii::t('rubrication', 'Select group'),
            ]
        ) ?>
    <?php else :?>
        <?= $form->field($model, 'tax_group_id')->hiddenInput()->label('') ?>
    <?php endif?>


    <?= $form->field($model, 'name')->textInput(['maxlength' => true]) ?>
<!--    --><?php //require(dirname(__FILE__) .'/value/_fields_'. $group->module .'.php')?>

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

    <?php if ($group->hierarchical) {
        $tree = TaxOption::find()->getTree($model->tax_group_id);
        $form->field($model, 'parent_id')->dropDownList(
        ArtboxTreeHelper::treeMap($tree, 'tax_option_id', 'ValueRenderFlash', '.'),
        [
            'prompt' => Yii::t('rubrication', 'Root level'),
            'options' => [
                $model->tax_option_id => ['disabled' => true]
            ]
        ]);

        }else {

        $form->field($model, 'parent_id')->hiddenInput()->label('');
    }
    ?>


    <?= $form->field($model, 'image')->widget(\kartik\file\FileInput::classname(), [
        'language' => 'ru',
        'options' => [
            'accept' => 'image/*',
            'multiple' => false,
        ],
        'pluginOptions' => [
            'allowedFileExtensions' => ['jpg', 'gif', 'png'],
            'initialPreview' => !empty($model->imageUrl) ? \common\components\artboximage\ArtboxImageHelper::getImage($model->imageUrl, 'list') : '',
            'overwriteInitial' => true,
            'showRemove' => false,
            'showUpload' => false,
            'previewFileType' => 'image',
        ],
    ]); ?>
    <?= $form->field($model, 'sort')->dropDownList(RubricationHelper::SortArray()) ?>

    <div class="form-group">
        <?= Html::submitButton($model->isNewRecord ? Yii::t('rubrication', 'Create') : Yii::t('rubrication', 'Update'), ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?>
        <?php if ($model->isNewRecord) :?>
        <?= Html::submitButton(Yii::t('rubrication', 'Create and continue'), ['name' => 'create_and_new', 'class' =>  'btn btn-primary']) ?>
        <?php endif?>
    </div>

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

</div>
