<?php
use yii\helpers\Html;
use kartik\file\FileInput;
use yii\helpers\Url;

use common\modules\school\models\Courses;

if ($model->image) {
    $image = "<div class='file-widget'>".FileInput::widget([
        'model' => $model,
        'attribute' => 'upload_image',
        'language' => 'en',
        'options' => ['multiple' => false, 'accept' => 'image/*'],
        'pluginOptions' => [/*'uploadUrl' => Url::to(['/school/courses-admin/upload']),*/'showUpload' => false,
            'initialPreview'=>[
                Html::img($model->getUrl($model->image))
            ],
            'overwriteInitial'=>true]
    ])."</div>";
}
else {
    $image = "<div class='file-widget'>".FileInput::widget([
        'model' => $model,
        'attribute' => 'upload_image',
        'language' => 'en',
        'options' => ['multiple' => false, 'accept' => 'image/*'],
        'pluginOptions' => [/*'uploadUrl' => Url::to(['/school/courses-admin/upload']),*/'showUpload' => false,
            'overwriteInitial'=>true]
    ])."</div>";
}

$elements = [
    'title'	=> ['type' => 'text'],
    'description' => ['type' => 'textarea'],
    'description_for_course' => ['type' => 'textarea'],
    'type' => [
        'type' => 'dropdownlist',
        'items' => Courses::$type_list,
    ],
    'spec_proposition'	=> ['type' => 'checkbox'],
    'image'	=> $image,
];


return [
    'activeForm'=>[
        'id' => 'course-form',
        'options' => [
            'enctype' => 'multipart/form-data'
        ],
    ],
    'elements'       => $elements,
    'buttons' => [
        'submit' => ['type' => 'submit', 'value' => 'Cохранить']
    ]
];

