<?php

namespace App\Admin\Actions\Form;

use App\Models\UserEpisodesRecord;
use App\Models\UserWithdraw;
use Dcat\Admin\Contracts\LazyRenderable;
use Dcat\Admin\Traits\LazyWidget;
use Dcat\Admin\Widgets\Form;

class WithdrawReview extends Form implements LazyRenderable
{

    use LazyWidget;

    public function handle(array $input)
    {
        $status = $input['status'];
        try {
            $withdraw = UserWithdraw::find($input['id']);
            if ($status > 0) {
                $withdraw->status = $status;
                $withdraw->save();
            }
        } catch (\Exception $exception) {
            return $this->response()->error($exception->getMessage());
        }
        return $this->response()->success('success')->refresh();
    }

    public function form()
    {
        $id = isset($this->payload['id']) ? $this->payload['id'] : 0;
        $this->hidden('id')->value($id);
        $this->radio('status', '审核结果')
            ->options(config('global.withdraw_status'))->default(1);
        $this->disableResetButton();
    }

}
