<?php

namespace App\Admin\Controllers;

use App\Models\SiteAlbumLog;
use Dcat\Admin\Form;
use Dcat\Admin\Grid;
use Dcat\Admin\Show;
use Dcat\Admin\Http\Controllers\AdminController;
use Dcat\Admin\Layout\Content;
use Dcat\Admin\Admin;

class SiteAlbumLogController extends AdminController
{
    /**
     * page index
     */
    public function index(Content $content)
    {
        return $content
            ->header('列表')
            ->description('全部')
            ->breadcrumb(['text'=>'列表','url'=>''])
            ->body($this->grid());
    }

    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        return Grid::make(new SiteAlbumLog(), function (Grid $grid) {
            $grid->column('id')->sortable();
            $grid->column('user_name');
            $grid->column('action');
            $grid->column('model');
            $grid->column('content')->display(function ($value) {
                return $value;
            });
            $grid->column('created_at');
            $grid->column('updated_at')->sortable();
            //搜索
            $grid->filter(function (Grid\Filter $filter) {
                $filter->panel();
                $filter->expand();
                $filter->equal('user_name')->width(2);
                $filter->equal('model')->width(2);
            });
            //按钮
            $grid->disableCreateButton();
            $grid->disableDeleteButton();
            $grid->disableEditButton();
            $grid->disableActions();
            $grid->model()->orderBy('id', 'desc');
        });
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     *
     * @return Show
     */
    protected function detail($id)
    {
        return Show::make($id, new SiteAlbumLog(), function (Show $show) {
            $show->field('id');
            $show->field('user_name');
            $show->field('action');
            $show->field('model');
            $show->field('content');
            $show->field('created_at');
            $show->field('updated_at');
        });
    }

}
