<?php

namespace App\Admin\Controllers;

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

class UserWithdrawController extends AdminController
{
    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        return Grid::make(new UserWithdraw(), function (Grid $grid) {
            $grid->with(['user']);
            $grid->column('id')->sortable();
            $grid->column('user_id','名称')->display(function () {
                return $this->user->nickname;
            });
            $grid->column('phone_num','手机号')->display(function () {
                return $this->user->phone_num;
            });
            $grid->column('price','提现金额');
            $grid->column('account','提现账号');
            $grid->column('created_at','申请时间')->sortable();
            $grid->column('desc','备注');
            $grid->column('status','状态')
                ->using([0=> '待审核',1 => '已通过', 2 => '已拒绝'])
                ->dot(
                    [
                        1 => 'success',
                        2 => 'danger',
                    ],
                    'primary' // 第二个参数为默认值
                );

            $grid->disableDeleteButton();
            $grid->disableCreateButton();
            $grid->disableBatchActions();
            $grid->disableRowSelector();

            $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 UserWithdraw(), function (Show $show) {
            $show->field('id');
            $show->field('user_id');
            $show->field('name');
            $show->field('type');
            $show->field('account');
            $show->field('price');
            $show->field('desc');
            $show->field('status');
            $show->field('created_at');
            $show->field('updated_at');
        });
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        return Form::make(new UserWithdraw(), function (Form $form) {
            $form->display('name');
            $form->display('account');
            $form->display('price');
            $form->display('desc');
            $form->switch('status', '通过？')->default(1);

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