<?php

use yii\helpers\Html;
use yii\grid\GridView;
use common\models\Card;
use yii\helpers\Url;
use common\components\Helper;
use common\models\DoorLog;

/* @var $this yii\web\View */
/* @var $searchModel backend\models\CardSearch */
/* @var $dataProvider yii\data\ActiveDataProvider */

$this->title = Yii::t('common/card', 'Cards');
$this->params['breadcrumbs'][] = $this->title;
?>

<style>
	.grid-view a{
		margin-right: 6px;
	}

</style>
<div class="card-index">

    <h1><?= Html::encode($this->title) ?></h1>
    <?php   echo $this->render('_search', ['model' => $searchModel]); ?>

    <p>
        <?= Html::a(Yii::t('common/card', 'Create Card'), ['create'], ['class' => 'btn btn-success']) ?>
    </p>

    <?= GridView::widget([
        'dataProvider' => $dataProvider,
        'columns' => [
            ['class' => 'yii\grid\SerialColumn'],
            [ 
            		'attribute' => 'card_number',
            		'label' => 'Kártyaszám'	
    		],
            [ 
            		'attribute' => 'card_rfid_key',
            		'label' => 'RFID szám'	
    		],
            [ 
            		'attribute' => 'card_status',
            		'label' => 'Státusz',
            		'value' => function ($model, $key, $index, $column){
        			return Card::toStatusName($model['card_status'],'-');
    			}
    		],
            [ 
            		'attribute' => 'card_type',
            		'label' => 'Típus',
            		'value' => function ($model, $key, $index, $column){
        			return Card::toTypeName($model['card_type'],'-');
    			}
    		],
    		[
	    		'attribute' => 'customer_id_customer',
	    		'label' => 'Vendég azonosító'
    		],
    		[
	    		'attribute' => 'customer_name',
	    		'label' => 'Vendég név'
    		],
    		[
	    		'attribute' => 'key_number',
	    		'label' => 'Kulcs száma'
    		],
    		[
	    		'attribute' => 'card_flag',
	    		'label' => 'Info',
	    		'value' => function ($model, $key, $index, $column){
	    				return Helper::getArrayValue(DoorLog::getCardFlagTexts(), $model['card_flag'], "Ismeretlen ok");
    			}
    		],
             

            [
            		'class' => 'yii\grid\ActionColumn',
            		'template' => '{view}{update}',
            		'urlCreator' => function  ($action, $model, $key, $index){
            			$result = "";
            			if ( 'view' == $action ){
            				$result = Url::toRoute(['card/view' , 'id' => $model['card_id_card'] ]);
            			}else if ( 'update' == $action ){
            				$result = Url::toRoute(['card/update' , 'id' => $model['card_id_card'] ]);
            			}
            			return $result;
    				},
    				'buttons' =>[
    						'view' =>   function ($url, $model, $key) {
    							return Html::a("Nézet" ,$url,['class' =>'btn btn-primary btn-xs']);
		    				},
    						'update' =>   function ($url, $model, $key) {
    							return Html::a("Módosít" ,$url,['class' =>'btn btn-primary btn-xs']);
		    				},
    				]
    				],
        ],
    ]); ?>

</div>
