<?php

namespace App\Admin\Controllers;

use App\Models\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('nickname');
            $grid->column('avatar');
            $grid->column('password');
            $grid->column('email');
            $grid->column('mobile');
            $grid->column('open_id');
            $grid->column('union_id');
            $grid->column('status');
            $grid->column('email_verified_at');
            $grid->column('remember_token');
            $grid->column('remark');
            $grid->column('type');
            $grid->column('created_at');
            $grid->column('updated_at')->sortable();

            $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('nickname');
            $show->field('avatar');
            $show->field('password');
            $show->field('email');
            $show->field('mobile');
            $show->field('open_id');
            $show->field('union_id');
            $show->field('status');
            $show->field('email_verified_at');
            $show->field('remember_token');
            $show->field('remark');
            $show->field('type');
            $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('nickname');
            $form->text('avatar');
            $form->text('password');
            $form->text('email');
            $form->text('mobile');
            $form->text('open_id');
            $form->text('union_id');
            $form->text('status');
            $form->text('email_verified_at');
            $form->text('remember_token');
            $form->text('remark');
            $form->text('type');

            $form->display('created_at');
            $form->display('updated_at');
        });
    }
}
