<?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 BplanBase\Globals\Models\Tenant;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\View;
use Illuminate\Support\ServiceProvider;


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


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


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


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


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


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


    /**
     * Bootstrap services
     *
     * @param       Request $Request
     *
     * @return      void
     *
     * @version     1.1.0 / 2026-05-03
     * @author      Emilio Cannarozzo <emilio.cannarozzo@bplan-solutions.de>
     * @author      Wassilios Meletiadis <wassilios.meletiadis@bplan-solutions.de>
     */
    public function boot(Request $Request): void
    {
        /*
        **  Inject module information into every view. */
        View::composer('*', function ($View) {
            $View->with('currentModule', \Registry::get('env.currentModule'))
                ->with('moduleName', \Registry::get('env.moduleName'));
        });
        /*
        **  Inject the page title. */
        View::composer([
                'layouts.app',
                'layouts.guest',
                '*::app',
                '*::guest',
                'globals::layouts.module-frame',
            ],
            function ($View) {

                $Module = \Registry::get('env.module');
                $Tenant = Tenant::current();
                $title = \Registry::get('env.page-title');

                if ($Module === null) {
                    $pageTitle = 'CORE';

                } else {
                    $pageTitle = 'CORE '.$Module->label;
                }
                if ($title !== null) {
                    $pageTitle .= ' ~ '.$title;
                }
                if ($Tenant !== null) {
                    $pageTitle .= ' ~ '.$Tenant->tenantRecord->company;
                }
                $View->with('pageTitle', $pageTitle);
            }
        );
    } // boot()


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


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


} // class ViewServiceProvider extends ServiceProvider {}
