<?php

namespace Modules\Notification\Http\Controllers\Admin;

use Encore\Admin\Controllers\AdminController;
use Encore\Admin\Form;
use Encore\Admin\Grid;
use Modules\Linker\Traits\WithLinker;
use Modules\Notification\Models\Template;

class IndexController extends AdminController
{

    use WithLinker;

    protected $title = '消息模板';

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

        $grid->column('title', '模板标题');
        $grid->column('slug', '调用标识');
        $grid->column('status', '状态')->bool();
        $grid->column('created_at', '创建时间');

        return $grid;
    }

    public function form(): Form
    {
        $form = new Form((new Template())->disableModelCaching());

        $form->text('title', '模板标题')
             ->required();
        $form->text('slug', '调用标识')
             ->required();
        $form->textarea('content', '模板内容')
             ->required();
        $form->switch('status', '状态');

        $this->withUrl($form);

        return $form;
    }

}