<?php
    
    use yii\helpers\Html;
    use yii\widgets\ActiveForm;
    
    /**
     * @var yii\web\View                    $this
     * @var common\models\CategoryToPurpose $model
     * @var array                           $purposes
     * @var array                           $categories
     * @var ActiveForm                      $form
     **/
?>

<div class="category-to-purpose-form">
    
    <?php $form = ActiveForm::begin([ 'options' => [ 'enctype' => 'multipart/form-data' ] ]); ?>
    
    <?= $form->field($model, 'category_id')
             ->dropDownList($categories) ?>
    
    <?= $form->field($model, 'purpose_id')
             ->dropDownList($purposes) ?>
    
    <?= $form->field($model, 'image')
             ->widget(
                 \kartik\file\FileInput::className(),
                 [
                     'language'      => 'ru',
                     'options'       => [
                         'accept'   => 'image/*',
                         'multiple' => false,
                     ],
                     'pluginOptions' => [
                         'allowedFileExtensions' => [
                             'jpg',
                             'gif',
                             'png',
                         ],
                         'initialPreview'        => !empty( $model->getImageUrl(
                             0,
                             false
                         ) ) ? \common\components\artboximage\ArtboxImageHelper::getImage(
                             $model->imageUrl,
                             'list'
                         ) : '',
                         'overwriteInitial'      => true,
                         'showRemove'            => false,
                         'showUpload'            => false,
                         'previewFileType'       => 'image',
                     ],
                 ]
             ); ?>
    
    <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>
