<?php

use common\models\Interview;
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\Interview */

$this->title = $model->title;
$this->params['breadcrumbs'][] = ['label' => Yii::t('common', 'Interviews'), '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 Interview Log'), ['/interview-log/create', 'interview_id' => $model->id, 'origin' => Yii::$app->request->url], ['class' => 'btn btn-success', 'title' => Yii::t('common', 'Create Interview Log'), 'target' => '_blank']) ?>
    <?= Html::a(Yii::t('common', 'Create Goods Index'), ['/goods-index/create', 'entity' => Interview::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>
        <li><a href="#tab_3" 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>';
                        }
                    ],
                    [
                        'attribute' => 'compere_id',
                        'format' => 'raw',
                        'value' => function ($model) {
                            if (!empty($model->compere)) {
                                return Html::a($model->compere->name, \yii\helpers\Url::to(['/compere/view', 'id' => $model->compere_id]), ['title' => '详情', 'target' => '_blank']);
                            } else {
                                return '无';
                            }
                        },
                    ],

                    [
                        'attribute' => 'master_id',
                        'format' => 'raw',
                        'value' => function ($model) {
                            if (!empty($model->master)) {
                                return Html::a($model->master->name, \yii\helpers\Url::to(['/master/view', 'id' => $model->master_id]), ['title' => '详情', 'target' => '_blank']);
                            } else {
                                return '无';
                            }
                        },
                    ],

                    'title',
                    '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',
                    'created_at:datetime',
                    'updated_at:datetime',
                    [
                        'attribute' => 'status',
                        'value' => function ($model) {
                            return Interview::getStatusList($model->status);
                        },
                    ],
                ],
            ]) ?>
        </div>
        <!--        访谈记录-->
        <div class="tab-pane " id="tab_2">
            <?= GridView::widget([
                'dataProvider' => $log['data'],
                'columns' => [
                    'id',
                    'interview_id',
                    'type',
                    'content',
                    'created_at',
                    'updated_at',
                    'status',

                    [
                        'class' => 'common\helpers\DiyActionColumn',
                        'template' => '{update} {delete}',
                        'buttons' => [
                            'update' => function ($url, $model, $key) {
                                return Html::a(Yii::t('yii', 'Update'), Url::to(['/interview-log/update', 'id' => $model->id, 'origin' => Yii::$app->request->url]), [
                                    'class' => 'btn btn-success btn-xs',
                                    'title' => Yii::t('common', 'Update Interview Log'),
                                    'target' => '_blank'
                                ]);
                            },
                            'delete' => function ($url, $model, $key) {
                                return Html::a('删除', Url::to(['/interview-log/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 class="tab-pane " id="tab_3">
            <?= 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>