<?php

namespace App\Actions;

use LaravelViews\Actions\Action;
use LaravelViews\Views\View;
use Illuminate\Support\Facades\Auth;

class ChangeUserPassword extends Action
{
    /**
     * Any title you want to be displayed
     * @var String
     */
    public $title;

    /**
     * This should be a valid Feather icon string
     * @var String
     */
    public $icon = "key";
    
    /**
     * Constructor
     */
    public function __construct()
    {
        parent::__construct();
        $this->title = "Cambiar contraseña";
    }

    /**
     * Execute the action when the user clicked on the button
     *
     * @param $model Model object of the list where the user has clicked
     * @param $view Current view where the action was executed from
     */
    public function handle($model, View $view)
    {
        // Redirigir a la página de cambio de contraseña
        return redirect('/admin/users/change-password?id=' . $model->id);
    }

    /**
     * Determines if the action can be executed
     *
     * @param $model Model instance of the list where the user has clicked
     * @param $view Current view where the action was executed from
     *
     * @return Bool
     */
    public function renderIf($model, View $view)
    {
        return Auth::user()->isAbleTo('edit-user');
    }
}
