<?php

namespace App\Admin\Controllers;

use App\Models\Withdraw;
use Dcat\Admin\Form;
use Dcat\Admin\Grid;
use Dcat\Admin\Show;
use Dcat\Admin\Http\Controllers\AdminController;

class WithdrawController extends AdminController
{
    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        return Grid::make(new Withdraw(), function (Grid $grid) {
            $grid->model()->with('userData')->orderByDesc('id');
            $grid->column('id')->sortable();
            $grid->column('userData.name','昵称')->sortable();
            $grid->column('userData.avatar','昵称')->image('',40,40);
            $grid->column('userData.mobile','手机号')->sortable();
            $grid->column('type')->using(Withdraw::$label)
                ->dot(
                    [
                        2 => 'primary',
                        1 => 'success',
                        3 => 'danger',
                    ],
                    'danger' // 第二个参数为默认值
                );
            $grid->column('bank_name');
            $grid->column('name');
            $grid->column('number');
            $grid->column('state')->using(Withdraw::$state)
                ->dot(
                    [
                        0 => 'primary',
                        1 => 'success',
                        2 => 'danger',
                    ],
                    'danger' // 第二个参数为默认值
                );;
//            $grid->column('user_id');
            $grid->column('amount');
            $grid->column('procedure');
            $grid->column('practical_amount');
            $grid->column('not_desc');
            $grid->column('created_at');
            $grid->column('updated_at')->sortable();
            $grid->disableDeleteButton();
            $grid->disableCreateButton();
            $grid->disableViewButton();
            $grid->filter(function (Grid\Filter $filter) {
                $filter->panel();
                $filter->equal('state')->select(Withdraw::$state);
                $filter->between('created_at')->datetime();
            });
        });
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     *
     * @return Show
     */
    protected function detail($id)
    {
        return Show::make($id, new Withdraw(), function (Show $show) {
            $show->field('id');
            $show->field('type');
            $show->field('bank_name');
            $show->field('name');
            $show->field('number');
            $show->field('state');
            $show->field('user_id');
            $show->field('amount');
            $show->field('procedure');
            $show->field('practical_amount');
            $show->field('not_desc');
            $show->field('created_at');
            $show->field('updated_at');
        });
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        return Form::make(new Withdraw(), function (Form $form) {
            $state = Withdraw::$state;
            // unset($state[0]);
            $form->display('id');
//            $form->select('type')->options(Withdraw::$label)->disable();
            $form->select('state')
                ->when(2, function (Form $form) {
                    $form->textarea('not_desc');
                })
                ->options($state);
            $form->display('amount');
            $form->display('procedure');
            $form->display('practical_amount');

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