<?php

namespace Modules\Cms\Http\Controllers\Admin;

use Encore\Admin\Controllers\AdminController;
use Encore\Admin\Form;
use Encore\Admin\Grid;
use Modules\Cms\Models\Tag;

class TagController extends AdminController
{

    protected $title = '标签管理';

    public function grid(): Grid
    {
        $grid = new Grid(new Tag());

        $grid->model()
             ->withCount(['articles', 'pages'])
             ->orderByDesc('id');

        $grid->filter(function (Grid\Filter $filter) {
            $filter->scope('trashed', '回收站')->onlyTrashed();

            $filter->column(1 / 2, function (Grid\Filter $filter) {
                $filter->like('name', '标签名称');
            });
        });

        $grid->column('name', '标签名称');
        $grid->column('articles_count');
        $grid->column('pages_count');
        $grid->column('created_at', '创建时间');

        return $grid;
    }

    public function form(): Form
    {
        $form = new Form(new Tag());

        $form->text('name', '标签名称');

        return $form;
    }

}