<?php

use common\components\artboximage\ArtboxImageHelper;
use yii\helpers\Html;
use yii\widgets\ActiveForm;
use common\modules\file\widgets\ImageUploader;
use kartik\select2\Select2;

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

<div class="category-form">

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

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

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

    <?php /*= $form->field($model, 'parent_id')->dropDownList($categories, [
        'prompt' => Yii::t('rubrication', 'Root category'),
        'options' => [
            $model->category_id => ['disabled' => true]
        ]
    ])->label(Yii::t('rubrication', 'Parent category')) */?>

    <?= $form->field($model, 'parent_id')->widget(Select2::className(), [
            'data' => $categories,
            'language' => 'ru',
            'options' => [
                'placeholder' => Yii::t('product', 'Parent category'),
                'multiple' => false,
            ],
            'pluginOptions' => [
                'allowClear' => true
            ],
        ]
    ) ?>

    <?= $form->field($model, 'product_unit_id')->widget(Select2::className(), [
            'data' => \yii\helpers\ArrayHelper::map(\common\modules\product\models\ProductUnit::find()->all(), 'product_unit_id', 'name'),
            'language' => 'ru',
            'options' => [
                'placeholder' => Yii::t('product', 'Select unit'),
                'multiple' => false,
            ],
            'pluginOptions' => [
                'allowClear' => true
            ],
        ]
    ) ?>

    <?php /*
    <?= $form->field($model, 'group_to_category')->dropDownList(
        \yii\helpers\ArrayHelper::map(\common\modules\rubrication\models\TaxGroup::find()->all(), 'tax_group_id', 'name'), [
            'multiple' => true
    ])->label(Yii::t('product', 'Linked options')) ?>
    */?>

    <?= $form->field($model, 'group_to_category')->widget(Select2::className(), [
            'data' => \yii\helpers\ArrayHelper::map(\common\modules\rubrication\models\TaxGroup::find()->all(), 'tax_group_id', 'name'),
            'language' => 'ru',
            'options' => [
                'placeholder' => 'Linked options',
                'multiple' => true,
            ],
            'pluginOptions' => [
                'allowClear' => true
            ],
        ]
    ) ?>

    <?= $form->field($model, 'imageUpload')->widget(\kartik\file\FileInput::classname(), [
        'options' => [
            'accept' => 'image/*',
        ],
        'pluginOptions' => [
            'allowedFileExtensions' => ['jpg','gif','png'],
            'initialPreview' => ArtboxImageHelper::getImage($model->imageUrl ? $model->imageUrl : '', 'product_list'),
            'overwriteInitial' => true,
            'showRemove' => true,
            'showUpload' => false,
        ],
    ]); ?>

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

    <?= $form->field($model, 'meta_desc')->textarea(['rows' => 6]) ?>

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

    <?= $form->field($model, 'seo_text')->textarea(['rows' => 6]) ?>

    <?= $form->field($model, 'remote_category')->widget(Select2::className(), [
            'data' => \yii\helpers\ArrayHelper::map(\common\modules\product\models\RemoteCategories::find()->all(), 'ID', 'Name'),
            'language' => 'ru',
            'options' => [
                'placeholder' => 'Select a remote category',
                'multiple' => true,
            ],
            'pluginOptions' => [
                'allowClear' => true
            ],
        ]
    ) ?>

    <?php if (!empty($model) && $model->depth == 2) :?>
    <?= $form->field($model, 'populary')->checkbox() ?>
    <?php endif?>

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

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

</div>
