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

namespace BplanBase\Globals\Providers;


use Illuminate\Http\Request;
use Illuminate\Support\Facades\View;
use Illuminate\Support\ServiceProvider;


/**
 * Global Navigation Service Provider Class
 *
 * @version     1.2.0 / 2026-03-15
 * @author      Emilio Cannarozzo <emilio.cannarozzo@bplan-solutions.de>
 * @author      Wassilios Meletiadis <wassilios.meletiadis@bplan-solutions.de>
 */
class NavigationServiceProvider extends ServiceProvider
{


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


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


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


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


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


    /**
     * Bootstrap services
     *
     * @param       Request $Request
     *
     * @return      void
     *
     * @version     1.2.0 / 2026-03-15
     * @author      Emilio Cannarozzo <emilio.cannarozzo@bplan-solutions.de>
     * @author      Wassilios Meletiadis <wassilios.meletiadis@bplan-solutions.de>
     */
    public function boot(Request $Request): void
    {
        /*
        **  Inject quick links and tenants into the header view. */
        View::composer('globals::layouts.module-frame.header', function ($View) {
            /*
            **  Check quick links. */
            $quickLinks = [];

            if (\Registry::has('quick-links')) {
                $quickLinks = \Registry::get('quick-links');
            }
            /*
            **  Prepare tenants. */
            $registryTenants = \Registry::get('core.tenants');
            $tenants = [];
            /*
                @todo   System in Abhängigkeit vom AccessLevel ausblenden.
                        Außerdem den Tenant-Array leeren, wenn am Ende nur ein Element enthalten ist.
            */
            if (count($registryTenants) > 1) {
                foreach ($registryTenants as $tenant) {
                    $active = false;
                    $label = '';

                    if (\Registry::get('core.tenantId') === $tenant['id']) {
                        $active = true;
                        $label .= '<span class="text-xl text-red-500">&rsaquo;</span>&nbsp;';

                    }
                    $label .= $tenant['identifier'];

                    $tenants[] = [
                        'id'     => $tenant['id'],
                        'active' => $active,
                        'label'  => $label,
                    ];
                }
            }
            $View->with('quickLinks', $quickLinks)
                ->with('tenants', $tenants);
        });
    } // boot()


    /**
     * Register services
     *
     * @return      void
     *
     * @version     1.0.0 / 2025-08-10
     * @author      Emilio Cannarozzo <emilio.cannarozzo@bplan-solutions.de>
     */
    public function register(): void
    {
        //
    } // register()


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


} // class NavigationServiceProvider extends ServiceProvider {}
