<?php

namespace App\Http\Middleware;

use Closure;
use App\Services\WebsiteTemplateService;
use Illuminate\Support\Facades\View;

class WebsiteMiddleware
{
    public function __construct()
    {
        //
    }

    public function handle($request, Closure $next)
    {
        // Verificar si estamos en el contexto de Administración
        if ($request->is('admin/*')) {
            return $next($request);
        }

        // Compartir variables globalmente solo si es una solicitud HTML
        if (str_contains($request->header('Accept'), 'text/html')) {
            $webVars = app(WebsiteTemplateService::class)->getWebsiteVars();

            View::share('_web', $webVars);
        }

        return $next($request);
    }
}
