<?php

use common\models\Space;
use slavkovrn\lightbox\LightBoxWidget;
use yii\grid\GridView;
use yii\helpers\Html;
use yii\helpers\Url;
use yii\widgets\DetailView;

/* @var $this yii\web\View */
/* @var $model common\models\Space */

$this->title = $model->name;
$this->params['breadcrumbs'][] = ['label' => Yii::t('common', 'Spaces'), 'url' => ['index']];
$this->params['breadcrumbs'][] = $this->title;
?>
<p>
    <?= Html::a(Yii::t('common', '更新空间信息'), ['update', 'id' => $model->id], ['class' => 'btn btn-success']) ?>

    <?= Html::a(Yii::t('common', 'Create Goods Index'), ['/goods-index/create','entity' => Space::className(),'entity_id'=>$model->id,'origin'=>Yii::$app->request->url], ['class' => 'btn btn-success', 'title' => Yii::t('common', 'Create Goods Index'), 'target' => '_blank']) ?>


    <?= Html::a(Yii::t('common', '删除空间'), ['delete', 'id' => $model->id], [
        'class' => 'btn btn-danger',
        'data' => [
            'confirm' => Yii::t('common', 'Are you sure you want to delete this item?'),
            'method' => 'post',
        ],
    ]) ?>
</p>


<div class="nav-tabs-custom">
    <ul class="nav nav-tabs">
        <li class="active"><a href="#tab_1" data-toggle="tab" aria-expanded="true">空间信息</a></li>
        <li><a href="#tab_2" data-toggle="tab" aria-expanded="true">关联商品</a></li>
    </ul>
    <div class="tab-content">
        <div class="tab-pane active" id="tab_1">

<!--            空间详情信息-->
            <?= DetailView::widget([
                'model' => $model,
                'attributes' => [
                    'id',

                    [
                        'attribute' => 'cover',
                        'format' => 'raw',
                        'value' => function ($model){
                            $images = [               // images at popup window of prettyPhoto galary
                                1 => [
                                    'src' => $model->cover,
                                    'title' => '',
                                ],
                            ];
                            return $model->cover ?  LightBoxWidget::widget([
                                'id'     =>'cover',  // id of plugin should be unique at page
                                'class'  =>'galary',    // class of plugin to define style
                                'height' =>'100px',     // height of image visible in widget
                                'width' =>'100px',      // width of image visible in widget
                                'images' => $images,
                            ]) : null;
                        }
                    ],
                    [
                        'attribute' => 'banner',
                        'format' => 'raw',
                        'value' => function ($model){
                            $images = [];
                            foreach ($model->banner as $index=>$banner) {
                                $images[$index] = ['src'=>$banner, 'title'=>''];
                            }
                            return $model->banner ?  LightBoxWidget::widget([
                                'id'     =>'banner',  // id of plugin should be unique at page
                                'class'  =>'galary',    // class of plugin to define style
                                'height' =>'100px',     // height of image visible in widget
                                'width' =>'100px',      // width of image visible in widget
                                'images' => $images,
                            ]) : null;
                        }
                    ],
                    [
                        'attribute' => 'picture',
                        'format' => 'raw',
                        'value' => function ($model){
                            $images = [];
                            foreach ($model->picture as $index=>$picture) {
                                $images[$index] = ['src'=>$picture, 'title'=>''];
                            }
                            return $model->picture ?  LightBoxWidget::widget([
                                'id'     =>'picture',  // id of plugin should be unique at page
                                'class'  =>'galary',    // class of plugin to define style
                                'height' =>'100px',     // height of image visible in widget
                                'width' =>'100px',      // width of image visible in widget
                                'images' => $images,
                            ]) : null;
                        }
                    ],
                    [
                        'attribute' => 'vid',
                        'format' => 'raw',
                        'value' => function ($model){
                            return '<iframe frameborder="0" src="https://v.qq.com/txp/iframe/player.html?vid='.$model->vid.'" allowFullScreen="true"></iframe>';
                        }
                    ],
                    'name',
                    'desc',
                    [
                        'attribute' => 'province',
                        'format' => 'raw',
                        'value' => function ($model) {
                            return \common\models\Region::getNameById($model->province);
                        },
                    ],
                    [
                        'attribute' => 'city',
                        'format' => 'raw',
                        'value' => function ($model) {
                            return \common\models\Region::getNameById($model->city);
                        },
                    ],
                    [
                        'attribute' => 'area',
                        'format' => 'raw',
                        'value' => function ($model) {
                            return \common\models\Region::getNameById($model->area);
                        },
                    ],
                    'address',
                    'contacts',
                    'tel',
                    'created_at:datetime',
                    'updated_at:datetime',
                    [
                        'attribute' => 'status',
                        'value' => function ($model) {
                            return  Space::getStatusList($model->status);
                        },
                    ],
                ],
            ]) ?>

        </div>

<!--        管理商品列表管理-->
        <div class="tab-pane " id="tab_2">
            <?= GridView::widget([
                'dataProvider' => $index['data'],
                //'filterModel' => $searchModel,
                'columns' => [
                    'id',
                    'goods_id',
                    'entity',
                    'entity_id',
                    'attribute',



                    [
                        'class' => 'common\helpers\DiyActionColumn',
                        'template' => '{update} {delete}',
                        'buttons' => [
                            'update' => function ($url, $model, $key) {
                                return Html::a(Yii::t('yii', 'Update'), Url::to(['/goods-index/update', 'id' => $model->id,'origin'=>Yii::$app->request->url]), [
                                    'class' => 'btn btn-success btn-xs',
                                    'title' => Yii::t('common', 'Update Goods Index'),
                                    'target' => '_blank'
                                ]);
                            },
                            'delete' => function ($url, $model, $key) {
                                return Html::a('删除', Url::to(['/goods-index/delete', 'id' => $model->id,'origin'=>Yii::$app->request->url]), [
                                    'class' => 'btn btn-success btn-xs',
                                    'title' => Yii::t('common', '删除关联商品'),
                                    'data-confirm' => Yii::t('yii', 'Are you sure you want to delete this item?'),
                                    'data-method' => 'post',
                                ]);
                            },
                        ],
                    ],
                ],
            ]); ?>
        </div>

    </div>
</div>

