<?php

/**
 * @var \Illuminate\Database\Eloquent\Collection $user_stage
 */

use Itguild\EloquentTable\ViewEloquentTable;
use Itguild\EloquentTable\ViewJsonTableEloquentModel;
use kernel\widgets\IconBtn\IconBtnDeleteWidget;
use kernel\widgets\IconBtn\IconBtnEditWidget;
use kernel\widgets\IconBtn\IconBtnListWidget;

$table = new ViewEloquentTable(new ViewJsonTableEloquentModel($user_stage, [
    'params' => ["class" => "table table-bordered", "border" => "2"],
    'baseUrl' => "/admin/user_stage",
]));
$table->beforePrint(function () use ($user_stage) {
    $btn = IconBtnListWidget::create(['url' => '/admin/user_stage'])->run();
    $btn .= IconBtnEditWidget::create(['url' => '/admin/user_stage/update/' . $user_stage->id])->run();
    $btn .= IconBtnDeleteWidget::create(['url' => '/admin/user_stage/delete/' . $user_stage->id])->run();
    return $btn;
});

$table->rows([
    'status' => (function ($data) {
        return \kernel\app_modules\user_stage\models\UserStage::getStatus()[$data];
    })
]);

$table->create();
$table->render();