<?php

namespace App\Admin\Extensions;

use Encore\Admin\Actions\Action;
use Encore\Admin\Actions\Response;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Artisan;

class CleanCache extends Action
{
    protected $selector = '.clear-cache';

    public function handle(Request $request): Response
    {
        Artisan::call('modelCache:clear');
        return $this->response()->success('清理完成')->refresh();
    }

    public function dialog()
    {
        $this->confirm('确认清除缓存');
    }

    public function html(): string
    {
        return <<<HTML
<li>
    <a class="clear-cache" href="#">
      <i class="fa fa-trash"></i>
    </a>
</li>
HTML;
    }
}
