<?php

namespace App\Providers;

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

class ViewServiceProvider extends ServiceProvider
{
    /**
     * Register services.
     */
    public function register(): void
    {
        //
    }

    /**
     * Bootstrap services.
     */
    public function handle(): void
    {
        View::composer('*', function ($view) {
            $currentRoute = request()->route() ? request()->route()->getName() : '';
            
            $view->with('isActive', function ($page) use ($currentRoute) {
                if (str_contains($currentRoute, 'services')) {
                    return $currentRoute == $page ? 'active' : '';
                } else {
                    return $currentRoute == $page ? 'class="active"' : '';
                }
            });
        });
    }
}