<?php

namespace App\Admin\Controllers\WeChatProgram\UserManagement;

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

class MenubarController extends AdminController
{
    /**
     * Title for current resource.
     *
     * @var string
     */
    protected $title = '底部菜单';

    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        $grid = new Grid(new Menubar());
        $grid->model()->orderBy('id','desc');

        $grid->column('id', __('Id'));
        $grid->column('name', __('名称'));
        $grid->column('image', __('默认图片'))->lightbox(['width' =>'', 'height' => 30]);
        $grid->column('image_at', __('点击图片'))->lightbox(['width' =>'', 'height' => 30]);
        $grid->column('url', __('链接'));
        $status = [
            'off' => ['value' => 0, 'text' => '禁用', 'color' => 'danger'],
            'on'  => ['value' => 1, 'text' => '启用', 'color' => 'success'],
        ];
        $grid->column('status', __('状态'))->switch($status);
        $grid->column('created_at', __('创建时间'));
        $grid->column('updated_at', __('更新时间'));

        return $grid;
    }


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

        $form->text('name', __('名称'));
        $form->image('image', __('默认图片'));
        $form->image('image_at', __('点击图片'));
        $form->text('url', __('链接'));
        $status = [
            'off' => ['value' => 0, 'text' => '禁用', 'color' => 'danger'],
            'on'  => ['value' => 1, 'text' => '启用', 'color' => 'success'],
        ];
        $form->switch('status', __('状态'))->states($status);
        return $form;
    }
}
