<?php

use yii\helpers\Html;
use yii\widgets\DetailView;
use yii\widgets\ActiveForm;
use kartik\file\FileInput;
use dosamigos\gallery\Gallery;

/* @var $this yii\web\View */
/* @var $model app\models\Publishing */

$this->title = $model->name;
$this->params['breadcrumbs'][] = ['label' => Yii::t('app', 'Auction ID'), 'url' => ['index']];
$this->params['breadcrumbs'][] = $this->title;
?>

<div class="container">
    <div class="panel panel-primary">
        <div class="panel-heading"><span class="glyphicon glyphicon-stats"></span><strong>
                <?= Html::encode(Yii::t('app','PublishAuctionMessage ID')." ".$model->name/*.' / '.Yii::t('app','Lot ID')*/.' #'.$model->lot_num) ?></strong></div>
        <div class="panel-body">

            <div class="publishing-view">

                <div class="row">

                    <div class="col-md-6">
                        <div class="well well-sm">

                            <h5><strong><?= Yii::t('app','PublishLotInfo ID') ?></strong></h5>

                            <?= DetailView::widget([
                                'model' => $model,
                                'attributes' => [
                                    'lotName',
                                    'lotDesc',
                                    'lotPrice',
                                    'lotStep',
                                    'statusName',
                                    [
                                        'attribute' => 'lot.count',
                                        'value' => $model->lot->count,
                                        'visible' => $model->lot->count,
                                    ],
                                    [
                                        'attribute' => 'lot.price_per_one',
                                        'value' => $model->lot->count ? ($model->lot->start_price / $model->lot->count) . ' грн' : '',
                                        'visible' => $model->lot->unitId ? true : false,
                                    ],
                                    [
                                        'attribute' => 'lot.unitName',
                                        'value' => $model->lot->unitId ? $model->lot->unit->name : '',
                                        'visible' => $model->lot->unitId ? true : false,
                                    ],
                                ],
                            ]) ?>
                        </div>

                    </div>

                    <div class="col-md-6">
                        <div class="well well-sm">
                            <h5><strong><?= Yii::t('app','PublishAucInfo ID') ?></strong></h5>

                            <?= DetailView::widget([
                                'model' => $model,
                                'attributes' => [
                                    //'created_at:datetime',
                                    'endBidding',
                                    'date_start',
                                ],
                            ]) ?>
                        </div>
                        <div>
                            <?php
                            $items = [];
                            $thumbnails = $model->lot->thumbnails;
                            $images = $model->lot->images;

                            foreach($images as $index => $image){
                                $items[] = [
                                    'src' => '/' . $thumbnails[$index]->path,
                                    'url' => '/'.$images[$index]->path,
                                ];
                            }
                            ?>
                            <!-- <?/*='<pre>';*/?>
                          --><?php /*print_r($items);die(); */?>
                            <?= Gallery::widget(['items' => $items]);?>
                        </div>
                    </div>


                </div>


                <div class="row">
                    <div class="col-md-12">
                        <div class="well well-sm">

                            <h5><strong><?= Yii::t('app','PublishMemReq ID') ?></strong></h5>

                            <?= DetailView::widget([
                                'model' => $model->lot,
                                'attributes' => [
                                    [
                                        'attribute' => 'member_require',
                                        'label'    =>  Yii::t('app','MemberRequire ID'),
                                    ],
                                    'term_procedure',
                                    /*[
                                        'attribute' => 'member_docs',
                                        'label'    =>  '',
                                    ],*/
                                ],
                            ]) ?>
                            <?= DetailView::widget([
                                'model' => $model->lot,
                                'attributes' => [
                                    [
                                        'attribute' => 'address',
                                        'label'    =>  Yii::t('app','AddressTo ID'),
                                    ],
                                    'payment_term',
                                    'notes',
                                    //'delivery_time',
                                    //'delivery_term',
                                ],
                            ]) ?>

                            <h5><strong><?= Yii::t('app','PublishFiles ID') ?></strong></h5>

                            <?= $this->render('_alert.php') ?>
                            <?php
                            if(isset($model->lot->docs_id))
                            {
                                $docs = Html::a(Yii::t('app','Download ID'), ['/files/download','id'=> $model->lot->docs_id], ['class' => 'glyphicon glyphicon-circle-arrow-down row1']);
                            }
                            if(empty($docs)) { $docs = null;}
                            $dogovor = Html::a(Yii::t('app','Download ID'), ['/files/download','id'=> $model->lot->dogovor_id], ['class' => 'glyphicon glyphicon-circle-arrow-down row1']);
                            ?>
                            <?= DetailView::widget([
                                'model' => $model->lot,
                                'attributes' => [
                                    [
                                        'attribute' => 'docs_id',
                                        'value'  =>  $docs,
                                        'format' => 'raw',
                                    ],
                                    [
                                        'attribute' => 'dogovor_id',
                                        'value'  =>  $dogovor,
                                        'format' => 'raw',
                                    ]
                                ],
                            ]) ?>
                            <?php

                            $protocol = $model->getProtocol();

                            if(Yii::$app->user->can('admin'))
                            {
                                if(!$protocol&&$model->status==3)
                                {
                                    echo Html::a(Yii::t('app','CreateDoc ID'), ['/publishing/doc','id'=> $model->id], ['class' => 'glyphicon glyphicon-circle-arrow-up']);
                                    $form = ActiveForm::begin([
                                        'options'=>['enctype'=>'multipart/form-data'] // important
                                    ]);
                                    $files = new \app\models\Files();
                                    echo $form->field($files, 'file')->widget(FileInput::classname(),[
                                        'model' => $files,
                                        'options' => ['multiple' => false],
                                        'pluginOptions' => ['showPreview' => false,],
                                    ])->label(Yii::t('app','DownloadProtocol ID'));
                                    ActiveForm::end();
                                }
                            }
                            if($protocol)
                            {
                                //echo Html::a($protocol['name'],'/files/download?id='.$protocol['id'],['class'=>'btn btn-link']);
                                echo Html::a(Yii::t('app','DownloadProtocol ID'), ['/files/download','id'=> $protocol['id']], ['class' => 'glyphicon glyphicon-circle-arrow-down']);
                            }

                            ?>
                        </div>
                    </div>
                </div>
                <div class="row"><div class="col-md-12">
                        <!-- <button id="" type="button" class="btn btn-primary" href="javascript:/" onclick="window.close();" role="button"><span class="glyphicon glyphicon-eye-close"></span> Закрити вікно</button> -->

                        <a id="btnPubLot" type="button" class="btn btn-primary" href="/lots/view?id=<?php echo $model->lot->id;?>" role="button"><?= Yii::t('app','GoToBid ID')?><span class="glyphicon glyphicon-chevron-right"></span></a>
                        <a id="btnPubLot" type="button" class="btn btn-success" href="/auctions/view?id=<?php echo $model->id;?>" role="button"><?= Yii::t('app','GoToAuction ID')?><span class="glyphicon glyphicon-chevron-right"></span></a>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

