<?php

namespace Modules\Payment\Http\Controllers\Admin;

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

class RefundController extends AdminController
{

    protected $title = '退款订单';

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

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

        $grid->quickSearch('refund_no')->placeholder('退款单号');
        $grid->filter(function (Grid\Filter $filter) {
            $filter->column(1 / 2, function (Grid\Filter $filter) {
                $filter->like('payment.trade_id', '订单编号');
            });
            $filter->column(1 / 2, function (Grid\Filter $filter) {
                $filter->like('refund_no', '退款单号');
            });
        });

        $grid->column('payment.trade_id', '订单编号')
             ->link(function () {
                 return route('admin.payment.index', ['trade_id' => $this->payment->trade_id]);
             }, '_self');
        $grid->column('payment.total', '订单金额');
        $grid->column('refund_no', '退款单号');
        $grid->column('total', '退款金额');
        $grid->column('退款类型')->display(function () {
            return $this->total === $this->payment->total ? '全额退款' : '部分退款';
        });
        $grid->column('refund_at', '退款时间');
        $grid->column('created_at', '创建时间');

        return $grid;
    }

}