<?php

namespace App\Distributor\Controllers;

use App\Distributor\Repositories\DistAdminDistributor;
use App\Distributor\Repositories\DistAppearancePublishList;
use App\Http\Controllers\Controller;
use Dcat\Admin\Layout\Content;
use Dcat\Admin\Traits\HasUploadedFile;
use Dcat\Admin\Form;
use Illuminate\Http\Request;

class CacheController extends Controller
{
    use HasUploadedFile;

    public function index(Content $content)
    {
        return $content
            ->body($this->form())
            ->header(admin_trans_label('cache'))
            ->description('');
    }

    protected function form()
    {
        return new Form(null, function (Form $form) {
            $form->title(admin_trans_label('clear_cache'));
            $form->disableListButton();
            $form->disableViewCheck();
            $form->disableEditingCheck();
            $form->disableCreatingCheck();
            //$form->disableResetButton();
            $form->action("/dist-cache/clear")->width(4,2);
            $form->url('url', admin_trans_label('site_url'))->width(4,2)->value(DistAdminDistributor::getDomain())->readOnly();
        });
    }

    public function clear(Request $request)
    {
        //更新版本
        //DistAppearancePublishList::publishVersion();
        //清除缓存
        DistAdminDistributor::clearCache();
        $form = new Form();
        return $form->response()->success(admin_trans_label('update_success'));
    }

}
