<?php

namespace App\Admin\Actions\Form;

use App\Admin\Forms\CreateBlindBoxForm;
use Dcat\Admin\Actions\Response;
use Dcat\Admin\Form\AbstractTool;
use Dcat\Admin\Traits\HasPermissions;
use Illuminate\Contracts\Auth\Authenticatable;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Http\Request;
use Dcat\Admin\Widgets\Modal;

class CreateBlindBox extends AbstractTool
{
    protected $title = "添加盲盒";
    protected $button = '<button class="btn btn-primary filter-btn-IuhkezMU btn-outline">添加盲盒</button>';

    public function handle(Request $request)
    {
        // dump($this->getKey());
        return $this->response()
            ->success('Processed successfully.')
            ->redirect('/');
    }

    /**
     * @return string|void
     */
    protected function href()
    {
        // return admin_url('auth/users');
    }

    /**
     * @return string|array|void
     */
    public function confirm()
    {
        // return ['Confirm?', 'contents'];
    }

    /**
     * @param Model|Authenticatable|HasPermissions|null $user
     *
     * @return bool
     */
    protected function authorize($user): bool
    {
        return true;
    }

    /**
     * @return array
     */
    protected function parameters()
    {
        return [];
    }

    public function render()
    {
        // 实例化表单类并传递自定义参数
        # $form = CreateBlindBoxForm::make()->payload(['id' => $this->getKey()]);
        $form = CreateBlindBoxForm::make();

        return Modal::make()
            ->lg()
            ->title($this->title)
            ->body($form)
            ->button($this->button);
    }
}
