<?php

namespace App\Admin\Controllers;

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

class TransferRecordController extends AdminController
{
    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        return Grid::make(new TransferRecord(), function (Grid $grid) {
            // 新增按钮-禁用
            $grid->disableCreateButton();
            // 行操作--禁用
            $grid->disableActions();
            // 行选择器
            $grid->disableRowSelector();
            $grid->column('id')->sortable();
            $grid->column('to');
            $grid->column('price');
            $grid->column('hash');
            $grid->column('status')->using([1 => '转账成功', 2 => '转账失败'])->label([
                'default' => 'primary', // 设置默认颜色，不设置则默认为 default
                1 => 'primary',
                2 => 'danger',
            ]);
            $grid->column('type')->using([1 => '开奖', 2 => '退款'])->label([
                'default' => 'primary', // 设置默认颜色，不设置则默认为 default
                1 => 'primary',
                2 => 'danger',
            ]);
            $grid->column('blind_box_id');
            $grid->column('created_at');
            $grid->column('updated_at')->sortable();

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

    /**
     * Make a show builder.
     *
     * @param mixed $id
     *
     * @return Show
     */
    protected function detail($id)
    {
        return Show::make($id, new TransferRecord(), function (Show $show) {
            $show->field('id');
            $show->field('to');
            $show->field('price');
            $show->field('hash');
            $show->field('status');
            $show->field('blind_box_id');
            $show->field('created_at');
            $show->field('updated_at');
        });
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        return Form::make(new TransferRecord(), function (Form $form) {
            $form->display('id');
            $form->text('to');
            $form->text('price');
            $form->text('hash');
            $form->text('status');
            $form->text('blind_box_id');

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