<?php /** @noinspection PhpUnhandledExceptionInspection */

use common\modules\event\models\timetable\TimeTableSearch;

/* @var $this yii\web\View */
/* @var $tableHeaders string */
/* @var $model TimeTableSearch */
/* @var $tableModel TimeTableModel */

$tableModel = $model->tableModel;
$timeTable = $model->tableModel->timeTableMonth;

use common\modules\event\models\timetable\TimeTableModel;
use common\modules\event\widgets\timetable\TimeTableMonthView;
use yii\helpers\Html;
use yii\helpers\Url;

?>
<h1>Órarend</h1>
<?php echo $this->render('_timetable_search', ['model' => $model]); ?>
<h2>
    <?= $timeTable->interval->firstActiveDate->format('Y') ?>
    -
    <?= $timeTable->interval->firstActiveDate->format('m') ?>
</h2>
<?= TimeTableMonthView::widget([
        'timeTable' => $timeTable,
        'actionsColumn' =>  ['class' => \yii\grid\ActionColumn::class,
            'template' =>'{delete}',
            'buttons' => [
                'delete' => static function ($url) { return Html::a( '<span class="glyphicon  glyphicon-trash"> </span>', $url,
                    [
                        'title' => 'Események törlése',
                        'data-confirm' => Yii::t('yii', 'Biztosan törölni szeretné a heti eseményeket?'),
                        'data-method' => 'post',
                    ]
                ); }
            ],

            'urlCreator' => /**
             * @param $action
             * @param common\modules\event\models\timetable\TimeTableMonthWeek $model
             * @param $key
             * @param $index
             * @return string|null
             */ static function($action, $model, $key, $index){
                if ( $action === 'delete' ){

                    /** @var DateTime $start */
                    $start = $model->getWeekStart();

                    return Url::toRoute( [ 'event/clear-week' , 'ClearWeekForm[targetDateString]' => $start->format('Y.m.d') ] );
                }
                return null;
            },
        ]
]) ?>

