<?php

use yii\helpers\Html;
use yii\widgets\ActiveForm;
use yii\helpers\ArrayHelper;
use kartik\file\FileInput;
use kartik\datetime\DateTimePicker;
use yii\widgets\DetailView;
use yii\grid\GridView;

use yii\helpers\Url;

use yii\data\ActiveDataProvider;
use app\models\Files;

/* @var $this yii\web\View */
/* @var $model app\models\Lots */
/* @var $model app\models\Category */
/* @var $form yii\widgets\ActiveForm */
?>
<div class="lots-form">

    <?php

    $files = new \app\models\Files();

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

    <?= $form->field($model, 'user_id')->hiddenInput(['value' => Yii::$app->user->identity->id]) ?>

    <?= $form->field($model, 'aukname')->dropDownList(ArrayHelper::map(\app\models\Auclots::find()->all(), 'name', 'name')) ?>

    <?= $form->field($model, 'category_id')->dropDownList(ArrayHelper::map(\app\models\Category::find()->all(), 'id', 'name')) ?>

    <?= $form->field($model, 'name')->textInput(['maxlength' => true])->label(Yii::t('app','LotName ID')) ?>

    <?= $form->field($model, 'description')->textarea(['maxlength' => true]) ?>
    <?= $form->field($model, 'bidding_date')->textInput()->widget(DateTimePicker::className(),[
        'name' => 'auction_date',
        'type' => DateTimePicker::TYPE_COMPONENT_PREPEND,
        'value' => date("dd-M-yyyy hh:ii"),
        'pluginOptions' => [
            'autoclose'=>true,
            'format' => 'yyyy-mm-dd hh:ii'
        ]
    ]) ?>

    <?= $form->field($model, 'auction_date')->widget(DateTimePicker::className(),[
        'name' => 'auction_date',
        'type' => DateTimePicker::TYPE_COMPONENT_PREPEND,
        'value' => date("dd-M-yyyy hh:ii"),
        'options' => ['placeholder' => Yii::t('app','CreateAukDate ID')],
        'pluginOptions' => [
            'autoclose'=>true,
            'format' => 'yyyy-mm-dd hh:ii'
        ]
    ]) ?>

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

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

    <?= $form->field($files, 'file')->widget(FileInput::classname(), [
        'model' => $files,
        //'attribute' => 'file',
        'pluginOptions' => [
            'allowedFileExtensions'=>['doc','docx','pdf', 'jpg', 'png', 'zip', 'rar'],
            'initialCaption'=>'*.doc, *.docx, *.pdf, *.jpg, *.png, *zip, *rar',
            'showPreview' => false,
            'showCaption' => true,
            'showRemove' => true,
            'showUpload' => false
        ],
        'options' => ['multiple' => true,],

    ])->label(Yii::t('app','DopDocumentation ID')); ?>

    <?php 
        print_r($model->file);
    ?>

    <?= GridView::widget([
        'dataProvider' => new ActiveDataProvider([
            'query' => Files::find()->where(['lot_id' => $model->id]),
        ]),
        'columns' => [

            'name',
            

            [
                'class' => 'yii\grid\ActionColumn',
                'template' => '{download} {delete}',
                'buttons' => [

                    'download' => function ($url, $model) {
                        return Html::a(
                            'Скачать',
                            Url::to(['files/download', 'id' => $model->id]),
                            ['class' => 'btn btn-success btn-sm']
                        );
                    },

                    'delete' => function ($url, $model) {
                        return Html::a(
                            'Удалить',
                            ['files/delete', 'id' => $model->id],
                            [
                                'class' => 'btn btn-danger btn-sm',
                                'data-confirm' => 'Удалить файл?',
                                'data-method' => 'get',
                            ]
                        );
                    },

                ],
            ],

        ],
    ]); ?>

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

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

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

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

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

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

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

    <?= $form->field($model, 'date')->hiddenInput(['value' => date('Y-m-d H:i:s')]) ?>

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

    <div class="form-group">
        <?= Html::submitButton($model->isNewRecord ? Yii::t('app', 'Create ID') : Yii::t('app', 'Update ID'), ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?>
    </div>

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

</div>
