<?php

use yii\helpers\Html;
use common\widgets\GridView;

/* @var $this yii\web\View */
/* @var $searchModel frontend\models\DT142Search */
/* @var $dataProvider yii\data\ActiveDataProvider */
    $this->title = $searchModel->formname;
    $serviceForm = in_array($searchModel->form, ['ServiceLifeRaft','ServiceLifeJacket','ServiceLifeJacketBulk']) ? true : false;
	$regForm = in_array($searchModel->form, ['qrreg','register']) ? true : false;
	$BookingForm = in_array($searchModel->form, ['bookservice']) ? true : false;	
?>
<div class="forms-index">

    <?= GridView::widget([
        'new' => '&nbsp;', //Html::a('New', ['/forms/'.$searchModel->form.'/create'], ['class' => 'btn btn-success']),
        'title' => $this->title,
        'dataProvider' => $dataProvider,
        'filterModel' => $searchModel,
        'columns' => [
           // 'id',
            'form',
            'status',
            [
                'label' => 'Email',
                'attribute' => '',
                'value' => 'data.email',
                'visible' => $BookingForm || $regForm,
            ],
			
			[
                'label' => 'Certificate Number',
                'attribute' => 'dcertno',
                'value' => function($dataModel){
                    return json_decode($dataModel->data)->certno;
                },
                'visible' => $serviceForm,
            ],
			
            [
                'label' => 'Serial Number',
                'attribute' => 'dserialno',
                
                'value' => function($dataModel){
                    return json_decode($dataModel->data)->serial_number;
                },
                'visible' => $serviceForm
            ],
            [
                'label' => 'Bay',
                'attribute' => 'dbay',                
                'value' => 'activityitem.bay',
                'visible' => $serviceForm
            ],
            [
                'label' => 'Agent Name',
                'attribute' => 'dagentname',
                'value' => function($dataModel){
                    return json_decode($dataModel->data)->agent;
                },
                'visible'=> $serviceForm,
            ],
            [
                'label' => 'Date',
                'value' => function($dataModel){
                    return json_decode($dataModel->data)->date_of_service;
                },
                'visible'=> $serviceForm,
            ],
            [
                'class' => common\widgets\TraceabilityColumn::class,
                'attribute' => 'traceability',
                'format'=> 'raw',
            ],
            [
                'class' => 'common\widgets\ActionColumn',
                'template' => '{view} {update} {delete}',
  			    'buttons' => [
                    'update' => function ($url, $model, $key) {
                        return Html::a('<i class="fa fa-pencil"></i>', $url);
                    },
                    'view' => function ($url, $model, $key) use ($searchModel){
                        return Html::a('<i class="fa fa-eye"></i>', ['/forms/view', 'id' => $model->id, 'form' => $model->form]);
                    },
                    'delete' => function ($url, $model, $key) use ($searchModel) {
                        return Html::a('<i class="fa fa-trash"></i>', ['/forms/delete', 'id' => $model->id, 'form' => $model->form], ['data-method' => 'POST']);
                    },
				],
            ]
        ],
    ]); ?>

</div>
