<?php
/**
 * @var int $page_number
 */

use kernel\app_modules\slider\models\Slider;
use Itguild\EloquentTable\EloquentDataProvider;
use Itguild\EloquentTable\ListEloquentTable;
use kernel\app_modules\photo\models\Photo;
use kernel\widgets\IconBtn\IconBtnCreateWidget;
use kernel\widgets\IconBtn\IconBtnDeleteWidget;
use kernel\widgets\IconBtn\IconBtnEditWidget;
use kernel\widgets\IconBtn\IconBtnViewWidget;

$table = new ListEloquentTable(new EloquentDataProvider(Slider::class, [
    'currentPage' => $page_number,
    'perPage' => 8,
    'params' => ["class" => "table table-bordered", "border" => "2"],
    'baseUrl' => "/admin/slider",
]));

$table->beforePrint(function () {
    return IconBtnCreateWidget::create(['url' => '/admin/slider/create'])->run();
});

$table->columns([
    "status" => [
        "value" => function ($cell) {
            return Slider::getStatus()[$cell];
        }]
]);

$table->addAction(function($row) {
    return IconBtnViewWidget::create(['url' => '/admin/slider/view/' . $row['id']])->run();
});
$table->addAction(function($row) {
    return IconBtnEditWidget::create(['url' => '/admin/slider/update/' . $row['id']])->run();
});
$table->addAction(function($row) {
    return IconBtnDeleteWidget::create(['url' => '/admin/slider/delete/' . $row['id']])->run();
});
$table->create();
$table->render();