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

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(Photo::class, [
    'currentPage' => $page_number,
    'perPage' => 8,
    'params' => ["class" => "table table-bordered", "border" => "2"],
    'baseUrl' => "/admin/photo",
]));

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

$table->columns([
    'image' => function ($data) {
        return $data ? "<img src='$data' width='150px'>" : "";
    }
]);

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