<?php

namespace App\Admin\Controllers;

use App\Models\HelpInfo;
use Encore\Admin\Controllers\AdminController;
use Encore\Admin\Form;
use Encore\Admin\Grid;
use Encore\Admin\Show;

class HelpInfoController extends AdminController
{
    /**
     * Title for current resource.
     *
     * @var string
     */
    protected $title = '常见问题';

    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        $grid = new Grid(new HelpInfo());

        $grid->column('id', __('Id'));
        $grid->column('title', __('标题'));
        $grid->column('content', __('内容'))->limit(50,'...');
        $state = [
            'on' => ['value' =>1, 'text' => '展示', 'color' => 'primary'],
            'off' => ['value' => 0, 'text' => '不展示', 'color' => 'danger']
        ];
        $grid->column('status', __('状态'))->switch($state);
        $grid->column('created_at', __('创建时间'));
        $grid->column('updated_at', __('修改时间'));

        return $grid;
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     * @return Show
     */
    protected function detail($id)
    {
        $show = new Show(HelpInfo::findOrFail($id));

        $show->field('id', __('Id'));
        $show->field('title', __('标题'));
        $show->field('content', __('内容'));
        $show->field('status', __('状态'))->using([0=>'不展示',1=>'展示']);
        $show->field('created_at', __('创建时间'));
        $show->field('updated_at', __('更新时间'));

        return $show;
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        $form = new Form(new HelpInfo());

        $form->text('title', __('标题'));
        $form->editor('content', __('内容'));
        $state = [
            'on' => ['value' =>1, 'text' => '展示', 'color' => 'primary'],
            'off' => ['value' => 0, 'text' => '不展示', 'color' => 'danger']
        ];
        $form->switch('status', __('状态'))->default(1);
        $form->footer(function ($footer) {
            // 去掉`查看`checkbox
            $footer->disableViewCheck();
            // 去掉`继续编辑`checkbox
            $footer->disableEditingCheck();
            // 去掉`继续创建`checkbox
            $footer->disableCreatingCheck();

        });
        return $form;
    }
}
