<?php

use yii\helpers\Html;
use yii\grid\GridView;
use yii\widgets\Pjax;
/* @var $this yii\web\View */
/* @var $searchModel backend\models\CarSearch */
/* @var $dataProvider yii\data\ActiveDataProvider */

$this->title = Yii::t('app', 'Cars');
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="car-index">

    <h1><?= Html::encode($this->title) ?></h1>

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

    <?php Pjax::begin(); ?>
    <?php // echo $this->render('_search', ['model' => $searchModel]); ?>

    <?= GridView::widget([
        'dataProvider' => $dataProvider,
        'filterModel' => $searchModel,
        'columns' => [
            ['class' => 'yii\grid\SerialColumn'],

            'name',
            [
                'attribute' => 'car_type_id',
                'content' => function ($model) {
                    return $model->carType->name;
                }
            ],
            'model',
            'price_rate',
            'no_of_passenger',
            'color',
            'no_of_doors',
            [
                'attribute' => 'car_image',
                'format' => 'html',
                'label' => 'Photo',
                'value' => function ($data) {
                    if($data->car_image!=null) {
                        return Html::img('uploads/' . $data->car_image,
                            ['width' => '40px', 'height' => '40px', 'class' => 'img-circle']);
                    }
                    else{
                        return Html::img('uploads/avatar.jpg',
                            ['width' => '40px', 'height' => '40px', 'class' => 'img-circle']);
                    }

                },
            ],


            [
                'class' => 'yii\grid\ActionColumn',
                'header' => 'Actions',
                'template' => '{view}',
                'buttons' => [
                    'view' => function ($url, $model) {
                        $url = ['view', 'id' => $model->id];
                        return Html::a('<span class="fas fa fa-money">View</span>', $url, [
                            'title' => 'Cars',
                            'data-toggle' => 'tooltip', 'data-original-title' => 'View',
                            'class' => 'btn btn-info',

                        ]);


                    },


                ]
            ]
        ],
    ]); ?>

    <?php Pjax::end(); ?>

</div>
