<?php #CodeGenerator V3 Δ fc3b44251a43972b12e3aef3417dbb91 Δ DYNAMICALLY GENERATED FILE - Do not modify this line! Remove it completely to protect the file from changes.
/**
 * Livewire Component
 *
 * @version     1.0.$Revision:$
 * @version     SVN: $Id:$
 * @version     STUB: 1.0.0
 * @generated   2026-06-08 23:11:11
 * @package     bplan-base/globals
 * @subpackage  LivewireComponents
 * @author      Emilio Cannarozzo <emilio.cannarozzo@bplan-solutions.de>
 * @author      Wassilios Meletiadis <wassilios.meletiadis@bplan-solutions.de>
 * @copyright   Copyright (C) 2025, 2026 bplan-solutions GmbH & Co. KG <https://www.bplan-solutions.de/>
 * /Δ\
 */

namespace BplanBase\Globals\Livewire\Role\Modals;


use BplanBase\Globals\Models\Role;
use BplanBase\Globals\Services\RoleService;
use Livewire\Attributes\On;
use Livewire\Component;


/**
 * Livewire Component
 *
 * @version     1.0.0 / 2026-06-08
 * @author      Emilio Cannarozzo <emilio.cannarozzo@bplan-solutions.de>
 * @author      Wassilios Meletiadis <wassilios.meletiadis@bplan-solutions.de>
 */
class Edit extends Component
{


/* +++ TRAITS +++ +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */


/* +++ CLASS CONSTANTS +++ ++++++++++++++++++++++++++++++++++++++++++++++++++ */


/* +++ OBJECT MEMBERS +++ +++++++++++++++++++++++++++++++++++++++++++++++++++ */


    /**
     * @var     RoleService
     */
    protected RoleService $_Service;


/* +++ CLASS MEMBERS +++ ++++++++++++++++++++++++++++++++++++++++++++++++++++ */


    /**
     * @var
     */
    private static $_logPrefix = 'Role/Modals/Edit';


/* +++ OBJECT METHODS +++ +++++++++++++++++++++++++++++++++++++++++++++++++++ */


    /**
     *
     * @param       RoleService $Service
     *
     * @version     1.0.0 / 2026-06-08
     * @author      Emilio Cannarozzo <emilio.cannarozzo@bplan-solutions.de>
     * @author      Wassilios Meletiadis <wassilios.meletiadis@bplan-solutions.de>
     */
    public function boot(RoleService $Service)
    {
        $this->_Service = $Service;

    } // boot()


    /**
     *
     * @return      void
     *
     * @version     1.0.0 / 2026-06-08
     * @author      Emilio Cannarozzo <emilio.cannarozzo@bplan-solutions.de>
     * @author      Wassilios Meletiadis <wassilios.meletiadis@bplan-solutions.de>
     */
    public function deleteRole()
    {
        $this->authorize('role.delete');

        try {
            $this->_Service->delete($this->role->id);
            $User = auth()->user();

            \AppLog::info('Role deleted by ['.$User->name.' ('.$User->email.')]', self::$_logPrefix);

            $this->dispatch('role-deleted');

        } catch (\Throwable $th) {
            $TraceCode = \TraceCode::capture();

            \AppLog::error($th, self::$_logPrefix, TraceCode: $TraceCode);

            $this->dangerBanner(__('bplan-base/globals::roles.error.delete-error', ['trace-code' => $TraceCode]));
        }
    } // deleteRole()


    /**
     *
     * @return      void
     *
     * @version     1.0.0 / 2026-06-08
     * @author      Emilio Cannarozzo <emilio.cannarozzo@bplan-solutions.de>
     * @author      Wassilios Meletiadis <wassilios.meletiadis@bplan-solutions.de>
     */
    public function editRole()
    {
        $this->authorize('role.update');

        $this->validate();

        try {
            $this->_Service->update($this->role->id, []);
            $User = auth()->user();

            \AppLog::info('Role edited by ['.$User->name.' ('.$User->email.')]', self::$_logPrefix);

            $this->dispatch('init-tippyjs');
            $this->dispatch('role-edited');

        } catch (\Throwable $th) {
            $TraceCode = \TraceCode::capture();

            \AppLog::error($th, self::$_logPrefix, TraceCode: $TraceCode);

            $this->dangerBanner(__('bplan-base/globals::roles.error.update-error', ['trace-code' => $TraceCode]));
        }
    } // editRole()


    /**
     *
     * @param       Role $role
     *
     * @return      void
     *
     * @version     1.0.0 / 2026-06-08
     * @author      Emilio Cannarozzo <emilio.cannarozzo@bplan-solutions.de>
     * @author      Wassilios Meletiadis <wassilios.meletiadis@bplan-solutions.de>
     */
//    #[On('show-create-role-modal')]
//    public function initRole(Role $role)
//    {
//        $this->role = $role;
//
////        $this->name = $user->name;
////        $this->email = $user->email;
////        $this->selectedRoles = [];
////
////        foreach ($user->roles as $key => $role) {
////            $this->selectedRoles[$role->id] = true;
////        }
//        $this->dispatch('init-tippyjs');
//
//    } // initRole()


    /**
     *
     * @version     1.0.0 / 2026-06-08
     * @author      Emilio Cannarozzo <emilio.cannarozzo@bplan-solutions.de>
     * @author      Wassilios Meletiadis <wassilios.meletiadis@bplan-solutions.de>
     */
    public function mount()
    {
        //
    } // mount()


    /**
     *
     * @version     1.0.0 / 2026-06-08
     * @author      Emilio Cannarozzo <emilio.cannarozzo@bplan-solutions.de>
     * @author      Wassilios Meletiadis <wassilios.meletiadis@bplan-solutions.de>
     */
    public function render()
    {
        return view('globals::livewire.role.modals.edit');

    } // render()


    /**
     *
     * @return      array
     *
     * @version     1.0.0 / 2026-06-08
     * @author      Emilio Cannarozzo <emilio.cannarozzo@bplan-solutions.de>
     * @author      Wassilios Meletiadis <wassilios.meletiadis@bplan-solutions.de>
     */
    public function rules(): array
    {
        $rules = [];

        return $rules;

    } // rules()


/* +++ CLASS METHODS +++ ++++++++++++++++++++++++++++++++++++++++++++++++++++ */


} // class Edit extends Component {}
