<?php

namespace Modules\Task\Http\Controllers\Admin;

use App\Admin\Traits\WithUploads;
use Encore\Admin\Controllers\AdminController;
use Encore\Admin\Form;
use Encore\Admin\Grid;
use Modules\Linker\Traits\WithLinker;
use Modules\Task\Models\Category;

class CategoryController extends AdminController
{

    use WithUploads, WithLinker;

    protected $title = '分类管理';

    public function grid(): Grid
    {
        $grid = new Grid(new Category());
        $grid->column('id', '#ID#');
        $grid->column('cover', '分类图片')->image('', 50, 100);
        $grid->column('title', '分类名称');
        $grid->column('remark', '描述');
        $grid->column('status', '状态')->switch([
            'on'  => ['value' => 1, 'text' => '打开', 'color' => 'success'],
            'off' => ['value' => 0, 'text' => '关闭', 'color' => 'danger'],
        ]);
        $grid->column('created_at', '创建时间');
        $grid->column('updated_at', '更新时间');

        return $grid;
    }

    public function form(): Form
    {
        $form = new Form(new Category());
        $form->text('title', '分类名称')->required();
        $form->text('remark', '描述')->required();

        $this->cover($form);

        $this->withUrl($form);

        $form->switch('status', '是否开启')->default(1)->states([
            'on'  => ['value' => 1, 'text' => '打开', 'color' => 'success'],
            'off' => ['value' => 0, 'text' => '关闭', 'color' => 'danger'],
        ]);

        return $form;
    }

}
