<?php

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

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($card, [
    'params' => ["class" => "table table-bordered", "border" => "2"],
    'baseUrl' => "/admin/card_template",
]));

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

$table->beforePrint(function () use ($card) {
    $btn = IconBtnListWidget::create(['url' => '/admin/card_template'])->run();
    $btn .= IconBtnEditWidget::create(['url' => '/admin/card_template/update/' . $card->id])->run();
    $btn .= IconBtnDeleteWidget::create(['url' => '/admin/card_template/delete/' . $card->id])->run();
    return $btn;
});

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