<?php

namespace App\Admin\Controllers\WeChatProgram\UserManagement;

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

class IconsUserController extends AdminController
{
    /**
     * Title for current resource.
     *
     * @var string
     */
    protected $title = '图标管理——用户端';

    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        $grid = new Grid(new Icons());
        $grid->model()->where('type_cl','1')->orderBy('id','desc');
        $grid->column('id', __('Id'));
        $grid->column('name', __('功能图标名称'));
        $grid->column('image', __('图片'))->lightbox(['width' =>'', 'height' => 30]);
        $grid->column('url', __('点击链接'));
        $grid->column('type', __('类别'))->using([1=>'首页',2=>'文章中心',3=>'个人中心']);
        $grid->column('laval', __('顺序'));
        $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 show builder.
     *
     * @param mixed $id
     * @return Show
     */
    protected function detail($id)
    {
        $show = new Show(Icons::findOrFail($id));

        $show->field('id', __('Id'));
        $show->field('name', __('功能图标名称'));
        $show->field('image', __('图片'))->image();
        $show->field('url', __('点击链接'));
        $show->field('type', __('类别'));
        $show->field('laval', __('顺序'));
        $show->field('status', __('状态'));
        $show->field('created_at', __('创建时间'));
        $show->field('updated_at', __('更新时间'));

        return $show;
    }

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

        $form->text('name', __('名称'))->rules('required' ,['required'=>'请填写名称！']);
        $form->image('image', __('图片'))->rules('required' ,['required'=>'请选择图片！']);
        $form->text('url', __('点击地址'))->rules('required',['requried'=>'请填写点击地址']);
        $form->hidden('type_cl')->default(1);
        $form->select('type', __('分类'))->options(Icons::$_post_type)->default(1);
        $form->number('laval', __('顺序'));
        $status = [
            'off' => ['value' => 0, 'text' => '禁用', 'color' => 'danger'],
            'on'  => ['value' => 1, 'text' => '启用', 'color' => 'success'],
        ];
        $form->switch('status', __('状态'))->states($status);

        return $form;
    }
}
