<?php

use yii\helpers\Html;
use yii\grid\GridView;
use yii\helpers\Url;

/* @var $this yii\web\View */
/* @var $dataProvider yii\data\ActiveDataProvider */

$this->title = 'Bookings';
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="booking-index">

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

    <p>
        <?= Html::a('Create Booking', ['create'], ['class' => 'btn btn-success']) ?>
        <?= Html::a('Calendar View', ['calendar/index'], ['class' => 'btn btn-primary']) ?>
    </p>

    <?= GridView::widget([
        'dataProvider' => $dataProvider,
        'columns' => [
            'booking_reference',
            'customer_name',
            'customer_email:email',
            [
                'attribute' => 'instructor_id',
                'value' => function($model) {
                    return $model->instructor ? $model->instructor->name : '';
                },
                'label' => 'Instructor',
            ],
            [
                'attribute' => 'sport_id',
                'value' => function($model) {
                    return $model->sport ? $model->sport->name : '';
                },
                'label' => 'Sport',
            ],
            'lesson_date:date',
            'start_time',
            'duration_minutes',
            'participants',
            [
                'attribute' => 'status',
                'format' => 'raw',
                'value' => function($model) {
                    $class = [
                        'pending' => 'warning',
                        'confirmed' => 'success',
                        'completed' => 'secondary',
                        'cancelled' => 'danger',
                        'no_show' => 'dark'
                    ][$model->status] ?? 'secondary';
                    
                    return '<span class="badge badge-' . $class . '">' . ucfirst($model->status) . '</span>';
                },
            ],
        ],
    ]) ?>
</div>
