<?php

namespace App\Distributor\Actions;

use App\Models\SiteMenu;
use Dcat\Admin\Tree\RowAction;

class MenuShow extends RowAction
{
    public function handle()
    {
        $key = $this->getKey();
        $menu = SiteMenu::where('id', $key)->first();
        $menu->show = $menu->show ? 0 : 1;
        $menu->save();

        $location = $menu->menu_location;
        return $this
            ->response()
            ->success(trans('admin.update_succeeded'))
            ->location('site-menu?location='.$location);
    }

    public function title()
    {
        $icon = $this->getRow()->show ? 'icon-eye-off' : 'icon-eye';

        return "&nbsp;<i class='feather $icon'></i>&nbsp;";
    }
}
