<?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\Redpack;

class RedpackController extends AdminController
{

    protected $title = '红包管理';

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

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

        $grid->quickSearch('redpack_no')->placeholder('红包编号');

        $grid->filter(function (Grid\Filter $filter) {
            $filter->column(1 / 3, function (Grid\Filter $filter) {
                $filter->like('redpack_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->equal('type', '红包类型')->select(Redpack::TYPE_MAP);
            });
        });

        $grid->column('redpack_no', '红包编号');
        $grid->column('driver', '发送渠道')
             ->using(Payment::DRIVER_MAP)
             ->label(Payment::DRIVER_LABEL_MAP);
        $grid->column('type', '红包类型')
             ->using(Redpack::TYPE_MAP);
        $grid->column('amount', '红包金额');
        $grid->column('to', '发送对象');
        $grid->column('status', '发送状态');
        $grid->column('created_at', '创建时间');

        return $grid;
    }

}