<?php

namespace Modules\Payment\Http\Controllers\Admin;

use Encore\Admin\Controllers\AdminController;
use Encore\Admin\Grid;
use Modules\Payment\Models\Payment;
use Modules\Payment\Models\Transfer;

class TransferController extends AdminController
{

    protected $title = '转账管理';

    public function grid(): Grid
    {
        $grid = new Grid(new Transfer());

        $grid->disableActions();
        $grid->disableCreateButton();

        $grid->quickSearch('transfer_no')->placeholder('转账单号');

        $grid->filter(function (Grid\Filter $filter) {
            $filter->column(1 / 3, function (Grid\Filter $filter) {
                $filter->like('transfer_no', '转账单号');
            });
            $filter->column(1 / 3, function (Grid\Filter $filter) {
                $filter->equal('driver', '转账渠道')->select(Payment::DRIVER_MAP);
            });
            $filter->column(1 / 3, function (Grid\Filter $filter) {
                $filter->like('user_name', '收款人姓名');
            });
        });

        $grid->column('transfer_no', '转账单号');
        $grid->column('driver', '转账渠道')
             ->using(Payment::DRIVER_MAP)
             ->label(Payment::DRIVER_LABEL_MAP);;
        $grid->column('to', '收款用户');
        $grid->column('check', '实名校验')->bool();
        $grid->column('user_name', '收款人姓名');
        $grid->column('desc', '转账附言');
        $grid->column('status', '转账状态');
        $grid->column('created_at', '创建时间');

        return $grid;
    }

}