<?php
/**
 * Base Navigation Service Provider Class
 *
 * @todo        Verlagern nach "Foundation/Providers".
 *
 * @version     1.0.$Revision:$
 * @version     SVN: $Id:$
 * @package     bplan-base/globals
 * @subpackage  Providers
 * @author      Wassilios Meletiadis <wassilios.meletiadis@bplan-solutions.de>
 * @copyright   Copyright (C) 2025, 2026 Wassilios Meletiadis <https://www.bplan-solutions.de/>
 * /Δ\
 */

namespace BplanBase\Globals\Foundation\Support;


use BplanBase\Globals\ViewModels\MenuItem;
use Illuminate\Http\Request;
use Illuminate\Support\ServiceProvider;


/**
 * Base Navigation Service Provider Class
 *
 * @version     1.0.0 / 2026-02-26
 * @author      Wassilios Meletiadis <wassilios.meletiadis@bplan-solutions.de>
 */
class BaseNavigationServiceProvider extends ServiceProvider
{


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


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


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


    /**
     * @var     string
     */
    protected string $_iconAttributes = ' :class="{ \'text-primary-500\': :active }"';


    /**
     * @var     string
     */
    protected string $_packagePrefix;


    /**
     * @var     Request
     */
    protected Request $_Request;


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


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


    /**
     *
     * @param       string $item
     *
     * @param       int $order
     *
     * @param       bool|null & $isActive
     *
     * @param       string|null $routeName
     *
     * @return      MenuItem
     *
     * @version     1.0.0 / 2026-02-26
     * @author      Emilio Cannarozzo <emilio.cannarozzo@bplan-solutions.de>
     * @author      Wassilios Meletiadis <wassilios.meletiadis@bplan-solutions.de>
     */
    protected function _getMenuItem(string $item, int $order, bool|null & $isActive = null, string|null $routeName = null): MenuItem
    {
        if ($routeName === null) {
            if ($item === 'dashboard') {
                $routeName = $this->_packagePrefix.'-dashboard';
            } else {
                $routeName = $this->_packagePrefix.'-'.$item.'.index';
            }
        }
        $active = $this->_Request->routeIs($routeName) ? true : false;
        $isActive = $active;
        $status = $active ? 'true' : 'false';

        return new MenuItem(
            active: $active,
            label: __('globals::core-navigation.'.$item),
            url: route($routeName),
            icon: svg_icon('globals.svg-icons.'.$item, str_replace(':active', $status, $this->_iconAttributes)),
            order: $order
        );
    } // _getMenuItem()


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


} // class BaseNavigationServiceProvider extends ServiceProvider {}
