<?php

namespace App\Admin\Controllers;

use App\Admin\Repositories\User;
use Dcat\Admin\Form;
use Dcat\Admin\Grid;
use Dcat\Admin\Show;
use Dcat\Admin\Http\Controllers\AdminController;

class UserController extends AdminController
{
    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        return Grid::make(new User(), function (Grid $grid) {
            $grid->column('id')->sortable();
            $grid->column('name', '用户名');
            $grid->column('email', '账号');
            # $grid->column('email_verified_at');
            # $grid->column('password');
            # $grid->column('remember_token');
            $grid->column('created_at')->display(function ($item) {
                return $item->format('Y-m-d H:i:s');
            });
            $grid->column('updated_at')->sortable()->display(function ($item) {
                return $item->format('Y-m-d H:i:s');
            });

            $grid->filter(function (Grid\Filter $filter) {
                $filter->equal('id');

            });
        });
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     *
     * @return Show
     */
    protected function detail($id)
    {
        return Show::make($id, new User(), function (Show $show) {
            $show->field('id');
            $show->field('name');
            $show->field('email');
            $show->field('email_verified_at');
            $show->field('password');
            $show->field('remember_token');
            $show->field('created_at');
            $show->field('updated_at');
        });
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        return Form::make(new User(), function (Form $form) {
            $form->display('id');
            $form->text('name', '用户名');
            $form->text('email', '账号');
            # $form->text('email_verified_at');
            $form->text('password', '密码');
            # $form->text('remember_token');
            $form->display('created_at');
            $form->display('updated_at');
        });
    }
}
