<?php

namespace App\Admin\Controllers;

use App\Admin\Actions\Dynamic\TagList;
use App\Models\DynamicTag;
use Dcat\Admin\Form;
use Dcat\Admin\Grid;
use Dcat\Admin\Show;
use Dcat\Admin\Http\Controllers\AdminController;

class DynamicTagController extends AdminController
{
    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        $grid = new Grid(new DynamicTag());
        $grid->model()->orderBy('id','desc');
        $grid->column('id')->sortable();
        $grid->column('title');
        $grid->column('hot');

        $grid->filter(function (Grid\Filter $filter) {
            $filter->equal('id');
            $filter->like('title','话题内容');
        });

        $grid->actions(function (Grid\Displayers\Actions $actions) {
            $actions->append(new TagList());
        });
        return $grid;
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     *
     * @return Show
     */
    protected function detail($id)
    {
        return Show::make($id, new DynamicTag(), function (Show $show) {
            $show->field('id');
            $show->field('title');
            $show->field('hot');
        });
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        return Form::make(new DynamicTag(), function (Form $form) {
            $form->display('id');
            $form->text('title');
            $form->text('hot')->default(0);
        });
    }
}
