<?php #CodeGenerator V3 Δ 92d6e363b3bbde68454be7e00f30b0d2 Δ 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\Permission\Modals;


use BplanBase\Globals\Models\Permission;
use BplanBase\Globals\Services\PermissionService;
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     PermissionService
     */
    protected PermissionService $_Service;


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


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


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


    /**
     *
     * @param       PermissionService $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(PermissionService $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 deletePermission()
    {
        $this->authorize('permission.delete');

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

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

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

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

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

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


    /**
     *
     * @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 editPermission()
    {
        $this->authorize('permission.update');

        $this->validate();

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

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

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

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

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

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


    /**
     *
     * @param       Permission $permission
     *
     * @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-permission-modal')]
//    public function initPermission(Permission $permission)
//    {
//        $this->permission = $permission;
//
////        $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');
//
//    } // initPermission()


    /**
     *
     * @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.permission.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 {}
